Add a public cogl_bitmap_new_for_data
This creates a CoglBitmap which points into an existing buffer in system memory. That way it can be used to create a texture or to read pixel data into. The function replaces the existing internal function _cogl_bitmap_new_from_data but removes the destroy notify call back. If the application wants notification of destruction it can just use the cogl_object_set_user_data function as normal. Internally there is now a convenience function to create a bitmap for system memory and automatically free the buffer using that mechanism. The name of the function is inspired by cairo_image_surface_create_for_data which has similar semantics. Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
@ -2036,9 +2036,9 @@ cogl_framebuffer_read_pixels_into_bitmap (CoglFramebuffer *framebuffer,
|
||||
(required_format & ~COGL_PREMULT_BIT) != (format & ~COGL_PREMULT_BIT))
|
||||
{
|
||||
CoglBitmap *tmp_bmp;
|
||||
guint8 *tmp_data;
|
||||
CoglPixelFormat read_format;
|
||||
int bpp, rowstride;
|
||||
guint8 *tmp_data;
|
||||
int succeeded;
|
||||
|
||||
if (ctx->driver == COGL_DRIVER_GL)
|
||||
@ -2054,22 +2054,24 @@ cogl_framebuffer_read_pixels_into_bitmap (CoglFramebuffer *framebuffer,
|
||||
read_format = ((read_format & ~COGL_PREMULT_BIT) |
|
||||
(framebuffer->format & COGL_PREMULT_BIT));
|
||||
|
||||
tmp_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
|
||||
width, height,
|
||||
read_format);
|
||||
bpp = _cogl_pixel_format_get_bytes_per_pixel (read_format);
|
||||
rowstride = (width * bpp + 3) & ~3;
|
||||
tmp_data = g_malloc (rowstride * height);
|
||||
|
||||
tmp_bmp = _cogl_bitmap_new_from_data (tmp_data,
|
||||
read_format,
|
||||
width, height, rowstride,
|
||||
(CoglBitmapDestroyNotify) g_free,
|
||||
NULL);
|
||||
rowstride = cogl_bitmap_get_rowstride (tmp_bmp);
|
||||
|
||||
ctx->texture_driver->prep_gl_for_pixels_download (rowstride, bpp);
|
||||
|
||||
tmp_data = _cogl_bitmap_bind (tmp_bmp,
|
||||
COGL_BUFFER_ACCESS_WRITE,
|
||||
COGL_BUFFER_MAP_HINT_DISCARD);
|
||||
|
||||
GE( ctx, glReadPixels (x, y, width, height,
|
||||
gl_format, gl_type,
|
||||
tmp_data) );
|
||||
|
||||
_cogl_bitmap_unbind (tmp_bmp);
|
||||
|
||||
succeeded = _cogl_bitmap_convert_into_bitmap (tmp_bmp, bitmap);
|
||||
|
||||
cogl_object_unref (tmp_bmp);
|
||||
|
Reference in New Issue
Block a user