cursor-renderer/native: Use MetaCrtcNative API to check capabilities

The cursor renderer shouldn't assume all the CRTCs of a logical are KMS
CRTC's, as we'll end up checking hardware capabilities for CRTC's of
virtual monitors as well, when they were created to not embed the cursor
image directly in the framebuffer.

Instead, use the newly introduced API for checking CRTC cursor
capabilities. This fixes a crash with the following backtrace:

 0) get_plane_with_type_for at ../src/backends/native/meta-kms-device.c:150
 1) meta_kms_device_get_cursor_plane_for at ../src/backends/native/meta-kms-device.c:173
 2) has_cursor_plane at ../src/backends/native/meta-cursor-renderer-native.c:678
 3) foreach_crtc at ../src/backends/meta-logical-monitor.c:247
 4) meta_monitor_mode_foreach_crtc at ../src/backends/meta-monitor.c:1920
 5) meta_logical_monitor_foreach_crtc at ../src/backends/meta-logical-monitor.c:274
 6) crtcs_has_cursor_planes at ../src/backends/native/meta-cursor-renderer-native.c:718
 7) should_have_hw_cursor at ../src/backends/native/meta-cursor-renderer-native.c:881
 8) meta_cursor_renderer_native_update_cursor at ../src/backends/native/meta-cursor-renderer-native.c:1085
 9) meta_cursor_renderer_update_cursor at ../src/backends/meta-cursor-renderer.c:411

Related: https://bugzilla.redhat.com/show_bug.cgi?id=2000183
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1991>
This commit is contained in:
Jonas Ådahl 2021-09-06 10:42:32 +02:00 committed by Marge Bot
parent e82685d049
commit 00c329a2e5

View File

@ -666,24 +666,21 @@ get_current_relative_transform (MetaCursorSprite *cursor_sprite)
} }
static void static void
has_cursor_plane (MetaLogicalMonitor *logical_monitor, crtc_supports_hw_cursor (MetaLogicalMonitor *logical_monitor,
MetaMonitor *monitor, MetaMonitor *monitor,
MetaOutput *output, MetaOutput *output,
MetaCrtc *crtc, MetaCrtc *crtc,
gpointer user_data) gpointer user_data)
{ {
gboolean *has_cursor_planes = user_data; gboolean *supports_hw_cursor = user_data;
MetaCrtcKms *crtc_kms = META_CRTC_KMS (crtc); MetaCrtcNative *crtc_native = META_CRTC_NATIVE (crtc);
MetaKmsCrtc *kms_crtc = meta_crtc_kms_get_kms_crtc (crtc_kms);
MetaKmsDevice *kms_device = meta_kms_crtc_get_device (kms_crtc);
*has_cursor_planes &= !!meta_kms_device_get_cursor_plane_for (kms_device, *supports_hw_cursor &= meta_crtc_native_is_hw_cursor_supported (crtc_native);
kms_crtc);
} }
static gboolean static gboolean
crtcs_has_cursor_planes (MetaCursorRenderer *renderer, crtcs_supports_hw_cursor (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite) MetaCursorSprite *cursor_sprite)
{ {
MetaCursorRendererNative *cursor_renderer_native = MetaCursorRendererNative *cursor_renderer_native =
META_CURSOR_RENDERER_NATIVE (renderer); META_CURSOR_RENDERER_NATIVE (renderer);
@ -705,7 +702,7 @@ crtcs_has_cursor_planes (MetaCursorRenderer *renderer,
MetaLogicalMonitor *logical_monitor = l->data; MetaLogicalMonitor *logical_monitor = l->data;
MetaRectangle logical_monitor_layout; MetaRectangle logical_monitor_layout;
graphene_rect_t logical_monitor_rect; graphene_rect_t logical_monitor_rect;
gboolean has_cursor_planes; gboolean supports_hw_cursor;
logical_monitor_layout = logical_monitor_layout =
meta_logical_monitor_get_layout (logical_monitor); meta_logical_monitor_get_layout (logical_monitor);
@ -716,11 +713,11 @@ crtcs_has_cursor_planes (MetaCursorRenderer *renderer,
NULL)) NULL))
continue; continue;
has_cursor_planes = TRUE; supports_hw_cursor = TRUE;
meta_logical_monitor_foreach_crtc (logical_monitor, meta_logical_monitor_foreach_crtc (logical_monitor,
has_cursor_plane, crtc_supports_hw_cursor,
&has_cursor_planes); &supports_hw_cursor);
if (!has_cursor_planes) if (!supports_hw_cursor)
return FALSE; return FALSE;
} }
@ -880,7 +877,7 @@ should_have_hw_cursor (MetaCursorRenderer *renderer,
return FALSE; return FALSE;
} }
if (!crtcs_has_cursor_planes (renderer, cursor_sprite)) if (!crtcs_supports_hw_cursor (renderer, cursor_sprite))
return FALSE; return FALSE;
texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite); texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);