| 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 base { class SingleThreadTaskRunner; } |
| 13 |
| 12 namespace cc { | 14 namespace cc { |
| 13 | 15 |
| 14 class Thread; | |
| 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 | 17 // in face of millisecond-precision delayed callbacks and random queueing |
| 18 // delays. | 18 // delays. |
| 19 class CC_EXPORT DelayBasedTimeSource : public TimeSource { | 19 class CC_EXPORT DelayBasedTimeSource : public TimeSource { |
| 20 public: | 20 public: |
| 21 static scoped_refptr<DelayBasedTimeSource> Create(base::TimeDelta interval, | 21 static scoped_refptr<DelayBasedTimeSource> Create( |
| 22 Thread* thread); | 22 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner); |
| 23 | 23 |
| 24 virtual void SetClient(TimeSourceClient* client) OVERRIDE; | 24 virtual void SetClient(TimeSourceClient* client) OVERRIDE; |
| 25 | 25 |
| 26 // TimeSource implementation | 26 // TimeSource implementation |
| 27 virtual void SetTimebaseAndInterval(base::TimeTicks timebase, | 27 virtual void SetTimebaseAndInterval(base::TimeTicks timebase, |
| 28 base::TimeDelta interval) OVERRIDE; | 28 base::TimeDelta interval) OVERRIDE; |
| 29 | 29 |
| 30 virtual void SetActive(bool active) OVERRIDE; | 30 virtual void SetActive(bool active) OVERRIDE; |
| 31 virtual bool Active() const OVERRIDE; | 31 virtual bool Active() const OVERRIDE; |
| 32 | 32 |
| 33 // Get the last and next tick times. nextTimeTime() returns null when | 33 // Get the last and next tick times. nextTimeTime() returns null when |
| 34 // inactive. | 34 // inactive. |
| 35 virtual base::TimeTicks LastTickTime() OVERRIDE; | 35 virtual base::TimeTicks LastTickTime() OVERRIDE; |
| 36 virtual base::TimeTicks NextTickTime() OVERRIDE; | 36 virtual base::TimeTicks NextTickTime() OVERRIDE; |
| 37 | 37 |
| 38 // Virtual for testing. | 38 // Virtual for testing. |
| 39 virtual base::TimeTicks Now() const; | 39 virtual base::TimeTicks Now() const; |
| 40 | 40 |
| 41 protected: | 41 protected: |
| 42 DelayBasedTimeSource(base::TimeDelta interval, Thread* thread); | 42 DelayBasedTimeSource(base::TimeDelta interval, |
| 43 base::SingleThreadTaskRunner* task_runner); |
| 43 virtual ~DelayBasedTimeSource(); | 44 virtual ~DelayBasedTimeSource(); |
| 44 | 45 |
| 45 base::TimeTicks NextTickTarget(base::TimeTicks now); | 46 base::TimeTicks NextTickTarget(base::TimeTicks now); |
| 46 void PostNextTickTask(base::TimeTicks now); | 47 void PostNextTickTask(base::TimeTicks now); |
| 47 void OnTimerFired(); | 48 void OnTimerFired(); |
| 48 | 49 |
| 49 enum State { | 50 enum State { |
| 50 STATE_INACTIVE, | 51 STATE_INACTIVE, |
| 51 STATE_STARTING, | 52 STATE_STARTING, |
| 52 STATE_ACTIVE, | 53 STATE_ACTIVE, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 65 | 66 |
| 66 // current_parameters_ should only be written by PostNextTickTask. | 67 // current_parameters_ should only be written by PostNextTickTask. |
| 67 // next_parameters_ will take effect on the next call to PostNextTickTask. | 68 // next_parameters_ will take effect on the next call to PostNextTickTask. |
| 68 // Maintaining a pending set of parameters allows NextTickTime() to always | 69 // Maintaining a pending set of parameters allows NextTickTime() to always |
| 69 // reflect the actual time we expect OnTimerFired to be called. | 70 // reflect the actual time we expect OnTimerFired to be called. |
| 70 Parameters current_parameters_; | 71 Parameters current_parameters_; |
| 71 Parameters next_parameters_; | 72 Parameters next_parameters_; |
| 72 | 73 |
| 73 State state_; | 74 State state_; |
| 74 | 75 |
| 75 Thread* thread_; | 76 base::SingleThreadTaskRunner* task_runner_; |
| 76 base::WeakPtrFactory<DelayBasedTimeSource> weak_factory_; | 77 base::WeakPtrFactory<DelayBasedTimeSource> weak_factory_; |
| 78 |
| 79 private: |
| 77 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource); | 80 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource); |
| 78 }; | 81 }; |
| 79 | 82 |
| 80 } // namespace cc | 83 } // namespace cc |
| 81 | 84 |
| 82 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ | 85 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ |
| OLD | NEW |