gsk: Change the colorize op api

Pass the ccs, opacity and GdkColors to the op to let it make
decisions about color conversion.

Update the callers.
This commit is contained in:
Matthias Clasen 2024-08-05 08:52:54 -04:00
parent d233f0ca3e
commit 3a99f1e9f1
3 changed files with 29 additions and 20 deletions

View File

@ -52,16 +52,20 @@ static const GskGpuShaderOpClass GSK_GPU_COLORIZE_OP_CLASS = {
void
gsk_gpu_colorize_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
GskGpuColorStates color_states,
GdkColorState *ccs,
float opacity,
const graphene_point_t *offset,
const GskGpuShaderImage *image,
const float color[4])
const GdkColor *color)
{
GskGpuColorizeInstance *instance;
GdkColorState *alt;
alt = gsk_gpu_color_states_find (ccs, color);
gsk_gpu_shader_op_alloc (frame,
&GSK_GPU_COLORIZE_OP_CLASS,
color_states,
gsk_gpu_color_states_create (ccs, TRUE, alt, FALSE),
0,
clip,
(GskGpuImage *[1]) { image->image },
@ -70,5 +74,5 @@ gsk_gpu_colorize_op (GskGpuFrame *frame,
gsk_gpu_rect_to_float (image->coverage ? image->coverage : image->bounds, offset, instance->rect);
gsk_gpu_rect_to_float (image->bounds, offset, instance->tex_rect);
gsk_gpu_vec4_to_float (color, instance->color);
gsk_gpu_color_to_float (color, alt, opacity, instance->color);
}

View File

@ -8,10 +8,11 @@ G_BEGIN_DECLS
void gsk_gpu_colorize_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
GskGpuColorStates color_states,
GdkColorState *ccs,
float opacity,
const graphene_point_t *offset,
const GskGpuShaderImage *image,
const float color[4]);
const GdkColor *color);
G_END_DECLS

View File

@ -2636,13 +2636,18 @@ gsk_gpu_node_processor_add_shadow_node (GskGpuNodeProcessor *self,
for (i = 0; i < n_shadows; i++)
{
const GskShadow *shadow = gsk_shadow_node_get_shadow (node, i);
if (shadow->radius == 0)
{
GdkColor color;
graphene_point_t shadow_offset = GRAPHENE_POINT_INIT (self->offset.x + shadow->dx,
self->offset.y + shadow->dy);
gdk_color_init_from_rgba (&color, &shadow->color);
gsk_gpu_colorize_op (self->frame,
gsk_gpu_clip_get_shader_clip (&self->clip, &shadow_offset, &child->bounds),
gsk_gpu_node_processor_color_states_for_rgba (self),
self->ccs,
1,
&shadow_offset,
&(GskGpuShaderImage) {
image,
@ -2650,7 +2655,8 @@ gsk_gpu_node_processor_add_shadow_node (GskGpuNodeProcessor *self,
&child->bounds,
&tex_rect,
},
GSK_RGBA_TO_VEC4 (&shadow->color));
&color);
gdk_color_finish (&color);
}
else
{
@ -2871,14 +2877,10 @@ gsk_gpu_node_processor_add_mask_node (GskGpuNodeProcessor *self,
if (gsk_render_node_get_node_type (source_child) == GSK_COLOR_NODE &&
mask_mode == GSK_MASK_MODE_ALPHA)
{
float color[4];
gdk_color_to_float (gsk_color_node_get_color2 (source_child), self->ccs, color);
color[3] *= self->opacity;
gsk_gpu_colorize_op (self->frame,
gsk_gpu_clip_get_shader_clip (&self->clip, &self->offset, &node->bounds),
gsk_gpu_node_processor_color_states_explicit (self, self->ccs, FALSE),
self->ccs,
self->opacity,
&self->offset,
&(GskGpuShaderImage) {
mask_image,
@ -2886,7 +2888,7 @@ gsk_gpu_node_processor_add_mask_node (GskGpuNodeProcessor *self,
&node->bounds,
&mask_rect,
},
color);
gsk_color_node_get_color2 (source_child));
}
else
{
@ -2938,7 +2940,7 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self,
graphene_point_t offset;
guint i, num_glyphs;
float scale;
GdkRGBA color;
GdkColor color;
float align_scale_x, align_scale_y;
float inv_align_scale_x, inv_align_scale_y;
unsigned int flags_mask;
@ -2954,8 +2956,7 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self,
cache = gsk_gpu_device_get_cache (gsk_gpu_frame_get_device (self->frame));
color = *gsk_text_node_get_color (node);
color.alpha *= self->opacity;
gdk_color_init_from_rgba (&color, gsk_text_node_get_color (node));
num_glyphs = gsk_text_node_get_num_glyphs (node);
glyphs = gsk_text_node_get_glyphs (node, NULL);
font = gsk_text_node_get_font (node);
@ -3033,7 +3034,8 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self,
else
gsk_gpu_colorize_op (self->frame,
gsk_gpu_clip_get_shader_clip (&self->clip, &glyph_origin, &glyph_bounds),
gsk_gpu_node_processor_color_states_for_rgba (self),
self->ccs,
self->opacity,
&glyph_origin,
&(GskGpuShaderImage) {
image,
@ -3041,10 +3043,12 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self,
&glyph_bounds,
&glyph_tex_rect
},
GSK_RGBA_TO_VEC4 (&color));
&color);
offset.x += glyphs[i].geometry.width * inv_pango_scale;
}
gdk_color_finish (&color);
}
static void