Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: cc/surfaces/display_scheduler_unittest.cc

Issue 1132753008: Replaced TestNowSource with SimpleTestTickClock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "cc/surfaces/display_scheduler.h" 5 #include "cc/surfaces/display_scheduler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/test/null_task_runner.h" 8 #include "base/test/null_task_runner.h"
9 #include "base/test/simple_test_tick_clock.h"
9 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
10 #include "cc/output/begin_frame_args.h" 11 #include "cc/output/begin_frame_args.h"
11 #include "cc/surfaces/display.h" 12 #include "cc/surfaces/display.h"
12 #include "cc/test/scheduler_test_common.h" 13 #include "cc/test/scheduler_test_common.h"
13 #include "cc/test/test_now_source.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace cc { 16 namespace cc {
17 namespace { 17 namespace {
18 18
19 class FakeDisplaySchedulerClient : public DisplaySchedulerClient { 19 class FakeDisplaySchedulerClient : public DisplaySchedulerClient {
20 public: 20 public:
21 FakeDisplaySchedulerClient() : draw_and_swap_count_(0) {} 21 FakeDisplaySchedulerClient() : draw_and_swap_count_(0) {}
22 22
23 ~FakeDisplaySchedulerClient() override {} 23 ~FakeDisplaySchedulerClient() override {}
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 int scheduler_begin_frame_deadline_count() { 61 int scheduler_begin_frame_deadline_count() {
62 return scheduler_begin_frame_deadline_count_; 62 return scheduler_begin_frame_deadline_count_;
63 } 63 }
64 64
65 protected: 65 protected:
66 int scheduler_begin_frame_deadline_count_; 66 int scheduler_begin_frame_deadline_count_;
67 }; 67 };
68 68
69 class DisplaySchedulerTest : public testing::Test { 69 class DisplaySchedulerTest : public testing::Test {
70 public: 70 public:
71 DisplaySchedulerTest() { 71 DisplaySchedulerTest() : now_src_(new base::SimpleTestTickClock()) {
72 const int max_pending_swaps = 1; 72 const int max_pending_swaps = 1;
73 now_src_ = TestNowSource::Create(); 73 now_src_->Advance(base::TimeDelta::FromMicroseconds(10000));
74 null_task_runner_ = make_scoped_refptr(new base::NullTaskRunner); 74 null_task_runner_ = make_scoped_refptr(new base::NullTaskRunner);
75 client_ = make_scoped_ptr(new FakeDisplaySchedulerClient); 75 client_ = make_scoped_ptr(new FakeDisplaySchedulerClient);
76 scheduler_ = make_scoped_ptr( 76 scheduler_ = make_scoped_ptr(
77 new TestDisplayScheduler(client_.get(), &fake_begin_frame_source_, 77 new TestDisplayScheduler(client_.get(), &fake_begin_frame_source_,
78 null_task_runner_, max_pending_swaps)); 78 null_task_runner_, max_pending_swaps));
79 } 79 }
80 80
81 ~DisplaySchedulerTest() override {} 81 ~DisplaySchedulerTest() override {}
82 82
83 void SetUp() override { scheduler_->SetRootSurfaceResourcesLocked(false); } 83 void SetUp() override { scheduler_->SetRootSurfaceResourcesLocked(false); }
84 84
85 void BeginFrameForTest() { 85 void BeginFrameForTest() {
86 base::TimeTicks frame_time = now_src_->Now(); 86 base::TimeTicks frame_time = now_src_->NowTicks();
87 base::TimeDelta interval = BeginFrameArgs::DefaultInterval(); 87 base::TimeDelta interval = BeginFrameArgs::DefaultInterval();
88 base::TimeTicks deadline = frame_time + interval; 88 base::TimeTicks deadline = frame_time + interval;
89 fake_begin_frame_source_.TestOnBeginFrame( 89 fake_begin_frame_source_.TestOnBeginFrame(
90 BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, deadline, 90 BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, deadline,
91 interval, BeginFrameArgs::NORMAL)); 91 interval, BeginFrameArgs::NORMAL));
92 } 92 }
93 93
94 protected: 94 protected:
95 TestNowSource& now_src() { return *now_src_; } 95 base::SimpleTestTickClock& now_src() { return *now_src_; }
96 FakeDisplaySchedulerClient& client() { return *client_; } 96 FakeDisplaySchedulerClient& client() { return *client_; }
97 DisplayScheduler& scheduler() { return *scheduler_; } 97 DisplayScheduler& scheduler() { return *scheduler_; }
98 98
99 scoped_refptr<TestNowSource> now_src_; 99 scoped_ptr<base::SimpleTestTickClock> now_src_;
100 scoped_refptr<base::NullTaskRunner> null_task_runner_; 100 scoped_refptr<base::NullTaskRunner> null_task_runner_;
101 101
102 FakeBeginFrameSource fake_begin_frame_source_; 102 FakeBeginFrameSource fake_begin_frame_source_;
103 scoped_ptr<FakeDisplaySchedulerClient> client_; 103 scoped_ptr<FakeDisplaySchedulerClient> client_;
104 scoped_ptr<TestDisplayScheduler> scheduler_; 104 scoped_ptr<TestDisplayScheduler> scheduler_;
105 }; 105 };
106 106
107 TEST_F(DisplaySchedulerTest, EntireDisplayDamagedDrawsImmediately) { 107 TEST_F(DisplaySchedulerTest, EntireDisplayDamagedDrawsImmediately) {
108 SurfaceId root_surface_id(1); 108 SurfaceId root_surface_id(1);
109 BeginFrameForTest(); 109 BeginFrameForTest();
110 EXPECT_LT(now_src().Now(), 110 EXPECT_LT(now_src().NowTicks(),
111 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 111 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
112 scheduler_->EntireDisplayDamaged(root_surface_id); 112 scheduler_->EntireDisplayDamaged(root_surface_id);
113 EXPECT_GE(now_src().Now(), 113 EXPECT_GE(now_src().NowTicks(),
114 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 114 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
115 } 115 }
116 116
117 TEST_F(DisplaySchedulerTest, SurfaceDamaged) { 117 TEST_F(DisplaySchedulerTest, SurfaceDamaged) {
118 SurfaceId root_surface_id(0); 118 SurfaceId root_surface_id(0);
119 SurfaceId sid1(1); 119 SurfaceId sid1(1);
120 SurfaceId sid2(2); 120 SurfaceId sid2(2);
121 121
122 // Set the root surface 122 // Set the root surface
123 scheduler_->EntireDisplayDamaged(root_surface_id); 123 scheduler_->EntireDisplayDamaged(root_surface_id);
124 124
125 // Get scheduler to detect surface 1 as active by drawing 125 // Get scheduler to detect surface 1 as active by drawing
126 // two frames in a row with damage from surface 1. 126 // two frames in a row with damage from surface 1.
127 BeginFrameForTest(); 127 BeginFrameForTest();
128 scheduler_->SurfaceDamaged(sid1); 128 scheduler_->SurfaceDamaged(sid1);
129 scheduler_->BeginFrameDeadlineForTest(); 129 scheduler_->BeginFrameDeadlineForTest();
130 BeginFrameForTest(); 130 BeginFrameForTest();
131 scheduler_->SurfaceDamaged(sid1); 131 scheduler_->SurfaceDamaged(sid1);
132 scheduler_->BeginFrameDeadlineForTest(); 132 scheduler_->BeginFrameDeadlineForTest();
133 133
134 // Damage only from surface 2 (inactive) does not trigger deadline early. 134 // Damage only from surface 2 (inactive) does not trigger deadline early.
135 BeginFrameForTest(); 135 BeginFrameForTest();
136 scheduler_->SurfaceDamaged(sid2); 136 scheduler_->SurfaceDamaged(sid2);
137 EXPECT_LT(now_src().Now(), 137 EXPECT_LT(now_src().NowTicks(),
138 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 138 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
139 139
140 // Damage from surface 1 triggers deadline early. 140 // Damage from surface 1 triggers deadline early.
141 scheduler_->SurfaceDamaged(sid1); 141 scheduler_->SurfaceDamaged(sid1);
142 EXPECT_GE(now_src().Now(), 142 EXPECT_GE(now_src().NowTicks(),
143 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 143 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
144 scheduler_->BeginFrameDeadlineForTest(); 144 scheduler_->BeginFrameDeadlineForTest();
145 145
146 // Make both surface 1 and 2 active. 146 // Make both surface 1 and 2 active.
147 BeginFrameForTest(); 147 BeginFrameForTest();
148 scheduler_->SurfaceDamaged(sid2); 148 scheduler_->SurfaceDamaged(sid2);
149 scheduler_->SurfaceDamaged(sid1); 149 scheduler_->SurfaceDamaged(sid1);
150 scheduler_->BeginFrameDeadlineForTest(); 150 scheduler_->BeginFrameDeadlineForTest();
151 151
152 // Deadline doesn't trigger early until surface 1 and 2 are both damaged. 152 // Deadline doesn't trigger early until surface 1 and 2 are both damaged.
153 BeginFrameForTest(); 153 BeginFrameForTest();
154 EXPECT_LT(now_src().Now(), 154 EXPECT_LT(now_src().NowTicks(),
155 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 155 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
156 scheduler_->SurfaceDamaged(sid1); 156 scheduler_->SurfaceDamaged(sid1);
157 EXPECT_LT(now_src().Now(), 157 EXPECT_LT(now_src().NowTicks(),
158 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 158 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
159 scheduler_->SurfaceDamaged(sid2); 159 scheduler_->SurfaceDamaged(sid2);
160 EXPECT_GE(now_src().Now(), 160 EXPECT_GE(now_src().NowTicks(),
161 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 161 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
162 scheduler_->BeginFrameDeadlineForTest(); 162 scheduler_->BeginFrameDeadlineForTest();
163 163
164 // Make the system idle 164 // Make the system idle
165 BeginFrameForTest(); 165 BeginFrameForTest();
166 scheduler_->BeginFrameDeadlineForTest(); 166 scheduler_->BeginFrameDeadlineForTest();
167 BeginFrameForTest(); 167 BeginFrameForTest();
168 scheduler_->BeginFrameDeadlineForTest(); 168 scheduler_->BeginFrameDeadlineForTest();
169 169
170 // Deadline should trigger early if child surfaces are idle and 170 // Deadline should trigger early if child surfaces are idle and
171 // we get damage on the root surface. 171 // we get damage on the root surface.
172 BeginFrameForTest(); 172 BeginFrameForTest();
173 EXPECT_LT(now_src().Now(), 173 EXPECT_LT(now_src().NowTicks(),
174 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 174 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
175 scheduler_->SurfaceDamaged(root_surface_id); 175 scheduler_->SurfaceDamaged(root_surface_id);
176 EXPECT_GE(now_src().Now(), 176 EXPECT_GE(now_src().NowTicks(),
177 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 177 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
178 scheduler_->BeginFrameDeadlineForTest(); 178 scheduler_->BeginFrameDeadlineForTest();
179 } 179 }
180 180
181 TEST_F(DisplaySchedulerTest, OutputSurfaceLost) { 181 TEST_F(DisplaySchedulerTest, OutputSurfaceLost) {
182 SurfaceId sid1(1); 182 SurfaceId sid1(1);
183 183
184 // DrawAndSwap normally. 184 // DrawAndSwap normally.
185 BeginFrameForTest(); 185 BeginFrameForTest();
186 EXPECT_LT(now_src().Now(), 186 EXPECT_LT(now_src().NowTicks(),
187 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 187 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
188 EXPECT_EQ(0, client_->draw_and_swap_count()); 188 EXPECT_EQ(0, client_->draw_and_swap_count());
189 scheduler_->SurfaceDamaged(sid1); 189 scheduler_->SurfaceDamaged(sid1);
190 scheduler_->BeginFrameDeadlineForTest(); 190 scheduler_->BeginFrameDeadlineForTest();
191 EXPECT_EQ(1, client_->draw_and_swap_count()); 191 EXPECT_EQ(1, client_->draw_and_swap_count());
192 192
193 // Deadline triggers immediately on OutputSurfaceLost. 193 // Deadline triggers immediately on OutputSurfaceLost.
194 BeginFrameForTest(); 194 BeginFrameForTest();
195 EXPECT_LT(now_src().Now(), 195 EXPECT_LT(now_src().NowTicks(),
196 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 196 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
197 scheduler_->OutputSurfaceLost(); 197 scheduler_->OutputSurfaceLost();
198 EXPECT_GE(now_src().Now(), 198 EXPECT_GE(now_src().NowTicks(),
199 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 199 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
200 200
201 // Deadline does not DrawAndSwap after OutputSurfaceLost. 201 // Deadline does not DrawAndSwap after OutputSurfaceLost.
202 EXPECT_EQ(1, client_->draw_and_swap_count()); 202 EXPECT_EQ(1, client_->draw_and_swap_count());
203 scheduler_->SurfaceDamaged(sid1); 203 scheduler_->SurfaceDamaged(sid1);
204 scheduler_->BeginFrameDeadlineForTest(); 204 scheduler_->BeginFrameDeadlineForTest();
205 EXPECT_EQ(1, client_->draw_and_swap_count()); 205 EXPECT_EQ(1, client_->draw_and_swap_count());
206 } 206 }
207 207
208 TEST_F(DisplaySchedulerTest, RootSurfaceResourcesLocked) { 208 TEST_F(DisplaySchedulerTest, RootSurfaceResourcesLocked) {
209 SurfaceId sid1(1); 209 SurfaceId sid1(1);
210 base::TimeTicks late_deadline; 210 base::TimeTicks late_deadline;
211 211
212 // DrawAndSwap normally. 212 // DrawAndSwap normally.
213 BeginFrameForTest(); 213 BeginFrameForTest();
214 EXPECT_LT(now_src().Now(), 214 EXPECT_LT(now_src().NowTicks(),
215 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 215 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
216 EXPECT_EQ(0, client_->draw_and_swap_count()); 216 EXPECT_EQ(0, client_->draw_and_swap_count());
217 scheduler_->SurfaceDamaged(sid1); 217 scheduler_->SurfaceDamaged(sid1);
218 scheduler_->BeginFrameDeadlineForTest(); 218 scheduler_->BeginFrameDeadlineForTest();
219 EXPECT_EQ(1, client_->draw_and_swap_count()); 219 EXPECT_EQ(1, client_->draw_and_swap_count());
220 220
221 // Deadline triggers late while root resources are locked. 221 // Deadline triggers late while root resources are locked.
222 late_deadline = now_src().Now() + BeginFrameArgs::DefaultInterval(); 222 late_deadline = now_src().NowTicks() + BeginFrameArgs::DefaultInterval();
223 BeginFrameForTest(); 223 BeginFrameForTest();
224 scheduler_->SurfaceDamaged(sid1); 224 scheduler_->SurfaceDamaged(sid1);
225 EXPECT_GT(late_deadline, scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 225 EXPECT_GT(late_deadline, scheduler_->DesiredBeginFrameDeadlineTimeForTest());
226 scheduler_->SetRootSurfaceResourcesLocked(true); 226 scheduler_->SetRootSurfaceResourcesLocked(true);
227 EXPECT_EQ(late_deadline, scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 227 EXPECT_EQ(late_deadline, scheduler_->DesiredBeginFrameDeadlineTimeForTest());
228 228
229 // Deadline does not DrawAndSwap while root resources are locked. 229 // Deadline does not DrawAndSwap while root resources are locked.
230 EXPECT_EQ(1, client_->draw_and_swap_count()); 230 EXPECT_EQ(1, client_->draw_and_swap_count());
231 scheduler_->SurfaceDamaged(sid1); 231 scheduler_->SurfaceDamaged(sid1);
232 scheduler_->BeginFrameDeadlineForTest(); 232 scheduler_->BeginFrameDeadlineForTest();
233 EXPECT_EQ(1, client_->draw_and_swap_count()); 233 EXPECT_EQ(1, client_->draw_and_swap_count());
234 234
235 // Deadline triggers normally when root resources are unlocked. 235 // Deadline triggers normally when root resources are unlocked.
236 late_deadline = now_src().Now() + BeginFrameArgs::DefaultInterval(); 236 late_deadline = now_src().NowTicks() + BeginFrameArgs::DefaultInterval();
237 BeginFrameForTest(); 237 BeginFrameForTest();
238 scheduler_->SurfaceDamaged(sid1); 238 scheduler_->SurfaceDamaged(sid1);
239 EXPECT_EQ(late_deadline, scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 239 EXPECT_EQ(late_deadline, scheduler_->DesiredBeginFrameDeadlineTimeForTest());
240 scheduler_->SetRootSurfaceResourcesLocked(false); 240 scheduler_->SetRootSurfaceResourcesLocked(false);
241 EXPECT_EQ(base::TimeTicks(), 241 EXPECT_EQ(base::TimeTicks(),
242 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 242 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
243 243
244 EXPECT_EQ(1, client_->draw_and_swap_count()); 244 EXPECT_EQ(1, client_->draw_and_swap_count());
245 scheduler_->BeginFrameDeadlineForTest(); 245 scheduler_->BeginFrameDeadlineForTest();
246 EXPECT_EQ(2, client_->draw_and_swap_count()); 246 EXPECT_EQ(2, client_->draw_and_swap_count());
247 } 247 }
248 248
249 TEST_F(DisplaySchedulerTest, DidSwapBuffers) { 249 TEST_F(DisplaySchedulerTest, DidSwapBuffers) {
250 SurfaceId sid1(1); 250 SurfaceId sid1(1);
251 SurfaceId sid2(2); 251 SurfaceId sid2(2);
252 base::TimeTicks expected_deadline; 252 base::TimeTicks expected_deadline;
253 253
254 // Get scheduler to detect surface 1 and 2 as active. 254 // Get scheduler to detect surface 1 and 2 as active.
255 BeginFrameForTest(); 255 BeginFrameForTest();
256 scheduler_->SurfaceDamaged(sid1); 256 scheduler_->SurfaceDamaged(sid1);
257 scheduler_->SurfaceDamaged(sid2); 257 scheduler_->SurfaceDamaged(sid2);
258 scheduler_->BeginFrameDeadlineForTest(); 258 scheduler_->BeginFrameDeadlineForTest();
259 BeginFrameForTest(); 259 BeginFrameForTest();
260 scheduler_->SurfaceDamaged(sid1); 260 scheduler_->SurfaceDamaged(sid1);
261 scheduler_->SurfaceDamaged(sid2); 261 scheduler_->SurfaceDamaged(sid2);
262 scheduler_->BeginFrameDeadlineForTest(); 262 scheduler_->BeginFrameDeadlineForTest();
263 263
264 // DrawAndSwap normally. 264 // DrawAndSwap normally.
265 BeginFrameForTest(); 265 BeginFrameForTest();
266 EXPECT_LT(now_src().Now(), 266 EXPECT_LT(now_src().NowTicks(),
267 scheduler_->DesiredBeginFrameDeadlineTimeForTest()); 267 scheduler_->DesiredBeginFrameDeadlineTimeForTest());
268 EXPECT_EQ(2, client_->draw_and_swap_count()); 268 EXPECT_EQ(2, client_->draw_and_swap_count());
269 scheduler_->SurfaceDamaged(sid1); 269 scheduler_->SurfaceDamaged(sid1);
270 scheduler_->SurfaceDamaged(sid2); 270 scheduler_->SurfaceDamaged(sid2);
271 scheduler_->BeginFrameDeadlineForTest(); 271 scheduler_->BeginFrameDeadlineForTest();
272 EXPECT_EQ(3, client_->draw_and_swap_count()); 272 EXPECT_EQ(3, client_->draw_and_swap_count());
273 scheduler_->DidSwapBuffers(); 273 scheduler_->DidSwapBuffers();
274 274
275 // Deadline triggers normally when swap throttled. 275 // Deadline triggers normally when swap throttled.
276 expected_deadline = 276 expected_deadline =
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 335
336 scheduler_->SetRootSurfaceResourcesLocked(true); 336 scheduler_->SetRootSurfaceResourcesLocked(true);
337 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count()); 337 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count());
338 338
339 scheduler_->OutputSurfaceLost(); 339 scheduler_->OutputSurfaceLost();
340 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count()); 340 EXPECT_EQ(count++, scheduler_->scheduler_begin_frame_deadline_count());
341 } 341 }
342 342
343 } // namespace 343 } // namespace
344 } // namespace cc 344 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_unittest.cc ('k') | cc/surfaces/surface_display_output_surface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698