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

Use _CGContextPushBegin/PopEndDraw for Drawing Tests #1870

Merged
merged 2 commits into from
Jan 28, 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
9 changes: 5 additions & 4 deletions Frameworks/CoreGraphics/CGContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2126,11 +2126,11 @@ void CGContextClearRect(CGContextRef context, CGRect rect) {
NOISY_RETURN_IF_NULL(context);
ComPtr<ID2D1DeviceContext> deviceContext = context->DeviceContext();
if (!context->CurrentGState().clippingGeometry) {
deviceContext->BeginDraw();
_CGContextPushBeginDraw(context);
deviceContext->PushAxisAlignedClip(__CGRectToD2D_F(rect), D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
deviceContext->Clear(nullptr); // transparent black clear
deviceContext->PopAxisAlignedClip();
deviceContext->EndDraw();
_CGContextPopEndDraw(context);
}
}

Expand Down Expand Up @@ -2830,8 +2830,9 @@ CGContextRef CGBitmapContextCreate(void* data,

/**
@Status Caveat
@Notes If data is provided, it can only be in one of the few pixel formats Direct2D can render to in system memory: (P)RGBA, (P)BGRA, or Alpha8. If a buffer is
provided for a grayscale image, render operations will be carried out into an Alpha8 buffer instead.
@Notes If data is provided, it can only be in one of the few pixel formats Direct2D can render to in system memory:
Copy link

@DHowett-MSFT DHowett-MSFT Jan 28, 2017

Choose a reason for hiding this comment

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

saddest comment. can you reflow this so clang-format doesn't? 😄 #Resolved

(P)RGBA, (P)BGRA, or Alpha8.
If a buffer is provided for a grayscale image, render operations will be carried out into an Alpha8 buffer instead.
Luminance values will be discarded in favour of alpha values.
*/
CGContextRef CGBitmapContextCreateWithData(void* data,
Expand Down
16 changes: 14 additions & 2 deletions tests/UnitTests/CoreGraphics.drawing/DrawingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <Starboard/SmartTypes.h>
#include <memory>

#if WINOBJC // Test with _CGContextPushBegin/PopEndDraw
#import "CGContextInternal.h"
#endif

static const CGSize g_defaultCanvasSize{ 512.f, 256.f };

template <typename TComparator>
Expand All @@ -34,10 +38,14 @@ void testing::DrawTest<TComparator>::SetUp() {
CGSize size = CanvasSize();

auto deviceColorSpace = woc::MakeStrongCF<CGColorSpaceRef>(CGColorSpaceCreateDeviceRGB());
_context.reset(CGBitmapContextCreate(
nullptr, size.width, size.height, 8, size.width * 4, deviceColorSpace, kCGImageAlphaPremultipliedFirst));
_context.reset(
CGBitmapContextCreate(nullptr, size.width, size.height, 8, size.width * 4, deviceColorSpace, kCGImageAlphaPremultipliedFirst));
ASSERT_NE(nullptr, _context);

#if WINOBJC // Validate that the results are correct even under batched drawing from _CGContextPushBegin/PopEndDraw
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why I didn't think of doing this earlier, sorry everyone!

Copy link

@DHowett-MSFT DHowett-MSFT Jan 28, 2017

Choose a reason for hiding this comment

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

It might even be more correct to do this in CGBitmapContext.

Here's what we can potentially do:

If the user passes !data, we push a begin draw. When they call CreateImage/GetImage, we pop an endDraw if we know we are in control of the data.

That way, people using data get immediate mode rendering, and people not using data automatically get batched mode rendering.

This opens up some testing avenues that don't require internal implementation details (pass data, do not pass data, etc.).

I do, however, think this is the right thing to do here until we normalize on a strategy for bitmap contexts. #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I'm not sure what you're envisioning for how we know if we control the data (will eventually call Create/GetImage). Leaving as-is for now.


In reply to: 98318678 [](ancestors = 98318678)

_CGContextPushBeginDraw(_context);
#endif

_bounds = { CGPointZero, size };

SetUpContext();
Expand Down Expand Up @@ -66,6 +74,10 @@ template <typename TComparator>
void testing::DrawTest<TComparator>::TearDown() {
CGContextRef context = GetDrawingContext();

#if WINOBJC // Validate that the results are correct even under batched drawing from _CGContextPushBegin/PopEndDraw
_CGContextPopEndDraw(_context);
#endif

// Generate image from context.
woc::unique_cf<CGImageRef> image{ CGBitmapContextCreateImage(context) };
ASSERT_NE(nullptr, image);
Expand Down