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

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

Issue 226283004: Rasterize at maximum scale for scale animations on CPU-rasterized layers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 6 years, 8 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 | Annotate | Revision Log
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/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
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
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 AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
9744 public:
9745 static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
9746 LayerTreeImpl* tree_impl,
9747 int id) {
9748 return make_scoped_ptr(
9749 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
9750 }
9751
9752 virtual ~AnimationScaleFactorTrackingLayerImpl() {}
9753
9754 virtual void CalculateContentsScale(float ideal_contents_scale,
9755 float device_scale_factor,
9756 float page_scale_factor,
9757 float maximum_animation_scale_factor,
9758 bool animating_transform_to_screen,
9759 float* contents_scale_x,
9760 float* contents_scale_y,
9761 gfx::Size* content_bounds) OVERRIDE {
9762 last_maximum_animation_scale_factor_ = maximum_animation_scale_factor;
9763 LayerImpl::CalculateContentsScale(ideal_contents_scale,
9764 device_scale_factor,
9765 page_scale_factor,
9766 maximum_animation_scale_factor,
9767 animating_transform_to_screen,
9768 contents_scale_x,
9769 contents_scale_y,
9770 content_bounds);
9771 }
9772
9773 float last_maximum_animation_scale_factor() {
9774 return last_maximum_animation_scale_factor_;
9775 }
9776
9777 private:
9778 explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
9779 int id)
9780 : LayerImpl(tree_impl, id), last_maximum_animation_scale_factor_(0.f) {
9781 SetDrawsContent(true);
9782 }
9783
9784 float last_maximum_animation_scale_factor_;
9785 };
9786
9787 TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
9788 FakeImplProxy proxy;
9789 TestSharedBitmapManager shared_bitmap_manager;
9790 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
9791 gfx::Transform identity_matrix;
9792 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
9793 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
9794 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
9795 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
9796 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
9797 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
9798 scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
9799 AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
9800
9801 AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
9802 AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
9803 AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
9804
9805 child->AddChild(grand_child.PassAs<LayerImpl>());
9806 parent->AddChild(child.PassAs<LayerImpl>());
9807 grand_parent->AddChild(parent.PassAs<LayerImpl>());
9808
9809 SetLayerPropertiesForTesting(grand_parent.get(),
9810 identity_matrix,
9811 gfx::PointF(),
9812 gfx::PointF(),
9813 gfx::Size(1, 2),
9814 true,
9815 false);
9816 SetLayerPropertiesForTesting(parent_raw,
9817 identity_matrix,
9818 gfx::PointF(),
9819 gfx::PointF(),
9820 gfx::Size(1, 2),
9821 true,
9822 false);
9823 SetLayerPropertiesForTesting(child_raw,
9824 identity_matrix,
9825 gfx::PointF(),
9826 gfx::PointF(),
9827 gfx::Size(1, 2),
9828 true,
9829 false);
9830 SetLayerPropertiesForTesting(grand_child_raw,
9831 identity_matrix,
9832 gfx::PointF(),
9833 gfx::PointF(),
9834 gfx::Size(1, 2),
9835 true,
9836 false);
9837
9838 ExecuteCalculateDrawProperties(grand_parent.get());
9839
9840 // No layers have animations.
9841 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_scale_factor());
9842 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
9843 EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
9844 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
9845
9846 TransformOperations translation;
9847 translation.AppendTranslate(1.f, 2.f, 3.f);
9848
9849 AddAnimatedTransformToLayer(
9850 parent_raw, 1.0, TransformOperations(), translation);
9851
9852 // No layers have scale-affecting animations.
9853 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_scale_factor());
9854 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
9855 EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
9856 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
9857
9858 TransformOperations scale;
9859 scale.AppendScale(5.f, 4.f, 3.f);
9860
9861 AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
9862 ExecuteCalculateDrawProperties(grand_parent.get());
9863
9864 // Only |child| has a scale-affecting animation.
9865 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_scale_factor());
9866 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
9867 EXPECT_EQ(5.f, child_raw->last_maximum_animation_scale_factor());
9868 EXPECT_EQ(5.f, grand_child_raw->last_maximum_animation_scale_factor());
9869
9870 AddAnimatedTransformToLayer(
9871 grand_parent.get(), 1.0, TransformOperations(), scale);
9872 ExecuteCalculateDrawProperties(grand_parent.get());
9873
9874 // |grand_parent| and |child| have scale-affecting animations.
9875 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_scale_factor());
9876 EXPECT_EQ(5.f, parent_raw->last_maximum_animation_scale_factor());
9877 // We don't support combining animated scales from two nodes; 0.f means
9878 // that the maximum scale could not be computed.
9879 EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
9880 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
9881
9882 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
9883 ExecuteCalculateDrawProperties(grand_parent.get());
9884
9885 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
9886 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_scale_factor());
9887 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
9888 EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
9889 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
9890
9891 grand_parent->layer_animation_controller()->AbortAnimations(
9892 Animation::Transform);
9893 parent_raw->layer_animation_controller()->AbortAnimations(
9894 Animation::Transform);
9895 child_raw->layer_animation_controller()->AbortAnimations(
9896 Animation::Transform);
9897
9898 TransformOperations perspective;
9899 perspective.AppendPerspective(10.f);
9900
9901 AddAnimatedTransformToLayer(
9902 child_raw, 1.0, TransformOperations(), perspective);
9903 ExecuteCalculateDrawProperties(grand_parent.get());
9904
9905 // |child| has a scale-affecting animation but computing the maximum of this
9906 // animation is not supported.
9907 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_scale_factor());
9908 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
9909 EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
9910 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
9911
9912 child_raw->layer_animation_controller()->AbortAnimations(
9913 Animation::Transform);
9914
9915 gfx::Transform scale_matrix;
9916 scale_matrix.Scale(1.f, 2.f);
9917 grand_parent->SetTransform(scale_matrix);
9918 parent_raw->SetTransform(scale_matrix);
9919 AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
9920 ExecuteCalculateDrawProperties(grand_parent.get());
9921
9922 // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
9923 // animation with maximum scale 5.f.
9924 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_scale_factor());
9925 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_scale_factor());
9926 EXPECT_EQ(10.f, child_raw->last_maximum_animation_scale_factor());
9927 EXPECT_EQ(10.f, grand_child_raw->last_maximum_animation_scale_factor());
9928
9929 gfx::Transform perspective_matrix;
9930 perspective_matrix.ApplyPerspectiveDepth(2.f);
9931 child_raw->SetTransform(perspective_matrix);
9932 ExecuteCalculateDrawProperties(grand_parent.get());
9933
9934 // |child| has a transform that's neither a translation nor a scale.
9935 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_scale_factor());
9936 EXPECT_EQ(10.f, parent_raw->last_maximum_animation_scale_factor());
9937 EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
9938 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
9939
9940 parent_raw->SetTransform(perspective_matrix);
9941 ExecuteCalculateDrawProperties(grand_parent.get());
9942
9943 // |parent| and |child| have transforms that are neither translations nor
9944 // scales.
9945 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_scale_factor());
9946 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
9947 EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
9948 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
9949
9950 parent_raw->SetTransform(identity_matrix);
9951 child_raw->SetTransform(identity_matrix);
9952 grand_parent->SetTransform(perspective_matrix);
9953
9954 ExecuteCalculateDrawProperties(grand_parent.get());
9955
9956 // |grand_parent| has a transform that's neither a translation nor a scale.
9957 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_scale_factor());
9958 EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
9959 EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
9960 EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
9961 }
9962
9740 } // namespace 9963 } // namespace
9741 } // namespace cc 9964 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698