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>
This commit is contained in:
Jonas Ådahl 2021-11-15 14:27:54 +01:00 committed by Marge Bot
parent ada524265f
commit 4159c76a5b
4 changed files with 51 additions and 0 deletions

View File

@ -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);
}

View File

@ -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 */

View File

@ -51,6 +51,7 @@ typedef struct _MetaRendererNativeGpuData
MetaRendererNative *renderer_native;
MetaRenderDevice *render_device;
MetaGpuKms *gpu_kms;
MetaRendererNativeMode mode;

View File

@ -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;
}