| OLD | NEW |
| 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 Loading... |
| 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 {} |
| 62 bool FillsBoundsCompletely() const override { return false; } | 63 bool FillsBoundsCompletely() const override { return false; } |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer( | 66 scoped_refptr<FakePictureLayer> CreateDrawablePictureLayer( |
| 66 ContentLayerClient* delegate) { | 67 ContentLayerClient* delegate) { |
| 67 scoped_refptr<FakePictureLayer> to_return = | 68 scoped_refptr<FakePictureLayer> to_return = |
| 68 FakePictureLayer::Create(delegate); | 69 FakePictureLayer::Create(delegate); |
| 69 to_return->SetIsDrawable(true); | 70 to_return->SetIsDrawable(true); |
| 70 return to_return; | 71 return to_return; |
| 71 } | 72 } |
| (...skipping 5564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5636 root.get(), root->bounds(), &render_surface_layer_list); | 5637 root.get(), root->bounds(), &render_surface_layer_list); |
| 5637 inputs.can_adjust_raster_scales = true; | 5638 inputs.can_adjust_raster_scales = true; |
| 5638 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 5639 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 5639 | 5640 |
| 5640 // We should have one render surface and two layers. The child | 5641 // We should have one render surface and two layers. The child |
| 5641 // layer should be included even though it is transparent. | 5642 // layer should be included even though it is transparent. |
| 5642 ASSERT_EQ(1u, render_surface_layer_list.size()); | 5643 ASSERT_EQ(1u, render_surface_layer_list.size()); |
| 5643 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); | 5644 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 5644 } | 5645 } |
| 5645 | 5646 |
| 5646 using LCDTextTestParam = std::tr1::tuple<bool, bool, bool>; | 5647 typedef std::tr1::tuple<bool, bool> LCDTextTestParam; |
| 5647 class LCDTextTest | 5648 class LCDTextTest |
| 5648 : public LayerTreeHostCommonTestBase, | 5649 : public LayerTreeHostCommonTestBase, |
| 5649 public testing::TestWithParam<LCDTextTestParam> { | 5650 public testing::TestWithParam<LCDTextTestParam> { |
| 5650 protected: | 5651 protected: |
| 5651 virtual void SetUp() { | 5652 virtual void SetUp() { |
| 5652 can_use_lcd_text_ = std::tr1::get<0>(GetParam()); | 5653 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 Loading... |
| 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<2>(GetParam())); | 5684 child_->SetForceRenderSurface(std::tr1::get<1>(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_; | |
| 5692 scoped_ptr<FakeLayerTreeHost> host_; | 5691 scoped_ptr<FakeLayerTreeHost> host_; |
| 5693 scoped_refptr<Layer> root_; | 5692 scoped_refptr<Layer> root_; |
| 5694 scoped_refptr<Layer> child_; | 5693 scoped_refptr<Layer> child_; |
| 5695 scoped_refptr<Layer> grand_child_; | 5694 scoped_refptr<Layer> grand_child_; |
| 5696 }; | 5695 }; |
| 5697 | 5696 |
| 5698 TEST_P(LCDTextTest, CanUseLCDText) { | 5697 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 | |
| 5702 // Case 1: Identity transform. | 5698 // Case 1: Identity transform. |
| 5703 gfx::Transform identity_matrix; | 5699 gfx::Transform identity_matrix; |
| 5704 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, | 5700 ExecuteCalculateDrawProperties( |
| 5705 layers_always_allowed_lcd_text_); | 5701 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
| 5706 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | 5702 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5707 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); | 5703 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 5708 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); | 5704 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
| 5709 | 5705 |
| 5710 // Case 2: Integral translation. | 5706 // Case 2: Integral translation. |
| 5711 gfx::Transform integral_translation; | 5707 gfx::Transform integral_translation; |
| 5712 integral_translation.Translate(1.0, 2.0); | 5708 integral_translation.Translate(1.0, 2.0); |
| 5713 child_->SetTransform(integral_translation); | 5709 child_->SetTransform(integral_translation); |
| 5714 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, | 5710 ExecuteCalculateDrawProperties( |
| 5715 layers_always_allowed_lcd_text_); | 5711 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
| 5716 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | 5712 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5717 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); | 5713 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 5718 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); | 5714 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
| 5719 | 5715 |
| 5720 // Case 3: Non-integral translation. | 5716 // Case 3: Non-integral translation. |
| 5721 gfx::Transform non_integral_translation; | 5717 gfx::Transform non_integral_translation; |
| 5722 non_integral_translation.Translate(1.5, 2.5); | 5718 non_integral_translation.Translate(1.5, 2.5); |
| 5723 child_->SetTransform(non_integral_translation); | 5719 child_->SetTransform(non_integral_translation); |
| 5724 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, | 5720 ExecuteCalculateDrawProperties( |
| 5725 layers_always_allowed_lcd_text_); | 5721 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
| 5726 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | 5722 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5727 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); | 5723 EXPECT_FALSE(child_->can_use_lcd_text()); |
| 5728 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); | 5724 EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
| 5729 | 5725 |
| 5730 // Case 4: Rotation. | 5726 // Case 4: Rotation. |
| 5731 gfx::Transform rotation; | 5727 gfx::Transform rotation; |
| 5732 rotation.Rotate(10.0); | 5728 rotation.Rotate(10.0); |
| 5733 child_->SetTransform(rotation); | 5729 child_->SetTransform(rotation); |
| 5734 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, | 5730 ExecuteCalculateDrawProperties( |
| 5735 layers_always_allowed_lcd_text_); | 5731 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
| 5736 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | 5732 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5737 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); | 5733 EXPECT_FALSE(child_->can_use_lcd_text()); |
| 5738 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); | 5734 EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
| 5739 | 5735 |
| 5740 // Case 5: Scale. | 5736 // Case 5: Scale. |
| 5741 gfx::Transform scale; | 5737 gfx::Transform scale; |
| 5742 scale.Scale(2.0, 2.0); | 5738 scale.Scale(2.0, 2.0); |
| 5743 child_->SetTransform(scale); | 5739 child_->SetTransform(scale); |
| 5744 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, | 5740 ExecuteCalculateDrawProperties( |
| 5745 layers_always_allowed_lcd_text_); | 5741 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
| 5746 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | 5742 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5747 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); | 5743 EXPECT_FALSE(child_->can_use_lcd_text()); |
| 5748 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); | 5744 EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
| 5749 | 5745 |
| 5750 // Case 6: Skew. | 5746 // Case 6: Skew. |
| 5751 gfx::Transform skew; | 5747 gfx::Transform skew; |
| 5752 skew.SkewX(10.0); | 5748 skew.SkewX(10.0); |
| 5753 child_->SetTransform(skew); | 5749 child_->SetTransform(skew); |
| 5754 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, | 5750 ExecuteCalculateDrawProperties( |
| 5755 layers_always_allowed_lcd_text_); | 5751 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
| 5756 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | 5752 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5757 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); | 5753 EXPECT_FALSE(child_->can_use_lcd_text()); |
| 5758 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); | 5754 EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
| 5759 | 5755 |
| 5760 // Case 7: Translucent. | 5756 // Case 7: Translucent. |
| 5761 child_->SetTransform(identity_matrix); | 5757 child_->SetTransform(identity_matrix); |
| 5762 child_->SetOpacity(0.5f); | 5758 child_->SetOpacity(0.5f); |
| 5763 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, | 5759 ExecuteCalculateDrawProperties( |
| 5764 layers_always_allowed_lcd_text_); | 5760 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
| 5765 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | 5761 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5766 EXPECT_EQ(expect_not_lcd_text, child_->can_use_lcd_text()); | 5762 EXPECT_FALSE(child_->can_use_lcd_text()); |
| 5767 EXPECT_EQ(expect_not_lcd_text, grand_child_->can_use_lcd_text()); | 5763 EXPECT_FALSE(grand_child_->can_use_lcd_text()); |
| 5768 | 5764 |
| 5769 // Case 8: Sanity check: restore transform and opacity. | 5765 // Case 8: Sanity check: restore transform and opacity. |
| 5770 child_->SetTransform(identity_matrix); | 5766 child_->SetTransform(identity_matrix); |
| 5771 child_->SetOpacity(1.f); | 5767 child_->SetOpacity(1.f); |
| 5772 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, | 5768 ExecuteCalculateDrawProperties( |
| 5773 layers_always_allowed_lcd_text_); | 5769 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
| 5774 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | 5770 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5775 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); | 5771 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 5776 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); | 5772 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
| 5777 } | 5773 } |
| 5778 | 5774 |
| 5779 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { | 5775 TEST_P(LCDTextTest, CanUseLCDTextWithAnimation) { |
| 5780 bool expect_lcd_text = can_use_lcd_text_ || layers_always_allowed_lcd_text_; | |
| 5781 | |
| 5782 // Sanity check: Make sure can_use_lcd_text_ is set on each node. | 5776 // Sanity check: Make sure can_use_lcd_text_ is set on each node. |
| 5783 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, | 5777 ExecuteCalculateDrawProperties( |
| 5784 layers_always_allowed_lcd_text_); | 5778 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
| 5785 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | 5779 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5786 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); | 5780 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 5787 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); | 5781 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
| 5788 | 5782 |
| 5789 // Add opacity animation. | 5783 // Add opacity animation. |
| 5790 child_->SetOpacity(0.9f); | 5784 child_->SetOpacity(0.9f); |
| 5791 AddOpacityTransitionToController( | 5785 AddOpacityTransitionToController( |
| 5792 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); | 5786 child_->layer_animation_controller(), 10.0, 0.9f, 0.1f, false); |
| 5793 | 5787 |
| 5794 ExecuteCalculateDrawProperties(root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_, | 5788 ExecuteCalculateDrawProperties( |
| 5795 layers_always_allowed_lcd_text_); | 5789 root_.get(), 1.f, 1.f, NULL, can_use_lcd_text_); |
| 5796 // Text AA should not be adjusted while animation is active. | 5790 // Text AA should not be adjusted while animation is active. |
| 5797 // Make sure LCD text AA setting remains unchanged. | 5791 // Make sure LCD text AA setting remains unchanged. |
| 5798 EXPECT_EQ(expect_lcd_text, root_->can_use_lcd_text()); | 5792 EXPECT_EQ(can_use_lcd_text_, root_->can_use_lcd_text()); |
| 5799 EXPECT_EQ(expect_lcd_text, child_->can_use_lcd_text()); | 5793 EXPECT_EQ(can_use_lcd_text_, child_->can_use_lcd_text()); |
| 5800 EXPECT_EQ(expect_lcd_text, grand_child_->can_use_lcd_text()); | 5794 EXPECT_EQ(can_use_lcd_text_, grand_child_->can_use_lcd_text()); |
| 5801 } | 5795 } |
| 5802 | 5796 |
| 5803 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, | 5797 INSTANTIATE_TEST_CASE_P(LayerTreeHostCommonTest, |
| 5804 LCDTextTest, | 5798 LCDTextTest, |
| 5805 testing::Combine(testing::Bool(), | 5799 testing::Combine(testing::Bool(), testing::Bool())); |
| 5806 testing::Bool(), | |
| 5807 testing::Bool())); | |
| 5808 | 5800 |
| 5809 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { | 5801 TEST_F(LayerTreeHostCommonTest, SubtreeHidden_SingleLayer) { |
| 5810 FakeImplProxy proxy; | 5802 FakeImplProxy proxy; |
| 5811 TestSharedBitmapManager shared_bitmap_manager; | 5803 TestSharedBitmapManager shared_bitmap_manager; |
| 5812 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); | 5804 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 5813 host_impl.CreatePendingTree(); | 5805 host_impl.CreatePendingTree(); |
| 5814 const gfx::Transform identity_matrix; | 5806 const gfx::Transform identity_matrix; |
| 5815 | 5807 |
| 5816 scoped_refptr<Layer> root = Layer::Create(); | 5808 scoped_refptr<Layer> root = Layer::Create(); |
| 5817 SetLayerPropertiesForTesting(root.get(), | 5809 SetLayerPropertiesForTesting(root.get(), |
| (...skipping 2777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8595 // by the viewport. | 8587 // by the viewport. |
| 8596 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); | 8588 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_content_rect()); |
| 8597 | 8589 |
| 8598 // Layers drawing to a child render surface should still have their visible | 8590 // Layers drawing to a child render surface should still have their visible |
| 8599 // content rect clipped by the viewport. | 8591 // content rect clipped by the viewport. |
| 8600 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); | 8592 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_content_rect()); |
| 8601 } | 8593 } |
| 8602 | 8594 |
| 8603 } // namespace | 8595 } // namespace |
| 8604 } // namespace cc | 8596 } // namespace cc |
| OLD | NEW |