| 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 #include "cc/scheduler/time_source.h" | |
| 14 | 13 |
| 15 namespace base { class SingleThreadTaskRunner; } | 14 namespace base { class SingleThreadTaskRunner; } |
| 16 | 15 |
| 17 namespace cc { | 16 namespace cc { |
| 18 | 17 |
| 18 class CC_EXPORT TimeSourceClient { |
| 19 public: |
| 20 virtual void OnTimerTick() = 0; |
| 21 |
| 22 protected: |
| 23 virtual ~TimeSourceClient() {} |
| 24 }; |
| 25 |
| 19 // This timer implements a time source that achieves the specified interval | 26 // This timer implements a time source that achieves the specified interval |
| 20 // in face of millisecond-precision delayed callbacks and random queueing | 27 // in face of millisecond-precision delayed callbacks and random queueing |
| 21 // delays. DelayBasedTimeSource uses base::TimeTicks::Now as its timebase. | 28 // delays. DelayBasedTimeSource uses base::TimeTicks::Now as its timebase. |
| 22 class CC_EXPORT DelayBasedTimeSource : public TimeSource { | 29 class CC_EXPORT DelayBasedTimeSource |
| 30 : public base::RefCounted<DelayBasedTimeSource> { |
| 23 public: | 31 public: |
| 24 static scoped_refptr<DelayBasedTimeSource> Create( | 32 static scoped_refptr<DelayBasedTimeSource> Create( |
| 25 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner); | 33 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner); |
| 26 | 34 |
| 27 virtual void SetClient(TimeSourceClient* client) OVERRIDE; | 35 virtual void SetClient(TimeSourceClient* client); |
| 28 | 36 |
| 29 // TimeSource implementation | 37 // TimeSource implementation |
| 30 virtual void SetTimebaseAndInterval(base::TimeTicks timebase, | 38 virtual void SetTimebaseAndInterval(base::TimeTicks timebase, |
| 31 base::TimeDelta interval) OVERRIDE; | 39 base::TimeDelta interval); |
| 32 | 40 |
| 33 virtual base::TimeTicks SetActive(bool active) OVERRIDE; | 41 virtual base::TimeTicks SetActive(bool active); |
| 34 virtual bool Active() const OVERRIDE; | 42 virtual bool Active() const; |
| 35 | 43 |
| 36 // Get the last and next tick times. NextTickTime() returns null when | 44 // Get the last and next tick times. NextTickTime() returns null when |
| 37 // inactive. | 45 // inactive. |
| 38 virtual base::TimeTicks LastTickTime() const OVERRIDE; | 46 virtual base::TimeTicks LastTickTime() const; |
| 39 virtual base::TimeTicks NextTickTime() const OVERRIDE; | 47 virtual base::TimeTicks NextTickTime() const; |
| 40 | 48 |
| 41 // Virtual for testing. | 49 // Virtual for testing. |
| 42 virtual base::TimeTicks Now() const; | 50 virtual base::TimeTicks Now() const; |
| 43 | 51 |
| 44 virtual scoped_ptr<base::Value> AsValue() const; | 52 virtual scoped_ptr<base::Value> AsValue() const; |
| 45 | 53 |
| 46 protected: | 54 protected: |
| 47 DelayBasedTimeSource(base::TimeDelta interval, | 55 DelayBasedTimeSource(base::TimeDelta interval, |
| 48 base::SingleThreadTaskRunner* task_runner); | 56 base::SingleThreadTaskRunner* task_runner); |
| 49 virtual ~DelayBasedTimeSource(); | 57 virtual ~DelayBasedTimeSource(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 70 // reflect the actual time we expect OnTimerFired to be called. | 78 // reflect the actual time we expect OnTimerFired to be called. |
| 71 Parameters current_parameters_; | 79 Parameters current_parameters_; |
| 72 Parameters next_parameters_; | 80 Parameters next_parameters_; |
| 73 | 81 |
| 74 bool active_; | 82 bool active_; |
| 75 | 83 |
| 76 base::SingleThreadTaskRunner* task_runner_; | 84 base::SingleThreadTaskRunner* task_runner_; |
| 77 base::WeakPtrFactory<DelayBasedTimeSource> weak_factory_; | 85 base::WeakPtrFactory<DelayBasedTimeSource> weak_factory_; |
| 78 | 86 |
| 79 private: | 87 private: |
| 88 friend class base::RefCounted<DelayBasedTimeSource>; |
| 80 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource); | 89 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource); |
| 81 }; | 90 }; |
| 82 | 91 |
| 83 // DelayBasedTimeSource uses base::TimeTicks::HighResNow as its timebase. | 92 // DelayBasedTimeSource uses base::TimeTicks::HighResNow as its timebase. |
| 84 class DelayBasedTimeSourceHighRes : public DelayBasedTimeSource { | 93 class DelayBasedTimeSourceHighRes : public DelayBasedTimeSource { |
| 85 public: | 94 public: |
| 86 static scoped_refptr<DelayBasedTimeSourceHighRes> Create( | 95 static scoped_refptr<DelayBasedTimeSourceHighRes> Create( |
| 87 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner); | 96 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner); |
| 88 | 97 |
| 89 virtual base::TimeTicks Now() const OVERRIDE; | 98 virtual base::TimeTicks Now() const OVERRIDE; |
| 90 | 99 |
| 91 protected: | 100 protected: |
| 92 DelayBasedTimeSourceHighRes(base::TimeDelta interval, | 101 DelayBasedTimeSourceHighRes(base::TimeDelta interval, |
| 93 base::SingleThreadTaskRunner* task_runner); | 102 base::SingleThreadTaskRunner* task_runner); |
| 94 virtual ~DelayBasedTimeSourceHighRes(); | 103 virtual ~DelayBasedTimeSourceHighRes(); |
| 95 | 104 |
| 96 virtual std::string TypeString() const OVERRIDE; | 105 virtual std::string TypeString() const OVERRIDE; |
| 97 | 106 |
| 98 private: | 107 private: |
| 99 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSourceHighRes); | 108 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSourceHighRes); |
| 100 }; | 109 }; |
| 101 | 110 |
| 102 } // namespace cc | 111 } // namespace cc |
| 103 | 112 |
| 104 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ | 113 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ |
| OLD | NEW |