From 58a70ad1dc63e0b04d41a8f9f0bfd545eb1d8290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 27 Jan 2015 10:58:10 +0100 Subject: [PATCH] [aurorae] Only update shadow if it had changed --- clients/aurorae/src/aurorae.cpp | 55 +++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/clients/aurorae/src/aurorae.cpp b/clients/aurorae/src/aurorae.cpp index f20b7e11ab..e24687d9cd 100644 --- a/clients/aurorae/src/aurorae.cpp +++ b/clients/aurorae/src/aurorae.cpp @@ -521,22 +521,57 @@ void Decoration::paint(QPainter *painter, const QRect &repaintRegion) #endif painter->fillRect(rect(), Qt::transparent); QRectF r(QPointF(0, 0), m_buffer.size()); + bool updateShadow = false; + const auto oldShadow = shadow(); if (m_padding && (m_padding->left() > 0 || m_padding->top() > 0 || m_padding->right() > 0 || m_padding->bottom() > 0) && !client().data()->isMaximized()) { r = r.adjusted(m_padding->left(), m_padding->top(), -m_padding->right(), -m_padding->bottom()); - auto s = QSharedPointer::create(); - s->setShadow(m_buffer); - s->setPadding(*m_padding); - s->setInnerShadowRect(QRect(m_padding->left(), - m_padding->top(), - m_buffer.width() - m_padding->left() - m_padding->right(), - m_buffer.height() - m_padding->top() - m_padding->bottom())); - m_scheduledShadow = s; + if (oldShadow.isNull()) { + updateShadow = true; + } else { + // compare padding + if (oldShadow->padding() != *m_padding) { + updateShadow = true; + } + } + QImage img(m_buffer.size(), QImage::Format_ARGB32_Premultiplied); + img.fill(Qt::transparent); + QPainter p(&img); + // top + p.drawImage(0, 0, m_buffer, 0, 0, img.width(), m_padding->top()); + // left + p.drawImage(0, m_padding->top(), m_buffer, 0, m_padding->top(), m_padding->left(), m_buffer.height() - m_padding->top()); + // bottom + p.drawImage(m_padding->left(), m_buffer.height() - m_padding->bottom(), m_buffer, + m_padding->left(), m_buffer.height() - m_padding->bottom(), + m_buffer.width() - m_padding->left(), m_padding->bottom()); + // right + p.drawImage(m_buffer.width() - m_padding->right(), m_padding->top(), m_buffer, + m_buffer.width() - m_padding->right(), m_padding->top(), + m_padding->right(), m_buffer.height() - m_padding->top() - m_padding->bottom()); + if (!updateShadow) { + updateShadow = (oldShadow->shadow() != img); + } + if (updateShadow) { + auto s = QSharedPointer::create(); + s->setShadow(img); + s->setPadding(*m_padding); + s->setInnerShadowRect(QRect(m_padding->left(), + m_padding->top(), + m_buffer.width() - m_padding->left() - m_padding->right(), + m_buffer.height() - m_padding->top() - m_padding->bottom())); + m_scheduledShadow = s; + } } else { - m_scheduledShadow = QSharedPointer(); + if (!oldShadow.isNull()) { + m_scheduledShadow = QSharedPointer(); + updateShadow = true; + } + } + if (updateShadow) { + QMetaObject::invokeMethod(this, "updateShadow", Qt::QueuedConnection); } - QMetaObject::invokeMethod(this, "updateShadow", Qt::QueuedConnection); painter->drawImage(rect(), m_buffer, r); }