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