gpu: Make conic gradient op obey ccs

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

View File

@ -51,6 +51,7 @@ static const GskGpuShaderOpClass GSK_GPU_CONIC_GRADIENT_OP_CLASS = {
void
gsk_gpu_conic_gradient_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
GskGpuColorStates color_states,
const graphene_rect_t *rect,
const graphene_point_t *center,
float angle,
@ -59,13 +60,15 @@ gsk_gpu_conic_gradient_op (GskGpuFrame *frame,
gsize n_stops)
{
GskGpuConicgradientInstance *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_CONIC_GRADIENT_OP_CLASS,
DEFAULT_COLOR_STATES,
color_states,
(gsk_gpu_frame_should_optimize (frame, GSK_GPU_OPTIMIZE_GRADIENTS) ? VARIATION_SUPERSAMPLING : 0),
clip,
NULL,
@ -74,18 +77,18 @@ gsk_gpu_conic_gradient_op (GskGpuFrame *frame,
gsk_gpu_rect_to_float (rect, offset, instance->rect);
gsk_gpu_point_to_float (center, offset, instance->center);
instance->angle = angle;
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_conic_gradient_op (GskGpuFrame *frame,
GskGpuShaderClip clip,
GskGpuColorStates color_states,
const graphene_rect_t *rect,
const graphene_point_t *center,
float angle,

View File

@ -2209,6 +2209,7 @@ gsk_gpu_node_processor_conic_gradient_op (GskGpuNodeProcessor *self,
{
gsk_gpu_conic_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),
&node->bounds,
gsk_conic_gradient_node_get_center (node),
gsk_conic_gradient_node_get_angle (node),

View File

@ -45,13 +45,13 @@ run (out vec2 pos)
_center = in_center;
_angle = in_angle;
_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;
}
@ -110,7 +110,7 @@ get_gradient_color_at (vec2 pos)
float offset = atan (pos.y, pos.x);
offset = degrees (offset + _angle) / 360.0;
offset = fract (offset);
return color_premultiply (get_gradient_color (offset));
return output_color_from_alt (get_gradient_color (offset));
}
void
@ -123,14 +123,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;
}