Chromium Code Reviews| 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" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" | 21 #include "platform/graphics/paint/ScrollPaintPropertyNode.h" |
| 22 #include "platform/testing/PaintPropertyTestHelpers.h" | 22 #include "platform/testing/PaintPropertyTestHelpers.h" |
| 23 #include "platform/testing/PictureMatchers.h" | 23 #include "platform/testing/PictureMatchers.h" |
| 24 #include "platform/testing/TestPaintArtifact.h" | 24 #include "platform/testing/TestPaintArtifact.h" |
| 25 #include "platform/testing/WebLayerTreeViewImplForTesting.h" | 25 #include "platform/testing/WebLayerTreeViewImplForTesting.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include <memory> | 28 #include <memory> |
| 29 | 29 |
| 30 namespace blink { | 30 namespace blink { |
| 31 namespace { | |
| 32 | 31 |
| 33 using ::blink::testing::createOpacityOnlyEffect; | 32 using ::blink::testing::createOpacityOnlyEffect; |
| 34 using ::testing::Pointee; | 33 using ::testing::Pointee; |
| 35 | 34 |
| 36 PaintChunkProperties defaultPaintChunkProperties() { | 35 PaintChunkProperties defaultPaintChunkProperties() { |
| 37 PropertyTreeState propertyTreeState( | 36 PropertyTreeState propertyTreeState( |
| 38 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | 37 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 39 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); | 38 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); |
| 40 return PaintChunkProperties(propertyTreeState); | 39 return PaintChunkProperties(propertyTreeState); |
| 41 } | 40 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 const cc::Layer* child = contentLayerAt(0); | 134 const cc::Layer* child = contentLayerAt(0); |
| 136 EXPECT_THAT(child->GetPicture(), | 135 EXPECT_THAT(child->GetPicture(), |
| 137 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); | 136 Pointee(drawsRectangle(FloatRect(0, 0, 100, 100), Color::white))); |
| 138 EXPECT_EQ(translation(50, -50), child->screen_space_transform()); | 137 EXPECT_EQ(translation(50, -50), child->screen_space_transform()); |
| 139 EXPECT_EQ(gfx::Size(100, 100), child->bounds()); | 138 EXPECT_EQ(gfx::Size(100, 100), child->bounds()); |
| 140 } | 139 } |
| 141 | 140 |
| 142 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneTransform) { | 141 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, OneTransform) { |
| 143 // A 90 degree clockwise rotation about (100, 100). | 142 // A 90 degree clockwise rotation about (100, 100). |
| 144 RefPtr<TransformPaintPropertyNode> transform = | 143 RefPtr<TransformPaintPropertyNode> transform = |
| 145 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), | 144 TransformPaintPropertyNode::create( |
| 146 TransformationMatrix().rotate(90), | 145 TransformPaintPropertyNode::root(), TransformationMatrix().rotate(90), |
| 147 FloatPoint3D(100, 100, 0)); | 146 FloatPoint3D(100, 100, 0), false, 0, CompositingReason3DTransform); |
| 148 | 147 |
| 149 TestPaintArtifact artifact; | 148 TestPaintArtifact artifact; |
| 150 artifact | 149 artifact |
| 151 .chunk(transform, ClipPaintPropertyNode::root(), | 150 .chunk(transform, ClipPaintPropertyNode::root(), |
| 152 EffectPaintPropertyNode::root()) | 151 EffectPaintPropertyNode::root()) |
| 153 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | 152 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); |
| 154 artifact | 153 artifact |
| 155 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | 154 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), |
| 156 EffectPaintPropertyNode::root()) | 155 EffectPaintPropertyNode::root()) |
| 157 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); | 156 .rectDrawing(FloatRect(0, 0, 100, 100), Color::gray); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 185 Pointee(drawsRectangle(FloatRect(0, 0, 200, 100), Color::black))); | 184 Pointee(drawsRectangle(FloatRect(0, 0, 200, 100), Color::black))); |
| 186 gfx::RectF mappedRect(0, 0, 200, 100); | 185 gfx::RectF mappedRect(0, 0, 200, 100); |
| 187 layer->screen_space_transform().TransformRect(&mappedRect); | 186 layer->screen_space_transform().TransformRect(&mappedRect); |
| 188 EXPECT_EQ(gfx::RectF(0, 100, 100, 200), mappedRect); | 187 EXPECT_EQ(gfx::RectF(0, 100, 100, 200), mappedRect); |
| 189 } | 188 } |
| 190 } | 189 } |
| 191 | 190 |
| 192 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TransformCombining) { | 191 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, TransformCombining) { |
| 193 // A translation by (5, 5) within a 2x scale about (10, 10). | 192 // A translation by (5, 5) within a 2x scale about (10, 10). |
| 194 RefPtr<TransformPaintPropertyNode> transform1 = | 193 RefPtr<TransformPaintPropertyNode> transform1 = |
| 195 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), | 194 TransformPaintPropertyNode::create( |
| 196 TransformationMatrix().scale(2), | 195 TransformPaintPropertyNode::root(), TransformationMatrix().scale(2), |
| 197 FloatPoint3D(10, 10, 0)); | 196 FloatPoint3D(10, 10, 0), false, 0, CompositingReason3DTransform); |
| 198 RefPtr<TransformPaintPropertyNode> transform2 = | 197 RefPtr<TransformPaintPropertyNode> transform2 = |
| 199 TransformPaintPropertyNode::create( | 198 TransformPaintPropertyNode::create( |
| 200 transform1, TransformationMatrix().translate(5, 5), FloatPoint3D()); | 199 transform1, TransformationMatrix().translate(5, 5), FloatPoint3D()); |
| 201 | 200 |
| 202 TestPaintArtifact artifact; | 201 TestPaintArtifact artifact; |
| 203 artifact | 202 artifact |
| 204 .chunk(transform1, ClipPaintPropertyNode::root(), | 203 .chunk(transform1, ClipPaintPropertyNode::root(), |
| 205 EffectPaintPropertyNode::root()) | 204 EffectPaintPropertyNode::root()) |
| 206 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); | 205 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); |
| 207 artifact | 206 artifact |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 | 292 |
| 294 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SortingContextID) { | 293 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, SortingContextID) { |
| 295 // Has no 3D rendering context. | 294 // Has no 3D rendering context. |
| 296 RefPtr<TransformPaintPropertyNode> transform1 = | 295 RefPtr<TransformPaintPropertyNode> transform1 = |
| 297 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), | 296 TransformPaintPropertyNode::create(TransformPaintPropertyNode::root(), |
| 298 TransformationMatrix(), | 297 TransformationMatrix(), |
| 299 FloatPoint3D()); | 298 FloatPoint3D()); |
| 300 // Establishes a 3D rendering context. | 299 // Establishes a 3D rendering context. |
| 301 RefPtr<TransformPaintPropertyNode> transform2 = | 300 RefPtr<TransformPaintPropertyNode> transform2 = |
| 302 TransformPaintPropertyNode::create(transform1, TransformationMatrix(), | 301 TransformPaintPropertyNode::create(transform1, TransformationMatrix(), |
| 303 FloatPoint3D(), false, 1); | 302 FloatPoint3D(), false, 1, |
| 303 CompositingReason3DTransform); | |
| 304 // Extends the 3D rendering context of transform2. | 304 // Extends the 3D rendering context of transform2. |
| 305 RefPtr<TransformPaintPropertyNode> transform3 = | 305 RefPtr<TransformPaintPropertyNode> transform3 = |
| 306 TransformPaintPropertyNode::create(transform2, TransformationMatrix(), | 306 TransformPaintPropertyNode::create(transform2, TransformationMatrix(), |
| 307 FloatPoint3D(), false, 1); | 307 FloatPoint3D(), false, 1, |
| 308 CompositingReason3DTransform); | |
| 308 // Establishes a 3D rendering context distinct from transform2. | 309 // Establishes a 3D rendering context distinct from transform2. |
| 309 RefPtr<TransformPaintPropertyNode> transform4 = | 310 RefPtr<TransformPaintPropertyNode> transform4 = |
| 310 TransformPaintPropertyNode::create(transform2, TransformationMatrix(), | 311 TransformPaintPropertyNode::create(transform2, TransformationMatrix(), |
| 311 FloatPoint3D(), false, 2); | 312 FloatPoint3D(), false, 2, |
| 313 CompositingReason3DTransform); | |
| 312 | 314 |
| 313 TestPaintArtifact artifact; | 315 TestPaintArtifact artifact; |
| 314 artifact | 316 artifact |
| 315 .chunk(transform1, ClipPaintPropertyNode::root(), | 317 .chunk(transform1, ClipPaintPropertyNode::root(), |
| 316 EffectPaintPropertyNode::root()) | 318 EffectPaintPropertyNode::root()) |
| 317 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); | 319 .rectDrawing(FloatRect(0, 0, 300, 200), Color::white); |
| 318 artifact | 320 artifact |
| 319 .chunk(transform2, ClipPaintPropertyNode::root(), | 321 .chunk(transform2, ClipPaintPropertyNode::root(), |
| 320 EffectPaintPropertyNode::root()) | 322 EffectPaintPropertyNode::root()) |
| 321 .rectDrawing(FloatRect(0, 0, 300, 200), Color::lightGray); | 323 .rectDrawing(FloatRect(0, 0, 300, 200), Color::lightGray); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 const cc::ClipNode* clipNode = | 396 const cc::ClipNode* clipNode = |
| 395 propertyTrees().clip_tree.Node(layer->clip_tree_index()); | 397 propertyTrees().clip_tree.Node(layer->clip_tree_index()); |
| 396 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, clipNode->clip_type); | 398 EXPECT_EQ(cc::ClipNode::ClipType::APPLIES_LOCAL_CLIP, clipNode->clip_type); |
| 397 EXPECT_TRUE(clipNode->layers_are_clipped); | 399 EXPECT_TRUE(clipNode->layers_are_clipped); |
| 398 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->clip); | 400 EXPECT_EQ(gfx::RectF(100, 100, 300, 200), clipNode->clip); |
| 399 } | 401 } |
| 400 | 402 |
| 401 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) { | 403 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, NestedClips) { |
| 402 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( | 404 RefPtr<ClipPaintPropertyNode> clip1 = ClipPaintPropertyNode::create( |
| 403 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), | 405 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), |
| 404 FloatRoundedRect(100, 100, 700, 700)); | 406 FloatRoundedRect(100, 100, 700, 700), |
| 407 CompositingReasonOverflowScrollingTouch); | |
| 405 RefPtr<ClipPaintPropertyNode> clip2 = | 408 RefPtr<ClipPaintPropertyNode> clip2 = |
| 406 ClipPaintPropertyNode::create(clip1, TransformPaintPropertyNode::root(), | 409 ClipPaintPropertyNode::create(clip1, TransformPaintPropertyNode::root(), |
| 407 FloatRoundedRect(200, 200, 700, 100)); | 410 FloatRoundedRect(200, 200, 700, 100), |
| 411 CompositingReasonOverflowScrollingTouch); | |
| 408 | 412 |
| 409 TestPaintArtifact artifact; | 413 TestPaintArtifact artifact; |
| 410 artifact | 414 artifact |
| 411 .chunk(TransformPaintPropertyNode::root(), clip1, | 415 .chunk(TransformPaintPropertyNode::root(), clip1, |
| 412 EffectPaintPropertyNode::root()) | 416 EffectPaintPropertyNode::root()) |
| 413 .rectDrawing(FloatRect(300, 350, 100, 100), Color::white); | 417 .rectDrawing(FloatRect(300, 350, 100, 100), Color::white); |
| 414 artifact | 418 artifact |
| 415 .chunk(TransformPaintPropertyNode::root(), clip2, | 419 .chunk(TransformPaintPropertyNode::root(), clip2, |
| 416 EffectPaintPropertyNode::root()) | 420 EffectPaintPropertyNode::root()) |
| 417 .rectDrawing(FloatRect(300, 350, 100, 100), Color::lightGray); | 421 .rectDrawing(FloatRect(300, 350, 100, 100), Color::lightGray); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 713 scrollTree.current_scroll_offset(contentLayerAt(0)->id())); | 717 scrollTree.current_scroll_offset(contentLayerAt(0)->id())); |
| 714 EXPECT_EQ(gfx::ScrollOffset(-37, -41), | 718 EXPECT_EQ(gfx::ScrollOffset(-37, -41), |
| 715 scrollTree.current_scroll_offset(contentLayerAt(1)->id())); | 719 scrollTree.current_scroll_offset(contentLayerAt(1)->id())); |
| 716 | 720 |
| 717 EXPECT_TRUE(scrollNodeA.main_thread_scrolling_reasons & | 721 EXPECT_TRUE(scrollNodeA.main_thread_scrolling_reasons & |
| 718 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); | 722 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 719 EXPECT_FALSE(scrollNodeB.main_thread_scrolling_reasons & | 723 EXPECT_FALSE(scrollNodeB.main_thread_scrolling_reasons & |
| 720 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); | 724 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 721 } | 725 } |
| 722 | 726 |
| 723 } // namespace | 727 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeSimpleChunks) { |
| 728 TestPaintArtifact testArtifact; | |
| 729 testArtifact | |
| 730 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | |
| 731 EffectPaintPropertyNode::root()) | |
| 732 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | |
| 733 testArtifact | |
| 734 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | |
| 735 EffectPaintPropertyNode::root()) | |
| 736 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); | |
| 737 | |
| 738 const PaintArtifact& artifact = testArtifact.build(); | |
| 739 | |
| 740 ASSERT_EQ(2u, artifact.paintChunks().size()); | |
| 741 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); | |
| 742 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[1], | |
| 743 pendingLayer)); | |
| 744 | |
| 745 update(artifact); | |
| 746 | |
| 747 ASSERT_EQ(1u, contentLayerCount()); | |
| 748 { | |
| 749 Vector<RectWithColor> rectsWithColor; | |
| 750 rectsWithColor.push_back( | |
| 751 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); | |
| 752 rectsWithColor.push_back( | |
| 753 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); | |
| 754 | |
| 755 const cc::Layer* layer = contentLayerAt(0); | |
| 756 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); | |
| 757 } | |
| 758 } | |
| 759 | |
| 760 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeClip) { | |
| 761 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( | |
| 762 ClipPaintPropertyNode::root(), TransformPaintPropertyNode::root(), | |
| 763 FloatRoundedRect(10, 20, 50, 60)); | |
| 764 | |
| 765 TestPaintArtifact testArtifact; | |
| 766 testArtifact | |
| 767 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | |
| 768 EffectPaintPropertyNode::root()) | |
| 769 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | |
| 770 testArtifact | |
| 771 .chunk(TransformPaintPropertyNode::root(), clip.get(), | |
| 772 EffectPaintPropertyNode::root()) | |
| 773 .rectDrawing(FloatRect(0, 0, 200, 300), Color::black); | |
| 774 testArtifact | |
| 775 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | |
| 776 EffectPaintPropertyNode::root()) | |
| 777 .rectDrawing(FloatRect(0, 0, 300, 400), Color::gray); | |
| 778 | |
| 779 const PaintArtifact& artifact = testArtifact.build(); | |
| 780 | |
| 781 ASSERT_EQ(3u, artifact.paintChunks().size()); | |
| 782 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); | |
| 783 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[1], | |
| 784 pendingLayer)); | |
| 785 pendingLayer.add(artifact.paintChunks()[1]); | |
| 786 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[2], | |
| 787 pendingLayer)); | |
| 788 | |
| 789 update(artifact); | |
| 790 | |
| 791 ASSERT_EQ(1u, contentLayerCount()); | |
| 792 { | |
| 793 Vector<RectWithColor> rectsWithColor; | |
| 794 rectsWithColor.push_back( | |
| 795 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); | |
| 796 // Clip is applied to this PaintChunk. | |
| 797 rectsWithColor.push_back( | |
| 798 RectWithColor(FloatRect(10, 20, 50, 60), Color::black)); | |
| 799 rectsWithColor.push_back( | |
| 800 RectWithColor(FloatRect(0, 0, 300, 400), Color::gray)); | |
| 801 | |
| 802 const cc::Layer* layer = contentLayerAt(0); | |
| 803 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); | |
| 804 } | |
| 805 } | |
| 806 | |
| 807 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, Merge2DTransform) { | |
| 808 RefPtr<TransformPaintPropertyNode> transform = | |
| 809 TransformPaintPropertyNode::create( | |
| 810 TransformPaintPropertyNode::root(), | |
| 811 TransformationMatrix().translate(50, 50), FloatPoint3D(100, 100, 0), | |
| 812 false, 0); | |
| 813 | |
| 814 TestPaintArtifact testArtifact; | |
| 815 testArtifact | |
| 816 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | |
| 817 EffectPaintPropertyNode::root()) | |
| 818 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | |
| 819 testArtifact | |
| 820 .chunk(transform.get(), ClipPaintPropertyNode::root(), | |
| 821 EffectPaintPropertyNode::root()) | |
| 822 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); | |
| 823 testArtifact | |
| 824 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | |
| 825 EffectPaintPropertyNode::root()) | |
| 826 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); | |
| 827 | |
| 828 const PaintArtifact& artifact = testArtifact.build(); | |
| 829 | |
| 830 ASSERT_EQ(3u, artifact.paintChunks().size()); | |
| 831 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); | |
| 832 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[1], | |
| 833 pendingLayer)); | |
| 834 pendingLayer.add(artifact.paintChunks()[1]); | |
| 835 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[2], | |
| 836 pendingLayer)); | |
| 837 | |
| 838 update(artifact); | |
| 839 | |
| 840 ASSERT_EQ(1u, contentLayerCount()); | |
| 841 { | |
| 842 Vector<RectWithColor> rectsWithColor; | |
| 843 rectsWithColor.push_back( | |
| 844 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); | |
| 845 // Transform is applied to this PaintChunk. | |
| 846 rectsWithColor.push_back( | |
| 847 RectWithColor(FloatRect(50, 50, 100, 100), Color::black)); | |
| 848 rectsWithColor.push_back( | |
| 849 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); | |
| 850 | |
| 851 const cc::Layer* layer = contentLayerAt(0); | |
| 852 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); | |
| 853 } | |
| 854 } | |
| 855 | |
| 856 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeOpacity) { | |
| 857 float opacity = 2.0 / 255.0; | |
| 858 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( | |
| 859 EffectPaintPropertyNode::root(), TransformPaintPropertyNode::root(), | |
| 860 ClipPaintPropertyNode::root(), CompositorFilterOperations(), opacity, | |
| 861 SkBlendMode::kSrcOver); | |
| 862 | |
| 863 TestPaintArtifact testArtifact; | |
| 864 testArtifact | |
| 865 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | |
| 866 EffectPaintPropertyNode::root()) | |
| 867 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | |
| 868 testArtifact | |
| 869 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | |
| 870 effect.get()) | |
| 871 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); | |
| 872 testArtifact | |
| 873 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | |
| 874 EffectPaintPropertyNode::root()) | |
| 875 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); | |
| 876 | |
| 877 const PaintArtifact& artifact = testArtifact.build(); | |
| 878 | |
| 879 ASSERT_EQ(3u, artifact.paintChunks().size()); | |
| 880 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); | |
| 881 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[1], | |
| 882 pendingLayer)); | |
| 883 pendingLayer.add(artifact.paintChunks()[1]); | |
| 884 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[2], | |
| 885 pendingLayer)); | |
| 886 | |
| 887 update(artifact); | |
| 888 | |
| 889 ASSERT_EQ(1u, contentLayerCount()); | |
| 890 { | |
| 891 Vector<RectWithColor> rectsWithColor; | |
| 892 rectsWithColor.push_back( | |
| 893 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); | |
| 894 // Transform is applied to this PaintChunk. | |
| 895 rectsWithColor.push_back( | |
| 896 RectWithColor(FloatRect(0, 0, 100, 100), | |
| 897 Color(Color::black).combineWithAlpha(opacity).rgb())); | |
| 898 rectsWithColor.push_back( | |
| 899 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); | |
| 900 | |
| 901 const cc::Layer* layer = contentLayerAt(0); | |
| 902 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); | |
| 903 } | |
| 904 } | |
| 905 | |
| 906 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, MergeNested) { | |
| 907 // Tests merging of an opacity effect, inside of a clip, inside of a | |
| 908 // transform. | |
| 909 | |
| 910 RefPtr<TransformPaintPropertyNode> transform = | |
| 911 TransformPaintPropertyNode::create( | |
| 912 TransformPaintPropertyNode::root(), | |
| 913 TransformationMatrix().translate(50, 50), FloatPoint3D(100, 100, 0), | |
| 914 false, 0); | |
| 915 | |
| 916 RefPtr<ClipPaintPropertyNode> clip = ClipPaintPropertyNode::create( | |
| 917 ClipPaintPropertyNode::root(), transform.get(), | |
| 918 FloatRoundedRect(10, 20, 50, 60)); | |
| 919 | |
| 920 float opacity = 2.0 / 255.0; | |
| 921 RefPtr<EffectPaintPropertyNode> effect = EffectPaintPropertyNode::create( | |
| 922 EffectPaintPropertyNode::root(), transform.get(), clip.get(), | |
| 923 CompositorFilterOperations(), opacity, SkBlendMode::kSrcOver); | |
| 924 | |
| 925 TestPaintArtifact testArtifact; | |
| 926 testArtifact | |
| 927 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | |
| 928 EffectPaintPropertyNode::root()) | |
| 929 .rectDrawing(FloatRect(0, 0, 100, 100), Color::white); | |
| 930 testArtifact.chunk(transform.get(), clip.get(), effect.get()) | |
| 931 .rectDrawing(FloatRect(0, 0, 100, 100), Color::black); | |
| 932 testArtifact | |
| 933 .chunk(TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | |
| 934 EffectPaintPropertyNode::root()) | |
| 935 .rectDrawing(FloatRect(0, 0, 200, 300), Color::gray); | |
| 936 | |
| 937 const PaintArtifact& artifact = testArtifact.build(); | |
| 938 | |
| 939 ASSERT_EQ(3u, artifact.paintChunks().size()); | |
| 940 PaintArtifactCompositor::PendingLayer pendingLayer(artifact.paintChunks()[0]); | |
| 941 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[1], | |
| 942 pendingLayer)); | |
| 943 pendingLayer.add(artifact.paintChunks()[1]); | |
| 944 EXPECT_TRUE(PaintArtifactCompositor::canMergeInto(artifact.paintChunks()[2], | |
| 945 pendingLayer)); | |
| 946 | |
| 947 update(artifact); | |
| 948 | |
| 949 ASSERT_EQ(1u, contentLayerCount()); | |
| 950 { | |
| 951 Vector<RectWithColor> rectsWithColor; | |
| 952 rectsWithColor.push_back( | |
| 953 RectWithColor(FloatRect(0, 0, 100, 100), Color::white)); | |
| 954 // Transform is applied to this PaintChunk. | |
| 955 rectsWithColor.push_back( | |
| 956 RectWithColor(FloatRect(60, 70, 50, 60), | |
| 957 Color(Color::black).combineWithAlpha(opacity).rgb())); | |
| 958 rectsWithColor.push_back( | |
| 959 RectWithColor(FloatRect(0, 0, 200, 300), Color::gray)); | |
| 960 | |
| 961 const cc::Layer* layer = contentLayerAt(0); | |
| 962 EXPECT_THAT(layer->GetPicture(), Pointee(drawsRectangles(rectsWithColor))); | |
| 963 } | |
| 964 } | |
| 965 | |
| 966 TEST_F(PaintArtifactCompositorTestWithPropertyTrees, PendingLayer) { | |
| 967 PaintChunk chunk1; | |
| 968 chunk1.properties.propertyTreeState = PropertyTreeState( | |
| 969 TransformPaintPropertyNode::root(), ClipPaintPropertyNode::root(), | |
| 970 EffectPaintPropertyNode::root(), ScrollPaintPropertyNode::root()); | |
| 971 chunk1.properties.backfaceHidden = true; | |
| 972 chunk1.knownToBeOpaque = true; | |
| 973 chunk1.bounds = FloatRect(0, 0, 30, 40); | |
| 974 | |
| 975 PaintArtifactCompositor::PendingLayer pendingLayer(chunk1); | |
| 976 | |
| 977 EXPECT_TRUE(pendingLayer.backfaceHidden); | |
| 978 EXPECT_TRUE(pendingLayer.knownToBeOpaque); | |
| 979 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 30, 40), pendingLayer.bounds); | |
| 980 | |
| 981 PaintChunk chunk2; | |
| 982 chunk2.properties.propertyTreeState = chunk1.properties.propertyTreeState; | |
| 983 chunk2.properties.backfaceHidden = true; | |
| 984 chunk2.knownToBeOpaque = false; | |
| 985 chunk2.bounds = FloatRect(10, 20, 30, 40); | |
| 986 pendingLayer.add(chunk2); | |
| 987 | |
| 988 EXPECT_TRUE(pendingLayer.backfaceHidden); | |
| 989 EXPECT_FALSE(pendingLayer.knownToBeOpaque); | |
| 990 EXPECT_FLOAT_RECT_EQ(FloatRect(0, 0, 40, 60), pendingLayer.bounds); | |
| 991 | |
| 992 PaintChunk chunk3; | |
| 993 chunk3.properties.propertyTreeState = chunk1.properties.propertyTreeState; | |
| 994 chunk3.properties.backfaceHidden = true; | |
| 995 chunk3.knownToBeOpaque = true; | |
| 996 chunk3.bounds = FloatRect(-5, -25, 20, 20); | |
| 997 pendingLayer.add(chunk3); | |
| 998 | |
| 999 EXPECT_TRUE(pendingLayer.backfaceHidden); | |
| 1000 EXPECT_FALSE(pendingLayer.knownToBeOpaque); | |
| 1001 EXPECT_FLOAT_RECT_EQ(FloatRect(-5, -25, 45, 85), pendingLayer.bounds); | |
| 1002 } | |
| 1003 | |
|
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
| |
| 724 } // namespace blink | 1004 } // namespace blink |
| OLD | NEW |