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

Side by Side Diff: ui/compositor/layer_animation_element_unittest.cc

Issue 22861008: Add support for inverse transform animations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add support for inverse transform animations. Created 7 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/compositor/layer_animation_element.h" 5 #include "ui/compositor/layer_animation_element.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/compositor/layer_animation_delegate.h" 12 #include "ui/compositor/layer_animation_delegate.h"
13 #include "ui/compositor/test/test_layer_animation_delegate.h" 13 #include "ui/compositor/test/test_layer_animation_delegate.h"
14 #include "ui/compositor/test/test_utils.h" 14 #include "ui/compositor/test/test_utils.h"
15 #include "ui/gfx/rect.h" 15 #include "ui/gfx/rect.h"
16 #include "ui/gfx/transform.h" 16 #include "ui/gfx/transform.h"
17 17
18 namespace ui { 18 namespace ui {
19 19
20 namespace { 20 namespace {
21 21
22 // Check that the transformation element progresses the delegate as expected and 22 // Check that the transformation element progresses the delegate as expected and
23 // that the element can be reused after it completes. 23 // that the element can be reused after it completes.
24 TEST(LayerAnimationElementTest, TransformElement) { 24 TEST(LayerAnimationElementTest, TransformElement) {
25 TestLayerAnimationDelegate delegate; 25 TestLayerAnimationDelegate delegate;
26 gfx::Transform start_transform, target_transform, middle_transform; 26 gfx::Transform start_transform, target_transform;
27 start_transform.Rotate(-30.0); 27 start_transform.Rotate(-30.0);
28 target_transform.Rotate(30.0); 28 target_transform.Rotate(30.0);
29 base::TimeTicks start_time; 29 base::TimeTicks start_time;
30 base::TimeTicks effective_start_time; 30 base::TimeTicks effective_start_time;
31 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 31 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
32 32
33 scoped_ptr<LayerAnimationElement> element( 33 scoped_ptr<LayerAnimationElement> element(
34 LayerAnimationElement::CreateTransformElement(target_transform, delta)); 34 LayerAnimationElement::CreateTransformElement(target_transform, delta));
35 element->set_animation_group_id(1); 35 element->set_animation_group_id(1);
36 36
(...skipping 21 matching lines...) Expand all
58 EXPECT_FLOAT_EQ(1.0, element->last_progressed_fraction()); 58 EXPECT_FLOAT_EQ(1.0, element->last_progressed_fraction());
59 CheckApproximatelyEqual(target_transform, 59 CheckApproximatelyEqual(target_transform,
60 delegate.GetTransformForAnimation()); 60 delegate.GetTransformForAnimation());
61 } 61 }
62 62
63 LayerAnimationElement::TargetValue target_value(&delegate); 63 LayerAnimationElement::TargetValue target_value(&delegate);
64 element->GetTargetValue(&target_value); 64 element->GetTargetValue(&target_value);
65 CheckApproximatelyEqual(target_transform, target_value.transform); 65 CheckApproximatelyEqual(target_transform, target_value.transform);
66 } 66 }
67 67
68 // Checks that the equation Child_start * Parent_start = Child_current *
69 // Parent_current is true.
70 TEST(LayerAnimationElementTest, CounterTransformElement) {
71 TestLayerAnimationDelegate delegate, parent_delegate;
72 gfx::Transform parent_start, parent_target;
73 parent_start.Scale(0.5, 3);
74 parent_start.Translate(-20, 30);
75 parent_target.Translate(0, 100);
76
77 gfx::Transform child_transform;
78 child_transform.Rotate(-30.0);
79
80 const gfx::Transform effective_child_transform =
81 child_transform * parent_start;
82
83 base::TimeTicks start_time;
84 base::TimeTicks now;
85 base::TimeDelta duration = base::TimeDelta::FromSeconds(1);
86
87 start_time += 5 * duration;
88 scoped_ptr<LayerAnimationElement> element(
89 LayerAnimationElement::CreateInverseTransformElement(parent_start,
90 parent_target,
91 duration));
92 element->set_animation_group_id(1);
93 scoped_ptr<LayerAnimationElement> parent_element(
94 LayerAnimationElement::CreateTransformElement(parent_target, duration));
95
96 parent_delegate.SetTransformFromAnimation(parent_start);
97 delegate.SetTransformFromAnimation(child_transform);
98
99 parent_element->set_requested_start_time(start_time);
100 parent_element->Start(&parent_delegate, 1);
101 parent_element->set_effective_start_time(start_time);
102 parent_element->Progress(start_time, &parent_delegate);
103
104 element->set_requested_start_time(start_time);
105 element->Start(&delegate, 1);
106 element->set_effective_start_time(start_time);
107 element->Progress(start_time, &delegate);
108 CheckApproximatelyEqual(effective_child_transform,
109 delegate.GetTransformForAnimation() *
110 parent_delegate.GetTransformForAnimation());
111 const int steps = 1000;
112 now = start_time;
113 for (int i = 0; i != steps; ++i) {
114 now += duration/steps;
115 parent_element->Progress(start_time, &parent_delegate);
116 element->Progress(start_time, &delegate);
117 CheckApproximatelyEqual(effective_child_transform,
118 delegate.GetTransformForAnimation() *
ajuma 2013/08/20 15:32:41 For threaded animations, the delegate won't actual
avallee 2013/08/22 22:21:59 Moved this test to a new test file for the transfo
119 parent_delegate.GetTransformForAnimation());
120 }
121 }
122
68 // Check that the bounds element progresses the delegate as expected and 123 // Check that the bounds element progresses the delegate as expected and
69 // that the element can be reused after it completes. 124 // that the element can be reused after it completes.
70 TEST(LayerAnimationElementTest, BoundsElement) { 125 TEST(LayerAnimationElementTest, BoundsElement) {
71 TestLayerAnimationDelegate delegate; 126 TestLayerAnimationDelegate delegate;
72 gfx::Rect start, target, middle; 127 gfx::Rect start, target, middle;
73 start = target = middle = gfx::Rect(0, 0, 50, 50); 128 start = target = middle = gfx::Rect(0, 0, 50, 50);
74 start.set_x(-90); 129 start.set_x(-90);
75 target.set_x(90); 130 target.set_x(90);
76 base::TimeTicks start_time; 131 base::TimeTicks start_time;
77 base::TimeDelta delta = base::TimeDelta::FromSeconds(1); 132 base::TimeDelta delta = base::TimeDelta::FromSeconds(1);
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 element->Abort(&delegate); 420 element->Abort(&delegate);
366 target_transform.Blend(start_transform, 421 target_transform.Blend(start_transform,
367 Tween::CalculateValue(tween_type, 0.5)); 422 Tween::CalculateValue(tween_type, 0.5));
368 CheckApproximatelyEqual(target_transform, 423 CheckApproximatelyEqual(target_transform,
369 delegate.GetTransformForAnimation()); 424 delegate.GetTransformForAnimation());
370 } 425 }
371 426
372 } // namespace 427 } // namespace
373 428
374 } // namespace ui 429 } // namespace ui
OLDNEW
« ui/compositor/layer_animation_element.cc ('K') | « ui/compositor/layer_animation_element.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698