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

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

Issue 26880010: gfx: Add FrameTime and DisplayTime classes (Closed) Base URL: http://git.chromium.org/chromium/src.git@checkHighResNow4
Patch Set: WIP Created 7 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
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 "cc/animation/animation_id_provider.h" 11 #include "cc/animation/animation_id_provider.h"
12 #include "ui/compositor/layer_animation_delegate.h" 12 #include "ui/compositor/layer_animation_delegate.h"
13 #include "ui/compositor/layer_animation_element.h" 13 #include "ui/compositor/layer_animation_element.h"
14 #include "ui/compositor/layer_animation_observer.h" 14 #include "ui/compositor/layer_animation_observer.h"
15 #include "ui/gfx/frame_time.h"
15 16
16 namespace ui { 17 namespace ui {
17 18
18 LayerAnimationSequence::LayerAnimationSequence() 19 LayerAnimationSequence::LayerAnimationSequence()
19 : is_cyclic_(false), 20 : is_cyclic_(false),
20 last_element_(0), 21 last_element_(0),
21 waiting_for_group_start_(false), 22 waiting_for_group_start_(false),
22 animation_group_id_(0), 23 animation_group_id_(0),
23 last_progressed_fraction_(0.0), 24 last_progressed_fraction_(0.0),
24 weak_ptr_factory_(this) { 25 weak_ptr_factory_(this) {
25 } 26 }
26 27
27 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element) 28 LayerAnimationSequence::LayerAnimationSequence(LayerAnimationElement* element)
28 : is_cyclic_(false), 29 : is_cyclic_(false),
29 last_element_(0), 30 last_element_(0),
30 waiting_for_group_start_(false), 31 waiting_for_group_start_(false),
31 animation_group_id_(0), 32 animation_group_id_(0),
32 last_progressed_fraction_(0.0), 33 last_progressed_fraction_(0.0),
33 weak_ptr_factory_(this) { 34 weak_ptr_factory_(this) {
34 AddElement(element); 35 AddElement(element);
35 } 36 }
36 37
37 LayerAnimationSequence::~LayerAnimationSequence() { 38 LayerAnimationSequence::~LayerAnimationSequence() {
38 FOR_EACH_OBSERVER(LayerAnimationObserver, 39 FOR_EACH_OBSERVER(LayerAnimationObserver,
39 observers_, 40 observers_,
40 DetachedFromSequence(this, true)); 41 DetachedFromSequence(this, true));
41 } 42 }
42 43
43 void LayerAnimationSequence::Start(LayerAnimationDelegate* delegate) { 44 void LayerAnimationSequence::Start(LayerAnimationDelegate* delegate) {
44 DCHECK(start_time_ != base::TimeTicks()); 45 DCHECK(start_time_ != gfx::FrameTime());
45 last_progressed_fraction_ = 0.0; 46 last_progressed_fraction_ = 0.0;
46 if (elements_.empty()) 47 if (elements_.empty())
47 return; 48 return;
48 49
49 elements_[0]->set_requested_start_time(start_time_); 50 elements_[0]->set_requested_start_time(start_time_);
50 elements_[0]->Start(delegate, animation_group_id_); 51 elements_[0]->Start(delegate, animation_group_id_);
51 } 52 }
52 53
53 void LayerAnimationSequence::Progress(base::TimeTicks now, 54 void LayerAnimationSequence::Progress(gfx::FrameTime now,
54 LayerAnimationDelegate* delegate) { 55 LayerAnimationDelegate* delegate) {
55 DCHECK(start_time_ != base::TimeTicks()); 56 DCHECK(start_time_ != gfx::FrameTime());
56 bool redraw_required = false; 57 bool redraw_required = false;
57 58
58 if (elements_.empty()) 59 if (elements_.empty())
59 return; 60 return;
60 61
61 if (last_element_ == 0) 62 if (last_element_ == 0)
62 last_start_ = start_time_; 63 last_start_ = start_time_;
63 64
64 size_t current_index = last_element_ % elements_.size(); 65 size_t current_index = last_element_ % elements_.size();
65 base::TimeDelta element_duration; 66 base::TimeDelta element_duration;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 delegate->ScheduleDrawForAnimation(); 99 delegate->ScheduleDrawForAnimation();
99 100
100 if (!is_cyclic_ && last_element_ == elements_.size()) { 101 if (!is_cyclic_ && last_element_ == elements_.size()) {
101 last_element_ = 0; 102 last_element_ = 0;
102 waiting_for_group_start_ = false; 103 waiting_for_group_start_ = false;
103 animation_group_id_ = 0; 104 animation_group_id_ = 0;
104 NotifyEnded(); 105 NotifyEnded();
105 } 106 }
106 } 107 }
107 108
108 bool LayerAnimationSequence::IsFinished(base::TimeTicks time) { 109 bool LayerAnimationSequence::IsFinished(gfx::FrameTime time) {
109 if (is_cyclic_ || waiting_for_group_start_) 110 if (is_cyclic_ || waiting_for_group_start_)
110 return false; 111 return false;
111 112
112 if (elements_.empty()) 113 if (elements_.empty())
113 return true; 114 return true;
114 115
115 if (last_element_ == 0) 116 if (last_element_ == 0)
116 last_start_ = start_time_; 117 last_start_ = start_time_;
117 118
118 base::TimeTicks current_start = last_start_; 119 gfx::FrameTime current_start = last_start_;
119 size_t current_index = last_element_; 120 size_t current_index = last_element_;
120 base::TimeDelta element_duration; 121 base::TimeDelta element_duration;
121 while (current_index < elements_.size()) { 122 while (current_index < elements_.size()) {
122 elements_[current_index]->set_requested_start_time(current_start); 123 elements_[current_index]->set_requested_start_time(current_start);
123 if (!elements_[current_index]->IsFinished(time, &element_duration)) 124 if (!elements_[current_index]->IsFinished(time, &element_duration))
124 break; 125 break;
125 126
126 current_start += element_duration; 127 current_start += element_duration;
127 ++current_index; 128 ++current_index;
128 } 129 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 if (elements_.empty() || event.group_id != animation_group_id_) 219 if (elements_.empty() || event.group_id != animation_group_id_)
219 return; 220 return;
220 221
221 size_t current_index = last_element_ % elements_.size(); 222 size_t current_index = last_element_ % elements_.size();
222 const LayerAnimationElement::AnimatableProperties& element_properties = 223 const LayerAnimationElement::AnimatableProperties& element_properties =
223 elements_[current_index]->properties(); 224 elements_[current_index]->properties();
224 LayerAnimationElement::AnimatableProperty event_property = 225 LayerAnimationElement::AnimatableProperty event_property =
225 LayerAnimationElement::ToAnimatableProperty(event.target_property); 226 LayerAnimationElement::ToAnimatableProperty(event.target_property);
226 DCHECK(element_properties.find(event_property) != element_properties.end()); 227 DCHECK(element_properties.find(event_property) != element_properties.end());
227 elements_[current_index]->set_effective_start_time( 228 elements_[current_index]->set_effective_start_time(
228 base::TimeTicks::FromInternalValue( 229 gfx::FrameTime::Unsafe_FromSecondsF(event.monotonic_time));
229 event.monotonic_time * base::Time::kMicrosecondsPerSecond));
230 } 230 }
231 231
232 void LayerAnimationSequence::OnScheduled() { 232 void LayerAnimationSequence::OnScheduled() {
233 NotifyScheduled(); 233 NotifyScheduled();
234 } 234 }
235 235
236 void LayerAnimationSequence::OnAnimatorDestroyed() { 236 void LayerAnimationSequence::OnAnimatorDestroyed() {
237 if (observers_.might_have_observers()) { 237 if (observers_.might_have_observers()) {
238 ObserverListBase<LayerAnimationObserver>::Iterator it(observers_); 238 ObserverListBase<LayerAnimationObserver>::Iterator it(observers_);
239 LayerAnimationObserver* obs; 239 LayerAnimationObserver* obs;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 279
280 LayerAnimationElement* LayerAnimationSequence::CurrentElement() const { 280 LayerAnimationElement* LayerAnimationSequence::CurrentElement() const {
281 if (elements_.empty()) 281 if (elements_.empty())
282 return NULL; 282 return NULL;
283 283
284 size_t current_index = last_element_ % elements_.size(); 284 size_t current_index = last_element_ % elements_.size();
285 return elements_[current_index].get(); 285 return elements_[current_index].get();
286 } 286 }
287 287
288 } // namespace ui 288 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer_animation_sequence.h ('k') | ui/compositor/layer_animation_sequence_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698