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

Side by Side Diff: cc/test/animation_test_common.cc

Issue 12517003: cc: Chromify the Animation and LayerAnimationController classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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
« no previous file with comments | « cc/test/animation_test_common.h ('k') | cc/test/fake_scrollbar_layer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "cc/test/animation_test_common.h" 5 #include "cc/test/animation_test_common.h"
6 6
7 #include "cc/keyframed_animation_curve.h" 7 #include "cc/keyframed_animation_curve.h"
8 #include "cc/layer.h" 8 #include "cc/layer.h"
9 #include "cc/layer_animation_controller.h" 9 #include "cc/layer_animation_controller.h"
10 #include "cc/layer_impl.h" 10 #include "cc/layer_impl.h"
11 #include "cc/transform_operations.h" 11 #include "cc/transform_operations.h"
12 12
13 using cc::Animation; 13 using cc::Animation;
14 using cc::AnimationCurve; 14 using cc::AnimationCurve;
15 using cc::EaseTimingFunction; 15 using cc::EaseTimingFunction;
16 using cc::FloatKeyframe; 16 using cc::FloatKeyframe;
17 using cc::KeyframedFloatAnimationCurve; 17 using cc::KeyframedFloatAnimationCurve;
18 using cc::KeyframedTransformAnimationCurve; 18 using cc::KeyframedTransformAnimationCurve;
19 using cc::TimingFunction; 19 using cc::TimingFunction;
20 using cc::TransformKeyframe; 20 using cc::TransformKeyframe;
21 21
22 namespace cc { 22 namespace cc {
23 23
24 static int nextAnimationId = 0; 24 static int nextAnimationId = 0;
25 25
26 template <class Target> 26 template <class Target>
27 int addOpacityTransition(Target& target, double duration, float startOpacity, fl oat endOpacity, bool useTimingFunction) 27 int addOpacityTransition(Target& target, double duration, float startOpacity, fl oat endOpacity, bool useTimingFunction)
28 { 28 {
29 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve: :create()); 29 scoped_ptr<KeyframedFloatAnimationCurve> curve(KeyframedFloatAnimationCurve: :Create());
30 30
31 scoped_ptr<TimingFunction> func; 31 scoped_ptr<TimingFunction> func;
32 if (!useTimingFunction) 32 if (!useTimingFunction)
33 func = EaseTimingFunction::create(); 33 func = EaseTimingFunction::create();
34 if (duration > 0) 34 if (duration > 0)
35 curve->addKeyframe(FloatKeyframe::create(0, startOpacity, func.Pass())); 35 curve->AddKeyframe(FloatKeyframe::Create(0, startOpacity, func.Pass()));
36 curve->addKeyframe(FloatKeyframe::create(duration, endOpacity, scoped_ptr<cc ::TimingFunction>())); 36 curve->AddKeyframe(FloatKeyframe::Create(duration, endOpacity, scoped_ptr<cc ::TimingFunction>()));
37 37
38 int id = nextAnimationId++; 38 int id = nextAnimationId++;
39 39
40 scoped_ptr<Animation> animation(Animation::create(curve.PassAs<AnimationCurv e>(), id, 0, Animation::Opacity)); 40 scoped_ptr<Animation> animation(Animation::Create(curve.PassAs<AnimationCurv e>(), id, 0, Animation::Opacity));
41 animation->setNeedsSynchronizedStartTime(true); 41 animation->set_needs_synchronized_start_time(true);
42 42
43 target.addAnimation(animation.Pass()); 43 target.AddAnimation(animation.Pass());
44 return id; 44 return id;
45 } 45 }
46 46
47 template <class Target> 47 template <class Target>
48 int addAnimatedTransform(Target& target, double duration, int deltaX, int deltaY ) 48 int addAnimatedTransform(Target& target, double duration, int deltaX, int deltaY )
49 { 49 {
50 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati onCurve::create()); 50 scoped_ptr<KeyframedTransformAnimationCurve> curve(KeyframedTransformAnimati onCurve::Create());
51 51
52 if (duration > 0) { 52 if (duration > 0) {
53 TransformOperations startOperations; 53 TransformOperations startOperations;
54 startOperations.AppendTranslate(deltaX, deltaY, 0); 54 startOperations.AppendTranslate(deltaX, deltaY, 0);
55 curve->addKeyframe(TransformKeyframe::create(0, startOperations, scoped_ ptr<cc::TimingFunction>())); 55 curve->AddKeyframe(TransformKeyframe::Create(0, startOperations, scoped_ ptr<cc::TimingFunction>()));
56 } 56 }
57 57
58 TransformOperations operations; 58 TransformOperations operations;
59 operations.AppendTranslate(deltaX, deltaY, 0); 59 operations.AppendTranslate(deltaX, deltaY, 0);
60 curve->addKeyframe(TransformKeyframe::create(duration, operations, scoped_pt r<cc::TimingFunction>())); 60 curve->AddKeyframe(TransformKeyframe::Create(duration, operations, scoped_pt r<cc::TimingFunction>()));
61 61
62 int id = nextAnimationId++; 62 int id = nextAnimationId++;
63 63
64 scoped_ptr<Animation> animation(Animation::create(curve.PassAs<AnimationCurv e>(), id, 0, Animation::Transform)); 64 scoped_ptr<Animation> animation(Animation::Create(curve.PassAs<AnimationCurv e>(), id, 0, Animation::Transform));
65 animation->setNeedsSynchronizedStartTime(true); 65 animation->set_needs_synchronized_start_time(true);
66 66
67 target.addAnimation(animation.Pass()); 67 target.AddAnimation(animation.Pass());
68 return id; 68 return id;
69 } 69 }
70 70
71 FakeFloatAnimationCurve::FakeFloatAnimationCurve() 71 FakeFloatAnimationCurve::FakeFloatAnimationCurve()
72 : m_duration(1) 72 : m_duration(1)
73 { 73 {
74 } 74 }
75 75
76 FakeFloatAnimationCurve::FakeFloatAnimationCurve(double duration) 76 FakeFloatAnimationCurve::FakeFloatAnimationCurve(double duration)
77 : m_duration(duration) 77 : m_duration(duration)
78 { 78 {
79 } 79 }
80 80
81 FakeFloatAnimationCurve::~FakeFloatAnimationCurve() 81 FakeFloatAnimationCurve::~FakeFloatAnimationCurve()
82 { 82 {
83 } 83 }
84 84
85 double FakeFloatAnimationCurve::duration() const 85 double FakeFloatAnimationCurve::Duration() const
86 { 86 {
87 return m_duration; 87 return m_duration;
88 } 88 }
89 89
90 float FakeFloatAnimationCurve::getValue(double now) const 90 float FakeFloatAnimationCurve::GetValue(double now) const
91 { 91 {
92 return 0; 92 return 0;
93 } 93 }
94 94
95 scoped_ptr<cc::AnimationCurve> FakeFloatAnimationCurve::clone() const 95 scoped_ptr<cc::AnimationCurve> FakeFloatAnimationCurve::Clone() const
96 { 96 {
97 return make_scoped_ptr(new FakeFloatAnimationCurve).PassAs<cc::AnimationCurv e>(); 97 return make_scoped_ptr(new FakeFloatAnimationCurve).PassAs<cc::AnimationCurv e>();
98 } 98 }
99 99
100 FakeTransformTransition::FakeTransformTransition(double duration) 100 FakeTransformTransition::FakeTransformTransition(double duration)
101 : m_duration(duration) 101 : m_duration(duration)
102 { 102 {
103 } 103 }
104 104
105 FakeTransformTransition::~FakeTransformTransition() 105 FakeTransformTransition::~FakeTransformTransition()
106 { 106 {
107 } 107 }
108 108
109 double FakeTransformTransition::duration() const 109 double FakeTransformTransition::Duration() const
110 { 110 {
111 return m_duration; 111 return m_duration;
112 } 112 }
113 113
114 gfx::Transform FakeTransformTransition::getValue(double time) const 114 gfx::Transform FakeTransformTransition::GetValue(double time) const
115 { 115 {
116 return gfx::Transform(); 116 return gfx::Transform();
117 } 117 }
118 118
119 scoped_ptr<cc::AnimationCurve> FakeTransformTransition::clone() const 119 scoped_ptr<cc::AnimationCurve> FakeTransformTransition::Clone() const
120 { 120 {
121 return make_scoped_ptr(new FakeTransformTransition(*this)).PassAs<cc::Animat ionCurve>(); 121 return make_scoped_ptr(new FakeTransformTransition(*this)).PassAs<cc::Animat ionCurve>();
122 } 122 }
123 123
124 124
125 FakeFloatTransition::FakeFloatTransition(double duration, float from, float to) 125 FakeFloatTransition::FakeFloatTransition(double duration, float from, float to)
126 : m_duration(duration) 126 : m_duration(duration)
127 , m_from(from) 127 , m_from(from)
128 , m_to(to) 128 , m_to(to)
129 { 129 {
130 } 130 }
131 131
132 FakeFloatTransition::~FakeFloatTransition() 132 FakeFloatTransition::~FakeFloatTransition()
133 { 133 {
134 } 134 }
135 135
136 double FakeFloatTransition::duration() const 136 double FakeFloatTransition::Duration() const
137 { 137 {
138 return m_duration; 138 return m_duration;
139 } 139 }
140 140
141 float FakeFloatTransition::getValue(double time) const 141 float FakeFloatTransition::GetValue(double time) const
142 { 142 {
143 time /= m_duration; 143 time /= m_duration;
144 if (time >= 1) 144 if (time >= 1)
145 time = 1; 145 time = 1;
146 return (1 - time) * m_from + time * m_to; 146 return (1 - time) * m_from + time * m_to;
147 } 147 }
148 148
149 FakeLayerAnimationValueObserver::FakeLayerAnimationValueObserver() 149 FakeLayerAnimationValueObserver::FakeLayerAnimationValueObserver()
150 : m_opacity(0) 150 : m_opacity(0)
151 { 151 {
(...skipping 11 matching lines...) Expand all
163 void FakeLayerAnimationValueObserver::OnTransformAnimated(const gfx::Transform& transform) 163 void FakeLayerAnimationValueObserver::OnTransformAnimated(const gfx::Transform& transform)
164 { 164 {
165 m_transform = transform; 165 m_transform = transform;
166 } 166 }
167 167
168 bool FakeLayerAnimationValueObserver::IsActive() const 168 bool FakeLayerAnimationValueObserver::IsActive() const
169 { 169 {
170 return true; 170 return true;
171 } 171 }
172 172
173 scoped_ptr<cc::AnimationCurve> FakeFloatTransition::clone() const 173 scoped_ptr<cc::AnimationCurve> FakeFloatTransition::Clone() const
174 { 174 {
175 return make_scoped_ptr(new FakeFloatTransition(*this)).PassAs<cc::AnimationC urve>(); 175 return make_scoped_ptr(new FakeFloatTransition(*this)).PassAs<cc::AnimationC urve>();
176 } 176 }
177 177
178 int addOpacityTransitionToController(cc::LayerAnimationController& controller, d ouble duration, float startOpacity, float endOpacity, bool useTimingFunction) 178 int addOpacityTransitionToController(cc::LayerAnimationController& controller, d ouble duration, float startOpacity, float endOpacity, bool useTimingFunction)
179 { 179 {
180 return addOpacityTransition(controller, duration, startOpacity, endOpacity, useTimingFunction); 180 return addOpacityTransition(controller, duration, startOpacity, endOpacity, useTimingFunction);
181 } 181 }
182 182
183 int addAnimatedTransformToController(cc::LayerAnimationController& controller, d ouble duration, int deltaX, int deltaY) 183 int addAnimatedTransformToController(cc::LayerAnimationController& controller, d ouble duration, int deltaX, int deltaY)
(...skipping 15 matching lines...) Expand all
199 { 199 {
200 return addAnimatedTransform(layer, duration, deltaX, deltaY); 200 return addAnimatedTransform(layer, duration, deltaX, deltaY);
201 } 201 }
202 202
203 int addAnimatedTransformToLayer(cc::LayerImpl& layer, double duration, int delta X, int deltaY) 203 int addAnimatedTransformToLayer(cc::LayerImpl& layer, double duration, int delta X, int deltaY)
204 { 204 {
205 return addAnimatedTransform(*layer.layerAnimationController(), duration, del taX, deltaY); 205 return addAnimatedTransform(*layer.layerAnimationController(), duration, del taX, deltaY);
206 } 206 }
207 207
208 } // namespace cc 208 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/animation_test_common.h ('k') | cc/test/fake_scrollbar_layer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698