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