Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -348,6 +348,7 @@ ${CMAKE_CURRENT_SOURCE_DIR}/libkwineffects ${CMAKE_CURRENT_SOURCE_DIR}/effects ${CMAKE_CURRENT_SOURCE_DIR}/tabbox + ${CMAKE_CURRENT_SOURCE_DIR}/platformsupport ) add_subdirectory( libkwineffects ) @@ -411,7 +412,6 @@ unmanaged.cpp scene.cpp scene_opengl.cpp - scene_qpainter.cpp screenlockerwatcher.cpp thumbnailitem.cpp lanczosfilter.cpp @@ -623,6 +623,7 @@ install(TARGETS kwin_wayland ${INSTALL_TARGETS_DEFAULT_ARGS} ) +add_subdirectory(platformsupport) add_subdirectory(plugins) ########### install files ############### Index: autotests/integration/effects/fade_test.cpp =================================================================== --- autotests/integration/effects/fade_test.cpp +++ autotests/integration/effects/fade_test.cpp @@ -23,7 +23,6 @@ #include "effectloader.h" #include "cursor.h" #include "platform.h" -#include "scene_qpainter.h" #include "shell_client.h" #include "wayland_server.h" #include "workspace.h" Index: autotests/integration/effects/slidingpopups_test.cpp =================================================================== --- autotests/integration/effects/slidingpopups_test.cpp +++ autotests/integration/effects/slidingpopups_test.cpp @@ -23,7 +23,6 @@ #include "effectloader.h" #include "cursor.h" #include "platform.h" -#include "scene_qpainter.h" #include "shell_client.h" #include "wayland_server.h" #include "workspace.h" Index: autotests/integration/effects/translucency_test.cpp =================================================================== --- autotests/integration/effects/translucency_test.cpp +++ autotests/integration/effects/translucency_test.cpp @@ -23,7 +23,6 @@ #include "effectloader.h" #include "cursor.h" #include "platform.h" -#include "scene_qpainter.h" #include "shell_client.h" #include "wayland_server.h" #include "workspace.h" Index: autotests/integration/scene_qpainter_test.cpp =================================================================== --- autotests/integration/scene_qpainter_test.cpp +++ autotests/integration/scene_qpainter_test.cpp @@ -22,8 +22,8 @@ #include "effectloader.h" #include "client.h" #include "cursor.h" +#include "effects.h" #include "platform.h" -#include "scene_qpainter.h" #include "shell_client.h" #include "wayland_server.h" #include "effect_builtins.h" @@ -101,7 +101,7 @@ { // this test verifies that the initial rendering is correct Compositor::self()->addRepaintFull(); - auto scene = qobject_cast(Compositor::self()->scene()); + auto scene = Compositor::self()->scene(); QVERIFY(scene); QSignalSpy frameRenderedSpy(scene, &Scene::frameRendered); QVERIFY(frameRenderedSpy.isValid()); @@ -113,13 +113,13 @@ const QImage cursorImage = kwinApp()->platform()->softwareCursor(); QVERIFY(!cursorImage.isNull()); p.drawImage(KWin::Cursor::pos() - kwinApp()->platform()->softwareCursorHotspot(), cursorImage); - QCOMPARE(referenceImage, *scene->backend()->buffer()); + QCOMPARE(referenceImage, *scene->qpainterRenderBuffer()); } void SceneQPainterTest::testCursorMoving() { // this test verifies that rendering is correct also after moving the cursor a few times - auto scene = qobject_cast(Compositor::self()->scene()); + auto scene = Compositor::self()->scene(); QVERIFY(scene); QSignalSpy frameRenderedSpy(scene, &Scene::frameRendered); QVERIFY(frameRenderedSpy.isValid()); @@ -142,7 +142,7 @@ const QImage cursorImage = kwinApp()->platform()->softwareCursor(); QVERIFY(!cursorImage.isNull()); p.drawImage(QPoint(45, 45) - kwinApp()->platform()->softwareCursorHotspot(), cursorImage); - QCOMPARE(referenceImage, *scene->backend()->buffer()); + QCOMPARE(referenceImage, *scene->qpainterRenderBuffer()); } void SceneQPainterTest::testWindow_data() @@ -165,7 +165,7 @@ QScopedPointer ss(Test::createShellSurface(type, s.data())); QScopedPointer p(Test::waylandSeat()->createPointer()); - auto scene = qobject_cast(KWin::Compositor::self()->scene()); + auto scene = KWin::Compositor::self()->scene(); QVERIFY(scene); QSignalSpy frameRenderedSpy(scene, &Scene::frameRendered); QVERIFY(frameRenderedSpy.isValid()); @@ -181,22 +181,22 @@ referenceImage.fill(Qt::black); QPainter painter(&referenceImage); painter.fillRect(0, 0, 200, 300, Qt::blue); - QCOMPARE(referenceImage, *scene->backend()->buffer()); + QCOMPARE(referenceImage, *scene->qpainterRenderBuffer()); // now let's set a cursor image QScopedPointer cs(Test::createSurface()); QVERIFY(!cs.isNull()); Test::render(cs.data(), QSize(10, 10), Qt::red); p->setCursor(cs.data(), QPoint(5, 5)); QVERIFY(frameRenderedSpy.wait()); painter.fillRect(KWin::Cursor::pos().x() - 5, KWin::Cursor::pos().y() - 5, 10, 10, Qt::red); - QCOMPARE(referenceImage, *scene->backend()->buffer()); + QCOMPARE(referenceImage, *scene->qpainterRenderBuffer()); // let's move the cursor again KWin::Cursor::setPos(10, 10); QVERIFY(frameRenderedSpy.wait()); painter.fillRect(0, 0, 200, 300, Qt::blue); painter.fillRect(5, 5, 10, 10, Qt::red); - QCOMPARE(referenceImage, *scene->backend()->buffer()); + QCOMPARE(referenceImage, *scene->qpainterRenderBuffer()); } void SceneQPainterTest::testWindowScaled() @@ -210,7 +210,7 @@ QScopedPointer ss(Test::createShellSurface(s.data())); QScopedPointer p(Test::waylandSeat()->createPointer()); - auto scene = qobject_cast(KWin::Compositor::self()->scene()); + auto scene = KWin::Compositor::self()->scene(); QVERIFY(scene); QSignalSpy frameRenderedSpy(scene, &Scene::frameRendered); QVERIFY(frameRenderedSpy.isValid()); @@ -246,7 +246,7 @@ painter.fillRect(100, 150, 100, 100, Qt::red); painter.fillRect(5, 5, 10, 10, Qt::red); //cursor - QCOMPARE(referenceImage, *scene->backend()->buffer()); + QCOMPARE(referenceImage, *scene->qpainterRenderBuffer()); } void SceneQPainterTest::testCompositorRestart_data() @@ -280,7 +280,7 @@ QVERIFY(sceneCreatedSpy.wait()); } QCOMPARE(sceneCreatedSpy.count(), 1); - auto scene = qobject_cast(KWin::Compositor::self()->scene()); + auto scene = KWin::Compositor::self()->scene(); QVERIFY(scene); // this should directly trigger a frame @@ -297,7 +297,7 @@ const QImage cursorImage = kwinApp()->platform()->softwareCursor(); QVERIFY(!cursorImage.isNull()); painter.drawImage(QPoint(400, 400) - kwinApp()->platform()->softwareCursorHotspot(), cursorImage); - QCOMPARE(referenceImage, *scene->backend()->buffer()); + QCOMPARE(referenceImage, *scene->qpainterRenderBuffer()); } struct XcbConnectionDeleter @@ -361,7 +361,7 @@ // enough time for rendering the window QTest::qWait(100); - auto scene = qobject_cast(KWin::Compositor::self()->scene()); + auto scene = KWin::Compositor::self()->scene(); QVERIFY(scene); // this should directly trigger a frame @@ -371,7 +371,7 @@ QVERIFY(frameRenderedSpy.wait()); const QPoint startPos = client->pos() + client->clientPos(); - auto image = scene->backend()->buffer(); + auto image = scene->qpainterRenderBuffer(); QCOMPARE(image->copy(QRect(startPos, client->clientSize())), compareImage); // and destroy the window again Index: autotests/integration/x11_client_test.cpp =================================================================== --- autotests/integration/x11_client_test.cpp +++ autotests/integration/x11_client_test.cpp @@ -23,7 +23,6 @@ #include "effectloader.h" #include "cursor.h" #include "platform.h" -#include "scene_qpainter.h" #include "screens.h" #include "shell_client.h" #include "wayland_server.h" Index: composite.cpp =================================================================== --- composite.cpp +++ composite.cpp @@ -31,7 +31,6 @@ #include "overlaywindow.h" #include "scene.h" #include "scene_opengl.h" -#include "scene_qpainter.h" #include "screens.h" #include "shadow.h" #include "useractions.h" @@ -249,10 +248,6 @@ // Do not Fall back to XRender - it causes problems when selfcheck fails during startup, but works later on break; } - case QPainterCompositing: - qCDebug(KWIN_CORE) << "Initializing QPainter compositing"; - m_scene = SceneQPainter::createScene(this); - break; default: qCDebug(KWIN_CORE) << "No compositing enabled"; m_starting = false; Index: platformsupport/CMakeLists.txt =================================================================== --- /dev/null +++ platformsupport/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(scenes) Index: platformsupport/scenes/CMakeLists.txt =================================================================== --- /dev/null +++ platformsupport/scenes/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(qpainter) Index: platformsupport/scenes/qpainter/CMakeLists.txt =================================================================== --- /dev/null +++ platformsupport/scenes/qpainter/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(SceneQPainterBackend STATIC backend.cpp) +target_link_libraries(SceneQPainterBackend Qt5::Core) Index: platformsupport/scenes/qpainter/backend.h =================================================================== --- /dev/null +++ platformsupport/scenes/qpainter/backend.h @@ -0,0 +1,108 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2013 Martin Gräßlin + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*********************************************************************/ +#ifndef KWIN_SCENE_QPAINTER_BACKEND_H +#define KWIN_SCENE_QPAINTER_BACKEND_H + +class QImage; +class QRegion; +class QSize; +class QString; + +namespace KWin { +class OverlayWindow; + +class QPainterBackend +{ +public: + virtual ~QPainterBackend(); + virtual void present(int mask, const QRegion &damage) = 0; + + /** + * @brief Returns the OverlayWindow used by the backend. + * + * A backend does not have to use an OverlayWindow, this is mostly for the X world. + * In case the backend does not use an OverlayWindow it is allowed to return @c null. + * It's the task of the caller to check whether it is @c null. + * + * @return :OverlayWindow* + **/ + virtual OverlayWindow *overlayWindow(); + virtual bool usesOverlayWindow() const = 0; + virtual void prepareRenderingFrame() = 0; + /** + * @brief Shows the Overlay Window + * + * Default implementation does nothing. + */ + virtual void showOverlay(); + /** + * @brief React on screen geometry changes. + * + * Default implementation does nothing. Override if specific functionality is required. + * + * @param size The new screen size + */ + virtual void screenGeometryChanged(const QSize &size); + /** + * @brief Whether the creation of the Backend failed. + * + * The SceneQPainter should test whether the Backend got constructed correctly. If this method + * returns @c true, the SceneQPainter should not try to start the rendering. + * + * @return bool @c true if the creation of the Backend failed, @c false otherwise. + **/ + bool isFailed() const { + return m_failed; + } + + virtual QImage *buffer() = 0; + /** + * Overload for the case that there is a different buffer per screen. + * Default implementation just calls buffer. + * @param screenId The id of the screen as used in Screens + * @todo Get a better identifier for screen then a counter variable + **/ + virtual QImage *bufferForScreen(int screenId); + virtual bool needsFullRepaint() const = 0; + /** + * Whether the rendering needs to be split per screen. + * Default implementation returns @c false. + **/ + virtual bool perScreenRendering() const; + +protected: + QPainterBackend(); + /** + * @brief Sets the backend initialization to failed. + * + * This method should be called by the concrete subclass in case the initialization failed. + * The given @p reason is logged as a warning. + * + * @param reason The reason why the initialization failed. + **/ + void setFailed(const QString &reason); + +private: + bool m_failed; +}; + +} // KWin + +#endif Index: platformsupport/scenes/qpainter/backend.cpp =================================================================== --- platformsupport/scenes/qpainter/backend.cpp +++ platformsupport/scenes/qpainter/backend.cpp @@ -2,7 +2,7 @@ KWin - the KDE window manager This file is part of the KDE project. -Copyright (C) 2015 Martin Gräßlin +Copyright (C) 2013 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,35 +17,51 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ -#ifndef KWIN_SCENE_QPAINTER_FB_BACKEND_H -#define KWIN_SCENE_QPAINTER_FB_BACKEND_H -#include "scene_qpainter.h" +#include "backend.h" -#include +#include namespace KWin { -class FramebufferBackend; -class FramebufferQPainterBackend : public QObject, public QPainterBackend +QPainterBackend::QPainterBackend() + : m_failed(false) { - Q_OBJECT -public: - FramebufferQPainterBackend(FramebufferBackend *backend); - virtual ~FramebufferQPainterBackend(); +} - QImage *buffer() override; - bool needsFullRepaint() const override; - bool usesOverlayWindow() const override; - void prepareRenderingFrame() override; - void present(int mask, const QRegion &damage) override; +QPainterBackend::~QPainterBackend() +{ +} + +OverlayWindow* QPainterBackend::overlayWindow() +{ + return nullptr; +} -private: - QImage m_renderBuffer; - QImage m_backBuffer; - FramebufferBackend *m_backend; -}; +void QPainterBackend::showOverlay() +{ +} +void QPainterBackend::screenGeometryChanged(const QSize &size) +{ + Q_UNUSED(size) } -#endif +void QPainterBackend::setFailed(const QString &reason) +{ + Q_UNUSED(reason) + m_failed = true; +} + +bool QPainterBackend::perScreenRendering() const +{ + return false; +} + +QImage *QPainterBackend::bufferForScreen(int screenId) +{ + Q_UNUSED(screenId) + return buffer(); +} + +} Index: plugins/platforms/drm/CMakeLists.txt =================================================================== --- plugins/platforms/drm/CMakeLists.txt +++ plugins/platforms/drm/CMakeLists.txt @@ -17,7 +17,7 @@ endif() add_library(KWinWaylandDrmBackend MODULE ${DRM_SOURCES}) -target_link_libraries(KWinWaylandDrmBackend kwin Libdrm::Libdrm) +target_link_libraries(KWinWaylandDrmBackend kwin Libdrm::Libdrm SceneQPainterBackend) if(HAVE_GBM) target_link_libraries(KWinWaylandDrmBackend gbm::gbm) Index: plugins/platforms/drm/scene_qpainter_drm_backend.h =================================================================== --- plugins/platforms/drm/scene_qpainter_drm_backend.h +++ plugins/platforms/drm/scene_qpainter_drm_backend.h @@ -19,8 +19,9 @@ *********************************************************************/ #ifndef KWIN_SCENE_QPAINTER_DRM_BACKEND_H #define KWIN_SCENE_QPAINTER_DRM_BACKEND_H -#include "scene_qpainter.h" +#include #include +#include namespace KWin { Index: plugins/platforms/fbdev/CMakeLists.txt =================================================================== --- plugins/platforms/fbdev/CMakeLists.txt +++ plugins/platforms/fbdev/CMakeLists.txt @@ -5,7 +5,7 @@ ) add_library(KWinWaylandFbdevBackend MODULE ${FBDEV_SOURCES}) -target_link_libraries(KWinWaylandFbdevBackend kwin) +target_link_libraries(KWinWaylandFbdevBackend kwin SceneQPainterBackend) install( TARGETS Index: plugins/platforms/fbdev/scene_qpainter_fb_backend.h =================================================================== --- plugins/platforms/fbdev/scene_qpainter_fb_backend.h +++ plugins/platforms/fbdev/scene_qpainter_fb_backend.h @@ -19,9 +19,10 @@ *********************************************************************/ #ifndef KWIN_SCENE_QPAINTER_FB_BACKEND_H #define KWIN_SCENE_QPAINTER_FB_BACKEND_H -#include "scene_qpainter.h" +#include #include +#include namespace KWin { Index: plugins/platforms/virtual/CMakeLists.txt =================================================================== --- plugins/platforms/virtual/CMakeLists.txt +++ plugins/platforms/virtual/CMakeLists.txt @@ -9,7 +9,7 @@ ecm_qt_declare_logging_category(VIRTUAL_SOURCES HEADER logging.h IDENTIFIER KWIN_VIRTUAL CATEGORY_NAME kwin_platform_virtual DEFAULT_SEVERITY Critical) add_library(KWinWaylandVirtualBackend MODULE ${VIRTUAL_SOURCES}) -target_link_libraries(KWinWaylandVirtualBackend kwin) +target_link_libraries(KWinWaylandVirtualBackend kwin SceneQPainterBackend) if(HAVE_GBM) target_link_libraries(KWinWaylandVirtualBackend gbm::gbm) Index: plugins/platforms/virtual/scene_qpainter_virtual_backend.h =================================================================== --- plugins/platforms/virtual/scene_qpainter_virtual_backend.h +++ plugins/platforms/virtual/scene_qpainter_virtual_backend.h @@ -20,9 +20,10 @@ #ifndef KWIN_SCENE_QPAINTER_VIRTUAL_BACKEND_H #define KWIN_SCENE_QPAINTER_VIRTUAL_BACKEND_H -#include "scene_qpainter.h" +#include #include +#include namespace KWin { Index: plugins/platforms/wayland/CMakeLists.txt =================================================================== --- plugins/platforms/wayland/CMakeLists.txt +++ plugins/platforms/wayland/CMakeLists.txt @@ -9,7 +9,7 @@ endif() add_library(KWinWaylandWaylandBackend MODULE ${WAYLAND_BACKEND_SOURCES}) -target_link_libraries(KWinWaylandWaylandBackend kwin KF5::WaylandClient) +target_link_libraries(KWinWaylandWaylandBackend kwin KF5::WaylandClient SceneQPainterBackend) if(HAVE_WAYLAND_EGL) target_link_libraries(KWinWaylandWaylandBackend Wayland::Egl) Index: plugins/platforms/wayland/scene_qpainter_wayland_backend.h =================================================================== --- plugins/platforms/wayland/scene_qpainter_wayland_backend.h +++ plugins/platforms/wayland/scene_qpainter_wayland_backend.h @@ -20,9 +20,11 @@ #ifndef KWIN_SCENE_QPAINTER_WAYLAND_BACKEND_H #define KWIN_SCENE_QPAINTER_WAYLAND_BACKEND_H -#include "scene_qpainter.h" +#include #include +#include +#include namespace KWayland { Index: plugins/platforms/x11/windowed/CMakeLists.txt =================================================================== --- plugins/platforms/x11/windowed/CMakeLists.txt +++ plugins/platforms/x11/windowed/CMakeLists.txt @@ -6,7 +6,7 @@ ) add_library(KWinWaylandX11Backend MODULE ${X11BACKEND_SOURCES}) -target_link_libraries(KWinWaylandX11Backend eglx11common kwin X11::XCB) +target_link_libraries(KWinWaylandX11Backend eglx11common kwin X11::XCB SceneQPainterBackend) install( TARGETS Index: plugins/platforms/x11/windowed/scene_qpainter_x11_backend.h =================================================================== --- plugins/platforms/x11/windowed/scene_qpainter_x11_backend.h +++ plugins/platforms/x11/windowed/scene_qpainter_x11_backend.h @@ -20,9 +20,13 @@ #ifndef KWIN_SCENE_QPAINTER_X11_BACKEND_H #define KWIN_SCENE_QPAINTER_X11_BACKEND_H -#include "scene_qpainter.h" +#include #include +#include +#include + +#include namespace KWin { Index: plugins/scenes/CMakeLists.txt =================================================================== --- plugins/scenes/CMakeLists.txt +++ plugins/scenes/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(qpainter) if( KWIN_BUILD_XRENDER_COMPOSITING ) add_subdirectory(xrender) endif() Index: plugins/scenes/qpainter/CMakeLists.txt =================================================================== --- /dev/null +++ plugins/scenes/qpainter/CMakeLists.txt @@ -0,0 +1,14 @@ +set(SCENE_QPAINTER_SRCS scene_qpainter.cpp) + +add_library(KWinSceneQPainter MODULE scene_qpainter.cpp) +target_link_libraries(KWinSceneQPainter + kwin + SceneQPainterBackend +) + +install( + TARGETS + KWinSceneQPainter + DESTINATION + ${PLUGIN_INSTALL_DIR}/org.kde.kwin.scenes/ +) Index: plugins/scenes/qpainter/qpainter.json =================================================================== --- /dev/null +++ plugins/scenes/qpainter/qpainter.json @@ -0,0 +1,9 @@ +{ + "KPlugin": { + "Description": "KWin Compositor plugin rendering through QPainter", + "Id": "KWinSceneQPainter", + "Name": "SceneQPainter" + }, + "CompositingType": 4 +} + Index: plugins/scenes/qpainter/scene_qpainter.h =================================================================== --- plugins/scenes/qpainter/scene_qpainter.h +++ plugins/scenes/qpainter/scene_qpainter.h @@ -21,87 +21,13 @@ #define KWIN_SCENE_QPAINTER_H #include "scene.h" +#include #include "shadow.h" #include "decorations/decorationrenderer.h" namespace KWin { -class KWIN_EXPORT QPainterBackend -{ -public: - virtual ~QPainterBackend(); - virtual void present(int mask, const QRegion &damage) = 0; - - /** - * @brief Returns the OverlayWindow used by the backend. - * - * A backend does not have to use an OverlayWindow, this is mostly for the X world. - * In case the backend does not use an OverlayWindow it is allowed to return @c null. - * It's the task of the caller to check whether it is @c null. - * - * @return :OverlayWindow* - **/ - virtual OverlayWindow *overlayWindow(); - virtual bool usesOverlayWindow() const = 0; - virtual void prepareRenderingFrame() = 0; - /** - * @brief Shows the Overlay Window - * - * Default implementation does nothing. - */ - virtual void showOverlay(); - /** - * @brief React on screen geometry changes. - * - * Default implementation does nothing. Override if specific functionality is required. - * - * @param size The new screen size - */ - virtual void screenGeometryChanged(const QSize &size); - /** - * @brief Whether the creation of the Backend failed. - * - * The SceneQPainter should test whether the Backend got constructed correctly. If this method - * returns @c true, the SceneQPainter should not try to start the rendering. - * - * @return bool @c true if the creation of the Backend failed, @c false otherwise. - **/ - bool isFailed() const { - return m_failed; - } - - virtual QImage *buffer() = 0; - /** - * Overload for the case that there is a different buffer per screen. - * Default implementation just calls buffer. - * @param screenId The id of the screen as used in Screens - * @todo Get a better identifier for screen then a counter variable - **/ - virtual QImage *bufferForScreen(int screenId); - virtual bool needsFullRepaint() const = 0; - /** - * Whether the rendering needs to be split per screen. - * Default implementation returns @c false. - **/ - virtual bool perScreenRendering() const; - -protected: - QPainterBackend(); - /** - * @brief Sets the backend initialization to failed. - * - * This method should be called by the concrete subclass in case the initialization failed. - * The given @p reason is logged as a warning. - * - * @param reason The reason why the initialization failed. - **/ - void setFailed(const QString &reason); - -private: - bool m_failed; -}; - class KWIN_EXPORT SceneQPainter : public Scene { Q_OBJECT @@ -124,6 +50,7 @@ } QPainter *scenePainter() const override; + QImage *qpainterRenderBuffer() const override; QPainterBackend *backend() const { return m_backend.data(); @@ -239,6 +166,19 @@ QImage m_images[int(DecorationPart::Count)]; }; +class KWIN_EXPORT QPainterFactory : public SceneFactory +{ + Q_OBJECT + Q_INTERFACES(KWin::SceneFactory) + Q_PLUGIN_METADATA(IID "org.kde.kwin.Scene" FILE "qpainter.json") + +public: + explicit QPainterFactory(QObject *parent = nullptr); + ~QPainterFactory() override; + + Scene *create(QObject *parent = nullptr) const override; +}; + inline bool SceneQPainter::usesOverlayWindow() const { Index: plugins/scenes/qpainter/scene_qpainter.cpp =================================================================== --- plugins/scenes/qpainter/scene_qpainter.cpp +++ plugins/scenes/qpainter/scene_qpainter.cpp @@ -42,49 +42,6 @@ { //**************************************** -// QPainterBackend -//**************************************** -QPainterBackend::QPainterBackend() - : m_failed(false) -{ -} - -QPainterBackend::~QPainterBackend() -{ -} - -OverlayWindow* QPainterBackend::overlayWindow() -{ - return NULL; -} - -void QPainterBackend::showOverlay() -{ -} - -void QPainterBackend::screenGeometryChanged(const QSize &size) -{ - Q_UNUSED(size) -} - -void QPainterBackend::setFailed(const QString &reason) -{ - qCWarning(KWIN_CORE) << "Creating the XRender backend failed: " << reason; - m_failed = true; -} - -bool QPainterBackend::perScreenRendering() const -{ - return false; -} - -QImage *QPainterBackend::bufferForScreen(int screenId) -{ - Q_UNUSED(screenId) - return buffer(); -} - -//**************************************** // SceneQPainter //**************************************** SceneQPainter *SceneQPainter::createScene(QObject *parent) @@ -233,6 +190,11 @@ m_backend->screenGeometryChanged(size); } +QImage *SceneQPainter::qpainterRenderBuffer() const +{ + return m_backend->buffer(); +} + //**************************************** // SceneQPainter::Window //**************************************** @@ -683,4 +645,22 @@ Renderer::reparent(deleted); } + +QPainterFactory::QPainterFactory(QObject *parent) + : SceneFactory(parent) +{ +} + +QPainterFactory::~QPainterFactory() = default; + +Scene *QPainterFactory::create(QObject *parent) const +{ + auto s = SceneQPainter::createScene(parent); + if (s && s->initFailed()) { + delete s; + s = nullptr; + } + return s; +} + } // KWin Index: scene.h =================================================================== --- scene.h +++ scene.h @@ -169,6 +169,12 @@ **/ virtual QPainter *scenePainter() const; + /** + * The render buffer used by a QPainter based compositor. + * Default implementation returns @c nullptr. + **/ + virtual QImage *qpainterRenderBuffer() const; + Q_SIGNALS: void frameRendered(); Index: scene.cpp =================================================================== --- scene.cpp +++ scene.cpp @@ -662,6 +662,11 @@ return nullptr; } +QImage *Scene::qpainterRenderBuffer() const +{ + return nullptr; +} + //**************************************** // Scene::Window //****************************************