[cogl-handle] Optimize how we define cogl handles

The cogl_is_* functions were showing up quite high on profiles due to
iterating through arrays of cogl handles.

This does away with all the handle arrays and implements a simple struct
inheritance scheme. All cogl objects now add a CoglHandleObject _parent;
member to their main structures. The base object includes 2 members a.t.m; a
ref_count, and a klass pointer. The klass in turn gives you a type and
virtual function for freeing objects of that type.

Each handle type has a _cogl_##handle_type##_get_type () function
automatically defined which returns a GQuark of the handle type, so now
implementing the cogl_is_* funcs is just a case of comparing with
obj->klass->type.

Another outcome of the re-work is that cogl_handle_{ref,unref} are also much
more efficient, and no longer need extending for each handle type added to
cogl. The cogl_##handle_type##_{ref,unref} functions are now deprecated and
are no longer used internally to Clutter or Cogl. Potentially we can remove
them completely before 1.0.
This commit is contained in:
Robert Bragg 2009-04-01 17:16:44 +01:00
parent 04ebd6be44
commit c3d9f0bed4
43 changed files with 206 additions and 317 deletions

View File

@ -592,13 +592,13 @@ clutter_shader_release (ClutterShader *shader)
g_assert (priv->program != COGL_INVALID_HANDLE); g_assert (priv->program != COGL_INVALID_HANDLE);
if (priv->vertex_is_glsl && priv->vertex_shader != COGL_INVALID_HANDLE) if (priv->vertex_is_glsl && priv->vertex_shader != COGL_INVALID_HANDLE)
cogl_shader_unref (priv->vertex_shader); cogl_handle_unref (priv->vertex_shader);
if (priv->fragment_is_glsl && priv->fragment_shader != COGL_INVALID_HANDLE) if (priv->fragment_is_glsl && priv->fragment_shader != COGL_INVALID_HANDLE)
cogl_shader_unref (priv->fragment_shader); cogl_handle_unref (priv->fragment_shader);
if (priv->program != COGL_INVALID_HANDLE) if (priv->program != COGL_INVALID_HANDLE)
cogl_program_unref (priv->program); cogl_handle_unref (priv->program);
priv->vertex_shader = COGL_INVALID_HANDLE; priv->vertex_shader = COGL_INVALID_HANDLE;
priv->fragment_shader = COGL_INVALID_HANDLE; priv->fragment_shader = COGL_INVALID_HANDLE;

View File

@ -246,7 +246,7 @@ clutter_texture_unrealize (ClutterActor *actor)
if (priv->fbo_source != COGL_INVALID_HANDLE) if (priv->fbo_source != COGL_INVALID_HANDLE)
{ {
/* Free up our fbo handle and texture resources, realize will recreate */ /* Free up our fbo handle and texture resources, realize will recreate */
cogl_offscreen_unref (priv->fbo_handle); cogl_handle_unref (priv->fbo_handle);
priv->fbo_handle = COGL_INVALID_HANDLE; priv->fbo_handle = COGL_INVALID_HANDLE;
texture_free_gl_resources (texture); texture_free_gl_resources (texture);
return; return;
@ -293,7 +293,7 @@ clutter_texture_realize (ClutterActor *actor)
/* Handle FBO's */ /* Handle FBO's */
if (priv->fbo_texture != COGL_INVALID_HANDLE) if (priv->fbo_texture != COGL_INVALID_HANDLE)
cogl_texture_unref (priv->fbo_texture); cogl_handle_unref (priv->fbo_texture);
if (!priv->no_slice) if (!priv->no_slice)
max_waste = priv->max_tile_waste; max_waste = priv->max_tile_waste;
@ -766,7 +766,7 @@ clutter_texture_finalize (GObject *object)
if (priv->material != COGL_INVALID_HANDLE) if (priv->material != COGL_INVALID_HANDLE)
{ {
cogl_material_unref (priv->material); cogl_handle_unref (priv->material);
priv->material = COGL_INVALID_HANDLE; priv->material = COGL_INVALID_HANDLE;
} }
@ -1302,7 +1302,7 @@ clutter_texture_load_from_local_data (ClutterTexture *texture)
* *
* Returns a handle to the underlying COGL material used for drawing * Returns a handle to the underlying COGL material used for drawing
* the actor. No extra reference is taken so if you need to keep the * the actor. No extra reference is taken so if you need to keep the
* handle then you should call cogl_material_ref() on it. * handle then you should call cogl_handle_ref() on it.
* *
* Since: 1.0 * Since: 1.0
* *
@ -1323,7 +1323,7 @@ clutter_texture_get_cogl_material (ClutterTexture *texture)
* *
* Replaces the underlying COGL texture drawn by this actor with * Replaces the underlying COGL texture drawn by this actor with
* @cogl_tex. A reference to the texture is taken so if the handle is * @cogl_tex. A reference to the texture is taken so if the handle is
* no longer needed it should be deref'd with cogl_texture_unref. * no longer needed it should be deref'd with cogl_handle_unref.
* *
* Since: 0.8 * Since: 0.8
* *
@ -1338,7 +1338,7 @@ clutter_texture_set_cogl_material (ClutterTexture *texture,
/* This */ /* This */
if (texture->priv->material) if (texture->priv->material)
cogl_material_unref (texture->priv->material); cogl_handle_unref (texture->priv->material);
texture->priv->material = cogl_material; texture->priv->material = cogl_material;
@ -1356,7 +1356,7 @@ clutter_texture_set_cogl_material (ClutterTexture *texture,
* *
* Retrieves the handle to the underlying COGL texture used for drawing * Retrieves the handle to the underlying COGL texture used for drawing
* the actor. No extra reference is taken so if you need to keep the * the actor. No extra reference is taken so if you need to keep the
* handle then you should call cogl_texture_ref() on it. * handle then you should call cogl_handle_ref() on it.
* *
* The texture handle returned is the first layer of the material * The texture handle returned is the first layer of the material
* handle used by the #ClutterTexture. If you need to access the other * handle used by the #ClutterTexture. If you need to access the other
@ -1390,7 +1390,7 @@ clutter_texture_get_cogl_texture (ClutterTexture *texture)
* *
* Replaces the underlying COGL texture drawn by this actor with * Replaces the underlying COGL texture drawn by this actor with
* @cogl_tex. A reference to the texture is taken so if the handle is * @cogl_tex. A reference to the texture is taken so if the handle is
* no longer needed it should be deref'd with cogl_texture_unref. * no longer needed it should be deref'd with cogl_handle_unref.
* *
* Since: 0.8 * Since: 0.8
*/ */
@ -1412,7 +1412,7 @@ clutter_texture_set_cogl_texture (ClutterTexture *texture,
/* Reference the new texture now in case it is the same one we are /* Reference the new texture now in case it is the same one we are
already using */ already using */
cogl_texture_ref (cogl_tex); cogl_handle_ref (cogl_tex);
/* Remove FBO if exisiting */ /* Remove FBO if exisiting */
if (priv->fbo_source) if (priv->fbo_source)
@ -1426,7 +1426,7 @@ clutter_texture_set_cogl_texture (ClutterTexture *texture,
/* The material now holds a reference to the texture so we can /* The material now holds a reference to the texture so we can
safely release the reference we claimed above */ safely release the reference we claimed above */
cogl_texture_unref (cogl_tex); cogl_handle_unref (cogl_tex);
size_change = width != priv->width || height != priv->height; size_change = width != priv->width || height != priv->height;
priv->width = width; priv->width = width;
@ -1504,7 +1504,7 @@ clutter_texture_set_from_data (ClutterTexture *texture,
clutter_texture_set_cogl_texture (texture, new_texture); clutter_texture_set_cogl_texture (texture, new_texture);
cogl_texture_unref (new_texture); cogl_handle_unref (new_texture);
g_signal_emit (texture, texture_signals[LOAD_FINISHED], 0, error); g_signal_emit (texture, texture_signals[LOAD_FINISHED], 0, error);
@ -1681,7 +1681,7 @@ clutter_texture_async_load_complete (ClutterTexture *self,
cogl_texture_get_width(handle), cogl_texture_get_width(handle),
cogl_texture_get_height (handle)); cogl_texture_get_height (handle));
} }
cogl_texture_unref (handle); cogl_handle_unref (handle);
} }
g_signal_emit (self, texture_signals[LOAD_FINISHED], 0, error); g_signal_emit (self, texture_signals[LOAD_FINISHED], 0, error);
@ -1949,7 +1949,7 @@ clutter_texture_set_from_file (ClutterTexture *texture,
clutter_texture_set_cogl_texture (texture, new_texture); clutter_texture_set_cogl_texture (texture, new_texture);
cogl_texture_unref (new_texture); cogl_handle_unref (new_texture);
g_signal_emit (texture, texture_signals[LOAD_FINISHED], 0, error); g_signal_emit (texture, texture_signals[LOAD_FINISHED], 0, error);
@ -2301,7 +2301,7 @@ on_fbo_source_size_change (GObject *object,
gint min_filter, mag_filter; gint min_filter, mag_filter;
/* tear down the FBO */ /* tear down the FBO */
cogl_offscreen_unref (priv->fbo_handle); cogl_handle_unref (priv->fbo_handle);
texture_free_gl_resources (texture); texture_free_gl_resources (texture);
@ -2548,7 +2548,7 @@ texture_fbo_free_resources (ClutterTexture *texture)
if (priv->fbo_handle != COGL_INVALID_HANDLE) if (priv->fbo_handle != COGL_INVALID_HANDLE)
{ {
cogl_offscreen_unref (priv->fbo_handle); cogl_handle_unref (priv->fbo_handle);
priv->fbo_handle = COGL_INVALID_HANDLE; priv->fbo_handle = COGL_INVALID_HANDLE;
} }
} }

View File

@ -26,82 +26,92 @@
#ifndef __COGL_HANDLE_H #ifndef __COGL_HANDLE_H
#define __COGL_HANDLE_H #define __COGL_HANDLE_H
typedef struct _CoglHandleClass
{
GQuark type;
void *virt_free;
} CoglHandleClass;
/* All Cogl objects inherit from this base object by adding a member:
*
* CoglHandleObject _parent;
*
* at the top of its main structure. This structure is initialized
* when you call _cogl_#type_name#_handle_new (new_object);
*/
typedef struct _CoglHandleObject
{
guint ref_count;
CoglHandleClass *klass;
} CoglHandleObject;
/* Helper macro to encapsulate the common code for COGL reference /* Helper macro to encapsulate the common code for COGL reference
counted handles */ counted handles */
#if COGL_DEBUG #if COGL_DEBUG
#define COGL_HANDLE_DEBUG_NEW(type_name, obj) \ #define _COGL_HANDLE_DEBUG_NEW(type_name, obj) \
printf ("COGL " G_STRINGIFY (type_name) " NEW %p %i\n", \ printf ("COGL " G_STRINGIFY (type_name) " NEW %p %i\n", \
(obj), (obj)->ref_count) (obj), (obj)->ref_count)
#define COGL_HANDLE_DEBUG_REF(type_name, obj) \ #define _COGL_HANDLE_DEBUG_REF(type_name, handle) \
printf ("COGL " G_STRINGIFY (type_name) " REF %p %i\n", \ do { \
(obj), (obj)->ref_count) CoglHandleObject *obj = (CoglHandleObject *)handle; \
printf ("COGL %s REF %p %i\n", \
g_quark_to_string ((obj)->klass->type), \
(obj), (obj)->ref_count) \
} while (0)
#define COGL_HANDLE_DEBUG_UNREF(type_name, obj) \ #define _COGL_HANDLE_DEBUG_UNREF(type_name, handle) \
printf ("COGL " G_STRINGIFY (type_name) " UNREF %p %i\n", \ do { \
(obj), (obj)->ref_count - 1) CoglHandleObject *obj = (CoglHandleObject *)handle; \
printf ("COGL %s UNREF %p %i\n", \
g_quark_to_string ((obj)->klass->type), \
(obj), (obj)->ref_count - 1)
} while (0)
#define COGL_HANDLE_DEBUG_FREE(type_name, obj) \ #define COGL_HANDLE_DEBUG_FREE(obj) \
printf ("COGL " G_STRINGIFY (type_name) " FREE %p\n", (obj)) printf ("COGL %s FREE %p\n", \
g_quark_to_string ((obj)->klass->type), (obj)) \
#else /* COGL_DEBUG */ #else /* COGL_DEBUG */
#define COGL_HANDLE_DEBUG_NEW(type_name, obj) (void) 0 #define _COGL_HANDLE_DEBUG_NEW(type_name, obj)
#define COGL_HANDLE_DEBUG_REF(type_name, obj) (void) 0 #define _COGL_HANDLE_DEBUG_REF(type_name, obj)
#define COGL_HANDLE_DEBUG_UNREF(type_name, obj) (void) 0 #define _COGL_HANDLE_DEBUG_UNREF(type_name, obj)
#define COGL_HANDLE_DEBUG_FREE(type_name, obj) (void) 0 #define COGL_HANDLE_DEBUG_FREE(obj)
#endif /* COGL_DEBUG */ #endif /* COGL_DEBUG */
#define COGL_HANDLE_DEFINE(TypeName, type_name, handle_array) \ #define COGL_HANDLE_DEFINE(TypeName, type_name) \
\ \
static gint \ static CoglHandleClass _cogl_##type_name##_class; \
_cogl_##type_name##_handle_find (CoglHandle handle) \
{ \
gint i; \
\ \
_COGL_GET_CONTEXT (ctx, -1); \ static GQuark \
\ _cogl_##type_name##_get_type (void) \
if (ctx->handle_array == NULL) \ { \
return -1; \ static GQuark type = 0; \
\ if (!type) \
for (i=0; i < ctx->handle_array->len; ++i) \ type = g_quark_from_static_string ("Cogl"#TypeName); \
if (g_array_index (ctx->handle_array, \ return type; \
CoglHandle, i) == handle) \ } \
return i; \
\
return -1; \
} \
\ \
static CoglHandle \ static CoglHandle \
_cogl_##type_name##_handle_new (Cogl##TypeName *obj) \ _cogl_##type_name##_handle_new (Cogl##TypeName *new_obj) \
{ \ { \
CoglHandle handle = (CoglHandle) obj; \ CoglHandleObject *obj = &new_obj->_parent; \
obj->ref_count = 1; \
\ \
_COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); \ obj->klass = &_cogl_##type_name##_class; \
if (!obj->klass->type) \
{ \
obj->klass->type = \
_cogl_##type_name##_get_type (); \
obj->klass->virt_free = _cogl_##type_name##_free; \
} \
\ \
if (ctx->handle_array == NULL) \ _COGL_HANDLE_DEBUG_NEW (TypeName, obj); \
ctx->handle_array \ return (CoglHandle) new_obj; \
= g_array_new (FALSE, FALSE, sizeof (CoglHandle)); \
\
g_array_append_val (ctx->handle_array, handle); \
\
return handle; \
} \
\
static void \
_cogl_##type_name##_handle_release (CoglHandle handle) \
{ \
gint i; \
\
_COGL_GET_CONTEXT (ctx, NO_RETVAL); \
\
if ( (i = _cogl_##type_name##_handle_find (handle)) == -1) \
return; \
\
g_array_remove_index_fast (ctx->handle_array, i); \
} \ } \
\ \
Cogl##TypeName * \ Cogl##TypeName * \
@ -112,49 +122,40 @@
\ \
gboolean \ gboolean \
cogl_is_##type_name (CoglHandle handle) \ cogl_is_##type_name (CoglHandle handle) \
{ \ { \
if (handle == COGL_INVALID_HANDLE) \ CoglHandleObject *obj = (CoglHandleObject *)handle; \
return FALSE; \ \
\ return (obj->klass->type == \
return _cogl_##type_name##_handle_find (handle) >= 0; \ _cogl_##type_name##_get_type ()); \
} \ } \
\ \
CoglHandle \ CoglHandle G_GNUC_DEPRECATED \
cogl_##type_name##_ref (CoglHandle handle) \ cogl_##type_name##_ref (CoglHandle handle) \
{ \ { \
Cogl##TypeName *obj; \
\
if (!cogl_is_##type_name (handle)) \ if (!cogl_is_##type_name (handle)) \
return COGL_INVALID_HANDLE; \ return COGL_INVALID_HANDLE; \
\
_COGL_HANDLE_DEBUG_REF (TypeName, handle); \
\ \
obj = _cogl_##type_name##_pointer_from_handle (handle); \ cogl_handle_ref (handle); \
\
obj->ref_count++; \
\
COGL_HANDLE_DEBUG_REF (type_name, obj); \
\ \
return handle; \ return handle; \
} \ } \
\ \
void \ void G_GNUC_DEPRECATED \
cogl_##type_name##_unref (CoglHandle handle) \ cogl_##type_name##_unref (CoglHandle handle) \
{ \ { \
Cogl##TypeName *obj; \
\
if (!cogl_is_##type_name (handle)) \ if (!cogl_is_##type_name (handle)) \
return; \ { \
g_warning (G_STRINGIFY (cogl_##type_name##_unref) \
": Ignoring unref of Cogl handle " \
"due to type missmatch"); \
return; \
} \
\ \
obj = _cogl_##type_name##_pointer_from_handle (handle); \ _COGL_HANDLE_DEBUG_UNREF (TypeName, handle); \
\ \
COGL_HANDLE_DEBUG_UNREF (type_name, obj); \ cogl_handle_unref (handle); \
\
if (--obj->ref_count < 1) \
{ \
COGL_HANDLE_DEBUG_FREE (type_name, obj); \
\
_cogl_##type_name##_handle_release (obj); \
_cogl_##type_name##_free (obj); \
} \
} }
#endif /* __COGL_HANDLE_H */ #endif /* __COGL_HANDLE_H */

View File

@ -3,6 +3,7 @@
#include "cogl-material.h" #include "cogl-material.h"
#include "cogl-matrix.h" #include "cogl-matrix.h"
#include "cogl-handle.h"
#include <glib.h> #include <glib.h>
@ -34,7 +35,7 @@ typedef struct _CoglLayerInfo
struct _CoglMaterialLayer struct _CoglMaterialLayer
{ {
guint ref_count; CoglHandleObject _parent;
guint index; /*!< lowest index is blended first then others guint index; /*!< lowest index is blended first then others
on top */ on top */
gulong flags; gulong flags;
@ -68,7 +69,7 @@ typedef enum _CoglMaterialFlags
struct _CoglMaterial struct _CoglMaterial
{ {
guint ref_count; CoglHandleObject _parent;
gulong flags; gulong flags;

View File

@ -30,10 +30,8 @@
static void _cogl_material_free (CoglMaterial *tex); static void _cogl_material_free (CoglMaterial *tex);
static void _cogl_material_layer_free (CoglMaterialLayer *layer); static void _cogl_material_layer_free (CoglMaterialLayer *layer);
COGL_HANDLE_DEFINE (Material, material, material_handles); COGL_HANDLE_DEFINE (Material, material);
COGL_HANDLE_DEFINE (MaterialLayer, COGL_HANDLE_DEFINE (MaterialLayer, material_layer);
material_layer,
material_layer_handles);
/* #define DISABLE_MATERIAL_CACHE 1 */ /* #define DISABLE_MATERIAL_CACHE 1 */
@ -48,9 +46,6 @@ cogl_material_new (void)
GLfloat *specular = material->specular; GLfloat *specular = material->specular;
GLfloat *emission = material->emission; GLfloat *emission = material->emission;
material->ref_count = 1;
COGL_HANDLE_DEBUG_NEW (material, material);
/* Use the same defaults as the GL spec... */ /* Use the same defaults as the GL spec... */
unlit[0] = 1.0; unlit[1] = 1.0; unlit[2] = 1.0; unlit[3] = 1.0; unlit[0] = 1.0; unlit[1] = 1.0; unlit[2] = 1.0; unlit[3] = 1.0;
material->flags |= COGL_MATERIAL_FLAG_DEFAULT_COLOR; material->flags |= COGL_MATERIAL_FLAG_DEFAULT_COLOR;
@ -84,7 +79,7 @@ _cogl_material_free (CoglMaterial *material)
released! Do that separately before this! */ released! Do that separately before this! */
g_list_foreach (material->layers, g_list_foreach (material->layers,
(GFunc)cogl_material_layer_unref, NULL); (GFunc)cogl_handle_unref, NULL);
g_free (material); g_free (material);
} }
@ -424,7 +419,7 @@ _cogl_material_get_layer (CoglMaterial *material,
layer = g_new0 (CoglMaterialLayer, 1); layer = g_new0 (CoglMaterialLayer, 1);
layer->ref_count = 1; layer_handle = _cogl_material_layer_handle_new (layer);
layer->index = index_; layer->index = index_;
layer->flags = COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE; layer->flags = COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE;
layer->texture = COGL_INVALID_HANDLE; layer->texture = COGL_INVALID_HANDLE;
@ -449,7 +444,6 @@ _cogl_material_get_layer (CoglMaterial *material,
cogl_matrix_init_identity (&layer->matrix); cogl_matrix_init_identity (&layer->matrix);
layer_handle = _cogl_material_layer_handle_new (layer);
/* Note: see comment after for() loop above */ /* Note: see comment after for() loop above */
material->layers = material->layers =
g_list_insert_before (material->layers, tmp, layer_handle); g_list_insert_before (material->layers, tmp, layer_handle);
@ -488,10 +482,10 @@ cogl_material_set_layer (CoglHandle material_handle,
* MAX_COMBINED_TEXTURE_IMAGE_UNITS layers. */ * MAX_COMBINED_TEXTURE_IMAGE_UNITS layers. */
} }
cogl_texture_ref (texture_handle); cogl_handle_ref (texture_handle);
if (layer->texture) if (layer->texture)
cogl_texture_unref (layer->texture); cogl_handle_unref (layer->texture);
layer->texture = texture_handle; layer->texture = texture_handle;
@ -625,7 +619,7 @@ cogl_material_set_layer_matrix (CoglHandle material_handle,
static void static void
_cogl_material_layer_free (CoglMaterialLayer *layer) _cogl_material_layer_free (CoglMaterialLayer *layer)
{ {
cogl_texture_unref (layer->texture); cogl_handle_unref (layer->texture);
g_free (layer); g_free (layer);
} }
@ -646,7 +640,7 @@ cogl_material_remove_layer (CoglHandle material_handle,
if (layer->index == layer_index) if (layer->index == layer_index)
{ {
CoglHandle handle = (CoglHandle) layer; CoglHandle handle = (CoglHandle) layer;
cogl_material_layer_unref (handle); cogl_handle_unref (handle);
material->layers = g_list_remove (material->layers, layer); material->layers = g_list_remove (material->layers, layer);
break; break;
} }
@ -1131,8 +1125,9 @@ cogl_material_flush_gl_state (CoglHandle handle, ...)
* cogl_material_flush_gl_state is called, we can compare the incomming * cogl_material_flush_gl_state is called, we can compare the incomming
* material pointer with ctx->current_material * material pointer with ctx->current_material
*/ */
cogl_material_ref (handle); cogl_handle_ref (handle);
cogl_material_unref (ctx->current_material); if (ctx->current_material)
cogl_handle_unref (ctx->current_material);
ctx->current_material = handle; ctx->current_material = handle;
ctx->current_material_flags = material->flags; ctx->current_material_flags = material->flags;
@ -1150,10 +1145,10 @@ cogl_set_source (CoglHandle material_handle)
if (ctx->source_material == material_handle) if (ctx->source_material == material_handle)
return; return;
cogl_material_ref (material_handle); cogl_handle_ref (material_handle);
if (ctx->source_material) if (ctx->source_material)
cogl_material_unref (ctx->source_material); cogl_handle_unref (ctx->source_material);
ctx->source_material = material_handle; ctx->source_material = material_handle;
} }

View File

@ -40,6 +40,7 @@
#include "cogl-shader.h" #include "cogl-shader.h"
#include "cogl-texture.h" #include "cogl-texture.h"
#include "cogl-types.h" #include "cogl-types.h"
#include "cogl-handle.h"
#include "cogl-util.h" #include "cogl-util.h"
/** /**
@ -66,45 +67,29 @@ cogl_util_next_p2 (int a)
CoglHandle CoglHandle
cogl_handle_ref (CoglHandle handle) cogl_handle_ref (CoglHandle handle)
{ {
CoglHandleObject *obj = (CoglHandleObject *)handle;
g_return_val_if_fail (handle != COGL_INVALID_HANDLE, COGL_INVALID_HANDLE); g_return_val_if_fail (handle != COGL_INVALID_HANDLE, COGL_INVALID_HANDLE);
if (cogl_is_texture (handle)) obj->ref_count++;
return cogl_texture_ref (handle); return handle;
if (cogl_is_offscreen (handle))
return cogl_offscreen_ref (handle);
if (cogl_is_material (handle))
return cogl_material_ref (handle);
if (cogl_is_program (handle))
return cogl_program_ref (handle);
if (cogl_is_shader (handle))
return cogl_shader_ref (handle);
return COGL_INVALID_HANDLE;
} }
void void
cogl_handle_unref (CoglHandle handle) cogl_handle_unref (CoglHandle handle)
{ {
CoglHandleObject *obj = (CoglHandleObject *)handle;
g_return_if_fail (handle != COGL_INVALID_HANDLE); g_return_if_fail (handle != COGL_INVALID_HANDLE);
if (cogl_is_texture (handle)) if (--obj->ref_count < 1)
cogl_texture_unref (handle); {
void (*free_func)(void *obj);
if (cogl_is_offscreen (handle)) COGL_HANDLE_DEBUG_FREE (obj);
cogl_offscreen_unref (handle); free_func = obj->klass->virt_free;
free_func (obj);
if (cogl_is_material (handle)) }
cogl_material_unref (handle);
if (cogl_is_program (handle))
cogl_program_unref (handle);
if (cogl_is_shader (handle))
cogl_shader_unref (handle);
} }
GType GType

View File

@ -24,6 +24,10 @@
#ifndef __COGL_VERTEX_BUFFER_H #ifndef __COGL_VERTEX_BUFFER_H
#define __COGL_VERTEX_BUFFER_H #define __COGL_VERTEX_BUFFER_H
#include "cogl-handle.h"
#include <glib.h>
/* Note we put quite a bit into the flags here to help keep /* Note we put quite a bit into the flags here to help keep
* the down size of the CoglVertexBufferAttrib struct below. */ * the down size of the CoglVertexBufferAttrib struct below. */
typedef enum _CoglVertexBufferAttribFlags typedef enum _CoglVertexBufferAttribFlags
@ -129,7 +133,8 @@ typedef struct _CoglVertexBufferVBO
typedef struct _CoglVertexBuffer typedef struct _CoglVertexBuffer
{ {
guint ref_count; CoglHandleObject _parent;
guint n_vertices; /*!< The number of vertices in the buffer */ guint n_vertices; /*!< The number of vertices in the buffer */
GList *submitted_vbos; /* The VBOs currently submitted to the GPU */ GList *submitted_vbos; /* The VBOs currently submitted to the GPU */

View File

@ -200,18 +200,13 @@
static void _cogl_vertex_buffer_free (CoglVertexBuffer *buffer); static void _cogl_vertex_buffer_free (CoglVertexBuffer *buffer);
COGL_HANDLE_DEFINE (VertexBuffer, COGL_HANDLE_DEFINE (VertexBuffer, vertex_buffer);
vertex_buffer,
vertex_buffer_handles);
CoglHandle CoglHandle
cogl_vertex_buffer_new (guint n_vertices) cogl_vertex_buffer_new (guint n_vertices)
{ {
CoglVertexBuffer *buffer = g_slice_alloc (sizeof (CoglVertexBuffer)); CoglVertexBuffer *buffer = g_slice_alloc (sizeof (CoglVertexBuffer));
buffer->ref_count = 1;
COGL_HANDLE_DEBUG_NEW (CoglVertexBuffer, buffer);
buffer->n_vertices = n_vertices; buffer->n_vertices = n_vertices;
buffer->submitted_vbos = NULL; buffer->submitted_vbos = NULL;

View File

@ -62,12 +62,9 @@ cogl_create_context ()
_context->indirect = gl_is_indirect; _context->indirect = gl_is_indirect;
_context->material_handles = NULL;
_context->material_layer_handles = NULL;
_context->default_material = cogl_material_new (); _context->default_material = cogl_material_new ();
_context->source_material = NULL; _context->source_material = NULL;
_context->texture_handles = NULL;
_context->default_gl_texture_2d_tex = COGL_INVALID_HANDLE; _context->default_gl_texture_2d_tex = COGL_INVALID_HANDLE;
_context->default_gl_texture_rect_tex = COGL_INVALID_HANDLE; _context->default_gl_texture_rect_tex = COGL_INVALID_HANDLE;
@ -83,15 +80,8 @@ cogl_create_context ()
sizeof (CoglLayerInfo)); sizeof (CoglLayerInfo));
_context->n_texcoord_arrays_enabled = 0; _context->n_texcoord_arrays_enabled = 0;
_context->fbo_handles = NULL;
_context->draw_buffer = COGL_WINDOW_BUFFER; _context->draw_buffer = COGL_WINDOW_BUFFER;
_context->shader_handles = NULL;
_context->program_handles = NULL;
_context->vertex_buffer_handles = NULL;
_context->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode)); _context->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode));
_context->last_path = 0; _context->last_path = 0;
_context->stencil_material = cogl_material_new (); _context->stencil_material = cogl_material_new ();
@ -193,22 +183,13 @@ cogl_destroy_context ()
if (_context->path_nodes) if (_context->path_nodes)
g_array_free (_context->path_nodes, TRUE); g_array_free (_context->path_nodes, TRUE);
if (_context->texture_handles)
g_array_free (_context->texture_handles, TRUE);
if (_context->fbo_handles)
g_array_free (_context->fbo_handles, TRUE);
if (_context->shader_handles)
g_array_free (_context->shader_handles, TRUE);
if (_context->program_handles)
g_array_free (_context->program_handles, TRUE);
if (_context->default_gl_texture_2d_tex) if (_context->default_gl_texture_2d_tex)
cogl_texture_unref (_context->default_gl_texture_2d_tex); cogl_handle_unref (_context->default_gl_texture_2d_tex);
if (_context->default_gl_texture_rect_tex) if (_context->default_gl_texture_rect_tex)
cogl_texture_unref (_context->default_gl_texture_rect_tex); cogl_handle_unref (_context->default_gl_texture_rect_tex);
if (_context->default_material) if (_context->default_material)
cogl_material_unref (_context->default_material); cogl_handle_unref (_context->default_material);
if (_context->journal) if (_context->journal)
g_array_free (_context->journal, TRUE); g_array_free (_context->journal, TRUE);

View File

@ -60,13 +60,10 @@ typedef struct
float inverse_projection[16]; float inverse_projection[16];
/* Materials */ /* Materials */
GArray *material_handles;
GArray *material_layer_handles;
CoglHandle default_material; CoglHandle default_material;
CoglHandle source_material; CoglHandle source_material;
/* Textures */ /* Textures */
GArray *texture_handles;
CoglHandle default_gl_texture_2d_tex; CoglHandle default_gl_texture_2d_tex;
CoglHandle default_gl_texture_rect_tex; CoglHandle default_gl_texture_rect_tex;
@ -87,21 +84,11 @@ typedef struct
guint n_texcoord_arrays_enabled; guint n_texcoord_arrays_enabled;
/* Framebuffer objects */ /* Framebuffer objects */
GArray *fbo_handles;
CoglBufferTarget draw_buffer; CoglBufferTarget draw_buffer;
/* Shaders */
GArray *shader_handles;
/* Programs */
GArray *program_handles;
/* Clip stack */ /* Clip stack */
CoglClipStackState clip; CoglClipStackState clip;
/* Vertex buffers */
GArray *vertex_buffer_handles;
/* Primitives */ /* Primitives */
floatVec2 path_start; floatVec2 path_start;
floatVec2 path_pen; floatVec2 path_pen;

View File

@ -58,7 +58,7 @@
static void _cogl_offscreen_free (CoglFbo *fbo); static void _cogl_offscreen_free (CoglFbo *fbo);
COGL_HANDLE_DEFINE (Fbo, offscreen, fbo_handles); COGL_HANDLE_DEFINE (Fbo, offscreen);
CoglHandle CoglHandle
cogl_offscreen_new_to_texture (CoglHandle texhandle) cogl_offscreen_new_to_texture (CoglHandle texhandle)
@ -142,14 +142,11 @@ cogl_offscreen_new_to_texture (CoglHandle texhandle)
/* Allocate and init a CoglFbo object (store non-wasted size /* Allocate and init a CoglFbo object (store non-wasted size
for subsequent blits and viewport setup) */ for subsequent blits and viewport setup) */
fbo = (CoglFbo*) g_malloc (sizeof (CoglFbo)); fbo = (CoglFbo*) g_malloc (sizeof (CoglFbo));
fbo->ref_count = 1;
fbo->width = x_span->size - x_span->waste; fbo->width = x_span->size - x_span->waste;
fbo->height = y_span->size - y_span->waste; fbo->height = y_span->size - y_span->waste;
fbo->gl_handle = fbo_gl_handle; fbo->gl_handle = fbo_gl_handle;
fbo->gl_stencil_handle = gl_stencil_handle; fbo->gl_stencil_handle = gl_stencil_handle;
COGL_HANDLE_DEBUG_NEW (offscreen, fbo);
return _cogl_offscreen_handle_new (fbo); return _cogl_offscreen_handle_new (fbo);
} }

View File

@ -26,9 +26,11 @@
#ifndef __COGL_FBO_H #ifndef __COGL_FBO_H
#define __COGL_FBO_H #define __COGL_FBO_H
#include "cogl-handle.h"
typedef struct typedef struct
{ {
guint ref_count; CoglHandleObject _parent;
int width; int width;
int height; int height;
GLuint gl_handle; GLuint gl_handle;

View File

@ -65,7 +65,7 @@
static void _cogl_program_free (CoglProgram *program); static void _cogl_program_free (CoglProgram *program);
COGL_HANDLE_DEFINE (Program, program, program_handles); COGL_HANDLE_DEFINE (Program, program);
static void static void
_cogl_program_free (CoglProgram *program) _cogl_program_free (CoglProgram *program)
@ -83,11 +83,8 @@ cogl_create_program (void)
_COGL_GET_CONTEXT (ctx, 0); _COGL_GET_CONTEXT (ctx, 0);
program = g_slice_new (CoglProgram); program = g_slice_new (CoglProgram);
program->ref_count = 1;
program->gl_handle = glCreateProgramObjectARB (); program->gl_handle = glCreateProgramObjectARB ();
COGL_HANDLE_DEBUG_NEW (program, program);
return _cogl_program_handle_new (program); return _cogl_program_handle_new (program);
} }

View File

@ -26,11 +26,13 @@
#ifndef __COGL_PROGRAM_H #ifndef __COGL_PROGRAM_H
#define __COGL_PROGRAM_H #define __COGL_PROGRAM_H
#include "cogl-handle.h"
typedef struct _CoglProgram CoglProgram; typedef struct _CoglProgram CoglProgram;
struct _CoglProgram struct _CoglProgram
{ {
guint ref_count; CoglHandleObject _parent;
GLhandleARB gl_handle; GLhandleARB gl_handle;
}; };

View File

@ -26,11 +26,13 @@
#ifndef __COGL_SHADER_H #ifndef __COGL_SHADER_H
#define __COGL_SHADER_H #define __COGL_SHADER_H
#include "cogl-handle.h"
typedef struct _CoglShader CoglShader; typedef struct _CoglShader CoglShader;
struct _CoglShader struct _CoglShader
{ {
guint ref_count; CoglHandleObject _parent;
GLhandleARB gl_handle; GLhandleARB gl_handle;
}; };

View File

@ -45,7 +45,7 @@
static void _cogl_shader_free (CoglShader *shader); static void _cogl_shader_free (CoglShader *shader);
COGL_HANDLE_DEFINE (Shader, shader, shader_handles); COGL_HANDLE_DEFINE (Shader, shader);
static void static void
_cogl_shader_free (CoglShader *shader) _cogl_shader_free (CoglShader *shader)
@ -64,11 +64,8 @@ cogl_create_shader (COGLenum shaderType)
_COGL_GET_CONTEXT (ctx, 0); _COGL_GET_CONTEXT (ctx, 0);
shader = g_slice_new (CoglShader); shader = g_slice_new (CoglShader);
shader->ref_count = 1;
shader->gl_handle = glCreateShaderObjectARB (shaderType); shader->gl_handle = glCreateShaderObjectARB (shaderType);
COGL_HANDLE_DEBUG_NEW (shader, shader);
return _cogl_shader_handle_new (shader); return _cogl_shader_handle_new (shader);
} }

View File

@ -27,6 +27,7 @@
#define __COGL_TEXTURE_H #define __COGL_TEXTURE_H
#include "cogl-bitmap.h" #include "cogl-bitmap.h"
#include "cogl-handle.h"
typedef struct _CoglTexture CoglTexture; typedef struct _CoglTexture CoglTexture;
typedef struct _CoglTexSliceSpan CoglTexSliceSpan; typedef struct _CoglTexSliceSpan CoglTexSliceSpan;
@ -58,7 +59,7 @@ struct _CoglSpanIter
struct _CoglTexture struct _CoglTexture
{ {
guint ref_count; CoglHandleObject _parent;
CoglBitmap bitmap; CoglBitmap bitmap;
gboolean bitmap_owner; gboolean bitmap_owner;
GLenum gl_target; GLenum gl_target;

View File

@ -70,7 +70,7 @@ extern void _cogl_journal_flush (void);
static void _cogl_texture_free (CoglTexture *tex); static void _cogl_texture_free (CoglTexture *tex);
COGL_HANDLE_DEFINE (Texture, texture, texture_handles); COGL_HANDLE_DEFINE (Texture, texture);
static void static void
_cogl_texture_bitmap_free (CoglTexture *tex) _cogl_texture_bitmap_free (CoglTexture *tex)
@ -1228,9 +1228,6 @@ cogl_texture_new_with_size (guint width,
/* Init texture with empty bitmap */ /* Init texture with empty bitmap */
tex = (CoglTexture*) g_malloc (sizeof (CoglTexture)); tex = (CoglTexture*) g_malloc (sizeof (CoglTexture));
tex->ref_count = 1;
COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0); tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
@ -1292,9 +1289,6 @@ cogl_texture_new_from_data (guint width,
/* Create new texture and fill with given data */ /* Create new texture and fill with given data */
tex = (CoglTexture*) g_malloc (sizeof (CoglTexture)); tex = (CoglTexture*) g_malloc (sizeof (CoglTexture));
tex->ref_count = 1;
COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0); tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
@ -1352,9 +1346,6 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp,
/* Create new texture and fill with loaded data */ /* Create new texture and fill with loaded data */
tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture));
tex->ref_count = 1;
COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0); tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
@ -1376,7 +1367,7 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp,
* this one instead (reloading from file is not needed * this one instead (reloading from file is not needed
* in that case). As a rule then, everytime a valid * in that case). As a rule then, everytime a valid
* CoglHandle is returned, it should also be destroyed * CoglHandle is returned, it should also be destroyed
* with cogl_texture_unref at some point! */ * with cogl_handle_unref at some point! */
if (!_cogl_texture_bitmap_prepare (tex, internal_format)) if (!_cogl_texture_bitmap_prepare (tex, internal_format))
{ {
@ -1531,9 +1522,6 @@ cogl_texture_new_from_foreign (GLuint gl_handle,
/* Create new texture */ /* Create new texture */
tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture));
tex->ref_count = 1;
COGL_HANDLE_DEBUG_NEW (texture, tex);
/* Setup bitmap info */ /* Setup bitmap info */
tex->is_foreign = TRUE; tex->is_foreign = TRUE;
tex->auto_mipmap = (gl_gen_mipmap == GL_TRUE) ? TRUE : FALSE; tex->auto_mipmap = (gl_gen_mipmap == GL_TRUE) ? TRUE : FALSE;

View File

@ -64,12 +64,9 @@ cogl_create_context ()
_context->indirect = gl_is_indirect; _context->indirect = gl_is_indirect;
_context->material_handles = NULL;
_context->material_layer_handles = NULL;
_context->default_material = cogl_material_new (); _context->default_material = cogl_material_new ();
_context->source_material = NULL; _context->source_material = NULL;
_context->texture_handles = NULL;
_context->default_gl_texture_2d_tex = COGL_INVALID_HANDLE; _context->default_gl_texture_2d_tex = COGL_INVALID_HANDLE;
_context->default_gl_texture_rect_tex = COGL_INVALID_HANDLE; _context->default_gl_texture_rect_tex = COGL_INVALID_HANDLE;
_context->texture_download_material = COGL_INVALID_HANDLE; _context->texture_download_material = COGL_INVALID_HANDLE;
@ -86,15 +83,8 @@ cogl_create_context ()
sizeof (CoglLayerInfo)); sizeof (CoglLayerInfo));
_context->n_texcoord_arrays_enabled = 0; _context->n_texcoord_arrays_enabled = 0;
_context->fbo_handles = NULL;
_context->draw_buffer = COGL_WINDOW_BUFFER; _context->draw_buffer = COGL_WINDOW_BUFFER;
_context->shader_handles = NULL;
_context->program_handles = NULL;
_context->vertex_buffer_handles = NULL;
_context->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode)); _context->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode));
_context->last_path = 0; _context->last_path = 0;
_context->stencil_material = cogl_material_new (); _context->stencil_material = cogl_material_new ();
@ -154,22 +144,13 @@ cogl_destroy_context ()
if (_context->path_nodes) if (_context->path_nodes)
g_array_free (_context->path_nodes, TRUE); g_array_free (_context->path_nodes, TRUE);
if (_context->texture_handles)
g_array_free (_context->texture_handles, TRUE);
if (_context->fbo_handles)
g_array_free (_context->fbo_handles, TRUE);
if (_context->shader_handles)
g_array_free (_context->shader_handles, TRUE);
if (_context->program_handles)
g_array_free (_context->program_handles, TRUE);
if (_context->default_gl_texture_2d_tex) if (_context->default_gl_texture_2d_tex)
cogl_texture_unref (_context->default_gl_texture_2d_tex); cogl_handle_unref (_context->default_gl_texture_2d_tex);
if (_context->default_gl_texture_rect_tex) if (_context->default_gl_texture_rect_tex)
cogl_texture_unref (_context->default_gl_texture_rect_tex); cogl_handle_unref (_context->default_gl_texture_rect_tex);
if (_context->default_material) if (_context->default_material)
cogl_material_unref (_context->default_material); cogl_handle_unref (_context->default_material);
if (_context->journal) if (_context->journal)
g_array_free (_context->journal, TRUE); g_array_free (_context->journal, TRUE);

View File

@ -62,13 +62,10 @@ typedef struct
float inverse_projection[16]; float inverse_projection[16];
/* Materials */ /* Materials */
GArray *material_handles;
GArray *material_layer_handles;
CoglHandle default_material; CoglHandle default_material;
CoglHandle source_material; CoglHandle source_material;
/* Textures */ /* Textures */
GArray *texture_handles;
CoglHandle default_gl_texture_2d_tex; CoglHandle default_gl_texture_2d_tex;
CoglHandle default_gl_texture_rect_tex; CoglHandle default_gl_texture_rect_tex;
CoglHandle texture_download_material; CoglHandle texture_download_material;
@ -89,21 +86,11 @@ typedef struct
guint n_texcoord_arrays_enabled; guint n_texcoord_arrays_enabled;
/* Framebuffer objects */ /* Framebuffer objects */
GArray *fbo_handles;
CoglBufferTarget draw_buffer; CoglBufferTarget draw_buffer;
/* Shaders */
GArray *shader_handles;
/* Programs */
GArray *program_handles;
/* Clip stack */ /* Clip stack */
CoglClipStackState clip; CoglClipStackState clip;
/* Vertex buffers */
GArray *vertex_buffer_handles;
/* Primitives */ /* Primitives */
floatVec2 path_start; floatVec2 path_start;
floatVec2 path_pen; floatVec2 path_pen;

View File

@ -40,7 +40,7 @@
static void _cogl_offscreen_free (CoglFbo *fbo); static void _cogl_offscreen_free (CoglFbo *fbo);
COGL_HANDLE_DEFINE (Fbo, offscreen, fbo_handles); COGL_HANDLE_DEFINE (Fbo, offscreen);
CoglHandle CoglHandle
cogl_offscreen_new_to_texture (CoglHandle texhandle) cogl_offscreen_new_to_texture (CoglHandle texhandle)
@ -124,14 +124,11 @@ cogl_offscreen_new_to_texture (CoglHandle texhandle)
/* Allocate and init a CoglFbo object (store non-wasted size /* Allocate and init a CoglFbo object (store non-wasted size
for subsequent blits and viewport setup) */ for subsequent blits and viewport setup) */
fbo = (CoglFbo*) g_malloc (sizeof (CoglFbo)); fbo = (CoglFbo*) g_malloc (sizeof (CoglFbo));
fbo->ref_count = 1;
fbo->width = x_span->size - x_span->waste; fbo->width = x_span->size - x_span->waste;
fbo->height = y_span->size - y_span->waste; fbo->height = y_span->size - y_span->waste;
fbo->gl_handle = fbo_gl_handle; fbo->gl_handle = fbo_gl_handle;
fbo->gl_stencil_handle = gl_stencil_handle; fbo->gl_stencil_handle = gl_stencil_handle;
COGL_HANDLE_DEBUG_NEW (offscreen, fbo);
return _cogl_offscreen_handle_new (fbo); return _cogl_offscreen_handle_new (fbo);
} }

View File

@ -26,9 +26,11 @@
#ifndef __COGL_FBO_H #ifndef __COGL_FBO_H
#define __COGL_FBO_H #define __COGL_FBO_H
#include "cogl-handle.h"
typedef struct typedef struct
{ {
guint ref_count; CoglHandleObject _parent;
int width; int width;
int height; int height;
GLuint gl_handle; GLuint gl_handle;

View File

@ -42,7 +42,7 @@
static void _cogl_program_free (CoglProgram *program); static void _cogl_program_free (CoglProgram *program);
COGL_HANDLE_DEFINE (Program, program, program_handles); COGL_HANDLE_DEFINE (Program, program);
static void static void
_cogl_program_free (CoglProgram *program) _cogl_program_free (CoglProgram *program)
@ -52,7 +52,7 @@ _cogl_program_free (CoglProgram *program)
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* Unref all of the attached shaders */ /* Unref all of the attached shaders */
g_slist_foreach (program->attached_shaders, (GFunc) cogl_shader_unref, NULL); g_slist_foreach (program->attached_shaders, (GFunc) cogl_handle_unref, NULL);
/* Destroy the list */ /* Destroy the list */
g_slist_free (program->attached_shaders); g_slist_free (program->attached_shaders);
@ -75,13 +75,10 @@ cogl_create_program (void)
CoglProgram *program; CoglProgram *program;
program = g_slice_new (CoglProgram); program = g_slice_new (CoglProgram);
program->ref_count = 1;
program->attached_shaders = NULL; program->attached_shaders = NULL;
memset (program->custom_uniform_names, 0, memset (program->custom_uniform_names, 0,
COGL_GLES2_NUM_CUSTOM_UNIFORMS * sizeof (char *)); COGL_GLES2_NUM_CUSTOM_UNIFORMS * sizeof (char *));
COGL_HANDLE_DEBUG_NEW (program, program);
return _cogl_program_handle_new (program); return _cogl_program_handle_new (program);
} }
@ -99,7 +96,7 @@ cogl_program_attach_shader (CoglHandle program_handle,
program = _cogl_program_pointer_from_handle (program_handle); program = _cogl_program_pointer_from_handle (program_handle);
program->attached_shaders program->attached_shaders
= g_slist_prepend (program->attached_shaders, = g_slist_prepend (program->attached_shaders,
cogl_shader_ref (shader_handle)); cogl_handle_ref (shader_handle));
/* Whenever the shader changes we will need to relink the program /* Whenever the shader changes we will need to relink the program
with the fixed functionality shaders so we should forget the with the fixed functionality shaders so we should forget the

View File

@ -27,12 +27,13 @@
#define __COGL_PROGRAM_H #define __COGL_PROGRAM_H
#include "cogl-gles2-wrapper.h" #include "cogl-gles2-wrapper.h"
#include "cogl-handle.h"
typedef struct _CoglProgram CoglProgram; typedef struct _CoglProgram CoglProgram;
struct _CoglProgram struct _CoglProgram
{ {
guint ref_count; CoglHandleObject _parent;
GSList *attached_shaders; GSList *attached_shaders;

View File

@ -26,11 +26,13 @@
#ifndef __COGL_SHADER_H #ifndef __COGL_SHADER_H
#define __COGL_SHADER_H #define __COGL_SHADER_H
#include "cogl-handle.h"
typedef struct _CoglShader CoglShader; typedef struct _CoglShader CoglShader;
struct _CoglShader struct _CoglShader
{ {
guint ref_count; CoglHandleObject _parent;
GLuint gl_handle; GLuint gl_handle;
GLenum type; GLenum type;
}; };

View File

@ -38,7 +38,7 @@
static void _cogl_shader_free (CoglShader *shader); static void _cogl_shader_free (CoglShader *shader);
COGL_HANDLE_DEFINE (Shader, shader, shader_handles); COGL_HANDLE_DEFINE (Shader, shader);
static void static void
_cogl_shader_free (CoglShader *shader) _cogl_shader_free (CoglShader *shader)
@ -57,12 +57,9 @@ cogl_create_shader (COGLenum shaderType)
_COGL_GET_CONTEXT (ctx, 0); _COGL_GET_CONTEXT (ctx, 0);
shader = g_slice_new (CoglShader); shader = g_slice_new (CoglShader);
shader->ref_count = 1;
shader->gl_handle = glCreateShader (shaderType); shader->gl_handle = glCreateShader (shaderType);
shader->type = shaderType; shader->type = shaderType;
COGL_HANDLE_DEBUG_NEW (shader, shader);
return _cogl_shader_handle_new (shader); return _cogl_shader_handle_new (shader);
} }

View File

@ -27,6 +27,7 @@
#define __COGL_TEXTURE_H #define __COGL_TEXTURE_H
#include "cogl-bitmap.h" #include "cogl-bitmap.h"
#include "cogl-handle.h"
typedef struct _CoglTexture CoglTexture; typedef struct _CoglTexture CoglTexture;
typedef struct _CoglTexSliceSpan CoglTexSliceSpan; typedef struct _CoglTexSliceSpan CoglTexSliceSpan;
@ -58,7 +59,7 @@ struct _CoglSpanIter
struct _CoglTexture struct _CoglTexture
{ {
guint ref_count; CoglHandleObject _parent;
CoglBitmap bitmap; CoglBitmap bitmap;
gboolean bitmap_owner; gboolean bitmap_owner;
GLenum gl_target; GLenum gl_target;

View File

@ -57,7 +57,7 @@ extern void _cogl_journal_flush (void);
static void _cogl_texture_free (CoglTexture *tex); static void _cogl_texture_free (CoglTexture *tex);
COGL_HANDLE_DEFINE (Texture, texture, texture_handles); COGL_HANDLE_DEFINE (Texture, texture);
static void static void
_cogl_texture_bitmap_free (CoglTexture *tex) _cogl_texture_bitmap_free (CoglTexture *tex)
@ -1327,9 +1327,6 @@ cogl_texture_new_with_size (guint width,
/* Init texture with empty bitmap */ /* Init texture with empty bitmap */
tex = (CoglTexture*) g_malloc (sizeof (CoglTexture)); tex = (CoglTexture*) g_malloc (sizeof (CoglTexture));
tex->ref_count = 1;
COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0); tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
@ -1391,9 +1388,6 @@ cogl_texture_new_from_data (guint width,
/* Create new texture and fill with given data */ /* Create new texture and fill with given data */
tex = (CoglTexture*) g_malloc (sizeof (CoglTexture)); tex = (CoglTexture*) g_malloc (sizeof (CoglTexture));
tex->ref_count = 1;
COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0); tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
@ -1451,9 +1445,6 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp,
/* Create new texture and fill with loaded data */ /* Create new texture and fill with loaded data */
tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture));
tex->ref_count = 1;
COGL_HANDLE_DEBUG_NEW (texture, tex);
tex->is_foreign = FALSE; tex->is_foreign = FALSE;
tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0); tex->auto_mipmap = ((flags & COGL_TEXTURE_AUTO_MIPMAP) != 0);
@ -1475,7 +1466,7 @@ cogl_texture_new_from_bitmap (CoglBitmap *bmp,
* this one instead (reloading from file is not needed * this one instead (reloading from file is not needed
* in that case). As a rule then, everytime a valid * in that case). As a rule then, everytime a valid
* CoglHandle is returned, it should also be destroyed * CoglHandle is returned, it should also be destroyed
* with cogl_texture_unref at some point! */ * with cogl_handle_unref at some point! */
if (!_cogl_texture_bitmap_prepare (tex, internal_format)) if (!_cogl_texture_bitmap_prepare (tex, internal_format))
{ {
@ -1629,9 +1620,6 @@ cogl_texture_new_from_foreign (GLuint gl_handle,
/* Create new texture */ /* Create new texture */
tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture)); tex = (CoglTexture*) g_malloc ( sizeof (CoglTexture));
tex->ref_count = 1;
COGL_HANDLE_DEBUG_NEW (texture, tex);
/* Setup bitmap info */ /* Setup bitmap info */
tex->is_foreign = TRUE; tex->is_foreign = TRUE;
tex->auto_mipmap = (gl_gen_mipmap == GL_TRUE) ? TRUE : FALSE; tex->auto_mipmap = (gl_gen_mipmap == GL_TRUE) ? TRUE : FALSE;

View File

@ -108,7 +108,7 @@ struct _CoglPangoGlyphCacheBand
static void static void
cogl_pango_glyph_cache_value_free (CoglPangoGlyphCacheValue *value) cogl_pango_glyph_cache_value_free (CoglPangoGlyphCacheValue *value)
{ {
cogl_texture_unref (value->texture); cogl_handle_unref (value->texture);
g_slice_free (CoglPangoGlyphCacheValue, value); g_slice_free (CoglPangoGlyphCacheValue, value);
} }
@ -156,7 +156,7 @@ cogl_pango_glyph_cache_free_textures (CoglPangoGlyphCacheTexture *node)
while (node) while (node)
{ {
next = node->next; next = node->next;
cogl_texture_unref (node->texture); cogl_handle_unref (node->texture);
g_slice_free (CoglPangoGlyphCacheTexture, node); g_slice_free (CoglPangoGlyphCacheTexture, node);
node = next; node = next;
} }
@ -170,7 +170,7 @@ cogl_pango_glyph_cache_free_bands (CoglPangoGlyphCacheBand *node)
while (node) while (node)
{ {
next = node->next; next = node->next;
cogl_texture_unref (node->texture); cogl_handle_unref (node->texture);
g_slice_free (CoglPangoGlyphCacheBand, node); g_slice_free (CoglPangoGlyphCacheBand, node);
node = next; node = next;
} }
@ -323,7 +323,7 @@ cogl_pango_glyph_cache_set (CoglPangoGlyphCache *cache,
band->top = texture->texture_size - texture->space_remaining; band->top = texture->texture_size - texture->space_remaining;
band->height = band_height; band->height = band_height;
band->space_remaining = texture->texture_size; band->space_remaining = texture->texture_size;
band->texture = cogl_texture_ref (texture->texture); band->texture = cogl_handle_ref (texture->texture);
band->texture_size = texture->texture_size; band->texture_size = texture->texture_size;
band->next = cache->bands; band->next = cache->bands;
cache->bands = band; cache->bands = band;
@ -350,7 +350,7 @@ cogl_pango_glyph_cache_set (CoglPangoGlyphCache *cache,
key->glyph = glyph; key->glyph = glyph;
value = g_slice_new (CoglPangoGlyphCacheValue); value = g_slice_new (CoglPangoGlyphCacheValue);
value->texture = cogl_texture_ref (band->texture); value->texture = cogl_handle_ref (band->texture);
value->tx1 = (float)(band->space_remaining) value->tx1 = (float)(band->space_remaining)
/ band->texture_size; / band->texture_size;
value->tx2 = (float)(band->space_remaining + width) value->tx2 = (float)(band->space_remaining + width)

View File

@ -266,7 +266,7 @@ test_backface_culling (TestConformSimpleFixture *fixture,
g_source_remove (idle_source); g_source_remove (idle_source);
cogl_texture_unref (state.texture); cogl_handle_unref (state.texture);
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("OK\n"); g_print ("OK\n");

View File

@ -202,7 +202,7 @@ test_npot_texture (TestConformSimpleFixture *fixture,
g_source_remove (idle_source); g_source_remove (idle_source);
cogl_texture_unref (state.texture); cogl_handle_unref (state.texture);
if (g_test_verbose ()) if (g_test_verbose ())
g_print ("OK\n"); g_print ("OK\n");

View File

@ -244,9 +244,9 @@ test_vertex_buffer_contiguous (TestConformSimpleFixture *fixture,
clutter_main (); clutter_main ();
cogl_vertex_buffer_unref (state.buffer); cogl_handle_unref (state.buffer);
cogl_material_unref (state.material); cogl_handle_unref (state.material);
cogl_texture_unref (state.texture); cogl_handle_unref (state.texture);
g_source_remove (idle_source); g_source_remove (idle_source);

View File

@ -163,7 +163,7 @@ test_vertex_buffer_interleved (TestConformSimpleFixture *fixture,
clutter_main (); clutter_main ();
cogl_vertex_buffer_unref (state.buffer); cogl_handle_unref (state.buffer);
g_source_remove (idle_source); g_source_remove (idle_source);

View File

@ -196,7 +196,7 @@ test_vertex_buffer_mutability (TestConformSimpleFixture *fixture,
clutter_main (); clutter_main ();
cogl_vertex_buffer_unref (state.buffer); cogl_handle_unref (state.buffer);
g_source_remove (idle_source); g_source_remove (idle_source);

View File

@ -328,7 +328,7 @@ test_clip_main (int argc, char **argv)
clutter_main (); clutter_main ();
cogl_texture_unref (data.hand); cogl_handle_unref (data.hand);
free_clips (&data); free_clips (&data);

View File

@ -144,10 +144,10 @@ test_cogl_multitexture_main (int argc, char *argv[])
clutter_main(); clutter_main();
cogl_material_unref (state->material); cogl_handle_unref (state->material);
cogl_texture_unref (state->alpha_tex); cogl_handle_unref (state->alpha_tex);
cogl_texture_unref (state->redhand_tex); cogl_handle_unref (state->redhand_tex);
cogl_texture_unref (state->light_tex0); cogl_handle_unref (state->light_tex0);
g_free (state); g_free (state);
g_object_unref (r_behave); g_object_unref (r_behave);

View File

@ -130,8 +130,8 @@ test_coglbox_dispose (GObject *object)
priv = TEST_COGLBOX_GET_PRIVATE (object); priv = TEST_COGLBOX_GET_PRIVATE (object);
cogl_texture_unref (priv->texture_id); cogl_handle_unref (priv->texture_id);
cogl_offscreen_unref (priv->offscreen_id); cogl_handle_unref (priv->offscreen_id);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);
} }

View File

@ -132,7 +132,7 @@ test_coglbox_dispose (GObject *object)
TestCoglboxPrivate *priv; TestCoglboxPrivate *priv;
priv = TEST_COGLBOX_GET_PRIVATE (object); priv = TEST_COGLBOX_GET_PRIVATE (object);
cogl_texture_unref (priv->cogl_tex_id); cogl_handle_unref (priv->cogl_tex_id);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);
} }

View File

@ -111,7 +111,7 @@ test_coglbox_dispose (GObject *object)
priv = TEST_COGLBOX_GET_PRIVATE (object); priv = TEST_COGLBOX_GET_PRIVATE (object);
cogl_texture_unref (priv->cogl_handle); cogl_handle_unref (priv->cogl_handle);
glDeleteTextures (1, &priv->gl_handle); glDeleteTextures (1, &priv->gl_handle);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);

View File

@ -109,7 +109,7 @@ test_coglbox_dispose (GObject *object)
TestCoglboxPrivate *priv; TestCoglboxPrivate *priv;
priv = TEST_COGLBOX_GET_PRIVATE (object); priv = TEST_COGLBOX_GET_PRIVATE (object);
cogl_texture_unref (priv->cogl_tex_id); cogl_handle_unref (priv->cogl_tex_id);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);
} }

View File

@ -229,8 +229,8 @@ test_coglbox_dispose (GObject *object)
TestCoglboxPrivate *priv; TestCoglboxPrivate *priv;
priv = TEST_COGLBOX_GET_PRIVATE (object); priv = TEST_COGLBOX_GET_PRIVATE (object);
cogl_texture_unref (priv->not_sliced_tex); cogl_handle_unref (priv->not_sliced_tex);
cogl_texture_unref (priv->sliced_tex); cogl_handle_unref (priv->sliced_tex);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);
} }

View File

@ -132,7 +132,7 @@ test_coglbox_dispose (GObject *object)
TestCoglboxPrivate *priv; TestCoglboxPrivate *priv;
priv = TEST_COGLBOX_GET_PRIVATE (object); priv = TEST_COGLBOX_GET_PRIVATE (object);
cogl_texture_unref (priv->cogl_tex_id); cogl_handle_unref (priv->cogl_tex_id);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);
} }

View File

@ -367,7 +367,7 @@ test_cogl_vertex_buffer_main (int argc, char *argv[])
clutter_main (); clutter_main ();
cogl_vertex_buffer_unref (state.buffer); cogl_handle_unref (state.buffer);
g_source_remove (idle_source); g_source_remove (idle_source);