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>
#include "qsgdefaultdistancefieldglyphcache_p.h"
#include <QtGui/private/qdistancefield_p.h>
#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
#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)
QSGDefaultDistanceFieldGlyphCache::QSGDefaultDistanceFieldGlyphCache(QSGDistanceFieldGlyphCacheManager *man, QOpenGLContext *c, const QRawFont &font)
: QSGDistanceFieldGlyphCache(man, c, font)
, m_maxTextureSize(0)
, m_maxTextureCount(3)
{
m_blitVertexCoordinateArray[0] = -1.0f;
m_blitVertexCoordinateArray[1] = -1.0f;
{
m_blitVertexCoordinateArray[0] = -1.0f;
m_blitVertexCoordinateArray[1] = -1.0f;
{
for (int i = 0; i < m_textures.count(); ++i)
glDeleteTextures(1, &m_textures[i].texture);
{
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;
}
delete m_blitProgram;
delete m_areaAllocator;
}
+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();
void QSGDefaultDistanceFieldGlyphCache::resizeTexture(TextureInfo *texInfo, int width, int height)
{
int oldWidth = texInfo->size.width();
- 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);
GLuint tmp_texture;
glGenTextures(1, &tmp_texture);
+class QOpenGLSharedResourceGuard;
class Q_QUICK_PRIVATE_EXPORT QSGDefaultDistanceFieldGlyphCache : public QSGDistanceFieldGlyphCache
{
public:
class Q_QUICK_PRIVATE_EXPORT QSGDefaultDistanceFieldGlyphCache : public QSGDistanceFieldGlyphCache
{
public:
QList<TextureInfo> m_textures;
QHash<glyph_t, TextureInfo *> m_glyphsTexture;
QList<TextureInfo> m_textures;
QHash<glyph_t, TextureInfo *> m_glyphsTexture;
QSet<glyph_t> m_unusedGlyphs;
QSGAreaAllocator *m_areaAllocator;
QSet<glyph_t> m_unusedGlyphs;
QSGAreaAllocator *m_areaAllocator;
QOpenGLShaderProgram *m_blitProgram;
GLfloat m_blitVertexCoordinateArray[8];
GLfloat m_blitTextureCoordinateArray[8];
QOpenGLShaderProgram *m_blitProgram;
GLfloat m_blitVertexCoordinateArray[8];
GLfloat m_blitTextureCoordinateArray[8];
+
+ QOpenGLSharedResourceGuard *m_fboGuard;
QCOMPARE(input.isCursorVisible(), true);
QCOMPARE(spy.count(), 5);
QCOMPARE(input.isCursorVisible(), true);
QCOMPARE(spy.count(), 5);
+ QQuickView alternateView;
alternateView.show();
alternateView.requestActivateWindow();
QTest::qWaitForWindowActive(&alternateView);
alternateView.show();
alternateView.requestActivateWindow();
QTest::qWaitForWindowActive(&alternateView);