From 6a986f03b615bdeb1b2e7ab5cda4b49f07a2229b Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 21 Aug 2024 03:46:22 +0200 Subject: [PATCH] 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. --- gsk/gpu/gskgpublurop.c | 83 ++++++++++++--------------------- gsk/gpu/shaders/gskgpublur.glsl | 2 +- 2 files changed, 32 insertions(+), 53 deletions(-) diff --git a/gsk/gpu/gskgpublurop.c b/gsk/gpu/gskgpublurop.c index 86bafae4df..260a2d70f5 100644 --- a/gsk/gpu/gskgpublurop.c +++ b/gsk/gpu/gskgpublurop.c @@ -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); } diff --git a/gsk/gpu/shaders/gskgpublur.glsl b/gsk/gpu/shaders/gskgpublur.glsl index 42eb39cc2f..f3279cd333 100644 --- a/gsk/gpu/shaders/gskgpublur.glsl +++ b/gsk/gpu/shaders/gskgpublur.glsl @@ -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;