| Index: cc/trees/layer_tree_host_common_unittest.cc
|
| diff --git a/cc/trees/layer_tree_host_common_unittest.cc b/cc/trees/layer_tree_host_common_unittest.cc
|
| index 72fa449cff6a60fafdb9303500540c43796aaf08..f9e69d0361f30a1a45f84a289dd4ecd4f8331675 100644
|
| --- a/cc/trees/layer_tree_host_common_unittest.cc
|
| +++ b/cc/trees/layer_tree_host_common_unittest.cc
|
| @@ -7,6 +7,7 @@
|
| #include <set>
|
|
|
| #include "cc/animation/layer_animation_controller.h"
|
| +#include "cc/animation/transform_operations.h"
|
| #include "cc/base/math_util.h"
|
| #include "cc/layers/content_layer.h"
|
| #include "cc/layers/content_layer_client.h"
|
| @@ -5999,6 +6000,7 @@ class NoScaleContentLayer : public ContentLayer {
|
| virtual void CalculateContentsScale(float ideal_contents_scale,
|
| float device_scale_factor,
|
| float page_scale_factor,
|
| + float maximum_animation_scale_factor,
|
| bool animating_transform_to_screen,
|
| float* contents_scale_x,
|
| float* contents_scale_y,
|
| @@ -6007,6 +6009,7 @@ class NoScaleContentLayer : public ContentLayer {
|
| Layer::CalculateContentsScale(ideal_contents_scale,
|
| device_scale_factor,
|
| page_scale_factor,
|
| + maximum_animation_scale_factor,
|
| animating_transform_to_screen,
|
| contents_scale_x,
|
| contents_scale_y,
|
| @@ -9737,5 +9740,207 @@ TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
|
| }
|
| }
|
|
|
| +class AnimationScaleFactorTrackingLayer : public Layer {
|
| + public:
|
| + static scoped_refptr<AnimationScaleFactorTrackingLayer> Create() {
|
| + return make_scoped_refptr(new AnimationScaleFactorTrackingLayer());
|
| + }
|
| +
|
| + virtual void CalculateContentsScale(float ideal_contents_scale,
|
| + float device_scale_factor,
|
| + float page_scale_factor,
|
| + float maximum_animation_scale_factor,
|
| + bool animating_transform_to_screen,
|
| + float* contents_scale_x,
|
| + float* contents_scale_y,
|
| + gfx::Size* content_bounds) OVERRIDE {
|
| + last_maximum_animation_scale_factor_ = maximum_animation_scale_factor;
|
| + Layer::CalculateContentsScale(ideal_contents_scale,
|
| + device_scale_factor,
|
| + page_scale_factor,
|
| + maximum_animation_scale_factor,
|
| + animating_transform_to_screen,
|
| + contents_scale_x,
|
| + contents_scale_y,
|
| + content_bounds);
|
| + }
|
| +
|
| + float last_maximum_animation_scale_factor() {
|
| + return last_maximum_animation_scale_factor_;
|
| + }
|
| +
|
| + virtual bool DrawsContent() const OVERRIDE { return true; }
|
| +
|
| + private:
|
| + AnimationScaleFactorTrackingLayer()
|
| + : last_maximum_animation_scale_factor_(0.f) {}
|
| + virtual ~AnimationScaleFactorTrackingLayer() {}
|
| +
|
| + float last_maximum_animation_scale_factor_;
|
| +};
|
| +
|
| +TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
|
| + gfx::Transform identity_matrix;
|
| + scoped_refptr<AnimationScaleFactorTrackingLayer> grand_parent =
|
| + AnimationScaleFactorTrackingLayer::Create();
|
| + scoped_refptr<AnimationScaleFactorTrackingLayer> parent =
|
| + AnimationScaleFactorTrackingLayer::Create();
|
| + scoped_refptr<AnimationScaleFactorTrackingLayer> child =
|
| + AnimationScaleFactorTrackingLayer::Create();
|
| + scoped_refptr<AnimationScaleFactorTrackingLayer> grand_child =
|
| + AnimationScaleFactorTrackingLayer::Create();
|
| + grand_parent->AddChild(parent);
|
| + parent->AddChild(child);
|
| + child->AddChild(grand_child);
|
| +
|
| + scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
|
| + host->SetRootLayer(grand_parent);
|
| +
|
| + SetLayerPropertiesForTesting(grand_parent.get(),
|
| + identity_matrix,
|
| + gfx::PointF(),
|
| + gfx::PointF(),
|
| + gfx::Size(1, 2),
|
| + true,
|
| + false);
|
| + SetLayerPropertiesForTesting(parent.get(),
|
| + identity_matrix,
|
| + gfx::PointF(),
|
| + gfx::PointF(),
|
| + gfx::Size(1, 2),
|
| + true,
|
| + false);
|
| + SetLayerPropertiesForTesting(child.get(),
|
| + identity_matrix,
|
| + gfx::PointF(),
|
| + gfx::PointF(),
|
| + gfx::Size(1, 2),
|
| + true,
|
| + false);
|
| + SetLayerPropertiesForTesting(grand_child.get(),
|
| + identity_matrix,
|
| + gfx::PointF(),
|
| + gfx::PointF(),
|
| + gfx::Size(1, 2),
|
| + true,
|
| + false);
|
| +
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // No layers have animations.
|
| + EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(1.f, parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(1.f, child->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(1.f, grand_child->last_maximum_animation_scale_factor());
|
| +
|
| + TransformOperations translation;
|
| + translation.AppendTranslate(1.f, 2.f, 3.f);
|
| +
|
| + AddAnimatedTransformToLayer(parent, 1.0, TransformOperations(), translation);
|
| +
|
| + // No layers have scale-affecting animations.
|
| + EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(1.f, parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(1.f, child->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(1.f, grand_child->last_maximum_animation_scale_factor());
|
| +
|
| + TransformOperations scale;
|
| + scale.AppendScale(5.f, 4.f, 3.f);
|
| +
|
| + AddAnimatedTransformToLayer(child, 1.0, TransformOperations(), scale);
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // Only |child| has a scale-affecting animation.
|
| + EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(1.f, parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(5.f, child->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(5.f, grand_child->last_maximum_animation_scale_factor());
|
| +
|
| + AddAnimatedTransformToLayer(grand_parent, 1.0, TransformOperations(), scale);
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // |grand_parent| and |child| have scale-affecting animations.
|
| + EXPECT_EQ(5.f, grand_parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(5.f, parent->last_maximum_animation_scale_factor());
|
| + // We don't support combining animated scales from two nodes; 0.f means
|
| + // that the maximum scale could not be computed.
|
| + EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor());
|
| +
|
| + AddAnimatedTransformToLayer(parent, 1.0, TransformOperations(), scale);
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // |grand_parent|, |parent|, and |child| have scale-affecting animations.
|
| + EXPECT_EQ(5.f, grand_parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor());
|
| +
|
| + grand_parent->layer_animation_controller()->AbortAnimations(
|
| + Animation::Transform);
|
| + parent->layer_animation_controller()->AbortAnimations(Animation::Transform);
|
| + child->layer_animation_controller()->AbortAnimations(Animation::Transform);
|
| +
|
| + TransformOperations perspective;
|
| + perspective.AppendPerspective(10.f);
|
| +
|
| + AddAnimatedTransformToLayer(child, 1.0, TransformOperations(), perspective);
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // |child| has a scale-affecting animation but computing the maximum of this
|
| + // animation is not supported.
|
| + EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(1.f, parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor());
|
| +
|
| + child->layer_animation_controller()->AbortAnimations(Animation::Transform);
|
| +
|
| + gfx::Transform scale_matrix;
|
| + scale_matrix.Scale(1.f, 2.f);
|
| + parent->SetTransform(scale_matrix);
|
| + AddAnimatedTransformToLayer(parent, 1.0, TransformOperations(), scale);
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // |parent| has scale 2.f and a scale animation with maximum scale 5.f.
|
| + EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(2.5f, parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(2.5f, child->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(2.5f, grand_child->last_maximum_animation_scale_factor());
|
| +
|
| + gfx::Transform perspective_matrix;
|
| + perspective_matrix.ApplyPerspectiveDepth(2.f);
|
| + child->SetTransform(perspective_matrix);
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // |child| has a transform that's neither a translation nor a scale.
|
| + EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(2.5f, parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor());
|
| +
|
| + parent->SetTransform(perspective_matrix);
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // |parent| and |child| have transforms that are neither translations nor
|
| + // scales.
|
| + EXPECT_EQ(1.f, grand_parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor());
|
| +
|
| + parent->SetTransform(identity_matrix);
|
| + child->SetTransform(identity_matrix);
|
| + grand_parent->SetTransform(perspective_matrix);
|
| +
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // |grand_parent| has a transform that's neither a translation nor a scale.
|
| + EXPECT_EQ(0.f, grand_parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, parent->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, child->last_maximum_animation_scale_factor());
|
| + EXPECT_EQ(0.f, grand_child->last_maximum_animation_scale_factor());
|
| +}
|
| +
|
| } // namespace
|
| } // namespace cc
|
|
|