2010-11-29 16:42:06 -05:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2010-11-29 16:42:06 -05:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Intel Corporation.
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2010-11-29 16:42:06 -05:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2010-11-29 16:42:06 -05:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-11-29 16:42:06 -05:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-09-02 11:02:42 -04:00
|
|
|
#ifndef __COGL_GTYPE_PRIVATE_H__
|
|
|
|
#define __COGL_GTYPE_PRIVATE_H__
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2010-11-29 16:42:06 -05:00
|
|
|
#include <glib.h>
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
2013-09-02 11:02:42 -04:00
|
|
|
#include "cogl-object-private.h"
|
|
|
|
|
|
|
|
/* Move this to public headers? */
|
|
|
|
typedef struct _CoglGtypeObject CoglGtypeObject;
|
|
|
|
typedef struct _CoglGtypeClass CoglGtypeClass;
|
|
|
|
|
|
|
|
struct _CoglGtypeObject
|
|
|
|
{
|
|
|
|
GTypeInstance parent_instance;
|
2010-11-29 16:42:06 -05:00
|
|
|
|
2013-09-02 11:02:42 -04:00
|
|
|
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) \
|
2010-11-29 16:42:06 -05:00
|
|
|
GType \
|
2013-09-02 11:02:42 -04:00
|
|
|
cogl_##underscore_name##_get_gtype (void) \
|
2010-11-29 16:42:06 -05:00
|
|
|
{ \
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
static volatile size_t type_volatile = 0; \
|
2010-11-29 16:42:06 -05:00
|
|
|
if (g_once_init_enter (&type_volatile)) \
|
|
|
|
{ \
|
|
|
|
GType type = \
|
2013-09-02 11:02:42 -04:00
|
|
|
g_boxed_type_register_static (g_intern_static_string (I_("Cogl" # Name)), \
|
2010-11-29 16:42:06 -05:00
|
|
|
(GBoxedCopyFunc)copy_func, \
|
|
|
|
(GBoxedFreeFunc)free_func); \
|
|
|
|
g_once_init_leave (&type_volatile, type); \
|
|
|
|
} \
|
|
|
|
return type_volatile; \
|
|
|
|
}
|
|
|
|
|
2013-09-02 11:02:42 -04:00
|
|
|
#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);
|
2010-11-29 16:42:06 -05:00
|
|
|
|
2013-09-02 11:02:42 -04:00
|
|
|
#define _COGL_GTYPE_DEFINE_BASE_CLASS_END() \
|
|
|
|
} \
|
|
|
|
return type_id__volatile; \
|
|
|
|
}
|
|
|
|
|
2014-04-17 22:33:15 -04:00
|
|
|
#define COGL_GTYPE_DEFINE_BASE_CLASS(Name,name,...) \
|
|
|
|
_COGL_GTYPE_DEFINE_BASE_CLASS_BEGIN(Name,name) \
|
|
|
|
{__VA_ARGS__;} \
|
2013-09-02 11:02:42 -04:00
|
|
|
_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; \
|
|
|
|
\
|
2014-03-21 13:16:34 -04:00
|
|
|
static void \
|
|
|
|
name##_class_intern_init (gpointer klass) \
|
|
|
|
{ \
|
|
|
|
name##_parent_class = g_type_class_peek_parent (klass); \
|
|
|
|
name##_class_init ((Name##Class*) klass); \
|
|
|
|
} \
|
2013-09-02 11:02:42 -04:00
|
|
|
\
|
|
|
|
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() */
|
|
|
|
|
|
|
|
|
2014-04-17 22:33:15 -04:00
|
|
|
#define COGL_GTYPE_DEFINE_CLASS(Name,name,...) \
|
2013-09-02 11:02:42 -04:00
|
|
|
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) \
|
2014-04-17 22:33:15 -04:00
|
|
|
{__VA_ARGS__;} \
|
2013-09-02 11:02:42 -04:00
|
|
|
_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__ */
|