Index: Source/platform/graphics/GraphicsContextTest.cpp |
diff --git a/Source/platform/graphics/GraphicsContextTest.cpp b/Source/platform/graphics/GraphicsContextTest.cpp |
index fd4a9588621b018e68224fc9756d57c97ef4e61d..0fc10ec267106941a8c4fd679fa04e9a8247386a 100644 |
--- a/Source/platform/graphics/GraphicsContextTest.cpp |
+++ b/Source/platform/graphics/GraphicsContextTest.cpp |
@@ -1042,6 +1042,81 @@ TEST(GraphicsContextTest, PreserveOpaqueOnlyMattersForFirstLayer) |
EXPECT_PIXELS_MATCH_EXACT(bitmap, context.opaqueRegion().asRect()); |
} |
+TEST(GraphicsContextTest, OpaqueRegionForLayerWithNonRectDeviceClip) |
+{ |
+ SkBitmap bitmap; |
+ ASSERT_TRUE(bitmap.allocN32Pixels(100, 100)); |
+ bitmap.eraseColor(0); |
+ SkCanvas canvas(bitmap); |
+ |
+ GraphicsContext context(&canvas); |
+ context.setRegionTrackingMode(GraphicsContext::RegionTrackingOpaque); |
+ Color opaque(1.0f, 0.0f, 0.0f, 1.0f); |
+ |
+ context.fillRect(FloatRect(30, 30, 90, 90), opaque, CompositeSourceOver); |
+ |
+ context.setCompositeOperation(CompositeSourceOver); |
+ context.beginTransparencyLayer(0.5); |
+ context.endLayer(); |
+ EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), context.opaqueRegion().asRect()); |
+ |
+ Path path; |
+ path.moveTo(FloatPoint(0, 0)); |
+ path.addLineTo(FloatPoint(50, 50)); |
+ |
+ // For opaque preserving mode and deviceClip is not rect |
+ // we will not alter opaque rect. |
+ context.clipPath(path, RULE_EVENODD); |
+ |
+ context.setCompositeOperation(CompositeSourceOver); |
+ context.beginTransparencyLayer(0.5); |
+ context.endLayer(); |
+ EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), context.opaqueRegion().asRect()); |
+ |
+ // For non-opaque preserving mode and deviceClip is not rect |
+ // we will mark opaque rect as empty. |
+ context.setCompositeOperation(CompositeSourceOut); |
+ context.beginTransparencyLayer(0.5); |
+ |
+ context.endLayer(); |
+ EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); |
+} |
+ |
+TEST(GraphicsContextTest, OpaqueRegionForLayerWithRectDeviceClip) |
+{ |
+ SkBitmap bitmap; |
+ ASSERT_TRUE(bitmap.allocN32Pixels(100, 100)); |
+ bitmap.eraseColor(0); |
+ SkCanvas canvas(bitmap); |
+ |
+ Color opaque(1.0f, 0.0f, 0.0f, 1.0f); |
+ |
+ GraphicsContext context(&canvas); |
+ context.setRegionTrackingMode(GraphicsContext::RegionTrackingOpaque); |
+ |
+ context.fillRect(FloatRect(30, 30, 90, 90), opaque, CompositeSourceOver); |
+ EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), context.opaqueRegion().asRect()); |
+ |
+ // For non-opaque preserving mode and deviceClip is rect |
+ // we will mark device clip rect as non opaque. |
+ context.setCompositeOperation(CompositeSourceOut); |
+ context.beginTransparencyLayer(0.5); |
+ context.endLayer(); |
+ EXPECT_EQ_RECT(IntRect(), context.opaqueRegion().asRect()); |
+ EXPECT_PIXELS_MATCH(bitmap, context.opaqueRegion().asRect()); |
+ |
+ context.clip(FloatRect(0, 0, 50, 50)); |
+ context.fillRect(FloatRect(20, 20, 100, 100), opaque, CompositeSourceOver); |
+ |
+ // For opaque preserving mode and deviceClip is rect |
+ // we will intersect device clip rect with src opaque rect. |
+ context.setCompositeOperation(CompositeSourceOver); |
+ context.beginTransparencyLayer(0.5); |
+ context.endLayer(); |
+ EXPECT_EQ_RECT(IntRect(20, 20, 30, 30), context.opaqueRegion().asRect()); |
+ EXPECT_PIXELS_MATCH(bitmap, context.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); |