From fd10e3a545f071e3006694cd1c0baa8dd2bd0914 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Mon, 29 Nov 2010 21:42:06 +0000 Subject: [PATCH] matrix gtype: registers a boxed type for CoglMatrix To allow us to have gobject properties that accept a CoglMatrix value we need to register a GType. This adds a cogl_gtype_matrix_get_type function that will register a static boxed type called "CoglMatrix". This adds a new section to the reference manual for GType integration functions. --- cogl/Makefile.am | 1 + cogl/cogl-gtype-private.h | 48 ++++++++++++++++++++++++++++ cogl/cogl-matrix.c | 7 ++++ cogl/cogl-matrix.h | 16 ++++++++++ cogl/cogl.h | 6 ++++ doc/reference/cogl/cogl-docs.xml.in | 1 + doc/reference/cogl/cogl-sections.txt | 6 ++++ 7 files changed, 85 insertions(+) create mode 100644 cogl/cogl-gtype-private.h diff --git a/cogl/Makefile.am b/cogl/Makefile.am index 599aab4b1..c29dd715d 100644 --- a/cogl/Makefile.am +++ b/cogl/Makefile.am @@ -282,6 +282,7 @@ cogl_sources_c = \ $(srcdir)/cogl-shader.c \ $(srcdir)/cogl-callback-list.h \ $(srcdir)/cogl-callback-list.c \ + $(srcdir)/cogl-gtype-private.h \ $(NULL) if SUPPORT_XLIB diff --git a/cogl/cogl-gtype-private.h b/cogl/cogl-gtype-private.h new file mode 100644 index 000000000..1d1233076 --- /dev/null +++ b/cogl/cogl-gtype-private.h @@ -0,0 +1,48 @@ +/* + * Cogl + * + * An object oriented GL/GLES Abstraction/Utility Layer + * + * Copyright (C) 2010 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * + */ + +#include +#include + +#ifndef __COGL_GTYPE_PRIVATE_H__ +#define __COGL_GTYPE_PRIVATE_H__ + +#define COGL_GTYPE_DEFINE_BOXED(Name, underscore_name, copy_func, free_func) \ +GType \ +cogl_gtype_ ## underscore_name ## _get_type (void) \ +{ \ + static volatile gsize type_volatile = 0; \ + if (g_once_init_enter (&type_volatile)) \ + { \ + GType type = \ + g_boxed_type_register_static (g_intern_static_string ("Cogl" Name), \ + (GBoxedCopyFunc)copy_func, \ + (GBoxedFreeFunc)free_func); \ + g_once_init_leave (&type_volatile, type); \ + } \ + return type_volatile; \ +} + +#endif /* __COGL_GTYPE_PRIVATE_H__ */ + diff --git a/cogl/cogl-matrix.c b/cogl/cogl-matrix.c index dc5578cc9..73a3463b2 100644 --- a/cogl/cogl-matrix.c +++ b/cogl/cogl-matrix.c @@ -42,6 +42,13 @@ #include #include +#ifdef _COGL_SUPPORTS_GTYPE_INTEGRATION +#include +COGL_GTYPE_DEFINE_BOXED ("Matrix", matrix, + cogl_matrix_copy, + cogl_matrix_free); +#endif + void _cogl_matrix_print (CoglMatrix *matrix) { diff --git a/cogl/cogl-matrix.h b/cogl/cogl-matrix.h index b54f4b948..24c01e6ca 100644 --- a/cogl/cogl-matrix.h +++ b/cogl/cogl-matrix.h @@ -484,6 +484,22 @@ cogl_matrix_project_points (const CoglMatrix *matrix, #endif /* COGL_ENABLE_EXPERIMENTAL_API */ +#ifdef _COGL_SUPPORTS_GTYPE_INTEGRATION + +#define COGL_GTYPE_TYPE_MATRIX (cogl_gtype_matrix_get_type ()) + +/** + * cogl_gtype_matrix_get_type: + * + * 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); + +#endif /* _COGL_SUPPORTS_GTYPE_INTEGRATION */ + G_END_DECLS #endif /* __COGL_MATRIX_H */ diff --git a/cogl/cogl.h b/cogl/cogl.h index c88c0133e..d6170fe16 100644 --- a/cogl/cogl.h +++ b/cogl/cogl.h @@ -35,6 +35,12 @@ #endif #endif +/* We currently keep gtype integration delimited in case we eventually + * want to split it out into a separate utility library when Cogl + * becomes a standalone project. (like cairo-gobject.so) + */ +#define _COGL_SUPPORTS_GTYPE_INTEGRATION + #include #include diff --git a/doc/reference/cogl/cogl-docs.xml.in b/doc/reference/cogl/cogl-docs.xml.in index 01d70adc9..7051d0920 100644 --- a/doc/reference/cogl/cogl-docs.xml.in +++ b/doc/reference/cogl/cogl-docs.xml.in @@ -72,6 +72,7 @@ + diff --git a/doc/reference/cogl/cogl-sections.txt b/doc/reference/cogl/cogl-sections.txt index 098be39aa..1a347e797 100644 --- a/doc/reference/cogl/cogl-sections.txt +++ b/doc/reference/cogl/cogl-sections.txt @@ -554,6 +554,12 @@ cogl_vector3_dot_product cogl_vector3_distance +
+cogl-gtype +GType Integration API +cogl_gtype_matrix_get_type +
+
cogl-deprecated General API (Deprecated)