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 QtWaylandCompositor 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 QWAYLANDQUICKITEM_P_H
31#define QWAYLANDQUICKITEM_P_H
32
33//
34// W A R N I N G
35// -------------
36//
37// This file is not part of the Qt API. It exists purely as an
38// implementation detail. This header file may change from version to
39// version without notice, or even be removed.
40//
41// We mean it.
42//
43
44#include <QtQuick/private/qquickitem_p.h>
45#include <QtQuick/QSGMaterialShader>
46#include <QtQuick/QSGMaterial>
47
48#include <QtWaylandCompositor/QWaylandQuickItem>
49#include <QtWaylandCompositor/QWaylandOutput>
50
51QT_BEGIN_NAMESPACE
52
53class QWaylandSurfaceTextureProvider;
54class QMutex;
55class QOpenGLTexture;
56
57#if QT_CONFIG(opengl)
58class QWaylandBufferMaterialShader : public QSGMaterialShader
59{
60public:
61 QWaylandBufferMaterialShader(QWaylandBufferRef::BufferFormatEgl format);
62
63 void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;
64 char const *const *attributeNames() const override;
65
66protected:
67 void initialize() override;
68
69private:
70 const QWaylandBufferRef::BufferFormatEgl m_format;
71 int m_id_matrix;
72 int m_id_opacity;
73 QVarLengthArray<int, 3> m_id_tex;
74};
75
76class QWaylandBufferMaterial : public QSGMaterial
77{
78public:
79 QWaylandBufferMaterial(QWaylandBufferRef::BufferFormatEgl format);
80 ~QWaylandBufferMaterial() override;
81
82 void setTextureForPlane(int plane, QOpenGLTexture *texture);
83 void setBufferRef(QWaylandQuickItem *surfaceItem, const QWaylandBufferRef &ref);
84
85 void bind();
86
87 QSGMaterialType *type() const override;
88 QSGMaterialShader *createShader() const override;
89
90private:
91 void setTextureParameters(GLenum target);
92 void ensureTextures(int count);
93
94 const QWaylandBufferRef::BufferFormatEgl m_format;
95 QVarLengthArray<QOpenGLTexture*, 3> m_textures;
96 QWaylandBufferRef m_bufferRef;
97};
98#endif // QT_CONFIG(opengl)
99
100class QWaylandQuickItemPrivate : public QQuickItemPrivate
101{
102 Q_DECLARE_PUBLIC(QWaylandQuickItem)
103public:
104 QWaylandQuickItemPrivate() = default;
105
106 void init()
107 {
108 Q_Q(QWaylandQuickItem);
109 if (!mutex)
110 mutex = new QMutex;
111
112 view.reset(other: new QWaylandView(q));
113 q->setFlag(flag: QQuickItem::ItemHasContents);
114
115 q->update();
116
117 q->setSmooth(true);
118
119 setInputEventsEnabled(true);
120 QObject::connect(sender: q, signal: &QQuickItem::windowChanged, receiver: q, slot: &QWaylandQuickItem::updateWindow);
121 QObject::connect(sender: view.data(), signal: &QWaylandView::surfaceChanged, receiver: q, slot: &QWaylandQuickItem::surfaceChanged);
122 QObject::connect(sender: view.data(), signal: &QWaylandView::surfaceChanged, receiver: q, slot: &QWaylandQuickItem::handleSurfaceChanged);
123 QObject::connect(sender: view.data(), signal: &QWaylandView::surfaceDestroyed, receiver: q, slot: &QWaylandQuickItem::surfaceDestroyed);
124 QObject::connect(sender: view.data(), signal: &QWaylandView::outputChanged, receiver: q, slot: &QWaylandQuickItem::outputChanged);
125 QObject::connect(sender: view.data(), signal: &QWaylandView::outputChanged, receiver: q, slot: &QWaylandQuickItem::updateOutput);
126 QObject::connect(sender: view.data(), signal: &QWaylandView::bufferLockedChanged, receiver: q, slot: &QWaylandQuickItem::bufferLockedChanged);
127 QObject::connect(sender: view.data(), signal: &QWaylandView::allowDiscardFrontBufferChanged, receiver: q, slot: &QWaylandQuickItem::allowDiscardFrontBuffer);
128
129 q->updateWindow();
130 }
131
132 static const QWaylandQuickItemPrivate* get(const QWaylandQuickItem *item) { return item->d_func(); }
133
134 void setInputEventsEnabled(bool enable)
135 {
136 Q_Q(QWaylandQuickItem);
137 q->setAcceptedMouseButtons(enable ? (Qt::LeftButton | Qt::MiddleButton | Qt::RightButton |
138 Qt::ExtraButton1 | Qt::ExtraButton2 | Qt::ExtraButton3 | Qt::ExtraButton4 |
139 Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 |
140 Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 |
141 Qt::ExtraButton12 | Qt::ExtraButton13) : Qt::NoButton);
142 q->setAcceptHoverEvents(enable);
143 inputEventsEnabled = enable;
144 }
145
146 bool shouldSendInputEvents() const { return view->surface() && inputEventsEnabled; }
147 qreal scaleFactor() const;
148
149 QWaylandQuickItem *findSibling(QWaylandSurface *surface) const;
150 void placeAboveSibling(QWaylandQuickItem *sibling);
151 void placeBelowSibling(QWaylandQuickItem *sibling);
152 void placeAboveParent();
153 void placeBelowParent();
154
155 static QMutex *mutex;
156
157 QScopedPointer<QWaylandView> view;
158 QPointer<QWaylandSurface> oldSurface;
159 mutable QWaylandSurfaceTextureProvider *provider = nullptr;
160 bool paintEnabled = true;
161 bool touchEventsEnabled = true;
162 bool inputEventsEnabled = true;
163 bool isDragging = false;
164 bool newTexture = false;
165 bool focusOnClick = true;
166 bool sizeFollowsSurface = true;
167 bool belowParent = false;
168 QPointF hoverPos;
169 QMatrix4x4 lastMatrix;
170
171 QQuickWindow *connectedWindow = nullptr;
172 QWaylandOutput *connectedOutput = nullptr;
173 QWaylandSurface::Origin origin = QWaylandSurface::OriginTopLeft;
174 QPointer<QObject> subsurfaceHandler;
175 QVector<QWaylandSeat *> touchingSeats;
176};
177
178QT_END_NAMESPACE
179
180#endif /*QWAYLANDQUICKITEM_P_H*/
181

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