From 258203706cdfc1357effe8cc752672b793cea37d Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 15 Dec 2025 18:01:13 +0000 Subject: [PATCH] Direct2D: Use WM_PAINT and vblank callbacks to drive painting --- .../native/juce_Windowing_windows.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp index 5a1c9b9765..b3f77fc2bd 100644 --- a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp +++ b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp @@ -5082,16 +5082,18 @@ public: updateRegion.findRECTAndValidate (peer.getHWND()); for (const auto& rect : updateRegion.getRects()) - repaint (D2DUtilities::toRectangle (rect)); + direct2DContext->addDeferredRepaint (D2DUtilities::toRectangle (rect)); #if JUCE_DIRECT2D_METRICS lastPaintStartTicks = paintStartTicks; #endif + + handleDirect2DPaint(); } void repaint (const Rectangle& area) override { - direct2DContext->addDeferredRepaint (area); + deferredRepaints.add (area); } void performAnyPendingRepaintsNow() override {} @@ -5103,7 +5105,13 @@ public: void onVBlank() override { - handleDirect2DPaint(); + for (auto deferredRect : deferredRepaints) + { + auto r = D2DUtilities::toRECT (deferredRect); + InvalidateRect (peer.getHWND(), &r, FALSE); + } + + deferredRepaints.clear(); } void handleShowWindow() override @@ -5472,6 +5480,7 @@ private: std::unique_ptr direct2DContext = getContextForPeer (peer); UpdateRegion updateRegion; + RectangleList deferredRepaints; #if JUCE_ETW_TRACELOGGING struct ETWEventProvider