| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt WebGL module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 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 General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | #ifndef QWEBGLINTEGRATION_P_H |
| 31 | #define QWEBGLINTEGRATION_P_H |
| 32 | |
| 33 | #include "qwebglscreen.h" |
| 34 | #include "qwebglhttpserver.h" |
| 35 | #include "qwebglplatformservices.h" |
| 36 | #include "qwebglwebsocketserver.h" |
| 37 | |
| 38 | #include <QtCore/qmutex.h> |
| 39 | #include <QtCore/qwaitcondition.h> |
| 40 | #include <QtGui/qpa/qplatforminputcontextfactory_p.h> |
| 41 | |
| 42 | #if defined(Q_OS_WIN) |
| 43 | #include <QtFontDatabaseSupport/private/qwindowsfontdatabase_p.h> |
| 44 | #include <QtEventDispatcherSupport/private/qwindowsguieventdispatcher_p.h> |
| 45 | #elif defined(Q_OS_MACOS) |
| 46 | #include <QtFontDatabaseSupport/private/qfontengine_coretext_p.h> |
| 47 | #include <QtFontDatabaseSupport/private/qcoretextfontdatabase_p.h> |
| 48 | #include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h> |
| 49 | #else |
| 50 | #include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h> |
| 51 | #include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h> |
| 52 | #endif // Q_OS_WIN |
| 53 | |
| 54 | QT_BEGIN_NAMESPACE |
| 55 | |
| 56 | class QWebSocket; |
| 57 | class QWebGLIntegration; |
| 58 | |
| 59 | class QWebGLIntegrationPrivate |
| 60 | { |
| 61 | Q_DECLARE_PUBLIC(QWebGLIntegration) |
| 62 | public: |
| 63 | QWebGLIntegration *q_ptr = nullptr; |
| 64 | |
| 65 | struct ClientData |
| 66 | { |
| 67 | QVector<QWebGLWindow *> platformWindows; |
| 68 | QWebSocket *socket; |
| 69 | QWebGLScreen *platformScreen = nullptr; |
| 70 | }; |
| 71 | |
| 72 | mutable QPlatformInputContext *inputContext = nullptr; |
| 73 | quint16 httpPort = 0; |
| 74 | quint16 wssPort = 0; |
| 75 | #if defined(Q_OS_WIN) |
| 76 | mutable QWindowsFontDatabase fontDatabase; |
| 77 | #elif defined(Q_OS_MACOS) |
| 78 | mutable QCoreTextFontDatabaseEngineFactory<QCoreTextFontEngine> fontDatabase; |
| 79 | #else |
| 80 | mutable QGenericUnixFontDatabase fontDatabase; |
| 81 | #endif |
| 82 | mutable QWebGLPlatformServices services; |
| 83 | QWebGLHttpServer *httpServer = nullptr; |
| 84 | QWebGLWebSocketServer *webSocketServer = nullptr; |
| 85 | QWebGLScreen *screen = nullptr; |
| 86 | QThread *webSocketServerThread = nullptr; |
| 87 | mutable struct { |
| 88 | QList<ClientData> list; |
| 89 | QMutex mutex; |
| 90 | } clients; |
| 91 | mutable QVector<QWindow *> windows; |
| 92 | |
| 93 | QMutex waitMutex; |
| 94 | QWaitCondition waitCondition; |
| 95 | QVector<int> pendingResponses; |
| 96 | QHash<int, QVariant> receivedResponses; |
| 97 | QTouchDevice *touchDevice = nullptr; |
| 98 | |
| 99 | ClientData *findClientData(const QWebSocket *socket); |
| 100 | ClientData *findClientData(const QPlatformSurface *surface); |
| 101 | QWebGLWindow *findWindow(const ClientData &clientData, WId winId); |
| 102 | |
| 103 | void clientConnected(QWebSocket *socket, |
| 104 | const int width, |
| 105 | const int height, |
| 106 | const double physicalWidth, |
| 107 | const double physicalHeight); |
| 108 | void clientDisconnected(QWebSocket *socket); |
| 109 | |
| 110 | void connectNextClient(); |
| 111 | |
| 112 | void sendMessage(QWebSocket *socket, |
| 113 | QWebGLWebSocketServer::MessageType type, |
| 114 | const QVariantMap &values) const; |
| 115 | void onTextMessageReceived(QWebSocket *socket, const QString &message); |
| 116 | void handleDefaultContextParameters(const ClientData &clientData, const QJsonObject &object); |
| 117 | void handleGlResponse(const QJsonObject &object); |
| 118 | void handleCanvasResize(const ClientData &clientData, const QJsonObject &object); |
| 119 | void handleMouse(const ClientData &clientData, const QJsonObject &object); |
| 120 | void handleWheel(const ClientData &clientData, const QJsonObject &object); |
| 121 | void handleTouch(const ClientData &clientData, const QJsonObject &object); |
| 122 | void handleKeyboard(const ClientData &clientData, |
| 123 | const QString &type, |
| 124 | const QJsonObject &object); |
| 125 | |
| 126 | Qt::KeyboardModifiers convertKeyboardModifiers(const QJsonObject &object); |
| 127 | |
| 128 | static QWebGLIntegrationPrivate *instance(); |
| 129 | }; |
| 130 | |
| 131 | QT_END_NAMESPACE |
| 132 | |
| 133 | #endif // QWEBGLINTEGRATION_P_H |
| 134 | |