gpu: Make radial gradient op obey ccs

Straight copy of the linear gradient changes.
This commit is contained in:
Benjamin Otte 2024-07-04 06:33:23 +02:00
parent 099d72f037
commit b59e4a929e
4 changed files with 27 additions and 21 deletions

View File

@ -2175,6 +2175,7 @@ gsk_gpu_node_processor_radial_gradient_op (GskGpuNodeProcessor *self,
{
gsk_gpu_radial_gradient_op (self->frame,
gsk_gpu_clip_get_shader_clip (&self->clip, &self->offset, &node->bounds),
gsk_gpu_node_processor_color_states_explicit (self, GDK_COLOR_STATE_SRGB, TRUE),
GSK_RENDER_NODE_TYPE (node) == GSK_REPEATING_RADIAL_GRADIENT_NODE,
&node->bounds,
gsk_radial_gradient_node_get_center (node),

View File

@ -54,6 +54,7 @@ static const GskGpuShaderOpClass GSK_GPU_RADIAL_GRADIENT_OP_CLASS = {
void
gsk_gpu_radial_gradient_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
GskGpuColorStates color_states,
gboolean repeating,
const graphene_rect_t *rect,
const graphene_point_t *center,
@ -65,13 +66,15 @@ gsk_gpu_radial_gradient_op (GskGpuFrame *frame,
gsize n_stops)
{
GskGpuRadialgradientInstance *instance;
GdkColorState *color_state = gsk_gpu_color_states_get_alt (color_states);
g_assert (n_stops > 1);
g_assert (n_stops <= 7);
g_assert (gsk_gpu_color_states_is_alt_premultiplied (color_states));
gsk_gpu_shader_op_alloc (frame,
&GSK_GPU_RADIAL_GRADIENT_OP_CLASS,
DEFAULT_COLOR_STATES,
color_states,
(repeating ? VARIATION_REPEATING : 0) |
(gsk_gpu_frame_should_optimize (frame, GSK_GPU_OPTIMIZE_GRADIENTS) ? VARIATION_SUPERSAMPLING : 0),
clip,
@ -83,18 +86,18 @@ gsk_gpu_radial_gradient_op (GskGpuFrame *frame,
gsk_gpu_point_to_float (radius, graphene_point_zero(), &instance->center_radius[2]);
instance->startend[0] = start;
instance->startend[1] = end;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 6)].color, instance->color6);
gdk_color_state_from_rgba (color_state, &stops[MIN (n_stops - 1, 6)].color, instance->color6);
instance->offsets1[2] = stops[MIN (n_stops - 1, 6)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 5)].color, instance->color5);
gdk_color_state_from_rgba (color_state, &stops[MIN (n_stops - 1, 5)].color, instance->color5);
instance->offsets1[1] = stops[MIN (n_stops - 1, 5)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 4)].color, instance->color4);
gdk_color_state_from_rgba (color_state, &stops[MIN (n_stops - 1, 4)].color, instance->color4);
instance->offsets1[0] = stops[MIN (n_stops - 1, 4)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 3)].color, instance->color3);
gdk_color_state_from_rgba (color_state, &stops[MIN (n_stops - 1, 3)].color, instance->color3);
instance->offsets0[3] = stops[MIN (n_stops - 1, 3)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 2)].color, instance->color2);
gdk_color_state_from_rgba (color_state, &stops[MIN (n_stops - 1, 2)].color, instance->color2);
instance->offsets0[2] = stops[MIN (n_stops - 1, 2)].offset;
gsk_gpu_rgba_to_float (&stops[1].color, instance->color1);
gdk_color_state_from_rgba (color_state, &stops[1].color, instance->color1);
instance->offsets0[1] = stops[1].offset;
gsk_gpu_rgba_to_float (&stops[0].color, instance->color0);
gdk_color_state_from_rgba (color_state, &stops[0].color, instance->color0);
instance->offsets0[0] = stops[0].offset;
}

View File

@ -10,6 +10,7 @@ G_BEGIN_DECLS
void gsk_gpu_radial_gradient_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
GskGpuColorStates color_states,
gboolean repeating,
const graphene_rect_t *rect,
const graphene_point_t *center,

View File

@ -46,13 +46,13 @@ run (out vec2 pos)
_center_radius = in_center_radius;
_startend = in_startend;
_color0 = in_color0;
_color1 = in_color1;
_color2 = in_color2;
_color3 = in_color3;
_color4 = in_color4;
_color5 = in_color5;
_color6 = in_color6;
_color0 = color_premultiply (in_color0);
_color1 = color_premultiply (in_color1);
_color2 = color_premultiply (in_color2);
_color3 = color_premultiply (in_color3);
_color4 = color_premultiply (in_color4);
_color5 = color_premultiply (in_color5);
_color6 = color_premultiply (in_color6);
_offsets0 = in_offsets0;
_offsets1 = in_offsets1;
}
@ -115,7 +115,7 @@ get_gradient_color_at (vec2 pos)
else
offset = clamp (offset, 0.0, 1.0);
return color_premultiply (get_gradient_color (offset));
return output_color_from_alt (get_gradient_color (offset));
}
void
@ -128,14 +128,15 @@ run (out vec4 color,
if (VARIATION_SUPERSAMPLING)
{
vec2 dpos = 0.25 * fwidth (pos);
color = alpha * 0.25 * (get_gradient_color_at (pos + vec2(- dpos.x, - dpos.y)) +
get_gradient_color_at (pos + vec2(- dpos.x, dpos.y)) +
get_gradient_color_at (pos + vec2( dpos.x, - dpos.y)) +
get_gradient_color_at (pos + vec2( dpos.x, dpos.y)));
color = output_color_alpha (get_gradient_color_at (pos + vec2(- dpos.x, - dpos.y)) +
get_gradient_color_at (pos + vec2(- dpos.x, dpos.y)) +
get_gradient_color_at (pos + vec2( dpos.x, - dpos.y)) +
get_gradient_color_at (pos + vec2( dpos.x, dpos.y)),
0.25 * alpha);
}
else
{
color = alpha * get_gradient_color_at (pos);
color = output_color_alpha (get_gradient_color_at (pos), alpha);;
}
position = _pos;