Index: Source/platform/graphics/GraphicsContextTest.cpp |
diff --git a/Source/platform/graphics/GraphicsContextTest.cpp b/Source/platform/graphics/GraphicsContextTest.cpp |
index fd4a9588621b018e68224fc9756d57c97ef4e61d..3b8b330631bab15276ec5862d2b2bb16b35a5393 100644 |
--- a/Source/platform/graphics/GraphicsContextTest.cpp |
+++ b/Source/platform/graphics/GraphicsContextTest.cpp |
@@ -1042,6 +1042,59 @@ TEST(GraphicsContextTest, PreserveOpaqueOnlyMattersForFirstLayer) |
EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); |
} |
+TEST(GraphicsContextTest, OpaqueRegionForLayer) |
+{ |
+ // Set non-rect device clip. |
+ Path path; |
+ path.moveTo(FloatPoint(0, 0)); |
+ path.addLineTo(FloatPoint(50, 50)); |
+ |
+ SkCanvas canvas(50, 50); |
danakj
2014/08/05 13:53:28
can you make the canvas bigger than the path's bou
sohanjg
2014/08/05 15:23:21
Done.
|
+ GraphicsContext context(&canvas); |
+ context.clipPath(path, RULE_EVENODD); |
+ context.setRegionTrackingMode(GraphicsContext::RegionTrackingOpaque); |
+ |
+ Color opaque(1.0f, 0.0f, 0.0f, 1.0f); |
+ |
+ // Set Opaque Rect. |
danakj
2014/08/05 13:53:28
Say why not what, all of these comments just say w
sohanjg
2014/08/05 15:23:20
Done.
|
+ context.fillRect(FloatRect(30, 30, 90, 90), opaque, CompositeSourceOver); |
danakj
2014/08/05 13:53:28
isn't this outside the bounds of the canvas?
sohanjg
2014/08/05 15:23:21
Done.
I was trying to avoid markRectAsNonOpaque ea
|
+ // Begin non-opaque-preserving layer. |
+ context.setCompositeOperation(CompositeSourceOut); |
+ context.beginTransparencyLayer(0.5); |
+ |
+ context.endLayer(); |
+ EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); |
+ |
+ // Set rect device clip. |
+ SkBitmap bitmap; |
+ ASSERT_TRUE(bitmap.allocN32Pixels(50, 50)); |
+ bitmap.eraseColor(0); |
+ SkCanvas canvas2(bitmap); |
+ |
+ GraphicsContext context2(&canvas2); |
+ context2.setRegionTrackingMode(GraphicsContext::RegionTrackingOpaque); |
+ |
+ // Set Opaque Rect. |
+ context2.fillRect(FloatRect(30, 30, 90, 90), opaque, CompositeSourceOver); |
+ // Begin non-opaque-preserving layer. |
+ context2.setCompositeOperation(CompositeSourceOut); |
+ context2.beginTransparencyLayer(0.5); |
+ |
+ context2.endLayer(); |
+ EXPECT_EQ_RECT(IntRect(), context2.opaqueRegion().asRect()); |
+ EXPECT_PIXELS_MATCH(bitmap, context2.opaqueRegion().asRect()); |
+ |
+ // Set Opaque Rect. |
+ context2.fillRect(FloatRect(30, 30, 90, 90), opaque, CompositeSourceOver); |
+ // Begin opaque-preserving layer. |
+ context2.setCompositeOperation(CompositeSourceOver); |
+ context2.beginTransparencyLayer(0.5); |
+ |
+ context2.endLayer(); |
+ EXPECT_EQ_RECT(IntRect(30, 30, 20, 20), context2.opaqueRegion().asRect()); |
+ EXPECT_PIXELS_MATCH(bitmap, context2.opaqueRegion().asRect()); |
+} |
+ |
#define DISPATCH1(c1, c2, op, param1) do { c1.op(param1); c2.op(param1); } while (0); |
#define DISPATCH2(c1, c2, op, param1, param2) do { c1.op(param1, param2); c2.op(param1, param2); } while (0); |