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

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

Issue 913203006: cc: Calculate "can use lcd text" on the compositor thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months 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 #include <tuple>
9 10
10 #include "cc/animation/layer_animation_controller.h" 11 #include "cc/animation/layer_animation_controller.h"
11 #include "cc/animation/transform_operations.h" 12 #include "cc/animation/transform_operations.h"
12 #include "cc/base/math_util.h" 13 #include "cc/base/math_util.h"
13 #include "cc/layers/content_layer.h" 14 #include "cc/layers/content_layer.h"
14 #include "cc/layers/content_layer_client.h" 15 #include "cc/layers/content_layer_client.h"
15 #include "cc/layers/layer.h" 16 #include "cc/layers/layer.h"
16 #include "cc/layers/layer_client.h" 17 #include "cc/layers/layer_client.h"
17 #include "cc/layers/layer_impl.h" 18 #include "cc/layers/layer_impl.h"
18 #include "cc/layers/layer_iterator.h" 19 #include "cc/layers/layer_iterator.h"
(...skipping 5651 matching lines...) Expand 10 before | Expand all | Expand 10 after
5670 // We should have one render surface and two layers. The child 5671 // We should have one render surface and two layers. The child
5671 // layer should be included even though it is transparent. 5672 // layer should be included even though it is transparent.
5672 ASSERT_EQ(1u, render_surface_layer_list.size()); 5673 ASSERT_EQ(1u, render_surface_layer_list.size());
5673 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); 5674 ASSERT_EQ(2u, root->render_surface()->layer_list().size());
5674 } 5675 }
5675 5676
5676 using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; 5677 using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>;
5677 class LCDTextTest 5678 class LCDTextTest
5678 : public LayerTreeHostCommonTestBase, 5679 : public LayerTreeHostCommonTestBase,
5679 public testing::TestWithParam<LCDTextTestParam> { 5680 public testing::TestWithParam<LCDTextTestParam> {
5681 public:
5682 LCDTextTest()
5683 : host_impl_(&proxy_, &shared_bitmap_manager_),
5684 root_(nullptr),
5685 child_(nullptr),
5686 grand_child_(nullptr) {}
5687
5680 protected: 5688 protected:
5681 void SetUp() override { 5689 void SetUp() override {
5682 can_use_lcd_text_ = std::tr1::get<0>(GetParam()); 5690 can_use_lcd_text_ = std::tr1::get<0>(GetParam());
5683 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam()); 5691 layers_always_allowed_lcd_text_ = std::tr1::get<1>(GetParam());
5684 5692
5685 root_ = Layer::Create(); 5693 scoped_ptr<LayerImpl> root_ptr =
5686 child_ = Layer::Create(); 5694 LayerImpl::Create(host_impl_.active_tree(), 1);
5687 grand_child_ = Layer::Create(); 5695 scoped_ptr<LayerImpl> child_ptr =
5688 child_->AddChild(grand_child_.get()); 5696 LayerImpl::Create(host_impl_.active_tree(), 2);
5689 root_->AddChild(child_.get()); 5697 scoped_ptr<LayerImpl> grand_child_ptr =
5698 LayerImpl::Create(host_impl_.active_tree(), 3);
5699
5700 // Stash raw pointers to look at later.
5701 root_ = root_ptr.get();
5702 child_ = child_ptr.get();
5703 grand_child_ = grand_child_ptr.get();
5704
5705 child_->AddChild(grand_child_ptr.Pass());
5706 root_->AddChild(child_ptr.Pass());
5707 host_impl_.active_tree()->SetRootLayer(root_ptr.Pass());
5690 5708
5691 root_->SetContentsOpaque(true); 5709 root_->SetContentsOpaque(true);
5692 child_->SetContentsOpaque(true); 5710 child_->SetContentsOpaque(true);
5693 grand_child_->SetContentsOpaque(true); 5711 grand_child_->SetContentsOpaque(true);
5694 5712
5695 gfx::Transform identity_matrix; 5713 gfx::Transform identity_matrix;
5696 SetLayerPropertiesForTesting(root_.get(), 5714 SetLayerPropertiesForTesting(root_, identity_matrix, gfx::Point3F(),
5697 identity_matrix, 5715 gfx::PointF(), gfx::Size(1, 1), true, false,
5698 gfx::Point3F(), 5716 true);
5699 gfx::PointF(), 5717 SetLayerPropertiesForTesting(child_, identity_matrix, gfx::Point3F(),
5700 gfx::Size(1, 1), 5718 gfx::PointF(), gfx::Size(1, 1), true, false,
5701 true, 5719 std::tr1::get<2>(GetParam()));
5720 SetLayerPropertiesForTesting(grand_child_, identity_matrix, gfx::Point3F(),
5721 gfx::PointF(), gfx::Size(1, 1), true, false,
5702 false); 5722 false);
5703 SetLayerPropertiesForTesting(child_.get(),
5704 identity_matrix,
5705 gfx::Point3F(),
5706 gfx::PointF(),
5707 gfx::Size(1, 1),
5708 true,
5709 false);
5710 SetLayerPropertiesForTesting(grand_child_.get(),
5711 identity_matrix,
5712 gfx::Point3F(),
5713 gfx::PointF(),
5714 gfx::Size(1, 1),
5715 true,
5716 false);
5717
5718 child_->SetForceRenderSurface(std::tr1::get<2>(GetParam()));
5719
5720 host_ = CreateFakeLayerTreeHost();
5721 host_->SetRootLayer(root_);
5722 } 5723 }
5723 5724
5724 bool can_use_lcd_text_; 5725 bool can_use_lcd_text_;
5725 bool layers_always_allowed_lcd_text_; 5726 bool layers_always_allowed_lcd_text_;
5726 scoped_ptr<FakeLayerTreeHost> host_; 5727
5727 scoped_refptr<Layer> root_; 5728 FakeImplProxy proxy_;
5728 scoped_refptr<Layer> child_; 5729 TestSharedBitmapManager shared_bitmap_manager_;
5729 scoped_refptr<Layer> grand_child_; 5730 FakeLayerTreeHostImpl host_impl_;
5731
5732 LayerImpl* root_;
5733 LayerImpl* child_;
5734 LayerImpl* grand_child_;
5730 }; 5735 };
5731 5736
5732 TEST_P(LCDTextTest, CanUseLCDText) { 5737 TEST_P(LCDTextTest, CanUseLCDText) {
5733 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; 5738 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5734 bool expect_not_lcd_text = layers_always_allowed_lcd_text_; 5739 bool expect_not_lcd_text = layers_always_allowed_lcd_text_;
5735 5740
5736 // Case 1: Identity transform. 5741 // Case 1: Identity transform.
5737 gfx::Transform identity_matrix; 5742 gfx::Transform identity_matrix;
5738 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, 5743 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5739 layers_always_allowed_lcd_text_); 5744 layers_always_allowed_lcd_text_);
5740 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); 5745 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5741 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); 5746 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5742 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); 5747 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5743 5748
5744 // Case 2: Integral translation. 5749 // Case 2: Integral translation.
5745 gfx::Transform integral_translation; 5750 gfx::Transform integral_translation;
5746 integral_translation.Translate(1.0, 2.0); 5751 integral_translation.Translate(1.0, 2.0);
5747 child_->SetTransform(integral_translation); 5752 child_->SetTransform(integral_translation);
5748 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, 5753 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5749 layers_always_allowed_lcd_text_); 5754 layers_always_allowed_lcd_text_);
5750 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); 5755 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5751 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); 5756 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5752 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); 5757 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5753 5758
5754 // Case 3: Non-integral translation. 5759 // Case 3: Non-integral translation.
5755 gfx::Transform non_integral_translation; 5760 gfx::Transform non_integral_translation;
5756 non_integral_translation.Translate(1.5, 2.5); 5761 non_integral_translation.Translate(1.5, 2.5);
5757 child_->SetTransform(non_integral_translation); 5762 child_->SetTransform(non_integral_translation);
5758 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, 5763 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5759 layers_always_allowed_lcd_text_); 5764 layers_always_allowed_lcd_text_);
5760 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); 5765 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5761 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); 5766 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5762 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); 5767 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5763 5768
5764 // Case 4: Rotation. 5769 // Case 4: Rotation.
5765 gfx::Transform rotation; 5770 gfx::Transform rotation;
5766 rotation.Rotate(10.0); 5771 rotation.Rotate(10.0);
5767 child_->SetTransform(rotation); 5772 child_->SetTransform(rotation);
5768 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, 5773 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5769 layers_always_allowed_lcd_text_); 5774 layers_always_allowed_lcd_text_);
5770 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); 5775 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5771 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); 5776 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5772 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); 5777 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5773 5778
5774 // Case 5: Scale. 5779 // Case 5: Scale.
5775 gfx::Transform scale; 5780 gfx::Transform scale;
5776 scale.Scale(2.0, 2.0); 5781 scale.Scale(2.0, 2.0);
5777 child_->SetTransform(scale); 5782 child_->SetTransform(scale);
5778 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, 5783 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5779 layers_always_allowed_lcd_text_); 5784 layers_always_allowed_lcd_text_);
5780 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); 5785 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5781 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); 5786 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5782 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); 5787 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5783 5788
5784 // Case 6: Skew. 5789 // Case 6: Skew.
5785 gfx::Transform skew; 5790 gfx::Transform skew;
5786 skew.SkewX(10.0); 5791 skew.SkewX(10.0);
5787 child_->SetTransform(skew); 5792 child_->SetTransform(skew);
5788 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, 5793 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5789 layers_always_allowed_lcd_text_); 5794 layers_always_allowed_lcd_text_);
5790 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); 5795 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5791 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); 5796 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5792 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); 5797 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5793 5798
5794 // Case 7: Translucent. 5799 // Case 7: Translucent.
5795 child_->SetTransform(identity_matrix); 5800 child_->SetTransform(identity_matrix);
5796 child_->SetOpacity(0.5f); 5801 child_->SetOpacity(0.5f);
5797 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, 5802 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5798 layers_always_allowed_lcd_text_); 5803 layers_always_allowed_lcd_text_);
5799 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); 5804 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5800 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); 5805 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5801 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); 5806 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text());
5802 5807
5803 // Case 8: Sanity check: restore transform and opacity. 5808 // Case 8: Sanity check: restore transform and opacity.
5804 child_->SetTransform(identity_matrix); 5809 child_->SetTransform(identity_matrix);
5805 child_->SetOpacity(1.f); 5810 child_->SetOpacity(1.f);
5806 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, 5811 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5807 layers_always_allowed_lcd_text_); 5812 layers_always_allowed_lcd_text_);
5808 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); 5813 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5809 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); 5814 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5810 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); 5815 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5811 5816
5812 // Case 9: Non-opaque content. 5817 // Case 9: Non-opaque content.
5813 child_->SetContentsOpaque(false); 5818 child_->SetContentsOpaque(false);
5814 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, 5819 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5815 layers_always_allowed_lcd_text_); 5820 layers_always_allowed_lcd_text_);
5816 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); 5821 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5817 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); 5822 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text());
5818 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); 5823 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5819 5824
5820 // Case 10: Sanity check: restore content opaqueness. 5825 // Case 10: Sanity check: restore content opaqueness.
5821 child_->SetContentsOpaque(true); 5826 child_->SetContentsOpaque(true);
5822 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, 5827 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5823 layers_always_allowed_lcd_text_); 5828 layers_always_allowed_lcd_text_);
5824 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); 5829 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5825 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); 5830 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5826 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); 5831 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5827 } 5832 }
5828 5833
5829 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { 5834 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) {
5830 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; 5835 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_;
5831 5836
5832 // Sanity check: Make sure can_use_lcd_text_ is set on each node. 5837 // Sanity check: Make sure can_use_lcd_text_ is set on each node.
5833 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, 5838 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5834 layers_always_allowed_lcd_text_); 5839 layers_always_allowed_lcd_text_);
5835 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); 5840 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5836 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); 5841 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5837 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); 5842 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5838 5843
5839 // Add opacity animation. 5844 // Add opacity animation.
5840 child_->SetOpacity(0.9f); 5845 child_->SetOpacity(0.9f);
5841 AddOpacityTransitionToController( 5846 AddOpacityTransitionToController(
5842 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); 5847 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false);
5843 5848
5844 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, 5849 ExecuteCalculateDrawProperties(root_, 1.f, 1.f, NULL, can_use_lcd_text_,
5845 layers_always_allowed_lcd_text_); 5850 layers_always_allowed_lcd_text_);
5846 // Text AA should not be adjusted while animation is active. 5851 // Text AA should not be adjusted while animation is active.
5847 // Make sure LCD text AA setting remains unchanged. 5852 // Make sure LCD text AA setting remains unchanged.
5848 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); 5853 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text());
5849 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); 5854 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text());
5850 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); 5855 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text());
5851 } 5856 }
5852 5857
5853 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, 5858 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest,
5854 LCDTextTest, 5859 LCDTextTest,
(...skipping 2811 matching lines...) Expand 10 before | Expand all | Expand 10 after
8666 8671
8667 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 8672 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
8668 8673
8669 gfx::Rect affected_by_delta(0, 0, root_size.width(), 8674 gfx::Rect affected_by_delta(0, 0, root_size.width(),
8670 root_size.height() + 50); 8675 root_size.height() + 50);
8671 EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect()); 8676 EXPECT_EQ(affected_by_delta, sublayer->visible_content_rect());
8672 } 8677 }
8673 8678
8674 } // namespace 8679 } // namespace
8675 } // namespace cc 8680 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698