path: Remove use of CoglHandle in the CoglPath API

This replaces the use of CoglHandle with strongly type CoglPath *
pointers instead. The only function not converted for now is
cogl_is_path which will be done in a later commit.
This commit is contained in:
Robert Bragg 2010-05-28 00:35:47 +01:00
parent 250d82cd3f
commit f3f268b0cd
4 changed files with 53 additions and 55 deletions

View File

@ -56,7 +56,6 @@ typedef struct _CoglBezCubic
floatVec2 p4; floatVec2 p4;
} CoglBezCubic; } CoglBezCubic;
typedef struct _CoglPath CoglPath;
typedef struct _CoglPathData CoglPathData; typedef struct _CoglPathData CoglPathData;
struct _CoglPath struct _CoglPath
@ -81,11 +80,11 @@ struct _CoglPathData
/* This is an internal version of cogl_path_new that doesn't affect /* This is an internal version of cogl_path_new that doesn't affect
the current path and just creates a new handle */ the current path and just creates a new handle */
CoglHandle CoglPath *
_cogl_path_new (void); _cogl_path_new (void);
void void
_cogl_add_path_to_stencil_buffer (CoglHandle path, _cogl_add_path_to_stencil_buffer (CoglPath *path,
gboolean merge, gboolean merge,
gboolean need_clear); gboolean need_clear);

View File

@ -26,6 +26,7 @@
#endif #endif
#include "cogl.h" #include "cogl.h"
#include "cogl-object.h"
#include "cogl-internal.h" #include "cogl-internal.h"
#include "cogl-context.h" #include "cogl-context.h"
#include "cogl-journal-private.h" #include "cogl-journal-private.h"
@ -44,7 +45,7 @@
static void _cogl_path_free (CoglPath *path); static void _cogl_path_free (CoglPath *path);
COGL_HANDLE_DEFINE (Path, path); COGL_OBJECT_DEFINE (Path, path);
static void static void
_cogl_path_data_unref (CoglPathData *data) _cogl_path_data_unref (CoglPathData *data)
@ -179,7 +180,7 @@ _cogl_path_get_bounds (floatVec2 nodes_min,
} }
void void
_cogl_add_path_to_stencil_buffer (CoglHandle path_handle, _cogl_add_path_to_stencil_buffer (CoglPath *path,
gboolean merge, gboolean merge,
gboolean need_clear) gboolean need_clear)
{ {
@ -190,17 +191,14 @@ _cogl_add_path_to_stencil_buffer (CoglHandle path_handle,
float bounds_h; float bounds_h;
unsigned long enable_flags = COGL_ENABLE_VERTEX_ARRAY; unsigned long enable_flags = COGL_ENABLE_VERTEX_ARRAY;
CoglHandle prev_source; CoglHandle prev_source;
CoglHandle framebuffer = _cogl_get_framebuffer (); CoglFramebuffer *framebuffer = _cogl_get_framebuffer ();
CoglMatrixStack *modelview_stack = CoglMatrixStack *modelview_stack =
_cogl_framebuffer_get_modelview_stack (framebuffer); _cogl_framebuffer_get_modelview_stack (framebuffer);
CoglMatrixStack *projection_stack = CoglMatrixStack *projection_stack =
_cogl_framebuffer_get_projection_stack (framebuffer); _cogl_framebuffer_get_projection_stack (framebuffer);
CoglPath *path;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
path = COGL_PATH (path_handle);
/* We don't track changes to the stencil buffer in the journal /* We don't track changes to the stencil buffer in the journal
* so we need to flush any batched geometry first */ * so we need to flush any batched geometry first */
_cogl_journal_flush (); _cogl_journal_flush ();
@ -211,7 +209,7 @@ _cogl_add_path_to_stencil_buffer (CoglHandle path_handle,
_cogl_framebuffer_flush_state (framebuffer, 0); _cogl_framebuffer_flush_state (framebuffer, 0);
/* Just setup a simple material that doesn't use texturing... */ /* Just setup a simple material that doesn't use texturing... */
prev_source = cogl_handle_ref (ctx->source_material); prev_source = cogl_object_ref (ctx->source_material);
cogl_set_source (ctx->stencil_material); cogl_set_source (ctx->stencil_material);
_cogl_material_flush_gl_state (ctx->source_material, NULL); _cogl_material_flush_gl_state (ctx->source_material, NULL);
@ -316,7 +314,7 @@ _cogl_add_path_to_stencil_buffer (CoglHandle path_handle,
/* restore the original material */ /* restore the original material */
cogl_set_source (prev_source); cogl_set_source (prev_source);
cogl_handle_unref (prev_source); cogl_object_unref (prev_source);
} }
static int static int
@ -525,7 +523,7 @@ _cogl_path_fill_nodes (void)
if (G_LIKELY (!(cogl_debug_flags & COGL_DEBUG_FORCE_SCANLINE_PATHS)) && if (G_LIKELY (!(cogl_debug_flags & COGL_DEBUG_FORCE_SCANLINE_PATHS)) &&
cogl_features_available (COGL_FEATURE_STENCIL_BUFFER)) cogl_features_available (COGL_FEATURE_STENCIL_BUFFER))
{ {
CoglHandle framebuffer; CoglFramebuffer *framebuffer;
CoglClipState *clip_state; CoglClipState *clip_state;
_cogl_journal_flush (); _cogl_journal_flush ();
@ -689,7 +687,7 @@ cogl_path_new (void)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
cogl_handle_unref (ctx->current_path); cogl_object_unref (ctx->current_path);
ctx->current_path = _cogl_path_new (); ctx->current_path = _cogl_path_new ();
} }
@ -1062,7 +1060,7 @@ cogl_path_rel_curve_to (float x_1,
data->path_pen.y + y_3); data->path_pen.y + y_3);
} }
CoglHandle CoglPath *
cogl_path_get (void) cogl_path_get (void)
{ {
_COGL_GET_CONTEXT (ctx, NULL); _COGL_GET_CONTEXT (ctx, NULL);
@ -1071,21 +1069,21 @@ cogl_path_get (void)
} }
void void
cogl_path_set (CoglHandle handle) cogl_path_set (CoglPath *path)
{ {
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
if (!cogl_is_path (handle)) if (!cogl_is_path (path))
return; return;
/* Reference the new handle first in case it is the same as the old /* Reference the new object first in case it is the same as the old
handle */ object */
cogl_handle_ref (handle); cogl_object_ref (path);
cogl_handle_unref (ctx->current_path); cogl_object_unref (ctx->current_path);
ctx->current_path = handle; ctx->current_path = path;
} }
CoglHandle CoglPath *
_cogl_path_new (void) _cogl_path_new (void)
{ {
CoglPath *path; CoglPath *path;
@ -1098,26 +1096,24 @@ _cogl_path_new (void)
data->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode)); data->path_nodes = g_array_new (FALSE, FALSE, sizeof (CoglPathNode));
data->last_path = 0; data->last_path = 0;
return _cogl_path_handle_new (path); return _cogl_path_object_new (path);
} }
CoglHandle CoglPath *
cogl_path_copy (CoglHandle handle) cogl_path_copy (CoglPath *old_path)
{ {
CoglPath *old_path, *new_path; CoglPath *new_path;
_COGL_GET_CONTEXT (ctx, NULL); _COGL_GET_CONTEXT (ctx, NULL);
if (!cogl_is_path (handle)) if (!cogl_is_path (old_path))
return COGL_INVALID_HANDLE; return NULL;
old_path = COGL_PATH (handle);
new_path = g_slice_new (CoglPath); new_path = g_slice_new (CoglPath);
new_path->data = old_path->data; new_path->data = old_path->data;
new_path->data->ref_count++; new_path->data->ref_count++;
return _cogl_path_handle_new (new_path); return _cogl_path_object_new (new_path);
} }
static void static void

View File

@ -51,6 +51,8 @@ G_BEGIN_DECLS
* rather then in the absolute coordinates. * rather then in the absolute coordinates.
*/ */
typedef struct _CoglPath CoglPath;
/** /**
* cogl_path_fill: * cogl_path_fill:
* *
@ -368,49 +370,50 @@ cogl_path_round_rectangle (float x_1,
/** /**
* cogl_path_get: * cogl_path_get:
* *
* Gets a handle to the current path. The path can later be used again * Gets a pointer to the current path. The path can later be used
* by calling cogl_path_set(). Note that the path isn't copied so if * again by calling cogl_path_set(). Note that the path isn't copied
* you later call any functions to add to the path it will affect the * so if you later call any functions to add to the path it will
* returned handle too. No reference is taken on the path so if you * affect the returned object too. No reference is taken on the path
* want to retain it you should take your own reference with * so if you want to retain it you should take your own reference with
* cogl_handle_ref(). * cogl_object_ref().
* *
* Return value: a handle to the current path. * Return value: a pointer to the current path.
* *
* Since: 1.4 * Since: 1.4
*/ */
CoglHandle CoglPath *
cogl_path_get (void); cogl_path_get (void);
/** /**
* cogl_path_set: * cogl_path_set:
* @handle: A %CoglHandle to a path * @path: A #CoglPath object
* *
* Replaces the current path with @handle. A reference is taken on the * Replaces the current path with @path. A reference is taken on the
* handle so if you no longer need the path you should unref with * object so if you no longer need the path you should unref with
* cogl_handle_unref(). * cogl_object_unref().
* *
* Since: 1.4 * Since: 1.4
*/ */
void void
cogl_path_set (CoglHandle handle); cogl_path_set (CoglPath *path);
/** /**
* cogl_path_copy: * cogl_path_copy:
* @handle: A %CoglHandle to a path * @path: A #CoglPath object
* *
* Returns a new copy of the path in @handle. The new path has a * Returns a new copy of the path in @path. The new path has a
* reference count of 1 so you should unref it with * reference count of 1 so you should unref it with
* cogl_handle_unref() if you no longer need it. * cogl_object_unref() if you no longer need it.
* *
* Internally the path will share the data until one of the paths is * Internally the path will share the data until one of the paths is
* modified so copying paths should be relatively cheap. * modified so copying paths should be relatively cheap.
* *
* Return value: a copy of the path in @handle. * Return value: a copy of the path in @path.
*/ */
CoglHandle CoglPath *
cogl_path_copy (CoglHandle handle); cogl_path_copy (CoglPath *path);
G_END_DECLS G_END_DECLS
#endif /* __COGL_PATH_H__ */ #endif /* __COGL_PATH_H__ */

View File

@ -389,7 +389,7 @@ cogl_set_viewport (int x,
int width, int width,
int height) int height)
{ {
CoglHandle framebuffer; CoglFramebuffer *framebuffer;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -514,7 +514,7 @@ cogl_features_available (CoglFeatureFlags features)
void void
cogl_get_viewport (float v[4]) cogl_get_viewport (float v[4])
{ {
CoglHandle framebuffer; CoglFramebuffer *framebuffer;
int viewport[4]; int viewport[4];
int i; int i;
@ -621,7 +621,7 @@ cogl_read_pixels (int x,
CoglPixelFormat format, CoglPixelFormat format,
guint8 *pixels) guint8 *pixels)
{ {
CoglHandle framebuffer; CoglFramebuffer *framebuffer;
int framebuffer_height; int framebuffer_height;
int bpp; int bpp;
CoglBitmap bmp; CoglBitmap bmp;
@ -1110,7 +1110,7 @@ cogl_set_projection_matrix (CoglMatrix *matrix)
CoglClipState * CoglClipState *
_cogl_get_clip_state (void) _cogl_get_clip_state (void)
{ {
CoglHandle framebuffer; CoglFramebuffer *framebuffer;
framebuffer = _cogl_get_framebuffer (); framebuffer = _cogl_get_framebuffer ();
return _cogl_framebuffer_get_clip_state (framebuffer); return _cogl_framebuffer_get_clip_state (framebuffer);
@ -1147,7 +1147,7 @@ cogl_set_source_texture (CoglHandle texture_handle)
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
g_return_if_fail (texture_handle != COGL_INVALID_HANDLE); g_return_if_fail (texture_handle != NULL);
cogl_material_set_layer (ctx->simple_material, 0, texture_handle); cogl_material_set_layer (ctx->simple_material, 0, texture_handle);
cogl_color_set_from_4ub (&white, 0xff, 0xff, 0xff, 0xff); cogl_color_set_from_4ub (&white, 0xff, 0xff, 0xff, 0xff);