summaryrefslogtreecommitdiffstats
path: root/src/opengl
diff options
context:
space:
mode:
Diffstat (limited to 'src/opengl')
-rw-r--r--src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp14
-rw-r--r--src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp28
-rw-r--r--src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h17
-rw-r--r--src/opengl/qgl_p.h3
4 files changed, 56 insertions, 6 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
index 1dcb773..3ddc15a 100644
--- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
+++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp
@@ -1212,6 +1212,9 @@ void QGL2PaintEngineExPrivate::stroke(const QVectorPath &path, const QPen &pen)
stroker.process(dashStroke, pen, clip);
}
+ if (!stroker.vertexCount())
+ return;
+
if (opaque) {
prepareForDraw(opaque);
setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, stroker.vertices());
@@ -1479,6 +1482,8 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
if (!cache || cache->cacheType() != glyphType) {
cache = new QGLTextureGlyphCache(ctx, glyphType, QTransform());
staticTextItem->fontEngine()->setGlyphCache(ctx, cache);
+ } else if (cache->context() == 0) { // Old context has been destroyed, new context has same ptr value
+ cache->setContext(ctx);
}
bool recreateVertexArrays = false;
@@ -1494,8 +1499,13 @@ void QGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyp
// cache so this text is performed before we test if the cache size has changed.
if (recreateVertexArrays) {
cache->setPaintEnginePrivate(this);
- cache->populate(staticTextItem->fontEngine(), staticTextItem->numGlyphs,
- staticTextItem->glyphs, staticTextItem->glyphPositions);
+ if (!cache->populate(staticTextItem->fontEngine(), staticTextItem->numGlyphs,
+ staticTextItem->glyphs, staticTextItem->glyphPositions)) {
+ // No space in cache. We need to clear the cache and try again
+ cache->clear();
+ cache->populate(staticTextItem->fontEngine(), staticTextItem->numGlyphs,
+ staticTextItem->glyphs, staticTextItem->glyphPositions);
+ }
}
if (cache->width() == 0 || cache->height() == 0)
diff --git a/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp b/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp
index 919c542..705ad09 100644
--- a/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp
+++ b/src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp
@@ -54,11 +54,18 @@ extern Q_GUI_EXPORT bool qt_cleartype_enabled;
QGLTextureGlyphCache::QGLTextureGlyphCache(QGLContext *context, QFontEngineGlyphCache::Type type, const QTransform &matrix)
: QImageTextureGlyphCache(type, matrix)
- , ctx(context)
+ , ctx(0)
, m_width(0)
, m_height(0)
, m_filterMode(Nearest)
{
+ setContext(context);
+}
+
+void QGLTextureGlyphCache::setContext(QGLContext *context)
+{
+ ctx = context;
+
// broken FBO readback is a bug in the SGX 1.3 and 1.4 drivers for the N900 where
// copying between FBO's is broken if the texture is either GL_ALPHA or POT. The
// workaround is to use a system-memory copy of the glyph cache for this device.
@@ -71,7 +78,7 @@ QGLTextureGlyphCache::QGLTextureGlyphCache(QGLContext *context, QFontEngineGlyph
SLOT(contextDestroyed(const QGLContext*)));
}
-QGLTextureGlyphCache::~QGLTextureGlyphCache()
+void QGLTextureGlyphCache::clear()
{
if (ctx) {
QGLShareContextScope scope(ctx);
@@ -81,7 +88,24 @@ QGLTextureGlyphCache::~QGLTextureGlyphCache()
if (m_width || m_height)
glDeleteTextures(1, &m_texture);
+
+ m_fbo = 0;
+ m_texture = 0;
+ m_width = 0;
+ m_height = 0;
+ m_w = 0;
+ m_h = 0;
+ m_cx = 0;
+ m_cy = 0;
+ m_currentRowHeight = 0;
+ coords.clear();
}
+
+}
+
+QGLTextureGlyphCache::~QGLTextureGlyphCache()
+{
+ clear();
}
void QGLTextureGlyphCache::createTextureData(int width, int height)
diff --git a/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h b/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h
index e22146d..aaef350 100644
--- a/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h
+++ b/src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h
@@ -90,6 +90,9 @@ public:
FilterMode filterMode() const { return m_filterMode; }
void setFilterMode(FilterMode m) { m_filterMode = m; }
+ void setContext(QGLContext *context);
+ QGLContext *context() const { return ctx; }
+
public Q_SLOTS:
void contextDestroyed(const QGLContext *context) {
if (context == ctx) {
@@ -98,10 +101,20 @@ public Q_SLOTS:
// the context may not be current, so we cannot directly
// destroy the fbo and texture here, but since the context
// is about to be destroyed, the GL server will do the
- // clean up for us anyway
+ // clean up for us anyway. We reset everything, so that the
+ // glyph cache object can be reused later by setting a new
+ // context on it.
m_fbo = 0;
m_texture = 0;
ctx = 0;
+ m_width = 0;
+ m_height = 0;
+ m_w = 0;
+ m_h = 0;
+ m_cx = 0;
+ m_cy = 0;
+ m_currentRowHeight = 0;
+ coords.clear();
} else {
// since the context holding the texture is shared, and
// about to be destroyed, we have to transfer ownership
@@ -111,6 +124,8 @@ public Q_SLOTS:
}
}
+ void clear();
+
private:
QGLContext *ctx;
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index 4742bdb..b46d428 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -506,7 +506,8 @@ private slots:
// when you come to delete the context.
QGLContextPrivate::unbindPixmapFromTexture(boundPixmap);
glDeleteTextures(1, &id);
- oldContext->makeCurrent();
+ if (oldContext)
+ oldContext->makeCurrent();
return;
}
#endif