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.
This commit is contained in:
Robert Bragg 2010-11-29 21:42:06 +00:00
parent 3ac023163f
commit fd10e3a545
7 changed files with 85 additions and 0 deletions

View File

@ -282,6 +282,7 @@ cogl_sources_c = \
$(srcdir)/cogl-shader.c \ $(srcdir)/cogl-shader.c \
$(srcdir)/cogl-callback-list.h \ $(srcdir)/cogl-callback-list.h \
$(srcdir)/cogl-callback-list.c \ $(srcdir)/cogl-callback-list.c \
$(srcdir)/cogl-gtype-private.h \
$(NULL) $(NULL)
if SUPPORT_XLIB if SUPPORT_XLIB

48
cogl/cogl-gtype-private.h Normal file
View File

@ -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__ */

View File

@ -42,6 +42,13 @@
#include <math.h> #include <math.h>
#include <string.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 void
_cogl_matrix_print (CoglMatrix *matrix) _cogl_matrix_print (CoglMatrix *matrix)
{ {

View File

@ -484,6 +484,22 @@ cogl_matrix_project_points (const CoglMatrix *matrix,
#endif /* COGL_ENABLE_EXPERIMENTAL_API */ #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 G_END_DECLS
#endif /* __COGL_MATRIX_H */ #endif /* __COGL_MATRIX_H */

View File

@ -35,6 +35,12 @@
#endif #endif
#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-defines.h>
#include <cogl/cogl-object.h> #include <cogl/cogl-object.h>

View File

@ -72,6 +72,7 @@
<xi:include href="xml/cogl-shaders.xml"/> <xi:include href="xml/cogl-shaders.xml"/>
<xi:include href="xml/cogl-offscreen.xml"/> <xi:include href="xml/cogl-offscreen.xml"/>
<xi:include href="xml/cogl-fixed.xml"/> <xi:include href="xml/cogl-fixed.xml"/>
<xi:include href="xml/cogl-gtype.xml"/>
</chapter> </chapter>

View File

@ -554,6 +554,12 @@ cogl_vector3_dot_product
cogl_vector3_distance cogl_vector3_distance
</SECTION> </SECTION>
<SECTION>
<FILE>cogl-gtype</FILE>
<TITLE>GType Integration API</TITLE>
cogl_gtype_matrix_get_type
</SECTION>
<SECTION> <SECTION>
<FILE>cogl-deprecated</FILE> <FILE>cogl-deprecated</FILE>
<TITLE>General API (Deprecated)</TITLE> <TITLE>General API (Deprecated)</TITLE>