From 2fd00d80b22dadfebfc927be0d153972575f9151 Mon Sep 17 00:00:00 2001 From: Jerry Date: Sun, 16 Jul 2023 10:43:22 +0800 Subject: [PATCH] refine cursor capture --- drm.c | 17 ++++++++++++++--- kmsvnc.c | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/drm.c b/drm.c index 3ed39b9..8ddb63f 100644 --- a/drm.c +++ b/drm.c @@ -251,6 +251,10 @@ static int drm_refresh_planes(char first_time) { } if (!drm->plane || (kmsvnc->capture_cursor && !drm->cursor_plane)) { drmModePlane *current_plane = NULL; + if (drm->plane_res) { + drmModeFreePlaneResources(kmsvnc->drm->plane_res); + drm->plane_res = NULL; + } drm->plane_res = drmModeGetPlaneResources(drm->drm_fd); if (!drm->plane_res) KMSVNC_FATAL("Failed to get plane resources: %s\n", strerror(errno)); @@ -336,11 +340,18 @@ static int drm_refresh_planes(char first_time) { int drm_dump_cursor_plane(char **data, int *width, int *height) { struct kmsvnc_drm_data *drm = kmsvnc->drm; - if (drm->cursor_plane) { + if (!drm->cursor_plane) { + drm_refresh_planes(0); // ignore error + if (drm->cursor_plane) { + printf("Using cursor plane %u\n", drm->cursor_plane->plane_id); + } + } + else { + uint32_t plane_id = drm->cursor_plane->plane_id; drmModeFreePlane(drm->cursor_plane); drm->cursor_plane = NULL; + drm->cursor_plane = drmModeGetPlane(drm->drm_fd, plane_id); } - drm_refresh_planes(0); // ignore error if (!drm->cursor_plane) { data = NULL; return 1; @@ -351,7 +362,7 @@ int drm_dump_cursor_plane(char **data, int *width, int *height) { KMSVNC_DEBUG("Cursor framebuffer missing\n"); return 1; } - + if (drm->cursor_mfb->modifier != DRM_FORMAT_MOD_NONE && drm->cursor_mfb->modifier != DRM_FORMAT_MOD_LINEAR) { //kmsvnc->capture_cursor = 0; KMSVNC_DEBUG("Cursor plane modifier is not linear: %lu\n", drm->cursor_mfb->modifier); diff --git a/kmsvnc.c b/kmsvnc.c index c1af49b..17504ba 100644 --- a/kmsvnc.c +++ b/kmsvnc.c @@ -230,7 +230,7 @@ static struct argp_option kmsvnc_main_options[] = { {"fps", 0xff00, "30", 0, "Target frames per second"}, {"disable-always-shared", 0xff01, 0, OPTION_ARG_OPTIONAL, "Do not always treat incoming connections as shared"}, {"disable-compare-fb", 0xff02, 0, OPTION_ARG_OPTIONAL, "Do not compare pixels"}, - {"capture-cursor", 'c', 0, OPTION_ARG_OPTIONAL, "Do not capture cursor fb"}, + {"capture-cursor", 'c', 0, OPTION_ARG_OPTIONAL, "Capture mouse cursor"}, {"capture-raw-fb", 0xff03, "/tmp/rawfb.bin", 0, "Capture RAW framebuffer instead of starting the vnc server (for debugging)"}, {"va-derive", 0xff04, "off", 0, "Enable derive with vaapi"}, {"debug", 0xff05, 0, OPTION_ARG_OPTIONAL, "Print debug message"},