summaryrefslogtreecommitdiffstats
path: root/src/opengl/qopengltexturecache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/opengl/qopengltexturecache.cpp')
-rw-r--r--src/opengl/qopengltexturecache.cpp52
1 files changed, 36 insertions, 16 deletions
diff --git a/src/opengl/qopengltexturecache.cpp b/src/opengl/qopengltexturecache.cpp
index f2b7565316..64583c03a9 100644
--- a/src/opengl/qopengltexturecache.cpp
+++ b/src/opengl/qopengltexturecache.cpp
@@ -61,9 +61,19 @@ void QOpenGLTextureCacheWrapper::cleanupTexturesForPixmapData(QPlatformPixmap *p
cleanupTexturesForCacheKey(pmd->cacheKey());
}
+static quint64 cacheSize()
+{
+ bool ok = false;
+ const int envCacheSize = qEnvironmentVariableIntValue("QT_OPENGL_TEXTURE_CACHE_SIZE", &ok);
+ if (ok)
+ return envCacheSize;
+
+ return 1024 * 1024; // 1024 MB cache default
+}
+
QOpenGLTextureCache::QOpenGLTextureCache(QOpenGLContext *ctx)
: QOpenGLSharedResource(ctx->shareGroup())
- , m_cache(256 * 1024) // 256 MB cache
+ , m_cache(cacheSize())
{
}
@@ -71,10 +81,12 @@ QOpenGLTextureCache::~QOpenGLTextureCache()
{
}
-GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QPixmap &pixmap, QOpenGLTextureUploader::BindOptions options)
+QOpenGLTextureCache::BindResult QOpenGLTextureCache::bindTexture(QOpenGLContext *context,
+ const QPixmap &pixmap,
+ QOpenGLTextureUploader::BindOptions options)
{
if (pixmap.isNull())
- return 0;
+ return { 0, {} };
QMutexLocker locker(&m_mutex);
qint64 key = pixmap.cacheKey();
@@ -83,21 +95,23 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QPixmap &
QOpenGLCachedTexture *entry = m_cache.object(key);
if (entry && entry->options() == options) {
context->functions()->glBindTexture(GL_TEXTURE_2D, entry->id());
- return entry->id();
+ return { entry->id(), {} };
}
}
- GLuint id = bindTexture(context, key, pixmap.toImage(), options);
- if (id > 0)
+ BindResult result = bindTexture(context, key, pixmap.toImage(), options);
+ if (result.id > 0)
QImagePixmapCleanupHooks::enableCleanupHooks(pixmap);
- return id;
+ return result;
}
-GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &image, QOpenGLTextureUploader::BindOptions options)
+QOpenGLTextureCache::BindResult QOpenGLTextureCache::bindTexture(QOpenGLContext *context,
+ const QImage &image,
+ QOpenGLTextureUploader::BindOptions options)
{
if (image.isNull())
- return 0;
+ return { 0, {} };
QMutexLocker locker(&m_mutex);
qint64 key = image.cacheKey();
@@ -106,7 +120,7 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &i
QOpenGLCachedTexture *entry = m_cache.object(key);
if (entry && entry->options() == options) {
context->functions()->glBindTexture(GL_TEXTURE_2D, entry->id());
- return entry->id();
+ return { entry->id(), {} };
}
}
@@ -114,16 +128,22 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, const QImage &i
if (!context->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextures))
options |= QOpenGLTextureUploader::PowerOfTwoBindOption;
- GLuint id = bindTexture(context, key, img, options);
- if (id > 0)
+ BindResult result = bindTexture(context, key, img, options);
+ if (result.id > 0)
QImagePixmapCleanupHooks::enableCleanupHooks(image);
- return id;
+ return result;
}
-GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, qint64 key, const QImage &image, QOpenGLTextureUploader::BindOptions options)
+Q_TRACE_POINT(qtopengl, QOpenGLTextureCache_bindTexture_entry, QOpenGLContext *context, qint64 key, const unsigned char *image, int options);
+Q_TRACE_POINT(qtopengl, QOpenGLTextureCache_bindTexture_exit);
+
+QOpenGLTextureCache::BindResult QOpenGLTextureCache::bindTexture(QOpenGLContext *context,
+ qint64 key,
+ const QImage &image,
+ QOpenGLTextureUploader::BindOptions options)
{
- Q_TRACE_SCOPE(QOpenGLTextureCache_bindTexture, context, key, image, options);
+ Q_TRACE_SCOPE(QOpenGLTextureCache_bindTexture, context, key, image.bits(), options);
GLuint id;
QOpenGLFunctions *funcs = context->functions();
@@ -134,7 +154,7 @@ GLuint QOpenGLTextureCache::bindTexture(QOpenGLContext *context, qint64 key, con
m_cache.insert(key, new QOpenGLCachedTexture(id, options, context), cost / 1024);
- return id;
+ return { id, BindResultFlag::NewTexture };
}
void QOpenGLTextureCache::invalidate(qint64 key)