aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/scenegraph/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/scenegraph/util')
-rw-r--r--src/quick/scenegraph/util/qsgatlastexture.cpp3
-rw-r--r--src/quick/scenegraph/util/qsgdefaultimagenode.cpp29
-rw-r--r--src/quick/scenegraph/util/qsgdefaultimagenode_p.h6
-rw-r--r--src/quick/scenegraph/util/qsgdefaultninepatchnode.cpp52
-rw-r--r--src/quick/scenegraph/util/qsgdefaultninepatchnode_p.h3
-rw-r--r--src/quick/scenegraph/util/qsgdistancefieldutil.cpp24
-rw-r--r--src/quick/scenegraph/util/qsgdistancefieldutil_p.h4
-rw-r--r--src/quick/scenegraph/util/qsgimagenode.cpp29
-rw-r--r--src/quick/scenegraph/util/qsgimagenode.h6
-rw-r--r--src/quick/scenegraph/util/qsgninepatchnode.cpp52
-rw-r--r--src/quick/scenegraph/util/qsgninepatchnode.h4
11 files changed, 96 insertions, 116 deletions
diff --git a/src/quick/scenegraph/util/qsgatlastexture.cpp b/src/quick/scenegraph/util/qsgatlastexture.cpp
index 40c3293c7b..b6abb55bd3 100644
--- a/src/quick/scenegraph/util/qsgatlastexture.cpp
+++ b/src/quick/scenegraph/util/qsgatlastexture.cpp
@@ -117,8 +117,9 @@ QSGTexture *Manager::create(const QImage &image, bool hasAlphaChannel)
if (image.width() < m_atlas_size_limit && image.height() < m_atlas_size_limit) {
if (!m_atlas)
m_atlas = new Atlas(m_atlas_size);
+ // t may be null for atlas allocation failure
t = m_atlas->create(image);
- if (!hasAlphaChannel && t->hasAlphaChannel())
+ if (t && !hasAlphaChannel && t->hasAlphaChannel())
t->setHasAlphaChannel(false);
}
return t;
diff --git a/src/quick/scenegraph/util/qsgdefaultimagenode.cpp b/src/quick/scenegraph/util/qsgdefaultimagenode.cpp
index 6afe591dca..63773887a0 100644
--- a/src/quick/scenegraph/util/qsgdefaultimagenode.cpp
+++ b/src/quick/scenegraph/util/qsgdefaultimagenode.cpp
@@ -173,33 +173,4 @@ bool QSGDefaultImageNode::ownsTexture() const
return m_ownsTexture;
}
-void QSGDefaultImageNode::rebuildGeometry(QSGGeometry *g,
- QSGTexture *texture,
- const QRectF &rect,
- QRectF sourceRect,
- TextureCoordinatesTransformMode texCoordMode)
-{
- if (!texture)
- return;
-
- if (!sourceRect.width() || !sourceRect.height()) {
- QSize ts = texture->textureSize();
- sourceRect = QRectF(0, 0, ts.width(), ts.height());
- }
-
- // Maybe transform the texture coordinates
- if (texCoordMode.testFlag(QSGImageNode::MirrorHorizontally)) {
- float tmp = sourceRect.left();
- sourceRect.setLeft(sourceRect.right());
- sourceRect.setRight(tmp);
- }
- if (texCoordMode.testFlag(QSGImageNode::MirrorVertically)) {
- float tmp = sourceRect.top();
- sourceRect.setTop(sourceRect.bottom());
- sourceRect.setBottom(tmp);
- }
-
- QSGGeometry::updateTexturedRectGeometry(g, rect, texture->convertToNormalizedSourceRect(sourceRect));
-}
-
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgdefaultimagenode_p.h b/src/quick/scenegraph/util/qsgdefaultimagenode_p.h
index eb6c487c18..bb9ebec885 100644
--- a/src/quick/scenegraph/util/qsgdefaultimagenode_p.h
+++ b/src/quick/scenegraph/util/qsgdefaultimagenode_p.h
@@ -85,12 +85,6 @@ public:
void setOwnsTexture(bool owns) override;
bool ownsTexture() const override;
- static void rebuildGeometry(QSGGeometry *g,
- QSGTexture *texture,
- const QRectF &rect,
- QRectF sourceRect,
- TextureCoordinatesTransformMode texCoordMode);
-
private:
QSGGeometry m_geometry;
QSGOpaqueTextureMaterial m_opaque_material;
diff --git a/src/quick/scenegraph/util/qsgdefaultninepatchnode.cpp b/src/quick/scenegraph/util/qsgdefaultninepatchnode.cpp
index e5a53a3617..6023a9af93 100644
--- a/src/quick/scenegraph/util/qsgdefaultninepatchnode.cpp
+++ b/src/quick/scenegraph/util/qsgdefaultninepatchnode.cpp
@@ -81,56 +81,4 @@ void QSGDefaultNinePatchNode::update()
markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial);
}
-void QSGDefaultNinePatchNode::rebuildGeometry(QSGTexture *texture, QSGGeometry *geometry, const QVector4D &padding,
- const QRectF &bounds, qreal dpr)
-{
- if (padding.x() <= 0 && padding.y() <= 0 && padding.z() <= 0 && padding.w() <= 0) {
- geometry->allocate(4, 0);
- QSGGeometry::updateTexturedRectGeometry(geometry, bounds, texture->normalizedTextureSubRect());
- return;
- }
-
- QRectF tc = texture->normalizedTextureSubRect();
- QSize ts = texture->textureSize();
- ts.setHeight(ts.height() / dpr);
- ts.setWidth(ts.width() / dpr);
-
- qreal invtw = tc.width() / ts.width();
- qreal invth = tc.height() / ts.height();
-
- struct Coord { qreal p; qreal t; };
- Coord cx[4] = { { bounds.left(), tc.left() },
- { bounds.left() + padding.x(), tc.left() + padding.x() * invtw },
- { bounds.right() - padding.z(), tc.right() - padding.z() * invtw },
- { bounds.right(), tc.right() }
- };
- Coord cy[4] = { { bounds.top(), tc.top() },
- { bounds.top() + padding.y(), tc.top() + padding.y() * invth },
- { bounds.bottom() - padding.w(), tc.bottom() - padding.w() * invth },
- { bounds.bottom(), tc.bottom() }
- };
-
- geometry->allocate(16, 28);
- QSGGeometry::TexturedPoint2D *v = geometry->vertexDataAsTexturedPoint2D();
- for (int y = 0; y < 4; ++y) {
- for (int x = 0; x < 4; ++x) {
- v->set(cx[x].p, cy[y].p, cx[x].t, cy[y].t);
- ++v;
- }
- }
-
- quint16 *i = geometry->indexDataAsUShort();
- for (int r = 0; r < 3; ++r) {
- if (r > 0)
- *i++ = 4 * r;
- for (int c = 0; c < 4; ++c) {
- i[0] = 4 * r + c;
- i[1] = 4 * r + c + 4;
- i += 2;
- }
- if (r < 2)
- *i++ = 4 * r + 3 + 4;
- }
-}
-
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgdefaultninepatchnode_p.h b/src/quick/scenegraph/util/qsgdefaultninepatchnode_p.h
index 675cf48f47..3752a75ac6 100644
--- a/src/quick/scenegraph/util/qsgdefaultninepatchnode_p.h
+++ b/src/quick/scenegraph/util/qsgdefaultninepatchnode_p.h
@@ -70,9 +70,6 @@ public:
void setPadding(qreal left, qreal top, qreal right, qreal bottom) override;
void update() override;
- static void rebuildGeometry(QSGTexture *texture, QSGGeometry *geometry, const QVector4D &padding,
- const QRectF &bounds, qreal dpr);
-
private:
QRectF m_bounds;
qreal m_devicePixelRatio;
diff --git a/src/quick/scenegraph/util/qsgdistancefieldutil.cpp b/src/quick/scenegraph/util/qsgdistancefieldutil.cpp
index 65a6bcd52c..79e43e3820 100644
--- a/src/quick/scenegraph/util/qsgdistancefieldutil.cpp
+++ b/src/quick/scenegraph/util/qsgdistancefieldutil.cpp
@@ -84,32 +84,12 @@ QSGDistanceFieldGlyphCacheManager::~QSGDistanceFieldGlyphCacheManager()
QSGDistanceFieldGlyphCache *QSGDistanceFieldGlyphCacheManager::cache(const QRawFont &font)
{
- return m_caches.value(fontKey(font), 0);
+ return m_caches.value(font, 0);
}
void QSGDistanceFieldGlyphCacheManager::insertCache(const QRawFont &font, QSGDistanceFieldGlyphCache *cache)
{
- m_caches.insert(fontKey(font), cache);
-}
-
-QString QSGDistanceFieldGlyphCacheManager::fontKey(const QRawFont &font)
-{
- 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");
- return QString::fromUtf8(keyName);
- } else {
- return QString::fromLatin1("%1_%2_%3_%4")
- .arg(font.familyName())
- .arg(font.styleName())
- .arg(font.weight())
- .arg(font.style());
- }
+ m_caches.insert(font, cache);
}
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgdistancefieldutil_p.h b/src/quick/scenegraph/util/qsgdistancefieldutil_p.h
index 354a48a81e..ad366cb4d4 100644
--- a/src/quick/scenegraph/util/qsgdistancefieldutil_p.h
+++ b/src/quick/scenegraph/util/qsgdistancefieldutil_p.h
@@ -80,9 +80,7 @@ public:
void setAntialiasingSpreadFunc(AntialiasingSpreadFunc func) { m_antialiasingSpread_func = func; }
private:
- static QString fontKey(const QRawFont &font);
-
- QHash<QString, QSGDistanceFieldGlyphCache *> m_caches;
+ QHash<QRawFont, QSGDistanceFieldGlyphCache *> m_caches;
ThresholdFunc m_threshold_func;
AntialiasingSpreadFunc m_antialiasingSpread_func;
diff --git a/src/quick/scenegraph/util/qsgimagenode.cpp b/src/quick/scenegraph/util/qsgimagenode.cpp
index a78bfc1c66..c03c91d1cb 100644
--- a/src/quick/scenegraph/util/qsgimagenode.cpp
+++ b/src/quick/scenegraph/util/qsgimagenode.cpp
@@ -187,4 +187,33 @@ QT_BEGIN_NAMESPACE
\return \c true if the node takes ownership of the texture; otherwise \c false.
*/
+void QSGImageNode::rebuildGeometry(QSGGeometry *g,
+ QSGTexture *texture,
+ const QRectF &rect,
+ QRectF sourceRect,
+ TextureCoordinatesTransformMode texCoordMode)
+{
+ if (!texture)
+ return;
+
+ if (!sourceRect.width() || !sourceRect.height()) {
+ QSize ts = texture->textureSize();
+ sourceRect = QRectF(0, 0, ts.width(), ts.height());
+ }
+
+ // Maybe transform the texture coordinates
+ if (texCoordMode.testFlag(QSGImageNode::MirrorHorizontally)) {
+ float tmp = sourceRect.left();
+ sourceRect.setLeft(sourceRect.right());
+ sourceRect.setRight(tmp);
+ }
+ if (texCoordMode.testFlag(QSGImageNode::MirrorVertically)) {
+ float tmp = sourceRect.top();
+ sourceRect.setTop(sourceRect.bottom());
+ sourceRect.setBottom(tmp);
+ }
+
+ QSGGeometry::updateTexturedRectGeometry(g, rect, texture->convertToNormalizedSourceRect(sourceRect));
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgimagenode.h b/src/quick/scenegraph/util/qsgimagenode.h
index 7eab42c4e6..d25e732e4b 100644
--- a/src/quick/scenegraph/util/qsgimagenode.h
+++ b/src/quick/scenegraph/util/qsgimagenode.h
@@ -79,6 +79,12 @@ public:
virtual void setOwnsTexture(bool owns) = 0;
virtual bool ownsTexture() const = 0;
+
+ static void rebuildGeometry(QSGGeometry *g,
+ QSGTexture *texture,
+ const QRectF &rect,
+ QRectF sourceRect,
+ TextureCoordinatesTransformMode texCoordMode);
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QSGImageNode::TextureCoordinatesTransformMode)
diff --git a/src/quick/scenegraph/util/qsgninepatchnode.cpp b/src/quick/scenegraph/util/qsgninepatchnode.cpp
index 9c167ca76f..33568b5488 100644
--- a/src/quick/scenegraph/util/qsgninepatchnode.cpp
+++ b/src/quick/scenegraph/util/qsgninepatchnode.cpp
@@ -74,4 +74,56 @@ QT_BEGIN_NAMESPACE
\internal
*/
+void QSGNinePatchNode::rebuildGeometry(QSGTexture *texture, QSGGeometry *geometry, const QVector4D &padding,
+ const QRectF &bounds, qreal dpr)
+{
+ if (padding.x() <= 0 && padding.y() <= 0 && padding.z() <= 0 && padding.w() <= 0) {
+ geometry->allocate(4, 0);
+ QSGGeometry::updateTexturedRectGeometry(geometry, bounds, texture->normalizedTextureSubRect());
+ return;
+ }
+
+ QRectF tc = texture->normalizedTextureSubRect();
+ QSize ts = texture->textureSize();
+ ts.setHeight(ts.height() / dpr);
+ ts.setWidth(ts.width() / dpr);
+
+ qreal invtw = tc.width() / ts.width();
+ qreal invth = tc.height() / ts.height();
+
+ struct Coord { qreal p; qreal t; };
+ Coord cx[4] = { { bounds.left(), tc.left() },
+ { bounds.left() + padding.x(), tc.left() + padding.x() * invtw },
+ { bounds.right() - padding.z(), tc.right() - padding.z() * invtw },
+ { bounds.right(), tc.right() }
+ };
+ Coord cy[4] = { { bounds.top(), tc.top() },
+ { bounds.top() + padding.y(), tc.top() + padding.y() * invth },
+ { bounds.bottom() - padding.w(), tc.bottom() - padding.w() * invth },
+ { bounds.bottom(), tc.bottom() }
+ };
+
+ geometry->allocate(16, 28);
+ QSGGeometry::TexturedPoint2D *v = geometry->vertexDataAsTexturedPoint2D();
+ for (int y = 0; y < 4; ++y) {
+ for (int x = 0; x < 4; ++x) {
+ v->set(cx[x].p, cy[y].p, cx[x].t, cy[y].t);
+ ++v;
+ }
+ }
+
+ quint16 *i = geometry->indexDataAsUShort();
+ for (int r = 0; r < 3; ++r) {
+ if (r > 0)
+ *i++ = 4 * r;
+ for (int c = 0; c < 4; ++c) {
+ i[0] = 4 * r + c;
+ i[1] = 4 * r + c + 4;
+ i += 2;
+ }
+ if (r < 2)
+ *i++ = 4 * r + 3 + 4;
+ }
+}
+
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/util/qsgninepatchnode.h b/src/quick/scenegraph/util/qsgninepatchnode.h
index 8677a432ba..8509cbd326 100644
--- a/src/quick/scenegraph/util/qsgninepatchnode.h
+++ b/src/quick/scenegraph/util/qsgninepatchnode.h
@@ -55,6 +55,10 @@ public:
virtual void setDevicePixelRatio(qreal ratio) = 0;
virtual void setPadding(qreal left, qreal top, qreal right, qreal bottom) = 0;
virtual void update() = 0;
+
+ static void rebuildGeometry(QSGTexture *texture, QSGGeometry *geometry,
+ const QVector4D &padding,
+ const QRectF &bounds, qreal dpr);
};
QT_END_NAMESPACE