Commit ea84e974 authored by Benjamin Otte's avatar Benjamin Otte

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.
parent abc9b944
Pipeline #6305 passed with stage
in 9 minutes and 12 seconds
......@@ -63,6 +63,7 @@
#include <gdk/gdkrectangle.h>
#include <gdk/gdkrgba.h>
#include <gdk/gdkseat.h>
#include <gdk/gdksnapshot.h>
#include <gdk/gdktexture.h>
#include <gdk/gdktypes.h>
#include <gdk/gdkvulkancontext.h>
......
......@@ -21,6 +21,8 @@
#include "gdkpaintable.h"
#include "gdksnapshotprivate.h"
/**
* SECTION:paintable
* @Title: GdkPaintable
......
......@@ -24,16 +24,12 @@
#error "Only <gdk/gdk.h> can be included directly."
#endif
#include <cairo.h>
#include <glib-object.h>
#include <gdk/gdktypes.h>
#include <gdk/gdkversionmacros.h>
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)
......
/*
* 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 <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#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)
{
}
/*
* 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 <http://www.gnu.org/licenses/>.
*
* Authors: Benjamin Otte <otte@gnome.org>
*/
#ifndef __GDK_SNAPSHOT_H__
#define __GDK_SNAPSHOT_H__
#if !defined (__GDK_H_INSIDE__) && !defined (GDK_COMPILATION)
#error "Only <gdk/gdk.h> can be included directly."
#endif
#include <gdk/gdktypes.h>
#include <gdk/gdkversionmacros.h>
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__ */
#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__ */
......@@ -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;
......
......@@ -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',
......
......@@ -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;
}
......
......@@ -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,
......
......@@ -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__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment