Remove Window::addRepaint() and Window::addLayerRepaint()

Conceptually, scheduling repainting in Window doesn't belong there. This
change rewires EffectWindow internals so it schedules repaints using the
associated WindowItem.

Window::addWorkspaceRepaint() has not been removed yet because
Window::elevate() uses it.
This commit is contained in:
Vlad Zahorodnii 2022-05-11 15:10:11 +03:00
parent 8cc5e04238
commit ea1fadfe8d
7 changed files with 32 additions and 61 deletions

View file

@ -1917,27 +1917,17 @@ void EffectWindowImpl::unrefVisible(int reason)
void EffectWindowImpl::addRepaint(const QRect &r) void EffectWindowImpl::addRepaint(const QRect &r)
{ {
m_window->addRepaint(r); m_windowItem->scheduleRepaint(r);
}
void EffectWindowImpl::addRepaint(int x, int y, int w, int h)
{
m_window->addRepaint(x, y, w, h);
} }
void EffectWindowImpl::addRepaintFull() void EffectWindowImpl::addRepaintFull()
{ {
m_window->addRepaintFull(); m_windowItem->scheduleRepaint(m_windowItem->boundingRect());
} }
void EffectWindowImpl::addLayerRepaint(const QRect &r) void EffectWindowImpl::addLayerRepaint(const QRect &r)
{ {
m_window->addLayerRepaint(r); m_windowItem->scheduleRepaint(m_windowItem->mapFromGlobal(r));
}
void EffectWindowImpl::addLayerRepaint(int x, int y, int w, int h)
{
m_window->addLayerRepaint(x, y, w, h);
} }
const EffectWindowGroup *EffectWindowImpl::group() const const EffectWindowGroup *EffectWindowImpl::group() const

View file

@ -382,10 +382,8 @@ public:
void unrefVisible(int reason) override; void unrefVisible(int reason) override;
void addRepaint(const QRect &r) override; void addRepaint(const QRect &r) override;
void addRepaint(int x, int y, int w, int h) override;
void addRepaintFull() override; void addRepaintFull() override;
void addLayerRepaint(const QRect &r) override; void addLayerRepaint(const QRect &r) override;
void addLayerRepaint(int x, int y, int w, int h) override;
void refWindow() override; void refWindow() override;
void unrefWindow() override; void unrefWindow() override;

View file

@ -219,6 +219,14 @@ QRect Item::mapToGlobal(const QRect &rect) const
return rect.translated(rootPosition()); return rect.translated(rootPosition());
} }
QRect Item::mapFromGlobal(const QRect &rect) const
{
if (rect.isEmpty()) {
return QRect();
}
return rect.translated(-rootPosition());
}
void Item::stackBefore(Item *sibling) void Item::stackBefore(Item *sibling)
{ {
if (Q_UNLIKELY(!sibling)) { if (Q_UNLIKELY(!sibling)) {

View file

@ -78,6 +78,11 @@ public:
* system. * system.
*/ */
QRect mapToGlobal(const QRect &rect) const; QRect mapToGlobal(const QRect &rect) const;
/**
* Maps the given @a rect from the scene's coordinate system to the item's coordinate
* system.
*/
QRect mapFromGlobal(const QRect &rect) const;
/** /**
* Moves this item right before the specified @a sibling in the parent's children list. * Moves this item right before the specified @a sibling in the parent's children list.

View file

@ -2350,10 +2350,10 @@ public:
~EffectWindow() override; ~EffectWindow() override;
Q_SCRIPTABLE virtual void addRepaint(const QRect &r) = 0; Q_SCRIPTABLE virtual void addRepaint(const QRect &r) = 0;
Q_SCRIPTABLE virtual void addRepaint(int x, int y, int w, int h) = 0; Q_SCRIPTABLE void addRepaint(int x, int y, int w, int h);
Q_SCRIPTABLE virtual void addRepaintFull() = 0; Q_SCRIPTABLE virtual void addRepaintFull() = 0;
Q_SCRIPTABLE virtual void addLayerRepaint(const QRect &r) = 0; Q_SCRIPTABLE virtual void addLayerRepaint(const QRect &r) = 0;
Q_SCRIPTABLE virtual void addLayerRepaint(int x, int y, int w, int h) = 0; Q_SCRIPTABLE void addLayerRepaint(int x, int y, int w, int h);
virtual void refWindow() = 0; virtual void refWindow() = 0;
virtual void unrefWindow() = 0; virtual void unrefWindow() = 0;
@ -4183,6 +4183,20 @@ void Effect::initConfig()
T::instance(effects->config()); T::instance(effects->config());
} }
/***************************************************************
EffectWindow
***************************************************************/
inline void EffectWindow::addRepaint(int x, int y, int w, int h)
{
addRepaint(QRect(x, y, w, h));
}
inline void EffectWindow::addLayerRepaint(int x, int y, int w, int h)
{
addLayerRepaint(QRect(x, y, w, h));
}
} // namespace } // namespace
Q_DECLARE_METATYPE(KWin::EffectWindow *) Q_DECLARE_METATYPE(KWin::EffectWindow *)
Q_DECLARE_METATYPE(KWin::EffectWindowList) Q_DECLARE_METATYPE(KWin::EffectWindowList)

View file

@ -365,43 +365,6 @@ void Window::finishCompositing(ReleaseReason releaseReason)
deleteItem(); deleteItem();
} }
void Window::addRepaint(const QRect &rect)
{
addRepaint(QRegion(rect));
}
void Window::addRepaint(int x, int y, int width, int height)
{
addRepaint(QRegion(x, y, width, height));
}
void Window::addRepaint(const QRegion &region)
{
if (auto item = windowItem()) {
item->scheduleRepaint(region);
}
}
void Window::addLayerRepaint(const QRect &rect)
{
addLayerRepaint(QRegion(rect));
}
void Window::addLayerRepaint(int x, int y, int width, int height)
{
addLayerRepaint(QRegion(x, y, width, height));
}
void Window::addLayerRepaint(const QRegion &region)
{
addRepaint(region.translated(-pos()));
}
void Window::addRepaintFull()
{
addLayerRepaint(visibleGeometry());
}
void Window::addWorkspaceRepaint(int x, int y, int w, int h) void Window::addWorkspaceRepaint(int x, int y, int w, int h)
{ {
addWorkspaceRepaint(QRect(x, y, w, h)); addWorkspaceRepaint(QRect(x, y, w, h));

View file

@ -719,13 +719,6 @@ public:
bool hasAlpha() const; bool hasAlpha() const;
virtual bool setupCompositing(); virtual bool setupCompositing();
virtual void finishCompositing(ReleaseReason releaseReason = ReleaseReason::Release); virtual void finishCompositing(ReleaseReason releaseReason = ReleaseReason::Release);
Q_INVOKABLE void addRepaint(const QRect &r);
Q_INVOKABLE void addRepaint(const QRegion &r);
Q_INVOKABLE void addRepaint(int x, int y, int w, int h);
Q_INVOKABLE void addLayerRepaint(const QRect &r);
Q_INVOKABLE void addLayerRepaint(const QRegion &r);
Q_INVOKABLE void addLayerRepaint(int x, int y, int w, int h);
Q_INVOKABLE virtual void addRepaintFull();
// these call workspace->addRepaint(), but first transform the damage if needed // these call workspace->addRepaint(), but first transform the damage if needed
void addWorkspaceRepaint(const QRect &r); void addWorkspaceRepaint(const QRect &r);
void addWorkspaceRepaint(int x, int y, int w, int h); void addWorkspaceRepaint(int x, int y, int w, int h);