gsk: Switch box shadow nodes to use offsets

Instead of
  float dx;
  float dy;
have a
  graphene_point_t offset;
in the object and in all APIs relating to them.
This commit is contained in:
Benjamin Otte 2024-08-10 01:04:54 +02:00
parent 2ee16e5dd9
commit d6322c6389
8 changed files with 139 additions and 119 deletions

View File

@ -2293,8 +2293,7 @@ gsk_gpu_node_processor_add_inset_shadow_node (GskGpuNodeProcessor *self,
self->opacity,
&self->offset,
gsk_inset_shadow_node_get_outline (node),
&GRAPHENE_POINT_INIT (gsk_inset_shadow_node_get_dx (node),
gsk_inset_shadow_node_get_dy (node)),
gsk_inset_shadow_node_get_offset (node),
(float[4]) { spread, spread, spread, spread },
colors);
@ -2311,8 +2310,7 @@ gsk_gpu_node_processor_add_inset_shadow_node (GskGpuNodeProcessor *self,
TRUE,
&node->bounds,
gsk_inset_shadow_node_get_outline (node),
&GRAPHENE_POINT_INIT (gsk_inset_shadow_node_get_dx (node),
gsk_inset_shadow_node_get_dy (node)),
gsk_inset_shadow_node_get_offset (node),
spread,
blur_radius,
color);
@ -2323,14 +2321,14 @@ static void
gsk_gpu_node_processor_add_outset_shadow_node (GskGpuNodeProcessor *self,
GskRenderNode *node)
{
float spread, blur_radius, dx, dy;
float spread, blur_radius;
const GdkColor *color;
const graphene_point_t *offset;
color = gsk_outset_shadow_node_get_color2 (node);
spread = gsk_outset_shadow_node_get_spread (node);
blur_radius = gsk_outset_shadow_node_get_blur_radius (node);
dx = gsk_outset_shadow_node_get_dx (node);
dy = gsk_outset_shadow_node_get_dy (node);
offset = gsk_outset_shadow_node_get_offset (node);
if (blur_radius < 0.01)
{
@ -2339,7 +2337,7 @@ gsk_gpu_node_processor_add_outset_shadow_node (GskGpuNodeProcessor *self,
gsk_rounded_rect_init_copy (&outline, gsk_outset_shadow_node_get_outline (node));
gsk_rounded_rect_shrink (&outline, -spread, -spread, -spread, -spread);
graphene_rect_offset (&outline.bounds, dx, dy);
graphene_rect_offset (&outline.bounds, offset->x, offset->y);
for (int i = 0; i < 4; i++)
gdk_color_init_copy (&colors[i], color);
@ -2350,7 +2348,7 @@ gsk_gpu_node_processor_add_outset_shadow_node (GskGpuNodeProcessor *self,
self->opacity,
&self->offset,
&outline,
&GRAPHENE_POINT_INIT (-dx, -dy),
&GRAPHENE_POINT_INIT (- offset->x, - offset->y),
(float[4]) { spread, spread, spread, spread },
colors);
@ -2367,7 +2365,7 @@ gsk_gpu_node_processor_add_outset_shadow_node (GskGpuNodeProcessor *self,
FALSE,
&node->bounds,
gsk_outset_shadow_node_get_outline (node),
&GRAPHENE_POINT_INIT (dx, dy),
offset,
spread,
blur_radius,
color);

View File

@ -2324,8 +2324,7 @@ struct _GskInsetShadowNode
GskRoundedRect outline;
GdkColor color;
float dx;
float dy;
graphene_point_t offset;
float spread;
float blur_radius;
};
@ -2650,7 +2649,7 @@ gsk_inset_shadow_node_draw (GskRenderNode *node,
cairo_clip (cr);
gsk_rounded_rect_init_copy (&box, &self->outline);
gsk_rounded_rect_offset (&box, self->dx, self->dy);
gsk_rounded_rect_offset (&box, self->offset.x, self->offset.y);
gsk_rounded_rect_shrink (&box, self->spread, self->spread, self->spread, self->spread);
gsk_rounded_rect_init_copy (&clip_box, &self->outline);
@ -2732,8 +2731,7 @@ gsk_inset_shadow_node_diff (GskRenderNode *node1,
if (gsk_rounded_rect_equal (&self1->outline, &self2->outline) &&
gdk_color_equal (&self1->color, &self2->color) &&
self1->dx == self2->dx &&
self1->dy == self2->dy &&
graphene_point_equal (&self1->offset, &self2->offset) &&
self1->spread == self2->spread &&
self1->blur_radius == self2->blur_radius)
return;
@ -2782,7 +2780,7 @@ gsk_inset_shadow_node_new (const GskRoundedRect *outline,
gdk_color_init_from_rgba (&color2, color);
node = gsk_inset_shadow_node_new2 (outline,
&color2,
dx, dy,
&GRAPHENE_POINT_INIT (dx, dy),
spread, blur_radius);
gdk_color_finish (&color2);
@ -2793,8 +2791,7 @@ gsk_inset_shadow_node_new (const GskRoundedRect *outline,
* gsk_inset_shadow_node_new2:
* @outline: outline of the region containing the shadow
* @color: color of the shadow
* @dx: horizontal offset of shadow
* @dy: vertical offset of shadow
* @offset: offset of shadow
* @spread: how far the shadow spreads towards the inside
* @blur_radius: how much blur to apply to the shadow
*
@ -2804,18 +2801,18 @@ gsk_inset_shadow_node_new (const GskRoundedRect *outline,
* Returns: (transfer full) (type GskInsetShadowNode): A new `GskRenderNode`
*/
GskRenderNode *
gsk_inset_shadow_node_new2 (const GskRoundedRect *outline,
const GdkColor *color,
float dx,
float dy,
float spread,
float blur_radius)
gsk_inset_shadow_node_new2 (const GskRoundedRect *outline,
const GdkColor *color,
const graphene_point_t *offset,
float spread,
float blur_radius)
{
GskInsetShadowNode *self;
GskRenderNode *node;
g_return_val_if_fail (outline != NULL, NULL);
g_return_val_if_fail (color != NULL, NULL);
g_return_val_if_fail (offset != NULL, NULL);
g_return_val_if_fail (blur_radius >= 0, NULL);
self = gsk_render_node_alloc (GSK_INSET_SHADOW_NODE);
@ -2825,8 +2822,7 @@ gsk_inset_shadow_node_new2 (const GskRoundedRect *outline,
gsk_rounded_rect_init_copy (&self->outline, outline);
gdk_color_init_copy (&self->color, color);
self->dx = dx;
self->dy = dy;
self->offset = *offset;
self->spread = spread;
self->blur_radius = blur_radius;
@ -2900,7 +2896,7 @@ gsk_inset_shadow_node_get_dx (const GskRenderNode *node)
{
const GskInsetShadowNode *self = (const GskInsetShadowNode *) node;
return self->dx;
return self->offset.x;
}
/**
@ -2916,7 +2912,23 @@ gsk_inset_shadow_node_get_dy (const GskRenderNode *node)
{
const GskInsetShadowNode *self = (const GskInsetShadowNode *) node;
return self->dy;
return self->offset.y;
}
/**
* gsk_inset_shadow_node_get_offset:
* @node: (type GskInsetShadowNode): a `GskRenderNode` for an inset shadow
*
* Retrieves the offset of the inset shadow.
*
* Returns: an offset, in pixels
**/
const graphene_point_t *
gsk_inset_shadow_node_get_offset (const GskRenderNode *node)
{
const GskInsetShadowNode *self = (const GskInsetShadowNode *) node;
return &self->offset;
}
/**
@ -2965,8 +2977,7 @@ struct _GskOutsetShadowNode
GskRoundedRect outline;
GdkColor color;
float dx;
float dy;
graphene_point_t offset;
float spread;
float blur_radius;
};
@ -2992,10 +3003,10 @@ gsk_outset_shadow_get_extents (GskOutsetShadowNode *self,
float clip_radius;
clip_radius = gsk_cairo_blur_compute_pixels (ceil (self->blur_radius / 2.0));
*top = MAX (0, ceil (clip_radius + self->spread - self->dy));
*right = MAX (0, ceil (clip_radius + self->spread + self->dx));
*bottom = MAX (0, ceil (clip_radius + self->spread + self->dy));
*left = MAX (0, ceil (clip_radius + self->spread - self->dx));
*top = MAX (0, ceil (clip_radius + self->spread - self->offset.y));
*right = MAX (0, ceil (clip_radius + self->spread + self->offset.x));
*bottom = MAX (0, ceil (clip_radius + self->spread + self->offset.y));
*left = MAX (0, ceil (clip_radius + self->spread - self->offset.x));
}
static void
@ -3035,7 +3046,7 @@ gsk_outset_shadow_node_draw (GskRenderNode *node,
cairo_clip (cr);
gsk_rounded_rect_init_copy (&box, &self->outline);
gsk_rounded_rect_offset (&box, self->dx, self->dy);
gsk_rounded_rect_offset (&box, self->offset.x, self->offset.y);
gsk_rounded_rect_shrink (&box, -self->spread, -self->spread, -self->spread, -self->spread);
if (!needs_blur (blur_radius))
@ -3116,8 +3127,7 @@ gsk_outset_shadow_node_diff (GskRenderNode *node1,
if (gsk_rounded_rect_equal (&self1->outline, &self2->outline) &&
gdk_color_equal (&self1->color, &self2->color) &&
self1->dx == self2->dx &&
self1->dy == self2->dy &&
graphene_point_equal (&self1->offset, &self2->offset) &&
self1->spread == self2->spread &&
self1->blur_radius == self2->blur_radius)
return;
@ -3166,7 +3176,8 @@ gsk_outset_shadow_node_new (const GskRoundedRect *outline,
gdk_color_init_from_rgba (&color2, color);
node = gsk_outset_shadow_node_new2 (outline,
&color2,
dx, dy, spread, blur_radius);
&GRAPHENE_POINT_INIT (dx, dy),
spread, blur_radius);
gdk_color_finish (&color2);
return node;
@ -3176,8 +3187,7 @@ gsk_outset_shadow_node_new (const GskRoundedRect *outline,
* gsk_outset_shadow_node_new2:
* @outline: outline of the region surrounded by shadow
* @color: color of the shadow
* @dx: horizontal offset of shadow
* @dy: vertical offset of shadow
* @offset: offset of shadow
* @spread: how far the shadow spreads towards the inside
* @blur_radius: how much blur to apply to the shadow
*
@ -3187,12 +3197,11 @@ gsk_outset_shadow_node_new (const GskRoundedRect *outline,
* Returns: (transfer full) (type GskOutsetShadowNode): A new `GskRenderNode`
*/
GskRenderNode *
gsk_outset_shadow_node_new2 (const GskRoundedRect *outline,
const GdkColor *color,
float dx,
float dy,
float spread,
float blur_radius)
gsk_outset_shadow_node_new2 (const GskRoundedRect *outline,
const GdkColor *color,
const graphene_point_t *offset,
float spread,
float blur_radius)
{
GskOutsetShadowNode *self;
GskRenderNode *node;
@ -3209,8 +3218,7 @@ gsk_outset_shadow_node_new2 (const GskRoundedRect *outline,
gsk_rounded_rect_init_copy (&self->outline, outline);
gdk_color_init_copy (&self->color, color);
self->dx = dx;
self->dy = dy;
self->offset = *offset;
self->spread = spread;
self->blur_radius = blur_radius;
@ -3290,7 +3298,7 @@ gsk_outset_shadow_node_get_dx (const GskRenderNode *node)
{
const GskOutsetShadowNode *self = (const GskOutsetShadowNode *) node;
return self->dx;
return self->offset.x;
}
/**
@ -3306,7 +3314,23 @@ gsk_outset_shadow_node_get_dy (const GskRenderNode *node)
{
const GskOutsetShadowNode *self = (const GskOutsetShadowNode *) node;
return self->dy;
return self->offset.y;
}
/**
* gsk_outset_shadow_node_get_offset:
* @node: (type GskOutsetShadowNode): a `GskRenderNode` for an outset shadow
*
* Retrieves the offset of the outset shadow.
*
* Returns: an offset, in pixels
**/
const graphene_point_t *
gsk_outset_shadow_node_get_offset (const GskRenderNode *node)
{
const GskOutsetShadowNode *self = (const GskOutsetShadowNode *) node;
return &self->offset;
}
/**

View File

@ -1892,7 +1892,7 @@ parse_inset_shadow_node (GtkCssParser *parser,
parse_declarations (parser, context, declarations, G_N_ELEMENTS (declarations));
node = gsk_inset_shadow_node_new2 (&outline, &color, dx, dy, spread, blur);
node = gsk_inset_shadow_node_new2 (&outline, &color, &GRAPHENE_POINT_INIT (dx, dy), spread, blur);
gdk_color_finish (&color);
@ -2306,7 +2306,7 @@ parse_outset_shadow_node (GtkCssParser *parser,
parse_declarations (parser, context, declarations, G_N_ELEMENTS (declarations));
node = gsk_outset_shadow_node_new2 (&outline, &color, dx, dy, spread, blur);
node = gsk_outset_shadow_node_new2 (&outline, &color, &GRAPHENE_POINT_INIT (dx, dy), spread, blur);
gdk_color_finish (&color);

View File

@ -123,31 +123,31 @@ _gsk_render_node_ref (GskRenderNode *node)
return node;
}
GskRenderNode * gsk_color_node_new2 (const GdkColor *color,
const graphene_rect_t *bounds);
GskRenderNode * gsk_color_node_new2 (const GdkColor *color,
const graphene_rect_t *bounds);
const GdkColor* gsk_color_node_get_color2 (const GskRenderNode *node);
const GdkColor * gsk_color_node_get_color2 (const GskRenderNode *node);
GskRenderNode * gsk_border_node_new2 (const GskRoundedRect *outline,
const float border_width[4],
const GdkColor border_color[4]);
const GdkColor *gsk_border_node_get_colors2 (const GskRenderNode *node);
GskRenderNode * gsk_border_node_new2 (const GskRoundedRect *outline,
const float border_width[4],
const GdkColor border_color[4]);
const GdkColor * gsk_border_node_get_colors2 (const GskRenderNode *node);
GskRenderNode * gsk_inset_shadow_node_new2 (const GskRoundedRect *outline,
const GdkColor *color,
float dx,
float dy,
float spread,
float blur_radius);
const GdkColor *gsk_inset_shadow_node_get_color2 (const GskRenderNode *node);
GskRenderNode * gsk_inset_shadow_node_new2 (const GskRoundedRect *outline,
const GdkColor *color,
const graphene_point_t *offset,
float spread,
float blur_radius);
const GdkColor * gsk_inset_shadow_node_get_color2 (const GskRenderNode *node);
const graphene_point_t *gsk_inset_shadow_node_get_offset (const GskRenderNode *node);
GskRenderNode * gsk_outset_shadow_node_new2 (const GskRoundedRect *outline,
const GdkColor *color,
float dx,
float dy,
float spread,
float blur_radius);
const GdkColor *gsk_outset_shadow_node_get_color2 (const GskRenderNode *node);
GskRenderNode * gsk_outset_shadow_node_new2 (const GskRoundedRect *outline,
const GdkColor *color,
const graphene_point_t *offset,
float spread,
float blur_radius);
const GdkColor * gsk_outset_shadow_node_get_color2 (const GskRenderNode *node);
const graphene_point_t *gsk_outset_shadow_node_get_offset (const GskRenderNode *node);

View File

@ -623,7 +623,8 @@ gtk_css_shadow_value_snapshot_outset (const GtkCssValue *value,
gtk_snapshot_append_outset_shadow2 (snapshot, border_box,
&color,
dx, dy, spread, radius);
&GRAPHENE_POINT_INIT (dx, dy),
spread, radius);
gdk_color_finish (&color);
}
}
@ -719,7 +720,8 @@ gtk_css_shadow_value_snapshot_inset (const GtkCssValue *value,
gtk_snapshot_append_inset_shadow2 (snapshot,
padding_box,
&color,
dx, dy, spread, radius);
&GRAPHENE_POINT_INIT (dx, dy),
spread, radius);
}
gdk_color_finish (&color);

View File

@ -2887,7 +2887,8 @@ gtk_snapshot_append_inset_shadow (GtkSnapshot *snapshot,
gtk_snapshot_append_inset_shadow2 (snapshot,
outline,
&color2,
dx, dy, spread, blur_radius);
&GRAPHENE_POINT_INIT (dx, dy),
spread, blur_radius);
gdk_color_finish (&color2);
}
@ -2896,21 +2897,19 @@ gtk_snapshot_append_inset_shadow (GtkSnapshot *snapshot,
* @snapshot: a `GtkSnapshot`
* @outline: outline of the region surrounded by shadow
* @color: color of the shadow
* @dx: horizontal offset of shadow
* @dy: vertical offset of shadow
* @offset: offset of shadow
* @spread: how far the shadow spreads towards the inside
* @blur_radius: how much blur to apply to the shadow
*
* Appends an inset shadow into the box given by @outline.
*/
void
gtk_snapshot_append_inset_shadow2 (GtkSnapshot *snapshot,
const GskRoundedRect *outline,
const GdkColor *color,
float dx,
float dy,
float spread,
float blur_radius)
gtk_snapshot_append_inset_shadow2 (GtkSnapshot *snapshot,
const GskRoundedRect *outline,
const GdkColor *color,
const graphene_point_t *offset,
float spread,
float blur_radius)
{
GskRenderNode *node;
GskRoundedRect real_outline;
@ -2919,14 +2918,15 @@ gtk_snapshot_append_inset_shadow2 (GtkSnapshot *snapshot,
g_return_if_fail (snapshot != NULL);
g_return_if_fail (outline != NULL);
g_return_if_fail (color != NULL);
g_return_if_fail (offset != NULL);
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &x, &y);
gsk_rounded_rect_scale_affine (&real_outline, outline, scale_x, scale_y, x, y);
node = gsk_inset_shadow_node_new2 (&real_outline,
color,
scale_x * dx,
scale_y * dy,
&GRAPHENE_POINT_INIT (scale_x * offset->x,
scale_y * offset->y),
spread,
blur_radius);
@ -2960,7 +2960,8 @@ gtk_snapshot_append_outset_shadow (GtkSnapshot *snapshot,
gtk_snapshot_append_outset_shadow2 (snapshot,
outline,
&color2,
dx, dy, spread, blur_radius);
&GRAPHENE_POINT_INIT (dx, dy),
spread, blur_radius);
gdk_color_finish (&color2);
}
@ -2969,21 +2970,19 @@ gtk_snapshot_append_outset_shadow (GtkSnapshot *snapshot,
* @snapshot: a `GtkSnapshot`
* @outline: outline of the region surrounded by shadow
* @color: color of the shadow
* @dx: horizontal offset of shadow
* @dy: vertical offset of shadow
* @offset: offset of shadow
* @spread: how far the shadow spreads towards the outside
* @blur_radius: how much blur to apply to the shadow
*
* Appends an outset shadow node around the box given by @outline.
*/
void
gtk_snapshot_append_outset_shadow2 (GtkSnapshot *snapshot,
const GskRoundedRect *outline,
const GdkColor *color,
float dx,
float dy,
float spread,
float blur_radius)
gtk_snapshot_append_outset_shadow2 (GtkSnapshot *snapshot,
const GskRoundedRect *outline,
const GdkColor *color,
const graphene_point_t *offset,
float spread,
float blur_radius)
{
GskRenderNode *node;
GskRoundedRect real_outline;
@ -2992,14 +2991,15 @@ gtk_snapshot_append_outset_shadow2 (GtkSnapshot *snapshot,
g_return_if_fail (snapshot != NULL);
g_return_if_fail (outline != NULL);
g_return_if_fail (color != NULL);
g_return_if_fail (offset != NULL);
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &x, &y);
gsk_rounded_rect_scale_affine (&real_outline, outline, scale_x, scale_y, x, y);
node = gsk_outset_shadow_node_new2 (&real_outline,
color,
scale_x * dx,
scale_y * dy,
&GRAPHENE_POINT_INIT (scale_x * offset->x,
scale_y * offset->y),
spread,
blur_radius);

View File

@ -45,21 +45,19 @@ void gtk_snapshot_append_border2 (GtkSnapshot
const float border_width[4],
const GdkColor border_color[4]);
void gtk_snapshot_append_inset_shadow2 (GtkSnapshot *snapshot,
const GskRoundedRect *outline,
const GdkColor *color,
float dx,
float dy,
float spread,
float blur_radius);
void gtk_snapshot_append_inset_shadow2 (GtkSnapshot *snapshot,
const GskRoundedRect *outline,
const GdkColor *color,
const graphene_point_t *offset,
float spread,
float blur_radius);
void gtk_snapshot_append_outset_shadow2 (GtkSnapshot *snapshot,
const GskRoundedRect *outline,
const GdkColor *color,
float dx,
float dy,
float spread,
float blur_radius);
void gtk_snapshot_append_outset_shadow2 (GtkSnapshot *snapshot,
const GskRoundedRect *outline,
const GdkColor *color,
const graphene_point_t *offset,
float spread,
float blur_radius);
G_END_DECLS

View File

@ -121,13 +121,12 @@ replay_inset_shadow_node (GskRenderNode *node, GtkSnapshot *snapshot)
{
const GskRoundedRect *outline = gsk_inset_shadow_node_get_outline (node);
const GdkColor *color = gsk_inset_shadow_node_get_color2 (node);
float dx = gsk_inset_shadow_node_get_dx (node);
float dy = gsk_inset_shadow_node_get_dy (node);
const graphene_point_t *offset = gsk_inset_shadow_node_get_offset (node);
float spread = gsk_inset_shadow_node_get_spread (node);
float blur_radius = gsk_inset_shadow_node_get_blur_radius (node);
gtk_snapshot_append_inset_shadow2 (snapshot, outline, color,
dx, dy, spread, blur_radius);
offset, spread, blur_radius);
}
static void
@ -135,13 +134,12 @@ replay_outset_shadow_node (GskRenderNode *node, GtkSnapshot *snapshot)
{
const GskRoundedRect *outline = gsk_outset_shadow_node_get_outline (node);
const GdkColor *color = gsk_outset_shadow_node_get_color2 (node);
float dx = gsk_outset_shadow_node_get_dx (node);
float dy = gsk_outset_shadow_node_get_dy (node);
const graphene_point_t *offset = gsk_outset_shadow_node_get_offset (node);
float spread = gsk_outset_shadow_node_get_spread (node);
float blur_radius = gsk_outset_shadow_node_get_blur_radius (node);
gtk_snapshot_append_outset_shadow2 (snapshot, outline, color,
dx, dy, spread, blur_radius);
offset, spread, blur_radius);
}
static void