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 <set> | 7 #include <set> |
8 | 8 |
9 #include "cc/animation/layer_animation_controller.h" | 9 #include "cc/animation/layer_animation_controller.h" |
| 10 #include "cc/animation/transform_operations.h" |
10 #include "cc/base/math_util.h" | 11 #include "cc/base/math_util.h" |
11 #include "cc/layers/content_layer.h" | 12 #include "cc/layers/content_layer.h" |
12 #include "cc/layers/content_layer_client.h" | 13 #include "cc/layers/content_layer_client.h" |
13 #include "cc/layers/heads_up_display_layer_impl.h" | 14 #include "cc/layers/heads_up_display_layer_impl.h" |
14 #include "cc/layers/layer.h" | 15 #include "cc/layers/layer.h" |
15 #include "cc/layers/layer_client.h" | 16 #include "cc/layers/layer_client.h" |
16 #include "cc/layers/layer_impl.h" | 17 #include "cc/layers/layer_impl.h" |
17 #include "cc/layers/render_surface.h" | 18 #include "cc/layers/render_surface.h" |
18 #include "cc/layers/render_surface_impl.h" | 19 #include "cc/layers/render_surface_impl.h" |
19 #include "cc/output/copy_output_request.h" | 20 #include "cc/output/copy_output_request.h" |
(...skipping 5972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5992 | 5993 |
5993 class NoScaleContentLayer : public ContentLayer { | 5994 class NoScaleContentLayer : public ContentLayer { |
5994 public: | 5995 public: |
5995 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { | 5996 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
5996 return make_scoped_refptr(new NoScaleContentLayer(client)); | 5997 return make_scoped_refptr(new NoScaleContentLayer(client)); |
5997 } | 5998 } |
5998 | 5999 |
5999 virtual void CalculateContentsScale(float ideal_contents_scale, | 6000 virtual void CalculateContentsScale(float ideal_contents_scale, |
6000 float device_scale_factor, | 6001 float device_scale_factor, |
6001 float page_scale_factor, | 6002 float page_scale_factor, |
| 6003 float maximum_animation_scale_factor, |
6002 bool animating_transform_to_screen, | 6004 bool animating_transform_to_screen, |
6003 float* contents_scale_x, | 6005 float* contents_scale_x, |
6004 float* contents_scale_y, | 6006 float* contents_scale_y, |
6005 gfx::Size* content_bounds) OVERRIDE { | 6007 gfx::Size* content_bounds) OVERRIDE { |
6006 // Skip over the ContentLayer to the base Layer class. | 6008 // Skip over the ContentLayer to the base Layer class. |
6007 Layer::CalculateContentsScale(ideal_contents_scale, | 6009 Layer::CalculateContentsScale(ideal_contents_scale, |
6008 device_scale_factor, | 6010 device_scale_factor, |
6009 page_scale_factor, | 6011 page_scale_factor, |
| 6012 maximum_animation_scale_factor, |
6010 animating_transform_to_screen, | 6013 animating_transform_to_screen, |
6011 contents_scale_x, | 6014 contents_scale_x, |
6012 contents_scale_y, | 6015 contents_scale_y, |
6013 content_bounds); | 6016 content_bounds); |
6014 } | 6017 } |
6015 | 6018 |
6016 protected: | 6019 protected: |
6017 explicit NoScaleContentLayer(ContentLayerClient* client) | 6020 explicit NoScaleContentLayer(ContentLayerClient* client) |
6018 : ContentLayer(client) {} | 6021 : ContentLayer(client) {} |
6019 virtual ~NoScaleContentLayer() {} | 6022 virtual ~NoScaleContentLayer() {} |
(...skipping 3710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9730 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 9733 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
9731 | 9734 |
9732 EXPECT_VECTOR_EQ( | 9735 EXPECT_VECTOR_EQ( |
9733 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), | 9736 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
9734 container_offset); | 9737 container_offset); |
9735 | 9738 |
9736 scroll_layer->SetTransform(identity_transform); | 9739 scroll_layer->SetTransform(identity_transform); |
9737 } | 9740 } |
9738 } | 9741 } |
9739 | 9742 |
| 9743 class AnimationScaleFactorTrackingLayer : public Layer { |
| 9744 public: |
| 9745 static scoped_refptr<AnimationScaleFactorTrackingLayer> Create() { |
| 9746 return make_scoped_refptr(new AnimationScaleFactorTrackingLayer()); |
| 9747 } |
| 9748 |
| 9749 virtual void CalculateContentsScale(float ideal_contents_scale, |
| 9750 float device_scale_factor, |
| 9751 float page_scale_factor, |
| 9752 float maximum_animation_scale_factor, |
| 9753 bool animating_transform_to_screen, |
| 9754 float* contents_scale_x, |
| 9755 float* contents_scale_y, |
| 9756 gfx::Size* content_bounds) OVERRIDE { |
| 9757 last_maximum_animation_scale_factor_ = maximum_animation_scale_factor; |
| 9758 Layer::CalculateContentsScale(ideal_contents_scale, |
| 9759 device_scale_factor, |
| 9760 page_scale_factor, |
| 9761 maximum_animation_scale_factor, |
| 9762 animating_transform_to_screen, |
| 9763 contents_scale_x, |
| 9764 contents_scale_y, |
| 9765 content_bounds); |
| 9766 } |
| 9767 |
| 9768 float last_maximum_animation_scale_factor() { |
| 9769 return last_maximum_animation_scale_factor_; |
| 9770 } |
| 9771 |
| 9772 virtual bool DrawsContent() const OVERRIDE { return true; } |
| 9773 |
| 9774 private: |
| 9775 AnimationScaleFactorTrackingLayer() |
| 9776 : last_maximum_animation_scale_factor_(0.f) {} |
| 9777 virtual ~AnimationScaleFactorTrackingLayer() {} |
| 9778 |
| 9779 float last_maximum_animation_scale_factor_; |
| 9780 }; |
| 9781 |
| 9782 TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
| 9783 gfx::Transform identity_matrix; |
| 9784 scoped_refptr<AnimationScaleFactorTrackingLayer> grand_parent = |
| 9785 AnimationScaleFactorTrackingLayer::Create(); |
| 9786 scoped_refptr<AnimationScaleFactorTrackingLayer> parent = |
| 9787 AnimationScaleFactorTrackingLayer::Create(); |
| 9788 scoped_refptr<AnimationScaleFactorTrackingLayer> child = |
| 9789 AnimationScaleFactorTrackingLayer::Create(); |
| 9790 scoped_refptr<AnimationScaleFactorTrackingLayer> grand_child = |
| 9791 AnimationScaleFactorTrackingLayer::Create(); |
| 9792 grand_parent->AddChild(parent); |
| 9793 parent->AddChild(child); |
| 9794 child->AddChild(grand_child); |
| 9795 |
| 9796 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 9797 host->SetRootLayer(grand_parent); |
| 9798 |
| 9799 SetLayerPropertiesForTesting(grand_parent.get(), |
| 9800 identity_matrix, |
| 9801 gfx::PointF(), |
| 9802 gfx::PointF(), |
| 9803 gfx::Size(1, 2), |
| 9804 true, |
| 9805 false); |
| 9806 SetLayerPropertiesForTesting(parent.get(), |
| 9807 identity_matrix, |
| 9808 gfx::PointF(), |
| 9809 gfx::PointF(), |
| 9810 gfx::Size(1, 2), |
| 9811 true, |
| 9812 false); |
| 9813 SetLayerPropertiesForTesting(child.get(), |
| 9814 identity_matrix, |
| 9815 gfx::PointF(), |
| 9816 gfx::PointF(), |
| 9817 gfx::Size(1, 2), |
| 9818 true, |
| 9819 false); |
| 9820 SetLayerPropertiesForTesting(grand_child.get(), |
| 9821 identity_matrix, |
| 9822 gfx::PointF(), |
| 9823 gfx::PointF(), |
| 9824 gfx::Size(1, 2), |
| 9825 true, |
| 9826 false); |
| 9827 |
| 9828 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9829 |
| 9830 // No layers have animations. |
| 9831 EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor()); |
| 9832 EXPECT_EQ(1.f, parent->last_maximum_animation_scale_factor()); |
| 9833 EXPECT_EQ(1.f, child->last_maximum_animation_scale_factor()); |
| 9834 EXPECT_EQ(1.f, grand_child->last_maximum_animation_scale_factor()); |
| 9835 |
| 9836 TransformOperations translation; |
| 9837 translation.AppendTranslate(1.f, 2.f, 3.f); |
| 9838 |
| 9839 AddAnimatedTransformToLayer(parent, 1.0, TransformOperations(), translation); |
| 9840 |
| 9841 // No layers have scale-affecting animations. |
| 9842 EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor()); |
| 9843 EXPECT_EQ(1.f, parent->last_maximum_animation_scale_factor()); |
| 9844 EXPECT_EQ(1.f, child->last_maximum_animation_scale_factor()); |
| 9845 EXPECT_EQ(1.f, grand_child->last_maximum_animation_scale_factor()); |
| 9846 |
| 9847 TransformOperations scale; |
| 9848 scale.AppendScale(5.f, 4.f, 3.f); |
| 9849 |
| 9850 AddAnimatedTransformToLayer(child, 1.0, TransformOperations(), scale); |
| 9851 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9852 |
| 9853 // Only |child| has a scale-affecting animation. |
| 9854 EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor()); |
| 9855 EXPECT_EQ(1.f, parent->last_maximum_animation_scale_factor()); |
| 9856 EXPECT_EQ(5.f, child->last_maximum_animation_scale_factor()); |
| 9857 EXPECT_EQ(5.f, grand_child->last_maximum_animation_scale_factor()); |
| 9858 |
| 9859 AddAnimatedTransformToLayer(grand_parent, 1.0, TransformOperations(), scale); |
| 9860 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9861 |
| 9862 // |grand_parent| and |child| have scale-affecting animations. |
| 9863 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_scale_factor()); |
| 9864 EXPECT_EQ(5.f, parent->last_maximum_animation_scale_factor()); |
| 9865 // We don't support combining animated scales from two nodes; 0.f means |
| 9866 // that the maximum scale could not be computed. |
| 9867 EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor()); |
| 9868 EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor()); |
| 9869 |
| 9870 AddAnimatedTransformToLayer(parent, 1.0, TransformOperations(), scale); |
| 9871 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9872 |
| 9873 // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
| 9874 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_scale_factor()); |
| 9875 EXPECT_EQ(0.f, parent->last_maximum_animation_scale_factor()); |
| 9876 EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor()); |
| 9877 EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor()); |
| 9878 |
| 9879 grand_parent->layer_animation_controller()->AbortAnimations( |
| 9880 Animation::Transform); |
| 9881 parent->layer_animation_controller()->AbortAnimations(Animation::Transform); |
| 9882 child->layer_animation_controller()->AbortAnimations(Animation::Transform); |
| 9883 |
| 9884 TransformOperations perspective; |
| 9885 perspective.AppendPerspective(10.f); |
| 9886 |
| 9887 AddAnimatedTransformToLayer(child, 1.0, TransformOperations(), perspective); |
| 9888 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9889 |
| 9890 // |child| has a scale-affecting animation but computing the maximum of this |
| 9891 // animation is not supported. |
| 9892 EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor()); |
| 9893 EXPECT_EQ(1.f, parent->last_maximum_animation_scale_factor()); |
| 9894 EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor()); |
| 9895 EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor()); |
| 9896 |
| 9897 child->layer_animation_controller()->AbortAnimations(Animation::Transform); |
| 9898 |
| 9899 gfx::Transform scale_matrix; |
| 9900 scale_matrix.Scale(1.f, 2.f); |
| 9901 parent->SetTransform(scale_matrix); |
| 9902 AddAnimatedTransformToLayer(parent, 1.0, TransformOperations(), scale); |
| 9903 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9904 |
| 9905 // |parent| has scale 2.f and a scale animation with maximum scale 5.f. |
| 9906 EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor()); |
| 9907 EXPECT_EQ(2.5f, parent->last_maximum_animation_scale_factor()); |
| 9908 EXPECT_EQ(2.5f, child->last_maximum_animation_scale_factor()); |
| 9909 EXPECT_EQ(2.5f, grand_child->last_maximum_animation_scale_factor()); |
| 9910 |
| 9911 gfx::Transform perspective_matrix; |
| 9912 perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 9913 child->SetTransform(perspective_matrix); |
| 9914 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9915 |
| 9916 // |child| has a transform that's neither a translation nor a scale. |
| 9917 EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor()); |
| 9918 EXPECT_EQ(2.5f, parent->last_maximum_animation_scale_factor()); |
| 9919 EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor()); |
| 9920 EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor()); |
| 9921 |
| 9922 parent->SetTransform(perspective_matrix); |
| 9923 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9924 |
| 9925 // |parent| and |child| have transforms that are neither translations nor |
| 9926 // scales. |
| 9927 EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor()); |
| 9928 EXPECT_EQ(0.f, parent->last_maximum_animation_scale_factor()); |
| 9929 EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor()); |
| 9930 EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor()); |
| 9931 |
| 9932 parent->SetTransform(identity_matrix); |
| 9933 child->SetTransform(identity_matrix); |
| 9934 grand_parent->SetTransform(perspective_matrix); |
| 9935 |
| 9936 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9937 |
| 9938 // |grand_parent| has a transform that's neither a translation nor a scale. |
| 9939 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_scale_factor()); |
| 9940 EXPECT_EQ(0.f, parent->last_maximum_animation_scale_factor()); |
| 9941 EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor()); |
| 9942 EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor()); |
| 9943 } |
| 9944 |
9740 } // namespace | 9945 } // namespace |
9741 } // namespace cc | 9946 } // namespace cc |
OLD | NEW |