From e1ae0b8bc40a6fc7dd3d3c9f805fe241fa360dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 27 Mar 2015 08:51:56 +0100 Subject: [PATCH] [wayland] Create OpenGLBackend through the AbstractBackend Replaces casting logic in the SceneOpenGL. Now the create is delegated to the backend allowing also to move the ifdef logic to where it belongs. --- abstract_backend.cpp | 5 +++++ abstract_backend.h | 2 ++ scene_opengl.cpp | 29 ++++++----------------------- wayland_backend.cpp | 12 ++++++++++++ wayland_backend.h | 1 + x11windowed_backend.cpp | 15 +++++++++++++++ x11windowed_backend.h | 1 + 7 files changed, 42 insertions(+), 23 deletions(-) diff --git a/abstract_backend.cpp b/abstract_backend.cpp index a0dd763638..44b50e136f 100644 --- a/abstract_backend.cpp +++ b/abstract_backend.cpp @@ -49,4 +49,9 @@ Screens *AbstractBackend::createScreens(QObject *parent) return nullptr; } +OpenGLBackend *AbstractBackend::createOpenGLBackend() +{ + return nullptr; +} + } diff --git a/abstract_backend.h b/abstract_backend.h index 94e407517c..9f30253de1 100644 --- a/abstract_backend.h +++ b/abstract_backend.h @@ -25,6 +25,7 @@ along with this program. If not, see . namespace KWin { +class OpenGLBackend; class Screens; class KWIN_EXPORT AbstractBackend : public QObject @@ -36,6 +37,7 @@ public: virtual void installCursorFromServer(); virtual void installCursorImage(Qt::CursorShape shape); virtual Screens *createScreens(QObject *parent = nullptr); + virtual OpenGLBackend *createOpenGLBackend(); protected: explicit AbstractBackend(QObject *parent = nullptr); diff --git a/scene_opengl.cpp b/scene_opengl.cpp index bb16451206..a7ab18fe42 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -29,22 +29,16 @@ along with this program. If not, see . #include "scene_opengl.h" #ifdef KWIN_HAVE_EGL #include "eglonxbackend.h" -// for Wayland -#if HAVE_WAYLAND -#include "wayland_server.h" -#if HAVE_WAYLAND_EGL -#include "egl_wayland_backend.h" -#include "wayland_backend.h" -#endif // HAVE_WAYLAND_EGL -#if HAVE_X11_XCB -#include "x11windowed_backend.h" -#endif // HAVE_X11_XCB -#endif // HAVE_WAYLAND #endif // KWIN_HAVE_EGL #ifndef KWIN_HAVE_OPENGLES #include "glxbackend.h" #endif // KWIN_HAVE_OPENGLES +#if HAVE_WAYLAND +#include "abstract_backend.h" +#include "wayland_server.h" +#endif // HAVE_WAYLAND + #include #include @@ -503,18 +497,7 @@ SceneOpenGL *SceneOpenGL::createScene(QObject *parent) #ifdef KWIN_HAVE_EGL #if HAVE_WAYLAND if (kwinApp()->shouldUseWaylandForCompositing()) { -#if HAVE_WAYLAND_EGL - if (Wayland::WaylandBackend *b = dynamic_cast(waylandServer()->backend())) { - backend = new EglWaylandBackend(b); - } -#endif // HAVE_WAYLAND_EGL -#if HAVE_X11_XCB - if (!backend) { - if (X11WindowedBackend *b = dynamic_cast(waylandServer()->backend())) { - backend = new EglOnXBackend(b); - } - } -#endif // HAVE_X11_XCB + backend = waylandServer()->backend()->createOpenGLBackend(); } else #endif // HAVE_WAYLAND { diff --git a/wayland_backend.cpp b/wayland_backend.cpp index 5b9349d5fd..b42e4ad4b8 100644 --- a/wayland_backend.cpp +++ b/wayland_backend.cpp @@ -26,6 +26,9 @@ along with this program. If not, see . #include "screens_wayland.h" #include "utils.h" #include "wayland_server.h" +#if HAVE_WAYLAND_EGL +#include "egl_wayland_backend.h" +#endif #include #include #include @@ -645,6 +648,15 @@ Screens *WaylandBackend::createScreens(QObject *parent) return new WaylandScreens(this, parent); } +OpenGLBackend *WaylandBackend::createOpenGLBackend() +{ +#if HAVE_WAYLAND_EGL + return new EglWaylandBackend(this); +#else + return nullptr; +#endif +} + } } // KWin diff --git a/wayland_backend.h b/wayland_backend.h index a3f397db08..096ebc378a 100644 --- a/wayland_backend.h +++ b/wayland_backend.h @@ -170,6 +170,7 @@ public: void installCursorFromServer() override; Screens *createScreens(QObject *parent = nullptr) override; + OpenGLBackend *createOpenGLBackend() override; protected: void connectNotify(const QMetaMethod &signal) override; diff --git a/x11windowed_backend.cpp b/x11windowed_backend.cpp index d8b34a312d..9352435197 100644 --- a/x11windowed_backend.cpp +++ b/x11windowed_backend.cpp @@ -24,6 +24,11 @@ along with this program. If not, see . #include "utils.h" #include "wayland_server.h" #include "xcbutils.h" +#ifdef KWIN_HAVE_EGL +#if HAVE_X11_XCB +#include "eglonxbackend.h" +#endif +#endif #include #include #include @@ -299,4 +304,14 @@ Screens *X11WindowedBackend::createScreens(QObject *parent) return new X11WindowedScreens(this, parent); } +OpenGLBackend *X11WindowedBackend::createOpenGLBackend() +{ +#ifdef KWIN_HAVE_EGL +#if HAVE_X11_XCB + return new EglOnXBackend(this); +#endif +#endif + return nullptr; +} + } diff --git a/x11windowed_backend.h b/x11windowed_backend.h index afecb70a1b..5a381d2718 100644 --- a/x11windowed_backend.h +++ b/x11windowed_backend.h @@ -67,6 +67,7 @@ public: void installCursorFromServer() override; Screens *createScreens(QObject *parent = nullptr) override; + OpenGLBackend *createOpenGLBackend() override; Q_SIGNALS: void sizeChanged();