opengl/qopenglpaintengine.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6 -
7 -
8 -
9 -
10 -
11 -
12 -
13 -
14 -
15 -
16 -
17__attribute__((visibility("default"))) QImage qt_imageForBrush(int brushStyle, bool invert); -
18 -
19 -
20 -
21QOpenGL2PaintEngineExPrivate::~QOpenGL2PaintEngineExPrivate() -
22{ -
23 delete shaderManager; -
24 -
25 while (pathCaches.size()) {
never evaluated: pathCaches.size()
0
26 QVectorPath::CacheEntry *e = *(pathCaches.constBegin()); -
27 e->cleanup(e->engine, e->data); -
28 e->data = 0; -
29 e->engine = 0; -
30 }
never executed: }
0
31 -
32 if (elementIndicesVBOId != 0) {
never evaluated: elementIndicesVBOId != 0
0
33 funcs.glDeleteBuffers(1, &elementIndicesVBOId); -
34 elementIndicesVBOId = 0; -
35 }
never executed: }
0
36}
never executed: }
0
37 -
38void QOpenGL2PaintEngineExPrivate::updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform, GLuint id) -
39{ -
40 -
41 if (id != GLuint(-1) && id == lastTextureUsed)
never evaluated: id != GLuint(-1)
never evaluated: id == lastTextureUsed
0
42 return;
never executed: return;
0
43 -
44 lastTextureUsed = id; -
45 -
46 if (smoothPixmapTransform) {
never evaluated: smoothPixmapTransform
0
47 glTexParameteri(target, 0x2800, 0x2601); -
48 glTexParameteri(target, 0x2801, 0x2601); -
49 } else {
never executed: }
0
50 glTexParameteri(target, 0x2800, 0x2600); -
51 glTexParameteri(target, 0x2801, 0x2600); -
52 }
never executed: }
0
53 glTexParameteri(target, 0x2802, wrapMode); -
54 glTexParameteri(target, 0x2803, wrapMode); -
55}
never executed: }
0
56 -
57 -
58inline QColor qt_premultiplyColor(QColor c, GLfloat opacity) -
59{ -
60 qreal alpha = c.alphaF() * opacity; -
61 c.setAlphaF(alpha); -
62 c.setRedF(c.redF() * alpha); -
63 c.setGreenF(c.greenF() * alpha); -
64 c.setBlueF(c.blueF() * alpha); -
65 return c;
never executed: return c;
0
66} -
67 -
68 -
69void QOpenGL2PaintEngineExPrivate::setBrush(const QBrush& brush) -
70{ -
71 if (qbrush_fast_equals(currentBrush, brush))
never evaluated: qbrush_fast_equals(currentBrush, brush)
0
72 return;
never executed: return;
0
73 -
74 const Qt::BrushStyle newStyle = qbrush_style(brush); -
75 qt_noop(); -
76 -
77 currentBrush = brush; -
78 if (!currentBrushPixmap.isNull())
never evaluated: !currentBrushPixmap.isNull()
0
79 currentBrushPixmap = QPixmap();
never executed: currentBrushPixmap = QPixmap();
0
80 brushUniformsDirty = true; -
81 -
82 if (newStyle > Qt::SolidPattern)
never evaluated: newStyle > Qt::SolidPattern
0
83 brushTextureDirty = true;
never executed: brushTextureDirty = true;
0
84 -
85 if (currentBrush.style() == Qt::TexturePattern
never evaluated: currentBrush.style() == Qt::TexturePattern
0
86 && qHasPixmapTexture(brush) && brush.texture().isQBitmap())
never evaluated: qHasPixmapTexture(brush)
never evaluated: brush.texture().isQBitmap()
0
87 { -
88 shaderManager->setSrcPixelType(QOpenGLEngineShaderManager::TextureSrcWithPattern); -
89 } else {
never executed: }
0
90 shaderManager->setSrcPixelType(newStyle); -
91 }
never executed: }
0
92 shaderManager->optimiseForBrushTransform(currentBrush.transform().type()); -
93}
never executed: }
0
94 -
95 -
96void QOpenGL2PaintEngineExPrivate::useSimpleShader() -
97{ -
98 shaderManager->useSimpleProgram(); -
99 -
100 if (matrixDirty)
never evaluated: matrixDirty
0
101 updateMatrix();
never executed: updateMatrix();
0
102}
never executed: }
0
103 -
104void QOpenGL2PaintEngineExPrivate::updateBrushTexture() -
105{ -
106 QOpenGL2PaintEngineEx * const q = q_func(); -
107 -
108 Qt::BrushStyle style = currentBrush.style(); -
109 -
110 if ( (style >= Qt::Dense1Pattern) && (style <= Qt::DiagCrossPattern) ) {
never evaluated: (style >= Qt::Dense1Pattern)
never evaluated: (style <= Qt::DiagCrossPattern)
0
111 -
112 QImage texImage = qt_imageForBrush(style, false); -
113 -
114 funcs.glActiveTexture(0x84C0 + GLuint(0)); -
115 QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, texImage); -
116 updateTextureFilter(0x0DE1, 0x2901, q->state()->renderHints & QPainter::SmoothPixmapTransform); -
117 }
never executed: }
0
118 else if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) {
never evaluated: style >= Qt::LinearGradientPattern
never evaluated: style <= Qt::ConicalGradientPattern
0
119 -
120 -
121 const QGradient* g = currentBrush.gradient(); -
122 -
123 -
124 -
125 GLuint texId = QOpenGL2GradientCache::cacheForContext(ctx)->getBuffer(*g, 1.0); -
126 -
127 funcs.glActiveTexture(0x84C0 + GLuint(0)); -
128 glBindTexture(0x0DE1, texId); -
129 -
130 if (g->spread() == QGradient::RepeatSpread || g->type() == QGradient::ConicalGradient)
never evaluated: g->spread() == QGradient::RepeatSpread
never evaluated: g->type() == QGradient::ConicalGradient
0
131 updateTextureFilter(0x0DE1, 0x2901, q->state()->renderHints & QPainter::SmoothPixmapTransform);
never executed: updateTextureFilter(0x0DE1, 0x2901, q->state()->renderHints & QPainter::SmoothPixmapTransform);
0
132 else if (g->spread() == QGradient::ReflectSpread)
never evaluated: g->spread() == QGradient::ReflectSpread
0
133 updateTextureFilter(0x0DE1, 0x8370, q->state()->renderHints & QPainter::SmoothPixmapTransform);
never executed: updateTextureFilter(0x0DE1, 0x8370, q->state()->renderHints & QPainter::SmoothPixmapTransform);
0
134 else -
135 updateTextureFilter(0x0DE1, 0x812F, q->state()->renderHints & QPainter::SmoothPixmapTransform);
never executed: updateTextureFilter(0x0DE1, 0x812F, q->state()->renderHints & QPainter::SmoothPixmapTransform);
0
136 } -
137 else if (style == Qt::TexturePattern) {
never evaluated: style == Qt::TexturePattern
0
138 currentBrushPixmap = currentBrush.texture(); -
139 -
140 int max_texture_size = ctx->d_func()->maxTextureSize(); -
141 if (currentBrushPixmap.width() > max_texture_size || currentBrushPixmap.height() > max_texture_size)
never evaluated: currentBrushPixmap.width() > max_texture_size
never evaluated: currentBrushPixmap.height() > max_texture_size
0
142 currentBrushPixmap = currentBrushPixmap.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio);
never executed: currentBrushPixmap = currentBrushPixmap.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio);
0
143 -
144 funcs.glActiveTexture(0x84C0 + GLuint(0)); -
145 QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, currentBrushPixmap); -
146 updateTextureFilter(0x0DE1, 0x2901, q->state()->renderHints & QPainter::SmoothPixmapTransform); -
147 textureInvertedY = false; -
148 }
never executed: }
0
149 brushTextureDirty = false; -
150}
never executed: }
0
151 -
152 -
153void QOpenGL2PaintEngineExPrivate::updateBrushUniforms() -
154{ -
155 -
156 Qt::BrushStyle style = currentBrush.style(); -
157 -
158 if (style == Qt::NoBrush)
never evaluated: style == Qt::NoBrush
0
159 return;
never executed: return;
0
160 -
161 QTransform brushQTransform = currentBrush.transform(); -
162 -
163 if (style == Qt::SolidPattern) {
never evaluated: style == Qt::SolidPattern
0
164 QColor col = qt_premultiplyColor(currentBrush.color(), (GLfloat)q->state()->opacity); -
165 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::FragmentColor), col); -
166 }
never executed: }
0
167 else { -
168 -
169 QPointF translationPoint; -
170 -
171 if (style <= Qt::DiagCrossPattern) {
never evaluated: style <= Qt::DiagCrossPattern
0
172 QColor col = qt_premultiplyColor(currentBrush.color(), (GLfloat)q->state()->opacity); -
173 -
174 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::PatternColor), col); -
175 -
176 QVector2D halfViewportSize(width*0.5, height*0.5); -
177 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::HalfViewportSize), halfViewportSize); -
178 }
never executed: }
0
179 else if (style == Qt::LinearGradientPattern) {
never evaluated: style == Qt::LinearGradientPattern
0
180 const QLinearGradient *g = static_cast<const QLinearGradient *>(currentBrush.gradient()); -
181 -
182 QPointF realStart = g->start(); -
183 QPointF realFinal = g->finalStop(); -
184 translationPoint = realStart; -
185 -
186 QPointF l = realFinal - realStart; -
187 -
188 QVector3D linearData( -
189 l.x(), -
190 l.y(), -
191 1.0f / (l.x() * l.x() + l.y() * l.y()) -
192 ); -
193 -
194 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::LinearData), linearData); -
195 -
196 QVector2D halfViewportSize(width*0.5, height*0.5); -
197 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::HalfViewportSize), halfViewportSize); -
198 }
never executed: }
0
199 else if (style == Qt::ConicalGradientPattern) {
never evaluated: style == Qt::ConicalGradientPattern
0
200 const QConicalGradient *g = static_cast<const QConicalGradient *>(currentBrush.gradient()); -
201 translationPoint = g->center(); -
202 -
203 GLfloat angle = -(g->angle() * 2 * Q_PI) / 360.0; -
204 -
205 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::Angle), angle); -
206 -
207 QVector2D halfViewportSize(width*0.5, height*0.5); -
208 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::HalfViewportSize), halfViewportSize); -
209 }
never executed: }
0
210 else if (style == Qt::RadialGradientPattern) {
never evaluated: style == Qt::RadialGradientPattern
0
211 const QRadialGradient *g = static_cast<const QRadialGradient *>(currentBrush.gradient()); -
212 QPointF realCenter = g->center(); -
213 QPointF realFocal = g->focalPoint(); -
214 qreal realRadius = g->centerRadius() - g->focalRadius(); -
215 translationPoint = realFocal; -
216 -
217 QPointF fmp = realCenter - realFocal; -
218 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::Fmp), fmp); -
219 -
220 GLfloat fmp2_m_radius2 = -fmp.x() * fmp.x() - fmp.y() * fmp.y() + realRadius*realRadius; -
221 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::Fmp2MRadius2), fmp2_m_radius2); -
222 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::Inverse2Fmp2MRadius2), -
223 GLfloat(1.0 / (2.0*fmp2_m_radius2))); -
224 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::SqrFr), -
225 GLfloat(g->focalRadius() * g->focalRadius())); -
226 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::BRadius), -
227 GLfloat(2 * (g->centerRadius() - g->focalRadius()) * g->focalRadius()), -
228 g->focalRadius(), -
229 g->centerRadius() - g->focalRadius()); -
230 -
231 QVector2D halfViewportSize(width*0.5, height*0.5); -
232 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::HalfViewportSize), halfViewportSize); -
233 }
never executed: }
0
234 else if (style == Qt::TexturePattern) {
never evaluated: style == Qt::TexturePattern
0
235 const QPixmap& texPixmap = currentBrush.texture(); -
236 -
237 if (qHasPixmapTexture(currentBrush) && currentBrush.texture().isQBitmap()) {
never evaluated: qHasPixmapTexture(currentBrush)
never evaluated: currentBrush.texture().isQBitmap()
0
238 QColor col = qt_premultiplyColor(currentBrush.color(), (GLfloat)q->state()->opacity); -
239 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::PatternColor), col); -
240 }
never executed: }
0
241 -
242 QSizeF invertedTextureSize(1.0 / texPixmap.width(), 1.0 / texPixmap.height()); -
243 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::InvertedTextureSize), invertedTextureSize); -
244 -
245 QVector2D halfViewportSize(width*0.5, height*0.5); -
246 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::HalfViewportSize), halfViewportSize); -
247 }
never executed: }
0
248 else -
249 QMessageLogger("opengl/qopenglpaintengine.cpp", 334, __PRETTY_FUNCTION__).warning("QOpenGL2PaintEngineEx: Unimplemented fill style");
never executed: QMessageLogger("opengl/qopenglpaintengine.cpp", 334, __PRETTY_FUNCTION__).warning("QOpenGL2PaintEngineEx: Unimplemented fill style");
0
250 -
251 const QPointF &brushOrigin = q->state()->brushOrigin; -
252 QTransform matrix = q->state()->matrix; -
253 matrix.translate(brushOrigin.x(), brushOrigin.y()); -
254 -
255 QTransform translate(1, 0, 0, 1, -translationPoint.x(), -translationPoint.y()); -
256 qreal m22 = -1; -
257 qreal dy = height; -
258 if (device->paintFlipped()) {
never evaluated: device->paintFlipped()
0
259 m22 = 1; -
260 dy = 0; -
261 }
never executed: }
0
262 QTransform gl_to_qt(1, 0, 0, m22, 0, dy); -
263 QTransform inv_matrix; -
264 if (style == Qt::TexturePattern && textureInvertedY == -1)
never evaluated: style == Qt::TexturePattern
never evaluated: textureInvertedY == -1
0
265 inv_matrix = gl_to_qt * (QTransform(1, 0, 0, -1, 0, currentBrush.texture().height()) * brushQTransform * matrix).inverted() * translate;
never executed: inv_matrix = gl_to_qt * (QTransform(1, 0, 0, -1, 0, currentBrush.texture().height()) * brushQTransform * matrix).inverted() * translate;
0
266 else -
267 inv_matrix = gl_to_qt * (brushQTransform * matrix).inverted() * translate;
never executed: inv_matrix = gl_to_qt * (brushQTransform * matrix).inverted() * translate;
0
268 -
269 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::BrushTransform), inv_matrix); -
270 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::BrushTexture), GLuint(0)); -
271 }
never executed: }
0
272 brushUniformsDirty = false; -
273}
never executed: }
0
274 -
275 -
276 -
277void QOpenGL2PaintEngineExPrivate::updateMatrix() -
278{ -
279 -
280 -
281 const QTransform& transform = q->state()->matrix; -
282 const GLfloat wfactor = 2.0f / width; -
283 GLfloat hfactor = -2.0f / height; -
284 -
285 GLfloat dx = transform.dx(); -
286 GLfloat dy = transform.dy(); -
287 -
288 if (device->paintFlipped()) {
never evaluated: device->paintFlipped()
0
289 hfactor *= -1; -
290 dy -= height; -
291 }
never executed: }
0
292 -
293 -
294 -
295 if (snapToPixelGrid && transform.type() == QTransform::TxTranslate) {
never evaluated: snapToPixelGrid
never evaluated: transform.type() == QTransform::TxTranslate
0
296 -
297 dx = ceilf(dx - 0.5f); -
298 dy = ceilf(dy - 0.5f); -
299 }
never executed: }
0
300 pmvMatrix[0][0] = (wfactor * transform.m11()) - transform.m13(); -
301 pmvMatrix[1][0] = (wfactor * transform.m21()) - transform.m23(); -
302 pmvMatrix[2][0] = (wfactor * dx) - transform.m33(); -
303 pmvMatrix[0][1] = (hfactor * transform.m12()) + transform.m13(); -
304 pmvMatrix[1][1] = (hfactor * transform.m22()) + transform.m23(); -
305 pmvMatrix[2][1] = (hfactor * dy) + transform.m33(); -
306 pmvMatrix[0][2] = transform.m13(); -
307 pmvMatrix[1][2] = transform.m23(); -
308 pmvMatrix[2][2] = transform.m33(); -
309 -
310 -
311 -
312 inverseScale = qMax(1 / qMax( qMax(qAbs(transform.m11()), qAbs(transform.m22())), -
313 qMax(qAbs(transform.m12()), qAbs(transform.m21())) ), -
314 qreal(0.0001)); -
315 -
316 matrixDirty = false; -
317 matrixUniformDirty = true; -
318 -
319 -
320 -
321 funcs.glVertexAttrib3fv(QT_PMV_MATRIX_1_ATTR, pmvMatrix[0]); -
322 funcs.glVertexAttrib3fv(QT_PMV_MATRIX_2_ATTR, pmvMatrix[1]); -
323 funcs.glVertexAttrib3fv(QT_PMV_MATRIX_3_ATTR, pmvMatrix[2]); -
324 -
325 dasher.setInvScale(inverseScale); -
326 stroker.setInvScale(inverseScale); -
327}
never executed: }
0
328 -
329 -
330void QOpenGL2PaintEngineExPrivate::updateCompositionMode() -
331{ -
332 -
333 -
334 -
335 switch(q->state()->composition_mode) { -
336 case QPainter::CompositionMode_SourceOver: -
337 glBlendFunc(0x1, 0x0303); -
338 break;
never executed: break;
0
339 case QPainter::CompositionMode_DestinationOver: -
340 glBlendFunc(0x0305, 0x1); -
341 break;
never executed: break;
0
342 case QPainter::CompositionMode_Clear: -
343 glBlendFunc(0x0, 0x0); -
344 break;
never executed: break;
0
345 case QPainter::CompositionMode_Source: -
346 glBlendFunc(0x1, 0x0); -
347 break;
never executed: break;
0
348 case QPainter::CompositionMode_Destination: -
349 glBlendFunc(0x0, 0x1); -
350 break;
never executed: break;
0
351 case QPainter::CompositionMode_SourceIn: -
352 glBlendFunc(0x0304, 0x0); -
353 break;
never executed: break;
0
354 case QPainter::CompositionMode_DestinationIn: -
355 glBlendFunc(0x0, 0x0302); -
356 break;
never executed: break;
0
357 case QPainter::CompositionMode_SourceOut: -
358 glBlendFunc(0x0305, 0x0); -
359 break;
never executed: break;
0
360 case QPainter::CompositionMode_DestinationOut: -
361 glBlendFunc(0x0, 0x0303); -
362 break;
never executed: break;
0
363 case QPainter::CompositionMode_SourceAtop: -
364 glBlendFunc(0x0304, 0x0303); -
365 break;
never executed: break;
0
366 case QPainter::CompositionMode_DestinationAtop: -
367 glBlendFunc(0x0305, 0x0302); -
368 break;
never executed: break;
0
369 case QPainter::CompositionMode_Xor: -
370 glBlendFunc(0x0305, 0x0303); -
371 break;
never executed: break;
0
372 case QPainter::CompositionMode_Plus: -
373 glBlendFunc(0x1, 0x1); -
374 break;
never executed: break;
0
375 default: -
376 QMessageLogger("opengl/qopenglpaintengine.cpp", 479, __PRETTY_FUNCTION__).warning("Unsupported composition mode"); -
377 break;
never executed: break;
0
378 } -
379 -
380 compositionModeDirty = false; -
381}
never executed: }
0
382 -
383static inline void setCoords(GLfloat *coords, const QOpenGLRect &rect) -
384{ -
385 coords[0] = rect.left; -
386 coords[1] = rect.top; -
387 coords[2] = rect.right; -
388 coords[3] = rect.top; -
389 coords[4] = rect.right; -
390 coords[5] = rect.bottom; -
391 coords[6] = rect.left; -
392 coords[7] = rect.bottom; -
393}
never executed: }
0
394 -
395void QOpenGL2PaintEngineExPrivate::drawTexture(const QOpenGLRect& dest, const QOpenGLRect& src, const QSize &textureSize, bool opaque, bool pattern) -
396{ -
397 -
398 currentBrush = noBrush; -
399 shaderManager->setSrcPixelType(pattern ? QOpenGLEngineShaderManager::PatternSrc : QOpenGLEngineShaderManager::ImageSrc); -
400 -
401 if (snapToPixelGrid) {
never evaluated: snapToPixelGrid
0
402 snapToPixelGrid = false; -
403 matrixDirty = true; -
404 }
never executed: }
0
405 -
406 if (prepareForDraw(opaque))
never evaluated: prepareForDraw(opaque)
0
407 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::ImageTexture), GLuint(0));
never executed: shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::ImageTexture), GLuint(0));
0
408 -
409 if (pattern) {
never evaluated: pattern
0
410 QColor col = qt_premultiplyColor(q->state()->pen.color(), (GLfloat)q->state()->opacity); -
411 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::PatternColor), col); -
412 }
never executed: }
0
413 -
414 GLfloat dx = 1.0 / textureSize.width(); -
415 GLfloat dy = 1.0 / textureSize.height(); -
416 -
417 QOpenGLRect srcTextureRect(src.left*dx, src.top*dy, src.right*dx, src.bottom*dy); -
418 -
419 setCoords(staticVertexCoordinateArray, dest); -
420 setCoords(staticTextureCoordinateArray, srcTextureRect); -
421 -
422 glDrawArrays(0x0006, 0, 4); -
423}
never executed: }
0
424 -
425void QOpenGL2PaintEngineEx::beginNativePainting() -
426{ -
427 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
428 ensureActive(); -
429 d->transferMode(BrushDrawingMode); -
430 -
431 d->nativePaintingActive = true; -
432 -
433 d->funcs.glUseProgram(0); -
434 -
435 -
436 for (int i = 0; i < 3; ++i)
never evaluated: i < 3
0
437 d->funcs.glDisableVertexAttribArray(i);
never executed: d->funcs.glDisableVertexAttribArray(i);
0
438 -
439 -
440 qt_noop(); -
441 const QSurfaceFormat &fmt = d->device->context()->format(); -
442 if (fmt.majorVersion() < 3 || (fmt.majorVersion() == 3 && fmt.minorVersion() < 1)
never evaluated: fmt.majorVersion() < 3
never evaluated: fmt.majorVersion() == 3
never evaluated: fmt.minorVersion() < 1
0
443 || fmt.profile() == QSurfaceFormat::CompatibilityProfile)
never evaluated: fmt.profile() == QSurfaceFormat::CompatibilityProfile
0
444 { -
445 -
446 -
447 -
448 const QTransform& mtx = state()->matrix; -
449 -
450 float mv_matrix[4][4] = -
451 { -
452 { float(mtx.m11()), float(mtx.m12()), 0, float(mtx.m13()) }, -
453 { float(mtx.m21()), float(mtx.m22()), 0, float(mtx.m23()) }, -
454 { 0, 0, 1, 0 }, -
455 { float(mtx.dx()), float(mtx.dy()), 0, float(mtx.m33()) } -
456 }; -
457 -
458 const QSize sz = d->device->size(); -
459 -
460 glMatrixMode(0x1701); -
461 glLoadIdentity(); -
462 glOrtho(0, sz.width(), sz.height(), 0, -999999, 999999); -
463 -
464 glMatrixMode(0x1700); -
465 glLoadMatrixf(&mv_matrix[0][0]); -
466 }
never executed: }
0
467 -
468 -
469 d->lastTextureUsed = GLuint(-1); -
470 d->dirtyStencilRegion = QRect(0, 0, d->width, d->height); -
471 d->resetGLState(); -
472 -
473 d->shaderManager->setDirty(); -
474 -
475 d->needsSync = true; -
476}
never executed: }
0
477 -
478void QOpenGL2PaintEngineExPrivate::resetGLState() -
479{ -
480 glDisable(0x0BE2); -
481 funcs.glActiveTexture(0x84C0); -
482 glDisable(0x0B90); -
483 glDisable(0x0B71); -
484 glDisable(0x0C11); -
485 glDepthMask(true); -
486 glDepthFunc(0x0201); -
487 funcs.glClearDepthf(1); -
488 glStencilMask(0xff); -
489 glStencilOp(0x1E00, 0x1E00, 0x1E00); -
490 glStencilFunc(0x0207, 0, 0xff); -
491 setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, false); -
492 setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, false); -
493 setVertexAttribArrayEnabled(QT_OPACITY_ATTR, false); -
494 -
495 -
496 float color[] = { 1.0f, 1.0f, 1.0f, 1.0f }; -
497 funcs.glVertexAttrib4fv(3, color); -
498 -
499}
never executed: }
0
500 -
501void QOpenGL2PaintEngineEx::endNativePainting() -
502{ -
503 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
504 d->needsSync = true; -
505 d->nativePaintingActive = false; -
506}
never executed: }
0
507 -
508void QOpenGL2PaintEngineEx::invalidateState() -
509{ -
510 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
511 d->needsSync = true; -
512}
never executed: }
0
513 -
514bool QOpenGL2PaintEngineEx::isNativePaintingActive() const { -
515 const QOpenGL2PaintEngineExPrivate * const d = d_func(); -
516 return d->nativePaintingActive;
never executed: return d->nativePaintingActive;
0
517} -
518 -
519void QOpenGL2PaintEngineExPrivate::transferMode(EngineMode newMode) -
520{ -
521 if (newMode == mode)
never evaluated: newMode == mode
0
522 return;
never executed: return;
0
523 -
524 if (mode == TextDrawingMode || mode == ImageDrawingMode || mode == ImageArrayDrawingMode) {
never evaluated: mode == TextDrawingMode
never evaluated: mode == ImageDrawingMode
never evaluated: mode == ImageArrayDrawingMode
0
525 lastTextureUsed = GLuint(-1); -
526 }
never executed: }
0
527 -
528 if (newMode == TextDrawingMode) {
never evaluated: newMode == TextDrawingMode
0
529 shaderManager->setHasComplexGeometry(true); -
530 } else {
never executed: }
0
531 shaderManager->setHasComplexGeometry(false); -
532 }
never executed: }
0
533 -
534 if (newMode == ImageDrawingMode) {
never evaluated: newMode == ImageDrawingMode
0
535 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray); -
536 setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, staticTextureCoordinateArray); -
537 }
never executed: }
0
538 -
539 if (newMode == ImageArrayDrawingMode) {
never evaluated: newMode == ImageArrayDrawingMode
0
540 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data()); -
541 setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data()); -
542 setVertexAttributePointer(QT_OPACITY_ATTR, (GLfloat*)opacityArray.data()); -
543 }
never executed: }
0
544 -
545 -
546 if (newMode != TextDrawingMode)
never evaluated: newMode != TextDrawingMode
0
547 shaderManager->setMaskType(QOpenGLEngineShaderManager::NoMask);
never executed: shaderManager->setMaskType(QOpenGLEngineShaderManager::NoMask);
0
548 -
549 mode = newMode; -
550}
never executed: }
0
551 -
552struct QOpenGL2PEVectorPathCache -
553{ -
554 -
555 -
556 -
557 -
558 float *vertices; -
559 void *indices; -
560 -
561 int vertexCount; -
562 int indexCount; -
563 GLenum primitiveType; -
564 qreal iscale; -
565 QVertexIndexVector::Type indexType; -
566}; -
567 -
568void QOpenGL2PaintEngineExPrivate::cleanupVectorPath(QPaintEngineEx *engine, void *data) -
569{ -
570 QOpenGL2PEVectorPathCache *c = (QOpenGL2PEVectorPathCache *) data; -
571 -
572 -
573 -
574 -
575 -
576 -
577 (void)engine;; -
578 free(c->vertices); -
579 free(c->indices); -
580 -
581 delete c; -
582}
never executed: }
0
583 -
584 -
585void QOpenGL2PaintEngineExPrivate::fill(const QVectorPath& path) -
586{ -
587 transferMode(BrushDrawingMode); -
588 -
589 if (snapToPixelGrid) {
never evaluated: snapToPixelGrid
0
590 snapToPixelGrid = false; -
591 matrixDirty = true; -
592 }
never executed: }
0
593 -
594 -
595 if (matrixDirty)
never evaluated: matrixDirty
0
596 updateMatrix();
never executed: updateMatrix();
0
597 -
598 const QPointF* const points = reinterpret_cast<const QPointF*>(path.points()); -
599 -
600 -
601 if (path.shape() == QVectorPath::RectangleHint) {
never evaluated: path.shape() == QVectorPath::RectangleHint
0
602 QOpenGLRect rect(points[0].x(), points[0].y(), points[2].x(), points[2].y()); -
603 prepareForDraw(currentBrush.isOpaque()); -
604 composite(rect); -
605 } else if (path.isConvex()) {
never evaluated: path.isConvex()
never executed: }
0
606 -
607 if (path.isCacheable()) {
never evaluated: path.isCacheable()
0
608 QVectorPath::CacheEntry *data = path.lookupCacheData(q); -
609 QOpenGL2PEVectorPathCache *cache; -
610 -
611 bool updateCache = false; -
612 -
613 if (data) {
never evaluated: data
0
614 cache = (QOpenGL2PEVectorPathCache *) data->data; -
615 -
616 if (path.isCurved()) {
never evaluated: path.isCurved()
0
617 qreal scaleFactor = cache->iscale / inverseScale; -
618 if (scaleFactor < 0.5 || scaleFactor > 2.0) {
never evaluated: scaleFactor < 0.5
never evaluated: scaleFactor > 2.0
0
619 -
620 -
621 -
622 -
623 -
624 free(cache->vertices); -
625 qt_noop(); -
626 -
627 updateCache = true; -
628 }
never executed: }
0
629 }
never executed: }
0
630 } else {
never executed: }
0
631 cache = new QOpenGL2PEVectorPathCache; -
632 data = const_cast<QVectorPath &>(path).addCacheData(q, cache, cleanupVectorPath); -
633 updateCache = true; -
634 }
never executed: }
0
635 -
636 -
637 if (updateCache) {
never evaluated: updateCache
0
638 vertexCoordinateArray.clear(); -
639 vertexCoordinateArray.addPath(path, inverseScale, false); -
640 int vertexCount = vertexCoordinateArray.vertexCount(); -
641 int floatSizeInBytes = vertexCount * 2 * sizeof(float); -
642 cache->vertexCount = vertexCount; -
643 cache->indexCount = 0; -
644 cache->primitiveType = 0x0006; -
645 cache->iscale = inverseScale; -
646 -
647 -
648 -
649 -
650 -
651 -
652 cache->vertices = (float *) malloc(floatSizeInBytes); -
653 memcpy(cache->vertices, vertexCoordinateArray.data(), floatSizeInBytes); -
654 cache->indices = 0; -
655 -
656 }
never executed: }
0
657 -
658 prepareForDraw(currentBrush.isOpaque()); -
659 -
660 -
661 -
662 -
663 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices); -
664 -
665 glDrawArrays(cache->primitiveType, 0, cache->vertexCount); -
666 -
667 } else {
never executed: }
0
668 -
669 -
670 path.makeCacheable(); -
671 vertexCoordinateArray.clear(); -
672 vertexCoordinateArray.addPath(path, inverseScale, false); -
673 prepareForDraw(currentBrush.isOpaque()); -
674 drawVertexArrays(vertexCoordinateArray, 0x0006); -
675 }
never executed: }
0
676 -
677 } else { -
678 bool useCache = path.isCacheable(); -
679 if (useCache) {
never evaluated: useCache
0
680 QRectF bbox = path.controlPointRect(); -
681 -
682 useCache &= (bbox.left() > -0x8000 * inverseScale)
never evaluated: (bbox.left() > -0x8000 * inverseScale)
0
683 && (bbox.right() < 0x8000 * inverseScale)
never evaluated: (bbox.right() < 0x8000 * inverseScale)
0
684 && (bbox.top() > -0x8000 * inverseScale)
never evaluated: (bbox.top() > -0x8000 * inverseScale)
0
685 && (bbox.bottom() < 0x8000 * inverseScale);
never evaluated: (bbox.bottom() < 0x8000 * inverseScale)
0
686 }
never executed: }
0
687 -
688 if (useCache) {
never evaluated: useCache
0
689 QVectorPath::CacheEntry *data = path.lookupCacheData(q); -
690 QOpenGL2PEVectorPathCache *cache; -
691 -
692 bool updateCache = false; -
693 -
694 if (data) {
never evaluated: data
0
695 cache = (QOpenGL2PEVectorPathCache *) data->data; -
696 -
697 if (path.isCurved()) {
never evaluated: path.isCurved()
0
698 qreal scaleFactor = cache->iscale / inverseScale; -
699 if (scaleFactor < 0.5 || scaleFactor > 2.0) {
never evaluated: scaleFactor < 0.5
never evaluated: scaleFactor > 2.0
0
700 -
701 -
702 -
703 -
704 free(cache->vertices); -
705 free(cache->indices); -
706 -
707 updateCache = true; -
708 }
never executed: }
0
709 }
never executed: }
0
710 } else {
never executed: }
0
711 cache = new QOpenGL2PEVectorPathCache; -
712 data = const_cast<QVectorPath &>(path).addCacheData(q, cache, cleanupVectorPath); -
713 updateCache = true; -
714 }
never executed: }
0
715 -
716 -
717 if (updateCache) {
never evaluated: updateCache
0
718 QTriangleSet polys = qTriangulate(path, QTransform().scale(1 / inverseScale, 1 / inverseScale)); -
719 cache->vertexCount = polys.vertices.size() / 2; -
720 cache->indexCount = polys.indices.size(); -
721 cache->primitiveType = 0x0004; -
722 cache->iscale = inverseScale; -
723 cache->indexType = polys.indices.type(); -
724 cache->vertices = (float *) malloc(sizeof(float) * polys.vertices.size()); -
725 if (polys.indices.type() == QVertexIndexVector::UnsignedInt) {
never evaluated: polys.indices.type() == QVertexIndexVector::UnsignedInt
0
726 cache->indices = (quint32 *) malloc(sizeof(quint32) * polys.indices.size()); -
727 memcpy(cache->indices, polys.indices.data(), sizeof(quint32) * polys.indices.size()); -
728 } else {
never executed: }
0
729 cache->indices = (quint16 *) malloc(sizeof(quint16) * polys.indices.size()); -
730 memcpy(cache->indices, polys.indices.data(), sizeof(quint16) * polys.indices.size()); -
731 }
never executed: }
0
732 for (int i = 0; i < polys.vertices.size(); ++i)
never evaluated: i < polys.vertices.size()
0
733 cache->vertices[i] = float(inverseScale * polys.vertices.at(i));
never executed: cache->vertices[i] = float(inverseScale * polys.vertices.at(i));
0
734 -
735 }
never executed: }
0
736 -
737 prepareForDraw(currentBrush.isOpaque()); -
738 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices); -
739 if (cache->indexType == QVertexIndexVector::UnsignedInt)
never evaluated: cache->indexType == QVertexIndexVector::UnsignedInt
0
740 glDrawElements(cache->primitiveType, cache->indexCount, 0x1405, (qint32 *)cache->indices);
never executed: glDrawElements(cache->primitiveType, cache->indexCount, 0x1405, (qint32 *)cache->indices);
0
741 else -
742 glDrawElements(cache->primitiveType, cache->indexCount, 0x1403, (qint16 *)cache->indices);
never executed: glDrawElements(cache->primitiveType, cache->indexCount, 0x1403, (qint16 *)cache->indices);
0
743 -
744 -
745 } else { -
746 -
747 -
748 path.makeCacheable(); -
749 -
750 if (device->context()->format().stencilBufferSize() <= 0) {
never evaluated: device->context()->format().stencilBufferSize() <= 0
0
751 -
752 -
753 QRectF bbox = path.controlPointRect(); -
754 -
755 bool withinLimits = (bbox.left() > -0x8000 * inverseScale)
never evaluated: (bbox.left() > -0x8000 * inverseScale)
0
756 && (bbox.right() < 0x8000 * inverseScale)
never evaluated: (bbox.right() < 0x8000 * inverseScale)
0
757 && (bbox.top() > -0x8000 * inverseScale)
never evaluated: (bbox.top() > -0x8000 * inverseScale)
0
758 && (bbox.bottom() < 0x8000 * inverseScale);
never evaluated: (bbox.bottom() < 0x8000 * inverseScale)
0
759 if (withinLimits) {
never evaluated: withinLimits
0
760 QTriangleSet polys = qTriangulate(path, QTransform().scale(1 / inverseScale, 1 / inverseScale)); -
761 -
762 QVarLengthArray<float> vertices(polys.vertices.size()); -
763 for (int i = 0; i < polys.vertices.size(); ++i)
never evaluated: i < polys.vertices.size()
0
764 vertices[i] = float(inverseScale * polys.vertices.at(i));
never executed: vertices[i] = float(inverseScale * polys.vertices.at(i));
0
765 -
766 prepareForDraw(currentBrush.isOpaque()); -
767 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, vertices.constData()); -
768 if (funcs.hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint))
never evaluated: funcs.hasOpenGLExtension(QOpenGLExtensions::ElementIndexUint)
0
769 glDrawElements(0x0004, polys.indices.size(), 0x1405, polys.indices.data());
never executed: glDrawElements(0x0004, polys.indices.size(), 0x1405, polys.indices.data());
0
770 else -
771 glDrawElements(0x0004, polys.indices.size(), 0x1403, polys.indices.data());
never executed: glDrawElements(0x0004, polys.indices.size(), 0x1403, polys.indices.data());
0
772 } else { -
773 -
774 QMessageLogger("opengl/qopenglpaintengine.cpp", 904, __PRETTY_FUNCTION__).warning("Painter path exceeds +/-32767 pixels."); -
775 }
never executed: }
0
776 return;
never executed: return;
0
777 } -
778 -
779 -
780 vertexCoordinateArray.clear(); -
781 vertexCoordinateArray.addPath(path, inverseScale, false); -
782 -
783 fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill()); -
784 -
785 glStencilMask(0xff); -
786 glStencilOp(0x1E00, 0x1E01, 0x1E01); -
787 -
788 if (q->state()->clipTestEnabled) {
never evaluated: q->state()->clipTestEnabled
0
789 -
790 glStencilFunc(0x0205, q->state()->currentClip, GLuint(0x80)); -
791 } else if (path.hasWindingFill()) {
never executed: }
never evaluated: path.hasWindingFill()
0
792 -
793 glStencilFunc(0x0205, 0, 0xff); -
794 } else {
never executed: }
0
795 -
796 glStencilFunc(0x0205, 0, GLuint(0x80)); -
797 }
never executed: }
0
798 prepareForDraw(currentBrush.isOpaque()); -
799 -
800 -
801 composite(vertexCoordinateArray.boundingRect()); -
802 glStencilMask(0); -
803 updateClipScissorTest(); -
804 }
never executed: }
0
805 } -
806} -
807 -
808 -
809void QOpenGL2PaintEngineExPrivate::fillStencilWithVertexArray(const float *data, -
810 int count, -
811 int *stops, -
812 int stopCount, -
813 const QOpenGLRect &bounds, -
814 StencilFillMode mode) -
815{ -
816 qt_noop(); -
817 -
818 -
819 glStencilMask(0xff); -
820 -
821 if (dirtyStencilRegion.intersects(currentScissorBounds)) {
never evaluated: dirtyStencilRegion.intersects(currentScissorBounds)
0
822 QVector<QRect> clearRegion = dirtyStencilRegion.intersected(currentScissorBounds).rects(); -
823 glClearStencil(0); -
824 for (int i = 0; i < clearRegion.size(); ++i) {
never evaluated: i < clearRegion.size()
0
825 -
826 setScissor(clearRegion.at(i)); -
827 -
828 glClear(0x00000400); -
829 }
never executed: }
0
830 -
831 dirtyStencilRegion -= currentScissorBounds; -
832 -
833 -
834 updateClipScissorTest(); -
835 -
836 }
never executed: }
0
837 -
838 glColorMask(0x0, 0x0, 0x0, 0x0); -
839 useSimpleShader(); -
840 glEnable(0x0B90); -
841 -
842 if (mode == WindingFillMode) {
never evaluated: mode == WindingFillMode
0
843 qt_noop(); -
844 if (q->state()->clipTestEnabled) {
never evaluated: q->state()->clipTestEnabled
0
845 -
846 glStencilFunc(0x0203, GLuint(0x80) | q->state()->currentClip, ~GLuint(0x80)); -
847 glStencilOp(0x1E00, 0x1E01, 0x1E01); -
848 composite(bounds); -
849 -
850 glStencilFunc(0x0202, GLuint(0x80), GLuint(0x80)); -
851 } else if (!stencilClean) {
never executed: }
never evaluated: !stencilClean
0
852 -
853 glStencilFunc(0x0207, 0, 0xff); -
854 glStencilOp(0x0, 0x0, 0x0); -
855 composite(bounds); -
856 }
never executed: }
0
857 -
858 -
859 funcs.glStencilOpSeparate(0x0404, 0x1E00, 0x8507, 0x8507); -
860 -
861 funcs.glStencilOpSeparate(0x0405, 0x1E00, 0x8508, 0x8508); -
862 glStencilMask(~GLuint(0x80)); -
863 drawVertexArrays(data, stops, stopCount, 0x0006); -
864 -
865 if (q->state()->clipTestEnabled) {
never evaluated: q->state()->clipTestEnabled
0
866 -
867 glStencilFunc(0x0202, q->state()->currentClip, ~GLuint(0x80)); -
868 glStencilOp(0x1E00, 0x1E01, 0x1E01); -
869 glStencilMask(GLuint(0x80)); -
870 composite(bounds); -
871 }
never executed: }
0
872 } else if (mode == OddEvenFillMode) {
never executed: }
never evaluated: mode == OddEvenFillMode
0
873 glStencilMask(GLuint(0x80)); -
874 glStencilOp(0x1E00, 0x1E00, 0x150A); -
875 drawVertexArrays(data, stops, stopCount, 0x0006); -
876 -
877 } else {
never executed: }
0
878 qt_noop(); -
879 glStencilMask(GLuint(0x80)); -
880 -
881 -
882 -
883 -
884 -
885 -
886 glStencilOp(0x1E00, 0x1E00, 0x1E01); -
887 if (q->state()->clipTestEnabled) {
never evaluated: q->state()->clipTestEnabled
0
888 glStencilFunc(0x0203, q->state()->currentClip | GLuint(0x80), -
889 ~GLuint(0x80)); -
890 } else {
never executed: }
0
891 glStencilFunc(0x0207, GLuint(0x80), 0xff); -
892 }
never executed: }
0
893 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, data); -
894 glDrawArrays(0x0005, 0, count); -
895 -
896 }
never executed: }
0
897 -
898 -
899 glColorMask(0x1, 0x1, 0x1, 0x1); -
900}
never executed: }
0
901 -
902 -
903 -
904 -
905 -
906 -
907void QOpenGL2PaintEngineExPrivate::resetClipIfNeeded() -
908{ -
909 if (maxClip != (GLuint(0x80) - 1))
never evaluated: maxClip != (GLuint(0x80) - 1)
0
910 return;
never executed: return;
0
911 -
912 QOpenGL2PaintEngineEx * const q = q_func(); -
913 -
914 useSimpleShader(); -
915 glEnable(0x0B90); -
916 glColorMask(0x0, 0x0, 0x0, 0x0); -
917 -
918 QRectF bounds = q->state()->matrix.inverted().mapRect(QRectF(0, 0, width, height)); -
919 QOpenGLRect rect(bounds.left(), bounds.top(), bounds.right(), bounds.bottom()); -
920 -
921 -
922 glStencilFunc(0x0203, q->state()->currentClip, 0xff); -
923 glStencilOp(0x1E00, 0x150A, 0x150A); -
924 glStencilMask(GLuint(0x80)); -
925 composite(rect); -
926 -
927 -
928 glStencilFunc(0x0205, 0x01, GLuint(0x80)); -
929 glStencilOp(0x0, 0x1E01, 0x1E01); -
930 glStencilMask(0xff); -
931 composite(rect); -
932 -
933 q->state()->currentClip = 1; -
934 q->state()->canRestoreClip = false; -
935 -
936 maxClip = 1; -
937 -
938 glStencilMask(0x0); -
939 glColorMask(0x1, 0x1, 0x1, 0x1); -
940}
never executed: }
0
941 -
942bool QOpenGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque) -
943{ -
944 if (brushTextureDirty && mode != ImageDrawingMode && mode != ImageArrayDrawingMode)
never evaluated: brushTextureDirty
never evaluated: mode != ImageDrawingMode
never evaluated: mode != ImageArrayDrawingMode
0
945 updateBrushTexture();
never executed: updateBrushTexture();
0
946 -
947 if (compositionModeDirty)
never evaluated: compositionModeDirty
0
948 updateCompositionMode();
never executed: updateCompositionMode();
0
949 -
950 if (matrixDirty)
never evaluated: matrixDirty
0
951 updateMatrix();
never executed: updateMatrix();
0
952 -
953 const bool stateHasOpacity = q->state()->opacity < 0.99f; -
954 if (q->state()->composition_mode == QPainter::CompositionMode_Source
never evaluated: q->state()->composition_mode == QPainter::CompositionMode_Source
0
955 || (q->state()->composition_mode == QPainter::CompositionMode_SourceOver
never evaluated: q->state()->composition_mode == QPainter::CompositionMode_SourceOver
0
956 && srcPixelsAreOpaque && !stateHasOpacity))
never evaluated: srcPixelsAreOpaque
never evaluated: !stateHasOpacity
0
957 { -
958 glDisable(0x0BE2); -
959 } else {
never executed: }
0
960 glEnable(0x0BE2); -
961 }
never executed: }
0
962 -
963 QOpenGLEngineShaderManager::OpacityMode opacityMode; -
964 if (mode == ImageArrayDrawingMode) {
never evaluated: mode == ImageArrayDrawingMode
0
965 opacityMode = QOpenGLEngineShaderManager::AttributeOpacity; -
966 } else {
never executed: }
0
967 opacityMode = stateHasOpacity ? QOpenGLEngineShaderManager::UniformOpacity
never evaluated: stateHasOpacity
0
968 : QOpenGLEngineShaderManager::NoOpacity; -
969 if (stateHasOpacity && (mode != ImageDrawingMode)) {
never evaluated: stateHasOpacity
never evaluated: (mode != ImageDrawingMode)
0
970 -
971 bool brushIsPattern = (currentBrush.style() >= Qt::Dense1Pattern) &&
never evaluated: (currentBrush.style() >= Qt::Dense1Pattern)
0
972 (currentBrush.style() <= Qt::DiagCrossPattern);
never evaluated: (currentBrush.style() <= Qt::DiagCrossPattern)
0
973 -
974 if ((currentBrush.style() == Qt::SolidPattern) || brushIsPattern)
never evaluated: (currentBrush.style() == Qt::SolidPattern)
never evaluated: brushIsPattern
0
975 opacityMode = QOpenGLEngineShaderManager::NoOpacity;
never executed: opacityMode = QOpenGLEngineShaderManager::NoOpacity;
0
976 }
never executed: }
0
977 }
never executed: }
0
978 shaderManager->setOpacityMode(opacityMode); -
979 -
980 bool changed = shaderManager->useCorrectShaderProg(); -
981 -
982 if (changed) {
never evaluated: changed
0
983 -
984 brushUniformsDirty = true; -
985 opacityUniformDirty = true; -
986 matrixUniformDirty = true; -
987 }
never executed: }
0
988 -
989 if (brushUniformsDirty && mode != ImageDrawingMode && mode != ImageArrayDrawingMode)
never evaluated: brushUniformsDirty
never evaluated: mode != ImageDrawingMode
never evaluated: mode != ImageArrayDrawingMode
0
990 updateBrushUniforms();
never executed: updateBrushUniforms();
0
991 -
992 if (opacityMode == QOpenGLEngineShaderManager::UniformOpacity && opacityUniformDirty) {
never evaluated: opacityMode == QOpenGLEngineShaderManager::UniformOpacity
never evaluated: opacityUniformDirty
0
993 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::GlobalOpacity), (GLfloat)q->state()->opacity); -
994 opacityUniformDirty = false; -
995 }
never executed: }
0
996 -
997 if (matrixUniformDirty && shaderManager->hasComplexGeometry()) {
never evaluated: matrixUniformDirty
never evaluated: shaderManager->hasComplexGeometry()
0
998 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::Matrix), -
999 pmvMatrix); -
1000 matrixUniformDirty = false; -
1001 }
never executed: }
0
1002 -
1003 return changed;
never executed: return changed;
0
1004} -
1005 -
1006void QOpenGL2PaintEngineExPrivate::composite(const QOpenGLRect& boundingRect) -
1007{ -
1008 setCoords(staticVertexCoordinateArray, boundingRect); -
1009 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray); -
1010 glDrawArrays(0x0006, 0, 4); -
1011}
never executed: }
0
1012 -
1013 -
1014void QOpenGL2PaintEngineExPrivate::drawVertexArrays(const float *data, int *stops, int stopCount, -
1015 GLenum primitive) -
1016{ -
1017 -
1018 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)data); -
1019 -
1020 int previousStop = 0; -
1021 for (int i=0; i<stopCount; ++i) {
never evaluated: i<stopCount
0
1022 int stop = stops[i]; -
1023 -
1024 -
1025 -
1026 -
1027 -
1028 glDrawArrays(primitive, previousStop, stop - previousStop); -
1029 previousStop = stop; -
1030 }
never executed: }
0
1031}
never executed: }
0
1032 -
1033 -
1034 -
1035QOpenGL2PaintEngineEx::QOpenGL2PaintEngineEx() -
1036 : QPaintEngineEx(*(new QOpenGL2PaintEngineExPrivate(this))) -
1037{ -
1038}
never executed: }
0
1039 -
1040QOpenGL2PaintEngineEx::~QOpenGL2PaintEngineEx() -
1041{ -
1042} -
1043 -
1044void QOpenGL2PaintEngineEx::fill(const QVectorPath &path, const QBrush &brush) -
1045{ -
1046 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1047 -
1048 if (qbrush_style(brush) == Qt::NoBrush)
never evaluated: qbrush_style(brush) == Qt::NoBrush
0
1049 return;
never executed: return;
0
1050 ensureActive(); -
1051 d->setBrush(brush); -
1052 d->fill(path); -
1053}
never executed: }
0
1054 -
1055__attribute__((visibility("default"))) bool qt_scaleForTransform(const QTransform &transform, qreal *scale); -
1056 -
1057 -
1058void QOpenGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) -
1059{ -
1060 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1061 -
1062 const QBrush &penBrush = qpen_brush(pen); -
1063 if (qpen_style(pen) == Qt::NoPen || qbrush_style(penBrush) == Qt::NoBrush)
never evaluated: qpen_style(pen) == Qt::NoPen
never evaluated: qbrush_style(penBrush) == Qt::NoBrush
0
1064 return;
never executed: return;
0
1065 -
1066 QOpenGL2PaintEngineState *s = state(); -
1067 if (qt_pen_is_cosmetic(pen, state()->renderHints) && !qt_scaleForTransform(s->transform(), 0)) {
never evaluated: qt_pen_is_cosmetic(pen, state()->renderHints)
never evaluated: !qt_scaleForTransform(s->transform(), 0)
0
1068 -
1069 QPaintEngineEx::stroke(path, pen); -
1070 return;
never executed: return;
0
1071 } -
1072 -
1073 ensureActive(); -
1074 d->setBrush(penBrush); -
1075 d->stroke(path, pen); -
1076}
never executed: }
0
1077 -
1078void QOpenGL2PaintEngineExPrivate::stroke(const QVectorPath &path, const QPen &pen) -
1079{ -
1080 const QOpenGL2PaintEngineState *s = q->state(); -
1081 if (snapToPixelGrid) {
never evaluated: snapToPixelGrid
0
1082 snapToPixelGrid = false; -
1083 matrixDirty = true; -
1084 }
never executed: }
0
1085 -
1086 const Qt::PenStyle penStyle = qpen_style(pen); -
1087 const QBrush &penBrush = qpen_brush(pen); -
1088 const bool opaque = penBrush.isOpaque() && s->opacity > 0.99;
never evaluated: penBrush.isOpaque()
never evaluated: s->opacity > 0.99
0
1089 -
1090 transferMode(BrushDrawingMode); -
1091 -
1092 -
1093 -
1094 -
1095 updateMatrix(); -
1096 -
1097 QRectF clip = q->state()->matrix.inverted().mapRect(q->state()->clipEnabled -
1098 ? q->state()->rectangleClip -
1099 : QRectF(0, 0, width, height)); -
1100 -
1101 if (penStyle == Qt::SolidLine) {
never evaluated: penStyle == Qt::SolidLine
0
1102 stroker.process(path, pen, clip, s->renderHints); -
1103 -
1104 } else {
never executed: }
0
1105 dasher.process(path, pen, clip, s->renderHints); -
1106 -
1107 QVectorPath dashStroke(dasher.points(), -
1108 dasher.elementCount(), -
1109 dasher.elementTypes(), -
1110 s->renderHints); -
1111 stroker.process(dashStroke, pen, clip, s->renderHints); -
1112 }
never executed: }
0
1113 -
1114 if (!stroker.vertexCount())
never evaluated: !stroker.vertexCount()
0
1115 return;
never executed: return;
0
1116 -
1117 if (opaque) {
never evaluated: opaque
0
1118 prepareForDraw(opaque); -
1119 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, stroker.vertices()); -
1120 glDrawArrays(0x0005, 0, stroker.vertexCount() / 2); -
1121 -
1122 -
1123 -
1124 -
1125 -
1126 -
1127 } else {
never executed: }
0
1128 qreal width = qpen_widthf(pen) / 2; -
1129 if (width == 0)
never evaluated: width == 0
0
1130 width = 0.5;
never executed: width = 0.5;
0
1131 qreal extra = pen.joinStyle() == Qt::MiterJoin
never evaluated: pen.joinStyle() == Qt::MiterJoin
0
1132 ? qMax(pen.miterLimit() * width, width) -
1133 : width; -
1134 -
1135 if (qt_pen_is_cosmetic(pen, q->state()->renderHints))
never evaluated: qt_pen_is_cosmetic(pen, q->state()->renderHints)
0
1136 extra = extra * inverseScale;
never executed: extra = extra * inverseScale;
0
1137 -
1138 QRectF bounds = path.controlPointRect().adjusted(-extra, -extra, extra, extra); -
1139 -
1140 fillStencilWithVertexArray(stroker.vertices(), stroker.vertexCount() / 2, -
1141 0, 0, bounds, QOpenGL2PaintEngineExPrivate::TriStripStrokeFillMode); -
1142 -
1143 glStencilOp(0x1E00, 0x1E01, 0x1E01); -
1144 -
1145 -
1146 glStencilFunc(0x0205, 0, GLuint(0x80)); -
1147 prepareForDraw(false); -
1148 -
1149 -
1150 composite(bounds); -
1151 -
1152 glStencilMask(0); -
1153 -
1154 updateClipScissorTest(); -
1155 }
never executed: }
0
1156} -
1157 -
1158void QOpenGL2PaintEngineEx::penChanged() { } -
1159void QOpenGL2PaintEngineEx::brushChanged() { } -
1160void QOpenGL2PaintEngineEx::brushOriginChanged() { } -
1161 -
1162void QOpenGL2PaintEngineEx::opacityChanged() -
1163{ -
1164 -
1165 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1166 state()->opacityChanged = true; -
1167 -
1168 qt_noop(); -
1169 d->brushUniformsDirty = true; -
1170 d->opacityUniformDirty = true; -
1171}
never executed: }
0
1172 -
1173void QOpenGL2PaintEngineEx::compositionModeChanged() -
1174{ -
1175 -
1176 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1177 state()->compositionModeChanged = true; -
1178 d->compositionModeDirty = true; -
1179}
never executed: }
0
1180 -
1181void QOpenGL2PaintEngineEx::renderHintsChanged() -
1182{ -
1183 state()->renderHintsChanged = true; -
1184 -
1185 -
1186 if ((state()->renderHints & QPainter::Antialiasing)
never evaluated: (state()->renderHints & QPainter::Antialiasing)
0
1187 || (state()->renderHints & QPainter::HighQualityAntialiasing))
never evaluated: (state()->renderHints & QPainter::HighQualityAntialiasing)
0
1188 glEnable(0x809D);
never executed: glEnable(0x809D);
0
1189 else -
1190 glDisable(0x809D);
never executed: glDisable(0x809D);
0
1191 -
1192 -
1193 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1194 d->lastTextureUsed = GLuint(-1); -
1195 d->brushTextureDirty = true; -
1196 -
1197}
never executed: }
0
1198 -
1199void QOpenGL2PaintEngineEx::transformChanged() -
1200{ -
1201 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1202 d->matrixDirty = true; -
1203 state()->matrixChanged = true; -
1204}
never executed: }
0
1205 -
1206 -
1207static const QRectF scaleRect(const QRectF &r, qreal sx, qreal sy) -
1208{ -
1209 return QRectF(r.x() * sx, r.y() * sy, r.width() * sx, r.height() * sy);
never executed: return QRectF(r.x() * sx, r.y() * sy, r.width() * sx, r.height() * sy);
0
1210} -
1211 -
1212void QOpenGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap & pixmap, const QRectF & src) -
1213{ -
1214 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1215 QOpenGLContext *ctx = d->ctx; -
1216 -
1217 int max_texture_size = ctx->d_func()->maxTextureSize(); -
1218 if (pixmap.width() > max_texture_size || pixmap.height() > max_texture_size) {
never evaluated: pixmap.width() > max_texture_size
never evaluated: pixmap.height() > max_texture_size
0
1219 QPixmap scaled = pixmap.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio); -
1220 -
1221 const qreal sx = scaled.width() / qreal(pixmap.width()); -
1222 const qreal sy = scaled.height() / qreal(pixmap.height()); -
1223 -
1224 drawPixmap(dest, scaled, scaleRect(src, sx, sy)); -
1225 return;
never executed: return;
0
1226 } -
1227 -
1228 ensureActive(); -
1229 d->transferMode(ImageDrawingMode); -
1230 -
1231 d->funcs.glActiveTexture(0x84C0 + GLuint(0)); -
1232 GLuint id = QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, pixmap); -
1233 -
1234 QOpenGLRect srcRect(src.left(), src.top(), src.right(), src.bottom()); -
1235 -
1236 bool isBitmap = pixmap.isQBitmap(); -
1237 bool isOpaque = !isBitmap && !pixmap.hasAlpha();
never evaluated: !isBitmap
never evaluated: !pixmap.hasAlpha()
0
1238 -
1239 d->updateTextureFilter(0x0DE1, 0x812F, -
1240 state()->renderHints & QPainter::SmoothPixmapTransform, id); -
1241 d->drawTexture(dest, srcRect, pixmap.size(), isOpaque, isBitmap); -
1242}
never executed: }
0
1243 -
1244void QOpenGL2PaintEngineEx::drawImage(const QRectF& dest, const QImage& image, const QRectF& src, -
1245 Qt::ImageConversionFlags) -
1246{ -
1247 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1248 QOpenGLContext *ctx = d->ctx; -
1249 -
1250 int max_texture_size = ctx->d_func()->maxTextureSize(); -
1251 if (image.width() > max_texture_size || image.height() > max_texture_size) {
never evaluated: image.width() > max_texture_size
never evaluated: image.height() > max_texture_size
0
1252 QImage scaled = image.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio); -
1253 -
1254 const qreal sx = scaled.width() / qreal(image.width()); -
1255 const qreal sy = scaled.height() / qreal(image.height()); -
1256 -
1257 drawImage(dest, scaled, scaleRect(src, sx, sy)); -
1258 return;
never executed: return;
0
1259 } -
1260 -
1261 ensureActive(); -
1262 d->transferMode(ImageDrawingMode); -
1263 -
1264 d->funcs.glActiveTexture(0x84C0 + GLuint(0)); -
1265 -
1266 GLuint id = QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, image); -
1267 -
1268 d->updateTextureFilter(0x0DE1, 0x812F, -
1269 state()->renderHints & QPainter::SmoothPixmapTransform, id); -
1270 d->drawTexture(dest, src, image.size(), !image.hasAlphaChannel()); -
1271}
never executed: }
0
1272 -
1273void QOpenGL2PaintEngineEx::drawStaticTextItem(QStaticTextItem *textItem) -
1274{ -
1275 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1276 -
1277 ensureActive(); -
1278 -
1279 QPainterState *s = state(); -
1280 float det = s->matrix.determinant(); -
1281 -
1282 -
1283 QFontEngine *fontEngine = textItem->fontEngine(); -
1284 if (shouldDrawCachedGlyphs(fontEngine, s->matrix) && det >= 0.25f && det <= 4.f) {
never evaluated: shouldDrawCachedGlyphs(fontEngine, s->matrix)
never evaluated: det >= 0.25f
never evaluated: det <= 4.f
0
1285 QFontEngineGlyphCache::Type glyphType = fontEngine->glyphFormat >= 0
never evaluated: fontEngine->glyphFormat >= 0
0
1286 ? QFontEngineGlyphCache::Type(textItem->fontEngine()->glyphFormat) -
1287 : d->glyphCacheType; -
1288 if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
never evaluated: glyphType == QFontEngineGlyphCache::Raster_RGBMask
0
1289 if (d->device->context()->format().alphaBufferSize() > 0 || s->matrix.type() > QTransform::TxTranslate
never evaluated: d->device->context()->format().alphaBufferSize() > 0
never evaluated: s->matrix.type() > QTransform::TxTranslate
0
1290 || (s->composition_mode != QPainter::CompositionMode_Source
never evaluated: s->composition_mode != QPainter::CompositionMode_Source
0
1291 && s->composition_mode != QPainter::CompositionMode_SourceOver))
never evaluated: s->composition_mode != QPainter::CompositionMode_SourceOver
0
1292 { -
1293 glyphType = QFontEngineGlyphCache::Raster_A8; -
1294 }
never executed: }
0
1295 }
never executed: }
0
1296 -
1297 d->drawCachedGlyphs(glyphType, textItem); -
1298 } else {
never executed: }
0
1299 QPaintEngineEx::drawStaticTextItem(textItem); -
1300 }
never executed: }
0
1301} -
1302 -
1303bool QOpenGL2PaintEngineEx::drawTexture(const QRectF &dest, GLuint textureId, const QSize &size, const QRectF &src) -
1304{ -
1305 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1306 if (!d->shaderManager)
never evaluated: !d->shaderManager
0
1307 return false;
never executed: return false;
0
1308 -
1309 ensureActive(); -
1310 d->transferMode(ImageDrawingMode); -
1311 -
1312 d->funcs.glActiveTexture(0x84C0 + GLuint(0)); -
1313 glBindTexture(0x0DE1, textureId); -
1314 -
1315 QOpenGLRect srcRect(src.left(), src.bottom(), src.right(), src.top()); -
1316 -
1317 d->updateTextureFilter(0x0DE1, 0x812F, -
1318 state()->renderHints & QPainter::SmoothPixmapTransform, textureId); -
1319 d->drawTexture(dest, srcRect, size, false); -
1320 return true;
never executed: return true;
0
1321} -
1322 -
1323void QOpenGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem) -
1324{ -
1325 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1326 -
1327 ensureActive(); -
1328 QOpenGL2PaintEngineState *s = state(); -
1329 -
1330 const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem); -
1331 -
1332 QTransform::TransformationType txtype = s->matrix.type(); -
1333 -
1334 float det = s->matrix.determinant(); -
1335 bool drawCached = txtype < QTransform::TxProject; -
1336 -
1337 -
1338 if (!shouldDrawCachedGlyphs(ti.fontEngine, s->matrix) || det < 0.25f || det > 4.f)
never evaluated: !shouldDrawCachedGlyphs(ti.fontEngine, s->matrix)
never evaluated: det < 0.25f
never evaluated: det > 4.f
0
1339 drawCached = false;
never executed: drawCached = false;
0
1340 -
1341 QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0
never evaluated: ti.fontEngine->glyphFormat >= 0
0
1342 ? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat) -
1343 : d->glyphCacheType; -
1344 -
1345 -
1346 if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
never evaluated: glyphType == QFontEngineGlyphCache::Raster_RGBMask
0
1347 if (d->device->context()->format().alphaBufferSize() > 0 || txtype > QTransform::TxTranslate
never evaluated: d->device->context()->format().alphaBufferSize() > 0
never evaluated: txtype > QTransform::TxTranslate
0
1348 || (state()->composition_mode != QPainter::CompositionMode_Source
never evaluated: state()->composition_mode != QPainter::CompositionMode_Source
0
1349 && state()->composition_mode != QPainter::CompositionMode_SourceOver))
never evaluated: state()->composition_mode != QPainter::CompositionMode_SourceOver
0
1350 { -
1351 glyphType = QFontEngineGlyphCache::Raster_A8; -
1352 }
never executed: }
0
1353 }
never executed: }
0
1354 -
1355 if (drawCached) {
never evaluated: drawCached
0
1356 QVarLengthArray<QFixedPoint> positions; -
1357 QVarLengthArray<glyph_t> glyphs; -
1358 QTransform matrix = QTransform::fromTranslate(p.x(), p.y()); -
1359 ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); -
1360 -
1361 { -
1362 QStaticTextItem staticTextItem; -
1363 staticTextItem.chars = const_cast<QChar *>(ti.chars); -
1364 staticTextItem.setFontEngine(ti.fontEngine); -
1365 staticTextItem.glyphs = glyphs.data(); -
1366 staticTextItem.numChars = ti.num_chars; -
1367 staticTextItem.numGlyphs = glyphs.size(); -
1368 staticTextItem.glyphPositions = positions.data(); -
1369 -
1370 d->drawCachedGlyphs(glyphType, &staticTextItem); -
1371 } -
1372 return;
never executed: return;
0
1373 } -
1374 -
1375 QPaintEngineEx::drawTextItem(p, ti); -
1376}
never executed: }
0
1377 -
1378namespace { -
1379 -
1380 class QOpenGLStaticTextUserData: public QStaticTextUserData -
1381 { -
1382 public: -
1383 QOpenGLStaticTextUserData() -
1384 : QStaticTextUserData(OpenGLUserData), cacheSize(0, 0), cacheSerialNumber(0) -
1385 { -
1386 }
never executed: }
0
1387 -
1388 ~QOpenGLStaticTextUserData() -
1389 { -
1390 } -
1391 -
1392 QSize cacheSize; -
1393 QOpenGL2PEXVertexArray vertexCoordinateArray; -
1394 QOpenGL2PEXVertexArray textureCoordinateArray; -
1395 QFontEngineGlyphCache::Type glyphType; -
1396 int cacheSerialNumber; -
1397 }; -
1398 -
1399} -
1400 -
1401 -
1402 -
1403 -
1404void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, -
1405 QStaticTextItem *staticTextItem) -
1406{ -
1407 QOpenGL2PaintEngineEx * const q = q_func(); -
1408 -
1409 QOpenGL2PaintEngineState *s = q->state(); -
1410 -
1411 void *cacheKey = ctx->shareGroup(); -
1412 bool recreateVertexArrays = false; -
1413 QFontEngine *fe = staticTextItem->fontEngine(); -
1414 -
1415 QOpenGLTextureGlyphCache *cache = -
1416 (QOpenGLTextureGlyphCache *) fe->glyphCache(cacheKey, glyphType, QTransform()); -
1417 if (!cache || cache->cacheType() != glyphType || cache->contextGroup() == 0) {
never evaluated: !cache
never evaluated: cache->cacheType() != glyphType
never evaluated: cache->contextGroup() == 0
0
1418 cache = new QOpenGLTextureGlyphCache(glyphType, QTransform()); -
1419 fe->setGlyphCache(cacheKey, cache); -
1420 recreateVertexArrays = true; -
1421 }
never executed: }
0
1422 -
1423 if (staticTextItem->userDataNeedsUpdate) {
never evaluated: staticTextItem->userDataNeedsUpdate
0
1424 recreateVertexArrays = true; -
1425 } else if (staticTextItem->userData() == 0) {
never executed: }
never evaluated: staticTextItem->userData() == 0
0
1426 recreateVertexArrays = true; -
1427 } else if (staticTextItem->userData()->type != QStaticTextUserData::OpenGLUserData) {
never executed: }
never evaluated: staticTextItem->userData()->type != QStaticTextUserData::OpenGLUserData
0
1428 recreateVertexArrays = true; -
1429 } else {
never executed: }
0
1430 QOpenGLStaticTextUserData *userData = static_cast<QOpenGLStaticTextUserData *>(staticTextItem->userData()); -
1431 if (userData->glyphType != glyphType) {
never evaluated: userData->glyphType != glyphType
0
1432 recreateVertexArrays = true; -
1433 } else if (userData->cacheSerialNumber != cache->serialNumber()) {
never executed: }
never evaluated: userData->cacheSerialNumber != cache->serialNumber()
0
1434 recreateVertexArrays = true; -
1435 }
never executed: }
0
1436 } -
1437 -
1438 -
1439 -
1440 -
1441 if (recreateVertexArrays) {
never evaluated: recreateVertexArrays
0
1442 cache->setPaintEnginePrivate(this); -
1443 if (!cache->populate(fe, staticTextItem->numGlyphs, 0
1444 staticTextItem->glyphs, staticTextItem->glyphPositions)) {
never evaluated: !cache->populate(fe, staticTextItem->numGlyphs, staticTextItem->glyphs, staticTextItem->glyphPositions)
0
1445 -
1446 cache->clear(); -
1447 cache->populate(fe, staticTextItem->numGlyphs, -
1448 staticTextItem->glyphs, staticTextItem->glyphPositions); -
1449 }
never executed: }
0
1450 cache->fillInPendingGlyphs(); -
1451 }
never executed: }
0
1452 -
1453 if (cache->width() == 0 || cache->height() == 0)
never evaluated: cache->width() == 0
never evaluated: cache->height() == 0
0
1454 return;
never executed: return;
0
1455 -
1456 transferMode(TextDrawingMode); -
1457 -
1458 int margin = fe->glyphMargin(glyphType); -
1459 -
1460 GLfloat dx = 1.0 / cache->width(); -
1461 GLfloat dy = 1.0 / cache->height(); -
1462 -
1463 -
1464 QOpenGL2PEXVertexArray *vertexCoordinates = &vertexCoordinateArray; -
1465 QOpenGL2PEXVertexArray *textureCoordinates = &textureCoordinateArray; -
1466 -
1467 if (staticTextItem->useBackendOptimizations) {
never evaluated: staticTextItem->useBackendOptimizations
0
1468 QOpenGLStaticTextUserData *userData = 0; -
1469 -
1470 if (staticTextItem->userData() == 0
never evaluated: staticTextItem->userData() == 0
0
1471 || staticTextItem->userData()->type != QStaticTextUserData::OpenGLUserData) {
never evaluated: staticTextItem->userData()->type != QStaticTextUserData::OpenGLUserData
0
1472 -
1473 userData = new QOpenGLStaticTextUserData(); -
1474 staticTextItem->setUserData(userData); -
1475 -
1476 } else {
never executed: }
0
1477 userData = static_cast<QOpenGLStaticTextUserData*>(staticTextItem->userData()); -
1478 }
never executed: }
0
1479 -
1480 userData->glyphType = glyphType; -
1481 userData->cacheSerialNumber = cache->serialNumber(); -
1482 -
1483 -
1484 vertexCoordinates = &userData->vertexCoordinateArray; -
1485 textureCoordinates = &userData->textureCoordinateArray; -
1486 -
1487 QSize size(cache->width(), cache->height()); -
1488 if (userData->cacheSize != size) {
never evaluated: userData->cacheSize != size
0
1489 recreateVertexArrays = true; -
1490 userData->cacheSize = size; -
1491 }
never executed: }
0
1492 }
never executed: }
0
1493 -
1494 if (recreateVertexArrays) {
never evaluated: recreateVertexArrays
0
1495 vertexCoordinates->clear(); -
1496 textureCoordinates->clear(); -
1497 -
1498 bool supportsSubPixelPositions = fe->supportsSubPixelPositions(); -
1499 for (int i=0; i<staticTextItem->numGlyphs; ++i) {
never evaluated: i<staticTextItem->numGlyphs
0
1500 QFixed subPixelPosition; -
1501 if (supportsSubPixelPositions)
never evaluated: supportsSubPixelPositions
0
1502 subPixelPosition = fe->subPixelPositionForX(staticTextItem->glyphPositions[i].x);
never executed: subPixelPosition = fe->subPixelPositionForX(staticTextItem->glyphPositions[i].x);
0
1503 -
1504 QTextureGlyphCache::GlyphAndSubPixelPosition glyph(staticTextItem->glyphs[i], subPixelPosition); -
1505 -
1506 const QTextureGlyphCache::Coord &c = cache->coords[glyph]; -
1507 if (c.isNull())
never evaluated: c.isNull()
0
1508 continue;
never executed: continue;
0
1509 -
1510 int x = qFloor(staticTextItem->glyphPositions[i].x) + c.baseLineX - margin; -
1511 int y = qRound(staticTextItem->glyphPositions[i].y) - c.baseLineY - margin; -
1512 -
1513 vertexCoordinates->addQuad(QRectF(x, y, c.w, c.h)); -
1514 textureCoordinates->addQuad(QRectF(c.x*dx, c.y*dy, c.w * dx, c.h * dy)); -
1515 }
never executed: }
0
1516 -
1517 staticTextItem->userDataNeedsUpdate = false; -
1518 }
never executed: }
0
1519 -
1520 int numGlyphs = vertexCoordinates->vertexCount() / 4; -
1521 if (numGlyphs == 0)
never evaluated: numGlyphs == 0
0
1522 return;
never executed: return;
0
1523 -
1524 if (elementIndices.size() < numGlyphs*6) {
never evaluated: elementIndices.size() < numGlyphs*6
0
1525 qt_noop(); -
1526 int j = elementIndices.size() / 6 * 4; -
1527 while (j < numGlyphs*4) {
never evaluated: j < numGlyphs*4
0
1528 elementIndices.append(j + 0); -
1529 elementIndices.append(j + 0); -
1530 elementIndices.append(j + 1); -
1531 elementIndices.append(j + 2); -
1532 elementIndices.append(j + 3); -
1533 elementIndices.append(j + 3); -
1534 -
1535 j += 4; -
1536 }
never executed: }
0
1537 } else {
never executed: }
0
1538 -
1539 -
1540 -
1541 }
never executed: }
0
1542 -
1543 setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinates->data()); -
1544 setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinates->data()); -
1545 -
1546 if (!snapToPixelGrid) {
never evaluated: !snapToPixelGrid
0
1547 snapToPixelGrid = true; -
1548 matrixDirty = true; -
1549 }
never executed: }
0
1550 -
1551 QBrush pensBrush = q->state()->pen.brush(); -
1552 setBrush(pensBrush); -
1553 -
1554 if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) {
never evaluated: glyphType == QFontEngineGlyphCache::Raster_RGBMask
0
1555 -
1556 -
1557 -
1558 QPainter::CompositionMode compMode = q->state()->composition_mode; -
1559 qt_noop(); -
1560 -
1561 -
1562 shaderManager->setMaskType(QOpenGLEngineShaderManager::SubPixelMaskPass1); -
1563 -
1564 if (pensBrush.style() == Qt::SolidPattern) {
never evaluated: pensBrush.style() == Qt::SolidPattern
0
1565 -
1566 QColor c = pensBrush.color(); -
1567 qreal oldOpacity = q->state()->opacity; -
1568 if (compMode == QPainter::CompositionMode_Source) {
never evaluated: compMode == QPainter::CompositionMode_Source
0
1569 c = qt_premultiplyColor(c, q->state()->opacity); -
1570 q->state()->opacity = 1; -
1571 opacityUniformDirty = true; -
1572 }
never executed: }
0
1573 -
1574 compositionModeDirty = false; -
1575 prepareForDraw(false); -
1576 -
1577 -
1578 if (compMode == QPainter::CompositionMode_Source) {
never evaluated: compMode == QPainter::CompositionMode_Source
0
1579 q->state()->opacity = oldOpacity; -
1580 opacityUniformDirty = true; -
1581 }
never executed: }
0
1582 -
1583 glEnable(0x0BE2); -
1584 glBlendFunc(0x8001, 0x0301); -
1585 funcs.glBlendColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); -
1586 } else {
never executed: }
0
1587 -
1588 -
1589 qreal oldOpacity = q->state()->opacity; -
1590 if (compMode == QPainter::CompositionMode_Source) {
never evaluated: compMode == QPainter::CompositionMode_Source
0
1591 q->state()->opacity = 1; -
1592 opacityUniformDirty = true; -
1593 pensBrush = Qt::white; -
1594 setBrush(pensBrush); -
1595 }
never executed: }
0
1596 -
1597 compositionModeDirty = false; -
1598 prepareForDraw(false); -
1599 glEnable(0x0BE2); -
1600 glBlendFunc(0x0, 0x0301); -
1601 -
1602 funcs.glActiveTexture(0x84C0 + GLuint(1)); -
1603 glBindTexture(0x0DE1, cache->texture()); -
1604 updateTextureFilter(0x0DE1, 0x2901, false); -
1605 -
1606 -
1607 -
1608 -
1609 glDrawElements(0x0005, 6 * numGlyphs, 0x1403, elementIndices.data()); -
1610 -
1611 -
1612 shaderManager->setMaskType(QOpenGLEngineShaderManager::SubPixelMaskPass2); -
1613 -
1614 if (compMode == QPainter::CompositionMode_Source) {
never evaluated: compMode == QPainter::CompositionMode_Source
0
1615 q->state()->opacity = oldOpacity; -
1616 opacityUniformDirty = true; -
1617 pensBrush = q->state()->pen.brush(); -
1618 setBrush(pensBrush); -
1619 }
never executed: }
0
1620 -
1621 compositionModeDirty = false; -
1622 prepareForDraw(false); -
1623 glEnable(0x0BE2); -
1624 glBlendFunc(0x1, 0x1); -
1625 }
never executed: }
0
1626 compositionModeDirty = true; -
1627 } else {
never executed: }
0
1628 -
1629 -
1630 shaderManager->setMaskType(QOpenGLEngineShaderManager::PixelMask); -
1631 prepareForDraw(false); -
1632 }
never executed: }
0
1633 -
1634 QOpenGLTextureGlyphCache::FilterMode filterMode = (s->matrix.type() > QTransform::TxTranslate)?QOpenGLTextureGlyphCache::Linear:QOpenGLTextureGlyphCache::Nearest;
never evaluated: (s->matrix.type() > QTransform::TxTranslate)
0
1635 if (lastMaskTextureUsed != cache->texture() || cache->filterMode() != filterMode) {
never evaluated: lastMaskTextureUsed != cache->texture()
never evaluated: cache->filterMode() != filterMode
0
1636 -
1637 funcs.glActiveTexture(0x84C0 + GLuint(1)); -
1638 if (lastMaskTextureUsed != cache->texture()) {
never evaluated: lastMaskTextureUsed != cache->texture()
0
1639 glBindTexture(0x0DE1, cache->texture()); -
1640 lastMaskTextureUsed = cache->texture(); -
1641 }
never executed: }
0
1642 -
1643 if (cache->filterMode() != filterMode) {
never evaluated: cache->filterMode() != filterMode
0
1644 if (filterMode == QOpenGLTextureGlyphCache::Linear) {
never evaluated: filterMode == QOpenGLTextureGlyphCache::Linear
0
1645 glTexParameteri(0x0DE1, 0x2800, 0x2601); -
1646 glTexParameteri(0x0DE1, 0x2801, 0x2601); -
1647 } else {
never executed: }
0
1648 glTexParameteri(0x0DE1, 0x2800, 0x2600); -
1649 glTexParameteri(0x0DE1, 0x2801, 0x2600); -
1650 }
never executed: }
0
1651 cache->setFilterMode(filterMode); -
1652 }
never executed: }
0
1653 }
never executed: }
0
1654 -
1655 bool srgbFrameBufferEnabled = false; -
1656 if (funcs.hasOpenGLExtension(QOpenGLExtensions::SRGBFrameBuffer)) {
never evaluated: funcs.hasOpenGLExtension(QOpenGLExtensions::SRGBFrameBuffer)
0
1657 if (false)
never evaluated: false
0
1658 { -
1659 glEnable(0x8DB9); -
1660 srgbFrameBufferEnabled = true; -
1661 }
never executed: }
0
1662 }
never executed: }
0
1663 -
1664 -
1665 -
1666 -
1667 -
1668 glDrawElements(0x0005, 6 * numGlyphs, 0x1403, elementIndices.data()); -
1669 -
1670 -
1671 if (srgbFrameBufferEnabled)
never evaluated: srgbFrameBufferEnabled
0
1672 glDisable(0x8DB9);
never executed: glDisable(0x8DB9);
0
1673 -
1674}
never executed: }
0
1675 -
1676void QOpenGL2PaintEngineEx::drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, -
1677 QPainter::PixmapFragmentHints hints) -
1678{ -
1679 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1680 -
1681 if (state()->composition_mode > QPainter::CompositionMode_Plus) {
never evaluated: state()->composition_mode > QPainter::CompositionMode_Plus
0
1682 QPaintEngineEx::drawPixmapFragments(fragments, fragmentCount, pixmap, hints); -
1683 return;
never executed: return;
0
1684 } -
1685 -
1686 ensureActive(); -
1687 int max_texture_size = d->ctx->d_func()->maxTextureSize(); -
1688 if (pixmap.width() > max_texture_size || pixmap.height() > max_texture_size) {
never evaluated: pixmap.width() > max_texture_size
never evaluated: pixmap.height() > max_texture_size
0
1689 QPixmap scaled = pixmap.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio); -
1690 d->drawPixmapFragments(fragments, fragmentCount, scaled, hints); -
1691 } else {
never executed: }
0
1692 d->drawPixmapFragments(fragments, fragmentCount, pixmap, hints); -
1693 }
never executed: }
0
1694} -
1695 -
1696 -
1697void QOpenGL2PaintEngineExPrivate::drawPixmapFragments(const QPainter::PixmapFragment *fragments, -
1698 int fragmentCount, const QPixmap &pixmap, -
1699 QPainter::PixmapFragmentHints hints) -
1700{ -
1701 GLfloat dx = 1.0f / pixmap.size().width(); -
1702 GLfloat dy = 1.0f / pixmap.size().height(); -
1703 -
1704 vertexCoordinateArray.clear(); -
1705 textureCoordinateArray.clear(); -
1706 opacityArray.reset(); -
1707 -
1708 if (snapToPixelGrid) {
never evaluated: snapToPixelGrid
0
1709 snapToPixelGrid = false; -
1710 matrixDirty = true; -
1711 }
never executed: }
0
1712 -
1713 bool allOpaque = true; -
1714 -
1715 for (int i = 0; i < fragmentCount; ++i) {
never evaluated: i < fragmentCount
0
1716 qreal s = 0; -
1717 qreal c = 1; -
1718 if (fragments[i].rotation != 0) {
never evaluated: fragments[i].rotation != 0
0
1719 s = qFastSin(fragments[i].rotation * Q_PI / 180); -
1720 c = qFastCos(fragments[i].rotation * Q_PI / 180); -
1721 }
never executed: }
0
1722 -
1723 qreal right = 0.5 * fragments[i].scaleX * fragments[i].width; -
1724 qreal bottom = 0.5 * fragments[i].scaleY * fragments[i].height; -
1725 QOpenGLPoint bottomRight(right * c - bottom * s, right * s + bottom * c); -
1726 QOpenGLPoint bottomLeft(-right * c - bottom * s, -right * s + bottom * c); -
1727 -
1728 vertexCoordinateArray.addVertex(bottomRight.x + fragments[i].x, bottomRight.y + fragments[i].y); -
1729 vertexCoordinateArray.addVertex(-bottomLeft.x + fragments[i].x, -bottomLeft.y + fragments[i].y); -
1730 vertexCoordinateArray.addVertex(-bottomRight.x + fragments[i].x, -bottomRight.y + fragments[i].y); -
1731 vertexCoordinateArray.addVertex(-bottomRight.x + fragments[i].x, -bottomRight.y + fragments[i].y); -
1732 vertexCoordinateArray.addVertex(bottomLeft.x + fragments[i].x, bottomLeft.y + fragments[i].y); -
1733 vertexCoordinateArray.addVertex(bottomRight.x + fragments[i].x, bottomRight.y + fragments[i].y); -
1734 -
1735 QOpenGLRect src(fragments[i].sourceLeft * dx, fragments[i].sourceTop * dy, -
1736 (fragments[i].sourceLeft + fragments[i].width) * dx, -
1737 (fragments[i].sourceTop + fragments[i].height) * dy); -
1738 -
1739 textureCoordinateArray.addVertex(src.right, src.bottom); -
1740 textureCoordinateArray.addVertex(src.right, src.top); -
1741 textureCoordinateArray.addVertex(src.left, src.top); -
1742 textureCoordinateArray.addVertex(src.left, src.top); -
1743 textureCoordinateArray.addVertex(src.left, src.bottom); -
1744 textureCoordinateArray.addVertex(src.right, src.bottom); -
1745 -
1746 qreal opacity = fragments[i].opacity * q->state()->opacity; -
1747 opacityArray << opacity << opacity << opacity << opacity << opacity << opacity; -
1748 allOpaque &= (opacity >= 0.99f); -
1749 }
never executed: }
0
1750 -
1751 funcs.glActiveTexture(0x84C0 + GLuint(0)); -
1752 GLuint id = QOpenGLTextureCache::cacheForContext(ctx)->bindTexture(ctx, pixmap); -
1753 transferMode(ImageArrayDrawingMode); -
1754 -
1755 bool isBitmap = pixmap.isQBitmap(); -
1756 bool isOpaque = !isBitmap && (!pixmap.hasAlpha() || (hints & QPainter::OpaqueHint)) && allOpaque;
never evaluated: !isBitmap
never evaluated: !pixmap.hasAlpha()
never evaluated: (hints & QPainter::OpaqueHint)
never evaluated: allOpaque
0
1757 -
1758 updateTextureFilter(0x0DE1, 0x812F, -
1759 q->state()->renderHints & QPainter::SmoothPixmapTransform, id); -
1760 -
1761 -
1762 currentBrush = noBrush; -
1763 shaderManager->setSrcPixelType(isBitmap ? QOpenGLEngineShaderManager::PatternSrc -
1764 : QOpenGLEngineShaderManager::ImageSrc); -
1765 if (prepareForDraw(isOpaque))
never evaluated: prepareForDraw(isOpaque)
0
1766 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::ImageTexture), GLuint(0));
never executed: shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::ImageTexture), GLuint(0));
0
1767 -
1768 if (isBitmap) {
never evaluated: isBitmap
0
1769 QColor col = qt_premultiplyColor(q->state()->pen.color(), (GLfloat)q->state()->opacity); -
1770 shaderManager->currentProgram()->setUniformValue(location(QOpenGLEngineShaderManager::PatternColor), col); -
1771 }
never executed: }
0
1772 -
1773 glDrawArrays(0x0004, 0, 6 * fragmentCount); -
1774}
never executed: }
0
1775 -
1776bool QOpenGL2PaintEngineEx::begin(QPaintDevice *pdev) -
1777{ -
1778 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1779 -
1780 qt_noop(); -
1781 d->device = static_cast<QOpenGLPaintDevice*>(pdev); -
1782 -
1783 if (!d->device)
never evaluated: !d->device
0
1784 return false;
never executed: return false;
0
1785 -
1786 if (d->device->context() != QOpenGLContext::currentContext()) {
never evaluated: d->device->context() != QOpenGLContext::currentContext()
0
1787 QMessageLogger("opengl/qopenglpaintengine.cpp", 1926, __PRETTY_FUNCTION__).warning("QPainter::begin(): QOpenGLPaintDevice's context needs to be current"); -
1788 return false;
never executed: return false;
0
1789 } -
1790 -
1791 d->ctx = QOpenGLContext::currentContext(); -
1792 d->ctx->d_func()->active_engine = this; -
1793 -
1794 d->funcs.initializeOpenGLFunctions(); -
1795 -
1796 for (int i = 0; i < 3; ++i)
never evaluated: i < 3
0
1797 d->vertexAttributeArraysEnabledState[i] = false;
never executed: d->vertexAttributeArraysEnabledState[i] = false;
0
1798 -
1799 const QSize sz = d->device->size(); -
1800 d->width = sz.width(); -
1801 d->height = sz.height(); -
1802 d->mode = BrushDrawingMode; -
1803 d->brushTextureDirty = true; -
1804 d->brushUniformsDirty = true; -
1805 d->matrixUniformDirty = true; -
1806 d->matrixDirty = true; -
1807 d->compositionModeDirty = true; -
1808 d->opacityUniformDirty = true; -
1809 d->needsSync = true; -
1810 d->useSystemClip = !systemClip().isEmpty(); -
1811 d->currentBrush = QBrush(); -
1812 -
1813 d->dirtyStencilRegion = QRect(0, 0, d->width, d->height); -
1814 d->stencilClean = true; -
1815 -
1816 d->shaderManager = new QOpenGLEngineShaderManager(d->ctx); -
1817 -
1818 glDisable(0x0B90); -
1819 glDisable(0x0B71); -
1820 glDisable(0x0C11); -
1821 -
1822 -
1823 glDisable(0x809D); -
1824 -
1825 -
1826 d->glyphCacheType = QFontEngineGlyphCache::Raster_A8; -
1827 -
1828 -
1829 d->glyphCacheType = QFontEngineGlyphCache::Raster_RGBMask; -
1830 -
1831 -
1832 -
1833 -
1834 -
1835 -
1836 -
1837 d->multisamplingAlwaysEnabled = false; -
1838 -
1839 -
1840 return true;
never executed: return true;
0
1841} -
1842 -
1843bool QOpenGL2PaintEngineEx::end() -
1844{ -
1845 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1846 -
1847 QOpenGLContext *ctx = d->ctx; -
1848 d->funcs.glUseProgram(0); -
1849 d->transferMode(BrushDrawingMode); -
1850 -
1851 ctx->d_func()->active_engine = 0; -
1852 -
1853 d->resetGLState(); -
1854 -
1855 delete d->shaderManager; -
1856 d->shaderManager = 0; -
1857 d->currentBrush = QBrush(); -
1858 return false;
never executed: return false;
0
1859} -
1860 -
1861void QOpenGL2PaintEngineEx::ensureActive() -
1862{ -
1863 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1864 QOpenGLContext *ctx = d->ctx; -
1865 -
1866 if (isActive() && ctx->d_func()->active_engine != this) {
never evaluated: isActive()
never evaluated: ctx->d_func()->active_engine != this
0
1867 ctx->d_func()->active_engine = this; -
1868 d->needsSync = true; -
1869 }
never executed: }
0
1870 -
1871 if (d->needsSync) {
never evaluated: d->needsSync
0
1872 d->device->ensureActiveTarget(); -
1873 -
1874 d->transferMode(BrushDrawingMode); -
1875 glViewport(0, 0, d->width, d->height); -
1876 d->needsSync = false; -
1877 d->lastMaskTextureUsed = 0; -
1878 d->shaderManager->setDirty(); -
1879 d->syncGlState(); -
1880 for (int i = 0; i < 3; ++i)
never evaluated: i < 3
0
1881 d->vertexAttribPointers[i] = (GLfloat*)-1;
never executed: d->vertexAttribPointers[i] = (GLfloat*)-1;
0
1882 setState(state()); -
1883 }
never executed: }
0
1884}
never executed: }
0
1885 -
1886void QOpenGL2PaintEngineExPrivate::updateClipScissorTest() -
1887{ -
1888 QOpenGL2PaintEngineEx * const q = q_func(); -
1889 if (q->state()->clipTestEnabled) {
never evaluated: q->state()->clipTestEnabled
0
1890 glEnable(0x0B90); -
1891 glStencilFunc(0x0203, q->state()->currentClip, ~GLuint(0x80)); -
1892 } else {
never executed: }
0
1893 glDisable(0x0B90); -
1894 glStencilFunc(0x0207, 0, 0xff); -
1895 }
never executed: }
0
1896 -
1897 -
1898 -
1899 -
1900 QRect bounds = q->state()->rectangleClip; -
1901 if (!q->state()->clipEnabled) {
never evaluated: !q->state()->clipEnabled
0
1902 if (useSystemClip)
never evaluated: useSystemClip
0
1903 bounds = systemClip.boundingRect();
never executed: bounds = systemClip.boundingRect();
0
1904 else -
1905 bounds = QRect(0, 0, width, height);
never executed: bounds = QRect(0, 0, width, height);
0
1906 } else { -
1907 if (useSystemClip)
never evaluated: useSystemClip
0
1908 bounds = bounds.intersected(systemClip.boundingRect());
never executed: bounds = bounds.intersected(systemClip.boundingRect());
0
1909 else -
1910 bounds = bounds.intersected(QRect(0, 0, width, height));
never executed: bounds = bounds.intersected(QRect(0, 0, width, height));
0
1911 } -
1912 -
1913 currentScissorBounds = bounds; -
1914 -
1915 if (bounds == QRect(0, 0, width, height)) {
never evaluated: bounds == QRect(0, 0, width, height)
0
1916 glDisable(0x0C11); -
1917 } else {
never executed: }
0
1918 glEnable(0x0C11); -
1919 setScissor(bounds); -
1920 }
never executed: }
0
1921 -
1922} -
1923 -
1924void QOpenGL2PaintEngineExPrivate::setScissor(const QRect &rect) -
1925{ -
1926 const int left = rect.left(); -
1927 const int width = rect.width(); -
1928 int bottom = height - (rect.top() + rect.height()); -
1929 if (device->paintFlipped()) {
never evaluated: device->paintFlipped()
0
1930 bottom = rect.top(); -
1931 }
never executed: }
0
1932 const int height = rect.height(); -
1933 -
1934 glScissor(left, bottom, width, height); -
1935}
never executed: }
0
1936 -
1937void QOpenGL2PaintEngineEx::clipEnabledChanged() -
1938{ -
1939 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
1940 -
1941 state()->clipChanged = true; -
1942 -
1943 if (painter()->hasClipping())
never evaluated: painter()->hasClipping()
0
1944 d->regenerateClip();
never executed: d->regenerateClip();
0
1945 else -
1946 d->systemStateChanged();
never executed: d->systemStateChanged();
0
1947} -
1948 -
1949void QOpenGL2PaintEngineExPrivate::clearClip(uint value) -
1950{ -
1951 dirtyStencilRegion -= currentScissorBounds; -
1952 -
1953 glStencilMask(0xff); -
1954 glClearStencil(value); -
1955 glClear(0x00000400); -
1956 glStencilMask(0x0); -
1957 -
1958 q->state()->needsClipBufferClear = false; -
1959}
never executed: }
0
1960 -
1961void QOpenGL2PaintEngineExPrivate::writeClip(const QVectorPath &path, uint value) -
1962{ -
1963 transferMode(BrushDrawingMode); -
1964 -
1965 if (snapToPixelGrid) {
never evaluated: snapToPixelGrid
0
1966 snapToPixelGrid = false; -
1967 matrixDirty = true; -
1968 }
never executed: }
0
1969 -
1970 if (matrixDirty)
never evaluated: matrixDirty
0
1971 updateMatrix();
never executed: updateMatrix();
0
1972 -
1973 stencilClean = false; -
1974 -
1975 const bool singlePass = !path.hasWindingFill()
never evaluated: !path.hasWindingFill()
0
1976 && (((q->state()->currentClip == maxClip - 1) && q->state()->clipTestEnabled)
never evaluated: (q->state()->currentClip == maxClip - 1)
never evaluated: q->state()->clipTestEnabled
0
1977 || q->state()->needsClipBufferClear);
never evaluated: q->state()->needsClipBufferClear
0
1978 const uint referenceClipValue = q->state()->needsClipBufferClear ? 1 : q->state()->currentClip;
never evaluated: q->state()->needsClipBufferClear
0
1979 -
1980 if (q->state()->needsClipBufferClear)
never evaluated: q->state()->needsClipBufferClear
0
1981 clearClip(1);
never executed: clearClip(1);
0
1982 -
1983 if (path.isEmpty()) {
never evaluated: path.isEmpty()
0
1984 glEnable(0x0B90); -
1985 glStencilFunc(0x0203, value, ~GLuint(0x80)); -
1986 return;
never executed: return;
0
1987 } -
1988 -
1989 if (q->state()->clipTestEnabled)
never evaluated: q->state()->clipTestEnabled
0
1990 glStencilFunc(0x0203, q->state()->currentClip, ~GLuint(0x80));
never executed: glStencilFunc(0x0203, q->state()->currentClip, ~GLuint(0x80));
0
1991 else -
1992 glStencilFunc(0x0207, 0, 0xff);
never executed: glStencilFunc(0x0207, 0, 0xff);
0
1993 -
1994 vertexCoordinateArray.clear(); -
1995 vertexCoordinateArray.addPath(path, inverseScale, false); -
1996 -
1997 if (!singlePass)
never evaluated: !singlePass
0
1998 fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill());
never executed: fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill());
0
1999 -
2000 glColorMask(false, false, false, false); -
2001 glEnable(0x0B90); -
2002 useSimpleShader(); -
2003 -
2004 if (singlePass) {
never evaluated: singlePass
0
2005 -
2006 -
2007 -
2008 glStencilFunc(0x0203, referenceClipValue, ~GLuint(0x80)); -
2009 glStencilOp(0x1E00, 0x150A, 0x150A); -
2010 glStencilMask(value ^ referenceClipValue); -
2011 -
2012 drawVertexArrays(vertexCoordinateArray, 0x0006); -
2013 } else {
never executed: }
0
2014 glStencilOp(0x1E00, 0x1E01, 0x1E01); -
2015 glStencilMask(0xff); -
2016 -
2017 if (!q->state()->clipTestEnabled && path.hasWindingFill()) {
never evaluated: !q->state()->clipTestEnabled
never evaluated: path.hasWindingFill()
0
2018 -
2019 glStencilFunc(0x0205, GLuint(0x80), ~GLuint(0x80)); -
2020 composite(vertexCoordinateArray.boundingRect()); -
2021 }
never executed: }
0
2022 -
2023 -
2024 glStencilFunc(0x0205, value, GLuint(0x80)); -
2025 -
2026 composite(vertexCoordinateArray.boundingRect()); -
2027 }
never executed: }
0
2028 -
2029 glStencilFunc(0x0203, value, ~GLuint(0x80)); -
2030 glStencilMask(0); -
2031 -
2032 glColorMask(true, true, true, true); -
2033}
never executed: }
0
2034 -
2035void QOpenGL2PaintEngineEx::clip(const QVectorPath &path, Qt::ClipOperation op) -
2036{ -
2037 -
2038 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
2039 -
2040 state()->clipChanged = true; -
2041 -
2042 ensureActive(); -
2043 -
2044 if (op == Qt::ReplaceClip) {
never evaluated: op == Qt::ReplaceClip
0
2045 op = Qt::IntersectClip; -
2046 if (d->hasClipOperations()) {
never evaluated: d->hasClipOperations()
0
2047 d->systemStateChanged(); -
2048 state()->canRestoreClip = false; -
2049 }
never executed: }
0
2050 }
never executed: }
0
2051 -
2052 -
2053 if (!path.isEmpty() && op == Qt::IntersectClip && (path.shape() == QVectorPath::RectangleHint)) {
never evaluated: !path.isEmpty()
never evaluated: op == Qt::IntersectClip
never evaluated: (path.shape() == QVectorPath::RectangleHint)
0
2054 const QPointF* const points = reinterpret_cast<const QPointF*>(path.points()); -
2055 QRectF rect(points[0], points[2]); -
2056 -
2057 if (state()->matrix.type() <= QTransform::TxScale
never evaluated: state()->matrix.type() <= QTransform::TxScale
0
2058 || (state()->matrix.type() == QTransform::TxRotate
never evaluated: state()->matrix.type() == QTransform::TxRotate
0
2059 && qFuzzyIsNull(state()->matrix.m11())
never evaluated: qFuzzyIsNull(state()->matrix.m11())
0
2060 && qFuzzyIsNull(state()->matrix.m22())))
never evaluated: qFuzzyIsNull(state()->matrix.m22())
0
2061 { -
2062 state()->rectangleClip = state()->rectangleClip.intersected(state()->matrix.mapRect(rect).toRect()); -
2063 d->updateClipScissorTest(); -
2064 return;
never executed: return;
0
2065 } -
2066 }
never executed: }
0
2067 -
2068 -
2069 const QRect pathRect = state()->matrix.mapRect(path.controlPointRect()).toAlignedRect(); -
2070 -
2071 switch (op) { -
2072 case Qt::NoClip: -
2073 if (d->useSystemClip) {
never evaluated: d->useSystemClip
0
2074 state()->clipTestEnabled = true; -
2075 state()->currentClip = 1; -
2076 } else {
never executed: }
0
2077 state()->clipTestEnabled = false; -
2078 }
never executed: }
0
2079 state()->rectangleClip = QRect(0, 0, d->width, d->height); -
2080 state()->canRestoreClip = false; -
2081 d->updateClipScissorTest(); -
2082 break;
never executed: break;
0
2083 case Qt::IntersectClip: -
2084 state()->rectangleClip = state()->rectangleClip.intersected(pathRect); -
2085 d->updateClipScissorTest(); -
2086 d->resetClipIfNeeded(); -
2087 ++d->maxClip; -
2088 d->writeClip(path, d->maxClip); -
2089 state()->currentClip = d->maxClip; -
2090 state()->clipTestEnabled = true; -
2091 break;
never executed: break;
0
2092 default: -
2093 break;
never executed: break;
0
2094 } -
2095}
never executed: }
0
2096 -
2097void QOpenGL2PaintEngineExPrivate::regenerateClip() -
2098{ -
2099 systemStateChanged(); -
2100 replayClipOperations(); -
2101}
never executed: }
0
2102 -
2103void QOpenGL2PaintEngineExPrivate::systemStateChanged() -
2104{ -
2105 QOpenGL2PaintEngineEx * const q = q_func(); -
2106 -
2107 q->state()->clipChanged = true; -
2108 -
2109 if (systemClip.isEmpty()) {
never evaluated: systemClip.isEmpty()
0
2110 useSystemClip = false; -
2111 } else {
never executed: }
0
2112 if (q->paintDevice()->devType() == QInternal::Widget && currentClipDevice) {
never evaluated: q->paintDevice()->devType() == QInternal::Widget
never evaluated: currentClipDevice
0
2113 -
2114 -
2115 useSystemClip = true; -
2116 } else {
never executed: }
0
2117 useSystemClip = true; -
2118 }
never executed: }
0
2119 } -
2120 -
2121 q->state()->clipTestEnabled = false; -
2122 q->state()->needsClipBufferClear = true; -
2123 -
2124 q->state()->currentClip = 1; -
2125 maxClip = 1; -
2126 -
2127 q->state()->rectangleClip = useSystemClip ? systemClip.boundingRect() : QRect(0, 0, width, height);
never evaluated: useSystemClip
0
2128 updateClipScissorTest(); -
2129 -
2130 if (systemClip.rectCount() == 1) {
never evaluated: systemClip.rectCount() == 1
0
2131 if (systemClip.boundingRect() == QRect(0, 0, width, height))
never evaluated: systemClip.boundingRect() == QRect(0, 0, width, height)
0
2132 useSystemClip = false;
never executed: useSystemClip = false;
0
2133 -
2134 -
2135 return;
never executed: return;
0
2136 -
2137 } -
2138 -
2139 if (useSystemClip) {
never evaluated: useSystemClip
0
2140 clearClip(0); -
2141 -
2142 QPainterPath path; -
2143 path.addRegion(systemClip); -
2144 -
2145 q->state()->currentClip = 0; -
2146 writeClip(qtVectorPathForPath(q->state()->matrix.inverted().map(path)), 1); -
2147 q->state()->currentClip = 1; -
2148 q->state()->clipTestEnabled = true; -
2149 }
never executed: }
0
2150}
never executed: }
0
2151 -
2152void QOpenGL2PaintEngineEx::setState(QPainterState *new_state) -
2153{ -
2154 -
2155 -
2156 QOpenGL2PaintEngineExPrivate * const d = d_func(); -
2157 -
2158 QOpenGL2PaintEngineState *s = static_cast<QOpenGL2PaintEngineState *>(new_state); -
2159 QOpenGL2PaintEngineState *old_state = state(); -
2160 -
2161 QPaintEngineEx::setState(s); -
2162 -
2163 if (s->isNew) {
never evaluated: s->isNew
0
2164 -
2165 -
2166 -
2167 s->isNew = false; -
2168 return;
never executed: return;
0
2169 } -
2170 -
2171 -
2172 -
2173 if (old_state == s || old_state->renderHintsChanged)
never evaluated: old_state == s
never evaluated: old_state->renderHintsChanged
0
2174 renderHintsChanged();
never executed: renderHintsChanged();
0
2175 -
2176 if (old_state == s || old_state->matrixChanged)
never evaluated: old_state == s
never evaluated: old_state->matrixChanged
0
2177 d->matrixDirty = true;
never executed: d->matrixDirty = true;
0
2178 -
2179 if (old_state == s || old_state->compositionModeChanged)
never evaluated: old_state == s
never evaluated: old_state->compositionModeChanged
0
2180 d->compositionModeDirty = true;
never executed: d->compositionModeDirty = true;
0
2181 -
2182 if (old_state == s || old_state->opacityChanged)
never evaluated: old_state == s
never evaluated: old_state->opacityChanged
0
2183 d->opacityUniformDirty = true;
never executed: d->opacityUniformDirty = true;
0
2184 -
2185 if (old_state == s || old_state->clipChanged) {
never evaluated: old_state == s
never evaluated: old_state->clipChanged
0
2186 if (old_state && old_state != s && old_state->canRestoreClip) {
never evaluated: old_state
never evaluated: old_state != s
never evaluated: old_state->canRestoreClip
0
2187 d->updateClipScissorTest(); -
2188 glDepthFunc(0x0203); -
2189 } else {
never executed: }
0
2190 d->regenerateClip(); -
2191 }
never executed: }
0
2192 } -
2193}
never executed: }
0
2194 -
2195QPainterState *QOpenGL2PaintEngineEx::createState(QPainterState *orig) const -
2196{ -
2197 if (orig)
never evaluated: orig
0
2198 const_cast<QOpenGL2PaintEngineEx *>(this)->ensureActive();
never executed: const_cast<QOpenGL2PaintEngineEx *>(this)->ensureActive();
0
2199 -
2200 QOpenGL2PaintEngineState *s; -
2201 if (!orig)
never evaluated: !orig
0
2202 s = new QOpenGL2PaintEngineState();
never executed: s = new QOpenGL2PaintEngineState();
0
2203 else -
2204 s = new QOpenGL2PaintEngineState(*static_cast<QOpenGL2PaintEngineState *>(orig));
never executed: s = new QOpenGL2PaintEngineState(*static_cast<QOpenGL2PaintEngineState *>(orig));
0
2205 -
2206 s->matrixChanged = false; -
2207 s->compositionModeChanged = false; -
2208 s->opacityChanged = false; -
2209 s->renderHintsChanged = false; -
2210 s->clipChanged = false; -
2211 -
2212 return s;
never executed: return s;
0
2213} -
2214 -
2215QOpenGL2PaintEngineState::QOpenGL2PaintEngineState(QOpenGL2PaintEngineState &other) -
2216 : QPainterState(other) -
2217{ -
2218 isNew = true; -
2219 needsClipBufferClear = other.needsClipBufferClear; -
2220 clipTestEnabled = other.clipTestEnabled; -
2221 currentClip = other.currentClip; -
2222 canRestoreClip = other.canRestoreClip; -
2223 rectangleClip = other.rectangleClip; -
2224}
never executed: }
0
2225 -
2226QOpenGL2PaintEngineState::QOpenGL2PaintEngineState() -
2227{ -
2228 isNew = true; -
2229 needsClipBufferClear = true; -
2230 clipTestEnabled = false; -
2231 canRestoreClip = true; -
2232}
never executed: }
0
2233 -
2234QOpenGL2PaintEngineState::~QOpenGL2PaintEngineState() -
2235{ -
2236} -
2237 -
2238void QOpenGL2PaintEngineExPrivate::setVertexAttribArrayEnabled(int arrayIndex, bool enabled) -
2239{ -
2240 qt_noop(); -
2241 -
2242 if (vertexAttributeArraysEnabledState[arrayIndex] && !enabled)
never evaluated: vertexAttributeArraysEnabledState[arrayIndex]
never evaluated: !enabled
0
2243 funcs.glDisableVertexAttribArray(arrayIndex);
never executed: funcs.glDisableVertexAttribArray(arrayIndex);
0
2244 -
2245 if (!vertexAttributeArraysEnabledState[arrayIndex] && enabled)
never evaluated: !vertexAttributeArraysEnabledState[arrayIndex]
never evaluated: enabled
0
2246 funcs.glEnableVertexAttribArray(arrayIndex);
never executed: funcs.glEnableVertexAttribArray(arrayIndex);
0
2247 -
2248 vertexAttributeArraysEnabledState[arrayIndex] = enabled; -
2249}
never executed: }
0
2250 -
2251void QOpenGL2PaintEngineExPrivate::syncGlState() -
2252{ -
2253 for (int i = 0; i < 3; ++i) {
never evaluated: i < 3
0
2254 if (vertexAttributeArraysEnabledState[i])
never evaluated: vertexAttributeArraysEnabledState[i]
0
2255 funcs.glEnableVertexAttribArray(i);
never executed: funcs.glEnableVertexAttribArray(i);
0
2256 else -
2257 funcs.glDisableVertexAttribArray(i);
never executed: funcs.glDisableVertexAttribArray(i);
0
2258 } -
2259}
never executed: }
0
2260 -
2261 -
2262 -
2263 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial