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

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

Issue 11896017: Thread ui opacity animations (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Correctly deal with sequences meant to start together Created 7 years, 11 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_sequence.h" 5 #include "ui/compositor/layer_animation_sequence.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "ui/compositor/layer_animation_delegate.h" 11 #include "ui/compositor/layer_animation_delegate.h"
12 #include "ui/compositor/layer_animation_element.h" 12 #include "ui/compositor/layer_animation_element.h"
13 #include "ui/compositor/layer_animation_observer.h" 13 #include "ui/compositor/layer_animation_observer.h"
14 14
15 namespace ui { 15 namespace ui {
16 16
17 LayerAnimationSequence::LayerAnimationSequence() 17 LayerAnimationSequence::LayerAnimationSequence()
18 : is_cyclic_(false), 18 : is_cyclic_(false),
19 last_element_(0) { 19 last_element_(0),
20 waiting_for_group_start_(false) {
20 } 21 }
21 22
22 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element) 23 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element)
23 : is_cyclic_(false), 24 : is_cyclic_(false),
24 last_element_(0) { 25 last_element_(0),
26 waiting_for_group_start_(false) {
25 AddElement(element); 27 AddElement(element);
26 } 28 }
27 29
28 LayerAnimationSequence::~LayerAnimationSequence() { 30 LayerAnimationSequence::~LayerAnimationSequence() {
29 FOR_EACH_OBSERVER(LayerAnimationObserver, 31 FOR_EACH_OBSERVER(LayerAnimationObserver,
30 observers_, 32 observers_,
31 DetachedFromSequence(this, true)); 33 DetachedFromSequence(this, true));
32 } 34 }
33 35
36 void LayerAnimationSequence::ProgressToEffectiveStart(
37 LayerAnimationDelegate* delegate) {
38 if (elements_.empty())
39 return;
40
41 elements_[0]->ProgressToEffectiveStart(delegate);
42 }
43
34 void LayerAnimationSequence::Progress(base::TimeTicks now, 44 void LayerAnimationSequence::Progress(base::TimeTicks now,
35 LayerAnimationDelegate* delegate) { 45 LayerAnimationDelegate* delegate) {
36 bool redraw_required = false; 46 bool redraw_required = false;
37 47
38 if (elements_.empty()) 48 if (elements_.empty())
39 return; 49 return;
40 50
41 if (last_element_ == 0) 51 if (last_element_ == 0)
42 last_start_ = start_time_; 52 last_start_ = start_time_;
43 53
44 size_t current_index = last_element_ % elements_.size(); 54 size_t current_index = last_element_ % elements_.size();
45 base::TimeDelta element_duration; 55 base::TimeDelta element_duration;
46 while (is_cyclic_ || last_element_ < elements_.size()) { 56 while (is_cyclic_ || last_element_ < elements_.size()) {
47 elements_[current_index]->set_start_time(last_start_); 57 elements_[current_index]->set_requested_start_time(last_start_);
58 elements_[current_index]->set_animation_group_id(animation_group_id_);
48 if (!elements_[current_index]->IsFinished(now, &element_duration)) 59 if (!elements_[current_index]->IsFinished(now, &element_duration))
49 break; 60 break;
50 61
51 // Let the element we're passing finish. 62 // Let the element we're passing finish.
52 if (elements_[current_index]->Progress(now, delegate)) 63 if (elements_[current_index]->Progress(now, delegate))
53 redraw_required = true; 64 redraw_required = true;
54 last_start_ += element_duration; 65 last_start_ += element_duration;
55 ++last_element_; 66 ++last_element_;
56 current_index = last_element_ % elements_.size(); 67 current_index = last_element_ % elements_.size();
57 } 68 }
58 69
59 if (is_cyclic_ || last_element_ < elements_.size()) { 70 if (is_cyclic_ || last_element_ < elements_.size()) {
60 if (elements_[current_index]->Progress(now, delegate)) 71 if (elements_[current_index]->Progress(now, delegate))
61 redraw_required = true; 72 redraw_required = true;
62 } 73 }
63 74
64 // Since the delegate may be deleted due to the notifications below, it is 75 // Since the delegate may be deleted due to the notifications below, it is
65 // important that we schedule a draw before sending them. 76 // important that we schedule a draw before sending them.
66 if (redraw_required) 77 if (redraw_required)
67 delegate->ScheduleDrawForAnimation(); 78 delegate->ScheduleDrawForAnimation();
68 79
69 if (!is_cyclic_ && last_element_ == elements_.size()) { 80 if (!is_cyclic_ && last_element_ == elements_.size()) {
70 last_element_ = 0; 81 last_element_ = 0;
82 waiting_for_group_start_ = false;
71 NotifyEnded(); 83 NotifyEnded();
72 } 84 }
73 } 85 }
74 86
75 bool LayerAnimationSequence::IsFinished(base::TimeTicks time) { 87 bool LayerAnimationSequence::IsFinished(base::TimeTicks time) {
76 if (is_cyclic_) 88 if (is_cyclic_)
77 return false; 89 return false;
78 90
79 if (elements_.empty()) 91 if (elements_.empty())
80 return true; 92 return true;
81 93
82 if (last_element_ == 0) 94 if (last_element_ == 0)
83 last_start_ = start_time_; 95 last_start_ = start_time_;
84 96
85 base::TimeTicks current_start = last_start_; 97 base::TimeTicks current_start = last_start_;
86 size_t current_index = last_element_; 98 size_t current_index = last_element_;
87 base::TimeDelta element_duration; 99 base::TimeDelta element_duration;
88 while (current_index < elements_.size()) { 100 while (current_index < elements_.size()) {
89 elements_[current_index]->set_start_time(current_start); 101 elements_[current_index]->set_requested_start_time(current_start);
90 if (!elements_[current_index]->IsFinished(time, &element_duration)) 102 if (!elements_[current_index]->IsFinished(time, &element_duration))
91 break; 103 break;
92 104
93 current_start += element_duration; 105 current_start += element_duration;
94 ++current_index; 106 ++current_index;
95 } 107 }
96 108
97 return (current_index == elements_.size()); 109 return (current_index == elements_.size());
98 } 110 }
99 111
100 void LayerAnimationSequence::ProgressToEnd(LayerAnimationDelegate* delegate) { 112 void LayerAnimationSequence::ProgressToEnd(LayerAnimationDelegate* delegate) {
101 bool redraw_required = false; 113 bool redraw_required = false;
102 114
103 if (elements_.empty()) 115 if (elements_.empty())
104 return; 116 return;
105 117
106 size_t current_index = last_element_ % elements_.size(); 118 size_t current_index = last_element_ % elements_.size();
107 while (current_index < elements_.size()) { 119 while (current_index < elements_.size()) {
108 if (elements_[current_index]->ProgressToEnd(delegate)) 120 if (elements_[current_index]->ProgressToEnd(delegate))
109 redraw_required = true; 121 redraw_required = true;
110 ++current_index; 122 ++current_index;
111 ++last_element_; 123 ++last_element_;
112 } 124 }
113 125
114 if (redraw_required) 126 if (redraw_required)
115 delegate->ScheduleDrawForAnimation(); 127 delegate->ScheduleDrawForAnimation();
116 128
117 if (!is_cyclic_) { 129 if (!is_cyclic_) {
118 last_element_ = 0; 130 last_element_ = 0;
131 waiting_for_group_start_ = false;
119 NotifyEnded(); 132 NotifyEnded();
120 } 133 }
121 } 134 }
122 135
123 void LayerAnimationSequence::GetTargetValue( 136 void LayerAnimationSequence::GetTargetValue(
124 LayerAnimationElement::TargetValue* target) const { 137 LayerAnimationElement::TargetValue* target) const {
125 if (is_cyclic_) 138 if (is_cyclic_)
126 return; 139 return;
127 140
128 for (size_t i = last_element_; i < elements_.size(); ++i) 141 for (size_t i = last_element_; i < elements_.size(); ++i)
129 elements_[i]->GetTargetValue(target); 142 elements_[i]->GetTargetValue(target);
130 } 143 }
131 144
132 void LayerAnimationSequence::Abort() { 145 void LayerAnimationSequence::Abort(LayerAnimationDelegate* delegate) {
133 size_t current_index = last_element_ % elements_.size(); 146 size_t current_index = last_element_ % elements_.size();
134 while (current_index < elements_.size()) { 147 while (current_index < elements_.size()) {
135 elements_[current_index]->Abort(); 148 elements_[current_index]->Abort(delegate);
136 ++current_index; 149 ++current_index;
137 } 150 }
138 last_element_ = 0; 151 last_element_ = 0;
152 waiting_for_group_start_ = false;
139 NotifyAborted(); 153 NotifyAborted();
140 } 154 }
141 155
142 void LayerAnimationSequence::AddElement(LayerAnimationElement* element) { 156 void LayerAnimationSequence::AddElement(LayerAnimationElement* element) {
143 properties_.insert(element->properties().begin(), 157 properties_.insert(element->properties().begin(),
144 element->properties().end()); 158 element->properties().end());
145 elements_.push_back(make_linked_ptr(element)); 159 elements_.push_back(make_linked_ptr(element));
146 } 160 }
147 161
148 bool LayerAnimationSequence::HasCommonProperty( 162 bool LayerAnimationSequence::HasCommonProperty(
149 const LayerAnimationElement::AnimatableProperties& other) const { 163 const LayerAnimationElement::AnimatableProperties& other) const {
150 LayerAnimationElement::AnimatableProperties intersection; 164 LayerAnimationElement::AnimatableProperties intersection;
151 std::insert_iterator<LayerAnimationElement::AnimatableProperties> ii( 165 std::insert_iterator<LayerAnimationElement::AnimatableProperties> ii(
152 intersection, intersection.begin()); 166 intersection, intersection.begin());
153 std::set_intersection(properties_.begin(), properties_.end(), 167 std::set_intersection(properties_.begin(), properties_.end(),
154 other.begin(), other.end(), 168 other.begin(), other.end(),
155 ii); 169 ii);
156 return intersection.size() > 0; 170 return intersection.size() > 0;
157 } 171 }
158 172
173 bool LayerAnimationSequence::IsFirstElementThreaded() const {
174 if (!elements_.empty())
175 return elements_[0]->IsThreaded();
176
177 return false;
178 }
179
159 void LayerAnimationSequence::AddObserver(LayerAnimationObserver* observer) { 180 void LayerAnimationSequence::AddObserver(LayerAnimationObserver* observer) {
160 if (!observers_.HasObserver(observer)) { 181 if (!observers_.HasObserver(observer)) {
161 observers_.AddObserver(observer); 182 observers_.AddObserver(observer);
162 observer->AttachedToSequence(this); 183 observer->AttachedToSequence(this);
163 } 184 }
164 } 185 }
165 186
166 void LayerAnimationSequence::RemoveObserver(LayerAnimationObserver* observer) { 187 void LayerAnimationSequence::RemoveObserver(LayerAnimationObserver* observer) {
167 observers_.RemoveObserver(observer); 188 observers_.RemoveObserver(observer);
168 observer->DetachedFromSequence(this, true); 189 observer->DetachedFromSequence(this, true);
169 } 190 }
170 191
192 void LayerAnimationSequence::OnThreadedAnimationStarted(
193 const cc::AnimationEvent& event) {
194 if (elements_.empty() || event.groupId != animation_group_id_)
195 return;
Ian Vollick 2013/01/25 15:11:47 Can you add some DCHECKs that we do find the thing
ajuma 2013/01/29 18:31:23 DCHECK added.
196
197 size_t current_index = last_element_ % elements_.size();
198 const LayerAnimationElement::AnimatableProperties& element_properties =
199 elements_[current_index]->properties();
200 LayerAnimationElement::AnimatableProperty event_property =
201 LayerAnimationElement::ToAnimatableProperty(event.targetProperty);
202 if (element_properties.find(event_property) != element_properties.end()) {
203 elements_[current_index]->set_effective_start_time(
204 base::TimeTicks::FromInternalValue(
205 event.monotonicTime * base::Time::kMicrosecondsPerSecond));
206 }
207 }
208
171 void LayerAnimationSequence::OnScheduled() { 209 void LayerAnimationSequence::OnScheduled() {
172 NotifyScheduled(); 210 NotifyScheduled();
173 } 211 }
174 212
175 void LayerAnimationSequence::OnAnimatorDestroyed() { 213 void LayerAnimationSequence::OnAnimatorDestroyed() {
176 if (observers_.might_have_observers()) { 214 if (observers_.might_have_observers()) {
177 ObserverListBase<LayerAnimationObserver>::Iterator it(observers_); 215 ObserverListBase<LayerAnimationObserver>::Iterator it(observers_);
178 LayerAnimationObserver* obs; 216 LayerAnimationObserver* obs;
179 while ((obs = it.GetNext()) != NULL) { 217 while ((obs = it.GetNext()) != NULL) {
180 if (!obs->RequiresNotificationWhenAnimatorDestroyed()) { 218 if (!obs->RequiresNotificationWhenAnimatorDestroyed()) {
(...skipping 17 matching lines...) Expand all
198 OnLayerAnimationEnded(this)); 236 OnLayerAnimationEnded(this));
199 } 237 }
200 238
201 void LayerAnimationSequence::NotifyAborted() { 239 void LayerAnimationSequence::NotifyAborted() {
202 FOR_EACH_OBSERVER(LayerAnimationObserver, 240 FOR_EACH_OBSERVER(LayerAnimationObserver,
203 observers_, 241 observers_,
204 OnLayerAnimationAborted(this)); 242 OnLayerAnimationAborted(this));
205 } 243 }
206 244
207 } // namespace ui 245 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698