From 898d62bad9f43b7437e357eb92aa163f0850d193 Mon Sep 17 00:00:00 2001 From: loki Date: Fri, 13 Aug 2021 16:09:05 +0200 Subject: [PATCH] Filter out cursors from drm planes --- sunshine/platform/linux/kmsgrab.cpp | 37 +++++++++++++++++++++++++---- sunshine/platform/linux/x11grab.cpp | 16 ------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/sunshine/platform/linux/kmsgrab.cpp b/sunshine/platform/linux/kmsgrab.cpp index 4180c815..8848d862 100644 --- a/sunshine/platform/linux/kmsgrab.cpp +++ b/sunshine/platform/linux/kmsgrab.cpp @@ -103,10 +103,14 @@ public: } if(drmSetClientCap(fd.el, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1)) { - BOOST_LOG(error) << "Couldn't expose some/all drm planes"sv; + BOOST_LOG(error) << "Couldn't expose some/all drm planes for card: "sv << path; return -1; } + if(drmSetClientCap(fd.el, DRM_CLIENT_CAP_ATOMIC, 1)) { + BOOST_LOG(warning) << "Couldn't expose some properties for card: "sv << path; + } + plane_res.reset(drmModeGetPlaneResources(fd.el)); if(!plane_res) { BOOST_LOG(error) << "Couldn't get drm plane resources"sv; @@ -257,6 +261,24 @@ public: auto end = std::end(card); for(auto plane = std::begin(card); plane != end; ++plane) { + bool cursor; + auto props = card.plane_props(plane->plane_id); + for(auto &[prop, val] : props) { + if(prop->name == "type"sv) { + BOOST_LOG(verbose) << prop->name << "::"sv << kms::plane_type(val); + + if(val == DRM_PLANE_TYPE_CURSOR) { + // Don't count as a monitor when it is a cursor + cursor = true; + break; + } + } + } + + if(cursor) { + continue; + } + if(monitor != monitor_index) { ++monitor; continue; @@ -581,12 +603,17 @@ std::vector kms_display_names() { break; } + bool cursor = false; { - BOOST_LOG(verbose) << "PLANE INFO"sv; - auto props = card.plane_props(card.plane_res->planes[count]); + BOOST_LOG(verbose) << "PLANE INFO ["sv << count << ']'; + auto props = card.plane_props(plane->plane_id); for(auto &[prop, val] : props) { if(prop->name == "type"sv) { BOOST_LOG(verbose) << prop->name << "::"sv << kms::plane_type(val); + + if(val == DRM_PLANE_TYPE_CURSOR) { + cursor = true; + } } else { BOOST_LOG(verbose) << prop->name << "::"sv << val; @@ -620,7 +647,9 @@ std::vector kms_display_names() { kms::print(plane.get(), fb.get(), crtc.get()); - display_names.emplace_back(std::to_string(count++)); + if(!cursor) { + display_names.emplace_back(std::to_string(count++)); + } } } diff --git a/sunshine/platform/linux/x11grab.cpp b/sunshine/platform/linux/x11grab.cpp index a8f9eb34..d10cfa88 100644 --- a/sunshine/platform/linux/x11grab.cpp +++ b/sunshine/platform/linux/x11grab.cpp @@ -57,22 +57,6 @@ _FN(Free, int, (void *data)); _FN(InitThreads, Status, (void)); namespace rr { -using Mode = XID; -using Output = XID; - -struct CrtcInfo { - Time timestamp; - int x, y; - unsigned int width, height; - Mode mode; - Rotation rotation; - int noutput; - Output *outputs; - Rotation rotations; - int npossible; - Output *possible; -}; - _FN(GetScreenResources, XRRScreenResources *, (Display * dpy, Window window)); _FN(GetOutputInfo, XRROutputInfo *, (Display * dpy, XRRScreenResources *resources, RROutput output)); _FN(GetCrtcInfo, XRRCrtcInfo *, (Display * dpy, XRRScreenResources *resources, RRCrtc crtc));