| 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/animation/transform_operations.h" |
| (...skipping 7848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7859 public: | 7859 public: |
| 7860 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( | 7860 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
| 7861 LayerTreeImpl* tree_impl, | 7861 LayerTreeImpl* tree_impl, |
| 7862 int id) { | 7862 int id) { |
| 7863 return make_scoped_ptr( | 7863 return make_scoped_ptr( |
| 7864 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); | 7864 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
| 7865 } | 7865 } |
| 7866 | 7866 |
| 7867 virtual ~AnimationScaleFactorTrackingLayerImpl() {} | 7867 virtual ~AnimationScaleFactorTrackingLayerImpl() {} |
| 7868 | 7868 |
| 7869 virtual void CalculateContentsScale(float ideal_contents_scale, | |
| 7870 float device_scale_factor, | |
| 7871 float page_scale_factor, | |
| 7872 float maximum_animation_contents_scale, | |
| 7873 bool animating_transform_to_screen, | |
| 7874 float* contents_scale_x, | |
| 7875 float* contents_scale_y, | |
| 7876 gfx::Size* content_bounds) OVERRIDE { | |
| 7877 last_maximum_animation_contents_scale_ = maximum_animation_contents_scale; | |
| 7878 LayerImpl::CalculateContentsScale(ideal_contents_scale, | |
| 7879 device_scale_factor, | |
| 7880 page_scale_factor, | |
| 7881 maximum_animation_contents_scale, | |
| 7882 animating_transform_to_screen, | |
| 7883 contents_scale_x, | |
| 7884 contents_scale_y, | |
| 7885 content_bounds); | |
| 7886 } | |
| 7887 | |
| 7888 float last_maximum_animation_contents_scale() { | |
| 7889 return last_maximum_animation_contents_scale_; | |
| 7890 } | |
| 7891 | |
| 7892 private: | 7869 private: |
| 7893 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, | 7870 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, |
| 7894 int id) | 7871 int id) |
| 7895 : LayerImpl(tree_impl, id), last_maximum_animation_contents_scale_(0.f) { | 7872 : LayerImpl(tree_impl, id) { |
| 7896 SetDrawsContent(true); | 7873 SetDrawsContent(true); |
| 7897 } | 7874 } |
| 7898 | |
| 7899 float last_maximum_animation_contents_scale_; | |
| 7900 }; | 7875 }; |
| 7901 | 7876 |
| 7902 TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { | 7877 TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { |
| 7903 FakeImplProxy proxy; | 7878 FakeImplProxy proxy; |
| 7904 TestSharedBitmapManager shared_bitmap_manager; | 7879 TestSharedBitmapManager shared_bitmap_manager; |
| 7905 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); | 7880 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); |
| 7906 gfx::Transform identity_matrix; | 7881 gfx::Transform identity_matrix; |
| 7907 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = | 7882 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = |
| 7908 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); | 7883 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); |
| 7909 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = | 7884 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7946 identity_matrix, | 7921 identity_matrix, |
| 7947 gfx::Point3F(), | 7922 gfx::Point3F(), |
| 7948 gfx::PointF(), | 7923 gfx::PointF(), |
| 7949 gfx::Size(1, 2), | 7924 gfx::Size(1, 2), |
| 7950 true, | 7925 true, |
| 7951 false); | 7926 false); |
| 7952 | 7927 |
| 7953 ExecuteCalculateDrawProperties(grand_parent.get()); | 7928 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7954 | 7929 |
| 7955 // No layers have animations. | 7930 // No layers have animations. |
| 7956 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); | 7931 EXPECT_EQ(0.f, |
| 7957 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); | 7932 grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7958 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); | 7933 EXPECT_EQ(0.f, |
| 7959 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); | 7934 parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7935 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7936 EXPECT_EQ( |
| 7937 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
| 7960 | 7938 |
| 7961 TransformOperations translation; | 7939 TransformOperations translation; |
| 7962 translation.AppendTranslate(1.f, 2.f, 3.f); | 7940 translation.AppendTranslate(1.f, 2.f, 3.f); |
| 7963 | 7941 |
| 7964 AddAnimatedTransformToLayer( | 7942 AddAnimatedTransformToLayer( |
| 7965 parent_raw, 1.0, TransformOperations(), translation); | 7943 parent_raw, 1.0, TransformOperations(), translation); |
| 7966 | 7944 |
| 7967 // No layers have scale-affecting animations. | 7945 // No layers have scale-affecting animations. |
| 7968 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); | 7946 EXPECT_EQ(0.f, |
| 7969 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); | 7947 grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7970 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); | 7948 EXPECT_EQ(0.f, |
| 7971 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); | 7949 parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7950 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7951 EXPECT_EQ( |
| 7952 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
| 7972 | 7953 |
| 7973 TransformOperations scale; | 7954 TransformOperations scale; |
| 7974 scale.AppendScale(5.f, 4.f, 3.f); | 7955 scale.AppendScale(5.f, 4.f, 3.f); |
| 7975 | 7956 |
| 7976 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); | 7957 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); |
| 7977 ExecuteCalculateDrawProperties(grand_parent.get()); | 7958 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7978 | 7959 |
| 7979 // Only |child| has a scale-affecting animation. | 7960 // Only |child| has a scale-affecting animation. |
| 7980 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); | 7961 EXPECT_EQ(0.f, |
| 7981 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); | 7962 grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7982 EXPECT_EQ(5.f, child_raw->last_maximum_animation_contents_scale()); | 7963 EXPECT_EQ(0.f, |
| 7983 EXPECT_EQ(5.f, grand_child_raw->last_maximum_animation_contents_scale()); | 7964 parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7965 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7966 EXPECT_EQ( |
| 7967 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
| 7984 | 7968 |
| 7985 AddAnimatedTransformToLayer( | 7969 AddAnimatedTransformToLayer( |
| 7986 grand_parent.get(), 1.0, TransformOperations(), scale); | 7970 grand_parent.get(), 1.0, TransformOperations(), scale); |
| 7987 ExecuteCalculateDrawProperties(grand_parent.get()); | 7971 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7988 | 7972 |
| 7989 // |grand_parent| and |child| have scale-affecting animations. | 7973 // |grand_parent| and |child| have scale-affecting animations. |
| 7990 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale()); | 7974 EXPECT_EQ(5.f, |
| 7991 EXPECT_EQ(5.f, parent_raw->last_maximum_animation_contents_scale()); | 7975 grand_parent->draw_properties().maximum_animation_contents_scale); |
| 7976 EXPECT_EQ(5.f, |
| 7977 parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7992 // We don't support combining animated scales from two nodes; 0.f means | 7978 // We don't support combining animated scales from two nodes; 0.f means |
| 7993 // that the maximum scale could not be computed. | 7979 // that the maximum scale could not be computed. |
| 7994 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); | 7980 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7995 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); | 7981 EXPECT_EQ( |
| 7982 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
| 7996 | 7983 |
| 7997 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); | 7984 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 7998 ExecuteCalculateDrawProperties(grand_parent.get()); | 7985 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 7999 | 7986 |
| 8000 // |grand_parent|, |parent|, and |child| have scale-affecting animations. | 7987 // |grand_parent|, |parent|, and |child| have scale-affecting animations. |
| 8001 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale()); | 7988 EXPECT_EQ(5.f, |
| 8002 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); | 7989 grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8003 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); | 7990 EXPECT_EQ(0.f, |
| 8004 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); | 7991 parent_raw->draw_properties().maximum_animation_contents_scale); |
| 7992 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 7993 EXPECT_EQ( |
| 7994 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
| 8005 | 7995 |
| 8006 grand_parent->layer_animation_controller()->AbortAnimations( | 7996 grand_parent->layer_animation_controller()->AbortAnimations( |
| 8007 Animation::Transform); | 7997 Animation::Transform); |
| 8008 parent_raw->layer_animation_controller()->AbortAnimations( | 7998 parent_raw->layer_animation_controller()->AbortAnimations( |
| 8009 Animation::Transform); | 7999 Animation::Transform); |
| 8010 child_raw->layer_animation_controller()->AbortAnimations( | 8000 child_raw->layer_animation_controller()->AbortAnimations( |
| 8011 Animation::Transform); | 8001 Animation::Transform); |
| 8012 | 8002 |
| 8013 TransformOperations perspective; | 8003 TransformOperations perspective; |
| 8014 perspective.AppendPerspective(10.f); | 8004 perspective.AppendPerspective(10.f); |
| 8015 | 8005 |
| 8016 AddAnimatedTransformToLayer( | 8006 AddAnimatedTransformToLayer( |
| 8017 child_raw, 1.0, TransformOperations(), perspective); | 8007 child_raw, 1.0, TransformOperations(), perspective); |
| 8018 ExecuteCalculateDrawProperties(grand_parent.get()); | 8008 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8019 | 8009 |
| 8020 // |child| has a scale-affecting animation but computing the maximum of this | 8010 // |child| has a scale-affecting animation but computing the maximum of this |
| 8021 // animation is not supported. | 8011 // animation is not supported. |
| 8022 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); | 8012 EXPECT_EQ(0.f, |
| 8023 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); | 8013 grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8024 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); | 8014 EXPECT_EQ(0.f, |
| 8025 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); | 8015 parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8016 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8017 EXPECT_EQ( |
| 8018 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
| 8026 | 8019 |
| 8027 child_raw->layer_animation_controller()->AbortAnimations( | 8020 child_raw->layer_animation_controller()->AbortAnimations( |
| 8028 Animation::Transform); | 8021 Animation::Transform); |
| 8029 | 8022 |
| 8030 gfx::Transform scale_matrix; | 8023 gfx::Transform scale_matrix; |
| 8031 scale_matrix.Scale(1.f, 2.f); | 8024 scale_matrix.Scale(1.f, 2.f); |
| 8032 grand_parent->SetTransform(scale_matrix); | 8025 grand_parent->SetTransform(scale_matrix); |
| 8033 parent_raw->SetTransform(scale_matrix); | 8026 parent_raw->SetTransform(scale_matrix); |
| 8034 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); | 8027 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); |
| 8035 ExecuteCalculateDrawProperties(grand_parent.get()); | 8028 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8036 | 8029 |
| 8037 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale | 8030 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale |
| 8038 // animation with maximum scale 5.f. | 8031 // animation with maximum scale 5.f. |
| 8039 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); | 8032 EXPECT_EQ(0.f, |
| 8040 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale()); | 8033 grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8041 EXPECT_EQ(10.f, child_raw->last_maximum_animation_contents_scale()); | 8034 EXPECT_EQ(10.f, |
| 8042 EXPECT_EQ(10.f, grand_child_raw->last_maximum_animation_contents_scale()); | 8035 parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8036 EXPECT_EQ(10.f, |
| 8037 child_raw->draw_properties().maximum_animation_contents_scale); |
| 8038 EXPECT_EQ( |
| 8039 10.f, |
| 8040 grand_child_raw->draw_properties().maximum_animation_contents_scale); |
| 8043 | 8041 |
| 8044 gfx::Transform perspective_matrix; | 8042 gfx::Transform perspective_matrix; |
| 8045 perspective_matrix.ApplyPerspectiveDepth(2.f); | 8043 perspective_matrix.ApplyPerspectiveDepth(2.f); |
| 8046 child_raw->SetTransform(perspective_matrix); | 8044 child_raw->SetTransform(perspective_matrix); |
| 8047 ExecuteCalculateDrawProperties(grand_parent.get()); | 8045 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8048 | 8046 |
| 8049 // |child| has a transform that's neither a translation nor a scale. | 8047 // |child| has a transform that's neither a translation nor a scale. |
| 8050 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); | 8048 EXPECT_EQ(0.f, |
| 8051 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale()); | 8049 grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8052 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); | 8050 EXPECT_EQ(10.f, |
| 8053 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); | 8051 parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8052 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8053 EXPECT_EQ( |
| 8054 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
| 8054 | 8055 |
| 8055 parent_raw->SetTransform(perspective_matrix); | 8056 parent_raw->SetTransform(perspective_matrix); |
| 8056 ExecuteCalculateDrawProperties(grand_parent.get()); | 8057 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8057 | 8058 |
| 8058 // |parent| and |child| have transforms that are neither translations nor | 8059 // |parent| and |child| have transforms that are neither translations nor |
| 8059 // scales. | 8060 // scales. |
| 8060 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); | 8061 EXPECT_EQ(0.f, |
| 8061 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); | 8062 grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8062 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); | 8063 EXPECT_EQ(0.f, |
| 8063 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); | 8064 parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8065 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8066 EXPECT_EQ( |
| 8067 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
| 8064 | 8068 |
| 8065 parent_raw->SetTransform(identity_matrix); | 8069 parent_raw->SetTransform(identity_matrix); |
| 8066 child_raw->SetTransform(identity_matrix); | 8070 child_raw->SetTransform(identity_matrix); |
| 8067 grand_parent->SetTransform(perspective_matrix); | 8071 grand_parent->SetTransform(perspective_matrix); |
| 8068 | 8072 |
| 8069 ExecuteCalculateDrawProperties(grand_parent.get()); | 8073 ExecuteCalculateDrawProperties(grand_parent.get()); |
| 8070 | 8074 |
| 8071 // |grand_parent| has a transform that's neither a translation nor a scale. | 8075 // |grand_parent| has a transform that's neither a translation nor a scale. |
| 8072 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); | 8076 EXPECT_EQ(0.f, |
| 8073 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); | 8077 grand_parent->draw_properties().maximum_animation_contents_scale); |
| 8074 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); | 8078 EXPECT_EQ(0.f, |
| 8075 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); | 8079 parent_raw->draw_properties().maximum_animation_contents_scale); |
| 8080 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale); |
| 8081 EXPECT_EQ( |
| 8082 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale); |
| 8076 } | 8083 } |
| 8077 | 8084 |
| 8078 static int membership_id(LayerImpl* layer) { | 8085 static int membership_id(LayerImpl* layer) { |
| 8079 return layer->draw_properties().last_drawn_render_surface_layer_list_id; | 8086 return layer->draw_properties().last_drawn_render_surface_layer_list_id; |
| 8080 } | 8087 } |
| 8081 | 8088 |
| 8082 static void GatherDrawnLayers(LayerImplList* rsll, | 8089 static void GatherDrawnLayers(LayerImplList* rsll, |
| 8083 std::set<LayerImpl*>* drawn_layers) { | 8090 std::set<LayerImpl*>* drawn_layers) { |
| 8084 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll), | 8091 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll), |
| 8085 end = LayerIterator<LayerImpl>::End(rsll); | 8092 end = LayerIterator<LayerImpl>::End(rsll); |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8586 EXPECT_FLOAT_EQ(4.f, | 8593 EXPECT_FLOAT_EQ(4.f, |
| 8587 child1_layer->replica_layer() | 8594 child1_layer->replica_layer() |
| 8588 ->mask_layer() | 8595 ->mask_layer() |
| 8589 ->draw_properties() | 8596 ->draw_properties() |
| 8590 .device_scale_factor); | 8597 .device_scale_factor); |
| 8591 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor); | 8598 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor); |
| 8592 } | 8599 } |
| 8593 | 8600 |
| 8594 } // namespace | 8601 } // namespace |
| 8595 } // namespace cc | 8602 } // namespace cc |
| OLD | NEW |