Chromium Code Reviews| Index: third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositorTest.cpp |
| diff --git a/third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositorTest.cpp b/third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositorTest.cpp |
| index 9385eac88be27466cb47953a261f6efc4669165b..adda589762db2b9b3a4e8bfd491a9f453948a609 100644 |
| --- a/third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositorTest.cpp |
| +++ b/third_party/WebKit/Source/platform/graphics/compositing/PaintArtifactCompositorTest.cpp |
| @@ -28,7 +28,6 @@ |
| #include <memory> |
| namespace blink { |
| -namespace { |
| using ::blink::testing::createOpacityOnlyEffect; |
| using ::testing::Pointee; |
| @@ -142,9 +141,9 @@ TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneChunkWithAnOffset) { |
| TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneTransform) { |
| // A 90 degree clockwise rotation about (100, 100). |
| RefPtr<TransformPaintPropertyNode> transform = |
| - TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), |
| - TransformationMatrix().rotate(90), |
| - FloatPoint3D(100, 100, 0)); |
| + TransformPaintPropertyNode::create( |
| + TransformPaintPropertyNode::root(), TransformationMatrix().rotate(90), |
| + FloatPoint3D(100, 100, 0), false, 0, CompositingReason3DTransform); |
| TestPaintArtifact artifact; |
| artifact |
| @@ -192,9 +191,9 @@ TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneTransform) { |
| TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TransformCombining) { |
| // A translation by (5, 5) within a 2x scale about (10, 10). |
| RefPtr<TransformPaintPropertyNode> transform1 = |
| - TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), |
| - TransformationMatrix().scale(2), |
| - FloatPoint3D(10, 10, 0)); |
| + TransformPaintPropertyNode::create( |
| + TransformPaintPropertyNode::root(), TransformationMatrix().scale(2), |
| + FloatPoint3D(10, 10, 0), false, 0, CompositingReason3DTransform); |
| RefPtr<TransformPaintPropertyNode> transform2 = |
| TransformPaintPropertyNode::create( |
| transform1, TransformationMatrix().translate(5, 5), FloatPoint3D()); |
| @@ -300,15 +299,18 @@ TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SortingContextID) { |
| // Establishes a 3D rendering context. |
| RefPtr<TransformPaintPropertyNode> transform2 = |
| TransformPaintPropertyNode::create(transform1, TransformationMatrix(), |
| - FloatPoint3D(), false, 1); |
| + FloatPoint3D(), false, 1, |
| + CompositingReason3DTransform); |
| // Extends the 3D rendering context of transform2. |
| RefPtr<TransformPaintPropertyNode> transform3 = |
| TransformPaintPropertyNode::create(transform2, TransformationMatrix(), |
| - FloatPoint3D(), false, 1); |
| + FloatPoint3D(), false, 1, |
| + CompositingReason3DTransform); |
| // Establishes a 3D rendering context distinct from transform2. |
| RefPtr<TransformPaintPropertyNode> transform4 = |
| TransformPaintPropertyNode::create(transform2, TransformationMatrix(), |
| - FloatPoint3D(), false, 2); |
| + FloatPoint3D(), false, 2, |
| + CompositingReason3DTransform); |
| TestPaintArtifact artifact; |
| artifact |
| @@ -401,10 +403,12 @@ TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneClip) { |
| TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) { |
| RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
| ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| - FloatRoundedRect(100, 100, 700, 700)); |
| + FloatRoundedRect(100, 100, 700, 700), |
| + CompositingReasonOverflowScrollingTouch); |
| RefPtr<ClipPaintPropertyNode> clip2 = |
| ClipPaintPropertyNode::create(clip1, TransformPaintPropertyNode::root(), |
| - FloatRoundedRect(200, 200, 700, 100)); |
| + FloatRoundedRect(200, 200, 700, 100), |
| + CompositingReasonOverflowScrollingTouch); |
| TestPaintArtifact artifact; |
| artifact |
| @@ -720,5 +724,281 @@ TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedScrollNodes) { |
| MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| } |
| -} // namespace |
| +TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeSimpleChunks) { |
| + TestPaintArtifact testArtifact; |
| + testArtifact |
| + .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| + EffectPaintPropertyNode::root()) |
| + .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| + testArtifact |
| + .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| + EffectPaintPropertyNode::root()) |
| + .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| + |
| + const PaintArtifact& artifact = testArtifact.build(); |
| + |
| + ASSERT_EQ(2u, artifact.paintChunks().size()); |
| + PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| + EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[1], |
| + pendingLayer)); |
| + |
| + update(artifact); |
| + |
| + ASSERT_EQ(1u, contentLayerCount()); |
| + { |
| + Vector<RectWithColor> rectsWithColor; |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| + |
| + const cc::Layer* layer = contentLayerAt(0); |
| + EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| + } |
| +} |
| + |
| +TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeClip) { |
| + RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| + ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| + FloatRoundedRect(10, 20, 50, 60)); |
| + |
| + TestPaintArtifact testArtifact; |
| + testArtifact |
| + .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| + EffectPaintPropertyNode::root()) |
| + .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| + testArtifact |
| + .chunk(TransformPaintPropertyNode::root(), clip.get(), |
| + EffectPaintPropertyNode::root()) |
| + .rectDrawing(FloatRect(0, 0, 200, 300), Color::black); |
| + testArtifact |
| + .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| + EffectPaintPropertyNode::root()) |
| + .rectDrawing(FloatRect(0, 0, 300, 400), Color::gray); |
| + |
| + const PaintArtifact& artifact = testArtifact.build(); |
| + |
| + ASSERT_EQ(3u, artifact.paintChunks().size()); |
| + PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| + EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[1], |
| + pendingLayer)); |
| + pendingLayer.add(artifact.paintChunks()[1]); |
| + EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[2], |
| + pendingLayer)); |
| + |
| + update(artifact); |
| + |
| + ASSERT_EQ(1u, contentLayerCount()); |
| + { |
| + Vector<RectWithColor> rectsWithColor; |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| + // Clip is applied to this PaintChunk. |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(10, 20, 50, 60), Color::black)); |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(0, 0, 300, 400), Color::gray)); |
| + |
| + const cc::Layer* layer = contentLayerAt(0); |
| + EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| + } |
| +} |
| + |
| +TEST_F(PaintArtifactCompositorTestWithPropertyTrees, Merge2DTransform) { |
| + RefPtr<TransformPaintPropertyNode> transform = |
| + TransformPaintPropertyNode::create( |
| + TransformPaintPropertyNode::root(), |
| + TransformationMatrix().translate(50, 50), FloatPoint3D(100, 100, 0), |
| + false, 0); |
| + |
| + TestPaintArtifact testArtifact; |
| + testArtifact |
| + .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| + EffectPaintPropertyNode::root()) |
| + .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| + testArtifact |
| + .chunk(transform.get(), ClipPaintPropertyNode::root(), |
| + EffectPaintPropertyNode::root()) |
| + .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); |
| + testArtifact |
| + .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| + EffectPaintPropertyNode::root()) |
| + .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| + |
| + const PaintArtifact& artifact = testArtifact.build(); |
| + |
| + ASSERT_EQ(3u, artifact.paintChunks().size()); |
| + PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| + EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[1], |
| + pendingLayer)); |
| + pendingLayer.add(artifact.paintChunks()[1]); |
| + EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[2], |
| + pendingLayer)); |
| + |
| + update(artifact); |
| + |
| + ASSERT_EQ(1u, contentLayerCount()); |
| + { |
| + Vector<RectWithColor> rectsWithColor; |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| + // Transform is applied to this PaintChunk. |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(50, 50, 100, 100), Color::black)); |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| + |
| + const cc::Layer* layer = contentLayerAt(0); |
| + EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| + } |
| +} |
| + |
| +TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeOpacity) { |
| + float opacity = 2.0 / 255.0; |
| + RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| + EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| + ClipPaintPropertyNode::root(), CompositorFilterOperations(), opacity, |
| + SkBlendMode::kSrcOver); |
| + |
| + TestPaintArtifact testArtifact; |
| + testArtifact |
| + .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| + EffectPaintPropertyNode::root()) |
| + .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| + testArtifact |
| + .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| + effect.get()) |
| + .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); |
| + testArtifact |
| + .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| + EffectPaintPropertyNode::root()) |
| + .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| + |
| + const PaintArtifact& artifact = testArtifact.build(); |
| + |
| + ASSERT_EQ(3u, artifact.paintChunks().size()); |
| + PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| + EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[1], |
| + pendingLayer)); |
| + pendingLayer.add(artifact.paintChunks()[1]); |
| + EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[2], |
| + pendingLayer)); |
| + |
| + update(artifact); |
| + |
| + ASSERT_EQ(1u, contentLayerCount()); |
| + { |
| + Vector<RectWithColor> rectsWithColor; |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| + // Transform is applied to this PaintChunk. |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(0, 0, 100, 100), |
| + Color(Color::black).combineWithAlpha(opacity).rgb())); |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| + |
| + const cc::Layer* layer = contentLayerAt(0); |
| + EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| + } |
| +} |
| + |
| +TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeNested) { |
| + // Tests merging of an opacity effect, inside of a clip, inside of a |
| + // transform. |
| + |
| + RefPtr<TransformPaintPropertyNode> transform = |
| + TransformPaintPropertyNode::create( |
| + TransformPaintPropertyNode::root(), |
| + TransformationMatrix().translate(50, 50), FloatPoint3D(100, 100, 0), |
| + false, 0); |
| + |
| + RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| + ClipPaintPropertyNode::root(), transform.get(), |
| + FloatRoundedRect(10, 20, 50, 60)); |
| + |
| + float opacity = 2.0 / 255.0; |
| + RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| + EffectPaintPropertyNode::root(), transform.get(), clip.get(), |
| + CompositorFilterOperations(), opacity, SkBlendMode::kSrcOver); |
| + |
| + TestPaintArtifact testArtifact; |
| + testArtifact |
| + .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| + EffectPaintPropertyNode::root()) |
| + .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| + testArtifact.chunk(transform.get(), clip.get(), effect.get()) |
| + .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); |
| + testArtifact |
| + .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| + EffectPaintPropertyNode::root()) |
| + .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| + |
| + const PaintArtifact& artifact = testArtifact.build(); |
| + |
| + ASSERT_EQ(3u, artifact.paintChunks().size()); |
| + PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| + EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[1], |
| + pendingLayer)); |
| + pendingLayer.add(artifact.paintChunks()[1]); |
| + EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[2], |
| + pendingLayer)); |
| + |
| + update(artifact); |
| + |
| + ASSERT_EQ(1u, contentLayerCount()); |
| + { |
| + Vector<RectWithColor> rectsWithColor; |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| + // Transform is applied to this PaintChunk. |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(60, 70, 50, 60), |
| + Color(Color::black).combineWithAlpha(opacity).rgb())); |
| + rectsWithColor.push_back( |
| + RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| + |
| + const cc::Layer* layer = contentLayerAt(0); |
| + EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| + } |
| +} |
| + |
| +TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayer) { |
| + PaintChunk chunk1; |
| + chunk1.properties.propertyTreeState = PropertyTreeState( |
| + TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| + EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); |
| + chunk1.properties.backfaceHidden = true; |
| + chunk1.knownToBeOpaque = true; |
| + chunk1.bounds = FloatRect(0, 0, 30, 40); |
| + |
| + PaintArtifactCompositor::PendingLayer pendingLayer(chunk1); |
| + |
| + EXPECT_TRUE(pendingLayer.backfaceHidden); |
| + EXPECT_TRUE(pendingLayer.knownToBeOpaque); |
| + EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 40), pendingLayer.bounds); |
| + |
| + PaintChunk chunk2; |
| + chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; |
| + chunk2.properties.backfaceHidden = true; |
| + chunk2.knownToBeOpaque = false; |
| + chunk2.bounds = FloatRect(10, 20, 30, 40); |
| + pendingLayer.add(chunk2); |
| + |
| + EXPECT_TRUE(pendingLayer.backfaceHidden); |
| + EXPECT_FALSE(pendingLayer.knownToBeOpaque); |
| + EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 40, 60), pendingLayer.bounds); |
| + |
| + PaintChunk chunk3; |
| + chunk3.properties.propertyTreeState = chunk1.properties.propertyTreeState; |
| + chunk3.properties.backfaceHidden = true; |
| + chunk3.knownToBeOpaque = true; |
| + chunk3.bounds = FloatRect(-5, -25, 20, 20); |
| + pendingLayer.add(chunk3); |
| + |
| + EXPECT_TRUE(pendingLayer.backfaceHidden); |
| + EXPECT_FALSE(pendingLayer.knownToBeOpaque); |
| + EXPECT_FLOAT_RECT_EQ(FloatRect(-5, -25, 45, 85), pendingLayer.bounds); |
| +} |
| + |
|
pdr.
2016/12/20 06:46:30
Can you add a test like PaintPropertyTreeBuilderTe
chrishtr
2016/12/20 23:48:31
Per offline discussion, not needed. I did add a co
|
| } // namespace blink |