From 587444f033cf51251f36321321ae358d187f37f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= <tor.arne.vestbo@digia.com>
Date: Wed, 12 Feb 2014 17:40:53 +0100
Subject: [PATCH] Update glyph cache type/format logic to match qtbase changes

https://codereview.qt-project.org/#change,77791 unified the glyph format
between QFontEngine and QFontEngineGlyphCache.

Now that we're up to date with qtbase, we can unpin the dependency.

Change-Id: Ibcafccb741ce94b454ff7c469804f44fef7fe06f
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
---
 .../scenegraph/qsgdefaultglyphnode_p.cpp      | 67 +++++++++----------
 .../scenegraph/qsgdefaultglyphnode_p_p.h      |  4 +-
 sync.profile                                  |  2 +-
 3 files changed, 35 insertions(+), 38 deletions(-)

diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
index 35c4d1c506..ad0c9dad07 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
+++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
@@ -69,7 +69,7 @@ static inline QVector4D qsg_premultiply(const QVector4D &c, float globalOpacity)
 class QSGTextMaskShader : public QSGMaterialShader
 {
 public:
-    QSGTextMaskShader(QFontEngineGlyphCache::Type cacheType);
+    QSGTextMaskShader(QFontEngine::GlyphFormat glyphFormat);
 
     virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect);
     virtual char const *const *attributeNames() const;
@@ -81,7 +81,7 @@ protected:
     int m_color_id;
     int m_textureScale_id;
 
-    QFontEngineGlyphCache::Type m_cacheType;
+    QFontEngine::GlyphFormat m_glyphFormat;
 };
 
 char const *const *QSGTextMaskShader::attributeNames() const
@@ -90,9 +90,9 @@ char const *const *QSGTextMaskShader::attributeNames() const
     return attr;
 }
 
-QSGTextMaskShader::QSGTextMaskShader(QFontEngineGlyphCache::Type cacheType)
+QSGTextMaskShader::QSGTextMaskShader(QFontEngine::GlyphFormat glyphFormat)
     : QSGMaterialShader(*new QSGMaterialShaderPrivate),
-      m_cacheType(cacheType)
+      m_glyphFormat(glyphFormat)
 {
     setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/scenegraph/shaders/textmask.vert"));
     setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/scenegraph/shaders/textmask.frag"));
@@ -162,8 +162,8 @@ void QSGTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEf
 class QSG8BitTextMaskShader : public QSGTextMaskShader
 {
 public:
-    QSG8BitTextMaskShader(QFontEngineGlyphCache::Type cacheType)
-        : QSGTextMaskShader(cacheType)
+    QSG8BitTextMaskShader(QFontEngine::GlyphFormat glyphFormat)
+        : QSGTextMaskShader(glyphFormat)
     {
         setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/scenegraph/shaders/8bittextmask.frag"));
     }
@@ -186,8 +186,8 @@ void QSG8BitTextMaskShader::updateState(const RenderState &state, QSGMaterial *n
 class QSG24BitTextMaskShader : public QSGTextMaskShader
 {
 public:
-    QSG24BitTextMaskShader(QFontEngineGlyphCache::Type cacheType)
-        : QSGTextMaskShader(cacheType)
+    QSG24BitTextMaskShader(QFontEngine::GlyphFormat glyphFormat)
+        : QSGTextMaskShader(glyphFormat)
         , m_useSRGB(false)
     {
         setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/scenegraph/shaders/24bittextmask.frag"));
@@ -207,7 +207,7 @@ void QSG24BitTextMaskShader::initialize()
     // 0.25 was found to be acceptable error margin by experimentation. On Mac, the gamma is 2.0,
     // but using sRGB looks okay.
     if (strstr((const char *) glGetString(GL_EXTENSIONS), "GL_ARB_framebuffer_sRGB")
-            && m_cacheType == QFontEngineGlyphCache::Raster_RGBMask
+            && m_glyphFormat == QFontEngine::Format_A32
             && qAbs(fontSmoothingGamma() - 2.2) < 0.25) {
         m_useSRGB = true;
     }
@@ -259,8 +259,8 @@ void QSG24BitTextMaskShader::updateState(const RenderState &state, QSGMaterial *
 class QSGStyledTextShader : public QSG8BitTextMaskShader
 {
 public:
-    QSGStyledTextShader(QFontEngineGlyphCache::Type cacheType)
-        : QSG8BitTextMaskShader(cacheType)
+    QSGStyledTextShader(QFontEngine::GlyphFormat glyphFormat)
+        : QSG8BitTextMaskShader(glyphFormat)
     {
         setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/scenegraph/shaders/styledtext.vert"));
         setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/scenegraph/shaders/styledtext.frag"));
@@ -330,27 +330,27 @@ void QSGStyledTextShader::updateState(const RenderState &state,
 class QSGOutlinedTextShader : public QSGStyledTextShader
 {
 public:
-    QSGOutlinedTextShader(QFontEngineGlyphCache::Type cacheType)
-        : QSGStyledTextShader(cacheType)
+    QSGOutlinedTextShader(QFontEngine::GlyphFormat glyphFormat)
+        : QSGStyledTextShader(glyphFormat)
     {
         setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/scenegraph/shaders/outlinedtext.vert"));
         setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/scenegraph/shaders/outlinedtext.frag"));
     }
 };
 
-QSGTextMaskMaterial::QSGTextMaskMaterial(const QRawFont &font, int cacheType)
+QSGTextMaskMaterial::QSGTextMaskMaterial(const QRawFont &font, QFontEngine::GlyphFormat glyphFormat)
     : m_texture(0)
     , m_glyphCache(0)
     , m_font(font)
 {
-    init(cacheType);
+    init(glyphFormat);
 }
 
 QSGTextMaskMaterial::~QSGTextMaskMaterial()
 {
 }
 
-void QSGTextMaskMaterial::init(int cacheType)
+void QSGTextMaskMaterial::init(QFontEngine::GlyphFormat glyphFormat)
 {
     Q_ASSERT(m_font.isValid());
 
@@ -367,17 +367,14 @@ void QSGTextMaskMaterial::init(int cacheType)
 
     QRawFontPrivate *fontD = QRawFontPrivate::get(m_font);
     if (fontD->fontEngine != 0) {
-        if (cacheType < 0) {
-            cacheType = fontD->fontEngine->glyphFormat < 0
-                        ? QFontEngineGlyphCache::Raster_RGBMask
-                        : fontD->fontEngine->glyphFormat;
+        if (glyphFormat == QFontEngine::Format_None) {
+            glyphFormat = fontD->fontEngine->glyphFormat != QFontEngine::Format_None
+                        ? fontD->fontEngine->glyphFormat
+                        : QFontEngine::Format_A32;
         }
-        m_glyphCache = fontD->fontEngine->glyphCache(ctx,
-                                                     QFontEngineGlyphCache::Type(cacheType),
-                                                     QTransform());
-        if (!m_glyphCache || int(m_glyphCache->cacheType()) != cacheType) {
-            m_glyphCache = new QOpenGLTextureGlyphCache(QFontEngineGlyphCache::Type(cacheType),
-                                                        QTransform());
+        m_glyphCache = fontD->fontEngine->glyphCache(ctx, glyphFormat, QTransform());
+        if (!m_glyphCache || int(m_glyphCache->glyphFormat()) != glyphFormat) {
+            m_glyphCache = new QOpenGLTextureGlyphCache(glyphFormat, QTransform());
             fontD->fontEngine->setGlyphCache(ctx, m_glyphCache.data());
             QSGRenderContext *sg = QSGRenderContext::from(ctx);
             Q_ASSERT(sg);
@@ -406,7 +403,7 @@ void QSGTextMaskMaterial::populate(const QPointF &p,
                     fixedPointPositions.data());
     cache->fillInPendingGlyphs();
 
-    int margin = fontD->fontEngine->glyphMargin(cache->cacheType());
+    int margin = fontD->fontEngine->glyphMargin(cache->glyphFormat());
 
     Q_ASSERT(geometry->indexType() == GL_UNSIGNED_SHORT);
     geometry->allocate(glyphIndexes.size() * 4, glyphIndexes.size() * 6);
@@ -461,7 +458,7 @@ void QSGTextMaskMaterial::populate(const QPointF &p,
 QSGMaterialType *QSGTextMaskMaterial::type() const
 {
     static QSGMaterialType rgb, gray;
-    return glyphCache()->cacheType() == QFontEngineGlyphCache::Raster_RGBMask ? &rgb : &gray;
+    return glyphCache()->glyphFormat() == QFontEngine::Format_A32 ? &rgb : &gray;
 }
 
 QOpenGLTextureGlyphCache *QSGTextMaskMaterial::glyphCache() const
@@ -471,10 +468,10 @@ QOpenGLTextureGlyphCache *QSGTextMaskMaterial::glyphCache() const
 
 QSGMaterialShader *QSGTextMaskMaterial::createShader() const
 {
-    QFontEngineGlyphCache::Type type = glyphCache()->cacheType();
-    return type == QFontEngineGlyphCache::Raster_RGBMask
-           ? (QSGMaterialShader *) new QSG24BitTextMaskShader(type)
-           : (QSGMaterialShader *) new QSG8BitTextMaskShader(type);
+    QFontEngine::GlyphFormat glyphFormat = glyphCache()->glyphFormat();
+    return glyphFormat == QFontEngine::Format_A32
+           ? (QSGMaterialShader *) new QSG24BitTextMaskShader(glyphFormat)
+           : (QSGMaterialShader *) new QSG8BitTextMaskShader(glyphFormat);
 }
 
 static inline int qsg_colorDiff(const QVector4D &a, const QVector4D &b)
@@ -530,7 +527,7 @@ int QSGTextMaskMaterial::cacheTextureHeight() const
 
 
 QSGStyledTextMaterial::QSGStyledTextMaterial(const QRawFont &font)
-    : QSGTextMaskMaterial(font, QFontEngineGlyphCache::Raster_A8)
+    : QSGTextMaskMaterial(font, QFontEngine::Format_A8)
 {
 }
 
@@ -542,7 +539,7 @@ QSGMaterialType *QSGStyledTextMaterial::type() const
 
 QSGMaterialShader *QSGStyledTextMaterial::createShader() const
 {
-    return new QSGStyledTextShader(glyphCache()->cacheType());
+    return new QSGStyledTextShader(glyphCache()->glyphFormat());
 }
 
 int QSGStyledTextMaterial::compare(const QSGMaterial *o) const
@@ -572,7 +569,7 @@ QSGMaterialType *QSGOutlinedTextMaterial::type() const
 
 QSGMaterialShader *QSGOutlinedTextMaterial::createShader() const
 {
-    return new QSGOutlinedTextShader(glyphCache()->cacheType());
+    return new QSGOutlinedTextShader(glyphCache()->glyphFormat());
 }
 
 QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h b/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h
index 5143921a1e..4e197b9d1f 100644
--- a/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h
+++ b/src/quick/scenegraph/qsgdefaultglyphnode_p_p.h
@@ -59,7 +59,7 @@ class Geometry;
 class QSGTextMaskMaterial: public QSGMaterial
 {
 public:
-    QSGTextMaskMaterial(const QRawFont &font, int cacheType = -1);
+    QSGTextMaskMaterial(const QRawFont &font, QFontEngine::GlyphFormat glyphFormat = QFontEngine::Format_None);
     virtual ~QSGTextMaskMaterial();
 
     virtual QSGMaterialType *type() const;
@@ -84,7 +84,7 @@ public:
                   const QMargins &margins = QMargins(0, 0, 0, 0));
 
 private:
-    void init(int cacheType);
+    void init(QFontEngine::GlyphFormat glyphFormat);
 
     QSGPlainTexture *m_texture;
     QExplicitlySharedDataPointer<QFontEngineGlyphCache> m_glyphCache;
diff --git a/sync.profile b/sync.profile
index bd75033aaa..4f4e767129 100644
--- a/sync.profile
+++ b/sync.profile
@@ -19,6 +19,6 @@
 #   - an empty string to use the same branch under test (dependencies will become "refs/heads/master" if we are in the master branch)
 #
 %dependencies = (
-        "qtbase" => "30fd22b9574def54726e7b193127cc0c901c1b4c",
+        "qtbase" => "",
         "qtxmlpatterns" => "",
 );
-- 
GitLab