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

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: Fix VS2010 Created 9 years, 1 month 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 #include <iterator>
9
10 #include "base/debug/trace_event.h"
11 #include "ui/gfx/compositor/layer_animation_delegate.h"
12 #include "ui/gfx/compositor/layer_animation_element.h"
13
14 namespace ui {
15
16 LayerAnimationSequence::LayerAnimationSequence()
17 : is_cyclic_(false),
18 last_element_(0) {
19 }
20
21 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element)
22 : is_cyclic_(false),
23 last_element_(0) {
24 AddElement(element);
25 }
26
27 LayerAnimationSequence::~LayerAnimationSequence() {
28 }
29
30 void LayerAnimationSequence::Progress(base::TimeDelta elapsed,
31 LayerAnimationDelegate* delegate) {
32 TRACE_EVENT0("LayerAnimationSequence", "Progress");
33 if (elements_.size() == 0 || duration_ == base::TimeDelta())
34 return;
35
36 if (is_cyclic_) {
37 // If delta = elapsed - last_start_ is huge, we can skip ahead by complete
38 // loops to save time.
39 base::TimeDelta delta = elapsed - last_start_;
40 int64 k = delta.ToInternalValue() / duration_.ToInternalValue() - 1;
41 if (k > 0) {
42 last_start_ += base::TimeDelta::FromInternalValue(
43 k * duration_.ToInternalValue());
44 }
45 }
46
47 size_t current_index = last_element_ % elements_.size();
48 while ((is_cyclic_ || last_element_ < elements_.size()) &&
49 (last_start_ + elements_[current_index]->duration() < elapsed)) {
50 // Let the element we're passing finish.
51 elements_[current_index]->Progress(1.0, delegate);
52 last_start_ += elements_[current_index]->duration();
53 ++last_element_;
54 current_index = last_element_ % elements_.size();
55 }
56
57 if (is_cyclic_ || last_element_ < elements_.size()) {
58 double t = 1.0;
59 if (elements_[current_index]->duration() > base::TimeDelta()) {
60 t = (elapsed - last_start_).InMillisecondsF() /
61 elements_[current_index]->duration().InMillisecondsF();
62 }
63 elements_[current_index]->Progress(t, delegate);
64 }
65
66 if (!is_cyclic_ && elapsed == duration_) {
67 last_element_ = 0;
68 last_start_ = base::TimeDelta::FromMilliseconds(0);
69 }
70 }
71
72 void LayerAnimationSequence::Abort() {
73 size_t current_index = last_element_ % elements_.size();
74 while (current_index < elements_.size()) {
75 elements_[current_index]->Abort();
76 ++current_index;
77 }
78 last_element_ = 0;
79 last_start_ = base::TimeDelta::FromMilliseconds(0);
80 }
81
82 void LayerAnimationSequence::AddElement(LayerAnimationElement* element) {
83 // Update duration and properties.
84 duration_ += element->duration();
85 properties_.insert(element->properties().begin(),
86 element->properties().end());
87 elements_.push_back(make_linked_ptr(element));
88 }
89
90 bool LayerAnimationSequence::HasCommonProperty(
91 const LayerAnimationElement::AnimatableProperties& other) const {
92 LayerAnimationElement::AnimatableProperties intersection;
93 std::insert_iterator<LayerAnimationElement::AnimatableProperties> ii(
94 intersection, intersection.begin());
95 std::set_intersection(properties_.begin(), properties_.end(),
96 other.begin(), other.end(),
97 ii);
98 return intersection.size() > 0;
99 }
100
101 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/compositor/layer_animation_sequence.h ('k') | ui/gfx/compositor/layer_animation_sequence_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698