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

Side by Side Diff: cc/animation/animation.cc

Issue 220403002: Revert "Handle direction control in compositor Animations" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/animation/animation.h ('k') | cc/animation/animation_unittest.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/animation/animation.h" 5 #include "cc/animation/animation.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 int animation_id, 58 int animation_id,
59 int group_id, 59 int group_id,
60 TargetProperty target_property) 60 TargetProperty target_property)
61 : curve_(curve.Pass()), 61 : curve_(curve.Pass()),
62 id_(animation_id), 62 id_(animation_id),
63 group_(group_id), 63 group_(group_id),
64 target_property_(target_property), 64 target_property_(target_property),
65 run_state_(WaitingForTargetAvailability), 65 run_state_(WaitingForTargetAvailability),
66 iterations_(1), 66 iterations_(1),
67 start_time_(0), 67 start_time_(0),
68 direction_(Normal), 68 alternates_direction_(false),
69 time_offset_(0), 69 time_offset_(0),
70 needs_synchronized_start_time_(false), 70 needs_synchronized_start_time_(false),
71 received_finished_event_(false), 71 received_finished_event_(false),
72 suspended_(false), 72 suspended_(false),
73 pause_time_(0), 73 pause_time_(0),
74 total_paused_time_(0), 74 total_paused_time_(0),
75 is_controlling_instance_(false), 75 is_controlling_instance_(false),
76 is_impl_only_(false) {} 76 is_impl_only_(false) {}
77 77
78 Animation::~Animation() { 78 Animation::~Animation() {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // Returned time should always be relative to the start time and should 166 // Returned time should always be relative to the start time and should
167 // subtract all time spent paused. 167 // subtract all time spent paused.
168 trimmed -= start_time_ + total_paused_time_; 168 trimmed -= start_time_ + total_paused_time_;
169 169
170 // If we're just starting or we're waiting on receiving a start time, 170 // If we're just starting or we're waiting on receiving a start time,
171 // time is 'stuck' at the initial state. 171 // time is 'stuck' at the initial state.
172 if ((run_state_ == Starting && !has_set_start_time()) || 172 if ((run_state_ == Starting && !has_set_start_time()) ||
173 needs_synchronized_start_time()) 173 needs_synchronized_start_time())
174 trimmed = time_offset_; 174 trimmed = time_offset_;
175 175
176 // Return 0 if we are before the start of the animation 176 // Zero is always the start of the animation.
177 if (trimmed < 0) 177 if (trimmed <= 0)
178 return 0; 178 return 0;
179 179
180 // Always return zero if we have no iterations. 180 // Always return zero if we have no iterations.
181 if (!iterations_) 181 if (!iterations_)
182 return 0; 182 return 0;
183 183
184 // Don't attempt to trim if we have no duration. 184 // Don't attempt to trim if we have no duration.
185 if (curve_->Duration() <= 0) 185 if (curve_->Duration() <= 0)
186 return 0; 186 return 0;
187 187
188 // check if we are past active interval 188 // If less than an iteration duration, just return trimmed.
189 bool is_past_total_duration = 189 if (trimmed < curve_->Duration())
190 (iterations_ > 0 && trimmed >= curve_->Duration() * iterations_); 190 return trimmed;
191
192 // If greater than or equal to the total duration, return iteration duration.
193 if (iterations_ >= 0 && trimmed >= curve_->Duration() * iterations_) {
194 if (alternates_direction_ && !(iterations_ % 2))
195 return 0;
196 return curve_->Duration();
197 }
191 198
192 // We need to know the current iteration if we're alternating. 199 // We need to know the current iteration if we're alternating.
193 int iteration = 0; 200 int iteration = static_cast<int>(trimmed / curve_->Duration());
194 201
195 // If we are past the active interval, return iteration duration. 202 // Calculate x where trimmed = x + n * curve_->Duration() for some positive
196 if (is_past_total_duration) { 203 // integer n.
197 iteration = iterations_; 204 trimmed = fmod(trimmed, curve_->Duration());
198 trimmed = curve_->Duration();
199 } else {
200 iteration = static_cast<int>(trimmed / curve_->Duration());
201 // Calculate x where trimmed = x + n * curve_->Duration() for some positive
202 // integer n.
203 trimmed = fmod(trimmed, curve_->Duration());
204 }
205 205
206 // check if we are running the animation in reverse direction for the current 206 // If we're alternating and on an odd iteration, reverse the direction.
207 // iteration 207 if (alternates_direction_ && iteration % 2 == 1)
208 bool reverse = (direction_ == Reverse) ||
209 (direction_ == Alternate && iteration % 2 == 1) ||
210 (direction_ == AlternateReverse && iteration % 2 == 0);
211
212 // if we are running the animation in reverse direction, reverse the result
213 if (reverse)
214 return curve_->Duration() - trimmed; 208 return curve_->Duration() - trimmed;
215 209
216 return trimmed; 210 return trimmed;
217 } 211 }
218 212
219 scoped_ptr<Animation> Animation::Clone() const { 213 scoped_ptr<Animation> Animation::Clone() const {
220 return CloneAndInitialize(run_state_, start_time_); 214 return CloneAndInitialize(run_state_, start_time_);
221 } 215 }
222 216
223 scoped_ptr<Animation> Animation::CloneAndInitialize(RunState initial_run_state, 217 scoped_ptr<Animation> Animation::CloneAndInitialize(RunState initial_run_state,
224 double start_time) const { 218 double start_time) const {
225 scoped_ptr<Animation> to_return( 219 scoped_ptr<Animation> to_return(
226 new Animation(curve_->Clone(), id_, group_, target_property_)); 220 new Animation(curve_->Clone(), id_, group_, target_property_));
227 to_return->run_state_ = initial_run_state; 221 to_return->run_state_ = initial_run_state;
228 to_return->iterations_ = iterations_; 222 to_return->iterations_ = iterations_;
229 to_return->start_time_ = start_time; 223 to_return->start_time_ = start_time;
230 to_return->pause_time_ = pause_time_; 224 to_return->pause_time_ = pause_time_;
231 to_return->total_paused_time_ = total_paused_time_; 225 to_return->total_paused_time_ = total_paused_time_;
232 to_return->time_offset_ = time_offset_; 226 to_return->time_offset_ = time_offset_;
233 to_return->direction_ = direction_; 227 to_return->alternates_direction_ = alternates_direction_;
234 DCHECK(!to_return->is_controlling_instance_); 228 DCHECK(!to_return->is_controlling_instance_);
235 to_return->is_controlling_instance_ = true; 229 to_return->is_controlling_instance_ = true;
236 return to_return.Pass(); 230 return to_return.Pass();
237 } 231 }
238 232
239 void Animation::PushPropertiesTo(Animation* other) const { 233 void Animation::PushPropertiesTo(Animation* other) const {
240 // Currently, we only push changes due to pausing and resuming animations on 234 // Currently, we only push changes due to pausing and resuming animations on
241 // the main thread. 235 // the main thread.
242 if (run_state_ == Animation::Paused || 236 if (run_state_ == Animation::Paused ||
243 other->run_state_ == Animation::Paused) { 237 other->run_state_ == Animation::Paused) {
244 other->run_state_ = run_state_; 238 other->run_state_ = run_state_;
245 other->pause_time_ = pause_time_; 239 other->pause_time_ = pause_time_;
246 other->total_paused_time_ = total_paused_time_; 240 other->total_paused_time_ = total_paused_time_;
247 } 241 }
248 } 242 }
249 243
250 } // namespace cc 244 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/animation.h ('k') | cc/animation/animation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698