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

@ -128,7 +128,7 @@ _cogl_bitmap_copy (CoglBitmap *src_bmp)
return dst_bmp;
}
void
gboolean
_cogl_bitmap_copy_subregion (CoglBitmap *src,
CoglBitmap *dst,
int src_x,
@ -142,9 +142,12 @@ _cogl_bitmap_copy_subregion (CoglBitmap *src,
guint8 *dstdata;
int bpp;
int line;
gboolean succeeded = FALSE;
/* Intended only for fast copies when format is equal! */
g_assert (src->format == dst->format);
g_assert ((src->format & ~COGL_PREMULT_BIT) ==
(dst->format & ~COGL_PREMULT_BIT));
bpp = _cogl_pixel_format_get_bytes_per_pixel (src->format);
if ((srcdata = _cogl_bitmap_map (src, COGL_BUFFER_ACCESS_READ, 0)))
@ -161,11 +164,15 @@ _cogl_bitmap_copy_subregion (CoglBitmap *src,
dstdata += dst->rowstride;
}
succeeded = TRUE;
_cogl_bitmap_unmap (dst);
}
_cogl_bitmap_unmap (src);
}
return succeeded;
}
gboolean