opengl/qopengltextureglyphcache.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/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 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qopengltextureglyphcache_p.h" -
43#include "qopenglpaintengine_p.h" -
44#include "private/qopenglengineshadersource_p.h" -
45#include "qopenglextensions_p.h" -
46 -
47QT_BEGIN_NAMESPACE -
48 -
49 -
50QBasicAtomicInt qopengltextureglyphcache_serial_number = Q_BASIC_ATOMIC_INITIALIZER(1); -
51 -
52QOpenGLTextureGlyphCache::QOpenGLTextureGlyphCache(QFontEngineGlyphCache::Type type, const QTransform &matrix) -
53 : QImageTextureGlyphCache(type, matrix) -
54 , m_textureResource(0) -
55 , pex(0) -
56 , m_blitProgram(0) -
57 , m_filterMode(Nearest) -
58 , m_serialNumber(qopengltextureglyphcache_serial_number.fetchAndAddRelaxed(1)) -
59{ -
60#ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG -
61 qDebug(" -> QOpenGLTextureGlyphCache() %p for context %p.", this, QOpenGLContext::currentContext()); -
62#endif -
63 m_vertexCoordinateArray[0] = -1.0f;
never executed (the execution status of this line is deduced): m_vertexCoordinateArray[0] = -1.0f;
-
64 m_vertexCoordinateArray[1] = -1.0f;
never executed (the execution status of this line is deduced): m_vertexCoordinateArray[1] = -1.0f;
-
65 m_vertexCoordinateArray[2] = 1.0f;
never executed (the execution status of this line is deduced): m_vertexCoordinateArray[2] = 1.0f;
-
66 m_vertexCoordinateArray[3] = -1.0f;
never executed (the execution status of this line is deduced): m_vertexCoordinateArray[3] = -1.0f;
-
67 m_vertexCoordinateArray[4] = 1.0f;
never executed (the execution status of this line is deduced): m_vertexCoordinateArray[4] = 1.0f;
-
68 m_vertexCoordinateArray[5] = 1.0f;
never executed (the execution status of this line is deduced): m_vertexCoordinateArray[5] = 1.0f;
-
69 m_vertexCoordinateArray[6] = -1.0f;
never executed (the execution status of this line is deduced): m_vertexCoordinateArray[6] = -1.0f;
-
70 m_vertexCoordinateArray[7] = 1.0f;
never executed (the execution status of this line is deduced): m_vertexCoordinateArray[7] = 1.0f;
-
71 -
72 m_textureCoordinateArray[0] = 0.0f;
never executed (the execution status of this line is deduced): m_textureCoordinateArray[0] = 0.0f;
-
73 m_textureCoordinateArray[1] = 0.0f;
never executed (the execution status of this line is deduced): m_textureCoordinateArray[1] = 0.0f;
-
74 m_textureCoordinateArray[2] = 1.0f;
never executed (the execution status of this line is deduced): m_textureCoordinateArray[2] = 1.0f;
-
75 m_textureCoordinateArray[3] = 0.0f;
never executed (the execution status of this line is deduced): m_textureCoordinateArray[3] = 0.0f;
-
76 m_textureCoordinateArray[4] = 1.0f;
never executed (the execution status of this line is deduced): m_textureCoordinateArray[4] = 1.0f;
-
77 m_textureCoordinateArray[5] = 1.0f;
never executed (the execution status of this line is deduced): m_textureCoordinateArray[5] = 1.0f;
-
78 m_textureCoordinateArray[6] = 0.0f;
never executed (the execution status of this line is deduced): m_textureCoordinateArray[6] = 0.0f;
-
79 m_textureCoordinateArray[7] = 1.0f;
never executed (the execution status of this line is deduced): m_textureCoordinateArray[7] = 1.0f;
-
80}
never executed: }
0
81 -
82QOpenGLTextureGlyphCache::~QOpenGLTextureGlyphCache() -
83{ -
84#ifdef QT_GL_TEXTURE_GLYPH_CACHE_DEBUG -
85 qDebug(" -> ~QOpenGLTextureGlyphCache() %p.", this); -
86#endif -
87} -
88 -
89void QOpenGLTextureGlyphCache::createTextureData(int width, int height) -
90{ -
91 QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext());
never executed (the execution status of this line is deduced): QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext());
-
92 if (ctx == 0) {
never evaluated: ctx == 0
0
93 qWarning("QOpenGLTextureGlyphCache::createTextureData: Called with no context");
never executed (the execution status of this line is deduced): QMessageLogger("opengl/qopengltextureglyphcache.cpp", 93, __PRETTY_FUNCTION__).warning("QOpenGLTextureGlyphCache::createTextureData: Called with no context");
-
94 return;
never executed: return;
0
95 } -
96 -
97 // create in QImageTextureGlyphCache baseclass is meant to be called -
98 // only to create the initial image and does not preserve the content, -
99 // so we don't call when this function is called from resize. -
100 if (ctx->d_func()->workaround_brokenFBOReadBack && image().isNull())
never evaluated: ctx->d_func()->workaround_brokenFBOReadBack
never evaluated: image().isNull()
0
101 QImageTextureGlyphCache::createTextureData(width, height);
never executed: QImageTextureGlyphCache::createTextureData(width, height);
0
102 -
103 // Make the lower glyph texture size 16 x 16. -
104 if (width < 16)
never evaluated: width < 16
0
105 width = 16;
never executed: width = 16;
0
106 if (height < 16)
never evaluated: height < 16
0
107 height = 16;
never executed: height = 16;
0
108 -
109 if (m_textureResource && !m_textureResource->m_texture) {
never evaluated: m_textureResource
never evaluated: !m_textureResource->m_texture
0
110 delete m_textureResource;
never executed (the execution status of this line is deduced): delete m_textureResource;
-
111 m_textureResource = 0;
never executed (the execution status of this line is deduced): m_textureResource = 0;
-
112 }
never executed: }
0
113 -
114 if (!m_textureResource)
never evaluated: !m_textureResource
0
115 m_textureResource = new QOpenGLGlyphTexture(ctx);
never executed: m_textureResource = new QOpenGLGlyphTexture(ctx);
0
116 -
117 glGenTextures(1, &m_textureResource->m_texture);
never executed (the execution status of this line is deduced): glGenTextures(1, &m_textureResource->m_texture);
-
118 glBindTexture(GL_TEXTURE_2D, m_textureResource->m_texture);
never executed (the execution status of this line is deduced): glBindTexture(0x0DE1, m_textureResource->m_texture);
-
119 -
120 m_textureResource->m_width = width;
never executed (the execution status of this line is deduced): m_textureResource->m_width = width;
-
121 m_textureResource->m_height = height;
never executed (the execution status of this line is deduced): m_textureResource->m_height = height;
-
122 -
123 if (m_type == QFontEngineGlyphCache::Raster_RGBMask) {
never evaluated: m_type == QFontEngineGlyphCache::Raster_RGBMask
0
124 QVarLengthArray<uchar> data(width * height * 4);
never executed (the execution status of this line is deduced): QVarLengthArray<uchar> data(width * height * 4);
-
125 for (int i = 0; i < data.size(); ++i)
never evaluated: i < data.size()
0
126 data[i] = 0;
never executed: data[i] = 0;
0
127 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
never executed (the execution status of this line is deduced): glTexImage2D(0x0DE1, 0, 0x1908, width, height, 0, 0x1908, 0x1401, &data[0]);
-
128 } else {
never executed: }
0
129 QVarLengthArray<uchar> data(width * height);
never executed (the execution status of this line is deduced): QVarLengthArray<uchar> data(width * height);
-
130 for (int i = 0; i < data.size(); ++i)
never evaluated: i < data.size()
0
131 data[i] = 0;
never executed: data[i] = 0;
0
132 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, width, height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, &data[0]);
never executed (the execution status of this line is deduced): glTexImage2D(0x0DE1, 0, 0x1906, width, height, 0, 0x1906, 0x1401, &data[0]);
-
133 }
never executed: }
0
134 -
135 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
never executed (the execution status of this line is deduced): glTexParameteri(0x0DE1, 0x2800, 0x2600);
-
136 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
never executed (the execution status of this line is deduced): glTexParameteri(0x0DE1, 0x2801, 0x2600);
-
137 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
never executed (the execution status of this line is deduced): glTexParameteri(0x0DE1, 0x2802, 0x812F);
-
138 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
never executed (the execution status of this line is deduced): glTexParameteri(0x0DE1, 0x2803, 0x812F);
-
139 m_filterMode = Nearest;
never executed (the execution status of this line is deduced): m_filterMode = Nearest;
-
140}
never executed: }
0
141 -
142void QOpenGLTextureGlyphCache::resizeTextureData(int width, int height) -
143{ -
144 QOpenGLContext *ctx = QOpenGLContext::currentContext();
never executed (the execution status of this line is deduced): QOpenGLContext *ctx = QOpenGLContext::currentContext();
-
145 if (ctx == 0) {
never evaluated: ctx == 0
0
146 qWarning("QOpenGLTextureGlyphCache::resizeTextureData: Called with no context");
never executed (the execution status of this line is deduced): QMessageLogger("opengl/qopengltextureglyphcache.cpp", 146, __PRETTY_FUNCTION__).warning("QOpenGLTextureGlyphCache::resizeTextureData: Called with no context");
-
147 return;
never executed: return;
0
148 } -
149 -
150 int oldWidth = m_textureResource->m_width;
never executed (the execution status of this line is deduced): int oldWidth = m_textureResource->m_width;
-
151 int oldHeight = m_textureResource->m_height;
never executed (the execution status of this line is deduced): int oldHeight = m_textureResource->m_height;
-
152 -
153 // Make the lower glyph texture size 16 x 16. -
154 if (width < 16)
never evaluated: width < 16
0
155 width = 16;
never executed: width = 16;
0
156 if (height < 16)
never evaluated: height < 16
0
157 height = 16;
never executed: height = 16;
0
158 -
159 GLuint oldTexture = m_textureResource->m_texture;
never executed (the execution status of this line is deduced): GLuint oldTexture = m_textureResource->m_texture;
-
160 createTextureData(width, height);
never executed (the execution status of this line is deduced): createTextureData(width, height);
-
161 -
162 if (ctx->d_func()->workaround_brokenFBOReadBack) {
never evaluated: ctx->d_func()->workaround_brokenFBOReadBack
0
163 QImageTextureGlyphCache::resizeTextureData(width, height);
never executed (the execution status of this line is deduced): QImageTextureGlyphCache::resizeTextureData(width, height);
-
164 Q_ASSERT(image().depth() == 8);
never executed (the execution status of this line is deduced): qt_noop();
-
165 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, oldHeight, GL_ALPHA, GL_UNSIGNED_BYTE, image().constBits());
never executed (the execution status of this line is deduced): glTexSubImage2D(0x0DE1, 0, 0, 0, width, oldHeight, 0x1906, 0x1401, image().constBits());
-
166 glDeleteTextures(1, &oldTexture);
never executed (the execution status of this line is deduced): glDeleteTextures(1, &oldTexture);
-
167 return;
never executed: return;
0
168 } -
169 -
170 // ### the QTextureGlyphCache API needs to be reworked to allow -
171 // ### resizeTextureData to fail -
172 -
173 QOpenGLFunctions funcs(ctx);
never executed (the execution status of this line is deduced): QOpenGLFunctions funcs(ctx);
-
174 -
175 funcs.glBindFramebuffer(GL_FRAMEBUFFER, m_textureResource->m_fbo);
never executed (the execution status of this line is deduced): funcs.glBindFramebuffer(0x8D40, m_textureResource->m_fbo);
-
176 -
177 GLuint tmp_texture;
never executed (the execution status of this line is deduced): GLuint tmp_texture;
-
178 glGenTextures(1, &tmp_texture);
never executed (the execution status of this line is deduced): glGenTextures(1, &tmp_texture);
-
179 glBindTexture(GL_TEXTURE_2D, tmp_texture);
never executed (the execution status of this line is deduced): glBindTexture(0x0DE1, tmp_texture);
-
180 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, oldWidth, oldHeight, 0,
never executed (the execution status of this line is deduced): glTexImage2D(0x0DE1, 0, 0x1908, oldWidth, oldHeight, 0,
-
181 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
never executed (the execution status of this line is deduced): 0x1908, 0x1401, __null);
-
182 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
never executed (the execution status of this line is deduced): glTexParameteri(0x0DE1, 0x2801, 0x2600);
-
183 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
never executed (the execution status of this line is deduced): glTexParameteri(0x0DE1, 0x2800, 0x2600);
-
184 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
never executed (the execution status of this line is deduced): glTexParameteri(0x0DE1, 0x2802, 0x812F);
-
185 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
never executed (the execution status of this line is deduced): glTexParameteri(0x0DE1, 0x2803, 0x812F);
-
186 m_filterMode = Nearest;
never executed (the execution status of this line is deduced): m_filterMode = Nearest;
-
187 glBindTexture(GL_TEXTURE_2D, 0);
never executed (the execution status of this line is deduced): glBindTexture(0x0DE1, 0);
-
188 funcs.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
never executed (the execution status of this line is deduced): funcs.glFramebufferTexture2D(0x8D40, 0x8CE0,
-
189 GL_TEXTURE_2D, tmp_texture, 0);
never executed (the execution status of this line is deduced): 0x0DE1, tmp_texture, 0);
-
190 -
191 funcs.glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT);
never executed (the execution status of this line is deduced): funcs.glActiveTexture(0x84C0 + GLuint(0));
-
192 glBindTexture(GL_TEXTURE_2D, oldTexture);
never executed (the execution status of this line is deduced): glBindTexture(0x0DE1, oldTexture);
-
193 -
194 if (pex != 0)
never evaluated: pex != 0
0
195 pex->transferMode(BrushDrawingMode);
never executed: pex->transferMode(BrushDrawingMode);
0
196 -
197 glDisable(GL_STENCIL_TEST);
never executed (the execution status of this line is deduced): glDisable(0x0B90);
-
198 glDisable(GL_DEPTH_TEST);
never executed (the execution status of this line is deduced): glDisable(0x0B71);
-
199 glDisable(GL_SCISSOR_TEST);
never executed (the execution status of this line is deduced): glDisable(0x0C11);
-
200 glDisable(GL_BLEND);
never executed (the execution status of this line is deduced): glDisable(0x0BE2);
-
201 -
202 glViewport(0, 0, oldWidth, oldHeight);
never executed (the execution status of this line is deduced): glViewport(0, 0, oldWidth, oldHeight);
-
203 -
204 QOpenGLShaderProgram *blitProgram = 0;
never executed (the execution status of this line is deduced): QOpenGLShaderProgram *blitProgram = 0;
-
205 if (pex == 0) {
never evaluated: pex == 0
0
206 if (m_blitProgram == 0) {
never evaluated: m_blitProgram == 0
0
207 m_blitProgram = new QOpenGLShaderProgram(ctx);
never executed (the execution status of this line is deduced): m_blitProgram = new QOpenGLShaderProgram(ctx);
-
208 -
209 { -
210 QString source;
never executed (the execution status of this line is deduced): QString source;
-
211 source.append(QLatin1String(qopenglslMainWithTexCoordsVertexShader));
never executed (the execution status of this line is deduced): source.append(QLatin1String(qopenglslMainWithTexCoordsVertexShader));
-
212 source.append(QLatin1String(qopenglslUntransformedPositionVertexShader));
never executed (the execution status of this line is deduced): source.append(QLatin1String(qopenglslUntransformedPositionVertexShader));
-
213 -
214 QOpenGLShader *vertexShader = new QOpenGLShader(QOpenGLShader::Vertex, m_blitProgram);
never executed (the execution status of this line is deduced): QOpenGLShader *vertexShader = new QOpenGLShader(QOpenGLShader::Vertex, m_blitProgram);
-
215 vertexShader->compileSourceCode(source);
never executed (the execution status of this line is deduced): vertexShader->compileSourceCode(source);
-
216 -
217 m_blitProgram->addShader(vertexShader);
never executed (the execution status of this line is deduced): m_blitProgram->addShader(vertexShader);
-
218 } -
219 -
220 { -
221 QString source;
never executed (the execution status of this line is deduced): QString source;
-
222 source.append(QLatin1String(qopenglslMainFragmentShader));
never executed (the execution status of this line is deduced): source.append(QLatin1String(qopenglslMainFragmentShader));
-
223 source.append(QLatin1String(qopenglslImageSrcFragmentShader));
never executed (the execution status of this line is deduced): source.append(QLatin1String(qopenglslImageSrcFragmentShader));
-
224 -
225 QOpenGLShader *fragmentShader = new QOpenGLShader(QOpenGLShader::Fragment, m_blitProgram);
never executed (the execution status of this line is deduced): QOpenGLShader *fragmentShader = new QOpenGLShader(QOpenGLShader::Fragment, m_blitProgram);
-
226 fragmentShader->compileSourceCode(source);
never executed (the execution status of this line is deduced): fragmentShader->compileSourceCode(source);
-
227 -
228 m_blitProgram->addShader(fragmentShader);
never executed (the execution status of this line is deduced): m_blitProgram->addShader(fragmentShader);
-
229 } -
230 -
231 m_blitProgram->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
never executed (the execution status of this line is deduced): m_blitProgram->bindAttributeLocation("vertexCoordsArray", QT_VERTEX_COORDS_ATTR);
-
232 m_blitProgram->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR);
never executed (the execution status of this line is deduced): m_blitProgram->bindAttributeLocation("textureCoordArray", QT_TEXTURE_COORDS_ATTR);
-
233 -
234 m_blitProgram->link();
never executed (the execution status of this line is deduced): m_blitProgram->link();
-
235 }
never executed: }
0
236 -
237 funcs.glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, m_vertexCoordinateArray);
never executed (the execution status of this line is deduced): funcs.glVertexAttribPointer(QT_VERTEX_COORDS_ATTR, 2, 0x1406, 0x0, 0, m_vertexCoordinateArray);
-
238 funcs.glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, GL_FLOAT, GL_FALSE, 0, m_textureCoordinateArray);
never executed (the execution status of this line is deduced): funcs.glVertexAttribPointer(QT_TEXTURE_COORDS_ATTR, 2, 0x1406, 0x0, 0, m_textureCoordinateArray);
-
239 -
240 m_blitProgram->bind();
never executed (the execution status of this line is deduced): m_blitProgram->bind();
-
241 m_blitProgram->enableAttributeArray(int(QT_VERTEX_COORDS_ATTR));
never executed (the execution status of this line is deduced): m_blitProgram->enableAttributeArray(int(QT_VERTEX_COORDS_ATTR));
-
242 m_blitProgram->enableAttributeArray(int(QT_TEXTURE_COORDS_ATTR));
never executed (the execution status of this line is deduced): m_blitProgram->enableAttributeArray(int(QT_TEXTURE_COORDS_ATTR));
-
243 m_blitProgram->disableAttributeArray(int(QT_OPACITY_ATTR));
never executed (the execution status of this line is deduced): m_blitProgram->disableAttributeArray(int(QT_OPACITY_ATTR));
-
244 -
245 blitProgram = m_blitProgram;
never executed (the execution status of this line is deduced): blitProgram = m_blitProgram;
-
246 -
247 } else {
never executed: }
0
248 pex->setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, m_vertexCoordinateArray);
never executed (the execution status of this line is deduced): pex->setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, m_vertexCoordinateArray);
-
249 pex->setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, m_textureCoordinateArray);
never executed (the execution status of this line is deduced): pex->setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, m_textureCoordinateArray);
-
250 -
251 pex->shaderManager->useBlitProgram();
never executed (the execution status of this line is deduced): pex->shaderManager->useBlitProgram();
-
252 blitProgram = pex->shaderManager->blitProgram();
never executed (the execution status of this line is deduced): blitProgram = pex->shaderManager->blitProgram();
-
253 }
never executed: }
0
254 -
255 blitProgram->setUniformValue("imageTexture", QT_IMAGE_TEXTURE_UNIT);
never executed (the execution status of this line is deduced): blitProgram->setUniformValue("imageTexture", GLuint(0));
-
256 -
257 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
never executed (the execution status of this line is deduced): glDrawArrays(0x0006, 0, 4);
-
258 -
259 glBindTexture(GL_TEXTURE_2D, m_textureResource->m_texture);
never executed (the execution status of this line is deduced): glBindTexture(0x0DE1, m_textureResource->m_texture);
-
260 -
261 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, oldWidth, oldHeight);
never executed (the execution status of this line is deduced): glCopyTexSubImage2D(0x0DE1, 0, 0, 0, 0, 0, oldWidth, oldHeight);
-
262 -
263 funcs.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
never executed (the execution status of this line is deduced): funcs.glFramebufferRenderbuffer(0x8D40, 0x8CE0,
-
264 GL_RENDERBUFFER, 0);
never executed (the execution status of this line is deduced): 0x8D41, 0);
-
265 glDeleteTextures(1, &tmp_texture);
never executed (the execution status of this line is deduced): glDeleteTextures(1, &tmp_texture);
-
266 glDeleteTextures(1, &oldTexture);
never executed (the execution status of this line is deduced): glDeleteTextures(1, &oldTexture);
-
267 -
268 funcs.glBindFramebuffer(GL_FRAMEBUFFER, ctx->d_func()->current_fbo);
never executed (the execution status of this line is deduced): funcs.glBindFramebuffer(0x8D40, ctx->d_func()->current_fbo);
-
269 -
270 if (pex != 0) {
never evaluated: pex != 0
0
271 glViewport(0, 0, pex->width, pex->height);
never executed (the execution status of this line is deduced): glViewport(0, 0, pex->width, pex->height);
-
272 pex->updateClipScissorTest();
never executed (the execution status of this line is deduced): pex->updateClipScissorTest();
-
273 } else {
never executed: }
0
274 m_blitProgram->disableAttributeArray(int(QT_VERTEX_COORDS_ATTR));
never executed (the execution status of this line is deduced): m_blitProgram->disableAttributeArray(int(QT_VERTEX_COORDS_ATTR));
-
275 m_blitProgram->disableAttributeArray(int(QT_TEXTURE_COORDS_ATTR));
never executed (the execution status of this line is deduced): m_blitProgram->disableAttributeArray(int(QT_TEXTURE_COORDS_ATTR));
-
276 }
never executed: }
0
277} -
278 -
279void QOpenGLTextureGlyphCache::fillTexture(const Coord &c, glyph_t glyph, QFixed subPixelPosition) -
280{ -
281 QOpenGLContext *ctx = QOpenGLContext::currentContext();
never executed (the execution status of this line is deduced): QOpenGLContext *ctx = QOpenGLContext::currentContext();
-
282 if (ctx == 0) {
never evaluated: ctx == 0
0
283 qWarning("QOpenGLTextureGlyphCache::fillTexture: Called with no context");
never executed (the execution status of this line is deduced): QMessageLogger("opengl/qopengltextureglyphcache.cpp", 283, __PRETTY_FUNCTION__).warning("QOpenGLTextureGlyphCache::fillTexture: Called with no context");
-
284 return;
never executed: return;
0
285 } -
286 -
287 if (ctx->d_func()->workaround_brokenFBOReadBack) {
never evaluated: ctx->d_func()->workaround_brokenFBOReadBack
0
288 QImageTextureGlyphCache::fillTexture(c, glyph, subPixelPosition);
never executed (the execution status of this line is deduced): QImageTextureGlyphCache::fillTexture(c, glyph, subPixelPosition);
-
289 -
290 glBindTexture(GL_TEXTURE_2D, m_textureResource->m_texture);
never executed (the execution status of this line is deduced): glBindTexture(0x0DE1, m_textureResource->m_texture);
-
291 const QImage &texture = image();
never executed (the execution status of this line is deduced): const QImage &texture = image();
-
292 const uchar *bits = texture.constBits();
never executed (the execution status of this line is deduced): const uchar *bits = texture.constBits();
-
293 bits += c.y * texture.bytesPerLine() + c.x;
never executed (the execution status of this line is deduced): bits += c.y * texture.bytesPerLine() + c.x;
-
294 for (int i=0; i<c.h; ++i) {
never evaluated: i<c.h
0
295 glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y + i, c.w, 1, GL_ALPHA, GL_UNSIGNED_BYTE, bits);
never executed (the execution status of this line is deduced): glTexSubImage2D(0x0DE1, 0, c.x, c.y + i, c.w, 1, 0x1906, 0x1401, bits);
-
296 bits += texture.bytesPerLine();
never executed (the execution status of this line is deduced): bits += texture.bytesPerLine();
-
297 }
never executed: }
0
298 return;
never executed: return;
0
299 } -
300 -
301 QImage mask = textureMapForGlyph(glyph, subPixelPosition);
never executed (the execution status of this line is deduced): QImage mask = textureMapForGlyph(glyph, subPixelPosition);
-
302 const int maskWidth = mask.width();
never executed (the execution status of this line is deduced): const int maskWidth = mask.width();
-
303 const int maskHeight = mask.height();
never executed (the execution status of this line is deduced): const int maskHeight = mask.height();
-
304 -
305#if defined(QT_OPENGL_ES_2) -
306 QOpenGLExtensions extensions(ctx); -
307 bool hasBGRA = extensions.hasOpenGLExtension(QOpenGLExtensions::BGRATextureFormat); -
308#endif -
309 -
310 if (mask.format() == QImage::Format_Mono) {
never evaluated: mask.format() == QImage::Format_Mono
0
311 mask = mask.convertToFormat(QImage::Format_Indexed8);
never executed (the execution status of this line is deduced): mask = mask.convertToFormat(QImage::Format_Indexed8);
-
312 for (int y = 0; y < maskHeight; ++y) {
never evaluated: y < maskHeight
0
313 uchar *src = (uchar *) mask.scanLine(y);
never executed (the execution status of this line is deduced): uchar *src = (uchar *) mask.scanLine(y);
-
314 for (int x = 0; x < maskWidth; ++x)
never evaluated: x < maskWidth
0
315 src[x] = -src[x]; // convert 0 and 1 into 0 and 255
never executed: src[x] = -src[x];
0
316 }
never executed: }
0
317 } else if (mask.format() == QImage::Format_RGB32) {
never executed: }
never evaluated: mask.format() == QImage::Format_RGB32
0
318 // Make the alpha component equal to the average of the RGB values. -
319 // This is needed when drawing sub-pixel antialiased text on translucent targets. -
320 for (int y = 0; y < maskHeight; ++y) {
never evaluated: y < maskHeight
0
321 quint32 *src = (quint32 *) mask.scanLine(y);
never executed (the execution status of this line is deduced): quint32 *src = (quint32 *) mask.scanLine(y);
-
322 for (int x = 0; x < maskWidth; ++x) {
never evaluated: x < maskWidth
0
323 uchar r = src[x] >> 16;
never executed (the execution status of this line is deduced): uchar r = src[x] >> 16;
-
324 uchar g = src[x] >> 8;
never executed (the execution status of this line is deduced): uchar g = src[x] >> 8;
-
325 uchar b = src[x];
never executed (the execution status of this line is deduced): uchar b = src[x];
-
326 quint32 avg = (quint32(r) + quint32(g) + quint32(b) + 1) / 3; // "+1" for rounding.
never executed (the execution status of this line is deduced): quint32 avg = (quint32(r) + quint32(g) + quint32(b) + 1) / 3;
-
327 -
328#if defined(QT_OPENGL_ES_2) -
329 if (!hasBGRA) { -
330 // Reverse bytes to match GL_RGBA -
331 src[x] = (avg << 24) | (quint32(r) << 0) | (quint32(g) << 8) | (quint32(b) << 16); -
332 } else -
333#endif -
334 src[x] = (src[x] & 0x00ffffff) | (avg << 24);
never executed (the execution status of this line is deduced): src[x] = (src[x] & 0x00ffffff) | (avg << 24);
-
335 }
never executed: }
0
336 }
never executed: }
0
337 }
never executed: }
0
338 -
339 glBindTexture(GL_TEXTURE_2D, m_textureResource->m_texture);
never executed (the execution status of this line is deduced): glBindTexture(0x0DE1, m_textureResource->m_texture);
-
340 if (mask.format() == QImage::Format_RGB32) {
never evaluated: mask.format() == QImage::Format_RGB32
0
341#if defined(QT_OPENGL_ES_2) -
342 glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, hasBGRA ? GL_BGRA_EXT : GL_RGBA, GL_UNSIGNED_BYTE, mask.bits()); -
343#else -
344 glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_BGRA, GL_UNSIGNED_BYTE, mask.bits());
never executed (the execution status of this line is deduced): glTexSubImage2D(0x0DE1, 0, c.x, c.y, maskWidth, maskHeight, 0x80E1, 0x1401, mask.bits());
-
345#endif -
346 } else {
never executed: }
0
347 // glTexSubImage2D() might cause some garbage to appear in the texture if the mask width is -
348 // not a multiple of four bytes. The bug appeared on a computer with 32-bit Windows Vista -
349 // and nVidia GeForce 8500GT. GL_UNPACK_ALIGNMENT is set to four bytes, 'mask' has a -
350 // multiple of four bytes per line, and most of the glyph shows up correctly in the -
351 // texture, which makes me think that this is a driver bug. -
352 // One workaround is to make sure the mask width is a multiple of four bytes, for instance -
353 // by converting it to a format with four bytes per pixel. Another is to copy one line at a -
354 // time. -
355 -
356#if 0 -
357 if (!ctx->d_func()->workaround_brokenAlphaTexSubImage_init) { -
358 // don't know which driver versions exhibit this bug, so be conservative for now -
359 const QByteArray versionString(reinterpret_cast<const char*>(glGetString(GL_VERSION))); -
360 glctx->d_func()->workaround_brokenAlphaTexSubImage = versionString.indexOf("NVIDIA") >= 0; -
361 glctx->d_func()->workaround_brokenAlphaTexSubImage_init = true; -
362 } -
363#endif -
364 -
365#if 0 -
366 if (ctx->d_func()->workaround_brokenAlphaTexSubImage) { -
367 for (int i = 0; i < maskHeight; ++i) -
368 glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y + i, maskWidth, 1, GL_ALPHA, GL_UNSIGNED_BYTE, mask.scanLine(i)); -
369 } else { -
370#endif -
371 glTexSubImage2D(GL_TEXTURE_2D, 0, c.x, c.y, maskWidth, maskHeight, GL_ALPHA, GL_UNSIGNED_BYTE, mask.bits());
never executed (the execution status of this line is deduced): glTexSubImage2D(0x0DE1, 0, c.x, c.y, maskWidth, maskHeight, 0x1906, 0x1401, mask.bits());
-
372// } -
373 }
never executed: }
0
374} -
375 -
376int QOpenGLTextureGlyphCache::glyphPadding() const -
377{ -
378 return 1;
never executed: return 1;
0
379} -
380 -
381int QOpenGLTextureGlyphCache::maxTextureWidth() const -
382{ -
383 QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext());
never executed (the execution status of this line is deduced): QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext());
-
384 if (ctx == 0)
never evaluated: ctx == 0
0
385 return QImageTextureGlyphCache::maxTextureWidth();
never executed: return QImageTextureGlyphCache::maxTextureWidth();
0
386 else -
387 return ctx->d_func()->maxTextureSize();
never executed: return ctx->d_func()->maxTextureSize();
0
388} -
389 -
390int QOpenGLTextureGlyphCache::maxTextureHeight() const -
391{ -
392 QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext());
never executed (the execution status of this line is deduced): QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext());
-
393 if (ctx == 0)
never evaluated: ctx == 0
0
394 return QImageTextureGlyphCache::maxTextureHeight();
never executed: return QImageTextureGlyphCache::maxTextureHeight();
0
395 -
396 if (ctx->d_func()->workaround_brokenTexSubImage)
never evaluated: ctx->d_func()->workaround_brokenTexSubImage
0
397 return qMin(1024, ctx->d_func()->maxTextureSize());
never executed: return qMin(1024, ctx->d_func()->maxTextureSize());
0
398 else -
399 return ctx->d_func()->maxTextureSize();
never executed: return ctx->d_func()->maxTextureSize();
0
400} -
401 -
402void QOpenGLTextureGlyphCache::clear() -
403{ -
404 m_textureResource->free();
never executed (the execution status of this line is deduced): m_textureResource->free();
-
405 m_textureResource = 0;
never executed (the execution status of this line is deduced): m_textureResource = 0;
-
406 -
407 m_w = 0;
never executed (the execution status of this line is deduced): m_w = 0;
-
408 m_h = 0;
never executed (the execution status of this line is deduced): m_h = 0;
-
409 m_cx = 0;
never executed (the execution status of this line is deduced): m_cx = 0;
-
410 m_cy = 0;
never executed (the execution status of this line is deduced): m_cy = 0;
-
411 m_currentRowHeight = 0;
never executed (the execution status of this line is deduced): m_currentRowHeight = 0;
-
412 coords.clear();
never executed (the execution status of this line is deduced): coords.clear();
-
413}
never executed: }
0
414 -
415QT_END_NAMESPACE -
416 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial