Chromium Code Reviews| OLD | NEW |
|---|---|
| 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), | |
| 21 last_progressed_fraction_(0.0) { | |
| 20 } | 22 } |
| 21 | 23 |
| 22 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element) | 24 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element) |
| 23 : is_cyclic_(false), | 25 : is_cyclic_(false), |
| 24 last_element_(0) { | 26 last_element_(0), |
| 27 waiting_for_group_start_(false), | |
| 28 last_progressed_fraction_(0.0) { | |
| 25 AddElement(element); | 29 AddElement(element); |
| 26 } | 30 } |
| 27 | 31 |
| 28 LayerAnimationSequence::~LayerAnimationSequence() { | 32 LayerAnimationSequence::~LayerAnimationSequence() { |
| 29 FOR_EACH_OBSERVER(LayerAnimationObserver, | 33 FOR_EACH_OBSERVER(LayerAnimationObserver, |
| 30 observers_, | 34 observers_, |
| 31 DetachedFromSequence(this, true)); | 35 DetachedFromSequence(this, true)); |
| 32 } | 36 } |
| 33 | 37 |
| 38 void LayerAnimationSequence::ProgressToEffectiveStart( | |
| 39 LayerAnimationDelegate* delegate) { | |
| 40 if (elements_.empty()) | |
| 41 return; | |
| 42 | |
| 43 elements_[0]->set_animation_group_id(animation_group_id_); | |
| 44 elements_[0]->ProgressToEffectiveStart(delegate); | |
| 45 } | |
| 46 | |
| 34 void LayerAnimationSequence::Progress(base::TimeTicks now, | 47 void LayerAnimationSequence::Progress(base::TimeTicks now, |
| 35 LayerAnimationDelegate* delegate) { | 48 LayerAnimationDelegate* delegate) { |
|
Ian Vollick
2013/02/13 03:59:38
If we're waiting for group start, do we need to pr
ajuma
2013/02/13 23:28:18
No, in this case, we shouldn't even call Progress
| |
| 36 bool redraw_required = false; | 49 bool redraw_required = false; |
| 37 | 50 |
| 38 if (elements_.empty()) | 51 if (elements_.empty()) |
| 39 return; | 52 return; |
| 40 | 53 |
| 41 if (last_element_ == 0) | 54 if (last_element_ == 0) |
| 42 last_start_ = start_time_; | 55 last_start_ = start_time_; |
| 43 | 56 |
| 44 size_t current_index = last_element_ % elements_.size(); | 57 size_t current_index = last_element_ % elements_.size(); |
| 45 base::TimeDelta element_duration; | 58 base::TimeDelta element_duration; |
| 46 while (is_cyclic_ || last_element_ < elements_.size()) { | 59 while (is_cyclic_ || last_element_ < elements_.size()) { |
| 47 elements_[current_index]->set_start_time(last_start_); | 60 elements_[current_index]->set_requested_start_time(last_start_); |
| 61 elements_[current_index]->set_animation_group_id(animation_group_id_); | |
| 48 if (!elements_[current_index]->IsFinished(now, &element_duration)) | 62 if (!elements_[current_index]->IsFinished(now, &element_duration)) |
| 49 break; | 63 break; |
| 50 | 64 |
| 51 // Let the element we're passing finish. | 65 // Let the element we're passing finish. |
| 52 if (elements_[current_index]->Progress(now, delegate)) | 66 if (elements_[current_index]->Progress(now, delegate)) |
| 53 redraw_required = true; | 67 redraw_required = true; |
| 54 last_start_ += element_duration; | 68 last_start_ += element_duration; |
| 55 ++last_element_; | 69 ++last_element_; |
| 70 last_progressed_fraction_ = | |
| 71 elements_[current_index]->last_progressed_fraction(); | |
| 56 current_index = last_element_ % elements_.size(); | 72 current_index = last_element_ % elements_.size(); |
| 57 } | 73 } |
| 58 | 74 |
| 59 if (is_cyclic_ || last_element_ < elements_.size()) { | 75 if (is_cyclic_ || last_element_ < elements_.size()) { |
| 60 if (elements_[current_index]->Progress(now, delegate)) | 76 if (elements_[current_index]->Progress(now, delegate)) |
| 61 redraw_required = true; | 77 redraw_required = true; |
| 78 last_progressed_fraction_ = | |
| 79 elements_[current_index]->last_progressed_fraction(); | |
| 62 } | 80 } |
| 63 | 81 |
| 64 // Since the delegate may be deleted due to the notifications below, it is | 82 // Since the delegate may be deleted due to the notifications below, it is |
| 65 // important that we schedule a draw before sending them. | 83 // important that we schedule a draw before sending them. |
| 66 if (redraw_required) | 84 if (redraw_required) |
| 67 delegate->ScheduleDrawForAnimation(); | 85 delegate->ScheduleDrawForAnimation(); |
| 68 | 86 |
| 69 if (!is_cyclic_ && last_element_ == elements_.size()) { | 87 if (!is_cyclic_ && last_element_ == elements_.size()) { |
| 70 last_element_ = 0; | 88 last_element_ = 0; |
| 89 waiting_for_group_start_ = false; | |
| 71 NotifyEnded(); | 90 NotifyEnded(); |
| 72 } | 91 } |
| 73 } | 92 } |
| 74 | 93 |
| 75 bool LayerAnimationSequence::IsFinished(base::TimeTicks time) { | 94 bool LayerAnimationSequence::IsFinished(base::TimeTicks time) { |
| 76 if (is_cyclic_) | 95 if (is_cyclic_ || waiting_for_group_start_) |
| 77 return false; | 96 return false; |
| 78 | 97 |
| 79 if (elements_.empty()) | 98 if (elements_.empty()) |
| 80 return true; | 99 return true; |
| 81 | 100 |
| 82 if (last_element_ == 0) | 101 if (last_element_ == 0) |
| 83 last_start_ = start_time_; | 102 last_start_ = start_time_; |
| 84 | 103 |
| 85 base::TimeTicks current_start = last_start_; | 104 base::TimeTicks current_start = last_start_; |
| 86 size_t current_index = last_element_; | 105 size_t current_index = last_element_; |
| 87 base::TimeDelta element_duration; | 106 base::TimeDelta element_duration; |
| 88 while (current_index < elements_.size()) { | 107 while (current_index < elements_.size()) { |
| 89 elements_[current_index]->set_start_time(current_start); | 108 elements_[current_index]->set_requested_start_time(current_start); |
| 90 if (!elements_[current_index]->IsFinished(time, &element_duration)) | 109 if (!elements_[current_index]->IsFinished(time, &element_duration)) |
| 91 break; | 110 break; |
| 92 | 111 |
| 93 current_start += element_duration; | 112 current_start += element_duration; |
| 94 ++current_index; | 113 ++current_index; |
| 95 } | 114 } |
| 96 | 115 |
| 97 return (current_index == elements_.size()); | 116 return (current_index == elements_.size()); |
| 98 } | 117 } |
| 99 | 118 |
| 100 void LayerAnimationSequence::ProgressToEnd(LayerAnimationDelegate* delegate) { | 119 void LayerAnimationSequence::ProgressToEnd(LayerAnimationDelegate* delegate) { |
| 101 bool redraw_required = false; | 120 bool redraw_required = false; |
| 102 | 121 |
| 103 if (elements_.empty()) | 122 if (elements_.empty()) |
| 104 return; | 123 return; |
| 105 | 124 |
| 106 size_t current_index = last_element_ % elements_.size(); | 125 size_t current_index = last_element_ % elements_.size(); |
| 107 while (current_index < elements_.size()) { | 126 while (current_index < elements_.size()) { |
| 108 if (elements_[current_index]->ProgressToEnd(delegate)) | 127 if (elements_[current_index]->ProgressToEnd(delegate)) |
| 109 redraw_required = true; | 128 redraw_required = true; |
| 129 last_progressed_fraction_ = | |
| 130 elements_[current_index]->last_progressed_fraction(); | |
| 110 ++current_index; | 131 ++current_index; |
| 111 ++last_element_; | 132 ++last_element_; |
| 112 } | 133 } |
| 113 | 134 |
| 114 if (redraw_required) | 135 if (redraw_required) |
| 115 delegate->ScheduleDrawForAnimation(); | 136 delegate->ScheduleDrawForAnimation(); |
| 116 | 137 |
| 117 if (!is_cyclic_) { | 138 if (!is_cyclic_) { |
| 118 last_element_ = 0; | 139 last_element_ = 0; |
| 140 waiting_for_group_start_ = false; | |
| 119 NotifyEnded(); | 141 NotifyEnded(); |
| 120 } | 142 } |
| 121 } | 143 } |
| 122 | 144 |
| 123 void LayerAnimationSequence::GetTargetValue( | 145 void LayerAnimationSequence::GetTargetValue( |
| 124 LayerAnimationElement::TargetValue* target) const { | 146 LayerAnimationElement::TargetValue* target) const { |
| 125 if (is_cyclic_) | 147 if (is_cyclic_) |
| 126 return; | 148 return; |
| 127 | 149 |
| 128 for (size_t i = last_element_; i < elements_.size(); ++i) | 150 for (size_t i = last_element_; i < elements_.size(); ++i) |
| 129 elements_[i]->GetTargetValue(target); | 151 elements_[i]->GetTargetValue(target); |
| 130 } | 152 } |
| 131 | 153 |
| 132 void LayerAnimationSequence::Abort() { | 154 void LayerAnimationSequence::Abort(LayerAnimationDelegate* delegate) { |
| 133 size_t current_index = last_element_ % elements_.size(); | 155 size_t current_index = last_element_ % elements_.size(); |
| 134 while (current_index < elements_.size()) { | 156 while (current_index < elements_.size()) { |
| 135 elements_[current_index]->Abort(); | 157 elements_[current_index]->Abort(delegate); |
| 136 ++current_index; | 158 ++current_index; |
| 137 } | 159 } |
| 138 last_element_ = 0; | 160 last_element_ = 0; |
| 161 waiting_for_group_start_ = false; | |
| 139 NotifyAborted(); | 162 NotifyAborted(); |
| 140 } | 163 } |
| 141 | 164 |
| 142 void LayerAnimationSequence::AddElement(LayerAnimationElement* element) { | 165 void LayerAnimationSequence::AddElement(LayerAnimationElement* element) { |
| 143 properties_.insert(element->properties().begin(), | 166 properties_.insert(element->properties().begin(), |
| 144 element->properties().end()); | 167 element->properties().end()); |
| 145 elements_.push_back(make_linked_ptr(element)); | 168 elements_.push_back(make_linked_ptr(element)); |
|
Ian Vollick
2013/02/13 03:59:38
Since we early out in LayerAnimation::OnThreadedAn
ajuma
2013/02/13 23:28:18
Only sequences started by LayerAnimator::ScheduleT
| |
| 146 } | 169 } |
| 147 | 170 |
| 148 bool LayerAnimationSequence::HasCommonProperty( | 171 bool LayerAnimationSequence::HasCommonProperty( |
| 149 const LayerAnimationElement::AnimatableProperties& other) const { | 172 const LayerAnimationElement::AnimatableProperties& other) const { |
| 150 LayerAnimationElement::AnimatableProperties intersection; | 173 LayerAnimationElement::AnimatableProperties intersection; |
| 151 std::insert_iterator<LayerAnimationElement::AnimatableProperties> ii( | 174 std::insert_iterator<LayerAnimationElement::AnimatableProperties> ii( |
| 152 intersection, intersection.begin()); | 175 intersection, intersection.begin()); |
| 153 std::set_intersection(properties_.begin(), properties_.end(), | 176 std::set_intersection(properties_.begin(), properties_.end(), |
| 154 other.begin(), other.end(), | 177 other.begin(), other.end(), |
| 155 ii); | 178 ii); |
| 156 return intersection.size() > 0; | 179 return intersection.size() > 0; |
| 157 } | 180 } |
| 158 | 181 |
| 182 bool LayerAnimationSequence::IsFirstElementThreaded() const { | |
| 183 if (!elements_.empty()) | |
| 184 return elements_[0]->IsThreaded(); | |
| 185 | |
| 186 return false; | |
| 187 } | |
| 188 | |
| 159 void LayerAnimationSequence::AddObserver(LayerAnimationObserver* observer) { | 189 void LayerAnimationSequence::AddObserver(LayerAnimationObserver* observer) { |
| 160 if (!observers_.HasObserver(observer)) { | 190 if (!observers_.HasObserver(observer)) { |
| 161 observers_.AddObserver(observer); | 191 observers_.AddObserver(observer); |
| 162 observer->AttachedToSequence(this); | 192 observer->AttachedToSequence(this); |
| 163 } | 193 } |
| 164 } | 194 } |
| 165 | 195 |
| 166 void LayerAnimationSequence::RemoveObserver(LayerAnimationObserver* observer) { | 196 void LayerAnimationSequence::RemoveObserver(LayerAnimationObserver* observer) { |
| 167 observers_.RemoveObserver(observer); | 197 observers_.RemoveObserver(observer); |
| 168 observer->DetachedFromSequence(this, true); | 198 observer->DetachedFromSequence(this, true); |
| 169 } | 199 } |
| 170 | 200 |
| 201 void LayerAnimationSequence::OnThreadedAnimationStarted( | |
| 202 const cc::AnimationEvent& event) { | |
| 203 if (elements_.empty() || event.groupId != animation_group_id_) | |
| 204 return; | |
| 205 | |
| 206 size_t current_index = last_element_ % elements_.size(); | |
| 207 const LayerAnimationElement::AnimatableProperties& element_properties = | |
| 208 elements_[current_index]->properties(); | |
| 209 LayerAnimationElement::AnimatableProperty event_property = | |
| 210 LayerAnimationElement::ToAnimatableProperty(event.targetProperty); | |
| 211 DCHECK(element_properties.find(event_property) != element_properties.end()); | |
| 212 elements_[current_index]->set_effective_start_time( | |
| 213 base::TimeTicks::FromInternalValue( | |
| 214 event.monotonicTime * base::Time::kMicrosecondsPerSecond)); | |
| 215 } | |
| 216 | |
| 171 void LayerAnimationSequence::OnScheduled() { | 217 void LayerAnimationSequence::OnScheduled() { |
| 172 NotifyScheduled(); | 218 NotifyScheduled(); |
| 173 } | 219 } |
| 174 | 220 |
| 175 void LayerAnimationSequence::OnAnimatorDestroyed() { | 221 void LayerAnimationSequence::OnAnimatorDestroyed() { |
| 176 if (observers_.might_have_observers()) { | 222 if (observers_.might_have_observers()) { |
| 177 ObserverListBase<LayerAnimationObserver>::Iterator it(observers_); | 223 ObserverListBase<LayerAnimationObserver>::Iterator it(observers_); |
| 178 LayerAnimationObserver* obs; | 224 LayerAnimationObserver* obs; |
| 179 while ((obs = it.GetNext()) != NULL) { | 225 while ((obs = it.GetNext()) != NULL) { |
| 180 if (!obs->RequiresNotificationWhenAnimatorDestroyed()) { | 226 if (!obs->RequiresNotificationWhenAnimatorDestroyed()) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 198 OnLayerAnimationEnded(this)); | 244 OnLayerAnimationEnded(this)); |
| 199 } | 245 } |
| 200 | 246 |
| 201 void LayerAnimationSequence::NotifyAborted() { | 247 void LayerAnimationSequence::NotifyAborted() { |
| 202 FOR_EACH_OBSERVER(LayerAnimationObserver, | 248 FOR_EACH_OBSERVER(LayerAnimationObserver, |
| 203 observers_, | 249 observers_, |
| 204 OnLayerAnimationAborted(this)); | 250 OnLayerAnimationAborted(this)); |
| 205 } | 251 } |
| 206 | 252 |
| 207 } // namespace ui | 253 } // namespace ui |
| OLD | NEW |