[cogl/cogl-1.14: 80/174] bitmap: ret CoglError from _new_with_malloc_buffer



commit da9f5e61799fad575ecca2ca55fe3f1fcd30620a
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>
    
    (cherry picked from commit 67cad9c0eb5e2650b75aff16abde49f23aabd0cc)

 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 15500ab..14f5511 100644
--- a/cogl/cogl-bitmap-conversion.c
+++ b/cogl/cogl-bitmap-conversion.c
@@ -488,7 +488,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 5114694..6dd0ffd 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 81c4b2e..f8c2e0a 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -1613,7 +1613,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 25426c3..385f7c2 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -659,7 +659,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,
@@ -787,7 +790,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,
@@ -1112,9 +1122,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 945bc2b..576de99 100644
--- a/cogl/driver/gl/gles/cogl-texture-driver-gles.c
+++ b/cogl/driver/gl/gles/cogl-texture-driver-gles.c
@@ -205,7 +205,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,
@@ -387,7 +391,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]