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

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: 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 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 EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor());
Ian Vollick 2014/04/05 02:24:33 Might be worth mentioning that we don't support co
ajuma 2014/04/07 15:27:00 Done.
9866 EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor());
9867
9868 AddAnimatedTransformToLayer(parent, 1.0, TransformOperations(), scale);
9869 ExecuteCalculateDrawProperties(grand_parent.get());
9870
9871 // |grand_parent|, |parent|, and |child| have scale-affecting animations.
9872 EXPECT_EQ(5.f, grand_parent->last_maximum_animation_scale_factor());
9873 EXPECT_EQ(0.f, parent->last_maximum_animation_scale_factor());
9874 EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor());
9875 EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor());
9876
9877 grand_parent->layer_animation_controller()->AbortAnimations(
9878 Animation::Transform);
9879 parent->layer_animation_controller()->AbortAnimations(Animation::Transform);
9880 child->layer_animation_controller()->AbortAnimations(Animation::Transform);
9881
9882 TransformOperations perspective;
9883 perspective.AppendPerspective(10.f);
9884
9885 AddAnimatedTransformToLayer(child, 1.0, TransformOperations(), perspective);
9886 ExecuteCalculateDrawProperties(grand_parent.get());
9887
9888 // |child| has a scale-affecting animation but computing the maximum of this
9889 // animation is not supported.
9890 EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor());
9891 EXPECT_EQ(1.f, parent->last_maximum_animation_scale_factor());
9892 EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor());
9893 EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor());
9894
9895 child->layer_animation_controller()->AbortAnimations(Animation::Transform);
9896
9897 gfx::Transform scale_matrix;
9898 scale_matrix.Scale(1.f, 2.f);
9899 parent->SetTransform(scale_matrix);
9900 AddAnimatedTransformToLayer(parent, 1.0, TransformOperations(), scale);
9901 ExecuteCalculateDrawProperties(grand_parent.get());
9902
9903 // |parent| has scale 2.f and a scale animation with maximum scale 5.f.
9904 EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor());
9905 EXPECT_EQ(2.5f, parent->last_maximum_animation_scale_factor());
9906 EXPECT_EQ(2.5f, child->last_maximum_animation_scale_factor());
9907 EXPECT_EQ(2.5f, grand_child->last_maximum_animation_scale_factor());
9908
9909 gfx::Transform perspective_matrix;
9910 perspective_matrix.ApplyPerspectiveDepth(2.f);
9911 child->SetTransform(perspective_matrix);
9912 ExecuteCalculateDrawProperties(grand_parent.get());
9913
9914 // |child| has a transform that's neither a translation nor a scale.
9915 EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor());
9916 EXPECT_EQ(2.5f, parent->last_maximum_animation_scale_factor());
9917 EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor());
9918 EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor());
9919
9920 parent->SetTransform(perspective_matrix);
9921 ExecuteCalculateDrawProperties(grand_parent.get());
9922
9923 // |parent| and |child| have transforms that are neither translations nor
9924 // scales.
9925 EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor());
9926 EXPECT_EQ(0.f, parent->last_maximum_animation_scale_factor());
9927 EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor());
9928 EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor());
9929
9930 parent->SetTransform(identity_matrix);
9931 child->SetTransform(identity_matrix);
9932 grand_parent->SetTransform(perspective_matrix);
9933
9934 ExecuteCalculateDrawProperties(grand_parent.get());
9935
9936 // |grand_parent| has a transform that's neither a translation nor a scale.
9937 EXPECT_EQ(0.f, grand_parent->last_maximum_animation_scale_factor());
9938 EXPECT_EQ(0.f, parent->last_maximum_animation_scale_factor());
9939 EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor());
9940 EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor());
9941 }
9942
9740 } // namespace 9943 } // namespace
9741 } // namespace cc 9944 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698