summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-03-18 19:21:33 +0100
committerBenjamin Otte <otte@redhat.com>2018-03-18 19:21:33 +0100
commitea84e974e6eb8565554c8514cf18a326e5b256ed (patch)
tree8275f6c6df004361fa4e535ad2bb12bca4a37086 /gtk
parentabc9b944f9153b5e770f0127589744c8b3f629c0 (diff)
downloadgtk+-ea84e974e6eb8565554c8514cf18a326e5b256ed.tar.gz
snapshot: Turn into GObject
This makes GdkSnapshot the base class for GtkSnapshot and hopefully stops confusing bindings. C code should see no difference to before.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtksnapshot.c62
-rw-r--r--gtk/gtksnapshot.h15
-rw-r--r--gtk/gtksnapshotprivate.h12
3 files changed, 44 insertions, 45 deletions
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index a74dba038b..c9ebf0b5a0 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -51,42 +51,12 @@
* use gtk_snapshot_new().
*/
-G_DEFINE_BOXED_TYPE (GtkSnapshot, gtk_snapshot, gtk_snapshot_ref, gtk_snapshot_unref)
+G_DEFINE_TYPE (GtkSnapshot, gtk_snapshot, GDK_TYPE_SNAPSHOT)
-/**
- * gtk_snapshot_ref:
- * @snapshot: a #GtkSnapshot
- *
- * Increase the reference count of @snapshot by 1.
- *
- * Returns: the @snapshot
- */
-GtkSnapshot *
-gtk_snapshot_ref (GtkSnapshot *snapshot)
-{
- g_assert (snapshot->ref_count > 0);
-
- snapshot->ref_count += 1;
-
- return snapshot;
-}
-
-/**
- * gtk_snapshot_unref:
- * @snapshot: a #GtkSnapshot
- *
- * Decrease the reference count of @snapshot by 1 and
- * free the object if the count drops to 0.
- */
-void
-gtk_snapshot_unref (GtkSnapshot *snapshot)
+static void
+gtk_snapshot_dispose (GObject *object)
{
- g_assert (snapshot->ref_count > 0);
-
- snapshot->ref_count -= 1;
-
- if (snapshot->ref_count > 0)
- return;
+ GtkSnapshot *snapshot = GTK_SNAPSHOT (object);
if (snapshot->state_stack)
gsk_render_node_unref (gtk_snapshot_to_node (snapshot));
@@ -94,7 +64,20 @@ gtk_snapshot_unref (GtkSnapshot *snapshot)
g_assert (snapshot->state_stack == NULL);
g_assert (snapshot->nodes == NULL);
- g_free (snapshot);
+ G_OBJECT_CLASS (gtk_snapshot_parent_class)->dispose (object);
+}
+
+static void
+gtk_snapshot_class_init (GtkSnapshotClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->dispose = gtk_snapshot_dispose;
+}
+
+static void
+gtk_snapshot_init (GtkSnapshot *self)
+{
}
static GskRenderNode *
@@ -205,8 +188,7 @@ gtk_snapshot_new (GskRenderer *renderer,
else
str = NULL;
- snapshot = g_new (GtkSnapshot, 1);
- snapshot->ref_count = 1;
+ snapshot = g_object_new (GTK_TYPE_SNAPSHOT, NULL);
snapshot->record_names = record_names;
snapshot->renderer = renderer;
@@ -224,8 +206,8 @@ gtk_snapshot_new (GskRenderer *renderer,
}
/**
- * gtk_snapshot_free_to_node:
- * @snapshot: a #GtkSnapshot
+ * gtk_snapshot_free_to_node: (skip)
+ * @snapshot: (transfer full): a #GtkSnapshot
*
* Returns the node that was constructed by @snapshot
* and frees @snapshot.
@@ -238,7 +220,7 @@ gtk_snapshot_free_to_node (GtkSnapshot *snapshot)
GskRenderNode *result;
result = gtk_snapshot_to_node (snapshot);
- gtk_snapshot_unref (snapshot);
+ g_object_unref (snapshot);
return result;
}
diff --git a/gtk/gtksnapshot.h b/gtk/gtksnapshot.h
index f908a3dcdf..e9852f8b96 100644
--- a/gtk/gtksnapshot.h
+++ b/gtk/gtksnapshot.h
@@ -36,13 +36,20 @@
G_BEGIN_DECLS
+typedef GdkSnapshot GtkSnapshot;
+typedef struct _GtkSnapshotClass GtkSnapshotClass;
+
+#define GTK_TYPE_SNAPSHOT (gtk_snapshot_get_type ())
+
+#define GTK_SNAPSHOT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SNAPSHOT, GtkSnapshot))
+#define GTK_IS_SNAPSHOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SNAPSHOT))
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSnapshot, g_object_unref)
+
+
GDK_AVAILABLE_IN_ALL
GType gtk_snapshot_get_type (void) G_GNUC_CONST;
-GDK_AVAILABLE_IN_ALL
-GtkSnapshot * gtk_snapshot_ref (GtkSnapshot *snapshot);
-GDK_AVAILABLE_IN_ALL
-void gtk_snapshot_unref (GtkSnapshot *snapshot);
GDK_AVAILABLE_IN_ALL
GtkSnapshot * gtk_snapshot_new (GskRenderer *renderer,
diff --git a/gtk/gtksnapshotprivate.h b/gtk/gtksnapshotprivate.h
index 370784e27d..d6e534deef 100644
--- a/gtk/gtksnapshotprivate.h
+++ b/gtk/gtksnapshotprivate.h
@@ -80,14 +80,24 @@ struct _GtkSnapshotState {
} data;
};
+/* This is a nasty little hack. We typedef GtkSnapshot to the fake object GdkSnapshot
+ * so that we don't need to typecast between them.
+ * After all, the GdkSnapshot only exist so poor language bindings don't trip. Hardcore
+ * C code can just blatantly ignore such layering violations with a typedef.
+ */
struct _GdkSnapshot {
- int ref_count;
+ GObject parent_instance; /* it's really GdkSnapshot, but don't tell anyone! */
+
gboolean record_names;
GskRenderer *renderer;
GArray *state_stack;
GPtrArray *nodes;
};
+struct _GtkSnapshotClass {
+ GObjectClass parent_class; /* it's really GdkSnapshotClass, but don't tell anyone! */
+};
+
G_END_DECLS
#endif /* __GTK_SNAPSHOT_PRIVATE_H__ */