OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCDelayBasedTimeSource.h" | 7 #include "CCDelayBasedTimeSource.h" |
8 | 8 |
9 #include "TraceEvent.h" | 9 #include "TraceEvent.h" |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 27 matching lines...) Expand all Loading... |
38 : m_client(0) | 38 : m_client(0) |
39 , m_hasTickTarget(false) | 39 , m_hasTickTarget(false) |
40 , m_currentParameters(interval, base::TimeTicks()) | 40 , m_currentParameters(interval, base::TimeTicks()) |
41 , m_nextParameters(interval, base::TimeTicks()) | 41 , m_nextParameters(interval, base::TimeTicks()) |
42 , m_state(STATE_INACTIVE) | 42 , m_state(STATE_INACTIVE) |
43 , m_timer(thread, this) | 43 , m_timer(thread, this) |
44 { | 44 { |
45 turnOffVerifier(); | 45 turnOffVerifier(); |
46 } | 46 } |
47 | 47 |
| 48 CCDelayBasedTimeSource::~CCDelayBasedTimeSource() |
| 49 { |
| 50 } |
| 51 |
48 void CCDelayBasedTimeSource::setActive(bool active) | 52 void CCDelayBasedTimeSource::setActive(bool active) |
49 { | 53 { |
50 TRACE_EVENT1("cc", "CCDelayBasedTimeSource::setActive", "active", active); | 54 TRACE_EVENT1("cc", "CCDelayBasedTimeSource::setActive", "active", active); |
51 if (!active) { | 55 if (!active) { |
52 m_state = STATE_INACTIVE; | 56 m_state = STATE_INACTIVE; |
53 m_timer.stop(); | 57 m_timer.stop(); |
54 return; | 58 return; |
55 } | 59 } |
56 | 60 |
57 if (m_state == STATE_STARTING || m_state == STATE_ACTIVE) | 61 if (m_state == STATE_STARTING || m_state == STATE_ACTIVE) |
58 return; | 62 return; |
59 | 63 |
60 if (!m_hasTickTarget) { | 64 if (!m_hasTickTarget) { |
61 // Becoming active the first time is deferred: we post a 0-delay task. W
hen | 65 // Becoming active the first time is deferred: we post a 0-delay task. W
hen |
62 // it runs, we use that to establish the timebase, become truly active,
and | 66 // it runs, we use that to establish the timebase, become truly active,
and |
63 // fire the first tick. | 67 // fire the first tick. |
64 m_state = STATE_STARTING; | 68 m_state = STATE_STARTING; |
65 m_timer.startOneShot(0); | 69 m_timer.startOneShot(0); |
66 return; | 70 return; |
67 } | 71 } |
68 | 72 |
69 m_state = STATE_ACTIVE; | 73 m_state = STATE_ACTIVE; |
70 | 74 |
71 postNextTickTask(now()); | 75 postNextTickTask(now()); |
72 } | 76 } |
73 | 77 |
| 78 bool CCDelayBasedTimeSource::active() const |
| 79 { |
| 80 return m_state != STATE_INACTIVE; |
| 81 } |
| 82 |
74 base::TimeTicks CCDelayBasedTimeSource::lastTickTime() | 83 base::TimeTicks CCDelayBasedTimeSource::lastTickTime() |
75 { | 84 { |
76 return m_lastTickTime; | 85 return m_lastTickTime; |
77 } | 86 } |
78 | 87 |
79 base::TimeTicks CCDelayBasedTimeSource::nextTickTimeIfActivated() | 88 base::TimeTicks CCDelayBasedTimeSource::nextTickTimeIfActivated() |
80 { | 89 { |
81 return active() ? m_currentParameters.tickTarget : nextTickTarget(now()); | 90 return active() ? m_currentParameters.tickTarget : nextTickTarget(now()); |
82 } | 91 } |
83 | 92 |
84 void CCDelayBasedTimeSource::onTimerFired() | 93 void CCDelayBasedTimeSource::onTimerFired() |
85 { | 94 { |
86 ASSERT(m_state != STATE_INACTIVE); | 95 ASSERT(m_state != STATE_INACTIVE); |
87 | 96 |
88 base::TimeTicks now = this->now(); | 97 base::TimeTicks now = this->now(); |
89 m_lastTickTime = now; | 98 m_lastTickTime = now; |
90 | 99 |
91 if (m_state == STATE_STARTING) { | 100 if (m_state == STATE_STARTING) { |
92 setTimebaseAndInterval(now, m_currentParameters.interval); | 101 setTimebaseAndInterval(now, m_currentParameters.interval); |
93 m_state = STATE_ACTIVE; | 102 m_state = STATE_ACTIVE; |
94 } | 103 } |
95 | 104 |
96 postNextTickTask(now); | 105 postNextTickTask(now); |
97 | 106 |
98 // Fire the tick | 107 // Fire the tick |
99 if (m_client) | 108 if (m_client) |
100 m_client->onTimerTick(); | 109 m_client->onTimerTick(); |
101 } | 110 } |
102 | 111 |
| 112 void CCDelayBasedTimeSource::setClient(CCTimeSourceClient* client) |
| 113 { |
| 114 m_client = client; |
| 115 } |
| 116 |
103 void CCDelayBasedTimeSource::setTimebaseAndInterval(base::TimeTicks timebase, ba
se::TimeDelta interval) | 117 void CCDelayBasedTimeSource::setTimebaseAndInterval(base::TimeTicks timebase, ba
se::TimeDelta interval) |
104 { | 118 { |
105 m_nextParameters.interval = interval; | 119 m_nextParameters.interval = interval; |
106 m_nextParameters.tickTarget = timebase; | 120 m_nextParameters.tickTarget = timebase; |
107 m_hasTickTarget = true; | 121 m_hasTickTarget = true; |
108 | 122 |
109 if (m_state != STATE_ACTIVE) { | 123 if (m_state != STATE_ACTIVE) { |
110 // If we aren't active, there's no need to reset the timer. | 124 // If we aren't active, there's no need to reset the timer. |
111 return; | 125 return; |
112 } | 126 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 base::TimeDelta delay = newTickTarget - now; | 223 base::TimeDelta delay = newTickTarget - now; |
210 ASSERT(delay.InMillisecondsF() <= | 224 ASSERT(delay.InMillisecondsF() <= |
211 m_nextParameters.interval.InMillisecondsF() * (1.0 + doubleTickThresh
old)); | 225 m_nextParameters.interval.InMillisecondsF() * (1.0 + doubleTickThresh
old)); |
212 m_timer.startOneShot(delay.InSecondsF()); | 226 m_timer.startOneShot(delay.InSecondsF()); |
213 | 227 |
214 m_nextParameters.tickTarget = newTickTarget; | 228 m_nextParameters.tickTarget = newTickTarget; |
215 m_currentParameters = m_nextParameters; | 229 m_currentParameters = m_nextParameters; |
216 } | 230 } |
217 | 231 |
218 } | 232 } |
OLD | NEW |