From 0c3c8a6a85fb56ec7fcf52d4f6b705a37912f154 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 27 Dec 2023 22:26:35 +0100 Subject: [PATCH] stroke: Turn stroke copy intialization into a macro That way I can use it in static initializers. --- gsk/gskrendernodeimpl.c | 2 +- gsk/gskstroke.c | 2 +- gsk/gskstrokeprivate.h | 18 ++++++++++-------- gtk/gtksnapshot.c | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c index f1be2dc12d..052c027cea 100644 --- a/gsk/gskrendernodeimpl.c +++ b/gsk/gskrendernodeimpl.c @@ -4829,7 +4829,7 @@ gsk_stroke_node_new (GskRenderNode *child, self->child = gsk_render_node_ref (child); self->path = gsk_path_ref (path); - gsk_stroke_init_copy (&self->stroke, stroke); + self->stroke = GSK_STROKE_INIT_COPY (stroke); if (gsk_path_get_stroke_bounds (self->path, &self->stroke, &stroke_bounds)) gsk_rect_intersection (&stroke_bounds, &child->bounds, &node->bounds); diff --git a/gsk/gskstroke.c b/gsk/gskstroke.c index 0344053793..61cdc6a47a 100644 --- a/gsk/gskstroke.c +++ b/gsk/gskstroke.c @@ -79,7 +79,7 @@ gsk_stroke_copy (const GskStroke *other) self = g_new (GskStroke, 1); - gsk_stroke_init_copy (self, other); + *self = GSK_STROKE_INIT_COPY (other); return self; } diff --git a/gsk/gskstrokeprivate.h b/gsk/gskstrokeprivate.h index 8738a2b671..2b4113cf45 100644 --- a/gsk/gskstrokeprivate.h +++ b/gsk/gskstrokeprivate.h @@ -37,14 +37,16 @@ struct _GskStroke float dash_offset; }; -static inline void -gsk_stroke_init_copy (GskStroke *stroke, - const GskStroke *other) -{ - *stroke = *other; - - stroke->dash = g_memdup (other->dash, stroke->n_dash * sizeof (float)); -} +#define GSK_STROKE_INIT_COPY(_stroke) ((GskStroke) {\ + .line_width = _stroke->line_width, \ + .line_cap = _stroke->line_cap, \ + .line_join = _stroke->line_join, \ + .miter_limit = _stroke->miter_limit, \ + .dash = g_memdup (_stroke->dash, _stroke->n_dash * sizeof (float)), \ + .n_dash = _stroke->n_dash, \ + .dash_length = _stroke->dash_length, \ + .dash_offset = _stroke->dash_offset, \ +}) static inline void gsk_stroke_clear (GskStroke *stroke) diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index 6e002859b4..2e47c8f85c 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -1301,7 +1301,7 @@ gtk_snapshot_push_stroke (GtkSnapshot *snapshot, gtk_snapshot_clear_stroke); state->data.stroke.path = gsk_path_ref (path); - gsk_stroke_init_copy (&state->data.stroke.stroke, stroke); + state->data.stroke.stroke = GSK_STROKE_INIT_COPY (stroke); } static GskRenderNode *