gsk: Use new gradient node apis

This requires changing the gradient ops again too,
so we can pass GskColorStop2 arrays to them.
This commit is contained in:
Matthias Clasen
2024-08-09 09:27:34 -04:00
parent 4c7631a645
commit 5d8e801d80
8 changed files with 50 additions and 73 deletions

View File

@@ -60,7 +60,7 @@ gsk_gpu_conic_gradient_op (GskGpuFrame *frame,
const graphene_rect_t *rect, const graphene_rect_t *rect,
const graphene_point_t *center, const graphene_point_t *center,
float angle, float angle,
const GskColorStop *stops, const GskColorStop2 *stops,
gsize n_stops) gsize n_stops)
{ {
GskGpuConicgradientInstance *instance; GskGpuConicgradientInstance *instance;
@@ -83,18 +83,18 @@ gsk_gpu_conic_gradient_op (GskGpuFrame *frame,
gsk_gpu_rect_to_float (rect, offset, instance->rect); gsk_gpu_rect_to_float (rect, offset, instance->rect);
gsk_gpu_point_to_float (center, offset, instance->center); gsk_gpu_point_to_float (center, offset, instance->center);
instance->angle = angle; instance->angle = angle;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 6)].color, ics, opacity, instance->color6); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 6)].color, ics, opacity, instance->color6);
instance->offsets1[2] = stops[MIN (n_stops - 1, 6)].offset; instance->offsets1[2] = stops[MIN (n_stops - 1, 6)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 5)].color, ics, opacity, instance->color5); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 5)].color, ics, opacity, instance->color5);
instance->offsets1[1] = stops[MIN (n_stops - 1, 5)].offset; instance->offsets1[1] = stops[MIN (n_stops - 1, 5)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 4)].color, ics, opacity, instance->color4); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 4)].color, ics, opacity, instance->color4);
instance->offsets1[0] = stops[MIN (n_stops - 1, 4)].offset; instance->offsets1[0] = stops[MIN (n_stops - 1, 4)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 3)].color, ics, opacity, instance->color3); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 3)].color, ics, opacity, instance->color3);
instance->offsets0[3] = stops[MIN (n_stops - 1, 3)].offset; instance->offsets0[3] = stops[MIN (n_stops - 1, 3)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 2)].color, ics, opacity, instance->color2); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 2)].color, ics, opacity, instance->color2);
instance->offsets0[2] = stops[MIN (n_stops - 1, 2)].offset; instance->offsets0[2] = stops[MIN (n_stops - 1, 2)].offset;
gsk_gpu_rgba_to_float (&stops[1].color, ics, opacity, instance->color1); gsk_gpu_color_to_float (&stops[1].color, ics, opacity, instance->color1);
instance->offsets0[1] = stops[1].offset; instance->offsets0[1] = stops[1].offset;
gsk_gpu_rgba_to_float (&stops[0].color, ics, opacity, instance->color0); gsk_gpu_color_to_float (&stops[0].color, ics, opacity, instance->color0);
instance->offsets0[0] = stops[0].offset; instance->offsets0[0] = stops[0].offset;
} }

View File

@@ -18,7 +18,7 @@ void gsk_gpu_conic_gradient_op (GskGpuF
const graphene_rect_t *rect, const graphene_rect_t *rect,
const graphene_point_t *center, const graphene_point_t *center,
float angle, float angle,
const GskColorStop *stops, const GskColorStop2 *stops,
gsize n_stops); gsize n_stops);

View File

@@ -64,7 +64,7 @@ gsk_gpu_linear_gradient_op (GskGpuFrame *frame,
const graphene_rect_t *rect, const graphene_rect_t *rect,
const graphene_point_t *start, const graphene_point_t *start,
const graphene_point_t *end, const graphene_point_t *end,
const GskColorStop *stops, const GskColorStop2 *stops,
gsize n_stops) gsize n_stops)
{ {
GskGpuLineargradientInstance *instance; GskGpuLineargradientInstance *instance;
@@ -88,18 +88,18 @@ gsk_gpu_linear_gradient_op (GskGpuFrame *frame,
gsk_gpu_rect_to_float (rect, offset, instance->rect); gsk_gpu_rect_to_float (rect, offset, instance->rect);
gsk_gpu_point_to_float (start, offset, instance->startend); gsk_gpu_point_to_float (start, offset, instance->startend);
gsk_gpu_point_to_float (end, offset, &instance->startend[2]); gsk_gpu_point_to_float (end, offset, &instance->startend[2]);
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 6)].color, ics, opacity, instance->color6); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 6)].color, ics, opacity, instance->color6);
instance->offsets1[2] = stops[MIN (n_stops - 1, 6)].offset; instance->offsets1[2] = stops[MIN (n_stops - 1, 6)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 5)].color, ics, opacity, instance->color5); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 5)].color, ics, opacity, instance->color5);
instance->offsets1[1] = stops[MIN (n_stops - 1, 5)].offset; instance->offsets1[1] = stops[MIN (n_stops - 1, 5)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 4)].color, ics, opacity, instance->color4); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 4)].color, ics, opacity, instance->color4);
instance->offsets1[0] = stops[MIN (n_stops - 1, 4)].offset; instance->offsets1[0] = stops[MIN (n_stops - 1, 4)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 3)].color, ics, opacity, instance->color3); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 3)].color, ics, opacity, instance->color3);
instance->offsets0[3] = stops[MIN (n_stops - 1, 3)].offset; instance->offsets0[3] = stops[MIN (n_stops - 1, 3)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 2)].color, ics, opacity, instance->color2); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 2)].color, ics, opacity, instance->color2);
instance->offsets0[2] = stops[MIN (n_stops - 1, 2)].offset; instance->offsets0[2] = stops[MIN (n_stops - 1, 2)].offset;
gsk_gpu_rgba_to_float (&stops[1].color, ics, opacity, instance->color1); gsk_gpu_color_to_float (&stops[1].color, ics, opacity, instance->color1);
instance->offsets0[1] = stops[1].offset; instance->offsets0[1] = stops[1].offset;
gsk_gpu_rgba_to_float (&stops[0].color, ics, opacity, instance->color0); gsk_gpu_color_to_float (&stops[0].color, ics, opacity, instance->color0);
instance->offsets0[0] = stops[0].offset; instance->offsets0[0] = stops[0].offset;
} }

View File

@@ -19,7 +19,7 @@ void gsk_gpu_linear_gradient_op (GskGpuF
const graphene_rect_t *rect, const graphene_rect_t *rect,
const graphene_point_t *start, const graphene_point_t *start,
const graphene_point_t *end, const graphene_point_t *end,
const GskColorStop *stops, const GskColorStop2 *stops,
gsize n_stops); gsize n_stops);

View File

@@ -2465,17 +2465,17 @@ gsk_gpu_node_processor_add_outset_shadow_node (GskGpuNodeProcessor *self,
typedef void (* GradientOpFunc) (GskGpuNodeProcessor *self, typedef void (* GradientOpFunc) (GskGpuNodeProcessor *self,
GskRenderNode *node, GskRenderNode *node,
const GskColorStop *stops, const GskColorStop2 *stops,
gsize n_stops); gsize n_stops);
static void static void
gsk_gpu_node_processor_add_gradient_node (GskGpuNodeProcessor *self, gsk_gpu_node_processor_add_gradient_node (GskGpuNodeProcessor *self,
GskRenderNode *node, GskRenderNode *node,
const GskColorStop *stops, const GskColorStop2 *stops,
gsize n_stops, gsize n_stops,
GradientOpFunc func) GradientOpFunc func)
{ {
GskColorStop real_stops[7]; GskColorStop2 real_stops[7];
GskGpuNodeProcessor other; GskGpuNodeProcessor other;
graphene_rect_t bounds; graphene_rect_t bounds;
gsize i, j; gsize i, j;
@@ -2483,18 +2483,7 @@ gsk_gpu_node_processor_add_gradient_node (GskGpuNodeProcessor *self,
if (n_stops < 8) if (n_stops < 8)
{ {
if (self->opacity < 1.0)
{
for (i = 0; i < n_stops; i++)
{
real_stops[i].offset = stops[i].offset;
real_stops[i].color = stops[i].color;
}
stops = real_stops;
}
func (self, node, stops, n_stops); func (self, node, stops, n_stops);
return; return;
} }
@@ -2513,38 +2502,40 @@ gsk_gpu_node_processor_add_gradient_node (GskGpuNodeProcessor *self,
other.blend = GSK_GPU_BLEND_ADD; other.blend = GSK_GPU_BLEND_ADD;
other.pending_globals |= GSK_GPU_GLOBAL_BLEND; other.pending_globals |= GSK_GPU_GLOBAL_BLEND;
gsk_gpu_node_processor_sync_globals (&other, 0); gsk_gpu_node_processor_sync_globals (&other, 0);
for (i = 0; i < n_stops; /* happens inside the loop */) for (i = 0; i < n_stops; /* happens inside the loop */)
{ {
if (i == 0) if (i == 0)
{ {
real_stops[0].offset = stops[i].offset; real_stops[0].offset = stops[i].offset;
real_stops[0].color = stops[i].color; gdk_color_init_copy (&real_stops[i].color, &stops[i].color);
i++; i++;
} }
else else
{ {
real_stops[0].offset = stops[i-1].offset; real_stops[0].offset = stops[i-1].offset;
real_stops[0].color = GDK_RGBA_INIT_ALPHA (&stops[i-1].color, 0); gdk_color_init_copy (&real_stops[0].color, &stops[i - 1].color);
real_stops[0].color.alpha *= 0;
} }
for (j = 1; j < 6 && i < n_stops; j++) for (j = 1; j < 6 && i < n_stops; j++)
{ {
real_stops[j].offset = stops[i].offset; real_stops[j].offset = stops[i].offset;
real_stops[j].color = stops[i].color; gdk_color_init_copy (&real_stops[j].color, &stops[i].color);
i++; i++;
} }
if (i == n_stops - 1) if (i == n_stops - 1)
{ {
g_assert (j == 6); g_assert (j == 6);
real_stops[j].offset = stops[i].offset; real_stops[j].offset = stops[i].offset;
real_stops[j].color = stops[i].color; gdk_color_init_copy (&real_stops[j].color, &stops[i].color);
j++; j++;
i++; i++;
} }
else if (i < n_stops) else if (i < n_stops)
{ {
real_stops[j].offset = stops[i].offset; real_stops[j].offset = stops[i].offset;
real_stops[j].color = GDK_RGBA_INIT_ALPHA (&stops[i].color, 0); gdk_color_init_copy (&real_stops[j].color, &stops[i].color);
real_stops[j].color.alpha *= 0;
j++; j++;
} }
@@ -2569,7 +2560,7 @@ gsk_gpu_node_processor_add_gradient_node (GskGpuNodeProcessor *self,
static void static void
gsk_gpu_node_processor_linear_gradient_op (GskGpuNodeProcessor *self, gsk_gpu_node_processor_linear_gradient_op (GskGpuNodeProcessor *self,
GskRenderNode *node, GskRenderNode *node,
const GskColorStop *stops, const GskColorStop2 *stops,
gsize n_stops) gsize n_stops)
{ {
gsk_gpu_linear_gradient_op (self->frame, gsk_gpu_linear_gradient_op (self->frame,
@@ -2577,8 +2568,8 @@ gsk_gpu_node_processor_linear_gradient_op (GskGpuNodeProcessor *self,
self->ccs, self->ccs,
self->opacity, self->opacity,
&self->offset, &self->offset,
GDK_COLOR_STATE_SRGB, gsk_linear_gradient_node_get_interpolation_color_state (node),
GSK_HUE_INTERPOLATION_SHORTER, gsk_linear_gradient_node_get_hue_interpolation (node),
GSK_RENDER_NODE_TYPE (node) == GSK_REPEATING_LINEAR_GRADIENT_NODE, GSK_RENDER_NODE_TYPE (node) == GSK_REPEATING_LINEAR_GRADIENT_NODE,
&node->bounds, &node->bounds,
gsk_linear_gradient_node_get_start (node), gsk_linear_gradient_node_get_start (node),
@@ -2593,7 +2584,7 @@ gsk_gpu_node_processor_add_linear_gradient_node (GskGpuNodeProcessor *self,
{ {
gsk_gpu_node_processor_add_gradient_node (self, gsk_gpu_node_processor_add_gradient_node (self,
node, node,
gsk_linear_gradient_node_get_color_stops (node, NULL), gsk_linear_gradient_node_get_color_stops2 (node),
gsk_linear_gradient_node_get_n_color_stops (node), gsk_linear_gradient_node_get_n_color_stops (node),
gsk_gpu_node_processor_linear_gradient_op); gsk_gpu_node_processor_linear_gradient_op);
} }
@@ -2601,7 +2592,7 @@ gsk_gpu_node_processor_add_linear_gradient_node (GskGpuNodeProcessor *self,
static void static void
gsk_gpu_node_processor_radial_gradient_op (GskGpuNodeProcessor *self, gsk_gpu_node_processor_radial_gradient_op (GskGpuNodeProcessor *self,
GskRenderNode *node, GskRenderNode *node,
const GskColorStop *stops, const GskColorStop2 *stops,
gsize n_stops) gsize n_stops)
{ {
gsk_gpu_radial_gradient_op (self->frame, gsk_gpu_radial_gradient_op (self->frame,
@@ -2609,8 +2600,8 @@ gsk_gpu_node_processor_radial_gradient_op (GskGpuNodeProcessor *self,
self->ccs, self->ccs,
self->opacity, self->opacity,
&self->offset, &self->offset,
GDK_COLOR_STATE_SRGB, gsk_radial_gradient_node_get_interpolation_color_state (node),
GSK_HUE_INTERPOLATION_SHORTER, gsk_radial_gradient_node_get_hue_interpolation (node),
GSK_RENDER_NODE_TYPE (node) == GSK_REPEATING_RADIAL_GRADIENT_NODE, GSK_RENDER_NODE_TYPE (node) == GSK_REPEATING_RADIAL_GRADIENT_NODE,
&node->bounds, &node->bounds,
gsk_radial_gradient_node_get_center (node), gsk_radial_gradient_node_get_center (node),
@@ -2630,7 +2621,7 @@ gsk_gpu_node_processor_add_radial_gradient_node (GskGpuNodeProcessor *self,
{ {
gsk_gpu_node_processor_add_gradient_node (self, gsk_gpu_node_processor_add_gradient_node (self,
node, node,
gsk_radial_gradient_node_get_color_stops (node, NULL), gsk_radial_gradient_node_get_color_stops2 (node),
gsk_radial_gradient_node_get_n_color_stops (node), gsk_radial_gradient_node_get_n_color_stops (node),
gsk_gpu_node_processor_radial_gradient_op); gsk_gpu_node_processor_radial_gradient_op);
} }
@@ -2638,7 +2629,7 @@ gsk_gpu_node_processor_add_radial_gradient_node (GskGpuNodeProcessor *self,
static void static void
gsk_gpu_node_processor_conic_gradient_op (GskGpuNodeProcessor *self, gsk_gpu_node_processor_conic_gradient_op (GskGpuNodeProcessor *self,
GskRenderNode *node, GskRenderNode *node,
const GskColorStop *stops, const GskColorStop2 *stops,
gsize n_stops) gsize n_stops)
{ {
gsk_gpu_conic_gradient_op (self->frame, gsk_gpu_conic_gradient_op (self->frame,
@@ -2646,8 +2637,8 @@ gsk_gpu_node_processor_conic_gradient_op (GskGpuNodeProcessor *self,
self->ccs, self->ccs,
self->opacity, self->opacity,
&self->offset, &self->offset,
GDK_COLOR_STATE_SRGB, gsk_conic_gradient_node_get_interpolation_color_state (node),
GSK_HUE_INTERPOLATION_SHORTER, gsk_conic_gradient_node_get_hue_interpolation (node),
&node->bounds, &node->bounds,
gsk_conic_gradient_node_get_center (node), gsk_conic_gradient_node_get_center (node),
gsk_conic_gradient_node_get_angle (node), gsk_conic_gradient_node_get_angle (node),
@@ -2661,7 +2652,7 @@ gsk_gpu_node_processor_add_conic_gradient_node (GskGpuNodeProcessor *self,
{ {
gsk_gpu_node_processor_add_gradient_node (self, gsk_gpu_node_processor_add_gradient_node (self,
node, node,
gsk_conic_gradient_node_get_color_stops (node, NULL), gsk_conic_gradient_node_get_color_stops2 (node),
gsk_conic_gradient_node_get_n_color_stops (node), gsk_conic_gradient_node_get_n_color_stops (node),
gsk_gpu_node_processor_conic_gradient_op); gsk_gpu_node_processor_conic_gradient_op);
} }

View File

@@ -66,7 +66,7 @@ gsk_gpu_radial_gradient_op (GskGpuFrame *frame,
const graphene_point_t *radius, const graphene_point_t *radius,
float start, float start,
float end, float end,
const GskColorStop *stops, const GskColorStop2 *stops,
gsize n_stops) gsize n_stops)
{ {
GskGpuRadialgradientInstance *instance; GskGpuRadialgradientInstance *instance;
@@ -92,18 +92,18 @@ gsk_gpu_radial_gradient_op (GskGpuFrame *frame,
gsk_gpu_point_to_float (radius, graphene_point_zero(), &instance->center_radius[2]); gsk_gpu_point_to_float (radius, graphene_point_zero(), &instance->center_radius[2]);
instance->startend[0] = start; instance->startend[0] = start;
instance->startend[1] = end; instance->startend[1] = end;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 6)].color, ics, opacity, instance->color6); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 6)].color, ics, opacity, instance->color6);
instance->offsets1[2] = stops[MIN (n_stops - 1, 6)].offset; instance->offsets1[2] = stops[MIN (n_stops - 1, 6)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 5)].color, ics, opacity, instance->color5); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 5)].color, ics, opacity, instance->color5);
instance->offsets1[1] = stops[MIN (n_stops - 1, 5)].offset; instance->offsets1[1] = stops[MIN (n_stops - 1, 5)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 4)].color, ics, opacity, instance->color4); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 4)].color, ics, opacity, instance->color4);
instance->offsets1[0] = stops[MIN (n_stops - 1, 4)].offset; instance->offsets1[0] = stops[MIN (n_stops - 1, 4)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 3)].color, ics, opacity, instance->color3); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 3)].color, ics, opacity, instance->color3);
instance->offsets0[3] = stops[MIN (n_stops - 1, 3)].offset; instance->offsets0[3] = stops[MIN (n_stops - 1, 3)].offset;
gsk_gpu_rgba_to_float (&stops[MIN (n_stops - 1, 2)].color, ics, opacity, instance->color2); gsk_gpu_color_to_float (&stops[MIN (n_stops - 1, 2)].color, ics, opacity, instance->color2);
instance->offsets0[2] = stops[MIN (n_stops - 1, 2)].offset; instance->offsets0[2] = stops[MIN (n_stops - 1, 2)].offset;
gsk_gpu_rgba_to_float (&stops[1].color, ics, opacity, instance->color1); gsk_gpu_color_to_float (&stops[1].color, ics, opacity, instance->color1);
instance->offsets0[1] = stops[1].offset; instance->offsets0[1] = stops[1].offset;
gsk_gpu_rgba_to_float (&stops[0].color, ics, opacity, instance->color0); gsk_gpu_color_to_float (&stops[0].color, ics, opacity, instance->color0);
instance->offsets0[0] = stops[0].offset; instance->offsets0[0] = stops[0].offset;
} }

View File

@@ -21,7 +21,7 @@ void gsk_gpu_radial_gradient_op (GskGpuF
const graphene_point_t *radius, const graphene_point_t *radius,
float start, float start,
float end, float end,
const GskColorStop *stops, const GskColorStop2 *stops,
gsize n_stops); gsize n_stops);

View File

@@ -113,18 +113,4 @@ gsk_gpu_color_to_float (const GdkColor *color,
values[3] *= opacity; values[3] *= opacity;
} }
static inline void
gsk_gpu_rgba_to_float (const GdkRGBA *rgba,
GdkColorState *target,
float opacity,
float values[4])
{
GdkColor color;
gdk_color_init_from_rgba (&color, rgba);
gdk_color_to_float (&color, target, values);
values[3] *= opacity;
gdk_color_finish (&color);
}
G_END_DECLS G_END_DECLS