Skip to content

Commit

Permalink
CoreGraphicsContext: Fix issue where clipping a gradient on a layer-b…
Browse files Browse the repository at this point in the history
…acked view could cause rendering glitches
  • Loading branch information
reuk committed May 4, 2023
1 parent b56f386 commit 8ed3618
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 37 deletions.
Expand Up @@ -143,7 +143,6 @@ class CoreGraphicsContext : public LowLevelGraphicsContext

void setContextClipToPath (const Path&, const AffineTransform&);
void drawGradient();
void createPath (const Path&) const;
void createPath (const Path&, const AffineTransform&) const;
void flip() const;
void applyTransform (const AffineTransform&) const;
Expand Down
42 changes: 6 additions & 36 deletions modules/juce_graphics/native/juce_CoreGraphicsContext_mac.mm
Expand Up @@ -497,26 +497,14 @@ static CGBitmapInfo getCGImageFlags (const Image::PixelFormat& format)
{
ScopedCGContextState scopedState (context.get());

if (state->fillType.isColour())
{
flip();
applyTransform (transform);
createPath (path);
setContextClipToPath (path, transform);

if (path.isUsingNonZeroWinding())
CGContextFillPath (context.get());
else
CGContextEOFillPath (context.get());
}
if (state->fillType.isColour())
CGContextFillRect (context.get(), CGContextGetClipBoundingBox (context.get()));
else if (state->fillType.isGradient())
drawGradient();
else
{
setContextClipToPath (path, transform);

if (state->fillType.isGradient())
drawGradient();
else
drawImage (state->fillType.image, state->fillType.transform, true);
}
drawImage (state->fillType.image, state->fillType.transform, true);
}

void CoreGraphicsContext::drawImage (const Image& sourceImage, const AffineTransform& transform)
Expand Down Expand Up @@ -770,24 +758,6 @@ static CGGradientRef createGradient (const ColourGradient& g, CGColorSpaceRef co
kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
}

void CoreGraphicsContext::createPath (const Path& path) const
{
CGContextBeginPath (context.get());

for (Path::Iterator i (path); i.next();)
{
switch (i.elementType)
{
case Path::Iterator::startNewSubPath: CGContextMoveToPoint (context.get(), i.x1, i.y1); break;
case Path::Iterator::lineTo: CGContextAddLineToPoint (context.get(), i.x1, i.y1); break;
case Path::Iterator::quadraticTo: CGContextAddQuadCurveToPoint (context.get(), i.x1, i.y1, i.x2, i.y2); break;
case Path::Iterator::cubicTo: CGContextAddCurveToPoint (context.get(), i.x1, i.y1, i.x2, i.y2, i.x3, i.y3); break;
case Path::Iterator::closePath: CGContextClosePath (context.get()); break;
default: jassertfalse; break;
}
}
}

void CoreGraphicsContext::createPath (const Path& path, const AffineTransform& transform) const
{
CGContextBeginPath (context.get());
Expand Down

1 comment on commit 8ed3618

@talaviram
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
Just logging this also here in case it got slipped.
This commit apparently also introduces a regression.

https://forum.juce.com/t/reduceclipregion-and-fillrectlist-results-in-broken-drawing-on-macos/56051/8?u=ttg

Please sign in to comment.