mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-08 17:50:10 +00:00
gpu: Make linear gradient op obey ccs
The alternative color state is used as the interpolation color state. Colors are transformed into that space on the CPU. For now we set the interpolation color state to SRGB, because ultimately we want to let callers specify it, so having something that's easy to map to that behavior is desirable. Otherwise we might have chosen to interpolate in the compositing colorstate. It also means that we need to premultiply colors on the CPU now because of the limitations of the shader colorstates APIs.
This commit is contained in:
parent
ec3cb0ad9a
commit
ebb7fdb099
@ -54,6 +54,7 @@ static const GskGpuShaderOpClass GSK_GPU_LINEAR_GRADIENT_OP_CLASS = {
|
||||
void
|
||||
gsk_gpu_linear_gradient_op (GskGpuFrame *frame,
|
||||
GskGpuShaderClip clip,
|
||||
GskGpuColorStates color_states,
|
||||
gboolean repeating,
|
||||
const graphene_rect_t *rect,
|
||||
const graphene_point_t *start,
|
||||
@ -63,13 +64,15 @@ gsk_gpu_linear_gradient_op (GskGpuFrame *frame,
|
||||
gsize n_stops)
|
||||
{
|
||||
GskGpuLineargradientInstance *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_LINEAR_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,
|
||||
@ -79,18 +82,18 @@ gsk_gpu_linear_gradient_op (GskGpuFrame *frame,
|
||||
gsk_gpu_rect_to_float (rect, offset, instance->rect);
|
||||
gsk_gpu_point_to_float (start, offset, instance->startend);
|
||||
gsk_gpu_point_to_float (end, offset, &instance->startend[2]);
|
||||
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;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ G_BEGIN_DECLS
|
||||
|
||||
void gsk_gpu_linear_gradient_op (GskGpuFrame *frame,
|
||||
GskGpuShaderClip clip,
|
||||
GskGpuColorStates color_states,
|
||||
gboolean repeating,
|
||||
const graphene_rect_t *rect,
|
||||
const graphene_point_t *start,
|
||||
|
@ -2151,6 +2151,7 @@ gsk_gpu_node_processor_linear_gradient_op (GskGpuNodeProcessor *self,
|
||||
{
|
||||
gsk_gpu_linear_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_LINEAR_GRADIENT_NODE,
|
||||
&node->bounds,
|
||||
gsk_linear_gradient_node_get_start (node),
|
||||
|
@ -46,13 +46,13 @@ run (out vec2 pos)
|
||||
|
||||
_pos = pos;
|
||||
_rect = r;
|
||||
_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;
|
||||
}
|
||||
@ -113,7 +113,7 @@ get_gradient_color_at (float offset)
|
||||
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
|
||||
@ -126,14 +126,15 @@ run (out vec4 color,
|
||||
{
|
||||
float dx = 0.25 * dFdx (_offset);
|
||||
float dy = 0.25 * dFdy (_offset);
|
||||
color = alpha * 0.25 * (get_gradient_color_at (_offset - dx - dy) +
|
||||
get_gradient_color_at (_offset - dx + dy) +
|
||||
get_gradient_color_at (_offset + dx - dy) +
|
||||
get_gradient_color_at (_offset + dx + dy));
|
||||
color = output_color_alpha (get_gradient_color_at (_offset - dx - dy) +
|
||||
get_gradient_color_at (_offset - dx + dy) +
|
||||
get_gradient_color_at (_offset + dx - dy) +
|
||||
get_gradient_color_at (_offset + dx + dy),
|
||||
alpha * 0.25);
|
||||
}
|
||||
else
|
||||
{
|
||||
color = alpha * get_gradient_color_at (_offset);
|
||||
color = output_color_alpha (get_gradient_color_at (_offset), alpha);
|
||||
}
|
||||
|
||||
position = _pos;
|
||||
|
Loading…
Reference in New Issue
Block a user