| 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..efcb543b4d546ea9011a1adafa7299fc222bc7bd 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_contents_scale,
|
| 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_contents_scale,
|
| animating_transform_to_screen,
|
| contents_scale_x,
|
| contents_scale_y,
|
| @@ -9737,5 +9740,225 @@ TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) {
|
| }
|
| }
|
|
|
| +class AnimationScaleFactorTrackingLayerImpl : public LayerImpl {
|
| + public:
|
| + static scoped_ptr<AnimationScaleFactorTrackingLayerImpl> Create(
|
| + LayerTreeImpl* tree_impl,
|
| + int id) {
|
| + return make_scoped_ptr(
|
| + new AnimationScaleFactorTrackingLayerImpl(tree_impl, id));
|
| + }
|
| +
|
| + virtual ~AnimationScaleFactorTrackingLayerImpl() {}
|
| +
|
| + virtual void CalculateContentsScale(float ideal_contents_scale,
|
| + float device_scale_factor,
|
| + float page_scale_factor,
|
| + float maximum_animation_contents_scale,
|
| + bool animating_transform_to_screen,
|
| + float* contents_scale_x,
|
| + float* contents_scale_y,
|
| + gfx::Size* content_bounds) OVERRIDE {
|
| + last_maximum_animation_contents_scale_ = maximum_animation_contents_scale;
|
| + LayerImpl::CalculateContentsScale(ideal_contents_scale,
|
| + device_scale_factor,
|
| + page_scale_factor,
|
| + maximum_animation_contents_scale,
|
| + animating_transform_to_screen,
|
| + contents_scale_x,
|
| + contents_scale_y,
|
| + content_bounds);
|
| + }
|
| +
|
| + float last_maximum_animation_contents_scale() {
|
| + return last_maximum_animation_contents_scale_;
|
| + }
|
| +
|
| + private:
|
| + explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
|
| + int id)
|
| + : LayerImpl(tree_impl, id), last_maximum_animation_contents_scale_(0.f) {
|
| + SetDrawsContent(true);
|
| + }
|
| +
|
| + float last_maximum_animation_contents_scale_;
|
| +};
|
| +
|
| +TEST_F(LayerTreeHostCommonTest, MaximumAnimationScaleFactor) {
|
| + FakeImplProxy proxy;
|
| + TestSharedBitmapManager shared_bitmap_manager;
|
| + FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
|
| + gfx::Transform identity_matrix;
|
| + scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_parent =
|
| + AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 1);
|
| + scoped_ptr<AnimationScaleFactorTrackingLayerImpl> parent =
|
| + AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 2);
|
| + scoped_ptr<AnimationScaleFactorTrackingLayerImpl> child =
|
| + AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 3);
|
| + scoped_ptr<AnimationScaleFactorTrackingLayerImpl> grand_child =
|
| + AnimationScaleFactorTrackingLayerImpl::Create(host_impl.active_tree(), 4);
|
| +
|
| + AnimationScaleFactorTrackingLayerImpl* parent_raw = parent.get();
|
| + AnimationScaleFactorTrackingLayerImpl* child_raw = child.get();
|
| + AnimationScaleFactorTrackingLayerImpl* grand_child_raw = grand_child.get();
|
| +
|
| + child->AddChild(grand_child.PassAs<LayerImpl>());
|
| + parent->AddChild(child.PassAs<LayerImpl>());
|
| + grand_parent->AddChild(parent.PassAs<LayerImpl>());
|
| +
|
| + SetLayerPropertiesForTesting(grand_parent.get(),
|
| + identity_matrix,
|
| + gfx::PointF(),
|
| + gfx::PointF(),
|
| + gfx::Size(1, 2),
|
| + true,
|
| + false);
|
| + SetLayerPropertiesForTesting(parent_raw,
|
| + identity_matrix,
|
| + gfx::PointF(),
|
| + gfx::PointF(),
|
| + gfx::Size(1, 2),
|
| + true,
|
| + false);
|
| + SetLayerPropertiesForTesting(child_raw,
|
| + identity_matrix,
|
| + gfx::PointF(),
|
| + gfx::PointF(),
|
| + gfx::Size(1, 2),
|
| + true,
|
| + false);
|
| + SetLayerPropertiesForTesting(grand_child_raw,
|
| + identity_matrix,
|
| + gfx::PointF(),
|
| + gfx::PointF(),
|
| + gfx::Size(1, 2),
|
| + true,
|
| + false);
|
| +
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // No layers have animations.
|
| + EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
|
| +
|
| + TransformOperations translation;
|
| + translation.AppendTranslate(1.f, 2.f, 3.f);
|
| +
|
| + AddAnimatedTransformToLayer(
|
| + parent_raw, 1.0, TransformOperations(), translation);
|
| +
|
| + // No layers have scale-affecting animations.
|
| + EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
|
| +
|
| + TransformOperations scale;
|
| + scale.AppendScale(5.f, 4.f, 3.f);
|
| +
|
| + AddAnimatedTransformToLayer(child_raw, 1.0, TransformOperations(), scale);
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // Only |child| has a scale-affecting animation.
|
| + EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(5.f, child_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(5.f, grand_child_raw->last_maximum_animation_contents_scale());
|
| +
|
| + AddAnimatedTransformToLayer(
|
| + grand_parent.get(), 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_contents_scale());
|
| + EXPECT_EQ(5.f, parent_raw->last_maximum_animation_contents_scale());
|
| + // 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_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
|
| +
|
| + AddAnimatedTransformToLayer(parent_raw, 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_contents_scale());
|
| + EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
|
| +
|
| + grand_parent->layer_animation_controller()->AbortAnimations(
|
| + Animation::Transform);
|
| + parent_raw->layer_animation_controller()->AbortAnimations(
|
| + Animation::Transform);
|
| + child_raw->layer_animation_controller()->AbortAnimations(
|
| + Animation::Transform);
|
| +
|
| + TransformOperations perspective;
|
| + perspective.AppendPerspective(10.f);
|
| +
|
| + AddAnimatedTransformToLayer(
|
| + child_raw, 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(0.f, grand_parent->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
|
| +
|
| + child_raw->layer_animation_controller()->AbortAnimations(
|
| + Animation::Transform);
|
| +
|
| + gfx::Transform scale_matrix;
|
| + scale_matrix.Scale(1.f, 2.f);
|
| + grand_parent->SetTransform(scale_matrix);
|
| + parent_raw->SetTransform(scale_matrix);
|
| + AddAnimatedTransformToLayer(parent_raw, 1.0, TransformOperations(), scale);
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // |grand_parent| and |parent| each have scale 2.f. |parent| has a scale
|
| + // animation with maximum scale 5.f.
|
| + EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(10.f, child_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(10.f, grand_child_raw->last_maximum_animation_contents_scale());
|
| +
|
| + gfx::Transform perspective_matrix;
|
| + perspective_matrix.ApplyPerspectiveDepth(2.f);
|
| + child_raw->SetTransform(perspective_matrix);
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // |child| has a transform that's neither a translation nor a scale.
|
| + EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(10.f, parent_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
|
| +
|
| + parent_raw->SetTransform(perspective_matrix);
|
| + ExecuteCalculateDrawProperties(grand_parent.get());
|
| +
|
| + // |parent| and |child| have transforms that are neither translations nor
|
| + // scales.
|
| + EXPECT_EQ(0.f, grand_parent->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
|
| +
|
| + parent_raw->SetTransform(identity_matrix);
|
| + child_raw->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_contents_scale());
|
| + EXPECT_EQ(0.f, parent_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, child_raw->last_maximum_animation_contents_scale());
|
| + EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_contents_scale());
|
| +}
|
| +
|
| } // namespace
|
| } // namespace cc
|
|
|