mirror of
https://github.com/brl/mutter.git
synced 2024-12-27 13:22:15 +00:00
cogl-buffer: Handle subclass registration like cogl-texture
Instead of having to extend cogl_is_buffer with new buffer types manually this now adds a new COGL_BUFFER_DEFINE macro to be used instead of COGL_OBJECT_DEFINE for CoglBuffer subclasses. This macro will automatically register the new type with ctx->buffer_types which will iterated by cogl_is_buffer. This is the same coding pattern used for CoglTexture.
This commit is contained in:
parent
90931e261f
commit
7820842262
@ -86,6 +86,18 @@ struct _CoglBuffer
|
||||
* fallback paths */
|
||||
};
|
||||
|
||||
/* This is used to register a type to the list of handle types that
|
||||
will be considered a texture in cogl_is_texture() */
|
||||
void
|
||||
_cogl_buffer_register_buffer_type (GQuark type);
|
||||
|
||||
#define COGL_BUFFER_DEFINE(TypeName, type_name) \
|
||||
COGL_OBJECT_DEFINE_WITH_CODE \
|
||||
(TypeName, type_name, \
|
||||
_cogl_buffer_register_buffer_type (_cogl_object_ \
|
||||
## type_name ## _get_type ()))
|
||||
|
||||
|
||||
void _cogl_buffer_initialize (CoglBuffer *buffer,
|
||||
unsigned int size,
|
||||
CoglBufferUsageHint usage_hint,
|
||||
|
@ -68,15 +68,37 @@
|
||||
|
||||
#endif
|
||||
|
||||
/* XXX:
|
||||
* The CoglHandle macros don't support any form of inheritance, so for
|
||||
* now we implement the CoglObject support for the CoglBuffer
|
||||
* abstract class manually.
|
||||
*/
|
||||
|
||||
void
|
||||
_cogl_buffer_register_buffer_type (GQuark type)
|
||||
{
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
|
||||
ctx->buffer_types = g_slist_prepend (ctx->buffer_types,
|
||||
GINT_TO_POINTER (type));
|
||||
}
|
||||
|
||||
gboolean
|
||||
cogl_is_buffer (const void *object)
|
||||
{
|
||||
CoglObject *obj = (CoglObject *)object;
|
||||
const CoglHandleObject *obj = object;
|
||||
GSList *l;
|
||||
|
||||
if (obj == NULL)
|
||||
_COGL_GET_CONTEXT (ctx, FALSE);
|
||||
|
||||
if (object == NULL)
|
||||
return FALSE;
|
||||
|
||||
return obj->klass->type == _cogl_handle_pixel_buffer_get_type ();
|
||||
for (l = ctx->buffer_types; l; l = l->next)
|
||||
if (GPOINTER_TO_INT (l->data) == obj->klass->type)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -70,6 +70,7 @@ cogl_create_context (void)
|
||||
_context->features_cached = FALSE;
|
||||
|
||||
_context->texture_types = NULL;
|
||||
_context->buffer_types = NULL;
|
||||
|
||||
/* Initialise the driver specific state */
|
||||
/* TODO: combine these two into one function */
|
||||
@ -262,6 +263,7 @@ _cogl_destroy_context (void)
|
||||
_cogl_bitmask_destroy (&_context->texcoord_arrays_to_disable);
|
||||
|
||||
g_slist_free (_context->texture_types);
|
||||
g_slist_free (_context->buffer_types);
|
||||
|
||||
g_free (_context);
|
||||
}
|
||||
|
@ -167,6 +167,10 @@ typedef struct
|
||||
cogl_is_texture */
|
||||
GSList *texture_types;
|
||||
|
||||
/* List of types that will be considered a subclass of CoglBuffer in
|
||||
cogl_is_buffer */
|
||||
GSList *buffer_types;
|
||||
|
||||
CoglContextDriver drv;
|
||||
CoglContextWinsys winsys;
|
||||
} CoglContext;
|
||||
|
@ -84,7 +84,7 @@ cogl_pixel_buffer_vtable;
|
||||
static const CoglBufferVtable
|
||||
cogl_malloc_pixel_buffer_vtable;
|
||||
|
||||
COGL_OBJECT_DEFINE (PixelBuffer, pixel_buffer)
|
||||
COGL_BUFFER_DEFINE (PixelBuffer, pixel_buffer)
|
||||
|
||||
CoglPixelBuffer *
|
||||
cogl_pixel_buffer_new (unsigned int size)
|
||||
|
Loading…
Reference in New Issue
Block a user