[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwin] /: Move the X11 specific OverlayWindow into the platform/x11
From:       Martin_Flöser <null () kde ! org>
Date:       2017-08-12 9:33:16
Message-ID: E1dgSnE-0007Rn-1b () code ! kde ! org
[Download RAW message or body]

Git commit b4a79d30e64f56d9638a465ae199042c82f87ec6 by Martin Flöser.
Committed on 12/08/2017 at 09:32.
Pushed by graesslin into branch 'master'.

Move the X11 specific OverlayWindow into the platform/x11

Summary:
The overlay window is only needed for the X11 based compositors. Given
that it is better suited in the X11 platform. Unfortunately it is not
possible to completely move it into the platform plugin as it is still
referenced in KWin core (e.g. SceneXRender). Due to that the
OverlayWindow in KWin core is turned into a pure virtual class with the
implementation being moved into the plugin.

The platform API gains a new virtual factory method which is only
implemented in the X11 platform.

Test Plan: Compiles

Reviewers: #kwin, #plasma

Subscribers: plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D7193

M  +0    -151  overlaywindow.cpp
M  +13   -19   overlaywindow.h
M  +6    -0    platform.cpp
M  +7    -0    platform.h
M  +1    -1    plugins/platforms/x11/common/eglonxbackend.cpp
M  +1    -0    plugins/platforms/x11/standalone/CMakeLists.txt
M  +2    -1    plugins/platforms/x11/standalone/glxbackend.cpp
C  +18   -16   plugins/platforms/x11/standalone/overlaywindow_x11.cpp [from: \
overlaywindow.cpp - 087% similarity] C  +16   -20   \
plugins/platforms/x11/standalone/overlaywindow_x11.h [from: overlaywindow.h - 068% \
similarity] M  +6    -0    plugins/platforms/x11/standalone/x11_platform.cpp
M  +2    -0    plugins/platforms/x11/standalone/x11_platform.h
M  +2    -1    scene_xrender.cpp

https://commits.kde.org/kwin/b4a79d30e64f56d9638a465ae199042c82f87ec6

diff --git a/overlaywindow.cpp b/overlaywindow.cpp
index 91642786e..ac697519f 100644
--- a/overlaywindow.cpp
+++ b/overlaywindow.cpp
@@ -20,26 +20,8 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  
 #include "overlaywindow.h"
 
-#include "kwinglobals.h"
-#include "screens.h"
-#include "utils.h"
-#include "xcbutils.h"
-
-#include "assert.h"
-
-#include <QVector>
-
-#include <xcb/composite.h>
-#include <xcb/shape.h>
-#if XCB_COMPOSITE_MAJOR_VERSION > 0 || XCB_COMPOSITE_MINOR_VERSION >= 3
-#define KWIN_HAVE_XCOMPOSITE_OVERLAY
-#endif
-
 namespace KWin {
 OverlayWindow::OverlayWindow()
-    : m_visible(true)
-    , m_shown(false)
-    , m_window(XCB_WINDOW_NONE)
 {
 }
 
@@ -47,137 +29,4 @@ OverlayWindow::~OverlayWindow()
 {
 }
 
-bool OverlayWindow::create()
-{
-    assert(m_window == XCB_WINDOW_NONE);
-    if (!Xcb::Extensions::self()->isCompositeOverlayAvailable())
-        return false;
-    if (!Xcb::Extensions::self()->isShapeInputAvailable())  // needed in \
                setupOverlay()
-        return false;
-#ifdef KWIN_HAVE_XCOMPOSITE_OVERLAY
-    Xcb::OverlayWindow overlay(rootWindow());
-    if (overlay.isNull()) {
-        return false;
-    }
-    m_window = overlay->overlay_win;
-    if (m_window == XCB_WINDOW_NONE)
-        return false;
-    resize(screens()->size());
-    return true;
-#else
-    return false;
-#endif
-}
-
-void OverlayWindow::setup(xcb_window_t window)
-{
-    assert(m_window != XCB_WINDOW_NONE);
-    assert(Xcb::Extensions::self()->isShapeInputAvailable());
-    setNoneBackgroundPixmap(m_window);
-    m_shape = QRegion();
-    const QSize &s = screens()->size();
-    setShape(QRect(0, 0, s.width(), s.height()));
-    if (window != XCB_WINDOW_NONE) {
-        setNoneBackgroundPixmap(window);
-        setupInputShape(window);
-    }
-    const uint32_t eventMask = XCB_EVENT_MASK_VISIBILITY_CHANGE;
-    xcb_change_window_attributes(connection(), m_window, XCB_CW_EVENT_MASK, \
                &eventMask);
-}
-
-void OverlayWindow::setupInputShape(xcb_window_t window)
-{
-    xcb_shape_rectangles(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT, \
                XCB_CLIP_ORDERING_UNSORTED, window, 0, 0, 0, NULL);
-}
-
-void OverlayWindow::setNoneBackgroundPixmap(xcb_window_t window)
-{
-    const uint32_t mask = XCB_BACK_PIXMAP_NONE;
-    xcb_change_window_attributes(connection(), window, XCB_CW_BACK_PIXMAP, &mask);
-}
-
-void OverlayWindow::show()
-{
-    assert(m_window != XCB_WINDOW_NONE);
-    if (m_shown)
-        return;
-    xcb_map_subwindows(connection(), m_window);
-    xcb_map_window(connection(), m_window);
-    m_shown = true;
-}
-
-void OverlayWindow::hide()
-{
-    assert(m_window != XCB_WINDOW_NONE);
-    xcb_unmap_window(connection(), m_window);
-    m_shown = false;
-    const QSize &s = screens()->size();
-    setShape(QRect(0, 0, s.width(), s.height()));
-}
-
-void OverlayWindow::setShape(const QRegion& reg)
-{
-    // Avoid setting the same shape again, it causes flicker (apparently it is not a \
                no-op
-    // and triggers something).
-    if (reg == m_shape)
-        return;
-    QVector< QRect > rects = reg.rects();
-    xcb_rectangle_t *xrects = new xcb_rectangle_t[rects.count()];
-    for (int i = 0;
-            i < rects.count();
-            ++i) {
-        xrects[ i ].x = rects[ i ].x();
-        xrects[ i ].y = rects[ i ].y();
-        xrects[ i ].width = rects[ i ].width();
-        xrects[ i ].height = rects[ i ].height();
-    }
-    xcb_shape_rectangles(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_BOUNDING, \
                XCB_CLIP_ORDERING_UNSORTED,
-                         m_window, 0, 0, rects.count(), xrects);
-    delete[] xrects;
-    setupInputShape(m_window);
-    m_shape = reg;
-}
-
-void OverlayWindow::resize(const QSize &size)
-{
-    assert(m_window != XCB_WINDOW_NONE);
-    const uint32_t geometry[2] = {
-        static_cast<uint32_t>(size.width()),
-        static_cast<uint32_t>(size.height())
-    };
-    xcb_configure_window(connection(), m_window, XCB_CONFIG_WINDOW_WIDTH | \
                XCB_CONFIG_WINDOW_HEIGHT, geometry);
-    setShape(QRegion(0, 0, size.width(), size.height()));
-}
-
-bool OverlayWindow::isVisible() const
-{
-    return m_visible;
-}
-
-void OverlayWindow::setVisibility(bool visible)
-{
-    m_visible = visible;
-}
-
-void OverlayWindow::destroy()
-{
-    if (m_window == XCB_WINDOW_NONE)
-        return;
-    // reset the overlay shape
-    const QSize &s = screens()->size();
-    xcb_rectangle_t rec = { 0, 0, static_cast<uint16_t>(s.width()), \
                static_cast<uint16_t>(s.height()) };
-    xcb_shape_rectangles(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_BOUNDING, \
                XCB_CLIP_ORDERING_UNSORTED, m_window, 0, 0, 1, &rec);
-    xcb_shape_rectangles(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT, \
                XCB_CLIP_ORDERING_UNSORTED, m_window, 0, 0, 1, &rec);
-#ifdef KWIN_HAVE_XCOMPOSITE_OVERLAY
-    xcb_composite_release_overlay_window(connection(), m_window);
-#endif
-    m_window = XCB_WINDOW_NONE;
-    m_shown = false;
-}
-
-xcb_window_t OverlayWindow::window() const
-{
-    return m_window;
-}
-
 } // namespace KWin
diff --git a/overlaywindow.h b/overlaywindow.h
index e1ec3ec2f..0afff215d 100644
--- a/overlaywindow.h
+++ b/overlaywindow.h
@@ -30,28 +30,22 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  namespace KWin {
 class KWIN_EXPORT OverlayWindow {
 public:
-    OverlayWindow();
-    ~OverlayWindow();
+    virtual ~OverlayWindow();
     /// Creates XComposite overlay window, call initOverlay() afterwards
-    bool create();
+    virtual bool create() = 0;
     /// Init overlay and the destination window in it
-    void setup(xcb_window_t window);
-    void show();
-    void hide(); // hides and resets overlay window
-    void setShape(const QRegion& reg);
-    void resize(const QSize &size);
+    virtual void setup(xcb_window_t window) = 0;
+    virtual void show() = 0;
+    virtual void hide() = 0; // hides and resets overlay window
+    virtual void setShape(const QRegion& reg) = 0;
+    virtual void resize(const QSize &size) = 0;
     /// Destroys XComposite overlay window
-    void destroy();
-    xcb_window_t window() const;
-    bool isVisible() const;
-    void setVisibility(bool visible);
-private:
-    void setNoneBackgroundPixmap(xcb_window_t window);
-    void setupInputShape(xcb_window_t window);
-    bool m_visible;
-    bool m_shown; // For showOverlay()
-    QRegion m_shape;
-    xcb_window_t m_window;
+    virtual void destroy() = 0;
+    virtual xcb_window_t window() const = 0;
+    virtual bool isVisible() const = 0;
+    virtual void setVisibility(bool visible) = 0;
+protected:
+    OverlayWindow();
 };
 } // namespace
 
diff --git a/platform.cpp b/platform.cpp
index afd3e6553..91ac210c5 100644
--- a/platform.cpp
+++ b/platform.cpp
@@ -23,6 +23,7 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include "composite.h"
 #include "cursor.h"
 #include "input.h"
+#include "overlaywindow.h"
 #include "pointer_input.h"
 #include "scene_opengl.h"
 #include "screenedge.h"
@@ -460,4 +461,9 @@ void Platform::setupActionForGlobalAccel(QAction *action)
     Q_UNUSED(action)
 }
 
+OverlayWindow *Platform::createOverlayWindow()
+{
+    return nullptr;
+}
+
 }
diff --git a/platform.h b/platform.h
index f27feda83..35392bf5d 100644
--- a/platform.h
+++ b/platform.h
@@ -40,6 +40,7 @@ namespace KWin
 {
 
 class Edge;
+class OverlayWindow;
 class OpenGLBackend;
 class QPainterBackend;
 class Screens;
@@ -301,6 +302,12 @@ public:
         m_initialOutputScale = scale;
     }
 
+    /**
+     * Creates the OverlayWindow required for X11 based compositors.
+     * Default implementation returns @c nullptr.
+     **/
+    virtual OverlayWindow *createOverlayWindow();
+
 public Q_SLOTS:
     void pointerMotion(const QPointF &position, quint32 time);
     void pointerButtonPressed(quint32 button, quint32 time);
diff --git a/plugins/platforms/x11/common/eglonxbackend.cpp \
b/plugins/platforms/x11/common/eglonxbackend.cpp index 49e23578d..6eaf518a3 100644
--- a/plugins/platforms/x11/common/eglonxbackend.cpp
+++ b/plugins/platforms/x11/common/eglonxbackend.cpp
@@ -40,7 +40,7 @@ namespace KWin
 
 EglOnXBackend::EglOnXBackend(Display *display)
     : AbstractEglBackend()
-    , m_overlayWindow(new OverlayWindow())
+    , m_overlayWindow(kwinApp()->platform()->createOverlayWindow())
     , surfaceHasSubPost(0)
     , m_bufferAge(0)
     , m_usesOverlayWindow(true)
diff --git a/plugins/platforms/x11/standalone/CMakeLists.txt \
b/plugins/platforms/x11/standalone/CMakeLists.txt index 98daa1220..c2cc0191a 100644
--- a/plugins/platforms/x11/standalone/CMakeLists.txt
+++ b/plugins/platforms/x11/standalone/CMakeLists.txt
@@ -5,6 +5,7 @@ set(X11PLATFORM_SOURCES
     x11_platform.cpp
     screens_xrandr.cpp
     windowselector.cpp
+    overlaywindow_x11.cpp
 )
 
 if(X11_Xinput_FOUND)
diff --git a/plugins/platforms/x11/standalone/glxbackend.cpp \
b/plugins/platforms/x11/standalone/glxbackend.cpp index 438052fb4..ee86434c5 100644
--- a/plugins/platforms/x11/standalone/glxbackend.cpp
+++ b/plugins/platforms/x11/standalone/glxbackend.cpp
@@ -29,6 +29,7 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include "options.h"
 #include "overlaywindow.h"
 #include "composite.h"
+#include "platform.h"
 #include "screens.h"
 #include "xcbutils.h"
 // kwin libs
@@ -104,7 +105,7 @@ bool SwapEventFilter::event(xcb_generic_event_t *event)
 
 GlxBackend::GlxBackend(Display *display)
     : OpenGLBackend()
-    , m_overlayWindow(new OverlayWindow())
+    , m_overlayWindow(kwinApp()->platform()->createOverlayWindow())
     , window(None)
     , fbconfig(NULL)
     , glxWindow(None)
diff --git a/overlaywindow.cpp \
b/plugins/platforms/x11/standalone/overlaywindow_x11.cpp similarity index 87%
copy from overlaywindow.cpp
copy to plugins/platforms/x11/standalone/overlaywindow_x11.cpp
index 91642786e..c1e4fe9da 100644
--- a/overlaywindow.cpp
+++ b/plugins/platforms/x11/standalone/overlaywindow_x11.cpp
@@ -18,7 +18,7 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *********************************************************************/
 
-#include "overlaywindow.h"
+#include "overlaywindow_x11.h"
 
 #include "kwinglobals.h"
 #include "screens.h"
@@ -36,18 +36,19 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #endif
 
 namespace KWin {
-OverlayWindow::OverlayWindow()
-    : m_visible(true)
+OverlayWindowX11::OverlayWindowX11()
+    : OverlayWindow()
+    , m_visible(true)
     , m_shown(false)
     , m_window(XCB_WINDOW_NONE)
 {
 }
 
-OverlayWindow::~OverlayWindow()
+OverlayWindowX11::~OverlayWindowX11()
 {
 }
 
-bool OverlayWindow::create()
+bool OverlayWindowX11::create()
 {
     assert(m_window == XCB_WINDOW_NONE);
     if (!Xcb::Extensions::self()->isCompositeOverlayAvailable())
@@ -69,7 +70,7 @@ bool OverlayWindow::create()
 #endif
 }
 
-void OverlayWindow::setup(xcb_window_t window)
+void OverlayWindowX11::setup(xcb_window_t window)
 {
     assert(m_window != XCB_WINDOW_NONE);
     assert(Xcb::Extensions::self()->isShapeInputAvailable());
@@ -85,18 +86,18 @@ void OverlayWindow::setup(xcb_window_t window)
     xcb_change_window_attributes(connection(), m_window, XCB_CW_EVENT_MASK, \
&eventMask);  }
 
-void OverlayWindow::setupInputShape(xcb_window_t window)
+void OverlayWindowX11::setupInputShape(xcb_window_t window)
 {
     xcb_shape_rectangles(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT, \
XCB_CLIP_ORDERING_UNSORTED, window, 0, 0, 0, NULL);  }
 
-void OverlayWindow::setNoneBackgroundPixmap(xcb_window_t window)
+void OverlayWindowX11::setNoneBackgroundPixmap(xcb_window_t window)
 {
     const uint32_t mask = XCB_BACK_PIXMAP_NONE;
     xcb_change_window_attributes(connection(), window, XCB_CW_BACK_PIXMAP, &mask);
 }
 
-void OverlayWindow::show()
+void OverlayWindowX11::show()
 {
     assert(m_window != XCB_WINDOW_NONE);
     if (m_shown)
@@ -106,7 +107,7 @@ void OverlayWindow::show()
     m_shown = true;
 }
 
-void OverlayWindow::hide()
+void OverlayWindowX11::hide()
 {
     assert(m_window != XCB_WINDOW_NONE);
     xcb_unmap_window(connection(), m_window);
@@ -115,7 +116,7 @@ void OverlayWindow::hide()
     setShape(QRect(0, 0, s.width(), s.height()));
 }
 
-void OverlayWindow::setShape(const QRegion& reg)
+void OverlayWindowX11::setShape(const QRegion& reg)
 {
     // Avoid setting the same shape again, it causes flicker (apparently it is not a \
no-op  // and triggers something).
@@ -138,7 +139,7 @@ void OverlayWindow::setShape(const QRegion& reg)
     m_shape = reg;
 }
 
-void OverlayWindow::resize(const QSize &size)
+void OverlayWindowX11::resize(const QSize &size)
 {
     assert(m_window != XCB_WINDOW_NONE);
     const uint32_t geometry[2] = {
@@ -149,17 +150,17 @@ void OverlayWindow::resize(const QSize &size)
     setShape(QRegion(0, 0, size.width(), size.height()));
 }
 
-bool OverlayWindow::isVisible() const
+bool OverlayWindowX11::isVisible() const
 {
     return m_visible;
 }
 
-void OverlayWindow::setVisibility(bool visible)
+void OverlayWindowX11::setVisibility(bool visible)
 {
     m_visible = visible;
 }
 
-void OverlayWindow::destroy()
+void OverlayWindowX11::destroy()
 {
     if (m_window == XCB_WINDOW_NONE)
         return;
@@ -175,9 +176,10 @@ void OverlayWindow::destroy()
     m_shown = false;
 }
 
-xcb_window_t OverlayWindow::window() const
+xcb_window_t OverlayWindowX11::window() const
 {
     return m_window;
 }
 
 } // namespace KWin
+
diff --git a/overlaywindow.h b/plugins/platforms/x11/standalone/overlaywindow_x11.h
similarity index 68%
copy from overlaywindow.h
copy to plugins/platforms/x11/standalone/overlaywindow_x11.h
index e1ec3ec2f..2cb562ae5 100644
--- a/overlaywindow.h
+++ b/plugins/platforms/x11/standalone/overlaywindow_x11.h
@@ -18,33 +18,29 @@ You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *********************************************************************/
 
-#ifndef KWIN_OVERLAYWINDOW_H
-#define KWIN_OVERLAYWINDOW_H
+#ifndef KWIN_OVERLAYWINDOW_X11_H
+#define KWIN_OVERLAYWINDOW_X11_H
 
-#include <QRegion>
-// xcb
-#include <xcb/xcb.h>
-
-#include <kwin_export.h>
+#include "../../../../overlaywindow.h"
 
 namespace KWin {
-class KWIN_EXPORT OverlayWindow {
+class KWIN_EXPORT OverlayWindowX11 : public OverlayWindow {
 public:
-    OverlayWindow();
-    ~OverlayWindow();
+    OverlayWindowX11();
+    ~OverlayWindowX11();
     /// Creates XComposite overlay window, call initOverlay() afterwards
-    bool create();
+    bool create() override;
     /// Init overlay and the destination window in it
-    void setup(xcb_window_t window);
-    void show();
-    void hide(); // hides and resets overlay window
-    void setShape(const QRegion& reg);
-    void resize(const QSize &size);
+    void setup(xcb_window_t window) override;
+    void show() override;
+    void hide() override; // hides and resets overlay window
+    void setShape(const QRegion& reg) override;
+    void resize(const QSize &size) override;
     /// Destroys XComposite overlay window
-    void destroy();
-    xcb_window_t window() const;
-    bool isVisible() const;
-    void setVisibility(bool visible);
+    void destroy() override;
+    xcb_window_t window() const override;
+    bool isVisible() const override;
+    void setVisibility(bool visible) override;
 private:
     void setNoneBackgroundPixmap(xcb_window_t window);
     void setupInputShape(xcb_window_t window);
diff --git a/plugins/platforms/x11/standalone/x11_platform.cpp \
b/plugins/platforms/x11/standalone/x11_platform.cpp index b6a9150c1..0a938b20e 100644
--- a/plugins/platforms/x11/standalone/x11_platform.cpp
+++ b/plugins/platforms/x11/standalone/x11_platform.cpp
@@ -34,6 +34,7 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include "logging.h"
 #include "screens_xrandr.h"
 #include "options.h"
+#include "overlaywindow_x11.h"
 
 #include <KConfigGroup>
 #include <KLocalizedString>
@@ -309,4 +310,9 @@ void X11StandalonePlatform::setupActionForGlobalAccel(QAction \
*action)  });
 }
 
+OverlayWindow *X11StandalonePlatform::createOverlayWindow()
+{
+    return new OverlayWindowX11();
+}
+
 }
diff --git a/plugins/platforms/x11/standalone/x11_platform.h \
b/plugins/platforms/x11/standalone/x11_platform.h index 7fa55261d..861b2bf10 100644
--- a/plugins/platforms/x11/standalone/x11_platform.h
+++ b/plugins/platforms/x11/standalone/x11_platform.h
@@ -55,6 +55,8 @@ public:
 
     void setupActionForGlobalAccel(QAction *action) override;
 
+    OverlayWindow *createOverlayWindow() override;
+
 protected:
     void doHideCursor() override;
     void doShowCursor() override;
diff --git a/scene_xrender.cpp b/scene_xrender.cpp
index 263c75f14..ead00b8c5 100644
--- a/scene_xrender.cpp
+++ b/scene_xrender.cpp
@@ -32,6 +32,7 @@ along with this program.  If not, see \
<http://www.gnu.org/licenses/>.  #include "effects.h"
 #include "main.h"
 #include "overlaywindow.h"
+#include "platform.h"
 #include "xcbutils.h"
 #include "kwinxrenderutils.h"
 #include "decorations/decoratedclient.h"
@@ -109,7 +110,7 @@ void XRenderBackend::screenGeometryChanged(const QSize &size)
 //****************************************
 X11XRenderBackend::X11XRenderBackend()
     : XRenderBackend()
-    , m_overlayWindow(new OverlayWindow())
+    , m_overlayWindow(kwinApp()->platform()->createOverlayWindow())
     , m_front(XCB_RENDER_PICTURE_NONE)
     , m_format(0)
 {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic