| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/graphics/compositing/PaintArtifactCompositor.h" | 5 #include "platform/graphics/compositing/PaintArtifactCompositor.h" |
| 6 | 6 |
| 7 #include "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
| 10 #include "cc/test/fake_compositor_frame_sink.h" | 10 #include "cc/test/fake_compositor_frame_sink.h" |
| 11 #include "cc/test/geometry_test_utils.h" | 11 #include "cc/test/geometry_test_utils.h" |
| 12 #include "cc/trees/clip_node.h" | 12 #include "cc/trees/clip_node.h" |
| 13 #include "cc/trees/effect_node.h" | 13 #include "cc/trees/effect_node.h" |
| 14 #include "cc/trees/layer_tree_host.h" | 14 #include "cc/trees/layer_tree_host.h" |
| 15 #include "cc/trees/layer_tree_settings.h" | 15 #include "cc/trees/layer_tree_settings.h" |
| 16 #include "cc/trees/scroll_node.h" | 16 #include "cc/trees/scroll_node.h" |
| 17 #include "cc/trees/transform_node.h" | 17 #include "cc/trees/transform_node.h" |
| 18 #include "platform/graphics/paint/EffectPaintPropertyNode.h" | 18 #include "platform/graphics/paint/EffectPaintPropertyNode.h" |
| 19 #include "platform/graphics/paint/GeometryMapper.h" |
| 19 #include "platform/graphics/paint/PaintArtifact.h" | 20 #include "platform/graphics/paint/PaintArtifact.h" |
| 20 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" | 21 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" |
| 21 #include "platform/testing/PaintPropertyTestHelpers.h" | 22 #include "platform/testing/PaintPropertyTestHelpers.h" |
| 22 #include "platform/testing/PictureMatchers.h" | 23 #include "platform/testing/PictureMatchers.h" |
| 23 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 24 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
| 24 #include "platform/testing/TestPaintArtifact.h" | 25 #include "platform/testing/TestPaintArtifact.h" |
| 25 #include "platform/testing/WebLayerTreeViewImplForTesting.h" | 26 #include "platform/testing/WebLayerTreeViewImplForTesting.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include <memory> | 29 #include <memory> |
| 29 | 30 |
| 30 namespace blink { | 31 namespace blink { |
| 31 namespace { | |
| 32 | 32 |
| 33 using ::blink::testing::createOpacityOnlyEffect; | 33 using ::blink::testing::createOpacityOnlyEffect; |
| 34 using ::testing::Pointee; | 34 using ::testing::Pointee; |
| 35 | 35 |
| 36 PaintChunkProperties defaultPaintChunkProperties() { | 36 PaintChunkProperties defaultPaintChunkProperties() { |
| 37 PropertyTreeState propertyTreeState( | 37 PropertyTreeState propertyTreeState( |
| 38 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | 38 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 39 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); | 39 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); |
| 40 return PaintChunkProperties(propertyTreeState); | 40 return PaintChunkProperties(propertyTreeState); |
| 41 } | 41 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 const cc::Layer* child = contentLayerAt(0); | 133 const cc::Layer* child = contentLayerAt(0); |
| 134 EXPECT_THAT(child->GetPicture(), | 134 EXPECT_THAT(child->GetPicture(), |
| 135 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); | 135 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); |
| 136 EXPECT_EQ(translation(50, -50), child->screen_space_transform()); | 136 EXPECT_EQ(translation(50, -50), child->screen_space_transform()); |
| 137 EXPECT_EQ(gfx::Size(100, 100), child->bounds()); | 137 EXPECT_EQ(gfx::Size(100, 100), child->bounds()); |
| 138 } | 138 } |
| 139 | 139 |
| 140 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneTransform) { | 140 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneTransform) { |
| 141 // A 90 degree clockwise rotation about (100, 100). | 141 // A 90 degree clockwise rotation about (100, 100). |
| 142 RefPtr<TransformPaintPropertyNode> transform = | 142 RefPtr<TransformPaintPropertyNode> transform = |
| 143 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), | 143 TransformPaintPropertyNode::create( |
| 144 TransformationMatrix().rotate(90), | 144 TransformPaintPropertyNode::root(), TransformationMatrix().rotate(90), |
| 145 FloatPoint3D(100, 100, 0)); | 145 FloatPoint3D(100, 100, 0), false, 0, CompositingReason3DTransform); |
| 146 | 146 |
| 147 TestPaintArtifact artifact; | 147 TestPaintArtifact artifact; |
| 148 artifact | 148 artifact |
| 149 .chunk(transform, ClipPaintPropertyNode::root(), | 149 .chunk(transform, ClipPaintPropertyNode::root(), |
| 150 EffectPaintPropertyNode::root()) | 150 EffectPaintPropertyNode::root()) |
| 151 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | 151 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 152 artifact | 152 artifact |
| 153 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | 153 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 154 EffectPaintPropertyNode::root()) | 154 EffectPaintPropertyNode::root()) |
| 155 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); | 155 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 183 Pointee(drawsRectangle(FloatRect(0, 0, 200, 100), Color::black))); | 183 Pointee(drawsRectangle(FloatRect(0, 0, 200, 100), Color::black))); |
| 184 gfx::RectF mappedRect(0, 0, 200, 100); | 184 gfx::RectF mappedRect(0, 0, 200, 100); |
| 185 layer->screen_space_transform().TransformRect(&mappedRect); | 185 layer->screen_space_transform().TransformRect(&mappedRect); |
| 186 EXPECT_EQ(gfx::RectF(0, 100, 100, 200), mappedRect); | 186 EXPECT_EQ(gfx::RectF(0, 100, 100, 200), mappedRect); |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TransformCombining) { | 190 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TransformCombining) { |
| 191 // A translation by (5, 5) within a 2x scale about (10, 10). | 191 // A translation by (5, 5) within a 2x scale about (10, 10). |
| 192 RefPtr<TransformPaintPropertyNode> transform1 = | 192 RefPtr<TransformPaintPropertyNode> transform1 = |
| 193 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), | 193 TransformPaintPropertyNode::create( |
| 194 TransformationMatrix().scale(2), | 194 TransformPaintPropertyNode::root(), TransformationMatrix().scale(2), |
| 195 FloatPoint3D(10, 10, 0)); | 195 FloatPoint3D(10, 10, 0), false, 0, CompositingReason3DTransform); |
| 196 RefPtr<TransformPaintPropertyNode> transform2 = | 196 RefPtr<TransformPaintPropertyNode> transform2 = |
| 197 TransformPaintPropertyNode::create( | 197 TransformPaintPropertyNode::create( |
| 198 transform1, TransformationMatrix().translate(5, 5), FloatPoint3D()); | 198 transform1, TransformationMatrix().translate(5, 5), FloatPoint3D()); |
| 199 | 199 |
| 200 TestPaintArtifact artifact; | 200 TestPaintArtifact artifact; |
| 201 artifact | 201 artifact |
| 202 .chunk(transform1, ClipPaintPropertyNode::root(), | 202 .chunk(transform1, ClipPaintPropertyNode::root(), |
| 203 EffectPaintPropertyNode::root()) | 203 EffectPaintPropertyNode::root()) |
| 204 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); | 204 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); |
| 205 artifact | 205 artifact |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 291 |
| 292 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SortingContextID) { | 292 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SortingContextID) { |
| 293 // Has no 3D rendering context. | 293 // Has no 3D rendering context. |
| 294 RefPtr<TransformPaintPropertyNode> transform1 = | 294 RefPtr<TransformPaintPropertyNode> transform1 = |
| 295 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), | 295 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), |
| 296 TransformationMatrix(), | 296 TransformationMatrix(), |
| 297 FloatPoint3D()); | 297 FloatPoint3D()); |
| 298 // Establishes a 3D rendering context. | 298 // Establishes a 3D rendering context. |
| 299 RefPtr<TransformPaintPropertyNode> transform2 = | 299 RefPtr<TransformPaintPropertyNode> transform2 = |
| 300 TransformPaintPropertyNode::create(transform1, TransformationMatrix(), | 300 TransformPaintPropertyNode::create(transform1, TransformationMatrix(), |
| 301 FloatPoint3D(), false, 1); | 301 FloatPoint3D(), false, 1, |
| 302 CompositingReason3DTransform); |
| 302 // Extends the 3D rendering context of transform2. | 303 // Extends the 3D rendering context of transform2. |
| 303 RefPtr<TransformPaintPropertyNode> transform3 = | 304 RefPtr<TransformPaintPropertyNode> transform3 = |
| 304 TransformPaintPropertyNode::create(transform2, TransformationMatrix(), | 305 TransformPaintPropertyNode::create(transform2, TransformationMatrix(), |
| 305 FloatPoint3D(), false, 1); | 306 FloatPoint3D(), false, 1, |
| 307 CompositingReason3DTransform); |
| 306 // Establishes a 3D rendering context distinct from transform2. | 308 // Establishes a 3D rendering context distinct from transform2. |
| 307 RefPtr<TransformPaintPropertyNode> transform4 = | 309 RefPtr<TransformPaintPropertyNode> transform4 = |
| 308 TransformPaintPropertyNode::create(transform2, TransformationMatrix(), | 310 TransformPaintPropertyNode::create(transform2, TransformationMatrix(), |
| 309 FloatPoint3D(), false, 2); | 311 FloatPoint3D(), false, 2, |
| 312 CompositingReason3DTransform); |
| 310 | 313 |
| 311 TestPaintArtifact artifact; | 314 TestPaintArtifact artifact; |
| 312 artifact | 315 artifact |
| 313 .chunk(transform1, ClipPaintPropertyNode::root(), | 316 .chunk(transform1, ClipPaintPropertyNode::root(), |
| 314 EffectPaintPropertyNode::root()) | 317 EffectPaintPropertyNode::root()) |
| 315 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); | 318 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); |
| 316 artifact | 319 artifact |
| 317 .chunk(transform2, ClipPaintPropertyNode::root(), | 320 .chunk(transform2, ClipPaintPropertyNode::root(), |
| 318 EffectPaintPropertyNode::root()) | 321 EffectPaintPropertyNode::root()) |
| 319 .rectDrawing(FloatRect(0, 0, 300, 200), Color::lightGray); | 322 .rectDrawing(FloatRect(0, 0, 300, 200), Color::lightGray); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 const cc::ClipNode* clipNode = | 395 const cc::ClipNode* clipNode = |
| 393 propertyTrees().clip_tree.Node(layer->clip_tree_index()); | 396 propertyTrees().clip_tree.Node(layer->clip_tree_index()); |
| 394 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, clipNode->clip_type); | 397 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, clipNode->clip_type); |
| 395 EXPECT_TRUE(clipNode->layers_are_clipped); | 398 EXPECT_TRUE(clipNode->layers_are_clipped); |
| 396 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->clip); | 399 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->clip); |
| 397 } | 400 } |
| 398 | 401 |
| 399 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) { | 402 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) { |
| 400 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 403 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
| 401 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), | 404 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 402 FloatRoundedRect(100, 100, 700, 700)); | 405 FloatRoundedRect(100, 100, 700, 700), |
| 406 CompositingReasonOverflowScrollingTouch); |
| 403 RefPtr<ClipPaintPropertyNode> clip2 = | 407 RefPtr<ClipPaintPropertyNode> clip2 = |
| 404 ClipPaintPropertyNode::create(clip1, TransformPaintPropertyNode::root(), | 408 ClipPaintPropertyNode::create(clip1, TransformPaintPropertyNode::root(), |
| 405 FloatRoundedRect(200, 200, 700, 100)); | 409 FloatRoundedRect(200, 200, 700, 100), |
| 410 CompositingReasonOverflowScrollingTouch); |
| 406 | 411 |
| 407 TestPaintArtifact artifact; | 412 TestPaintArtifact artifact; |
| 408 artifact | 413 artifact |
| 409 .chunk(TransformPaintPropertyNode::root(), clip1, | 414 .chunk(TransformPaintPropertyNode::root(), clip1, |
| 410 EffectPaintPropertyNode::root()) | 415 EffectPaintPropertyNode::root()) |
| 411 .rectDrawing(FloatRect(300, 350, 100, 100), Color::white); | 416 .rectDrawing(FloatRect(300, 350, 100, 100), Color::white); |
| 412 artifact | 417 artifact |
| 413 .chunk(TransformPaintPropertyNode::root(), clip2, | 418 .chunk(TransformPaintPropertyNode::root(), clip2, |
| 414 EffectPaintPropertyNode::root()) | 419 EffectPaintPropertyNode::root()) |
| 415 .rectDrawing(FloatRect(300, 350, 100, 100), Color::lightGray); | 420 .rectDrawing(FloatRect(300, 350, 100, 100), Color::lightGray); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, | 553 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, |
| 549 commonClipNode->clip_type); | 554 commonClipNode->clip_type); |
| 550 EXPECT_TRUE(commonClipNode->layers_are_clipped); | 555 EXPECT_TRUE(commonClipNode->layers_are_clipped); |
| 551 ASSERT_EQ(gfx::RectF(0, 0, 800, 600), commonClipNode->clip); | 556 ASSERT_EQ(gfx::RectF(0, 0, 800, 600), commonClipNode->clip); |
| 552 } | 557 } |
| 553 | 558 |
| 554 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, | 559 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, |
| 555 ForeignLayerPassesThrough) { | 560 ForeignLayerPassesThrough) { |
| 556 scoped_refptr<cc::Layer> layer = cc::Layer::Create(); | 561 scoped_refptr<cc::Layer> layer = cc::Layer::Create(); |
| 557 | 562 |
| 558 TestPaintArtifact artifact; | 563 TestPaintArtifact testArtifact; |
| 559 artifact.chunk(defaultPaintChunkProperties()) | 564 testArtifact |
| 565 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 566 EffectPaintPropertyNode::root()) |
| 567 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 568 testArtifact.chunk(defaultPaintChunkProperties()) |
| 560 .foreignLayer(FloatPoint(50, 100), IntSize(400, 300), layer); | 569 .foreignLayer(FloatPoint(50, 100), IntSize(400, 300), layer); |
| 561 update(artifact.build()); | 570 testArtifact |
| 571 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 572 EffectPaintPropertyNode::root()) |
| 573 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); |
| 562 | 574 |
| 563 ASSERT_EQ(1u, contentLayerCount()); | 575 const PaintArtifact& artifact = testArtifact.build(); |
| 564 EXPECT_EQ(layer, contentLayerAt(0)); | 576 |
| 577 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 578 PaintArtifactCompositor::PendingLayer pendingLayer1( |
| 579 artifact.paintChunks()[0]); |
| 580 // Foreign layers can't merge. |
| 581 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( |
| 582 artifact, artifact.paintChunks()[1], pendingLayer1)); |
| 583 PaintArtifactCompositor::PendingLayer pendingLayer2( |
| 584 artifact.paintChunks()[1]); |
| 585 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto( |
| 586 artifact, artifact.paintChunks()[2], pendingLayer2)); |
| 587 |
| 588 update(artifact); |
| 589 |
| 590 ASSERT_EQ(3u, contentLayerCount()); |
| 591 EXPECT_EQ(layer, contentLayerAt(1)); |
| 565 EXPECT_EQ(gfx::Size(400, 300), layer->bounds()); | 592 EXPECT_EQ(gfx::Size(400, 300), layer->bounds()); |
| 566 EXPECT_EQ(translation(50, 100), layer->screen_space_transform()); | 593 EXPECT_EQ(translation(50, 100), layer->screen_space_transform()); |
| 567 } | 594 } |
| 568 | 595 |
| 569 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectTreeConversion) { | 596 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectTreeConversion) { |
| 570 RefPtr<EffectPaintPropertyNode> effect1 = | 597 RefPtr<EffectPaintPropertyNode> effect1 = |
| 571 createOpacityOnlyEffect(EffectPaintPropertyNode::root(), 0.5); | 598 createOpacityOnlyEffect(EffectPaintPropertyNode::root(), 0.5); |
| 572 RefPtr<EffectPaintPropertyNode> effect2 = | 599 RefPtr<EffectPaintPropertyNode> effect2 = |
| 573 createOpacityOnlyEffect(effect1, 0.3); | 600 createOpacityOnlyEffect(effect1, 0.3); |
| 574 RefPtr<EffectPaintPropertyNode> effect3 = | 601 RefPtr<EffectPaintPropertyNode> effect3 = |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 scrollTree.current_scroll_offset(contentLayerAt(0)->id())); | 738 scrollTree.current_scroll_offset(contentLayerAt(0)->id())); |
| 712 EXPECT_EQ(gfx::ScrollOffset(-37, -41), | 739 EXPECT_EQ(gfx::ScrollOffset(-37, -41), |
| 713 scrollTree.current_scroll_offset(contentLayerAt(1)->id())); | 740 scrollTree.current_scroll_offset(contentLayerAt(1)->id())); |
| 714 | 741 |
| 715 EXPECT_TRUE(scrollNodeA.main_thread_scrolling_reasons & | 742 EXPECT_TRUE(scrollNodeA.main_thread_scrolling_reasons & |
| 716 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); | 743 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 717 EXPECT_FALSE(scrollNodeB.main_thread_scrolling_reasons & | 744 EXPECT_FALSE(scrollNodeB.main_thread_scrolling_reasons & |
| 718 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); | 745 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 719 } | 746 } |
| 720 | 747 |
| 721 } // namespace | 748 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeSimpleChunks) { |
| 749 TestPaintArtifact testArtifact; |
| 750 testArtifact |
| 751 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 752 EffectPaintPropertyNode::root()) |
| 753 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 754 testArtifact |
| 755 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 756 EffectPaintPropertyNode::root()) |
| 757 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 758 |
| 759 const PaintArtifact& artifact = testArtifact.build(); |
| 760 |
| 761 ASSERT_EQ(2u, artifact.paintChunks().size()); |
| 762 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 763 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 764 artifact, artifact.paintChunks()[1], pendingLayer)); |
| 765 |
| 766 update(artifact); |
| 767 |
| 768 ASSERT_EQ(1u, contentLayerCount()); |
| 769 { |
| 770 Vector<RectWithColor> rectsWithColor; |
| 771 rectsWithColor.push_back( |
| 772 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 773 rectsWithColor.push_back( |
| 774 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 775 |
| 776 const cc::Layer* layer = contentLayerAt(0); |
| 777 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 778 } |
| 779 } |
| 780 |
| 781 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeClip) { |
| 782 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 783 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 784 FloatRoundedRect(10, 20, 50, 60)); |
| 785 |
| 786 TestPaintArtifact testArtifact; |
| 787 testArtifact |
| 788 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 789 EffectPaintPropertyNode::root()) |
| 790 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 791 testArtifact |
| 792 .chunk(TransformPaintPropertyNode::root(), clip.get(), |
| 793 EffectPaintPropertyNode::root()) |
| 794 .rectDrawing(FloatRect(0, 0, 200, 300), Color::black); |
| 795 testArtifact |
| 796 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 797 EffectPaintPropertyNode::root()) |
| 798 .rectDrawing(FloatRect(0, 0, 300, 400), Color::gray); |
| 799 |
| 800 const PaintArtifact& artifact = testArtifact.build(); |
| 801 |
| 802 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 803 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 804 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 805 artifact, artifact.paintChunks()[1], pendingLayer)); |
| 806 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 807 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 808 artifact, artifact.paintChunks()[2], pendingLayer)); |
| 809 |
| 810 update(artifact); |
| 811 |
| 812 ASSERT_EQ(1u, contentLayerCount()); |
| 813 { |
| 814 Vector<RectWithColor> rectsWithColor; |
| 815 rectsWithColor.push_back( |
| 816 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 817 // Clip is applied to this PaintChunk. |
| 818 rectsWithColor.push_back( |
| 819 RectWithColor(FloatRect(10, 20, 50, 60), Color::black)); |
| 820 rectsWithColor.push_back( |
| 821 RectWithColor(FloatRect(0, 0, 300, 400), Color::gray)); |
| 822 |
| 823 const cc::Layer* layer = contentLayerAt(0); |
| 824 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 825 } |
| 826 } |
| 827 |
| 828 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, Merge2DTransform) { |
| 829 RefPtr<TransformPaintPropertyNode> transform = |
| 830 TransformPaintPropertyNode::create( |
| 831 TransformPaintPropertyNode::root(), |
| 832 TransformationMatrix().translate(50, 50), FloatPoint3D(100, 100, 0), |
| 833 false, 0); |
| 834 |
| 835 TestPaintArtifact testArtifact; |
| 836 testArtifact |
| 837 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 838 EffectPaintPropertyNode::root()) |
| 839 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 840 testArtifact |
| 841 .chunk(transform.get(), ClipPaintPropertyNode::root(), |
| 842 EffectPaintPropertyNode::root()) |
| 843 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); |
| 844 testArtifact |
| 845 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 846 EffectPaintPropertyNode::root()) |
| 847 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 848 |
| 849 const PaintArtifact& artifact = testArtifact.build(); |
| 850 |
| 851 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 852 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 853 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 854 artifact, artifact.paintChunks()[1], pendingLayer)); |
| 855 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 856 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 857 artifact, artifact.paintChunks()[2], pendingLayer)); |
| 858 |
| 859 update(artifact); |
| 860 |
| 861 ASSERT_EQ(1u, contentLayerCount()); |
| 862 { |
| 863 Vector<RectWithColor> rectsWithColor; |
| 864 rectsWithColor.push_back( |
| 865 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 866 // Transform is applied to this PaintChunk. |
| 867 rectsWithColor.push_back( |
| 868 RectWithColor(FloatRect(50, 50, 100, 100), Color::black)); |
| 869 rectsWithColor.push_back( |
| 870 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 871 |
| 872 const cc::Layer* layer = contentLayerAt(0); |
| 873 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 874 } |
| 875 } |
| 876 |
| 877 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeOpacity) { |
| 878 float opacity = 2.0 / 255.0; |
| 879 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 880 EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 881 ClipPaintPropertyNode::root(), CompositorFilterOperations(), opacity, |
| 882 SkBlendMode::kSrcOver); |
| 883 |
| 884 TestPaintArtifact testArtifact; |
| 885 testArtifact |
| 886 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 887 EffectPaintPropertyNode::root()) |
| 888 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 889 testArtifact |
| 890 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 891 effect.get()) |
| 892 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); |
| 893 testArtifact |
| 894 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 895 EffectPaintPropertyNode::root()) |
| 896 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 897 |
| 898 const PaintArtifact& artifact = testArtifact.build(); |
| 899 |
| 900 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 901 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 902 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 903 artifact, artifact.paintChunks()[1], pendingLayer)); |
| 904 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 905 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 906 artifact, artifact.paintChunks()[2], pendingLayer)); |
| 907 |
| 908 update(artifact); |
| 909 |
| 910 ASSERT_EQ(1u, contentLayerCount()); |
| 911 { |
| 912 Vector<RectWithColor> rectsWithColor; |
| 913 rectsWithColor.push_back( |
| 914 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 915 // Transform is applied to this PaintChunk. |
| 916 rectsWithColor.push_back( |
| 917 RectWithColor(FloatRect(0, 0, 100, 100), |
| 918 Color(Color::black).combineWithAlpha(opacity).rgb())); |
| 919 rectsWithColor.push_back( |
| 920 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 921 |
| 922 const cc::Layer* layer = contentLayerAt(0); |
| 923 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 924 } |
| 925 } |
| 926 |
| 927 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeNested) { |
| 928 // Tests merging of an opacity effect, inside of a clip, inside of a |
| 929 // transform. |
| 930 |
| 931 RefPtr<TransformPaintPropertyNode> transform = |
| 932 TransformPaintPropertyNode::create( |
| 933 TransformPaintPropertyNode::root(), |
| 934 TransformationMatrix().translate(50, 50), FloatPoint3D(100, 100, 0), |
| 935 false, 0); |
| 936 |
| 937 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 938 ClipPaintPropertyNode::root(), transform.get(), |
| 939 FloatRoundedRect(10, 20, 50, 60)); |
| 940 |
| 941 float opacity = 2.0 / 255.0; |
| 942 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 943 EffectPaintPropertyNode::root(), transform.get(), clip.get(), |
| 944 CompositorFilterOperations(), opacity, SkBlendMode::kSrcOver); |
| 945 |
| 946 TestPaintArtifact testArtifact; |
| 947 testArtifact |
| 948 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 949 EffectPaintPropertyNode::root()) |
| 950 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 951 testArtifact.chunk(transform.get(), clip.get(), effect.get()) |
| 952 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); |
| 953 testArtifact |
| 954 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 955 EffectPaintPropertyNode::root()) |
| 956 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 957 |
| 958 const PaintArtifact& artifact = testArtifact.build(); |
| 959 |
| 960 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 961 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 962 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 963 artifact, artifact.paintChunks()[1], pendingLayer)); |
| 964 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 965 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 966 artifact, artifact.paintChunks()[2], pendingLayer)); |
| 967 update(artifact); |
| 968 |
| 969 ASSERT_EQ(1u, contentLayerCount()); |
| 970 { |
| 971 Vector<RectWithColor> rectsWithColor; |
| 972 rectsWithColor.push_back( |
| 973 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 974 // Transform is applied to this PaintChunk. |
| 975 rectsWithColor.push_back( |
| 976 RectWithColor(FloatRect(60, 70, 50, 60), |
| 977 Color(Color::black).combineWithAlpha(opacity).rgb())); |
| 978 rectsWithColor.push_back( |
| 979 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 980 |
| 981 const cc::Layer* layer = contentLayerAt(0); |
| 982 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 983 } |
| 984 } |
| 985 |
| 986 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, ClipPushedUp) { |
| 987 // Tests merging of an element which has a clipapplied to it, |
| 988 // but has an ancestor transform of them. This can happen for fixed- |
| 989 // or absolute-position elements which escape scroll transforms. |
| 990 |
| 991 RefPtr<TransformPaintPropertyNode> transform = |
| 992 TransformPaintPropertyNode::create( |
| 993 TransformPaintPropertyNode::root(), |
| 994 TransformationMatrix().translate(20, 25), FloatPoint3D(100, 100, 0), |
| 995 false, 0); |
| 996 |
| 997 RefPtr<TransformPaintPropertyNode> transform2 = |
| 998 TransformPaintPropertyNode::create( |
| 999 transform.get(), TransformationMatrix().translate(20, 25), |
| 1000 FloatPoint3D(100, 100, 0), false, 0); |
| 1001 |
| 1002 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 1003 ClipPaintPropertyNode::root(), transform2.get(), |
| 1004 FloatRoundedRect(10, 20, 50, 60)); |
| 1005 |
| 1006 TestPaintArtifact testArtifact; |
| 1007 testArtifact |
| 1008 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1009 EffectPaintPropertyNode::root()) |
| 1010 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 1011 testArtifact |
| 1012 .chunk(TransformPaintPropertyNode::root(), clip.get(), |
| 1013 EffectPaintPropertyNode::root()) |
| 1014 .rectDrawing(FloatRect(0, 0, 300, 400), Color::black); |
| 1015 testArtifact |
| 1016 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1017 EffectPaintPropertyNode::root()) |
| 1018 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 1019 |
| 1020 const PaintArtifact& artifact = testArtifact.build(); |
| 1021 |
| 1022 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 1023 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 1024 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 1025 artifact, artifact.paintChunks()[1], pendingLayer)); |
| 1026 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 1027 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 1028 artifact, artifact.paintChunks()[2], pendingLayer)); |
| 1029 update(artifact); |
| 1030 |
| 1031 ASSERT_EQ(1u, contentLayerCount()); |
| 1032 { |
| 1033 Vector<RectWithColor> rectsWithColor; |
| 1034 rectsWithColor.push_back( |
| 1035 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 1036 // The two transforms (combined translation of (40, 50)) are applied here, |
| 1037 // before clipping. |
| 1038 rectsWithColor.push_back( |
| 1039 RectWithColor(FloatRect(50, 70, 50, 60), Color(Color::black))); |
| 1040 rectsWithColor.push_back( |
| 1041 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 1042 |
| 1043 const cc::Layer* layer = contentLayerAt(0); |
| 1044 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 1045 } |
| 1046 } |
| 1047 |
| 1048 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectPushedUp) { |
| 1049 // Tests merging of an element which has an effect applied to it, |
| 1050 // but has an ancestor transform of them. This can happen for fixed- |
| 1051 // or absolute-position elements which escape scroll transforms. |
| 1052 |
| 1053 RefPtr<TransformPaintPropertyNode> transform = |
| 1054 TransformPaintPropertyNode::create( |
| 1055 TransformPaintPropertyNode::root(), |
| 1056 TransformationMatrix().translate(20, 25), FloatPoint3D(100, 100, 0), |
| 1057 false, 0); |
| 1058 |
| 1059 RefPtr<TransformPaintPropertyNode> transform2 = |
| 1060 TransformPaintPropertyNode::create( |
| 1061 transform.get(), TransformationMatrix().translate(20, 25), |
| 1062 FloatPoint3D(100, 100, 0), false, 0); |
| 1063 |
| 1064 float opacity = 2.0 / 255.0; |
| 1065 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 1066 EffectPaintPropertyNode::root(), transform2.get(), |
| 1067 ClipPaintPropertyNode::root(), CompositorFilterOperations(), opacity, |
| 1068 SkBlendMode::kSrcOver); |
| 1069 |
| 1070 TestPaintArtifact testArtifact; |
| 1071 testArtifact |
| 1072 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1073 EffectPaintPropertyNode::root()) |
| 1074 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 1075 testArtifact |
| 1076 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1077 effect.get()) |
| 1078 .rectDrawing(FloatRect(0, 0, 300, 400), Color::black); |
| 1079 testArtifact |
| 1080 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1081 EffectPaintPropertyNode::root()) |
| 1082 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 1083 |
| 1084 const PaintArtifact& artifact = testArtifact.build(); |
| 1085 |
| 1086 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 1087 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 1088 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 1089 artifact, artifact.paintChunks()[1], pendingLayer)); |
| 1090 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 1091 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 1092 artifact, artifact.paintChunks()[2], pendingLayer)); |
| 1093 update(artifact); |
| 1094 |
| 1095 ASSERT_EQ(1u, contentLayerCount()); |
| 1096 { |
| 1097 Vector<RectWithColor> rectsWithColor; |
| 1098 rectsWithColor.push_back( |
| 1099 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 1100 rectsWithColor.push_back( |
| 1101 RectWithColor(FloatRect(0, 0, 300, 400), |
| 1102 Color(Color::black).combineWithAlpha(opacity).rgb())); |
| 1103 rectsWithColor.push_back( |
| 1104 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 1105 |
| 1106 const cc::Layer* layer = contentLayerAt(0); |
| 1107 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 1108 } |
| 1109 } |
| 1110 |
| 1111 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectAndClipPushedUp) { |
| 1112 // Tests merging of an element which has an effect applied to it, |
| 1113 // but has an ancestor transform of them. This can happen for fixed- |
| 1114 // or absolute-position elements which escape scroll transforms. |
| 1115 |
| 1116 RefPtr<TransformPaintPropertyNode> transform = |
| 1117 TransformPaintPropertyNode::create( |
| 1118 TransformPaintPropertyNode::root(), |
| 1119 TransformationMatrix().translate(20, 25), FloatPoint3D(100, 100, 0), |
| 1120 false, 0); |
| 1121 |
| 1122 RefPtr<TransformPaintPropertyNode> transform2 = |
| 1123 TransformPaintPropertyNode::create( |
| 1124 transform.get(), TransformationMatrix().translate(20, 25), |
| 1125 FloatPoint3D(100, 100, 0), false, 0); |
| 1126 |
| 1127 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 1128 ClipPaintPropertyNode::root(), transform.get(), |
| 1129 FloatRoundedRect(10, 20, 50, 60)); |
| 1130 |
| 1131 float opacity = 2.0 / 255.0; |
| 1132 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 1133 EffectPaintPropertyNode::root(), transform2.get(), clip.get(), |
| 1134 CompositorFilterOperations(), opacity, SkBlendMode::kSrcOver); |
| 1135 |
| 1136 TestPaintArtifact testArtifact; |
| 1137 testArtifact |
| 1138 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1139 EffectPaintPropertyNode::root()) |
| 1140 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 1141 testArtifact |
| 1142 .chunk(TransformPaintPropertyNode::root(), clip.get(), effect.get()) |
| 1143 .rectDrawing(FloatRect(0, 0, 300, 400), Color::black); |
| 1144 testArtifact |
| 1145 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1146 EffectPaintPropertyNode::root()) |
| 1147 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 1148 |
| 1149 const PaintArtifact& artifact = testArtifact.build(); |
| 1150 |
| 1151 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 1152 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 1153 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 1154 artifact, artifact.paintChunks()[1], pendingLayer)); |
| 1155 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 1156 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 1157 artifact, artifact.paintChunks()[2], pendingLayer)); |
| 1158 update(artifact); |
| 1159 |
| 1160 ASSERT_EQ(1u, contentLayerCount()); |
| 1161 { |
| 1162 Vector<RectWithColor> rectsWithColor; |
| 1163 rectsWithColor.push_back( |
| 1164 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 1165 // The clip is under |transform| but not |transform2|, so only an adjustment |
| 1166 // of (20, 25) occurs. |
| 1167 rectsWithColor.push_back( |
| 1168 RectWithColor(FloatRect(30, 45, 50, 60), |
| 1169 Color(Color::black).combineWithAlpha(opacity).rgb())); |
| 1170 rectsWithColor.push_back( |
| 1171 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 1172 |
| 1173 const cc::Layer* layer = contentLayerAt(0); |
| 1174 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 1175 } |
| 1176 } |
| 1177 |
| 1178 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, ClipAndEffectNoTransform) { |
| 1179 // Tests merging of an element which has a clip and effect in the root |
| 1180 // transform space. |
| 1181 |
| 1182 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 1183 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 1184 FloatRoundedRect(10, 20, 50, 60)); |
| 1185 |
| 1186 float opacity = 2.0 / 255.0; |
| 1187 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 1188 EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 1189 clip.get(), CompositorFilterOperations(), opacity, SkBlendMode::kSrcOver); |
| 1190 |
| 1191 TestPaintArtifact testArtifact; |
| 1192 testArtifact |
| 1193 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1194 EffectPaintPropertyNode::root()) |
| 1195 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 1196 testArtifact |
| 1197 .chunk(TransformPaintPropertyNode::root(), clip.get(), effect.get()) |
| 1198 .rectDrawing(FloatRect(0, 0, 300, 400), Color::black); |
| 1199 testArtifact |
| 1200 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1201 EffectPaintPropertyNode::root()) |
| 1202 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 1203 |
| 1204 const PaintArtifact& artifact = testArtifact.build(); |
| 1205 |
| 1206 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 1207 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 1208 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 1209 artifact, artifact.paintChunks()[1], pendingLayer)); |
| 1210 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 1211 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 1212 artifact, artifact.paintChunks()[2], pendingLayer)); |
| 1213 update(artifact); |
| 1214 |
| 1215 ASSERT_EQ(1u, contentLayerCount()); |
| 1216 { |
| 1217 Vector<RectWithColor> rectsWithColor; |
| 1218 rectsWithColor.push_back( |
| 1219 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 1220 rectsWithColor.push_back( |
| 1221 RectWithColor(FloatRect(10, 20, 50, 60), |
| 1222 Color(Color::black).combineWithAlpha(opacity).rgb())); |
| 1223 rectsWithColor.push_back( |
| 1224 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 1225 |
| 1226 const cc::Layer* layer = contentLayerAt(0); |
| 1227 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 1228 } |
| 1229 } |
| 1230 |
| 1231 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TwoClips) { |
| 1232 // Tests merging of an element which has two clips in the root |
| 1233 // transform space. |
| 1234 |
| 1235 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 1236 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 1237 FloatRoundedRect(20, 30, 10, 20)); |
| 1238 |
| 1239 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( |
| 1240 clip.get(), TransformPaintPropertyNode::root(), |
| 1241 FloatRoundedRect(10, 20, 50, 60)); |
| 1242 |
| 1243 TestPaintArtifact testArtifact; |
| 1244 testArtifact |
| 1245 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1246 EffectPaintPropertyNode::root()) |
| 1247 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 1248 testArtifact |
| 1249 .chunk(TransformPaintPropertyNode::root(), clip2.get(), |
| 1250 EffectPaintPropertyNode::root()) |
| 1251 .rectDrawing(FloatRect(0, 0, 300, 400), Color::black); |
| 1252 testArtifact |
| 1253 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1254 EffectPaintPropertyNode::root()) |
| 1255 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 1256 |
| 1257 const PaintArtifact& artifact = testArtifact.build(); |
| 1258 |
| 1259 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 1260 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 1261 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 1262 artifact, artifact.paintChunks()[1], pendingLayer)); |
| 1263 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 1264 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto( |
| 1265 artifact, artifact.paintChunks()[2], pendingLayer)); |
| 1266 update(artifact); |
| 1267 |
| 1268 ASSERT_EQ(1u, contentLayerCount()); |
| 1269 { |
| 1270 Vector<RectWithColor> rectsWithColor; |
| 1271 rectsWithColor.push_back( |
| 1272 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 1273 // The interesction of the two clips is (20, 30, 10, 20). |
| 1274 rectsWithColor.push_back( |
| 1275 RectWithColor(FloatRect(20, 30, 10, 20), Color(Color::black))); |
| 1276 rectsWithColor.push_back( |
| 1277 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 1278 |
| 1279 const cc::Layer* layer = contentLayerAt(0); |
| 1280 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 1281 } |
| 1282 } |
| 1283 |
| 1284 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayer) { |
| 1285 PaintChunk chunk1; |
| 1286 chunk1.properties.propertyTreeState = PropertyTreeState( |
| 1287 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1288 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); |
| 1289 chunk1.properties.backfaceHidden = true; |
| 1290 chunk1.knownToBeOpaque = true; |
| 1291 chunk1.bounds = FloatRect(0, 0, 30, 40); |
| 1292 |
| 1293 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1); |
| 1294 |
| 1295 EXPECT_TRUE(pendingLayer.backfaceHidden); |
| 1296 EXPECT_TRUE(pendingLayer.knownToBeOpaque); |
| 1297 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 40), pendingLayer.bounds); |
| 1298 |
| 1299 PaintChunk chunk2; |
| 1300 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; |
| 1301 chunk2.properties.backfaceHidden = true; |
| 1302 chunk2.knownToBeOpaque = true; |
| 1303 chunk2.bounds = FloatRect(10, 20, 30, 40); |
| 1304 pendingLayer.add(chunk2, nullptr); |
| 1305 |
| 1306 EXPECT_TRUE(pendingLayer.backfaceHidden); |
| 1307 // Bounds not equal to one PaintChunk. |
| 1308 EXPECT_FALSE(pendingLayer.knownToBeOpaque); |
| 1309 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 40, 60), pendingLayer.bounds); |
| 1310 |
| 1311 PaintChunk chunk3; |
| 1312 chunk3.properties.propertyTreeState = chunk1.properties.propertyTreeState; |
| 1313 chunk3.properties.backfaceHidden = true; |
| 1314 chunk3.knownToBeOpaque = true; |
| 1315 chunk3.bounds = FloatRect(-5, -25, 20, 20); |
| 1316 pendingLayer.add(chunk3, nullptr); |
| 1317 |
| 1318 EXPECT_TRUE(pendingLayer.backfaceHidden); |
| 1319 EXPECT_FALSE(pendingLayer.knownToBeOpaque); |
| 1320 EXPECT_FLOAT_RECT_EQ(FloatRect(-5, -25, 45, 85), pendingLayer.bounds); |
| 1321 } |
| 1322 |
| 1323 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayerWithGeometry) { |
| 1324 RefPtr<TransformPaintPropertyNode> transform = |
| 1325 TransformPaintPropertyNode::create( |
| 1326 TransformPaintPropertyNode::root(), |
| 1327 TransformationMatrix().translate(20, 25), FloatPoint3D(100, 100, 0), |
| 1328 false, 0); |
| 1329 |
| 1330 PaintChunk chunk1; |
| 1331 chunk1.properties.propertyTreeState = PropertyTreeState( |
| 1332 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1333 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); |
| 1334 chunk1.bounds = FloatRect(0, 0, 30, 40); |
| 1335 |
| 1336 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1); |
| 1337 |
| 1338 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 40), pendingLayer.bounds); |
| 1339 |
| 1340 PaintChunk chunk2; |
| 1341 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; |
| 1342 chunk2.properties.propertyTreeState.setTransform(transform); |
| 1343 chunk2.bounds = FloatRect(0, 0, 50, 60); |
| 1344 GeometryMapper geometryMapper; |
| 1345 pendingLayer.add(chunk2, &geometryMapper); |
| 1346 |
| 1347 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 70, 85), pendingLayer.bounds); |
| 1348 } |
| 1349 |
| 722 } // namespace blink | 1350 } // namespace blink |
| OLD | NEW |