gpu: Add support for cross-fades

This commit is contained in:
Benjamin Otte 2023-09-17 08:00:38 +02:00
parent 0876089f8f
commit e01311a565
4 changed files with 64 additions and 2 deletions

View File

@ -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,

View File

@ -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;

View File

@ -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

View File

@ -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;
}
}
}