From 1a1dc90a2486e257829ef0a69f67285e17f71244 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 1 Oct 2024 14:39:54 +0100 Subject: [PATCH] Direct2D: Remove frameSize member from Direct2DHwndContext pimpl --- .../juce_Direct2DHwndContext_windows.cpp | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/modules/juce_graphics/native/juce_Direct2DHwndContext_windows.cpp b/modules/juce_graphics/native/juce_Direct2DHwndContext_windows.cpp index b7d984f463..761288dc71 100644 --- a/modules/juce_graphics/native/juce_Direct2DHwndContext_windows.cpp +++ b/modules/juce_graphics/native/juce_Direct2DHwndContext_windows.cpp @@ -315,7 +315,6 @@ private: BackBufferLock presentation; std::optional compositionTree; RectangleList deferredRepaints; - Rectangle frameSize; std::vector dirtyRectangles; bool resizing = false; int64 lastFinishFrameTicks = 0; @@ -341,12 +340,12 @@ private: if (! deviceResources.has_value()) return false; - if (! hwnd || frameSize.isEmpty()) + if (! hwnd || getClientRect().isEmpty()) return false; if (! swap.canPaint()) { - if (auto hr = swap.create (hwnd, frameSize, adapter); FAILED (hr)) + if (auto hr = swap.create (hwnd, getClientRect(), adapter); FAILED (hr)) return false; if (auto hr = swap.createBuffer (getDeviceContext()); FAILED (hr)) @@ -423,9 +422,7 @@ public: // that's not really spelled out in the documentation. // This method is called when the component peer receives WM_SHOWWINDOW prepare(); - - frameSize = getClientRect(); - deferredRepaints = frameSize; + deferredRepaints = getClientRect(); } Rectangle getClientRect() const @@ -466,11 +463,10 @@ public: void setSize (Rectangle size) { - if (size == frameSize || size.isEmpty()) + if (size == swap.getSize() || size.isEmpty()) return; // Require the entire window to be repainted - frameSize = size; deferredRepaints = size; InvalidateRect (hwnd, nullptr, TRUE); @@ -502,8 +498,9 @@ public: { if (resizing) { - deferredRepaints = frameSize; - setSize (getClientRect()); + const auto size = getClientRect(); + setSize (size); + deferredRepaints = size; } auto* savedState = Pimpl::startFrame (dpiScale); @@ -622,7 +619,7 @@ public: const auto context = getDeviceContext(); - if (frameSize.isEmpty() || context == nullptr || swap.buffer == nullptr) + if (context == nullptr || swap.buffer == nullptr) return {}; // Create the bitmap to receive the snapshot @@ -630,7 +627,8 @@ public: bitmapProperties.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET; bitmapProperties.pixelFormat = swap.buffer->GetPixelFormat(); - const D2D_SIZE_U size { (UINT32) frameSize.getWidth(), (UINT32) frameSize.getHeight() }; + const auto swapRect = swap.getSize(); + const auto size = D2D1::SizeU ((UINT32) swapRect.getWidth(), (UINT32) swapRect.getHeight()); ComSmartPtr snapshot; @@ -643,7 +641,7 @@ public: // Copy the swap chain buffer to the bitmap snapshot D2D_POINT_2U p { 0, 0 }; - const auto sourceRect = D2DUtilities::toRECT_U (frameSize); + const auto sourceRect = D2DUtilities::toRECT_U (swapRect); if (const auto hr = snapshot->CopyFromBitmap (&p, swap.buffer, &sourceRect); FAILED (hr)) return {};