1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2018 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: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 QWASMCOMPOSITOR_H 31 #define QWASMCOMPOSITOR_H 32 33 #include <QtGui/qregion.h> 34 #include <qpa/qplatformwindow.h> 35 36 #include <QtGui/qopengltextureblitter.h> 37 #include <QtGui/qopengltexture.h> 38 #include <QtGui/qpalette.h> 39 #include <QtGui/qpainter.h> 40 41 QT_BEGIN_NAMESPACE 42 43 class QWasmWindow; 44 class QWasmScreen; 45 class QOpenGLContext; 46 class QOpenGLTextureBlitter; 47 48 class QWasmCompositedWindow 49 { 50 public: 51 QWasmCompositedWindow(); 52 53 QWasmWindow *window; 54 QWasmWindow *parentWindow; 55 QRegion damage; 56 bool flushPending; 57 bool visible; 58 QList<QWasmWindow *> childWindows; 59 }; 60 61 class QWasmCompositor : public QObject 62 { 63 Q_OBJECT 64 public: 65 QWasmCompositor(QWasmScreen *screen); 66 ~QWasmCompositor(); 67 void destroy(); 68 69 enum QWasmSubControl { 70 SC_None = 0x00000000, 71 SC_TitleBarSysMenu = 0x00000001, 72 SC_TitleBarMinButton = 0x00000002, 73 SC_TitleBarMaxButton = 0x00000004, 74 SC_TitleBarCloseButton = 0x00000008, 75 SC_TitleBarNormalButton = 0x00000010, 76 SC_TitleBarLabel = 0x00000100 77 }; 78 Q_DECLARE_FLAGS(SubControls, QWasmSubControl) 79 80 enum QWasmStateFlag { 81 State_None = 0x00000000, 82 State_Enabled = 0x00000001, 83 State_Raised = 0x00000002, 84 State_Sunken = 0x00000004 85 }; 86 Q_DECLARE_FLAGS(StateFlags, QWasmStateFlag) 87 88 struct QWasmTitleBarOptions { 89 QRect rect; 90 Qt::WindowFlags flags; 91 int state; 92 QPalette palette; 93 QString titleBarOptionsString; 94 QWasmCompositor::SubControls subControls; 95 }; 96 97 struct QWasmFrameOptions { 98 QRect rect; 99 int lineWidth; 100 QPalette palette; 101 }; 102 103 void setEnabled(bool enabled); 104 105 void addWindow(QWasmWindow *window, QWasmWindow *parentWindow = nullptr); 106 void removeWindow(QWasmWindow *window); 107 108 void setVisible(QWasmWindow *window, bool visible); 109 void raise(QWasmWindow *window); 110 void lower(QWasmWindow *window); 111 void setParent(QWasmWindow *window, QWasmWindow *parent); 112 113 void flush(QWasmWindow *surface, const QRegion ®ion); 114 115 int windowCount() const; 116 117 void redrawWindowContent(); 118 void requestRedraw(); 119 120 QWindow *windowAt(QPoint globalPoint, int padding = 0) const; 121 QWindow *keyWindow() const; 122 123 bool event(QEvent *event); 124 125 static QWasmTitleBarOptions makeTitleBarOptions(const QWasmWindow *window); 126 static QRect titlebarRect(QWasmTitleBarOptions tb, QWasmCompositor::SubControls subcontrol); 127 128 QWasmScreen *screen(); 129 QOpenGLContext *context(); 130 131 private slots: 132 void frame(); 133 134 private: 135 void notifyTopWindowChanged(QWasmWindow *window); 136 void drawWindow(QOpenGLTextureBlitter *blitter, QWasmScreen *screen, QWasmWindow *window); 137 void drawWindowContent(QOpenGLTextureBlitter *blitter, QWasmScreen *screen, QWasmWindow *window); 138 void blit(QOpenGLTextureBlitter *blitter, QWasmScreen *screen, const QOpenGLTexture *texture, QRect targetGeometry); 139 140 void drawWindowDecorations(QOpenGLTextureBlitter *blitter, QWasmScreen *screen, QWasmWindow *window); 141 void drwPanelButton(); 142 143 QScopedPointer<QOpenGLContext> m_context; 144 QScopedPointer<QOpenGLTextureBlitter> m_blitter; 145 146 QHash<QWasmWindow *, QWasmCompositedWindow> m_compositedWindows; 147 QList<QWasmWindow *> m_windowStack; 148 QRegion m_globalDamage; // damage caused by expose, window close, etc. 149 bool m_needComposit; 150 bool m_inFlush; 151 bool m_inResize; 152 bool m_isEnabled; 153 QSize m_targetSize; 154 qreal m_targetDevicePixelRatio; 155 156 static QPalette makeWindowPalette(); 157 158 void drawFrameWindow(QWasmFrameOptions options, QPainter *painter); 159 void drawTitlebarWindow(QWasmTitleBarOptions options, QPainter *painter); 160 void drawShadePanel(QWasmTitleBarOptions options, QPainter *painter); 161 void drawItemPixmap(QPainter *painter, const QRect &rect, 162 int alignment, const QPixmap &pixmap) const; 163 }; 164 Q_DECLARE_OPERATORS_FOR_FLAGS(QWasmCompositor::SubControls) 165 166 QT_END_NAMESPACE 167 168 #endif 169