aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@digia.com>2013-05-18 08:24:45 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-22 14:49:10 +0200
commit81a9dd71b9ce60ab4cae629b67d6f26ebdeb19db (patch)
tree4c85a2ca61bef3f7772af33aba45a62663d6a8b1 /src/quick
parentcc36ce673545131047595c79ded1f465ec601780 (diff)
Avoid using QColor::xxxF functions.
In our usecase, the color is always used as a float so using QColor (which is ushort) internally adds a lot of pointless conversion. Enough so that it shows up in profiles as 1-2% each. Not a lot, but easy to fix. The compare function is also somewhat simplified. For colors we're primarily searching for equallity. If that fails, we just need to provide consistent values, so use the address instead of doing any fancy calculation. Change-Id: Icae7e78ed767e802c137bab7fcacff66e9a4bc66 Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
Diffstat (limited to 'src/quick')
-rw-r--r--src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp39
-rw-r--r--src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h12
2 files changed, 22 insertions, 29 deletions
diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp
index 86c3356d58..bdbce6165b 100644
--- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp
+++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp
@@ -144,8 +144,7 @@ void QSGDistanceFieldTextMaterialShader::updateState(const RenderState &state, Q
if (oldMaterial == 0
|| material->color() != oldMaterial->color()
|| state.isOpacityDirty()) {
- QColor c = material->color();
- QVector4D color(c.redF(), c.greenF(), c.blueF(), c.alphaF());
+ QVector4D color = material->color();
color *= state.opacity();
program()->setUniformValue(m_color_id, color);
}
@@ -206,10 +205,10 @@ QSGMaterialType *QSGDistanceFieldTextMaterial::type() const
void QSGDistanceFieldTextMaterial::setColor(const QColor &color)
{
- m_color = QColor::fromRgbF(color.redF() * color.alphaF(),
- color.greenF() * color.alphaF(),
- color.blueF() * color.alphaF(),
- color.alphaF());
+ m_color = QVector4D(color.redF() * color.alphaF(),
+ color.greenF() * color.alphaF(),
+ color.blueF() * color.alphaF(),
+ color.alphaF());
}
QSGMaterialShader *QSGDistanceFieldTextMaterial::createShader() const
@@ -239,10 +238,8 @@ int QSGDistanceFieldTextMaterial::compare(const QSGMaterial *o) const
if (m_fontScale != other->m_fontScale) {
return int(other->m_fontScale < m_fontScale) - int(m_fontScale < other->m_fontScale);
}
- QRgb c1 = m_color.rgba();
- QRgb c2 = other->m_color.rgba();
- if (c1 != c2)
- return int(c2 < c1) - int(c1 < c2);
+ if (m_color != other->m_color)
+ return &m_color < &other->m_color ? -1 : 1;
int t0 = m_texture ? m_texture->textureId : -1;
int t1 = other->m_texture ? other->m_texture->textureId : -1;
return t0 - t1;
@@ -284,8 +281,7 @@ void DistanceFieldStyledTextMaterialShader::updateState(const RenderState &state
if (oldMaterial == 0
|| material->styleColor() != oldMaterial->styleColor()
|| (state.isOpacityDirty())) {
- QColor c = material->styleColor();
- QVector4D color(c.redF(), c.greenF(), c.blueF(), c.alphaF());
+ QVector4D color = material->styleColor();
color *= state.opacity();
program()->setUniformValue(m_styleColor_id, color);
}
@@ -302,21 +298,18 @@ QSGDistanceFieldStyledTextMaterial::~QSGDistanceFieldStyledTextMaterial()
void QSGDistanceFieldStyledTextMaterial::setStyleColor(const QColor &color)
{
- m_styleColor = QColor::fromRgbF(color.redF() * color.alphaF(),
- color.greenF() * color.alphaF(),
- color.blueF() * color.alphaF(),
- color.alphaF());
+ m_styleColor = QVector4D(color.redF() * color.alphaF(),
+ color.greenF() * color.alphaF(),
+ color.blueF() * color.alphaF(),
+ color.alphaF());
}
int QSGDistanceFieldStyledTextMaterial::compare(const QSGMaterial *o) const
{
Q_ASSERT(o && type() == o->type());
const QSGDistanceFieldStyledTextMaterial *other = static_cast<const QSGDistanceFieldStyledTextMaterial *>(o);
- if (m_styleColor != other->m_styleColor) {
- QRgb c1 = m_styleColor.rgba();
- QRgb c2 = other->m_styleColor.rgba();
- return int(c2 < c1) - int(c1 < c2);
- }
+ if (m_styleColor != other->m_color)
+ return &m_styleColor < &other->m_styleColor ? -1 : 1;
return QSGDistanceFieldTextMaterial::compare(o);
}
@@ -657,8 +650,8 @@ void QSGHiQSubPixelDistanceFieldTextMaterialShader::updateState(const RenderStat
QSGDistanceFieldTextMaterial *oldMaterial = static_cast<QSGDistanceFieldTextMaterial *>(oldEffect);
if (oldMaterial == 0 || material->color() != oldMaterial->color()) {
- QColor c = material->color();
- state.context()->functions()->glBlendColor(c.redF(), c.greenF(), c.blueF(), 1.0f);
+ QVector4D c = material->color();
+ state.context()->functions()->glBlendColor(c.x(), c.y(), c.z(), 1.0f);
}
if (oldMaterial == 0 || material->fontScale() != oldMaterial->fontScale())
diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h b/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h
index 7fea8f65dc..54d4146ddb 100644
--- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h
+++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h
@@ -59,7 +59,7 @@ public:
virtual int compare(const QSGMaterial *other) const;
virtual void setColor(const QColor &color);
- const QColor &color() const { return m_color; }
+ const QVector4D &color() const { return m_color; }
void setGlyphCache(QSGDistanceFieldGlyphCache *a) { m_glyph_cache = a; }
QSGDistanceFieldGlyphCache *glyphCache() const { return m_glyph_cache; }
@@ -76,7 +76,7 @@ public:
protected:
QSize m_size;
- QColor m_color;
+ QVector4D m_color;
QSGDistanceFieldGlyphCache *m_glyph_cache;
const QSGDistanceFieldGlyphCache::Texture *m_texture;
qreal m_fontScale;
@@ -93,10 +93,10 @@ public:
virtual int compare(const QSGMaterial *other) const;
void setStyleColor(const QColor &color);
- const QColor &styleColor() const { return m_styleColor; }
+ const QVector4D &styleColor() const { return m_styleColor; }
protected:
- QColor m_styleColor;
+ QVector4D m_styleColor;
};
class Q_QUICK_PRIVATE_EXPORT QSGDistanceFieldOutlineTextMaterial : public QSGDistanceFieldStyledTextMaterial
@@ -130,7 +130,7 @@ class Q_QUICK_PRIVATE_EXPORT QSGHiQSubPixelDistanceFieldTextMaterial : public QS
public:
virtual QSGMaterialType *type() const;
virtual QSGMaterialShader *createShader() const;
- void setColor(const QColor &color) { m_color = color; }
+ void setColor(const QColor &color) { m_color = QVector4D(color.redF(), color.greenF(), color.blueF(), color.alphaF()); }
};
class Q_QUICK_PRIVATE_EXPORT QSGLoQSubPixelDistanceFieldTextMaterial : public QSGDistanceFieldTextMaterial
@@ -138,7 +138,7 @@ class Q_QUICK_PRIVATE_EXPORT QSGLoQSubPixelDistanceFieldTextMaterial : public QS
public:
virtual QSGMaterialType *type() const;
virtual QSGMaterialShader *createShader() const;
- void setColor(const QColor &color) { m_color = color; }
+ void setColor(const QColor &color) { m_color = QVector4D(color.redF(), color.greenF(), color.blueF(), color.alphaF()); }
};
QT_END_NAMESPACE