[cogl] When internally using an FBO, check for allocation errors



commit ec1bb4ce39ea0103fa0d1d408ca325922fdb7131
Author: Neil Roberts <neil linux intel com>
Date:   Mon Feb 6 12:23:39 2012 +0000

    When internally using an FBO, check for allocation errors
    
    Both the cogl_texture_get_data and _cogl_blit_begin implementations
    will internally try to create an FBO for a texture and have fallbacks
    if the FBO fails. However neither of them were catching errors when
    allocating the framebuffer so the fallback wouldn't work properly.
    This patch just adds an explicit call to cogl_framebuffer_allocate for
    these uses and causes it to use the next fallback if it fails.
    
    Based on a patch by Adel Gadllah.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=669368
    
    Reviewed-by: Robert Bragg <robert linux intel com>

 cogl/cogl-blit.c    |   50 ++++++++++++++++++++++++++++++++++++++------------
 cogl/cogl-texture.c |    6 ++++++
 2 files changed, 44 insertions(+), 12 deletions(-)
---
diff --git a/cogl/cogl-blit.c b/cogl/cogl-blit.c
index e65a5b0..2ab1445 100644
--- a/cogl/cogl-blit.c
+++ b/cogl/cogl-blit.c
@@ -55,6 +55,12 @@ _cogl_blit_texture_render_begin (CoglBlitData *data)
   if (fbo == COGL_INVALID_HANDLE)
     return FALSE;
 
+  if (!cogl_framebuffer_allocate (fbo, NULL))
+    {
+      cogl_handle_unref (fbo);
+      return FALSE;
+    }
+
   cogl_push_framebuffer (fbo);
   cogl_handle_unref (fbo);
 
@@ -141,6 +147,7 @@ static gboolean
 _cogl_blit_framebuffer_begin (CoglBlitData *data)
 {
   CoglHandle dst_fbo, src_fbo;
+  gboolean ret;
 
   _COGL_GET_CONTEXT (ctx, FALSE);
 
@@ -155,22 +162,35 @@ _cogl_blit_framebuffer_begin (CoglBlitData *data)
     (data->dst_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */);
 
   if (dst_fbo == COGL_INVALID_HANDLE)
-    return FALSE;
+    ret = FALSE;
+  else
+    {
+      if (!cogl_framebuffer_allocate (dst_fbo, NULL))
+        ret = FALSE;
+      else
+        {
+          src_fbo = _cogl_offscreen_new_to_texture_full
+            (data->src_tex,
+             COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL,
+             0 /* level */);
+
+          if (src_fbo == COGL_INVALID_HANDLE)
+            ret = FALSE;
+          else
+            {
+              if (!cogl_framebuffer_allocate (src_fbo, NULL))
+                ret = FALSE;
+              else
+                _cogl_push_framebuffers (dst_fbo, src_fbo);
 
-  src_fbo = _cogl_offscreen_new_to_texture_full
-    (data->src_tex, COGL_OFFSCREEN_DISABLE_DEPTH_AND_STENCIL, 0 /* level */);
+              cogl_handle_unref (src_fbo);
+            }
+        }
 
-  if (src_fbo == COGL_INVALID_HANDLE)
-    {
       cogl_handle_unref (dst_fbo);
-      return FALSE;
     }
 
-  _cogl_push_framebuffers (dst_fbo, src_fbo);
-  cogl_handle_unref (src_fbo);
-  cogl_handle_unref (dst_fbo);
-
-  return TRUE;
+  return ret;
 }
 
 static void
@@ -210,6 +230,12 @@ _cogl_blit_copy_tex_sub_image_begin (CoglBlitData *data)
   if (fbo == COGL_INVALID_HANDLE)
     return FALSE;
 
+  if (!cogl_framebuffer_allocate (fbo, NULL))
+    {
+      cogl_handle_unref (fbo);
+      return FALSE;
+    }
+
   cogl_push_framebuffer (fbo);
   cogl_handle_unref (fbo);
 
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index d75f6c1..d957a94 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -1026,6 +1026,12 @@ get_texture_bits_via_offscreen (CoglTexture    *texture,
   if (framebuffer == NULL)
     return FALSE;
 
+  if (!cogl_framebuffer_allocate (framebuffer, NULL))
+    {
+      cogl_object_unref (framebuffer);
+      return FALSE;
+    }
+
   cogl_push_framebuffer (framebuffer);
 
   _cogl_read_pixels_with_rowstride (x, y, width, height,



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