1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKMULTIEFFECT_P_P_H
5#define QQUICKMULTIEFFECT_P_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 <private/qtquickglobal_p.h>
19
20QT_REQUIRE_CONFIG(quick_shadereffect);
21
22#include <private/qquickmultieffect_p.h>
23#include <private/qquickitem_p.h>
24#include <private/qgfxsourceproxy_p.h>
25#include <QtCore/qvector.h>
26
27QT_BEGIN_NAMESPACE
28
29class QQuickShaderEffect;
30
31class QQuickMultiEffectPrivate : public QQuickItemPrivate
32{
33 Q_DECLARE_PUBLIC(QQuickMultiEffect)
34
35public:
36 QQuickMultiEffectPrivate();
37 ~QQuickMultiEffectPrivate();
38
39 QQuickItem *source() const;
40 void setSource(QQuickItem *item);
41
42 bool autoPaddingEnabled() const;
43 void setAutoPaddingEnabled(bool enabled);
44
45 QRectF paddingRect() const;
46 void setPaddingRect(const QRectF &rect);
47
48 qreal brightness() const;
49 void setBrightness(qreal brightness);
50
51 qreal contrast() const;
52 void setContrast(qreal contrast);
53
54 qreal saturation() const;
55 void setSaturation(qreal saturation);
56
57 qreal colorization() const;
58 void setColorization(qreal colorization);
59
60 QColor colorizationColor() const;
61 void setColorizationColor(const QColor &color);
62
63 bool blurEnabled() const;
64 void setBlurEnabled(bool enabled);
65
66 qreal blur() const;
67 void setBlur(qreal blur);
68
69 int blurMax() const;
70 void setBlurMax(int blurMax);
71
72 qreal blurMultiplier() const;
73 void setBlurMultiplier(qreal blurMultiplier);
74
75 bool shadowEnabled() const;
76 void setShadowEnabled(bool enabled);
77
78 qreal shadowOpacity() const;
79 void setShadowOpacity(qreal shadowOpacity);
80
81 qreal shadowBlur() const;
82 void setShadowBlur(qreal shadowBlur);
83
84 qreal shadowHorizontalOffset() const;
85 void setShadowHorizontalOffset(qreal offset);
86
87 qreal shadowVerticalOffset() const;
88 void setShadowVerticalOffset(qreal offset);
89
90 QColor shadowColor() const;
91 void setShadowColor(const QColor &color);
92
93 qreal shadowScale() const;
94 void setShadowScale(qreal shadowScale);
95
96 bool maskEnabled() const;
97 void setMaskEnabled(bool enabled);
98
99 QQuickItem *maskSource() const;
100 void setMaskSource(QQuickItem *item);
101
102 qreal maskThresholdMin() const;
103 void setMaskThresholdMin(qreal threshold);
104
105 qreal maskSpreadAtMin() const;
106 void setMaskSpreadAtMin(qreal spread);
107
108 qreal maskThresholdMax() const;
109 void setMaskThresholdMax(qreal threshold);
110
111 qreal maskSpreadAtMax() const;
112 void setMaskSpreadAtMax(qreal spread);
113
114 bool maskInverted() const;
115 void setMaskInverted(bool inverted);
116
117 QRectF itemRect() const;
118 QString fragmentShader() const;
119 QString vertexShader() const;
120 bool hasProxySource() const;
121
122 void handleGeometryChange(const QRectF &newGeometry, const QRectF &oldGeometry);
123 void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value);
124 void initialize();
125 void updateMaskThresholdSpread();
126 void updateCenterOffset();
127 void updateShadowOffset();
128 void updateColorizationColor();
129 void updateShadowColor();
130 float calculateLod(float blurAmount);
131 float blurWeight(float v);
132 void getBlurWeights(float blurLod, QVector4D &blurWeight1, QVector2D &blurWeight2);
133 void updateBlurWeights();
134 void updateShadowBlurWeights();
135 void updateBlurItemSizes(bool forceUpdate = false);
136 void updateEffectShaders();
137 void updateBlurLevel(bool forceUpdate = false);
138 void updateBlurItemsAmount(int blurLevel);
139 void updateSourcePadding();
140 void updateProxyActiveCheck();
141 void proxyOutputChanged();
142
143private:
144 bool m_initialized = false;
145 QQuickItem *m_sourceItem = nullptr;
146 QGfxSourceProxy *m_shaderSource = nullptr;
147 QQuickShaderEffect *m_shaderEffect = nullptr;
148 QVector<QQuickShaderEffect *> m_blurEffects;
149 bool m_autoPaddingEnabled = true;
150 QRectF m_paddingRect;
151 qreal m_brightness = 0.0;
152 qreal m_contrast = 0.0;
153 qreal m_saturation = 0.0;
154 qreal m_colorization = 0.0;
155 QColor m_colorizationColor = { 255, 0, 0, 255 };
156 bool m_blurEnabled = false;
157 qreal m_blur = 0.0;
158 int m_blurMax = 32;
159 qreal m_blurMultiplier = 0.0;
160 bool m_shadowEnabled = false;
161 qreal m_shadowOpacity = 1.0;
162 qreal m_shadowBlur = 1.0;
163 qreal m_shadowHorizontalOffset = 0.0;
164 qreal m_shadowVerticalOffset = 0.0;
165 QColor m_shadowColor = { 0, 0, 0, 255 };
166 qreal m_shadowScale = 1.0;
167 bool m_maskEnabled = false;
168 QQuickItem *m_maskSourceItem = nullptr;
169 qreal m_maskThresholdMin = 0.0;
170 qreal m_maskSpreadAtMin = 0.0;
171 qreal m_maskThresholdMax = 1.0;
172 qreal m_maskSpreadAtMax = 0.0;
173 bool m_maskInverted = false;
174
175 int m_blurLevel = 0;
176 QString m_vertShader;
177 QString m_fragShader;
178 QSizeF m_firstBlurItemSize;
179
180 QVector4D m_blurWeight1;
181 QVector2D m_blurWeight2;
182 QVector4D m_shadowBlurWeight1;
183 QVector2D m_shadowBlurWeight2;
184};
185
186
187
188QT_END_NAMESPACE
189
190#endif // QQUICKMULTIEFFECT_P_P_H
191

source code of qtdeclarative/src/effects/qquickmultieffect_p_p.h