[cogl] bitmap: ret CoglError from _new_with_malloc_buffer



commit 67cad9c0eb5e2650b75aff16abde49f23aabd0cc
Author: Robert Bragg <robert linux intel com>
Date:   Thu Nov 8 22:14:18 2012 +0000

    bitmap: ret CoglError from _new_with_malloc_buffer
    
    _cogl_bitmap_new_with_malloc_buffer() now takes a CoglError for throwing
    exceptional errors and all callers have been updated to pass through
    any application error pointer as appropriate.
    
    Reviewed-by: Neil Roberts <neil linux intel com>

 cogl/cogl-bitmap-conversion.c                  |    5 +++-
 cogl/cogl-bitmap-private.h                     |    4 ++-
 cogl/cogl-bitmap.c                             |   19 +++++++++++++--
 cogl/cogl-framebuffer.c                        |    6 ++++-
 cogl/cogl-texture-3d.c                         |    5 +++-
 cogl/cogl-texture.c                            |   28 +++++++++++++++++++----
 cogl/driver/gl/gles/cogl-texture-driver-gles.c |   11 +++++++-
 7 files changed, 64 insertions(+), 14 deletions(-)
---
diff --git a/cogl/cogl-bitmap-conversion.c b/cogl/cogl-bitmap-conversion.c
index 3ce8c71..ccc32cd 100644
--- a/cogl/cogl-bitmap-conversion.c
+++ b/cogl/cogl-bitmap-conversion.c
@@ -487,7 +487,10 @@ _cogl_bitmap_convert (CoglBitmap *src_bmp,
 
   dst_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
                                                  width, height,
-                                                 dst_format);
+                                                 dst_format,
+                                                 error);
+  if (!dst_bmp)
+    return NULL;
 
   if (!_cogl_bitmap_convert_into_bitmap (src_bmp, dst_bmp, error))
     {
diff --git a/cogl/cogl-bitmap-private.h b/cogl/cogl-bitmap-private.h
index ac1fd4b..ae96aaf 100644
--- a/cogl/cogl-bitmap-private.h
+++ b/cogl/cogl-bitmap-private.h
@@ -69,6 +69,7 @@ struct _CoglBitmap
  * @width: width of the bitmap in pixels
  * @height: height of the bitmap in pixels
  * @format: the format of the pixels the array will store
+ * @error: A #CoglError for catching exceptional errors or %NULL
  *
  * This is equivalent to cogl_bitmap_new_with_size() except that it
  * allocated the buffer using g_malloc() instead of creating a
@@ -84,7 +85,8 @@ CoglBitmap *
 _cogl_bitmap_new_with_malloc_buffer (CoglContext *context,
                                      unsigned int width,
                                      unsigned int height,
-                                     CoglPixelFormat format);
+                                     CoglPixelFormat format,
+                                     CoglError **error);
 
 /* The idea of this function is that it will create a bitmap that
    shares the actual data with another bitmap. This is needed for the
diff --git a/cogl/cogl-bitmap.c b/cogl/cogl-bitmap.c
index 0e2c394..f5497c4 100644
--- a/cogl/cogl-bitmap.c
+++ b/cogl/cogl-bitmap.c
@@ -89,7 +89,10 @@ _cogl_bitmap_copy (CoglBitmap *src_bmp,
   dst_bmp =
     _cogl_bitmap_new_with_malloc_buffer (src_bmp->context,
                                          width, height,
-                                         src_format);
+                                         src_format,
+                                         error);
+  if (!dst_bmp)
+    return NULL;
 
   if (!_cogl_bitmap_copy_subregion (src_bmp,
                                     dst_bmp,
@@ -194,14 +197,24 @@ CoglBitmap *
 _cogl_bitmap_new_with_malloc_buffer (CoglContext *context,
                                      unsigned int width,
                                      unsigned int height,
-                                     CoglPixelFormat format)
+                                     CoglPixelFormat format,
+                                     CoglError **error)
 {
   static CoglUserDataKey bitmap_free_key;
   int bpp = _cogl_pixel_format_get_bytes_per_pixel (format);
   int rowstride = ((width * bpp) + 3) & ~3;
-  uint8_t *data = g_malloc (rowstride * height);
+  uint8_t *data = g_try_malloc (rowstride * height);
   CoglBitmap *bitmap;
 
+  if (!data)
+    {
+      _cogl_set_error (error,
+                       COGL_SYSTEM_ERROR,
+                       COGL_SYSTEM_ERROR_NO_MEMORY,
+                       "Failed to allocate memory for bitmap");
+      return NULL;
+    }
+
   bitmap = cogl_bitmap_new_for_data (context,
                                      width, height,
                                      format,
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index f0a41c0..41c3bfa 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -1597,7 +1597,11 @@ cogl_framebuffer_read_pixels_into_bitmap (CoglFramebuffer *framebuffer,
 
       tmp_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
                                                      width, height,
-                                                     read_format);
+                                                     read_format,
+                                                     error);
+      if (!tmp_bmp)
+        goto EXIT;
+
       bpp = _cogl_pixel_format_get_bytes_per_pixel (read_format);
       rowstride = cogl_bitmap_get_rowstride (tmp_bmp);
 
diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c
index c901c6a..0b3fa81 100644
--- a/cogl/cogl-texture-3d.c
+++ b/cogl/cogl-texture-3d.c
@@ -405,7 +405,10 @@ cogl_texture_3d_new_from_data (CoglContext *context,
       bitmap = _cogl_bitmap_new_with_malloc_buffer (context,
                                                     width,
                                                     depth * height,
-                                                    format);
+                                                    format,
+                                                    error);
+      if (!bitmap)
+        return NULL;
 
       bmp_data = _cogl_bitmap_map (bitmap,
                                    COGL_BUFFER_ACCESS_WRITE,
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index 04f362d..fc7f63e 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -550,7 +550,10 @@ do_texture_draw_and_read (CoglFramebuffer *fb,
           rect_bmp = _cogl_bitmap_new_with_malloc_buffer
                                               (ctx,
                                                width, height,
-                                               COGL_PIXEL_FORMAT_RGBA_8888_PRE);
+                                               COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+                                               error);
+          if (!rect_bmp)
+            return FALSE;
 
           if (!cogl_framebuffer_read_pixels_into_bitmap
                                                (fb,
@@ -678,7 +681,14 @@ _cogl_texture_draw_and_read (CoglTexture *texture,
         _cogl_bitmap_new_with_malloc_buffer (ctx,
                                              target_width,
                                              target_height,
-                                             COGL_PIXEL_FORMAT_RGBA_8888);
+                                             COGL_PIXEL_FORMAT_RGBA_8888,
+                                             error);
+      if (!alpha_bmp)
+        {
+          _cogl_bitmap_unmap (target_bmp);
+          goto EXIT;
+        }
+
 
       /* Draw alpha values into RGB channels */
       cogl_pipeline_set_layer_combine (ctx->texture_download_pipeline,
@@ -1003,9 +1013,17 @@ cogl_texture_get_data (CoglTexture *texture,
                                            rowstride,
                                            data);
   else
-    target_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
-                                                      tex_width, tex_height,
-                                                      closest_format);
+    {
+      target_bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
+                                                        tex_width, tex_height,
+                                                        closest_format,
+                                                        &ignore_error);
+      if (!target_bmp)
+        {
+          cogl_error_free (ignore_error);
+          return 0;
+        }
+    }
 
   tg_data.target_bits = _cogl_bitmap_map (target_bmp, COGL_BUFFER_ACCESS_WRITE,
                                           COGL_BUFFER_MAP_HINT_DISCARD,
diff --git a/cogl/driver/gl/gles/cogl-texture-driver-gles.c b/cogl/driver/gl/gles/cogl-texture-driver-gles.c
index 6a9d064..7b17ef8 100644
--- a/cogl/driver/gl/gles/cogl-texture-driver-gles.c
+++ b/cogl/driver/gl/gles/cogl-texture-driver-gles.c
@@ -204,7 +204,11 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
       slice_bmp =
         _cogl_bitmap_new_with_malloc_buffer (ctx,
                                              width, height,
-                                             source_format);
+                                             source_format,
+                                             error);
+      if (!slice_bmp)
+        return FALSE;
+
       if (!_cogl_bitmap_copy_subregion (source_bmp,
                                         slice_bmp,
                                         src_x, src_y,
@@ -386,7 +390,10 @@ _cogl_texture_driver_upload_to_gl_3d (CoglContext *ctx,
       bmp = _cogl_bitmap_new_with_malloc_buffer (ctx,
                                                  bmp_width,
                                                  height,
-                                                 source_bmp_format);
+                                                 source_bmp_format,
+                                                 error);
+      if (!bmp)
+        return FALSE;
 
       for (i = 0; i < depth; i++)
         {



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