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