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 a8c8cbee51
commit e2fc489f08
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) \
((buffer)->flags & (COGL_BUFFER_FLAG_ ## flag))
typedef struct _CoglBuffer CoglBuffer;
typedef struct _CoglBufferVtable CoglBufferVtable;
struct _CoglBufferVtable

View File

@ -70,14 +70,14 @@
#endif
void cogl_buffer_unmap_EXP (CoglHandle handle);
void cogl_buffer_unmap_EXP (CoglBuffer *buffer);
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 obj->klass->type == _cogl_handle_pixel_buffer_get_type ();
@ -179,69 +179,65 @@ _cogl_buffer_bind (CoglBuffer *buffer,
}
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 COGL_BUFFER (handle)->size;
return COGL_BUFFER (buffer)->size;
}
void
cogl_buffer_set_usage_hint_EXP (CoglHandle handle,
cogl_buffer_set_usage_hint_EXP (CoglBuffer *buffer,
CoglBufferUsageHint hint)
{
if (!cogl_is_buffer (handle))
if (!cogl_is_buffer (buffer))
return;
if (G_UNLIKELY (hint > COGL_BUFFER_USAGE_HINT_TEXTURE))
hint = COGL_BUFFER_USAGE_HINT_TEXTURE;
COGL_BUFFER (handle)->usage_hint = hint;
buffer->usage_hint = hint;
}
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 COGL_BUFFER (handle)->usage_hint;
return buffer->usage_hint;
}
void
cogl_buffer_set_update_hint_EXP (CoglHandle handle,
cogl_buffer_set_update_hint_EXP (CoglBuffer *buffer,
CoglBufferUpdateHint hint)
{
if (!cogl_is_buffer (handle))
if (!cogl_is_buffer (buffer))
return;
if (G_UNLIKELY (hint > COGL_BUFFER_UPDATE_HINT_STREAM))
hint = COGL_BUFFER_UPDATE_HINT_STATIC;
COGL_BUFFER (handle)->update_hint = hint;
buffer->update_hint = hint;
}
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 COGL_BUFFER (handle)->update_hint;
return buffer->update_hint;
}
guint8 *
cogl_buffer_map_EXP (CoglHandle handle,
cogl_buffer_map_EXP (CoglBuffer *buffer,
CoglBufferAccess access)
{
CoglBuffer *buffer;
if (!cogl_is_buffer (handle))
if (!cogl_is_buffer (buffer))
return FALSE;
buffer = COGL_BUFFER (handle);
if (COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED))
return buffer->data;
@ -250,15 +246,11 @@ cogl_buffer_map_EXP (CoglHandle handle,
}
void
cogl_buffer_unmap_EXP (CoglHandle handle)
cogl_buffer_unmap_EXP (CoglBuffer *buffer)
{
CoglBuffer *buffer;
if (!cogl_is_buffer (handle))
if (!cogl_is_buffer (buffer))
return;
buffer = COGL_BUFFER (handle);
if (!COGL_BUFFER_FLAG_IS_SET (buffer, MAPPED))
return;
@ -266,18 +258,14 @@ cogl_buffer_unmap_EXP (CoglHandle handle)
}
gboolean
cogl_buffer_set_data_EXP (CoglHandle handle,
cogl_buffer_set_data_EXP (CoglBuffer *buffer,
gsize offset,
const guint8 *data,
gsize size)
{
CoglBuffer *buffer;
if (!cogl_is_buffer (handle))
if (!cogl_is_buffer (buffer))
return FALSE;
buffer = COGL_BUFFER (handle);
if (G_UNLIKELY((offset + size) > buffer->size))
return FALSE;

View File

@ -45,11 +45,13 @@ G_BEGIN_DECLS
* OpenGL implementation allows it, COGL will use Pixel Buffer Objects.
*/
typedef struct _CoglBuffer CoglBuffer;
/**
* cogl_is_buffer:
* @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
*
@ -61,7 +63,7 @@ cogl_is_buffer (CoglHandle handle);
/**
* cogl_buffer_get_size:
* @handle: a buffer handle
* @buffer: a buffer object
*
* Retrieves the size of buffer
*
@ -71,7 +73,7 @@ cogl_is_buffer (CoglHandle handle);
* Stability: Unstable
*/
unsigned int
cogl_buffer_get_size (CoglHandle handle);
cogl_buffer_get_size (CoglBuffer *buffer);
/**
* CoglBufferUsageHint:
@ -90,7 +92,7 @@ typedef enum { /*< prefix=COGL_BUFFER_USAGE_HINT >*/
/**
* cogl_buffer_set_usage_hint:
* @handle: a buffer handle
* @buffer: a buffer object
* @hint: the new hint
*
* 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
*/
void
cogl_buffer_set_usage_hint (CoglHandle handle,
cogl_buffer_set_usage_hint (CoglBuffer *buffer,
CoglBufferUsageHint 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()
*
@ -115,7 +117,7 @@ cogl_buffer_set_usage_hint (CoglHandle handle,
* Stability: Unstable
*/
CoglBufferUsageHint
cogl_buffer_get_usage_hint (CoglHandle handle);
cogl_buffer_get_usage_hint (CoglBuffer *buffer);
/**
* CoglBufferUpdateHint:
@ -138,7 +140,7 @@ typedef enum { /*< prefix=COGL_BUFFER_UPDATE_HINT >*/
/**
* cogl_buffer_set_update_hint:
* @handle: a buffer handle
* @buffer: a buffer object
* @hint: the new hint
*
* 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
*/
void
cogl_buffer_set_update_hint (CoglHandle handle,
cogl_buffer_set_update_hint (CoglBuffer *buffer,
CoglBufferUpdateHint 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()
*
@ -163,7 +165,7 @@ cogl_buffer_set_update_hint (CoglHandle handle,
* Stability: Unstable
*/
CoglBufferUpdateHint
cogl_buffer_get_update_hint (CoglHandle handle);
cogl_buffer_get_update_hint (CoglBuffer *buffer);
/**
* CoglBufferAccess:
@ -186,7 +188,7 @@ typedef enum { /*< prefix=COGL_BUFFER_ACCESS >*/
/**
* cogl_buffer_map:
* @handle: a buffer handle
* @buffer: a buffer object
* @access: how the mapped buffer will by use by the application
*
* Maps the buffer into the application address space for direct access.
@ -197,12 +199,12 @@ typedef enum { /*< prefix=COGL_BUFFER_ACCESS >*/
* Stability: Unstable
*/
guint8 *
cogl_buffer_map (CoglHandle handle,
cogl_buffer_map (CoglBuffer *buffer,
CoglBufferAccess access);
/**
* cogl_buffer_unmap:
* @handle: a buffer handle
* @buffer: a buffer object
*
* Unmaps a buffer previously mapped by cogl_buffer_map().
*
@ -210,11 +212,11 @@ cogl_buffer_map (CoglHandle handle,
* Stability: Unstable
*/
void
cogl_buffer_unmap (CoglHandle handle);
cogl_buffer_unmap (CoglBuffer *buffer);
/**
* cogl_buffer_set_data:
* @handle: a buffer handle
* @buffer: a buffer object
* @offset: destination offset (in bytes) in the buffer
* @data: a pointer to the data to be copied into the buffer
* @size: number of bytes to copy
@ -229,7 +231,7 @@ cogl_buffer_unmap (CoglHandle handle);
* Stability: Unstable
*/
gboolean
cogl_buffer_set_data (CoglHandle handle,
cogl_buffer_set_data (CoglBuffer *buffer,
gsize offset,
const guint8 *data,
gsize size);
@ -240,34 +242,34 @@ cogl_buffer_set_data (CoglHandle handle,
* above into the real symbols */
gboolean
cogl_is_buffer_EXP (CoglHandle handle);
cogl_is_buffer_EXP (const void *object);
unsigned int
cogl_buffer_get_size_EXP (CoglHandle handle);
cogl_buffer_get_size_EXP (CoglBuffer *buffer);
void
cogl_buffer_set_usage_hint_EXP (CoglHandle handle,
cogl_buffer_set_usage_hint_EXP (CoglBuffer *buffer,
CoglBufferUsageHint hint);
CoglBufferUsageHint
cogl_buffer_get_usage_hint_EXP (CoglHandle handle);
cogl_buffer_get_usage_hint_EXP (CoglBuffer *buffer);
void
cogl_buffer_set_update_hint_EXP (CoglHandle handle,
cogl_buffer_set_update_hint_EXP (CoglBuffer *buffer,
CoglBufferUpdateHint hint);
CoglBufferUpdateHint
cogl_buffer_get_update_hint_EXP (CoglHandle handle);
cogl_buffer_get_update_hint_EXP (CoglBuffer *buffer);
guint8 *
cogl_buffer_map_EXP (CoglHandle handle,
cogl_buffer_map_EXP (CoglBuffer *buffer,
CoglBufferAccess access);
void
cogl_buffer_unmap_EXP (CoglHandle handle);
cogl_buffer_unmap_EXP (CoglBuffer *buffer);
gboolean
cogl_buffer_set_data_EXP (CoglHandle handle,
cogl_buffer_set_data_EXP (CoglBuffer *buffer,
gsize offset,
const guint8 *data,
gsize size);