OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ |
| 6 #define CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/memory/weak_ptr.h" |
| 11 #include "base/values.h" |
| 12 |
| 13 namespace base { |
| 14 namespace trace_event { |
| 15 class TracedValue; |
| 16 } |
| 17 class SingleThreadTaskRunner; |
| 18 } |
| 19 |
| 20 namespace cc { |
| 21 |
| 22 class TimeSourceClient { |
| 23 public: |
| 24 virtual void OnTimerTick() = 0; |
| 25 |
| 26 protected: |
| 27 virtual ~TimeSourceClient() {} |
| 28 }; |
| 29 |
| 30 // This timer implements a time source that achieves the specified interval |
| 31 // in face of millisecond-precision delayed callbacks and random queueing |
| 32 // delays. DelayBasedTimeSource uses base::TimeTicks::Now as its timebase. |
| 33 class DelayBasedTimeSource : public base::RefCounted<DelayBasedTimeSource> { |
| 34 public: |
| 35 static scoped_refptr<DelayBasedTimeSource> Create( |
| 36 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner); |
| 37 |
| 38 virtual void SetClient(TimeSourceClient* client); |
| 39 |
| 40 // TimeSource implementation |
| 41 virtual void SetTimebaseAndInterval(base::TimeTicks timebase, |
| 42 base::TimeDelta interval); |
| 43 base::TimeDelta Interval() const { return next_parameters_.interval; } |
| 44 |
| 45 virtual base::TimeTicks SetActive(bool active); |
| 46 virtual bool Active() const; |
| 47 |
| 48 // Get the last and next tick times. NextTickTime() returns null when |
| 49 // inactive. |
| 50 virtual base::TimeTicks LastTickTime() const; |
| 51 virtual base::TimeTicks NextTickTime() const; |
| 52 |
| 53 // Virtual for testing. |
| 54 virtual base::TimeTicks Now() const; |
| 55 |
| 56 virtual void AsValueInto(base::trace_event::TracedValue* dict) const; |
| 57 |
| 58 protected: |
| 59 DelayBasedTimeSource(base::TimeDelta interval, |
| 60 base::SingleThreadTaskRunner* task_runner); |
| 61 virtual ~DelayBasedTimeSource(); |
| 62 |
| 63 virtual std::string TypeString() const; |
| 64 |
| 65 base::TimeTicks NextTickTarget(base::TimeTicks now); |
| 66 void PostNextTickTask(base::TimeTicks now); |
| 67 void OnTimerFired(); |
| 68 |
| 69 struct Parameters { |
| 70 Parameters(base::TimeDelta interval, base::TimeTicks tick_target) |
| 71 : interval(interval), tick_target(tick_target) {} |
| 72 base::TimeDelta interval; |
| 73 base::TimeTicks tick_target; |
| 74 }; |
| 75 |
| 76 TimeSourceClient* client_; |
| 77 base::TimeTicks last_tick_time_; |
| 78 |
| 79 // current_parameters_ should only be written by PostNextTickTask. |
| 80 // next_parameters_ will take effect on the next call to PostNextTickTask. |
| 81 // Maintaining a pending set of parameters allows NextTickTime() to always |
| 82 // reflect the actual time we expect OnTimerFired to be called. |
| 83 Parameters current_parameters_; |
| 84 Parameters next_parameters_; |
| 85 |
| 86 bool active_; |
| 87 |
| 88 base::SingleThreadTaskRunner* task_runner_; |
| 89 base::WeakPtrFactory<DelayBasedTimeSource> weak_factory_; |
| 90 |
| 91 private: |
| 92 friend class base::RefCounted<DelayBasedTimeSource>; |
| 93 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSource); |
| 94 }; |
| 95 |
| 96 // DelayBasedTimeSource that once used base::TimeTicks::HighResNow as its time |
| 97 // source, but is now a no-op. |
| 98 // TODO(brianderson): Remove along with gfx::/FrameTime.http://crbug.com/447329 |
| 99 class DelayBasedTimeSourceHighRes : public DelayBasedTimeSource { |
| 100 public: |
| 101 static scoped_refptr<DelayBasedTimeSourceHighRes> Create( |
| 102 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner); |
| 103 |
| 104 base::TimeTicks Now() const override; |
| 105 |
| 106 protected: |
| 107 DelayBasedTimeSourceHighRes(base::TimeDelta interval, |
| 108 base::SingleThreadTaskRunner* task_runner); |
| 109 ~DelayBasedTimeSourceHighRes() override; |
| 110 |
| 111 std::string TypeString() const override; |
| 112 |
| 113 private: |
| 114 DISALLOW_COPY_AND_ASSIGN(DelayBasedTimeSourceHighRes); |
| 115 }; |
| 116 |
| 117 } // namespace cc |
| 118 |
| 119 #endif // CC_SCHEDULER_DELAY_BASED_TIME_SOURCE_H_ |
OLD | NEW |