[gtk/wip/otte/lottie: 244/251] path: Add gsk_path_builder_add_path()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/lottie: 244/251] path: Add gsk_path_builder_add_path()
- Date: Wed, 18 Nov 2020 08:05:05 +0000 (UTC)
commit 3f3ce29435bfece16365712886b25f20f0413ab6
Author: Benjamin Otte <otte redhat com>
Date: Tue Nov 17 00:13:32 2020 +0100
path: Add gsk_path_builder_add_path()
gsk/gskpath.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++----
gsk/gskpath.h | 4 ++
gsk/gskpathprivate.h | 4 ++
3 files changed, 103 insertions(+), 8 deletions(-)
---
diff --git a/gsk/gskpath.c b/gsk/gskpath.c
index f17a5965d3..290061b94a 100644
--- a/gsk/gskpath.c
+++ b/gsk/gskpath.c
@@ -59,6 +59,8 @@ struct _GskContourClass
float *out_length);
void (* free_measure) (const GskContour *contour,
gpointer measure_data);
+ void (* copy) (const GskContour *contour,
+ GskContour *dest);
};
struct _GskPath
@@ -152,6 +154,16 @@ gsk_rect_contour_free_measure (const GskContour *contour,
{
}
+static void
+gsk_rect_contour_copy (const GskContour *contour,
+ GskContour *dest)
+{
+ const GskRectContour *self = (const GskRectContour *) contour;
+ GskRectContour *target = (GskRectContour *) dest;
+
+ *target = *self;
+}
+
static const GskContourClass GSK_RECT_CONTOUR_CLASS =
{
sizeof (GskRectContour),
@@ -161,7 +173,8 @@ static const GskContourClass GSK_RECT_CONTOUR_CLASS =
gsk_rect_contour_to_cairo,
gsk_rect_contour_get_bounds,
gsk_rect_contour_init_measure,
- gsk_rect_contour_free_measure
+ gsk_rect_contour_free_measure,
+ gsk_rect_contour_copy
};
static void
@@ -395,6 +408,22 @@ gsk_standard_contour_free_measure (const GskContour *contour,
{
}
+static void
+gsk_standard_contour_init (GskContour *contour,
+ const GskStandardOperation *ops,
+ gsize n_ops,
+ const graphene_point_t *points,
+ gsize n_points);
+
+static void
+gsk_standard_contour_copy (const GskContour *contour,
+ GskContour *dest)
+{
+ const GskStandardContour *self = (const GskStandardContour *) contour;
+
+ gsk_standard_contour_init (dest, self->ops, self->n_ops, self->points, self->n_points);
+}
+
static const GskContourClass GSK_STANDARD_CONTOUR_CLASS =
{
sizeof (GskStandardContour),
@@ -404,7 +433,8 @@ static const GskContourClass GSK_STANDARD_CONTOUR_CLASS =
gsk_standard_contour_to_cairo,
gsk_standard_contour_get_bounds,
gsk_standard_contour_init_measure,
- gsk_standard_contour_free_measure
+ gsk_standard_contour_free_measure,
+ gsk_standard_contour_copy
};
/* You must ensure the contour has enough size allocated,
@@ -430,6 +460,30 @@ gsk_standard_contour_init (GskContour *contour,
/* CONTOUR */
+static gsize
+gsk_contour_get_size (const GskContour *contour)
+{
+ return contour->klass->get_size (contour);
+}
+
+static void
+gsk_contour_copy (GskContour *dest,
+ const GskContour *src)
+{
+ src->klass->copy (src, dest);
+}
+
+static GskContour *
+gsk_contour_dup (const GskContour *src)
+{
+ GskContour *copy;
+
+ copy = g_malloc0 (gsk_contour_get_size (src));
+ gsk_contour_copy (copy, src);
+
+ return copy;
+}
+
gpointer
gsk_contour_init_measure (GskPath *path,
gsize i,
@@ -784,6 +838,17 @@ G_DEFINE_BOXED_TYPE (GskPathBuilder,
gsk_path_builder_unref)
+void
+gsk_path_builder_add_contour (GskPathBuilder *builder,
+ GskPath *path,
+ gsize i)
+{
+ GskContour *copy;
+
+ copy = gsk_contour_dup (path->contours[i]);
+ builder->contours = g_slist_prepend (builder->contours, copy);
+}
+
/**
* gsk_path_builder_new:
*
@@ -956,7 +1021,7 @@ gsk_path_builder_to_path (GskPathBuilder *builder)
n_contours++;
size += sizeof (GskContour *);
- size += contour->klass->get_size (contour);
+ size += gsk_contour_get_size (contour);
}
path = gsk_path_alloc (size);
@@ -969,8 +1034,8 @@ gsk_path_builder_to_path (GskPathBuilder *builder)
GskContour *contour = l->data;
path->contours[n_contours] = (GskContour *) contour_data;
- size = contour->klass->get_size (contour);
- memcpy (contour_data, contour, size);
+ gsk_contour_copy ((GskContour *) contour_data, contour);
+ size = gsk_contour_get_size (contour);
contour_data += size;
n_contours++;
}
@@ -980,9 +1045,31 @@ gsk_path_builder_to_path (GskPathBuilder *builder)
return path;
}
+/**
+ * gsk_path_builder_add_path:
+ * @builder: a #GskPathBuilder
+ * @path: (transfer none): the path to append
+ *
+ * Appends all of @path to @builder.
+ **/
+void
+gsk_path_builder_add_path (GskPathBuilder *builder,
+ GskPath *path)
+{
+ gsize i;
+
+ g_return_if_fail (builder != NULL);
+ g_return_if_fail (path != NULL);
+
+ for (i = 0; i < path->n_contours; i++)
+ {
+ gsk_path_builder_add_contour (builder, path, i);
+ }
+}
+
static GskContour *
-gsk_path_builder_add_contour (GskPathBuilder *builder,
- const GskContourClass *klass)
+gsk_path_builder_add_contour_by_klass (GskPathBuilder *builder,
+ const GskContourClass *klass)
{
GskContour *contour;
@@ -1007,7 +1094,7 @@ gsk_path_builder_add_rect (GskPathBuilder *builder,
g_return_if_fail (width != 0);
g_return_if_fail (height != 0);
- contour = gsk_path_builder_add_contour (builder, &GSK_RECT_CONTOUR_CLASS);
+ contour = gsk_path_builder_add_contour_by_klass (builder, &GSK_RECT_CONTOUR_CLASS);
gsk_rect_contour_init (contour, x, y, width, height);
}
diff --git a/gsk/gskpath.h b/gsk/gskpath.h
index b01c3aae75..1be4ec189f 100644
--- a/gsk/gskpath.h
+++ b/gsk/gskpath.h
@@ -78,6 +78,10 @@ GDK_AVAILABLE_IN_ALL
GskPath * gsk_path_builder_free_to_path (GskPathBuilder *builder)
G_GNUC_WARN_UNUSED_RESULT;
GDK_AVAILABLE_IN_ALL
GskPath * gsk_path_builder_to_path (GskPathBuilder *builder)
G_GNUC_WARN_UNUSED_RESULT;
+
+GDK_AVAILABLE_IN_ALL
+void gsk_path_builder_add_path (GskPathBuilder *builder,
+ GskPath *path);
GDK_AVAILABLE_IN_ALL
void gsk_path_builder_add_rect (GskPathBuilder *builder,
float x,
diff --git a/gsk/gskpathprivate.h b/gsk/gskpathprivate.h
index 5551734411..aae06f1dd3 100644
--- a/gsk/gskpathprivate.h
+++ b/gsk/gskpathprivate.h
@@ -34,6 +34,10 @@ void gsk_contour_free_measure (GskPath
gsize i,
gpointer data);
+void gsk_path_builder_add_contour (GskPathBuilder *builder,
+ GskPath *path,
+ gsize i);
+
G_END_DECLS
#endif /* __GSK_PATH_PRIVATE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]