Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: cc/trees/layer_tree_host_common_unittest.cc

Issue 737943002: Update from https://crrev.com/304715 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host_common_perftest.cc ('k') | cc/trees/layer_tree_host_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 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 "cc/trees/layer_tree_host_common.h" 5 #include "cc/trees/layer_tree_host_common.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "cc/animation/layer_animation_controller.h" 10 #include "cc/animation/layer_animation_controller.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } 52 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; }
53 53
54 class MockContentLayerClient : public ContentLayerClient { 54 class MockContentLayerClient : public ContentLayerClient {
55 public: 55 public:
56 MockContentLayerClient() {} 56 MockContentLayerClient() {}
57 ~MockContentLayerClient() override {} 57 ~MockContentLayerClient() override {}
58 void PaintContents( 58 void PaintContents(
59 SkCanvas* canvas, 59 SkCanvas* canvas,
60 const gfx::Rect& clip, 60 const gfx::Rect& clip,
61 ContentLayerClient::GraphicsContextStatus gc_status) override {} 61 ContentLayerClient::GraphicsContextStatus gc_status) override {}
62 void DidChangeLayerCanUseLCDText() override {}
63 bool FillsBoundsCompletely() const override { return false; } 62 bool FillsBoundsCompletely() const override { return false; }
64 }; 63 };
65 64
66 scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer( 65 scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer(
67 ContentLayerClient* delegate) { 66 ContentLayerClient* delegate) {
68 scoped_refptr<FakePictureLayer> to_return = 67 scoped_refptr<FakePictureLayer> to_return =
69 FakePictureLayer::Create(delegate); 68 FakePictureLayer::Create(delegate);
70 to_return->SetIsDrawable(true); 69 to_return->SetIsDrawable(true);
71 return to_return; 70 return to_return;
72 } 71 }
(...skipping 5564 matching lines...) Expand 10 before | Expand all | Expand 10 after
5637 root.get(), root->bounds(), &render_surface_layer_list); 5636 root.get(), root->bounds(), &render_surface_layer_list);
5638 inputs.can_adjust_raster_scales = true; 5637 inputs.can_adjust_raster_scales = true;
5639 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 5638 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
5640 5639
5641 // We should have one render surface and two layers. The child 5640 // We should have one render surface and two layers. The child
5642 // layer should be included even though it is transparent. 5641 // layer should be included even though it is transparent.
5643 ASSERT_EQ(1u, render_surface_layer_list.size()); 5642 ASSERT_EQ(1u, render_surface_layer_list.size());
5644 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); 5643 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5645 } 5644 }
5646 5645
5647 typedef std::tr1::tuple<bool, bool> LCDTextTestParam; 5646 using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
5648 class LCDTextTest 5647 class LCDTextTest
5649 : public LayerTreeHostCommonTestBase, 5648 : public LayerTreeHostCommonTestBase,
5650 public testing::TestWithParam<LCDTextTestParam> { 5649 public testing::TestWithParam<LCDTextTestParam> {
5651 protected: 5650 protected:
5652 virtual void SetUp() { 5651 virtual void SetUp() {
5653 can_use_lcd_text_ = std::tr1::get<0>(GetParam()); 5652 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
5653 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
5654 5654
5655 root_ = Layer::Create(); 5655 root_ = Layer::Create();
5656 child_ = Layer::Create(); 5656 child_ = Layer::Create();
5657 grand_child_ = Layer::Create(); 5657 grand_child_ = Layer::Create();
5658 child_->AddChild(grand_child_.get()); 5658 child_->AddChild(grand_child_.get());
5659 root_->AddChild(child_.get()); 5659 root_->AddChild(child_.get());
5660 5660
5661 root_->SetContentsOpaque(true);
5662 child_->SetContentsOpaque(true);
5663 grand_child_->SetContentsOpaque(true);
5664
5661 gfx::Transform identity_matrix; 5665 gfx::Transform identity_matrix;
5662 SetLayerPropertiesForTesting(root_.get(), 5666 SetLayerPropertiesForTesting(root_.get(),
5663 identity_matrix, 5667 identity_matrix,
5664 gfx::Point3F(), 5668 gfx::Point3F(),
5665 gfx::PointF(), 5669 gfx::PointF(),
5666 gfx::Size(1, 1), 5670 gfx::Size(1, 1),
5667 true, 5671 true,
5668 false); 5672 false);
5669 SetLayerPropertiesForTesting(child_.get(), 5673 SetLayerPropertiesForTesting(child_.get(),
5670 identity_matrix, 5674 identity_matrix,
5671 gfx::Point3F(), 5675 gfx::Point3F(),
5672 gfx::PointF(), 5676 gfx::PointF(),
5673 gfx::Size(1, 1), 5677 gfx::Size(1, 1),
5674 true, 5678 true,
5675 false); 5679 false);
5676 SetLayerPropertiesForTesting(grand_child_.get(), 5680 SetLayerPropertiesForTesting(grand_child_.get(),
5677 identity_matrix, 5681 identity_matrix,
5678 gfx::Point3F(), 5682 gfx::Point3F(),
5679 gfx::PointF(), 5683 gfx::PointF(),
5680 gfx::Size(1, 1), 5684 gfx::Size(1, 1),
5681 true, 5685 true,
5682 false); 5686 false);
5683 5687
5684 child_->SetForceRenderSurface(std::tr1::get<1>(GetParam())); 5688 child_->SetForceRenderSurface(std::tr1::get<2>(GetParam()));
5685 5689
5686 host_ = CreateFakeLayerTreeHost(); 5690 host_ = CreateFakeLayerTreeHost();
5687 host_->SetRootLayer(root_); 5691 host_->SetRootLayer(root_);
5688 } 5692 }
5689 5693
5690 bool can_use_lcd_text_; 5694 bool can_use_lcd_text_;
5695 bool layers_always_allowed_lcd_text_;
5691 scoped_ptr<FakeLayerTreeHost> host_; 5696 scoped_ptr<FakeLayerTreeHost> host_;
5692 scoped_refptr<Layer> root_; 5697 scoped_refptr<Layer> root_;
5693 scoped_refptr<Layer> child_; 5698 scoped_refptr<Layer> child_;
5694 scoped_refptr<Layer> grand_child_; 5699 scoped_refptr<Layer> grand_child_;
5695 }; 5700 };
5696 5701
5697 TEST_P(LCDTextTest, CanUseLCDText) { 5702 TEST_P(LCDTextTest, CanUseLCDText) {
5703 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5704 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5705
5698 // Case 1: Identity transform. 5706 // Case 1: Identity transform.
5699 gfx::Transform identity_matrix; 5707 gfx::Transform identity_matrix;
5700 ExecuteCalculateDrawProperties( 5708 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5701 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5709 layers_always_allowed_lcd_text_);
5702 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5710 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5703 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); 5711 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5704 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); 5712 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5705 5713
5706 // Case 2: Integral translation. 5714 // Case 2: Integral translation.
5707 gfx::Transform integral_translation; 5715 gfx::Transform integral_translation;
5708 integral_translation.Translate(1.0, 2.0); 5716 integral_translation.Translate(1.0, 2.0);
5709 child_->SetTransform(integral_translation); 5717 child_->SetTransform(integral_translation);
5710 ExecuteCalculateDrawProperties( 5718 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5711 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5719 layers_always_allowed_lcd_text_);
5712 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5720 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5713 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); 5721 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5714 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); 5722 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5715 5723
5716 // Case 3: Non-integral translation. 5724 // Case 3: Non-integral translation.
5717 gfx::Transform non_integral_translation; 5725 gfx::Transform non_integral_translation;
5718 non_integral_translation.Translate(1.5, 2.5); 5726 non_integral_translation.Translate(1.5, 2.5);
5719 child_->SetTransform(non_integral_translation); 5727 child_->SetTransform(non_integral_translation);
5720 ExecuteCalculateDrawProperties( 5728 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5721 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5729 layers_always_allowed_lcd_text_);
5722 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5730 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5723 EXPECT_FALSE(child_->can_use_lcd_text()); 5731 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5724 EXPECT_FALSE(grand_child_->can_use_lcd_text()); 5732 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5725 5733
5726 // Case 4: Rotation. 5734 // Case 4: Rotation.
5727 gfx::Transform rotation; 5735 gfx::Transform rotation;
5728 rotation.Rotate(10.0); 5736 rotation.Rotate(10.0);
5729 child_->SetTransform(rotation); 5737 child_->SetTransform(rotation);
5730 ExecuteCalculateDrawProperties( 5738 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5731 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5739 layers_always_allowed_lcd_text_);
5732 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5740 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5733 EXPECT_FALSE(child_->can_use_lcd_text()); 5741 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5734 EXPECT_FALSE(grand_child_->can_use_lcd_text()); 5742 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5735 5743
5736 // Case 5: Scale. 5744 // Case 5: Scale.
5737 gfx::Transform scale; 5745 gfx::Transform scale;
5738 scale.Scale(2.0, 2.0); 5746 scale.Scale(2.0, 2.0);
5739 child_->SetTransform(scale); 5747 child_->SetTransform(scale);
5740 ExecuteCalculateDrawProperties( 5748 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5741 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5749 layers_always_allowed_lcd_text_);
5742 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5750 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5743 EXPECT_FALSE(child_->can_use_lcd_text()); 5751 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5744 EXPECT_FALSE(grand_child_->can_use_lcd_text()); 5752 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5745 5753
5746 // Case 6: Skew. 5754 // Case 6: Skew.
5747 gfx::Transform skew; 5755 gfx::Transform skew;
5748 skew.SkewX(10.0); 5756 skew.SkewX(10.0);
5749 child_->SetTransform(skew); 5757 child_->SetTransform(skew);
5750 ExecuteCalculateDrawProperties( 5758 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5751 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5759 layers_always_allowed_lcd_text_);
5752 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5760 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5753 EXPECT_FALSE(child_->can_use_lcd_text()); 5761 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5754 EXPECT_FALSE(grand_child_->can_use_lcd_text()); 5762 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5755 5763
5756 // Case 7: Translucent. 5764 // Case 7: Translucent.
5757 child_->SetTransform(identity_matrix); 5765 child_->SetTransform(identity_matrix);
5758 child_->SetOpacity(0.5f); 5766 child_->SetOpacity(0.5f);
5759 ExecuteCalculateDrawProperties( 5767 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5760 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5768 layers_always_allowed_lcd_text_);
5761 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5769 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5762 EXPECT_FALSE(child_->can_use_lcd_text()); 5770 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5763 EXPECT_FALSE(grand_child_->can_use_lcd_text()); 5771 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5764 5772
5765 // Case 8: Sanity check: restore transform and opacity. 5773 // Case 8: Sanity check: restore transform and opacity.
5766 child_->SetTransform(identity_matrix); 5774 child_->SetTransform(identity_matrix);
5767 child_->SetOpacity(1.f); 5775 child_->SetOpacity(1.f);
5768 ExecuteCalculateDrawProperties( 5776 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5769 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5777 layers_always_allowed_lcd_text_);
5770 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5778 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5771 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); 5779 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5772 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); 5780 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5781
5782 // Case 9: Non-opaque content.
5783 child_->SetContentsOpaque(false);
5784 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5785 layers_always_allowed_lcd_text_);
5786 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5787 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5788 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5789
5790 // Case 10: Sanity check: restore content opaqueness.
5791 child_->SetContentsOpaque(true);
5792 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5793 layers_always_allowed_lcd_text_);
5794 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5795 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5796 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5773 } 5797 }
5774 5798
5775 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { 5799 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
5800 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5801
5776 // Sanity check: Make sure can_use_lcd_text_ is set on each node. 5802 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
5777 ExecuteCalculateDrawProperties( 5803 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5778 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5804 layers_always_allowed_lcd_text_);
5779 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5805 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5780 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); 5806 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5781 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); 5807 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5782 5808
5783 // Add opacity animation. 5809 // Add opacity animation.
5784 child_->SetOpacity(0.9f); 5810 child_->SetOpacity(0.9f);
5785 AddOpacityTransitionToController( 5811 AddOpacityTransitionToController(
5786 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); 5812 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
5787 5813
5788 ExecuteCalculateDrawProperties( 5814 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5789 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5815 layers_always_allowed_lcd_text_);
5790 // Text AA should not be adjusted while animation is active. 5816 // Text AA should not be adjusted while animation is active.
5791 // Make sure LCD text AA setting remains unchanged. 5817 // Make sure LCD text AA setting remains unchanged.
5792 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5818 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5793 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); 5819 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5794 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); 5820 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5795 } 5821 }
5796 5822
5797 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, 5823 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5798 LCDTextTest, 5824 LCDTextTest,
5799 testing::Combine(testing::Bool(), testing::Bool())); 5825 testing::Combine(testing::Bool(),
5826 testing::Bool(),
5827 testing::Bool()));
5800 5828
5801 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { 5829 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
5802 FakeImplProxy proxy; 5830 FakeImplProxy proxy;
5803 TestSharedBitmapManager shared_bitmap_manager; 5831 TestSharedBitmapManager shared_bitmap_manager;
5804 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); 5832 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
5805 host_impl.CreatePendingTree(); 5833 host_impl.CreatePendingTree();
5806 const gfx::Transform identity_matrix; 5834 const gfx::Transform identity_matrix;
5807 5835
5808 scoped_refptr<Layer> root = Layer::Create(); 5836 scoped_refptr<Layer> root = Layer::Create();
5809 SetLayerPropertiesForTesting(root.get(), 5837 SetLayerPropertiesForTesting(root.get(),
(...skipping 2777 matching lines...) Expand 10 before | Expand all | Expand 10 after
8587 // by the viewport. 8615 // by the viewport.
8588 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); 8616 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect());
8589 8617
8590 // Layers drawing to a child render surface should still have their visible 8618 // Layers drawing to a child render surface should still have their visible
8591 // content rect clipped by the viewport. 8619 // content rect clipped by the viewport.
8592 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); 8620 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect());
8593 } 8621 }
8594 8622
8595 } // namespace 8623 } // namespace
8596 } // namespace cc 8624 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_common_perftest.cc ('k') | cc/trees/layer_tree_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698