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

Direct2D: Refactor paintAreas handling in graphics contexts

This commit is contained in:
reuk 2024-08-12 20:15:06 +01:00
parent e2b9dd9a05
commit c94b8e1712
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
3 changed files with 19 additions and 25 deletions

View file

@ -547,7 +547,6 @@ protected:
Direct2DGraphicsContext& owner;
SharedResourcePointer<DirectX> directX;
SharedResourcePointer<Direct2DFactories> directWrite;
RectangleList<int> paintAreas;
std::optional<Direct2DDeviceResources> deviceResources;
@ -568,8 +567,6 @@ protected:
virtual ComSmartPtr<ID2D1Image> getDeviceContextTarget() const = 0;
virtual void updatePaintAreas() = 0;
virtual bool checkPaintReady()
{
return deviceResources.has_value();
@ -602,8 +599,8 @@ public:
prepare();
// Anything to paint?
updatePaintAreas();
auto paintBounds = paintAreas.getBounds();
const auto paintAreas = getPaintAreas();
const auto paintBounds = paintAreas.getBounds();
if (! getFrameSize().intersects (paintBounds) || paintBounds.isEmpty())
return nullptr;
@ -705,12 +702,8 @@ public:
return deviceResources->deviceContext;
}
const auto& getPaintAreas() const noexcept
{
return paintAreas;
}
virtual Rectangle<int> getFrameSize() = 0;
virtual RectangleList<int> getPaintAreas() const = 0;
virtual Rectangle<int> getFrameSize() const = 0;
void setDeviceContextTransform (AffineTransform transform)
{
@ -893,7 +886,8 @@ Direct2DGraphicsContext::~Direct2DGraphicsContext() = default;
bool Direct2DGraphicsContext::startFrame (float dpiScale)
{
auto pimpl = getPimpl();
const auto pimpl = getPimpl();
const auto paintAreas = pimpl->getPaintAreas();
currentState = pimpl->startFrame (dpiScale);
if (currentState == nullptr)
@ -903,7 +897,7 @@ bool Direct2DGraphicsContext::startFrame (float dpiScale)
{
resetPendingClipList();
clipToRectangleList (pimpl->getPaintAreas());
clipToRectangleList (paintAreas);
// Clear the buffer *after* setting the clip region
clearTargetBuffer();

View file

@ -371,18 +371,18 @@ private:
Pimpl::teardown();
}
void updatePaintAreas() override
RectangleList<int> getPaintAreas() const override
{
// Does the entire buffer need to be filled?
if (swap.state == SwapChain::State::bufferAllocated || resizing)
deferredRepaints = swap.getSize();
return swap.getSize();
// If the window alpha is less than 1.0, clip to the union of the
// deferred repaints so the device context Clear() works correctly
if (targetAlpha < 1.0f || ! opaque)
paintAreas = deferredRepaints.getBounds();
else
paintAreas = deferredRepaints;
return deferredRepaints.getBounds();
return deferredRepaints;
}
bool checkPaintReady() override
@ -436,7 +436,7 @@ public:
return Rectangle<int>::leftTopRightBottom (clientRect.left, clientRect.top, clientRect.right, clientRect.bottom);
}
Rectangle<int> getFrameSize() override
Rectangle<int> getFrameSize() const override
{
return getClientRect();
}
@ -523,7 +523,7 @@ public:
// next frame
JUCE_TRACE_LOG_D2D_PAINT_CALL (etw::direct2dHwndPaintStart, owner.getFrameId());
presentation.getPresentation()->setPaintAreas (paintAreas);
presentation.getPresentation()->setPaintAreas (getPaintAreas());
deferredRepaints.clear();

View file

@ -46,15 +46,15 @@ public:
{
}
Rectangle<int> getFrameSize() override
Rectangle<int> getFrameSize() const override
{
const auto targetBitmap = getBitmap();
if (targetBitmap == nullptr)
return {};
auto size = targetBitmap->GetSize();
return Rectangle<float> { size.width, size.height }.getSmallestIntegerContainer();
const auto size = targetBitmap->GetSize();
return { (int) size.width, (int) size.height };
}
ComSmartPtr<ID2D1Image> getDeviceContextTarget() const override
@ -81,9 +81,9 @@ private:
return target->getAdapterD2D1Bitmap();
}
void updatePaintAreas() override
RectangleList<int> getPaintAreas() const override
{
paintAreas = getFrameSize();
return getFrameSize();
}
Direct2DPixelData::Ptr target;