From 2ffb708be83cba136c6ec89f8882f22ed783651d Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 3 Dec 2018 23:59:42 -0300 Subject: [PATCH] Move Manager::invalidateDisplayRegion() to Manager::onInvalidateRegion() --- src/app/modules/gui.cpp | 2 +- src/ui/manager.cpp | 30 ++++++++++++++++++++++-------- src/ui/manager.h | 4 ++-- src/ui/widget.cpp | 27 ++++++++++++++------------- src/ui/window.cpp | 2 +- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/app/modules/gui.cpp b/src/app/modules/gui.cpp index 1f46f433f..d762c1276 100644 --- a/src/app/modules/gui.cpp +++ b/src/app/modules/gui.cpp @@ -484,7 +484,7 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg) case kTimerMessage: if (static_cast(msg)->timer() == defered_invalid_timer) { - invalidateDisplayRegion(defered_invalid_region); + invalidateRegion(defered_invalid_region); defered_invalid_region.clear(); defered_invalid_timer->stop(); } diff --git a/src/ui/manager.cpp b/src/ui/manager.cpp index 595810546..ff11c349c 100644 --- a/src/ui/manager.cpp +++ b/src/ui/manager.cpp @@ -1,4 +1,5 @@ // Aseprite UI Library +// Copyright (C) 2018 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This file is released under the terms of the MIT license. @@ -1530,9 +1531,18 @@ bool Manager::sendMessageToWidget(Message* msg, Widget* widget) return used; } -void Manager::invalidateDisplayRegion(const gfx::Region& region) +// It's like Widget::onInvalidateRegion() but optimized for the +// Manager (as we know that all children in a Manager will be windows, +// we can use this knowledge to avoid some calculations). +void Manager::onInvalidateRegion(const gfx::Region& region) { - // TODO intersect with getDrawableRegion()??? + if (!isVisible() || region.contains(bounds()) == gfx::Region::Out) + return; + + // Intersect only with manager bounds, we don't need to use + // getDrawableRegion() because each window will be processed in the + // following for() loop (and it's highly probable that a desktop + // Window will use the whole manager portion anyway). gfx::Region reg1; reg1.createIntersection(region, gfx::Region(bounds())); @@ -1549,19 +1559,23 @@ void Manager::invalidateDisplayRegion(const gfx::Region& region) // There is desktop? if (window->isDesktop()) { withDesktop = true; - break; // Work done + break; // Work done } // Clip this window area for the next window. - gfx::Region reg3; - window->getRegion(reg3); - reg1.createSubtraction(reg1, reg3); + gfx::Region reg2; + window->getRegion(reg2); + reg1.createSubtraction(reg1, reg2); } // Invalidate areas outside windows (only when there are not a // desktop window). - if (!withDesktop) - Widget::invalidateRegion(reg1); + if (!withDesktop) { + // TODO we should be able to modify m_updateRegion directly here, + // so we avoid the getDrawableRegion() call from + // Widget::onInvalidateRegion(). + Widget::onInvalidateRegion(reg1); + } } LayoutIO* Manager::getLayoutIO() diff --git a/src/ui/manager.h b/src/ui/manager.h index 8fc4c8858..391e212d2 100644 --- a/src/ui/manager.h +++ b/src/ui/manager.h @@ -1,4 +1,5 @@ // Aseprite UI Library +// Copyright (C) 2018 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This file is released under the terms of the MIT license. @@ -82,8 +83,6 @@ namespace ui { void removeMessageFilter(int message, Widget* widget); void removeMessageFilterFor(Widget* widget); - void invalidateDisplayRegion(const gfx::Region& region); - LayoutIO* getLayoutIO(); bool isFocusMovementMessage(Message* msg); @@ -109,6 +108,7 @@ namespace ui { protected: bool onProcessMessage(Message* msg) override; + void onInvalidateRegion(const gfx::Region& region) override; void onResize(ResizeEvent& ev) override; void onSizeHint(SizeHintEvent& ev) override; void onBroadcastMouseMessage(WidgetsList& targets) override; diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index 3b98a2346..62e63e4ae 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -1480,21 +1480,22 @@ bool Widget::onProcessMessage(Message* msg) void Widget::onInvalidateRegion(const Region& region) { - if (isVisible() && region.contains(bounds()) != Region::Out) { - Region reg1; - reg1.createUnion(m_updateRegion, region); - { - Region reg2; - getDrawableRegion(reg2, kCutTopWindows); - m_updateRegion.createIntersection(reg1, reg2); - } - reg1.createSubtraction(region, m_updateRegion); + if (!isVisible() || region.contains(bounds()) == Region::Out) + return; - setDirtyFlag(); - - for (auto child : m_children) - child->invalidateRegion(reg1); + Region reg1; + reg1.createUnion(m_updateRegion, region); + { + Region reg2; + getDrawableRegion(reg2, kCutTopWindows); + m_updateRegion.createIntersection(reg1, reg2); } + reg1.createSubtraction(region, m_updateRegion); + + setDirtyFlag(); + + for (auto child : m_children) + child->invalidateRegion(reg1); } void Widget::onSizeHint(SizeHintEvent& ev) diff --git a/src/ui/window.cpp b/src/ui/window.cpp index 7b4785a1e..6d7792441 100644 --- a/src/ui/window.cpp +++ b/src/ui/window.cpp @@ -673,7 +673,7 @@ void Window::moveWindow(const gfx::Rect& rect, bool use_blit) invalidateRegion(reg1); } - manager->invalidateDisplayRegion(invalidManagerRegion); + manager->invalidateRegion(invalidManagerRegion); onWindowMovement(); }