mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-12 05:20:17 +00:00
gpu: Handle >7 color stops
If there are more than 7 color stops, we can split the gradient into multiple gradients with color stops like so: 0, 1, 2, 3, 4, 5, transparent transparent, 6, 7, 8, 9, 10, transparent ... transparent, n-2, n-1, n and use the new BLEND_ADD to draw them on top of each other. Adapt the testcae that tests this to use colors that work with the fancy algorithm we use now, so that BLEND_ADD and transitions to transparent do not cause issues.
This commit is contained in:
parent
8372bc00bd
commit
8361949ba1
@ -26,7 +26,10 @@ gsk_gpu_linear_gradient_op_print (GskGpuOp *op,
|
||||
|
||||
instance = (GskGpuLineargradientInstance *) gsk_gpu_frame_get_vertex_data (frame, shader->vertex_offset);
|
||||
|
||||
gsk_gpu_print_op (string, indent, "linear-gradient");
|
||||
if (instance->repeating)
|
||||
gsk_gpu_print_op (string, indent, "repeating-linear-gradient");
|
||||
else
|
||||
gsk_gpu_print_op (string, indent, "linear-gradient");
|
||||
gsk_gpu_print_rect (string, instance->rect);
|
||||
gsk_gpu_print_newline (string);
|
||||
}
|
||||
@ -53,6 +56,7 @@ static const GskGpuShaderOpClass GSK_GPU_LINEAR_GRADIENT_OP_CLASS = {
|
||||
void
|
||||
gsk_gpu_linear_gradient_op (GskGpuFrame *frame,
|
||||
GskGpuShaderClip clip,
|
||||
gboolean repeating,
|
||||
const graphene_rect_t *rect,
|
||||
const graphene_point_t *start,
|
||||
const graphene_point_t *end,
|
||||
@ -88,4 +92,5 @@ gsk_gpu_linear_gradient_op (GskGpuFrame *frame,
|
||||
instance->offsets0[1] = stops[1].offset;
|
||||
gsk_gpu_rgba_to_float (&stops[0].color, instance->color0);
|
||||
instance->offsets0[0] = stops[0].offset;
|
||||
instance->repeating = repeating;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ G_BEGIN_DECLS
|
||||
|
||||
void gsk_gpu_linear_gradient_op (GskGpuFrame *frame,
|
||||
GskGpuShaderClip clip,
|
||||
gboolean repeating,
|
||||
const graphene_rect_t *rect,
|
||||
const graphene_point_t *start,
|
||||
const graphene_point_t *end,
|
||||
|
@ -1992,28 +1992,35 @@ gsk_gpu_node_processor_add_linear_gradient_node (GskGpuNodeProcessor *self,
|
||||
{
|
||||
const graphene_point_t *start, *end;
|
||||
const GskColorStop *stops;
|
||||
gsize i, n_stops;
|
||||
GskColorStop real_stops[7];
|
||||
GskGpuNodeProcessor other;
|
||||
graphene_rect_t bounds;
|
||||
gsize i, j, n_stops;
|
||||
GskGpuImage *image;
|
||||
int width, height;
|
||||
guint32 descriptor;
|
||||
gboolean repeating;
|
||||
|
||||
start = gsk_linear_gradient_node_get_start (node);
|
||||
end = gsk_linear_gradient_node_get_end (node);
|
||||
stops = gsk_linear_gradient_node_get_color_stops (node, &n_stops);
|
||||
repeating = gsk_render_node_get_node_type (node) == GSK_REPEATING_LINEAR_GRADIENT_NODE;
|
||||
|
||||
if (n_stops < 8)
|
||||
{
|
||||
GskColorStop opacity_stops[7];
|
||||
|
||||
if (self->opacity < 1.0)
|
||||
{
|
||||
for (i = 0; i < n_stops; i++)
|
||||
{
|
||||
opacity_stops[i].offset = stops[i].offset;
|
||||
opacity_stops[i].color = GDK_RGBA_INIT_ALPHA (&stops[i].color, self->opacity);
|
||||
real_stops[i].offset = stops[i].offset;
|
||||
real_stops[i].color = GDK_RGBA_INIT_ALPHA (&stops[i].color, self->opacity);
|
||||
}
|
||||
stops = opacity_stops;
|
||||
stops = real_stops;
|
||||
}
|
||||
|
||||
gsk_gpu_linear_gradient_op (self->frame,
|
||||
gsk_gpu_clip_get_shader_clip (&self->clip, &self->offset, &node->bounds),
|
||||
repeating,
|
||||
&node->bounds,
|
||||
start,
|
||||
end,
|
||||
@ -2026,7 +2033,94 @@ gsk_gpu_node_processor_add_linear_gradient_node (GskGpuNodeProcessor *self,
|
||||
if (gsk_gpu_node_processor_try_node_as_pattern (self, node))
|
||||
return;
|
||||
|
||||
gsk_gpu_node_processor_add_fallback_node (self, node);
|
||||
if (!gsk_gpu_node_processor_clip_node_bounds (self, node, &bounds))
|
||||
return;
|
||||
rect_round_to_pixels (&bounds, &self->scale, &bounds);
|
||||
|
||||
width = ceil (graphene_vec2_get_x (&self->scale) * bounds.size.width);
|
||||
height = ceil (graphene_vec2_get_y (&self->scale) * bounds.size.height);
|
||||
|
||||
image = gsk_gpu_device_create_offscreen_image (gsk_gpu_frame_get_device (self->frame),
|
||||
FALSE,
|
||||
gsk_render_node_get_preferred_depth (node),
|
||||
width, height);
|
||||
gsk_gpu_node_processor_init (&other,
|
||||
self->frame,
|
||||
NULL,
|
||||
image,
|
||||
&(cairo_rectangle_int_t) { 0, 0, width, height },
|
||||
&bounds);
|
||||
|
||||
gsk_gpu_render_pass_begin_op (other.frame,
|
||||
image,
|
||||
&(cairo_rectangle_int_t) { 0, 0, width, height },
|
||||
GSK_RENDER_PASS_OFFSCREEN);
|
||||
|
||||
other.blend = GSK_GPU_BLEND_ADD;
|
||||
other.pending_globals |= GSK_GPU_GLOBAL_BLEND;
|
||||
gsk_gpu_node_processor_sync_globals (&other, 0);
|
||||
|
||||
for (i = 0; i < n_stops; /* happens inside the loop */)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
real_stops[0].offset = stops[i].offset;
|
||||
real_stops[0].color = GDK_RGBA_INIT_ALPHA (&stops[i].color, self->opacity);
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
real_stops[0].offset = stops[i-1].offset;
|
||||
real_stops[0].color = GDK_RGBA_INIT_ALPHA (&stops[i-1].color, 0);
|
||||
}
|
||||
for (j = 1; j < 6 && i < n_stops; j++)
|
||||
{
|
||||
real_stops[j].offset = stops[i].offset;
|
||||
real_stops[j].color = GDK_RGBA_INIT_ALPHA (&stops[i].color, self->opacity);
|
||||
i++;
|
||||
}
|
||||
if (i == n_stops - 1)
|
||||
{
|
||||
g_assert (j == 6);
|
||||
real_stops[j].offset = stops[i].offset;
|
||||
real_stops[j].color = GDK_RGBA_INIT_ALPHA (&stops[i].color, self->opacity);
|
||||
j++;
|
||||
i++;
|
||||
}
|
||||
else if (i < n_stops)
|
||||
{
|
||||
real_stops[j].offset = stops[i].offset;
|
||||
real_stops[j].color = GDK_RGBA_INIT_ALPHA (&stops[i].color, 0);
|
||||
j++;
|
||||
}
|
||||
gsk_gpu_linear_gradient_op (other.frame,
|
||||
gsk_gpu_clip_get_shader_clip (&self->clip, &other.offset, &node->bounds),
|
||||
repeating,
|
||||
&node->bounds,
|
||||
start,
|
||||
end,
|
||||
&other.offset,
|
||||
real_stops,
|
||||
j);
|
||||
}
|
||||
|
||||
gsk_gpu_render_pass_end_op (other.frame,
|
||||
image,
|
||||
GSK_RENDER_PASS_OFFSCREEN);
|
||||
|
||||
gsk_gpu_node_processor_finish (&other);
|
||||
|
||||
descriptor = gsk_gpu_node_processor_add_image (self, image, GSK_GPU_SAMPLER_DEFAULT);
|
||||
|
||||
gsk_gpu_texture_op (self->frame,
|
||||
gsk_gpu_clip_get_shader_clip (&self->clip, &self->offset, &bounds),
|
||||
self->desc,
|
||||
descriptor,
|
||||
&node->bounds,
|
||||
&self->offset,
|
||||
&bounds);
|
||||
|
||||
g_object_unref (image);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -3042,7 +3136,7 @@ static const struct
|
||||
[GSK_REPEATING_LINEAR_GRADIENT_NODE] = {
|
||||
0,
|
||||
GSK_GPU_HANDLE_OPACITY,
|
||||
gsk_gpu_node_processor_add_node_as_pattern,
|
||||
gsk_gpu_node_processor_add_linear_gradient_node,
|
||||
gsk_gpu_node_processor_create_linear_gradient_pattern,
|
||||
},
|
||||
[GSK_RADIAL_GRADIENT_NODE] = {
|
||||
|
@ -12,6 +12,7 @@ PASS_FLAT(8) vec4 _color6;
|
||||
PASS_FLAT(9) vec4 _offsets0;
|
||||
PASS_FLAT(10) vec3 _offsets1;
|
||||
PASS(11) float _offset;
|
||||
PASS_FLAT(12) uint _repeating;
|
||||
|
||||
|
||||
#ifdef GSK_VERTEX_SHADER
|
||||
@ -27,6 +28,7 @@ IN(7) vec4 in_color5;
|
||||
IN(8) vec4 in_color6;
|
||||
IN(9) vec4 in_offsets0;
|
||||
IN(10) vec3 in_offsets1;
|
||||
IN(11) uint in_repeating;
|
||||
|
||||
void
|
||||
run (out vec2 pos)
|
||||
@ -52,6 +54,7 @@ run (out vec2 pos)
|
||||
_color6 = in_color6;
|
||||
_offsets0 = in_offsets0;
|
||||
_offsets1 = in_offsets1;
|
||||
_repeating = in_repeating;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -107,7 +110,11 @@ run (out vec4 color,
|
||||
out vec2 position)
|
||||
{
|
||||
float alpha = rect_coverage (_rect, _pos);
|
||||
float offset = clamp (_offset, 0.0, 1.0);
|
||||
float offset;
|
||||
if (_repeating != 0u)
|
||||
offset = fract (_offset);
|
||||
else
|
||||
offset = clamp (_offset, 0.0, 1.0);
|
||||
|
||||
color = alpha * color_premultiply (get_gradient_color (offset));
|
||||
position = _pos;
|
||||
|
@ -1,6 +1,6 @@
|
||||
linear-gradient {
|
||||
bounds: 0 0 320 50;
|
||||
bounds: 0 0 256 32;
|
||||
start: 0 0;
|
||||
end: 320 0;
|
||||
stops: 0 rgb(255,0,0), 0.015625 rgb(255,0,0), 0.015625 rgb(178,0,255), 0.03125 rgb(178,0,255), 0.03125 rgb(0,153,255), 0.046875 rgb(0,153,255), 0.046875 rgb(0,255,25), 0.0625 rgb(0,255,25), 0.0625 rgb(255,204,0), 0.078125 rgb(255,204,0), 0.078125 rgb(255,0,127), 0.09375 rgb(255,0,127), 0.09375 rgb(51,0,255), 0.109375 rgb(51,0,255), 0.109375 rgb(0,255,229), 0.125 rgb(0,255,229), 0.125 rgb(102,255,0), 0.140625 rgb(102,255,0), 0.140625 rgb(255,76,0), 0.15625 rgb(255,76,0), 0.15625 rgb(255,0,255), 0.171875 rgb(255,0,255), 0.171875 rgb(0,76,255), 0.1875 rgb(0,76,255), 0.1875 rgb(0,255,102), 0.203125 rgb(0,255,102), 0.203125 rgb(229,255,0), 0.21875 rgb(229,255,0), 0.21875 rgb(255,0,51), 0.234375 rgb(255,0,51), 0.234375 rgb(127,0,255), 0.25 rgb(127,0,255), 0.25 rgb(0,204,255), 0.265625 rgb(0,204,255), 0.265625 rgb(25,255,0), 0.28125 rgb(25,255,0), 0.28125 rgb(255,153,0), 0.296875 rgb(255,153,0), 0.296875 rgb(255,0,178), 0.3125 rgb(255,0,178), 0.3125 rgb(0,0,255), 0.328125 rgb(0,0,255), 0.328125 rgb(0,255,178), 0.34375 rgb(0,255,178), 0.34375 rgb(153,255,0), 0.359375 rgb(153,255,0), 0.359375 rgb(255,25,0), 0.375 rgb(255,25,0), 0.375 rgb(204,0,255), 0.390625 rgb(204,0,255), 0.390625 rgb(0,127,255), 0.40625 rgb(0,127,255), 0.40625 rgb(0,255,51), 0.421875 rgb(0,255,51), 0.421875 rgb(255,229,0), 0.4375 rgb(255,229,0), 0.4375 rgb(255,0,102), 0.453125 rgb(255,0,102), 0.453125 rgb(76,0,255), 0.46875 rgb(76,0,255), 0.46875 rgb(0,255,255), 0.484375 rgb(0,255,255), 0.484375 rgb(76,255,0), 0.5 rgb(76,255,0), 0.5 rgb(255,102,0), 0.515625 rgb(255,102,0), 0.515625 rgb(255,0,229), 0.53125 rgb(255,0,229), 0.53125 rgb(0,51,255), 0.546875 rgb(0,51,255), 0.546875 rgb(0,255,127), 0.5625 rgb(0,255,127), 0.5625 rgb(204,255,0), 0.578125 rgb(204,255,0), 0.578125 rgb(255,0,25), 0.59375 rgb(255,0,25), 0.59375 rgb(153,0,255), 0.609375 rgb(153,0,255), 0.609375 rgb(0,178,255), 0.625 rgb(0,178,255), 0.625 rgb(0,255,0), 0.640625 rgb(0,255,0), 0.640625 rgb(255,178,0), 0.65625 rgb(255,178,0), 0.65625 rgb(255,0,153), 0.671875 rgb(255,0,153), 0.671875 rgb(25,0,255), 0.6875 rgb(25,0,255), 0.6875 rgb(0,255,204), 0.703125 rgb(0,255,204), 0.703125 rgb(127,255,0), 0.71875 rgb(127,255,0), 0.71875 rgb(255,51,0), 0.734375 rgb(255,51,0), 0.734375 rgb(229,0,255), 0.75 rgb(229,0,255), 0.75 rgb(0,102,255), 0.765625 rgb(0,102,255), 0.765625 rgb(0,255,76), 0.78125 rgb(0,255,76), 0.78125 rgb(255,255,0), 0.796875 rgb(255,255,0), 0.796875 rgb(255,0,76), 0.8125 rgb(255,0,76), 0.8125 rgb(102,0,255), 0.828125 rgb(102,0,255), 0.828125 rgb(0,229,255), 0.84375 rgb(0,229,255), 0.84375 rgb(51,255,0), 0.859375 rgb(51,255,0), 0.859375 rgb(255,127,0), 0.875 rgb(255,127,0), 0.875 rgb(255,0,204), 0.890625 rgb(255,0,204), 0.890625 rgb(0,25,255), 0.90625 rgb(0,25,255), 0.90625 rgb(0,255,153), 0.921875 rgb(0,255,153), 0.921875 rgb(178,255,0), 0.9375 rgb(178,255,0), 0.9375 rgb(255,0,0), 0.953125 rgb(255,0,0), 0.953125 rgb(178,0,255), 0.96875 rgb(178,0,255), 0.96875 rgb(0,153,255), 0.984375 rgb(0,153,255), 0.984375 rgb(0,255,25), 1 rgb(0,255,25);
|
||||
end: 256 0;
|
||||
stops: 0 rgba(240,240,30,0.666667), 0.015625 rgba(240,240,30,0.666667), 0.015625 rgba(240,0,120,0.333333), 0.03125 rgba(240,0,120,0.333333), 0.03125 rgba(240,240,180,0.666667), 0.046875 rgba(240,240,180,0.666667), 0.046875 rgba(0,60,240,0.333333), 0.0625 rgba(0,60,240,0.333333), 0.0625 rgb(240,240,120), 0.078125 rgb(240,240,120), 0.078125 rgba(240,0,210,0.333333), 0.09375 rgba(240,0,210,0.333333), 0.09375 rgba(90,240,0,0.333333), 0.109375 rgba(90,240,0,0.333333), 0.109375 rgba(0,240,210,0.333333), 0.125 rgba(0,240,210,0.333333), 0.125 rgba(0,210,240,0.333333), 0.140625 rgba(0,210,240,0.333333), 0.140625 rgba(0,240,0,0.666667), 0.15625 rgba(0,240,0,0.666667), 0.15625 rgb(210,0,240), 0.171875 rgb(210,0,240), 0.171875 rgb(0,150,240), 0.1875 rgb(0,150,240), 0.1875 rgba(240,240,0,0.666667), 0.203125 rgba(240,240,0,0.666667), 0.203125 rgba(210,240,240,0.666667), 0.21875 rgba(210,240,240,0.666667), 0.21875 rgb(240,0,120), 0.234375 rgb(240,0,120), 0.234375 rgba(240,0,30,0.333333), 0.25 rgba(240,0,30,0.333333), 0.25 rgba(240,0,120,0.333333), 0.265625 rgba(240,0,120,0.333333), 0.265625 rgba(240,210,0,0.666667), 0.28125 rgba(240,210,0,0.666667), 0.28125 rgba(240,120,240,0.333333), 0.296875 rgba(240,120,240,0.333333), 0.296875 rgba(240,240,0,0.333333), 0.3125 rgba(240,240,0,0.333333), 0.3125 rgb(240,0,0), 0.328125 rgb(240,0,0), 0.328125 rgb(240,0,240), 0.34375 rgb(240,0,240), 0.34375 rgba(210,240,0,0.666667), 0.359375 rgba(210,240,0,0.666667), 0.359375 rgba(0,30,240,0.333333), 0.375 rgba(0,30,240,0.333333), 0.375 rgba(0,240,180,0.333333), 0.390625 rgba(0,240,180,0.333333), 0.390625 rgba(240,240,120,0.666667), 0.40625 rgba(240,240,120,0.666667), 0.40625 rgb(240,30,0), 0.421875 rgb(240,30,0), 0.421875 rgb(240,240,90), 0.4375 rgb(240,240,90), 0.4375 rgb(30,240,0), 0.453125 rgb(30,240,0), 0.453125 rgba(240,210,0,0.333333), 0.46875 rgba(240,210,0,0.333333), 0.46875 rgba(240,0,0,0.666667), 0.484375 rgba(240,0,0,0.666667), 0.484375 rgba(0,150,240,0.666667), 0.5 rgba(0,150,240,0.666667), 0.5 rgb(30,0,240), 0.515625 rgb(30,0,240), 0.515625 rgba(0,120,240,0.666667), 0.53125 rgba(0,120,240,0.666667), 0.53125 rgba(240,30,0,0.333333), 0.546875 rgba(240,30,0,0.333333), 0.546875 rgb(240,0,120), 0.5625 rgb(240,0,120), 0.5625 rgb(0,30,240), 0.578125 rgb(0,30,240), 0.578125 rgb(240,0,0), 0.59375 rgb(240,0,0), 0.59375 rgba(240,210,0,0.666667), 0.609375 rgba(240,210,0,0.666667), 0.609375 rgba(240,90,240,0.333333), 0.625 rgba(240,90,240,0.333333), 0.625 rgba(240,240,180,0.666667), 0.640625 rgba(240,240,180,0.666667), 0.640625 rgba(240,0,0,0.666667), 0.65625 rgba(240,0,0,0.666667), 0.65625 rgb(240,0,210), 0.671875 rgb(240,0,210), 0.671875 rgb(180,0,240), 0.6875 rgb(180,0,240), 0.6875 rgba(240,0,60,0.666667), 0.703125 rgba(240,0,60,0.666667), 0.703125 rgb(0,0,240), 0.71875 rgb(0,0,240), 0.71875 rgba(0,240,0,0.333333), 0.734375 rgba(0,240,0,0.333333), 0.734375 rgba(240,0,90,0.666667), 0.75 rgba(240,0,90,0.666667), 0.75 rgba(240,60,0,0.666667), 0.765625 rgba(240,60,0,0.666667), 0.765625 rgba(240,180,240,0.666667), 0.78125 rgba(240,180,240,0.666667), 0.78125 rgb(240,240,120), 0.796875 rgb(240,240,120), 0.796875 rgb(240,0,60), 0.8125 rgb(240,0,60), 0.8125 rgba(180,240,0,0.666667), 0.828125 rgba(180,240,0,0.666667), 0.828125 rgba(240,90,0,0.333333), 0.84375 rgba(240,90,0,0.333333), 0.84375 rgba(0,240,210,0.666667), 0.859375 rgba(0,240,210,0.666667), 0.859375 rgba(30,240,0,0.333333), 0.875 rgba(30,240,0,0.333333), 0.875 rgba(0,150,240,0.333333), 0.890625 rgba(0,150,240,0.333333), 0.890625 rgba(0,210,240,0.333333), 0.90625 rgba(0,210,240,0.333333), 0.90625 rgba(0,240,120,0.666667), 0.921875 rgba(0,240,120,0.666667), 0.921875 rgba(0,90,240,0.333333), 0.9375 rgba(0,90,240,0.333333), 0.9375 rgba(120,240,0,0.666667), 0.953125 rgba(120,240,0,0.666667), 0.953125 rgb(180,240,0), 0.96875 rgb(180,240,0), 0.96875 rgba(120,240,240,0.333333), 0.984375 rgba(120,240,240,0.333333), 0.984375 rgb(240,60,0), 1 rgb(240,60,0);
|
||||
}
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 484 B After Width: | Height: | Size: 426 B |
Loading…
Reference in New Issue
Block a user