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

Side by Side Diff: ui/gfx/animation/animation_container.cc

Issue 27710005: cc: Use HighResNow as timebase if it is fast and reliable (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix DCHECK 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
« no previous file with comments | « ui/compositor/test/layer_animator_test_controller.cc ('k') | ui/gfx/frame_time.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/gfx/animation/animation_container.h" 5 #include "ui/gfx/animation/animation_container.h"
6 6
7 #include "ui/gfx/animation/animation_container_element.h" 7 #include "ui/gfx/animation/animation_container_element.h"
8 #include "ui/gfx/animation/animation_container_observer.h" 8 #include "ui/gfx/animation/animation_container_observer.h"
9 #include "ui/gfx/frame_time.h"
9 10
10 using base::TimeDelta; 11 using base::TimeDelta;
11 using base::TimeTicks; 12 using base::TimeTicks;
12 13
13 namespace gfx { 14 namespace gfx {
14 15
15 AnimationContainer::AnimationContainer() 16 AnimationContainer::AnimationContainer()
16 : last_tick_time_(TimeTicks::Now()), 17 : last_tick_time_(gfx::FrameTime::Now()),
17 observer_(NULL) { 18 observer_(NULL) {
18 } 19 }
19 20
20 AnimationContainer::~AnimationContainer() { 21 AnimationContainer::~AnimationContainer() {
21 // The animations own us and stop themselves before being deleted. If 22 // The animations own us and stop themselves before being deleted. If
22 // elements_ is not empty, something is wrong. 23 // elements_ is not empty, something is wrong.
23 DCHECK(elements_.empty()); 24 DCHECK(elements_.empty());
24 } 25 }
25 26
26 void AnimationContainer::Start(AnimationContainerElement* element) { 27 void AnimationContainer::Start(AnimationContainerElement* element) {
27 DCHECK(elements_.count(element) == 0); // Start should only be invoked if the 28 DCHECK(elements_.count(element) == 0); // Start should only be invoked if the
28 // element isn't running. 29 // element isn't running.
29 30
30 if (elements_.empty()) { 31 if (elements_.empty()) {
31 last_tick_time_ = TimeTicks::Now(); 32 last_tick_time_ = gfx::FrameTime::Now();
32 SetMinTimerInterval(element->GetTimerInterval()); 33 SetMinTimerInterval(element->GetTimerInterval());
33 } else if (element->GetTimerInterval() < min_timer_interval_) { 34 } else if (element->GetTimerInterval() < min_timer_interval_) {
34 SetMinTimerInterval(element->GetTimerInterval()); 35 SetMinTimerInterval(element->GetTimerInterval());
35 } 36 }
36 37
37 element->SetStartTime(last_tick_time_); 38 element->SetStartTime(last_tick_time_);
38 elements_.insert(element); 39 elements_.insert(element);
39 } 40 }
40 41
41 void AnimationContainer::Stop(AnimationContainerElement* element) { 42 void AnimationContainer::Stop(AnimationContainerElement* element) {
(...skipping 12 matching lines...) Expand all
54 } 55 }
55 } 56 }
56 57
57 void AnimationContainer::Run() { 58 void AnimationContainer::Run() {
58 // We notify the observer after updating all the elements. If all the elements 59 // We notify the observer after updating all the elements. If all the elements
59 // are deleted as a result of updating then our ref count would go to zero and 60 // are deleted as a result of updating then our ref count would go to zero and
60 // we would be deleted before we notify our observer. We add a reference to 61 // we would be deleted before we notify our observer. We add a reference to
61 // ourself here to make sure we're still valid after running all the elements. 62 // ourself here to make sure we're still valid after running all the elements.
62 scoped_refptr<AnimationContainer> this_ref(this); 63 scoped_refptr<AnimationContainer> this_ref(this);
63 64
64 TimeTicks current_time = TimeTicks::Now(); 65 TimeTicks current_time = gfx::FrameTime::Now();
65 66
66 last_tick_time_ = current_time; 67 last_tick_time_ = current_time;
67 68
68 // Make a copy of the elements to iterate over so that if any elements are 69 // Make a copy of the elements to iterate over so that if any elements are
69 // removed as part of invoking Step there aren't any problems. 70 // removed as part of invoking Step there aren't any problems.
70 Elements elements = elements_; 71 Elements elements = elements_;
71 72
72 for (Elements::const_iterator i = elements.begin(); 73 for (Elements::const_iterator i = elements.begin();
73 i != elements.end(); ++i) { 74 i != elements.end(); ++i) {
74 // Make sure the element is still valid. 75 // Make sure the element is still valid.
(...skipping 20 matching lines...) Expand all
95 Elements::const_iterator i = elements_.begin(); 96 Elements::const_iterator i = elements_.begin();
96 min = (*i)->GetTimerInterval(); 97 min = (*i)->GetTimerInterval();
97 for (++i; i != elements_.end(); ++i) { 98 for (++i; i != elements_.end(); ++i) {
98 if ((*i)->GetTimerInterval() < min) 99 if ((*i)->GetTimerInterval() < min)
99 min = (*i)->GetTimerInterval(); 100 min = (*i)->GetTimerInterval();
100 } 101 }
101 return min; 102 return min;
102 } 103 }
103 104
104 } // namespace gfx 105 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/compositor/test/layer_animator_test_controller.cc ('k') | ui/gfx/frame_time.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698