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

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

Issue 684543006: cc: Toggle LCD text at raster time instead of record time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lcdraster: initvar 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
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 gfx::Transform identity_matrix; 5661 gfx::Transform identity_matrix;
5662 SetLayerPropertiesForTesting(root_.get(), 5662 SetLayerPropertiesForTesting(root_.get(),
5663 identity_matrix, 5663 identity_matrix,
(...skipping 10 matching lines...) Expand all
5674 true, 5674 true,
5675 false); 5675 false);
5676 SetLayerPropertiesForTesting(grand_child_.get(), 5676 SetLayerPropertiesForTesting(grand_child_.get(),
5677 identity_matrix, 5677 identity_matrix,
5678 gfx::Point3F(), 5678 gfx::Point3F(),
5679 gfx::PointF(), 5679 gfx::PointF(),
5680 gfx::Size(1, 1), 5680 gfx::Size(1, 1),
5681 true, 5681 true,
5682 false); 5682 false);
5683 5683
5684 child_->SetForceRenderSurface(std::tr1::get<1>(GetParam())); 5684 child_->SetForceRenderSurface(std::tr1::get<2>(GetParam()));
5685 5685
5686 host_ = CreateFakeLayerTreeHost(); 5686 host_ = CreateFakeLayerTreeHost();
5687 host_->SetRootLayer(root_); 5687 host_->SetRootLayer(root_);
5688 } 5688 }
5689 5689
5690 bool can_use_lcd_text_; 5690 bool can_use_lcd_text_;
5691 bool layers_always_allowed_lcd_text_;
5691 scoped_ptr<FakeLayerTreeHost> host_; 5692 scoped_ptr<FakeLayerTreeHost> host_;
5692 scoped_refptr<Layer> root_; 5693 scoped_refptr<Layer> root_;
5693 scoped_refptr<Layer> child_; 5694 scoped_refptr<Layer> child_;
5694 scoped_refptr<Layer> grand_child_; 5695 scoped_refptr<Layer> grand_child_;
5695 }; 5696 };
5696 5697
5697 TEST_P(LCDTextTest, CanUseLCDText) { 5698 TEST_P(LCDTextTest, CanUseLCDText) {
5699 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5700 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5701
5698 // Case 1: Identity transform. 5702 // Case 1: Identity transform.
5699 gfx::Transform identity_matrix; 5703 gfx::Transform identity_matrix;
5700 ExecuteCalculateDrawProperties( 5704 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5701 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5705 layers_always_allowed_lcd_text_);
5702 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5706 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5703 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); 5707 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5704 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); 5708 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5705 5709
5706 // Case 2: Integral translation. 5710 // Case 2: Integral translation.
5707 gfx::Transform integral_translation; 5711 gfx::Transform integral_translation;
5708 integral_translation.Translate(1.0, 2.0); 5712 integral_translation.Translate(1.0, 2.0);
5709 child_->SetTransform(integral_translation); 5713 child_->SetTransform(integral_translation);
5710 ExecuteCalculateDrawProperties( 5714 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5711 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5715 layers_always_allowed_lcd_text_);
5712 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5716 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5713 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); 5717 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5714 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); 5718 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5715 5719
5716 // Case 3: Non-integral translation. 5720 // Case 3: Non-integral translation.
5717 gfx::Transform non_integral_translation; 5721 gfx::Transform non_integral_translation;
5718 non_integral_translation.Translate(1.5, 2.5); 5722 non_integral_translation.Translate(1.5, 2.5);
5719 child_->SetTransform(non_integral_translation); 5723 child_->SetTransform(non_integral_translation);
5720 ExecuteCalculateDrawProperties( 5724 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5721 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5725 layers_always_allowed_lcd_text_);
5722 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5726 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5723 EXPECT_FALSE(child_->can_use_lcd_text()); 5727 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5724 EXPECT_FALSE(grand_child_->can_use_lcd_text()); 5728 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5725 5729
5726 // Case 4: Rotation. 5730 // Case 4: Rotation.
5727 gfx::Transform rotation; 5731 gfx::Transform rotation;
5728 rotation.Rotate(10.0); 5732 rotation.Rotate(10.0);
5729 child_->SetTransform(rotation); 5733 child_->SetTransform(rotation);
5730 ExecuteCalculateDrawProperties( 5734 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5731 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5735 layers_always_allowed_lcd_text_);
5732 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5736 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5733 EXPECT_FALSE(child_->can_use_lcd_text()); 5737 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5734 EXPECT_FALSE(grand_child_->can_use_lcd_text()); 5738 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5735 5739
5736 // Case 5: Scale. 5740 // Case 5: Scale.
5737 gfx::Transform scale; 5741 gfx::Transform scale;
5738 scale.Scale(2.0, 2.0); 5742 scale.Scale(2.0, 2.0);
5739 child_->SetTransform(scale); 5743 child_->SetTransform(scale);
5740 ExecuteCalculateDrawProperties( 5744 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5741 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5745 layers_always_allowed_lcd_text_);
5742 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5746 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5743 EXPECT_FALSE(child_->can_use_lcd_text()); 5747 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5744 EXPECT_FALSE(grand_child_->can_use_lcd_text()); 5748 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5745 5749
5746 // Case 6: Skew. 5750 // Case 6: Skew.
5747 gfx::Transform skew; 5751 gfx::Transform skew;
5748 skew.SkewX(10.0); 5752 skew.SkewX(10.0);
5749 child_->SetTransform(skew); 5753 child_->SetTransform(skew);
5750 ExecuteCalculateDrawProperties( 5754 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5751 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5755 layers_always_allowed_lcd_text_);
5752 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5756 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5753 EXPECT_FALSE(child_->can_use_lcd_text()); 5757 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5754 EXPECT_FALSE(grand_child_->can_use_lcd_text()); 5758 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5755 5759
5756 // Case 7: Translucent. 5760 // Case 7: Translucent.
5757 child_->SetTransform(identity_matrix); 5761 child_->SetTransform(identity_matrix);
5758 child_->SetOpacity(0.5f); 5762 child_->SetOpacity(0.5f);
5759 ExecuteCalculateDrawProperties( 5763 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5760 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5764 layers_always_allowed_lcd_text_);
5761 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5765 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5762 EXPECT_FALSE(child_->can_use_lcd_text()); 5766 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5763 EXPECT_FALSE(grand_child_->can_use_lcd_text()); 5767 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5764 5768
5765 // Case 8: Sanity check: restore transform and opacity. 5769 // Case 8: Sanity check: restore transform and opacity.
5766 child_->SetTransform(identity_matrix); 5770 child_->SetTransform(identity_matrix);
5767 child_->SetOpacity(1.f); 5771 child_->SetOpacity(1.f);
5768 ExecuteCalculateDrawProperties( 5772 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5769 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5773 layers_always_allowed_lcd_text_);
5770 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5774 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5771 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); 5775 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5772 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); 5776 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5773 } 5777 }
5774 5778
5775 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { 5779 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
5780 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5781
5776 // Sanity check: Make sure can_use_lcd_text_ is set on each node. 5782 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
5777 ExecuteCalculateDrawProperties( 5783 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5778 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5784 layers_always_allowed_lcd_text_);
5779 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5785 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5780 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); 5786 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5781 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); 5787 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5782 5788
5783 // Add opacity animation. 5789 // Add opacity animation.
5784 child_->SetOpacity(0.9f); 5790 child_->SetOpacity(0.9f);
5785 AddOpacityTransitionToController( 5791 AddOpacityTransitionToController(
5786 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); 5792 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
5787 5793
5788 ExecuteCalculateDrawProperties( 5794 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_,
5789 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); 5795 layers_always_allowed_lcd_text_);
5790 // Text AA should not be adjusted while animation is active. 5796 // Text AA should not be adjusted while animation is active.
5791 // Make sure LCD text AA setting remains unchanged. 5797 // Make sure LCD text AA setting remains unchanged.
5792 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); 5798 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5793 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); 5799 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5794 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); 5800 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5795 } 5801 }
5796 5802
5797 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, 5803 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5798 LCDTextTest, 5804 LCDTextTest,
5799 testing::Combine(testing::Bool(), testing::Bool())); 5805 testing::Combine(testing::Bool(),
5806 testing::Bool(),
5807 testing::Bool()));
5800 5808
5801 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { 5809 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) {
5802 FakeImplProxy proxy; 5810 FakeImplProxy proxy;
5803 TestSharedBitmapManager shared_bitmap_manager; 5811 TestSharedBitmapManager shared_bitmap_manager;
5804 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); 5812 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
5805 host_impl.CreatePendingTree(); 5813 host_impl.CreatePendingTree();
5806 const gfx::Transform identity_matrix; 5814 const gfx::Transform identity_matrix;
5807 5815
5808 scoped_refptr<Layer> root = Layer::Create(); 5816 scoped_refptr<Layer> root = Layer::Create();
5809 SetLayerPropertiesForTesting(root.get(), 5817 SetLayerPropertiesForTesting(root.get(),
(...skipping 2777 matching lines...) Expand 10 before | Expand all | Expand 10 after
8587 // by the viewport. 8595 // by the viewport.
8588 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); 8596 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect());
8589 8597
8590 // Layers drawing to a child render surface should still have their visible 8598 // Layers drawing to a child render surface should still have their visible
8591 // content rect clipped by the viewport. 8599 // content rect clipped by the viewport.
8592 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); 8600 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect());
8593 } 8601 }
8594 8602
8595 } // namespace 8603 } // namespace
8596 } // namespace cc 8604 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698