From 7991c91fb2d951e7e39620788e33c895f6daefc2 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 22 Apr 2024 21:05:18 +0100 Subject: [PATCH] D2D: Move null checks --- .../juce_Direct2DGraphicsContext_windows.cpp | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp b/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp index 74ca54db6c..73811bff0a 100644 --- a/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp +++ b/modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp @@ -699,9 +699,6 @@ public: const auto brush = owner.currentState->getBrush (fillTransform); - if (brush == nullptr) - return; - if (transform.isOnlyTranslated) { const auto translated = shape + transform.offset.toFloat(); @@ -1181,7 +1178,7 @@ void Direct2DGraphicsContext::fillRect (const Rectangle& r, bool replaceExi { if (replaceExistingContents) deviceContext->Clear (D2DUtilities::toCOLOR_F (clearColour)); - else + else if (brush != nullptr) deviceContext->FillRectangle (D2DUtilities::toRECT_F (rect), brush); }; @@ -1192,7 +1189,8 @@ void Direct2DGraphicsContext::fillRect (const Rectangle& r) { auto fill = [] (Rectangle rect, ComSmartPtr deviceContext, ComSmartPtr brush) { - deviceContext->FillRectangle (D2DUtilities::toRECT_F (rect), brush); + if (brush != nullptr) + deviceContext->FillRectangle (D2DUtilities::toRECT_F (rect), brush); }; getPimpl()->paintPrimitive (r, fill); @@ -1205,8 +1203,9 @@ void Direct2DGraphicsContext::fillRectList (const RectangleList& list) auto fill = [] (const RectangleList& l, ComSmartPtr deviceContext, ComSmartPtr brush) { - for (const auto& r : l) - deviceContext->FillRectangle (D2DUtilities::toRECT_F (r), brush); + if (brush != nullptr) + for (const auto& r : l) + deviceContext->FillRectangle (D2DUtilities::toRECT_F (r), brush); }; getPimpl()->paintPrimitive (list, fill); @@ -1222,7 +1221,8 @@ void Direct2DGraphicsContext::drawRect (const Rectangle& r, float lineThi auto draw = [&] (Rectangle rect, ComSmartPtr deviceContext, ComSmartPtr brush) { - deviceContext->DrawRectangle (D2DUtilities::toRECT_F (rect), brush, lineThickness); + if (brush != nullptr) + deviceContext->DrawRectangle (D2DUtilities::toRECT_F (rect), brush, lineThickness); }; auto reducedR = r.reduced (lineThickness * 0.5f); @@ -1369,6 +1369,9 @@ void Direct2DGraphicsContext::drawLineWithThickness (const Line& line, fl { auto draw = [&] (Line l, ComSmartPtr deviceContext, ComSmartPtr brush) { + if (brush == nullptr) + return; + const auto makePoint = [] (const auto& x) { return D2D1::Point2F (x.getX(), x.getY()); }; deviceContext->DrawLine (makePoint (l.getStart()), makePoint (l.getEnd()), @@ -1405,6 +1408,9 @@ void Direct2DGraphicsContext::drawRoundedRectangle (const Rectangle& area { auto draw = [&] (Rectangle rect, ComSmartPtr deviceContext, ComSmartPtr brush) { + if (brush == nullptr) + return; + D2D1_ROUNDED_RECT roundedRect { D2DUtilities::toRECT_F (rect), cornerSize, cornerSize }; deviceContext->DrawRoundedRectangle (roundedRect, brush, lineThickness); }; @@ -1416,6 +1422,9 @@ void Direct2DGraphicsContext::fillRoundedRectangle (const Rectangle& area { auto fill = [&] (Rectangle rect, ComSmartPtr deviceContext, ComSmartPtr brush) { + if (brush == nullptr) + return; + D2D1_ROUNDED_RECT roundedRect { D2DUtilities::toRECT_F (rect), cornerSize, cornerSize }; deviceContext->FillRoundedRectangle (roundedRect, brush); }; @@ -1427,6 +1436,9 @@ void Direct2DGraphicsContext::drawEllipse (const Rectangle& area, float l { auto draw = [&] (Rectangle rect, ComSmartPtr deviceContext, ComSmartPtr brush) { + if (brush == nullptr) + return; + auto centre = rect.getCentre(); D2D1_ELLIPSE ellipse { { centre.x, centre.y }, rect.proportionOfWidth (0.5f), rect.proportionOfHeight (0.5f) }; deviceContext->DrawEllipse (ellipse, brush, lineThickness); @@ -1439,6 +1451,9 @@ void Direct2DGraphicsContext::fillEllipse (const Rectangle& area) { auto fill = [&] (Rectangle rect, ComSmartPtr deviceContext, ComSmartPtr brush) { + if (brush == nullptr) + return; + auto centre = rect.getCentre(); D2D1_ELLIPSE ellipse { { centre.x, centre.y }, rect.proportionOfWidth (0.5f), rect.proportionOfHeight (0.5f) }; deviceContext->FillEllipse (ellipse, brush);