aboutsummaryrefslogtreecommitdiffstats
path: root/src/effects/qquickmultieffect_p_p.h
blob: 7d635e2e254d4154220493c90a8285e613b81e6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QQUICKMULTIEFFECT_P_P_H
#define QQUICKMULTIEFFECT_P_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <private/qtquickglobal_p.h>

QT_REQUIRE_CONFIG(quick_shadereffect);

#include <private/qquickmultieffect_p.h>
#include <private/qquickitem_p.h>
#include <private/qgfxsourceproxy_p.h>
#include <QtCore/qvector.h>

QT_BEGIN_NAMESPACE

class QQuickShaderEffect;
class QQuickShaderEffectSource;

class QQuickMultiEffectPrivate : public QQuickItemPrivate
{
    Q_DECLARE_PUBLIC(QQuickMultiEffect)

public:
    QQuickMultiEffectPrivate();
    ~QQuickMultiEffectPrivate();

    QQuickItem *source() const;
    void setSource(QQuickItem *item);

    bool autoPaddingEnabled() const;
    void setAutoPaddingEnabled(bool enabled);

    QRectF paddingRect() const;
    void setPaddingRect(const QRectF &rect);

    qreal brightness() const;
    void setBrightness(qreal brightness);

    qreal contrast() const;
    void setContrast(qreal contrast);

    qreal saturation() const;
    void setSaturation(qreal saturation);

    qreal colorization() const;
    void setColorization(qreal colorization);

    QColor colorizationColor() const;
    void setColorizationColor(const QColor &color);

    bool blurEnabled() const;
    void setBlurEnabled(bool enabled);

    qreal blur() const;
    void setBlur(qreal blur);

    int blurMax() const;
    void setBlurMax(int blurMax);

    qreal blurMultiplier() const;
    void setBlurMultiplier(qreal blurMultiplier);

    bool shadowEnabled() const;
    void setShadowEnabled(bool enabled);

    qreal shadowOpacity() const;
    void setShadowOpacity(qreal shadowOpacity);

    qreal shadowBlur() const;
    void setShadowBlur(qreal shadowBlur);

    qreal shadowHorizontalOffset() const;
    void setShadowHorizontalOffset(qreal offset);

    qreal shadowVerticalOffset() const;
    void setShadowVerticalOffset(qreal offset);

    QColor shadowColor() const;
    void setShadowColor(const QColor &color);

    qreal shadowScale() const;
    void setShadowScale(qreal shadowScale);

    bool maskEnabled() const;
    void setMaskEnabled(bool enabled);

    QQuickItem *maskSource() const;
    void setMaskSource(QQuickItem *item);

    qreal maskThresholdMin() const;
    void setMaskThresholdMin(qreal threshold);

    qreal maskSpreadAtMin() const;
    void setMaskSpreadAtMin(qreal spread);

    qreal maskThresholdMax() const;
    void setMaskThresholdMax(qreal threshold);

    qreal maskSpreadAtMax() const;
    void setMaskSpreadAtMax(qreal spread);

    bool maskInverted() const;
    void setMaskInverted(bool inverted);

    QRectF itemRect() const;
    QString fragmentShader() const;
    QString vertexShader() const;
    bool hasProxySource() const;

    void handleGeometryChange(const QRectF &newGeometry, const QRectF &oldGeometry);
    void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value);
    void initialize();
    void updateMaskThresholdSpread();
    void updateCenterOffset();
    void updateShadowOffset();
    void updateColorizationColor();
    void updateShadowColor();
    float calculateLod(float blurAmount);
    float blurWeight(float v);
    void getBlurWeights(float blurLod, QVector4D &blurWeight1, QVector2D &blurWeight2);
    void updateBlurWeights();
    void updateShadowBlurWeights();
    void updateBlurItemSizes(bool forceUpdate = false);
    void updateEffectShaders();
    void updateBlurLevel(bool forceUpdate = false);
    void updateBlurItemsAmount(int blurLevel);
    void updateSourcePadding();
    void updateProxyActiveCheck();
    void proxyOutputChanged();

private:
    bool m_initialized = false;
    QQuickItem *m_sourceItem = nullptr;
    QGfxSourceProxy *m_shaderSource = nullptr;
    QQuickShaderEffect *m_shaderEffect = nullptr;
    QQuickShaderEffectSource *m_dummyShaderSource = nullptr;
    QVector<QQuickShaderEffect *> m_blurEffects;
    bool m_autoPaddingEnabled = true;
    QRectF m_paddingRect;
    qreal m_brightness = 0.0;
    qreal m_contrast = 0.0;
    qreal m_saturation = 0.0;
    qreal m_colorization = 0.0;
    QColor m_colorizationColor = { 255, 0, 0, 255 };
    bool m_blurEnabled = false;
    qreal m_blur = 0.0;
    int m_blurMax = 32;
    qreal m_blurMultiplier = 0.0;
    bool m_shadowEnabled = false;
    qreal m_shadowOpacity = 1.0;
    qreal m_shadowBlur = 1.0;
    qreal m_shadowHorizontalOffset = 0.0;
    qreal m_shadowVerticalOffset = 0.0;
    QColor m_shadowColor = { 0, 0, 0, 255 };
    qreal m_shadowScale = 1.0;
    bool m_maskEnabled = false;
    QQuickItem *m_maskSourceItem = nullptr;
    qreal m_maskThresholdMin = 0.0;
    qreal m_maskSpreadAtMin = 0.0;
    qreal m_maskThresholdMax = 1.0;
    qreal m_maskSpreadAtMax = 0.0;
    bool m_maskInverted = false;

    int m_blurLevel = 0;
    QString m_vertShader;
    QString m_fragShader;
    QSizeF m_firstBlurItemSize;

    QVector4D m_blurWeight1;
    QVector2D m_blurWeight2;
    QVector4D m_shadowBlurWeight1;
    QVector2D m_shadowBlurWeight2;
};



QT_END_NAMESPACE

#endif // QQUICKMULTIEFFECT_P_P_H