| 1 | // Copyright (C) 2017 The Qt Company Ltd. | 
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only | 
| 3 |  | 
| 4 | #ifndef QWAYLANDQUICKITEM_P_H | 
| 5 | #define QWAYLANDQUICKITEM_P_H | 
| 6 |  | 
| 7 | // | 
| 8 | //  W A R N I N G | 
| 9 | //  ------------- | 
| 10 | // | 
| 11 | // This file is not part of the Qt API.  It exists purely as an | 
| 12 | // implementation detail.  This header file may change from version to | 
| 13 | // version without notice, or even be removed. | 
| 14 | // | 
| 15 | // We mean it. | 
| 16 | // | 
| 17 |  | 
| 18 | #include <QtQuick/private/qquickitem_p.h> | 
| 19 | #include <QtQuick/QSGMaterialShader> | 
| 20 | #include <QtQuick/QSGMaterial> | 
| 21 |  | 
| 22 | #include <QtWaylandCompositor/QWaylandQuickItem> | 
| 23 | #include <QtWaylandCompositor/QWaylandOutput> | 
| 24 |  | 
| 25 | #include <QtCore/qpointer.h> | 
| 26 |  | 
| 27 | QT_BEGIN_NAMESPACE | 
| 28 |  | 
| 29 | class QWaylandSurfaceTextureProvider; | 
| 30 | class QMutex; | 
| 31 | class QOpenGLTexture; | 
| 32 |  | 
| 33 | #if QT_CONFIG(opengl) | 
| 34 | class QWaylandBufferMaterialShader : public QSGMaterialShader | 
| 35 | { | 
| 36 | public: | 
| 37 |     QWaylandBufferMaterialShader(QWaylandBufferRef::BufferFormatEgl format); | 
| 38 |  | 
| 39 |     bool updateUniformData(RenderState &state, | 
| 40 |                            QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; | 
| 41 |     void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, | 
| 42 |                             QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; | 
| 43 |     void setupExternalOESShader(const QString &shaderFilename); | 
| 44 | }; | 
| 45 |  | 
| 46 | class QWaylandBufferMaterial : public QSGMaterial | 
| 47 | { | 
| 48 | public: | 
| 49 |     QWaylandBufferMaterial(QWaylandBufferRef::BufferFormatEgl format); | 
| 50 |     ~QWaylandBufferMaterial() override; | 
| 51 |  | 
| 52 |     void setTextureForPlane(int plane, QOpenGLTexture *texture, QSGTexture *scenegraphTexture); | 
| 53 |     void setBufferRef(QWaylandQuickItem *surfaceItem, const QWaylandBufferRef &ref); | 
| 54 |  | 
| 55 |     void bind(); | 
| 56 |     void updateScenegraphTextures(QRhi *rhi); | 
| 57 |  | 
| 58 |     QSGMaterialType *type() const override; | 
| 59 |     QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override; | 
| 60 |  | 
| 61 | private: | 
| 62 |     friend QWaylandBufferMaterialShader; | 
| 63 |  | 
| 64 |     void setTextureParameters(GLenum target); | 
| 65 |     void ensureTextures(int count); | 
| 66 |  | 
| 67 |     const QWaylandBufferRef::BufferFormatEgl m_format; | 
| 68 |     QVarLengthArray<QOpenGLTexture*, 3> m_textures; | 
| 69 |     QVarLengthArray<QSGTexture*, 3> m_scenegraphTextures; | 
| 70 |     QWaylandBufferRef m_bufferRef; | 
| 71 | }; | 
| 72 | #endif // QT_CONFIG(opengl) | 
| 73 |  | 
| 74 | class QWaylandQuickItemPrivate : public QQuickItemPrivate | 
| 75 | { | 
| 76 |     Q_DECLARE_PUBLIC(QWaylandQuickItem) | 
| 77 | public: | 
| 78 |     QWaylandQuickItemPrivate() = default; | 
| 79 |  | 
| 80 |     void init() | 
| 81 |     { | 
| 82 |         Q_Q(QWaylandQuickItem); | 
| 83 |         if (!mutex) | 
| 84 |             mutex = new QMutex; | 
| 85 |  | 
| 86 |         view.reset(other: new QWaylandView(q)); | 
| 87 |         q->setFlag(flag: QQuickItem::ItemHasContents); | 
| 88 |  | 
| 89 |         q->update(); | 
| 90 |  | 
| 91 |         q->setSmooth(true); | 
| 92 |  | 
| 93 |         setInputEventsEnabled(true); | 
| 94 |         QObject::connect(sender: q, signal: &QQuickItem::windowChanged, context: q, slot: &QWaylandQuickItem::updateWindow); | 
| 95 |         QObject::connect(sender: view.data(), signal: &QWaylandView::surfaceChanged, context: q, slot: &QWaylandQuickItem::surfaceChanged); | 
| 96 |         QObject::connect(sender: view.data(), signal: &QWaylandView::surfaceChanged, context: q, slot: &QWaylandQuickItem::handleSurfaceChanged); | 
| 97 |         QObject::connect(sender: view.data(), signal: &QWaylandView::surfaceDestroyed, context: q, slot: &QWaylandQuickItem::surfaceDestroyed); | 
| 98 |         QObject::connect(sender: view.data(), signal: &QWaylandView::outputChanged, context: q, slot: &QWaylandQuickItem::outputChanged); | 
| 99 |         QObject::connect(sender: view.data(), signal: &QWaylandView::outputChanged, context: q, slot: &QWaylandQuickItem::updateOutput); | 
| 100 |         QObject::connect(sender: view.data(), signal: &QWaylandView::bufferLockedChanged, context: q, slot: &QWaylandQuickItem::bufferLockedChanged); | 
| 101 |         QObject::connect(sender: view.data(), signal: &QWaylandView::allowDiscardFrontBufferChanged, context: q, slot: &QWaylandQuickItem::allowDiscardFrontBuffer); | 
| 102 |  | 
| 103 |         q->updateWindow(); | 
| 104 |     } | 
| 105 |  | 
| 106 |     static const QWaylandQuickItemPrivate* get(const QWaylandQuickItem *item) { return item->d_func(); } | 
| 107 |  | 
| 108 |     void setInputEventsEnabled(bool enable) | 
| 109 |     { | 
| 110 |         Q_Q(QWaylandQuickItem); | 
| 111 |         q->setAcceptedMouseButtons(enable ? (Qt::LeftButton | Qt::MiddleButton | Qt::RightButton | | 
| 112 |                                    Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::ExtraButton3 | Qt::ExtraButton4 | | 
| 113 |                                    Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 | | 
| 114 |                                    Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 | | 
| 115 |                                    Qt::ExtraButton12 | Qt::ExtraButton13) : Qt::NoButton); | 
| 116 |         q->setAcceptTouchEvents(enable); | 
| 117 |         q->setAcceptHoverEvents(enable); | 
| 118 |         inputEventsEnabled = enable; | 
| 119 |     } | 
| 120 |  | 
| 121 |     void handleDragEnded(QWaylandSeat *seat); | 
| 122 |     void handleDragUpdate(QWaylandSeat *seat, const QPointF &globalPosition); | 
| 123 |  | 
| 124 |     bool shouldSendInputEvents() const { return view->surface() && inputEventsEnabled; } | 
| 125 |     qreal scaleFactor() const; | 
| 126 |  | 
| 127 |     QWaylandQuickItem *findSibling(QWaylandSurface *surface) const; | 
| 128 |     void placeAboveSibling(QWaylandQuickItem *sibling); | 
| 129 |     void placeBelowSibling(QWaylandQuickItem *sibling); | 
| 130 |     void placeAboveParent(); | 
| 131 |     void placeBelowParent(); | 
| 132 |  | 
| 133 |     virtual void raise(); | 
| 134 |     virtual void lower(); | 
| 135 |  | 
| 136 |     static QMutex *mutex; | 
| 137 |  | 
| 138 |     QScopedPointer<QWaylandView> view; | 
| 139 |     QPointer<QWaylandSurface> oldSurface; | 
| 140 |     mutable QWaylandSurfaceTextureProvider *provider = nullptr; | 
| 141 |     QMetaObject::Connection texProviderConnection; | 
| 142 |     bool paintEnabled = true; | 
| 143 |     bool touchEventsEnabled = true; | 
| 144 |     bool inputEventsEnabled = true; | 
| 145 |     bool isDragging = false; | 
| 146 |     bool newTexture = false; | 
| 147 |     bool focusOnClick = true; | 
| 148 |     bool belowParent = false; | 
| 149 | #if QT_CONFIG(opengl) | 
| 150 |     bool paintByProvider = false; | 
| 151 | #endif | 
| 152 |     QPointF hoverPos; | 
| 153 |     QMatrix4x4 lastMatrix; | 
| 154 |  | 
| 155 |     QQuickWindow *connectedWindow = nullptr; | 
| 156 |     QWaylandOutput *connectedOutput = nullptr; | 
| 157 |     QWaylandSurface::Origin origin = QWaylandSurface::OriginTopLeft; | 
| 158 |     QPointer<QObject> subsurfaceHandler; | 
| 159 |     QList<QWaylandSeat *> touchingSeats; | 
| 160 | }; | 
| 161 |  | 
| 162 | QT_END_NAMESPACE | 
| 163 |  | 
| 164 | #endif  /*QWAYLANDQUICKITEM_P_H*/ | 
| 165 |  |