From 8a5aed36fe8e9cd57c4644653a8e7103ca946bc3 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Sun, 4 Jul 2010 00:49:31 +0100 Subject: [PATCH] pixel-array: Only allow allocation of arrays with a 2D size This removes cogl_pixel_array_new which just took a size in bytes. Without the image size and pixel format then the driver often doesn't have enough information to allocate optimal GPU memory that can be textured from directly. This is because GPUs often have ways to spatially alter the layout of a texture to improve cache access patterns which may require special alignment and padding dependant in the images width, height and bpp. Although currently we are limited by OpenGL because it doesn't let us pass on the width and height when allocating a PBO, the hope is that we can define a better extension at some point. --- clutter/cogl/cogl/cogl-pixel-array.c | 6 ++-- clutter/cogl/cogl/cogl-pixel-array.h | 16 ----------- tests/conform/test-cogl-pixel-buffer.c | 38 ++++++++++++++------------ 3 files changed, 24 insertions(+), 36 deletions(-) diff --git a/clutter/cogl/cogl/cogl-pixel-array.c b/clutter/cogl/cogl/cogl-pixel-array.c index 574a71c0f..ba8d60fc2 100644 --- a/clutter/cogl/cogl/cogl-pixel-array.c +++ b/clutter/cogl/cogl/cogl-pixel-array.c @@ -87,8 +87,8 @@ cogl_malloc_pixel_array_vtable; COGL_BUFFER_DEFINE (PixelArray, pixel_array) -CoglPixelArray * -cogl_pixel_array_new (unsigned int size) +static CoglPixelArray * +_cogl_pixel_array_new (unsigned int size) { CoglPixelArray *pixel_array = g_slice_new0 (CoglPixelArray); CoglBuffer *buffer = COGL_BUFFER (pixel_array); @@ -148,7 +148,7 @@ cogl_pixel_array_new_with_size (unsigned int width, if (rowstride) *rowstride = stride; - buffer = cogl_pixel_array_new (height * stride); + buffer = _cogl_pixel_array_new (height * stride); if (G_UNLIKELY (buffer == COGL_INVALID_HANDLE)) return COGL_INVALID_HANDLE; diff --git a/clutter/cogl/cogl/cogl-pixel-array.h b/clutter/cogl/cogl/cogl-pixel-array.h index 3e17782d8..870ed9cbf 100644 --- a/clutter/cogl/cogl/cogl-pixel-array.h +++ b/clutter/cogl/cogl/cogl-pixel-array.h @@ -52,22 +52,6 @@ G_BEGIN_DECLS typedef struct _CoglPixelArray CoglPixelArray; -/** - * cogl_pixel_array_new: - * @size: size of the array in bytes - * - * Creates a new array to store pixel data. You can create a new texture from - * this array using cogl_texture_new_from_buffer(). - * - * Return value: a #CoglPixelArray representing the newly created array or - * %NULL on failure - * - * Since: 1.2 - * Stability: Unstable - */ -CoglPixelArray * -cogl_pixel_array_new (unsigned int size); - /** * cogl_pixel_array_new_with_size: * @width: width of the pixel array in pixels diff --git a/tests/conform/test-cogl-pixel-buffer.c b/tests/conform/test-cogl-pixel-buffer.c index 49c36d598..f68110fbc 100644 --- a/tests/conform/test-cogl-pixel-buffer.c +++ b/tests/conform/test-cogl-pixel-buffer.c @@ -62,8 +62,13 @@ create_map_tile (TestTile *tile) CoglHandle buffer; guchar *map; guint i; + unsigned int stride = 0; + guint8 *line; - buffer = cogl_pixel_array_new (TILE_SIZE * TILE_SIZE * 4); + buffer = cogl_pixel_array_new_with_size (TILE_SIZE, + TILE_SIZE, + COGL_PIXEL_FORMAT_RGBA_8888, + &stride); g_assert (cogl_is_pixel_array (buffer)); g_assert (cogl_is_buffer (buffer)); @@ -76,8 +81,12 @@ create_map_tile (TestTile *tile) map = cogl_buffer_map (buffer, COGL_BUFFER_ACCESS_WRITE); g_assert (map); - for (i = 0; i < TILE_SIZE * TILE_SIZE * 4; i += 4) - memcpy (map + i, &tile->color, 4); + line = g_alloca (TILE_SIZE * 4); + for (i = 0; i < TILE_SIZE; i += 4) + memcpy (line + i, &tile->color, 4); + + for (i = 0; i < TILE_SIZE; i++) + memcpy (map + stride, line, 4); cogl_buffer_unmap (buffer); @@ -95,10 +104,10 @@ create_set_region_tile (TestTile *tile) guchar *data; guint i; - buffer = cogl_pixel_array_new_for_size (TILE_SIZE, - TILE_SIZE, - COGL_PIXEL_FORMAT_RGBA_8888, - &rowstride); + buffer = cogl_pixel_array_with_size (TILE_SIZE, + TILE_SIZE, + COGL_PIXEL_FORMAT_RGBA_8888, + &rowstride); g_assert (cogl_is_pixel_array (buffer)); g_assert (cogl_is_buffer (buffer)); @@ -143,26 +152,21 @@ create_set_data_tile (TestTile *tile) guchar *data; guint i; - buffer = cogl_pixel_array_new_for_size (TILE_SIZE, - TILE_SIZE, - COGL_PIXEL_FORMAT_RGBA_8888, - &rowstride); + buffer = cogl_pixel_array_new_with_size (TILE_SIZE, + TILE_SIZE, + COGL_PIXEL_FORMAT_RGBA_8888, + &rowstride); g_assert (cogl_is_pixel_array (buffer)); g_assert (cogl_is_buffer (buffer)); g_assert_cmpint (cogl_buffer_get_size (buffer), ==, rowstride * TILE_SIZE); - /* while at it, set/get the hint */ - cogl_buffer_set_usage_hint (buffer, COGL_BUFFER_USAGE_HINT_TEXTURE); - g_assert_cmpint (cogl_buffer_get_usage_hint (buffer), - ==, - COGL_BUFFER_USAGE_HINT_TEXTURE); - /* create a buffer with the data we want to copy to the buffer */ data = g_malloc (TILE_SIZE * TILE_SIZE * 4); for (i = 0; i < TILE_SIZE * TILE_SIZE * 4; i += 4) memcpy (data + i, &tile->color, 4); + /* FIXME: this doesn't consider the rowstride */ res = cogl_buffer_set_data (buffer, 0, data, TILE_SIZE * TILE_SIZE * 4); g_assert (res);