| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtOpenGL module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||
| 34 | /* | - | ||||||||||||||||||||||||
| 35 | When the active program changes, we need to update it's uniforms. | - | ||||||||||||||||||||||||
| 36 | We could track state for each program and only update stale uniforms | - | ||||||||||||||||||||||||
| 37 | - Could lead to lots of overhead if there's a lot of programs | - | ||||||||||||||||||||||||
| 38 | We could update all the uniforms when the program changes | - | ||||||||||||||||||||||||
| 39 | - Could end up updating lots of uniforms which don't need updating | - | ||||||||||||||||||||||||
| 40 | - | |||||||||||||||||||||||||
| 41 | Updating uniforms should be cheap, so the overhead of updating up-to-date | - | ||||||||||||||||||||||||
| 42 | uniforms should be minimal. It's also less complex. | - | ||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||
| 44 | Things which _may_ cause a different program to be used: | - | ||||||||||||||||||||||||
| 45 | - Change in brush/pen style | - | ||||||||||||||||||||||||
| 46 | - Change in painter opacity | - | ||||||||||||||||||||||||
| 47 | - Change in composition mode | - | ||||||||||||||||||||||||
| 48 | - | |||||||||||||||||||||||||
| 49 | Whenever we set a mode on the shader manager - it needs to tell us if it had | - | ||||||||||||||||||||||||
| 50 | to switch to a different program. | - | ||||||||||||||||||||||||
| 51 | - | |||||||||||||||||||||||||
| 52 | The shader manager should only switch when we tell it to. E.g. if we set a new | - | ||||||||||||||||||||||||
| 53 | brush style and then switch to transparent painter, we only want it to compile | - | ||||||||||||||||||||||||
| 54 | and use the correct program when we really need it. | - | ||||||||||||||||||||||||
| 55 | */ | - | ||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||
| 57 | // #define QT_OPENGL_CACHE_AS_VBOS | - | ||||||||||||||||||||||||
| 58 | - | |||||||||||||||||||||||||
| 59 | #include "qglgradientcache_p.h" | - | ||||||||||||||||||||||||
| 60 | #include "qpaintengineex_opengl2_p.h" | - | ||||||||||||||||||||||||
| 61 | - | |||||||||||||||||||||||||
| 62 | #include <string.h> //for memcpy | - | ||||||||||||||||||||||||
| 63 | #include <qmath.h> | - | ||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||
| 65 | #include <private/qgl_p.h> | - | ||||||||||||||||||||||||
| 66 | #include <private/qpaintengineex_p.h> | - | ||||||||||||||||||||||||
| 67 | #include <QPaintEngine> | - | ||||||||||||||||||||||||
| 68 | #include <private/qpainter_p.h> | - | ||||||||||||||||||||||||
| 69 | #include <private/qfontengine_p.h> | - | ||||||||||||||||||||||||
| 70 | #include <private/qdatabuffer_p.h> | - | ||||||||||||||||||||||||
| 71 | #include <private/qstatictext_p.h> | - | ||||||||||||||||||||||||
| 72 | #include <QtGui/private/qtriangulator_p.h> | - | ||||||||||||||||||||||||
| 73 | - | |||||||||||||||||||||||||
| 74 | #include "qglengineshadermanager_p.h" | - | ||||||||||||||||||||||||
| 75 | #include "qgl2pexvertexarray_p.h" | - | ||||||||||||||||||||||||
| 76 | #include "qtextureglyphcache_gl_p.h" | - | ||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||
| 78 | #include <QDebug> | - | ||||||||||||||||||||||||
| 79 | - | |||||||||||||||||||||||||
| 80 | #ifndef QT_OPENGL_ES_2 | - | ||||||||||||||||||||||||
| 81 | # include <qopenglfunctions_1_1.h> | - | ||||||||||||||||||||||||
| 82 | #endif | - | ||||||||||||||||||||||||
| 83 | - | |||||||||||||||||||||||||
| 84 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 85 | - | |||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||
| 87 | - | |||||||||||||||||||||||||
| 88 | Q_GUI_EXPORT QImage qt_imageForBrush(int brushStyle, bool invert); | - | ||||||||||||||||||||||||
| 89 | - | |||||||||||||||||||||||||
| 90 | ////////////////////////////////// Private Methods ////////////////////////////////////////// | - | ||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||
| 92 | QGL2PaintEngineExPrivate::~QGL2PaintEngineExPrivate() | - | ||||||||||||||||||||||||
| 93 | { | - | ||||||||||||||||||||||||
| 94 | delete shaderManager; | - | ||||||||||||||||||||||||
| 95 | - | |||||||||||||||||||||||||
| 96 | while (pathCaches.size()) {
| 0-1 | ||||||||||||||||||||||||
| 97 | QVectorPath::CacheEntry *e = *(pathCaches.constBegin()); | - | ||||||||||||||||||||||||
| 98 | e->cleanup(e->engine, e->data); | - | ||||||||||||||||||||||||
| 99 | e->data = 0; | - | ||||||||||||||||||||||||
| 100 | e->engine = 0; | - | ||||||||||||||||||||||||
| 101 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 102 | - | |||||||||||||||||||||||||
| 103 | if (elementIndicesVBOId != 0) {
| 0-1 | ||||||||||||||||||||||||
| 104 | glDeleteBuffers(1, &elementIndicesVBOId); | - | ||||||||||||||||||||||||
| 105 | elementIndicesVBOId = 0; | - | ||||||||||||||||||||||||
| 106 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 107 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||
| 109 | void QGL2PaintEngineExPrivate::updateTextureFilter(GLenum target, GLenum wrapMode, bool smoothPixmapTransform, GLuint id) | - | ||||||||||||||||||||||||
| 110 | { | - | ||||||||||||||||||||||||
| 111 | // glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); //### Is it always this texture unit? | - | ||||||||||||||||||||||||
| 112 | if (id != GLuint(-1) && id == lastTextureUsed)
| 0 | ||||||||||||||||||||||||
| 113 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 114 | - | |||||||||||||||||||||||||
| 115 | lastTextureUsed = id; | - | ||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||
| 117 | if (smoothPixmapTransform) {
| 0 | ||||||||||||||||||||||||
| 118 | glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | - | ||||||||||||||||||||||||
| 119 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | - | ||||||||||||||||||||||||
| 120 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 121 | glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | - | ||||||||||||||||||||||||
| 122 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | - | ||||||||||||||||||||||||
| 123 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 124 | glTexParameteri(target, GL_TEXTURE_WRAP_S, wrapMode); | - | ||||||||||||||||||||||||
| 125 | glTexParameteri(target, GL_TEXTURE_WRAP_T, wrapMode); | - | ||||||||||||||||||||||||
| 126 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 127 | - | |||||||||||||||||||||||||
| 128 | - | |||||||||||||||||||||||||
| 129 | inline QColor qt_premultiplyColor(QColor c, GLfloat opacity) | - | ||||||||||||||||||||||||
| 130 | { | - | ||||||||||||||||||||||||
| 131 | qreal alpha = c.alphaF() * opacity; | - | ||||||||||||||||||||||||
| 132 | c.setAlphaF(alpha); | - | ||||||||||||||||||||||||
| 133 | c.setRedF(c.redF() * alpha); | - | ||||||||||||||||||||||||
| 134 | c.setGreenF(c.greenF() * alpha); | - | ||||||||||||||||||||||||
| 135 | c.setBlueF(c.blueF() * alpha); | - | ||||||||||||||||||||||||
| 136 | return c; executed 2 times by 1 test: return c;Executed by:
| 2 | ||||||||||||||||||||||||
| 137 | } | - | ||||||||||||||||||||||||
| 138 | - | |||||||||||||||||||||||||
| 139 | - | |||||||||||||||||||||||||
| 140 | void QGL2PaintEngineExPrivate::setBrush(const QBrush& brush) | - | ||||||||||||||||||||||||
| 141 | { | - | ||||||||||||||||||||||||
| 142 | if (qbrush_fast_equals(currentBrush, brush))
| 2-26 | ||||||||||||||||||||||||
| 143 | return; executed 26 times by 1 test: return;Executed by:
| 26 | ||||||||||||||||||||||||
| 144 | - | |||||||||||||||||||||||||
| 145 | const Qt::BrushStyle newStyle = qbrush_style(brush); | - | ||||||||||||||||||||||||
| 146 | Q_ASSERT(newStyle != Qt::NoBrush); | - | ||||||||||||||||||||||||
| 147 | - | |||||||||||||||||||||||||
| 148 | currentBrush = brush; | - | ||||||||||||||||||||||||
| 149 | if (!currentBrushPixmap.isNull())
| 0-2 | ||||||||||||||||||||||||
| 150 | currentBrushPixmap = QPixmap(); never executed: currentBrushPixmap = QPixmap(); | 0 | ||||||||||||||||||||||||
| 151 | brushUniformsDirty = true; // All brushes have at least one uniform | - | ||||||||||||||||||||||||
| 152 | - | |||||||||||||||||||||||||
| 153 | if (newStyle > Qt::SolidPattern)
| 0-2 | ||||||||||||||||||||||||
| 154 | brushTextureDirty = true; never executed: brushTextureDirty = true; | 0 | ||||||||||||||||||||||||
| 155 | - | |||||||||||||||||||||||||
| 156 | if (currentBrush.style() == Qt::TexturePattern
| 0-2 | ||||||||||||||||||||||||
| 157 | && qHasPixmapTexture(brush) && brush.texture().isQBitmap())
| 0 | ||||||||||||||||||||||||
| 158 | { | - | ||||||||||||||||||||||||
| 159 | shaderManager->setSrcPixelType(QGLEngineShaderManager::TextureSrcWithPattern); | - | ||||||||||||||||||||||||
| 160 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 161 | shaderManager->setSrcPixelType(newStyle); | - | ||||||||||||||||||||||||
| 162 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 163 | shaderManager->optimiseForBrushTransform(currentBrush.transform().type()); | - | ||||||||||||||||||||||||
| 164 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 165 | - | |||||||||||||||||||||||||
| 166 | - | |||||||||||||||||||||||||
| 167 | void QGL2PaintEngineExPrivate::useSimpleShader() | - | ||||||||||||||||||||||||
| 168 | { | - | ||||||||||||||||||||||||
| 169 | shaderManager->useSimpleProgram(); | - | ||||||||||||||||||||||||
| 170 | - | |||||||||||||||||||||||||
| 171 | if (matrixDirty)
| 0-4 | ||||||||||||||||||||||||
| 172 | updateMatrix(); never executed: updateMatrix(); | 0 | ||||||||||||||||||||||||
| 173 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 174 | - | |||||||||||||||||||||||||
| 175 | // ####TODO Properly #ifdef this class to use #define symbols actually defined | - | ||||||||||||||||||||||||
| 176 | // by OpenGL/ES includes | - | ||||||||||||||||||||||||
| 177 | #ifndef GL_MIRRORED_REPEAT_IBM | - | ||||||||||||||||||||||||
| 178 | #define GL_MIRRORED_REPEAT_IBM 0x8370 | - | ||||||||||||||||||||||||
| 179 | #endif | - | ||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||
| 181 | void QGL2PaintEngineExPrivate::updateBrushTexture() | - | ||||||||||||||||||||||||
| 182 | { | - | ||||||||||||||||||||||||
| 183 | Q_Q(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 184 | // qDebug("QGL2PaintEngineExPrivate::updateBrushTexture()"); | - | ||||||||||||||||||||||||
| 185 | Qt::BrushStyle style = currentBrush.style(); | - | ||||||||||||||||||||||||
| 186 | - | |||||||||||||||||||||||||
| 187 | if ( (style >= Qt::Dense1Pattern) && (style <= Qt::DiagCrossPattern) ) {
| 0-2 | ||||||||||||||||||||||||
| 188 | // Get the image data for the pattern | - | ||||||||||||||||||||||||
| 189 | QImage texImage = qt_imageForBrush(style, false); | - | ||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||
| 191 | glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); | - | ||||||||||||||||||||||||
| 192 | ctx->d_func()->bindTexture(texImage, GL_TEXTURE_2D, GL_RGBA, QGLContext::InternalBindOption); | - | ||||||||||||||||||||||||
| 193 | updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform); | - | ||||||||||||||||||||||||
| 194 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 195 | else if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) {
| 0-2 | ||||||||||||||||||||||||
| 196 | // Gradiant brush: All the gradiants use the same texture | - | ||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||
| 198 | const QGradient* g = currentBrush.gradient(); | - | ||||||||||||||||||||||||
| 199 | - | |||||||||||||||||||||||||
| 200 | // We apply global opacity in the fragment shaders, so we always pass 1.0 | - | ||||||||||||||||||||||||
| 201 | // for opacity to the cache. | - | ||||||||||||||||||||||||
| 202 | GLuint texId = QGL2GradientCache::cacheForContext(ctx)->getBuffer(*g, 1.0); | - | ||||||||||||||||||||||||
| 203 | - | |||||||||||||||||||||||||
| 204 | glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); | - | ||||||||||||||||||||||||
| 205 | glBindTexture(GL_TEXTURE_2D, texId); | - | ||||||||||||||||||||||||
| 206 | - | |||||||||||||||||||||||||
| 207 | if (g->spread() == QGradient::RepeatSpread || g->type() == QGradient::ConicalGradient)
| 0 | ||||||||||||||||||||||||
| 208 | updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, q->state()->renderHints & QPainter::SmoothPixmapTransform); never executed: updateTextureFilter(0x0DE1, 0x2901, q->state()->renderHints & QPainter::SmoothPixmapTransform); | 0 | ||||||||||||||||||||||||
| 209 | else if (g->spread() == QGradient::ReflectSpread)
| 0 | ||||||||||||||||||||||||
| 210 | updateTextureFilter(GL_TEXTURE_2D, GL_MIRRORED_REPEAT_IBM, q->state()->renderHints & QPainter::SmoothPixmapTransform); never executed: updateTextureFilter(0x0DE1, 0x8370, q->state()->renderHints & QPainter::SmoothPixmapTransform); | 0 | ||||||||||||||||||||||||
| 211 | else | - | ||||||||||||||||||||||||
| 212 | updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, q->state()->renderHints & QPainter::SmoothPixmapTransform); never executed: updateTextureFilter(0x0DE1, 0x812F, q->state()->renderHints & QPainter::SmoothPixmapTransform); | 0 | ||||||||||||||||||||||||
| 213 | } | - | ||||||||||||||||||||||||
| 214 | else if (style == Qt::TexturePattern) {
| 0-2 | ||||||||||||||||||||||||
| 215 | currentBrushPixmap = currentBrush.texture(); | - | ||||||||||||||||||||||||
| 216 | - | |||||||||||||||||||||||||
| 217 | int max_texture_size = ctx->d_func()->maxTextureSize(); | - | ||||||||||||||||||||||||
| 218 | if (currentBrushPixmap.width() > max_texture_size || currentBrushPixmap.height() > max_texture_size)
| 0 | ||||||||||||||||||||||||
| 219 | 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 | ||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||
| 221 | GLuint wrapMode = GL_REPEAT; | - | ||||||||||||||||||||||||
| 222 | if (ctx->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||||||||
| 223 | // OpenGL ES does not support GL_REPEAT wrap modes for NPOT textures. So instead, | - | ||||||||||||||||||||||||
| 224 | // we emulate GL_REPEAT by only taking the fractional part of the texture coords | - | ||||||||||||||||||||||||
| 225 | // in the qopenglslTextureBrushSrcFragmentShader program. | - | ||||||||||||||||||||||||
| 226 | wrapMode = GL_CLAMP_TO_EDGE; | - | ||||||||||||||||||||||||
| 227 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 228 | - | |||||||||||||||||||||||||
| 229 | glActiveTexture(GL_TEXTURE0 + QT_BRUSH_TEXTURE_UNIT); | - | ||||||||||||||||||||||||
| 230 | QGLTexture *tex = ctx->d_func()->bindTexture(currentBrushPixmap, GL_TEXTURE_2D, GL_RGBA, | - | ||||||||||||||||||||||||
| 231 | QGLContext::InternalBindOption | | - | ||||||||||||||||||||||||
| 232 | QGLContext::CanFlipNativePixmapBindOption); | - | ||||||||||||||||||||||||
| 233 | updateTextureFilter(GL_TEXTURE_2D, wrapMode, q->state()->renderHints & QPainter::SmoothPixmapTransform); | - | ||||||||||||||||||||||||
| 234 | textureInvertedY = tex->options & QGLContext::InvertedYBindOption ? -1 : 1;
| 0 | ||||||||||||||||||||||||
| 235 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 236 | brushTextureDirty = false; | - | ||||||||||||||||||||||||
| 237 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 238 | - | |||||||||||||||||||||||||
| 239 | - | |||||||||||||||||||||||||
| 240 | void QGL2PaintEngineExPrivate::updateBrushUniforms() | - | ||||||||||||||||||||||||
| 241 | { | - | ||||||||||||||||||||||||
| 242 | // qDebug("QGL2PaintEngineExPrivate::updateBrushUniforms()"); | - | ||||||||||||||||||||||||
| 243 | Qt::BrushStyle style = currentBrush.style(); | - | ||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||
| 245 | if (style == Qt::NoBrush)
| 0-2 | ||||||||||||||||||||||||
| 246 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 247 | - | |||||||||||||||||||||||||
| 248 | QTransform brushQTransform = currentBrush.transform(); | - | ||||||||||||||||||||||||
| 249 | - | |||||||||||||||||||||||||
| 250 | if (style == Qt::SolidPattern) {
| 0-2 | ||||||||||||||||||||||||
| 251 | QColor col = qt_premultiplyColor(currentBrush.color(), (GLfloat)q->state()->opacity); | - | ||||||||||||||||||||||||
| 252 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::FragmentColor), col); | - | ||||||||||||||||||||||||
| 253 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 254 | else { | - | ||||||||||||||||||||||||
| 255 | // All other brushes have a transform and thus need the translation point: | - | ||||||||||||||||||||||||
| 256 | QPointF translationPoint; | - | ||||||||||||||||||||||||
| 257 | - | |||||||||||||||||||||||||
| 258 | if (style <= Qt::DiagCrossPattern) {
| 0 | ||||||||||||||||||||||||
| 259 | QColor col = qt_premultiplyColor(currentBrush.color(), (GLfloat)q->state()->opacity); | - | ||||||||||||||||||||||||
| 260 | - | |||||||||||||||||||||||||
| 261 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::PatternColor), col); | - | ||||||||||||||||||||||||
| 262 | - | |||||||||||||||||||||||||
| 263 | QVector2D halfViewportSize(width*0.5, height*0.5); | - | ||||||||||||||||||||||||
| 264 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize); | - | ||||||||||||||||||||||||
| 265 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 266 | else if (style == Qt::LinearGradientPattern) {
| 0 | ||||||||||||||||||||||||
| 267 | const QLinearGradient *g = static_cast<const QLinearGradient *>(currentBrush.gradient()); | - | ||||||||||||||||||||||||
| 268 | - | |||||||||||||||||||||||||
| 269 | QPointF realStart = g->start(); | - | ||||||||||||||||||||||||
| 270 | QPointF realFinal = g->finalStop(); | - | ||||||||||||||||||||||||
| 271 | translationPoint = realStart; | - | ||||||||||||||||||||||||
| 272 | - | |||||||||||||||||||||||||
| 273 | QPointF l = realFinal - realStart; | - | ||||||||||||||||||||||||
| 274 | - | |||||||||||||||||||||||||
| 275 | QVector3D linearData( | - | ||||||||||||||||||||||||
| 276 | l.x(), | - | ||||||||||||||||||||||||
| 277 | l.y(), | - | ||||||||||||||||||||||||
| 278 | 1.0f / (l.x() * l.x() + l.y() * l.y()) | - | ||||||||||||||||||||||||
| 279 | ); | - | ||||||||||||||||||||||||
| 280 | - | |||||||||||||||||||||||||
| 281 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::LinearData), linearData); | - | ||||||||||||||||||||||||
| 282 | - | |||||||||||||||||||||||||
| 283 | QVector2D halfViewportSize(width*0.5, height*0.5); | - | ||||||||||||||||||||||||
| 284 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize); | - | ||||||||||||||||||||||||
| 285 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 286 | else if (style == Qt::ConicalGradientPattern) {
| 0 | ||||||||||||||||||||||||
| 287 | const QConicalGradient *g = static_cast<const QConicalGradient *>(currentBrush.gradient()); | - | ||||||||||||||||||||||||
| 288 | translationPoint = g->center(); | - | ||||||||||||||||||||||||
| 289 | - | |||||||||||||||||||||||||
| 290 | GLfloat angle = -qDegreesToRadians(g->angle()); | - | ||||||||||||||||||||||||
| 291 | - | |||||||||||||||||||||||||
| 292 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Angle), angle); | - | ||||||||||||||||||||||||
| 293 | - | |||||||||||||||||||||||||
| 294 | QVector2D halfViewportSize(width*0.5, height*0.5); | - | ||||||||||||||||||||||||
| 295 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize); | - | ||||||||||||||||||||||||
| 296 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 297 | else if (style == Qt::RadialGradientPattern) {
| 0 | ||||||||||||||||||||||||
| 298 | const QRadialGradient *g = static_cast<const QRadialGradient *>(currentBrush.gradient()); | - | ||||||||||||||||||||||||
| 299 | QPointF realCenter = g->center(); | - | ||||||||||||||||||||||||
| 300 | QPointF realFocal = g->focalPoint(); | - | ||||||||||||||||||||||||
| 301 | qreal realRadius = g->centerRadius() - g->focalRadius(); | - | ||||||||||||||||||||||||
| 302 | translationPoint = realFocal; | - | ||||||||||||||||||||||||
| 303 | - | |||||||||||||||||||||||||
| 304 | QPointF fmp = realCenter - realFocal; | - | ||||||||||||||||||||||||
| 305 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Fmp), fmp); | - | ||||||||||||||||||||||||
| 306 | - | |||||||||||||||||||||||||
| 307 | GLfloat fmp2_m_radius2 = -fmp.x() * fmp.x() - fmp.y() * fmp.y() + realRadius*realRadius; | - | ||||||||||||||||||||||||
| 308 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Fmp2MRadius2), fmp2_m_radius2); | - | ||||||||||||||||||||||||
| 309 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Inverse2Fmp2MRadius2), | - | ||||||||||||||||||||||||
| 310 | GLfloat(1.0 / (2.0*fmp2_m_radius2))); | - | ||||||||||||||||||||||||
| 311 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::SqrFr), | - | ||||||||||||||||||||||||
| 312 | GLfloat(g->focalRadius() * g->focalRadius())); | - | ||||||||||||||||||||||||
| 313 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::BRadius), | - | ||||||||||||||||||||||||
| 314 | GLfloat(2 * (g->centerRadius() - g->focalRadius()) * g->focalRadius()), | - | ||||||||||||||||||||||||
| 315 | g->focalRadius(), | - | ||||||||||||||||||||||||
| 316 | g->centerRadius() - g->focalRadius()); | - | ||||||||||||||||||||||||
| 317 | - | |||||||||||||||||||||||||
| 318 | QVector2D halfViewportSize(width*0.5, height*0.5); | - | ||||||||||||||||||||||||
| 319 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize); | - | ||||||||||||||||||||||||
| 320 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 321 | else if (style == Qt::TexturePattern) {
| 0 | ||||||||||||||||||||||||
| 322 | const QPixmap& texPixmap = currentBrush.texture(); | - | ||||||||||||||||||||||||
| 323 | - | |||||||||||||||||||||||||
| 324 | if (qHasPixmapTexture(currentBrush) && currentBrush.texture().isQBitmap()) {
| 0 | ||||||||||||||||||||||||
| 325 | QColor col = qt_premultiplyColor(currentBrush.color(), (GLfloat)q->state()->opacity); | - | ||||||||||||||||||||||||
| 326 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::PatternColor), col); | - | ||||||||||||||||||||||||
| 327 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 328 | - | |||||||||||||||||||||||||
| 329 | QSizeF invertedTextureSize(1.0 / texPixmap.width(), 1.0 / texPixmap.height()); | - | ||||||||||||||||||||||||
| 330 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::InvertedTextureSize), invertedTextureSize); | - | ||||||||||||||||||||||||
| 331 | - | |||||||||||||||||||||||||
| 332 | QVector2D halfViewportSize(width*0.5, height*0.5); | - | ||||||||||||||||||||||||
| 333 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::HalfViewportSize), halfViewportSize); | - | ||||||||||||||||||||||||
| 334 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 335 | else | - | ||||||||||||||||||||||||
| 336 | qWarning("QGL2PaintEngineEx: Unimplemented fill style"); never executed: QMessageLogger(__FILE__, 336, __PRETTY_FUNCTION__).warning("QGL2PaintEngineEx: Unimplemented fill style"); | 0 | ||||||||||||||||||||||||
| 337 | - | |||||||||||||||||||||||||
| 338 | const QPointF &brushOrigin = q->state()->brushOrigin; | - | ||||||||||||||||||||||||
| 339 | QTransform matrix = q->state()->matrix; | - | ||||||||||||||||||||||||
| 340 | matrix.translate(brushOrigin.x(), brushOrigin.y()); | - | ||||||||||||||||||||||||
| 341 | - | |||||||||||||||||||||||||
| 342 | QTransform translate(1, 0, 0, 1, -translationPoint.x(), -translationPoint.y()); | - | ||||||||||||||||||||||||
| 343 | qreal m22 = -1; | - | ||||||||||||||||||||||||
| 344 | qreal dy = height; | - | ||||||||||||||||||||||||
| 345 | if (device->isFlipped()) {
| 0 | ||||||||||||||||||||||||
| 346 | m22 = 1; | - | ||||||||||||||||||||||||
| 347 | dy = 0; | - | ||||||||||||||||||||||||
| 348 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 349 | QTransform gl_to_qt(1, 0, 0, m22, 0, dy); | - | ||||||||||||||||||||||||
| 350 | QTransform inv_matrix; | - | ||||||||||||||||||||||||
| 351 | if (style == Qt::TexturePattern && textureInvertedY == -1)
| 0 | ||||||||||||||||||||||||
| 352 | 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 | ||||||||||||||||||||||||
| 353 | else | - | ||||||||||||||||||||||||
| 354 | inv_matrix = gl_to_qt * (brushQTransform * matrix).inverted() * translate; never executed: inv_matrix = gl_to_qt * (brushQTransform * matrix).inverted() * translate; | 0 | ||||||||||||||||||||||||
| 355 | - | |||||||||||||||||||||||||
| 356 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::BrushTransform), inv_matrix); | - | ||||||||||||||||||||||||
| 357 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::BrushTexture), QT_BRUSH_TEXTURE_UNIT); | - | ||||||||||||||||||||||||
| 358 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 359 | brushUniformsDirty = false; | - | ||||||||||||||||||||||||
| 360 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 361 | - | |||||||||||||||||||||||||
| 362 | - | |||||||||||||||||||||||||
| 363 | // This assumes the shader manager has already setup the correct shader program | - | ||||||||||||||||||||||||
| 364 | void QGL2PaintEngineExPrivate::updateMatrix() | - | ||||||||||||||||||||||||
| 365 | { | - | ||||||||||||||||||||||||
| 366 | // qDebug("QGL2PaintEngineExPrivate::updateMatrix()"); | - | ||||||||||||||||||||||||
| 367 | - | |||||||||||||||||||||||||
| 368 | const QTransform& transform = q->state()->matrix; | - | ||||||||||||||||||||||||
| 369 | - | |||||||||||||||||||||||||
| 370 | // The projection matrix converts from Qt's coordinate system to GL's coordinate system | - | ||||||||||||||||||||||||
| 371 | // * GL's viewport is 2x2, Qt's is width x height | - | ||||||||||||||||||||||||
| 372 | // * GL has +y -> -y going from bottom -> top, Qt is the other way round | - | ||||||||||||||||||||||||
| 373 | // * GL has [0,0] in the center, Qt has it in the top-left | - | ||||||||||||||||||||||||
| 374 | // | - | ||||||||||||||||||||||||
| 375 | // This results in the Projection matrix below, which is multiplied by the painter's | - | ||||||||||||||||||||||||
| 376 | // transformation matrix, as shown below: | - | ||||||||||||||||||||||||
| 377 | // | - | ||||||||||||||||||||||||
| 378 | // Projection Matrix Painter Transform | - | ||||||||||||||||||||||||
| 379 | // ------------------------------------------------ ------------------------ | - | ||||||||||||||||||||||||
| 380 | // | 2.0 / width | 0.0 | -1.0 | | m11 | m21 | dx | | - | ||||||||||||||||||||||||
| 381 | // | 0.0 | -2.0 / height | 1.0 | * | m12 | m22 | dy | | - | ||||||||||||||||||||||||
| 382 | // | 0.0 | 0.0 | 1.0 | | m13 | m23 | m33 | | - | ||||||||||||||||||||||||
| 383 | // ------------------------------------------------ ------------------------ | - | ||||||||||||||||||||||||
| 384 | // | - | ||||||||||||||||||||||||
| 385 | // NOTE: The resultant matrix is also transposed, as GL expects column-major matracies | - | ||||||||||||||||||||||||
| 386 | - | |||||||||||||||||||||||||
| 387 | const GLfloat wfactor = 2.0f / width; | - | ||||||||||||||||||||||||
| 388 | GLfloat hfactor = -2.0f / height; | - | ||||||||||||||||||||||||
| 389 | - | |||||||||||||||||||||||||
| 390 | GLfloat dx = transform.dx(); | - | ||||||||||||||||||||||||
| 391 | GLfloat dy = transform.dy(); | - | ||||||||||||||||||||||||
| 392 | - | |||||||||||||||||||||||||
| 393 | if (device->isFlipped()) {
| 0-2 | ||||||||||||||||||||||||
| 394 | hfactor *= -1; | - | ||||||||||||||||||||||||
| 395 | dy -= height; | - | ||||||||||||||||||||||||
| 396 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 397 | - | |||||||||||||||||||||||||
| 398 | // Non-integer translates can have strange effects for some rendering operations such as | - | ||||||||||||||||||||||||
| 399 | // anti-aliased text rendering. In such cases, we snap the translate to the pixel grid. | - | ||||||||||||||||||||||||
| 400 | if (snapToPixelGrid && transform.type() == QTransform::TxTranslate) {
| 0-2 | ||||||||||||||||||||||||
| 401 | // 0.50 needs to rounded down to 0.0 for consistency with raster engine: | - | ||||||||||||||||||||||||
| 402 | dx = std::ceil(dx - 0.5f); | - | ||||||||||||||||||||||||
| 403 | dy = std::ceil(dy - 0.5f); | - | ||||||||||||||||||||||||
| 404 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 405 | pmvMatrix[0][0] = (wfactor * transform.m11()) - transform.m13(); | - | ||||||||||||||||||||||||
| 406 | pmvMatrix[1][0] = (wfactor * transform.m21()) - transform.m23(); | - | ||||||||||||||||||||||||
| 407 | pmvMatrix[2][0] = (wfactor * dx) - transform.m33(); | - | ||||||||||||||||||||||||
| 408 | pmvMatrix[0][1] = (hfactor * transform.m12()) + transform.m13(); | - | ||||||||||||||||||||||||
| 409 | pmvMatrix[1][1] = (hfactor * transform.m22()) + transform.m23(); | - | ||||||||||||||||||||||||
| 410 | pmvMatrix[2][1] = (hfactor * dy) + transform.m33(); | - | ||||||||||||||||||||||||
| 411 | pmvMatrix[0][2] = transform.m13(); | - | ||||||||||||||||||||||||
| 412 | pmvMatrix[1][2] = transform.m23(); | - | ||||||||||||||||||||||||
| 413 | pmvMatrix[2][2] = transform.m33(); | - | ||||||||||||||||||||||||
| 414 | - | |||||||||||||||||||||||||
| 415 | // 1/10000 == 0.0001, so we have good enough res to cover curves | - | ||||||||||||||||||||||||
| 416 | // that span the entire widget... | - | ||||||||||||||||||||||||
| 417 | inverseScale = qMax(1 / qMax( qMax(qAbs(transform.m11()), qAbs(transform.m22())), | - | ||||||||||||||||||||||||
| 418 | qMax(qAbs(transform.m12()), qAbs(transform.m21())) ), | - | ||||||||||||||||||||||||
| 419 | qreal(0.0001)); | - | ||||||||||||||||||||||||
| 420 | - | |||||||||||||||||||||||||
| 421 | matrixDirty = false; | - | ||||||||||||||||||||||||
| 422 | matrixUniformDirty = true; | - | ||||||||||||||||||||||||
| 423 | - | |||||||||||||||||||||||||
| 424 | // Set the PMV matrix attribute. As we use an attributes rather than uniforms, we only | - | ||||||||||||||||||||||||
| 425 | // need to do this once for every matrix change and persists across all shader programs. | - | ||||||||||||||||||||||||
| 426 | glVertexAttrib3fv(QT_PMV_MATRIX_1_ATTR, pmvMatrix[0]); | - | ||||||||||||||||||||||||
| 427 | glVertexAttrib3fv(QT_PMV_MATRIX_2_ATTR, pmvMatrix[1]); | - | ||||||||||||||||||||||||
| 428 | glVertexAttrib3fv(QT_PMV_MATRIX_3_ATTR, pmvMatrix[2]); | - | ||||||||||||||||||||||||
| 429 | - | |||||||||||||||||||||||||
| 430 | dasher.setInvScale(inverseScale); | - | ||||||||||||||||||||||||
| 431 | stroker.setInvScale(inverseScale); | - | ||||||||||||||||||||||||
| 432 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 433 | - | |||||||||||||||||||||||||
| 434 | - | |||||||||||||||||||||||||
| 435 | void QGL2PaintEngineExPrivate::updateCompositionMode() | - | ||||||||||||||||||||||||
| 436 | { | - | ||||||||||||||||||||||||
| 437 | // NOTE: The entire paint engine works on pre-multiplied data - which is why some of these | - | ||||||||||||||||||||||||
| 438 | // composition modes look odd. | - | ||||||||||||||||||||||||
| 439 | // qDebug() << "QGL2PaintEngineExPrivate::updateCompositionMode() - Setting GL composition mode for " << q->state()->composition_mode; | - | ||||||||||||||||||||||||
| 440 | switch(q->state()->composition_mode) { | - | ||||||||||||||||||||||||
| 441 | case QPainter::CompositionMode_SourceOver: executed 2 times by 1 test: case QPainter::CompositionMode_SourceOver:Executed by:
| 2 | ||||||||||||||||||||||||
| 442 | glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); | - | ||||||||||||||||||||||||
| 443 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||||||||
| 444 | case QPainter::CompositionMode_DestinationOver: never executed: case QPainter::CompositionMode_DestinationOver: | 0 | ||||||||||||||||||||||||
| 445 | glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE); | - | ||||||||||||||||||||||||
| 446 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 447 | case QPainter::CompositionMode_Clear: never executed: case QPainter::CompositionMode_Clear: | 0 | ||||||||||||||||||||||||
| 448 | glBlendFunc(GL_ZERO, GL_ZERO); | - | ||||||||||||||||||||||||
| 449 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 450 | case QPainter::CompositionMode_Source: never executed: case QPainter::CompositionMode_Source: | 0 | ||||||||||||||||||||||||
| 451 | glBlendFunc(GL_ONE, GL_ZERO); | - | ||||||||||||||||||||||||
| 452 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 453 | case QPainter::CompositionMode_Destination: never executed: case QPainter::CompositionMode_Destination: | 0 | ||||||||||||||||||||||||
| 454 | glBlendFunc(GL_ZERO, GL_ONE); | - | ||||||||||||||||||||||||
| 455 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 456 | case QPainter::CompositionMode_SourceIn: never executed: case QPainter::CompositionMode_SourceIn: | 0 | ||||||||||||||||||||||||
| 457 | glBlendFunc(GL_DST_ALPHA, GL_ZERO); | - | ||||||||||||||||||||||||
| 458 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 459 | case QPainter::CompositionMode_DestinationIn: never executed: case QPainter::CompositionMode_DestinationIn: | 0 | ||||||||||||||||||||||||
| 460 | glBlendFunc(GL_ZERO, GL_SRC_ALPHA); | - | ||||||||||||||||||||||||
| 461 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 462 | case QPainter::CompositionMode_SourceOut: never executed: case QPainter::CompositionMode_SourceOut: | 0 | ||||||||||||||||||||||||
| 463 | glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ZERO); | - | ||||||||||||||||||||||||
| 464 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 465 | case QPainter::CompositionMode_DestinationOut: never executed: case QPainter::CompositionMode_DestinationOut: | 0 | ||||||||||||||||||||||||
| 466 | glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA); | - | ||||||||||||||||||||||||
| 467 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 468 | case QPainter::CompositionMode_SourceAtop: never executed: case QPainter::CompositionMode_SourceAtop: | 0 | ||||||||||||||||||||||||
| 469 | glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | - | ||||||||||||||||||||||||
| 470 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 471 | case QPainter::CompositionMode_DestinationAtop: never executed: case QPainter::CompositionMode_DestinationAtop: | 0 | ||||||||||||||||||||||||
| 472 | glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_SRC_ALPHA); | - | ||||||||||||||||||||||||
| 473 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 474 | case QPainter::CompositionMode_Xor: never executed: case QPainter::CompositionMode_Xor: | 0 | ||||||||||||||||||||||||
| 475 | glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | - | ||||||||||||||||||||||||
| 476 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 477 | case QPainter::CompositionMode_Plus: never executed: case QPainter::CompositionMode_Plus: | 0 | ||||||||||||||||||||||||
| 478 | glBlendFunc(GL_ONE, GL_ONE); | - | ||||||||||||||||||||||||
| 479 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 480 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 481 | qWarning("Unsupported composition mode"); | - | ||||||||||||||||||||||||
| 482 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 483 | } | - | ||||||||||||||||||||||||
| 484 | - | |||||||||||||||||||||||||
| 485 | compositionModeDirty = false; | - | ||||||||||||||||||||||||
| 486 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 487 | - | |||||||||||||||||||||||||
| 488 | static inline void setCoords(GLfloat *coords, const QGLRect &rect) | - | ||||||||||||||||||||||||
| 489 | { | - | ||||||||||||||||||||||||
| 490 | coords[0] = rect.left; | - | ||||||||||||||||||||||||
| 491 | coords[1] = rect.top; | - | ||||||||||||||||||||||||
| 492 | coords[2] = rect.right; | - | ||||||||||||||||||||||||
| 493 | coords[3] = rect.top; | - | ||||||||||||||||||||||||
| 494 | coords[4] = rect.right; | - | ||||||||||||||||||||||||
| 495 | coords[5] = rect.bottom; | - | ||||||||||||||||||||||||
| 496 | coords[6] = rect.left; | - | ||||||||||||||||||||||||
| 497 | coords[7] = rect.bottom; | - | ||||||||||||||||||||||||
| 498 | } executed 30 times by 1 test: end of blockExecuted by:
| 30 | ||||||||||||||||||||||||
| 499 | - | |||||||||||||||||||||||||
| 500 | void QGL2PaintEngineExPrivate::drawTexture(const QGLRect& dest, const QGLRect& src, const QSize &textureSize, bool opaque, bool pattern) | - | ||||||||||||||||||||||||
| 501 | { | - | ||||||||||||||||||||||||
| 502 | // Setup for texture drawing | - | ||||||||||||||||||||||||
| 503 | currentBrush = noBrush; | - | ||||||||||||||||||||||||
| 504 | shaderManager->setSrcPixelType(pattern ? QGLEngineShaderManager::PatternSrc : QGLEngineShaderManager::ImageSrc); | - | ||||||||||||||||||||||||
| 505 | - | |||||||||||||||||||||||||
| 506 | if (snapToPixelGrid) {
| 0 | ||||||||||||||||||||||||
| 507 | snapToPixelGrid = false; | - | ||||||||||||||||||||||||
| 508 | matrixDirty = true; | - | ||||||||||||||||||||||||
| 509 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 510 | - | |||||||||||||||||||||||||
| 511 | if (prepareForDraw(opaque))
| 0 | ||||||||||||||||||||||||
| 512 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::ImageTexture), QT_IMAGE_TEXTURE_UNIT); never executed: shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::ImageTexture), GLuint(0)); | 0 | ||||||||||||||||||||||||
| 513 | - | |||||||||||||||||||||||||
| 514 | if (pattern) {
| 0 | ||||||||||||||||||||||||
| 515 | QColor col = qt_premultiplyColor(q->state()->pen.color(), (GLfloat)q->state()->opacity); | - | ||||||||||||||||||||||||
| 516 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::PatternColor), col); | - | ||||||||||||||||||||||||
| 517 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 518 | - | |||||||||||||||||||||||||
| 519 | GLfloat dx = 1.0 / textureSize.width(); | - | ||||||||||||||||||||||||
| 520 | GLfloat dy = 1.0 / textureSize.height(); | - | ||||||||||||||||||||||||
| 521 | - | |||||||||||||||||||||||||
| 522 | QGLRect srcTextureRect(src.left*dx, src.top*dy, src.right*dx, src.bottom*dy); | - | ||||||||||||||||||||||||
| 523 | - | |||||||||||||||||||||||||
| 524 | setCoords(staticVertexCoordinateArray, dest); | - | ||||||||||||||||||||||||
| 525 | setCoords(staticTextureCoordinateArray, srcTextureRect); | - | ||||||||||||||||||||||||
| 526 | - | |||||||||||||||||||||||||
| 527 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | - | ||||||||||||||||||||||||
| 528 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 529 | - | |||||||||||||||||||||||||
| 530 | void QGL2PaintEngineEx::beginNativePainting() | - | ||||||||||||||||||||||||
| 531 | { | - | ||||||||||||||||||||||||
| 532 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 533 | ensureActive(); | - | ||||||||||||||||||||||||
| 534 | d->transferMode(BrushDrawingMode); | - | ||||||||||||||||||||||||
| 535 | - | |||||||||||||||||||||||||
| 536 | d->nativePaintingActive = true; | - | ||||||||||||||||||||||||
| 537 | - | |||||||||||||||||||||||||
| 538 | d->glUseProgram(0); | - | ||||||||||||||||||||||||
| 539 | - | |||||||||||||||||||||||||
| 540 | // Disable all the vertex attribute arrays: | - | ||||||||||||||||||||||||
| 541 | for (int i = 0; i < QT_GL_VERTEX_ARRAY_TRACKED_COUNT; ++i)
| 0 | ||||||||||||||||||||||||
| 542 | d->glDisableVertexAttribArray(i); never executed: d->glDisableVertexAttribArray(i); | 0 | ||||||||||||||||||||||||
| 543 | - | |||||||||||||||||||||||||
| 544 | #ifndef QT_OPENGL_ES_2 | - | ||||||||||||||||||||||||
| 545 | if (!d->ctx->contextHandle()->isOpenGLES()) {
| 0 | ||||||||||||||||||||||||
| 546 | const QGLContext *ctx = d->ctx; | - | ||||||||||||||||||||||||
| 547 | const QGLFormat &fmt = d->device->format(); | - | ||||||||||||||||||||||||
| 548 | if (fmt.majorVersion() < 3 || (fmt.majorVersion() == 3 && fmt.minorVersion() < 1)
| 0 | ||||||||||||||||||||||||
| 549 | || (fmt.majorVersion() == 3 && fmt.minorVersion() == 1 && ctx->contextHandle()->hasExtension(QByteArrayLiteral("GL_ARB_compatibility"))) never executed: return ba;
| 0 | ||||||||||||||||||||||||
| 550 | || fmt.profile() == QGLFormat::CompatibilityProfile)
| 0 | ||||||||||||||||||||||||
| 551 | { | - | ||||||||||||||||||||||||
| 552 | // be nice to people who mix OpenGL 1.x code with QPainter commands | - | ||||||||||||||||||||||||
| 553 | // by setting modelview and projection matrices to mirror the GL 1 | - | ||||||||||||||||||||||||
| 554 | // paint engine | - | ||||||||||||||||||||||||
| 555 | const QTransform& mtx = state()->matrix; | - | ||||||||||||||||||||||||
| 556 | - | |||||||||||||||||||||||||
| 557 | float mv_matrix[4][4] = | - | ||||||||||||||||||||||||
| 558 | { | - | ||||||||||||||||||||||||
| 559 | { float(mtx.m11()), float(mtx.m12()), 0, float(mtx.m13()) }, | - | ||||||||||||||||||||||||
| 560 | { float(mtx.m21()), float(mtx.m22()), 0, float(mtx.m23()) }, | - | ||||||||||||||||||||||||
| 561 | { 0, 0, 1, 0 }, | - | ||||||||||||||||||||||||
| 562 | { float(mtx.dx()), float(mtx.dy()), 0, float(mtx.m33()) } | - | ||||||||||||||||||||||||
| 563 | }; | - | ||||||||||||||||||||||||
| 564 | - | |||||||||||||||||||||||||
| 565 | const QSize sz = d->device->size(); | - | ||||||||||||||||||||||||
| 566 | - | |||||||||||||||||||||||||
| 567 | QOpenGLFunctions_1_1 *gl1funcs = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_1_1>(); | - | ||||||||||||||||||||||||
| 568 | gl1funcs->initializeOpenGLFunctions(); | - | ||||||||||||||||||||||||
| 569 | - | |||||||||||||||||||||||||
| 570 | gl1funcs->glMatrixMode(GL_PROJECTION); | - | ||||||||||||||||||||||||
| 571 | gl1funcs->glLoadIdentity(); | - | ||||||||||||||||||||||||
| 572 | gl1funcs->glOrtho(0, sz.width(), sz.height(), 0, -999999, 999999); | - | ||||||||||||||||||||||||
| 573 | - | |||||||||||||||||||||||||
| 574 | gl1funcs->glMatrixMode(GL_MODELVIEW); | - | ||||||||||||||||||||||||
| 575 | gl1funcs->glLoadMatrixf(&mv_matrix[0][0]); | - | ||||||||||||||||||||||||
| 576 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 577 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 578 | #endif | - | ||||||||||||||||||||||||
| 579 | - | |||||||||||||||||||||||||
| 580 | d->lastTextureUsed = GLuint(-1); | - | ||||||||||||||||||||||||
| 581 | d->dirtyStencilRegion = QRect(0, 0, d->width, d->height); | - | ||||||||||||||||||||||||
| 582 | d->resetGLState(); | - | ||||||||||||||||||||||||
| 583 | - | |||||||||||||||||||||||||
| 584 | d->shaderManager->setDirty(); | - | ||||||||||||||||||||||||
| 585 | - | |||||||||||||||||||||||||
| 586 | d->needsSync = true; | - | ||||||||||||||||||||||||
| 587 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 588 | - | |||||||||||||||||||||||||
| 589 | void QGL2PaintEngineExPrivate::resetGLState() | - | ||||||||||||||||||||||||
| 590 | { | - | ||||||||||||||||||||||||
| 591 | glDisable(GL_BLEND); | - | ||||||||||||||||||||||||
| 592 | glActiveTexture(GL_TEXTURE0); | - | ||||||||||||||||||||||||
| 593 | glDisable(GL_STENCIL_TEST); | - | ||||||||||||||||||||||||
| 594 | glDisable(GL_DEPTH_TEST); | - | ||||||||||||||||||||||||
| 595 | glDisable(GL_SCISSOR_TEST); | - | ||||||||||||||||||||||||
| 596 | glDepthMask(true); | - | ||||||||||||||||||||||||
| 597 | glDepthFunc(GL_LESS); | - | ||||||||||||||||||||||||
| 598 | glClearDepthf(1); | - | ||||||||||||||||||||||||
| 599 | glStencilMask(0xff); | - | ||||||||||||||||||||||||
| 600 | glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); | - | ||||||||||||||||||||||||
| 601 | glStencilFunc(GL_ALWAYS, 0, 0xff); | - | ||||||||||||||||||||||||
| 602 | ctx->d_func()->setVertexAttribArrayEnabled(QT_TEXTURE_COORDS_ATTR, false); | - | ||||||||||||||||||||||||
| 603 | ctx->d_func()->setVertexAttribArrayEnabled(QT_VERTEX_COORDS_ATTR, false); | - | ||||||||||||||||||||||||
| 604 | ctx->d_func()->setVertexAttribArrayEnabled(QT_OPACITY_ATTR, false); | - | ||||||||||||||||||||||||
| 605 | #ifndef QT_OPENGL_ES_2 | - | ||||||||||||||||||||||||
| 606 | if (!ctx->contextHandle()->isOpenGLES()) {
| 0-2 | ||||||||||||||||||||||||
| 607 | // gl_Color, corresponding to vertex attribute 3, may have been changed | - | ||||||||||||||||||||||||
| 608 | float color[] = { 1.0f, 1.0f, 1.0f, 1.0f }; | - | ||||||||||||||||||||||||
| 609 | glVertexAttrib4fv(3, color); | - | ||||||||||||||||||||||||
| 610 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 611 | #endif | - | ||||||||||||||||||||||||
| 612 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 613 | - | |||||||||||||||||||||||||
| 614 | bool QGL2PaintEngineExPrivate::resetOpenGLContextActiveEngine() | - | ||||||||||||||||||||||||
| 615 | { | - | ||||||||||||||||||||||||
| 616 | QOpenGLContext *guiGlContext = ctx->contextHandle(); | - | ||||||||||||||||||||||||
| 617 | QOpenGLContextPrivate *guiGlContextPrivate = | - | ||||||||||||||||||||||||
| 618 | guiGlContext ? QOpenGLContextPrivate::get(guiGlContext) : 0;
| 0-32 | ||||||||||||||||||||||||
| 619 | - | |||||||||||||||||||||||||
| 620 | if (guiGlContextPrivate && guiGlContextPrivate->active_engine) {
| 0-32 | ||||||||||||||||||||||||
| 621 | ctx->d_func()->refreshCurrentFbo(); | - | ||||||||||||||||||||||||
| 622 | guiGlContextPrivate->active_engine = 0; | - | ||||||||||||||||||||||||
| 623 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 624 | } | - | ||||||||||||||||||||||||
| 625 | - | |||||||||||||||||||||||||
| 626 | return false; executed 32 times by 1 test: return false;Executed by:
| 32 | ||||||||||||||||||||||||
| 627 | } | - | ||||||||||||||||||||||||
| 628 | - | |||||||||||||||||||||||||
| 629 | void QGL2PaintEngineEx::endNativePainting() | - | ||||||||||||||||||||||||
| 630 | { | - | ||||||||||||||||||||||||
| 631 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 632 | d->needsSync = true; | - | ||||||||||||||||||||||||
| 633 | d->nativePaintingActive = false; | - | ||||||||||||||||||||||||
| 634 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 635 | - | |||||||||||||||||||||||||
| 636 | void QGL2PaintEngineEx::invalidateState() | - | ||||||||||||||||||||||||
| 637 | { | - | ||||||||||||||||||||||||
| 638 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 639 | d->needsSync = true; | - | ||||||||||||||||||||||||
| 640 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 641 | - | |||||||||||||||||||||||||
| 642 | bool QGL2PaintEngineEx::isNativePaintingActive() const { | - | ||||||||||||||||||||||||
| 643 | Q_D(const QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 644 | return d->nativePaintingActive; never executed: return d->nativePaintingActive; | 0 | ||||||||||||||||||||||||
| 645 | } | - | ||||||||||||||||||||||||
| 646 | - | |||||||||||||||||||||||||
| 647 | bool QGL2PaintEngineEx::shouldDrawCachedGlyphs(QFontEngine *fontEngine, const QTransform &t) const | - | ||||||||||||||||||||||||
| 648 | { | - | ||||||||||||||||||||||||
| 649 | // The paint engine does not support projected cached glyph drawing | - | ||||||||||||||||||||||||
| 650 | if (t.type() == QTransform::TxProject)
| 0 | ||||||||||||||||||||||||
| 651 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 652 | - | |||||||||||||||||||||||||
| 653 | // The font engine might not support filling the glyph cache | - | ||||||||||||||||||||||||
| 654 | // with the given transform applied, in which case we need to | - | ||||||||||||||||||||||||
| 655 | // fall back to the QPainterPath code-path. | - | ||||||||||||||||||||||||
| 656 | if (!fontEngine->supportsTransformation(t)) {
| 0 | ||||||||||||||||||||||||
| 657 | // Except that drawing paths is slow, so for scales between | - | ||||||||||||||||||||||||
| 658 | // 0.5 and 2.0 we leave the glyph cache untransformed and deal | - | ||||||||||||||||||||||||
| 659 | // with the transform ourselves when painting, resulting in | - | ||||||||||||||||||||||||
| 660 | // drawing 1x cached glyphs with a smooth-scale. | - | ||||||||||||||||||||||||
| 661 | float det = t.determinant(); | - | ||||||||||||||||||||||||
| 662 | if (det >= 0.25f && det <= 4.f) {
| 0 | ||||||||||||||||||||||||
| 663 | // Assuming the baseclass still agrees | - | ||||||||||||||||||||||||
| 664 | return QPaintEngineEx::shouldDrawCachedGlyphs(fontEngine, t); never executed: return QPaintEngineEx::shouldDrawCachedGlyphs(fontEngine, t); | 0 | ||||||||||||||||||||||||
| 665 | } | - | ||||||||||||||||||||||||
| 666 | - | |||||||||||||||||||||||||
| 667 | return false; // Fall back to path-drawing never executed: return false; | 0 | ||||||||||||||||||||||||
| 668 | } | - | ||||||||||||||||||||||||
| 669 | - | |||||||||||||||||||||||||
| 670 | return QPaintEngineEx::shouldDrawCachedGlyphs(fontEngine, t); never executed: return QPaintEngineEx::shouldDrawCachedGlyphs(fontEngine, t); | 0 | ||||||||||||||||||||||||
| 671 | } | - | ||||||||||||||||||||||||
| 672 | - | |||||||||||||||||||||||||
| 673 | void QGL2PaintEngineExPrivate::transferMode(EngineMode newMode) | - | ||||||||||||||||||||||||
| 674 | { | - | ||||||||||||||||||||||||
| 675 | if (newMode == mode)
| 0-34 | ||||||||||||||||||||||||
| 676 | return; executed 34 times by 1 test: return;Executed by:
| 34 | ||||||||||||||||||||||||
| 677 | - | |||||||||||||||||||||||||
| 678 | if (mode == TextDrawingMode || mode == ImageDrawingMode || mode == ImageArrayDrawingMode) {
| 0 | ||||||||||||||||||||||||
| 679 | lastTextureUsed = GLuint(-1); | - | ||||||||||||||||||||||||
| 680 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 681 | - | |||||||||||||||||||||||||
| 682 | if (newMode == TextDrawingMode) {
| 0 | ||||||||||||||||||||||||
| 683 | shaderManager->setHasComplexGeometry(true); | - | ||||||||||||||||||||||||
| 684 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 685 | shaderManager->setHasComplexGeometry(false); | - | ||||||||||||||||||||||||
| 686 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 687 | - | |||||||||||||||||||||||||
| 688 | if (newMode == ImageDrawingMode) {
| 0 | ||||||||||||||||||||||||
| 689 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray); | - | ||||||||||||||||||||||||
| 690 | setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, staticTextureCoordinateArray); | - | ||||||||||||||||||||||||
| 691 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 692 | - | |||||||||||||||||||||||||
| 693 | if (newMode == ImageArrayDrawingMode) {
| 0 | ||||||||||||||||||||||||
| 694 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinateArray.data()); | - | ||||||||||||||||||||||||
| 695 | setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinateArray.data()); | - | ||||||||||||||||||||||||
| 696 | setVertexAttributePointer(QT_OPACITY_ATTR, (GLfloat*)opacityArray.data()); | - | ||||||||||||||||||||||||
| 697 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 698 | - | |||||||||||||||||||||||||
| 699 | // This needs to change when we implement high-quality anti-aliasing... | - | ||||||||||||||||||||||||
| 700 | if (newMode != TextDrawingMode)
| 0 | ||||||||||||||||||||||||
| 701 | shaderManager->setMaskType(QGLEngineShaderManager::NoMask); never executed: shaderManager->setMaskType(QGLEngineShaderManager::NoMask); | 0 | ||||||||||||||||||||||||
| 702 | - | |||||||||||||||||||||||||
| 703 | mode = newMode; | - | ||||||||||||||||||||||||
| 704 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 705 | - | |||||||||||||||||||||||||
| 706 | struct QGL2PEVectorPathCache | - | ||||||||||||||||||||||||
| 707 | { | - | ||||||||||||||||||||||||
| 708 | #ifdef QT_OPENGL_CACHE_AS_VBOS | - | ||||||||||||||||||||||||
| 709 | GLuint vbo; | - | ||||||||||||||||||||||||
| 710 | GLuint ibo; | - | ||||||||||||||||||||||||
| 711 | #else | - | ||||||||||||||||||||||||
| 712 | float *vertices; | - | ||||||||||||||||||||||||
| 713 | void *indices; | - | ||||||||||||||||||||||||
| 714 | #endif | - | ||||||||||||||||||||||||
| 715 | int vertexCount; | - | ||||||||||||||||||||||||
| 716 | int indexCount; | - | ||||||||||||||||||||||||
| 717 | GLenum primitiveType; | - | ||||||||||||||||||||||||
| 718 | qreal iscale; | - | ||||||||||||||||||||||||
| 719 | QVertexIndexVector::Type indexType; | - | ||||||||||||||||||||||||
| 720 | }; | - | ||||||||||||||||||||||||
| 721 | - | |||||||||||||||||||||||||
| 722 | void QGL2PaintEngineExPrivate::cleanupVectorPath(QPaintEngineEx *engine, void *data) | - | ||||||||||||||||||||||||
| 723 | { | - | ||||||||||||||||||||||||
| 724 | QGL2PEVectorPathCache *c = (QGL2PEVectorPathCache *) data; | - | ||||||||||||||||||||||||
| 725 | #ifdef QT_OPENGL_CACHE_AS_VBOS | - | ||||||||||||||||||||||||
| 726 | Q_ASSERT(engine->type() == QPaintEngine::OpenGL2); | - | ||||||||||||||||||||||||
| 727 | static_cast<QGL2PaintEngineEx *>(engine)->d_func()->unusedVBOSToClean << c->vbo; | - | ||||||||||||||||||||||||
| 728 | if (c->ibo) | - | ||||||||||||||||||||||||
| 729 | d->unusedIBOSToClean << c->ibo; | - | ||||||||||||||||||||||||
| 730 | #else | - | ||||||||||||||||||||||||
| 731 | Q_UNUSED(engine); | - | ||||||||||||||||||||||||
| 732 | free(c->vertices); | - | ||||||||||||||||||||||||
| 733 | free(c->indices); | - | ||||||||||||||||||||||||
| 734 | #endif | - | ||||||||||||||||||||||||
| 735 | delete c; | - | ||||||||||||||||||||||||
| 736 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 737 | - | |||||||||||||||||||||||||
| 738 | // Assumes everything is configured for the brush you want to use | - | ||||||||||||||||||||||||
| 739 | void QGL2PaintEngineExPrivate::fill(const QVectorPath& path) | - | ||||||||||||||||||||||||
| 740 | { | - | ||||||||||||||||||||||||
| 741 | transferMode(BrushDrawingMode); | - | ||||||||||||||||||||||||
| 742 | - | |||||||||||||||||||||||||
| 743 | if (snapToPixelGrid) {
| 0-28 | ||||||||||||||||||||||||
| 744 | snapToPixelGrid = false; | - | ||||||||||||||||||||||||
| 745 | matrixDirty = true; | - | ||||||||||||||||||||||||
| 746 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 747 | - | |||||||||||||||||||||||||
| 748 | // Might need to call updateMatrix to re-calculate inverseScale | - | ||||||||||||||||||||||||
| 749 | if (matrixDirty)
| 0-28 | ||||||||||||||||||||||||
| 750 | updateMatrix(); never executed: updateMatrix(); | 0 | ||||||||||||||||||||||||
| 751 | - | |||||||||||||||||||||||||
| 752 | const QPointF* const points = reinterpret_cast<const QPointF*>(path.points()); | - | ||||||||||||||||||||||||
| 753 | - | |||||||||||||||||||||||||
| 754 | // Check to see if there's any hints | - | ||||||||||||||||||||||||
| 755 | if (path.shape() == QVectorPath::RectangleHint) {
| 0-28 | ||||||||||||||||||||||||
| 756 | QGLRect rect(points[0].x(), points[0].y(), points[2].x(), points[2].y()); | - | ||||||||||||||||||||||||
| 757 | prepareForDraw(currentBrush.isOpaque()); | - | ||||||||||||||||||||||||
| 758 | composite(rect); | - | ||||||||||||||||||||||||
| 759 | } else if (path.isConvex()) { executed 28 times by 1 test: end of blockExecuted by:
| 0-28 | ||||||||||||||||||||||||
| 760 | - | |||||||||||||||||||||||||
| 761 | if (path.isCacheable()) {
| 0 | ||||||||||||||||||||||||
| 762 | QVectorPath::CacheEntry *data = path.lookupCacheData(q); | - | ||||||||||||||||||||||||
| 763 | QGL2PEVectorPathCache *cache; | - | ||||||||||||||||||||||||
| 764 | - | |||||||||||||||||||||||||
| 765 | bool updateCache = false; | - | ||||||||||||||||||||||||
| 766 | - | |||||||||||||||||||||||||
| 767 | if (data) {
| 0 | ||||||||||||||||||||||||
| 768 | cache = (QGL2PEVectorPathCache *) data->data; | - | ||||||||||||||||||||||||
| 769 | // Check if scale factor is exceeded for curved paths and generate curves if so... | - | ||||||||||||||||||||||||
| 770 | if (path.isCurved()) {
| 0 | ||||||||||||||||||||||||
| 771 | qreal scaleFactor = cache->iscale / inverseScale; | - | ||||||||||||||||||||||||
| 772 | if (scaleFactor < 0.5 || scaleFactor > 2.0) {
| 0 | ||||||||||||||||||||||||
| 773 | #ifdef QT_OPENGL_CACHE_AS_VBOS | - | ||||||||||||||||||||||||
| 774 | glDeleteBuffers(1, &cache->vbo); | - | ||||||||||||||||||||||||
| 775 | cache->vbo = 0; | - | ||||||||||||||||||||||||
| 776 | Q_ASSERT(cache->ibo == 0); | - | ||||||||||||||||||||||||
| 777 | #else | - | ||||||||||||||||||||||||
| 778 | free(cache->vertices); | - | ||||||||||||||||||||||||
| 779 | Q_ASSERT(cache->indices == 0); | - | ||||||||||||||||||||||||
| 780 | #endif | - | ||||||||||||||||||||||||
| 781 | updateCache = true; | - | ||||||||||||||||||||||||
| 782 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 783 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 784 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 785 | cache = new QGL2PEVectorPathCache; | - | ||||||||||||||||||||||||
| 786 | data = const_cast<QVectorPath &>(path).addCacheData(q, cache, cleanupVectorPath); | - | ||||||||||||||||||||||||
| 787 | updateCache = true; | - | ||||||||||||||||||||||||
| 788 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 789 | - | |||||||||||||||||||||||||
| 790 | // Flatten the path at the current scale factor and fill it into the cache struct. | - | ||||||||||||||||||||||||
| 791 | if (updateCache) {
| 0 | ||||||||||||||||||||||||
| 792 | vertexCoordinateArray.clear(); | - | ||||||||||||||||||||||||
| 793 | vertexCoordinateArray.addPath(path, inverseScale, false); | - | ||||||||||||||||||||||||
| 794 | int vertexCount = vertexCoordinateArray.vertexCount(); | - | ||||||||||||||||||||||||
| 795 | int floatSizeInBytes = vertexCount * 2 * sizeof(float); | - | ||||||||||||||||||||||||
| 796 | cache->vertexCount = vertexCount; | - | ||||||||||||||||||||||||
| 797 | cache->indexCount = 0; | - | ||||||||||||||||||||||||
| 798 | cache->primitiveType = GL_TRIANGLE_FAN; | - | ||||||||||||||||||||||||
| 799 | cache->iscale = inverseScale; | - | ||||||||||||||||||||||||
| 800 | #ifdef QT_OPENGL_CACHE_AS_VBOS | - | ||||||||||||||||||||||||
| 801 | glGenBuffers(1, &cache->vbo); | - | ||||||||||||||||||||||||
| 802 | glBindBuffer(GL_ARRAY_BUFFER, cache->vbo); | - | ||||||||||||||||||||||||
| 803 | glBufferData(GL_ARRAY_BUFFER, floatSizeInBytes, vertexCoordinateArray.data(), GL_STATIC_DRAW); | - | ||||||||||||||||||||||||
| 804 | cache->ibo = 0; | - | ||||||||||||||||||||||||
| 805 | #else | - | ||||||||||||||||||||||||
| 806 | cache->vertices = (float *) malloc(floatSizeInBytes); | - | ||||||||||||||||||||||||
| 807 | memcpy(cache->vertices, vertexCoordinateArray.data(), floatSizeInBytes); | - | ||||||||||||||||||||||||
| 808 | cache->indices = 0; | - | ||||||||||||||||||||||||
| 809 | #endif | - | ||||||||||||||||||||||||
| 810 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 811 | - | |||||||||||||||||||||||||
| 812 | prepareForDraw(currentBrush.isOpaque()); | - | ||||||||||||||||||||||||
| 813 | #ifdef QT_OPENGL_CACHE_AS_VBOS | - | ||||||||||||||||||||||||
| 814 | glBindBuffer(GL_ARRAY_BUFFER, cache->vbo); | - | ||||||||||||||||||||||||
| 815 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, 0); | - | ||||||||||||||||||||||||
| 816 | #else | - | ||||||||||||||||||||||||
| 817 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices); | - | ||||||||||||||||||||||||
| 818 | #endif | - | ||||||||||||||||||||||||
| 819 | glDrawArrays(cache->primitiveType, 0, cache->vertexCount); | - | ||||||||||||||||||||||||
| 820 | - | |||||||||||||||||||||||||
| 821 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 822 | // printf(" - Marking path as cachable...\n"); | - | ||||||||||||||||||||||||
| 823 | // Tag it for later so that if the same path is drawn twice, it is assumed to be static and thus cachable | - | ||||||||||||||||||||||||
| 824 | path.makeCacheable(); | - | ||||||||||||||||||||||||
| 825 | vertexCoordinateArray.clear(); | - | ||||||||||||||||||||||||
| 826 | vertexCoordinateArray.addPath(path, inverseScale, false); | - | ||||||||||||||||||||||||
| 827 | prepareForDraw(currentBrush.isOpaque()); | - | ||||||||||||||||||||||||
| 828 | drawVertexArrays(vertexCoordinateArray, GL_TRIANGLE_FAN); | - | ||||||||||||||||||||||||
| 829 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 830 | - | |||||||||||||||||||||||||
| 831 | } else { | - | ||||||||||||||||||||||||
| 832 | bool useCache = path.isCacheable(); | - | ||||||||||||||||||||||||
| 833 | if (useCache) {
| 0 | ||||||||||||||||||||||||
| 834 | QRectF bbox = path.controlPointRect(); | - | ||||||||||||||||||||||||
| 835 | // If the path doesn't fit within these limits, it is possible that the triangulation will fail. | - | ||||||||||||||||||||||||
| 836 | useCache &= (bbox.left() > -0x8000 * inverseScale)
| 0 | ||||||||||||||||||||||||
| 837 | && (bbox.right() < 0x8000 * inverseScale)
| 0 | ||||||||||||||||||||||||
| 838 | && (bbox.top() > -0x8000 * inverseScale)
| 0 | ||||||||||||||||||||||||
| 839 | && (bbox.bottom() < 0x8000 * inverseScale);
| 0 | ||||||||||||||||||||||||
| 840 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 841 | - | |||||||||||||||||||||||||
| 842 | if (useCache) {
| 0 | ||||||||||||||||||||||||
| 843 | QVectorPath::CacheEntry *data = path.lookupCacheData(q); | - | ||||||||||||||||||||||||
| 844 | QGL2PEVectorPathCache *cache; | - | ||||||||||||||||||||||||
| 845 | - | |||||||||||||||||||||||||
| 846 | bool updateCache = false; | - | ||||||||||||||||||||||||
| 847 | - | |||||||||||||||||||||||||
| 848 | if (data) {
| 0 | ||||||||||||||||||||||||
| 849 | cache = (QGL2PEVectorPathCache *) data->data; | - | ||||||||||||||||||||||||
| 850 | // Check if scale factor is exceeded for curved paths and generate curves if so... | - | ||||||||||||||||||||||||
| 851 | if (path.isCurved()) {
| 0 | ||||||||||||||||||||||||
| 852 | qreal scaleFactor = cache->iscale / inverseScale; | - | ||||||||||||||||||||||||
| 853 | if (scaleFactor < 0.5 || scaleFactor > 2.0) {
| 0 | ||||||||||||||||||||||||
| 854 | #ifdef QT_OPENGL_CACHE_AS_VBOS | - | ||||||||||||||||||||||||
| 855 | glDeleteBuffers(1, &cache->vbo); | - | ||||||||||||||||||||||||
| 856 | glDeleteBuffers(1, &cache->ibo); | - | ||||||||||||||||||||||||
| 857 | #else | - | ||||||||||||||||||||||||
| 858 | free(cache->vertices); | - | ||||||||||||||||||||||||
| 859 | free(cache->indices); | - | ||||||||||||||||||||||||
| 860 | #endif | - | ||||||||||||||||||||||||
| 861 | updateCache = true; | - | ||||||||||||||||||||||||
| 862 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 863 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 864 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 865 | cache = new QGL2PEVectorPathCache; | - | ||||||||||||||||||||||||
| 866 | data = const_cast<QVectorPath &>(path).addCacheData(q, cache, cleanupVectorPath); | - | ||||||||||||||||||||||||
| 867 | updateCache = true; | - | ||||||||||||||||||||||||
| 868 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 869 | - | |||||||||||||||||||||||||
| 870 | // Flatten the path at the current scale factor and fill it into the cache struct. | - | ||||||||||||||||||||||||
| 871 | if (updateCache) {
| 0 | ||||||||||||||||||||||||
| 872 | QTriangleSet polys = qTriangulate(path, QTransform().scale(1 / inverseScale, 1 / inverseScale)); | - | ||||||||||||||||||||||||
| 873 | cache->vertexCount = polys.vertices.size() / 2; | - | ||||||||||||||||||||||||
| 874 | cache->indexCount = polys.indices.size(); | - | ||||||||||||||||||||||||
| 875 | cache->primitiveType = GL_TRIANGLES; | - | ||||||||||||||||||||||||
| 876 | cache->iscale = inverseScale; | - | ||||||||||||||||||||||||
| 877 | cache->indexType = polys.indices.type(); | - | ||||||||||||||||||||||||
| 878 | #ifdef QT_OPENGL_CACHE_AS_VBOS | - | ||||||||||||||||||||||||
| 879 | glGenBuffers(1, &cache->vbo); | - | ||||||||||||||||||||||||
| 880 | glGenBuffers(1, &cache->ibo); | - | ||||||||||||||||||||||||
| 881 | glBindBuffer(GL_ARRAY_BUFFER, cache->vbo); | - | ||||||||||||||||||||||||
| 882 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cache->ibo); | - | ||||||||||||||||||||||||
| 883 | - | |||||||||||||||||||||||||
| 884 | if (polys.indices.type() == QVertexIndexVector::UnsignedInt) | - | ||||||||||||||||||||||||
| 885 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quint32) * polys.indices.size(), polys.indices.data(), GL_STATIC_DRAW); | - | ||||||||||||||||||||||||
| 886 | else | - | ||||||||||||||||||||||||
| 887 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(quint16) * polys.indices.size(), polys.indices.data(), GL_STATIC_DRAW); | - | ||||||||||||||||||||||||
| 888 | - | |||||||||||||||||||||||||
| 889 | QVarLengthArray<float> vertices(polys.vertices.size()); | - | ||||||||||||||||||||||||
| 890 | for (int i = 0; i < polys.vertices.size(); ++i) | - | ||||||||||||||||||||||||
| 891 | vertices[i] = float(inverseScale * polys.vertices.at(i)); | - | ||||||||||||||||||||||||
| 892 | glBufferData(GL_ARRAY_BUFFER, sizeof(float) * vertices.size(), vertices.data(), GL_STATIC_DRAW); | - | ||||||||||||||||||||||||
| 893 | #else | - | ||||||||||||||||||||||||
| 894 | cache->vertices = (float *) malloc(sizeof(float) * polys.vertices.size()); | - | ||||||||||||||||||||||||
| 895 | if (polys.indices.type() == QVertexIndexVector::UnsignedInt) {
| 0 | ||||||||||||||||||||||||
| 896 | cache->indices = (quint32 *) malloc(sizeof(quint32) * polys.indices.size()); | - | ||||||||||||||||||||||||
| 897 | memcpy(cache->indices, polys.indices.data(), sizeof(quint32) * polys.indices.size()); | - | ||||||||||||||||||||||||
| 898 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 899 | cache->indices = (quint16 *) malloc(sizeof(quint16) * polys.indices.size()); | - | ||||||||||||||||||||||||
| 900 | memcpy(cache->indices, polys.indices.data(), sizeof(quint16) * polys.indices.size()); | - | ||||||||||||||||||||||||
| 901 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 902 | for (int i = 0; i < polys.vertices.size(); ++i)
| 0 | ||||||||||||||||||||||||
| 903 | cache->vertices[i] = float(inverseScale * polys.vertices.at(i)); never executed: cache->vertices[i] = float(inverseScale * polys.vertices.at(i)); | 0 | ||||||||||||||||||||||||
| 904 | #endif | - | ||||||||||||||||||||||||
| 905 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 906 | - | |||||||||||||||||||||||||
| 907 | prepareForDraw(currentBrush.isOpaque()); | - | ||||||||||||||||||||||||
| 908 | #ifdef QT_OPENGL_CACHE_AS_VBOS | - | ||||||||||||||||||||||||
| 909 | glBindBuffer(GL_ARRAY_BUFFER, cache->vbo); | - | ||||||||||||||||||||||||
| 910 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, cache->ibo); | - | ||||||||||||||||||||||||
| 911 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, 0); | - | ||||||||||||||||||||||||
| 912 | if (cache->indexType == QVertexIndexVector::UnsignedInt) | - | ||||||||||||||||||||||||
| 913 | glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_INT, 0); | - | ||||||||||||||||||||||||
| 914 | else | - | ||||||||||||||||||||||||
| 915 | glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_SHORT, 0); | - | ||||||||||||||||||||||||
| 916 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | - | ||||||||||||||||||||||||
| 917 | glBindBuffer(GL_ARRAY_BUFFER, 0); | - | ||||||||||||||||||||||||
| 918 | #else | - | ||||||||||||||||||||||||
| 919 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, cache->vertices); | - | ||||||||||||||||||||||||
| 920 | if (cache->indexType == QVertexIndexVector::UnsignedInt)
| 0 | ||||||||||||||||||||||||
| 921 | glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_INT, (qint32 *)cache->indices); never executed: glDrawElements(cache->primitiveType, cache->indexCount, 0x1405, (qint32 *)cache->indices); | 0 | ||||||||||||||||||||||||
| 922 | else | - | ||||||||||||||||||||||||
| 923 | glDrawElements(cache->primitiveType, cache->indexCount, GL_UNSIGNED_SHORT, (qint16 *)cache->indices); never executed: glDrawElements(cache->primitiveType, cache->indexCount, 0x1403, (qint16 *)cache->indices); | 0 | ||||||||||||||||||||||||
| 924 | #endif | - | ||||||||||||||||||||||||
| 925 | - | |||||||||||||||||||||||||
| 926 | } else { | - | ||||||||||||||||||||||||
| 927 | // printf(" - Marking path as cachable...\n"); | - | ||||||||||||||||||||||||
| 928 | // Tag it for later so that if the same path is drawn twice, it is assumed to be static and thus cachable | - | ||||||||||||||||||||||||
| 929 | path.makeCacheable(); | - | ||||||||||||||||||||||||
| 930 | - | |||||||||||||||||||||||||
| 931 | if (!device->format().stencil()) {
| 0 | ||||||||||||||||||||||||
| 932 | // If there is no stencil buffer, triangulate the path instead. | - | ||||||||||||||||||||||||
| 933 | - | |||||||||||||||||||||||||
| 934 | QRectF bbox = path.controlPointRect(); | - | ||||||||||||||||||||||||
| 935 | // If the path doesn't fit within these limits, it is possible that the triangulation will fail. | - | ||||||||||||||||||||||||
| 936 | bool withinLimits = (bbox.left() > -0x8000 * inverseScale)
| 0 | ||||||||||||||||||||||||
| 937 | && (bbox.right() < 0x8000 * inverseScale)
| 0 | ||||||||||||||||||||||||
| 938 | && (bbox.top() > -0x8000 * inverseScale)
| 0 | ||||||||||||||||||||||||
| 939 | && (bbox.bottom() < 0x8000 * inverseScale);
| 0 | ||||||||||||||||||||||||
| 940 | if (withinLimits) {
| 0 | ||||||||||||||||||||||||
| 941 | QTriangleSet polys = qTriangulate(path, QTransform().scale(1 / inverseScale, 1 / inverseScale)); | - | ||||||||||||||||||||||||
| 942 | - | |||||||||||||||||||||||||
| 943 | QVarLengthArray<float> vertices(polys.vertices.size()); | - | ||||||||||||||||||||||||
| 944 | for (int i = 0; i < polys.vertices.size(); ++i)
| 0 | ||||||||||||||||||||||||
| 945 | vertices[i] = float(inverseScale * polys.vertices.at(i)); never executed: vertices[i] = float(inverseScale * polys.vertices.at(i)); | 0 | ||||||||||||||||||||||||
| 946 | - | |||||||||||||||||||||||||
| 947 | prepareForDraw(currentBrush.isOpaque()); | - | ||||||||||||||||||||||||
| 948 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, vertices.constData()); | - | ||||||||||||||||||||||||
| 949 | if (polys.indices.type() == QVertexIndexVector::UnsignedInt)
| 0 | ||||||||||||||||||||||||
| 950 | glDrawElements(GL_TRIANGLES, polys.indices.size(), GL_UNSIGNED_INT, polys.indices.data()); never executed: glDrawElements(0x0004, polys.indices.size(), 0x1405, polys.indices.data()); | 0 | ||||||||||||||||||||||||
| 951 | else | - | ||||||||||||||||||||||||
| 952 | glDrawElements(GL_TRIANGLES, polys.indices.size(), GL_UNSIGNED_SHORT, polys.indices.data()); never executed: glDrawElements(0x0004, polys.indices.size(), 0x1403, polys.indices.data()); | 0 | ||||||||||||||||||||||||
| 953 | } else { | - | ||||||||||||||||||||||||
| 954 | // We can't handle big, concave painter paths with OpenGL without stencil buffer. | - | ||||||||||||||||||||||||
| 955 | qWarning("Painter path exceeds +/-32767 pixels."); | - | ||||||||||||||||||||||||
| 956 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 957 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 958 | } | - | ||||||||||||||||||||||||
| 959 | - | |||||||||||||||||||||||||
| 960 | // The path is too complicated & needs the stencil technique | - | ||||||||||||||||||||||||
| 961 | vertexCoordinateArray.clear(); | - | ||||||||||||||||||||||||
| 962 | vertexCoordinateArray.addPath(path, inverseScale, false); | - | ||||||||||||||||||||||||
| 963 | - | |||||||||||||||||||||||||
| 964 | fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill()); | - | ||||||||||||||||||||||||
| 965 | - | |||||||||||||||||||||||||
| 966 | glStencilMask(0xff); | - | ||||||||||||||||||||||||
| 967 | glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE); | - | ||||||||||||||||||||||||
| 968 | - | |||||||||||||||||||||||||
| 969 | if (q->state()->clipTestEnabled) {
| 0 | ||||||||||||||||||||||||
| 970 | // Pass when high bit is set, replace stencil value with current clip | - | ||||||||||||||||||||||||
| 971 | glStencilFunc(GL_NOTEQUAL, q->state()->currentClip, GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 972 | } else if (path.hasWindingFill()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 973 | // Pass when any bit is set, replace stencil value with 0 | - | ||||||||||||||||||||||||
| 974 | glStencilFunc(GL_NOTEQUAL, 0, 0xff); | - | ||||||||||||||||||||||||
| 975 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 976 | // Pass when high bit is set, replace stencil value with 0 | - | ||||||||||||||||||||||||
| 977 | glStencilFunc(GL_NOTEQUAL, 0, GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 978 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 979 | prepareForDraw(currentBrush.isOpaque()); | - | ||||||||||||||||||||||||
| 980 | - | |||||||||||||||||||||||||
| 981 | // Stencil the brush onto the dest buffer | - | ||||||||||||||||||||||||
| 982 | composite(vertexCoordinateArray.boundingRect()); | - | ||||||||||||||||||||||||
| 983 | glStencilMask(0); | - | ||||||||||||||||||||||||
| 984 | updateClipScissorTest(); | - | ||||||||||||||||||||||||
| 985 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 986 | } | - | ||||||||||||||||||||||||
| 987 | } | - | ||||||||||||||||||||||||
| 988 | - | |||||||||||||||||||||||||
| 989 | - | |||||||||||||||||||||||||
| 990 | void QGL2PaintEngineExPrivate::fillStencilWithVertexArray(const float *data, | - | ||||||||||||||||||||||||
| 991 | int count, | - | ||||||||||||||||||||||||
| 992 | int *stops, | - | ||||||||||||||||||||||||
| 993 | int stopCount, | - | ||||||||||||||||||||||||
| 994 | const QGLRect &bounds, | - | ||||||||||||||||||||||||
| 995 | StencilFillMode mode) | - | ||||||||||||||||||||||||
| 996 | { | - | ||||||||||||||||||||||||
| 997 | Q_ASSERT(count || stops); | - | ||||||||||||||||||||||||
| 998 | - | |||||||||||||||||||||||||
| 999 | // qDebug("QGL2PaintEngineExPrivate::fillStencilWithVertexArray()"); | - | ||||||||||||||||||||||||
| 1000 | glStencilMask(0xff); // Enable stencil writes | - | ||||||||||||||||||||||||
| 1001 | - | |||||||||||||||||||||||||
| 1002 | if (dirtyStencilRegion.intersects(currentScissorBounds)) {
| 0-2 | ||||||||||||||||||||||||
| 1003 | QVector<QRect> clearRegion = dirtyStencilRegion.intersected(currentScissorBounds).rects(); | - | ||||||||||||||||||||||||
| 1004 | glClearStencil(0); // Clear to zero | - | ||||||||||||||||||||||||
| 1005 | for (int i = 0; i < clearRegion.size(); ++i) {
| 0 | ||||||||||||||||||||||||
| 1006 | #ifndef QT_GL_NO_SCISSOR_TEST | - | ||||||||||||||||||||||||
| 1007 | setScissor(clearRegion.at(i)); | - | ||||||||||||||||||||||||
| 1008 | #endif | - | ||||||||||||||||||||||||
| 1009 | glClear(GL_STENCIL_BUFFER_BIT); | - | ||||||||||||||||||||||||
| 1010 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1011 | - | |||||||||||||||||||||||||
| 1012 | dirtyStencilRegion -= currentScissorBounds; | - | ||||||||||||||||||||||||
| 1013 | - | |||||||||||||||||||||||||
| 1014 | #ifndef QT_GL_NO_SCISSOR_TEST | - | ||||||||||||||||||||||||
| 1015 | updateClipScissorTest(); | - | ||||||||||||||||||||||||
| 1016 | #endif | - | ||||||||||||||||||||||||
| 1017 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1018 | - | |||||||||||||||||||||||||
| 1019 | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // Disable color writes | - | ||||||||||||||||||||||||
| 1020 | useSimpleShader(); | - | ||||||||||||||||||||||||
| 1021 | glEnable(GL_STENCIL_TEST); // For some reason, this has to happen _after_ the simple shader is use()'d | - | ||||||||||||||||||||||||
| 1022 | - | |||||||||||||||||||||||||
| 1023 | if (mode == WindingFillMode) {
| 0-2 | ||||||||||||||||||||||||
| 1024 | Q_ASSERT(stops && !count); | - | ||||||||||||||||||||||||
| 1025 | if (q->state()->clipTestEnabled) {
| 0 | ||||||||||||||||||||||||
| 1026 | // Flatten clip values higher than current clip, and set high bit to match current clip | - | ||||||||||||||||||||||||
| 1027 | glStencilFunc(GL_LEQUAL, GL_STENCIL_HIGH_BIT | q->state()->currentClip, ~GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 1028 | glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE); | - | ||||||||||||||||||||||||
| 1029 | composite(bounds); | - | ||||||||||||||||||||||||
| 1030 | - | |||||||||||||||||||||||||
| 1031 | glStencilFunc(GL_EQUAL, GL_STENCIL_HIGH_BIT, GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 1032 | } else if (!stencilClean) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1033 | // Clear stencil buffer within bounding rect | - | ||||||||||||||||||||||||
| 1034 | glStencilFunc(GL_ALWAYS, 0, 0xff); | - | ||||||||||||||||||||||||
| 1035 | glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); | - | ||||||||||||||||||||||||
| 1036 | composite(bounds); | - | ||||||||||||||||||||||||
| 1037 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1038 | - | |||||||||||||||||||||||||
| 1039 | // Inc. for front-facing triangle | - | ||||||||||||||||||||||||
| 1040 | glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_INCR_WRAP, GL_INCR_WRAP); | - | ||||||||||||||||||||||||
| 1041 | // Dec. for back-facing "holes" | - | ||||||||||||||||||||||||
| 1042 | glStencilOpSeparate(GL_BACK, GL_KEEP, GL_DECR_WRAP, GL_DECR_WRAP); | - | ||||||||||||||||||||||||
| 1043 | glStencilMask(~GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 1044 | drawVertexArrays(data, stops, stopCount, GL_TRIANGLE_FAN); | - | ||||||||||||||||||||||||
| 1045 | - | |||||||||||||||||||||||||
| 1046 | if (q->state()->clipTestEnabled) {
| 0 | ||||||||||||||||||||||||
| 1047 | // Clear high bit of stencil outside of path | - | ||||||||||||||||||||||||
| 1048 | glStencilFunc(GL_EQUAL, q->state()->currentClip, ~GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 1049 | glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE); | - | ||||||||||||||||||||||||
| 1050 | glStencilMask(GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 1051 | composite(bounds); | - | ||||||||||||||||||||||||
| 1052 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1053 | } else if (mode == OddEvenFillMode) { never executed: end of block
| 0-2 | ||||||||||||||||||||||||
| 1054 | glStencilMask(GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 1055 | glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT); // Simply invert the stencil bit | - | ||||||||||||||||||||||||
| 1056 | drawVertexArrays(data, stops, stopCount, GL_TRIANGLE_FAN); | - | ||||||||||||||||||||||||
| 1057 | - | |||||||||||||||||||||||||
| 1058 | } else { // TriStripStrokeFillMode executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 1059 | Q_ASSERT(count && !stops); // tristrips generated directly, so no vertexArray or stops | - | ||||||||||||||||||||||||
| 1060 | glStencilMask(GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 1061 | #if 0 | - | ||||||||||||||||||||||||
| 1062 | glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT); // Simply invert the stencil bit | - | ||||||||||||||||||||||||
| 1063 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, data); | - | ||||||||||||||||||||||||
| 1064 | glDrawArrays(GL_TRIANGLE_STRIP, 0, count); | - | ||||||||||||||||||||||||
| 1065 | #else | - | ||||||||||||||||||||||||
| 1066 | - | |||||||||||||||||||||||||
| 1067 | glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); | - | ||||||||||||||||||||||||
| 1068 | if (q->state()->clipTestEnabled) {
| 0 | ||||||||||||||||||||||||
| 1069 | glStencilFunc(GL_LEQUAL, q->state()->currentClip | GL_STENCIL_HIGH_BIT, | - | ||||||||||||||||||||||||
| 1070 | ~GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 1071 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1072 | glStencilFunc(GL_ALWAYS, GL_STENCIL_HIGH_BIT, 0xff); | - | ||||||||||||||||||||||||
| 1073 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1074 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, data); | - | ||||||||||||||||||||||||
| 1075 | glDrawArrays(GL_TRIANGLE_STRIP, 0, count); | - | ||||||||||||||||||||||||
| 1076 | #endif | - | ||||||||||||||||||||||||
| 1077 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1078 | - | |||||||||||||||||||||||||
| 1079 | // Enable color writes & disable stencil writes | - | ||||||||||||||||||||||||
| 1080 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | - | ||||||||||||||||||||||||
| 1081 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 1082 | - | |||||||||||||||||||||||||
| 1083 | /* | - | ||||||||||||||||||||||||
| 1084 | If the maximum value in the stencil buffer is GL_STENCIL_HIGH_BIT - 1, | - | ||||||||||||||||||||||||
| 1085 | restore the stencil buffer to a pristine state. The current clip region | - | ||||||||||||||||||||||||
| 1086 | is set to 1, and the rest to 0. | - | ||||||||||||||||||||||||
| 1087 | */ | - | ||||||||||||||||||||||||
| 1088 | void QGL2PaintEngineExPrivate::resetClipIfNeeded() | - | ||||||||||||||||||||||||
| 1089 | { | - | ||||||||||||||||||||||||
| 1090 | if (maxClip != (GL_STENCIL_HIGH_BIT - 1))
| 0 | ||||||||||||||||||||||||
| 1091 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1092 | - | |||||||||||||||||||||||||
| 1093 | Q_Q(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1094 | - | |||||||||||||||||||||||||
| 1095 | useSimpleShader(); | - | ||||||||||||||||||||||||
| 1096 | glEnable(GL_STENCIL_TEST); | - | ||||||||||||||||||||||||
| 1097 | glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); | - | ||||||||||||||||||||||||
| 1098 | - | |||||||||||||||||||||||||
| 1099 | QRectF bounds = q->state()->matrix.inverted().mapRect(QRectF(0, 0, width, height)); | - | ||||||||||||||||||||||||
| 1100 | QGLRect rect(bounds.left(), bounds.top(), bounds.right(), bounds.bottom()); | - | ||||||||||||||||||||||||
| 1101 | - | |||||||||||||||||||||||||
| 1102 | // Set high bit on clip region | - | ||||||||||||||||||||||||
| 1103 | glStencilFunc(GL_LEQUAL, q->state()->currentClip, 0xff); | - | ||||||||||||||||||||||||
| 1104 | glStencilOp(GL_KEEP, GL_INVERT, GL_INVERT); | - | ||||||||||||||||||||||||
| 1105 | glStencilMask(GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 1106 | composite(rect); | - | ||||||||||||||||||||||||
| 1107 | - | |||||||||||||||||||||||||
| 1108 | // Reset clipping to 1 and everything else to zero | - | ||||||||||||||||||||||||
| 1109 | glStencilFunc(GL_NOTEQUAL, 0x01, GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 1110 | glStencilOp(GL_ZERO, GL_REPLACE, GL_REPLACE); | - | ||||||||||||||||||||||||
| 1111 | glStencilMask(0xff); | - | ||||||||||||||||||||||||
| 1112 | composite(rect); | - | ||||||||||||||||||||||||
| 1113 | - | |||||||||||||||||||||||||
| 1114 | q->state()->currentClip = 1; | - | ||||||||||||||||||||||||
| 1115 | q->state()->canRestoreClip = false; | - | ||||||||||||||||||||||||
| 1116 | - | |||||||||||||||||||||||||
| 1117 | maxClip = 1; | - | ||||||||||||||||||||||||
| 1118 | - | |||||||||||||||||||||||||
| 1119 | glStencilMask(0x0); | - | ||||||||||||||||||||||||
| 1120 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); | - | ||||||||||||||||||||||||
| 1121 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1122 | - | |||||||||||||||||||||||||
| 1123 | bool QGL2PaintEngineExPrivate::prepareForCachedGlyphDraw(const QFontEngineGlyphCache &cache) | - | ||||||||||||||||||||||||
| 1124 | { | - | ||||||||||||||||||||||||
| 1125 | Q_Q(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1126 | - | |||||||||||||||||||||||||
| 1127 | Q_ASSERT(cache.transform().type() <= QTransform::TxScale); | - | ||||||||||||||||||||||||
| 1128 | - | |||||||||||||||||||||||||
| 1129 | QTransform &transform = q->state()->matrix; | - | ||||||||||||||||||||||||
| 1130 | transform.scale(1.0 / cache.transform().m11(), 1.0 / cache.transform().m22()); | - | ||||||||||||||||||||||||
| 1131 | bool ret = prepareForDraw(false); | - | ||||||||||||||||||||||||
| 1132 | transform.scale(cache.transform().m11(), cache.transform().m22()); | - | ||||||||||||||||||||||||
| 1133 | - | |||||||||||||||||||||||||
| 1134 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
| 1135 | } | - | ||||||||||||||||||||||||
| 1136 | - | |||||||||||||||||||||||||
| 1137 | bool QGL2PaintEngineExPrivate::prepareForDraw(bool srcPixelsAreOpaque) | - | ||||||||||||||||||||||||
| 1138 | { | - | ||||||||||||||||||||||||
| 1139 | if (brushTextureDirty && mode != ImageDrawingMode && mode != ImageArrayDrawingMode)
| 0-26 | ||||||||||||||||||||||||
| 1140 | updateBrushTexture(); executed 2 times by 1 test: updateBrushTexture();Executed by:
| 2 | ||||||||||||||||||||||||
| 1141 | - | |||||||||||||||||||||||||
| 1142 | if (compositionModeDirty)
| 2-26 | ||||||||||||||||||||||||
| 1143 | updateCompositionMode(); executed 2 times by 1 test: updateCompositionMode();Executed by:
| 2 | ||||||||||||||||||||||||
| 1144 | - | |||||||||||||||||||||||||
| 1145 | if (matrixDirty)
| 0-28 | ||||||||||||||||||||||||
| 1146 | updateMatrix(); never executed: updateMatrix(); | 0 | ||||||||||||||||||||||||
| 1147 | - | |||||||||||||||||||||||||
| 1148 | const bool stateHasOpacity = q->state()->opacity < 0.99f; | - | ||||||||||||||||||||||||
| 1149 | if (q->state()->composition_mode == QPainter::CompositionMode_Source
| 0-28 | ||||||||||||||||||||||||
| 1150 | || (q->state()->composition_mode == QPainter::CompositionMode_SourceOver
| 0-28 | ||||||||||||||||||||||||
| 1151 | && srcPixelsAreOpaque && !stateHasOpacity))
| 0-28 | ||||||||||||||||||||||||
| 1152 | { | - | ||||||||||||||||||||||||
| 1153 | glDisable(GL_BLEND); | - | ||||||||||||||||||||||||
| 1154 | } else { executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||||||||
| 1155 | glEnable(GL_BLEND); | - | ||||||||||||||||||||||||
| 1156 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1157 | - | |||||||||||||||||||||||||
| 1158 | QGLEngineShaderManager::OpacityMode opacityMode; | - | ||||||||||||||||||||||||
| 1159 | if (mode == ImageArrayDrawingMode) {
| 0-28 | ||||||||||||||||||||||||
| 1160 | opacityMode = QGLEngineShaderManager::AttributeOpacity; | - | ||||||||||||||||||||||||
| 1161 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1162 | opacityMode = stateHasOpacity ? QGLEngineShaderManager::UniformOpacity
| 0-28 | ||||||||||||||||||||||||
| 1163 | : QGLEngineShaderManager::NoOpacity; | - | ||||||||||||||||||||||||
| 1164 | if (stateHasOpacity && (mode != ImageDrawingMode)) {
| 0-28 | ||||||||||||||||||||||||
| 1165 | // Using a brush | - | ||||||||||||||||||||||||
| 1166 | bool brushIsPattern = (currentBrush.style() >= Qt::Dense1Pattern) &&
| 0 | ||||||||||||||||||||||||
| 1167 | (currentBrush.style() <= Qt::DiagCrossPattern);
| 0 | ||||||||||||||||||||||||
| 1168 | - | |||||||||||||||||||||||||
| 1169 | if ((currentBrush.style() == Qt::SolidPattern) || brushIsPattern)
| 0 | ||||||||||||||||||||||||
| 1170 | opacityMode = QGLEngineShaderManager::NoOpacity; // Global opacity handled by srcPixel shader never executed: opacityMode = QGLEngineShaderManager::NoOpacity; | 0 | ||||||||||||||||||||||||
| 1171 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1172 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||||||||
| 1173 | shaderManager->setOpacityMode(opacityMode); | - | ||||||||||||||||||||||||
| 1174 | - | |||||||||||||||||||||||||
| 1175 | bool changed = shaderManager->useCorrectShaderProg(); | - | ||||||||||||||||||||||||
| 1176 | // If the shader program needs changing, we change it and mark all uniforms as dirty | - | ||||||||||||||||||||||||
| 1177 | if (changed) {
| 2-26 | ||||||||||||||||||||||||
| 1178 | // The shader program has changed so mark all uniforms as dirty: | - | ||||||||||||||||||||||||
| 1179 | brushUniformsDirty = true; | - | ||||||||||||||||||||||||
| 1180 | opacityUniformDirty = true; | - | ||||||||||||||||||||||||
| 1181 | matrixUniformDirty = true; | - | ||||||||||||||||||||||||
| 1182 | translateZUniformDirty = true; | - | ||||||||||||||||||||||||
| 1183 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 1184 | - | |||||||||||||||||||||||||
| 1185 | if (brushUniformsDirty && mode != ImageDrawingMode && mode != ImageArrayDrawingMode)
| 0-26 | ||||||||||||||||||||||||
| 1186 | updateBrushUniforms(); executed 2 times by 1 test: updateBrushUniforms();Executed by:
| 2 | ||||||||||||||||||||||||
| 1187 | - | |||||||||||||||||||||||||
| 1188 | if (opacityMode == QGLEngineShaderManager::UniformOpacity && opacityUniformDirty) {
| 0-28 | ||||||||||||||||||||||||
| 1189 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::GlobalOpacity), (GLfloat)q->state()->opacity); | - | ||||||||||||||||||||||||
| 1190 | opacityUniformDirty = false; | - | ||||||||||||||||||||||||
| 1191 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1192 | - | |||||||||||||||||||||||||
| 1193 | if (matrixUniformDirty && shaderManager->hasComplexGeometry()) {
| 0-28 | ||||||||||||||||||||||||
| 1194 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::Matrix), | - | ||||||||||||||||||||||||
| 1195 | pmvMatrix); | - | ||||||||||||||||||||||||
| 1196 | matrixUniformDirty = false; | - | ||||||||||||||||||||||||
| 1197 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1198 | - | |||||||||||||||||||||||||
| 1199 | if (translateZUniformDirty && shaderManager->hasComplexGeometry()) {
| 0-28 | ||||||||||||||||||||||||
| 1200 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::TranslateZ), | - | ||||||||||||||||||||||||
| 1201 | translateZ); | - | ||||||||||||||||||||||||
| 1202 | translateZUniformDirty = false; | - | ||||||||||||||||||||||||
| 1203 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1204 | - | |||||||||||||||||||||||||
| 1205 | return changed; executed 28 times by 1 test: return changed;Executed by:
| 28 | ||||||||||||||||||||||||
| 1206 | } | - | ||||||||||||||||||||||||
| 1207 | - | |||||||||||||||||||||||||
| 1208 | void QGL2PaintEngineExPrivate::composite(const QGLRect& boundingRect) | - | ||||||||||||||||||||||||
| 1209 | { | - | ||||||||||||||||||||||||
| 1210 | setCoords(staticVertexCoordinateArray, boundingRect); | - | ||||||||||||||||||||||||
| 1211 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, staticVertexCoordinateArray); | - | ||||||||||||||||||||||||
| 1212 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | - | ||||||||||||||||||||||||
| 1213 | } executed 30 times by 1 test: end of blockExecuted by:
| 30 | ||||||||||||||||||||||||
| 1214 | - | |||||||||||||||||||||||||
| 1215 | // Draws the vertex array as a set of <vertexArrayStops.size()> triangle fans. | - | ||||||||||||||||||||||||
| 1216 | void QGL2PaintEngineExPrivate::drawVertexArrays(const float *data, int *stops, int stopCount, | - | ||||||||||||||||||||||||
| 1217 | GLenum primitive) | - | ||||||||||||||||||||||||
| 1218 | { | - | ||||||||||||||||||||||||
| 1219 | // Now setup the pointer to the vertex array: | - | ||||||||||||||||||||||||
| 1220 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, data); | - | ||||||||||||||||||||||||
| 1221 | - | |||||||||||||||||||||||||
| 1222 | int previousStop = 0; | - | ||||||||||||||||||||||||
| 1223 | for (int i=0; i<stopCount; ++i) {
| 2-28 | ||||||||||||||||||||||||
| 1224 | int stop = stops[i]; | - | ||||||||||||||||||||||||
| 1225 | /* | - | ||||||||||||||||||||||||
| 1226 | qDebug("Drawing triangle fan for vertecies %d -> %d:", previousStop, stop-1); | - | ||||||||||||||||||||||||
| 1227 | for (int i=previousStop; i<stop; ++i) | - | ||||||||||||||||||||||||
| 1228 | qDebug(" %02d: [%.2f, %.2f]", i, vertexArray.data()[i].x, vertexArray.data()[i].y); | - | ||||||||||||||||||||||||
| 1229 | */ | - | ||||||||||||||||||||||||
| 1230 | glDrawArrays(primitive, previousStop, stop - previousStop); | - | ||||||||||||||||||||||||
| 1231 | previousStop = stop; | - | ||||||||||||||||||||||||
| 1232 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||||||||
| 1233 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 1234 | - | |||||||||||||||||||||||||
| 1235 | /////////////////////////////////// Public Methods ////////////////////////////////////////// | - | ||||||||||||||||||||||||
| 1236 | - | |||||||||||||||||||||||||
| 1237 | QGL2PaintEngineEx::QGL2PaintEngineEx() | - | ||||||||||||||||||||||||
| 1238 | : QPaintEngineEx(*(new QGL2PaintEngineExPrivate(this))) | - | ||||||||||||||||||||||||
| 1239 | { | - | ||||||||||||||||||||||||
| 1240 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||
| 1241 | - | |||||||||||||||||||||||||
| 1242 | QGL2PaintEngineEx::~QGL2PaintEngineEx() | - | ||||||||||||||||||||||||
| 1243 | { | - | ||||||||||||||||||||||||
| 1244 | } | - | ||||||||||||||||||||||||
| 1245 | - | |||||||||||||||||||||||||
| 1246 | void QGL2PaintEngineEx::fill(const QVectorPath &path, const QBrush &brush) | - | ||||||||||||||||||||||||
| 1247 | { | - | ||||||||||||||||||||||||
| 1248 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1249 | - | |||||||||||||||||||||||||
| 1250 | if (qbrush_style(brush) == Qt::NoBrush)
| 0-28 | ||||||||||||||||||||||||
| 1251 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1252 | ensureActive(); | - | ||||||||||||||||||||||||
| 1253 | d->setBrush(brush); | - | ||||||||||||||||||||||||
| 1254 | d->fill(path); | - | ||||||||||||||||||||||||
| 1255 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||||||||
| 1256 | - | |||||||||||||||||||||||||
| 1257 | Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp | - | ||||||||||||||||||||||||
| 1258 | - | |||||||||||||||||||||||||
| 1259 | - | |||||||||||||||||||||||||
| 1260 | void QGL2PaintEngineEx::stroke(const QVectorPath &path, const QPen &pen) | - | ||||||||||||||||||||||||
| 1261 | { | - | ||||||||||||||||||||||||
| 1262 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1263 | - | |||||||||||||||||||||||||
| 1264 | const QBrush &penBrush = qpen_brush(pen); | - | ||||||||||||||||||||||||
| 1265 | if (qpen_style(pen) == Qt::NoPen || qbrush_style(penBrush) == Qt::NoBrush)
| 0 | ||||||||||||||||||||||||
| 1266 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1267 | - | |||||||||||||||||||||||||
| 1268 | QGL2PaintEngineState *s = state(); | - | ||||||||||||||||||||||||
| 1269 | if (qt_pen_is_cosmetic(pen, s->renderHints) && !qt_scaleForTransform(s->transform(), 0)) {
| 0 | ||||||||||||||||||||||||
| 1270 | // QTriangulatingStroker class is not meant to support cosmetically sheared strokes. | - | ||||||||||||||||||||||||
| 1271 | QPaintEngineEx::stroke(path, pen); | - | ||||||||||||||||||||||||
| 1272 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1273 | } | - | ||||||||||||||||||||||||
| 1274 | - | |||||||||||||||||||||||||
| 1275 | ensureActive(); | - | ||||||||||||||||||||||||
| 1276 | d->setBrush(penBrush); | - | ||||||||||||||||||||||||
| 1277 | d->stroke(path, pen); | - | ||||||||||||||||||||||||
| 1278 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1279 | - | |||||||||||||||||||||||||
| 1280 | void QGL2PaintEngineExPrivate::stroke(const QVectorPath &path, const QPen &pen) | - | ||||||||||||||||||||||||
| 1281 | { | - | ||||||||||||||||||||||||
| 1282 | const QGL2PaintEngineState *s = q->state(); | - | ||||||||||||||||||||||||
| 1283 | if (snapToPixelGrid) {
| 0 | ||||||||||||||||||||||||
| 1284 | snapToPixelGrid = false; | - | ||||||||||||||||||||||||
| 1285 | matrixDirty = true; | - | ||||||||||||||||||||||||
| 1286 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1287 | - | |||||||||||||||||||||||||
| 1288 | const Qt::PenStyle penStyle = qpen_style(pen); | - | ||||||||||||||||||||||||
| 1289 | const QBrush &penBrush = qpen_brush(pen); | - | ||||||||||||||||||||||||
| 1290 | const bool opaque = penBrush.isOpaque() && s->opacity > 0.99;
| 0 | ||||||||||||||||||||||||
| 1291 | - | |||||||||||||||||||||||||
| 1292 | transferMode(BrushDrawingMode); | - | ||||||||||||||||||||||||
| 1293 | - | |||||||||||||||||||||||||
| 1294 | // updateMatrix() is responsible for setting the inverse scale on | - | ||||||||||||||||||||||||
| 1295 | // the strokers, so we need to call it here and not wait for | - | ||||||||||||||||||||||||
| 1296 | // prepareForDraw() down below. | - | ||||||||||||||||||||||||
| 1297 | updateMatrix(); | - | ||||||||||||||||||||||||
| 1298 | - | |||||||||||||||||||||||||
| 1299 | QRectF clip = q->state()->matrix.inverted().mapRect(q->state()->clipEnabled | - | ||||||||||||||||||||||||
| 1300 | ? q->state()->rectangleClip | - | ||||||||||||||||||||||||
| 1301 | : QRectF(0, 0, width, height)); | - | ||||||||||||||||||||||||
| 1302 | - | |||||||||||||||||||||||||
| 1303 | if (penStyle == Qt::SolidLine) {
| 0 | ||||||||||||||||||||||||
| 1304 | stroker.process(path, pen, clip, s->renderHints); | - | ||||||||||||||||||||||||
| 1305 | - | |||||||||||||||||||||||||
| 1306 | } else { // Some sort of dash never executed: end of block | 0 | ||||||||||||||||||||||||
| 1307 | dasher.process(path, pen, clip, s->renderHints); | - | ||||||||||||||||||||||||
| 1308 | - | |||||||||||||||||||||||||
| 1309 | QVectorPath dashStroke(dasher.points(), | - | ||||||||||||||||||||||||
| 1310 | dasher.elementCount(), | - | ||||||||||||||||||||||||
| 1311 | dasher.elementTypes()); | - | ||||||||||||||||||||||||
| 1312 | stroker.process(dashStroke, pen, clip, s->renderHints); | - | ||||||||||||||||||||||||
| 1313 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1314 | - | |||||||||||||||||||||||||
| 1315 | if (!stroker.vertexCount())
| 0 | ||||||||||||||||||||||||
| 1316 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1317 | - | |||||||||||||||||||||||||
| 1318 | if (opaque) {
| 0 | ||||||||||||||||||||||||
| 1319 | prepareForDraw(opaque); | - | ||||||||||||||||||||||||
| 1320 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, stroker.vertices()); | - | ||||||||||||||||||||||||
| 1321 | glDrawArrays(GL_TRIANGLE_STRIP, 0, stroker.vertexCount() / 2); | - | ||||||||||||||||||||||||
| 1322 | - | |||||||||||||||||||||||||
| 1323 | // QBrush b(Qt::green); | - | ||||||||||||||||||||||||
| 1324 | // d->setBrush(&b); | - | ||||||||||||||||||||||||
| 1325 | // d->prepareForDraw(true); | - | ||||||||||||||||||||||||
| 1326 | // glDrawArrays(GL_LINE_STRIP, 0, d->stroker.vertexCount() / 2); | - | ||||||||||||||||||||||||
| 1327 | - | |||||||||||||||||||||||||
| 1328 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1329 | qreal width = qpen_widthf(pen) / 2; | - | ||||||||||||||||||||||||
| 1330 | if (width == 0)
| 0 | ||||||||||||||||||||||||
| 1331 | width = 0.5; never executed: width = 0.5; | 0 | ||||||||||||||||||||||||
| 1332 | qreal extra = pen.joinStyle() == Qt::MiterJoin
| 0 | ||||||||||||||||||||||||
| 1333 | ? qMax(pen.miterLimit() * width, width) | - | ||||||||||||||||||||||||
| 1334 | : width; | - | ||||||||||||||||||||||||
| 1335 | - | |||||||||||||||||||||||||
| 1336 | if (qt_pen_is_cosmetic(pen, s->renderHints))
| 0 | ||||||||||||||||||||||||
| 1337 | extra = extra * inverseScale; never executed: extra = extra * inverseScale; | 0 | ||||||||||||||||||||||||
| 1338 | - | |||||||||||||||||||||||||
| 1339 | QRectF bounds = path.controlPointRect().adjusted(-extra, -extra, extra, extra); | - | ||||||||||||||||||||||||
| 1340 | - | |||||||||||||||||||||||||
| 1341 | fillStencilWithVertexArray(stroker.vertices(), stroker.vertexCount() / 2, | - | ||||||||||||||||||||||||
| 1342 | 0, 0, bounds, QGL2PaintEngineExPrivate::TriStripStrokeFillMode); | - | ||||||||||||||||||||||||
| 1343 | - | |||||||||||||||||||||||||
| 1344 | glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE); | - | ||||||||||||||||||||||||
| 1345 | - | |||||||||||||||||||||||||
| 1346 | // Pass when any bit is set, replace stencil value with 0 | - | ||||||||||||||||||||||||
| 1347 | glStencilFunc(GL_NOTEQUAL, 0, GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 1348 | prepareForDraw(false); | - | ||||||||||||||||||||||||
| 1349 | - | |||||||||||||||||||||||||
| 1350 | // Stencil the brush onto the dest buffer | - | ||||||||||||||||||||||||
| 1351 | composite(bounds); | - | ||||||||||||||||||||||||
| 1352 | - | |||||||||||||||||||||||||
| 1353 | glStencilMask(0); | - | ||||||||||||||||||||||||
| 1354 | - | |||||||||||||||||||||||||
| 1355 | updateClipScissorTest(); | - | ||||||||||||||||||||||||
| 1356 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1357 | } | - | ||||||||||||||||||||||||
| 1358 | - | |||||||||||||||||||||||||
| 1359 | void QGL2PaintEngineEx::penChanged() { } | - | ||||||||||||||||||||||||
| 1360 | void QGL2PaintEngineEx::brushChanged() { } | - | ||||||||||||||||||||||||
| 1361 | void QGL2PaintEngineEx::brushOriginChanged() { } | - | ||||||||||||||||||||||||
| 1362 | - | |||||||||||||||||||||||||
| 1363 | void QGL2PaintEngineEx::opacityChanged() | - | ||||||||||||||||||||||||
| 1364 | { | - | ||||||||||||||||||||||||
| 1365 | // qDebug("QGL2PaintEngineEx::opacityChanged()"); | - | ||||||||||||||||||||||||
| 1366 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1367 | state()->opacityChanged = true; | - | ||||||||||||||||||||||||
| 1368 | - | |||||||||||||||||||||||||
| 1369 | Q_ASSERT(d->shaderManager); | - | ||||||||||||||||||||||||
| 1370 | d->brushUniformsDirty = true; | - | ||||||||||||||||||||||||
| 1371 | d->opacityUniformDirty = true; | - | ||||||||||||||||||||||||
| 1372 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1373 | - | |||||||||||||||||||||||||
| 1374 | void QGL2PaintEngineEx::compositionModeChanged() | - | ||||||||||||||||||||||||
| 1375 | { | - | ||||||||||||||||||||||||
| 1376 | // qDebug("QGL2PaintEngineEx::compositionModeChanged()"); | - | ||||||||||||||||||||||||
| 1377 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1378 | state()->compositionModeChanged = true; | - | ||||||||||||||||||||||||
| 1379 | d->compositionModeDirty = true; | - | ||||||||||||||||||||||||
| 1380 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1381 | - | |||||||||||||||||||||||||
| 1382 | void QGL2PaintEngineEx::renderHintsChanged() | - | ||||||||||||||||||||||||
| 1383 | { | - | ||||||||||||||||||||||||
| 1384 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1385 | state()->renderHintsChanged = true; | - | ||||||||||||||||||||||||
| 1386 | - | |||||||||||||||||||||||||
| 1387 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||||||||
| 1388 | if (!d->ctx->contextHandle()->isOpenGLES()) {
| 0-2 | ||||||||||||||||||||||||
| 1389 | if ((state()->renderHints & QPainter::Antialiasing) | - | ||||||||||||||||||||||||
| 1390 | || (state()->renderHints & QPainter::HighQualityAntialiasing)) | - | ||||||||||||||||||||||||
| 1391 | d->glEnable(GL_MULTISAMPLE); never executed: d->glEnable(0x809D); | 0 | ||||||||||||||||||||||||
| 1392 | else | - | ||||||||||||||||||||||||
| 1393 | d->glDisable(GL_MULTISAMPLE); executed 2 times by 1 test: d->glDisable(0x809D);Executed by:
| 2 | ||||||||||||||||||||||||
| 1394 | } | - | ||||||||||||||||||||||||
| 1395 | #endif | - | ||||||||||||||||||||||||
| 1396 | - | |||||||||||||||||||||||||
| 1397 | d->lastTextureUsed = GLuint(-1); | - | ||||||||||||||||||||||||
| 1398 | d->brushTextureDirty = true; | - | ||||||||||||||||||||||||
| 1399 | // qDebug("QGL2PaintEngineEx::renderHintsChanged() not implemented!"); | - | ||||||||||||||||||||||||
| 1400 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 1401 | - | |||||||||||||||||||||||||
| 1402 | void QGL2PaintEngineEx::transformChanged() | - | ||||||||||||||||||||||||
| 1403 | { | - | ||||||||||||||||||||||||
| 1404 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1405 | d->matrixDirty = true; | - | ||||||||||||||||||||||||
| 1406 | state()->matrixChanged = true; | - | ||||||||||||||||||||||||
| 1407 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1408 | - | |||||||||||||||||||||||||
| 1409 | - | |||||||||||||||||||||||||
| 1410 | static const QRectF scaleRect(const QRectF &r, qreal sx, qreal sy) | - | ||||||||||||||||||||||||
| 1411 | { | - | ||||||||||||||||||||||||
| 1412 | 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 | ||||||||||||||||||||||||
| 1413 | } | - | ||||||||||||||||||||||||
| 1414 | - | |||||||||||||||||||||||||
| 1415 | void QGL2PaintEngineEx::drawPixmap(const QRectF& dest, const QPixmap & pixmap, const QRectF & src) | - | ||||||||||||||||||||||||
| 1416 | { | - | ||||||||||||||||||||||||
| 1417 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1418 | QGLContext *ctx = d->ctx; | - | ||||||||||||||||||||||||
| 1419 | - | |||||||||||||||||||||||||
| 1420 | int max_texture_size = ctx->d_func()->maxTextureSize(); | - | ||||||||||||||||||||||||
| 1421 | if (pixmap.width() > max_texture_size || pixmap.height() > max_texture_size) {
| 0 | ||||||||||||||||||||||||
| 1422 | QPixmap scaled = pixmap.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio); | - | ||||||||||||||||||||||||
| 1423 | - | |||||||||||||||||||||||||
| 1424 | const qreal sx = scaled.width() / qreal(pixmap.width()); | - | ||||||||||||||||||||||||
| 1425 | const qreal sy = scaled.height() / qreal(pixmap.height()); | - | ||||||||||||||||||||||||
| 1426 | - | |||||||||||||||||||||||||
| 1427 | drawPixmap(dest, scaled, scaleRect(src, sx, sy)); | - | ||||||||||||||||||||||||
| 1428 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1429 | } | - | ||||||||||||||||||||||||
| 1430 | - | |||||||||||||||||||||||||
| 1431 | ensureActive(); | - | ||||||||||||||||||||||||
| 1432 | d->transferMode(ImageDrawingMode); | - | ||||||||||||||||||||||||
| 1433 | - | |||||||||||||||||||||||||
| 1434 | QGLContext::BindOptions bindOptions = QGLContext::InternalBindOption|QGLContext::CanFlipNativePixmapBindOption; | - | ||||||||||||||||||||||||
| 1435 | #ifdef QGL_USE_TEXTURE_POOL | - | ||||||||||||||||||||||||
| 1436 | bindOptions |= QGLContext::TemporarilyCachedBindOption; | - | ||||||||||||||||||||||||
| 1437 | #endif | - | ||||||||||||||||||||||||
| 1438 | - | |||||||||||||||||||||||||
| 1439 | d->glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); | - | ||||||||||||||||||||||||
| 1440 | QGLTexture *texture = | - | ||||||||||||||||||||||||
| 1441 | ctx->d_func()->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, bindOptions); | - | ||||||||||||||||||||||||
| 1442 | - | |||||||||||||||||||||||||
| 1443 | GLfloat top = texture->options & QGLContext::InvertedYBindOption ? (pixmap.height() - src.top()) : src.top();
| 0 | ||||||||||||||||||||||||
| 1444 | GLfloat bottom = texture->options & QGLContext::InvertedYBindOption ? (pixmap.height() - src.bottom()) : src.bottom();
| 0 | ||||||||||||||||||||||||
| 1445 | QGLRect srcRect(src.left(), top, src.right(), bottom); | - | ||||||||||||||||||||||||
| 1446 | - | |||||||||||||||||||||||||
| 1447 | bool isBitmap = pixmap.isQBitmap(); | - | ||||||||||||||||||||||||
| 1448 | bool isOpaque = !isBitmap && !pixmap.hasAlpha();
| 0 | ||||||||||||||||||||||||
| 1449 | - | |||||||||||||||||||||||||
| 1450 | d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, | - | ||||||||||||||||||||||||
| 1451 | state()->renderHints & QPainter::SmoothPixmapTransform, texture->id); | - | ||||||||||||||||||||||||
| 1452 | d->drawTexture(dest, srcRect, pixmap.size(), isOpaque, isBitmap); | - | ||||||||||||||||||||||||
| 1453 | - | |||||||||||||||||||||||||
| 1454 | if (texture->options&QGLContext::TemporarilyCachedBindOption) {
| 0 | ||||||||||||||||||||||||
| 1455 | // pixmap was temporarily cached as a QImage texture by pooling system | - | ||||||||||||||||||||||||
| 1456 | // and should be destroyed immediately | - | ||||||||||||||||||||||||
| 1457 | QGLTextureCache::instance()->remove(ctx, texture->id); | - | ||||||||||||||||||||||||
| 1458 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1459 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1460 | - | |||||||||||||||||||||||||
| 1461 | void QGL2PaintEngineEx::drawImage(const QRectF& dest, const QImage& image, const QRectF& src, | - | ||||||||||||||||||||||||
| 1462 | Qt::ImageConversionFlags) | - | ||||||||||||||||||||||||
| 1463 | { | - | ||||||||||||||||||||||||
| 1464 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1465 | QGLContext *ctx = d->ctx; | - | ||||||||||||||||||||||||
| 1466 | - | |||||||||||||||||||||||||
| 1467 | int max_texture_size = ctx->d_func()->maxTextureSize(); | - | ||||||||||||||||||||||||
| 1468 | if (image.width() > max_texture_size || image.height() > max_texture_size) {
| 0 | ||||||||||||||||||||||||
| 1469 | QImage scaled = image.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio); | - | ||||||||||||||||||||||||
| 1470 | - | |||||||||||||||||||||||||
| 1471 | const qreal sx = scaled.width() / qreal(image.width()); | - | ||||||||||||||||||||||||
| 1472 | const qreal sy = scaled.height() / qreal(image.height()); | - | ||||||||||||||||||||||||
| 1473 | - | |||||||||||||||||||||||||
| 1474 | drawImage(dest, scaled, scaleRect(src, sx, sy)); | - | ||||||||||||||||||||||||
| 1475 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1476 | } | - | ||||||||||||||||||||||||
| 1477 | - | |||||||||||||||||||||||||
| 1478 | ensureActive(); | - | ||||||||||||||||||||||||
| 1479 | d->transferMode(ImageDrawingMode); | - | ||||||||||||||||||||||||
| 1480 | - | |||||||||||||||||||||||||
| 1481 | d->glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); | - | ||||||||||||||||||||||||
| 1482 | - | |||||||||||||||||||||||||
| 1483 | QGLContext::BindOptions bindOptions = QGLContext::InternalBindOption; | - | ||||||||||||||||||||||||
| 1484 | #ifdef QGL_USE_TEXTURE_POOL | - | ||||||||||||||||||||||||
| 1485 | bindOptions |= QGLContext::TemporarilyCachedBindOption; | - | ||||||||||||||||||||||||
| 1486 | #endif | - | ||||||||||||||||||||||||
| 1487 | - | |||||||||||||||||||||||||
| 1488 | QGLTexture *texture = ctx->d_func()->bindTexture(image, GL_TEXTURE_2D, GL_RGBA, bindOptions); | - | ||||||||||||||||||||||||
| 1489 | GLuint id = texture->id; | - | ||||||||||||||||||||||||
| 1490 | - | |||||||||||||||||||||||||
| 1491 | d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, | - | ||||||||||||||||||||||||
| 1492 | state()->renderHints & QPainter::SmoothPixmapTransform, id); | - | ||||||||||||||||||||||||
| 1493 | d->drawTexture(dest, src, image.size(), !image.hasAlphaChannel()); | - | ||||||||||||||||||||||||
| 1494 | - | |||||||||||||||||||||||||
| 1495 | if (texture->options&QGLContext::TemporarilyCachedBindOption) {
| 0 | ||||||||||||||||||||||||
| 1496 | // image was temporarily cached by texture pooling system | - | ||||||||||||||||||||||||
| 1497 | // and should be destroyed immediately | - | ||||||||||||||||||||||||
| 1498 | QGLTextureCache::instance()->remove(ctx, texture->id); | - | ||||||||||||||||||||||||
| 1499 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1500 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1501 | - | |||||||||||||||||||||||||
| 1502 | void QGL2PaintEngineEx::drawStaticTextItem(QStaticTextItem *textItem) | - | ||||||||||||||||||||||||
| 1503 | { | - | ||||||||||||||||||||||||
| 1504 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1505 | - | |||||||||||||||||||||||||
| 1506 | ensureActive(); | - | ||||||||||||||||||||||||
| 1507 | - | |||||||||||||||||||||||||
| 1508 | QPainterState *s = state(); | - | ||||||||||||||||||||||||
| 1509 | - | |||||||||||||||||||||||||
| 1510 | // don't try to cache huge fonts or vastly transformed fonts | - | ||||||||||||||||||||||||
| 1511 | QFontEngine *fontEngine = textItem->fontEngine(); | - | ||||||||||||||||||||||||
| 1512 | if (shouldDrawCachedGlyphs(fontEngine, s->matrix)) {
| 0 | ||||||||||||||||||||||||
| 1513 | - | |||||||||||||||||||||||||
| 1514 | QFontEngine::GlyphFormat glyphFormat = fontEngine->glyphFormat != QFontEngine::Format_None
| 0 | ||||||||||||||||||||||||
| 1515 | ? fontEngine->glyphFormat : d->glyphCacheFormat; | - | ||||||||||||||||||||||||
| 1516 | - | |||||||||||||||||||||||||
| 1517 | if (glyphFormat == QFontEngine::Format_A32) {
| 0 | ||||||||||||||||||||||||
| 1518 | if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()
| 0 | ||||||||||||||||||||||||
| 1519 | || d->device->alphaRequested() || s->matrix.type() > QTransform::TxTranslate
| 0 | ||||||||||||||||||||||||
| 1520 | || (s->composition_mode != QPainter::CompositionMode_Source
| 0 | ||||||||||||||||||||||||
| 1521 | && s->composition_mode != QPainter::CompositionMode_SourceOver))
| 0 | ||||||||||||||||||||||||
| 1522 | { | - | ||||||||||||||||||||||||
| 1523 | glyphFormat = QFontEngine::Format_A8; | - | ||||||||||||||||||||||||
| 1524 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1525 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1526 | - | |||||||||||||||||||||||||
| 1527 | d->drawCachedGlyphs(glyphFormat, textItem); | - | ||||||||||||||||||||||||
| 1528 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1529 | QPaintEngineEx::drawStaticTextItem(textItem); | - | ||||||||||||||||||||||||
| 1530 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1531 | } | - | ||||||||||||||||||||||||
| 1532 | - | |||||||||||||||||||||||||
| 1533 | bool QGL2PaintEngineEx::drawTexture(const QRectF &dest, GLuint textureId, const QSize &size, const QRectF &src) | - | ||||||||||||||||||||||||
| 1534 | { | - | ||||||||||||||||||||||||
| 1535 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1536 | if (!d->shaderManager)
| 0 | ||||||||||||||||||||||||
| 1537 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1538 | - | |||||||||||||||||||||||||
| 1539 | ensureActive(); | - | ||||||||||||||||||||||||
| 1540 | d->transferMode(ImageDrawingMode); | - | ||||||||||||||||||||||||
| 1541 | - | |||||||||||||||||||||||||
| 1542 | d->glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); | - | ||||||||||||||||||||||||
| 1543 | d->glBindTexture(GL_TEXTURE_2D, textureId); | - | ||||||||||||||||||||||||
| 1544 | - | |||||||||||||||||||||||||
| 1545 | QGLRect srcRect(src.left(), src.bottom(), src.right(), src.top()); | - | ||||||||||||||||||||||||
| 1546 | - | |||||||||||||||||||||||||
| 1547 | d->updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, | - | ||||||||||||||||||||||||
| 1548 | state()->renderHints & QPainter::SmoothPixmapTransform, textureId); | - | ||||||||||||||||||||||||
| 1549 | d->drawTexture(dest, srcRect, size, false); | - | ||||||||||||||||||||||||
| 1550 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
| 1551 | } | - | ||||||||||||||||||||||||
| 1552 | - | |||||||||||||||||||||||||
| 1553 | void QGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &textItem) | - | ||||||||||||||||||||||||
| 1554 | { | - | ||||||||||||||||||||||||
| 1555 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1556 | - | |||||||||||||||||||||||||
| 1557 | ensureActive(); | - | ||||||||||||||||||||||||
| 1558 | QGL2PaintEngineState *s = state(); | - | ||||||||||||||||||||||||
| 1559 | - | |||||||||||||||||||||||||
| 1560 | const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem); | - | ||||||||||||||||||||||||
| 1561 | - | |||||||||||||||||||||||||
| 1562 | QTransform::TransformationType txtype = s->matrix.type(); | - | ||||||||||||||||||||||||
| 1563 | - | |||||||||||||||||||||||||
| 1564 | QFontEngine::GlyphFormat glyphFormat = ti.fontEngine->glyphFormat != QFontEngine::Format_None
| 0 | ||||||||||||||||||||||||
| 1565 | ? ti.fontEngine->glyphFormat : d->glyphCacheFormat; | - | ||||||||||||||||||||||||
| 1566 | - | |||||||||||||||||||||||||
| 1567 | if (glyphFormat == QFontEngine::Format_A32) {
| 0 | ||||||||||||||||||||||||
| 1568 | if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()
| 0 | ||||||||||||||||||||||||
| 1569 | || d->device->alphaRequested() || txtype > QTransform::TxTranslate
| 0 | ||||||||||||||||||||||||
| 1570 | || (state()->composition_mode != QPainter::CompositionMode_Source
| 0 | ||||||||||||||||||||||||
| 1571 | && state()->composition_mode != QPainter::CompositionMode_SourceOver))
| 0 | ||||||||||||||||||||||||
| 1572 | { | - | ||||||||||||||||||||||||
| 1573 | glyphFormat = QFontEngine::Format_A8; | - | ||||||||||||||||||||||||
| 1574 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1575 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1576 | - | |||||||||||||||||||||||||
| 1577 | if (shouldDrawCachedGlyphs(ti.fontEngine, s->matrix)) {
| 0 | ||||||||||||||||||||||||
| 1578 | QVarLengthArray<QFixedPoint> positions; | - | ||||||||||||||||||||||||
| 1579 | QVarLengthArray<glyph_t> glyphs; | - | ||||||||||||||||||||||||
| 1580 | QTransform matrix = QTransform::fromTranslate(p.x(), p.y()); | - | ||||||||||||||||||||||||
| 1581 | ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); | - | ||||||||||||||||||||||||
| 1582 | - | |||||||||||||||||||||||||
| 1583 | { | - | ||||||||||||||||||||||||
| 1584 | QStaticTextItem staticTextItem; | - | ||||||||||||||||||||||||
| 1585 | staticTextItem.setFontEngine(ti.fontEngine); | - | ||||||||||||||||||||||||
| 1586 | staticTextItem.glyphs = glyphs.data(); | - | ||||||||||||||||||||||||
| 1587 | staticTextItem.numGlyphs = glyphs.size(); | - | ||||||||||||||||||||||||
| 1588 | staticTextItem.glyphPositions = positions.data(); | - | ||||||||||||||||||||||||
| 1589 | - | |||||||||||||||||||||||||
| 1590 | d->drawCachedGlyphs(glyphFormat, &staticTextItem); | - | ||||||||||||||||||||||||
| 1591 | } | - | ||||||||||||||||||||||||
| 1592 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1593 | } | - | ||||||||||||||||||||||||
| 1594 | - | |||||||||||||||||||||||||
| 1595 | QPaintEngineEx::drawTextItem(p, ti); | - | ||||||||||||||||||||||||
| 1596 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1597 | - | |||||||||||||||||||||||||
| 1598 | namespace { | - | ||||||||||||||||||||||||
| 1599 | - | |||||||||||||||||||||||||
| 1600 | class QOpenGLStaticTextUserData: public QStaticTextUserData | - | ||||||||||||||||||||||||
| 1601 | { | - | ||||||||||||||||||||||||
| 1602 | public: | - | ||||||||||||||||||||||||
| 1603 | QOpenGLStaticTextUserData() | - | ||||||||||||||||||||||||
| 1604 | : QStaticTextUserData(OpenGLUserData), cacheSize(0, 0), cacheSerialNumber(0) | - | ||||||||||||||||||||||||
| 1605 | { | - | ||||||||||||||||||||||||
| 1606 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1607 | - | |||||||||||||||||||||||||
| 1608 | ~QOpenGLStaticTextUserData() | - | ||||||||||||||||||||||||
| 1609 | { | - | ||||||||||||||||||||||||
| 1610 | } | - | ||||||||||||||||||||||||
| 1611 | - | |||||||||||||||||||||||||
| 1612 | QSize cacheSize; | - | ||||||||||||||||||||||||
| 1613 | QGL2PEXVertexArray vertexCoordinateArray; | - | ||||||||||||||||||||||||
| 1614 | QGL2PEXVertexArray textureCoordinateArray; | - | ||||||||||||||||||||||||
| 1615 | QFontEngine::GlyphFormat glyphFormat; | - | ||||||||||||||||||||||||
| 1616 | int cacheSerialNumber; | - | ||||||||||||||||||||||||
| 1617 | }; | - | ||||||||||||||||||||||||
| 1618 | - | |||||||||||||||||||||||||
| 1619 | } | - | ||||||||||||||||||||||||
| 1620 | - | |||||||||||||||||||||||||
| 1621 | - | |||||||||||||||||||||||||
| 1622 | // #define QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO | - | ||||||||||||||||||||||||
| 1623 | - | |||||||||||||||||||||||||
| 1624 | void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngine::GlyphFormat glyphFormat, | - | ||||||||||||||||||||||||
| 1625 | QStaticTextItem *staticTextItem) | - | ||||||||||||||||||||||||
| 1626 | { | - | ||||||||||||||||||||||||
| 1627 | Q_Q(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1628 | - | |||||||||||||||||||||||||
| 1629 | QGL2PaintEngineState *s = q->state(); | - | ||||||||||||||||||||||||
| 1630 | - | |||||||||||||||||||||||||
| 1631 | void *cacheKey = const_cast<QGLContext *>(QGLContextPrivate::contextGroup(ctx)->context()); | - | ||||||||||||||||||||||||
| 1632 | bool recreateVertexArrays = false; | - | ||||||||||||||||||||||||
| 1633 | - | |||||||||||||||||||||||||
| 1634 | QTransform glyphCacheTransform; | - | ||||||||||||||||||||||||
| 1635 | QFontEngine *fe = staticTextItem->fontEngine(); | - | ||||||||||||||||||||||||
| 1636 | if (fe->supportsTransformation(s->matrix)) {
| 0 | ||||||||||||||||||||||||
| 1637 | // The font-engine supports rendering glyphs with the current transform, so we | - | ||||||||||||||||||||||||
| 1638 | // build a glyph-cache with the scale pre-applied, so that the cache contains | - | ||||||||||||||||||||||||
| 1639 | // glyphs with the appropriate resolution in the case of retina displays. | - | ||||||||||||||||||||||||
| 1640 | glyphCacheTransform = s->matrix.type() < QTransform::TxRotate ?
| 0 | ||||||||||||||||||||||||
| 1641 | QTransform::fromScale(qAbs(s->matrix.m11()), qAbs(s->matrix.m22())) : | - | ||||||||||||||||||||||||
| 1642 | QTransform::fromScale( | - | ||||||||||||||||||||||||
| 1643 | QVector2D(s->matrix.m11(), s->matrix.m12()).length(), | - | ||||||||||||||||||||||||
| 1644 | QVector2D(s->matrix.m21(), s->matrix.m22()).length()); | - | ||||||||||||||||||||||||
| 1645 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1646 | - | |||||||||||||||||||||||||
| 1647 | QGLTextureGlyphCache *cache = | - | ||||||||||||||||||||||||
| 1648 | (QGLTextureGlyphCache *) fe->glyphCache(cacheKey, glyphFormat, glyphCacheTransform); | - | ||||||||||||||||||||||||
| 1649 | if (!cache || cache->glyphFormat() != glyphFormat || cache->contextGroup() == 0) {
| 0 | ||||||||||||||||||||||||
| 1650 | cache = new QGLTextureGlyphCache(glyphFormat, glyphCacheTransform); | - | ||||||||||||||||||||||||
| 1651 | fe->setGlyphCache(cacheKey, cache); | - | ||||||||||||||||||||||||
| 1652 | recreateVertexArrays = true; | - | ||||||||||||||||||||||||
| 1653 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1654 | - | |||||||||||||||||||||||||
| 1655 | if (staticTextItem->userDataNeedsUpdate) {
| 0 | ||||||||||||||||||||||||
| 1656 | recreateVertexArrays = true; | - | ||||||||||||||||||||||||
| 1657 | } else if (staticTextItem->userData() == 0) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1658 | recreateVertexArrays = true; | - | ||||||||||||||||||||||||
| 1659 | } else if (staticTextItem->userData()->type != QStaticTextUserData::OpenGLUserData) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1660 | recreateVertexArrays = true; | - | ||||||||||||||||||||||||
| 1661 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1662 | QOpenGLStaticTextUserData *userData = static_cast<QOpenGLStaticTextUserData *>(staticTextItem->userData()); | - | ||||||||||||||||||||||||
| 1663 | if (userData->glyphFormat != glyphFormat) {
| 0 | ||||||||||||||||||||||||
| 1664 | recreateVertexArrays = true; | - | ||||||||||||||||||||||||
| 1665 | } else if (userData->cacheSerialNumber != cache->serialNumber()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
| 1666 | recreateVertexArrays = true; | - | ||||||||||||||||||||||||
| 1667 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1668 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1669 | - | |||||||||||||||||||||||||
| 1670 | // We only need to update the cache with new glyphs if we are actually going to recreate the vertex arrays. | - | ||||||||||||||||||||||||
| 1671 | // If the cache size has changed, we do need to regenerate the vertices, but we don't need to repopulate the | - | ||||||||||||||||||||||||
| 1672 | // cache so this text is performed before we test if the cache size has changed. | - | ||||||||||||||||||||||||
| 1673 | if (recreateVertexArrays) {
| 0 | ||||||||||||||||||||||||
| 1674 | cache->setPaintEnginePrivate(this); | - | ||||||||||||||||||||||||
| 1675 | if (!cache->populate(fe, staticTextItem->numGlyphs,
| 0 | ||||||||||||||||||||||||
| 1676 | staticTextItem->glyphs, staticTextItem->glyphPositions)) {
| 0 | ||||||||||||||||||||||||
| 1677 | // No space for glyphs in cache. We need to reset it and try again. | - | ||||||||||||||||||||||||
| 1678 | cache->clear(); | - | ||||||||||||||||||||||||
| 1679 | cache->populate(fe, staticTextItem->numGlyphs, | - | ||||||||||||||||||||||||
| 1680 | staticTextItem->glyphs, staticTextItem->glyphPositions); | - | ||||||||||||||||||||||||
| 1681 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1682 | cache->fillInPendingGlyphs(); | - | ||||||||||||||||||||||||
| 1683 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1684 | - | |||||||||||||||||||||||||
| 1685 | if (cache->width() == 0 || cache->height() == 0)
| 0 | ||||||||||||||||||||||||
| 1686 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1687 | - | |||||||||||||||||||||||||
| 1688 | transferMode(TextDrawingMode); | - | ||||||||||||||||||||||||
| 1689 | - | |||||||||||||||||||||||||
| 1690 | int margin = fe->glyphMargin(glyphFormat); | - | ||||||||||||||||||||||||
| 1691 | - | |||||||||||||||||||||||||
| 1692 | GLfloat dx = 1.0 / cache->width(); | - | ||||||||||||||||||||||||
| 1693 | GLfloat dy = 1.0 / cache->height(); | - | ||||||||||||||||||||||||
| 1694 | - | |||||||||||||||||||||||||
| 1695 | // Use global arrays by default | - | ||||||||||||||||||||||||
| 1696 | QGL2PEXVertexArray *vertexCoordinates = &vertexCoordinateArray; | - | ||||||||||||||||||||||||
| 1697 | QGL2PEXVertexArray *textureCoordinates = &textureCoordinateArray; | - | ||||||||||||||||||||||||
| 1698 | - | |||||||||||||||||||||||||
| 1699 | if (staticTextItem->useBackendOptimizations) {
| 0 | ||||||||||||||||||||||||
| 1700 | QOpenGLStaticTextUserData *userData = 0; | - | ||||||||||||||||||||||||
| 1701 | - | |||||||||||||||||||||||||
| 1702 | if (staticTextItem->userData() == 0
| 0 | ||||||||||||||||||||||||
| 1703 | || staticTextItem->userData()->type != QStaticTextUserData::OpenGLUserData) {
| 0 | ||||||||||||||||||||||||
| 1704 | - | |||||||||||||||||||||||||
| 1705 | userData = new QOpenGLStaticTextUserData(); | - | ||||||||||||||||||||||||
| 1706 | staticTextItem->setUserData(userData); | - | ||||||||||||||||||||||||
| 1707 | - | |||||||||||||||||||||||||
| 1708 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1709 | userData = static_cast<QOpenGLStaticTextUserData*>(staticTextItem->userData()); | - | ||||||||||||||||||||||||
| 1710 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1711 | - | |||||||||||||||||||||||||
| 1712 | userData->glyphFormat = glyphFormat; | - | ||||||||||||||||||||||||
| 1713 | userData->cacheSerialNumber = cache->serialNumber(); | - | ||||||||||||||||||||||||
| 1714 | - | |||||||||||||||||||||||||
| 1715 | // Use cache if backend optimizations is turned on | - | ||||||||||||||||||||||||
| 1716 | vertexCoordinates = &userData->vertexCoordinateArray; | - | ||||||||||||||||||||||||
| 1717 | textureCoordinates = &userData->textureCoordinateArray; | - | ||||||||||||||||||||||||
| 1718 | - | |||||||||||||||||||||||||
| 1719 | QSize size(cache->width(), cache->height()); | - | ||||||||||||||||||||||||
| 1720 | if (userData->cacheSize != size) {
| 0 | ||||||||||||||||||||||||
| 1721 | recreateVertexArrays = true; | - | ||||||||||||||||||||||||
| 1722 | userData->cacheSize = size; | - | ||||||||||||||||||||||||
| 1723 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1724 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1725 | - | |||||||||||||||||||||||||
| 1726 | if (recreateVertexArrays) {
| 0 | ||||||||||||||||||||||||
| 1727 | vertexCoordinates->clear(); | - | ||||||||||||||||||||||||
| 1728 | textureCoordinates->clear(); | - | ||||||||||||||||||||||||
| 1729 | - | |||||||||||||||||||||||||
| 1730 | bool supportsSubPixelPositions = fe->supportsSubPixelPositions(); | - | ||||||||||||||||||||||||
| 1731 | for (int i=0; i<staticTextItem->numGlyphs; ++i) {
| 0 | ||||||||||||||||||||||||
| 1732 | QFixed subPixelPosition; | - | ||||||||||||||||||||||||
| 1733 | if (supportsSubPixelPositions)
| 0 | ||||||||||||||||||||||||
| 1734 | subPixelPosition = fe->subPixelPositionForX(staticTextItem->glyphPositions[i].x); never executed: subPixelPosition = fe->subPixelPositionForX(staticTextItem->glyphPositions[i].x); | 0 | ||||||||||||||||||||||||
| 1735 | - | |||||||||||||||||||||||||
| 1736 | QTextureGlyphCache::GlyphAndSubPixelPosition glyph(staticTextItem->glyphs[i], subPixelPosition); | - | ||||||||||||||||||||||||
| 1737 | - | |||||||||||||||||||||||||
| 1738 | const QTextureGlyphCache::Coord &c = cache->coords[glyph]; | - | ||||||||||||||||||||||||
| 1739 | if (c.isNull())
| 0 | ||||||||||||||||||||||||
| 1740 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
| 1741 | - | |||||||||||||||||||||||||
| 1742 | int x = qFloor(staticTextItem->glyphPositions[i].x.toReal() * cache->transform().m11()) + c.baseLineX - margin; | - | ||||||||||||||||||||||||
| 1743 | int y = qRound(staticTextItem->glyphPositions[i].y.toReal() * cache->transform().m22()) - c.baseLineY - margin; | - | ||||||||||||||||||||||||
| 1744 | - | |||||||||||||||||||||||||
| 1745 | vertexCoordinates->addQuad(QRectF(x, y, c.w, c.h)); | - | ||||||||||||||||||||||||
| 1746 | textureCoordinates->addQuad(QRectF(c.x*dx, c.y*dy, c.w * dx, c.h * dy)); | - | ||||||||||||||||||||||||
| 1747 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1748 | - | |||||||||||||||||||||||||
| 1749 | staticTextItem->userDataNeedsUpdate = false; | - | ||||||||||||||||||||||||
| 1750 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1751 | - | |||||||||||||||||||||||||
| 1752 | int numGlyphs = vertexCoordinates->vertexCount() / 4; | - | ||||||||||||||||||||||||
| 1753 | if (numGlyphs == 0)
| 0 | ||||||||||||||||||||||||
| 1754 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1755 | - | |||||||||||||||||||||||||
| 1756 | if (elementIndices.size() < numGlyphs*6) {
| 0 | ||||||||||||||||||||||||
| 1757 | Q_ASSERT(elementIndices.size() % 6 == 0); | - | ||||||||||||||||||||||||
| 1758 | int j = elementIndices.size() / 6 * 4; | - | ||||||||||||||||||||||||
| 1759 | while (j < numGlyphs*4) {
| 0 | ||||||||||||||||||||||||
| 1760 | elementIndices.append(j + 0); | - | ||||||||||||||||||||||||
| 1761 | elementIndices.append(j + 0); | - | ||||||||||||||||||||||||
| 1762 | elementIndices.append(j + 1); | - | ||||||||||||||||||||||||
| 1763 | elementIndices.append(j + 2); | - | ||||||||||||||||||||||||
| 1764 | elementIndices.append(j + 3); | - | ||||||||||||||||||||||||
| 1765 | elementIndices.append(j + 3); | - | ||||||||||||||||||||||||
| 1766 | - | |||||||||||||||||||||||||
| 1767 | j += 4; | - | ||||||||||||||||||||||||
| 1768 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1769 | - | |||||||||||||||||||||||||
| 1770 | #if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO) | - | ||||||||||||||||||||||||
| 1771 | if (elementIndicesVBOId == 0) | - | ||||||||||||||||||||||||
| 1772 | glGenBuffers(1, &elementIndicesVBOId); | - | ||||||||||||||||||||||||
| 1773 | - | |||||||||||||||||||||||||
| 1774 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementIndicesVBOId); | - | ||||||||||||||||||||||||
| 1775 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementIndices.size() * sizeof(GLushort), | - | ||||||||||||||||||||||||
| 1776 | elementIndices.constData(), GL_STATIC_DRAW); | - | ||||||||||||||||||||||||
| 1777 | #endif | - | ||||||||||||||||||||||||
| 1778 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1779 | #if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO) | - | ||||||||||||||||||||||||
| 1780 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementIndicesVBOId); | - | ||||||||||||||||||||||||
| 1781 | #endif | - | ||||||||||||||||||||||||
| 1782 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1783 | - | |||||||||||||||||||||||||
| 1784 | setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinates->data()); | - | ||||||||||||||||||||||||
| 1785 | setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinates->data()); | - | ||||||||||||||||||||||||
| 1786 | - | |||||||||||||||||||||||||
| 1787 | if (!snapToPixelGrid) {
| 0 | ||||||||||||||||||||||||
| 1788 | snapToPixelGrid = true; | - | ||||||||||||||||||||||||
| 1789 | matrixDirty = true; | - | ||||||||||||||||||||||||
| 1790 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1791 | - | |||||||||||||||||||||||||
| 1792 | QBrush pensBrush = q->state()->pen.brush(); | - | ||||||||||||||||||||||||
| 1793 | setBrush(pensBrush); | - | ||||||||||||||||||||||||
| 1794 | - | |||||||||||||||||||||||||
| 1795 | if (glyphFormat == QFontEngine::Format_A32) {
| 0 | ||||||||||||||||||||||||
| 1796 | - | |||||||||||||||||||||||||
| 1797 | // Subpixel antialiasing without gamma correction | - | ||||||||||||||||||||||||
| 1798 | - | |||||||||||||||||||||||||
| 1799 | QPainter::CompositionMode compMode = q->state()->composition_mode; | - | ||||||||||||||||||||||||
| 1800 | Q_ASSERT(compMode == QPainter::CompositionMode_Source | - | ||||||||||||||||||||||||
| 1801 | || compMode == QPainter::CompositionMode_SourceOver); | - | ||||||||||||||||||||||||
| 1802 | - | |||||||||||||||||||||||||
| 1803 | shaderManager->setMaskType(QGLEngineShaderManager::SubPixelMaskPass1); | - | ||||||||||||||||||||||||
| 1804 | - | |||||||||||||||||||||||||
| 1805 | if (pensBrush.style() == Qt::SolidPattern) {
| 0 | ||||||||||||||||||||||||
| 1806 | // Solid patterns can get away with only one pass. | - | ||||||||||||||||||||||||
| 1807 | QColor c = pensBrush.color(); | - | ||||||||||||||||||||||||
| 1808 | qreal oldOpacity = q->state()->opacity; | - | ||||||||||||||||||||||||
| 1809 | if (compMode == QPainter::CompositionMode_Source) {
| 0 | ||||||||||||||||||||||||
| 1810 | c = qt_premultiplyColor(c, q->state()->opacity); | - | ||||||||||||||||||||||||
| 1811 | q->state()->opacity = 1; | - | ||||||||||||||||||||||||
| 1812 | opacityUniformDirty = true; | - | ||||||||||||||||||||||||
| 1813 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1814 | - | |||||||||||||||||||||||||
| 1815 | compositionModeDirty = false; // I can handle this myself, thank you very much | - | ||||||||||||||||||||||||
| 1816 | prepareForCachedGlyphDraw(*cache); | - | ||||||||||||||||||||||||
| 1817 | - | |||||||||||||||||||||||||
| 1818 | // prepareForCachedGlyphDraw() have set the opacity on the current shader, so the opacity state can now be reset. | - | ||||||||||||||||||||||||
| 1819 | if (compMode == QPainter::CompositionMode_Source) {
| 0 | ||||||||||||||||||||||||
| 1820 | q->state()->opacity = oldOpacity; | - | ||||||||||||||||||||||||
| 1821 | opacityUniformDirty = true; | - | ||||||||||||||||||||||||
| 1822 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1823 | - | |||||||||||||||||||||||||
| 1824 | glEnable(GL_BLEND); | - | ||||||||||||||||||||||||
| 1825 | glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); | - | ||||||||||||||||||||||||
| 1826 | glBlendColor(c.redF(), c.greenF(), c.blueF(), c.alphaF()); | - | ||||||||||||||||||||||||
| 1827 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1828 | // Other brush styles need two passes. | - | ||||||||||||||||||||||||
| 1829 | - | |||||||||||||||||||||||||
| 1830 | qreal oldOpacity = q->state()->opacity; | - | ||||||||||||||||||||||||
| 1831 | if (compMode == QPainter::CompositionMode_Source) {
| 0 | ||||||||||||||||||||||||
| 1832 | q->state()->opacity = 1; | - | ||||||||||||||||||||||||
| 1833 | opacityUniformDirty = true; | - | ||||||||||||||||||||||||
| 1834 | pensBrush = Qt::white; | - | ||||||||||||||||||||||||
| 1835 | setBrush(pensBrush); | - | ||||||||||||||||||||||||
| 1836 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1837 | - | |||||||||||||||||||||||||
| 1838 | compositionModeDirty = false; // I can handle this myself, thank you very much | - | ||||||||||||||||||||||||
| 1839 | prepareForCachedGlyphDraw(*cache); | - | ||||||||||||||||||||||||
| 1840 | glEnable(GL_BLEND); | - | ||||||||||||||||||||||||
| 1841 | glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); | - | ||||||||||||||||||||||||
| 1842 | - | |||||||||||||||||||||||||
| 1843 | glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT); | - | ||||||||||||||||||||||||
| 1844 | glBindTexture(GL_TEXTURE_2D, cache->texture()); | - | ||||||||||||||||||||||||
| 1845 | updateTextureFilter(GL_TEXTURE_2D, GL_REPEAT, false); | - | ||||||||||||||||||||||||
| 1846 | - | |||||||||||||||||||||||||
| 1847 | #if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO) | - | ||||||||||||||||||||||||
| 1848 | glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, 0); | - | ||||||||||||||||||||||||
| 1849 | #else | - | ||||||||||||||||||||||||
| 1850 | glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data()); | - | ||||||||||||||||||||||||
| 1851 | #endif | - | ||||||||||||||||||||||||
| 1852 | - | |||||||||||||||||||||||||
| 1853 | shaderManager->setMaskType(QGLEngineShaderManager::SubPixelMaskPass2); | - | ||||||||||||||||||||||||
| 1854 | - | |||||||||||||||||||||||||
| 1855 | if (compMode == QPainter::CompositionMode_Source) {
| 0 | ||||||||||||||||||||||||
| 1856 | q->state()->opacity = oldOpacity; | - | ||||||||||||||||||||||||
| 1857 | opacityUniformDirty = true; | - | ||||||||||||||||||||||||
| 1858 | pensBrush = q->state()->pen.brush(); | - | ||||||||||||||||||||||||
| 1859 | setBrush(pensBrush); | - | ||||||||||||||||||||||||
| 1860 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1861 | - | |||||||||||||||||||||||||
| 1862 | compositionModeDirty = false; | - | ||||||||||||||||||||||||
| 1863 | prepareForCachedGlyphDraw(*cache); | - | ||||||||||||||||||||||||
| 1864 | glEnable(GL_BLEND); | - | ||||||||||||||||||||||||
| 1865 | glBlendFunc(GL_ONE, GL_ONE); | - | ||||||||||||||||||||||||
| 1866 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1867 | compositionModeDirty = true; | - | ||||||||||||||||||||||||
| 1868 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1869 | // Grayscale/mono glyphs | - | ||||||||||||||||||||||||
| 1870 | - | |||||||||||||||||||||||||
| 1871 | shaderManager->setMaskType(QGLEngineShaderManager::PixelMask); | - | ||||||||||||||||||||||||
| 1872 | prepareForCachedGlyphDraw(*cache); | - | ||||||||||||||||||||||||
| 1873 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1874 | - | |||||||||||||||||||||||||
| 1875 | QGLTextureGlyphCache::FilterMode filterMode = (s->matrix.type() > QTransform::TxTranslate)?QGLTextureGlyphCache::Linear:QGLTextureGlyphCache::Nearest;
| 0 | ||||||||||||||||||||||||
| 1876 | if (lastMaskTextureUsed != cache->texture() || cache->filterMode() != filterMode) {
| 0 | ||||||||||||||||||||||||
| 1877 | - | |||||||||||||||||||||||||
| 1878 | glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT); | - | ||||||||||||||||||||||||
| 1879 | if (lastMaskTextureUsed != cache->texture()) {
| 0 | ||||||||||||||||||||||||
| 1880 | glBindTexture(GL_TEXTURE_2D, cache->texture()); | - | ||||||||||||||||||||||||
| 1881 | lastMaskTextureUsed = cache->texture(); | - | ||||||||||||||||||||||||
| 1882 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1883 | - | |||||||||||||||||||||||||
| 1884 | if (cache->filterMode() != filterMode) {
| 0 | ||||||||||||||||||||||||
| 1885 | if (filterMode == QGLTextureGlyphCache::Linear) {
| 0 | ||||||||||||||||||||||||
| 1886 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | - | ||||||||||||||||||||||||
| 1887 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | - | ||||||||||||||||||||||||
| 1888 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1889 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | - | ||||||||||||||||||||||||
| 1890 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | - | ||||||||||||||||||||||||
| 1891 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1892 | cache->setFilterMode(filterMode); | - | ||||||||||||||||||||||||
| 1893 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1894 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1895 | - | |||||||||||||||||||||||||
| 1896 | #if defined(QT_OPENGL_DRAWCACHEDGLYPHS_INDEX_ARRAY_VBO) | - | ||||||||||||||||||||||||
| 1897 | glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, 0); | - | ||||||||||||||||||||||||
| 1898 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | - | ||||||||||||||||||||||||
| 1899 | #else | - | ||||||||||||||||||||||||
| 1900 | glDrawElements(GL_TRIANGLE_STRIP, 6 * numGlyphs, GL_UNSIGNED_SHORT, elementIndices.data()); | - | ||||||||||||||||||||||||
| 1901 | #endif | - | ||||||||||||||||||||||||
| 1902 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1903 | - | |||||||||||||||||||||||||
| 1904 | void QGL2PaintEngineEx::drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, | - | ||||||||||||||||||||||||
| 1905 | QPainter::PixmapFragmentHints hints) | - | ||||||||||||||||||||||||
| 1906 | { | - | ||||||||||||||||||||||||
| 1907 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 1908 | // Use fallback for extended composition modes. | - | ||||||||||||||||||||||||
| 1909 | if (state()->composition_mode > QPainter::CompositionMode_Plus) {
| 0 | ||||||||||||||||||||||||
| 1910 | QPaintEngineEx::drawPixmapFragments(fragments, fragmentCount, pixmap, hints); | - | ||||||||||||||||||||||||
| 1911 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 1912 | } | - | ||||||||||||||||||||||||
| 1913 | - | |||||||||||||||||||||||||
| 1914 | ensureActive(); | - | ||||||||||||||||||||||||
| 1915 | int max_texture_size = d->ctx->d_func()->maxTextureSize(); | - | ||||||||||||||||||||||||
| 1916 | if (pixmap.width() > max_texture_size || pixmap.height() > max_texture_size) {
| 0 | ||||||||||||||||||||||||
| 1917 | QPixmap scaled = pixmap.scaled(max_texture_size, max_texture_size, Qt::KeepAspectRatio); | - | ||||||||||||||||||||||||
| 1918 | d->drawPixmapFragments(fragments, fragmentCount, scaled, hints); | - | ||||||||||||||||||||||||
| 1919 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1920 | d->drawPixmapFragments(fragments, fragmentCount, pixmap, hints); | - | ||||||||||||||||||||||||
| 1921 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1922 | } | - | ||||||||||||||||||||||||
| 1923 | - | |||||||||||||||||||||||||
| 1924 | - | |||||||||||||||||||||||||
| 1925 | void QGL2PaintEngineExPrivate::drawPixmapFragments(const QPainter::PixmapFragment *fragments, | - | ||||||||||||||||||||||||
| 1926 | int fragmentCount, const QPixmap &pixmap, | - | ||||||||||||||||||||||||
| 1927 | QPainter::PixmapFragmentHints hints) | - | ||||||||||||||||||||||||
| 1928 | { | - | ||||||||||||||||||||||||
| 1929 | GLfloat dx = 1.0f / pixmap.size().width(); | - | ||||||||||||||||||||||||
| 1930 | GLfloat dy = 1.0f / pixmap.size().height(); | - | ||||||||||||||||||||||||
| 1931 | - | |||||||||||||||||||||||||
| 1932 | vertexCoordinateArray.clear(); | - | ||||||||||||||||||||||||
| 1933 | textureCoordinateArray.clear(); | - | ||||||||||||||||||||||||
| 1934 | opacityArray.reset(); | - | ||||||||||||||||||||||||
| 1935 | - | |||||||||||||||||||||||||
| 1936 | if (snapToPixelGrid) {
| 0 | ||||||||||||||||||||||||
| 1937 | snapToPixelGrid = false; | - | ||||||||||||||||||||||||
| 1938 | matrixDirty = true; | - | ||||||||||||||||||||||||
| 1939 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1940 | - | |||||||||||||||||||||||||
| 1941 | bool allOpaque = true; | - | ||||||||||||||||||||||||
| 1942 | - | |||||||||||||||||||||||||
| 1943 | for (int i = 0; i < fragmentCount; ++i) {
| 0 | ||||||||||||||||||||||||
| 1944 | qreal s = 0; | - | ||||||||||||||||||||||||
| 1945 | qreal c = 1; | - | ||||||||||||||||||||||||
| 1946 | if (fragments[i].rotation != 0) {
| 0 | ||||||||||||||||||||||||
| 1947 | s = qFastSin(qDegreesToRadians(fragments[i].rotation)); | - | ||||||||||||||||||||||||
| 1948 | c = qFastCos(qDegreesToRadians(fragments[i].rotation)); | - | ||||||||||||||||||||||||
| 1949 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1950 | - | |||||||||||||||||||||||||
| 1951 | qreal right = 0.5 * fragments[i].scaleX * fragments[i].width; | - | ||||||||||||||||||||||||
| 1952 | qreal bottom = 0.5 * fragments[i].scaleY * fragments[i].height; | - | ||||||||||||||||||||||||
| 1953 | QGLPoint bottomRight(right * c - bottom * s, right * s + bottom * c); | - | ||||||||||||||||||||||||
| 1954 | QGLPoint bottomLeft(-right * c - bottom * s, -right * s + bottom * c); | - | ||||||||||||||||||||||||
| 1955 | - | |||||||||||||||||||||||||
| 1956 | vertexCoordinateArray.addVertex(bottomRight.x + fragments[i].x, bottomRight.y + fragments[i].y); | - | ||||||||||||||||||||||||
| 1957 | vertexCoordinateArray.addVertex(-bottomLeft.x + fragments[i].x, -bottomLeft.y + fragments[i].y); | - | ||||||||||||||||||||||||
| 1958 | vertexCoordinateArray.addVertex(-bottomRight.x + fragments[i].x, -bottomRight.y + fragments[i].y); | - | ||||||||||||||||||||||||
| 1959 | vertexCoordinateArray.addVertex(-bottomRight.x + fragments[i].x, -bottomRight.y + fragments[i].y); | - | ||||||||||||||||||||||||
| 1960 | vertexCoordinateArray.addVertex(bottomLeft.x + fragments[i].x, bottomLeft.y + fragments[i].y); | - | ||||||||||||||||||||||||
| 1961 | vertexCoordinateArray.addVertex(bottomRight.x + fragments[i].x, bottomRight.y + fragments[i].y); | - | ||||||||||||||||||||||||
| 1962 | - | |||||||||||||||||||||||||
| 1963 | QGLRect src(fragments[i].sourceLeft * dx, fragments[i].sourceTop * dy, | - | ||||||||||||||||||||||||
| 1964 | (fragments[i].sourceLeft + fragments[i].width) * dx, | - | ||||||||||||||||||||||||
| 1965 | (fragments[i].sourceTop + fragments[i].height) * dy); | - | ||||||||||||||||||||||||
| 1966 | - | |||||||||||||||||||||||||
| 1967 | textureCoordinateArray.addVertex(src.right, src.bottom); | - | ||||||||||||||||||||||||
| 1968 | textureCoordinateArray.addVertex(src.right, src.top); | - | ||||||||||||||||||||||||
| 1969 | textureCoordinateArray.addVertex(src.left, src.top); | - | ||||||||||||||||||||||||
| 1970 | textureCoordinateArray.addVertex(src.left, src.top); | - | ||||||||||||||||||||||||
| 1971 | textureCoordinateArray.addVertex(src.left, src.bottom); | - | ||||||||||||||||||||||||
| 1972 | textureCoordinateArray.addVertex(src.right, src.bottom); | - | ||||||||||||||||||||||||
| 1973 | - | |||||||||||||||||||||||||
| 1974 | qreal opacity = fragments[i].opacity * q->state()->opacity; | - | ||||||||||||||||||||||||
| 1975 | opacityArray << opacity << opacity << opacity << opacity << opacity << opacity; | - | ||||||||||||||||||||||||
| 1976 | allOpaque &= (opacity >= 0.99f); | - | ||||||||||||||||||||||||
| 1977 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1978 | - | |||||||||||||||||||||||||
| 1979 | glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); | - | ||||||||||||||||||||||||
| 1980 | QGLTexture *texture = ctx->d_func()->bindTexture(pixmap, GL_TEXTURE_2D, GL_RGBA, | - | ||||||||||||||||||||||||
| 1981 | QGLContext::InternalBindOption | - | ||||||||||||||||||||||||
| 1982 | | QGLContext::CanFlipNativePixmapBindOption); | - | ||||||||||||||||||||||||
| 1983 | - | |||||||||||||||||||||||||
| 1984 | if (texture->options & QGLContext::InvertedYBindOption) {
| 0 | ||||||||||||||||||||||||
| 1985 | // Flip texture y-coordinate. | - | ||||||||||||||||||||||||
| 1986 | QGLPoint *data = textureCoordinateArray.data(); | - | ||||||||||||||||||||||||
| 1987 | for (int i = 0; i < 6 * fragmentCount; ++i)
| 0 | ||||||||||||||||||||||||
| 1988 | data[i].y = 1 - data[i].y; never executed: data[i].y = 1 - data[i].y; | 0 | ||||||||||||||||||||||||
| 1989 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1990 | - | |||||||||||||||||||||||||
| 1991 | transferMode(ImageArrayDrawingMode); | - | ||||||||||||||||||||||||
| 1992 | - | |||||||||||||||||||||||||
| 1993 | bool isBitmap = pixmap.isQBitmap(); | - | ||||||||||||||||||||||||
| 1994 | bool isOpaque = !isBitmap && (!pixmap.hasAlpha() || (hints & QPainter::OpaqueHint)) && allOpaque;
| 0 | ||||||||||||||||||||||||
| 1995 | - | |||||||||||||||||||||||||
| 1996 | updateTextureFilter(GL_TEXTURE_2D, GL_CLAMP_TO_EDGE, | - | ||||||||||||||||||||||||
| 1997 | q->state()->renderHints & QPainter::SmoothPixmapTransform, texture->id); | - | ||||||||||||||||||||||||
| 1998 | - | |||||||||||||||||||||||||
| 1999 | // Setup for texture drawing | - | ||||||||||||||||||||||||
| 2000 | currentBrush = noBrush; | - | ||||||||||||||||||||||||
| 2001 | shaderManager->setSrcPixelType(isBitmap ? QGLEngineShaderManager::PatternSrc | - | ||||||||||||||||||||||||
| 2002 | : QGLEngineShaderManager::ImageSrc); | - | ||||||||||||||||||||||||
| 2003 | if (prepareForDraw(isOpaque))
| 0 | ||||||||||||||||||||||||
| 2004 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::ImageTexture), QT_IMAGE_TEXTURE_UNIT); never executed: shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::ImageTexture), GLuint(0)); | 0 | ||||||||||||||||||||||||
| 2005 | - | |||||||||||||||||||||||||
| 2006 | if (isBitmap) {
| 0 | ||||||||||||||||||||||||
| 2007 | QColor col = qt_premultiplyColor(q->state()->pen.color(), (GLfloat)q->state()->opacity); | - | ||||||||||||||||||||||||
| 2008 | shaderManager->currentProgram()->setUniformValue(location(QGLEngineShaderManager::PatternColor), col); | - | ||||||||||||||||||||||||
| 2009 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2010 | - | |||||||||||||||||||||||||
| 2011 | glDrawArrays(GL_TRIANGLES, 0, 6 * fragmentCount); | - | ||||||||||||||||||||||||
| 2012 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2013 | - | |||||||||||||||||||||||||
| 2014 | bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) | - | ||||||||||||||||||||||||
| 2015 | { | - | ||||||||||||||||||||||||
| 2016 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 2017 | - | |||||||||||||||||||||||||
| 2018 | // qDebug("QGL2PaintEngineEx::begin()"); | - | ||||||||||||||||||||||||
| 2019 | if (pdev->devType() == QInternal::OpenGL)
| 0-2 | ||||||||||||||||||||||||
| 2020 | d->device = static_cast<QGLPaintDevice*>(pdev); never executed: d->device = static_cast<QGLPaintDevice*>(pdev); | 0 | ||||||||||||||||||||||||
| 2021 | else | - | ||||||||||||||||||||||||
| 2022 | d->device = QGLPaintDevice::getDevice(pdev); executed 2 times by 1 test: d->device = QGLPaintDevice::getDevice(pdev);Executed by:
| 2 | ||||||||||||||||||||||||
| 2023 | - | |||||||||||||||||||||||||
| 2024 | if (!d->device)
| 0-2 | ||||||||||||||||||||||||
| 2025 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2026 | - | |||||||||||||||||||||||||
| 2027 | d->ctx = d->device->context(); | - | ||||||||||||||||||||||||
| 2028 | d->ctx->d_ptr->active_engine = this; | - | ||||||||||||||||||||||||
| 2029 | - | |||||||||||||||||||||||||
| 2030 | d->resetOpenGLContextActiveEngine(); | - | ||||||||||||||||||||||||
| 2031 | - | |||||||||||||||||||||||||
| 2032 | const QSize sz = d->device->size(); | - | ||||||||||||||||||||||||
| 2033 | d->width = sz.width(); | - | ||||||||||||||||||||||||
| 2034 | d->height = sz.height(); | - | ||||||||||||||||||||||||
| 2035 | d->mode = BrushDrawingMode; | - | ||||||||||||||||||||||||
| 2036 | d->brushTextureDirty = true; | - | ||||||||||||||||||||||||
| 2037 | d->brushUniformsDirty = true; | - | ||||||||||||||||||||||||
| 2038 | d->matrixUniformDirty = true; | - | ||||||||||||||||||||||||
| 2039 | d->matrixDirty = true; | - | ||||||||||||||||||||||||
| 2040 | d->compositionModeDirty = true; | - | ||||||||||||||||||||||||
| 2041 | d->opacityUniformDirty = true; | - | ||||||||||||||||||||||||
| 2042 | d->translateZUniformDirty = true; | - | ||||||||||||||||||||||||
| 2043 | d->needsSync = true; | - | ||||||||||||||||||||||||
| 2044 | d->useSystemClip = !systemClip().isEmpty(); | - | ||||||||||||||||||||||||
| 2045 | d->currentBrush = QBrush(); | - | ||||||||||||||||||||||||
| 2046 | - | |||||||||||||||||||||||||
| 2047 | d->dirtyStencilRegion = QRect(0, 0, d->width, d->height); | - | ||||||||||||||||||||||||
| 2048 | d->stencilClean = true; | - | ||||||||||||||||||||||||
| 2049 | - | |||||||||||||||||||||||||
| 2050 | // Calling begin paint should make the correct context current. So, any | - | ||||||||||||||||||||||||
| 2051 | // code which calls into GL or otherwise needs a current context *must* | - | ||||||||||||||||||||||||
| 2052 | // go after beginPaint: | - | ||||||||||||||||||||||||
| 2053 | d->device->beginPaint(); | - | ||||||||||||||||||||||||
| 2054 | - | |||||||||||||||||||||||||
| 2055 | d->initializeOpenGLFunctions(); | - | ||||||||||||||||||||||||
| 2056 | - | |||||||||||||||||||||||||
| 2057 | d->shaderManager = new QGLEngineShaderManager(d->ctx); | - | ||||||||||||||||||||||||
| 2058 | - | |||||||||||||||||||||||||
| 2059 | d->glDisable(GL_STENCIL_TEST); | - | ||||||||||||||||||||||||
| 2060 | d->glDisable(GL_DEPTH_TEST); | - | ||||||||||||||||||||||||
| 2061 | d->glDisable(GL_SCISSOR_TEST); | - | ||||||||||||||||||||||||
| 2062 | - | |||||||||||||||||||||||||
| 2063 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||||||||
| 2064 | if (!d->ctx->contextHandle()->isOpenGLES())
| 0-2 | ||||||||||||||||||||||||
| 2065 | d->glDisable(GL_MULTISAMPLE); executed 2 times by 1 test: d->glDisable(0x809D);Executed by:
| 2 | ||||||||||||||||||||||||
| 2066 | #endif | - | ||||||||||||||||||||||||
| 2067 | - | |||||||||||||||||||||||||
| 2068 | d->glyphCacheFormat = QFontEngine::Format_A8; | - | ||||||||||||||||||||||||
| 2069 | - | |||||||||||||||||||||||||
| 2070 | #if !defined(QT_OPENGL_ES_2) | - | ||||||||||||||||||||||||
| 2071 | if (!d->ctx->contextHandle()->isOpenGLES()) {
| 0-2 | ||||||||||||||||||||||||
| 2072 | d->glyphCacheFormat = QFontEngine::Format_A32; | - | ||||||||||||||||||||||||
| 2073 | d->multisamplingAlwaysEnabled = false; | - | ||||||||||||||||||||||||
| 2074 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2075 | d->multisamplingAlwaysEnabled = d->device->format().sampleBuffers(); | - | ||||||||||||||||||||||||
| 2076 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2077 | #else | - | ||||||||||||||||||||||||
| 2078 | // OpenGL ES can't switch MSAA off, so if the gl paint device is | - | ||||||||||||||||||||||||
| 2079 | // multisampled, it's always multisampled. | - | ||||||||||||||||||||||||
| 2080 | d->multisamplingAlwaysEnabled = d->device->format().sampleBuffers(); | - | ||||||||||||||||||||||||
| 2081 | #endif | - | ||||||||||||||||||||||||
| 2082 | - | |||||||||||||||||||||||||
| 2083 | return true; executed 2 times by 1 test: return true;Executed by:
| 2 | ||||||||||||||||||||||||
| 2084 | } | - | ||||||||||||||||||||||||
| 2085 | - | |||||||||||||||||||||||||
| 2086 | bool QGL2PaintEngineEx::end() | - | ||||||||||||||||||||||||
| 2087 | { | - | ||||||||||||||||||||||||
| 2088 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 2089 | - | |||||||||||||||||||||||||
| 2090 | QGLContext *ctx = d->ctx; | - | ||||||||||||||||||||||||
| 2091 | d->glUseProgram(0); | - | ||||||||||||||||||||||||
| 2092 | d->transferMode(BrushDrawingMode); | - | ||||||||||||||||||||||||
| 2093 | d->device->endPaint(); | - | ||||||||||||||||||||||||
| 2094 | - | |||||||||||||||||||||||||
| 2095 | ctx->d_ptr->active_engine = 0; | - | ||||||||||||||||||||||||
| 2096 | - | |||||||||||||||||||||||||
| 2097 | d->resetOpenGLContextActiveEngine(); | - | ||||||||||||||||||||||||
| 2098 | - | |||||||||||||||||||||||||
| 2099 | d->resetGLState(); | - | ||||||||||||||||||||||||
| 2100 | - | |||||||||||||||||||||||||
| 2101 | delete d->shaderManager; | - | ||||||||||||||||||||||||
| 2102 | d->shaderManager = 0; | - | ||||||||||||||||||||||||
| 2103 | d->currentBrush = QBrush(); | - | ||||||||||||||||||||||||
| 2104 | - | |||||||||||||||||||||||||
| 2105 | #ifdef QT_OPENGL_CACHE_AS_VBOS | - | ||||||||||||||||||||||||
| 2106 | if (!d->unusedVBOSToClean.isEmpty()) { | - | ||||||||||||||||||||||||
| 2107 | d->glDeleteBuffers(d->unusedVBOSToClean.size(), d->unusedVBOSToClean.constData()); | - | ||||||||||||||||||||||||
| 2108 | d->unusedVBOSToClean.clear(); | - | ||||||||||||||||||||||||
| 2109 | } | - | ||||||||||||||||||||||||
| 2110 | if (!d->unusedIBOSToClean.isEmpty()) { | - | ||||||||||||||||||||||||
| 2111 | d->glDeleteBuffers(d->unusedIBOSToClean.size(), d->unusedIBOSToClean.constData()); | - | ||||||||||||||||||||||||
| 2112 | d->unusedIBOSToClean.clear(); | - | ||||||||||||||||||||||||
| 2113 | } | - | ||||||||||||||||||||||||
| 2114 | #endif | - | ||||||||||||||||||||||||
| 2115 | - | |||||||||||||||||||||||||
| 2116 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||||||||
| 2117 | } | - | ||||||||||||||||||||||||
| 2118 | - | |||||||||||||||||||||||||
| 2119 | void QGL2PaintEngineEx::ensureActive() | - | ||||||||||||||||||||||||
| 2120 | { | - | ||||||||||||||||||||||||
| 2121 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 2122 | QGLContext *ctx = d->ctx; | - | ||||||||||||||||||||||||
| 2123 | - | |||||||||||||||||||||||||
| 2124 | if (isActive() && (ctx->d_ptr->active_engine != this || d->resetOpenGLContextActiveEngine())) {
| 0-28 | ||||||||||||||||||||||||
| 2125 | ctx->d_ptr->active_engine = this; | - | ||||||||||||||||||||||||
| 2126 | d->needsSync = true; | - | ||||||||||||||||||||||||
| 2127 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2128 | - | |||||||||||||||||||||||||
| 2129 | d->device->ensureActiveTarget(); | - | ||||||||||||||||||||||||
| 2130 | - | |||||||||||||||||||||||||
| 2131 | if (d->needsSync) {
| 2-26 | ||||||||||||||||||||||||
| 2132 | d->transferMode(BrushDrawingMode); | - | ||||||||||||||||||||||||
| 2133 | d->glViewport(0, 0, d->width, d->height); | - | ||||||||||||||||||||||||
| 2134 | d->needsSync = false; | - | ||||||||||||||||||||||||
| 2135 | d->lastMaskTextureUsed = 0; | - | ||||||||||||||||||||||||
| 2136 | d->shaderManager->setDirty(); | - | ||||||||||||||||||||||||
| 2137 | d->ctx->d_func()->syncGlState(); | - | ||||||||||||||||||||||||
| 2138 | for (int i = 0; i < 3; ++i)
| 2-6 | ||||||||||||||||||||||||
| 2139 | d->vertexAttribPointers[i] = (GLfloat*)-1; // Assume the pointers are clobbered executed 6 times by 1 test: d->vertexAttribPointers[i] = (GLfloat*)-1;Executed by:
| 6 | ||||||||||||||||||||||||
| 2140 | setState(state()); | - | ||||||||||||||||||||||||
| 2141 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2142 | } executed 28 times by 1 test: end of blockExecuted by:
| 28 | ||||||||||||||||||||||||
| 2143 | - | |||||||||||||||||||||||||
| 2144 | void QGL2PaintEngineExPrivate::updateClipScissorTest() | - | ||||||||||||||||||||||||
| 2145 | { | - | ||||||||||||||||||||||||
| 2146 | Q_Q(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 2147 | if (q->state()->clipTestEnabled) {
| 0-2 | ||||||||||||||||||||||||
| 2148 | glEnable(GL_STENCIL_TEST); | - | ||||||||||||||||||||||||
| 2149 | glStencilFunc(GL_LEQUAL, q->state()->currentClip, ~GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 2150 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2151 | glDisable(GL_STENCIL_TEST); | - | ||||||||||||||||||||||||
| 2152 | glStencilFunc(GL_ALWAYS, 0, 0xff); | - | ||||||||||||||||||||||||
| 2153 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2154 | - | |||||||||||||||||||||||||
| 2155 | #ifdef QT_GL_NO_SCISSOR_TEST | - | ||||||||||||||||||||||||
| 2156 | currentScissorBounds = QRect(0, 0, width, height); | - | ||||||||||||||||||||||||
| 2157 | #else | - | ||||||||||||||||||||||||
| 2158 | QRect bounds = q->state()->rectangleClip; | - | ||||||||||||||||||||||||
| 2159 | if (!q->state()->clipEnabled) {
| 0-2 | ||||||||||||||||||||||||
| 2160 | if (useSystemClip)
| 0 | ||||||||||||||||||||||||
| 2161 | bounds = systemClip.boundingRect(); never executed: bounds = systemClip.boundingRect(); | 0 | ||||||||||||||||||||||||
| 2162 | else | - | ||||||||||||||||||||||||
| 2163 | bounds = QRect(0, 0, width, height); never executed: bounds = QRect(0, 0, width, height); | 0 | ||||||||||||||||||||||||
| 2164 | } else { | - | ||||||||||||||||||||||||
| 2165 | if (useSystemClip)
| 0-2 | ||||||||||||||||||||||||
| 2166 | bounds = bounds.intersected(systemClip.boundingRect()); executed 2 times by 1 test: bounds = bounds.intersected(systemClip.boundingRect());Executed by:
| 2 | ||||||||||||||||||||||||
| 2167 | else | - | ||||||||||||||||||||||||
| 2168 | bounds = bounds.intersected(QRect(0, 0, width, height)); never executed: bounds = bounds.intersected(QRect(0, 0, width, height)); | 0 | ||||||||||||||||||||||||
| 2169 | } | - | ||||||||||||||||||||||||
| 2170 | - | |||||||||||||||||||||||||
| 2171 | currentScissorBounds = bounds; | - | ||||||||||||||||||||||||
| 2172 | - | |||||||||||||||||||||||||
| 2173 | if (bounds == QRect(0, 0, width, height)) {
| 0-2 | ||||||||||||||||||||||||
| 2174 | glDisable(GL_SCISSOR_TEST); | - | ||||||||||||||||||||||||
| 2175 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2176 | glEnable(GL_SCISSOR_TEST); | - | ||||||||||||||||||||||||
| 2177 | setScissor(bounds); | - | ||||||||||||||||||||||||
| 2178 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2179 | #endif | - | ||||||||||||||||||||||||
| 2180 | } | - | ||||||||||||||||||||||||
| 2181 | - | |||||||||||||||||||||||||
| 2182 | void QGL2PaintEngineExPrivate::setScissor(const QRect &rect) | - | ||||||||||||||||||||||||
| 2183 | { | - | ||||||||||||||||||||||||
| 2184 | const int left = rect.left(); | - | ||||||||||||||||||||||||
| 2185 | const int width = rect.width(); | - | ||||||||||||||||||||||||
| 2186 | int bottom = height - (rect.top() + rect.height()); | - | ||||||||||||||||||||||||
| 2187 | if (device->isFlipped()) {
| 0 | ||||||||||||||||||||||||
| 2188 | bottom = rect.top(); | - | ||||||||||||||||||||||||
| 2189 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2190 | const int height = rect.height(); | - | ||||||||||||||||||||||||
| 2191 | - | |||||||||||||||||||||||||
| 2192 | glScissor(left, bottom, width, height); | - | ||||||||||||||||||||||||
| 2193 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2194 | - | |||||||||||||||||||||||||
| 2195 | void QGL2PaintEngineEx::clipEnabledChanged() | - | ||||||||||||||||||||||||
| 2196 | { | - | ||||||||||||||||||||||||
| 2197 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 2198 | - | |||||||||||||||||||||||||
| 2199 | state()->clipChanged = true; | - | ||||||||||||||||||||||||
| 2200 | - | |||||||||||||||||||||||||
| 2201 | if (painter()->hasClipping())
| 0 | ||||||||||||||||||||||||
| 2202 | d->regenerateClip(); never executed: d->regenerateClip(); | 0 | ||||||||||||||||||||||||
| 2203 | else | - | ||||||||||||||||||||||||
| 2204 | d->systemStateChanged(); never executed: d->systemStateChanged(); | 0 | ||||||||||||||||||||||||
| 2205 | } | - | ||||||||||||||||||||||||
| 2206 | - | |||||||||||||||||||||||||
| 2207 | void QGL2PaintEngineExPrivate::clearClip(uint value) | - | ||||||||||||||||||||||||
| 2208 | { | - | ||||||||||||||||||||||||
| 2209 | dirtyStencilRegion -= currentScissorBounds; | - | ||||||||||||||||||||||||
| 2210 | - | |||||||||||||||||||||||||
| 2211 | glStencilMask(0xff); | - | ||||||||||||||||||||||||
| 2212 | glClearStencil(value); | - | ||||||||||||||||||||||||
| 2213 | glClear(GL_STENCIL_BUFFER_BIT); | - | ||||||||||||||||||||||||
| 2214 | glStencilMask(0x0); | - | ||||||||||||||||||||||||
| 2215 | - | |||||||||||||||||||||||||
| 2216 | q->state()->needsClipBufferClear = false; | - | ||||||||||||||||||||||||
| 2217 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2218 | - | |||||||||||||||||||||||||
| 2219 | void QGL2PaintEngineExPrivate::writeClip(const QVectorPath &path, uint value) | - | ||||||||||||||||||||||||
| 2220 | { | - | ||||||||||||||||||||||||
| 2221 | transferMode(BrushDrawingMode); | - | ||||||||||||||||||||||||
| 2222 | - | |||||||||||||||||||||||||
| 2223 | if (snapToPixelGrid) {
| 0-2 | ||||||||||||||||||||||||
| 2224 | snapToPixelGrid = false; | - | ||||||||||||||||||||||||
| 2225 | matrixDirty = true; | - | ||||||||||||||||||||||||
| 2226 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2227 | - | |||||||||||||||||||||||||
| 2228 | if (matrixDirty)
| 0-2 | ||||||||||||||||||||||||
| 2229 | updateMatrix(); executed 2 times by 1 test: updateMatrix();Executed by:
| 2 | ||||||||||||||||||||||||
| 2230 | - | |||||||||||||||||||||||||
| 2231 | stencilClean = false; | - | ||||||||||||||||||||||||
| 2232 | - | |||||||||||||||||||||||||
| 2233 | const bool singlePass = !path.hasWindingFill()
| 0-2 | ||||||||||||||||||||||||
| 2234 | && (((q->state()->currentClip == maxClip - 1) && q->state()->clipTestEnabled)
| 0-2 | ||||||||||||||||||||||||
| 2235 | || q->state()->needsClipBufferClear);
| 0-2 | ||||||||||||||||||||||||
| 2236 | const uint referenceClipValue = q->state()->needsClipBufferClear ? 1 : q->state()->currentClip;
| 0-2 | ||||||||||||||||||||||||
| 2237 | - | |||||||||||||||||||||||||
| 2238 | if (q->state()->needsClipBufferClear)
| 0-2 | ||||||||||||||||||||||||
| 2239 | clearClip(1); never executed: clearClip(1); | 0 | ||||||||||||||||||||||||
| 2240 | - | |||||||||||||||||||||||||
| 2241 | if (path.isEmpty()) {
| 0-2 | ||||||||||||||||||||||||
| 2242 | glEnable(GL_STENCIL_TEST); | - | ||||||||||||||||||||||||
| 2243 | glStencilFunc(GL_LEQUAL, value, ~GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 2244 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2245 | } | - | ||||||||||||||||||||||||
| 2246 | - | |||||||||||||||||||||||||
| 2247 | if (q->state()->clipTestEnabled)
| 0-2 | ||||||||||||||||||||||||
| 2248 | glStencilFunc(GL_LEQUAL, q->state()->currentClip, ~GL_STENCIL_HIGH_BIT); never executed: glStencilFunc(0x0203, q->state()->currentClip, ~GLuint(0x80)); | 0 | ||||||||||||||||||||||||
| 2249 | else | - | ||||||||||||||||||||||||
| 2250 | glStencilFunc(GL_ALWAYS, 0, 0xff); executed 2 times by 1 test: glStencilFunc(0x0207, 0, 0xff);Executed by:
| 2 | ||||||||||||||||||||||||
| 2251 | - | |||||||||||||||||||||||||
| 2252 | vertexCoordinateArray.clear(); | - | ||||||||||||||||||||||||
| 2253 | vertexCoordinateArray.addPath(path, inverseScale, false); | - | ||||||||||||||||||||||||
| 2254 | - | |||||||||||||||||||||||||
| 2255 | if (!singlePass)
| 0-2 | ||||||||||||||||||||||||
| 2256 | fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill()); executed 2 times by 1 test: fillStencilWithVertexArray(vertexCoordinateArray, path.hasWindingFill());Executed by:
| 2 | ||||||||||||||||||||||||
| 2257 | - | |||||||||||||||||||||||||
| 2258 | glColorMask(false, false, false, false); | - | ||||||||||||||||||||||||
| 2259 | glEnable(GL_STENCIL_TEST); | - | ||||||||||||||||||||||||
| 2260 | useSimpleShader(); | - | ||||||||||||||||||||||||
| 2261 | - | |||||||||||||||||||||||||
| 2262 | if (singlePass) {
| 0-2 | ||||||||||||||||||||||||
| 2263 | // Under these conditions we can set the new stencil value in a single | - | ||||||||||||||||||||||||
| 2264 | // pass, by using the current value and the "new value" as the toggles | - | ||||||||||||||||||||||||
| 2265 | - | |||||||||||||||||||||||||
| 2266 | glStencilFunc(GL_LEQUAL, referenceClipValue, ~GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 2267 | glStencilOp(GL_KEEP, GL_INVERT, GL_INVERT); | - | ||||||||||||||||||||||||
| 2268 | glStencilMask(value ^ referenceClipValue); | - | ||||||||||||||||||||||||
| 2269 | - | |||||||||||||||||||||||||
| 2270 | drawVertexArrays(vertexCoordinateArray, GL_TRIANGLE_FAN); | - | ||||||||||||||||||||||||
| 2271 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2272 | glStencilOp(GL_KEEP, GL_REPLACE, GL_REPLACE); | - | ||||||||||||||||||||||||
| 2273 | glStencilMask(0xff); | - | ||||||||||||||||||||||||
| 2274 | - | |||||||||||||||||||||||||
| 2275 | if (!q->state()->clipTestEnabled && path.hasWindingFill()) {
| 0-2 | ||||||||||||||||||||||||
| 2276 | // Pass when any clip bit is set, set high bit | - | ||||||||||||||||||||||||
| 2277 | glStencilFunc(GL_NOTEQUAL, GL_STENCIL_HIGH_BIT, ~GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 2278 | composite(vertexCoordinateArray.boundingRect()); | - | ||||||||||||||||||||||||
| 2279 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2280 | - | |||||||||||||||||||||||||
| 2281 | // Pass when high bit is set, replace stencil value with new clip value | - | ||||||||||||||||||||||||
| 2282 | glStencilFunc(GL_NOTEQUAL, value, GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 2283 | - | |||||||||||||||||||||||||
| 2284 | composite(vertexCoordinateArray.boundingRect()); | - | ||||||||||||||||||||||||
| 2285 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2286 | - | |||||||||||||||||||||||||
| 2287 | glStencilFunc(GL_LEQUAL, value, ~GL_STENCIL_HIGH_BIT); | - | ||||||||||||||||||||||||
| 2288 | glStencilMask(0); | - | ||||||||||||||||||||||||
| 2289 | - | |||||||||||||||||||||||||
| 2290 | glColorMask(true, true, true, true); | - | ||||||||||||||||||||||||
| 2291 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2292 | - | |||||||||||||||||||||||||
| 2293 | void QGL2PaintEngineEx::clip(const QVectorPath &path, Qt::ClipOperation op) | - | ||||||||||||||||||||||||
| 2294 | { | - | ||||||||||||||||||||||||
| 2295 | // qDebug("QGL2PaintEngineEx::clip()"); | - | ||||||||||||||||||||||||
| 2296 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 2297 | - | |||||||||||||||||||||||||
| 2298 | state()->clipChanged = true; | - | ||||||||||||||||||||||||
| 2299 | - | |||||||||||||||||||||||||
| 2300 | ensureActive(); | - | ||||||||||||||||||||||||
| 2301 | - | |||||||||||||||||||||||||
| 2302 | if (op == Qt::ReplaceClip) {
| 0 | ||||||||||||||||||||||||
| 2303 | op = Qt::IntersectClip; | - | ||||||||||||||||||||||||
| 2304 | if (d->hasClipOperations()) {
| 0 | ||||||||||||||||||||||||
| 2305 | d->systemStateChanged(); | - | ||||||||||||||||||||||||
| 2306 | state()->canRestoreClip = false; | - | ||||||||||||||||||||||||
| 2307 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2308 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2309 | - | |||||||||||||||||||||||||
| 2310 | #ifndef QT_GL_NO_SCISSOR_TEST | - | ||||||||||||||||||||||||
| 2311 | if (!path.isEmpty() && op == Qt::IntersectClip && (path.shape() == QVectorPath::RectangleHint)) {
| 0 | ||||||||||||||||||||||||
| 2312 | const QPointF* const points = reinterpret_cast<const QPointF*>(path.points()); | - | ||||||||||||||||||||||||
| 2313 | QRectF rect(points[0], points[2]); | - | ||||||||||||||||||||||||
| 2314 | - | |||||||||||||||||||||||||
| 2315 | if (state()->matrix.type() <= QTransform::TxScale
| 0 | ||||||||||||||||||||||||
| 2316 | || (state()->matrix.type() == QTransform::TxRotate
| 0 | ||||||||||||||||||||||||
| 2317 | && qFuzzyIsNull(state()->matrix.m11())
| 0 | ||||||||||||||||||||||||
| 2318 | && qFuzzyIsNull(state()->matrix.m22())))
| 0 | ||||||||||||||||||||||||
| 2319 | { | - | ||||||||||||||||||||||||
| 2320 | state()->rectangleClip = state()->rectangleClip.intersected(state()->matrix.mapRect(rect).toRect()); | - | ||||||||||||||||||||||||
| 2321 | d->updateClipScissorTest(); | - | ||||||||||||||||||||||||
| 2322 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2323 | } | - | ||||||||||||||||||||||||
| 2324 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2325 | #endif | - | ||||||||||||||||||||||||
| 2326 | - | |||||||||||||||||||||||||
| 2327 | const QRect pathRect = state()->matrix.mapRect(path.controlPointRect()).toAlignedRect(); | - | ||||||||||||||||||||||||
| 2328 | - | |||||||||||||||||||||||||
| 2329 | switch (op) { | - | ||||||||||||||||||||||||
| 2330 | case Qt::NoClip: never executed: case Qt::NoClip: | 0 | ||||||||||||||||||||||||
| 2331 | if (d->useSystemClip) {
| 0 | ||||||||||||||||||||||||
| 2332 | state()->clipTestEnabled = true; | - | ||||||||||||||||||||||||
| 2333 | state()->currentClip = 1; | - | ||||||||||||||||||||||||
| 2334 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2335 | state()->clipTestEnabled = false; | - | ||||||||||||||||||||||||
| 2336 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2337 | state()->rectangleClip = QRect(0, 0, d->width, d->height); | - | ||||||||||||||||||||||||
| 2338 | state()->canRestoreClip = false; | - | ||||||||||||||||||||||||
| 2339 | d->updateClipScissorTest(); | - | ||||||||||||||||||||||||
| 2340 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2341 | case Qt::IntersectClip: never executed: case Qt::IntersectClip: | 0 | ||||||||||||||||||||||||
| 2342 | state()->rectangleClip = state()->rectangleClip.intersected(pathRect); | - | ||||||||||||||||||||||||
| 2343 | d->updateClipScissorTest(); | - | ||||||||||||||||||||||||
| 2344 | d->resetClipIfNeeded(); | - | ||||||||||||||||||||||||
| 2345 | ++d->maxClip; | - | ||||||||||||||||||||||||
| 2346 | d->writeClip(path, d->maxClip); | - | ||||||||||||||||||||||||
| 2347 | state()->currentClip = d->maxClip; | - | ||||||||||||||||||||||||
| 2348 | state()->clipTestEnabled = true; | - | ||||||||||||||||||||||||
| 2349 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2350 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 2351 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2352 | } | - | ||||||||||||||||||||||||
| 2353 | } | - | ||||||||||||||||||||||||
| 2354 | - | |||||||||||||||||||||||||
| 2355 | void QGL2PaintEngineExPrivate::regenerateClip() | - | ||||||||||||||||||||||||
| 2356 | { | - | ||||||||||||||||||||||||
| 2357 | systemStateChanged(); | - | ||||||||||||||||||||||||
| 2358 | replayClipOperations(); | - | ||||||||||||||||||||||||
| 2359 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2360 | - | |||||||||||||||||||||||||
| 2361 | void QGL2PaintEngineExPrivate::systemStateChanged() | - | ||||||||||||||||||||||||
| 2362 | { | - | ||||||||||||||||||||||||
| 2363 | Q_Q(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 2364 | - | |||||||||||||||||||||||||
| 2365 | q->state()->clipChanged = true; | - | ||||||||||||||||||||||||
| 2366 | - | |||||||||||||||||||||||||
| 2367 | if (systemClip.isEmpty()) {
| 0-2 | ||||||||||||||||||||||||
| 2368 | useSystemClip = false; | - | ||||||||||||||||||||||||
| 2369 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2370 | if (q->paintDevice()->devType() == QInternal::Widget && currentClipDevice) {
| 0-2 | ||||||||||||||||||||||||
| 2371 | QWidgetPrivate *widgetPrivate = qt_widget_private(static_cast<QWidget *>(currentClipDevice)->window()); | - | ||||||||||||||||||||||||
| 2372 | useSystemClip = widgetPrivate->extra && widgetPrivate->extra->inRenderWithPainter;
| 0 | ||||||||||||||||||||||||
| 2373 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2374 | useSystemClip = true; | - | ||||||||||||||||||||||||
| 2375 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2376 | } | - | ||||||||||||||||||||||||
| 2377 | - | |||||||||||||||||||||||||
| 2378 | q->state()->clipTestEnabled = false; | - | ||||||||||||||||||||||||
| 2379 | q->state()->needsClipBufferClear = true; | - | ||||||||||||||||||||||||
| 2380 | - | |||||||||||||||||||||||||
| 2381 | q->state()->currentClip = 1; | - | ||||||||||||||||||||||||
| 2382 | maxClip = 1; | - | ||||||||||||||||||||||||
| 2383 | - | |||||||||||||||||||||||||
| 2384 | q->state()->rectangleClip = useSystemClip ? systemClip.boundingRect() : QRect(0, 0, width, height);
| 0-2 | ||||||||||||||||||||||||
| 2385 | updateClipScissorTest(); | - | ||||||||||||||||||||||||
| 2386 | - | |||||||||||||||||||||||||
| 2387 | if (systemClip.rectCount() == 1) {
| 0-2 | ||||||||||||||||||||||||
| 2388 | if (systemClip.boundingRect() == QRect(0, 0, width, height))
| 0 | ||||||||||||||||||||||||
| 2389 | useSystemClip = false; never executed: useSystemClip = false; | 0 | ||||||||||||||||||||||||
| 2390 | #ifndef QT_GL_NO_SCISSOR_TEST | - | ||||||||||||||||||||||||
| 2391 | // scissoring takes care of the system clip | - | ||||||||||||||||||||||||
| 2392 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 2393 | #endif | - | ||||||||||||||||||||||||
| 2394 | } | - | ||||||||||||||||||||||||
| 2395 | - | |||||||||||||||||||||||||
| 2396 | if (useSystemClip) {
| 0-2 | ||||||||||||||||||||||||
| 2397 | clearClip(0); | - | ||||||||||||||||||||||||
| 2398 | - | |||||||||||||||||||||||||
| 2399 | QPainterPath path; | - | ||||||||||||||||||||||||
| 2400 | path.addRegion(systemClip); | - | ||||||||||||||||||||||||
| 2401 | - | |||||||||||||||||||||||||
| 2402 | q->state()->currentClip = 0; | - | ||||||||||||||||||||||||
| 2403 | writeClip(qtVectorPathForPath(q->state()->matrix.inverted().map(path)), 1); | - | ||||||||||||||||||||||||
| 2404 | q->state()->currentClip = 1; | - | ||||||||||||||||||||||||
| 2405 | q->state()->clipTestEnabled = true; | - | ||||||||||||||||||||||||
| 2406 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2407 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2408 | - | |||||||||||||||||||||||||
| 2409 | void QGL2PaintEngineEx::setTranslateZ(GLfloat z) | - | ||||||||||||||||||||||||
| 2410 | { | - | ||||||||||||||||||||||||
| 2411 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 2412 | if (d->translateZ != z) {
| 0 | ||||||||||||||||||||||||
| 2413 | d->translateZ = z; | - | ||||||||||||||||||||||||
| 2414 | d->translateZUniformDirty = true; | - | ||||||||||||||||||||||||
| 2415 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2416 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2417 | - | |||||||||||||||||||||||||
| 2418 | void QGL2PaintEngineEx::setState(QPainterState *new_state) | - | ||||||||||||||||||||||||
| 2419 | { | - | ||||||||||||||||||||||||
| 2420 | // qDebug("QGL2PaintEngineEx::setState()"); | - | ||||||||||||||||||||||||
| 2421 | - | |||||||||||||||||||||||||
| 2422 | Q_D(QGL2PaintEngineEx); | - | ||||||||||||||||||||||||
| 2423 | - | |||||||||||||||||||||||||
| 2424 | QGL2PaintEngineState *s = static_cast<QGL2PaintEngineState *>(new_state); | - | ||||||||||||||||||||||||
| 2425 | QGL2PaintEngineState *old_state = state(); | - | ||||||||||||||||||||||||
| 2426 | - | |||||||||||||||||||||||||
| 2427 | QPaintEngineEx::setState(s); | - | ||||||||||||||||||||||||
| 2428 | - | |||||||||||||||||||||||||
| 2429 | if (s->isNew) {
| 2 | ||||||||||||||||||||||||
| 2430 | // Newly created state object. The call to setState() | - | ||||||||||||||||||||||||
| 2431 | // will either be followed by a call to begin(), or we are | - | ||||||||||||||||||||||||
| 2432 | // setting the state as part of a save(). | - | ||||||||||||||||||||||||
| 2433 | s->isNew = false; | - | ||||||||||||||||||||||||
| 2434 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||||||||
| 2435 | } | - | ||||||||||||||||||||||||
| 2436 | - | |||||||||||||||||||||||||
| 2437 | // Setting the state as part of a restore(). | - | ||||||||||||||||||||||||
| 2438 | - | |||||||||||||||||||||||||
| 2439 | if (old_state == s || old_state->renderHintsChanged)
| 0-2 | ||||||||||||||||||||||||
| 2440 | renderHintsChanged(); executed 2 times by 1 test: renderHintsChanged();Executed by:
| 2 | ||||||||||||||||||||||||
| 2441 | - | |||||||||||||||||||||||||
| 2442 | if (old_state == s || old_state->matrixChanged)
| 0-2 | ||||||||||||||||||||||||
| 2443 | d->matrixDirty = true; executed 2 times by 1 test: d->matrixDirty = true;Executed by:
| 2 | ||||||||||||||||||||||||
| 2444 | - | |||||||||||||||||||||||||
| 2445 | if (old_state == s || old_state->compositionModeChanged)
| 0-2 | ||||||||||||||||||||||||
| 2446 | d->compositionModeDirty = true; executed 2 times by 1 test: d->compositionModeDirty = true;Executed by:
| 2 | ||||||||||||||||||||||||
| 2447 | - | |||||||||||||||||||||||||
| 2448 | if (old_state == s || old_state->opacityChanged)
| 0-2 | ||||||||||||||||||||||||
| 2449 | d->opacityUniformDirty = true; executed 2 times by 1 test: d->opacityUniformDirty = true;Executed by:
| 2 | ||||||||||||||||||||||||
| 2450 | - | |||||||||||||||||||||||||
| 2451 | if (old_state == s || old_state->clipChanged) {
| 0-2 | ||||||||||||||||||||||||
| 2452 | if (old_state && old_state != s && old_state->canRestoreClip) {
| 0-2 | ||||||||||||||||||||||||
| 2453 | d->updateClipScissorTest(); | - | ||||||||||||||||||||||||
| 2454 | d->glDepthFunc(GL_LEQUAL); | - | ||||||||||||||||||||||||
| 2455 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2456 | d->regenerateClip(); | - | ||||||||||||||||||||||||
| 2457 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2458 | } | - | ||||||||||||||||||||||||
| 2459 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2460 | - | |||||||||||||||||||||||||
| 2461 | QPainterState *QGL2PaintEngineEx::createState(QPainterState *orig) const | - | ||||||||||||||||||||||||
| 2462 | { | - | ||||||||||||||||||||||||
| 2463 | if (orig)
| 0-2 | ||||||||||||||||||||||||
| 2464 | const_cast<QGL2PaintEngineEx *>(this)->ensureActive(); never executed: const_cast<QGL2PaintEngineEx *>(this)->ensureActive(); | 0 | ||||||||||||||||||||||||
| 2465 | - | |||||||||||||||||||||||||
| 2466 | QGL2PaintEngineState *s; | - | ||||||||||||||||||||||||
| 2467 | if (!orig)
| 0-2 | ||||||||||||||||||||||||
| 2468 | s = new QGL2PaintEngineState(); executed 2 times by 1 test: s = new QGL2PaintEngineState();Executed by:
| 2 | ||||||||||||||||||||||||
| 2469 | else | - | ||||||||||||||||||||||||
| 2470 | s = new QGL2PaintEngineState(*static_cast<QGL2PaintEngineState *>(orig)); never executed: s = new QGL2PaintEngineState(*static_cast<QGL2PaintEngineState *>(orig)); | 0 | ||||||||||||||||||||||||
| 2471 | - | |||||||||||||||||||||||||
| 2472 | s->matrixChanged = false; | - | ||||||||||||||||||||||||
| 2473 | s->compositionModeChanged = false; | - | ||||||||||||||||||||||||
| 2474 | s->opacityChanged = false; | - | ||||||||||||||||||||||||
| 2475 | s->renderHintsChanged = false; | - | ||||||||||||||||||||||||
| 2476 | s->clipChanged = false; | - | ||||||||||||||||||||||||
| 2477 | - | |||||||||||||||||||||||||
| 2478 | return s; executed 2 times by 1 test: return s;Executed by:
| 2 | ||||||||||||||||||||||||
| 2479 | } | - | ||||||||||||||||||||||||
| 2480 | - | |||||||||||||||||||||||||
| 2481 | QGL2PaintEngineState::QGL2PaintEngineState(QGL2PaintEngineState &other) | - | ||||||||||||||||||||||||
| 2482 | : QPainterState(other) | - | ||||||||||||||||||||||||
| 2483 | { | - | ||||||||||||||||||||||||
| 2484 | isNew = true; | - | ||||||||||||||||||||||||
| 2485 | needsClipBufferClear = other.needsClipBufferClear; | - | ||||||||||||||||||||||||
| 2486 | clipTestEnabled = other.clipTestEnabled; | - | ||||||||||||||||||||||||
| 2487 | currentClip = other.currentClip; | - | ||||||||||||||||||||||||
| 2488 | canRestoreClip = other.canRestoreClip; | - | ||||||||||||||||||||||||
| 2489 | rectangleClip = other.rectangleClip; | - | ||||||||||||||||||||||||
| 2490 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2491 | - | |||||||||||||||||||||||||
| 2492 | QGL2PaintEngineState::QGL2PaintEngineState() | - | ||||||||||||||||||||||||
| 2493 | { | - | ||||||||||||||||||||||||
| 2494 | isNew = true; | - | ||||||||||||||||||||||||
| 2495 | needsClipBufferClear = true; | - | ||||||||||||||||||||||||
| 2496 | clipTestEnabled = false; | - | ||||||||||||||||||||||||
| 2497 | canRestoreClip = true; | - | ||||||||||||||||||||||||
| 2498 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 2499 | - | |||||||||||||||||||||||||
| 2500 | QGL2PaintEngineState::~QGL2PaintEngineState() | - | ||||||||||||||||||||||||
| 2501 | { | - | ||||||||||||||||||||||||
| 2502 | } | - | ||||||||||||||||||||||||
| 2503 | - | |||||||||||||||||||||||||
| 2504 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |