gpu: Add clip pattern

So now we can clip inside an opacity node without needing fallback.
This commit is contained in:
Benjamin Otte 2023-09-11 05:46:23 +02:00
parent 0cac75aff1
commit a9b8551e70
4 changed files with 43 additions and 1 deletions

View File

@ -531,6 +531,30 @@ gsk_gpu_node_processor_add_clip_node (GskGpuNodeProcessor *self,
}
}
static gboolean
gsk_gpu_node_processor_create_clip_pattern (GskGpuNodeProcessor *self,
GskGpuBufferWriter *writer,
GskRenderNode *node,
GskGpuShaderImage *images,
gsize n_images,
gsize *out_n_images)
{
if (!gsk_gpu_node_processor_create_node_pattern (self,
writer,
gsk_opacity_node_get_child (node),
images,
n_images,
out_n_images))
return FALSE;
gsk_gpu_buffer_writer_append_uint (writer, GSK_GPU_PATTERN_CLIP);
gsk_gpu_buffer_writer_append_rect (writer,
gsk_clip_node_get_clip (node),
&self->offset);
return TRUE;
}
static void
gsk_gpu_node_processor_add_rounded_clip_node (GskGpuNodeProcessor *self,
GskRenderNode *node)
@ -1142,7 +1166,7 @@ static const struct
[GSK_CLIP_NODE] = {
GSK_GPU_GLOBAL_MATRIX | GSK_GPU_GLOBAL_SCALE | GSK_GPU_GLOBAL_CLIP | GSK_GPU_GLOBAL_SCISSOR,
gsk_gpu_node_processor_add_clip_node,
NULL,
gsk_gpu_node_processor_create_clip_pattern,
},
[GSK_ROUNDED_CLIP_NODE] = {
GSK_GPU_GLOBAL_MATRIX | GSK_GPU_GLOBAL_SCALE | GSK_GPU_GLOBAL_CLIP | GSK_GPU_GLOBAL_SCISSOR,

View File

@ -39,5 +39,7 @@ typedef enum {
GSK_GPU_PATTERN_RADIAL_GRADIENT,
GSK_GPU_PATTERN_REPEATING_RADIAL_GRADIENT,
GSK_GPU_PATTERN_CONIC_GRADIENT,
GSK_GPU_PATTERN_CLIP,
GSK_GPU_PATTERN_ROUNDED_CLIP,
} GskGpuPatternType;

View File

@ -16,6 +16,8 @@
#define GSK_GPU_PATTERN_RADIAL_GRADIENT 8u
#define GSK_GPU_PATTERN_REPEATING_RADIAL_GRADIENT 9u
#define GSK_GPU_PATTERN_CONIC_GRADIENT 10u
#define GSK_GPU_PATTERN_CLIP 11u
#define GSK_GPU_PATTERN_ROUNDED_CLIP 12u
#define TOP 0u
#define RIGHT 1u

View File

@ -65,6 +65,17 @@ read_gradient (inout uint reader)
return gradient;
}
void
clip_pattern (inout uint reader,
inout vec4 color,
vec2 pos)
{
Rect clip = read_rect (reader);
float alpha = rect_coverage (clip, pos);
color *= alpha;
}
void
opacity_pattern (inout uint reader,
inout vec4 color,
@ -234,6 +245,9 @@ pattern (uint reader,
case GSK_GPU_PATTERN_CONIC_GRADIENT:
color = conic_gradient_pattern (reader, pos);
break;
case GSK_GPU_PATTERN_CLIP:
clip_pattern (reader, color, pos);
break;
}
}
}