| 1 | /**************************************************************************** |
|---|---|
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the plugins of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qminimaleglintegration.h" |
| 41 | |
| 42 | #include "qminimaleglwindow.h" |
| 43 | #ifndef QT_NO_OPENGL |
| 44 | # include "qminimaleglbackingstore.h" |
| 45 | #endif |
| 46 | #include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h> |
| 47 | |
| 48 | #if defined(Q_OS_UNIX) |
| 49 | # include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h> |
| 50 | #elif defined(Q_OS_WINRT) |
| 51 | # include <QtCore/private/qeventdispatcher_winrt_p.h> |
| 52 | # include <QtGui/qpa/qwindowsysteminterface.h> |
| 53 | #elif defined(Q_OS_WIN) |
| 54 | # include <QtEventDispatcherSupport/private/qwindowsguieventdispatcher_p.h> |
| 55 | #endif |
| 56 | |
| 57 | #include <qpa/qplatformwindow.h> |
| 58 | #include <QtGui/QSurfaceFormat> |
| 59 | #include <QtGui/QOpenGLContext> |
| 60 | #include <QtGui/QScreen> |
| 61 | #include <qpa/qwindowsysteminterface.h> |
| 62 | |
| 63 | // this is where EGL headers are pulled in, make sure it is last |
| 64 | #include "qminimaleglscreen.h" |
| 65 | |
| 66 | QT_BEGIN_NAMESPACE |
| 67 | |
| 68 | #ifdef Q_OS_WINRT |
| 69 | namespace { |
| 70 | class QWinRTEventDispatcher : public QEventDispatcherWinRT { |
| 71 | public: |
| 72 | QWinRTEventDispatcher() {} |
| 73 | |
| 74 | protected: |
| 75 | bool hasPendingEvents() override |
| 76 | { |
| 77 | return QEventDispatcherWinRT::hasPendingEvents() || QWindowSystemInterface::windowSystemEventsQueued(); |
| 78 | } |
| 79 | |
| 80 | bool sendPostedEvents(QEventLoop::ProcessEventsFlags flags) |
| 81 | { |
| 82 | bool didProcess = QEventDispatcherWinRT::sendPostedEvents(flags); |
| 83 | if (!(flags & QEventLoop::ExcludeUserInputEvents)) |
| 84 | didProcess |= QWindowSystemInterface::sendWindowSystemEvents(flags); |
| 85 | return didProcess; |
| 86 | } |
| 87 | }; |
| 88 | } // anonymous namespace |
| 89 | #endif // Q_OS_WINRT |
| 90 | |
| 91 | QMinimalEglIntegration::QMinimalEglIntegration() |
| 92 | : mFontDb(new QGenericUnixFontDatabase()), mScreen(new QMinimalEglScreen(EGL_DEFAULT_DISPLAY)) |
| 93 | { |
| 94 | QWindowSystemInterface::handleScreenAdded(screen: mScreen); |
| 95 | |
| 96 | #ifdef QEGL_EXTRA_DEBUG |
| 97 | qWarning("QMinimalEglIntegration\n"); |
| 98 | #endif |
| 99 | } |
| 100 | |
| 101 | QMinimalEglIntegration::~QMinimalEglIntegration() |
| 102 | { |
| 103 | QWindowSystemInterface::handleScreenRemoved(screen: mScreen); |
| 104 | delete mFontDb; |
| 105 | } |
| 106 | |
| 107 | bool QMinimalEglIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
| 108 | { |
| 109 | switch (cap) { |
| 110 | case ThreadedPixmaps: return true; |
| 111 | case OpenGL: return true; |
| 112 | case ThreadedOpenGL: return true; |
| 113 | default: return QPlatformIntegration::hasCapability(cap); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | QPlatformWindow *QMinimalEglIntegration::createPlatformWindow(QWindow *window) const |
| 118 | { |
| 119 | #ifdef QEGL_EXTRA_DEBUG |
| 120 | qWarning("QMinimalEglIntegration::createPlatformWindow %p\n",window); |
| 121 | #endif |
| 122 | QPlatformWindow *w = new QMinimalEglWindow(window); |
| 123 | w->requestActivateWindow(); |
| 124 | return w; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | QPlatformBackingStore *QMinimalEglIntegration::createPlatformBackingStore(QWindow *window) const |
| 129 | { |
| 130 | #ifdef QEGL_EXTRA_DEBUG |
| 131 | qWarning("QMinimalEglIntegration::createWindowSurface %p\n", window); |
| 132 | #endif |
| 133 | #ifndef QT_NO_OPENGL |
| 134 | return new QMinimalEglBackingStore(window); |
| 135 | #else |
| 136 | Q_UNUSED(window); |
| 137 | return nullptr; |
| 138 | #endif |
| 139 | } |
| 140 | #ifndef QT_NO_OPENGL |
| 141 | QPlatformOpenGLContext *QMinimalEglIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const |
| 142 | { |
| 143 | return static_cast<QMinimalEglScreen *>(context->screen()->handle())->platformContext(); |
| 144 | } |
| 145 | #endif |
| 146 | |
| 147 | QPlatformFontDatabase *QMinimalEglIntegration::fontDatabase() const |
| 148 | { |
| 149 | return mFontDb; |
| 150 | } |
| 151 | |
| 152 | QAbstractEventDispatcher *QMinimalEglIntegration::createEventDispatcher() const |
| 153 | { |
| 154 | #if defined(Q_OS_UNIX) |
| 155 | return createUnixEventDispatcher(); |
| 156 | #elif defined(Q_OS_WINRT) |
| 157 | return new QWinRTEventDispatcher; |
| 158 | #elif defined(Q_OS_WIN) |
| 159 | return new QWindowsGuiEventDispatcher; |
| 160 | #else |
| 161 | return nullptr; |
| 162 | #endif |
| 163 | } |
| 164 | |
| 165 | QVariant QMinimalEglIntegration::styleHint(QPlatformIntegration::StyleHint hint) const |
| 166 | { |
| 167 | if (hint == QPlatformIntegration::ShowIsFullScreen) |
| 168 | return true; |
| 169 | |
| 170 | return QPlatformIntegration::styleHint(hint); |
| 171 | } |
| 172 | |
| 173 | QT_END_NAMESPACE |
| 174 |
