bitmap: Add a function to convert into an existing buffer

This adds _cogl_bitmap_convert_into_bitmap which is the same as
_cogl_bitmap_convert except that it writes into an existing bitmap
instead of allocating a new one. _cogl_bitmap_convert now just
allocates a buffer and calls the new function. This is used in
_cogl_read_pixels to avoid allocating a second intermediate buffer
when the pixel format to store in is not GL_RGBA.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
Neil Roberts
2012-03-01 14:44:41 +00:00
parent f4cd5aceb9
commit 031dd661c0
4 changed files with 88 additions and 41 deletions

View File

@ -484,7 +484,7 @@ _cogl_read_pixels_with_rowstride (int x,
(gl_format != GL_RGBA || gl_type != GL_UNSIGNED_BYTE ||
rowstride != 4 * width))
{
CoglBitmap *tmp_bmp, *dst_bmp;
CoglBitmap *tmp_bmp;
guint8 *tmp_data = g_malloc (width * height * 4);
tmp_bmp = _cogl_bitmap_new_from_data (tmp_data,
@ -500,19 +500,7 @@ _cogl_read_pixels_with_rowstride (int x,
GL_RGBA, GL_UNSIGNED_BYTE,
tmp_data) );
/* CoglBitmap doesn't currently have a way to convert without
allocating its own buffer so we have to copy the data
again */
if ((dst_bmp = _cogl_bitmap_convert (tmp_bmp, format)))
{
_cogl_bitmap_copy_subregion (dst_bmp,
bmp,
0, 0,
0, 0,
width, height);
cogl_object_unref (dst_bmp);
}
else
if (!_cogl_bitmap_convert_into_bitmap (tmp_bmp, bmp))
{
/* FIXME: there's no way to report an error here so we'll
just have to leave the data initialised */