}
if (!invalidatedGlyphs.isEmpty()) {
- QLinkedList<QSGDistanceFieldGlyphNode *>::iterator it = m_registeredNodes.begin();
+ QLinkedList<QSGDistanceFieldGlyphConsumer *>::iterator it = m_registeredNodes.begin();
while (it != m_registeredNodes.end()) {
(*it)->invalidateGlyphs(invalidatedGlyphs);
++it;
}
if (!invalidatedGlyphs.isEmpty()) {
- QLinkedList<QSGDistanceFieldGlyphNode *>::iterator it = m_registeredNodes.begin();
+ QLinkedList<QSGDistanceFieldGlyphConsumer*>::iterator it = m_registeredNodes.begin();
while (it != m_registeredNodes.end()) {
(*it)->invalidateGlyphs(invalidatedGlyphs);
++it;
}
}
-
QT_END_NAMESPACE
QQuickItem *m_ownerElement;
};
+class Q_QUICK_EXPORT QSGDistanceFieldGlyphConsumer
+{
+public:
+ virtual ~QSGDistanceFieldGlyphConsumer() {}
+
+ virtual void invalidateGlyphs(const QVector<quint32> &glyphs) = 0;
+};
+
class Q_QUICK_EXPORT QSGDistanceFieldGlyphCache
{
public:
void update();
- void registerGlyphNode(QSGDistanceFieldGlyphNode *node) { m_registeredNodes.append(node); }
- void unregisterGlyphNode(QSGDistanceFieldGlyphNode *node) { m_registeredNodes.removeOne(node); }
+ void registerGlyphNode(QSGDistanceFieldGlyphConsumer *node) { m_registeredNodes.append(node); }
+ void unregisterGlyphNode(QSGDistanceFieldGlyphConsumer *node) { m_registeredNodes.removeOne(node); }
virtual void registerOwnerElement(QQuickItem *ownerElement);
virtual void unregisterOwnerElement(QQuickItem *ownerElement);
QList<Texture> m_textures;
QHash<glyph_t, GlyphData> m_glyphsData;
QDataBuffer<glyph_t> m_pendingGlyphs;
- QLinkedList<QSGDistanceFieldGlyphNode*> m_registeredNodes;
+ QLinkedList<QSGDistanceFieldGlyphConsumer*> m_registeredNodes;
static Texture s_emptyTexture;
};
QSGContextPrivate()
: gl(0)
, distanceFieldCacheManager(0)
+ #ifndef QT_OPENGL_ES
+ , distanceFieldAntialiasing(QSGGlyphNode::HighQualitySubPixelAntialiasing)
+ #else
+ , distanceFieldAntialiasing(QSGGlyphNode::GrayAntialiasing)
+ #endif
, flashMode(qmlFlashMode())
, distanceFieldDisabled(qmlDisableDistanceField())
{
QSGDistanceFieldGlyphCacheManager *distanceFieldCacheManager;
+ QSGDistanceFieldGlyphNode::AntialiasingMode distanceFieldAntialiasing;
+
bool flashMode;
float renderAlpha;
bool distanceFieldDisabled;
QSGContext::QSGContext(QObject *parent) :
QObject(*(new QSGContextPrivate), parent)
{
+ Q_D(QSGContext);
+ // ### Do something with these before final release...
+ static bool doSubpixel = qApp->arguments().contains(QLatin1String("--text-subpixel-antialiasing"));
+ static bool doLowQualSubpixel = qApp->arguments().contains(QLatin1String("--text-subpixel-antialiasing-lowq"));
+ static bool doGray = qApp->arguments().contains(QLatin1String("--text-gray-antialiasing"));
+ if (doSubpixel)
+ d->distanceFieldAntialiasing = QSGGlyphNode::HighQualitySubPixelAntialiasing;
+ else if (doLowQualSubpixel)
+ d->distanceFieldAntialiasing = QSGGlyphNode::LowQualitySubPixelAntialiasing;
+ else if (doGray)
+ d->distanceFieldAntialiasing = QSGGlyphNode::GrayAntialiasing;
}
/*!
Factory function for scene graph backends of the distance-field glyph cache.
*/
-QSGDistanceFieldGlyphCache *QSGContext::createDistanceFieldGlyphCache(const QRawFont &font)
+QSGDistanceFieldGlyphCache *QSGContext::distanceFieldGlyphCache(const QRawFont &font)
{
Q_D(QSGContext);
- QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
- if (platformIntegration != 0
- && platformIntegration->hasCapability(QPlatformIntegration::SharedGraphicsCache)) {
- QFontEngine *fe = QRawFontPrivate::get(font)->fontEngine;
- if (!fe->faceId().filename.isEmpty()) {
- QByteArray keyName = fe->faceId().filename;
- if (font.style() != QFont::StyleNormal)
- keyName += QByteArray(" I");
- if (font.weight() != QFont::Normal)
- keyName += " " + QByteArray::number(font.weight());
- keyName += QByteArray(" DF");
- QPlatformSharedGraphicsCache *sharedGraphicsCache =
- platformIntegration->createPlatformSharedGraphicsCache(keyName);
-
- if (sharedGraphicsCache != 0) {
- sharedGraphicsCache->ensureCacheInitialized(keyName,
- QPlatformSharedGraphicsCache::OpenGLTexture,
- QPlatformSharedGraphicsCache::Alpha8);
-
- return new QSGSharedDistanceFieldGlyphCache(keyName,
- sharedGraphicsCache,
- d->distanceFieldCacheManager,
- glContext(),
- font);
+ if (!d->distanceFieldCacheManager)
+ d->distanceFieldCacheManager = new QSGDistanceFieldGlyphCacheManager;
+
+ QSGDistanceFieldGlyphCache *cache = d->distanceFieldCacheManager->cache(font);
+ if (!cache) {
+ QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
+ if (platformIntegration != 0
+ && platformIntegration->hasCapability(QPlatformIntegration::SharedGraphicsCache)) {
+ QFontEngine *fe = QRawFontPrivate::get(font)->fontEngine;
+ if (!fe->faceId().filename.isEmpty()) {
+ QByteArray keyName = fe->faceId().filename;
+ if (font.style() != QFont::StyleNormal)
+ keyName += QByteArray(" I");
+ if (font.weight() != QFont::Normal)
+ keyName += " " + QByteArray::number(font.weight());
+ keyName += QByteArray(" DF");
+ QPlatformSharedGraphicsCache *sharedGraphicsCache =
+ platformIntegration->createPlatformSharedGraphicsCache(keyName);
+
+ if (sharedGraphicsCache != 0) {
+ sharedGraphicsCache->ensureCacheInitialized(keyName,
+ QPlatformSharedGraphicsCache::OpenGLTexture,
+ QPlatformSharedGraphicsCache::Alpha8);
+
+ cache = new QSGSharedDistanceFieldGlyphCache(keyName,
+ sharedGraphicsCache,
+ d->distanceFieldCacheManager,
+ glContext(),
+ font);
+ }
}
}
+ if (!cache)
+ cache = new QSGDefaultDistanceFieldGlyphCache(d->distanceFieldCacheManager, glContext(), font);
+ d->distanceFieldCacheManager->insertCache(font, cache);
}
-
- return new QSGDefaultDistanceFieldGlyphCache(d->distanceFieldCacheManager, glContext(), font);
+ return cache;
}
/*!
{
Q_D(QSGContext);
- // ### Do something with these before final release...
- static bool doSubpixel = qApp->arguments().contains(QLatin1String("--text-subpixel-antialiasing"));
- static bool doLowQualSubpixel = qApp->arguments().contains(QLatin1String("--text-subpixel-antialiasing-lowq"));
- static bool doGray = qApp->arguments().contains(QLatin1String("--text-gray-antialiasing"));
-
if (d->distanceFieldDisabled) {
return new QSGDefaultGlyphNode;
} else {
- if (!d->distanceFieldCacheManager) {
- d->distanceFieldCacheManager = new QSGDistanceFieldGlyphCacheManager(this);
- if (doSubpixel)
- d->distanceFieldCacheManager->setDefaultAntialiasingMode(QSGGlyphNode::HighQualitySubPixelAntialiasing);
- else if (doLowQualSubpixel)
- d->distanceFieldCacheManager->setDefaultAntialiasingMode(QSGGlyphNode::LowQualitySubPixelAntialiasing);
- else if (doGray)
- d->distanceFieldCacheManager->setDefaultAntialiasingMode(QSGGlyphNode::GrayAntialiasing);
- }
-
- QSGGlyphNode *node = new QSGDistanceFieldGlyphNode(d->distanceFieldCacheManager);
+ QSGDistanceFieldGlyphNode *node = new QSGDistanceFieldGlyphNode(this);
+ node->setPreferredAntialiasingMode(d->distanceFieldAntialiasing);
return node;
}
}
virtual void renderNextFrame(QSGRenderer *renderer, GLuint fboId);
- virtual QSGDistanceFieldGlyphCache *createDistanceFieldGlyphCache(const QRawFont &font);
+ virtual QSGDistanceFieldGlyphCache *distanceFieldGlyphCache(const QRawFont &font);
virtual QSGRectangleNode *createRectangleNode();
virtual QSGImageNode *createImageNode();
QT_BEGIN_NAMESPACE
-QSGDistanceFieldGlyphNode::QSGDistanceFieldGlyphNode(QSGDistanceFieldGlyphCacheManager *cacheManager)
- : m_material(0)
- , m_glyph_cacheManager(cacheManager)
+QSGDistanceFieldGlyphNode::QSGDistanceFieldGlyphNode(QSGContext *context)
+ : m_context(context)
+ , m_material(0)
, m_glyph_cache(0)
, m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 0)
, m_style(QQuickText::Normal)
{
m_geometry.setDrawingMode(GL_TRIANGLES);
setGeometry(&m_geometry);
- setPreferredAntialiasingMode(cacheManager->defaultAntialiasingMode());
setFlag(UsePreprocess);
#ifdef QML_RUNTIME_TESTING
description = QLatin1String("glyphs");
m_glyphs = glyphs;
QSGDistanceFieldGlyphCache *oldCache = m_glyph_cache;
- m_glyph_cache = m_glyph_cacheManager->cache(m_glyphs.rawFont());
+ m_glyph_cache = m_context->distanceFieldGlyphCache(m_glyphs.rawFont());
if (m_glyph_cache != oldCache) {
Q_ASSERT(ownerElement() != 0);
if (oldCache) {
while (ite != glyphsInOtherTextures.constEnd()) {
QHash<const QSGDistanceFieldGlyphCache::Texture *, QSGDistanceFieldGlyphNode *>::iterator subIt = m_subNodes.find(ite.key());
if (subIt == m_subNodes.end()) {
- QSGDistanceFieldGlyphNode *subNode = new QSGDistanceFieldGlyphNode(m_glyph_cacheManager);
+ QSGDistanceFieldGlyphNode *subNode = new QSGDistanceFieldGlyphNode(m_context);
subNode->setOwnerElement(m_ownerElement);
subNode->setColor(m_color);
subNode->setStyle(m_style);
QT_BEGIN_NAMESPACE
+class QSGContext;
class QSGDistanceFieldGlyphCacheManager;
class QSGDistanceFieldTextMaterial;
-class QSGDistanceFieldGlyphNode: public QSGGlyphNode
+class QSGDistanceFieldGlyphNode: public QSGGlyphNode, public QSGDistanceFieldGlyphConsumer
{
public:
- QSGDistanceFieldGlyphNode(QSGDistanceFieldGlyphCacheManager *cacheManager);
+ QSGDistanceFieldGlyphNode(QSGContext *context);
~QSGDistanceFieldGlyphNode();
virtual QPointF baseLine() const { return m_baseLine; }
QColor m_color;
QPointF m_baseLine;
+ QSGContext *m_context;
QSGDistanceFieldTextMaterial *m_material;
QPointF m_originalPosition;
QPointF m_position;
QGlyphRun m_glyphs;
- QSGDistanceFieldGlyphCacheManager *m_glyph_cacheManager;
QSGDistanceFieldGlyphCache *m_glyph_cache;
QSGGeometry m_geometry;
QQuickText::TextStyle m_style;
QT_BEGIN_NAMESPACE
-class QSGDistanceFieldTextMaterial: public QSGMaterial
+class Q_QUICK_EXPORT QSGDistanceFieldTextMaterial: public QSGMaterial
{
public:
QSGDistanceFieldTextMaterial();
qreal m_fontScale;
};
-class QSGDistanceFieldStyledTextMaterial : public QSGDistanceFieldTextMaterial
+class Q_QUICK_EXPORT QSGDistanceFieldStyledTextMaterial : public QSGDistanceFieldTextMaterial
{
public:
QSGDistanceFieldStyledTextMaterial();
QColor m_styleColor;
};
-class QSGDistanceFieldOutlineTextMaterial : public QSGDistanceFieldStyledTextMaterial
+class Q_QUICK_EXPORT QSGDistanceFieldOutlineTextMaterial : public QSGDistanceFieldStyledTextMaterial
{
public:
QSGDistanceFieldOutlineTextMaterial();
virtual QSGMaterialShader *createShader() const;
};
-class QSGDistanceFieldShiftedStyleTextMaterial : public QSGDistanceFieldStyledTextMaterial
+class Q_QUICK_EXPORT QSGDistanceFieldShiftedStyleTextMaterial : public QSGDistanceFieldStyledTextMaterial
{
public:
QSGDistanceFieldShiftedStyleTextMaterial();
QPointF m_shift;
};
-class QSGHiQSubPixelDistanceFieldTextMaterial : public QSGDistanceFieldTextMaterial
+class Q_QUICK_EXPORT QSGHiQSubPixelDistanceFieldTextMaterial : public QSGDistanceFieldTextMaterial
{
public:
virtual QSGMaterialType *type() const;
virtual QSGMaterialShader *createShader() const;
};
-class QSGLoQSubPixelDistanceFieldTextMaterial : public QSGDistanceFieldTextMaterial
+class Q_QUICK_EXPORT QSGLoQSubPixelDistanceFieldTextMaterial : public QSGDistanceFieldTextMaterial
{
public:
virtual QSGMaterialType *type() const;
return range / glyphScale;
}
-QSGDistanceFieldGlyphCacheManager::QSGDistanceFieldGlyphCacheManager(QSGContext *c)
- : sgCtx(c)
- , m_threshold_func(defaultThresholdFunc)
+QSGDistanceFieldGlyphCacheManager::QSGDistanceFieldGlyphCacheManager()
+ : m_threshold_func(defaultThresholdFunc)
, m_antialiasingSpread_func(defaultAntialiasingSpreadFunc)
{
-#ifndef QT_OPENGL_ES
- m_defaultAntialiasingMode = QSGGlyphNode::HighQualitySubPixelAntialiasing;
-#else
- m_defaultAntialiasingMode = QSGGlyphNode::GrayAntialiasing;
-#endif
}
QSGDistanceFieldGlyphCacheManager::~QSGDistanceFieldGlyphCacheManager()
.arg(font.styleName())
.arg(font.weight())
.arg(font.style());
- QHash<QString , QSGDistanceFieldGlyphCache *>::iterator cache = m_caches.find(key);
- if (cache == m_caches.end())
- cache = m_caches.insert(key, sgCtx->createDistanceFieldGlyphCache(font));
- return cache.value();
+ return m_caches.value(key, 0);
+}
+
+void QSGDistanceFieldGlyphCacheManager::insertCache(const QRawFont &font, QSGDistanceFieldGlyphCache *cache)
+{
+ QString key = QString::fromLatin1("%1_%2_%3_%4")
+ .arg(font.familyName())
+ .arg(font.styleName())
+ .arg(font.weight())
+ .arg(font.style());
+ m_caches.insert(key, cache);
}
QT_END_NAMESPACE
class Q_QUICK_EXPORT QSGDistanceFieldGlyphCacheManager
{
public:
- QSGDistanceFieldGlyphCacheManager(QSGContext *c);
+ QSGDistanceFieldGlyphCacheManager();
~QSGDistanceFieldGlyphCacheManager();
QSGDistanceFieldGlyphCache *cache(const QRawFont &font);
-
- QSGGlyphNode::AntialiasingMode defaultAntialiasingMode() const { return m_defaultAntialiasingMode; }
- void setDefaultAntialiasingMode(QSGGlyphNode::AntialiasingMode mode) { m_defaultAntialiasingMode = mode; }
+ void insertCache(const QRawFont &font, QSGDistanceFieldGlyphCache *cache);
ThresholdFunc thresholdFunc() const { return m_threshold_func; }
void setThresholdFunc(ThresholdFunc func) { m_threshold_func = func; }
private:
QHash<QString, QSGDistanceFieldGlyphCache *> m_caches;
- QSGContext *sgCtx;
-
QSGGlyphNode::AntialiasingMode m_defaultAntialiasingMode;
ThresholdFunc m_threshold_func;
AntialiasingSpreadFunc m_antialiasingSpread_func;