| 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.chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::
root(), |
| 565 EffectPaintPropertyNode::root()) |
| 566 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 567 testArtifact.chunk(defaultPaintChunkProperties()) |
| 560 .foreignLayer(FloatPoint(50, 100), IntSize(400, 300), layer); | 568 .foreignLayer(FloatPoint(50, 100), IntSize(400, 300), layer); |
| 561 update(artifact.build()); | 569 testArtifact.chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode:
:root(), |
| 570 EffectPaintPropertyNode::root()) |
| 571 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); |
| 562 | 572 |
| 563 ASSERT_EQ(1u, contentLayerCount()); | 573 const PaintArtifact& artifact = testArtifact.build(); |
| 564 EXPECT_EQ(layer, contentLayerAt(0)); | 574 |
| 575 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 576 PaintArtifactCompositor::PendingLayer pendingLayer1(artifact.paintChunks()[0])
; |
| 577 // Foreign layers can't merge. |
| 578 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChu
nks()[1], |
| 579 pendingLayer1)); |
| 580 PaintArtifactCompositor::PendingLayer pendingLayer2(artifact.paintChunks()[1])
; |
| 581 EXPECT_FALSE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChu
nks()[2], |
| 582 pendingLayer2)); |
| 583 |
| 584 update(artifact); |
| 585 |
| 586 ASSERT_EQ(3u, contentLayerCount()); |
| 587 EXPECT_EQ(layer, contentLayerAt(1)); |
| 565 EXPECT_EQ(gfx::Size(400, 300), layer->bounds()); | 588 EXPECT_EQ(gfx::Size(400, 300), layer->bounds()); |
| 566 EXPECT_EQ(translation(50, 100), layer->screen_space_transform()); | 589 EXPECT_EQ(translation(50, 100), layer->screen_space_transform()); |
| 567 } | 590 } |
| 568 | 591 |
| 569 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectTreeConversion) { | 592 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectTreeConversion) { |
| 570 RefPtr<EffectPaintPropertyNode> effect1 = | 593 RefPtr<EffectPaintPropertyNode> effect1 = |
| 571 createOpacityOnlyEffect(EffectPaintPropertyNode::root(), 0.5); | 594 createOpacityOnlyEffect(EffectPaintPropertyNode::root(), 0.5); |
| 572 RefPtr<EffectPaintPropertyNode> effect2 = | 595 RefPtr<EffectPaintPropertyNode> effect2 = |
| 573 createOpacityOnlyEffect(effect1, 0.3); | 596 createOpacityOnlyEffect(effect1, 0.3); |
| 574 RefPtr<EffectPaintPropertyNode> effect3 = | 597 RefPtr<EffectPaintPropertyNode> effect3 = |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 scrollTree.current_scroll_offset(contentLayerAt(0)->id())); | 734 scrollTree.current_scroll_offset(contentLayerAt(0)->id())); |
| 712 EXPECT_EQ(gfx::ScrollOffset(-37, -41), | 735 EXPECT_EQ(gfx::ScrollOffset(-37, -41), |
| 713 scrollTree.current_scroll_offset(contentLayerAt(1)->id())); | 736 scrollTree.current_scroll_offset(contentLayerAt(1)->id())); |
| 714 | 737 |
| 715 EXPECT_TRUE(scrollNodeA.main_thread_scrolling_reasons & | 738 EXPECT_TRUE(scrollNodeA.main_thread_scrolling_reasons & |
| 716 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); | 739 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 717 EXPECT_FALSE(scrollNodeB.main_thread_scrolling_reasons & | 740 EXPECT_FALSE(scrollNodeB.main_thread_scrolling_reasons & |
| 718 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); | 741 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 719 } | 742 } |
| 720 | 743 |
| 721 } // namespace | 744 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeSimpleChunks) { |
| 745 TestPaintArtifact testArtifact; |
| 746 testArtifact |
| 747 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 748 EffectPaintPropertyNode::root()) |
| 749 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 750 testArtifact |
| 751 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 752 EffectPaintPropertyNode::root()) |
| 753 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 754 |
| 755 const PaintArtifact& artifact = testArtifact.build(); |
| 756 |
| 757 ASSERT_EQ(2u, artifact.paintChunks().size()); |
| 758 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 759 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[1], |
| 760 pendingLayer)); |
| 761 |
| 762 update(artifact); |
| 763 |
| 764 ASSERT_EQ(1u, contentLayerCount()); |
| 765 { |
| 766 Vector<RectWithColor> rectsWithColor; |
| 767 rectsWithColor.push_back( |
| 768 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 769 rectsWithColor.push_back( |
| 770 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 771 |
| 772 const cc::Layer* layer = contentLayerAt(0); |
| 773 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 774 } |
| 775 } |
| 776 |
| 777 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeClip) { |
| 778 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 779 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 780 FloatRoundedRect(10, 20, 50, 60)); |
| 781 |
| 782 TestPaintArtifact testArtifact; |
| 783 testArtifact |
| 784 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 785 EffectPaintPropertyNode::root()) |
| 786 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 787 testArtifact |
| 788 .chunk(TransformPaintPropertyNode::root(), clip.get(), |
| 789 EffectPaintPropertyNode::root()) |
| 790 .rectDrawing(FloatRect(0, 0, 200, 300), Color::black); |
| 791 testArtifact |
| 792 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 793 EffectPaintPropertyNode::root()) |
| 794 .rectDrawing(FloatRect(0, 0, 300, 400), Color::gray); |
| 795 |
| 796 const PaintArtifact& artifact = testArtifact.build(); |
| 797 |
| 798 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 799 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 800 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[1], |
| 801 pendingLayer)); |
| 802 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 803 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[2], |
| 804 pendingLayer)); |
| 805 |
| 806 update(artifact); |
| 807 |
| 808 ASSERT_EQ(1u, contentLayerCount()); |
| 809 { |
| 810 Vector<RectWithColor> rectsWithColor; |
| 811 rectsWithColor.push_back( |
| 812 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 813 // Clip is applied to this PaintChunk. |
| 814 rectsWithColor.push_back( |
| 815 RectWithColor(FloatRect(10, 20, 50, 60), Color::black)); |
| 816 rectsWithColor.push_back( |
| 817 RectWithColor(FloatRect(0, 0, 300, 400), Color::gray)); |
| 818 |
| 819 const cc::Layer* layer = contentLayerAt(0); |
| 820 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 821 } |
| 822 } |
| 823 |
| 824 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, Merge2DTransform) { |
| 825 RefPtr<TransformPaintPropertyNode> transform = |
| 826 TransformPaintPropertyNode::create( |
| 827 TransformPaintPropertyNode::root(), |
| 828 TransformationMatrix().translate(50, 50), FloatPoint3D(100, 100, 0), |
| 829 false, 0); |
| 830 |
| 831 TestPaintArtifact testArtifact; |
| 832 testArtifact |
| 833 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 834 EffectPaintPropertyNode::root()) |
| 835 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 836 testArtifact |
| 837 .chunk(transform.get(), ClipPaintPropertyNode::root(), |
| 838 EffectPaintPropertyNode::root()) |
| 839 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); |
| 840 testArtifact |
| 841 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 842 EffectPaintPropertyNode::root()) |
| 843 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 844 |
| 845 const PaintArtifact& artifact = testArtifact.build(); |
| 846 |
| 847 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 848 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 849 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[1], |
| 850 pendingLayer)); |
| 851 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 852 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[2], |
| 853 pendingLayer)); |
| 854 |
| 855 update(artifact); |
| 856 |
| 857 ASSERT_EQ(1u, contentLayerCount()); |
| 858 { |
| 859 Vector<RectWithColor> rectsWithColor; |
| 860 rectsWithColor.push_back( |
| 861 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 862 // Transform is applied to this PaintChunk. |
| 863 rectsWithColor.push_back( |
| 864 RectWithColor(FloatRect(50, 50, 100, 100), Color::black)); |
| 865 rectsWithColor.push_back( |
| 866 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 867 |
| 868 const cc::Layer* layer = contentLayerAt(0); |
| 869 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 870 } |
| 871 } |
| 872 |
| 873 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeOpacity) { |
| 874 float opacity = 2.0 / 255.0; |
| 875 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 876 EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 877 ClipPaintPropertyNode::root(), CompositorFilterOperations(), opacity, |
| 878 SkBlendMode::kSrcOver); |
| 879 |
| 880 TestPaintArtifact testArtifact; |
| 881 testArtifact |
| 882 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 883 EffectPaintPropertyNode::root()) |
| 884 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 885 testArtifact |
| 886 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 887 effect.get()) |
| 888 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); |
| 889 testArtifact |
| 890 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 891 EffectPaintPropertyNode::root()) |
| 892 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 893 |
| 894 const PaintArtifact& artifact = testArtifact.build(); |
| 895 |
| 896 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 897 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 898 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[1], |
| 899 pendingLayer)); |
| 900 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 901 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[2], |
| 902 pendingLayer)); |
| 903 |
| 904 update(artifact); |
| 905 |
| 906 ASSERT_EQ(1u, contentLayerCount()); |
| 907 { |
| 908 Vector<RectWithColor> rectsWithColor; |
| 909 rectsWithColor.push_back( |
| 910 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 911 // Transform is applied to this PaintChunk. |
| 912 rectsWithColor.push_back( |
| 913 RectWithColor(FloatRect(0, 0, 100, 100), |
| 914 Color(Color::black).combineWithAlpha(opacity).rgb())); |
| 915 rectsWithColor.push_back( |
| 916 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 917 |
| 918 const cc::Layer* layer = contentLayerAt(0); |
| 919 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 920 } |
| 921 } |
| 922 |
| 923 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeNested) { |
| 924 // Tests merging of an opacity effect, inside of a clip, inside of a |
| 925 // transform. |
| 926 |
| 927 RefPtr<TransformPaintPropertyNode> transform = |
| 928 TransformPaintPropertyNode::create( |
| 929 TransformPaintPropertyNode::root(), |
| 930 TransformationMatrix().translate(50, 50), FloatPoint3D(100, 100, 0), |
| 931 false, 0); |
| 932 |
| 933 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 934 ClipPaintPropertyNode::root(), transform.get(), |
| 935 FloatRoundedRect(10, 20, 50, 60)); |
| 936 |
| 937 float opacity = 2.0 / 255.0; |
| 938 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 939 EffectPaintPropertyNode::root(), transform.get(), clip.get(), |
| 940 CompositorFilterOperations(), opacity, SkBlendMode::kSrcOver); |
| 941 |
| 942 TestPaintArtifact testArtifact; |
| 943 testArtifact |
| 944 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 945 EffectPaintPropertyNode::root()) |
| 946 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 947 testArtifact.chunk(transform.get(), clip.get(), effect.get()) |
| 948 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); |
| 949 testArtifact |
| 950 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 951 EffectPaintPropertyNode::root()) |
| 952 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 953 |
| 954 const PaintArtifact& artifact = testArtifact.build(); |
| 955 |
| 956 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 957 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 958 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[1], |
| 959 pendingLayer)); |
| 960 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 961 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[2], |
| 962 pendingLayer)); |
| 963 update(artifact); |
| 964 |
| 965 ASSERT_EQ(1u, contentLayerCount()); |
| 966 { |
| 967 Vector<RectWithColor> rectsWithColor; |
| 968 rectsWithColor.push_back( |
| 969 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 970 // Transform is applied to this PaintChunk. |
| 971 rectsWithColor.push_back( |
| 972 RectWithColor(FloatRect(60, 70, 50, 60), |
| 973 Color(Color::black).combineWithAlpha(opacity).rgb())); |
| 974 rectsWithColor.push_back( |
| 975 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 976 |
| 977 const cc::Layer* layer = contentLayerAt(0); |
| 978 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 979 } |
| 980 } |
| 981 |
| 982 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, ClipPushedUp) { |
| 983 // Tests merging of an element which has a clipapplied to it, |
| 984 // but has an ancestor transform of them. This can happen for fixed- |
| 985 // or absolute-position elements which escape scroll transforms. |
| 986 |
| 987 RefPtr<TransformPaintPropertyNode> transform = |
| 988 TransformPaintPropertyNode::create( |
| 989 TransformPaintPropertyNode::root(), |
| 990 TransformationMatrix().translate(20, 25), FloatPoint3D(100, 100, 0), |
| 991 false, 0); |
| 992 |
| 993 RefPtr<TransformPaintPropertyNode> transform2 = |
| 994 TransformPaintPropertyNode::create( |
| 995 transform.get(), TransformationMatrix().translate(20, 25), |
| 996 FloatPoint3D(100, 100, 0), false, 0); |
| 997 |
| 998 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 999 ClipPaintPropertyNode::root(), transform2.get(), |
| 1000 FloatRoundedRect(10, 20, 50, 60)); |
| 1001 |
| 1002 TestPaintArtifact testArtifact; |
| 1003 testArtifact |
| 1004 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1005 EffectPaintPropertyNode::root()) |
| 1006 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 1007 testArtifact |
| 1008 .chunk(TransformPaintPropertyNode::root(), clip.get(), |
| 1009 EffectPaintPropertyNode::root()) |
| 1010 .rectDrawing(FloatRect(0, 0, 300, 400), Color::black); |
| 1011 testArtifact |
| 1012 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1013 EffectPaintPropertyNode::root()) |
| 1014 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 1015 |
| 1016 const PaintArtifact& artifact = testArtifact.build(); |
| 1017 |
| 1018 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 1019 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 1020 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[1], |
| 1021 pendingLayer)); |
| 1022 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 1023 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[2], |
| 1024 pendingLayer)); |
| 1025 update(artifact); |
| 1026 |
| 1027 ASSERT_EQ(1u, contentLayerCount()); |
| 1028 { |
| 1029 Vector<RectWithColor> rectsWithColor; |
| 1030 rectsWithColor.push_back( |
| 1031 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 1032 // The two transforms (combined translation of (40, 50)) are applied here, |
| 1033 // before clipping. |
| 1034 rectsWithColor.push_back( |
| 1035 RectWithColor(FloatRect(50, 70, 50, 60), Color(Color::black))); |
| 1036 rectsWithColor.push_back( |
| 1037 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 1038 |
| 1039 const cc::Layer* layer = contentLayerAt(0); |
| 1040 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 1041 } |
| 1042 } |
| 1043 |
| 1044 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectPushedUp) { |
| 1045 // Tests merging of an element which has an effect applied to it, |
| 1046 // but has an ancestor transform of them. This can happen for fixed- |
| 1047 // or absolute-position elements which escape scroll transforms. |
| 1048 |
| 1049 RefPtr<TransformPaintPropertyNode> transform = |
| 1050 TransformPaintPropertyNode::create( |
| 1051 TransformPaintPropertyNode::root(), |
| 1052 TransformationMatrix().translate(20, 25), FloatPoint3D(100, 100, 0), |
| 1053 false, 0); |
| 1054 |
| 1055 RefPtr<TransformPaintPropertyNode> transform2 = |
| 1056 TransformPaintPropertyNode::create( |
| 1057 transform.get(), TransformationMatrix().translate(20, 25), |
| 1058 FloatPoint3D(100, 100, 0), false, 0); |
| 1059 |
| 1060 float opacity = 2.0 / 255.0; |
| 1061 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 1062 EffectPaintPropertyNode::root(), transform2.get(), |
| 1063 ClipPaintPropertyNode::root(), CompositorFilterOperations(), opacity, |
| 1064 SkBlendMode::kSrcOver); |
| 1065 |
| 1066 TestPaintArtifact testArtifact; |
| 1067 testArtifact |
| 1068 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1069 EffectPaintPropertyNode::root()) |
| 1070 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 1071 testArtifact |
| 1072 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1073 effect.get()) |
| 1074 .rectDrawing(FloatRect(0, 0, 300, 400), Color::black); |
| 1075 testArtifact |
| 1076 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1077 EffectPaintPropertyNode::root()) |
| 1078 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 1079 |
| 1080 const PaintArtifact& artifact = testArtifact.build(); |
| 1081 |
| 1082 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 1083 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 1084 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[1], |
| 1085 pendingLayer)); |
| 1086 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 1087 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[2], |
| 1088 pendingLayer)); |
| 1089 update(artifact); |
| 1090 |
| 1091 ASSERT_EQ(1u, contentLayerCount()); |
| 1092 { |
| 1093 Vector<RectWithColor> rectsWithColor; |
| 1094 rectsWithColor.push_back( |
| 1095 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 1096 rectsWithColor.push_back( |
| 1097 RectWithColor(FloatRect(0, 0, 300, 400), |
| 1098 Color(Color::black).combineWithAlpha(opacity).rgb())); |
| 1099 rectsWithColor.push_back( |
| 1100 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 1101 |
| 1102 const cc::Layer* layer = contentLayerAt(0); |
| 1103 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 1104 } |
| 1105 } |
| 1106 |
| 1107 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, EffectAndClipPushedUp) { |
| 1108 // Tests merging of an element which has an effect applied to it, |
| 1109 // but has an ancestor transform of them. This can happen for fixed- |
| 1110 // or absolute-position elements which escape scroll transforms. |
| 1111 |
| 1112 RefPtr<TransformPaintPropertyNode> transform = |
| 1113 TransformPaintPropertyNode::create( |
| 1114 TransformPaintPropertyNode::root(), |
| 1115 TransformationMatrix().translate(20, 25), FloatPoint3D(100, 100, 0), |
| 1116 false, 0); |
| 1117 |
| 1118 RefPtr<TransformPaintPropertyNode> transform2 = |
| 1119 TransformPaintPropertyNode::create( |
| 1120 transform.get(), TransformationMatrix().translate(20, 25), |
| 1121 FloatPoint3D(100, 100, 0), false, 0); |
| 1122 |
| 1123 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 1124 ClipPaintPropertyNode::root(), transform.get(), |
| 1125 FloatRoundedRect(10, 20, 50, 60)); |
| 1126 |
| 1127 float opacity = 2.0 / 255.0; |
| 1128 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 1129 EffectPaintPropertyNode::root(), transform2.get(), clip.get(), |
| 1130 CompositorFilterOperations(), opacity, SkBlendMode::kSrcOver); |
| 1131 |
| 1132 TestPaintArtifact testArtifact; |
| 1133 testArtifact |
| 1134 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1135 EffectPaintPropertyNode::root()) |
| 1136 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 1137 testArtifact |
| 1138 .chunk(TransformPaintPropertyNode::root(), clip.get(), effect.get()) |
| 1139 .rectDrawing(FloatRect(0, 0, 300, 400), Color::black); |
| 1140 testArtifact |
| 1141 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1142 EffectPaintPropertyNode::root()) |
| 1143 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 1144 |
| 1145 const PaintArtifact& artifact = testArtifact.build(); |
| 1146 |
| 1147 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 1148 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 1149 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[1], |
| 1150 pendingLayer)); |
| 1151 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 1152 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[2], |
| 1153 pendingLayer)); |
| 1154 update(artifact); |
| 1155 |
| 1156 ASSERT_EQ(1u, contentLayerCount()); |
| 1157 { |
| 1158 Vector<RectWithColor> rectsWithColor; |
| 1159 rectsWithColor.push_back( |
| 1160 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 1161 // The clip is under |transform| but not |transform2|, so only an adjustment |
| 1162 // of (20, 25) occurs. |
| 1163 rectsWithColor.push_back( |
| 1164 RectWithColor(FloatRect(30, 45, 50, 60), |
| 1165 Color(Color::black).combineWithAlpha(opacity).rgb())); |
| 1166 rectsWithColor.push_back( |
| 1167 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 1168 |
| 1169 const cc::Layer* layer = contentLayerAt(0); |
| 1170 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 1171 } |
| 1172 } |
| 1173 |
| 1174 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, ClipAndEffectNoTransform) { |
| 1175 // Tests merging of an element which has a clip and effect in the root |
| 1176 // transform space. |
| 1177 |
| 1178 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 1179 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 1180 FloatRoundedRect(10, 20, 50, 60)); |
| 1181 |
| 1182 float opacity = 2.0 / 255.0; |
| 1183 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( |
| 1184 EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 1185 clip.get(), CompositorFilterOperations(), opacity, SkBlendMode::kSrcOver); |
| 1186 |
| 1187 TestPaintArtifact testArtifact; |
| 1188 testArtifact |
| 1189 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1190 EffectPaintPropertyNode::root()) |
| 1191 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 1192 testArtifact |
| 1193 .chunk(TransformPaintPropertyNode::root(), clip.get(), effect.get()) |
| 1194 .rectDrawing(FloatRect(0, 0, 300, 400), Color::black); |
| 1195 testArtifact |
| 1196 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1197 EffectPaintPropertyNode::root()) |
| 1198 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 1199 |
| 1200 const PaintArtifact& artifact = testArtifact.build(); |
| 1201 |
| 1202 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 1203 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 1204 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[1], |
| 1205 pendingLayer)); |
| 1206 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 1207 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[2], |
| 1208 pendingLayer)); |
| 1209 update(artifact); |
| 1210 |
| 1211 ASSERT_EQ(1u, contentLayerCount()); |
| 1212 { |
| 1213 Vector<RectWithColor> rectsWithColor; |
| 1214 rectsWithColor.push_back( |
| 1215 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 1216 rectsWithColor.push_back( |
| 1217 RectWithColor(FloatRect(10, 20, 50, 60), |
| 1218 Color(Color::black).combineWithAlpha(opacity).rgb())); |
| 1219 rectsWithColor.push_back( |
| 1220 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 1221 |
| 1222 const cc::Layer* layer = contentLayerAt(0); |
| 1223 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 1224 } |
| 1225 } |
| 1226 |
| 1227 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TwoClips) { |
| 1228 // Tests merging of an element which has two clips in the root |
| 1229 // transform space. |
| 1230 |
| 1231 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( |
| 1232 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 1233 FloatRoundedRect(20, 30, 10, 20)); |
| 1234 |
| 1235 RefPtr<ClipPaintPropertyNode> clip2 = ClipPaintPropertyNode::create( |
| 1236 clip.get(), TransformPaintPropertyNode::root(), |
| 1237 FloatRoundedRect(10, 20, 50, 60)); |
| 1238 |
| 1239 TestPaintArtifact testArtifact; |
| 1240 testArtifact |
| 1241 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1242 EffectPaintPropertyNode::root()) |
| 1243 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 1244 testArtifact |
| 1245 .chunk(TransformPaintPropertyNode::root(), clip2.get(), |
| 1246 EffectPaintPropertyNode::root()) |
| 1247 .rectDrawing(FloatRect(0, 0, 300, 400), Color::black); |
| 1248 testArtifact |
| 1249 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1250 EffectPaintPropertyNode::root()) |
| 1251 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); |
| 1252 |
| 1253 const PaintArtifact& artifact = testArtifact.build(); |
| 1254 |
| 1255 ASSERT_EQ(3u, artifact.paintChunks().size()); |
| 1256 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); |
| 1257 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[1], |
| 1258 pendingLayer)); |
| 1259 pendingLayer.add(artifact.paintChunks()[1], nullptr); |
| 1260 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact, artifact.paintChun
ks()[2], |
| 1261 pendingLayer)); |
| 1262 update(artifact); |
| 1263 |
| 1264 ASSERT_EQ(1u, contentLayerCount()); |
| 1265 { |
| 1266 Vector<RectWithColor> rectsWithColor; |
| 1267 rectsWithColor.push_back( |
| 1268 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); |
| 1269 // The interesction of the two clips is (20, 30, 10, 20). |
| 1270 rectsWithColor.push_back( |
| 1271 RectWithColor(FloatRect(20, 30, 10, 20), Color(Color::black))); |
| 1272 rectsWithColor.push_back( |
| 1273 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); |
| 1274 |
| 1275 const cc::Layer* layer = contentLayerAt(0); |
| 1276 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); |
| 1277 } |
| 1278 } |
| 1279 |
| 1280 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayer) { |
| 1281 PaintChunk chunk1; |
| 1282 chunk1.properties.propertyTreeState = PropertyTreeState( |
| 1283 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1284 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); |
| 1285 chunk1.properties.backfaceHidden = true; |
| 1286 chunk1.knownToBeOpaque = true; |
| 1287 chunk1.bounds = FloatRect(0, 0, 30, 40); |
| 1288 |
| 1289 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1); |
| 1290 |
| 1291 EXPECT_TRUE(pendingLayer.backfaceHidden); |
| 1292 EXPECT_TRUE(pendingLayer.knownToBeOpaque); |
| 1293 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 40), pendingLayer.bounds); |
| 1294 |
| 1295 PaintChunk chunk2; |
| 1296 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; |
| 1297 chunk2.properties.backfaceHidden = true; |
| 1298 chunk2.knownToBeOpaque = true; |
| 1299 chunk2.bounds = FloatRect(10, 20, 30, 40); |
| 1300 pendingLayer.add(chunk2, nullptr); |
| 1301 |
| 1302 EXPECT_TRUE(pendingLayer.backfaceHidden); |
| 1303 // Bounds not equal to one PaintChunk. |
| 1304 EXPECT_FALSE(pendingLayer.knownToBeOpaque); |
| 1305 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 40, 60), pendingLayer.bounds); |
| 1306 |
| 1307 PaintChunk chunk3; |
| 1308 chunk3.properties.propertyTreeState = chunk1.properties.propertyTreeState; |
| 1309 chunk3.properties.backfaceHidden = true; |
| 1310 chunk3.knownToBeOpaque = true; |
| 1311 chunk3.bounds = FloatRect(-5, -25, 20, 20); |
| 1312 pendingLayer.add(chunk3, nullptr); |
| 1313 |
| 1314 EXPECT_TRUE(pendingLayer.backfaceHidden); |
| 1315 EXPECT_FALSE(pendingLayer.knownToBeOpaque); |
| 1316 EXPECT_FLOAT_RECT_EQ(FloatRect(-5, -25, 45, 85), pendingLayer.bounds); |
| 1317 } |
| 1318 |
| 1319 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayerWithGeometry) { |
| 1320 RefPtr<TransformPaintPropertyNode> transform = |
| 1321 TransformPaintPropertyNode::create( |
| 1322 TransformPaintPropertyNode::root(), |
| 1323 TransformationMatrix().translate(20, 25), FloatPoint3D(100, 100, 0), |
| 1324 false, 0); |
| 1325 |
| 1326 PaintChunk chunk1; |
| 1327 chunk1.properties.propertyTreeState = PropertyTreeState( |
| 1328 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 1329 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); |
| 1330 chunk1.bounds = FloatRect(0, 0, 30, 40); |
| 1331 |
| 1332 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1); |
| 1333 |
| 1334 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 40), pendingLayer.bounds); |
| 1335 |
| 1336 PaintChunk chunk2; |
| 1337 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; |
| 1338 chunk2.properties.propertyTreeState.setTransform(transform); |
| 1339 chunk2.bounds = FloatRect(0, 0, 50, 60); |
| 1340 GeometryMapper geometryMapper; |
| 1341 pendingLayer.add(chunk2, &geometryMapper); |
| 1342 |
| 1343 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 70, 85), pendingLayer.bounds); |
| 1344 } |
| 1345 |
| 722 } // namespace blink | 1346 } // namespace blink |
| OLD | NEW |