From 1b2dd815b4a81048f445890b91d12237a8a06a8b Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Mon, 2 Sep 2013 16:02:42 +0100 Subject: [PATCH] Registers gtypes for all public objects and structs This adds much more comprehensive support for gobject-introspection based bindings by registering all objects as fundamental types that inherit from CoglObject, and all structs as boxed types. Co-Author: Robert Bragg Reviewed-by: Neil Roberts --- cogl-gst/Makefile.am | 37 ++++ cogl-gst/cogl-gst-video-sink.c | 30 ++++ cogl-gst/cogl-gst-video-sink.h | 6 + cogl-pango/Makefile.am | 18 +- cogl-path/cogl-path.c | 2 + cogl-path/cogl2-path-functions.h | 14 +- cogl/Makefile.am | 28 +++- cogl/cogl-atlas-texture.c | 2 + cogl/cogl-atlas-texture.h | 12 ++ cogl/cogl-attribute-buffer.c | 2 + cogl/cogl-attribute-buffer.h | 13 ++ cogl/cogl-attribute.c | 2 + cogl/cogl-attribute.h | 13 ++ cogl/cogl-bitmap.c | 2 + cogl/cogl-bitmap.h | 13 ++ cogl/cogl-buffer-private.h | 2 +- cogl/cogl-color.c | 3 + cogl/cogl-color.h | 13 ++ cogl/cogl-context.c | 2 + cogl/cogl-context.h | 13 ++ cogl/cogl-display.c | 2 + cogl/cogl-display.h | 13 ++ cogl/cogl-euler.c | 5 + cogl/cogl-euler.h | 13 ++ cogl/cogl-frame-info.c | 2 + cogl/cogl-frame-info.h | 13 ++ cogl/cogl-framebuffer.c | 3 + cogl/cogl-framebuffer.h | 13 +- cogl/cogl-gles2-context.c | 2 + cogl/cogl-gles2.h | 13 ++ cogl/cogl-gtype-private.h | 233 +++++++++++++++++++++++++- cogl/cogl-gtype.c | 153 +++++++++++++++++ cogl/cogl-index-buffer.c | 2 + cogl/cogl-index-buffer.h | 13 ++ cogl/cogl-indices.c | 2 + cogl/cogl-indices.h | 13 ++ cogl/cogl-matrix-stack.c | 5 + cogl/cogl-matrix-stack.h | 19 +++ cogl/cogl-matrix.c | 12 +- cogl/cogl-matrix.h | 20 ++- cogl/cogl-object-private.h | 77 ++++++--- cogl/cogl-object.c | 3 + cogl/cogl-object.h | 22 +++ cogl/cogl-offscreen.h | 13 ++ cogl/cogl-onscreen-template.c | 2 + cogl/cogl-onscreen-template.h | 13 ++ cogl/cogl-onscreen.c | 3 + cogl/cogl-onscreen.h | 13 ++ cogl/cogl-output.c | 2 + cogl/cogl-output.h | 13 ++ cogl/cogl-pipeline.c | 2 + cogl/cogl-pipeline.h | 13 ++ cogl/cogl-pixel-buffer.c | 2 + cogl/cogl-pixel-buffer.h | 13 ++ cogl/cogl-primitive.c | 2 + cogl/cogl-primitive.h | 14 +- cogl/cogl-quaternion.c | 5 + cogl/cogl-quaternion.h | 14 ++ cogl/cogl-renderer.c | 2 + cogl/cogl-renderer.h | 13 ++ cogl/cogl-snippet.c | 2 + cogl/cogl-snippet.h | 9 + cogl/cogl-sub-texture.c | 2 + cogl/cogl-sub-texture.h | 9 + cogl/cogl-swap-chain.c | 3 + cogl/cogl-swap-chain.h | 15 ++ cogl/cogl-texture-2d-sliced.c | 3 + cogl/cogl-texture-2d-sliced.h | 9 + cogl/cogl-texture-2d.c | 3 + cogl/cogl-texture-2d.h | 9 + cogl/cogl-texture-3d.c | 3 + cogl/cogl-texture-3d.h | 9 + cogl/cogl-texture-private.h | 2 +- cogl/cogl-texture-rectangle.c | 3 + cogl/cogl-texture-rectangle.h | 9 + cogl/cogl-texture.c | 3 + cogl/cogl-texture.h | 14 +- cogl/winsys/cogl-texture-pixmap-x11.c | 2 + cogl/winsys/cogl-texture-pixmap-x11.h | 13 ++ 79 files changed, 1099 insertions(+), 42 deletions(-) create mode 100644 cogl/cogl-gtype.c diff --git a/cogl-gst/Makefile.am b/cogl-gst/Makefile.am index 49c68ad9a..ba0c3d82d 100644 --- a/cogl-gst/Makefile.am +++ b/cogl-gst/Makefile.am @@ -68,3 +68,40 @@ pkgconfig_DATA = $(pc_files) EXTRA_DIST += cogl-gst.pc.in DISTCLEANFILES += $(pc_files) + +-include $(INTROSPECTION_MAKEFILE) + +INTROSPECTION_GIRS = + +if HAVE_INTROSPECTION +INTROSPECTION_COMPILER_ARGS=--includedir=$(top_builddir)/cogl + +CoglGst-2.0.gir: libcogl-gst.la Makefile + +CoglGst_2_0_gir_NAMESPACE = CoglGst +CoglGst_2_0_gir_VERSION = 2.0 +CoglGst_2_0_gir_LIBS = $(top_builddir)/cogl/libcogl.la libcogl-gst.la +CoglGst_2_0_gir_FILES = $(source_h) $(source_c) +CoglGst_2_0_gir_CFLAGS = $(AM_CPPFLAGS) $(COGL_GST_DEP_CFLAGS) +CoglGst_2_0_gir_INCLUDES = GObject-2.0 Gst-1.0 GstBase-1.0 +CoglGst_2_0_gir_EXPORT_PACKAGES = cogl-gst-2.0-experimental +CoglGst_2_0_gir_SCANNERFLAGS = \ + --warn-all \ + --identifier-prefix=CoglGst \ + --symbol-prefix=cogl_gst \ + --c-include='cogl-gst/cogl-gst.h' \ + --c-include="gst/gst.h" \ + --include-uninstalled=$(top_builddir)/cogl/Cogl-2.0.gir \ + --pkg gstreamer-1.0 \ + --add-init-section="gst_init(NULL, NULL);" + +INTROSPECTION_GIRS += CoglGst-2.0.gir + +girdir = $(datadir)/gir-1.0 +gir_DATA = $(INTROSPECTION_GIRS) + +typelibdir = $(libdir)/girepository-1.0 +typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib) + +CLEANFILES += $(gir_DATA) $(typelib_DATA) +endif diff --git a/cogl-gst/cogl-gst-video-sink.c b/cogl-gst/cogl-gst-video-sink.c index 42b50a9a0..146108344 100644 --- a/cogl-gst/cogl-gst-video-sink.c +++ b/cogl-gst/cogl-gst-video-sink.c @@ -35,6 +35,8 @@ #include #include +#include "cogl-gtype-private.h" + /* We just need the public Cogl api for cogl-gst but we first need to * undef COGL_COMPILATION to avoid getting an error that normally * checks cogl.h isn't used internally. */ @@ -171,6 +173,34 @@ struct _CoglGstVideoSinkPrivate GstVideoInfo info; }; +/* GTypes */ + +static gpointer +cogl_gst_rectangle_copy (gpointer src) +{ + if (G_LIKELY (src)) + { + CoglGstRectangle *new = g_slice_new (CoglGstRectangle); + memcpy (new, src, sizeof (CoglGstRectangle)); + return new; + } + else + return NULL; +} + +static void +cogl_gst_rectangle_free (gpointer ptr) +{ + g_slice_free (CoglGstRectangle, ptr); +} + +COGL_GTYPE_DEFINE_BOXED (GstRectangle, + gst_rectangle, + cogl_gst_rectangle_copy, + cogl_gst_rectangle_free); + +/**/ + static void cogl_gst_source_finalize (GSource *source) { diff --git a/cogl-gst/cogl-gst-video-sink.h b/cogl-gst/cogl-gst-video-sink.h index 71718c2bc..12a6480d5 100644 --- a/cogl-gst/cogl-gst-video-sink.h +++ b/cogl-gst/cogl-gst-video-sink.h @@ -87,6 +87,10 @@ G_BEGIN_DECLS +#define COGL_GST_GTYPE_DECLARE_TYPE(name) \ + GType cogl_gst_ ## name ## _get_gtype (void) + + #define COGL_GST_TYPE_VIDEO_SINK cogl_gst_video_sink_get_type() #define COGL_GST_VIDEO_SINK(obj) \ @@ -500,6 +504,8 @@ typedef struct _CoglGstRectangle float height; } CoglGstRectangle; +COGL_GST_GTYPE_DECLARE_TYPE (rectangle); + /** * cogl_gst_video_sink_fit_size: * @sink: A #CoglGstVideoSink diff --git a/cogl-pango/Makefile.am b/cogl-pango/Makefile.am index 2f86cb707..64d977119 100644 --- a/cogl-pango/Makefile.am +++ b/cogl-pango/Makefile.am @@ -116,7 +116,23 @@ CoglPango_1_0_gir_SCANNERFLAGS = \ --c-include='cogl-pango/cogl-pango.h' \ --include-uninstalled=$(top_builddir)/cogl/Cogl-1.0.gir -INTROSPECTION_GIRS += CoglPango-1.0.gir +CoglPango-2.0.gir: libcogl-pango.la Makefile + +CoglPango_2_0_gir_NAMESPACE = CoglPango +CoglPango_2_0_gir_VERSION = 2.0 +CoglPango_2_0_gir_LIBS = $(top_builddir)/cogl/libcogl.la libcogl-pango.la +CoglPango_2_0_gir_FILES = $(source_h) $(source_c) +CoglPango_2_0_gir_CFLAGS = $(AM_CPPFLAGS) $(COGL_DEP_CFLAGS) $(COGL_PANGO_DEP_CFLAGS) +CoglPango_2_0_gir_INCLUDES = Pango-1.0 PangoCairo-1.0 +CoglPango_2_0_gir_EXPORT_PACKAGES = cogl-pango-2.0-experimental +CoglPango_2_0_gir_SCANNERFLAGS = \ + --warn-all \ + --identifier-prefix=CoglPango \ + --symbol-prefix=cogl_pango \ + --c-include='cogl-pango/cogl-pango.h' \ + --include-uninstalled=$(top_builddir)/cogl/Cogl-2.0.gir + +INTROSPECTION_GIRS += CoglPango-1.0.gir CoglPango-2.0.gir girdir = $(datadir)/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) diff --git a/cogl-path/cogl-path.c b/cogl-path/cogl-path.c index fd7413143..2b4b3c683 100644 --- a/cogl-path/cogl-path.c +++ b/cogl-path/cogl-path.c @@ -50,6 +50,7 @@ #include "cogl-path/cogl-path.h" #include "cogl-path-private.h" +#include "cogl-gtype-private.h" #include #include @@ -63,6 +64,7 @@ static CoglPrimitive *_cogl_path_get_fill_primitive (CoglPath *path); static void _cogl_path_build_stroke_attribute_buffer (CoglPath *path); COGL_OBJECT_DEFINE (Path, path); +COGL_GTYPE_DEFINE_CLASS (Path, path); static void _cogl_path_data_clear_vbos (CoglPathData *data) diff --git a/cogl-path/cogl2-path-functions.h b/cogl-path/cogl2-path-functions.h index 61f8f650e..72c1fc84f 100644 --- a/cogl-path/cogl2-path-functions.h +++ b/cogl-path/cogl2-path-functions.h @@ -41,9 +41,21 @@ #else #include #endif +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif COGL_BEGIN_DECLS +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_path_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_path_get_gtype (void); +#endif + #define cogl_path_new cogl2_path_new /** * cogl_path_new: @@ -70,7 +82,7 @@ cogl_path_new (void); * Internally the path will share the data until one of the paths is * modified so copying paths should be relatively cheap. * - * Return value: a copy of the path in @path. + * Return value: (transfer full): a copy of the path in @path. * * Since: 2.0 */ diff --git a/cogl/Makefile.am b/cogl/Makefile.am index 9c01227db..62d376290 100644 --- a/cogl/Makefile.am +++ b/cogl/Makefile.am @@ -143,6 +143,15 @@ cogl_experimental_h = \ $(srcdir)/cogl-error.h \ $(NULL) +cogl_additional_experimental_h = \ + $(srcdir)/cogl-bitmap.h \ + $(srcdir)/cogl-color.h \ + $(srcdir)/cogl-matrix.h \ + $(srcdir)/cogl-texture.h \ + $(srcdir)/cogl-types.h \ + $(srcdir)/cogl-gtype-private.h \ + $(NULL) + cogl_nodist_experimental_h = \ $(NULL) @@ -357,6 +366,7 @@ cogl_sources_c = \ $(srcdir)/cogl-flags.h \ $(srcdir)/cogl-bitmask.h \ $(srcdir)/cogl-bitmask.c \ + $(srcdir)/cogl-gtype.c \ $(srcdir)/cogl-gtype-private.h \ $(srcdir)/cogl-point-in-poly-private.h \ $(srcdir)/cogl-point-in-poly.c \ @@ -668,12 +678,28 @@ if UNIT_TESTS Cogl_1_0_gir_LIBS += $(top_builddir)/test-fixtures/libtest-fixtures.la endif Cogl_1_0_gir_FILES = $(cogl_1_public_h) cogl-enum-types.h + +Cogl-2.0.gir: libcogl.la Makefile + +Cogl_2_0_gir_NAMESPACE = Cogl +Cogl_2_0_gir_VERSION = 2.0 +Cogl_2_0_gir_LIBS = libcogl.la +if UNIT_TESTS +Cogl_2_0_gir_LIBS += $(top_builddir)/test-fixtures/libtest-fixtures.la +endif +Cogl_2_0_gir_FILES = $(cogl_experimental_h) $(cogl_additional_experimental_h) cogl-enum-types.h + Cogl_1_0_gir_CFLAGS = $(AM_CPPFLAGS) $(COGL_DEP_CFLAGS) -UCOGL_ENABLE_EXPERIMENTAL_API -UCOGL_ENABLE_EXPERIMENTAL_2_0_API -UCOGL_COMPILATION -D__COGL_H_INSIDE__ -D__COGL_XLIB_H_INSIDE__ -D__COGL_EGL_H_INSIDE__ -D__COGL_GLX_H_INSIDE__ -DCOGL_GIR_SCANNING Cogl_1_0_gir_INCLUDES = GL-1.0 GObject-2.0 Cogl_1_0_gir_EXPORT_PACKAGES = cogl-1.0 Cogl_1_0_gir_SCANNERFLAGS = --warn-all --c-include='cogl/cogl.h' -INTROSPECTION_GIRS += Cogl-1.0.gir +Cogl_2_0_gir_CFLAGS = $(AM_CPPFLAGS) $(COGL_DEP_CFLAGS) -DCOGL_ENABLE_EXPERIMENTAL_API=1 -UCOGL_COMPILATION -D__COGL_H_INSIDE__ -D__COGL_XLIB_H_INSIDE__ -DCOGL_GIR_SCANNING +Cogl_2_0_gir_INCLUDES = GL-1.0 GObject-2.0 +Cogl_2_0_gir_EXPORT_PACKAGES = cogl-2.0-experimental +Cogl_2_0_gir_SCANNERFLAGS = --warn-all --c-include='cogl/cogl.h' --symbol-prefix=cogl --symbol-prefix=cogl2 + +INTROSPECTION_GIRS += Cogl-1.0.gir Cogl-2.0.gir girdir = $(datadir)/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c index fcdd064dd..beaaf2470 100644 --- a/cogl/cogl-atlas-texture.c +++ b/cogl/cogl-atlas-texture.c @@ -52,12 +52,14 @@ #include "cogl-sub-texture.h" #include "cogl-error-private.h" #include "cogl-texture-gl-private.h" +#include "cogl-gtype-private.h" #include static void _cogl_atlas_texture_free (CoglAtlasTexture *sub_tex); COGL_TEXTURE_DEFINE (AtlasTexture, atlas_texture); +COGL_GTYPE_DEFINE_CLASS (AtlasTexture, atlas_texture); static const CoglTextureVtable cogl_atlas_texture_vtable; diff --git a/cogl/cogl-atlas-texture.h b/cogl/cogl-atlas-texture.h index 081df6ec8..79c15b9e9 100644 --- a/cogl/cogl-atlas-texture.h +++ b/cogl/cogl-atlas-texture.h @@ -37,6 +37,10 @@ #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -67,6 +71,14 @@ COGL_BEGIN_DECLS typedef struct _CoglAtlasTexture CoglAtlasTexture; #define COGL_ATLAS_TEXTURE(tex) ((CoglAtlasTexture *) tex) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_atlas_texture_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_atlas_texture_get_gtype (void); +#endif /** * cogl_atlas_texture_new_with_size: diff --git a/cogl/cogl-attribute-buffer.c b/cogl/cogl-attribute-buffer.c index 0e8b41741..8d92d29da 100644 --- a/cogl/cogl-attribute-buffer.c +++ b/cogl/cogl-attribute-buffer.c @@ -39,10 +39,12 @@ #include "cogl-attribute-buffer.h" #include "cogl-attribute-buffer-private.h" #include "cogl-context-private.h" +#include "cogl-gtype-private.h" static void _cogl_attribute_buffer_free (CoglAttributeBuffer *array); COGL_BUFFER_DEFINE (AttributeBuffer, attribute_buffer); +COGL_GTYPE_DEFINE_CLASS (AttributeBuffer, attribute_buffer); CoglAttributeBuffer * cogl_attribute_buffer_new_with_size (CoglContext *context, diff --git a/cogl/cogl-attribute-buffer.h b/cogl/cogl-attribute-buffer.h index a713439b1..189d81ebe 100644 --- a/cogl/cogl-attribute-buffer.h +++ b/cogl/cogl-attribute-buffer.h @@ -45,6 +45,10 @@ typedef struct _CoglAttributeBuffer CoglAttributeBuffer; #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -57,6 +61,15 @@ COGL_BEGIN_DECLS #define COGL_ATTRIBUTE_BUFFER(buffer) ((CoglAttributeBuffer *)(buffer)) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_attribute_buffer_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_attribute_buffer_get_gtype (void); +#endif + /** * cogl_attribute_buffer_new_with_size: * @context: A #CoglContext diff --git a/cogl/cogl-attribute.c b/cogl/cogl-attribute.c index 6264f0919..bcfbf78c6 100644 --- a/cogl/cogl-attribute.c +++ b/cogl/cogl-attribute.c @@ -51,6 +51,7 @@ #include "cogl-pipeline-progend-glsl-private.h" #endif #include "cogl-private.h" +#include "cogl-gtype-private.h" #include #include @@ -64,6 +65,7 @@ static void _cogl_attribute_free (CoglAttribute *attribute); COGL_OBJECT_DEFINE (Attribute, attribute); +COGL_GTYPE_DEFINE_CLASS (Attribute, attribute); static CoglBool validate_cogl_attribute_name (const char *name, diff --git a/cogl/cogl-attribute.h b/cogl/cogl-attribute.h index f9748938f..736b0c675 100644 --- a/cogl/cogl-attribute.h +++ b/cogl/cogl-attribute.h @@ -46,6 +46,10 @@ typedef struct _CoglAttribute CoglAttribute; #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -56,6 +60,15 @@ COGL_BEGIN_DECLS * FIXME */ +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_attribute_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_attribute_get_gtype (void); +#endif + /** * cogl_attribute_new: (constructor) * @attribute_buffer: The #CoglAttributeBuffer containing the actual diff --git a/cogl/cogl-bitmap.c b/cogl/cogl-bitmap.c index 27565d7ba..5b2aa8ed5 100644 --- a/cogl/cogl-bitmap.c +++ b/cogl/cogl-bitmap.c @@ -41,12 +41,14 @@ #include "cogl-context-private.h" #include "cogl-buffer-gl-private.h" #include "cogl-error-private.h" +#include "cogl-gtype-private.h" #include static void _cogl_bitmap_free (CoglBitmap *bmp); COGL_OBJECT_DEFINE (Bitmap, bitmap); +COGL_GTYPE_DEFINE_CLASS (Bitmap, bitmap); static void _cogl_bitmap_free (CoglBitmap *bmp) diff --git a/cogl/cogl-bitmap.h b/cogl/cogl-bitmap.h index fd4f292ff..13b5cd2be 100644 --- a/cogl/cogl-bitmap.h +++ b/cogl/cogl-bitmap.h @@ -44,12 +44,25 @@ typedef struct _CoglBitmap CoglBitmap; #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + #ifdef COGL_HAS_ANDROID_SUPPORT #include #endif COGL_BEGIN_DECLS +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_bitmap_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_bitmap_get_gtype (void); +#endif + /** * SECTION:cogl-bitmap * @short_description: Functions for loading images diff --git a/cogl/cogl-buffer-private.h b/cogl/cogl-buffer-private.h index eab81fda4..0402abb9c 100644 --- a/cogl/cogl-buffer-private.h +++ b/cogl/cogl-buffer-private.h @@ -119,7 +119,7 @@ void _cogl_buffer_register_buffer_type (const CoglObjectClass *klass); #define COGL_BUFFER_DEFINE(TypeName, type_name) \ - COGL_OBJECT_DEFINE_WITH_CODE \ + COGL_OBJECT_DEFINE_WITH_CODE_GTYPE \ (TypeName, type_name, \ _cogl_buffer_register_buffer_type (&_cogl_##type_name##_class)) diff --git a/cogl/cogl-color.c b/cogl/cogl-color.c index c26a2b824..02e501d43 100644 --- a/cogl/cogl-color.c +++ b/cogl/cogl-color.c @@ -38,6 +38,9 @@ #include "cogl-color.h" #include "cogl-fixed.h" #include "cogl-color-private.h" +#include "cogl-gtype-private.h" + +COGL_GTYPE_DEFINE_BOXED (Color, color, cogl_color_copy, cogl_color_free); CoglColor * cogl_color_new (void) diff --git a/cogl/cogl-color.h b/cogl/cogl-color.h index e52e92aac..bdb0bfaf6 100644 --- a/cogl/cogl-color.h +++ b/cogl/cogl-color.h @@ -48,8 +48,21 @@ #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_color_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_color_get_gtype (void); +#endif + /** * cogl_color_new: * diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c index 2c0057947..a7eed29ab 100644 --- a/cogl/cogl-context.c +++ b/cogl/cogl-context.c @@ -56,6 +56,7 @@ #include "cogl-gpu-info-private.h" #include "cogl-config-private.h" #include "cogl-error-private.h" +#include "cogl-gtype-private.h" #include "cogl/deprecated/cogl-framebuffer-deprecated.h" @@ -78,6 +79,7 @@ static void _cogl_context_free (CoglContext *context); COGL_OBJECT_DEFINE (Context, context); +COGL_GTYPE_DEFINE_CLASS (Context, context); extern void _cogl_create_context_driver (CoglContext *context); diff --git a/cogl/cogl-context.h b/cogl/cogl-context.h index f7cd2e8ad..07badeb44 100644 --- a/cogl/cogl-context.h +++ b/cogl/cogl-context.h @@ -45,6 +45,10 @@ typedef struct _CoglContext CoglContext; #include #include #include + +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif #ifdef COGL_HAS_EGL_PLATFORM_ANDROID_SUPPORT #include #endif @@ -97,6 +101,15 @@ COGL_BEGIN_DECLS #define COGL_CONTEXT(OBJECT) ((CoglContext *)OBJECT) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_context_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_context_get_gtype (void); +#endif + /** * cogl_context_new: (constructor) * @display: (allow-none): A #CoglDisplay pointer diff --git a/cogl/cogl-display.c b/cogl/cogl-display.c index 54852d6f9..ced922fa9 100644 --- a/cogl/cogl-display.c +++ b/cogl/cogl-display.c @@ -44,10 +44,12 @@ #ifdef COGL_HAS_WAYLAND_EGL_SERVER_SUPPORT #include "cogl-wayland-server.h" #endif +#include "cogl-gtype-private.h" static void _cogl_display_free (CoglDisplay *display); COGL_OBJECT_DEFINE (Display, display); +COGL_GTYPE_DEFINE_CLASS (Display, display); static const CoglWinsysVtable * _cogl_display_get_winsys (CoglDisplay *display) diff --git a/cogl/cogl-display.h b/cogl/cogl-display.h index 68e961674..ae3f3c960 100644 --- a/cogl/cogl-display.h +++ b/cogl/cogl-display.h @@ -40,6 +40,10 @@ #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS #ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT @@ -72,6 +76,15 @@ typedef struct _CoglDisplay CoglDisplay; #define COGL_DISPLAY(OBJECT) ((CoglDisplay *)OBJECT) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_display_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_display_get_gtype (void); +#endif + /** * cogl_display_new: * @renderer: A #CoglRenderer diff --git a/cogl/cogl-euler.c b/cogl/cogl-euler.c index fce6b497b..f877bbc6e 100644 --- a/cogl/cogl-euler.c +++ b/cogl/cogl-euler.c @@ -36,10 +36,15 @@ #include #include #include +#include "cogl-gtype-private.h" #include #include +COGL_GTYPE_DEFINE_BOXED (Euler, euler, + cogl_euler_copy, + cogl_euler_free); + void cogl_euler_init (CoglEuler *euler, float heading, diff --git a/cogl/cogl-euler.h b/cogl/cogl-euler.h index 62d4b8241..4ccbb2a66 100644 --- a/cogl/cogl-euler.h +++ b/cogl/cogl-euler.h @@ -38,6 +38,10 @@ #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -162,6 +166,15 @@ struct _CoglEuler }; COGL_STRUCT_SIZE_ASSERT (CoglEuler, 32); +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_euler_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_euler_get_gtype (void); +#endif + /** * cogl_euler_init: * @euler: The #CoglEuler angle to initialize diff --git a/cogl/cogl-frame-info.c b/cogl/cogl-frame-info.c index 0f7dddaad..2114a64b5 100644 --- a/cogl/cogl-frame-info.c +++ b/cogl/cogl-frame-info.c @@ -33,10 +33,12 @@ #endif #include "cogl-frame-info-private.h" +#include "cogl-gtype-private.h" static void _cogl_frame_info_free (CoglFrameInfo *info); COGL_OBJECT_DEFINE (FrameInfo, frame_info); +COGL_GTYPE_DEFINE_CLASS (FrameInfo, frame_info); CoglFrameInfo * _cogl_frame_info_new (void) diff --git a/cogl/cogl-frame-info.h b/cogl/cogl-frame-info.h index ceb57c9df..7304c530f 100644 --- a/cogl/cogl-frame-info.h +++ b/cogl/cogl-frame-info.h @@ -39,6 +39,10 @@ #include #include + +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif #include G_BEGIN_DECLS @@ -46,6 +50,15 @@ G_BEGIN_DECLS typedef struct _CoglFrameInfo CoglFrameInfo; #define COGL_FRAME_INFO(X) ((CoglFrameInfo *)(X)) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_frame_info_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_frame_info_get_gtype (void); +#endif + /** * cogl_is_frame_info: * @object: A #CoglObject pointer diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c index e14c72ac9..3245d61eb 100644 --- a/cogl/cogl-framebuffer.c +++ b/cogl/cogl-framebuffer.c @@ -55,6 +55,7 @@ #include "cogl-primitives-private.h" #include "cogl-error-private.h" #include "cogl-texture-gl-private.h" +#include "cogl-gtype-private.h" extern CoglObjectClass _cogl_onscreen_class; @@ -67,7 +68,9 @@ static void _cogl_offscreen_free (CoglOffscreen *offscreen); COGL_OBJECT_DEFINE_WITH_CODE (Offscreen, offscreen, _cogl_offscreen_class.virt_unref = _cogl_framebuffer_unref); +COGL_GTYPE_DEFINE_CLASS (Offscreen, offscreen); COGL_OBJECT_DEFINE_DEPRECATED_REF_COUNTING (offscreen); +COGL_GTYPE_DEFINE_INTERFACE (Framebuffer, framebuffer); /* XXX: * The CoglObject macros don't support any form of inheritance, so for diff --git a/cogl/cogl-framebuffer.h b/cogl/cogl-framebuffer.h index 3c93e0de3..347284f65 100644 --- a/cogl/cogl-framebuffer.h +++ b/cogl/cogl-framebuffer.h @@ -59,6 +59,9 @@ typedef struct _CoglFramebuffer CoglFramebuffer; #include #include #endif +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif COGL_BEGIN_DECLS @@ -102,6 +105,15 @@ COGL_BEGIN_DECLS #ifdef COGL_ENABLE_EXPERIMENTAL_API +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_framebuffer_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_framebuffer_get_gtype (void); +#endif + /** * cogl_framebuffer_allocate: * @framebuffer: A #CoglFramebuffer @@ -1804,4 +1816,3 @@ cogl_is_framebuffer (void *object); COGL_END_DECLS #endif /* __COGL_FRAMEBUFFER_H */ - diff --git a/cogl/cogl-gles2-context.c b/cogl/cogl-gles2-context.c index 516339eb1..33c438798 100644 --- a/cogl/cogl-gles2-context.c +++ b/cogl/cogl-gles2-context.c @@ -53,10 +53,12 @@ #include "cogl-texture-2d-private.h" #include "cogl-pipeline-opengl-private.h" #include "cogl-error-private.h" +#include "cogl-gtype-private.h" static void _cogl_gles2_context_free (CoglGLES2Context *gles2_context); COGL_OBJECT_DEFINE (GLES2Context, gles2_context); +COGL_GTYPE_DEFINE_CLASS (GLES2Context, gles2_context); static CoglGLES2Context *current_gles2_context; diff --git a/cogl/cogl-gles2.h b/cogl/cogl-gles2.h index 49de955fd..84c9ba15d 100644 --- a/cogl/cogl-gles2.h +++ b/cogl/cogl-gles2.h @@ -142,11 +142,24 @@ struct _CoglGLES2Vtable #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + #undef COGL_EXT_BEGIN #undef COGL_EXT_FUNCTION #undef COGL_EXT_END }; +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_gles2_context_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_gles2_context_get_gtype (void); +#endif + uint32_t _cogl_gles2_context_error_quark (void); diff --git a/cogl/cogl-gtype-private.h b/cogl/cogl-gtype-private.h index 4889e7e83..21590da69 100644 --- a/cogl/cogl-gtype-private.h +++ b/cogl/cogl-gtype-private.h @@ -28,21 +28,47 @@ * */ -#include -#include - #ifndef __COGL_GTYPE_PRIVATE_H__ #define __COGL_GTYPE_PRIVATE_H__ -#define COGL_GTYPE_DEFINE_BOXED(Name, underscore_name, copy_func, free_func) \ +#include "config.h" + +#include +#include + +#include "cogl-object-private.h" + +/* Move this to public headers? */ +typedef struct _CoglGtypeObject CoglGtypeObject; +typedef struct _CoglGtypeClass CoglGtypeClass; + +struct _CoglGtypeObject +{ + GTypeInstance parent_instance; + + guint dummy; +}; + +struct _CoglGtypeClass +{ + GTypeClass base_class; + + guint dummy; +}; + +#define I_(str) (g_intern_static_string ((str))) + +/**/ + +#define COGL_GTYPE_DEFINE_BOXED(Name,underscore_name,copy_func,free_func) \ GType \ -cogl_gtype_ ## underscore_name ## _get_type (void) \ +cogl_##underscore_name##_get_gtype (void) \ { \ static volatile size_t type_volatile = 0; \ if (g_once_init_enter (&type_volatile)) \ { \ GType type = \ - g_boxed_type_register_static (g_intern_static_string ("Cogl" Name), \ + g_boxed_type_register_static (g_intern_static_string (I_("Cogl" # Name)), \ (GBoxedCopyFunc)copy_func, \ (GBoxedFreeFunc)free_func); \ g_once_init_leave (&type_volatile, type); \ @@ -50,5 +76,198 @@ cogl_gtype_ ## underscore_name ## _get_type (void) \ return type_volatile; \ } -#endif /* __COGL_GTYPE_PRIVATE_H__ */ +#define COGL_GTYPE_IMPLEMENT_INTERFACE(name) { \ + const GInterfaceInfo g_implement_interface_info = { \ + (GInterfaceInitFunc) _cogl_gtype_dummy_iface_init, NULL, NULL \ + }; \ + g_type_add_interface_static (fundamental_type_id, \ + cogl_##name##_get_gtype(), \ + &g_implement_interface_info); \ + } +#define _COGL_GTYPE_DEFINE_BASE_CLASS_BEGIN(Name,name) \ +GType \ +cogl_##name##_get_gtype (void) \ +{ \ + static volatile gsize type_id__volatile = 0; \ + if (g_once_init_enter (&type_id__volatile)) \ + { \ + static const GTypeFundamentalInfo finfo = { \ + (G_TYPE_FLAG_CLASSED | \ + G_TYPE_FLAG_INSTANTIATABLE | \ + G_TYPE_FLAG_DERIVABLE | \ + G_TYPE_FLAG_DEEP_DERIVABLE), \ + }; \ + static const GTypeValueTable value_table = { \ + _cogl_gtype_object_init_value, \ + _cogl_gtype_object_free_value, \ + _cogl_gtype_object_copy_value, \ + _cogl_gtype_object_peek_pointer, \ + "p", \ + _cogl_gtype_object_collect_value, \ + "p", \ + _cogl_gtype_object_lcopy_value, \ + }; \ + const GTypeInfo node_info = { \ + sizeof (CoglObjectClass), \ + (GBaseInitFunc) _cogl_gtype_object_class_base_init, \ + (GBaseFinalizeFunc) _cogl_gtype_object_class_base_finalize, \ + (GClassInitFunc) _cogl_gtype_object_class_init, \ + (GClassFinalizeFunc) NULL, \ + NULL, \ + sizeof (CoglObject), \ + 0, \ + (GInstanceInitFunc) _cogl_gtype_object_init, \ + &value_table, \ + }; \ + GType fundamental_type_id = \ + g_type_register_fundamental (g_type_fundamental_next (), \ + I_("Cogl" # Name), \ + &node_info, &finfo, \ + G_TYPE_FLAG_ABSTRACT); \ + g_once_init_leave (&type_id__volatile, \ + fundamental_type_id); + +#define _COGL_GTYPE_DEFINE_BASE_CLASS_END() \ + } \ + return type_id__volatile; \ + } + +#define COGL_GTYPE_DEFINE_BASE_CLASS(Name,name,interfaces...) \ + _COGL_GTYPE_DEFINE_BASE_CLASS_BEGIN(Name,name) \ + {interfaces;} \ + _COGL_GTYPE_DEFINE_BASE_CLASS_END() + +#define _COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_BEGIN(Name,name) \ + \ + static void name##_default_init (Name##Interface *klass); \ + GType \ + name##_get_gtype (void) \ + { \ + static volatile gsize type_id__volatile = 0; \ + if (g_once_init_enter (&type_id__volatile)) \ + { \ + GType fundamental_type_id = \ + g_type_register_static_simple (G_TYPE_INTERFACE, \ + g_intern_static_string (#Name), \ + sizeof (Name##Interface), \ + (GClassInitFunc)name##_default_init, \ + 0, \ + (GInstanceInitFunc)NULL, \ + (GTypeFlags) 0); \ + g_type_interface_add_prerequisite (fundamental_type_id, \ + cogl_object_get_gtype()); \ + { /* custom code follows */ + +#define _COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_END() \ + /* following custom code */ \ + } \ + g_once_init_leave (&type_id__volatile, \ + fundamental_type_id); \ + } \ + return type_id__volatile; \ + } /* closes name##_get_type() */ + + +#define COGL_GTYPE_DEFINE_INTERFACE(Name,name) \ + typedef struct _Cogl##Name##Iface Cogl##Name##Iface; \ + typedef Cogl##Name##Iface Cogl##Name##Interface; \ + struct _Cogl##Name##Iface \ + { \ + /*< private >*/ \ + GTypeInterface g_iface; \ + }; \ + _COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_BEGIN (Cogl##Name, cogl_##name) \ + _COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_END () \ + static void \ + cogl_##name##_default_init (Cogl##Name##Interface *iface) \ + { \ + } + +#define _COGL_GTYPE_DEFINE_TYPE_EXTENDED_BEGIN(Name,name,parent,flags) \ + \ + static void name##_init (Name *self); \ + static void name##_class_init (Name##Class *klass); \ + static gpointer name##_parent_class = NULL; \ + static gint Name##_private_offset; \ + \ + _G_DEFINE_TYPE_EXTENDED_CLASS_INIT(Name, name) \ + \ + static inline gpointer \ + name##_get_instance_private (Name *self) \ + { \ + return (G_STRUCT_MEMBER_P (self, Name ##_private_offset)); \ + } \ + \ + GType \ + name##_get_gtype (void) \ + { \ + static volatile gsize type_id__volatile = 0; \ + if (g_once_init_enter (&type_id__volatile)) \ + { \ + GType fundamental_type_id = \ + g_type_register_static_simple (parent, \ + g_intern_static_string (#Name), \ + sizeof (Name##Class), \ + (GClassInitFunc) name##_class_intern_init, \ + sizeof (Name), \ + (GInstanceInitFunc) name##_init, \ + (GTypeFlags) flags); \ + { /* custom code follows */ + +#define _COGL_GTYPE_DEFINE_TYPE_EXTENDED_END() \ + /* following custom code */ \ + } \ + g_once_init_leave (&type_id__volatile, \ + fundamental_type_id); \ + } \ + return type_id__volatile; \ + } /* closes name##_get_type() */ + + +#define COGL_GTYPE_DEFINE_CLASS(Name,name,interfaces...) \ + typedef struct _Cogl##Name##Class Cogl##Name##Class; \ + struct _Cogl##Name##Class { \ + CoglObjectClass parent_class; \ + }; \ + _COGL_GTYPE_DEFINE_TYPE_EXTENDED_BEGIN(Cogl##Name, \ + cogl_##name, \ + cogl_object_get_gtype(), \ + 0) \ + {interfaces;} \ + _COGL_GTYPE_DEFINE_TYPE_EXTENDED_END() \ + static void \ + cogl_##name##_init (Cogl##Name *instance) \ + { \ + } \ + static void \ + cogl_##name##_class_init (Cogl##Name##Class *klass) \ + { \ + } + +void _cogl_gtype_object_init_value (GValue *value); +void _cogl_gtype_object_free_value (GValue *value); +void _cogl_gtype_object_copy_value (const GValue *src, + GValue *dst); +gpointer _cogl_gtype_object_peek_pointer (const GValue *value); +gchar *_cogl_gtype_object_collect_value (GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags); +gchar *_cogl_gtype_object_lcopy_value (const GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags); + +void _cogl_gtype_object_class_base_init (CoglObjectClass *klass); +void _cogl_gtype_object_class_base_finalize (CoglObjectClass *klass); +void _cogl_gtype_object_class_init (CoglObjectClass *klass); +void _cogl_gtype_object_init (CoglObject *object); + +void cogl_object_value_set_object (GValue *value, + gpointer object); +gpointer cogl_object_value_get_object (const GValue *value); + +void _cogl_gtype_dummy_iface_init (gpointer iface); + +#endif /* __COGL_GTYPE_PRIVATE_H__ */ diff --git a/cogl/cogl-gtype.c b/cogl/cogl-gtype.c new file mode 100644 index 000000000..314d8e41f --- /dev/null +++ b/cogl/cogl-gtype.c @@ -0,0 +1,153 @@ +#include "cogl-gtype-private.h" + +#include + +void +_cogl_gtype_object_init_value (GValue *value) +{ + value->data[0].v_pointer = NULL; +} + +void +_cogl_gtype_object_free_value (GValue *value) +{ + if (value->data[0].v_pointer != NULL) + cogl_object_unref (value->data[0].v_pointer); +} + +void +_cogl_gtype_object_copy_value (const GValue *src, + GValue *dst) +{ + if (src->data[0].v_pointer != NULL) + dst->data[0].v_pointer = cogl_object_ref (src->data[0].v_pointer); + else + dst->data[0].v_pointer = NULL; +} + +gpointer +_cogl_gtype_object_peek_pointer (const GValue *value) +{ + return value->data[0].v_pointer; +} + +gchar * +_cogl_gtype_object_collect_value (GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) +{ + CoglObject *object; + + object = collect_values[0].v_pointer; + + if (object == NULL) + { + value->data[0].v_pointer = NULL; + return NULL; + } + + if (object->klass == NULL) + return g_strconcat ("invalid unclassed CoglObject pointer for " + "value type '", + G_VALUE_TYPE_NAME (value), + "'", + NULL); + + value->data[0].v_pointer = cogl_object_ref (object); + + return NULL; +} + +gchar * +_cogl_gtype_object_lcopy_value (const GValue *value, + guint n_collect_values, + GTypeCValue *collect_values, + guint collect_flags) +{ + CoglObject **object_p = collect_values[0].v_pointer; + + if (object_p == NULL) + return g_strconcat ("value location for '", + G_VALUE_TYPE_NAME (value), + "' passed as NULL", + NULL); + + if (value->data[0].v_pointer == NULL) + *object_p = NULL; + else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) + *object_p = value->data[0].v_pointer; + else + *object_p = cogl_object_ref (value->data[0].v_pointer); + + return NULL; +} + +void +_cogl_gtype_object_class_base_init (CoglObjectClass *klass) +{ +} + +void +_cogl_gtype_object_class_base_finalize (CoglObjectClass *klass) +{ +} + +void +_cogl_gtype_object_class_init (CoglObjectClass *klass) +{ +} + +void +_cogl_gtype_object_init (CoglObject *object) +{ +} + +void +_cogl_gtype_dummy_iface_init (gpointer iface) +{ +} + +/** + * cogl_object_value_set_object: + * @value: a #GValue initialized with %COGL_GTYPE_TYPE_OBJECT + * @object: (type Cogl.GtypeObject) (allow-none): a #CoglGtypeObject, or %NULL + * + * Sets the contents of a #GValue initialized with %COGL_GTYPE_TYPE_OBJECT. + * + */ +void +cogl_object_value_set_object (GValue *value, + gpointer object) +{ + CoglObject *old_object; + + old_object = value->data[0].v_pointer; + + if (object != NULL) + { + /* take over ownership */ + value->data[0].v_pointer = object; + } + else + value->data[0].v_pointer = NULL; + + if (old_object != NULL) + cogl_object_unref (old_object); +} + +/** + * cogl_object_value_get_object: + * @value: a #GValue initialized with %COGL_GTYPE_TYPE_OBJECT + * + * Retrieves a pointer to the #CoglGtypeObject contained inside + * the passed #GValue. + * + * Return value: (transfer none) (type Cogl.GtypeObject): a pointer to + * a #CoglGtypeObject, or %NULL + */ +gpointer +cogl_object_value_get_object (const GValue *value) +{ + return value->data[0].v_pointer; +} diff --git a/cogl/cogl-index-buffer.c b/cogl/cogl-index-buffer.c index 33190d2b9..cddaf4762 100644 --- a/cogl/cogl-index-buffer.c +++ b/cogl/cogl-index-buffer.c @@ -39,10 +39,12 @@ #include "cogl-indices.h" #include "cogl-indices-private.h" #include "cogl-context-private.h" +#include "cogl-gtype-private.h" static void _cogl_index_buffer_free (CoglIndexBuffer *indices); COGL_BUFFER_DEFINE (IndexBuffer, index_buffer); +COGL_GTYPE_DEFINE_CLASS (IndexBuffer, index_buffer); /* XXX: Unlike the wiki design this just takes a size. A single * indices buffer should be able to contain multiple ranges of indices diff --git a/cogl/cogl-index-buffer.h b/cogl/cogl-index-buffer.h index 2eef2aa0f..204c85856 100644 --- a/cogl/cogl-index-buffer.h +++ b/cogl/cogl-index-buffer.h @@ -40,6 +40,10 @@ #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -54,6 +58,15 @@ COGL_BEGIN_DECLS typedef struct _CoglIndexBuffer CoglIndexBuffer; +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_index_buffer_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_index_buffer_get_gtype (void); +#endif + /** * cogl_index_buffer_new: * @context: A #CoglContext diff --git a/cogl/cogl-indices.c b/cogl/cogl-indices.c index 581a4c214..22568304c 100644 --- a/cogl/cogl-indices.c +++ b/cogl/cogl-indices.c @@ -42,12 +42,14 @@ #include "cogl-indices.h" #include "cogl-indices-private.h" #include "cogl-index-buffer.h" +#include "cogl-gtype-private.h" #include static void _cogl_indices_free (CoglIndices *indices); COGL_OBJECT_DEFINE (Indices, indices); +COGL_GTYPE_DEFINE_CLASS (Indices, indices); static size_t sizeof_indices_type (CoglIndicesType type) diff --git a/cogl/cogl-indices.h b/cogl/cogl-indices.h index 636f9a1ca..3cc923911 100644 --- a/cogl/cogl-indices.h +++ b/cogl/cogl-indices.h @@ -45,6 +45,10 @@ typedef struct _CoglIndices CoglIndices; #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -105,6 +109,15 @@ COGL_BEGIN_DECLS * for drawing quads as above. */ +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_indices_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_indices_get_gtype (void); +#endif + CoglIndices * cogl_indices_new (CoglContext *context, CoglIndicesType type, diff --git a/cogl/cogl-matrix-stack.c b/cogl/cogl-matrix-stack.c index 62ef30d9b..400855f60 100644 --- a/cogl/cogl-matrix-stack.c +++ b/cogl/cogl-matrix-stack.c @@ -43,10 +43,15 @@ #include "cogl-offscreen.h" #include "cogl-matrix-private.h" #include "cogl-magazine-private.h" +#include "cogl-gtype-private.h" static void _cogl_matrix_stack_free (CoglMatrixStack *stack); COGL_OBJECT_DEFINE (MatrixStack, matrix_stack); +COGL_GTYPE_DEFINE_CLASS (MatrixStack, matrix_stack); +COGL_GTYPE_DEFINE_BOXED (MatrixEntry, matrix_entry, + cogl_matrix_entry_ref, + cogl_matrix_entry_unref); static CoglMagazine *cogl_matrix_stack_magazine; static CoglMagazine *cogl_matrix_stack_matrices_magazine; diff --git a/cogl/cogl-matrix-stack.h b/cogl/cogl-matrix-stack.h index cd09d4b8a..6ea323a32 100644 --- a/cogl/cogl-matrix-stack.h +++ b/cogl/cogl-matrix-stack.h @@ -134,6 +134,15 @@ */ typedef struct _CoglMatrixStack CoglMatrixStack; +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_matrix_stack_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_matrix_stack_get_gtype (void); +#endif + /** * CoglMatrixEntry: * @@ -170,6 +179,16 @@ typedef struct _CoglMatrixStack CoglMatrixStack; */ typedef struct _CoglMatrixEntry CoglMatrixEntry; +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_matrix_entry_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_matrix_entry_get_gtype (void); +#endif + + /** * cogl_matrix_stack_new: * @ctx: A #CoglContext diff --git a/cogl/cogl-matrix.c b/cogl/cogl-matrix.c index 6a8cef5f5..fd0f6af3c 100644 --- a/cogl/cogl-matrix.c +++ b/cogl/cogl-matrix.c @@ -85,12 +85,10 @@ #include #include -#ifdef _COGL_SUPPORTS_GTYPE_INTEGRATION #include -COGL_GTYPE_DEFINE_BOXED ("Matrix", matrix, +COGL_GTYPE_DEFINE_BOXED (Matrix, matrix, cogl_matrix_copy, cogl_matrix_free); -#endif /* * Symbolic names to some of the entries in the matrix @@ -2305,3 +2303,11 @@ cogl_matrix_transpose (CoglMatrix *matrix) cogl_matrix_init_from_array (matrix, new_values); } + +#ifdef COGL_HAS_GTYPE_SUPPORT +GType +cogl_gtype_matrix_get_type (void) +{ + return cogl_matrix_get_gtype (); +} +#endif diff --git a/cogl/cogl-matrix.h b/cogl/cogl-matrix.h index 5b3ba3787..58ec5c760 100644 --- a/cogl/cogl-matrix.h +++ b/cogl/cogl-matrix.h @@ -46,6 +46,9 @@ #ifdef COGL_ENABLE_EXPERIMENTAL_API #include #endif +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif COGL_BEGIN_DECLS @@ -123,6 +126,7 @@ struct _CoglMatrix }; COGL_STRUCT_SIZE_ASSERT (CoglMatrix, 128 + sizeof (unsigned long) * 3); + /** * cogl_matrix_init_identity: * @matrix: A 4x4 transformation matrix @@ -787,9 +791,16 @@ cogl_matrix_transpose (CoglMatrix *matrix); void cogl_debug_matrix_print (const CoglMatrix *matrix); -#ifdef _COGL_SUPPORTS_GTYPE_INTEGRATION +#ifdef COGL_HAS_GTYPE_SUPPORT -#define COGL_GTYPE_TYPE_MATRIX (cogl_gtype_matrix_get_type ()) +#define COGL_GTYPE_TYPE_MATRIX (cogl_matrix_get_gtype ()) + +/** + * cogl_matrix_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_matrix_get_gtype (void); /** * cogl_gtype_matrix_get_type: @@ -797,13 +808,14 @@ cogl_debug_matrix_print (const CoglMatrix *matrix); * Returns: the GType for the registered "CoglMatrix" boxed type. This * can be used for example to define GObject properties that accept a * #CoglMatrix value. + * + * Deprecated: 1.18: Use cogl_matrix_get_gtype() instead. */ GType cogl_gtype_matrix_get_type (void); -#endif /* _COGL_SUPPORTS_GTYPE_INTEGRATION */ +#endif /* COGL_HAS_GTYPE_SUPPORT*/ COGL_END_DECLS #endif /* __COGL_MATRIX_H */ - diff --git a/cogl/cogl-object-private.h b/cogl/cogl-object-private.h index cf5d18943..61ada8f3a 100644 --- a/cogl/cogl-object-private.h +++ b/cogl/cogl-object-private.h @@ -57,6 +57,9 @@ typedef void (*CoglUserDataDestroyInternalCallback) (void *user_data, typedef struct _CoglObjectClass { +#ifdef COGL_HAS_GTYPE_SUPPORT + GTypeClass base_class; +#endif const char *name; void *virt_free; void *virt_unref; @@ -80,7 +83,7 @@ typedef struct */ struct _CoglObject { - CoglObjectClass *klass; + CoglObjectClass *klass; /* equivalent to GTypeInstance */ CoglUserDataEntry user_data_entry[ COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES]; @@ -124,6 +127,14 @@ struct _CoglObject #endif /* COGL_OBJECT_DEBUG */ +#ifdef COGL_HAS_GTYPE_SUPPORT +#define _COGL_GTYPE_INIT_CLASS(type_name) do { \ + _cogl_##type_name##_class.base_class.g_type = cogl_##type_name##_get_gtype (); \ +} while (0) +#else +#define _COGL_GTYPE_INIT_CLASS(type_name) +#endif + #define COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \ \ CoglObjectClass _cogl_##type_name##_class; \ @@ -148,6 +159,28 @@ _cogl_object_##type_name##_indirect_free (CoglObject *obj) \ _cogl_object_##type_name##_dec (); \ } \ \ +static void \ +_cogl_object_##type_name##_class_init (void) \ +{ \ + _cogl_object_##type_name##_count = 0; \ + \ + if (_cogl_debug_instances == NULL) \ + _cogl_debug_instances = \ + g_hash_table_new (g_str_hash, g_str_equal); \ + \ + _cogl_##type_name##_class.virt_free = \ + _cogl_object_##type_name##_indirect_free; \ + _cogl_##type_name##_class.virt_unref = \ + _cogl_object_default_unref; \ + _cogl_##type_name##_class.name = "Cogl"#TypeName; \ + \ + g_hash_table_insert (_cogl_debug_instances, \ + (void *) _cogl_##type_name##_class.name, \ + &_cogl_object_##type_name##_count); \ + \ + { code; } \ +} \ + \ static Cogl##TypeName * \ _cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \ { \ @@ -160,23 +193,7 @@ _cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \ obj->klass = &_cogl_##type_name##_class; \ if (!obj->klass->virt_free) \ { \ - _cogl_object_##type_name##_count = 0; \ - \ - if (_cogl_debug_instances == NULL) \ - _cogl_debug_instances = \ - g_hash_table_new (g_str_hash, g_str_equal); \ - \ - obj->klass->virt_free = \ - _cogl_object_##type_name##_indirect_free; \ - obj->klass->virt_unref = \ - _cogl_object_default_unref; \ - obj->klass->name = "Cogl"#TypeName, \ - \ - g_hash_table_insert (_cogl_debug_instances, \ - (void *) obj->klass->name, \ - &_cogl_object_##type_name##_count); \ - \ - { code; } \ + _cogl_object_##type_name##_class_init (); \ } \ \ _cogl_object_##type_name##_inc (); \ @@ -184,9 +201,29 @@ _cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \ return new_obj; \ } +#define COGL_OBJECT_DEFINE_WITH_CODE_GTYPE(TypeName, type_name, code) \ + \ +COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, \ + type_name, \ + do { code; } while (0); \ + _COGL_GTYPE_INIT_CLASS (type_name)) \ + \ +CoglBool \ +cogl_is_##type_name (void *object) \ +{ \ + CoglObject *obj = object; \ + \ + if (object == NULL) \ + return FALSE; \ + \ + return obj->klass == &_cogl_##type_name##_class; \ +} + #define COGL_OBJECT_DEFINE_WITH_CODE(TypeName, type_name, code) \ \ -COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \ +COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, \ + type_name, \ + do { code; } while (0);) \ \ CoglBool \ cogl_is_##type_name (void *object) \ @@ -246,7 +283,7 @@ cogl_##type_name##_unref (void *object) \ } #define COGL_OBJECT_DEFINE(TypeName, type_name) \ - COGL_OBJECT_DEFINE_WITH_CODE (TypeName, type_name, (void) 0) + COGL_OBJECT_DEFINE_WITH_CODE_GTYPE (TypeName, type_name, (void) 0) #define COGL_OBJECT_INTERNAL_DEFINE(TypeName, type_name) \ COGL_OBJECT_INTERNAL_DEFINE_WITH_CODE (TypeName, type_name, (void) 0) diff --git a/cogl/cogl-object.c b/cogl/cogl-object.c index fe9a27970..452f625f9 100644 --- a/cogl/cogl-object.c +++ b/cogl/cogl-object.c @@ -39,6 +39,9 @@ #include "cogl-util.h" #include "cogl-types.h" #include "cogl-object-private.h" +#include "cogl-gtype-private.h" + +COGL_GTYPE_DEFINE_BASE_CLASS (Object, object); void * cogl_object_ref (void *object) diff --git a/cogl/cogl-object.h b/cogl/cogl-object.h index e07a9236a..a0bed88dc 100644 --- a/cogl/cogl-object.h +++ b/cogl/cogl-object.h @@ -33,12 +33,34 @@ #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS typedef struct _CoglObject CoglObject; #define COGL_OBJECT(X) ((CoglObject *)X) +/** + * CoglObject: + * + * Ref Func: cogl_object_ref + * Unref Func: cogl_object_unref + * Set Value Func: cogl_object_value_set_object + * Get Value Func: cogl_object_value_get_object + */ + +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_object_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_object_get_gtype (void); +#endif + /** * cogl_object_ref: (skip) * @object: a #CoglObject diff --git a/cogl/cogl-offscreen.h b/cogl/cogl-offscreen.h index 7de4bd779..9c844426c 100644 --- a/cogl/cogl-offscreen.h +++ b/cogl/cogl-offscreen.h @@ -38,6 +38,10 @@ #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -52,6 +56,15 @@ typedef struct _CoglOffscreen CoglOffscreen; #define COGL_OFFSCREEN(X) ((CoglOffscreen *)X) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_offscreen_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_offscreen_get_gtype (void); +#endif + /* Offscreen api */ /** diff --git a/cogl/cogl-onscreen-template.c b/cogl/cogl-onscreen-template.c index ce9458791..5a5e54c19 100644 --- a/cogl/cogl-onscreen-template.c +++ b/cogl/cogl-onscreen-template.c @@ -37,12 +37,14 @@ #include "cogl-framebuffer-private.h" #include "cogl-onscreen-template-private.h" +#include "cogl-gtype-private.h" #include static void _cogl_onscreen_template_free (CoglOnscreenTemplate *onscreen_template); COGL_OBJECT_DEFINE (OnscreenTemplate, onscreen_template); +COGL_GTYPE_DEFINE_CLASS (OnscreenTemplate, onscreen_template); static void _cogl_onscreen_template_free (CoglOnscreenTemplate *onscreen_template) diff --git a/cogl/cogl-onscreen-template.h b/cogl/cogl-onscreen-template.h index 7b22b7757..cd1d853e3 100644 --- a/cogl/cogl-onscreen-template.h +++ b/cogl/cogl-onscreen-template.h @@ -39,12 +39,25 @@ #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS typedef struct _CoglOnscreenTemplate CoglOnscreenTemplate; #define COGL_ONSCREEN_TEMPLATE(OBJECT) ((CoglOnscreenTemplate *)OBJECT) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_onscreen_template_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_onscreen_template_get_gtype (void); +#endif + CoglOnscreenTemplate * cogl_onscreen_template_new (CoglSwapChain *swap_chain); diff --git a/cogl/cogl-onscreen.c b/cogl/cogl-onscreen.c index bc20f54f1..8ca97709e 100644 --- a/cogl/cogl-onscreen.c +++ b/cogl/cogl-onscreen.c @@ -42,12 +42,15 @@ #include "cogl1-context.h" #include "cogl-closure-list-private.h" #include "cogl-poll-private.h" +#include "cogl-gtype-private.h" static void _cogl_onscreen_free (CoglOnscreen *onscreen); COGL_OBJECT_DEFINE_WITH_CODE (Onscreen, onscreen, _cogl_onscreen_class.virt_unref = _cogl_framebuffer_unref); +COGL_GTYPE_DEFINE_CLASS (Onscreen, onscreen, + COGL_GTYPE_IMPLEMENT_INTERFACE (framebuffer)); static void _cogl_onscreen_init_from_template (CoglOnscreen *onscreen, diff --git a/cogl/cogl-onscreen.h b/cogl/cogl-onscreen.h index 867d6f42c..fd24e129f 100644 --- a/cogl/cogl-onscreen.h +++ b/cogl/cogl-onscreen.h @@ -43,11 +43,24 @@ #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS typedef struct _CoglOnscreen CoglOnscreen; #define COGL_ONSCREEN(X) ((CoglOnscreen *)(X)) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_onscreen_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_onscreen_get_gtype (void); +#endif + /** * cogl_onscreen_new: (constructor) * @context: A #CoglContext diff --git a/cogl/cogl-output.c b/cogl/cogl-output.c index 56f1e4c42..ae8560518 100644 --- a/cogl/cogl-output.c +++ b/cogl/cogl-output.c @@ -33,12 +33,14 @@ #endif #include "cogl-output-private.h" +#include "cogl-gtype-private.h" #include static void _cogl_output_free (CoglOutput *output); COGL_OBJECT_DEFINE (Output, output); +COGL_GTYPE_DEFINE_CLASS (Output, output); CoglOutput * _cogl_output_new (const char *name) diff --git a/cogl/cogl-output.h b/cogl/cogl-output.h index dea3166e4..6eec10eeb 100644 --- a/cogl/cogl-output.h +++ b/cogl/cogl-output.h @@ -39,6 +39,10 @@ #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -66,6 +70,15 @@ COGL_BEGIN_DECLS typedef struct _CoglOutput CoglOutput; #define COGL_OUTPUT(X) ((CoglOutput *)(X)) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_output_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_output_get_gtype (void); +#endif + /** * CoglSubpixelOrder: * @COGL_SUBPIXEL_ORDER_UNKNOWN: the layout of subpixel diff --git a/cogl/cogl-pipeline.c b/cogl/cogl-pipeline.c index 6d60a6f0e..b2fee10d4 100644 --- a/cogl/cogl-pipeline.c +++ b/cogl/cogl-pipeline.c @@ -51,6 +51,7 @@ #include "cogl-profile.h" #include "cogl-depth-state-private.h" #include "cogl1-context.h" +#include "cogl-gtype-private.h" #include #include @@ -95,6 +96,7 @@ _cogl_pipeline_progends[MAX (COGL_PIPELINE_N_PROGENDS, 1)]; #endif COGL_OBJECT_DEFINE (Pipeline, pipeline); +COGL_GTYPE_DEFINE_CLASS (Pipeline, pipeline); /* * This initializes the first pipeline owned by the Cogl context. All diff --git a/cogl/cogl-pipeline.h b/cogl/cogl-pipeline.h index 9d2c4dbae..08ae3f69c 100644 --- a/cogl/cogl-pipeline.h +++ b/cogl/cogl-pipeline.h @@ -44,6 +44,10 @@ typedef struct _CoglPipeline CoglPipeline; #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS #ifdef COGL_ENABLE_EXPERIMENTAL_API @@ -64,6 +68,15 @@ COGL_BEGIN_DECLS #define COGL_PIPELINE(OBJECT) ((CoglPipeline *)OBJECT) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_pipeline_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_pipeline_get_gtype (void); +#endif + /** * cogl_pipeline_new: * @context: a #CoglContext diff --git a/cogl/cogl-pixel-buffer.c b/cogl/cogl-pixel-buffer.c index 1960b90e6..e2d6565fb 100644 --- a/cogl/cogl-pixel-buffer.c +++ b/cogl/cogl-pixel-buffer.c @@ -51,6 +51,7 @@ #include "cogl-object.h" #include "cogl-pixel-buffer-private.h" #include "cogl-pixel-buffer.h" +#include "cogl-gtype-private.h" /* * GL/GLES compatibility defines for the buffer API: @@ -72,6 +73,7 @@ static void _cogl_pixel_buffer_free (CoglPixelBuffer *buffer); COGL_BUFFER_DEFINE (PixelBuffer, pixel_buffer) +COGL_GTYPE_DEFINE_CLASS (PixelBuffer, pixel_buffer) static CoglPixelBuffer * _cogl_pixel_buffer_new (CoglContext *context, diff --git a/cogl/cogl-pixel-buffer.h b/cogl/cogl-pixel-buffer.h index e53eb51df..8ae616483 100644 --- a/cogl/cogl-pixel-buffer.h +++ b/cogl/cogl-pixel-buffer.h @@ -46,10 +46,23 @@ typedef struct _CoglPixelBuffer CoglPixelBuffer; #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS #define COGL_PIXEL_BUFFER(buffer) ((CoglPixelBuffer *)(buffer)) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_pixel_buffer_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_pixel_buffer_get_gtype (void); +#endif + /** * cogl_pixel_buffer_new: * @context: A #CoglContext diff --git a/cogl/cogl-primitive.c b/cogl/cogl-primitive.c index 6c2866d33..b31a25a86 100644 --- a/cogl/cogl-primitive.c +++ b/cogl/cogl-primitive.c @@ -41,6 +41,7 @@ #include "cogl-primitive-private.h" #include "cogl-attribute-private.h" #include "cogl-framebuffer-private.h" +#include "cogl-gtype-private.h" #include #include @@ -48,6 +49,7 @@ static void _cogl_primitive_free (CoglPrimitive *primitive); COGL_OBJECT_DEFINE (Primitive, primitive); +COGL_GTYPE_DEFINE_CLASS (Primitive, primitive); CoglPrimitive * cogl_primitive_new_with_attributes (CoglVerticesMode mode, diff --git a/cogl/cogl-primitive.h b/cogl/cogl-primitive.h index a3549d4d2..0f20bb58b 100644 --- a/cogl/cogl-primitive.h +++ b/cogl/cogl-primitive.h @@ -47,6 +47,10 @@ typedef struct _CoglPrimitive CoglPrimitive; #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -57,6 +61,15 @@ COGL_BEGIN_DECLS * FIXME */ +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_primitive_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_primitive_get_gtype (void); +#endif + /** * CoglVertexP2: * @x: The x component of a position attribute @@ -272,7 +285,6 @@ cogl_primitive_new_with_attributes (CoglVerticesMode mode, * @mode: A #CoglVerticesMode defining how to draw the vertices * @n_vertices: The number of vertices to read from @data and also * the number of vertices to read when later drawing. - * @data: (array length=n_vertices): (type Cogl.VertexP2): An array * of #CoglVertexP2 vertices * diff --git a/cogl/cogl-quaternion.c b/cogl/cogl-quaternion.c index 0c47adcf3..956744322 100644 --- a/cogl/cogl-quaternion.c +++ b/cogl/cogl-quaternion.c @@ -49,12 +49,17 @@ #include #include #include +#include "cogl-gtype-private.h" #include #include #define FLOAT_EPSILON 1e-03 +COGL_GTYPE_DEFINE_BOXED (Quaternion, quaternion, + cogl_quaternion_copy, + cogl_quaternion_free); + static CoglQuaternion zero_quaternion = { 0.0, 0.0, 0.0, 0.0, diff --git a/cogl/cogl-quaternion.h b/cogl/cogl-quaternion.h index a4a4704a2..c70eccab4 100644 --- a/cogl/cogl-quaternion.h +++ b/cogl/cogl-quaternion.h @@ -59,6 +59,10 @@ COGL_BEGIN_DECLS #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + /** * CoglQuaternion: * @w: based on the angle of rotation it is cos(𝜃/2) @@ -128,6 +132,7 @@ COGL_BEGIN_DECLS */ struct _CoglQuaternion { + /*< public >*/ float w; float x; @@ -142,6 +147,15 @@ struct _CoglQuaternion }; COGL_STRUCT_SIZE_ASSERT (CoglQuaternion, 32); +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_quaternion_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_quaternion_get_gtype (void); +#endif + /** * cogl_quaternion_init: * @quaternion: An uninitialized #CoglQuaternion diff --git a/cogl/cogl-renderer.c b/cogl/cogl-renderer.c index 9672f7ce0..ef6e900f9 100644 --- a/cogl/cogl-renderer.c +++ b/cogl/cogl-renderer.c @@ -49,6 +49,7 @@ #include "cogl-winsys-stub-private.h" #include "cogl-config-private.h" #include "cogl-error-private.h" +#include "cogl-gtype-private.h" #ifdef COGL_HAS_EGL_PLATFORM_XLIB_SUPPORT #include "cogl-winsys-egl-x11-private.h" @@ -227,6 +228,7 @@ static CoglWinsysVtableGetter _cogl_winsys_vtable_getters[] = static void _cogl_renderer_free (CoglRenderer *renderer); COGL_OBJECT_DEFINE (Renderer, renderer); +COGL_GTYPE_DEFINE_CLASS (Renderer, renderer); typedef struct _CoglNativeFilterClosure { diff --git a/cogl/cogl-renderer.h b/cogl/cogl-renderer.h index 012706fe6..78cb25dff 100644 --- a/cogl/cogl-renderer.h +++ b/cogl/cogl-renderer.h @@ -38,6 +38,10 @@ #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -85,6 +89,15 @@ cogl_renderer_error_quark (void); typedef struct _CoglRenderer CoglRenderer; +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_renderer_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_renderer_get_gtype (void); +#endif + /** * cogl_is_renderer: * @object: A #CoglObject pointer diff --git a/cogl/cogl-snippet.c b/cogl/cogl-snippet.c index 3e1bf8a03..a3f5d6c31 100644 --- a/cogl/cogl-snippet.c +++ b/cogl/cogl-snippet.c @@ -38,11 +38,13 @@ #include "cogl-types.h" #include "cogl-snippet-private.h" #include "cogl-util.h" +#include "cogl-gtype-private.h" static void _cogl_snippet_free (CoglSnippet *snippet); COGL_OBJECT_DEFINE (Snippet, snippet); +COGL_GTYPE_DEFINE_CLASS (Snippet, snippet); CoglSnippet * cogl_snippet_new (CoglSnippetHook hook, diff --git a/cogl/cogl-snippet.h b/cogl/cogl-snippet.h index 41e0d88b0..b8d9efdec 100644 --- a/cogl/cogl-snippet.h +++ b/cogl/cogl-snippet.h @@ -341,6 +341,15 @@ typedef struct _CoglSnippet CoglSnippet; #define COGL_SNIPPET(OBJECT) ((CoglSnippet *)OBJECT) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_snippet_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_snippet_get_gtype (void); +#endif + /* Enumeration of all the hook points that a snippet can be attached to within a pipeline. */ /** diff --git a/cogl/cogl-sub-texture.c b/cogl/cogl-sub-texture.c index 26aebefe8..7baf95eb6 100644 --- a/cogl/cogl-sub-texture.c +++ b/cogl/cogl-sub-texture.c @@ -45,6 +45,7 @@ #include "cogl-texture-rectangle-private.h" #include "cogl-texture-2d.h" #include "cogl-texture-gl-private.h" +#include "cogl-gtype-private.h" #include #include @@ -52,6 +53,7 @@ static void _cogl_sub_texture_free (CoglSubTexture *sub_tex); COGL_TEXTURE_DEFINE (SubTexture, sub_texture); +COGL_GTYPE_DEFINE_CLASS (SubTexture, sub_texture); static const CoglTextureVtable cogl_sub_texture_vtable; diff --git a/cogl/cogl-sub-texture.h b/cogl/cogl-sub-texture.h index 1db67df18..ced267787 100644 --- a/cogl/cogl-sub-texture.h +++ b/cogl/cogl-sub-texture.h @@ -52,6 +52,15 @@ COGL_BEGIN_DECLS #define COGL_SUB_TEXTURE(tex) ((CoglSubTexture *) tex) typedef struct _CoglSubTexture CoglSubTexture; +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_sub_texture_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_sub_texture_get_gtype (void); +#endif + /** * cogl_sub_texture_new: * @ctx: A #CoglContext pointer diff --git a/cogl/cogl-swap-chain.c b/cogl/cogl-swap-chain.c index 1f8a4bacd..e5dd2f449 100644 --- a/cogl/cogl-swap-chain.c +++ b/cogl/cogl-swap-chain.c @@ -37,10 +37,13 @@ #include "cogl-swap-chain-private.h" #include "cogl-swap-chain.h" +#include "cogl-gtype-private.h" static void _cogl_swap_chain_free (CoglSwapChain *swap_chain); COGL_OBJECT_DEFINE (SwapChain, swap_chain); +COGL_GTYPE_DEFINE_CLASS (SwapChain, swap_chain); + static void _cogl_swap_chain_free (CoglSwapChain *swap_chain) diff --git a/cogl/cogl-swap-chain.h b/cogl/cogl-swap-chain.h index a153a2dde..d0488674b 100644 --- a/cogl/cogl-swap-chain.h +++ b/cogl/cogl-swap-chain.h @@ -33,10 +33,25 @@ #ifndef __COGL_SWAP_CHAIN_H__ #define __COGL_SWAP_CHAIN_H__ +#include + +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS typedef struct _CoglSwapChain CoglSwapChain; +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_swap_chain_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_swap_chain_get_gtype (void); +#endif + CoglSwapChain * cogl_swap_chain_new (void); diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c index 46500f6c8..e76bef697 100644 --- a/cogl/cogl-texture-2d-sliced.c +++ b/cogl/cogl-texture-2d-sliced.c @@ -56,6 +56,7 @@ #include "cogl-primitive-texture.h" #include "cogl-error-private.h" #include "cogl-texture-gl-private.h" +#include "cogl-gtype-private.h" #include #include @@ -64,6 +65,8 @@ static void _cogl_texture_2d_sliced_free (CoglTexture2DSliced *tex_2ds); COGL_TEXTURE_DEFINE (Texture2DSliced, texture_2d_sliced); +COGL_GTYPE_DEFINE_CLASS (Texture2DSliced, texture_2d_sliced, + COGL_GTYPE_IMPLEMENT_INTERFACE (texture)); static const CoglTextureVtable cogl_texture_2d_sliced_vtable; diff --git a/cogl/cogl-texture-2d-sliced.h b/cogl/cogl-texture-2d-sliced.h index 538dd19fb..ec959a91b 100644 --- a/cogl/cogl-texture-2d-sliced.h +++ b/cogl/cogl-texture-2d-sliced.h @@ -70,6 +70,15 @@ typedef struct _CoglTexture2DSliced CoglTexture2DSliced; #define COGL_TEXTURE_2D_SLICED(X) ((CoglTexture2DSliced *)X) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_texture_2d_sliced_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_texture_2d_sliced_get_gtype (void); +#endif + /** * cogl_texture_2d_sliced_new_with_size: * @ctx: A #CoglContext diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c index a65e84730..cc28cd951 100644 --- a/cogl/cogl-texture-2d.c +++ b/cogl/cogl-texture-2d.c @@ -50,6 +50,7 @@ #ifdef COGL_HAS_EGL_SUPPORT #include "cogl-winsys-egl-private.h" #endif +#include "cogl-gtype-private.h" #include #include @@ -61,6 +62,8 @@ static void _cogl_texture_2d_free (CoglTexture2D *tex_2d); COGL_TEXTURE_DEFINE (Texture2D, texture_2d); +COGL_GTYPE_DEFINE_CLASS (Texture2D, texture_2d, + COGL_GTYPE_IMPLEMENT_INTERFACE (texture)); static const CoglTextureVtable cogl_texture_2d_vtable; diff --git a/cogl/cogl-texture-2d.h b/cogl/cogl-texture-2d.h index db71a52e6..c806ced5a 100644 --- a/cogl/cogl-texture-2d.h +++ b/cogl/cogl-texture-2d.h @@ -61,6 +61,15 @@ COGL_BEGIN_DECLS typedef struct _CoglTexture2D CoglTexture2D; #define COGL_TEXTURE_2D(X) ((CoglTexture2D *)X) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_texture_2d_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_texture_2d_get_gtype (void); +#endif + /** * cogl_is_texture_2d: * @object: A #CoglObject diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c index 2205b256b..8e2ff0821 100644 --- a/cogl/cogl-texture-3d.c +++ b/cogl/cogl-texture-3d.c @@ -47,6 +47,7 @@ #include "cogl-pipeline-opengl-private.h" #include "cogl-error-private.h" #include "cogl-util-gl-private.h" +#include "cogl-gtype-private.h" #include #include @@ -62,6 +63,8 @@ static void _cogl_texture_3d_free (CoglTexture3D *tex_3d); COGL_TEXTURE_DEFINE (Texture3D, texture_3d); +COGL_GTYPE_DEFINE_CLASS (Texture3D, texture_3d, + COGL_GTYPE_IMPLEMENT_INTERFACE (texture)); static const CoglTextureVtable cogl_texture_3d_vtable; diff --git a/cogl/cogl-texture-3d.h b/cogl/cogl-texture-3d.h index 17a71e052..b3b038ae8 100644 --- a/cogl/cogl-texture-3d.h +++ b/cogl/cogl-texture-3d.h @@ -52,6 +52,15 @@ typedef struct _CoglTexture3D CoglTexture3D; #define COGL_TEXTURE_3D(X) ((CoglTexture3D *)X) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_texture_3d_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_texture_3d_get_gtype (void); +#endif + /** * cogl_texture_3d_new_with_size: * @context: a #CoglContext diff --git a/cogl/cogl-texture-private.h b/cogl/cogl-texture-private.h index 0d2f5685a..472c41d9d 100644 --- a/cogl/cogl-texture-private.h +++ b/cogl/cogl-texture-private.h @@ -254,7 +254,7 @@ void _cogl_texture_register_texture_type (const CoglObjectClass *klass); #define COGL_TEXTURE_DEFINE(TypeName, type_name) \ - COGL_OBJECT_DEFINE_WITH_CODE \ + COGL_OBJECT_DEFINE_WITH_CODE_GTYPE \ (TypeName, type_name, \ _cogl_texture_register_texture_type (&_cogl_##type_name##_class)) diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c index 368588f3d..65d2f062b 100644 --- a/cogl/cogl-texture-rectangle.c +++ b/cogl/cogl-texture-rectangle.c @@ -46,6 +46,7 @@ #include "cogl-pipeline-opengl-private.h" #include "cogl-error-private.h" #include "cogl-util-gl-private.h" +#include "cogl-gtype-private.h" #include #include @@ -64,6 +65,8 @@ static void _cogl_texture_rectangle_free (CoglTextureRectangle *tex_rect); COGL_TEXTURE_DEFINE (TextureRectangle, texture_rectangle); +COGL_GTYPE_DEFINE_CLASS (TextureRectangle, texture_rectangle, + COGL_GTYPE_IMPLEMENT_INTERFACE (texture)); static const CoglTextureVtable cogl_texture_rectangle_vtable; diff --git a/cogl/cogl-texture-rectangle.h b/cogl/cogl-texture-rectangle.h index 0b86215f5..761968608 100644 --- a/cogl/cogl-texture-rectangle.h +++ b/cogl/cogl-texture-rectangle.h @@ -69,6 +69,15 @@ COGL_BEGIN_DECLS typedef struct _CoglTextureRectangle CoglTextureRectangle; #define COGL_TEXTURE_RECTANGLE(X) ((CoglTextureRectangle *)X) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_texture_rectangle_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_texture_rectangle_get_gtype (void); +#endif + /** * cogl_is_texture_rectangle: * @object: A #CoglObject diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c index a89069275..d93db2276 100644 --- a/cogl/cogl-texture.c +++ b/cogl/cogl-texture.c @@ -63,6 +63,7 @@ #include "cogl-sub-texture.h" #include "cogl-primitive-texture.h" #include "cogl-error-private.h" +#include "cogl-gtype-private.h" #include #include @@ -73,6 +74,8 @@ #define GL_RED 0x1903 #endif +COGL_GTYPE_DEFINE_INTERFACE (Texture, texture); + uint32_t cogl_texture_error_quark (void) { diff --git a/cogl/cogl-texture.h b/cogl/cogl-texture.h index 7ea6e9e1c..27188309b 100644 --- a/cogl/cogl-texture.h +++ b/cogl/cogl-texture.h @@ -56,6 +56,10 @@ typedef struct _CoglTexture CoglTexture; #endif #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -69,6 +73,15 @@ COGL_BEGIN_DECLS #define COGL_TEXTURE_MAX_WASTE 127 +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_texture_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_texture_get_gtype (void); +#endif + /** * COGL_TEXTURE_ERROR: * @@ -79,7 +92,6 @@ COGL_BEGIN_DECLS */ #define COGL_TEXTURE_ERROR (cogl_texture_error_quark ()) - /** * CoglTextureError: * @COGL_TEXTURE_ERROR_SIZE: Unsupported size diff --git a/cogl/winsys/cogl-texture-pixmap-x11.c b/cogl/winsys/cogl-texture-pixmap-x11.c index 896fdba73..6c1edeb09 100644 --- a/cogl/winsys/cogl-texture-pixmap-x11.c +++ b/cogl/winsys/cogl-texture-pixmap-x11.c @@ -57,6 +57,7 @@ #include "cogl-error-private.h" #include "cogl-texture-gl-private.h" #include "cogl-private.h" +#include "cogl-gtype-private.h" #include #include @@ -71,6 +72,7 @@ static void _cogl_texture_pixmap_x11_free (CoglTexturePixmapX11 *tex_pixmap); COGL_TEXTURE_DEFINE (TexturePixmapX11, texture_pixmap_x11); +COGL_GTYPE_DEFINE_CLASS (TexturePixmapX11, texture_pixmap_x11); static const CoglTextureVtable cogl_texture_pixmap_x11_vtable; diff --git a/cogl/winsys/cogl-texture-pixmap-x11.h b/cogl/winsys/cogl-texture-pixmap-x11.h index 12dd41662..35155cda8 100644 --- a/cogl/winsys/cogl-texture-pixmap-x11.h +++ b/cogl/winsys/cogl-texture-pixmap-x11.h @@ -50,6 +50,10 @@ #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS #ifdef COGL_ENABLE_EXPERIMENTAL_API @@ -68,6 +72,15 @@ typedef struct _CoglTexturePixmapX11 CoglTexturePixmapX11; #define COGL_TEXTURE_PIXMAP_X11(X) ((CoglTexturePixmapX11 *)X) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_texture_pixmap_x11_get_gtype: + * + * Returns: a #GType that can be used with the GLib type system. + */ +GType cogl_texture_pixmap_x11_get_gtype (void); +#endif + typedef enum { COGL_TEXTURE_PIXMAP_X11_DAMAGE_RAW_RECTANGLES,