Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | static const char qglslDefaultImageFragmentShader[] = " lowp vec4 customShader(lowp sampler2D imageTexture, highp vec2 textureCoords) { return texture2D(imageTexture, textureCoords); }\n"; | - |
5 | | - |
6 | | - |
7 | | - |
8 | | - |
9 | | - |
10 | | - |
11 | class QGLCustomShaderEffectStage : public QGLCustomShaderStage | - |
12 | { | - |
13 | public: | - |
14 | QGLCustomShaderEffectStage | - |
15 | (QGraphicsShaderEffect *e, const QByteArray& source) | - |
16 | : QGLCustomShaderStage(), | - |
17 | effect(e) | - |
18 | { | - |
19 | setSource(source); | - |
20 | } | 0 |
21 | | - |
22 | void setUniforms(QGLShaderProgram *program); | - |
23 | | - |
24 | QGraphicsShaderEffect *effect; | - |
25 | }; | - |
26 | | - |
27 | void QGLCustomShaderEffectStage::setUniforms(QGLShaderProgram *program) | - |
28 | { | - |
29 | effect->setUniforms(program); | - |
30 | } | 0 |
31 | | - |
32 | | - |
33 | | - |
34 | class QGraphicsShaderEffectPrivate : public QGraphicsEffectPrivate | - |
35 | { | - |
36 | inline QGraphicsShaderEffect* q_func() { return static_cast<QGraphicsShaderEffect *>(q_ptr); } inline const QGraphicsShaderEffect* q_func() const { return static_cast<const QGraphicsShaderEffect *>(q_ptr); } friend class QGraphicsShaderEffect; | - |
37 | public: | - |
38 | QGraphicsShaderEffectPrivate() | - |
39 | : pixelShaderFragment(qglslDefaultImageFragmentShader) | - |
40 | | - |
41 | , customShaderStage(0) | - |
42 | | - |
43 | { | - |
44 | } | 0 |
45 | | - |
46 | QByteArray pixelShaderFragment; | - |
47 | | - |
48 | QGLCustomShaderEffectStage *customShaderStage; | - |
49 | | - |
50 | }; | - |
51 | | - |
52 | | - |
53 | | - |
54 | | - |
55 | QGraphicsShaderEffect::QGraphicsShaderEffect(QObject *parent) | - |
56 | : QGraphicsEffect(*new QGraphicsShaderEffectPrivate(), parent) | - |
57 | { | - |
58 | } | 0 |
59 | | - |
60 | | - |
61 | | - |
62 | | - |
63 | QGraphicsShaderEffect::~QGraphicsShaderEffect() | - |
64 | { | - |
65 | | - |
66 | QGraphicsShaderEffectPrivate * const d = d_func(); | - |
67 | delete d->customShaderStage; | - |
68 | | - |
69 | } | 0 |
70 | QByteArray QGraphicsShaderEffect::pixelShaderFragment() const | - |
71 | { | - |
72 | const QGraphicsShaderEffectPrivate * const d = d_func(); | - |
73 | return d->pixelShaderFragment; never executed: return d->pixelShaderFragment; | 0 |
74 | } | - |
75 | void QGraphicsShaderEffect::setPixelShaderFragment(const QByteArray& code) | - |
76 | { | - |
77 | QGraphicsShaderEffectPrivate * const d = d_func(); | - |
78 | if (d->pixelShaderFragment != code) { never evaluated: d->pixelShaderFragment != code | 0 |
79 | d->pixelShaderFragment = code; | - |
80 | | - |
81 | delete d->customShaderStage; | - |
82 | d->customShaderStage = 0; | - |
83 | | - |
84 | } | 0 |
85 | } | 0 |
86 | | - |
87 | | - |
88 | | - |
89 | | - |
90 | void QGraphicsShaderEffect::draw(QPainter *painter) | - |
91 | { | - |
92 | QGraphicsShaderEffectPrivate * const d = d_func(); | - |
93 | | - |
94 | | - |
95 | | - |
96 | | - |
97 | | - |
98 | if (!d->customShaderStage) { never evaluated: !d->customShaderStage | 0 |
99 | d->customShaderStage = new QGLCustomShaderEffectStage | - |
100 | (this, d->pixelShaderFragment); | - |
101 | } | 0 |
102 | bool usingShader = d->customShaderStage->setOnPainter(painter); | - |
103 | | - |
104 | QPoint offset; | - |
105 | if (sourceIsPixmap()) { never evaluated: sourceIsPixmap() | 0 |
106 | | - |
107 | const QPixmap pixmap = sourcePixmap(Qt::LogicalCoordinates, &offset); | - |
108 | painter->drawPixmap(offset, pixmap); | - |
109 | } else { | 0 |
110 | | - |
111 | const QPixmap pixmap = sourcePixmap(Qt::DeviceCoordinates, &offset); | - |
112 | QTransform restoreTransform = painter->worldTransform(); | - |
113 | painter->setWorldTransform(QTransform()); | - |
114 | painter->drawPixmap(offset, pixmap); | - |
115 | painter->setWorldTransform(restoreTransform); | - |
116 | } | 0 |
117 | | - |
118 | | - |
119 | if (usingShader) never evaluated: usingShader | 0 |
120 | d->customShaderStage->removeFromPainter(painter); never executed: d->customShaderStage->removeFromPainter(painter); | 0 |
121 | | - |
122 | | - |
123 | | - |
124 | } | 0 |
125 | void QGraphicsShaderEffect::setUniformsDirty() | - |
126 | { | - |
127 | | - |
128 | QGraphicsShaderEffectPrivate * const d = d_func(); | - |
129 | if (d->customShaderStage) never evaluated: d->customShaderStage | 0 |
130 | d->customShaderStage->setUniformsDirty(); never executed: d->customShaderStage->setUniformsDirty(); | 0 |
131 | | - |
132 | } | 0 |
133 | void QGraphicsShaderEffect::setUniforms(QGLShaderProgram *program) | - |
134 | { | - |
135 | (void)program;; | - |
136 | } | 0 |
137 | | - |
138 | | - |
139 | | - |
| | |