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