From 26950a65a6fab7d7eb58b61bc2a4a2705de13aab Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Tue, 22 Sep 2020 02:13:11 +0200 Subject: [PATCH] Have Toplevel::damage emit a QRegion Instead of looping through the rects in the region, emit the region at bulk. It reduces the amount of emissions we do and allows us to pack the response accordingly. --- effects.cpp | 2 +- effects.h | 2 +- effects/thumbnailaside/thumbnailaside.cpp | 2 +- effects/thumbnailaside/thumbnailaside.h | 2 +- libkwineffects/kwineffects.h | 4 ++-- screencast/screencastmanager.cpp | 2 +- toplevel.cpp | 14 ++++++-------- toplevel.h | 2 +- 8 files changed, 14 insertions(+), 16 deletions(-) diff --git a/effects.cpp b/effects.cpp index 2a987250e..67d9ab298 100644 --- a/effects.cpp +++ b/effects.cpp @@ -590,7 +590,7 @@ void EffectsHandlerImpl::slotTabRemoved(EffectWindow *w, EffectWindow* leaderOfF emit tabRemoved(w, leaderOfFormerGroup); } -void EffectsHandlerImpl::slotWindowDamaged(Toplevel* t, const QRect& r) +void EffectsHandlerImpl::slotWindowDamaged(Toplevel* t, const QRegion& r) { if (!t->effectWindow()) { // can happen during tear down of window diff --git a/effects.h b/effects.h index d7d54d779..9b4b249d5 100644 --- a/effects.h +++ b/effects.h @@ -289,7 +289,7 @@ protected Q_SLOTS: void slotGeometryShapeChanged(KWin::Toplevel *t, const QRect &old); void slotFrameGeometryChanged(Toplevel *toplevel, const QRect &oldGeometry); void slotPaddingChanged(KWin::Toplevel *t, const QRect &old); - void slotWindowDamaged(KWin::Toplevel *t, const QRect& r); + void slotWindowDamaged(KWin::Toplevel *t, const QRegion& r); protected: void connectNotify(const QMetaMethod &signal) override; diff --git a/effects/thumbnailaside/thumbnailaside.cpp b/effects/thumbnailaside/thumbnailaside.cpp index 9bbda907e..629bae82b 100644 --- a/effects/thumbnailaside/thumbnailaside.cpp +++ b/effects/thumbnailaside/thumbnailaside.cpp @@ -73,7 +73,7 @@ void ThumbnailAsideEffect::paintWindow(EffectWindow *w, int mask, QRegion region painted |= region; } -void ThumbnailAsideEffect::slotWindowDamaged(EffectWindow* w, const QRect&) +void ThumbnailAsideEffect::slotWindowDamaged(EffectWindow* w, const QRegion&) { foreach (const Data & d, windows) { if (d.window == w) diff --git a/effects/thumbnailaside/thumbnailaside.h b/effects/thumbnailaside/thumbnailaside.h index ef3f0045e..15dc70265 100644 --- a/effects/thumbnailaside/thumbnailaside.h +++ b/effects/thumbnailaside/thumbnailaside.h @@ -55,7 +55,7 @@ private Q_SLOTS: void toggleCurrentThumbnail(); void slotWindowClosed(KWin::EffectWindow *w); void slotWindowFrameGeometryChanged(KWin::EffectWindow *w, const QRect &old); - void slotWindowDamaged(KWin::EffectWindow* w, const QRect& damage); + void slotWindowDamaged(KWin::EffectWindow* w, const QRegion& damage); bool isActive() const override; void repaintAll(); private: diff --git a/libkwineffects/kwineffects.h b/libkwineffects/kwineffects.h index 61cf95107..19f039feb 100644 --- a/libkwineffects/kwineffects.h +++ b/libkwineffects/kwineffects.h @@ -175,7 +175,7 @@ X-KDE-Library=kwin4_effect_cooleffect #define KWIN_EFFECT_API_MAKE_VERSION( major, minor ) (( major ) << 8 | ( minor )) #define KWIN_EFFECT_API_VERSION_MAJOR 0 -#define KWIN_EFFECT_API_VERSION_MINOR 231 +#define KWIN_EFFECT_API_VERSION_MINOR 232 #define KWIN_EFFECT_API_VERSION KWIN_EFFECT_API_MAKE_VERSION( \ KWIN_EFFECT_API_VERSION_MAJOR, KWIN_EFFECT_API_VERSION_MINOR ) @@ -1561,7 +1561,7 @@ Q_SIGNALS: * @param r Always empty. * @since 4.7 */ - void windowDamaged(KWin::EffectWindow *w, const QRect &r); + void windowDamaged(KWin::EffectWindow *w, const QRegion &r); /** * Signal emitted when a tabbox is added. * An effect who wants to replace the tabbox with itself should use refTabBox. diff --git a/screencast/screencastmanager.cpp b/screencast/screencastmanager.cpp index b5a2d70cc..8b34ac970 100644 --- a/screencast/screencastmanager.cpp +++ b/screencast/screencastmanager.cpp @@ -90,7 +90,7 @@ private: m_toplevel->addRepaintFull(); } - void includeDamage(Toplevel *toplevel, const QRect &damage) { + void includeDamage(Toplevel *toplevel, const QRegion &damage) { Q_ASSERT(m_toplevel == toplevel); m_damagedRegion |= damage; } diff --git a/toplevel.cpp b/toplevel.cpp index 26ee4fe93..234f6d4ff 100644 --- a/toplevel.cpp +++ b/toplevel.cpp @@ -45,7 +45,7 @@ Toplevel::Toplevel() , m_screen(0) , m_skipCloseAnimation(false) { - connect(this, SIGNAL(damaged(KWin::Toplevel*,QRect)), SIGNAL(needsRepaint())); + connect(this, &Toplevel::damaged, this, &Toplevel::needsRepaint); connect(screens(), SIGNAL(changed()), SLOT(checkScreen())); connect(screens(), SIGNAL(countChanged(int,int)), SLOT(checkScreen())); setupCheckScreenConnection(); @@ -327,10 +327,10 @@ void Toplevel::damageNotifyEvent() { m_isDamaged = true; - // Note: The rect is supposed to specify the damage extents, + // Note: The damage is supposed to specify the damage extents, // but we don't know it at this point. No one who connects // to this signal uses the rect however. - emit damaged(this, QRect()); + emit damaged(this, {}); } bool Toplevel::compositing() const @@ -421,12 +421,12 @@ void Toplevel::addDamageFull() const int offsetX = bufferRect.x() - frameRect.x(); const int offsetY = bufferRect.y() - frameRect.y(); - const QRect damagedRect = QRect(0, 0, bufferRect.width(), bufferRect.height()); + const QRect damagedRect(0, 0, bufferRect.width(), bufferRect.height()); damage_region = damagedRect; repaints_region |= damagedRect.translated(offsetX, offsetY); - emit damaged(this, damagedRect); + emit damaged(this, damage_region); } void Toplevel::resetDamage() @@ -748,9 +748,7 @@ void Toplevel::addDamage(const QRegion &damage) { m_isDamaged = true; damage_region += damage; - for (const QRect &r : damage) { - emit damaged(this, r); - } + emit damaged(this, damage); } QByteArray Toplevel::windowRole() const diff --git a/toplevel.h b/toplevel.h index d159a2af2..2cea2f41f 100644 --- a/toplevel.h +++ b/toplevel.h @@ -585,7 +585,7 @@ public: Q_SIGNALS: void opacityChanged(KWin::Toplevel* toplevel, qreal oldOpacity); - void damaged(KWin::Toplevel* toplevel, const QRect& damage); + void damaged(KWin::Toplevel* toplevel, const QRegion& damage); void inputTransformationChanged(); /** * This signal is emitted when the Toplevel's frame geometry changes.