1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-21 01:24:21 +00:00

HWNDComponentPeer: Avoid glitches and sluggishness during live resize

258203706c introduced a problem where
live-resize of a window would cause the window content to flash and slow
down.

The cause of the errant behaviour seems to be that, during resize, many
WM_PAINT messages might be dispatched over the course of a single vblank
interval. Then, each of these paint calls was waiting for the next
vblank interval to display. This additional waiting resulted in
sluggishness, since many frames would have to be presented before the
presentation 'caught up' with the current window size. This also meant
that many consecutive frames were presented with stale window size
information.

The solution added here simply checks whether we're live resizing, and
uses the vblank instead of WM_PAINT to synchronise repaints during the
resize operation.
This commit is contained in:
reuk 2026-01-07 15:35:07 +00:00
parent d5a84475da
commit 7685a84c81
No known key found for this signature in database

View file

@ -2096,6 +2096,7 @@ public:
}
bool hasTitleBar() const { return (styleFlags & windowHasTitleBar) != 0; }
bool isSizing() const { return sizing; }
private:
HWND hwnd, parentToAddTo;
@ -5077,14 +5078,22 @@ public:
updateRegion.findRECTAndValidate (peer.getHWND());
for (const auto& rect : updateRegion.getRects())
direct2DContext->addDeferredRepaint (D2DUtilities::toRectangle (rect));
if (peer.isSizing())
{
for (const auto& rect : updateRegion.getRects())
deferredRepaints.add (D2DUtilities::toRectangle (rect));
}
else
{
for (const auto& rect : updateRegion.getRects())
direct2DContext->addDeferredRepaint (D2DUtilities::toRectangle (rect));
#if JUCE_DIRECT2D_METRICS
lastPaintStartTicks = paintStartTicks;
#endif
#if JUCE_DIRECT2D_METRICS
lastPaintStartTicks = paintStartTicks;
#endif
handleDirect2DPaint();
handleDirect2DPaint();
}
}
void repaint (const Rectangle<int>& area) override
@ -5101,10 +5110,20 @@ public:
void onVBlank() override
{
for (auto deferredRect : deferredRepaints)
if (peer.isSizing())
{
auto r = D2DUtilities::toRECT (deferredRect);
InvalidateRect (peer.getHWND(), &r, FALSE);
for (const auto& rect : deferredRepaints)
direct2DContext->addDeferredRepaint (rect);
handleDirect2DPaint();
}
else
{
for (auto deferredRect : deferredRepaints)
{
auto r = D2DUtilities::toRECT (deferredRect);
InvalidateRect (peer.getHWND(), &r, FALSE);
}
}
deferredRepaints.clear();