From 8397c12738b38a60b1a03c1ade81b3b4a98c6534 Mon Sep 17 00:00:00 2001 From: Oliver Bestmann Date: Tue, 10 Mar 2026 19:26:03 +0100 Subject: [PATCH] backend/native: move cursor to overlay plane. Overlay planes on apple hardware can not be exposed as cursor planes due to them having some limitations. Because of that, mutter is not able to take advantage of those planes to enable hardware compositing for the cursor. The most relevant restriction is that at least 32x32px of the overlay must be visible on the screen, otherwise the dcp crashes. This hack makes the drm overlay planes available as cursor planes. It then adds transparent padding to the cursor, so that the intersection between cursor and screen has always at least the required size. Signed-off-by: Oliver Bestmann --- .../native/meta-cursor-renderer-native.c | 30 ++++++++++++--- src/backends/native/meta-kms-impl-device.c | 6 ++- src/backends/native/meta-kms-plane.c | 38 +++++++++++++++++-- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/backends/native/meta-cursor-renderer-native.c b/src/backends/native/meta-cursor-renderer-native.c index 949f922d76..d5676ed322 100644 --- a/src/backends/native/meta-cursor-renderer-native.c +++ b/src/backends/native/meta-cursor-renderer-native.c @@ -779,6 +779,7 @@ scale_and_transform_cursor_sprite_cpu (MetaCursorRendererNative *cursor_renderer CoglPixelFormat dst_format, int dst_width, int dst_height, + int dst_padding, GError **error) { MetaCursorRendererNativePrivate *priv = @@ -791,6 +792,7 @@ scale_and_transform_cursor_sprite_cpu (MetaCursorRendererNative *cursor_renderer g_autoptr (CoglOffscreen) offscreen = NULL; g_autoptr (CoglPipeline) pipeline = NULL; ClutterColorState *color_state; + int min_size = dst_padding * 2 + 1; src_texture = cogl_texture_2d_new_from_data (cogl_context, width, height, @@ -801,7 +803,7 @@ scale_and_transform_cursor_sprite_cpu (MetaCursorRendererNative *cursor_renderer if (!src_texture) return NULL; - if (dst_width < 1 || dst_height < 1) + if (dst_width < min_size || dst_height < min_size) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid size for cursor texture %d x %d", @@ -809,6 +811,10 @@ scale_and_transform_cursor_sprite_cpu (MetaCursorRendererNative *cursor_renderer return NULL; } + /* Center the cursor within padded region */ + float dst_x = 1 - 2 * dst_padding / (float)(dst_width); + float dst_y = 1 - 2 * dst_padding / (float)(dst_height); + dst_texture = cogl_texture_2d_new_with_format (cogl_context, dst_width, dst_height, @@ -838,10 +844,10 @@ scale_and_transform_cursor_sprite_cpu (MetaCursorRendererNative *cursor_renderer 0.0f, 0.0f, 0.0f, 0.0f); cogl_framebuffer_draw_textured_rectangle (COGL_FRAMEBUFFER (offscreen), pipeline, - -1.0f, -1.0f, - 1.0f, 1.0f, - 0.0f, 1.0f, - 1.0f, 0.0f); + -dst_x, -dst_y, + dst_x, dst_y, + 0.0f, 1.0, + 1.0, 0.0f); return COGL_TEXTURE (g_steal_pointer (&dst_texture)); } @@ -968,11 +974,22 @@ load_scaled_and_transformed_cursor_sprite (MetaCursorRendererNative *native, &hot_x, &hot_y); hotspot = GRAPHENE_POINT_INIT (hot_x, hot_y); - if (width != crtc_dst_width || height != crtc_dst_height || + /* Cursor padding in pixels. To work around a limition of the apple dcp + * create a larger buffer and offset the cursor by the given amount. This + * ensures that the visible rectangle always stays within the limits. + */ + const int crtc_cursor_padding = 32; + + if (crtc_cursor_padding > 0 || width != crtc_dst_width || height != crtc_dst_height || !graphene_matrix_is_identity (&matrix) || gbm_format != cursor_renderer_gpu_data->drm_format || !clutter_color_state_equals (cursor_color_state, target_color_state)) { + crtc_dst_width += crtc_cursor_padding * 2; + crtc_dst_height += crtc_cursor_padding * 2; + hotspot.x += crtc_cursor_padding; + hotspot.y += crtc_cursor_padding; + const MetaFormatInfo *format_info; g_autoptr (GError) error = NULL; g_autoptr (CoglTexture) texture = NULL; @@ -996,6 +1013,7 @@ load_scaled_and_transformed_cursor_sprite (MetaCursorRendererNative *native, cursor_renderer_gpu_data->cogl_format, crtc_dst_width, crtc_dst_height, + crtc_cursor_padding, &error); if (!texture) { diff --git a/src/backends/native/meta-kms-impl-device.c b/src/backends/native/meta-kms-impl-device.c index 4a53915dea..544e9746ef 100644 --- a/src/backends/native/meta-kms-impl-device.c +++ b/src/backends/native/meta-kms-impl-device.c @@ -736,9 +736,11 @@ get_plane_type (MetaKmsImplDevice *impl_device, case DRM_PLANE_TYPE_PRIMARY: return META_KMS_PLANE_TYPE_PRIMARY; case DRM_PLANE_TYPE_CURSOR: - return META_KMS_PLANE_TYPE_CURSOR; case DRM_PLANE_TYPE_OVERLAY: - return META_KMS_PLANE_TYPE_OVERLAY; + /* HACK: Expose overlay plane as cursor. + * Not a problem, as overlay planes are not used by mutter anyways. + */ + return META_KMS_PLANE_TYPE_CURSOR; default: g_warning ("Unhandled plane type %" G_GUINT64_FORMAT, props->prop_values[idx]); diff --git a/src/backends/native/meta-kms-plane.c b/src/backends/native/meta-kms-plane.c index d8eef0a8bc..7fa8d25ab2 100644 --- a/src/backends/native/meta-kms-plane.c +++ b/src/backends/native/meta-kms-plane.c @@ -434,6 +434,31 @@ update_formats (MetaKmsPlane *plane, drmModeFreePropertyBlob (blob); } + +/* + * Fills the plane with a static size hint. This prevents mutter asking drm + * about DRM_CAP_CURSOR_WIDTH, which seems to default to a pretty small value of + * only 64px. + */ +static void +fake_cursor_size_hints (MetaKmsPlane *plane) { + plane->size_hints.has_size_hints = TRUE; + + plane->size_hints.cursor_width = g_new0(uint64_t, 4); + plane->size_hints.cursor_width[0] = 64 + 32; + plane->size_hints.cursor_width[1] = 64 + 48; + plane->size_hints.cursor_width[2] = 64 + 64; + plane->size_hints.cursor_width[3] = 64 + 92; + + plane->size_hints.cursor_height = g_new0(uint64_t, 4); + plane->size_hints.cursor_height[0] = 64 + 32; + plane->size_hints.cursor_height[1] = 64 + 48; + plane->size_hints.cursor_height[2] = 64 + 64; + plane->size_hints.cursor_height[3] = 64 + 92; + + plane->size_hints.num_of_size_hints = 4; +} + static void update_cursor_size_hints (MetaKmsPlane *plane, MetaKmsImplDevice *impl_device) @@ -448,18 +473,25 @@ update_cursor_size_hints (MetaKmsPlane *plane, if (type != META_KMS_PLANE_TYPE_CURSOR) return; + prop = &plane->prop_table.props[META_KMS_PLANE_PROP_SIZE_HINTS]; - if(!prop) + if (!prop) { + fake_cursor_size_hints(plane); return; + } blob_id = prop->value; - if (blob_id == 0) + if (blob_id == 0) { + fake_cursor_size_hints(plane); return; + } fd = meta_kms_impl_device_get_fd (impl_device); size_hints_blob = drmModeGetPropertyBlob (fd, blob_id); - if (!size_hints_blob) + if (!size_hints_blob) { + fake_cursor_size_hints(plane); return; + } plane->size_hints.has_size_hints = TRUE; size_hints_ptr = size_hints_blob->data; -- 2.53.0