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 | |
95 class FakeDelayBasedTimeSource : public cc::DelayBasedTimeSource { | 65 class FakeDelayBasedTimeSource : public cc::DelayBasedTimeSource { |
96 public: | 66 public: |
97 static scoped_refptr<FakeDelayBasedTimeSource> Create( | 67 static scoped_refptr<FakeDelayBasedTimeSource> Create( |
98 base::TimeDelta interval, cc::Thread* thread) { | 68 base::TimeDelta interval, cc::Thread* thread) { |
99 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval, thread)); | 69 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval, thread)); |
100 } | 70 } |
101 | 71 |
102 void SetNow(base::TimeTicks time) { now_ = time; } | 72 void SetNow(base::TimeTicks time) { now_ = time; } |
103 virtual base::TimeTicks Now() const OVERRIDE; | 73 virtual base::TimeTicks Now() const OVERRIDE; |
104 | 74 |
105 protected: | 75 protected: |
106 FakeDelayBasedTimeSource(base::TimeDelta interval, cc::Thread* thread) | 76 FakeDelayBasedTimeSource(base::TimeDelta interval, cc::Thread* thread) |
107 : DelayBasedTimeSource(interval, thread) {} | 77 : DelayBasedTimeSource(interval, thread) {} |
108 virtual ~FakeDelayBasedTimeSource() {} | 78 virtual ~FakeDelayBasedTimeSource() {} |
109 | 79 |
110 base::TimeTicks now_; | 80 base::TimeTicks now_; |
111 }; | 81 }; |
112 | 82 |
113 class FakeFrameRateController : public cc::FrameRateController { | 83 class FakeFrameRateController : public cc::FrameRateController { |
114 public: | 84 public: |
115 explicit FakeFrameRateController(scoped_refptr<cc::TimeSource> timer) | 85 explicit FakeFrameRateController(scoped_refptr<cc::TimeSource> timer) |
116 : cc::FrameRateController(timer) {} | 86 : cc::FrameRateController(timer) {} |
117 | 87 |
118 int NumFramesPending() const { return num_frames_pending_; } | 88 int NumFramesPending() const { return num_frames_pending_; } |
119 }; | 89 }; |
120 | 90 |
121 } // namespace cc | 91 } // namespace cc |
122 | 92 |
123 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ | 93 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ |
OLD | NEW |