gpu: Use variations in the blur shader

Have one variation for colorizing to a shadow color and another
variation that just blurs.
This commit is contained in:
Benjamin Otte 2023-12-31 06:44:16 +01:00
parent 177b19a2da
commit d11886e7ac
4 changed files with 102 additions and 27 deletions

View File

@ -6,8 +6,12 @@
#include "gskgpuprintprivate.h"
#include "gskrectprivate.h"
#include "gdk/gdkrgbaprivate.h"
#include "gpu/shaders/gskgpublurinstance.h"
#define VARIATION_COLORIZE 1
typedef struct _GskGpuBlurOp GskGpuBlurOp;
struct _GskGpuBlurOp
@ -51,22 +55,23 @@ static const GskGpuShaderOpClass GSK_GPU_BLUR_OP_CLASS = {
gsk_gpu_blur_setup_vao
};
void
gsk_gpu_blur_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
GskGpuDescriptors *desc,
guint32 descriptor,
const graphene_rect_t *rect,
const graphene_point_t *offset,
const graphene_rect_t *tex_rect,
const graphene_vec2_t *blur_direction,
const GdkRGBA *blur_color)
static void
gsk_gpu_blur_op_full (GskGpuFrame *frame,
guint32 variation,
GskGpuShaderClip clip,
GskGpuDescriptors *desc,
guint32 descriptor,
const graphene_rect_t *rect,
const graphene_point_t *offset,
const graphene_rect_t *tex_rect,
const graphene_vec2_t *blur_direction,
const GdkRGBA *blur_color)
{
GskGpuBlurInstance *instance;
gsk_gpu_shader_op_alloc (frame,
&GSK_GPU_BLUR_OP_CLASS,
0,
variation,
clip,
desc,
&instance);
@ -77,3 +82,49 @@ gsk_gpu_blur_op (GskGpuFrame *frame,
gsk_gpu_rgba_to_float (blur_color, instance->blur_color);
instance->tex_id = descriptor;
}
void
gsk_gpu_blur_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
GskGpuDescriptors *desc,
guint32 descriptor,
const graphene_rect_t *rect,
const graphene_point_t *offset,
const graphene_rect_t *tex_rect,
const graphene_vec2_t *blur_direction)
{
gsk_gpu_blur_op_full (frame,
0,
clip,
desc,
descriptor,
rect,
offset,
tex_rect,
blur_direction,
&GDK_RGBA_TRANSPARENT);
}
void
gsk_gpu_blur_shadow_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
GskGpuDescriptors *desc,
guint32 descriptor,
const graphene_rect_t *rect,
const graphene_point_t *offset,
const graphene_rect_t *tex_rect,
const graphene_vec2_t *blur_direction,
const GdkRGBA *shadow_color)
{
gsk_gpu_blur_op_full (frame,
VARIATION_COLORIZE,
clip,
desc,
descriptor,
rect,
offset,
tex_rect,
blur_direction,
shadow_color);
}

View File

@ -7,6 +7,15 @@
G_BEGIN_DECLS
void gsk_gpu_blur_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
GskGpuDescriptors *desc,
guint32 descriptor,
const graphene_rect_t *rect,
const graphene_point_t *offset,
const graphene_rect_t *tex_rect,
const graphene_vec2_t *blur_direction);
void gsk_gpu_blur_shadow_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
GskGpuDescriptors *desc,
guint32 descriptor,
@ -14,7 +23,7 @@ void gsk_gpu_blur_op (GskGpuF
const graphene_point_t *offset,
const graphene_rect_t *tex_rect,
const graphene_vec2_t *blur_direction,
const GdkRGBA *blur_color);
const GdkRGBA *shadow_color);
G_END_DECLS

View File

@ -948,7 +948,7 @@ gsk_gpu_node_processor_blur_op (GskGpuNodeProcessor *self,
const graphene_rect_t *rect,
const graphene_point_t *shadow_offset,
float blur_radius,
const GdkRGBA *blur_color_or_null,
const GdkRGBA *shadow_color,
GskGpuDescriptors *source_desc,
guint32 source_descriptor,
GdkMemoryDepth source_depth,
@ -1001,8 +1001,7 @@ gsk_gpu_node_processor_blur_op (GskGpuNodeProcessor *self,
&intermediate_rect,
&other.offset,
source_rect,
&direction,
&GDK_RGBA_TRANSPARENT);
&direction);
gsk_gpu_render_pass_end_op (other.frame,
intermediate,
@ -1014,15 +1013,29 @@ gsk_gpu_node_processor_blur_op (GskGpuNodeProcessor *self,
self->offset.y + shadow_offset->y);
graphene_vec2_init (&direction, 0.0f, blur_radius);
intermediate_descriptor = gsk_gpu_node_processor_add_image (self, intermediate, GSK_GPU_SAMPLER_TRANSPARENT);
gsk_gpu_blur_op (self->frame,
gsk_gpu_clip_get_shader_clip (&self->clip, &real_offset, rect),
self->desc,
intermediate_descriptor,
rect,
&real_offset,
&intermediate_rect,
&direction,
blur_color_or_null ? blur_color_or_null : &GDK_RGBA_TRANSPARENT);
if (shadow_color)
{
gsk_gpu_blur_shadow_op (self->frame,
gsk_gpu_clip_get_shader_clip (&self->clip, &real_offset, rect),
self->desc,
intermediate_descriptor,
rect,
&real_offset,
&intermediate_rect,
&direction,
shadow_color);
}
else
{
gsk_gpu_blur_op (self->frame,
gsk_gpu_clip_get_shader_clip (&self->clip, &real_offset, rect),
self->desc,
intermediate_descriptor,
rect,
&real_offset,
&intermediate_rect,
&direction);
}
g_object_unref (intermediate);
}

View File

@ -2,6 +2,8 @@
/* blur radius (aka in_blur_direction) 0 is NOT supported and MUST be caught before */
#define VARIATION_COLORIZE ((GSK_VARIATION & 1u) == 1u)
PASS(0) vec2 _pos;
PASS_FLAT(1) Rect _rect;
PASS_FLAT(2) vec4 _blur_color;
@ -70,10 +72,10 @@ run (out vec4 color,
p += _tex_blur_step;
}
if (_blur_color.a <= 0.0)
color = sum / coefficient_sum;
else
if (VARIATION_COLORIZE)
color = _blur_color * sum.a / coefficient_sum;
else
color = sum / coefficient_sum;
position = _pos;
}