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:
Neil Roberts
2012-03-13 14:46:18 +00:00
parent f65a895b4f
commit d18b59d9e6
14 changed files with 273 additions and 261 deletions

View File

@ -158,6 +158,11 @@ cogl_context_new (CoglDisplay *display,
/* Allocate context memory */
context = g_malloc (sizeof (CoglContext));
/* Convert the context into an object immediately in case any of the
code below wants to verify that the context pointer is a valid
object */
_cogl_context_object_new (context);
/* XXX: Gross hack!
* Currently everything in Cogl just assumes there is a default
* context which it can access via _COGL_GET_CONTEXT() including
@ -380,12 +385,11 @@ cogl_context_new (CoglDisplay *display,
_cogl_matrix_stack_init_cache (&_context->builtin_flushed_modelview);
default_texture_bitmap =
_cogl_bitmap_new_from_data (default_texture_data,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
1, 1, /* width/height */
4, /* rowstride */
NULL, /* destroy function */
NULL /* destroy function data */);
cogl_bitmap_new_for_data (_context,
1, 1, /* width/height */
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
4, /* rowstride */
default_texture_data);
/* Create default textures used for fall backs */
context->default_gl_texture_2d_tex =
@ -430,7 +434,7 @@ cogl_context_new (CoglDisplay *display,
cogl_has_feature (context, COGL_FEATURE_ID_POINT_SPRITE))
GE (context, glEnable (GL_POINT_SPRITE));
return _cogl_context_object_new (context);
return context;
}
static void