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_TEST_SCHEDULER_TEST_COMMON_H_ | 5 #ifndef CC_TEST_SCHEDULER_TEST_COMMON_H_ |
6 #define CC_TEST_SCHEDULER_TEST_COMMON_H_ | 6 #define CC_TEST_SCHEDULER_TEST_COMMON_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 virtual void PostDelayedTask(base::Closure cb, base::TimeDelta delay) | 55 virtual void PostDelayedTask(base::Closure cb, base::TimeDelta delay) |
56 OVERRIDE; | 56 OVERRIDE; |
57 virtual bool BelongsToCurrentThread() const OVERRIDE; | 57 virtual bool BelongsToCurrentThread() const OVERRIDE; |
58 | 58 |
59 protected: | 59 protected: |
60 scoped_ptr<base::Closure> pending_task_; | 60 scoped_ptr<base::Closure> pending_task_; |
61 int64 pending_task_delay_; | 61 int64 pending_task_delay_; |
62 bool run_pending_task_on_overwrite_; | 62 bool run_pending_task_on_overwrite_; |
63 }; | 63 }; |
64 | 64 |
| 65 class FakeTimeSource : public cc::TimeSource { |
| 66 public: |
| 67 FakeTimeSource() : active_(false), client_(0) {} |
| 68 |
| 69 virtual void SetClient(cc::TimeSourceClient* client) OVERRIDE; |
| 70 virtual void SetActive(bool b) OVERRIDE; |
| 71 virtual bool Active() const OVERRIDE; |
| 72 virtual void SetTimebaseAndInterval(base::TimeTicks timebase, |
| 73 base::TimeDelta interval) OVERRIDE {} |
| 74 virtual base::TimeTicks LastTickTime() OVERRIDE; |
| 75 virtual base::TimeTicks NextTickTime() OVERRIDE; |
| 76 |
| 77 void Tick() { |
| 78 ASSERT_TRUE(active_); |
| 79 if (client_) |
| 80 client_->OnTimerTick(); |
| 81 } |
| 82 |
| 83 void SetNextTickTime(base::TimeTicks next_tick_time) { |
| 84 next_tick_time_ = next_tick_time; |
| 85 } |
| 86 |
| 87 protected: |
| 88 virtual ~FakeTimeSource() {} |
| 89 |
| 90 bool active_; |
| 91 base::TimeTicks next_tick_time_; |
| 92 cc::TimeSourceClient* client_; |
| 93 }; |
| 94 |
65 class FakeDelayBasedTimeSource : public cc::DelayBasedTimeSource { | 95 class FakeDelayBasedTimeSource : public cc::DelayBasedTimeSource { |
66 public: | 96 public: |
67 static scoped_refptr<FakeDelayBasedTimeSource> Create( | 97 static scoped_refptr<FakeDelayBasedTimeSource> Create( |
68 base::TimeDelta interval, cc::Thread* thread) { | 98 base::TimeDelta interval, cc::Thread* thread) { |
69 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval, thread)); | 99 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval, thread)); |
70 } | 100 } |
71 | 101 |
72 void SetNow(base::TimeTicks time) { now_ = time; } | 102 void SetNow(base::TimeTicks time) { now_ = time; } |
73 virtual base::TimeTicks Now() const OVERRIDE; | 103 virtual base::TimeTicks Now() const OVERRIDE; |
74 | 104 |
75 protected: | 105 protected: |
76 FakeDelayBasedTimeSource(base::TimeDelta interval, cc::Thread* thread) | 106 FakeDelayBasedTimeSource(base::TimeDelta interval, cc::Thread* thread) |
77 : DelayBasedTimeSource(interval, thread) {} | 107 : DelayBasedTimeSource(interval, thread) {} |
78 virtual ~FakeDelayBasedTimeSource() {} | 108 virtual ~FakeDelayBasedTimeSource() {} |
79 | 109 |
80 base::TimeTicks now_; | 110 base::TimeTicks now_; |
81 }; | 111 }; |
82 | 112 |
83 class FakeFrameRateController : public cc::FrameRateController { | 113 class FakeFrameRateController : public cc::FrameRateController { |
84 public: | 114 public: |
85 explicit FakeFrameRateController(scoped_refptr<cc::TimeSource> timer) | 115 explicit FakeFrameRateController(scoped_refptr<cc::TimeSource> timer) |
86 : cc::FrameRateController(timer) {} | 116 : cc::FrameRateController(timer) {} |
87 | 117 |
88 int NumFramesPending() const { return num_frames_pending_; } | 118 int NumFramesPending() const { return num_frames_pending_; } |
89 }; | 119 }; |
90 | 120 |
91 } // namespace cc | 121 } // namespace cc |
92 | 122 |
93 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ | 123 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ |
OLD | NEW |