[gtk/wip/matthiasc/lottie-stroke] Move stroke api to GskPathMeasure
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/lottie-stroke] Move stroke api to GskPathMeasure
- Date: Tue, 1 Dec 2020 15:55:47 +0000 (UTC)
commit 08faff176f98769ac0c62f33784b9dcb3cbc875b
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 1 10:55:04 2020 -0500
Move stroke api to GskPathMeasure
We will need the measure when we implement dashing.
Update all callers.
gsk/gskcontourprivate.h | 4 ++++
gsk/gskpath.h | 4 ----
gsk/gskpathmeasure.c | 29 +++++++++++++++++++++++++
gsk/gskpathmeasure.h | 4 ++++
gsk/gskpathstroke.c | 37 ++++----------------------------
gsk/gskrendernodeimpl.c | 6 +++++-
gtk/gtktestutils.c | 12 ++++++++---
tests/curve-editor.c | 5 ++++-
tests/curve2.c | 43 +++++++++++++++++++++++---------------
testsuite/gsk/path-special-cases.c | 5 ++++-
10 files changed, 89 insertions(+), 60 deletions(-)
---
diff --git a/gsk/gskcontourprivate.h b/gsk/gskcontourprivate.h
index 13e54a8e5d..4fef8189c1 100644
--- a/gsk/gskcontourprivate.h
+++ b/gsk/gskcontourprivate.h
@@ -96,6 +96,10 @@ void gsk_contour_add_segment (const GskContou
gpointer measure_data,
float start,
float end);
+void gsk_contour_stroke (const GskContour *contour,
+ GskStroke *stroke,
+ GskPathBuilder *builder);
+
G_END_DECLS
diff --git a/gsk/gskpath.h b/gsk/gskpath.h
index 033ec77bd1..98a724946d 100644
--- a/gsk/gskpath.h
+++ b/gsk/gskpath.h
@@ -90,10 +90,6 @@ gboolean gsk_path_in_fill (GskPath
graphene_point_t *point,
GskFillRule fill_rule);
-GDK_AVAILABLE_IN_ALL
-GskPath * gsk_path_to_stroke (GskPath *path,
- GskStroke *stroke);
-
G_END_DECLS
#endif /* __GSK_PATH_H__ */
diff --git a/gsk/gskpathmeasure.c b/gsk/gskpathmeasure.c
index 623ee02746..0e4317ce42 100644
--- a/gsk/gskpathmeasure.c
+++ b/gsk/gskpathmeasure.c
@@ -20,6 +20,7 @@
#include "config.h"
#include "gskpathmeasure.h"
+#include "gskpathbuilder.h"
#include "gskpathprivate.h"
@@ -474,3 +475,31 @@ gsk_path_measure_in_fill (GskPathMeasure *self,
}
}
+/**
+ * gsk_path_measure_stroke:
+ * @self: a #GskPathMeasure
+ * @stroke: stroke parameters
+ *
+ * Create a new path that follows the outline of the area
+ * that would be affected by stroking along the path of
+ * @self with the given stroke parameters.
+ *
+ * Returns: a new #GskPath
+ */
+GskPath *
+gsk_path_measure_stroke (GskPathMeasure *self,
+ GskStroke *stroke)
+{
+ GskPathBuilder *builder;
+ int i;
+
+ builder = gsk_path_builder_new ();
+
+ for (i = 0; i < self->n_contours; i++)
+ {
+ gsk_contour_stroke (gsk_path_get_contour (self->path, i), stroke, builder);
+ }
+
+ return gsk_path_builder_free_to_path (builder);
+}
+
diff --git a/gsk/gskpathmeasure.h b/gsk/gskpathmeasure.h
index 6d1829caba..d3c3c9d82a 100644
--- a/gsk/gskpathmeasure.h
+++ b/gsk/gskpathmeasure.h
@@ -75,6 +75,10 @@ gboolean gsk_path_measure_in_fill (GskPathMeasure
graphene_point_t *point,
GskFillRule fill_rule);
+GDK_AVAILABLE_IN_ALL
+GskPath * gsk_path_measure_stroke (GskPathMeasure *self,
+ GskStroke *stroke);
+
G_END_DECLS
#endif /* __GSK_PATH_MEASURE_H__ */
diff --git a/gsk/gskpathstroke.c b/gsk/gskpathstroke.c
index b7e924c15d..6d2b22a015 100644
--- a/gsk/gskpathstroke.c
+++ b/gsk/gskpathstroke.c
@@ -1025,10 +1025,10 @@ add_cap (GskPathBuilder *builder,
}
}
-static void
-gsk_contour_to_stroke (const GskContour *contour,
- GskStroke *stroke,
- GskPathBuilder *builder)
+void
+gsk_contour_stroke (const GskContour *contour,
+ GskStroke *stroke,
+ GskPathBuilder *builder)
{
GList *ops, *l;
GList *last = NULL;
@@ -1373,32 +1373,3 @@ gsk_contour_to_stroke (const GskContour *contour,
g_list_free_full (ops, g_free);
}
-
-/**
- * gsk_path_to_stroke:
- * @path: a #GskPath
- * @stroke: stroke parameters
- *
- * Create a new path that follows the outline of the area
- * that would be affected by stroking along @path with
- * the given stroke parameters.
- *
- * Returns: a new #GskPath
- */
-GskPath *
-gsk_path_to_stroke (GskPath *path,
- GskStroke *stroke)
-{
- GskPathBuilder *builder;
- int i;
-
- builder = gsk_path_builder_new ();
-
- for (i = 0; i < gsk_path_get_n_contours (path); i++)
- {
- const GskContour *contour = gsk_path_get_contour (path, i);
- gsk_contour_to_stroke (contour, stroke, builder);
- }
-
- return gsk_path_builder_free_to_path (builder);
-}
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index a805ce93af..e97a32a82c 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -24,6 +24,7 @@
#include "gskdebugprivate.h"
#include "gskdiffprivate.h"
#include "gskpath.h"
+#include "gskpathmeasure.h"
#include "gskrendererprivate.h"
#include "gskroundedrectprivate.h"
#include "gskstrokeprivate.h"
@@ -3509,6 +3510,7 @@ gsk_stroke_node_new (GskRenderNode *child,
{
GskStrokeNode *self;
GskRenderNode *node;
+ GskPathMeasure *measure;
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
g_return_val_if_fail (path != NULL, NULL);
@@ -3520,7 +3522,9 @@ 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_path = gsk_path_to_stroke (self->path, &self->stroke);
+ measure = gsk_path_measure_new (path);
+ self->stroke_path = gsk_path_measure_stroke (measure, &self->stroke);
+ gsk_path_measure_unref (measure);
graphene_rect_init_from_rect (&node->bounds, &child->bounds);
diff --git a/gtk/gtktestutils.c b/gtk/gtktestutils.c
index 5cbe02c898..702248681c 100644
--- a/gtk/gtktestutils.c
+++ b/gtk/gtktestutils.c
@@ -96,18 +96,24 @@ gtk_test_init (int *argcp,
*/
{
GskPathBuilder *builder;
- GskPath *path, *path2;
+ GskPath *path;
+ GskPathMeasure *measure;
GskStroke *stroke;
builder = gsk_path_builder_new ();
gsk_path_builder_move_to (builder, 10, 10);
gsk_path_builder_close (builder);
path = gsk_path_builder_free_to_path (builder);
+ measure = gsk_path_measure_new (path);
+ gsk_path_unref (path);
+
stroke = gsk_stroke_new (1);
- path2 = gsk_path_to_stroke (path, stroke);
+ path = gsk_path_measure_stroke (measure, stroke);
gsk_stroke_free (stroke);
+
+ gsk_path_measure_unref (measure);
+
gsk_path_unref (path);
- gsk_path_unref (path2);
}
}
diff --git a/tests/curve-editor.c b/tests/curve-editor.c
index a29c038ae6..2b6e1fc84e 100644
--- a/tests/curve-editor.c
+++ b/tests/curve-editor.c
@@ -1355,6 +1355,7 @@ curve_editor_snapshot (GtkWidget *widget,
GskPath *path;
GskPath *path2;
GskStroke *stroke;
+ GskPathMeasure *measure;
int i, j, k;
float width;
float height;
@@ -1372,9 +1373,11 @@ curve_editor_snapshot (GtkWidget *widget,
curve_editor_add_path (self, builder);
path = gsk_path_builder_free_to_path (builder);
+ measure = gsk_path_measure_new (path);
stroke = gsk_stroke_new (20);
- path2 = gsk_path_to_stroke (path, stroke);
+ path2 = gsk_path_measure_stroke (measure, stroke);
gsk_stroke_free (stroke);
+ gsk_path_measure_unref (measure);
gtk_snapshot_push_stroke (snapshot, path2, self->stroke);
gsk_path_unref (path2);
diff --git a/tests/curve2.c b/tests/curve2.c
index 74a9f16d74..9e1e5fd47a 100644
--- a/tests/curve2.c
+++ b/tests/curve2.c
@@ -14,18 +14,19 @@ struct _DemoWidget
graphene_point_t point2;
graphene_vec2_t tangent;
double start, end;
- float line_width;
gboolean track;
gboolean show_bounding_box;
GtkWidget *label;
gboolean do_stroke;
- GskPathMeasure *stroke_measure;
GskPath *stroke_path;
+ GskStroke *stroke;
+ GskPathMeasure *stroke_measure;
+ GskPath *outline_path;
+ GskStroke *outline_stroke;
gboolean inside;
GskFillRule fill_rule;
- GskStroke *stroke;
};
struct _DemoWidgetClass
@@ -127,10 +128,7 @@ demo_widget_snapshot (GtkWidget *widget,
gtk_snapshot_pop (snapshot);
}
- stroke = gsk_stroke_new (self->line_width);
- path = gsk_path_to_stroke (self->stroke_path, stroke);
- gtk_snapshot_push_fill (snapshot, path, GSK_FILL_RULE_WINDING);
- gsk_path_unref (path);
+ gtk_snapshot_push_fill (snapshot, self->outline_path, GSK_FILL_RULE_WINDING);
gtk_snapshot_append_color (snapshot,
&(GdkRGBA){ 0, 0, 0, 0.2},
@@ -138,22 +136,19 @@ demo_widget_snapshot (GtkWidget *widget,
gtk_snapshot_pop (snapshot);
- gsk_stroke_free (stroke);
stroke = gsk_stroke_new (1);
gtk_snapshot_push_stroke (snapshot, self->path, stroke);
+ gsk_stroke_free (stroke);
gtk_snapshot_append_color (snapshot,
&(GdkRGBA){ 0, 0, 0, 0.3},
&GRAPHENE_RECT_INIT (0, 0, width, height ));
gtk_snapshot_pop (snapshot);
- gsk_stroke_free (stroke);
}
else
{
- stroke = gsk_stroke_new (self->line_width);
- gtk_snapshot_push_stroke (snapshot, self->path, stroke);
- gsk_stroke_free (stroke);
+ gtk_snapshot_push_stroke (snapshot, self->path, self->outline_stroke);
gtk_snapshot_append_color (snapshot,
&(GdkRGBA){ 0, 0, 0, 1},
@@ -166,7 +161,7 @@ demo_widget_snapshot (GtkWidget *widget,
{
graphene_rect_t bounds;
- if (gsk_path_get_bounds (self->do_stroke ? self->stroke_path : self->path, &bounds))
+ if (gsk_path_get_bounds (self->do_stroke ? self->outline_path : self->path, &bounds))
{
builder = gsk_path_builder_new ();
@@ -254,6 +249,8 @@ demo_widget_dispose (GObject *object)
g_clear_pointer (&self->stroke_path, gsk_path_unref);
g_clear_pointer (&self->stroke_measure, gsk_path_measure_unref);
g_clear_pointer (&self->stroke, gsk_stroke_free);
+ g_clear_pointer (&self->outline_path, gsk_path_unref);
+ g_clear_pointer (&self->outline_stroke, gsk_stroke_free);
g_clear_pointer (&self->label, gtk_widget_unparent);
G_OBJECT_CLASS (demo_widget_parent_class)->dispose (object);
@@ -278,6 +275,17 @@ demo_widget_new (void)
return g_object_new (DEMO_TYPE_WIDGET, NULL);
}
+static void
+update_outline_path (DemoWidget *self)
+{
+ if (self->stroke_measure)
+ {
+ g_clear_pointer (&self->outline_path, gsk_path_unref);
+ self->outline_path = gsk_path_measure_stroke (self->stroke_measure, self->outline_stroke);
+ gtk_widget_queue_draw (GTK_WIDGET (self));
+ }
+}
+
static void
update_stroke_path (DemoWidget *self)
{
@@ -286,8 +294,9 @@ update_stroke_path (DemoWidget *self)
if (self->do_stroke)
{
- self->stroke_path = gsk_path_to_stroke (self->path, self->stroke);
+ self->stroke_path = gsk_path_measure_stroke (self->measure, self->stroke);
self->stroke_measure = gsk_path_measure_new (self->stroke_path);
+ update_outline_path (self);
}
gtk_widget_queue_draw (GTK_WIDGET (self));
@@ -372,7 +381,7 @@ init_demo (DemoWidget *demo,
gsk_path_unref (path);
demo->stroke = gsk_stroke_new (20);
- demo->line_width = 1;
+ demo->outline_stroke = gsk_stroke_new (1);
}
static void
@@ -475,8 +484,8 @@ static void
line_width_changed (GtkSpinButton *spin,
DemoWidget *self)
{
- self->line_width = gtk_spin_button_get_value (spin);
- gtk_widget_queue_draw (GTK_WIDGET (self));
+ gsk_stroke_set_line_width (self->outline_stroke, gtk_spin_button_get_value (spin));
+ update_outline_path (self);
}
int
diff --git a/testsuite/gsk/path-special-cases.c b/testsuite/gsk/path-special-cases.c
index bc9cb4d8c7..8f97eaa17c 100644
--- a/testsuite/gsk/path-special-cases.c
+++ b/testsuite/gsk/path-special-cases.c
@@ -312,6 +312,7 @@ test_point_to_stroke (void)
{
GskPathBuilder *builder;
GskPath *path;
+ GskPathMeasure *measure;
GskStroke *stroke;
GskPath *path1;
char *string;
@@ -333,7 +334,9 @@ test_point_to_stroke (void)
g_free (string);
stroke = gsk_stroke_new (20.f);
- path1 = gsk_path_to_stroke (path, stroke);
+ measure = gsk_path_measure_new (path);
+ path1 = gsk_path_measure_stroke (measure, stroke);
+ gsk_path_measure_unref (measure);
gsk_stroke_free (stroke);
g_assert_nonnull (path1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]