summaryrefslogtreecommitdiff
path: root/cogl/cogl-pixel-buffer.c
diff options
context:
space:
mode:
authorNeil Roberts <neil@linux.intel.com>2012-02-25 20:04:45 +0000
committerNeil Roberts <neil@linux.intel.com>2012-03-05 18:47:45 +0000
commit3700cc26a58cbf6ba255506b85acc9d93348a1fb (patch)
tree097b019dea15874d8b556a337cd7a6f24587eec8 /cogl/cogl-pixel-buffer.c
parent10a38bb14fac3ba8dc05115feb04bde56dc590e7 (diff)
downloadcogl-3700cc26a58cbf6ba255506b85acc9d93348a1fb.tar.gz
Change API so that CoglPixelBuffer no longer knows its w/h/format
The idea is that CoglPixelBuffer should just be a buffer that can be used for pixel data and it has no idea about the details of any images that are stored in it. This is analogous to CoglAttributeBuffer which itself does not have any information about the attributes. When you want to use a pixel buffer you should create a CoglBitmap which points to a region of the attribute buffer and provides the extra needed information such as the width, height and format. That way it is also possible to use a single CoglPixelBuffer with multiple bitmaps. The changes that are made are: • cogl_pixel_buffer_new_with_size has been removed and in its place is cogl_bitmap_new_with_size. This will create a pixel buffer at the right size and rowstride for the given width/height/format and immediately create a single CoglBitmap to point into it. The old function had an out-parameter for the stride of the image but with the new API this should be queriable from the bitmap (although there is no function for this yet). • There is now a public cogl_pixel_buffer_new constructor. This takes a size in bytes and data pointer similarly to cogl_attribute_buffer_new. • cogl_texture_new_from_buffer has been removed. If you want to create a texture from a pixel buffer you should wrap it up in a bitmap first. There is already API to create a texture from a bitmap. This patch also does a bit of header juggling because cogl-context.h was including cogl-texture.h and cogl-framebuffer.h which were causing some circular dependencies when cogl-bitmap.h includes cogl-context.h. These weren't actually needed in cogl-context.h itself but a few other headers were relying on them being included so this adds the #includes where necessary. Reviewed-by: Robert Bragg <robert@linux.intel.com>
Diffstat (limited to 'cogl/cogl-pixel-buffer.c')
-rw-r--r--cogl/cogl-pixel-buffer.c49
1 files changed, 12 insertions, 37 deletions
diff --git a/cogl/cogl-pixel-buffer.c b/cogl/cogl-pixel-buffer.c
index 12292ac2..4fd5fa53 100644
--- a/cogl/cogl-pixel-buffer.c
+++ b/cogl/cogl-pixel-buffer.c
@@ -66,8 +66,10 @@ _cogl_pixel_buffer_free (CoglPixelBuffer *buffer);
COGL_BUFFER_DEFINE (PixelBuffer, pixel_buffer)
-static CoglPixelBuffer *
-_cogl_pixel_buffer_new (CoglContext *context, unsigned int size)
+CoglPixelBuffer *
+cogl_pixel_buffer_new (CoglContext *context,
+ gsize size,
+ const void *data)
{
CoglPixelBuffer *pixel_buffer = g_slice_new0 (CoglPixelBuffer);
CoglBuffer *buffer = COGL_BUFFER (pixel_buffer);
@@ -87,42 +89,15 @@ _cogl_pixel_buffer_new (CoglContext *context, unsigned int size)
COGL_BUFFER_USAGE_HINT_TEXTURE,
COGL_BUFFER_UPDATE_HINT_STATIC);
- /* return COGL_INVALID_HANDLE; */
- return _cogl_pixel_buffer_object_new (pixel_buffer);
-}
+ _cogl_pixel_buffer_object_new (pixel_buffer);
-CoglPixelBuffer *
-cogl_pixel_buffer_new_with_size (CoglContext *context,
- unsigned int width,
- unsigned int height,
- CoglPixelFormat format,
- unsigned int *rowstride)
-{
- CoglPixelBuffer *buffer;
- CoglPixelBuffer *pixel_buffer;
- unsigned int stride;
-
- /* creating a buffer to store "any" format does not make sense */
- if (G_UNLIKELY (format == COGL_PIXEL_FORMAT_ANY))
- return COGL_INVALID_HANDLE;
-
- /* for now we fallback to cogl_pixel_buffer_new, later, we could ask
- * libdrm a tiled buffer for instance */
- stride = width * _cogl_pixel_format_get_bytes_per_pixel (format);
- if (rowstride)
- *rowstride = stride;
-
- buffer = _cogl_pixel_buffer_new (context, height * stride);
- if (G_UNLIKELY (buffer == COGL_INVALID_HANDLE))
- return COGL_INVALID_HANDLE;
-
- pixel_buffer = COGL_PIXEL_BUFFER (buffer);
- pixel_buffer->width = width;
- pixel_buffer->height = height;
- pixel_buffer->format = format;
- pixel_buffer->stride = stride;
-
- return buffer;
+ if (data)
+ cogl_buffer_set_data (COGL_BUFFER (pixel_buffer),
+ 0,
+ data,
+ size);
+
+ return pixel_buffer;
}
static void