Skip to content

Commit e2afa5f

Browse files
committed
Block repainting on invisible canvases
1 parent d247381 commit e2afa5f

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Source/CanvasViewport.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,9 @@ class CanvasViewport final : public Viewport
488488
addAndMakeVisible(vbar);
489489
addAndMakeVisible(hbar);
490490

491-
setCachedComponentImage(new NVGSurface::InvalidationListener(editor->nvgSurface, this));
491+
setCachedComponentImage(new NVGSurface::InvalidationListener(editor->nvgSurface, this, [this](){
492+
return editor->getTabComponent().getVisibleCanvases().contains(this->cnv);
493+
}));
492494

493495
lookAndFeelChanged();
494496
}

Source/NVGSurface.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ class NVGSurface final :
5656

5757
class InvalidationListener final : public CachedComponentImage {
5858
public:
59-
InvalidationListener(NVGSurface& s, Component* origin, bool const passRepaintEvents = false)
59+
InvalidationListener(NVGSurface& s, Component* origin, std::function<bool()> canRepaintCheck = [](){ return true; })
6060
: surface(s)
6161
, originComponent(origin)
62-
, passEvents(passRepaintEvents)
62+
, canRepaint(canRepaintCheck)
6363
{
6464
}
6565

@@ -71,26 +71,26 @@ class NVGSurface final :
7171
auto invalidatedBounds = surface.getLocalArea(originComponent, rect.expanded(2).toFloat()).getSmallestIntegerContainer();
7272
invalidatedBounds = invalidatedBounds.getIntersection(surface.getLocalBounds());
7373

74-
if (originComponent->isVisible() && !invalidatedBounds.isEmpty()) {
74+
if (originComponent->isVisible() && canRepaint() && !invalidatedBounds.isEmpty()) {
7575
surface.invalidateArea(invalidatedBounds);
7676
}
7777

78-
return surface.renderThroughImage || passEvents;
78+
return surface.renderThroughImage;
7979
}
8080

8181
bool invalidateAll() override
8282
{
83-
if (originComponent->isVisible()) {
83+
if (originComponent->isVisible() && canRepaint()) {
8484
surface.invalidateArea(originComponent->getLocalBounds());
8585
}
86-
return surface.renderThroughImage || passEvents;
86+
return surface.renderThroughImage;
8787
}
8888

8989
void releaseResources() override { }
9090

9191
NVGSurface& surface;
9292
Component* originComponent;
93-
bool passEvents;
93+
std::function<bool()> canRepaint;
9494
};
9595

9696
void invalidateArea(Rectangle<int> area);

0 commit comments

Comments
 (0)