Skip to content

Commit 81e4d59

Browse files
committed
Direct2D: Avoid unnecessarily transforming solid colour brush
The changes were not cleared between frames, so they could end up accumulating and causing floating-point exceptions.
1 parent 7981957 commit 81e4d59

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

modules/juce_graphics/native/juce_Direct2DGraphicsContext_windows.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,13 @@ void Direct2DGraphicsContext::drawGlyphs (Span<const uint16_t> glyphNumbers,
11301130
if (brush == nullptr)
11311131
return;
11321132

1133+
const auto getBrushTransform = [] (auto brushIn) -> AffineTransform
1134+
{
1135+
D2D1::Matrix3x2F matrix{};
1136+
brushIn->GetTransform (&matrix);
1137+
return D2DUtilities::matrixToTransform (matrix);
1138+
};
1139+
11331140
applyPendingClipList();
11341141

11351142
D2D1_POINT_2F baselineOrigin { 0.0f, 0.0f };
@@ -1140,13 +1147,18 @@ void Direct2DGraphicsContext::drawGlyphs (Span<const uint16_t> glyphNumbers,
11401147
}
11411148
else
11421149
{
1143-
D2D1::Matrix3x2F matrix{};
1144-
brush->GetTransform (&matrix);
1145-
const auto brushTransform = D2DUtilities::matrixToTransform (matrix);
1146-
brush->SetTransform (D2DUtilities::transformToMatrix (brushTransform.followedBy (textTransform.inverted())));
1150+
if (brush != currentState->colourBrush)
1151+
{
1152+
const auto brushTransform = getBrushTransform (brush);
1153+
brush->SetTransform (D2DUtilities::transformToMatrix (brushTransform.followedBy (textTransform.inverted())));
1154+
}
1155+
11471156
getPimpl()->setDeviceContextTransform (textAndWorldTransform);
11481157
}
11491158

1159+
// There's no need to transform a plain colour brush
1160+
jassert (brush != currentState->colourBrush || getBrushTransform (brush).isIdentity());
1161+
11501162
auto& run = getPimpl()->glyphRun;
11511163
run.replace (positions, fontScale);
11521164

0 commit comments

Comments
 (0)