mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 08:00:42 -05:00
object: Remove the type member of CoglObjectClass
Unlike in GObject the type number for a CoglObject is entirely an internal implementation detail so there is no need to make a GQuark to make it safe to export out of the library. Instead we can just directly use a fixed pointer address as the identifier for the type. This patch makes it use the address of the class struct of the identifier. This should make it faster to do type checks because it does not need to call a function every time it wants to get the type number. Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
parent
c39333a2c6
commit
139421de19
@ -55,9 +55,6 @@ struct _CoglAtlasTexture
|
|||||||
CoglHandle sub_texture;
|
CoglHandle sub_texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
GQuark
|
|
||||||
_cogl_handle_atlas_texture_get_type (void);
|
|
||||||
|
|
||||||
CoglHandle
|
CoglHandle
|
||||||
_cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
|
_cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp,
|
||||||
CoglTextureFlags flags,
|
CoglTextureFlags flags,
|
||||||
|
@ -102,13 +102,12 @@ struct _CoglBuffer
|
|||||||
/* This is used to register a type to the list of handle types that
|
/* This is used to register a type to the list of handle types that
|
||||||
will be considered a texture in cogl_is_texture() */
|
will be considered a texture in cogl_is_texture() */
|
||||||
void
|
void
|
||||||
_cogl_buffer_register_buffer_type (GQuark type);
|
_cogl_buffer_register_buffer_type (const CoglObjectClass *klass);
|
||||||
|
|
||||||
#define COGL_BUFFER_DEFINE(TypeName, type_name) \
|
#define COGL_BUFFER_DEFINE(TypeName, type_name) \
|
||||||
COGL_OBJECT_DEFINE_WITH_CODE \
|
COGL_OBJECT_DEFINE_WITH_CODE \
|
||||||
(TypeName, type_name, \
|
(TypeName, type_name, \
|
||||||
_cogl_buffer_register_buffer_type (_cogl_object_ \
|
_cogl_buffer_register_buffer_type (&_cogl_##type_name##_class))
|
||||||
## type_name ## _get_type ()))
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_buffer_initialize (CoglBuffer *buffer,
|
_cogl_buffer_initialize (CoglBuffer *buffer,
|
||||||
|
@ -78,12 +78,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_buffer_register_buffer_type (GQuark type)
|
_cogl_buffer_register_buffer_type (const CoglObjectClass *klass)
|
||||||
{
|
{
|
||||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||||
|
|
||||||
ctx->buffer_types = g_slist_prepend (ctx->buffer_types,
|
ctx->buffer_types = g_slist_prepend (ctx->buffer_types, (void *) klass);
|
||||||
GINT_TO_POINTER (type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@ -98,7 +97,7 @@ cogl_is_buffer (const void *object)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
for (l = ctx->buffer_types; l; l = l->next)
|
for (l = ctx->buffer_types; l; l = l->next)
|
||||||
if (GPOINTER_TO_INT (l->data) == obj->klass->type)
|
if (l->data == obj->klass)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -109,7 +109,7 @@ typedef struct _CoglFramebufferStackEntry
|
|||||||
CoglFramebuffer *read_buffer;
|
CoglFramebuffer *read_buffer;
|
||||||
} CoglFramebufferStackEntry;
|
} CoglFramebufferStackEntry;
|
||||||
|
|
||||||
extern GQuark _cogl_object_onscreen_get_type (void);
|
extern CoglObjectClass _cogl_onscreen_class;
|
||||||
|
|
||||||
static void _cogl_offscreen_free (CoglOffscreen *offscreen);
|
static void _cogl_offscreen_free (CoglOffscreen *offscreen);
|
||||||
|
|
||||||
@ -136,8 +136,8 @@ _cogl_is_framebuffer (void *object)
|
|||||||
if (obj == NULL)
|
if (obj == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
return obj->klass->type == _cogl_object_onscreen_get_type ()
|
return (obj->klass == &_cogl_onscreen_class ||
|
||||||
|| obj->klass->type == _cogl_object_offscreen_get_type ();
|
obj->klass == &_cogl_offscreen_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -51,8 +51,8 @@ typedef void (*CoglUserDataDestroyInternalCallback) (void *user_data,
|
|||||||
|
|
||||||
typedef struct _CoglObjectClass
|
typedef struct _CoglObjectClass
|
||||||
{
|
{
|
||||||
GQuark type;
|
const char *name;
|
||||||
void *virt_free;
|
void *virt_free;
|
||||||
} CoglObjectClass;
|
} CoglObjectClass;
|
||||||
|
|
||||||
#define COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES 2
|
#define COGL_OBJECT_N_PRE_ALLOCATED_USER_DATA_ENTRIES 2
|
||||||
@ -95,18 +95,18 @@ struct _CoglObject
|
|||||||
#define _COGL_OBJECT_DEBUG_REF(type_name, object) G_STMT_START { \
|
#define _COGL_OBJECT_DEBUG_REF(type_name, object) G_STMT_START { \
|
||||||
CoglObject *__obj = (CoglObject *)object; \
|
CoglObject *__obj = (CoglObject *)object; \
|
||||||
COGL_NOTE (HANDLE, "COGL %s REF %p %i", \
|
COGL_NOTE (HANDLE, "COGL %s REF %p %i", \
|
||||||
g_quark_to_string ((__obj)->klass->type), \
|
(__obj)->klass->name, \
|
||||||
(__obj), (__obj)->ref_count); } G_STMT_END
|
(__obj), (__obj)->ref_count); } G_STMT_END
|
||||||
|
|
||||||
#define _COGL_OBJECT_DEBUG_UNREF(type_name, object) G_STMT_START { \
|
#define _COGL_OBJECT_DEBUG_UNREF(type_name, object) G_STMT_START { \
|
||||||
CoglObject *__obj = (CoglObject *)object; \
|
CoglObject *__obj = (CoglObject *)object; \
|
||||||
COGL_NOTE (HANDLE, "COGL %s UNREF %p %i", \
|
COGL_NOTE (HANDLE, "COGL %s UNREF %p %i", \
|
||||||
g_quark_to_string ((__obj)->klass->type), \
|
(__obj)->klass->name, \
|
||||||
(__obj), (__obj)->ref_count - 1); } G_STMT_END
|
(__obj), (__obj)->ref_count - 1); } G_STMT_END
|
||||||
|
|
||||||
#define COGL_OBJECT_DEBUG_FREE(obj) \
|
#define COGL_OBJECT_DEBUG_FREE(obj) \
|
||||||
COGL_NOTE (HANDLE, "COGL %s FREE %p", \
|
COGL_NOTE (HANDLE, "COGL %s FREE %p", \
|
||||||
g_quark_to_string ((obj)->klass->type), (obj))
|
(obj)->klass->name, (obj))
|
||||||
|
|
||||||
#else /* !COGL_OBJECT_DEBUG */
|
#else /* !COGL_OBJECT_DEBUG */
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ struct _CoglObject
|
|||||||
|
|
||||||
#define COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
#define COGL_OBJECT_COMMON_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
||||||
\
|
\
|
||||||
static CoglObjectClass _cogl_##type_name##_class; \
|
CoglObjectClass _cogl_##type_name##_class; \
|
||||||
static unsigned long _cogl_object_##type_name##_count; \
|
static unsigned long _cogl_object_##type_name##_count; \
|
||||||
\
|
\
|
||||||
static inline void \
|
static inline void \
|
||||||
@ -147,34 +147,6 @@ _cogl_object_##type_name##_indirect_free (CoglObject *obj) \
|
|||||||
_cogl_object_##type_name##_dec (); \
|
_cogl_object_##type_name##_dec (); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
GQuark \
|
|
||||||
_cogl_object_##type_name##_get_type (void) \
|
|
||||||
{ \
|
|
||||||
static GQuark type = 0; \
|
|
||||||
if (!type) \
|
|
||||||
{ \
|
|
||||||
type = g_quark_from_static_string ("Cogl"#TypeName); \
|
|
||||||
_cogl_object_##type_name##_count = 0; \
|
|
||||||
\
|
|
||||||
if (_cogl_debug_instances == NULL) \
|
|
||||||
_cogl_debug_instances = \
|
|
||||||
g_hash_table_new (g_str_hash, g_str_equal); \
|
|
||||||
\
|
|
||||||
g_hash_table_insert (_cogl_debug_instances, \
|
|
||||||
"Cogl"#TypeName, \
|
|
||||||
&_cogl_object_##type_name##_count); \
|
|
||||||
\
|
|
||||||
{ code; } \
|
|
||||||
} \
|
|
||||||
return type; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
GQuark \
|
|
||||||
_cogl_handle_##type_name##_get_type (void) \
|
|
||||||
{ \
|
|
||||||
return _cogl_object_##type_name##_get_type (); \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
static Cogl##TypeName * \
|
static Cogl##TypeName * \
|
||||||
_cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \
|
_cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \
|
||||||
{ \
|
{ \
|
||||||
@ -185,11 +157,23 @@ _cogl_##type_name##_object_new (Cogl##TypeName *new_obj) \
|
|||||||
obj->user_data_array = NULL; \
|
obj->user_data_array = NULL; \
|
||||||
\
|
\
|
||||||
obj->klass = &_cogl_##type_name##_class; \
|
obj->klass = &_cogl_##type_name##_class; \
|
||||||
if (!obj->klass->type) \
|
if (!obj->klass->virt_free) \
|
||||||
{ \
|
{ \
|
||||||
obj->klass->type = _cogl_object_##type_name##_get_type (); \
|
_cogl_object_##type_name##_count = 0; \
|
||||||
|
\
|
||||||
|
if (_cogl_debug_instances == NULL) \
|
||||||
|
_cogl_debug_instances = \
|
||||||
|
g_hash_table_new (g_str_hash, g_str_equal); \
|
||||||
|
\
|
||||||
obj->klass->virt_free = \
|
obj->klass->virt_free = \
|
||||||
_cogl_object_##type_name##_indirect_free; \
|
_cogl_object_##type_name##_indirect_free; \
|
||||||
|
obj->klass->name = "Cogl"#TypeName, \
|
||||||
|
\
|
||||||
|
g_hash_table_insert (_cogl_debug_instances, \
|
||||||
|
(void *) obj->klass->name, \
|
||||||
|
&_cogl_object_##type_name##_count); \
|
||||||
|
\
|
||||||
|
{ code; } \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
_cogl_object_##type_name##_inc (); \
|
_cogl_object_##type_name##_inc (); \
|
||||||
@ -215,8 +199,7 @@ cogl_is_##type_name (void *object) \
|
|||||||
if (object == NULL) \
|
if (object == NULL) \
|
||||||
return FALSE; \
|
return FALSE; \
|
||||||
\
|
\
|
||||||
return (obj->klass->type == \
|
return obj->klass == &_cogl_##type_name##_class; \
|
||||||
_cogl_object_##type_name##_get_type ()); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define COGL_OBJECT_INTERNAL_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
#define COGL_OBJECT_INTERNAL_DEFINE_WITH_CODE(TypeName, type_name, code) \
|
||||||
@ -231,8 +214,7 @@ _cogl_is_##type_name (void *object) \
|
|||||||
if (object == NULL) \
|
if (object == NULL) \
|
||||||
return FALSE; \
|
return FALSE; \
|
||||||
\
|
\
|
||||||
return (obj->klass->type == \
|
return obj->klass == &_cogl_##type_name##_class; \
|
||||||
_cogl_object_##type_name##_get_type ()); \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define COGL_OBJECT_DEFINE_DEPRECATED_REF_COUNTING(type_name) \
|
#define COGL_OBJECT_DEFINE_DEPRECATED_REF_COUNTING(type_name) \
|
||||||
|
@ -50,6 +50,7 @@ struct _CoglOnscreen
|
|||||||
|
|
||||||
void *winsys;
|
void *winsys;
|
||||||
};
|
};
|
||||||
|
|
||||||
CoglOnscreen *
|
CoglOnscreen *
|
||||||
_cogl_onscreen_new (void);
|
_cogl_onscreen_new (void);
|
||||||
|
|
||||||
@ -57,7 +58,4 @@ void
|
|||||||
_cogl_framebuffer_winsys_update_size (CoglFramebuffer *framebuffer,
|
_cogl_framebuffer_winsys_update_size (CoglFramebuffer *framebuffer,
|
||||||
int width, int height);
|
int width, int height);
|
||||||
|
|
||||||
GQuark
|
|
||||||
_cogl_object_onscreen_get_type (void);
|
|
||||||
|
|
||||||
#endif /* __COGL_ONSCREEN_PRIVATE_H */
|
#endif /* __COGL_ONSCREEN_PRIVATE_H */
|
||||||
|
@ -47,9 +47,6 @@ struct _CoglPixelBuffer
|
|||||||
unsigned int stride;
|
unsigned int stride;
|
||||||
};
|
};
|
||||||
|
|
||||||
GQuark
|
|
||||||
_cogl_handle_pixel_buffer_get_type (void);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __COGL_PIXEL_BUFFER_PRIVATE_H__ */
|
#endif /* __COGL_PIXEL_BUFFER_PRIVATE_H__ */
|
||||||
|
@ -54,7 +54,4 @@ struct _CoglSubTexture
|
|||||||
int sub_height;
|
int sub_height;
|
||||||
};
|
};
|
||||||
|
|
||||||
GQuark
|
|
||||||
_cogl_handle_sub_texture_get_type (void);
|
|
||||||
|
|
||||||
#endif /* __COGL_SUB_TEXTURE_PRIVATE_H */
|
#endif /* __COGL_SUB_TEXTURE_PRIVATE_H */
|
||||||
|
@ -52,9 +52,6 @@ struct _CoglTexture2D
|
|||||||
CoglTexturePixel first_pixel;
|
CoglTexturePixel first_pixel;
|
||||||
};
|
};
|
||||||
|
|
||||||
GQuark
|
|
||||||
_cogl_handle_texture_2d_get_type (void);
|
|
||||||
|
|
||||||
CoglHandle
|
CoglHandle
|
||||||
_cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
|
_cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
|
||||||
CoglTextureFlags flags,
|
CoglTextureFlags flags,
|
||||||
|
@ -43,9 +43,6 @@ struct _CoglTexture2DSliced
|
|||||||
int height;
|
int height;
|
||||||
};
|
};
|
||||||
|
|
||||||
GQuark
|
|
||||||
_cogl_handle_texture_2d_sliced_get_type (void);
|
|
||||||
|
|
||||||
CoglTexture2DSliced *
|
CoglTexture2DSliced *
|
||||||
_cogl_texture_2d_sliced_new_from_foreign (GLuint gl_handle,
|
_cogl_texture_2d_sliced_new_from_foreign (GLuint gl_handle,
|
||||||
GLenum gl_target,
|
GLenum gl_target,
|
||||||
|
@ -58,9 +58,6 @@ struct _CoglTexture3D
|
|||||||
CoglTexturePixel first_pixel;
|
CoglTexturePixel first_pixel;
|
||||||
};
|
};
|
||||||
|
|
||||||
GQuark
|
|
||||||
_cogl_handle_texture_3d_get_type (void);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* cogl_texture_3d_new_from_bitmap:
|
* cogl_texture_3d_new_from_bitmap:
|
||||||
* @bmp_handle: A #CoglHandle to a bitmap.
|
* @bmp_handle: A #CoglHandle to a bitmap.
|
||||||
|
@ -168,19 +168,17 @@ _cogl_texture_free (CoglTexture *texture);
|
|||||||
/* This is used to register a type to the list of handle types that
|
/* This is used to register a type to the list of handle types that
|
||||||
will be considered a texture in cogl_is_texture() */
|
will be considered a texture in cogl_is_texture() */
|
||||||
void
|
void
|
||||||
_cogl_texture_register_texture_type (GQuark type);
|
_cogl_texture_register_texture_type (const CoglObjectClass *klass);
|
||||||
|
|
||||||
#define COGL_TEXTURE_DEFINE(TypeName, type_name) \
|
#define COGL_TEXTURE_DEFINE(TypeName, type_name) \
|
||||||
COGL_HANDLE_DEFINE_WITH_CODE \
|
COGL_HANDLE_DEFINE_WITH_CODE \
|
||||||
(TypeName, type_name, \
|
(TypeName, type_name, \
|
||||||
_cogl_texture_register_texture_type (_cogl_handle_ \
|
_cogl_texture_register_texture_type (&_cogl_##type_name##_class))
|
||||||
## type_name ## _get_type ()))
|
|
||||||
|
|
||||||
#define COGL_TEXTURE_INTERNAL_DEFINE(TypeName, type_name) \
|
#define COGL_TEXTURE_INTERNAL_DEFINE(TypeName, type_name) \
|
||||||
COGL_HANDLE_INTERNAL_DEFINE_WITH_CODE \
|
COGL_HANDLE_INTERNAL_DEFINE_WITH_CODE \
|
||||||
(TypeName, type_name, \
|
(TypeName, type_name, \
|
||||||
_cogl_texture_register_texture_type (_cogl_handle_ \
|
_cogl_texture_register_texture_type (&_cogl_##type_name##_class))
|
||||||
## type_name ## _get_type ()))
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
_cogl_texture_can_hardware_repeat (CoglTexture *texture);
|
_cogl_texture_can_hardware_repeat (CoglTexture *texture);
|
||||||
|
@ -47,9 +47,6 @@ struct _CoglTextureRectangle
|
|||||||
gboolean is_foreign;
|
gboolean is_foreign;
|
||||||
};
|
};
|
||||||
|
|
||||||
GQuark
|
|
||||||
_cogl_handle_texture_rectangle_get_type (void);
|
|
||||||
|
|
||||||
CoglTextureRectangle *
|
CoglTextureRectangle *
|
||||||
_cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp,
|
_cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp,
|
||||||
CoglTextureFlags flags,
|
CoglTextureFlags flags,
|
||||||
|
@ -70,12 +70,11 @@ cogl_texture_error_quark (void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
_cogl_texture_register_texture_type (GQuark type)
|
_cogl_texture_register_texture_type (const CoglObjectClass *klass)
|
||||||
{
|
{
|
||||||
_COGL_GET_CONTEXT (ctxt, NO_RETVAL);
|
_COGL_GET_CONTEXT (ctxt, NO_RETVAL);
|
||||||
|
|
||||||
ctxt->texture_types = g_slist_prepend (ctxt->texture_types,
|
ctxt->texture_types = g_slist_prepend (ctxt->texture_types, (void *) klass);
|
||||||
GINT_TO_POINTER (type));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
@ -90,7 +89,7 @@ cogl_is_texture (void *object)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
for (l = ctxt->texture_types; l; l = l->next)
|
for (l = ctxt->texture_types; l; l = l->next)
|
||||||
if (GPOINTER_TO_INT (l->data) == obj->klass->type)
|
if (l->data == obj->klass)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -81,7 +81,4 @@ struct _CoglTexturePixmapX11
|
|||||||
gboolean use_winsys_texture;
|
gboolean use_winsys_texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
GQuark
|
|
||||||
_cogl_handle_texture_pixmap_x11_get_type (void);
|
|
||||||
|
|
||||||
#endif /* __COGL_TEXTURE_PIXMAP_X11_PRIVATE_H */
|
#endif /* __COGL_TEXTURE_PIXMAP_X11_PRIVATE_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user