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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 }; | 181 }; |
181 | 182 |
182 class LayerWithForcedDrawsContent : public Layer { | 183 class LayerWithForcedDrawsContent : public Layer { |
183 public: | 184 public: |
184 LayerWithForcedDrawsContent() : Layer(), last_device_scale_factor_(0.f) {} | 185 LayerWithForcedDrawsContent() : Layer(), last_device_scale_factor_(0.f) {} |
185 | 186 |
186 virtual bool DrawsContent() const OVERRIDE; | 187 virtual bool DrawsContent() const OVERRIDE; |
187 virtual void CalculateContentsScale(float ideal_contents_scale, | 188 virtual void CalculateContentsScale(float ideal_contents_scale, |
188 float device_scale_factor, | 189 float device_scale_factor, |
189 float page_scale_factor, | 190 float page_scale_factor, |
| 191 float maximum_animation_contents_scale, |
190 bool animating_transform_to_screen, | 192 bool animating_transform_to_screen, |
191 float* contents_scale_x, | 193 float* contents_scale_x, |
192 float* contents_scale_y, | 194 float* contents_scale_y, |
193 gfx::Size* content_bounds) OVERRIDE; | 195 gfx::Size* content_bounds) OVERRIDE; |
194 | 196 |
195 float last_device_scale_factor() const { return last_device_scale_factor_; } | 197 float last_device_scale_factor() const { return last_device_scale_factor_; } |
196 | 198 |
197 private: | 199 private: |
198 virtual ~LayerWithForcedDrawsContent() {} | 200 virtual ~LayerWithForcedDrawsContent() {} |
199 | 201 |
200 // Parameters from last CalculateContentsScale. | 202 // Parameters from last CalculateContentsScale. |
201 float last_device_scale_factor_; | 203 float last_device_scale_factor_; |
202 }; | 204 }; |
203 | 205 |
204 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } | 206 bool LayerWithForcedDrawsContent::DrawsContent() const { return true; } |
205 | 207 |
206 void LayerWithForcedDrawsContent::CalculateContentsScale( | 208 void LayerWithForcedDrawsContent::CalculateContentsScale( |
207 float ideal_contents_scale, | 209 float ideal_contents_scale, |
208 float device_scale_factor, | 210 float device_scale_factor, |
209 float page_scale_factor, | 211 float page_scale_factor, |
| 212 float maximum_animation_contents_scale, |
210 bool animating_transform_to_screen, | 213 bool animating_transform_to_screen, |
211 float* contents_scale_x, | 214 float* contents_scale_x, |
212 float* contents_scale_y, | 215 float* contents_scale_y, |
213 gfx::Size* content_bounds) { | 216 gfx::Size* content_bounds) { |
214 last_device_scale_factor_ = device_scale_factor; | 217 last_device_scale_factor_ = device_scale_factor; |
215 Layer::CalculateContentsScale(ideal_contents_scale, | 218 Layer::CalculateContentsScale(ideal_contents_scale, |
216 device_scale_factor, | 219 device_scale_factor, |
217 page_scale_factor, | 220 page_scale_factor, |
| 221 maximum_animation_contents_scale, |
218 animating_transform_to_screen, | 222 animating_transform_to_screen, |
219 contents_scale_x, | 223 contents_scale_x, |
220 contents_scale_y, | 224 contents_scale_y, |
221 content_bounds); | 225 content_bounds); |
222 } | 226 } |
223 | 227 |
224 class MockContentLayerClient : public ContentLayerClient { | 228 class MockContentLayerClient : public ContentLayerClient { |
225 public: | 229 public: |
226 MockContentLayerClient() {} | 230 MockContentLayerClient() {} |
227 virtual ~MockContentLayerClient() {} | 231 virtual ~MockContentLayerClient() {} |
(...skipping 5806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6034 | 6038 |
6035 class NoScaleContentLayer : public ContentLayer { | 6039 class NoScaleContentLayer : public ContentLayer { |
6036 public: | 6040 public: |
6037 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { | 6041 static scoped_refptr<NoScaleContentLayer> Create(ContentLayerClient* client) { |
6038 return make_scoped_refptr(new NoScaleContentLayer(client)); | 6042 return make_scoped_refptr(new NoScaleContentLayer(client)); |
6039 } | 6043 } |
6040 | 6044 |
6041 virtual void CalculateContentsScale(float ideal_contents_scale, | 6045 virtual void CalculateContentsScale(float ideal_contents_scale, |
6042 float device_scale_factor, | 6046 float device_scale_factor, |
6043 float page_scale_factor, | 6047 float page_scale_factor, |
| 6048 float maximum_animation_contents_scale, |
6044 bool animating_transform_to_screen, | 6049 bool animating_transform_to_screen, |
6045 float* contents_scale_x, | 6050 float* contents_scale_x, |
6046 float* contents_scale_y, | 6051 float* contents_scale_y, |
6047 gfx::Size* content_bounds) OVERRIDE { | 6052 gfx::Size* content_bounds) OVERRIDE { |
6048 // Skip over the ContentLayer to the base Layer class. | 6053 // Skip over the ContentLayer to the base Layer class. |
6049 Layer::CalculateContentsScale(ideal_contents_scale, | 6054 Layer::CalculateContentsScale(ideal_contents_scale, |
6050 device_scale_factor, | 6055 device_scale_factor, |
6051 page_scale_factor, | 6056 page_scale_factor, |
| 6057 maximum_animation_contents_scale, |
6052 animating_transform_to_screen, | 6058 animating_transform_to_screen, |
6053 contents_scale_x, | 6059 contents_scale_x, |
6054 contents_scale_y, | 6060 contents_scale_y, |
6055 content_bounds); | 6061 content_bounds); |
6056 } | 6062 } |
6057 | 6063 |
6058 protected: | 6064 protected: |
6059 explicit NoScaleContentLayer(ContentLayerClient* client) | 6065 explicit NoScaleContentLayer(ContentLayerClient* client) |
6060 : ContentLayer(client) {} | 6066 : ContentLayer(client) {} |
6061 virtual ~NoScaleContentLayer() {} | 6067 virtual ~NoScaleContentLayer() {} |
(...skipping 3710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9772 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 9778 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
9773 | 9779 |
9774 EXPECT_VECTOR_EQ( | 9780 EXPECT_VECTOR_EQ( |
9775 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), | 9781 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
9776 container_offset); | 9782 container_offset); |
9777 | 9783 |
9778 scroll_layer->SetTransform(identity_transform); | 9784 scroll_layer->SetTransform(identity_transform); |
9779 } | 9785 } |
9780 } | 9786 } |
9781 | 9787 |
| 9788 class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
| 9789 public: |
| 9790 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
| 9791 LayerTreeImpl* tree_impl, |
| 9792 int id) { |
| 9793 return make_scoped_ptr( |
| 9794 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 9795 } |
| 9796 |
| 9797 virtual ~AnimationScaleFactorTrackingLayerImpl() {} |
| 9798 |
| 9799 virtual void CalculateContentsScale(float ideal_contents_scale, |
| 9800 float device_scale_factor, |
| 9801 float page_scale_factor, |
| 9802 float maximum_animation_contents_scale, |
| 9803 bool animating_transform_to_screen, |
| 9804 float* contents_scale_x, |
| 9805 float* contents_scale_y, |
| 9806 gfx::Size* content_bounds) OVERRIDE { |
| 9807 last_maximum_animation_contents_scale_ = maximum_animation_contents_scale; |
| 9808 LayerImpl::CalculateContentsScale(ideal_contents_scale, |
| 9809 device_scale_factor, |
| 9810 page_scale_factor, |
| 9811 maximum_animation_contents_scale, |
| 9812 animating_transform_to_screen, |
| 9813 contents_scale_x, |
| 9814 contents_scale_y, |
| 9815 content_bounds); |
| 9816 } |
| 9817 |
| 9818 float last_maximum_animation_contents_scale() { |
| 9819 return last_maximum_animation_contents_scale_; |
| 9820 } |
| 9821 |
| 9822 private: |
| 9823 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 9824 int id) |
| 9825 : LayerImpl(tree_impl, id), last_maximum_animation_contents_scale_(0.f) { |
| 9826 SetDrawsContent(true); |
| 9827 } |
| 9828 |
| 9829 float last_maximum_animation_contents_scale_; |
| 9830 }; |
| 9831 |
| 9832 TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
| 9833 FakeImplProxy proxy; |
| 9834 TestSharedBitmapManager shared_bitmap_manager; |
| 9835 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 9836 gfx::Transform identity_matrix; |
| 9837 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
| 9838 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
| 9839 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
| 9840 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2); |
| 9841 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child = |
| 9842 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3); |
| 9843 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child = |
| 9844 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4); |
| 9845 |
| 9846 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get(); |
| 9847 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get(); |
| 9848 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get(); |
| 9849 |
| 9850 child->AddChild(grand_child.PassAs<LayerImpl>()); |
| 9851 parent->AddChild(child.PassAs<LayerImpl>()); |
| 9852 grand_parent->AddChild(parent.PassAs<LayerImpl>()); |
| 9853 |
| 9854 SetLayerPropertiesForTesting(grand_parent.get(), |
| 9855 identity_matrix, |
| 9856 gfx::PointF(), |
| 9857 gfx::PointF(), |
| 9858 gfx::Size(1, 2), |
| 9859 true, |
| 9860 false); |
| 9861 SetLayerPropertiesForTesting(parent_raw, |
| 9862 identity_matrix, |
| 9863 gfx::PointF(), |
| 9864 gfx::PointF(), |
| 9865 gfx::Size(1, 2), |
| 9866 true, |
| 9867 false); |
| 9868 SetLayerPropertiesForTesting(child_raw, |
| 9869 identity_matrix, |
| 9870 gfx::PointF(), |
| 9871 gfx::PointF(), |
| 9872 gfx::Size(1, 2), |
| 9873 true, |
| 9874 false); |
| 9875 SetLayerPropertiesForTesting(grand_child_raw, |
| 9876 identity_matrix, |
| 9877 gfx::PointF(), |
| 9878 gfx::PointF(), |
| 9879 gfx::Size(1, 2), |
| 9880 true, |
| 9881 false); |
| 9882 |
| 9883 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9884 |
| 9885 // No layers have animations. |
| 9886 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 9887 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 9888 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 9889 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 9890 |
| 9891 TransformOperations translation; |
| 9892 translation.AppendTranslate(1.f, 2.f, 3.f); |
| 9893 |
| 9894 AddAnimatedTransformToLayer( |
| 9895 parent_raw, 1.0, TransformOperations(), translation); |
| 9896 |
| 9897 // No layers have scale-affecting animations. |
| 9898 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 9899 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 9900 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 9901 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 9902 |
| 9903 TransformOperations scale; |
| 9904 scale.AppendScale(5.f, 4.f, 3.f); |
| 9905 |
| 9906 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); |
| 9907 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9908 |
| 9909 // Only |child| has a scale-affecting animation. |
| 9910 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 9911 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 9912 EXPECT_EQ(5.f, child_raw->last_maximum_animation_contents_scale()); |
| 9913 EXPECT_EQ(5.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 9914 |
| 9915 AddAnimatedTransformToLayer( |
| 9916 grand_parent.get(), 1.0, TransformOperations(), scale); |
| 9917 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9918 |
| 9919 // |grand_parent| and |child| have scale-affecting animations. |
| 9920 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale()); |
| 9921 EXPECT_EQ(5.f, parent_raw->last_maximum_animation_contents_scale()); |
| 9922 // We don't support combining animated scales from two nodes; 0.f means |
| 9923 // that the maximum scale could not be computed. |
| 9924 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 9925 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 9926 |
| 9927 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 9928 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9929 |
| 9930 // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
| 9931 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale()); |
| 9932 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 9933 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 9934 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 9935 |
| 9936 grand_parent->layer_animation_controller()->AbortAnimations( |
| 9937 Animation::Transform); |
| 9938 parent_raw->layer_animation_controller()->AbortAnimations( |
| 9939 Animation::Transform); |
| 9940 child_raw->layer_animation_controller()->AbortAnimations( |
| 9941 Animation::Transform); |
| 9942 |
| 9943 TransformOperations perspective; |
| 9944 perspective.AppendPerspective(10.f); |
| 9945 |
| 9946 AddAnimatedTransformToLayer( |
| 9947 child_raw, 1.0, TransformOperations(), perspective); |
| 9948 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9949 |
| 9950 // |child| has a scale-affecting animation but computing the maximum of this |
| 9951 // animation is not supported. |
| 9952 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 9953 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 9954 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 9955 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 9956 |
| 9957 child_raw->layer_animation_controller()->AbortAnimations( |
| 9958 Animation::Transform); |
| 9959 |
| 9960 gfx::Transform scale_matrix; |
| 9961 scale_matrix.Scale(1.f, 2.f); |
| 9962 grand_parent->SetTransform(scale_matrix); |
| 9963 parent_raw->SetTransform(scale_matrix); |
| 9964 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 9965 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9966 |
| 9967 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 9968 // animation with maximum scale 5.f. |
| 9969 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 9970 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale()); |
| 9971 EXPECT_EQ(10.f, child_raw->last_maximum_animation_contents_scale()); |
| 9972 EXPECT_EQ(10.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 9973 |
| 9974 gfx::Transform perspective_matrix; |
| 9975 perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 9976 child_raw->SetTransform(perspective_matrix); |
| 9977 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9978 |
| 9979 // |child| has a transform that's neither a translation nor a scale. |
| 9980 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 9981 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale()); |
| 9982 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 9983 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 9984 |
| 9985 parent_raw->SetTransform(perspective_matrix); |
| 9986 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 9987 |
| 9988 // |parent| and |child| have transforms that are neither translations nor |
| 9989 // scales. |
| 9990 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 9991 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 9992 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 9993 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 9994 |
| 9995 parent_raw->SetTransform(identity_matrix); |
| 9996 child_raw->SetTransform(identity_matrix); |
| 9997 grand_parent->SetTransform(perspective_matrix); |
| 9998 |
| 9999 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 10000 |
| 10001 // |grand_parent| has a transform that's neither a translation nor a scale. |
| 10002 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); |
| 10003 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); |
| 10004 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); |
| 10005 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); |
| 10006 } |
| 10007 |
9782 } // namespace | 10008 } // namespace |
9783 } // namespace cc | 10009 } // namespace cc |
OLD | NEW |