From: Benjamin Otte Date: Sun, 18 Mar 2018 18:21:33 +0000 (+0100) Subject: snapshot: Turn into GObject X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~22^2~901 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=ea84e974e6eb8565554c8514cf18a326e5b256ed;p=gtk4.git 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. --- diff --git a/gdk/gdk.h b/gdk/gdk.h index b07a00e19f..6bb48e004a 100644 --- a/gdk/gdk.h +++ b/gdk/gdk.h @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include diff --git a/gdk/gdkpaintable.c b/gdk/gdkpaintable.c index eb317a8234..dd6422654a 100644 --- a/gdk/gdkpaintable.c +++ b/gdk/gdkpaintable.c @@ -21,6 +21,8 @@ #include "gdkpaintable.h" +#include "gdksnapshotprivate.h" + /** * SECTION:paintable * @Title: GdkPaintable diff --git a/gdk/gdkpaintable.h b/gdk/gdkpaintable.h index 99e4e83ff9..d38f0511e5 100644 --- a/gdk/gdkpaintable.h +++ b/gdk/gdkpaintable.h @@ -24,16 +24,12 @@ #error "Only can be included directly." #endif -#include -#include - +#include #include G_BEGIN_DECLS -#define GDK_TYPE_PAINTABLE (gdk_paintable_get_type ()) - -typedef struct _GdkSnapshot GdkSnapshot; /* Forward declaration */ +#define GDK_TYPE_PAINTABLE (gdk_paintable_get_type ()) GDK_AVAILABLE_IN_ALL G_DECLARE_INTERFACE (GdkPaintable, gdk_paintable, GDK, PAINTABLE, GObject) diff --git a/gdk/gdksnapshot.c b/gdk/gdksnapshot.c new file mode 100644 index 0000000000..1589428e5e --- /dev/null +++ b/gdk/gdksnapshot.c @@ -0,0 +1,35 @@ +/* + * Copyright © 2018 Benjamin Otte + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Authors: Benjamin Otte + */ + +#include "config.h" + +#include "gdksnapshotprivate.h" + +G_DEFINE_ABSTRACT_TYPE (GdkSnapshot, gdk_snapshot, G_TYPE_OBJECT) + +static void +gdk_snapshot_class_init (GdkSnapshotClass *klass) +{ +} + +static void +gdk_snapshot_init (GdkSnapshot *self) +{ +} + diff --git a/gdk/gdksnapshot.h b/gdk/gdksnapshot.h new file mode 100644 index 0000000000..5f282f69fa --- /dev/null +++ b/gdk/gdksnapshot.h @@ -0,0 +1,47 @@ +/* + * Copyright © 2018 Benjamin Otte + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Authors: Benjamin Otte + */ + +#ifndef __GDK_SNAPSHOT_H__ +#define __GDK_SNAPSHOT_H__ + +#if !defined (__GDK_H_INSIDE__) && !defined (GDK_COMPILATION) +#error "Only can be included directly." +#endif + +#include +#include + +G_BEGIN_DECLS + +typedef struct _GdkSnapshotClass GdkSnapshotClass; + +#define GDK_TYPE_SNAPSHOT (gdk_snapshot_get_type ()) + +#define GDK_SNAPSHOT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDK_TYPE_SNAPSHOT, GdkSnapshot)) +#define GDK_IS_SNAPSHOT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDK_TYPE_SNAPSHOT)) + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkSnapshot, g_object_unref) + +GDK_AVAILABLE_IN_ALL +GType gdk_snapshot_get_type (void) G_GNUC_CONST; + + +G_END_DECLS + +#endif /* __GDK_SNAPSHOT_H__ */ diff --git a/gdk/gdksnapshotprivate.h b/gdk/gdksnapshotprivate.h new file mode 100644 index 0000000000..b7cdc761e3 --- /dev/null +++ b/gdk/gdksnapshotprivate.h @@ -0,0 +1,23 @@ +#ifndef __GDK_SNAPSHOT_PRIVATE_H__ +#define __GDK_SNAPSHOT_PRIVATE_H__ + +#include "gdksnapshot.h" + +G_BEGIN_DECLS + +#define GDK_SNAPSHOT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_SNAPSHOT, GdkSnapshotClass)) +#define GDK_IS_SNAPSHOT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_SNAPSHOT)) +#define GDK_SNAPSHOT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_SNAPSHOT, GdkSnapshotClass)) + +struct _GdkSnapshot +{ + GObject parent_instance; +}; + +struct _GdkSnapshotClass { + GObjectClass parent_class; +}; + +G_END_DECLS + +#endif /* __GDK_SNAPSHOT_PRIVATE_H__ */ diff --git a/gdk/gdktypes.h b/gdk/gdktypes.h index 6b2778373d..2622d05619 100644 --- a/gdk/gdktypes.h +++ b/gdk/gdktypes.h @@ -132,6 +132,7 @@ typedef struct _GdkWindow GdkWindow; typedef struct _GdkKeymap GdkKeymap; typedef struct _GdkAppLaunchContext GdkAppLaunchContext; typedef struct _GdkSeat GdkSeat; +typedef struct _GdkSnapshot GdkSnapshot; typedef struct _GdkDrawingContext GdkDrawingContext; typedef struct _GdkDrawContext GdkDrawContext; diff --git a/gdk/meson.build b/gdk/meson.build index 7808ab20ea..8f69e1ca24 100644 --- a/gdk/meson.build +++ b/gdk/meson.build @@ -39,6 +39,7 @@ gdk_public_sources = files([ 'gdkseat.c', 'gdkseatdefault.c', 'gdkselection.c', + 'gdksnapshot.c', 'gdktexture.c', 'gdkvulkancontext.c', 'gdkwindow.c', @@ -81,6 +82,7 @@ gdk_public_headers = files([ 'gdkrectangle.h', 'gdkrgba.h', 'gdkseat.h', + 'gdksnapshot.h', 'gdktexture.h', 'gdktypes.h', 'gdkvulkancontext.h', 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__ */