From f5cc7902b158f4ca14deb9691f91d4bf77d0645f Mon Sep 17 00:00:00 2001 From: reuk Date: Fri, 11 Oct 2024 22:08:39 +0100 Subject: [PATCH] Direct2D: Avoid using dirty rects when painting full frame This fixes an issue where Direct2D will emit an error when using dirty rects on the first full frame after resizing. The issue isn't present on all hardware/drivers, but was observed on a Windows 11 computer with a 890M iGPU. --- .../juce_Direct2DHwndContext_windows.cpp | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/modules/juce_graphics/native/juce_Direct2DHwndContext_windows.cpp b/modules/juce_graphics/native/juce_Direct2DHwndContext_windows.cpp index 2b7c483d6c..ab4aaa49f4 100644 --- a/modules/juce_graphics/native/juce_Direct2DHwndContext_windows.cpp +++ b/modules/juce_graphics/native/juce_Direct2DHwndContext_windows.cpp @@ -301,20 +301,23 @@ public: if (swap.buffer == nullptr || dirtyRegionsInBackBuffer.isEmpty() || ! swapEventReceived) return; - // Allocate enough memory for the array of dirty rectangles - dirtyRectangles.resize ((size_t) dirtyRegionsInBackBuffer.getNumRectangles()); - - // Fill the array of dirty rectangles, intersecting each paint area with the swap chain buffer - DXGI_PRESENT_PARAMETERS presentParameters{}; - presentParameters.pDirtyRects = dirtyRectangles.data(); - presentParameters.DirtyRectsCount = 0; - auto const swapChainSize = swap.getSize(); + DXGI_PRESENT_PARAMETERS presentParameters{}; - for (const auto& area : dirtyRegionsInBackBuffer) + if (! dirtyRegionsInBackBuffer.containsRectangle (swapChainSize)) { - if (const auto intersection = area.getIntersection (swapChainSize); ! intersection.isEmpty()) - presentParameters.pDirtyRects[presentParameters.DirtyRectsCount++] = D2DUtilities::toRECT (intersection); + // Allocate enough memory for the array of dirty rectangles + dirtyRectangles.resize ((size_t) dirtyRegionsInBackBuffer.getNumRectangles()); + + // Fill the array of dirty rectangles, intersecting each paint area with the swap chain buffer + presentParameters.pDirtyRects = dirtyRectangles.data(); + presentParameters.DirtyRectsCount = 0; + + for (const auto& area : dirtyRegionsInBackBuffer) + { + if (const auto intersection = area.getIntersection (swapChainSize); ! intersection.isEmpty()) + presentParameters.pDirtyRects[presentParameters.DirtyRectsCount++] = D2DUtilities::toRECT (intersection); + } } // Present the freshly painted buffer