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

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

Issue 336793003: cc: Move CalculateContentsScale from LayerImpl to LayerTreeHostCommon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 6 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 <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
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, 7869 virtual void CalculateContentsScale(float ideal_contents_scale,
danakj 2014/06/13 15:00:27 Can just remove this method? It's not overriding a
sohanjg 2014/06/13 15:36:06 Done.
7870 float device_scale_factor, 7870 float device_scale_factor,
7871 float page_scale_factor, 7871 float page_scale_factor,
7872 float maximum_animation_contents_scale, 7872 float maximum_animation_contents_scale,
7873 bool animating_transform_to_screen, 7873 bool animating_transform_to_screen,
7874 float* contents_scale_x, 7874 float* contents_scale_x,
7875 float* contents_scale_y, 7875 float* contents_scale_y,
7876 gfx::Size* content_bounds) OVERRIDE { 7876 gfx::Size* content_bounds) OVERRIDE {
7877 last_maximum_animation_contents_scale_ = maximum_animation_contents_scale; 7877 this->draw_properties().ideal_contents_scale = ideal_contents_scale;
7878 LayerImpl::CalculateContentsScale(ideal_contents_scale, 7878 this->draw_properties().device_scale_factor = device_scale_factor;
7879 device_scale_factor, 7879 this->draw_properties().page_scale_factor = page_scale_factor;
7880 page_scale_factor, 7880 this->draw_properties().maximum_animation_contents_scale =
7881 maximum_animation_contents_scale, 7881 maximum_animation_contents_scale;
7882 animating_transform_to_screen, 7882 this->draw_properties().screen_space_transform_is_animating =
7883 contents_scale_x, 7883 animating_transform_to_screen;
7884 contents_scale_y,
7885 content_bounds);
7886 }
7887
7888 float last_maximum_animation_contents_scale() {
7889 return last_maximum_animation_contents_scale_;
7890 } 7884 }
7891 7885
7892 private: 7886 private:
7893 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl, 7887 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
7894 int id) 7888 int id)
7895 : LayerImpl(tree_impl, id), last_maximum_animation_contents_scale_(0.f) { 7889 : LayerImpl(tree_impl, id) {
7896 SetDrawsContent(true); 7890 SetDrawsContent(true);
7897 } 7891 }
7898
7899 float last_maximum_animation_contents_scale_;
7900 }; 7892 };
7901 7893
7902 TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) { 7894 TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
7903 FakeImplProxy proxy; 7895 FakeImplProxy proxy;
7904 TestSharedBitmapManager shared_bitmap_manager; 7896 TestSharedBitmapManager shared_bitmap_manager;
7905 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); 7897 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
7906 gfx::Transform identity_matrix; 7898 gfx::Transform identity_matrix;
7907 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent = 7899 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
7908 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1); 7900 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
7909 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent = 7901 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
7946 identity_matrix, 7938 identity_matrix,
7947 gfx::Point3F(), 7939 gfx::Point3F(),
7948 gfx::PointF(), 7940 gfx::PointF(),
7949 gfx::Size(1, 2), 7941 gfx::Size(1, 2),
7950 true, 7942 true,
7951 false); 7943 false);
7952 7944
7953 ExecuteCalculateDrawProperties(grand_parent.get()); 7945 ExecuteCalculateDrawProperties(grand_parent.get());
7954 7946
7955 // No layers have animations. 7947 // No layers have animations.
7956 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); 7948 EXPECT_EQ(0.f,
7957 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); 7949 grand_parent->draw_properties().maximum_animation_contents_scale);
7958 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); 7950 EXPECT_EQ(0.f,
7959 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); 7951 parent_raw->draw_properties().maximum_animation_contents_scale);
7952 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7953 EXPECT_EQ(
7954 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
7960 7955
7961 TransformOperations translation; 7956 TransformOperations translation;
7962 translation.AppendTranslate(1.f, 2.f, 3.f); 7957 translation.AppendTranslate(1.f, 2.f, 3.f);
7963 7958
7964 AddAnimatedTransformToLayer( 7959 AddAnimatedTransformToLayer(
7965 parent_raw, 1.0, TransformOperations(), translation); 7960 parent_raw, 1.0, TransformOperations(), translation);
7966 7961
7967 // No layers have scale-affecting animations. 7962 // No layers have scale-affecting animations.
7968 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); 7963 EXPECT_EQ(0.f,
7969 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); 7964 grand_parent->draw_properties().maximum_animation_contents_scale);
7970 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); 7965 EXPECT_EQ(0.f,
7971 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); 7966 parent_raw->draw_properties().maximum_animation_contents_scale);
7967 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
7968 EXPECT_EQ(
7969 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
7972 7970
7973 TransformOperations scale; 7971 TransformOperations scale;
7974 scale.AppendScale(5.f, 4.f, 3.f); 7972 scale.AppendScale(5.f, 4.f, 3.f);
7975 7973
7976 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale); 7974 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
7977 ExecuteCalculateDrawProperties(grand_parent.get()); 7975 ExecuteCalculateDrawProperties(grand_parent.get());
7978 7976
7979 // Only |child| has a scale-affecting animation. 7977 // Only |child| has a scale-affecting animation.
7980 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); 7978 EXPECT_EQ(0.f,
7981 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); 7979 grand_parent->draw_properties().maximum_animation_contents_scale);
7982 EXPECT_EQ(5.f, child_raw->last_maximum_animation_contents_scale()); 7980 EXPECT_EQ(0.f,
7983 EXPECT_EQ(5.f, grand_child_raw->last_maximum_animation_contents_scale()); 7981 parent_raw->draw_properties().maximum_animation_contents_scale);
7982 EXPECT_EQ(5.f, child_raw->draw_properties().maximum_animation_contents_scale);
7983 EXPECT_EQ(
7984 5.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
7984 7985
7985 AddAnimatedTransformToLayer( 7986 AddAnimatedTransformToLayer(
7986 grand_parent.get(), 1.0, TransformOperations(), scale); 7987 grand_parent.get(), 1.0, TransformOperations(), scale);
7987 ExecuteCalculateDrawProperties(grand_parent.get()); 7988 ExecuteCalculateDrawProperties(grand_parent.get());
7988 7989
7989 // |grand_parent| and |child| have scale-affecting animations. 7990 // |grand_parent| and |child| have scale-affecting animations.
7990 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale()); 7991 EXPECT_EQ(5.f,
7991 EXPECT_EQ(5.f, parent_raw->last_maximum_animation_contents_scale()); 7992 grand_parent->draw_properties().maximum_animation_contents_scale);
7993 EXPECT_EQ(5.f,
7994 parent_raw->draw_properties().maximum_animation_contents_scale);
7992 // We don't support combining animated scales from two nodes; 0.f means 7995 // We don't support combining animated scales from two nodes; 0.f means
7993 // that the maximum scale could not be computed. 7996 // that the maximum scale could not be computed.
7994 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); 7997 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()); 7998 EXPECT_EQ(
7999 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
7996 8000
7997 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); 8001 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
7998 ExecuteCalculateDrawProperties(grand_parent.get()); 8002 ExecuteCalculateDrawProperties(grand_parent.get());
7999 8003
8000 // |grand_parent|, |parent|, and |child| have scale-affecting animations. 8004 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
8001 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_contents_scale()); 8005 EXPECT_EQ(5.f,
8002 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); 8006 grand_parent->draw_properties().maximum_animation_contents_scale);
8003 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); 8007 EXPECT_EQ(0.f,
8004 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); 8008 parent_raw->draw_properties().maximum_animation_contents_scale);
8009 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8010 EXPECT_EQ(
8011 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
8005 8012
8006 grand_parent->layer_animation_controller()->AbortAnimations( 8013 grand_parent->layer_animation_controller()->AbortAnimations(
8007 Animation::Transform); 8014 Animation::Transform);
8008 parent_raw->layer_animation_controller()->AbortAnimations( 8015 parent_raw->layer_animation_controller()->AbortAnimations(
8009 Animation::Transform); 8016 Animation::Transform);
8010 child_raw->layer_animation_controller()->AbortAnimations( 8017 child_raw->layer_animation_controller()->AbortAnimations(
8011 Animation::Transform); 8018 Animation::Transform);
8012 8019
8013 TransformOperations perspective; 8020 TransformOperations perspective;
8014 perspective.AppendPerspective(10.f); 8021 perspective.AppendPerspective(10.f);
8015 8022
8016 AddAnimatedTransformToLayer( 8023 AddAnimatedTransformToLayer(
8017 child_raw, 1.0, TransformOperations(), perspective); 8024 child_raw, 1.0, TransformOperations(), perspective);
8018 ExecuteCalculateDrawProperties(grand_parent.get()); 8025 ExecuteCalculateDrawProperties(grand_parent.get());
8019 8026
8020 // |child| has a scale-affecting animation but computing the maximum of this 8027 // |child| has a scale-affecting animation but computing the maximum of this
8021 // animation is not supported. 8028 // animation is not supported.
8022 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); 8029 EXPECT_EQ(0.f,
8023 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); 8030 grand_parent->draw_properties().maximum_animation_contents_scale);
8024 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); 8031 EXPECT_EQ(0.f,
8025 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); 8032 parent_raw->draw_properties().maximum_animation_contents_scale);
8033 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8034 EXPECT_EQ(
8035 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
8026 8036
8027 child_raw->layer_animation_controller()->AbortAnimations( 8037 child_raw->layer_animation_controller()->AbortAnimations(
8028 Animation::Transform); 8038 Animation::Transform);
8029 8039
8030 gfx::Transform scale_matrix; 8040 gfx::Transform scale_matrix;
8031 scale_matrix.Scale(1.f, 2.f); 8041 scale_matrix.Scale(1.f, 2.f);
8032 grand_parent->SetTransform(scale_matrix); 8042 grand_parent->SetTransform(scale_matrix);
8033 parent_raw->SetTransform(scale_matrix); 8043 parent_raw->SetTransform(scale_matrix);
8034 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale); 8044 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
8035 ExecuteCalculateDrawProperties(grand_parent.get()); 8045 ExecuteCalculateDrawProperties(grand_parent.get());
8036 8046
8037 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale 8047 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
8038 // animation with maximum scale 5.f. 8048 // animation with maximum scale 5.f.
8039 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); 8049 EXPECT_EQ(0.f,
8040 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale()); 8050 grand_parent->draw_properties().maximum_animation_contents_scale);
8041 EXPECT_EQ(10.f, child_raw->last_maximum_animation_contents_scale()); 8051 EXPECT_EQ(10.f,
8042 EXPECT_EQ(10.f, grand_child_raw->last_maximum_animation_contents_scale()); 8052 parent_raw->draw_properties().maximum_animation_contents_scale);
8053 EXPECT_EQ(10.f,
8054 child_raw->draw_properties().maximum_animation_contents_scale);
8055 EXPECT_EQ(
8056 10.f,
8057 grand_child_raw->draw_properties().maximum_animation_contents_scale);
8043 8058
8044 gfx::Transform perspective_matrix; 8059 gfx::Transform perspective_matrix;
8045 perspective_matrix.ApplyPerspectiveDepth(2.f); 8060 perspective_matrix.ApplyPerspectiveDepth(2.f);
8046 child_raw->SetTransform(perspective_matrix); 8061 child_raw->SetTransform(perspective_matrix);
8047 ExecuteCalculateDrawProperties(grand_parent.get()); 8062 ExecuteCalculateDrawProperties(grand_parent.get());
8048 8063
8049 // |child| has a transform that's neither a translation nor a scale. 8064 // |child| has a transform that's neither a translation nor a scale.
8050 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); 8065 EXPECT_EQ(0.f,
8051 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale()); 8066 grand_parent->draw_properties().maximum_animation_contents_scale);
8052 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); 8067 EXPECT_EQ(10.f,
8053 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); 8068 parent_raw->draw_properties().maximum_animation_contents_scale);
8069 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8070 EXPECT_EQ(
8071 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
8054 8072
8055 parent_raw->SetTransform(perspective_matrix); 8073 parent_raw->SetTransform(perspective_matrix);
8056 ExecuteCalculateDrawProperties(grand_parent.get()); 8074 ExecuteCalculateDrawProperties(grand_parent.get());
8057 8075
8058 // |parent| and |child| have transforms that are neither translations nor 8076 // |parent| and |child| have transforms that are neither translations nor
8059 // scales. 8077 // scales.
8060 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale()); 8078 EXPECT_EQ(0.f,
8061 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); 8079 grand_parent->draw_properties().maximum_animation_contents_scale);
8062 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); 8080 EXPECT_EQ(0.f,
8063 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); 8081 parent_raw->draw_properties().maximum_animation_contents_scale);
8082 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8083 EXPECT_EQ(
8084 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
8064 8085
8065 parent_raw->SetTransform(identity_matrix); 8086 parent_raw->SetTransform(identity_matrix);
8066 child_raw->SetTransform(identity_matrix); 8087 child_raw->SetTransform(identity_matrix);
8067 grand_parent->SetTransform(perspective_matrix); 8088 grand_parent->SetTransform(perspective_matrix);
8068 8089
8069 ExecuteCalculateDrawProperties(grand_parent.get()); 8090 ExecuteCalculateDrawProperties(grand_parent.get());
8070 8091
8071 // |grand_parent| has a transform that's neither a translation nor a scale. 8092 // |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()); 8093 EXPECT_EQ(0.f,
8073 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale()); 8094 grand_parent->draw_properties().maximum_animation_contents_scale);
8074 EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale()); 8095 EXPECT_EQ(0.f,
8075 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale()); 8096 parent_raw->draw_properties().maximum_animation_contents_scale);
8097 EXPECT_EQ(0.f, child_raw->draw_properties().maximum_animation_contents_scale);
8098 EXPECT_EQ(
8099 0.f, grand_child_raw->draw_properties().maximum_animation_contents_scale);
8076 } 8100 }
8077 8101
8078 static int membership_id(LayerImpl* layer) { 8102 static int membership_id(LayerImpl* layer) {
8079 return layer->draw_properties().last_drawn_render_surface_layer_list_id; 8103 return layer->draw_properties().last_drawn_render_surface_layer_list_id;
8080 } 8104 }
8081 8105
8082 static void GatherDrawnLayers(LayerImplList* rsll, 8106 static void GatherDrawnLayers(LayerImplList* rsll,
8083 std::set<LayerImpl*>* drawn_layers) { 8107 std::set<LayerImpl*>* drawn_layers) {
8084 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll), 8108 for (LayerIterator<LayerImpl> it = LayerIterator<LayerImpl>::Begin(rsll),
8085 end = LayerIterator<LayerImpl>::End(rsll); 8109 end = LayerIterator<LayerImpl>::End(rsll);
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
8586 EXPECT_FLOAT_EQ(4.f, 8610 EXPECT_FLOAT_EQ(4.f,
8587 child1_layer->replica_layer() 8611 child1_layer->replica_layer()
8588 ->mask_layer() 8612 ->mask_layer()
8589 ->draw_properties() 8613 ->draw_properties()
8590 .device_scale_factor); 8614 .device_scale_factor);
8591 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor); 8615 EXPECT_FLOAT_EQ(4.f, child2_layer->draw_properties().device_scale_factor);
8592 } 8616 }
8593 8617
8594 } // namespace 8618 } // namespace
8595 } // namespace cc 8619 } // namespace cc
OLDNEW
« cc/trees/layer_tree_host_common.cc ('K') | « cc/trees/layer_tree_host_common.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698