[cogl] bitmap-pixbuf: Fix the CoglBitmap wrapper for the STB fallback



commit 2d1623313c6163d552bea00567a0fcaf702e87d9
Author: Neil Roberts <neil linux intel com>
Date:   Tue Mar 20 13:53:50 2012 +0000

    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 <robert linux intel com>

 cogl/cogl-bitmap-pixbuf.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)
---
diff --git a/cogl/cogl-bitmap-pixbuf.c b/cogl/cogl-bitmap-pixbuf.c
index ada8e54..025a940 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;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]