From e01311a565faf5289f27cc4e7e31b8bf31ba1fa3 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 17 Sep 2023 08:00:38 +0200 Subject: [PATCH] gpu: Add support for cross-fades --- gsk/gpu/gskgpunodeprocessor.c | 45 +++++++++++++++++++++++++++++++++-- gsk/gpu/gskgputypesprivate.h | 2 ++ gsk/gpu/shaders/enums.glsl | 2 ++ gsk/gpu/shaders/pattern.glsl | 17 +++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/gsk/gpu/gskgpunodeprocessor.c b/gsk/gpu/gskgpunodeprocessor.c index 10c5bac147..4104b022df 100644 --- a/gsk/gpu/gskgpunodeprocessor.c +++ b/gsk/gpu/gskgpunodeprocessor.c @@ -1006,6 +1006,47 @@ gsk_gpu_node_processor_create_conic_gradient_pattern (GskGpuPatternWriter *self, return TRUE; } +static gboolean +gsk_gpu_node_processor_create_cross_fade_pattern (GskGpuPatternWriter *self, + GskRenderNode *node) +{ + GskRenderNode *start_child, *end_child; + + start_child = gsk_cross_fade_node_get_start_child (node); + end_child = gsk_cross_fade_node_get_end_child (node); + + if (!gsk_gpu_node_processor_create_node_pattern (self, start_child)) + return FALSE; + if (!gsk_rect_contains_rect (&start_child->bounds, &node->bounds)) + { + gsk_gpu_buffer_writer_append_uint (&self->writer, GSK_GPU_PATTERN_CLIP); + gsk_gpu_buffer_writer_append_rect (&self->writer, &start_child->bounds, &self->offset); + } + + gsk_gpu_buffer_writer_append_uint (&self->writer, GSK_GPU_PATTERN_PUSH_COLOR); + + if (!gsk_gpu_pattern_writer_push_stack (self)) + return FALSE; + + if (!gsk_gpu_node_processor_create_node_pattern (self, end_child)) + { + gsk_gpu_pattern_writer_pop_stack (self); + return FALSE; + } + if (!gsk_rect_contains_rect (&end_child->bounds, &node->bounds)) + { + gsk_gpu_buffer_writer_append_uint (&self->writer, GSK_GPU_PATTERN_CLIP); + gsk_gpu_buffer_writer_append_rect (&self->writer, &end_child->bounds, &self->offset); + } + + gsk_gpu_buffer_writer_append_uint (&self->writer, GSK_GPU_PATTERN_POP_CROSS_FADE); + gsk_gpu_buffer_writer_append_float (&self->writer, gsk_cross_fade_node_get_progress (node)); + + gsk_gpu_pattern_writer_pop_stack (self); + + return TRUE; +} + static void gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self, GskRenderNode *node) @@ -1377,8 +1418,8 @@ static const struct }, [GSK_CROSS_FADE_NODE] = { 0, - NULL, - NULL, + gsk_gpu_node_processor_add_node_as_pattern, + gsk_gpu_node_processor_create_cross_fade_pattern, }, [GSK_TEXT_NODE] = { 0, diff --git a/gsk/gpu/gskgputypesprivate.h b/gsk/gpu/gskgputypesprivate.h index adbc3df9a4..512003c80b 100644 --- a/gsk/gpu/gskgputypesprivate.h +++ b/gsk/gpu/gskgputypesprivate.h @@ -45,5 +45,7 @@ typedef enum { GSK_GPU_PATTERN_ROUNDED_CLIP, GSK_GPU_PATTERN_REPEAT_PUSH, GSK_GPU_PATTERN_POSITION_POP, + GSK_GPU_PATTERN_PUSH_COLOR, + GSK_GPU_PATTERN_POP_CROSS_FADE, } GskGpuPatternType; diff --git a/gsk/gpu/shaders/enums.glsl b/gsk/gpu/shaders/enums.glsl index 2a548dc7e2..7635baf63d 100644 --- a/gsk/gpu/shaders/enums.glsl +++ b/gsk/gpu/shaders/enums.glsl @@ -22,6 +22,8 @@ #define GSK_GPU_PATTERN_ROUNDED_CLIP 12u #define GSK_GPU_PATTERN_REPEAT_PUSH 13u #define GSK_GPU_PATTERN_POSITION_POP 14u +#define GSK_GPU_PATTERN_PUSH_COLOR 15u +#define GSK_GPU_PATTERN_POP_CROSS_FADE 16u #define TOP 0u #define RIGHT 1u diff --git a/gsk/gpu/shaders/pattern.glsl b/gsk/gpu/shaders/pattern.glsl index 8729dfa890..3d84cee6d1 100644 --- a/gsk/gpu/shaders/pattern.glsl +++ b/gsk/gpu/shaders/pattern.glsl @@ -140,6 +140,16 @@ position_pop_pattern (inout uint reader, pos = stack_pop ().xy; } +void +cross_fade_pattern (inout uint reader, + inout vec4 color) +{ + vec4 start = stack_pop (); + float progress = read_float (reader); + + color = mix (start, color, progress); +} + vec4 glyphs_pattern (inout uint reader, vec2 pos) @@ -294,6 +304,13 @@ pattern (uint reader, case GSK_GPU_PATTERN_POSITION_POP: position_pop_pattern (reader, pos); break; + case GSK_GPU_PATTERN_PUSH_COLOR: + stack_push (color); + color = vec4 (0.0); + break; + case GSK_GPU_PATTERN_POP_CROSS_FADE: + cross_fade_pattern (reader, color); + break; } } }