From 2d1623313c6163d552bea00567a0fcaf702e87d9 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Tue, 20 Mar 2012 13:53:50 +0000 Subject: [PATCH] bitmap-pixbuf: Fix the CoglBitmap wrapper for the STB fallback The fallback code using stb-image.c was missed out in the upgrade to cogl_bitmap_new_for_data from commit d18b59d9e6 so it wouldn't compile. Reviewed-by: Robert Bragg --- cogl/cogl-bitmap-pixbuf.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cogl/cogl-bitmap-pixbuf.c b/cogl/cogl-bitmap-pixbuf.c index ada8e54d1..025a940e1 100644 --- a/cogl/cogl-bitmap-pixbuf.c +++ b/cogl/cogl-bitmap-pixbuf.c @@ -268,12 +268,15 @@ CoglBitmap * _cogl_bitmap_from_file (const char *filename, GError **error) { + static CoglUserDataKey bitmap_data_key; CoglBitmap *bmp; int stb_pixel_format; int width; int height; guint8 *pixels; + _COGL_GET_CONTEXT (ctx, NULL); + _COGL_RETURN_VAL_IF_FAIL (error == NULL || *error == NULL, FALSE); /* Load from file using stb */ @@ -284,14 +287,14 @@ _cogl_bitmap_from_file (const char *filename, return FALSE; /* Store bitmap info */ - bmp = _cogl_bitmap_new_from_data (g_memdup (pixels, height * width * 4), - COGL_PIXEL_FORMAT_RGBA_8888, - width, height, - width * 4, - (CoglBitmapDestroyNotify) g_free, - NULL); - - free (pixels); + bmp = cogl_bitmap_new_for_data (ctx, + width, height, + COGL_PIXEL_FORMAT_RGBA_8888, + width * 4, /* rowstride */ + pixels); + /* Register a destroy function so the pixel data will be freed + automatically when the bitmap object is destroyed */ + cogl_object_set_user_data (COGL_OBJECT (bmp), &bitmap_data_key, pixels, free); return bmp; }