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
25QT_BEGIN_NAMESPACE
26
27class QWaylandSurfaceTextureProvider;
28class QMutex;
29class QOpenGLTexture;
30
31#if QT_CONFIG(opengl)
32class QWaylandBufferMaterialShader : public QSGMaterialShader
33{
34public:
35 QWaylandBufferMaterialShader(QWaylandBufferRef::BufferFormatEgl format);
36
37 bool updateUniformData(RenderState &state,
38 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
39 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
40 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
41 void setupExternalOESShader(const QString &shaderFilename);
42};
43
44class QWaylandBufferMaterial : public QSGMaterial
45{
46public:
47 QWaylandBufferMaterial(QWaylandBufferRef::BufferFormatEgl format);
48 ~QWaylandBufferMaterial() override;
49
50 void setTextureForPlane(int plane, QOpenGLTexture *texture, QSGTexture *scenegraphTexture);
51 void setBufferRef(QWaylandQuickItem *surfaceItem, const QWaylandBufferRef &ref);
52
53 void bind();
54 void updateScenegraphTextures(QRhi *rhi);
55
56 QSGMaterialType *type() const override;
57 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
58
59private:
60 friend QWaylandBufferMaterialShader;
61
62 void setTextureParameters(GLenum target);
63 void ensureTextures(int count);
64
65 const QWaylandBufferRef::BufferFormatEgl m_format;
66 QVarLengthArray<QOpenGLTexture*, 3> m_textures;
67 QVarLengthArray<QSGTexture*, 3> m_scenegraphTextures;
68 QWaylandBufferRef m_bufferRef;
69};
70#endif // QT_CONFIG(opengl)
71
72class QWaylandQuickItemPrivate : public QQuickItemPrivate
73{
74 Q_DECLARE_PUBLIC(QWaylandQuickItem)
75public:
76 QWaylandQuickItemPrivate() = default;
77
78 void init()
79 {
80 Q_Q(QWaylandQuickItem);
81 if (!mutex)
82 mutex = new QMutex;
83
84 view.reset(other: new QWaylandView(q));
85 q->setFlag(flag: QQuickItem::ItemHasContents);
86
87 q->update();
88
89 q->setSmooth(true);
90
91 setInputEventsEnabled(true);
92 QObject::connect(sender: q, signal: &QQuickItem::windowChanged, context: q, slot: &QWaylandQuickItem::updateWindow);
93 QObject::connect(sender: view.data(), signal: &QWaylandView::surfaceChanged, context: q, slot: &QWaylandQuickItem::surfaceChanged);
94 QObject::connect(sender: view.data(), signal: &QWaylandView::surfaceChanged, context: q, slot: &QWaylandQuickItem::handleSurfaceChanged);
95 QObject::connect(sender: view.data(), signal: &QWaylandView::surfaceDestroyed, context: q, slot: &QWaylandQuickItem::surfaceDestroyed);
96 QObject::connect(sender: view.data(), signal: &QWaylandView::outputChanged, context: q, slot: &QWaylandQuickItem::outputChanged);
97 QObject::connect(sender: view.data(), signal: &QWaylandView::outputChanged, context: q, slot: &QWaylandQuickItem::updateOutput);
98 QObject::connect(sender: view.data(), signal: &QWaylandView::bufferLockedChanged, context: q, slot: &QWaylandQuickItem::bufferLockedChanged);
99 QObject::connect(sender: view.data(), signal: &QWaylandView::allowDiscardFrontBufferChanged, context: q, slot: &QWaylandQuickItem::allowDiscardFrontBuffer);
100
101 q->updateWindow();
102 }
103
104 static const QWaylandQuickItemPrivate* get(const QWaylandQuickItem *item) { return item->d_func(); }
105
106 void setInputEventsEnabled(bool enable)
107 {
108 Q_Q(QWaylandQuickItem);
109 q->setAcceptedMouseButtons(enable ? (Qt::LeftButton | Qt::MiddleButton | Qt::RightButton |
110 Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::ExtraButton3 | Qt::ExtraButton4 |
111 Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 |
112 Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 |
113 Qt::ExtraButton12 | Qt::ExtraButton13) : Qt::NoButton);
114 q->setAcceptTouchEvents(enable);
115 q->setAcceptHoverEvents(enable);
116 inputEventsEnabled = enable;
117 }
118
119 bool shouldSendInputEvents() const { return view->surface() && inputEventsEnabled; }
120 qreal scaleFactor() const;
121
122 QWaylandQuickItem *findSibling(QWaylandSurface *surface) const;
123 void placeAboveSibling(QWaylandQuickItem *sibling);
124 void placeBelowSibling(QWaylandQuickItem *sibling);
125 void placeAboveParent();
126 void placeBelowParent();
127
128 virtual void raise();
129 virtual void lower();
130
131 static QMutex *mutex;
132
133 QScopedPointer<QWaylandView> view;
134 QPointer<QWaylandSurface> oldSurface;
135 mutable QWaylandSurfaceTextureProvider *provider = nullptr;
136 QMetaObject::Connection texProviderConnection;
137 bool paintEnabled = true;
138 bool touchEventsEnabled = true;
139 bool inputEventsEnabled = true;
140 bool isDragging = false;
141 bool newTexture = false;
142 bool focusOnClick = true;
143 bool belowParent = false;
144#if QT_CONFIG(opengl)
145 bool paintByProvider = false;
146#endif
147 QPointF hoverPos;
148 QMatrix4x4 lastMatrix;
149
150 QQuickWindow *connectedWindow = nullptr;
151 QWaylandOutput *connectedOutput = nullptr;
152 QWaylandSurface::Origin origin = QWaylandSurface::OriginTopLeft;
153 QPointer<QObject> subsurfaceHandler;
154 QList<QWaylandSeat *> touchingSeats;
155};
156
157QT_END_NAMESPACE
158
159#endif /*QWAYLANDQUICKITEM_P_H*/
160

source code of qtwayland/src/compositor/compositor_api/qwaylandquickitem_p.h