[mutter] renderer/native: Create dummy offscreens if onscreens fail to allocate



commit ceff2a93ca2f5f66d236fe99863519d6662f6c20
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Sat Apr 10 21:29:22 2021 +0200

    renderer/native: Create dummy offscreens if onscreens fail to allocate
    
    This is less dramatic than aborting, and could in theory be a temporary
    issue, so handle it by rendering into an offscreen.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1828>

 src/backends/native/meta-renderer-native.c | 46 ++++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 6 deletions(-)
---
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
index 7e4af8fe0c..ee58429698 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -1007,6 +1007,29 @@ should_force_shadow_fb (MetaRendererNative *renderer_native,
   return FALSE;
 }
 
+static CoglFramebuffer *
+create_fallback_offscreen (MetaRendererNative *renderer_native,
+                           CoglContext        *cogl_context,
+                           int                 width,
+                           int                 height)
+{
+  CoglOffscreen *fallback_offscreen;
+  GError *error = NULL;
+
+  fallback_offscreen = meta_renderer_native_create_offscreen (renderer_native,
+                                                              cogl_context,
+                                                              width,
+                                                              height,
+                                                              &error);
+  if (!fallback_offscreen)
+    {
+      g_error ("Failed to create fallback offscreen framebuffer: %s",
+               error->message);
+    }
+
+  return COGL_FRAMEBUFFER (fallback_offscreen);
+}
+
 static MetaRendererView *
 meta_renderer_native_create_view (MetaRenderer       *renderer,
                                   MetaLogicalMonitor *logical_monitor,
@@ -1041,10 +1064,12 @@ meta_renderer_native_create_view (MetaRenderer       *renderer,
 
   if (META_IS_CRTC_KMS (crtc))
     {
+      MetaGpuKms *gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (crtc));
+      MetaGpuKms *primary_gpu_kms = renderer_native->primary_gpu_kms;
       MetaOnscreenNative *onscreen_native;
 
       onscreen_native = meta_onscreen_native_new (renderer_native,
-                                                  renderer_native->primary_gpu_kms,
+                                                  primary_gpu_kms,
                                                   output,
                                                   crtc,
                                                   cogl_context,
@@ -1052,11 +1077,20 @@ meta_renderer_native_create_view (MetaRenderer       *renderer,
                                                   onscreen_height);
 
       if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (onscreen_native), &error))
-        g_error ("Failed to allocate onscreen framebuffer: %s", error->message);
-
-      use_shadowfb = should_force_shadow_fb (renderer_native,
-                                             renderer_native->primary_gpu_kms);
-      framebuffer = COGL_FRAMEBUFFER (onscreen_native);
+        {
+          g_warning ("Failed to allocate onscreen framebuffer for %s",
+                     meta_gpu_kms_get_file_path (gpu_kms));
+          framebuffer = create_fallback_offscreen (renderer_native,
+                                                   cogl_context,
+                                                   onscreen_width,
+                                                   onscreen_height);
+        }
+      else
+        {
+          use_shadowfb = should_force_shadow_fb (renderer_native,
+                                                 primary_gpu_kms);
+          framebuffer = COGL_FRAMEBUFFER (onscreen_native);
+        }
     }
   else
     {


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