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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "cc/base/cc_export.h" | 12 #include "cc/base/cc_export.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 namespace trace_event { | 15 namespace trace_event { |
16 class TracedValue; | 16 class TracedValue; |
17 } | 17 } |
18 class SingleThreadTaskRunner; | 18 class SingleThreadTaskRunner; |
19 } | 19 } |
20 | 20 |
21 namespace cc { | 21 namespace cc { |
22 | 22 class CC_EXPORT DelayBasedTimeSourceClient { |
23 class CC_EXPORT TimeSourceClient { | |
24 public: | 23 public: |
24 virtual void OnMissedTick() = 0; | |
25 virtual void OnTimerTick() = 0; | 25 virtual void OnTimerTick() = 0; |
mithro-old
2015/06/30 08:11:52
I feel like these callbacks should just take a tim
| |
26 | 26 |
27 protected: | 27 protected: |
28 virtual ~TimeSourceClient() {} | 28 virtual ~DelayBasedTimeSourceClient() {} |
29 }; | 29 }; |
30 | 30 |
31 // This timer implements a time source that achieves the specified interval | 31 // This timer implements a time source that achieves the specified interval |
32 // in face of millisecond-precision delayed callbacks and random queueing | 32 // in face of millisecond-precision delayed callbacks and random queueing |
33 // delays. DelayBasedTimeSource uses base::TimeTicks::Now as its timebase. | 33 // delays. DelayBasedTimeSource uses base::TimeTicks::Now as its timebase. |
34 class CC_EXPORT DelayBasedTimeSource { | 34 class CC_EXPORT DelayBasedTimeSource { |
35 public: | 35 public: |
36 static scoped_ptr<DelayBasedTimeSource> Create( | 36 static scoped_ptr<DelayBasedTimeSource> Create( |
37 base::TimeDelta interval, | 37 base::TimeDelta interval, |
38 base::SingleThreadTaskRunner* task_runner) { | 38 base::SingleThreadTaskRunner* task_runner) { |
39 return make_scoped_ptr(new DelayBasedTimeSource(interval, task_runner)); | 39 return make_scoped_ptr(new DelayBasedTimeSource(interval, task_runner)); |
40 } | 40 } |
41 | 41 |
42 virtual ~DelayBasedTimeSource(); | 42 virtual ~DelayBasedTimeSource(); |
43 | 43 |
44 virtual void SetClient(TimeSourceClient* client); | 44 void SetClient(DelayBasedTimeSourceClient* client); |
45 | 45 |
46 // TimeSource implementation | 46 void SetTimebaseAndInterval(base::TimeTicks timebase, |
47 virtual void SetTimebaseAndInterval(base::TimeTicks timebase, | 47 base::TimeDelta interval); |
48 base::TimeDelta interval); | |
49 base::TimeDelta Interval() const { return next_parameters_.interval; } | |
50 | 48 |
51 virtual base::TimeTicks SetActive(bool active); | 49 base::TimeDelta Interval() const; |
52 virtual bool Active() const; | 50 |
51 void SetActive(bool active); | |
52 bool Active() const; | |
53 | 53 |
54 // Get the last and next tick times. NextTickTime() returns null when | 54 // Get the last and next tick times. NextTickTime() returns null when |
55 // inactive. | 55 // inactive. |
56 virtual base::TimeTicks LastTickTime() const; | 56 base::TimeTicks LastTickTime() const; |
57 virtual base::TimeTicks NextTickTime() const; | 57 base::TimeTicks MissedTickTime() const; |
58 | 58 base::TimeTicks NextTickTime() const; |
59 // Virtual for testing. | |
60 virtual base::TimeTicks Now() const; | |
61 | 59 |
62 virtual void AsValueInto(base::trace_event::TracedValue* dict) const; | 60 virtual void AsValueInto(base::trace_event::TracedValue* dict) const; |
63 | 61 |
64 protected: | 62 protected: |
65 DelayBasedTimeSource(base::TimeDelta interval, | 63 DelayBasedTimeSource(base::TimeDelta interval, |
66 base::SingleThreadTaskRunner* task_runner); | 64 base::SingleThreadTaskRunner* task_runner); |
67 | 65 |
66 // Virtual for testing. | |
67 virtual base::TimeTicks Now() const; | |
68 virtual std::string TypeString() const; | 68 virtual std::string TypeString() const; |
69 | 69 |
70 base::TimeTicks NextTickTarget(base::TimeTicks now); | 70 base::TimeTicks NextTickTarget(base::TimeTicks now) const; |
71 | |
71 void PostNextTickTask(base::TimeTicks now); | 72 void PostNextTickTask(base::TimeTicks now); |
72 void OnTimerFired(); | 73 void ResetTickTask(base::TimeTicks now); |
73 | 74 |
74 struct Parameters { | 75 void OnMissedTick(); |
75 Parameters(base::TimeDelta interval, base::TimeTicks tick_target) | 76 void OnTimerTick(); |
76 : interval(interval), tick_target(tick_target) {} | |
77 base::TimeDelta interval; | |
78 base::TimeTicks tick_target; | |
79 }; | |
80 | 77 |
81 TimeSourceClient* client_; | 78 DelayBasedTimeSourceClient* client_; |
79 | |
82 base::TimeTicks last_tick_time_; | 80 base::TimeTicks last_tick_time_; |
81 base::TimeTicks missed_tick_time_; | |
82 base::TimeTicks next_tick_time_; | |
83 | 83 |
84 // current_parameters_ should only be written by PostNextTickTask. | 84 base::TimeTicks timebase_; |
85 // next_parameters_ will take effect on the next call to PostNextTickTask. | 85 base::TimeDelta interval_; |
86 // Maintaining a pending set of parameters allows NextTickTime() to always | |
87 // reflect the actual time we expect OnTimerFired to be called. | |
mithro-old
2015/06/30 08:11:52
Is this still preserved? I assume there was a test
| |
88 Parameters current_parameters_; | |
89 Parameters next_parameters_; | |
90 | 86 |
91 bool active_; | 87 bool active_; |
92 | 88 |
93 base::SingleThreadTaskRunner* task_runner_; | 89 base::SingleThreadTaskRunner* task_runner_; |
94 base::WeakPtrFactory<DelayBasedTimeSource> weak_factory_; | 90 base::WeakPtrFactory<DelayBasedTimeSource> weak_factory_; |
95 | 91 |
96 private: | 92 private: |
97 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource); | 93 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource); |
98 }; | 94 }; |
99 | 95 |
100 } // namespace cc | 96 } // namespace cc |
101 | 97 |
102 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ | 98 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ |
OLD | NEW |