Introduce the FrameSvgItem fastPath alternative, opt out of it on overlays

Fallback to the old code if there's something not (yet?) handled by the
new implementation. This way we get to optimize for the the common use-case
without breaking former, complex, code-paths.

Reviewed by David Edmundson
This commit is contained in:
Aleix Pol 2014-07-16 17:01:05 +02:00
parent cbe13ac765
commit a4e3569bbd
2 changed files with 59 additions and 33 deletions

View File

@ -157,7 +157,8 @@ bool FrameSvgItemMargins::isFixed() const
FrameSvgItem::FrameSvgItem(QQuickItem *parent) FrameSvgItem::FrameSvgItem(QQuickItem *parent)
: QQuickItem(parent), : QQuickItem(parent),
m_textureChanged(false), m_textureChanged(false),
m_sizeChanged(false) m_sizeChanged(false),
m_fastPath(true)
{ {
m_frameSvg = new Plasma::FrameSvg(this); m_frameSvg = new Plasma::FrameSvg(this);
m_margins = new FrameSvgItemMargins(m_frameSvg, this); m_margins = new FrameSvgItemMargins(m_frameSvg, this);
@ -289,6 +290,8 @@ void FrameSvgItem::doUpdate()
setImplicitHeight(m_frameSvg->marginSize(Plasma::Types::TopMargin) + m_frameSvg->marginSize(Plasma::Types::BottomMargin)); setImplicitHeight(m_frameSvg->marginSize(Plasma::Types::TopMargin) + m_frameSvg->marginSize(Plasma::Types::BottomMargin));
} }
bool hasOverlay = !actualPrefix().startsWith(QLatin1String("mask-")) && m_frameSvg->hasElement(actualPrefix() % "overlay");
m_fastPath = !hasOverlay;
m_textureChanged = true; m_textureChanged = true;
update(); update();
} }
@ -337,6 +340,7 @@ QSGNode *FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaint
return Q_NULLPTR; return Q_NULLPTR;
} }
if (m_fastPath) {
if (m_textureChanged) { if (m_textureChanged) {
delete oldNode; delete oldNode;
oldNode = 0; oldNode = 0;
@ -372,6 +376,27 @@ QSGNode *FrameSvgItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaint
} else if(!frame) { } else if(!frame) {
qWarning() << "no frame for" << imagePath() << prefix(); qWarning() << "no frame for" << imagePath() << prefix();
} }
} else {
SVGTextureNode *textureNode = dynamic_cast<SVGTextureNode *>(oldNode);
if (!textureNode) {
delete oldNode;
textureNode = new SVGTextureNode;
textureNode->setFiltering(QSGTexture::Nearest);
m_textureChanged = true; //force updating the texture on our newly created node
oldNode = textureNode;
}
if ((m_textureChanged || m_sizeChanged) || textureNode->texture()->textureSize() != m_frameSvg->size()) {
QImage image = m_frameSvg->framePixmap().toImage();
QSGTexture *texture = window()->createTextureFromImage(image);
texture->setFiltering(QSGTexture::Nearest);
textureNode->setTexture(texture);
textureNode->setRect(0, 0, width(), height());
m_textureChanged = false;
m_sizeChanged = false;
}
}
return oldNode; return oldNode;
} }

View File

@ -194,6 +194,7 @@ private:
Units m_units; Units m_units;
bool m_textureChanged; bool m_textureChanged;
bool m_sizeChanged; bool m_sizeChanged;
bool m_fastPath;
}; };
} }