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

Side by Side Diff: ui/gfx/compositor/layer_animation_sequence.cc

Issue 8247009: Explicit animation support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 2 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/gfx/compositor/layer_animation_sequence.h"
6
7 #include <algorithm>
8
9 #include "base/debug/trace_event.h"
10 #include "ui/gfx/compositor/layer_animation_delegate.h"
11 #include "ui/gfx/compositor/layer_animation_element.h"
12
13 namespace ui {
14
15 LayerAnimationSequence::LayerAnimationSequence()
16 : is_cyclic_(false),
17 last_element_(0) {
18 }
19
20 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element)
21 : is_cyclic_(false),
22 last_element_(0) {
23 AddElement(element);
24 }
25
26 LayerAnimationSequence::~LayerAnimationSequence() {
27 }
28
29 void LayerAnimationSequence::Progress(base::TimeDelta elapsed,
30 LayerAnimationDelegate* delegate) {
31 TRACE_EVENT0("LayerAnimationSequence", "Progress");
32 if (elements_.size() == 0 || duration_ == base::TimeDelta())
33 return;
34
35 // If delta = elapsed - last_start_ is huge, we can skip ahead by complete
36 // loops to save time.
37 base::TimeDelta delta = elapsed - last_start_;
38 int64 k = delta.ToInternalValue() / duration_.ToInternalValue() - 1;
39 if (k > 0) {
40 last_start_ += base::TimeDelta::FromInternalValue(
41 k * duration_.ToInternalValue());
42 }
43
44 size_t current_index = last_element_ % elements_.size();
45 while ((is_cyclic_ || last_element_ < elements_.size()) &&
46 (last_start_ + elements_[current_index]->duration() < elapsed)) {
47 // Let the element we're passing finish.
48 elements_[current_index]->Progress(1.0, delegate);
49 last_start_ += elements_[current_index]->duration();
50 ++last_element_;
51 current_index = last_element_ % elements_.size();
52 }
53
54 if (is_cyclic_ || last_element_ < elements_.size()) {
55 double t = 1.0;
56 if (elements_[current_index]->duration() > base::TimeDelta()) {
57 t = (elapsed - last_start_).InMillisecondsF() /
58 elements_[current_index]->duration().InMillisecondsF();
59 }
60 elements_[current_index]->Progress(t, delegate);
61 }
62
63 if (!is_cyclic_ && elapsed == duration_) {
64 last_element_ = 0;
65 last_start_ = base::TimeDelta::FromMilliseconds(0);
66 }
67 }
sky 2011/10/20 16:33:03 Do you want something like: if (is_cyclic_) last
68
69 void LayerAnimationSequence::Abort() {
70 while (last_element_ < elements_.size()) {
71 elements_[last_element_]->Abort();
72 ++last_element_;
73 }
74 last_element_ = 0;
75 last_start_ = base::TimeDelta::FromMilliseconds(0);
76 }
77
78 void LayerAnimationSequence::AddElement(LayerAnimationElement* element) {
79 // Update duration and properties.
80 duration_ += element->duration();
81 properties_.insert(element->properties().begin(),
82 element->properties().end());
83 elements_.push_back(element);
84 }
85
86 bool LayerAnimationSequence::HasCommonProperty(
87 const LayerAnimationElement::AnimatableProperties& other) const {
88 LayerAnimationElement::AnimatableProperties intersection;
89 std::insert_iterator<LayerAnimationElement::AnimatableProperties> ii(
90 intersection, intersection.begin());
91 std::set_intersection(properties_.begin(), properties_.end(),
92 other.begin(), other.end(),
93 ii);
94 return intersection.size() > 0;
95 }
96
97 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698