Git commit 23ef40e638095a6bcd1eb30dd0bb2756df83be3e by Martin Fl=C3=B6ser. Committed on 01/09/2017 at 15:49. Pushed by graesslin into branch 'master'. Move the X11 Decoration Renderer into the X11 standalone platform Summary: Not needed except for X11/non-composited usage, so should be in the plugin instead of core. Platform API is extended to create a decoration renderer. Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D7444 M +2 -6 decorations/decoratedclient.cpp M +0 -75 decorations/decorationrenderer.cpp M +0 -21 decorations/decorationrenderer.h M +8 -0 platform.cpp M +13 -0 platform.h M +1 -0 plugins/platforms/x11/standalone/CMakeLists.txt C +2 -49 plugins/platforms/x11/standalone/x11_decoration_renderer.cpp= [from: decorations/decorationrenderer.cpp - 070% similarity] C +3 -55 plugins/platforms/x11/standalone/x11_decoration_renderer.h [= from: decorations/decorationrenderer.h - 052% similarity] M +10 -0 plugins/platforms/x11/standalone/x11_platform.cpp M +1 -0 plugins/platforms/x11/standalone/x11_platform.h https://commits.kde.org/kwin/23ef40e638095a6bcd1eb30dd0bb2756df83be3e diff --git a/decorations/decoratedclient.cpp b/decorations/decoratedclient.= cpp index 8ba6c6c9a..ff5ce64d4 100644 --- a/decorations/decoratedclient.cpp +++ b/decorations/decoratedclient.cpp @@ -24,7 +24,7 @@ along with this program. If not, see . #include "composite.h" #include "cursor.h" #include "options.h" -#include "scene.h" +#include "platform.h" #include "workspace.h" = #include @@ -290,11 +290,7 @@ bool DecoratedClientImpl::isApplicationMenuActive() co= nst = void DecoratedClientImpl::createRenderer() { - if (Compositor::self()->hasScene()) { - m_renderer =3D Compositor::self()->scene()->createDecorationRender= er(this); - } else { - m_renderer =3D new X11Renderer(this); - } + m_renderer =3D kwinApp()->platform()->createDecorationRenderer(this); } = void DecoratedClientImpl::destroyRenderer() diff --git a/decorations/decorationrenderer.cpp b/decorations/decorationren= derer.cpp index 5c281e634..420c2476c 100644 --- a/decorations/decorationrenderer.cpp +++ b/decorations/decorationrenderer.cpp @@ -19,17 +19,13 @@ along with this program. If not, see . *********************************************************************/ #include "decorationrenderer.h" #include "decoratedclient.h" -#include "client.h" #include "deleted.h" = -#include - #include #include = #include #include -#include = namespace KWin { @@ -81,76 +77,5 @@ void Renderer::reparent(Deleted *deleted) m_client =3D nullptr; } = -X11Renderer::X11Renderer(DecoratedClientImpl *client) - : Renderer(client) - , m_scheduleTimer(new QTimer(this)) - , m_gc(XCB_NONE) -{ - // delay any rendering to end of event cycle to catch multiple updates= per cycle - m_scheduleTimer->setSingleShot(true); - m_scheduleTimer->setInterval(0); - connect(m_scheduleTimer, &QTimer::timeout, this, &X11Renderer::render); - connect(this, &Renderer::renderScheduled, m_scheduleTimer, static_cast= (&QTimer::start)); -} - -X11Renderer::~X11Renderer() -{ - if (m_gc !=3D XCB_NONE) { - xcb_free_gc(connection(), m_gc); - } -} - -void X11Renderer::reparent(Deleted *deleted) -{ - if (m_scheduleTimer->isActive()) { - m_scheduleTimer->stop(); - } - disconnect(m_scheduleTimer, &QTimer::timeout, this, &X11Renderer::rend= er); - disconnect(this, &Renderer::renderScheduled, m_scheduleTimer, static_c= ast(&QTimer::start)); - Renderer::reparent(deleted); -} - -void X11Renderer::render() -{ - if (!client()) { - return; - } - const QRegion scheduled =3D getScheduled(); - if (scheduled.isEmpty()) { - return; - } - xcb_connection_t *c =3D connection(); - if (m_gc =3D=3D XCB_NONE) { - m_gc =3D xcb_generate_id(c); - xcb_create_gc(c, m_gc, client()->client()->frameId(), 0, nullptr); - } - - QRect left, top, right, bottom; - client()->client()->layoutDecorationRects(left, top, right, bottom); - - const QRect geometry =3D scheduled.boundingRect(); - left =3D left.intersected(geometry); - top =3D top.intersected(geometry); - right =3D right.intersected(geometry); - bottom =3D bottom.intersected(geometry); - - auto renderPart =3D [this, c](const QRect &geo) { - if (geo.isNull()) { - return; - } - QImage image =3D renderToImage(geo); - xcb_put_image(c, XCB_IMAGE_FORMAT_Z_PIXMAP, client()->client()->fr= ameId(), m_gc, - image.width(), image.height(), geo.x(), geo.y(), 0, = client()->client()->depth(), - image.byteCount(), image.constBits()); - }; - renderPart(left); - renderPart(top); - renderPart(right); - renderPart(bottom); - - xcb_flush(c); - resetImageSizesDirty(); -} - } } diff --git a/decorations/decorationrenderer.h b/decorations/decorationrende= rer.h index 17d184bda..417bf849f 100644 --- a/decorations/decorationrenderer.h +++ b/decorations/decorationrenderer.h @@ -23,12 +23,8 @@ along with this program. If not, see . #include #include = -#include - #include = -class QTimer; - namespace KWin { = @@ -84,23 +80,6 @@ private: bool m_imageSizesDirty; }; = -class X11Renderer : public Renderer -{ - Q_OBJECT -public: - explicit X11Renderer(DecoratedClientImpl *client); - virtual ~X11Renderer(); - - void reparent(Deleted *deleted) override; - -protected: - void render() override; - -private: - QTimer *m_scheduleTimer; - xcb_gcontext_t m_gc; -}; - } } = diff --git a/platform.cpp b/platform.cpp index d9ac03206..8400d4b09 100644 --- a/platform.cpp +++ b/platform.cpp @@ -479,4 +479,12 @@ OutlineVisual *Platform::createOutline(Outline *outlin= e) return nullptr; } = +Decoration::Renderer *Platform::createDecorationRenderer(Decoration::Decor= atedClientImpl *client) +{ + if (Compositor::self()->hasScene()) { + Compositor::self()->scene()->createDecorationRenderer(client); + } + return nullptr; +} + } diff --git a/platform.h b/platform.h index 80b5072a1..5c55480c5 100644 --- a/platform.h +++ b/platform.h @@ -50,6 +50,12 @@ class ScreenEdges; class Toplevel; class WaylandCursorTheme; = +namespace Decoration +{ +class Renderer; +class DecoratedClientImpl; +} + class KWIN_EXPORT Platform : public QObject { Q_OBJECT @@ -325,6 +331,13 @@ public: **/ virtual OutlineVisual *createOutline(Outline *outline); = + /** + * Creates the Decoration::Renderer for the given @p client. + * + * The default implementation creates a Renderer suited for the Compos= itor, @c nullptr if there is no Compositor. + **/ + virtual Decoration::Renderer *createDecorationRenderer(Decoration::Dec= oratedClientImpl *client); + public Q_SLOTS: void pointerMotion(const QPointF &position, quint32 time); void pointerButtonPressed(quint32 button, quint32 time); diff --git a/plugins/platforms/x11/standalone/CMakeLists.txt b/plugins/plat= forms/x11/standalone/CMakeLists.txt index 1f398bc6f..20bab3f5a 100644 --- a/plugins/platforms/x11/standalone/CMakeLists.txt +++ b/plugins/platforms/x11/standalone/CMakeLists.txt @@ -8,6 +8,7 @@ set(X11PLATFORM_SOURCES overlaywindow_x11.cpp screenedges_filter.cpp non_composited_outline.cpp + x11_decoration_renderer.cpp ) = if(X11_Xinput_FOUND) diff --git a/decorations/decorationrenderer.cpp b/plugins/platforms/x11/sta= ndalone/x11_decoration_renderer.cpp similarity index 70% copy from decorations/decorationrenderer.cpp copy to plugins/platforms/x11/standalone/x11_decoration_renderer.cpp index 5c281e634..d8b49544a 100644 --- a/decorations/decorationrenderer.cpp +++ b/plugins/platforms/x11/standalone/x11_decoration_renderer.cpp @@ -17,8 +17,8 @@ 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 . *********************************************************************/ -#include "decorationrenderer.h" -#include "decoratedclient.h" +#include "x11_decoration_renderer.h" +#include "decorations/decoratedclient.h" #include "client.h" #include "deleted.h" = @@ -27,8 +27,6 @@ along with this program. If not, see . #include #include = -#include -#include #include = namespace KWin @@ -36,51 +34,6 @@ namespace KWin namespace Decoration { = -Renderer::Renderer(DecoratedClientImpl *client) - : QObject(client) - , m_client(client) - , m_imageSizesDirty(true) -{ - auto markImageSizesDirty =3D [this]{ m_imageSizesDirty =3D true; }; - connect(client->decoration(), &KDecoration2::Decoration::bordersChange= d, this, markImageSizesDirty); - connect(client->decoratedClient(), &KDecoration2::DecoratedClient::wid= thChanged, this, markImageSizesDirty); - connect(client->decoratedClient(), &KDecoration2::DecoratedClient::hei= ghtChanged, this, markImageSizesDirty); -} - -Renderer::~Renderer() =3D default; - -void Renderer::schedule(const QRect &rect) -{ - m_scheduled =3D m_scheduled.united(rect); - emit renderScheduled(rect); -} - -QRegion Renderer::getScheduled() -{ - QRegion region =3D m_scheduled; - m_scheduled =3D QRegion(); - return region; -} - -QImage Renderer::renderToImage(const QRect &geo) -{ - Q_ASSERT(m_client); - QImage image(geo.width(), geo.height(), QImage::Format_ARGB32_Premulti= plied); - image.fill(Qt::transparent); - QPainter p(&image); - p.setRenderHint(QPainter::Antialiasing); - p.setWindow(geo); - p.setClipRect(geo); - client()->decoration()->paint(&p, geo); - return image; -} - -void Renderer::reparent(Deleted *deleted) -{ - setParent(deleted); - m_client =3D nullptr; -} - X11Renderer::X11Renderer(DecoratedClientImpl *client) : Renderer(client) , m_scheduleTimer(new QTimer(this)) diff --git a/decorations/decorationrenderer.h b/plugins/platforms/x11/stand= alone/x11_decoration_renderer.h similarity index 52% copy from decorations/decorationrenderer.h copy to plugins/platforms/x11/standalone/x11_decoration_renderer.h index 17d184bda..bbcda9728 100644 --- a/decorations/decorationrenderer.h +++ b/plugins/platforms/x11/standalone/x11_decoration_renderer.h @@ -17,73 +17,21 @@ 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_DECORATION_RENDERER_H -#define KWIN_DECORATION_RENDERER_H +#ifndef KWIN_DECORATION_X11_RENDERER_H +#define KWIN_DECORATION_X11_RENDERER_H = -#include -#include +#include "decorations/decorationrenderer.h" = #include = -#include - class QTimer; = namespace KWin { = -class Deleted; - namespace Decoration { = -class DecoratedClientImpl; - -class KWIN_EXPORT Renderer : public QObject -{ - Q_OBJECT -public: - virtual ~Renderer(); - - void schedule(const QRect &rect); - - /** - * Reparents this Renderer to the @p deleted. - * After this call the Renderer is no longer able to render - * anything, client() returns a nullptr. - **/ - virtual void reparent(Deleted *deleted); - -Q_SIGNALS: - void renderScheduled(const QRect &geo); - -protected: - explicit Renderer(DecoratedClientImpl *client); - /** - * @returns the scheduled paint region and resets - **/ - QRegion getScheduled(); - - virtual void render() =3D 0; - - DecoratedClientImpl *client() { - return m_client; - } - - bool areImageSizesDirty() const { - return m_imageSizesDirty; - } - void resetImageSizesDirty() { - m_imageSizesDirty =3D false; - } - QImage renderToImage(const QRect &geo); - -private: - DecoratedClientImpl *m_client; - QRegion m_scheduled; - bool m_imageSizesDirty; -}; - class X11Renderer : public Renderer { Q_OBJECT diff --git a/plugins/platforms/x11/standalone/x11_platform.cpp b/plugins/pl= atforms/x11/standalone/x11_platform.cpp index 59bd8dd90..34cb91cd1 100644 --- a/plugins/platforms/x11/standalone/x11_platform.cpp +++ b/plugins/platforms/x11/standalone/x11_platform.cpp @@ -37,6 +37,7 @@ along with this program. If not, see . #include "options.h" #include "overlaywindow_x11.h" #include "non_composited_outline.h" +#include "x11_decoration_renderer.h" = #include #include @@ -346,4 +347,13 @@ OutlineVisual *X11StandalonePlatform::createOutline(Ou= tline *outline) return ret; } = +Decoration::Renderer *X11StandalonePlatform::createDecorationRenderer(Deco= ration::DecoratedClientImpl *client) +{ + auto renderer =3D Platform::createDecorationRenderer(client); + if (!renderer) { + renderer =3D new Decoration::X11Renderer(client); + } + return renderer; +} + } diff --git a/plugins/platforms/x11/standalone/x11_platform.h b/plugins/plat= forms/x11/standalone/x11_platform.h index 9fce72a0a..6f0022ffe 100644 --- a/plugins/platforms/x11/standalone/x11_platform.h +++ b/plugins/platforms/x11/standalone/x11_platform.h @@ -60,6 +60,7 @@ public: = void updateXTime() override; OutlineVisual *createOutline(Outline *outline) override; + Decoration::Renderer *createDecorationRenderer(Decoration::DecoratedCl= ientImpl *client) override; = protected: void doHideCursor() override;