[mutter] cursor-renderer/native: Clear GPU state before closing device



commit 4159c76a5b5b0fd0dfff8c9ba6b8269aedaebfec
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Mon Nov 15 14:27:54 2021 +0100

    cursor-renderer/native: Clear GPU state before closing device
    
    This ensures we don't have any left over cursor GPU buffers (via
    gbm_bo's) after destroying the corresponding gbm_device (owned by
    MetaRenderDevice).
    
    Fixes crashes with backtraces such as
    
      1) meta_drm_buffer_gbm_finalize at ../src/backends/native/meta-drm-buffer-gbm.c:450
      4) invalidate_cursor_gpu_state at ../src/backends/native/meta-cursor-renderer-native.c:1167
      9) update_cursor_sprite_texture at ../src/wayland/meta-wayland-cursor-surface.c:70
     10) meta_wayland_surface_role_apply_state at ../src/wayland/meta-wayland-surface.c:1869
     11) meta_wayland_surface_apply_state at ../src/wayland/meta-wayland-surface.c:832
     12) meta_wayland_surface_commit at ../src/wayland/meta-wayland-surface.c:993
     13) wl_surface_commit at ../src/wayland/meta-wayland-surface.c:1158
     14) ffi_call_unix64 at ../src/x86/unix64.S:76
     15) ffi_call at ../src/x86/ffi64.c:525
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2147>

 src/backends/native/meta-cursor-renderer-native.c  | 14 ++++++++++
 src/backends/native/meta-cursor-renderer-native.h  |  5 ++++
 src/backends/native/meta-renderer-native-private.h |  1 +
 src/backends/native/meta-renderer-native.c         | 31 ++++++++++++++++++++++
 4 files changed, 51 insertions(+)
---
diff --git a/src/backends/native/meta-cursor-renderer-native.c 
b/src/backends/native/meta-cursor-renderer-native.c
index 8a1a6d6446..df5862c4c0 100644
--- a/src/backends/native/meta-cursor-renderer-native.c
+++ b/src/backends/native/meta-cursor-renderer-native.c
@@ -1886,3 +1886,17 @@ static void
 meta_cursor_renderer_native_init (MetaCursorRendererNative *native)
 {
 }
+
+void
+meta_cursor_renderer_native_invalidate_gpu_state (MetaCursorRendererNative *native,
+                                                  MetaCursorSprite         *cursor_sprite,
+                                                  MetaGpuKms               *gpu_kms)
+{
+  MetaCursorNativePrivate *cursor_priv;
+
+  cursor_priv = get_cursor_priv (cursor_sprite);
+  if (!cursor_priv)
+    return;
+
+  g_hash_table_remove (cursor_priv->gpu_states, gpu_kms);
+}
diff --git a/src/backends/native/meta-cursor-renderer-native.h 
b/src/backends/native/meta-cursor-renderer-native.h
index 5113b96ce1..72b7b3c35f 100644
--- a/src/backends/native/meta-cursor-renderer-native.h
+++ b/src/backends/native/meta-cursor-renderer-native.h
@@ -26,6 +26,7 @@
 #define META_CURSOR_RENDERER_NATIVE_H
 
 #include "backends/meta-cursor-renderer.h"
+#include "backends/native/meta-backend-native-types.h"
 #include "meta/meta-backend.h"
 
 #define META_TYPE_CURSOR_RENDERER_NATIVE (meta_cursor_renderer_native_get_type ())
@@ -39,4 +40,8 @@ void meta_cursor_renderer_native_prepare_frame (MetaCursorRendererNative *cursor
 MetaCursorRendererNative * meta_cursor_renderer_native_new (MetaBackend        *backend,
                                                             ClutterInputDevice *device);
 
+void meta_cursor_renderer_native_invalidate_gpu_state (MetaCursorRendererNative *native,
+                                                       MetaCursorSprite         *cursor_sprite,
+                                                       MetaGpuKms               *gpu_kms);
+
 #endif /* META_CURSOR_RENDERER_NATIVE_H */
diff --git a/src/backends/native/meta-renderer-native-private.h 
b/src/backends/native/meta-renderer-native-private.h
index 0364fd779f..e2e133bd96 100644
--- a/src/backends/native/meta-renderer-native-private.h
+++ b/src/backends/native/meta-renderer-native-private.h
@@ -51,6 +51,7 @@ typedef struct _MetaRendererNativeGpuData
   MetaRendererNative *renderer_native;
 
   MetaRenderDevice *render_device;
+  MetaGpuKms *gpu_kms;
 
   MetaRendererNativeMode mode;
 
diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c
index 4bcd00cb4c..440b33c0d6 100644
--- a/src/backends/native/meta-renderer-native.c
+++ b/src/backends/native/meta-renderer-native.c
@@ -46,9 +46,11 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "backends/meta-cursor-tracker-private.h"
 #include "backends/meta-gles3.h"
 #include "backends/meta-logical-monitor.h"
 #include "backends/native/meta-backend-native-private.h"
+#include "backends/native/meta-cursor-renderer-native.h"
 #include "backends/native/meta-cogl-utils.h"
 #include "backends/native/meta-crtc-kms.h"
 #include "backends/native/meta-crtc-virtual.h"
@@ -125,6 +127,12 @@ meta_get_renderer_native_parent_vtable (void)
 static void
 meta_renderer_native_gpu_data_free (MetaRendererNativeGpuData *renderer_gpu_data)
 {
+  MetaRenderer *renderer = META_RENDERER (renderer_gpu_data->renderer_native);
+  MetaBackend *backend = meta_renderer_get_backend (renderer);
+  MetaCursorRenderer *cursor_renderer;
+  MetaGpuKms *gpu_kms;
+  GList *l;
+
   if (renderer_gpu_data->secondary.egl_context != EGL_NO_CONTEXT)
     {
       MetaRenderDevice *render_device = renderer_gpu_data->render_device;
@@ -139,6 +147,27 @@ meta_renderer_native_gpu_data_free (MetaRendererNativeGpuData *renderer_gpu_data
                                 NULL);
     }
 
+  cursor_renderer = meta_backend_get_cursor_renderer (backend);
+  gpu_kms = renderer_gpu_data->gpu_kms;
+  if (cursor_renderer && gpu_kms)
+    {
+      MetaCursorRendererNative *cursor_renderer_native =
+        META_CURSOR_RENDERER_NATIVE (cursor_renderer);
+      MetaCursorTracker *cursor_tracker =
+        meta_backend_get_cursor_tracker (backend);
+      GList *cursor_sprites =
+        meta_cursor_tracker_peek_cursor_sprites (cursor_tracker);
+
+      for (l = cursor_sprites; l; l = l->next)
+        {
+          MetaCursorSprite *cursor_sprite = META_CURSOR_SPRITE (l->data);
+
+          meta_cursor_renderer_native_invalidate_gpu_state (cursor_renderer_native,
+                                                            cursor_sprite,
+                                                            gpu_kms);
+        }
+    }
+
   g_clear_pointer (&renderer_gpu_data->render_device, g_object_unref);
   g_free (renderer_gpu_data);
 }
@@ -1599,6 +1628,7 @@ create_renderer_gpu_data_gbm (MetaRendererNative  *renderer_native,
   renderer_gpu_data->renderer_native = renderer_native;
   renderer_gpu_data->mode = META_RENDERER_NATIVE_MODE_GBM;
   renderer_gpu_data->render_device = META_RENDER_DEVICE (render_device_gbm);
+  renderer_gpu_data->gpu_kms = gpu_kms;
 
   init_secondary_gpu_data (renderer_gpu_data);
   return renderer_gpu_data;
@@ -1650,6 +1680,7 @@ create_renderer_gpu_data_egl_device (MetaRendererNative  *renderer_native,
   renderer_gpu_data->mode = META_RENDERER_NATIVE_MODE_EGL_DEVICE;
   renderer_gpu_data->render_device =
     META_RENDER_DEVICE (render_device_egl_stream);
+  renderer_gpu_data->gpu_kms = gpu_kms;
 
   return renderer_gpu_data;
 }


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