From 6a0f47f8c323f5ff77c85cbaa8a751f9461b80af Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Mon, 2 Sep 2013 16:02:42 +0100 Subject: 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 --- cogl-gst/Makefile.am | 37 ++++++ cogl-gst/cogl-gst-video-sink.c | 30 +++++ cogl-gst/cogl-gst-video-sink.h | 6 + cogl-path/cogl-path.c | 3 +- cogl-path/cogl-path.h | 15 ++- cogl/Makefile.am | 11 +- cogl/Makefile.sources | 8 +- cogl/cogl-atlas-texture.c | 7 +- cogl/cogl-atlas-texture.h | 12 ++ cogl/cogl-attribute-buffer.c | 2 + cogl/cogl-attribute-buffer.h | 10 ++ cogl/cogl-attribute.c | 2 + cogl/cogl-attribute.h | 13 ++ cogl/cogl-bitmap.c | 2 + cogl/cogl-bitmap.h | 15 +++ 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 | 14 ++ cogl/cogl-frame-info.c | 2 + cogl/cogl-frame-info.h | 13 ++ cogl/cogl-framebuffer.c | 7 +- cogl/cogl-framebuffer.h | 14 +- cogl/cogl-gles2-context.c | 2 + cogl/cogl-gles2.h | 13 ++ cogl/cogl-gtype-private.h | 236 +++++++++++++++++++++++++++++++++- 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 | 10 +- cogl/cogl-matrix.h | 12 +- cogl/cogl-object-private.h | 77 ++++++++--- cogl/cogl-object.c | 3 + cogl/cogl-object.h | 20 ++- 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 | 14 ++ 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 | 13 ++ cogl/cogl-sub-texture.c | 2 + cogl/cogl-sub-texture.h | 9 ++ 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 ++ 77 files changed, 1048 insertions(+), 56 deletions(-) create mode 100644 cogl/cogl-gtype.c diff --git a/cogl-gst/Makefile.am b/cogl-gst/Makefile.am index d5e49aea..f2315da9 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/libcogl2.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-gst2 +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 5db660f1..85c2f6b3 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 3c11be75..4f6daf1d 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) \ @@ -429,6 +433,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-path/cogl-path.c b/cogl-path/cogl-path.c index 37f344d6..1e452757 100644 --- a/cogl-path/cogl-path.c +++ b/cogl-path/cogl-path.c @@ -53,7 +53,7 @@ #include "cogl-attribute-private.h" #include "cogl-primitive-private.h" #include "tesselator/tesselator.h" - +#include "cogl-gtype-private.h" #define _COGL_MAX_BEZ_RECURSE_DEPTH 16 @@ -64,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/cogl-path.h b/cogl-path/cogl-path.h index 57c191cb..f61161e7 100644 --- a/cogl-path/cogl-path.h +++ b/cogl-path/cogl-path.h @@ -36,6 +36,9 @@ #else #include #endif +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif COGL_BEGIN_DECLS @@ -59,6 +62,16 @@ COGL_BEGIN_DECLS */ typedef struct _CoglPath CoglPath; +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_path_get_gtype: + * + * Returns a #GType representing the #CoglPath type that can be used + * with the GLib type system. + */ +GType cogl_path_get_gtype (void); +#endif + /** * cogl_path_new: * @context: A #CoglContext pointer @@ -85,7 +98,7 @@ cogl_path_new (CoglContext *context); * 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 d83d6dc7..be7e205d 100644 --- a/cogl/Makefile.am +++ b/cogl/Makefile.am @@ -58,6 +58,15 @@ DISTCLEANFILES += $(pc_files) cogl_experimental_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) @@ -134,7 +143,7 @@ if USE_GLIB # glib-mkenums rules glib_enum_h = cogl-enum-types.h glib_enum_c = cogl-enum-types.c -glib_enum_headers = $(cogl_public_h) +glib_enum_headers = $(addprefix $(srcdir)/, $(cogl_public_h)) include $(top_srcdir)/build/autotools/Makefile.am.enums endif diff --git a/cogl/Makefile.sources b/cogl/Makefile.sources index dedf4081..46adf379 100644 --- a/cogl/Makefile.sources +++ b/cogl/Makefile.sources @@ -284,8 +284,12 @@ cogl_sources_c = \ cogl-fence.c \ cogl-fence-private.h -cogl_glib_sources_h = cogl-glib-source.h -cogl_glib_sources_c = cogl-glib-source.c +cogl_glib_sources_h = \ + cogl-glib-source.h \ + cogl-gtype-private.h +cogl_glib_sources_c = \ + cogl-glib-source.c \ + cogl-gtype.c cogl_xlib_sources_h = \ cogl-clutter-xlib.h \ diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c index a812a004..ba9fb011 100644 --- a/cogl/cogl-atlas-texture.c +++ b/cogl/cogl-atlas-texture.c @@ -31,9 +31,7 @@ * Neil Roberts */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include #include "cogl-debug.h" #include "cogl-util.h" @@ -51,13 +49,14 @@ #include "cogl-sub-texture.h" #include "cogl-error-private.h" #include "cogl-texture-gl-private.h" -#include "cogl-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 cf8f778c..86ff0280 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 90e0326a..fc9c2566 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 1255a51f..d68413e1 100644 --- a/cogl/cogl-attribute-buffer.h +++ b/cogl/cogl-attribute-buffer.h @@ -57,6 +57,16 @@ COGL_BEGIN_DECLS #define COGL_ATTRIBUTE_BUFFER(buffer) ((CoglAttributeBuffer *)(buffer)) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_attribute_buffer_get_gtype: + * + * Returns a #GType representing the #CoglAttributeBuffer type 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 b6c24334..694ca36e 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 d2e3290c..641d6fc1 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 5b1fcf50..a87387f8 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 d8c066d0..2b8b1931 100644 --- a/cogl/cogl-bitmap.h +++ b/cogl/cogl-bitmap.h @@ -44,12 +44,27 @@ 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 representing the #CoglBitmap type 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 51707485..a634fe13 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 afe36bcb..2b8e470d 100644 --- a/cogl/cogl-color.c +++ b/cogl/cogl-color.c @@ -37,6 +37,9 @@ #include "cogl-util.h" #include "cogl-color.h" #include "cogl-color-private.h" +#include "cogl-gtype-private.h" + +COGL_GTYPE_DEFINE_BOXED (Color, color, cogl_color_copy, cogl_color_free); void cogl_color_init_from_4ub (CoglColor *color, diff --git a/cogl/cogl-color.h b/cogl/cogl-color.h index a5a11704..5c651ab7 100644 --- a/cogl/cogl-color.h +++ b/cogl/cogl-color.h @@ -47,8 +47,21 @@ #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_init_from_4ub: * @color: A pointer to a #CoglColor to initialize diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c index f2d16965..b7c30fdd 100644 --- a/cogl/cogl-context.c +++ b/cogl/cogl-context.c @@ -55,6 +55,7 @@ #include "cogl-gpu-info-private.h" #include "cogl-config-private.h" #include "cogl-error-private.h" +#include "cogl-gtype-private.h" #include #include @@ -75,6 +76,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 8e1775c1..84435221 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 @@ -95,6 +99,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 aba965f3..5824e231 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 58208dfe..70fde487 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 57436c6c..96b3f74e 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 03719bda..f659c340 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 /** @@ -154,6 +158,16 @@ struct _CoglEuler }; COGL_STRUCT_SIZE_ASSERT (CoglEuler, 12); +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_euler_get_gtype: + * + * Returns a #GType representing the #CoglObject type 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 ef9f4c13..151c2988 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 a8c2e11d..89828253 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 90aaecdc..b46ff977 100644 --- a/cogl/cogl-framebuffer.c +++ b/cogl/cogl-framebuffer.c @@ -28,9 +28,7 @@ * */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include #include @@ -54,6 +52,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; @@ -66,6 +65,8 @@ 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_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 c9f17ecf..495a9947 100644 --- a/cogl/cogl-framebuffer.h +++ b/cogl/cogl-framebuffer.h @@ -58,6 +58,10 @@ typedef struct _CoglFramebuffer CoglFramebuffer; #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -98,6 +102,15 @@ COGL_BEGIN_DECLS * configuration. */ +#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 @@ -1551,4 +1564,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 d1cbaae1..c8ee9d82 100644 --- a/cogl/cogl-gles2-context.c +++ b/cogl/cogl-gles2-context.c @@ -52,10 +52,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 dcb1a68f..14a60cf6 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_domain (void); diff --git a/cogl/cogl-gtype-private.h b/cogl/cogl-gtype-private.h index f1f4f814..74962120 100644 --- a/cogl/cogl-gtype-private.h +++ b/cogl/cogl-gtype-private.h @@ -28,21 +28,47 @@ * */ +#ifndef __COGL_GTYPE_PRIVATE_H__ +#define __COGL_GTYPE_PRIVATE_H__ + +#include "config.h" + #include #include -#ifndef __COGL_GTYPE_PRIVATE_H__ -#define __COGL_GTYPE_PRIVATE_H__ +#include "cogl-object-private.h" + +/* Move this to public headers? */ +typedef struct _CoglGtypeObject CoglGtypeObject; +typedef struct _CoglGtypeClass CoglGtypeClass; + +struct _CoglGtypeObject +{ + GTypeInstance parent_instance; -#define COGL_GTYPE_DEFINE_BOXED(Name, underscore_name, copy_func, free_func) \ + 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,203 @@ 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; \ + \ + static void \ + name##_class_intern_init (gpointer klass) \ + { \ + name##_parent_class = g_type_class_peek_parent (klass); \ + name##_class_init ((Name##Class*) klass); \ + } \ + \ + 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 00000000..314d8e41 --- /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 43ceee96..112346ef 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 3644e0e1..8047c680 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 52155ebc..62c7e5c5 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 31be0aef..d48e6f20 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 e57154b8..d58ce83f 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 5f4c8d4e..a55818bc 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 4a9b9ce3..e6bd3d6f 100644 --- a/cogl/cogl-matrix.c +++ b/cogl/cogl-matrix.c @@ -66,9 +66,7 @@ * inverse. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#include #include #include @@ -77,17 +75,15 @@ #include #include #include +#include #include #include #include -#ifdef COGL_HAS_GTYPE_SUPPORT -#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 diff --git a/cogl/cogl-matrix.h b/cogl/cogl-matrix.h index 57d31352..6329853a 100644 --- a/cogl/cogl-matrix.h +++ b/cogl/cogl-matrix.h @@ -114,6 +114,11 @@ struct _CoglMatrix }; COGL_STRUCT_SIZE_ASSERT (CoglMatrix, sizeof (float) * 16 + 4); + +#ifdef _COGL_SUPPORTS_GTYPE_INTEGRATION +#define COGL_GTYPE_TYPE_MATRIX (cogl_matrix_get_gtype ()) +#endif /* _COGL_SUPPORTS_GTYPE_INTEGRATION */ + /** * cogl_matrix_init_identity: * @matrix: A 4x4 transformation matrix @@ -741,21 +746,18 @@ cogl_debug_matrix_print (const CoglMatrix *matrix); #ifdef COGL_HAS_GTYPE_SUPPORT -#define COGL_GTYPE_TYPE_MATRIX (cogl_gtype_matrix_get_type ()) - /** - * cogl_gtype_matrix_get_type: + * cogl_matrix_get_gtype: * * Returns: the GType for the registered "CoglMatrix" boxed type. This * can be used for example to define GObject properties that accept a * #CoglMatrix value. */ GType -cogl_gtype_matrix_get_type (void); +cogl_matrix_get_gtype (void); #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 f2f88223..355e6ff5 100644 --- a/cogl/cogl-object-private.h +++ b/cogl/cogl-object-private.h @@ -53,6 +53,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; @@ -76,7 +79,7 @@ typedef struct */ struct _CoglObject { - CoglObjectClass *klass; + CoglObjectClass *klass; /* equivalent to GTypeInstance */ CoglUserDataEntry user_data_entry[ COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES]; @@ -120,6 +123,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; \ @@ -144,6 +155,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) \ { \ @@ -156,23 +189,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 (); \ @@ -180,9 +197,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) \ @@ -211,7 +248,7 @@ _cogl_is_##type_name (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 0029a30b..c0bc3bf9 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 cf731167..01f8877b 100644 --- a/cogl/cogl-object.h +++ b/cogl/cogl-object.h @@ -33,7 +33,7 @@ #include #ifdef COGL_HAS_GTYPE_SUPPORT -#include +#include #endif COGL_BEGIN_DECLS @@ -42,6 +42,24 @@ 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 b971b1f6..ae653dc9 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 4f350e13..8ff2c8cd 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 c10d3849..e16c0df7 100644 --- a/cogl/cogl-onscreen-template.h +++ b/cogl/cogl-onscreen-template.h @@ -37,12 +37,25 @@ #ifndef __COGL_ONSCREEN_TEMPLATE_H__ #define __COGL_ONSCREEN_TEMPLATE_H__ +#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 (void); diff --git a/cogl/cogl-onscreen.c b/cogl/cogl-onscreen.c index b884def9..20534c8b 100644 --- a/cogl/cogl-onscreen.c +++ b/cogl/cogl-onscreen.c @@ -41,12 +41,15 @@ #include "cogl-object-private.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 4d922b21..16537e06 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 15d5e5fe..f68945fc 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 5acc7ef7..5025143c 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 29c59286..0c6e7d47 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 "cogl-private.h" +#include "cogl-gtype-private.h" #include #include @@ -94,6 +95,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 ead3a44a..da60cfdb 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 /** @@ -62,6 +66,16 @@ COGL_BEGIN_DECLS #define COGL_PIPELINE(OBJECT) ((CoglPipeline *)OBJECT) +#ifdef COGL_HAS_GTYPE_SUPPORT +/** + * cogl_pipeline_get_gtype: + * + * Returns a #GType representing the #CoglPipeline type 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 74e1c06c..76584a40 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) CoglPixelBuffer * cogl_pixel_buffer_new (CoglContext *context, diff --git a/cogl/cogl-pixel-buffer.h b/cogl/cogl-pixel-buffer.h index 5991646e..339641b2 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 b899799d..105a4609 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 21ffcfcc..4b9dbaae 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 6e63211a..d1afc3a5 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 a1d8a27e..7f3befce 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; @@ -136,6 +141,15 @@ struct _CoglQuaternion }; COGL_STRUCT_SIZE_ASSERT (CoglQuaternion, 16); +#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 041b19b2..a38ae661 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 b299c6fa..c7b26f80 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_domain (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 b4108ac1..26b63e83 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 92964696..5b24dd70 100644 --- a/cogl/cogl-snippet.h +++ b/cogl/cogl-snippet.h @@ -38,6 +38,10 @@ #ifndef __COGL_SNIPPET_H__ #define __COGL_SNIPPET_H__ +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -331,6 +335,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 4b4ee28d..4aaa0bca 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 e79982be..ad5cc11f 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-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c index 1236178b..389e7d65 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 e3d9a2b3..599142aa 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 28f32e09..e70d6ca4 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 101ad281..c1b3ea17 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 eedfda9c..ff184e53 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 2f96a7a6..d63da639 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 878fb5f5..20995376 100644 --- a/cogl/cogl-texture-private.h +++ b/cogl/cogl-texture-private.h @@ -252,7 +252,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 5d61d035..71d163e0 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 2421a1bf..11f3b739 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 8378ec69..dd31e3ca 100644 --- a/cogl/cogl-texture.c +++ b/cogl/cogl-texture.c @@ -61,6 +61,7 @@ #include "cogl-sub-texture.h" #include "cogl-primitive-texture.h" #include "cogl-error-private.h" +#include "cogl-gtype-private.h" #include #include @@ -71,6 +72,8 @@ #define GL_RED 0x1903 #endif +COGL_GTYPE_DEFINE_INTERFACE (Texture, texture); + uint32_t cogl_texture_error_domain (void) { diff --git a/cogl/cogl-texture.h b/cogl/cogl-texture.h index b07da9bb..51dc9969 100644 --- a/cogl/cogl-texture.h +++ b/cogl/cogl-texture.h @@ -54,6 +54,10 @@ typedef struct _CoglTexture CoglTexture; #include #include +#ifdef COGL_HAS_GTYPE_SUPPORT +#include +#endif + COGL_BEGIN_DECLS /** @@ -71,6 +75,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: * @@ -81,7 +94,6 @@ COGL_BEGIN_DECLS */ #define COGL_TEXTURE_ERROR (cogl_texture_error_domain ()) - /** * 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 8035d3d0..826c4ccc 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 4935e99f..751d2547 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 /** @@ -66,6 +70,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, -- cgit v1.2.1