Stop relying on timer to schedule pixmap updates.

The timer was used to skip ahead of parsing and to compress prop
updates to handle width/height changes atomically. This achieves
both by moving pixmap load into the polish phase after those are
guaranteed to be done.

This fixes a bunch of flicker all over the place since 150ms is
obviously far beyond the frame time budget on 60 hz, but we can
usually easily fit into one frame on hot caches.
This commit is contained in:
Eike Hein 2015-12-22 18:36:23 +01:00
parent 01cd374c8e
commit 706276d108
2 changed files with 24 additions and 11 deletions

View File

@ -65,7 +65,7 @@ IconItem::IconItem(QQuickItem *parent)
this, SIGNAL(implicitHeightChanged())); this, SIGNAL(implicitHeightChanged()));
connect(this, SIGNAL(enabledChanged()), connect(this, SIGNAL(enabledChanged()),
this, SLOT(loadPixmap())); this, SLOT(schedulePixmapUpdate()));
//initialize implicit size to the Dialog size //initialize implicit size to the Dialog size
setImplicitWidth(KIconLoader::global()->currentSize(KIconLoader::Dialog)); setImplicitWidth(KIconLoader::global()->currentSize(KIconLoader::Dialog));
@ -97,7 +97,7 @@ void IconItem::setSource(const QVariant &source)
m_svgIcon = 0; m_svgIcon = 0;
m_icon = QIcon(); m_icon = QIcon();
emit validChanged(); emit validChanged();
loadPixmap(); schedulePixmapUpdate();
return; return;
} }
@ -123,7 +123,7 @@ void IconItem::setSource(const QVariant &source)
//success? //success?
if (m_svgIcon->isValid() && m_svgIcon->hasElement(m_source.toString())) { if (m_svgIcon->isValid() && m_svgIcon->hasElement(m_source.toString())) {
m_icon = QIcon(); m_icon = QIcon();
connect(m_svgIcon, SIGNAL(repaintNeeded()), this, SLOT(loadPixmap())); connect(m_svgIcon, SIGNAL(repaintNeeded()), this, SLOT(schedulePixmapUpdate()));
//ok, svg not available from the plasma theme //ok, svg not available from the plasma theme
} else { } else {
@ -176,7 +176,7 @@ void IconItem::setSource(const QVariant &source)
} }
if (width() > 0 && height() > 0) { if (width() > 0 && height() > 0) {
loadPixmap(); schedulePixmapUpdate();
} }
emit sourceChanged(); emit sourceChanged();
@ -221,7 +221,7 @@ void IconItem::setActive(bool active)
m_active = active; m_active = active;
if (isComponentComplete()) { if (isComponentComplete()) {
loadPixmap(); schedulePixmapUpdate();
} }
emit activeChanged(); emit activeChanged();
} }
@ -245,6 +245,12 @@ bool IconItem::isValid() const
return !m_icon.isNull() || m_svgIcon || !m_pixmapIcon.isNull() || !m_imageIcon.isNull(); return !m_icon.isNull() || m_svgIcon || !m_pixmapIcon.isNull() || !m_imageIcon.isNull();
} }
void IconItem::updatePolish()
{
QQuickItem::updatePolish();
loadPixmap();
}
QSGNode* IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) QSGNode* IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
{ {
Q_UNUSED(updatePaintNodeData) Q_UNUSED(updatePaintNodeData)
@ -315,6 +321,11 @@ void IconItem::animationFinished()
update(); update();
} }
void IconItem::schedulePixmapUpdate()
{
polish();
}
void IconItem::loadPixmap() void IconItem::loadPixmap()
{ {
if (!isComponentComplete()) { if (!isComponentComplete()) {
@ -391,11 +402,10 @@ void IconItem::geometryChanged(const QRectF &newGeometry,
{ {
if (newGeometry.size() != oldGeometry.size()) { if (newGeometry.size() != oldGeometry.size()) {
m_sizeChanged = true; m_sizeChanged = true;
update();
if (newGeometry.width() > 0 && newGeometry.height() > 0) { if (newGeometry.width() > 0 && newGeometry.height() > 0) {
if (isComponentComplete()) { schedulePixmapUpdate();
loadPixmap(); } else {
} update();
} }
} }
@ -405,5 +415,5 @@ void IconItem::geometryChanged(const QRectF &newGeometry,
void IconItem::componentComplete() void IconItem::componentComplete()
{ {
QQuickItem::componentComplete(); QQuickItem::componentComplete();
loadPixmap(); schedulePixmapUpdate();
} }

View File

@ -64,6 +64,7 @@ public:
bool isValid() const; bool isValid() const;
void updatePolish() Q_DECL_OVERRIDE;
QSGNode* updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData) Q_DECL_OVERRIDE; QSGNode* updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData) Q_DECL_OVERRIDE;
void geometryChanged(const QRectF &newGeometry, void geometryChanged(const QRectF &newGeometry,
@ -79,11 +80,13 @@ Q_SIGNALS:
void colorGroupChanged(); void colorGroupChanged();
private Q_SLOTS: private Q_SLOTS:
void loadPixmap(); void schedulePixmapUpdate();
void animationFinished(); void animationFinished();
void valueChanged(const QVariant &value); void valueChanged(const QVariant &value);
private: private:
void loadPixmap();
//all the ways we can set an source. Only one of them will be valid //all the ways we can set an source. Only one of them will be valid
QIcon m_icon; QIcon m_icon;
Plasma::Svg *m_svgIcon; Plasma::Svg *m_svgIcon;