bitmap: ret CoglError from _new_with_malloc_buffer

_cogl_bitmap_new_with_malloc_buffer() now takes a CoglError for throwing
exceptional errors and all callers have been updated to pass through
any application error pointer as appropriate.

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 67cad9c0eb5e2650b75aff16abde49f23aabd0cc)
This commit is contained in:
Robert Bragg 2012-11-08 22:14:18 +00:00
parent 07d47eadd3
commit da9f5e6179
7 changed files with 64 additions and 14 deletions

View File

@ -488,7 +488,10 @@ _cogl_bitmap_convert (CoglBitmap *src_bmp,
dst_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx, dst_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
width, height, width, height,
dst_format); dst_format,
error);
if (!dst_bmp)
return NULL;
if (!_cogl_bitmap_convert_into_bitmap (src_bmp, dst_bmp, error)) if (!_cogl_bitmap_convert_into_bitmap (src_bmp, dst_bmp, error))
{ {

View File

@ -69,6 +69,7 @@ struct _CoglBitmap
* @width: width of the bitmap in pixels * @width: width of the bitmap in pixels
* @height: height of the bitmap in pixels * @height: height of the bitmap in pixels
* @format: the format of the pixels the array will store * @format: the format of the pixels the array will store
* @error: A #CoglError for catching exceptional errors or %NULL
* *
* This is equivalent to cogl_bitmap_new_with_size() except that it * This is equivalent to cogl_bitmap_new_with_size() except that it
* allocated the buffer using g_malloc() instead of creating a * allocated the buffer using g_malloc() instead of creating a
@ -84,7 +85,8 @@ CoglBitmap *
_cogl_bitmap_new_with_malloc_buffer (CoglContext *context, _cogl_bitmap_new_with_malloc_buffer (CoglContext *context,
unsigned int width, unsigned int width,
unsigned int height, unsigned int height,
CoglPixelFormat format); CoglPixelFormat format,
CoglError **error);
/* The idea of this function is that it will create a bitmap that /* The idea of this function is that it will create a bitmap that
shares the actual data with another bitmap. This is needed for the shares the actual data with another bitmap. This is needed for the

View File

@ -89,7 +89,10 @@ _cogl_bitmap_copy (CoglBitmap *src_bmp,
dst_bmp = dst_bmp =
_cogl_bitmap_new_with_malloc_buffer (src_bmp->context, _cogl_bitmap_new_with_malloc_buffer (src_bmp->context,
width, height, width, height,
src_format); src_format,
error);
if (!dst_bmp)
return NULL;
if (!_cogl_bitmap_copy_subregion (src_bmp, if (!_cogl_bitmap_copy_subregion (src_bmp,
dst_bmp, dst_bmp,
@ -194,14 +197,24 @@ CoglBitmap *
_cogl_bitmap_new_with_malloc_buffer (CoglContext *context, _cogl_bitmap_new_with_malloc_buffer (CoglContext *context,
unsigned int width, unsigned int width,
unsigned int height, unsigned int height,
CoglPixelFormat format) CoglPixelFormat format,
CoglError **error)
{ {
static CoglUserDataKey bitmap_free_key; static CoglUserDataKey bitmap_free_key;
int bpp = _cogl_pixel_format_get_bytes_per_pixel (format); int bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
int rowstride = ((width * bpp) + 3) & ~3; int rowstride = ((width * bpp) + 3) & ~3;
uint8_t *data = g_malloc (rowstride * height); uint8_t *data = g_try_malloc (rowstride * height);
CoglBitmap *bitmap; CoglBitmap *bitmap;
if (!data)
{
_cogl_set_error (error,
COGL_SYSTEM_ERROR,
COGL_SYSTEM_ERROR_NO_MEMORY,
"Failed to allocate memory for bitmap");
return NULL;
}
bitmap = cogl_bitmap_new_for_data (context, bitmap = cogl_bitmap_new_for_data (context,
width, height, width, height,
format, format,

View File

@ -1613,7 +1613,11 @@ _cogl_framebuffer_read_pixels_into_bitmap (CoglFramebuffer *framebuffer,
tmp_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx, tmp_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
width, height, width, height,
read_format); read_format,
error);
if (!tmp_bmp)
goto EXIT;
bpp = _cogl_pixel_format_get_bytes_per_pixel (read_format); bpp = _cogl_pixel_format_get_bytes_per_pixel (read_format);
rowstride = cogl_bitmap_get_rowstride (tmp_bmp); rowstride = cogl_bitmap_get_rowstride (tmp_bmp);

View File

@ -405,7 +405,10 @@ cogl_texture_3d_new_from_data (CoglContext *context,
bitmap = _cogl_bitmap_new_with_malloc_buffer (context, bitmap = _cogl_bitmap_new_with_malloc_buffer (context,
width, width,
depth * height, depth * height,
format); format,
error);
if (!bitmap)
return NULL;
bmp_data = _cogl_bitmap_map (bitmap, bmp_data = _cogl_bitmap_map (bitmap,
COGL_BUFFER_ACCESS_WRITE, COGL_BUFFER_ACCESS_WRITE,

View File

@ -659,7 +659,10 @@ do_texture_draw_and_read (CoglFramebuffer *fb,
rect_bmp = _cogl_bitmap_new_with_malloc_buffer rect_bmp = _cogl_bitmap_new_with_malloc_buffer
(ctx, (ctx,
width, height, width, height,
COGL_PIXEL_FORMAT_RGBA_8888_PRE); COGL_PIXEL_FORMAT_RGBA_8888_PRE,
error);
if (!rect_bmp)
return FALSE;
if (!_cogl_framebuffer_read_pixels_into_bitmap if (!_cogl_framebuffer_read_pixels_into_bitmap
(fb, (fb,
@ -787,7 +790,14 @@ _cogl_texture_draw_and_read (CoglTexture *texture,
_cogl_bitmap_new_with_malloc_buffer (ctx, _cogl_bitmap_new_with_malloc_buffer (ctx,
target_width, target_width,
target_height, target_height,
COGL_PIXEL_FORMAT_RGBA_8888); COGL_PIXEL_FORMAT_RGBA_8888,
error);
if (!alpha_bmp)
{
_cogl_bitmap_unmap (target_bmp);
goto EXIT;
}
/* Draw alpha values into RGB channels */ /* Draw alpha values into RGB channels */
cogl_pipeline_set_layer_combine (ctx->texture_download_pipeline, cogl_pipeline_set_layer_combine (ctx->texture_download_pipeline,
@ -1112,9 +1122,17 @@ cogl_texture_get_data (CoglTexture *texture,
rowstride, rowstride,
data); data);
else else
{
target_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx, target_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
tex_width, tex_height, tex_width, tex_height,
closest_format); closest_format,
&ignore_error);
if (!target_bmp)
{
cogl_error_free (ignore_error);
return 0;
}
}
tg_data.target_bits = _cogl_bitmap_map (target_bmp, COGL_BUFFER_ACCESS_WRITE, tg_data.target_bits = _cogl_bitmap_map (target_bmp, COGL_BUFFER_ACCESS_WRITE,
COGL_BUFFER_MAP_HINT_DISCARD, COGL_BUFFER_MAP_HINT_DISCARD,

View File

@ -205,7 +205,11 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
slice_bmp = slice_bmp =
_cogl_bitmap_new_with_malloc_buffer (ctx, _cogl_bitmap_new_with_malloc_buffer (ctx,
width, height, width, height,
source_format); source_format,
error);
if (!slice_bmp)
return FALSE;
if (!_cogl_bitmap_copy_subregion (source_bmp, if (!_cogl_bitmap_copy_subregion (source_bmp,
slice_bmp, slice_bmp,
src_x, src_y, src_x, src_y,
@ -387,7 +391,10 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
bmp = _cogl_bitmap_new_with_malloc_buffer (ctx, bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
bmp_width, bmp_width,
height, height,
source_bmp_format); source_bmp_format,
error);
if (!bmp)
return FALSE;
for (i = 0; i < depth; i++) for (i = 0; i < depth; i++)
{ {