2010-05-27 17:24:56 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2010-05-27 17:24:56 -04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008,2009,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-05-27 17:24:56 -04: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-05-27 17:24:56 -04: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-05-27 17:24:56 -04:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Robert Bragg <robert@linux.intel.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __COGL_OBJECT_PRIVATE_H
|
|
|
|
#define __COGL_OBJECT_PRIVATE_H
|
|
|
|
|
2010-07-03 16:10:05 -04:00
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "cogl-types.h"
|
2010-05-27 17:24:56 -04:00
|
|
|
#include "cogl-object.h"
|
2010-09-17 12:18:09 -04:00
|
|
|
#include "cogl-debug.h"
|
2010-05-27 17:24:56 -04:00
|
|
|
|
|
|
|
/* For compatability until all components have been converted */
|
|
|
|
typedef struct _CoglObjectClass CoglHandleClass;
|
|
|
|
typedef struct _CoglObject CoglHandleObject;
|
|
|
|
|
2011-01-12 15:37:53 -05:00
|
|
|
/* XXX: sadly we didn't fully consider when we copied the cairo API
|
|
|
|
* for _set_user_data that the callback doesn't get a pointer to the
|
|
|
|
* instance which is desired in most cases. This means you tend to end
|
|
|
|
* up creating micro allocations for the private data just so you can
|
|
|
|
* pair up the data of interest with the original instance for
|
|
|
|
* identification when it is later destroyed.
|
|
|
|
*
|
|
|
|
* Internally we use a small hack to avoid needing these micro
|
|
|
|
* allocations by actually passing the instance as a second argument
|
|
|
|
* to the callback */
|
|
|
|
typedef void (*CoglUserDataDestroyInternalCallback) (void *user_data,
|
|
|
|
void *instance);
|
|
|
|
|
2010-05-27 17:24:56 -04:00
|
|
|
typedef struct _CoglObjectClass
|
|
|
|
{
|
2013-09-02 11:02:42 -04:00
|
|
|
#ifdef COGL_HAS_GTYPE_SUPPORT
|
|
|
|
GTypeClass base_class;
|
|
|
|
#endif
|
2012-01-24 11:24:26 -05:00
|
|
|
const char *name;
|
|
|
|
void *virt_free;
|
2012-01-24 11:36:16 -05:00
|
|
|
void *virt_unref;
|
2010-05-27 17:24:56 -04:00
|
|
|
} CoglObjectClass;
|
|
|
|
|
|
|
|
#define COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES 2
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
CoglUserDataKey *key;
|
|
|
|
void *user_data;
|
2011-01-12 15:37:53 -05:00
|
|
|
CoglUserDataDestroyInternalCallback destroy;
|
2010-05-27 17:24:56 -04:00
|
|
|
} CoglUserDataEntry;
|
|
|
|
|
|
|
|
/* All Cogl objects inherit from this base object by adding a member:
|
|
|
|
*
|
|
|
|
* CoglObject _parent;
|
|
|
|
*
|
|
|
|
* at the top of its main structure. This structure is initialized
|
|
|
|
* when you call _cogl_#type_name#_object_new (new_object);
|
|
|
|
*/
|
|
|
|
struct _CoglObject
|
|
|
|
{
|
2013-09-02 11:02:42 -04:00
|
|
|
CoglObjectClass *klass; /* equivalent to GTypeInstance */
|
2010-05-27 17:24:56 -04:00
|
|
|
|
|
|
|
CoglUserDataEntry user_data_entry[
|
|
|
|
COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES];
|
|
|
|
GArray *user_data_array;
|
|
|
|
int n_user_data_entries;
|
|
|
|
|
2012-01-24 10:55:27 -05:00
|
|
|
unsigned int ref_count;
|
2010-05-27 17:24:56 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Helper macro to encapsulate the common code for COGL reference
|
|
|
|
counted objects */
|
|
|
|
|
|
|
|
#ifdef COGL_OBJECT_DEBUG
|
|
|
|
|
2010-06-01 14:27:07 -04:00
|
|
|
#define _COGL_OBJECT_DEBUG_NEW(type_name, obj) \
|
2012-04-16 09:14:10 -04:00
|
|
|
COGL_NOTE (OBJECT, "COGL " G_STRINGIFY (type_name) " NEW %p %i", \
|
2010-06-01 14:27:07 -04:00
|
|
|
(obj), (obj)->ref_count)
|
2010-05-27 17:24:56 -04:00
|
|
|
|
|
|
|
#define _COGL_OBJECT_DEBUG_REF(type_name, object) G_STMT_START { \
|
|
|
|
CoglObject *__obj = (CoglObject *)object; \
|
2012-04-16 09:14:10 -04:00
|
|
|
COGL_NOTE (OBJECT, "COGL %s REF %p %i", \
|
2012-01-24 11:24:26 -05:00
|
|
|
(__obj)->klass->name, \
|
2010-05-27 17:24:56 -04:00
|
|
|
(__obj), (__obj)->ref_count); } G_STMT_END
|
|
|
|
|
|
|
|
#define _COGL_OBJECT_DEBUG_UNREF(type_name, object) G_STMT_START { \
|
2010-06-01 14:27:07 -04:00
|
|
|
CoglObject *__obj = (CoglObject *)object; \
|
2012-04-16 09:14:10 -04:00
|
|
|
COGL_NOTE (OBJECT, "COGL %s UNREF %p %i", \
|
2012-01-24 11:24:26 -05:00
|
|
|
(__obj)->klass->name, \
|
2010-05-27 17:24:56 -04:00
|
|
|
(__obj), (__obj)->ref_count - 1); } G_STMT_END
|
|
|
|
|
|
|
|
#define COGL_OBJECT_DEBUG_FREE(obj) \
|
2012-04-16 09:14:10 -04:00
|
|
|
COGL_NOTE (OBJECT, "COGL %s FREE %p", \
|
2012-01-24 11:24:26 -05:00
|
|
|
(obj)->klass->name, (obj))
|
2010-05-27 17:24:56 -04:00
|
|
|
|
|
|
|
#else /* !COGL_OBJECT_DEBUG */
|
|
|
|
|
|
|
|
#define _COGL_OBJECT_DEBUG_NEW(type_name, obj)
|
|
|
|
#define _COGL_OBJECT_DEBUG_REF(type_name, obj)
|
|
|
|
#define _COGL_OBJECT_DEBUG_UNREF(type_name, obj)
|
|
|
|
#define COGL_OBJECT_DEBUG_FREE(obj)
|
|
|
|
|
|
|
|
#endif /* COGL_OBJECT_DEBUG */
|
|
|
|
|
2013-09-02 11:02:42 -04:00
|
|
|
#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
|
|
|
|
|
2011-06-10 13:44:09 -04:00
|
|
|
#define COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
|
|
|
\
|
2012-01-24 11:24:26 -05:00
|
|
|
CoglObjectClass _cogl_##type_name##_class; \
|
2011-06-10 13:44:09 -04:00
|
|
|
static unsigned long _cogl_object_##type_name##_count; \
|
|
|
|
\
|
|
|
|
static inline void \
|
|
|
|
_cogl_object_##type_name##_inc (void) \
|
|
|
|
{ \
|
|
|
|
_cogl_object_##type_name##_count++; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static inline void \
|
|
|
|
_cogl_object_##type_name##_dec (void) \
|
|
|
|
{ \
|
|
|
|
_cogl_object_##type_name##_count--; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
static void \
|
|
|
|
_cogl_object_##type_name##_indirect_free (CoglObject *obj) \
|
|
|
|
{ \
|
|
|
|
_cogl_##type_name##_free ((Cogl##TypeName *) obj); \
|
|
|
|
_cogl_object_##type_name##_dec (); \
|
|
|
|
} \
|
|
|
|
\
|
2013-09-02 11:02:42 -04:00
|
|
|
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; } \
|
|
|
|
} \
|
|
|
|
\
|
2011-06-10 13:44:09 -04:00
|
|
|
static Cogl##TypeName * \
|
|
|
|
_cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \
|
|
|
|
{ \
|
|
|
|
CoglObject *obj = (CoglObject *)&new_obj->_parent; \
|
|
|
|
obj->ref_count = 0; \
|
|
|
|
cogl_object_ref (obj); \
|
|
|
|
obj->n_user_data_entries = 0; \
|
|
|
|
obj->user_data_array = NULL; \
|
|
|
|
\
|
|
|
|
obj->klass = &_cogl_##type_name##_class; \
|
2012-01-24 11:24:26 -05:00
|
|
|
if (!obj->klass->virt_free) \
|
2011-06-10 13:44:09 -04:00
|
|
|
{ \
|
2013-09-02 11:02:42 -04:00
|
|
|
_cogl_object_##type_name##_class_init (); \
|
2011-06-10 13:44:09 -04:00
|
|
|
} \
|
|
|
|
\
|
|
|
|
_cogl_object_##type_name##_inc (); \
|
|
|
|
_COGL_OBJECT_DEBUG_NEW (TypeName, obj); \
|
|
|
|
return new_obj; \
|
2010-07-09 13:46:31 -04:00
|
|
|
}
|
|
|
|
|
2013-09-02 11:02:42 -04:00
|
|
|
#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; \
|
|
|
|
}
|
|
|
|
|
2010-07-09 13:46:31 -04:00
|
|
|
#define COGL_OBJECT_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
|
|
|
\
|
2014-02-23 12:24:11 -05:00
|
|
|
COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
2010-07-09 13:46:31 -04: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
|
|
|
CoglBool \
|
2010-07-09 13:46:31 -04:00
|
|
|
cogl_is_##type_name (void *object) \
|
|
|
|
{ \
|
|
|
|
CoglObject *obj = object; \
|
|
|
|
\
|
|
|
|
if (object == NULL) \
|
|
|
|
return FALSE; \
|
|
|
|
\
|
2012-01-24 11:24:26 -05:00
|
|
|
return obj->klass == &_cogl_##type_name##_class; \
|
2010-07-09 13:46:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define COGL_OBJECT_INTERNAL_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
|
|
|
\
|
|
|
|
COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
|
|
|
\
|
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
|
|
|
CoglBool \
|
2010-07-09 13:46:31 -04:00
|
|
|
_cogl_is_##type_name (void *object) \
|
|
|
|
{ \
|
|
|
|
CoglObject *obj = object; \
|
|
|
|
\
|
|
|
|
if (object == NULL) \
|
|
|
|
return FALSE; \
|
|
|
|
\
|
2012-01-24 11:24:26 -05:00
|
|
|
return obj->klass == &_cogl_##type_name##_class; \
|
2010-07-09 12:59:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define COGL_OBJECT_DEFINE_DEPRECATED_REF_COUNTING(type_name) \
|
2010-06-01 14:27:07 -04:00
|
|
|
\
|
|
|
|
void * G_GNUC_DEPRECATED \
|
|
|
|
cogl_##type_name##_ref (void *object) \
|
|
|
|
{ \
|
|
|
|
if (!cogl_is_##type_name (object)) \
|
|
|
|
return NULL; \
|
|
|
|
\
|
|
|
|
_COGL_OBJECT_DEBUG_REF (TypeName, object); \
|
|
|
|
\
|
2010-05-27 17:24:56 -04:00
|
|
|
cogl_handle_ref (object); \
|
2010-06-01 14:27:07 -04:00
|
|
|
\
|
|
|
|
return object; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
void G_GNUC_DEPRECATED \
|
|
|
|
cogl_##type_name##_unref (void *object) \
|
|
|
|
{ \
|
|
|
|
if (!cogl_is_##type_name (object)) \
|
2010-05-27 17:24:56 -04:00
|
|
|
{ \
|
|
|
|
g_warning (G_STRINGIFY (cogl_##type_name##_unref) \
|
|
|
|
": Ignoring unref of Cogl handle " \
|
|
|
|
"due to type mismatch"); \
|
2010-06-01 14:27:07 -04:00
|
|
|
return; \
|
2010-05-27 17:24:56 -04:00
|
|
|
} \
|
2010-06-01 14:27:07 -04:00
|
|
|
\
|
|
|
|
_COGL_OBJECT_DEBUG_UNREF (TypeName, object); \
|
2010-05-27 17:24:56 -04:00
|
|
|
\
|
|
|
|
cogl_handle_unref (object); \
|
|
|
|
}
|
|
|
|
|
2010-06-11 08:44:27 -04:00
|
|
|
#define COGL_OBJECT_DEFINE(TypeName, type_name) \
|
2013-09-02 11:02:42 -04:00
|
|
|
COGL_OBJECT_DEFINE_WITH_CODE_GTYPE (TypeName, type_name, (void) 0)
|
2010-06-11 08:44:27 -04:00
|
|
|
|
2010-07-09 13:46:31 -04:00
|
|
|
#define COGL_OBJECT_INTERNAL_DEFINE(TypeName, type_name) \
|
|
|
|
COGL_OBJECT_INTERNAL_DEFINE_WITH_CODE (TypeName, type_name, (void) 0)
|
|
|
|
|
2010-05-27 17:24:56 -04:00
|
|
|
/* For temporary compatability */
|
2010-07-09 13:46:31 -04:00
|
|
|
#define COGL_HANDLE_INTERNAL_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
|
|
|
\
|
|
|
|
COGL_OBJECT_INTERNAL_DEFINE_WITH_CODE (TypeName, type_name, code) \
|
|
|
|
\
|
|
|
|
static Cogl##TypeName * \
|
|
|
|
_cogl_##type_name##_handle_new (CoglHandle handle) \
|
|
|
|
{ \
|
|
|
|
return _cogl_##type_name##_object_new (handle); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define COGL_HANDLE_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
|
|
|
\
|
|
|
|
COGL_OBJECT_DEFINE_WITH_CODE (TypeName, type_name, code) \
|
|
|
|
\
|
|
|
|
static Cogl##TypeName * \
|
|
|
|
_cogl_##type_name##_handle_new (CoglHandle handle) \
|
|
|
|
{ \
|
|
|
|
return _cogl_##type_name##_object_new (handle); \
|
2010-05-27 17:24:56 -04:00
|
|
|
}
|
|
|
|
|
2010-06-11 08:44:27 -04:00
|
|
|
#define COGL_HANDLE_DEFINE(TypeName, type_name) \
|
|
|
|
COGL_HANDLE_DEFINE_WITH_CODE (TypeName, type_name, (void) 0)
|
|
|
|
|
2011-01-12 15:37:53 -05:00
|
|
|
void
|
|
|
|
_cogl_object_set_user_data (CoglObject *object,
|
|
|
|
CoglUserDataKey *key,
|
|
|
|
void *user_data,
|
|
|
|
CoglUserDataDestroyInternalCallback destroy);
|
|
|
|
|
2012-01-24 11:36:16 -05:00
|
|
|
void
|
|
|
|
_cogl_object_default_unref (void *obj);
|
|
|
|
|
2010-05-27 17:24:56 -04:00
|
|
|
#endif /* __COGL_OBJECT_PRIVATE_H */
|
|
|
|
|