diff options
author | Tor Arne Vestbø <tor.arne.vestbo@digia.com> | 2014-02-10 13:59:44 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-19 19:36:25 +0100 |
commit | 4de3c5db238f45404feb6c6ce60810a3e11eae84 (patch) | |
tree | bc0a4d7af2f757fed94c1b52ca6bcd0e74bae25f /src/gui/opengl | |
parent | 30fd22b9574def54726e7b193127cc0c901c1b4c (diff) |
Unify glyph format between QFontEngine and QFontEngineGlyphCache
Instead of the glyph cache having its own cache type that always mapped
one to one to a font engine glyph format, causing confusion and needless
conversions, the glyph caches now use QFontEngine's glyph format enum.
This also removes the iffy use of an int for the glyphFormat in the font
engines.
Change-Id: I529bad5c179e004f63e152f7dcc311d298c3db98
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/gui/opengl')
-rw-r--r-- | src/gui/opengl/qopenglpaintengine.cpp | 53 | ||||
-rw-r--r-- | src/gui/opengl/qopenglpaintengine_p.h | 4 | ||||
-rw-r--r-- | src/gui/opengl/qopengltextureglyphcache.cpp | 6 | ||||
-rw-r--r-- | src/gui/opengl/qopengltextureglyphcache_p.h | 2 |
4 files changed, 31 insertions, 34 deletions
diff --git a/src/gui/opengl/qopenglpaintengine.cpp b/src/gui/opengl/qopenglpaintengine.cpp index e91ada7b3a..63127668a5 100644 --- a/src/gui/opengl/qopenglpaintengine.cpp +++ b/src/gui/opengl/qopenglpaintengine.cpp @@ -1434,19 +1434,18 @@ void QOpenGL2PaintEngineEx::drawStaticTextItem(QStaticTextItem *textItem) QFontEngine *fontEngine = textItem->fontEngine(); if (shouldDrawCachedGlyphs(fontEngine, s->matrix)) { - QFontEngineGlyphCache::Type glyphType = fontEngine->glyphFormat >= 0 - ? QFontEngineGlyphCache::Type(textItem->fontEngine()->glyphFormat) - : d->glyphCacheType; - if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { + QFontEngine::GlyphFormat glyphFormat = fontEngine->glyphFormat != QFontEngine::Format_None + ? fontEngine->glyphFormat : d->glyphCacheFormat; + if (glyphFormat == QFontEngine::Format_A32) { if (d->device->context()->format().alphaBufferSize() > 0 || s->matrix.type() > QTransform::TxTranslate || (s->composition_mode != QPainter::CompositionMode_Source && s->composition_mode != QPainter::CompositionMode_SourceOver)) { - glyphType = QFontEngineGlyphCache::Raster_A8; + glyphFormat = QFontEngine::Format_A8; } } - d->drawCachedGlyphs(glyphType, textItem); + d->drawCachedGlyphs(glyphFormat, textItem); } else { QPaintEngineEx::drawStaticTextItem(textItem); } @@ -1483,17 +1482,15 @@ void QOpenGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &text QTransform::TransformationType txtype = s->matrix.type(); - QFontEngineGlyphCache::Type glyphType = ti.fontEngine->glyphFormat >= 0 - ? QFontEngineGlyphCache::Type(ti.fontEngine->glyphFormat) - : d->glyphCacheType; + QFontEngine::GlyphFormat glyphFormat = ti.fontEngine->glyphFormat != QFontEngine::Format_None + ? ti.fontEngine->glyphFormat : d->glyphCacheFormat; - - if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { + if (glyphFormat == QFontEngine::Format_A32) { if (d->device->context()->format().alphaBufferSize() > 0 || txtype > QTransform::TxTranslate || (state()->composition_mode != QPainter::CompositionMode_Source && state()->composition_mode != QPainter::CompositionMode_SourceOver)) { - glyphType = QFontEngineGlyphCache::Raster_A8; + glyphFormat = QFontEngine::Format_A8; } } @@ -1512,7 +1509,7 @@ void QOpenGL2PaintEngineEx::drawTextItem(const QPointF &p, const QTextItem &text staticTextItem.numGlyphs = glyphs.size(); staticTextItem.glyphPositions = positions.data(); - d->drawCachedGlyphs(glyphType, &staticTextItem); + d->drawCachedGlyphs(glyphFormat, &staticTextItem); } return; } @@ -1537,7 +1534,7 @@ namespace { QSize cacheSize; QOpenGL2PEXVertexArray vertexCoordinateArray; QOpenGL2PEXVertexArray textureCoordinateArray; - QFontEngineGlyphCache::Type glyphType; + QFontEngine::GlyphFormat glyphFormat; int cacheSerialNumber; }; @@ -1572,7 +1569,7 @@ bool QOpenGL2PaintEngineEx::shouldDrawCachedGlyphs(QFontEngine *fontEngine, cons return QPaintEngineEx::shouldDrawCachedGlyphs(fontEngine, t); } -void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, +void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngine::GlyphFormat glyphFormat, QStaticTextItem *staticTextItem) { Q_Q(QOpenGL2PaintEngineEx); @@ -1596,9 +1593,9 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type } QOpenGLTextureGlyphCache *cache = - (QOpenGLTextureGlyphCache *) fe->glyphCache(cacheKey, glyphType, glyphCacheTransform); - if (!cache || cache->cacheType() != glyphType || cache->contextGroup() == 0) { - cache = new QOpenGLTextureGlyphCache(glyphType, glyphCacheTransform); + (QOpenGLTextureGlyphCache *) fe->glyphCache(cacheKey, glyphFormat, glyphCacheTransform); + if (!cache || cache->glyphFormat() != glyphFormat || cache->contextGroup() == 0) { + cache = new QOpenGLTextureGlyphCache(glyphFormat, glyphCacheTransform); fe->setGlyphCache(cacheKey, cache); recreateVertexArrays = true; } @@ -1611,7 +1608,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type recreateVertexArrays = true; } else { QOpenGLStaticTextUserData *userData = static_cast<QOpenGLStaticTextUserData *>(staticTextItem->userData()); - if (userData->glyphType != glyphType) { + if (userData->glyphFormat != glyphFormat) { recreateVertexArrays = true; } else if (userData->cacheSerialNumber != cache->serialNumber()) { recreateVertexArrays = true; @@ -1636,12 +1633,12 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type if (cache->width() == 0 || cache->height() == 0) return; - if (glyphType == QFontEngineGlyphCache::Raster_ARGB) + if (glyphFormat == QFontEngine::Format_ARGB) transferMode(ImageArrayDrawingMode); else transferMode(TextDrawingMode); - int margin = fe->glyphMargin(glyphType); + int margin = fe->glyphMargin(glyphFormat); GLfloat dx = 1.0 / cache->width(); GLfloat dy = 1.0 / cache->height(); @@ -1663,7 +1660,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type userData = static_cast<QOpenGLStaticTextUserData*>(staticTextItem->userData()); } - userData->glyphType = glyphType; + userData->glyphFormat = glyphFormat; userData->cacheSerialNumber = cache->serialNumber(); // Use cache if backend optimizations is turned on @@ -1735,7 +1732,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type #endif } - if (glyphType != QFontEngineGlyphCache::Raster_ARGB || recreateVertexArrays) { + if (glyphFormat != QFontEngine::Format_ARGB || recreateVertexArrays) { setVertexAttributePointer(QT_VERTEX_COORDS_ATTR, (GLfloat*)vertexCoordinates->data()); setVertexAttributePointer(QT_TEXTURE_COORDS_ATTR, (GLfloat*)textureCoordinates->data()); } @@ -1748,7 +1745,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type QBrush pensBrush = q->state()->pen.brush(); setBrush(pensBrush); - if (glyphType == QFontEngineGlyphCache::Raster_RGBMask) { + if (glyphFormat == QFontEngine::Format_A32) { // Subpixel antialiasing without gamma correction @@ -1821,7 +1818,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type glBlendFunc(GL_ONE, GL_ONE); } compositionModeDirty = true; - } else if (glyphType == QFontEngineGlyphCache::Raster_ARGB) { + } else if (glyphFormat == QFontEngine::Format_ARGB) { currentBrush = noBrush; shaderManager->setSrcPixelType(QOpenGLEngineShaderManager::ImageSrc); if (prepareForCachedGlyphDraw(*cache)) @@ -1836,7 +1833,7 @@ void QOpenGL2PaintEngineExPrivate::drawCachedGlyphs(QFontEngineGlyphCache::Type QOpenGLTextureGlyphCache::FilterMode filterMode = (s->matrix.type() > QTransform::TxTranslate)?QOpenGLTextureGlyphCache::Linear:QOpenGLTextureGlyphCache::Nearest; if (lastMaskTextureUsed != cache->texture() || cache->filterMode() != filterMode) { - if (glyphType == QFontEngineGlyphCache::Raster_ARGB) + if (glyphFormat == QFontEngine::Format_ARGB) funcs.glActiveTexture(GL_TEXTURE0 + QT_IMAGE_TEXTURE_UNIT); else funcs.glActiveTexture(GL_TEXTURE0 + QT_MASK_TEXTURE_UNIT); @@ -2012,12 +2009,12 @@ bool QOpenGL2PaintEngineEx::begin(QPaintDevice *pdev) glDisable(GL_DEPTH_TEST); glDisable(GL_SCISSOR_TEST); - d->glyphCacheType = QFontEngineGlyphCache::Raster_A8; + d->glyphCacheFormat = QFontEngine::Format_A8; #ifndef QT_OPENGL_ES_2 if (!QOpenGLFunctions::isES()) { glDisable(GL_MULTISAMPLE); - d->glyphCacheType = QFontEngineGlyphCache::Raster_RGBMask; + d->glyphCacheFormat = QFontEngine::Format_A32; d->multisamplingAlwaysEnabled = false; } else #endif // QT_OPENGL_ES_2 diff --git a/src/gui/opengl/qopenglpaintengine_p.h b/src/gui/opengl/qopenglpaintengine_p.h index d51f0e5256..4f0e2e52a4 100644 --- a/src/gui/opengl/qopenglpaintengine_p.h +++ b/src/gui/opengl/qopenglpaintengine_p.h @@ -212,7 +212,7 @@ public: void drawTexture(const QOpenGLRect& dest, const QOpenGLRect& src, const QSize &textureSize, bool opaque, bool pattern = false); void drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, QPainter::PixmapFragmentHints hints); - void drawCachedGlyphs(QFontEngineGlyphCache::Type glyphType, QStaticTextItem *staticTextItem); + void drawCachedGlyphs(QFontEngine::GlyphFormat glyphFormat, QStaticTextItem *staticTextItem); // Calls glVertexAttributePointer if the pointer has changed inline void setVertexAttributePointer(unsigned int arrayIndex, const GLfloat *pointer); @@ -267,7 +267,7 @@ public: int width, height; QOpenGLContext *ctx; EngineMode mode; - QFontEngineGlyphCache::Type glyphCacheType; + QFontEngine::GlyphFormat glyphCacheFormat; bool vertexAttributeArraysEnabledState[QT_GL_VERTEX_ARRAY_TRACKED_COUNT]; diff --git a/src/gui/opengl/qopengltextureglyphcache.cpp b/src/gui/opengl/qopengltextureglyphcache.cpp index 0d9a2359bd..ba1fa8f486 100644 --- a/src/gui/opengl/qopengltextureglyphcache.cpp +++ b/src/gui/opengl/qopengltextureglyphcache.cpp @@ -51,8 +51,8 @@ QT_BEGIN_NAMESPACE QBasicAtomicInt qopengltextureglyphcache_serial_number = Q_BASIC_ATOMIC_INITIALIZER(1); -QOpenGLTextureGlyphCache::QOpenGLTextureGlyphCache(QFontEngineGlyphCache::Type type, const QTransform &matrix) - : QImageTextureGlyphCache(type, matrix) +QOpenGLTextureGlyphCache::QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat format, const QTransform &matrix) + : QImageTextureGlyphCache(format, matrix) , m_textureResource(0) , pex(0) , m_blitProgram(0) @@ -122,7 +122,7 @@ void QOpenGLTextureGlyphCache::createTextureData(int width, int height) m_textureResource->m_width = width; m_textureResource->m_height = height; - if (m_type == QFontEngineGlyphCache::Raster_RGBMask || m_type == QFontEngineGlyphCache::Raster_ARGB) { + if (m_format == QFontEngine::Format_A32 || m_format == QFontEngine::Format_ARGB) { QVarLengthArray<uchar> data(width * height * 4); for (int i = 0; i < data.size(); ++i) data[i] = 0; diff --git a/src/gui/opengl/qopengltextureglyphcache_p.h b/src/gui/opengl/qopengltextureglyphcache_p.h index d9456db6ed..a361a79de2 100644 --- a/src/gui/opengl/qopengltextureglyphcache_p.h +++ b/src/gui/opengl/qopengltextureglyphcache_p.h @@ -109,7 +109,7 @@ public: class Q_GUI_EXPORT QOpenGLTextureGlyphCache : public QImageTextureGlyphCache { public: - QOpenGLTextureGlyphCache(QFontEngineGlyphCache::Type type, const QTransform &matrix); + QOpenGLTextureGlyphCache(QFontEngine::GlyphFormat glyphFormat, const QTransform &matrix); ~QOpenGLTextureGlyphCache(); virtual void createTextureData(int width, int height); |