From cfd3676e96ba6933e326490a5bc58d511f2d3fc3 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Tue, 24 May 2022 12:04:10 +0200 Subject: [PATCH] backends/x11: Restore dedicated XRenderUtils::init function Under kwin_wayland `kwinApp()->connection()` is for communicating with XWayland, but in X11Windowed backend we need to talk to the host XServer. Restore `XRenderUtils::init` and set it accordingly based on whether we're running standalone or windowed, so that `kwin_wayland` works running nested in an X session again. Signed-off-by: Victoria Fischer Tested-by: Merge Service Part-of: --- src/backends/x11/common/kwinxrenderutils.cpp | 32 +++++++++++++++---- src/backends/x11/common/kwinxrenderutils.h | 10 ++++++ src/backends/x11/standalone/x11_platform.cpp | 6 ++++ .../x11/windowed/x11windowed_backend.cpp | 1 + 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/backends/x11/common/kwinxrenderutils.cpp b/src/backends/x11/common/kwinxrenderutils.cpp index 6dd533a9f1..1b069e199c 100644 --- a/src/backends/x11/common/kwinxrenderutils.cpp +++ b/src/backends/x11/common/kwinxrenderutils.cpp @@ -11,7 +11,6 @@ #include "kwinxrenderutils.h" #include "logging_p.h" -#include "main.h" #include #include @@ -19,12 +18,31 @@ namespace KWin { +namespace XRenderUtils +{ +static xcb_connection_t *s_connection = nullptr; +static xcb_window_t s_rootWindow = XCB_WINDOW_NONE; + +void init(xcb_connection_t *connection, xcb_window_t rootWindow) +{ + s_connection = connection; + s_rootWindow = rootWindow; +} + +void cleanup() +{ + s_connection = nullptr; + s_rootWindow = XCB_WINDOW_NONE; +} + +} // namespace + static xcb_render_picture_t createPicture(xcb_pixmap_t pix, int depth) { if (pix == XCB_PIXMAP_NONE) { return XCB_RENDER_PICTURE_NONE; } - xcb_connection_t *c = kwinApp()->x11Connection(); + xcb_connection_t *c = XRenderUtils::s_connection; static QHash s_renderFormats; if (!s_renderFormats.contains(depth)) { xcb_render_query_pict_formats_reply_t *formats = xcb_render_query_pict_formats_reply(c, xcb_render_query_pict_formats_unchecked(c), nullptr); @@ -58,10 +76,10 @@ XRenderPicture::XRenderPicture(const QImage &img) void XRenderPicture::fromImage(const QImage &img) { - xcb_connection_t *c = kwinApp()->x11Connection(); + xcb_connection_t *c = XRenderUtils::s_connection; const int depth = img.depth(); xcb_pixmap_t xpix = xcb_generate_id(c); - xcb_create_pixmap(c, depth, xpix, kwinApp()->x11RootWindow(), img.width(), img.height()); + xcb_create_pixmap(c, depth, xpix, XRenderUtils::s_rootWindow, img.width(), img.height()); xcb_gcontext_t cid = xcb_generate_id(c); xcb_create_gc(c, cid, xpix, 0, nullptr); @@ -82,7 +100,7 @@ XRenderPictureData::~XRenderPictureData() { if (picture != XCB_RENDER_PICTURE_NONE) { Q_ASSERT(qApp); - xcb_render_free_picture(kwinApp()->x11Connection(), picture); + xcb_render_free_picture(XRenderUtils::s_connection, picture); } } @@ -94,8 +112,8 @@ struct PictFormatData PictFormatData() { // Fetch the render pict formats - reply = xcb_render_query_pict_formats_reply(kwinApp()->x11Connection(), - xcb_render_query_pict_formats_unchecked(kwinApp()->x11Connection()), nullptr); + reply = xcb_render_query_pict_formats_reply(s_connection, + xcb_render_query_pict_formats_unchecked(s_connection), nullptr); // Init the visual ID -> format ID hash table for (auto screens = xcb_render_query_pict_formats_screens_iterator(reply); screens.rem; xcb_render_pictscreen_next(&screens)) { diff --git a/src/backends/x11/common/kwinxrenderutils.h b/src/backends/x11/common/kwinxrenderutils.h index 258586f55f..9e96d9f47c 100644 --- a/src/backends/x11/common/kwinxrenderutils.h +++ b/src/backends/x11/common/kwinxrenderutils.h @@ -83,6 +83,11 @@ inline XRenderPicture::operator xcb_render_picture_t() namespace XRenderUtils { +/** + * @internal + */ +KWIN_EXPORT void init(xcb_connection_t *connection, xcb_window_t rootWindow); + /** * Returns the Xrender format that corresponds to the given visual ID. */ @@ -93,6 +98,11 @@ KWIN_EXPORT xcb_render_pictformat_t findPictFormat(xcb_visualid_t visual); */ KWIN_EXPORT const xcb_render_directformat_t *findPictFormatInfo(xcb_render_pictformat_t format); +/** + * @internal + */ +KWIN_EXPORT void cleanup(); + } // namespace XRenderUtils } // namespace KWin diff --git a/src/backends/x11/standalone/x11_platform.cpp b/src/backends/x11/standalone/x11_platform.cpp index 9a26c3cf29..89f8e9d4ff 100644 --- a/src/backends/x11/standalone/x11_platform.cpp +++ b/src/backends/x11/standalone/x11_platform.cpp @@ -36,6 +36,8 @@ #include "workspace.h" #include "x11_output.h" +#include "kwinxrenderutils.h" + #include #include #include @@ -129,6 +131,9 @@ X11StandalonePlatform::~X11StandalonePlatform() if (sceneEglDisplay() != EGL_NO_DISPLAY) { eglTerminate(sceneEglDisplay()); } + if (isReady()) { + XRenderUtils::cleanup(); + } } bool X11StandalonePlatform::initialize() @@ -136,6 +141,7 @@ bool X11StandalonePlatform::initialize() if (!QX11Info::isPlatformX11()) { return false; } + XRenderUtils::init(kwinApp()->x11Connection(), kwinApp()->x11RootWindow()); setReady(true); initOutputs(); diff --git a/src/backends/x11/windowed/x11windowed_backend.cpp b/src/backends/x11/windowed/x11windowed_backend.cpp index 612c52db93..fd86731c41 100644 --- a/src/backends/x11/windowed/x11windowed_backend.cpp +++ b/src/backends/x11/windowed/x11windowed_backend.cpp @@ -210,6 +210,7 @@ bool X11WindowedBackend::initialize() } } initXInput(); + XRenderUtils::init(m_connection, m_screen->root); createOutputs(); connect(kwinApp(), &Application::workspaceCreated, this, &X11WindowedBackend::startEventReading); connect(Cursors::self(), &Cursors::currentCursorChanged, this, [this]() {