Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1733 CGContextClearRect: Support to clear rect if clipping is not set #1743

Merged
merged 2 commits into from
Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Frameworks/CoreGraphics/CGContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2068,14 +2068,21 @@ void CGContextShowGlyphsWithAdvances(CGContextRef context, const CGGlyph* glyphs

#pragma region Drawing Operations - Basic Shapes
/**
@Status Interoperable
@Status Caveat
@Notes only supports the scenario where clipping is not set.
Copy link

@DHowett-MSFT DHowett-MSFT Jan 19, 2017

Choose a reason for hiding this comment

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

Also,

  • Only works on untransformed coordinates. The cleared region will be cleared in device space.
    #Resolved

Also only works on untransformed coordinates.
The cleared region will be cleared in device space.
*/
void CGContextClearRect(CGContextRef context, CGRect rect) {
NOISY_RETURN_IF_NULL(context);
ComPtr<ID2D1DeviceContext> deviceContext = context->DeviceContext();
deviceContext->PushAxisAlignedClip(__CGRectToD2D_F(rect), D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
deviceContext->Clear(nullptr); // transparent black clear
deviceContext->PopAxisAlignedClip();
if (!context->CurrentGState().clippingGeometry) {
deviceContext->BeginDraw();
deviceContext->PushAxisAlignedClip(__CGRectToD2D_F(rect), D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
deviceContext->Clear(nullptr); // transparent black clear
deviceContext->PopAxisAlignedClip();
deviceContext->EndDraw();
}
}

HRESULT __CGContext::_CreateShadowEffect(ID2D1Image* inputImage, ID2D1Effect** outShadowEffect) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ DISABLED_DRAW_TEST_F(CGContextFill, ConcentricRectsWinding, WhiteBackgroundTest<
CGPathRelease(path);
}

DRAW_TEST_F(CGContextFill, ClearRect, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1);
CGContextFillRect(context, bounds);

CGRect borderRect = CGRectInset(bounds, 30, 50);
CGContextClearRect(context, borderRect);
}

DISABLED_DRAW_TEST_F(CGContextFill, ConcentricRectsEvenOdd, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();
Expand Down