gpu: Simplify the blur op a bit

I was looking through it and thought this looks better.

It's also 21 lineas of code less.
This commit is contained in:
Benjamin Otte 2024-08-21 03:46:22 +02:00
parent a52ae238ab
commit 6a986f03b6
2 changed files with 32 additions and 53 deletions

View File

@ -53,37 +53,6 @@ static const GskGpuShaderOpClass GSK_GPU_BLUR_OP_CLASS = {
gsk_gpu_blur_setup_vao
};
static void
gsk_gpu_blur_op_full (GskGpuFrame *frame,
GskGpuShaderClip clip,
GdkColorState *ccs,
float opacity,
const graphene_point_t *offset,
guint32 variation,
const GskGpuShaderImage *image,
const graphene_vec2_t *blur_direction,
const GdkColor *blur_color)
{
GskGpuBlurInstance *instance;
GdkColorState *alt;
alt = gsk_gpu_color_states_find (ccs, blur_color);
gsk_gpu_shader_op_alloc (frame,
&GSK_GPU_BLUR_OP_CLASS,
gsk_gpu_color_states_create (ccs, TRUE, alt, variation & VARIATION_COLORIZE ? FALSE : TRUE),
variation,
clip,
(GskGpuImage *[1]) { image->image },
(GskGpuSampler[1]) { image->sampler },
&instance);
gsk_gpu_rect_to_float (image->coverage, offset, instance->rect);
gsk_gpu_rect_to_float (image->bounds, offset, instance->tex_rect);
graphene_vec2_to_float (blur_direction, instance->blur_direction);
gsk_gpu_color_to_float (blur_color, alt, opacity, instance->blur_color);
}
void
gsk_gpu_blur_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
@ -93,19 +62,20 @@ gsk_gpu_blur_op (GskGpuFrame *frame,
const GskGpuShaderImage *image,
const graphene_vec2_t *blur_direction)
{
GdkColor blur_color;
GskGpuBlurInstance *instance;
gdk_color_init (&blur_color, ccs, (float[]) { 1, 1, 1, 1 });
gsk_gpu_blur_op_full (frame,
clip,
ccs,
opacity,
offset,
0,
image,
blur_direction,
&blur_color);
gdk_color_finish (&blur_color);
gsk_gpu_shader_op_alloc (frame,
&GSK_GPU_BLUR_OP_CLASS,
gsk_gpu_color_states_create_equal (TRUE, TRUE),
0,
clip,
(GskGpuImage *[1]) { image->image },
(GskGpuSampler[1]) { image->sampler },
&instance);
gsk_gpu_rect_to_float (image->coverage, offset, instance->rect);
gsk_gpu_rect_to_float (image->bounds, offset, instance->tex_rect);
graphene_vec2_to_float (blur_direction, instance->blur_direction);
}
void
@ -118,14 +88,23 @@ gsk_gpu_blur_shadow_op (GskGpuFrame *frame,
const graphene_vec2_t *blur_direction,
const GdkColor *shadow_color)
{
gsk_gpu_blur_op_full (frame,
clip,
ccs,
opacity,
offset,
VARIATION_COLORIZE,
image,
blur_direction,
shadow_color);
GskGpuBlurInstance *instance;
GdkColorState *alt;
alt = gsk_gpu_color_states_find (ccs, shadow_color);
gsk_gpu_shader_op_alloc (frame,
&GSK_GPU_BLUR_OP_CLASS,
gsk_gpu_color_states_create (ccs, TRUE, alt, FALSE),
VARIATION_COLORIZE,
clip,
(GskGpuImage *[1]) { image->image },
(GskGpuSampler[1]) { image->sampler },
&instance);
gsk_gpu_rect_to_float (image->coverage, offset, instance->rect);
gsk_gpu_rect_to_float (image->bounds, offset, instance->tex_rect);
graphene_vec2_to_float (blur_direction, instance->blur_direction);
gsk_gpu_color_to_float (shadow_color, alt, opacity, instance->blur_color);
}

View File

@ -72,7 +72,7 @@ run (out vec4 color,
}
if (VARIATION_COLORIZE)
color = _blur_color * sum.a / coefficient_sum;
color = output_color_alpha (_blur_color, sum.a / coefficient_sum);
else
color = sum / coefficient_sum;
position = _pos;