matrix gtype: registers a boxed type for CoglMatrix
authorRobert Bragg <robert@linux.intel.com>
Mon, 29 Nov 2010 21:42:06 +0000 (21:42 +0000)
committerRobert Bragg <robert@linux.intel.com>
Tue, 7 Dec 2010 12:16:50 +0000 (12:16 +0000)
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.

clutter/cogl/cogl/Makefile.am
clutter/cogl/cogl/cogl-gtype-private.h [new file with mode: 0644]
clutter/cogl/cogl/cogl-matrix.c
clutter/cogl/cogl/cogl-matrix.h
clutter/cogl/cogl/cogl.h
doc/reference/cogl-2.0/cogl-docs.xml.in
doc/reference/cogl-2.0/cogl-sections.txt
doc/reference/cogl/cogl-docs.xml.in
doc/reference/cogl/cogl-sections.txt

index 599aab4..c29dd71 100644 (file)
@@ -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/clutter/cogl/cogl/cogl-gtype-private.h b/clutter/cogl/cogl/cogl-gtype-private.h
new file mode 100644 (file)
index 0000000..1d12330
--- /dev/null
@@ -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
+ * <http://www.gnu.org/licenses/>.
+ *
+ *
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+
+#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__ */
+
index dc5578c..73a3463 100644 (file)
 #include <math.h>
 #include <string.h>
 
+#ifdef _COGL_SUPPORTS_GTYPE_INTEGRATION
+#include <cogl-gtype-private.h>
+COGL_GTYPE_DEFINE_BOXED ("Matrix", matrix,
+                         cogl_matrix_copy,
+                         cogl_matrix_free);
+#endif
+
 void
 _cogl_matrix_print (CoglMatrix *matrix)
 {
index b54f4b9..24c01e6 100644 (file)
@@ -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 */
index c88c013..d6170fe 100644 (file)
 #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 <cogl/cogl-defines.h>
 
 #include <cogl/cogl-object.h>
index d8350cc..5b991c6 100644 (file)
       <xi:include href="xml/cogl-vector.xml"/>
       <xi:include href="xml/cogl-types.xml"/>
     </section>
+
+    <section id="cogl-integration">
+      <title>Binding and Integrating</title>
+      <xi:include href="xml/cogl-gtype.xml"/>
+    </section>
+
   </chapter>
 
   <chapter id="coglglossary">
index d64b90b..e73a348 100644 (file)
@@ -477,4 +477,8 @@ CoglBufferBit
 CoglAttributeType
 </SECTION>
 
-
+<SECTION>
+<FILE>cogl-gtype</FILE>
+<TITLE>GType Integration API</TITLE>
+cogl_gtype_matrix_get_type
+</SECTION>
index 01d70ad..7051d09 100644 (file)
@@ -72,6 +72,7 @@
     <xi:include href="xml/cogl-shaders.xml"/>
     <xi:include href="xml/cogl-offscreen.xml"/>
     <xi:include href="xml/cogl-fixed.xml"/>
+    <xi:include href="xml/cogl-gtype.xml"/>
 
   </chapter>
 
index 098be39..1a347e7 100644 (file)
@@ -555,6 +555,12 @@ cogl_vector3_distance
 </SECTION>
 
 <SECTION>
+<FILE>cogl-gtype</FILE>
+<TITLE>GType Integration API</TITLE>
+cogl_gtype_matrix_get_type
+</SECTION>
+
+<SECTION>
 <FILE>cogl-deprecated</FILE>
 <TITLE>General API (Deprecated)</TITLE>
 cogl_check_extension