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 #ifndef CCDelayBasedTimeSource_h | 5 #ifndef CCDelayBasedTimeSource_h |
6 #define CCDelayBasedTimeSource_h | 6 #define CCDelayBasedTimeSource_h |
7 | 7 |
8 #include "CCTimeSource.h" | 8 #include "CCTimeSource.h" |
9 #include "CCTimer.h" | 9 #include "CCTimer.h" |
10 | 10 |
11 namespace cc { | 11 namespace cc { |
12 | 12 |
13 class CCThread; | 13 class Thread; |
14 | 14 |
15 // This timer implements a time source that achieves the specified interval | 15 // This timer implements a time source that achieves the specified interval |
16 // in face of millisecond-precision delayed callbacks and random queueing delays
. | 16 // in face of millisecond-precision delayed callbacks and random queueing delays
. |
17 class CCDelayBasedTimeSource : public CCTimeSource, CCTimerClient { | 17 class DelayBasedTimeSource : public TimeSource, TimerClient { |
18 public: | 18 public: |
19 static scoped_refptr<CCDelayBasedTimeSource> create(base::TimeDelta interval
, CCThread*); | 19 static scoped_refptr<DelayBasedTimeSource> create(base::TimeDelta interval,
Thread*); |
20 | 20 |
21 virtual void setClient(CCTimeSourceClient* client) OVERRIDE; | 21 virtual void setClient(TimeSourceClient* client) OVERRIDE; |
22 | 22 |
23 // CCTimeSource implementation | 23 // TimeSource implementation |
24 virtual void setTimebaseAndInterval(base::TimeTicks timebase, base::TimeDelt
a interval) OVERRIDE; | 24 virtual void setTimebaseAndInterval(base::TimeTicks timebase, base::TimeDelt
a interval) OVERRIDE; |
25 | 25 |
26 virtual void setActive(bool) OVERRIDE; | 26 virtual void setActive(bool) OVERRIDE; |
27 virtual bool active() const OVERRIDE; | 27 virtual bool active() const OVERRIDE; |
28 | 28 |
29 // Get the last and next tick times. nextTimeTime() returns null when | 29 // Get the last and next tick times. nextTimeTime() returns null when |
30 // inactive. | 30 // inactive. |
31 virtual base::TimeTicks lastTickTime() OVERRIDE; | 31 virtual base::TimeTicks lastTickTime() OVERRIDE; |
32 virtual base::TimeTicks nextTickTime() OVERRIDE; | 32 virtual base::TimeTicks nextTickTime() OVERRIDE; |
33 | 33 |
34 // CCTimerClient implementation. | 34 // TimerClient implementation. |
35 virtual void onTimerFired() OVERRIDE; | 35 virtual void onTimerFired() OVERRIDE; |
36 | 36 |
37 // Virtual for testing. | 37 // Virtual for testing. |
38 virtual base::TimeTicks now() const; | 38 virtual base::TimeTicks now() const; |
39 | 39 |
40 protected: | 40 protected: |
41 CCDelayBasedTimeSource(base::TimeDelta interval, CCThread*); | 41 DelayBasedTimeSource(base::TimeDelta interval, Thread*); |
42 virtual ~CCDelayBasedTimeSource(); | 42 virtual ~DelayBasedTimeSource(); |
43 | 43 |
44 base::TimeTicks nextTickTarget(base::TimeTicks now); | 44 base::TimeTicks nextTickTarget(base::TimeTicks now); |
45 void postNextTickTask(base::TimeTicks now); | 45 void postNextTickTask(base::TimeTicks now); |
46 | 46 |
47 enum State { | 47 enum State { |
48 STATE_INACTIVE, | 48 STATE_INACTIVE, |
49 STATE_STARTING, | 49 STATE_STARTING, |
50 STATE_ACTIVE, | 50 STATE_ACTIVE, |
51 }; | 51 }; |
52 | 52 |
53 struct Parameters { | 53 struct Parameters { |
54 Parameters(base::TimeDelta interval, base::TimeTicks tickTarget) | 54 Parameters(base::TimeDelta interval, base::TimeTicks tickTarget) |
55 : interval(interval), tickTarget(tickTarget) | 55 : interval(interval), tickTarget(tickTarget) |
56 { } | 56 { } |
57 base::TimeDelta interval; | 57 base::TimeDelta interval; |
58 base::TimeTicks tickTarget; | 58 base::TimeTicks tickTarget; |
59 }; | 59 }; |
60 | 60 |
61 CCTimeSourceClient* m_client; | 61 TimeSourceClient* m_client; |
62 bool m_hasTickTarget; | 62 bool m_hasTickTarget; |
63 base::TimeTicks m_lastTickTime; | 63 base::TimeTicks m_lastTickTime; |
64 | 64 |
65 // m_currentParameters should only be written by postNextTickTask. | 65 // m_currentParameters should only be written by postNextTickTask. |
66 // m_nextParameters will take effect on the next call to postNextTickTask. | 66 // m_nextParameters will take effect on the next call to postNextTickTask. |
67 // Maintaining a pending set of parameters allows nextTickTime() to always | 67 // Maintaining a pending set of parameters allows nextTickTime() to always |
68 // reflect the actual time we expect onTimerFired to be called. | 68 // reflect the actual time we expect onTimerFired to be called. |
69 Parameters m_currentParameters; | 69 Parameters m_currentParameters; |
70 Parameters m_nextParameters; | 70 Parameters m_nextParameters; |
71 | 71 |
72 State m_state; | 72 State m_state; |
73 CCThread* m_thread; | 73 Thread* m_thread; |
74 CCTimer m_timer; | 74 Timer m_timer; |
75 }; | 75 }; |
76 | 76 |
77 } // namespace cc | 77 } // namespace cc |
78 | 78 |
79 #endif // CCDelayBasedTimeSource_h | 79 #endif // CCDelayBasedTimeSource_h |
OLD | NEW |