1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
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 Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QQUICKSHADEREFFECTSOURCE_P_H
41#define QQUICKSHADEREFFECTSOURCE_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <QtQuick/private/qtquickglobal_p.h>
55
56QT_REQUIRE_CONFIG(quick_shadereffect);
57
58#include "qquickitem.h"
59#include <QtQuick/qsgtextureprovider.h>
60#include <private/qsgadaptationlayer_p.h>
61#include <QtQuick/private/qsgcontext_p.h>
62#include <private/qsgdefaultinternalimagenode_p.h>
63#include <private/qquickitemchangelistener_p.h>
64
65#include "qpointer.h"
66#include "qsize.h"
67#include "qrect.h"
68
69QT_BEGIN_NAMESPACE
70
71class QSGNode;
72class UpdatePaintNodeData;
73class QOpenGLFramebufferObject;
74class QSGSimpleRectNode;
75
76class QQuickShaderEffectSourceTextureProvider;
77
78class Q_QUICK_PRIVATE_EXPORT QQuickShaderEffectSource : public QQuickItem, public QQuickItemChangeListener
79{
80 Q_OBJECT
81 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
82 Q_PROPERTY(QQuickItem *sourceItem READ sourceItem WRITE setSourceItem NOTIFY sourceItemChanged)
83 Q_PROPERTY(QRectF sourceRect READ sourceRect WRITE setSourceRect NOTIFY sourceRectChanged)
84 Q_PROPERTY(QSize textureSize READ textureSize WRITE setTextureSize NOTIFY textureSizeChanged)
85 Q_PROPERTY(Format format READ format WRITE setFormat NOTIFY formatChanged)
86 Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged)
87 Q_PROPERTY(bool hideSource READ hideSource WRITE setHideSource NOTIFY hideSourceChanged)
88 Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged)
89 Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged)
90 Q_PROPERTY(TextureMirroring textureMirroring READ textureMirroring WRITE setTextureMirroring NOTIFY textureMirroringChanged REVISION 6)
91 Q_PROPERTY(int samples READ samples WRITE setSamples NOTIFY samplesChanged REVISION 9)
92 QML_NAMED_ELEMENT(ShaderEffectSource)
93
94public:
95 enum WrapMode {
96 ClampToEdge,
97 RepeatHorizontally,
98 RepeatVertically,
99 Repeat
100 };
101 Q_ENUM(WrapMode)
102 // Equivalents to GL_ALPHA and similar type constants.
103 enum Format {
104 Alpha = 0x1906,
105 RGB = 0x1907,
106 RGBA = 0x1908
107 };
108 Q_ENUM(Format)
109
110 enum TextureMirroring {
111 NoMirroring = 0x00,
112 MirrorHorizontally = 0x01,
113 MirrorVertically = 0x02
114 };
115 Q_ENUM(TextureMirroring)
116
117 QQuickShaderEffectSource(QQuickItem *parent = nullptr);
118 ~QQuickShaderEffectSource() override;
119
120 WrapMode wrapMode() const;
121 void setWrapMode(WrapMode mode);
122
123 QQuickItem *sourceItem() const;
124 void setSourceItem(QQuickItem *item);
125
126 QRectF sourceRect() const;
127 void setSourceRect(const QRectF &rect);
128
129 QSize textureSize() const;
130 void setTextureSize(const QSize &size);
131
132 Format format() const;
133 void setFormat(Format format);
134
135 bool live() const;
136 void setLive(bool live);
137
138 bool hideSource() const;
139 void setHideSource(bool hide);
140
141 bool mipmap() const;
142 void setMipmap(bool enabled);
143
144 bool recursive() const;
145 void setRecursive(bool enabled);
146
147 TextureMirroring textureMirroring() const;
148 void setTextureMirroring(TextureMirroring mirroring);
149
150 bool isTextureProvider() const override { return true; }
151 QSGTextureProvider *textureProvider() const override;
152
153 Q_INVOKABLE void scheduleUpdate();
154
155 int samples() const;
156 void setSamples(int count);
157
158Q_SIGNALS:
159 void wrapModeChanged();
160 void sourceItemChanged();
161 void sourceRectChanged();
162 void textureSizeChanged();
163 void formatChanged();
164 void liveChanged();
165 void hideSourceChanged();
166 void mipmapChanged();
167 void recursiveChanged();
168 void textureMirroringChanged();
169 void samplesChanged();
170
171 void scheduledUpdateCompleted();
172
173private Q_SLOTS:
174 void sourceItemDestroyed(QObject *item);
175 void invalidateSceneGraph();
176
177protected:
178 void releaseResources() override;
179 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
180
181 void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) override;
182 void itemChange(ItemChange change, const ItemChangeData &value) override;
183
184private:
185 void ensureTexture();
186
187 QQuickShaderEffectSourceTextureProvider *m_provider;
188 QSGLayer *m_texture;
189 WrapMode m_wrapMode;
190 QQuickItem *m_sourceItem;
191 QRectF m_sourceRect;
192 QSize m_textureSize;
193 Format m_format;
194 int m_samples;
195 uint m_live : 1;
196 uint m_hideSource : 1;
197 uint m_mipmap : 1;
198 uint m_recursive : 1;
199 uint m_grab : 1;
200 uint m_textureMirroring : 2; // Stores TextureMirroring enum
201};
202
203QT_END_NAMESPACE
204
205#endif // QQUICKSHADEREFFECTSOURCE_P_H
206

source code of qtdeclarative/src/quick/items/qquickshadereffectsource_p.h