diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2012-08-06 11:51:09 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-09-28 16:15:31 +0200 |
commit | e03363dfd1aeddd085c4c86d9a1964da769d7980 (patch) | |
tree | 9bffd1443a010a418e306cdd06642df7f3f48cbf /src | |
parent | 5bd0e08063fcacba0c2b63528712968c7d74e7f9 (diff) |
Fix potential crash when using text and more than 1 QQuickView
We need to use a resource guard for the FBO in case there is no
current context when the glyph cache is deleted.
This reverts commit b3264e2cb6a8fe87754aa1335ab9f8d5e3910c14 which
was implemented as a band-aid for this crash.
Change-Id: I5b3a09a3998da38836ea851cd0978d3ddadcd2cc
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp | 23 | ||||
-rw-r--r-- | src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h | 4 |
2 files changed, 20 insertions, 7 deletions
diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp index 07c17a5791..d889b4028b 100644 --- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp +++ b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache.cpp @@ -42,19 +42,19 @@ #include "qsgdefaultdistancefieldglyphcache_p.h" #include <QtGui/private/qdistancefield_p.h> +#include <QtGui/private/qopenglcontext_p.h> #include <QtQuick/private/qsgdistancefieldutil_p.h> #include <qopenglfunctions.h> #include <qmath.h> QT_BEGIN_NAMESPACE - QSGDefaultDistanceFieldGlyphCache::QSGDefaultDistanceFieldGlyphCache(QSGDistanceFieldGlyphCacheManager *man, QOpenGLContext *c, const QRawFont &font) : QSGDistanceFieldGlyphCache(man, c, font) , m_maxTextureSize(0) , m_maxTextureCount(3) - , m_fbo(0) , m_blitProgram(0) + , m_fboGuard(0) { m_blitVertexCoordinateArray[0] = -1.0f; m_blitVertexCoordinateArray[1] = -1.0f; @@ -81,7 +81,10 @@ QSGDefaultDistanceFieldGlyphCache::~QSGDefaultDistanceFieldGlyphCache() { for (int i = 0; i < m_textures.count(); ++i) glDeleteTextures(1, &m_textures[i].texture); - ctx->functions()->glDeleteFramebuffers(1, &m_fbo); + + if (m_fboGuard != 0) + m_fboGuard->free(); + delete m_blitProgram; delete m_areaAllocator; } @@ -215,6 +218,11 @@ void QSGDefaultDistanceFieldGlyphCache::createTexture(TextureInfo *texInfo, int } +static void freeFramebufferFunc(QOpenGLFunctions *funcs, GLuint id) +{ + funcs->glDeleteFramebuffers(1, &id); +} + void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int width, int height) { int oldWidth = texInfo->size.width(); @@ -242,9 +250,12 @@ void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int Q_ASSERT(m_blitProgram); - if (!m_fbo) - ctx->functions()->glGenFramebuffers(1, &m_fbo); - ctx->functions()->glBindFramebuffer(GL_FRAMEBUFFER, m_fbo); + if (!m_fboGuard) { + GLuint fbo; + ctx->functions()->glGenFramebuffers(1, &fbo); + m_fboGuard = new QOpenGLSharedResourceGuard(ctx, fbo, freeFramebufferFunc); + } + ctx->functions()->glBindFramebuffer(GL_FRAMEBUFFER, m_fboGuard->id()); GLuint tmp_texture; glGenTextures(1, &tmp_texture); diff --git a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h index 2fc706cff5..decac2cc0f 100644 --- a/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h +++ b/src/quick/scenegraph/qsgdefaultdistancefieldglyphcache_p.h @@ -50,6 +50,7 @@ QT_BEGIN_NAMESPACE +class QOpenGLSharedResourceGuard; class Q_QUICK_PRIVATE_EXPORT QSGDefaultDistanceFieldGlyphCache : public QSGDistanceFieldGlyphCache { public: @@ -122,7 +123,6 @@ private: QList<TextureInfo> m_textures; QHash<glyph_t, TextureInfo *> m_glyphsTexture; - GLuint m_fbo; QSet<glyph_t> m_unusedGlyphs; QSGAreaAllocator *m_areaAllocator; @@ -130,6 +130,8 @@ private: QOpenGLShaderProgram *m_blitProgram; GLfloat m_blitVertexCoordinateArray[8]; GLfloat m_blitTextureCoordinateArray[8]; + + QOpenGLSharedResourceGuard *m_fboGuard; }; QT_END_NAMESPACE |