diff --git a/modules/juce_graphics/images/juce_Image.cpp b/modules/juce_graphics/images/juce_Image.cpp index e593d95392..c001bf5669 100644 --- a/modules/juce_graphics/images/juce_Image.cpp +++ b/modules/juce_graphics/images/juce_Image.cpp @@ -522,12 +522,12 @@ void Image::BitmapData::setPixelColour (int x, int y, Colour colour) const noexc //============================================================================== void Image::clear (const Rectangle& area, Colour colourToClearTo) { - if (image != nullptr) - { - auto g = image->createLowLevelContext(); - g->setFill (colourToClearTo); - g->fillRect (area, true); - } + if (image == nullptr) + return; + + auto g = image->createLowLevelContext(); + g->setFill (colourToClearTo); + g->fillRect (area, true); } //============================================================================== diff --git a/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp b/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp index fac464eaef..74ca54db6c 100644 --- a/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp +++ b/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp @@ -466,11 +466,6 @@ public: targetAlpha = alpha; } - virtual void clearBackground() - { - deviceResources.deviceContext.context->Clear (backgroundColor); - } - virtual SavedState* startFrame (float dpiScale) { prepare(); @@ -1176,18 +1171,18 @@ void Direct2DGraphicsContext::setInterpolationQuality (Graphics::ResamplingQuali void Direct2DGraphicsContext::fillRect (const Rectangle& r, bool replaceExistingContents) { if (replaceExistingContents) - { - JUCE_SCOPED_TRACE_EVENT_FRAME_RECT_I32 (etw::fillRectReplace, etw::direct2dKeyword, getFrameId(), r); - - applyPendingClipList(); clipToRectangle (r); - getPimpl()->clearBackground(); - currentState->popTopLayer(); - } - auto fill = [] (Rectangle rect, ComSmartPtr deviceContext, ComSmartPtr brush) + const auto clearColour = currentState->fillType.colour; + + auto fill = [replaceExistingContents, clearColour] (Rectangle rect, + ComSmartPtr deviceContext, + ComSmartPtr brush) { - deviceContext->FillRectangle (D2DUtilities::toRECT_F (rect), brush); + if (replaceExistingContents) + deviceContext->Clear (D2DUtilities::toCOLOR_F (clearColour)); + else + deviceContext->FillRectangle (D2DUtilities::toRECT_F (rect), brush); }; getPimpl()->paintPrimitive (r.toFloat(), fill);