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



commit d959af49d3b1664a3133368687edadb08000e0aa
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>
    
    (cherry picked from commit ec1bb4ce39ea0103fa0d1d408ca325922fdb7131)

 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 2cf3cda..238f57b 100644
--- a/cogl/cogl-blit.c
+++ b/cogl/cogl-blit.c
@@ -54,6 +54,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);
 
@@ -140,6 +146,7 @@ static gboolean
 _cogl_blit_framebuffer_begin (CoglBlitData *data)
 {
   CoglHandle dst_fbo, src_fbo;
+  gboolean ret;
 
   _COGL_GET_CONTEXT (ctx, FALSE);
 
@@ -154,22 +161,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
@@ -209,6 +229,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 4904fea..10912f3 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -1213,6 +1213,12 @@ get_texture_bits_via_offscreen (CoglHandle      texture_handle,
   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]