Move Manager::invalidateDisplayRegion() to Manager::onInvalidateRegion()

This commit is contained in:
David Capello 2018-12-03 23:59:42 -03:00
parent 767897d665
commit 2ffb708be8
5 changed files with 40 additions and 25 deletions

View File

@ -484,7 +484,7 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg)
case kTimerMessage: case kTimerMessage:
if (static_cast<TimerMessage*>(msg)->timer() == defered_invalid_timer) { if (static_cast<TimerMessage*>(msg)->timer() == defered_invalid_timer) {
invalidateDisplayRegion(defered_invalid_region); invalidateRegion(defered_invalid_region);
defered_invalid_region.clear(); defered_invalid_region.clear();
defered_invalid_timer->stop(); defered_invalid_timer->stop();
} }

View File

@ -1,4 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello // Copyright (C) 2001-2018 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -1530,9 +1531,18 @@ bool Manager::sendMessageToWidget(Message* msg, Widget* widget)
return used; 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; gfx::Region reg1;
reg1.createIntersection(region, gfx::Region(bounds())); reg1.createIntersection(region, gfx::Region(bounds()));
@ -1549,19 +1559,23 @@ void Manager::invalidateDisplayRegion(const gfx::Region& region)
// There is desktop? // There is desktop?
if (window->isDesktop()) { if (window->isDesktop()) {
withDesktop = true; withDesktop = true;
break; // Work done break; // Work done
} }
// Clip this window area for the next window. // Clip this window area for the next window.
gfx::Region reg3; gfx::Region reg2;
window->getRegion(reg3); window->getRegion(reg2);
reg1.createSubtraction(reg1, reg3); reg1.createSubtraction(reg1, reg2);
} }
// Invalidate areas outside windows (only when there are not a // Invalidate areas outside windows (only when there are not a
// desktop window). // desktop window).
if (!withDesktop) if (!withDesktop) {
Widget::invalidateRegion(reg1); // 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() LayoutIO* Manager::getLayoutIO()

View File

@ -1,4 +1,5 @@
// Aseprite UI Library // Aseprite UI Library
// Copyright (C) 2018 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello // Copyright (C) 2001-2017 David Capello
// //
// This file is released under the terms of the MIT license. // This file is released under the terms of the MIT license.
@ -82,8 +83,6 @@ namespace ui {
void removeMessageFilter(int message, Widget* widget); void removeMessageFilter(int message, Widget* widget);
void removeMessageFilterFor(Widget* widget); void removeMessageFilterFor(Widget* widget);
void invalidateDisplayRegion(const gfx::Region& region);
LayoutIO* getLayoutIO(); LayoutIO* getLayoutIO();
bool isFocusMovementMessage(Message* msg); bool isFocusMovementMessage(Message* msg);
@ -109,6 +108,7 @@ namespace ui {
protected: protected:
bool onProcessMessage(Message* msg) override; bool onProcessMessage(Message* msg) override;
void onInvalidateRegion(const gfx::Region& region) override;
void onResize(ResizeEvent& ev) override; void onResize(ResizeEvent& ev) override;
void onSizeHint(SizeHintEvent& ev) override; void onSizeHint(SizeHintEvent& ev) override;
void onBroadcastMouseMessage(WidgetsList& targets) override; void onBroadcastMouseMessage(WidgetsList& targets) override;

View File

@ -1480,21 +1480,22 @@ bool Widget::onProcessMessage(Message* msg)
void Widget::onInvalidateRegion(const Region& region) void Widget::onInvalidateRegion(const Region& region)
{ {
if (isVisible() && region.contains(bounds()) != Region::Out) { if (!isVisible() || region.contains(bounds()) == Region::Out)
Region reg1; return;
reg1.createUnion(m_updateRegion, region);
{
Region reg2;
getDrawableRegion(reg2, kCutTopWindows);
m_updateRegion.createIntersection(reg1, reg2);
}
reg1.createSubtraction(region, m_updateRegion);
setDirtyFlag(); Region reg1;
reg1.createUnion(m_updateRegion, region);
for (auto child : m_children) {
child->invalidateRegion(reg1); 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) void Widget::onSizeHint(SizeHintEvent& ev)

View File

@ -673,7 +673,7 @@ void Window::moveWindow(const gfx::Rect& rect, bool use_blit)
invalidateRegion(reg1); invalidateRegion(reg1);
} }
manager->invalidateDisplayRegion(invalidManagerRegion); manager->invalidateRegion(invalidManagerRegion);
onWindowMovement(); onWindowMovement();
} }