DtkDeclarative
DTK Declarative module
载入中...
搜索中...
未找到
dblurimagenode_p.h
1// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DSOFTWAREBLURIMAGENODE_H
6#define DSOFTWAREBLURIMAGENODE_H
7
8#include <dtkdeclarative_global.h>
9#include <QSGRenderNode>
10#include <QImage>
11#include <QPointer>
12#ifndef QT_NO_OPENGL
13#include <qopengl.h>
14#endif
15
16QT_BEGIN_NAMESPACE
17class QQuickItem;
18class QSGTexture;
19class QSGPlainTexture;
20class QQuickWindow;
21#ifndef QT_NO_OPENGL
22class QOpenGLShaderProgram;
23class QOpenGLFramebufferObject;
24class QOpenGLBuffer;
25#endif
26QT_END_NAMESPACE
27
28DQUICK_BEGIN_NAMESPACE
29
30class DSGBlurNode : public QSGRenderNode
31{
32public:
33 DSGBlurNode(QQuickItem *owner);
34
35 typedef void(*RenderCallback)(DSGBlurNode *node, void *data);
36 void setRenderCallback(RenderCallback callback, void *data);
37 inline void doRenderCallback() {
38 if (!m_renderCallback)
39 return;
40 m_renderCallback(this, m_callbackData);
41 }
42
43 inline void setOffscreen(bool offscreen) {
44 if (m_offscreen == offscreen)
45 return;
46 m_offscreen = offscreen;
47 markDirty(DirtyMaterial);
48 }
49
50 virtual void setTexture(QSGTexture *texture);
51 inline QSGTexture *texture() const
52 { return m_texture;}
53 virtual bool writeToTexture(QSGPlainTexture *targetTexture) const;
54 virtual void setRadius(qreal radius);
55 void setSourceRect(const QRectF &source);
56 void setRect(const QRectF &target);
57 void setDisabledOpaqueRendering(bool disabled);
58 void setBlendColor(const QColor &color);
59 void setFollowMatrixForSource(bool on);
60
61 RenderingFlags flags() const override;
62 QRectF rect() const override;
63 void setWindow(QQuickWindow *window);
64
65protected:
66 RenderCallback m_renderCallback = nullptr;
67 void *m_callbackData = nullptr;
68 bool m_offscreen = false;
69
70 QPointer<QQuickItem> m_item;
71 QSGTexture *m_texture = nullptr;
72 qreal m_radius = 0;
73 QRectF m_sourceRect;
74 QRectF m_targetRect;
75 QColor m_blendColor = Qt::transparent;
76 bool m_disabledOpaqueRendering = false;
77 bool m_followMatrixForSource = false;
78 QPointer<QQuickWindow> m_window;
79};
80
82{
83public:
84 DSoftwareBlurImageNode(QQuickItem *owner);
85
86private:
87 void render(const RenderState *state) override;
88 void releaseResources() override;
89 void updateCachedImage();
90 bool writeToTexture(QSGPlainTexture *targetTexture) const override;
91
92 QImage cachedSource;
93};
94
95#ifndef QT_NO_OPENGL
97{
98public:
99 DOpenGLBlurEffectNode(QQuickItem *owner);
100 ~DOpenGLBlurEffectNode() override;
101
102 void setTexture(QSGTexture *texture) override;
103 void setRadius(qreal radius) override;
104
105 void render(const RenderState *state) override;
106 StateFlags changedStates() const override;
107
108private:
109 bool writeToTexture(QSGPlainTexture *targetTexture) const override;
110
111 void initialize();
112 void initBlurSahder();
113 void applyDaulBlur(QOpenGLFramebufferObject* targetFBO, GLuint sourceTexture, QOpenGLShaderProgram *shader
114 , const QSGRenderNode::RenderState *state, int matrixUniform, int scale);
115 void applyNoise(GLuint sourceTexture, const QSGRenderNode::RenderState *state);
116 void renderToScreen(GLuint sourceTexture, const QSGRenderNode::RenderState *state);
117 void initFBOTextures();
118 void initDispalyShader();
119 void initNoiseShader();
120
121private:
122 bool m_needUpdateFBO = false;
123
124 QOpenGLShaderProgram *m_programKawaseUp = nullptr;
125 QOpenGLShaderProgram *m_programKawaseDown = nullptr;
126 QVector<QOpenGLFramebufferObject*> m_fboVector;
127 int m_matrixKawaseUpUniform;
128 int m_matrixKawaseDownUniform;
129 QOpenGLBuffer *m_sampleVbo = nullptr;
130
131 QOpenGLShaderProgram *m_program = nullptr;
132 int m_matrixUniform;
133 int m_opacityUniform;
134 QOpenGLBuffer *m_vbo = nullptr;
135
136 QOpenGLShaderProgram *m_programNoise = nullptr;
137 QOpenGLBuffer *m_noiseVbo = nullptr;
138};
139#endif
140
141DQUICK_END_NAMESPACE
142
143#endif // DSOFTWAREBLURIMAGENODE_H
Definition dblurimagenode_p.h:97
Definition dblurimagenode_p.h:31
Definition dblurimagenode_p.h:82