buffer: Remove use of CoglHandle in the CoglBuffer API

This replaces the use of CoglHandle with strongly type CoglBuffer *
pointers instead. The only function not converted for now is
cogl_is_buffer which will be done in a later commit.
This commit is contained in:
Robert Bragg 2010-05-27 23:40:40 +01:00
parent 7bcea1c64e
commit 3aaef72e50
3 changed files with 55 additions and 66 deletions

View File

@ -45,7 +45,6 @@ G_BEGIN_DECLS
#define COGL_BUFFER_FLAG_IS_SET(buffer, flag) \ #define COGL_BUFFER_FLAG_IS_SET(buffer, flag) \
((buffer)->flags & (COGL_BUFFER_FLAG_ ## flag)) ((buffer)->flags & (COGL_BUFFER_FLAG_ ## flag))
typedef struct _CoglBuffer CoglBuffer;
typedef struct _CoglBufferVtable CoglBufferVtable; typedef struct _CoglBufferVtable CoglBufferVtable;
struct _CoglBufferVtable struct _CoglBufferVtable

View File

@ -70,14 +70,14 @@
#endif #endif
void cogl_buffer_unmap_EXP (CoglHandle handle); void cogl_buffer_unmap_EXP (CoglBuffer *buffer);
gboolean gboolean
cogl_is_buffer_EXP (CoglHandle handle) cogl_is_buffer_EXP (const void *object)
{ {
CoglHandleObject *obj = (CoglHandleObject *) handle; CoglObject *obj = (CoglObject *)object;
if (handle == COGL_INVALID_HANDLE) if (obj == NULL)
return FALSE; return FALSE;
return obj->klass->type == _cogl_handle_pixel_buffer_get_type (); return obj->klass->type == _cogl_handle_pixel_buffer_get_type ();
@ -179,69 +179,65 @@ _cogl_buffer_bind (CoglBuffer *buffer,
} }
unsigned int unsigned int
cogl_buffer_get_size_EXP (CoglHandle handle) cogl_buffer_get_size_EXP (CoglBuffer *buffer)
{ {
if (!cogl_is_buffer (handle)) if (!cogl_is_buffer (buffer))
return 0; return 0;
return COGL_BUFFER (handle)->size; return COGL_BUFFER (buffer)->size;
} }
void void
cogl_buffer_set_usage_hint_EXP (CoglHandle handle, cogl_buffer_set_usage_hint_EXP (CoglBuffer *buffer,
CoglBufferUsageHint hint) CoglBufferUsageHint hint)
{ {
if (!cogl_is_buffer (handle)) if (!cogl_is_buffer (buffer))
return; return;
if (G_UNLIKELY (hint > COGL_BUFFER_USAGE_HINT_TEXTURE)) if (G_UNLIKELY (hint > COGL_BUFFER_USAGE_HINT_TEXTURE))
hint = COGL_BUFFER_USAGE_HINT_TEXTURE; hint = COGL_BUFFER_USAGE_HINT_TEXTURE;
COGL_BUFFER (handle)->usage_hint = hint; buffer->usage_hint = hint;
} }
CoglBufferUsageHint CoglBufferUsageHint
cogl_buffer_get_usage_hint_EXP (CoglHandle handle) cogl_buffer_get_usage_hint_EXP (CoglBuffer *buffer)
{ {
if (!cogl_is_buffer (handle)) if (!cogl_is_buffer (buffer))
return FALSE; return FALSE;
return COGL_BUFFER (handle)->usage_hint; return buffer->usage_hint;
} }
void void
cogl_buffer_set_update_hint_EXP (CoglHandle handle, cogl_buffer_set_update_hint_EXP (CoglBuffer *buffer,
CoglBufferUpdateHint hint) CoglBufferUpdateHint hint)
{ {
if (!cogl_is_buffer (handle)) if (!cogl_is_buffer (buffer))
return; return;
if (G_UNLIKELY (hint > COGL_BUFFER_UPDATE_HINT_STREAM)) if (G_UNLIKELY (hint > COGL_BUFFER_UPDATE_HINT_STREAM))
hint = COGL_BUFFER_UPDATE_HINT_STATIC; hint = COGL_BUFFER_UPDATE_HINT_STATIC;
COGL_BUFFER (handle)->update_hint = hint; buffer->update_hint = hint;
} }
CoglBufferUpdateHint CoglBufferUpdateHint
cogl_buffer_get_update_hint_EXP (CoglHandle handle) cogl_buffer_get_update_hint_EXP (CoglBuffer *buffer)
{ {
if (!cogl_is_buffer (handle)) if (!cogl_is_buffer (buffer))
return FALSE; return FALSE;
return COGL_BUFFER (handle)->update_hint; return buffer->update_hint;
} }
guint8 * guint8 *
cogl_buffer_map_EXP (CoglHandle handle, cogl_buffer_map_EXP (CoglBuffer *buffer,
CoglBufferAccess access) CoglBufferAccess access)
{ {
CoglBuffer *buffer; if (!cogl_is_buffer (buffer))
if (!cogl_is_buffer (handle))
return FALSE; return FALSE;
buffer = COGL_BUFFER (handle);
if (COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED)) if (COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED))
return buffer->data; return buffer->data;
@ -250,15 +246,11 @@ cogl_buffer_map_EXP (CoglHandle handle,
} }
void void
cogl_buffer_unmap_EXP (CoglHandle handle) cogl_buffer_unmap_EXP (CoglBuffer *buffer)
{ {
CoglBuffer *buffer; if (!cogl_is_buffer (buffer))
if (!cogl_is_buffer (handle))
return; return;
buffer = COGL_BUFFER (handle);
if (!COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED)) if (!COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED))
return; return;
@ -266,18 +258,14 @@ cogl_buffer_unmap_EXP (CoglHandle handle)
} }
gboolean gboolean
cogl_buffer_set_data_EXP (CoglHandle handle, cogl_buffer_set_data_EXP (CoglBuffer *buffer,
gsize offset, gsize offset,
const guint8 *data, const guint8 *data,
gsize size) gsize size)
{ {
CoglBuffer *buffer; if (!cogl_is_buffer (buffer))
if (!cogl_is_buffer (handle))
return FALSE; return FALSE;
buffer = COGL_BUFFER (handle);
if (G_UNLIKELY((offset + size) > buffer->size)) if (G_UNLIKELY((offset + size) > buffer->size))
return FALSE; return FALSE;

View File

@ -45,11 +45,13 @@ G_BEGIN_DECLS
* OpenGL implementation allows it, COGL will use Pixel Buffer Objects. * OpenGL implementation allows it, COGL will use Pixel Buffer Objects.
*/ */
typedef struct _CoglBuffer CoglBuffer;
/** /**
* cogl_is_buffer: * cogl_is_buffer:
* @handle: a #CoglHandle to test * @handle: a #CoglHandle to test
* *
* Checks whether @handle is a buffer handle. * Checks whether @buffer is a buffer object.
* *
* Return value: %TRUE if the handle is a CoglBuffer, and %FALSE otherwise * Return value: %TRUE if the handle is a CoglBuffer, and %FALSE otherwise
* *
@ -61,7 +63,7 @@ cogl_is_buffer (CoglHandle handle);
/** /**
* cogl_buffer_get_size: * cogl_buffer_get_size:
* @handle: a buffer handle * @buffer: a buffer object
* *
* Retrieves the size of buffer * Retrieves the size of buffer
* *
@ -71,7 +73,7 @@ cogl_is_buffer (CoglHandle handle);
* Stability: Unstable * Stability: Unstable
*/ */
unsigned int unsigned int
cogl_buffer_get_size (CoglHandle handle); cogl_buffer_get_size (CoglBuffer *buffer);
/** /**
* CoglBufferUsageHint: * CoglBufferUsageHint:
@ -90,7 +92,7 @@ typedef enum { /*< prefix=COGL_BUFFER_USAGE_HINT >*/
/** /**
* cogl_buffer_set_usage_hint: * cogl_buffer_set_usage_hint:
* @handle: a buffer handle * @buffer: a buffer object
* @hint: the new hint * @hint: the new hint
* *
* Sets the usage hint on a buffer. See #CoglBufferUsageHint for a description * Sets the usage hint on a buffer. See #CoglBufferUsageHint for a description
@ -100,12 +102,12 @@ typedef enum { /*< prefix=COGL_BUFFER_USAGE_HINT >*/
* Stability: Unstable * Stability: Unstable
*/ */
void void
cogl_buffer_set_usage_hint (CoglHandle handle, cogl_buffer_set_usage_hint (CoglBuffer *buffer,
CoglBufferUsageHint hint); CoglBufferUsageHint hint);
/** /**
* cogl_buffer_get_usage_hint: * cogl_buffer_get_usage_hint:
* @handle: a buffer handle * @buffer: a buffer object
* *
* Retrieves the usage hint set using cogl_buffer_set_usage_hint() * Retrieves the usage hint set using cogl_buffer_set_usage_hint()
* *
@ -115,7 +117,7 @@ cogl_buffer_set_usage_hint (CoglHandle handle,
* Stability: Unstable * Stability: Unstable
*/ */
CoglBufferUsageHint CoglBufferUsageHint
cogl_buffer_get_usage_hint (CoglHandle handle); cogl_buffer_get_usage_hint (CoglBuffer *buffer);
/** /**
* CoglBufferUpdateHint: * CoglBufferUpdateHint:
@ -138,7 +140,7 @@ typedef enum { /*< prefix=COGL_BUFFER_UPDATE_HINT >*/
/** /**
* cogl_buffer_set_update_hint: * cogl_buffer_set_update_hint:
* @handle: a buffer handle * @buffer: a buffer object
* @hint: the new hint * @hint: the new hint
* *
* Sets the update hint on a buffer. See #CoglBufferUpdateHint for a description * Sets the update hint on a buffer. See #CoglBufferUpdateHint for a description
@ -148,12 +150,12 @@ typedef enum { /*< prefix=COGL_BUFFER_UPDATE_HINT >*/
* Stability: Unstable * Stability: Unstable
*/ */
void void
cogl_buffer_set_update_hint (CoglHandle handle, cogl_buffer_set_update_hint (CoglBuffer *buffer,
CoglBufferUpdateHint hint); CoglBufferUpdateHint hint);
/** /**
* cogl_buffer_get_update_hint: * cogl_buffer_get_update_hint:
* @handle: a buffer handle * @buffer: a buffer object
* *
* Retrieves the update hints set using cogl_buffer_set_update_hint() * Retrieves the update hints set using cogl_buffer_set_update_hint()
* *
@ -163,7 +165,7 @@ cogl_buffer_set_update_hint (CoglHandle handle,
* Stability: Unstable * Stability: Unstable
*/ */
CoglBufferUpdateHint CoglBufferUpdateHint
cogl_buffer_get_update_hint (CoglHandle handle); cogl_buffer_get_update_hint (CoglBuffer *buffer);
/** /**
* CoglBufferAccess: * CoglBufferAccess:
@ -186,7 +188,7 @@ typedef enum { /*< prefix=COGL_BUFFER_ACCESS >*/
/** /**
* cogl_buffer_map: * cogl_buffer_map:
* @handle: a buffer handle * @buffer: a buffer object
* @access: how the mapped buffer will by use by the application * @access: how the mapped buffer will by use by the application
* *
* Maps the buffer into the application address space for direct access. * Maps the buffer into the application address space for direct access.
@ -197,12 +199,12 @@ typedef enum { /*< prefix=COGL_BUFFER_ACCESS >*/
* Stability: Unstable * Stability: Unstable
*/ */
guint8 * guint8 *
cogl_buffer_map (CoglHandle handle, cogl_buffer_map (CoglBuffer *buffer,
CoglBufferAccess access); CoglBufferAccess access);
/** /**
* cogl_buffer_unmap: * cogl_buffer_unmap:
* @handle: a buffer handle * @buffer: a buffer object
* *
* Unmaps a buffer previously mapped by cogl_buffer_map(). * Unmaps a buffer previously mapped by cogl_buffer_map().
* *
@ -210,11 +212,11 @@ cogl_buffer_map (CoglHandle handle,
* Stability: Unstable * Stability: Unstable
*/ */
void void
cogl_buffer_unmap (CoglHandle handle); cogl_buffer_unmap (CoglBuffer *buffer);
/** /**
* cogl_buffer_set_data: * cogl_buffer_set_data:
* @handle: a buffer handle * @buffer: a buffer object
* @offset: destination offset (in bytes) in the buffer * @offset: destination offset (in bytes) in the buffer
* @data: a pointer to the data to be copied into the buffer * @data: a pointer to the data to be copied into the buffer
* @size: number of bytes to copy * @size: number of bytes to copy
@ -229,7 +231,7 @@ cogl_buffer_unmap (CoglHandle handle);
* Stability: Unstable * Stability: Unstable
*/ */
gboolean gboolean
cogl_buffer_set_data (CoglHandle handle, cogl_buffer_set_data (CoglBuffer *buffer,
gsize offset, gsize offset,
const guint8 *data, const guint8 *data,
gsize size); gsize size);
@ -240,37 +242,37 @@ cogl_buffer_set_data (CoglHandle handle,
* above into the real symbols */ * above into the real symbols */
gboolean gboolean
cogl_is_buffer_EXP (CoglHandle handle); cogl_is_buffer_EXP (const void *object);
unsigned int unsigned int
cogl_buffer_get_size_EXP (CoglHandle handle); cogl_buffer_get_size_EXP (CoglBuffer *buffer);
void void
cogl_buffer_set_usage_hint_EXP (CoglHandle handle, cogl_buffer_set_usage_hint_EXP (CoglBuffer *buffer,
CoglBufferUsageHint hint); CoglBufferUsageHint hint);
CoglBufferUsageHint CoglBufferUsageHint
cogl_buffer_get_usage_hint_EXP (CoglHandle handle); cogl_buffer_get_usage_hint_EXP (CoglBuffer *buffer);
void void
cogl_buffer_set_update_hint_EXP (CoglHandle handle, cogl_buffer_set_update_hint_EXP (CoglBuffer *buffer,
CoglBufferUpdateHint hint); CoglBufferUpdateHint hint);
CoglBufferUpdateHint CoglBufferUpdateHint
cogl_buffer_get_update_hint_EXP (CoglHandle handle); cogl_buffer_get_update_hint_EXP (CoglBuffer *buffer);
guint8 * guint8 *
cogl_buffer_map_EXP (CoglHandle handle, cogl_buffer_map_EXP (CoglBuffer *buffer,
CoglBufferAccess access); CoglBufferAccess access);
void void
cogl_buffer_unmap_EXP (CoglHandle handle); cogl_buffer_unmap_EXP (CoglBuffer *buffer);
gboolean gboolean
cogl_buffer_set_data_EXP (CoglHandle handle, cogl_buffer_set_data_EXP (CoglBuffer *buffer,
gsize offset, gsize offset,
const guint8 *data, const guint8 *data,
gsize size); gsize size);
#define cogl_is_buffer cogl_is_buffer_EXP #define cogl_is_buffer cogl_is_buffer_EXP
#define cogl_buffer_get_size cogl_buffer_get_size_EXP #define cogl_buffer_get_size cogl_buffer_get_size_EXP