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

Unified 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 side-by-side diff with in-line comments
Download patch
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..293f4829caf292aab4289238314dca78aa825c9b 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,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_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;
+ LayerImpl::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_;
+ }
+
+ private:
+ explicit AnimationScaleFactorTrackingLayerImpl(LayerTreeImpl* tree_impl,
+ int id)
+ : LayerImpl(tree_impl, id), last_maximum_animation_scale_factor_(0.f) {
+ SetDrawsContent(true);
+ }
+
+ float last_maximum_animation_scale_factor_;
+};
+
+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_scale_factor());
+ EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
+
+ 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_scale_factor());
+ EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
+
+ 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_scale_factor());
+ EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(5.f, child_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(5.f, grand_child_raw->last_maximum_animation_scale_factor());
+
+ 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_scale_factor());
+ EXPECT_EQ(5.f, parent_raw->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_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
+
+ 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_scale_factor());
+ EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
+
+ 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_scale_factor());
+ EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
+
+ 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_scale_factor());
+ EXPECT_EQ(10.f, parent_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(10.f, child_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(10.f, grand_child_raw->last_maximum_animation_scale_factor());
+
+ 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_scale_factor());
+ EXPECT_EQ(10.f, parent_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
+
+ 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_scale_factor());
+ EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
+
+ 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_scale_factor());
+ EXPECT_EQ(0.f, parent_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, child_raw->last_maximum_animation_scale_factor());
+ EXPECT_EQ(0.f, grand_child_raw->last_maximum_animation_scale_factor());
+}
+
} // namespace
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698