qopengltexturecache.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/opengl/qopengltexturecache.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3class QOpenGLTextureCacheWrapper-
4{-
5public:-
6 QOpenGLTextureCacheWrapper()-
7 {-
8 QImagePixmapCleanupHooks::instance()->addPlatformPixmapModificationHook(cleanupTexturesForPixmapData);-
9 QImagePixmapCleanupHooks::instance()->addPlatformPixmapDestructionHook(cleanupTexturesForPixmapData);-
10 QImagePixmapCleanupHooks::instance()->addImageHook(cleanupTexturesForCacheKey);-
11 }
never executed: end of block
0
12-
13 ~QOpenGLTextureCacheWrapper()-
14 {-
15 QImagePixmapCleanupHooks::instance()->removePlatformPixmapModificationHook(cleanupTexturesForPixmapData);-
16 QImagePixmapCleanupHooks::instance()->removePlatformPixmapDestructionHook(cleanupTexturesForPixmapData);-
17 QImagePixmapCleanupHooks::instance()->removeImageHook(cleanupTexturesForCacheKey);-
18 }
never executed: end of block
0
19-
20 QOpenGLTextureCache *cacheForContext(QOpenGLContext *context) {-
21 QMutexLocker lock(&m_mutex);-
22 return
never executed: return m_resource.value<QOpenGLTextureCache>(context);
m_resource.value<QOpenGLTextureCache>(context);
never executed: return m_resource.value<QOpenGLTextureCache>(context);
0
23 }-
24-
25 static void cleanupTexturesForCacheKey(qint64 key);-
26 static void cleanupTexturesForPixmapData(QPlatformPixmap *pmd);-
27-
28private:-
29 QOpenGLMultiGroupSharedResource m_resource;-
30 QMutex m_mutex;-
31};-
32-
33namespace { namespace Q_QGS_qt_texture_caches { typedef QOpenGLTextureCacheWrapper Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
guard.load() =...c::InitializedDescription
TRUEnever evaluated
FALSEnever evaluated
) guard.store(QtGlobalStatic::Destroyed);
never executed: guard.store(QtGlobalStatic::Destroyed);
}
never executed: end of block
}; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return
never executed: return &holder.value;
&holder.value;
never executed: return &holder.value;
} } } static QGlobalStatic<QOpenGLTextureCacheWrapper, Q_QGS_qt_texture_caches::innerFunction, Q_QGS_qt_texture_caches::guard> qt_texture_caches;
0
34-
35QOpenGLTextureCache *QOpenGLTextureCache::cacheForContext(QOpenGLContext *context)-
36{-
37 return
never executed: return qt_texture_caches()->cacheForContext(context);
qt_texture_caches()->cacheForContext(context);
never executed: return qt_texture_caches()->cacheForContext(context);
0
38}-
39-
40void QOpenGLTextureCacheWrapper::cleanupTexturesForCacheKey(qint64 key)-
41{-
42 QList<QOpenGLSharedResource *> resources = qt_texture_caches()->m_resource.resources();-
43 for (QList<QOpenGLSharedResource *>::iterator it = resources.begin(); it != resources.end()
it != resources.end()Description
TRUEnever evaluated
FALSEnever evaluated
; ++it)
0
44 static_cast<
never executed: static_cast<QOpenGLTextureCache *>(*it)->invalidate(key);
QOpenGLTextureCache *>(*it)->invalidate(key);
never executed: static_cast<QOpenGLTextureCache *>(*it)->invalidate(key);
0
45}
never executed: end of block
0
46-
47void QOpenGLTextureCacheWrapper::cleanupTexturesForPixmapData(QPlatformPixmap *pmd)-
48{-
49 cleanupTexturesForCacheKey(pmd->cacheKey());-
50}
never executed: end of block
0
51-
52QOpenGLTextureCache::QOpenGLTextureCache(QOpenGLContext *ctx)-
53 : QOpenGLSharedResource(ctx->shareGroup())-
54 , m_cache(64 * 1024)-
55{-
56}
never executed: end of block
0
57-
58QOpenGLTextureCache::~QOpenGLTextureCache()-
59{-
60}-
61-
62GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QPixmap &pixmap, BindOptions options)-
63{-
64 if (pixmap.isNull()
pixmap.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
65 return
never executed: return 0;
0;
never executed: return 0;
0
66 QMutexLocker locker(&m_mutex);-
67 qint64 key = pixmap.cacheKey();-
68-
69-
70 if (!pixmap.paintingActive()
!pixmap.paintingActive()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
71 QOpenGLCachedTexture *entry = m_cache.object(key);-
72 if (entry
entryDescription
TRUEnever evaluated
FALSEnever evaluated
&& entry->options() == options
entry->options() == optionsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
73 context->functions()->glBindTexture(0x0DE1, entry->id());-
74 return
never executed: return entry->id();
entry->id();
never executed: return entry->id();
0
75 }-
76 }
never executed: end of block
0
77-
78 GLuint id = bindTexture(context, key, pixmap.toImage(), options);-
79 if (id > 0
id > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
80 QImagePixmapCleanupHooks::enableCleanupHooks(pixmap);
never executed: QImagePixmapCleanupHooks::enableCleanupHooks(pixmap);
0
81-
82 return
never executed: return id;
id;
never executed: return id;
0
83}-
84-
85GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &image, BindOptions options)-
86{-
87 if (image.isNull()
image.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
88 return
never executed: return 0;
0;
never executed: return 0;
0
89 QMutexLocker locker(&m_mutex);-
90 qint64 key = image.cacheKey();-
91-
92-
93 if (!image.paintingActive()
!image.paintingActive()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
94 QOpenGLCachedTexture *entry = m_cache.object(key);-
95 if (entry
entryDescription
TRUEnever evaluated
FALSEnever evaluated
&& entry->options() == options
entry->options() == optionsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
96 context->functions()->glBindTexture(0x0DE1, entry->id());-
97 return
never executed: return entry->id();
entry->id();
never executed: return entry->id();
0
98 }-
99 }
never executed: end of block
0
100-
101 QImage img = image;-
102 if (!context->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)
!context->func...:NPOTTextures)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
103-
104-
105-
106 int tx_w = qNextPowerOfTwo(image.width() - 1);-
107 int tx_h = qNextPowerOfTwo(image.height() - 1);-
108 if (tx_w != image.width()
tx_w != image.width()Description
TRUEnever evaluated
FALSEnever evaluated
|| tx_h != image.height()
tx_h != image.height()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
109 img = img.scaled(tx_w, tx_h);-
110 }
never executed: end of block
0
111 }
never executed: end of block
0
112-
113 GLuint id = bindTexture(context, key, img, options);-
114 if (id > 0
id > 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
115 QImagePixmapCleanupHooks::enableCleanupHooks(image);
never executed: QImagePixmapCleanupHooks::enableCleanupHooks(image);
0
116-
117 return
never executed: return id;
id;
never executed: return id;
0
118}-
119-
120GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, qint64 key, const QImage &image, BindOptions options)-
121{-
122 GLuint id;-
123 QOpenGLFunctions *funcs = context->functions();-
124 funcs->glGenTextures(1, &id);-
125 funcs->glBindTexture(0x0DE1, id);-
126-
127 QImage tx;-
128 GLenum externalFormat;-
129 GLenum internalFormat;-
130 GLuint pixelType;-
131 QImage::Format targetFormat = QImage::Format_Invalid;-
132 const bool isOpenGL12orBetter = !context->isOpenGLES()
!context->isOpenGLES()Description
TRUEnever evaluated
FALSEnever evaluated
&& (context->format().majorVersion() >= 2
context->forma...Version() >= 2Description
TRUEnever evaluated
FALSEnever evaluated
|| context->format().minorVersion() >= 2
context->forma...Version() >= 2Description
TRUEnever evaluated
FALSEnever evaluated
);
0
133-
134 switch (image.format()) {-
135 case
never executed: case QImage::Format_RGB32:
QImage::Format_RGB32:
never executed: case QImage::Format_RGB32:
0
136 case
never executed: case QImage::Format_ARGB32:
QImage::Format_ARGB32:
never executed: case QImage::Format_ARGB32:
0
137 case
never executed: case QImage::Format_ARGB32_Premultiplied:
QImage::Format_ARGB32_Premultiplied:
never executed: case QImage::Format_ARGB32_Premultiplied:
0
138 if (isOpenGL12orBetter
isOpenGL12orBetterDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
139 externalFormat = 0x80E1;-
140 internalFormat = 0x1908;-
141 pixelType = 0x8367;-
142 }
never executed: end of block
else {
0
143-
144-
145-
146-
147 if (static_cast<
static_cast<QO...TextureFormat)Description
TRUEnever evaluated
FALSEnever evaluated
QOpenGLExtensions*>(context->functions())->hasOpenGLExtension(QOpenGLExtensions::BGRATextureFormat)
static_cast<QO...TextureFormat)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
148-
149 if (context->isOpenGLES()
context->isOpenGLES()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
150-
151 externalFormat = internalFormat = 0x80E1;-
152 }
never executed: end of block
else {
0
153-
154 externalFormat = 0x80E1;-
155 internalFormat = 0x1908;-
156 }
never executed: end of block
0
157 pixelType = 0x1401;-
158 }
never executed: end of block
else if (context->isOpenGLES()
context->isOpenGLES()Description
TRUEnever evaluated
FALSEnever evaluated
&& context->hasExtension(([]() -> QByteArray { enum { Size = sizeof("GL_APPLE_texture_format_BGRA8888") - 1 }; static const QStaticByteArrayData<Size> qbytearray_literal = { { { { -1 } }, Size, 0, 0, sizeof(QByteArrayData) }, "GL_APPLE_texture_format_BGRA8888" }; QByteArrayDataPtr holder = { qbytearray_literal.data_ptr() }; const QByteArray ba(holder); return ba; }()))
context->hasEx...turn ba; }()))Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
159-
160 externalFormat = 0x80E1;-
161 internalFormat = 0x1908;-
162 pixelType = 0x1401;-
163 }
never executed: end of block
else {
0
164-
165 break;
never executed: break;
0
166 }-
167 }-
168 targetFormat = image.format();-
169 break;
never executed: break;
0
170 case
never executed: case QImage::Format_BGR30:
QImage::Format_BGR30:
never executed: case QImage::Format_BGR30:
0
171 case
never executed: case QImage::Format_A2BGR30_Premultiplied:
QImage::Format_A2BGR30_Premultiplied:
never executed: case QImage::Format_A2BGR30_Premultiplied:
0
172 if (isOpenGL12orBetter
isOpenGL12orBetterDescription
TRUEnever evaluated
FALSEnever evaluated
|| (context->isOpenGLES()
context->isOpenGLES()Description
TRUEnever evaluated
FALSEnever evaluated
&& context->format().majorVersion() >= 3
context->forma...Version() >= 3Description
TRUEnever evaluated
FALSEnever evaluated
)) {
0
173 pixelType = 0x8368;-
174 externalFormat = 0x1908;-
175 internalFormat = 0x8059;-
176 targetFormat = image.format();-
177 }
never executed: end of block
0
178 break;
never executed: break;
0
179 case
never executed: case QImage::Format_RGB30:
QImage::Format_RGB30:
never executed: case QImage::Format_RGB30:
0
180 case
never executed: case QImage::Format_A2RGB30_Premultiplied:
QImage::Format_A2RGB30_Premultiplied:
never executed: case QImage::Format_A2RGB30_Premultiplied:
0
181 if (isOpenGL12orBetter
isOpenGL12orBetterDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
182 pixelType = 0x8368;-
183 externalFormat = 0x80E1;-
184 internalFormat = 0x8059;-
185 targetFormat = image.format();-
186 }
never executed: end of block
else if (context->isOpenGLES()
context->isOpenGLES()Description
TRUEnever evaluated
FALSEnever evaluated
&& context->format().majorVersion() >= 3
context->forma...Version() >= 3Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
187 pixelType = 0x8368;-
188 externalFormat = 0x1908;-
189 internalFormat = 0x8059;-
190 targetFormat = QImage::Format_A2BGR30_Premultiplied;-
191 }
never executed: end of block
0
192 break;
never executed: break;
0
193 case
never executed: case QImage::Format_RGB444:
QImage::Format_RGB444:
never executed: case QImage::Format_RGB444:
0
194 case
never executed: case QImage::Format_RGB555:
QImage::Format_RGB555:
never executed: case QImage::Format_RGB555:
0
195 case
never executed: case QImage::Format_RGB16:
QImage::Format_RGB16:
never executed: case QImage::Format_RGB16:
0
196 if (isOpenGL12orBetter
isOpenGL12orBetterDescription
TRUEnever evaluated
FALSEnever evaluated
|| context->isOpenGLES()
context->isOpenGLES()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
197 externalFormat = internalFormat = 0x1907;-
198 pixelType = 0x8363;-
199 targetFormat = QImage::Format_RGB16;-
200 }
never executed: end of block
0
201 break;
never executed: break;
0
202 case
never executed: case QImage::Format_RGB666:
QImage::Format_RGB666:
never executed: case QImage::Format_RGB666:
0
203 case
never executed: case QImage::Format_RGB888:
QImage::Format_RGB888:
never executed: case QImage::Format_RGB888:
0
204 externalFormat = internalFormat = 0x1907;-
205 pixelType = 0x1401;-
206 targetFormat = QImage::Format_RGB888;-
207 break;
never executed: break;
0
208 case
never executed: case QImage::Format_RGBX8888:
QImage::Format_RGBX8888:
never executed: case QImage::Format_RGBX8888:
0
209 case
never executed: case QImage::Format_RGBA8888:
QImage::Format_RGBA8888:
never executed: case QImage::Format_RGBA8888:
0
210 case
never executed: case QImage::Format_RGBA8888_Premultiplied:
QImage::Format_RGBA8888_Premultiplied:
never executed: case QImage::Format_RGBA8888_Premultiplied:
0
211 externalFormat = internalFormat = 0x1908;-
212 pixelType = 0x1401;-
213 targetFormat = image.format();-
214 break;
never executed: break;
0
215 case
never executed: case QImage::Format_Indexed8:
QImage::Format_Indexed8:
never executed: case QImage::Format_Indexed8:
0
216 if (options & UseRedFor8BitBindOption
options & UseR...8BitBindOptionDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
217 externalFormat = internalFormat = 0x1903;-
218 pixelType = 0x1401;-
219 targetFormat = image.format();-
220 }
never executed: end of block
0
221 break;
never executed: break;
0
222 case
never executed: case QImage::Format_Alpha8:
QImage::Format_Alpha8:
never executed: case QImage::Format_Alpha8:
0
223 if (options & UseRedFor8BitBindOption
options & UseR...8BitBindOptionDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
224 externalFormat = internalFormat = 0x1903;-
225 pixelType = 0x1401;-
226 targetFormat = image.format();-
227 }
never executed: end of block
else if (context->isOpenGLES()
context->isOpenGLES()Description
TRUEnever evaluated
FALSEnever evaluated
|| context->format().profile() != QSurfaceFormat::CoreProfile
context->forma...t::CoreProfileDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
228 externalFormat = internalFormat = 0x1906;-
229 pixelType = 0x1401;-
230 targetFormat = image.format();-
231 }
never executed: end of block
0
232 break;
never executed: break;
0
233 case
never executed: case QImage::Format_Grayscale8:
QImage::Format_Grayscale8:
never executed: case QImage::Format_Grayscale8:
0
234 if (options & UseRedFor8BitBindOption
options & UseR...8BitBindOptionDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
235 externalFormat = internalFormat = 0x1903;-
236 pixelType = 0x1401;-
237 targetFormat = image.format();-
238 }
never executed: end of block
else if (context->isOpenGLES()
context->isOpenGLES()Description
TRUEnever evaluated
FALSEnever evaluated
|| context->format().profile() != QSurfaceFormat::CoreProfile
context->forma...t::CoreProfileDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
239 externalFormat = internalFormat = 0x1909;-
240 pixelType = 0x1401;-
241 targetFormat = image.format();-
242 }
never executed: end of block
0
243 break;
never executed: break;
0
244 default
never executed: default:
:
never executed: default:
0
245 break;
never executed: break;
0
246 }-
247-
248 if (targetFormat == QImage::Format_Invalid
targetFormat =...Format_InvalidDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
249 externalFormat = internalFormat = 0x1908;-
250 pixelType = 0x1401;-
251 if (!image.hasAlphaChannel()
!image.hasAlphaChannel()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
252 targetFormat = QImage::Format_RGBX8888;
never executed: targetFormat = QImage::Format_RGBX8888;
0
253 else-
254 targetFormat = QImage::Format_RGBA8888;
never executed: targetFormat = QImage::Format_RGBA8888;
0
255 }-
256-
257 if (options & PremultipliedAlphaBindOption
options & Prem...lphaBindOptionDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
258 if (targetFormat == QImage::Format_ARGB32
targetFormat =...:Format_ARGB32Description
TRUEnever evaluated
FALSEnever evaluated
)
0
259 targetFormat = QImage::Format_ARGB32_Premultiplied;
never executed: targetFormat = QImage::Format_ARGB32_Premultiplied;
0
260 else if (targetFormat == QImage::Format_RGBA8888
targetFormat =...ormat_RGBA8888Description
TRUEnever evaluated
FALSEnever evaluated
)
0
261 targetFormat = QImage::Format_RGBA8888_Premultiplied;
never executed: targetFormat = QImage::Format_RGBA8888_Premultiplied;
0
262 }
never executed: end of block
else {
0
263 if (targetFormat == QImage::Format_ARGB32_Premultiplied
targetFormat =..._PremultipliedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
264 targetFormat = QImage::Format_ARGB32;
never executed: targetFormat = QImage::Format_ARGB32;
0
265 else if (targetFormat == QImage::Format_RGBA8888_Premultiplied
targetFormat =..._PremultipliedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
266 targetFormat = QImage::Format_RGBA8888;
never executed: targetFormat = QImage::Format_RGBA8888;
0
267 }
never executed: end of block
0
268-
269 if (image.format() != targetFormat
image.format() != targetFormatDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
270 tx = image.convertToFormat(targetFormat);
never executed: tx = image.convertToFormat(targetFormat);
0
271 else-
272 tx = image;
never executed: tx = image;
0
273-
274 funcs->glTexImage2D(0x0DE1, 0, internalFormat, tx.width(), tx.height(), 0, externalFormat, pixelType, const_cast<const QImage &>(tx).bits());-
275-
276 int cost = tx.width() * tx.height() * tx.depth() / (1024 * 8);-
277 m_cache.insert(key, new QOpenGLCachedTexture(id, options, context), cost);-
278-
279 return
never executed: return id;
id;
never executed: return id;
0
280}-
281-
282void QOpenGLTextureCache::invalidate(qint64 key)-
283{-
284 QMutexLocker locker(&m_mutex);-
285 m_cache.remove(key);-
286}
never executed: end of block
0
287-
288void QOpenGLTextureCache::invalidateResource()-
289{-
290 m_cache.clear();-
291}
never executed: end of block
0
292-
293void QOpenGLTextureCache::freeResource(QOpenGLContext *)-
294{-
295 ((!(false)) ? qt_assert("false",__FILE__,366) : qt_noop());-
296}
never executed: end of block
0
297-
298static void freeTexture(QOpenGLFunctions *funcs, GLuint id)-
299{-
300 funcs->glDeleteTextures(1, &id);-
301}
never executed: end of block
0
302-
303QOpenGLCachedTexture::QOpenGLCachedTexture(GLuint id, int options, QOpenGLContext *context) : m_options(options)-
304{-
305 m_resource = new QOpenGLSharedResourceGuard(context, id, freeTexture);-
306}
never executed: end of block
0
307-
308-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9