| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | QBasicAtomicInt qopengltextureglyphcache_serial_number = { (1) }; | - |
| 6 | | - |
| 7 | QOpenGLTextureGlyphCache::QOpenGLTextureGlyphCache(QFontEngineGlyphCache::Type type, const QTransform &matrix) | - |
| 8 | : QImageTextureGlyphCache(type, matrix) | - |
| 9 | , m_textureResource(0) | - |
| 10 | , pex(0) | - |
| 11 | , m_blitProgram(0) | - |
| 12 | , m_filterMode(Nearest) | - |
| 13 | , m_serialNumber(qopengltextureglyphcache_serial_number.fetchAndAddRelaxed(1)) | - |
| 14 | { | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | m_vertexCoordinateArray[0] = -1.0f; | - |
| 19 | m_vertexCoordinateArray[1] = -1.0f; | - |
| 20 | m_vertexCoordinateArray[2] = 1.0f; | - |
| 21 | m_vertexCoordinateArray[3] = -1.0f; | - |
| 22 | m_vertexCoordinateArray[4] = 1.0f; | - |
| 23 | m_vertexCoordinateArray[5] = 1.0f; | - |
| 24 | m_vertexCoordinateArray[6] = -1.0f; | - |
| 25 | m_vertexCoordinateArray[7] = 1.0f; | - |
| 26 | | - |
| 27 | m_textureCoordinateArray[0] = 0.0f; | - |
| 28 | m_textureCoordinateArray[1] = 0.0f; | - |
| 29 | m_textureCoordinateArray[2] = 1.0f; | - |
| 30 | m_textureCoordinateArray[3] = 0.0f; | - |
| 31 | m_textureCoordinateArray[4] = 1.0f; | - |
| 32 | m_textureCoordinateArray[5] = 1.0f; | - |
| 33 | m_textureCoordinateArray[6] = 0.0f; | - |
| 34 | m_textureCoordinateArray[7] = 1.0f; | - |
| 35 | } | 0 |
| 36 | | - |
| 37 | QOpenGLTextureGlyphCache::~QOpenGLTextureGlyphCache() | - |
| 38 | { | - |
| 39 | | - |
| 40 | | - |
| 41 | | - |
| 42 | } | - |
| 43 | | - |
| 44 | void QOpenGLTextureGlyphCache::createTextureData(int width, int height) | - |
| 45 | { | - |
| 46 | QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext()); | - |
| 47 | if (ctx == 0) { never evaluated: ctx == 0 | 0 |
| 48 | QMessageLogger("opengl/qopengltextureglyphcache.cpp", 93, __PRETTY_FUNCTION__).warning("QOpenGLTextureGlyphCache::createTextureData: Called with no context"); | - |
| 49 | return; | 0 |
| 50 | } | - |
| 51 | | - |
| 52 | | - |
| 53 | | - |
| 54 | | - |
| 55 | if (ctx->d_func()->workaround_brokenFBOReadBack && image().isNull()) never evaluated: ctx->d_func()->workaround_brokenFBOReadBack never evaluated: image().isNull() | 0 |
| 56 | QImageTextureGlyphCache::createTextureData(width, height); never executed: QImageTextureGlyphCache::createTextureData(width, height); | 0 |
| 57 | | - |
| 58 | | - |
| 59 | if (width < 16) never evaluated: width < 16 | 0 |
| 60 | width = 16; never executed: width = 16; | 0 |
| 61 | if (height < 16) never evaluated: height < 16 | 0 |
| 62 | height = 16; never executed: height = 16; | 0 |
| 63 | | - |
| 64 | if (m_textureResource && !m_textureResource->m_texture) { never evaluated: m_textureResource never evaluated: !m_textureResource->m_texture | 0 |
| 65 | delete m_textureResource; | - |
| 66 | m_textureResource = 0; | - |
| 67 | } | 0 |
| 68 | | - |
| 69 | if (!m_textureResource) never evaluated: !m_textureResource | 0 |
| 70 | m_textureResource = new QOpenGLGlyphTexture(ctx); never executed: m_textureResource = new QOpenGLGlyphTexture(ctx); | 0 |
| 71 | | - |
| 72 | glGenTextures(1, &m_textureResource->m_texture); | - |
| 73 | glBindTexture(0x0DE1, m_textureResource->m_texture); | - |
| 74 | | - |
| 75 | m_textureResource->m_width = width; | - |
| 76 | m_textureResource->m_height = height; | - |
| 77 | | - |
| 78 | if (m_type == QFontEngineGlyphCache::Raster_RGBMask) { never evaluated: m_type == QFontEngineGlyphCache::Raster_RGBMask | 0 |
| 79 | QVarLengthArray<uchar> data(width * height * 4); | - |
| 80 | for (int i = 0; i < data.size(); ++i) never evaluated: i < data.size() | 0 |
| 81 | data[i] = 0; never executed: data[i] = 0; | 0 |
| 82 | glTexImage2D(0x0DE1, 0, 0x1908, width, height, 0, 0x1908, 0x1401, &data[0]); | - |
| 83 | } else { | 0 |
| 84 | QVarLengthArray<uchar> data(width * height); | - |
| 85 | for (int i = 0; i < data.size(); ++i) never evaluated: i < data.size() | 0 |
| 86 | data[i] = 0; never executed: data[i] = 0; | 0 |
| 87 | glTexImage2D(0x0DE1, 0, 0x1906, width, height, 0, 0x1906, 0x1401, &data[0]); | - |
| 88 | } | 0 |
| 89 | | - |
| 90 | glTexParameteri(0x0DE1, 0x2800, 0x2600); | - |
| 91 | glTexParameteri(0x0DE1, 0x2801, 0x2600); | - |
| 92 | glTexParameteri(0x0DE1, 0x2802, 0x812F); | - |
| 93 | glTexParameteri(0x0DE1, 0x2803, 0x812F); | - |
| 94 | m_filterMode = Nearest; | - |
| 95 | } | 0 |
| 96 | | - |
| 97 | void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height) | - |
| 98 | { | - |
| 99 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - |
| 100 | if (ctx == 0) { never evaluated: ctx == 0 | 0 |
| 101 | QMessageLogger("opengl/qopengltextureglyphcache.cpp", 146, __PRETTY_FUNCTION__).warning("QOpenGLTextureGlyphCache::resizeTextureData: Called with no context"); | - |
| 102 | return; | 0 |
| 103 | } | - |
| 104 | | - |
| 105 | int oldWidth = m_textureResource->m_width; | - |
| 106 | int oldHeight = m_textureResource->m_height; | - |
| 107 | | - |
| 108 | | - |
| 109 | if (width < 16) never evaluated: width < 16 | 0 |
| 110 | width = 16; never executed: width = 16; | 0 |
| 111 | if (height < 16) never evaluated: height < 16 | 0 |
| 112 | height = 16; never executed: height = 16; | 0 |
| 113 | | - |
| 114 | GLuint oldTexture = m_textureResource->m_texture; | - |
| 115 | createTextureData(width, height); | - |
| 116 | | - |
| 117 | if (ctx->d_func()->workaround_brokenFBOReadBack) { never evaluated: ctx->d_func()->workaround_brokenFBOReadBack | 0 |
| 118 | QImageTextureGlyphCache::resizeTextureData(width, height); | - |
| 119 | qt_noop(); | - |
| 120 | glTexSubImage2D(0x0DE1, 0, 0, 0, width, oldHeight, 0x1906, 0x1401, image().constBits()); | - |
| 121 | glDeleteTextures(1, &oldTexture); | - |
| 122 | return; | 0 |
| 123 | } | - |
| 124 | | - |
| 125 | | - |
| 126 | | - |
| 127 | | - |
| 128 | QOpenGLFunctions funcs(ctx); | - |
| 129 | | - |
| 130 | funcs.glBindFramebuffer(0x8D40, m_textureResource->m_fbo); | - |
| 131 | | - |
| 132 | GLuint tmp_texture; | - |
| 133 | glGenTextures(1, &tmp_texture); | - |
| 134 | glBindTexture(0x0DE1, tmp_texture); | - |
| 135 | glTexImage2D(0x0DE1, 0, 0x1908, oldWidth, oldHeight, 0, | - |
| 136 | 0x1908, 0x1401, __null); | - |
| 137 | glTexParameteri(0x0DE1, 0x2801, 0x2600); | - |
| 138 | glTexParameteri(0x0DE1, 0x2800, 0x2600); | - |
| 139 | glTexParameteri(0x0DE1, 0x2802, 0x812F); | - |
| 140 | glTexParameteri(0x0DE1, 0x2803, 0x812F); | - |
| 141 | m_filterMode = Nearest; | - |
| 142 | glBindTexture(0x0DE1, 0); | - |
| 143 | funcs.glFramebufferTexture2D(0x8D40, 0x8CE0, | - |
| 144 | 0x0DE1, tmp_texture, 0); | - |
| 145 | | - |
| 146 | funcs.glActiveTexture(0x84C0 + GLuint(0)); | - |
| 147 | glBindTexture(0x0DE1, oldTexture); | - |
| 148 | | - |
| 149 | if (pex != 0) never evaluated: pex != 0 | 0 |
| 150 | pex->transferMode(BrushDrawingMode); never executed: pex->transferMode(BrushDrawingMode); | 0 |
| 151 | | - |
| 152 | glDisable(0x0B90); | - |
| 153 | glDisable(0x0B71); | - |
| 154 | glDisable(0x0C11); | - |
| 155 | glDisable(0x0BE2); | - |
| 156 | | - |
| 157 | glViewport(0, 0, oldWidth, oldHeight); | - |
| 158 | | - |
| 159 | QOpenGLShaderProgram *blitProgram = 0; | - |
| 160 | if (pex == 0) { never evaluated: pex == 0 | 0 |
| 161 | if (m_blitProgram == 0) { never evaluated: m_blitProgram == 0 | 0 |
| 162 | m_blitProgram = new QOpenGLShaderProgram(ctx); | - |
| 163 | | - |
| 164 | { | - |
| 165 | QString source; | - |
| 166 | source.append(QLatin1String(qopenglslMainWithTexCoordsVertexShader)); | - |
| 167 | source.append(QLatin1String(qopenglslUntransformedPositionVertexShader)); | - |
| 168 | | - |
| 169 | QOpenGLShader *vertexShader = new QOpenGLShader(QOpenGLShader::Vertex, m_blitProgram); | - |
| 170 | vertexShader->compileSourceCode(source); | - |
| 171 | | - |
| 172 | m_blitProgram->addShader(vertexShader); | - |
| 173 | } | - |
| 174 | | - |
| 175 | { | - |
| 176 | QString source; | - |
| 177 | source.append(QLatin1String(qopenglslMainFragmentShader)); | - |
| 178 | source.append(QLatin1String(qopenglslImageSrcFragmentShader)); | - |
| 179 | | - |
| 180 | QOpenGLShader *fragmentShader = new QOpenGLShader(QOpenGLShader::Fragment, m_blitProgram); | - |
| 181 | fragmentShader->compileSourceCode(source); | - |
| 182 | | - |
| 183 | m_blitProgram->addShader(fragmentShader); | - |
| 184 | } | - |
| 185 | | - |
| 186 | m_blitProgram->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR); | - |
| 187 | m_blitProgram->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR); | - |
| 188 | | - |
| 189 | m_blitProgram->link(); | - |
| 190 | } | 0 |
| 191 | | - |
| 192 | funcs.glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, 0x1406, 0x0, 0, m_vertexCoordinateArray); | - |
| 193 | funcs.glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, 0x1406, 0x0, 0, m_textureCoordinateArray); | - |
| 194 | | - |
| 195 | m_blitProgram->bind(); | - |
| 196 | m_blitProgram->enableAttributeArray(int(QT_VERTEX_COORDS_ATTR)); | - |
| 197 | m_blitProgram->enableAttributeArray(int(QT_TEXTURE_COORDS_ATTR)); | - |
| 198 | m_blitProgram->disableAttributeArray(int(QT_OPACITY_ATTR)); | - |
| 199 | | - |
| 200 | blitProgram = m_blitProgram; | - |
| 201 | | - |
| 202 | } else { | 0 |
| 203 | pex->setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, m_vertexCoordinateArray); | - |
| 204 | pex->setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, m_textureCoordinateArray); | - |
| 205 | | - |
| 206 | pex->shaderManager->useBlitProgram(); | - |
| 207 | blitProgram = pex->shaderManager->blitProgram(); | - |
| 208 | } | 0 |
| 209 | | - |
| 210 | blitProgram->setUniformValue("imageTexture", GLuint(0)); | - |
| 211 | | - |
| 212 | glDrawArrays(0x0006, 0, 4); | - |
| 213 | | - |
| 214 | glBindTexture(0x0DE1, m_textureResource->m_texture); | - |
| 215 | | - |
| 216 | glCopyTexSubImage2D(0x0DE1, 0, 0, 0, 0, 0, oldWidth, oldHeight); | - |
| 217 | | - |
| 218 | funcs.glFramebufferRenderbuffer(0x8D40, 0x8CE0, | - |
| 219 | 0x8D41, 0); | - |
| 220 | glDeleteTextures(1, &tmp_texture); | - |
| 221 | glDeleteTextures(1, &oldTexture); | - |
| 222 | | - |
| 223 | funcs.glBindFramebuffer(0x8D40, ctx->d_func()->current_fbo); | - |
| 224 | | - |
| 225 | if (pex != 0) { never evaluated: pex != 0 | 0 |
| 226 | glViewport(0, 0, pex->width, pex->height); | - |
| 227 | pex->updateClipScissorTest(); | - |
| 228 | } else { | 0 |
| 229 | m_blitProgram->disableAttributeArray(int(QT_VERTEX_COORDS_ATTR)); | - |
| 230 | m_blitProgram->disableAttributeArray(int(QT_TEXTURE_COORDS_ATTR)); | - |
| 231 | } | 0 |
| 232 | } | - |
| 233 | | - |
| 234 | void QOpenGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, QFixed subPixelPosition) | - |
| 235 | { | - |
| 236 | QOpenGLContext *ctx = QOpenGLContext::currentContext(); | - |
| 237 | if (ctx == 0) { never evaluated: ctx == 0 | 0 |
| 238 | QMessageLogger("opengl/qopengltextureglyphcache.cpp", 283, __PRETTY_FUNCTION__).warning("QOpenGLTextureGlyphCache::fillTexture: Called with no context"); | - |
| 239 | return; | 0 |
| 240 | } | - |
| 241 | | - |
| 242 | if (ctx->d_func()->workaround_brokenFBOReadBack) { never evaluated: ctx->d_func()->workaround_brokenFBOReadBack | 0 |
| 243 | QImageTextureGlyphCache::fillTexture(c, glyph, subPixelPosition); | - |
| 244 | | - |
| 245 | glBindTexture(0x0DE1, m_textureResource->m_texture); | - |
| 246 | const QImage &texture = image(); | - |
| 247 | const uchar *bits = texture.constBits(); | - |
| 248 | bits += c.y * texture.bytesPerLine() + c.x; | - |
| 249 | for (int i=0; i<c.h; ++i) { | 0 |
| 250 | glTexSubImage2D(0x0DE1, 0, c.x, c.y + i, c.w, 1, 0x1906, 0x1401, bits); | - |
| 251 | bits += texture.bytesPerLine(); | - |
| 252 | } | 0 |
| 253 | return; | 0 |
| 254 | } | - |
| 255 | | - |
| 256 | QImage mask = textureMapForGlyph(glyph, subPixelPosition); | - |
| 257 | const int maskWidth = mask.width(); | - |
| 258 | const int maskHeight = mask.height(); | - |
| 259 | | - |
| 260 | | - |
| 261 | | - |
| 262 | | - |
| 263 | | - |
| 264 | | - |
| 265 | if (mask.format() == QImage::Format_Mono) { never evaluated: mask.format() == QImage::Format_Mono | 0 |
| 266 | mask = mask.convertToFormat(QImage::Format_Indexed8); | - |
| 267 | for (int y = 0; y < maskHeight; ++y) { never evaluated: y < maskHeight | 0 |
| 268 | uchar *src = (uchar *) mask.scanLine(y); | - |
| 269 | for (int x = 0; x < maskWidth; ++x) never evaluated: x < maskWidth | 0 |
| 270 | src[x] = -src[x]; never executed: src[x] = -src[x]; | 0 |
| 271 | } | 0 |
| 272 | } else if (mask.format() == QImage::Format_RGB32) { never evaluated: mask.format() == QImage::Format_RGB32 | 0 |
| 273 | | - |
| 274 | | - |
| 275 | for (int y = 0; y < maskHeight; ++y) { never evaluated: y < maskHeight | 0 |
| 276 | quint32 *src = (quint32 *) mask.scanLine(y); | - |
| 277 | for (int x = 0; x < maskWidth; ++x) { never evaluated: x < maskWidth | 0 |
| 278 | uchar r = src[x] >> 16; | - |
| 279 | uchar g = src[x] >> 8; | - |
| 280 | uchar b = src[x]; | - |
| 281 | quint32 avg = (quint32(r) + quint32(g) + quint32(b) + 1) / 3; | - |
| 282 | | - |
| 283 | | - |
| 284 | | - |
| 285 | | - |
| 286 | | - |
| 287 | | - |
| 288 | | - |
| 289 | src[x] = (src[x] & 0x00ffffff) | (avg << 24); | - |
| 290 | } | 0 |
| 291 | } | 0 |
| 292 | } | 0 |
| 293 | | - |
| 294 | glBindTexture(0x0DE1, m_textureResource->m_texture); | - |
| 295 | if (mask.format() == QImage::Format_RGB32) { never evaluated: mask.format() == QImage::Format_RGB32 | 0 |
| 296 | | - |
| 297 | | - |
| 298 | | - |
| 299 | glTexSubImage2D(0x0DE1, 0, c.x, c.y, maskWidth, maskHeight, 0x80E1, 0x1401, mask.bits()); | - |
| 300 | | - |
| 301 | } else { | 0 |
| 302 | glTexSubImage2D(0x0DE1, 0, c.x, c.y, maskWidth, maskHeight, 0x1906, 0x1401, mask.bits()); | - |
| 303 | | - |
| 304 | } | 0 |
| 305 | } | - |
| 306 | | - |
| 307 | int QOpenGLTextureGlyphCache::glyphPadding() const | - |
| 308 | { | - |
| 309 | return 1; never executed: return 1; | 0 |
| 310 | } | - |
| 311 | | - |
| 312 | int QOpenGLTextureGlyphCache::maxTextureWidth() const | - |
| 313 | { | - |
| 314 | QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext()); | - |
| 315 | if (ctx == 0) never evaluated: ctx == 0 | 0 |
| 316 | return QImageTextureGlyphCache::maxTextureWidth(); never executed: return QImageTextureGlyphCache::maxTextureWidth(); | 0 |
| 317 | else | - |
| 318 | return ctx->d_func()->maxTextureSize(); never executed: return ctx->d_func()->maxTextureSize(); | 0 |
| 319 | } | - |
| 320 | | - |
| 321 | int QOpenGLTextureGlyphCache::maxTextureHeight() const | - |
| 322 | { | - |
| 323 | QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext()); | - |
| 324 | if (ctx == 0) never evaluated: ctx == 0 | 0 |
| 325 | return QImageTextureGlyphCache::maxTextureHeight(); never executed: return QImageTextureGlyphCache::maxTextureHeight(); | 0 |
| 326 | | - |
| 327 | if (ctx->d_func()->workaround_brokenTexSubImage) never evaluated: ctx->d_func()->workaround_brokenTexSubImage | 0 |
| 328 | return qMin(1024, ctx->d_func()->maxTextureSize()); never executed: return qMin(1024, ctx->d_func()->maxTextureSize()); | 0 |
| 329 | else | - |
| 330 | return ctx->d_func()->maxTextureSize(); never executed: return ctx->d_func()->maxTextureSize(); | 0 |
| 331 | } | - |
| 332 | | - |
| 333 | void QOpenGLTextureGlyphCache::clear() | - |
| 334 | { | - |
| 335 | m_textureResource->free(); | - |
| 336 | m_textureResource = 0; | - |
| 337 | | - |
| 338 | m_w = 0; | - |
| 339 | m_h = 0; | - |
| 340 | m_cx = 0; | - |
| 341 | m_cy = 0; | - |
| 342 | m_currentRowHeight = 0; | - |
| 343 | coords.clear(); | - |
| 344 | } | 0 |
| 345 | | - |
| 346 | | - |
| 347 | | - |
| | |