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

Side by Side Diff: cc/scheduler/scheduler_unittest.cc

Issue 24304002: cc: Implement deadline scheduling disabled by default (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 7 years, 3 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
« no previous file with comments | « cc/scheduler/scheduler_state_machine_unittest.cc ('k') | cc/trees/layer_tree_host_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
5 #include "cc/scheduler/scheduler.h" 4 #include "cc/scheduler/scheduler.h"
6 5
7 #include <string> 6 #include <string>
8 #include <vector> 7 #include <vector>
9 8
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
12 #include "cc/test/scheduler_test_common.h" 11 #include "cc/test/scheduler_test_common.h"
13 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 13 matching lines...) Expand all
28 27
29 namespace cc { 28 namespace cc {
30 namespace { 29 namespace {
31 30
32 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler) { 31 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler) {
33 scheduler->DidCreateAndInitializeOutputSurface(); 32 scheduler->DidCreateAndInitializeOutputSurface();
34 scheduler->SetNeedsCommit(); 33 scheduler->SetNeedsCommit();
35 scheduler->FinishCommit(); 34 scheduler->FinishCommit();
36 // Go through the motions to draw the commit. 35 // Go through the motions to draw the commit.
37 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 36 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
38 // We need another BeginFrame so scheduler calls SetNeedsBeginFrame(false). 37 scheduler->OnBeginFrameDeadline();
38 // We need another BeginFrame so Scheduler calls SetNeedsBeginFrame(false).
39 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 39 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
40 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 40 scheduler->OnBeginFrameDeadline();
41 } 41 }
42 42
43 class FakeSchedulerClient : public SchedulerClient { 43 class FakeSchedulerClient : public SchedulerClient {
44 public: 44 public:
45 FakeSchedulerClient() 45 FakeSchedulerClient()
46 : needs_begin_frame_(false) { 46 : needs_begin_frame_(false) {
47 Reset(); 47 Reset();
48 } 48 }
49 49
50 void Reset() { 50 void Reset() {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE { 149 virtual base::TimeDelta DrawDurationEstimate() OVERRIDE {
150 return base::TimeDelta(); 150 return base::TimeDelta();
151 } 151 }
152 virtual base::TimeDelta BeginFrameToCommitDurationEstimate() OVERRIDE { 152 virtual base::TimeDelta BeginFrameToCommitDurationEstimate() OVERRIDE {
153 return base::TimeDelta(); 153 return base::TimeDelta();
154 } 154 }
155 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { 155 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE {
156 return base::TimeDelta(); 156 return base::TimeDelta();
157 } 157 }
158 158
159 virtual void PostBeginFrameDeadline(const base::Closure& closure,
160 base::TimeTicks deadline) OVERRIDE {
161 actions_.push_back("PostBeginFrameDeadlineTask");
162 states_.push_back(scheduler_->StateAsValue().release());
163 }
164
165 virtual void DidBeginFrameDeadlineOnImplThread() OVERRIDE {}
166
159 protected: 167 protected:
160 bool needs_begin_frame_; 168 bool needs_begin_frame_;
161 bool draw_will_happen_; 169 bool draw_will_happen_;
162 bool swap_will_happen_if_draw_happens_; 170 bool swap_will_happen_if_draw_happens_;
163 int num_draws_; 171 int num_draws_;
164 std::vector<const char*> actions_; 172 std::vector<const char*> actions_;
165 ScopedVector<base::Value> states_; 173 ScopedVector<base::Value> states_;
166 scoped_ptr<Scheduler> scheduler_; 174 scoped_ptr<Scheduler> scheduler_;
167 }; 175 };
168 176
169 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginFrame) { 177 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginFrame) {
170 FakeSchedulerClient client; 178 FakeSchedulerClient client;
171 SchedulerSettings default_scheduler_settings; 179 SchedulerSettings default_scheduler_settings;
172 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 180 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
173 scheduler->SetCanStart(); 181 scheduler->SetCanStart();
174 scheduler->SetVisible(true); 182 scheduler->SetVisible(true);
175 scheduler->SetCanDraw(true); 183 scheduler->SetCanDraw(true);
176 184
177 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 185 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
178 client.Reset(); 186 client.Reset();
179 scheduler->DidCreateAndInitializeOutputSurface(); 187 scheduler->DidCreateAndInitializeOutputSurface();
180 EXPECT_EQ(0, client.num_actions_()); 188 EXPECT_EQ(0, client.num_actions_());
181 } 189 }
182 190
183 TEST(SchedulerTest, RequestCommit) { 191 void RequestCommit(bool deadline_scheduling_enabled) {
184 FakeSchedulerClient client; 192 FakeSchedulerClient client;
185 SchedulerSettings default_scheduler_settings; 193 SchedulerSettings scheduler_settings;
186 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 194 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled;
195 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
187 scheduler->SetCanStart(); 196 scheduler->SetCanStart();
188 scheduler->SetVisible(true); 197 scheduler->SetVisible(true);
189 scheduler->SetCanDraw(true); 198 scheduler->SetCanDraw(true);
190 199
191 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 200 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
192 InitializeOutputSurfaceAndFirstCommit(scheduler); 201 InitializeOutputSurfaceAndFirstCommit(scheduler);
193 202
194 // SetNeedsCommit should begin the frame. 203 // SetNeedsCommit should begin the frame on the next BeginFrame.
195 client.Reset(); 204 client.Reset();
196 scheduler->SetNeedsCommit(); 205 scheduler->SetNeedsCommit();
197 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); 206 EXPECT_TRUE(client.needs_begin_frame());
198 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); 207 if (deadline_scheduling_enabled) {
208 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
209 } else {
210 EXPECT_EQ(client.num_actions_(), 2);
211 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginFrameToMainThread"));
212 EXPECT_TRUE(client.HasAction("SetNeedsBeginFrameOnImplThread"));
213 }
214 client.Reset();
215
216 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
217 if (deadline_scheduling_enabled) {
218 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
219 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
220 } else {
221 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
222 }
199 EXPECT_TRUE(client.needs_begin_frame()); 223 EXPECT_TRUE(client.needs_begin_frame());
200 client.Reset(); 224 client.Reset();
201 225
226 // If we don't swap on the deadline, we need to request another BeginFrame.
227 scheduler->OnBeginFrameDeadline();
228 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
229 EXPECT_TRUE(client.needs_begin_frame());
230 client.Reset();
231
202 // FinishCommit should commit 232 // FinishCommit should commit
203 scheduler->FinishCommit(); 233 scheduler->FinishCommit();
204 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 234 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
205 EXPECT_TRUE(client.needs_begin_frame()); 235 EXPECT_TRUE(client.needs_begin_frame());
206 client.Reset(); 236 client.Reset();
207 237
208 // BeginFrame should draw. 238 // BeginFrame should prepare the draw.
209 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 239 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
240 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
241 EXPECT_TRUE(client.needs_begin_frame());
242 client.Reset();
243
244 // BeginFrame deadline should draw.
245 scheduler->OnBeginFrameDeadline();
210 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 246 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
211 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); 247 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
212 EXPECT_TRUE(client.needs_begin_frame()); 248 EXPECT_TRUE(client.needs_begin_frame());
213 client.Reset(); 249 client.Reset();
250
251 // The following BeginFrame deadline should SetNeedsBeginFrame(false) to avoid
252 // excessive toggles.
253 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
254 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
255 client.Reset();
256
257 scheduler->OnBeginFrameDeadline();
258 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
259 EXPECT_FALSE(client.needs_begin_frame());
260 client.Reset();
214 } 261 }
215 262
216 TEST(SchedulerTest, RequestCommitAfterBeginFrameSentToMainThread) { 263 TEST(SchedulerTest, RequestCommit) {
264 bool deadline_scheduling_enabled = false;
265 RequestCommit(deadline_scheduling_enabled);
266 }
267
268 TEST(SchedulerTest, RequestCommit_Deadline) {
269 bool deadline_scheduling_enabled = true;
270 RequestCommit(deadline_scheduling_enabled);
271 }
272
273 void RequestCommitAfterBeginFrameSentToMainThread(
274 bool deadline_scheduling_enabled) {
217 FakeSchedulerClient client; 275 FakeSchedulerClient client;
218 SchedulerSettings default_scheduler_settings; 276 SchedulerSettings scheduler_settings;
219 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 277 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled;
278 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
220 scheduler->SetCanStart(); 279 scheduler->SetCanStart();
221 scheduler->SetVisible(true); 280 scheduler->SetVisible(true);
222 scheduler->SetCanDraw(true); 281 scheduler->SetCanDraw(true);
223 282
224 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 283 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
225 InitializeOutputSurfaceAndFirstCommit(scheduler); 284 InitializeOutputSurfaceAndFirstCommit(scheduler);
226 client.Reset(); 285 client.Reset();
227 286
228 // SetNedsCommit should begin the frame. 287 // SetNeedsCommit should begin the frame.
229 scheduler->SetNeedsCommit(); 288 scheduler->SetNeedsCommit();
230 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); 289 if (deadline_scheduling_enabled) {
231 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); 290 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
291 } else {
292 EXPECT_EQ(client.num_actions_(), 2);
293 EXPECT_TRUE(client.HasAction("SetNeedsBeginFrameOnImplThread"));
294 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginFrameToMainThread"));
295 }
296
297 client.Reset();
298 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
299 if (deadline_scheduling_enabled) {
300 EXPECT_EQ(client.num_actions_(), 2);
301 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginFrameToMainThread"));
302 EXPECT_TRUE(client.HasAction("PostBeginFrameDeadlineTask"));
303 } else {
304 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
305 }
306
307 EXPECT_TRUE(client.needs_begin_frame());
232 client.Reset(); 308 client.Reset();
233 309
234 // Now SetNeedsCommit again. Calling here means we need a second frame. 310 // Now SetNeedsCommit again. Calling here means we need a second commit.
235 scheduler->SetNeedsCommit(); 311 scheduler->SetNeedsCommit();
236 312 EXPECT_EQ(client.num_actions_(), 0);
237 // Finish the commit for the first frame.
238 scheduler->FinishCommit();
239 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
240 client.Reset(); 313 client.Reset();
241 314
242 // Tick should draw but then begin another frame for the second commit. 315 // Finish the first commit.
316 scheduler->FinishCommit();
317 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2);
318 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
319 client.Reset();
320 scheduler->OnBeginFrameDeadline();
321 if (deadline_scheduling_enabled) {
322 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
323 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
324 } else {
325 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3);
326 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 3);
327 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3);
328 }
329
243 // Because we just swapped, the Scheduler should also request the next 330 // Because we just swapped, the Scheduler should also request the next
244 // BeginFrame from the OutputSurface. 331 // BeginFrame from the OutputSurface.
245 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
246 EXPECT_TRUE(client.needs_begin_frame()); 332 EXPECT_TRUE(client.needs_begin_frame());
247 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3);
248 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 3);
249 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3);
250 client.Reset(); 333 client.Reset();
251 334
252 // Finish the second commit. 335 // Since another commit is needed, the next BeginFrame should initiate
336 // the second commit.
337 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
338 if (deadline_scheduling_enabled) {
339 EXPECT_EQ(client.num_actions_(), 2);
340 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginFrameToMainThread"));
341 EXPECT_TRUE(client.HasAction("PostBeginFrameDeadlineTask"));
342 } else {
343 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
344 }
345 client.Reset();
346
347 // Finishing the commit before the deadline should post a new deadline task
348 // to trigger the deadline early.
253 scheduler->FinishCommit(); 349 scheduler->FinishCommit();
254 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 350 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2);
255 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); 351 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
256 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 3); 352 client.Reset();
257 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); 353 scheduler->OnBeginFrameDeadline();
354 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
355 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
258 EXPECT_TRUE(client.needs_begin_frame()); 356 EXPECT_TRUE(client.needs_begin_frame());
259 client.Reset(); 357 client.Reset();
260 358
261 // On the next BeginFrame, verify we go back to a quiescent state and 359 // On the next BeginFrame, verify we go back to a quiescent state and
262 // no longer request BeginFrames. 360 // no longer request BeginFrames.
263 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 361 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
362 scheduler->OnBeginFrameDeadline();
264 EXPECT_FALSE(client.needs_begin_frame()); 363 EXPECT_FALSE(client.needs_begin_frame());
364 client.Reset();
265 } 365 }
266 366
267 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { 367 TEST(SchedulerTest, RequestCommitAfterBeginFrameSentToMainThread) {
368 bool deadline_scheduling_enabled = false;
369 RequestCommitAfterBeginFrameSentToMainThread(deadline_scheduling_enabled);
370 }
371
372 TEST(SchedulerTest, RequestCommitAfterBeginFrameSentToMainThread_Deadline) {
373 bool deadline_scheduling_enabled = true;
374 RequestCommitAfterBeginFrameSentToMainThread(deadline_scheduling_enabled);
375 }
376
377 void TextureAcquisitionCausesCommitInsteadOfDraw(
378 bool deadline_scheduling_enabled) {
268 FakeSchedulerClient client; 379 FakeSchedulerClient client;
269 SchedulerSettings default_scheduler_settings; 380 SchedulerSettings scheduler_settings;
270 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 381 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled;
382 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
271 scheduler->SetCanStart(); 383 scheduler->SetCanStart();
272 scheduler->SetVisible(true); 384 scheduler->SetVisible(true);
273 scheduler->SetCanDraw(true); 385 scheduler->SetCanDraw(true);
274 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 386 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
275 387
276 InitializeOutputSurfaceAndFirstCommit(scheduler); 388 InitializeOutputSurfaceAndFirstCommit(scheduler);
277 client.Reset(); 389 client.Reset();
278 scheduler->SetNeedsRedraw(); 390 scheduler->SetNeedsRedraw();
279 EXPECT_TRUE(scheduler->RedrawPending()); 391 EXPECT_TRUE(scheduler->RedrawPending());
280 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); 392 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
281 EXPECT_TRUE(client.needs_begin_frame()); 393 EXPECT_TRUE(client.needs_begin_frame());
282 394
283 client.Reset(); 395 client.Reset();
284 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 396 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
397 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
398 client.Reset();
399 scheduler->OnBeginFrameDeadline();
285 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 400 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
286 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); 401 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
287 EXPECT_FALSE(scheduler->RedrawPending()); 402 EXPECT_FALSE(scheduler->RedrawPending());
288 EXPECT_TRUE(client.needs_begin_frame()); 403 EXPECT_TRUE(client.needs_begin_frame());
289 404
290 client.Reset(); 405 client.Reset();
291 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 406 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
407 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
408 client.Reset();
409 scheduler->OnBeginFrameDeadline();
292 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); 410 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
293 EXPECT_FALSE(scheduler->RedrawPending()); 411 EXPECT_FALSE(scheduler->RedrawPending());
294 EXPECT_FALSE(client.needs_begin_frame()); 412 EXPECT_FALSE(client.needs_begin_frame());
295 413
296 client.Reset(); 414 client.Reset();
297 scheduler->SetMainThreadNeedsLayerTextures(); 415 scheduler->SetMainThreadNeedsLayerTextures();
298 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", 416 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread",
299 client); 417 client);
300 418
301 // We should request a BeginFrame in anticipation of a draw. 419 // We should request a BeginFrame in anticipation of a draw.
302 client.Reset(); 420 client.Reset();
303 scheduler->SetNeedsRedraw(); 421 scheduler->SetNeedsRedraw();
304 EXPECT_TRUE(scheduler->RedrawPending()); 422 EXPECT_TRUE(scheduler->RedrawPending());
305 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); 423 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
306 EXPECT_TRUE(client.needs_begin_frame()); 424 EXPECT_TRUE(client.needs_begin_frame());
307 425
308 // No draw happens since the textures are acquired by the main thread. 426 // No draw happens since the textures are acquired by the main thread.
309 client.Reset(); 427 client.Reset();
310 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 428 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
429 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
430 client.Reset();
431 scheduler->OnBeginFrameDeadline();
311 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); 432 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
312 EXPECT_TRUE(scheduler->RedrawPending()); 433 EXPECT_TRUE(scheduler->RedrawPending());
313 EXPECT_TRUE(client.needs_begin_frame()); 434 EXPECT_TRUE(client.needs_begin_frame());
314 435
436 client.Reset();
315 scheduler->SetNeedsCommit(); 437 scheduler->SetNeedsCommit();
316 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 0, 2); 438 if (deadline_scheduling_enabled) {
317 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 2); 439 EXPECT_EQ(0, client.num_actions_());
318 EXPECT_TRUE(client.needs_begin_frame()); 440 } else {
441 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginFrameToMainThread", client);
442 }
443
444 client.Reset();
445 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
446 if (deadline_scheduling_enabled) {
447 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
448 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
449 } else {
450 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
451 }
319 452
320 // Commit will release the texture. 453 // Commit will release the texture.
321 client.Reset(); 454 client.Reset();
322 scheduler->FinishCommit(); 455 scheduler->FinishCommit();
323 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); 456 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2);
457 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
324 EXPECT_TRUE(scheduler->RedrawPending()); 458 EXPECT_TRUE(scheduler->RedrawPending());
325 EXPECT_TRUE(client.needs_begin_frame());
326 459
327 // Now we can draw again after the commit happens. 460 // Now we can draw again after the commit happens.
328 client.Reset(); 461 client.Reset();
329 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 462 scheduler->OnBeginFrameDeadline();
330 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 463 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
331 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); 464 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
332 EXPECT_FALSE(scheduler->RedrawPending()); 465 EXPECT_FALSE(scheduler->RedrawPending());
333 EXPECT_TRUE(client.needs_begin_frame()); 466 EXPECT_TRUE(client.needs_begin_frame());
334 467
335 // Make sure we stop requesting BeginFrames if we don't swap. 468 // Make sure we stop requesting BeginFrames if we don't swap.
336 client.Reset(); 469 client.Reset();
337 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 470 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
471 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
472 client.Reset();
473 scheduler->OnBeginFrameDeadline();
338 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); 474 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
339 EXPECT_FALSE(client.needs_begin_frame()); 475 EXPECT_FALSE(client.needs_begin_frame());
340 } 476 }
341 477
342 TEST(SchedulerTest, TextureAcquisitionCollision) { 478 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) {
479 bool deadline_scheduling_enabled = false;
480 TextureAcquisitionCausesCommitInsteadOfDraw(deadline_scheduling_enabled);
481 }
482
483 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw_Deadline) {
484 bool deadline_scheduling_enabled = true;
485 TextureAcquisitionCausesCommitInsteadOfDraw(deadline_scheduling_enabled);
486 }
487
488 void TextureAcquisitionCollision(bool deadline_scheduling_enabled) {
343 FakeSchedulerClient client; 489 FakeSchedulerClient client;
344 SchedulerSettings default_scheduler_settings; 490 SchedulerSettings scheduler_settings;
345 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 491 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled;
492 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
346 scheduler->SetCanStart(); 493 scheduler->SetCanStart();
347 scheduler->SetVisible(true); 494 scheduler->SetVisible(true);
348 scheduler->SetCanDraw(true); 495 scheduler->SetCanDraw(true);
349 496
350 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 497 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
351 InitializeOutputSurfaceAndFirstCommit(scheduler); 498 InitializeOutputSurfaceAndFirstCommit(scheduler);
352 499
353 client.Reset(); 500 client.Reset();
354 scheduler->SetNeedsCommit(); 501 scheduler->SetNeedsCommit();
502 if (deadline_scheduling_enabled) {
503 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
504 } else {
505 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
506 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
507 }
508
509 client.Reset();
355 scheduler->SetMainThreadNeedsLayerTextures(); 510 scheduler->SetMainThreadNeedsLayerTextures();
356 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 3); 511 EXPECT_SINGLE_ACTION(
357 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 3); 512 "ScheduledActionAcquireLayerTexturesForMainThread", client);
358 EXPECT_ACTION( 513
359 "ScheduledActionAcquireLayerTexturesForMainThread", client, 2, 3);
360 client.Reset(); 514 client.Reset();
515 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
516 if (deadline_scheduling_enabled) {
517 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
518 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
519 } else {
520 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
521 }
522
523 client.Reset();
524 scheduler->OnBeginFrameDeadline();
525 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
361 526
362 // Although the compositor cannot draw because textures are locked by main 527 // Although the compositor cannot draw because textures are locked by main
363 // thread, we continue requesting SetNeedsBeginFrame in anticipation of the 528 // thread, we continue requesting SetNeedsBeginFrame in anticipation of the
364 // unlock. 529 // unlock.
365 EXPECT_TRUE(client.needs_begin_frame()); 530 EXPECT_TRUE(client.needs_begin_frame());
366 531
367 // Trigger the commit 532 // Trigger the commit
368 scheduler->FinishCommit(); 533 scheduler->FinishCommit();
369 EXPECT_TRUE(client.needs_begin_frame()); 534 EXPECT_TRUE(client.needs_begin_frame());
370 client.Reset();
371 535
372 // Between commit and draw, texture acquisition for main thread delayed, 536 // Between commit and draw, texture acquisition for main thread delayed,
373 // and main thread blocks. 537 // and main thread blocks.
538 client.Reset();
374 scheduler->SetMainThreadNeedsLayerTextures(); 539 scheduler->SetMainThreadNeedsLayerTextures();
375 EXPECT_EQ(0, client.num_actions_()); 540 EXPECT_EQ(0, client.num_actions_());
541
542 // No implicit commit is expected.
543 client.Reset();
544 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
545 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
546
547 client.Reset();
548 scheduler->OnBeginFrameDeadline();
549 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3);
550 EXPECT_ACTION(
551 "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3);
552 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3);
553 EXPECT_TRUE(client.needs_begin_frame());
554
555 // The compositor should not draw because textures are locked by main
556 // thread.
557 client.Reset();
558 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
559 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
560 client.Reset();
561 scheduler->OnBeginFrameDeadline();
562 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
563 EXPECT_FALSE(client.needs_begin_frame());
564
565 // The impl thread need an explicit commit from the main thread to lock
566 // the textures.
567 client.Reset();
568 scheduler->SetNeedsCommit();
569 if (deadline_scheduling_enabled) {
570 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
571 } else {
572 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
573 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
574 }
575 EXPECT_TRUE(client.needs_begin_frame());
576
577 client.Reset();
578 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
579 if (deadline_scheduling_enabled) {
580 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
581 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
582 } else {
583 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
584 }
376 client.Reset(); 585 client.Reset();
377 586
378 // No implicit commit is expected. 587 // Trigger the commit, which will trigger the deadline task early.
379 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 588 scheduler->FinishCommit();
380 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); 589 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2);
381 EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", 590 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
382 client,
383 1,
384 3);
385 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3);
386 EXPECT_TRUE(client.needs_begin_frame()); 591 EXPECT_TRUE(client.needs_begin_frame());
387 client.Reset(); 592 client.Reset();
388 593
389 // Compositor not scheduled to draw because textures are locked by main 594 // Verify we draw on the next BeginFrame deadline
390 // thread. 595 scheduler->OnBeginFrameDeadline();
391 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
392 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);
393 EXPECT_FALSE(client.needs_begin_frame());
394 client.Reset();
395
396 // Needs an explicit commit from the main thread.
397 scheduler->SetNeedsCommit();
398 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
399 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
400 client.Reset();
401
402 // Trigger the commit
403 scheduler->FinishCommit();
404 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client);
405 EXPECT_TRUE(client.needs_begin_frame());
406 client.Reset();
407
408 // Verify we draw on the next BeginFrame.
409 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
410 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); 596 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2);
411 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); 597 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2);
412 EXPECT_TRUE(client.needs_begin_frame()); 598 EXPECT_TRUE(client.needs_begin_frame());
413 client.Reset(); 599 client.Reset();
414 } 600 }
415 601
416 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { 602 TEST(SchedulerTest, TextureAcquisitionCollision) {
603 bool deadline_scheduling_enabled = false;
604 TextureAcquisitionCollision(deadline_scheduling_enabled);
605 }
606
607 TEST(SchedulerTest, TextureAcquisitionCollision_Deadline) {
608 bool deadline_scheduling_enabled = true;
609 TextureAcquisitionCollision(deadline_scheduling_enabled);
610 }
611
612 void VisibilitySwitchWithTextureAcquisition(bool deadline_scheduling_enabled) {
417 FakeSchedulerClient client; 613 FakeSchedulerClient client;
418 SchedulerSettings default_scheduler_settings; 614 SchedulerSettings scheduler_settings;
419 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 615 scheduler_settings.deadline_scheduling_enabled = deadline_scheduling_enabled;
616 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
420 scheduler->SetCanStart(); 617 scheduler->SetCanStart();
421 scheduler->SetVisible(true); 618 scheduler->SetVisible(true);
422 scheduler->SetCanDraw(true); 619 scheduler->SetCanDraw(true);
423 620
424 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 621 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
425 client.Reset(); 622 client.Reset();
426 scheduler->DidCreateAndInitializeOutputSurface(); 623 scheduler->DidCreateAndInitializeOutputSurface();
427 624
428 scheduler->SetNeedsCommit(); 625 scheduler->SetNeedsCommit();
626 if (deadline_scheduling_enabled) {
627 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
628 scheduler->OnBeginFrameDeadline();
629 }
429 scheduler->FinishCommit(); 630 scheduler->FinishCommit();
430 scheduler->SetMainThreadNeedsLayerTextures(); 631 scheduler->SetMainThreadNeedsLayerTextures();
431 scheduler->SetNeedsCommit(); 632 scheduler->SetNeedsCommit();
432 client.Reset(); 633 client.Reset();
433 // Verify that pending texture acquisition fires when visibility 634 // Verify that pending texture acquisition fires when visibility
434 // is lost in order to avoid a deadlock. 635 // is lost in order to avoid a deadlock.
435 scheduler->SetVisible(false); 636 scheduler->SetVisible(false);
436 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", 637 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread",
437 client); 638 client);
639
438 client.Reset(); 640 client.Reset();
439
440 // Already sent a begin frame on this current frame, so wait.
441 scheduler->SetVisible(true); 641 scheduler->SetVisible(true);
442 EXPECT_EQ(0, client.num_actions_()); 642 EXPECT_EQ(0, client.num_actions_());
443 client.Reset(); 643 EXPECT_TRUE(client.needs_begin_frame());
444 644
445 // Regaining visibility with textures acquired by main thread while 645 // Regaining visibility with textures acquired by main thread while
446 // compositor is waiting for first draw should result in a request 646 // compositor is waiting for first draw should result in a request
447 // for a new frame in order to escape a deadlock. 647 // for a new frame in order to escape a deadlock.
648 client.Reset();
448 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 649 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
449 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); 650 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2);
450 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); 651 EXPECT_ACTION("PostBeginFrameDeadlineTask", client, 1, 2);
652 }
653
654 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) {
655 bool deadline_scheduling_enabled = false;
656 VisibilitySwitchWithTextureAcquisition(deadline_scheduling_enabled);
657 }
658
659 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition_Deadline) {
660 bool deadline_scheduling_enabled = true;
661 VisibilitySwitchWithTextureAcquisition(deadline_scheduling_enabled);
451 } 662 }
452 663
453 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { 664 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient {
454 public: 665 public:
455 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {} 666 virtual void ScheduledActionSendBeginFrameToMainThread() OVERRIDE {}
456 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() 667 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible()
457 OVERRIDE { 668 OVERRIDE {
458 // Only SetNeedsRedraw the first time this is called 669 // Only SetNeedsRedraw the first time this is called
459 if (!num_draws_) 670 if (!num_draws_)
460 scheduler_->SetNeedsRedraw(); 671 scheduler_->SetNeedsRedraw();
(...skipping 26 matching lines...) Expand all
487 scheduler->SetCanDraw(true); 698 scheduler->SetCanDraw(true);
488 InitializeOutputSurfaceAndFirstCommit(scheduler); 699 InitializeOutputSurfaceAndFirstCommit(scheduler);
489 client.Reset(); 700 client.Reset();
490 701
491 scheduler->SetNeedsRedraw(); 702 scheduler->SetNeedsRedraw();
492 EXPECT_TRUE(scheduler->RedrawPending()); 703 EXPECT_TRUE(scheduler->RedrawPending());
493 EXPECT_TRUE(client.needs_begin_frame()); 704 EXPECT_TRUE(client.needs_begin_frame());
494 EXPECT_EQ(0, client.num_draws()); 705 EXPECT_EQ(0, client.num_draws());
495 706
496 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 707 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
708 scheduler->OnBeginFrameDeadline();
497 EXPECT_EQ(1, client.num_draws()); 709 EXPECT_EQ(1, client.num_draws());
498 EXPECT_TRUE(scheduler->RedrawPending()); 710 EXPECT_TRUE(scheduler->RedrawPending());
499 EXPECT_TRUE(client.needs_begin_frame()); 711 EXPECT_TRUE(client.needs_begin_frame());
500 712
501 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 713 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
714 scheduler->OnBeginFrameDeadline();
502 EXPECT_EQ(2, client.num_draws()); 715 EXPECT_EQ(2, client.num_draws());
503 EXPECT_FALSE(scheduler->RedrawPending()); 716 EXPECT_FALSE(scheduler->RedrawPending());
504 EXPECT_TRUE(client.needs_begin_frame()); 717 EXPECT_TRUE(client.needs_begin_frame());
505 718
506 // We stop requesting BeginFrames after a BeginFrame where we don't swap. 719 // We stop requesting BeginFrames after a BeginFrame where we don't swap.
507 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 720 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
721 scheduler->OnBeginFrameDeadline();
508 EXPECT_EQ(2, client.num_draws()); 722 EXPECT_EQ(2, client.num_draws());
509 EXPECT_FALSE(scheduler->RedrawPending()); 723 EXPECT_FALSE(scheduler->RedrawPending());
510 EXPECT_FALSE(client.needs_begin_frame()); 724 EXPECT_FALSE(client.needs_begin_frame());
511 } 725 }
512 726
513 // Test that requesting redraw inside a failed draw doesn't lose the request. 727 // Test that requesting redraw inside a failed draw doesn't lose the request.
514 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { 728 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) {
515 SchedulerClientThatsetNeedsDrawInsideDraw client; 729 SchedulerClientThatsetNeedsDrawInsideDraw client;
516 SchedulerSettings default_scheduler_settings; 730 SchedulerSettings default_scheduler_settings;
517 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 731 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
518 scheduler->SetCanStart(); 732 scheduler->SetCanStart();
519 scheduler->SetVisible(true); 733 scheduler->SetVisible(true);
520 scheduler->SetCanDraw(true); 734 scheduler->SetCanDraw(true);
521 InitializeOutputSurfaceAndFirstCommit(scheduler); 735 InitializeOutputSurfaceAndFirstCommit(scheduler);
522 client.Reset(); 736 client.Reset();
523 737
524 client.SetDrawWillHappen(false); 738 client.SetDrawWillHappen(false);
525 739
526 scheduler->SetNeedsRedraw(); 740 scheduler->SetNeedsRedraw();
527 EXPECT_TRUE(scheduler->RedrawPending()); 741 EXPECT_TRUE(scheduler->RedrawPending());
528 EXPECT_TRUE(client.needs_begin_frame()); 742 EXPECT_TRUE(client.needs_begin_frame());
529 EXPECT_EQ(0, client.num_draws()); 743 EXPECT_EQ(0, client.num_draws());
530 744
531 // Fail the draw. 745 // Fail the draw.
532 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 746 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
747 scheduler->OnBeginFrameDeadline();
533 EXPECT_EQ(1, client.num_draws()); 748 EXPECT_EQ(1, client.num_draws());
534 749
535 // We have a commit pending and the draw failed, and we didn't lose the redraw 750 // We have a commit pending and the draw failed, and we didn't lose the redraw
536 // request. 751 // request.
537 EXPECT_TRUE(scheduler->CommitPending()); 752 EXPECT_TRUE(scheduler->CommitPending());
538 EXPECT_TRUE(scheduler->RedrawPending()); 753 EXPECT_TRUE(scheduler->RedrawPending());
539 EXPECT_TRUE(client.needs_begin_frame()); 754 EXPECT_TRUE(client.needs_begin_frame());
540 755
541 // Fail the draw again. 756 // Fail the draw again.
542 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 757 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
758 scheduler->OnBeginFrameDeadline();
543 EXPECT_EQ(2, client.num_draws()); 759 EXPECT_EQ(2, client.num_draws());
544 EXPECT_TRUE(scheduler->CommitPending()); 760 EXPECT_TRUE(scheduler->CommitPending());
545 EXPECT_TRUE(scheduler->RedrawPending()); 761 EXPECT_TRUE(scheduler->RedrawPending());
546 EXPECT_TRUE(client.needs_begin_frame()); 762 EXPECT_TRUE(client.needs_begin_frame());
547 763
548 // Draw successfully. 764 // Draw successfully.
549 client.SetDrawWillHappen(true); 765 client.SetDrawWillHappen(true);
550 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 766 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
767 scheduler->OnBeginFrameDeadline();
551 EXPECT_EQ(3, client.num_draws()); 768 EXPECT_EQ(3, client.num_draws());
552 EXPECT_TRUE(scheduler->CommitPending()); 769 EXPECT_TRUE(scheduler->CommitPending());
553 EXPECT_FALSE(scheduler->RedrawPending()); 770 EXPECT_FALSE(scheduler->RedrawPending());
554 EXPECT_TRUE(client.needs_begin_frame()); 771 EXPECT_TRUE(client.needs_begin_frame());
555 } 772 }
556 773
557 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { 774 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient {
558 public: 775 public:
559 SchedulerClientThatSetNeedsCommitInsideDraw() 776 SchedulerClientThatSetNeedsCommitInsideDraw()
560 : set_needs_commit_on_next_draw_(false) {} 777 : set_needs_commit_on_next_draw_(false) {}
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 TEST(SchedulerTest, RequestCommitInsideDraw) { 810 TEST(SchedulerTest, RequestCommitInsideDraw) {
594 SchedulerClientThatSetNeedsCommitInsideDraw client; 811 SchedulerClientThatSetNeedsCommitInsideDraw client;
595 SchedulerSettings default_scheduler_settings; 812 SchedulerSettings default_scheduler_settings;
596 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 813 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
597 scheduler->SetCanStart(); 814 scheduler->SetCanStart();
598 scheduler->SetVisible(true); 815 scheduler->SetVisible(true);
599 scheduler->SetCanDraw(true); 816 scheduler->SetCanDraw(true);
600 InitializeOutputSurfaceAndFirstCommit(scheduler); 817 InitializeOutputSurfaceAndFirstCommit(scheduler);
601 client.Reset(); 818 client.Reset();
602 819
820 EXPECT_FALSE(client.needs_begin_frame());
603 scheduler->SetNeedsRedraw(); 821 scheduler->SetNeedsRedraw();
604 EXPECT_TRUE(scheduler->RedrawPending()); 822 EXPECT_TRUE(scheduler->RedrawPending());
605 EXPECT_EQ(0, client.num_draws()); 823 EXPECT_EQ(0, client.num_draws());
606 EXPECT_TRUE(client.needs_begin_frame()); 824 EXPECT_TRUE(client.needs_begin_frame());
607 825
608 client.SetNeedsCommitOnNextDraw(); 826 client.SetNeedsCommitOnNextDraw();
609 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 827 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
828 client.SetNeedsCommitOnNextDraw();
829 scheduler->OnBeginFrameDeadline();
610 EXPECT_EQ(1, client.num_draws()); 830 EXPECT_EQ(1, client.num_draws());
611 EXPECT_TRUE(scheduler->CommitPending()); 831 EXPECT_TRUE(scheduler->CommitPending());
612 EXPECT_TRUE(client.needs_begin_frame()); 832 EXPECT_TRUE(client.needs_begin_frame());
613 scheduler->FinishCommit(); 833 scheduler->FinishCommit();
614 834
615 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 835 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
616 EXPECT_EQ(2, client.num_draws());; 836 scheduler->OnBeginFrameDeadline();
837 EXPECT_EQ(2, client.num_draws());
838
617 EXPECT_FALSE(scheduler->RedrawPending()); 839 EXPECT_FALSE(scheduler->RedrawPending());
618 EXPECT_FALSE(scheduler->CommitPending()); 840 EXPECT_FALSE(scheduler->CommitPending());
619 EXPECT_TRUE(client.needs_begin_frame()); 841 EXPECT_TRUE(client.needs_begin_frame());
620 842
621 // We stop requesting BeginFrames after a BeginFrame where we don't swap. 843 // We stop requesting BeginFrames after a BeginFrame where we don't swap.
622 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 844 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
845 scheduler->OnBeginFrameDeadline();
623 EXPECT_EQ(2, client.num_draws()); 846 EXPECT_EQ(2, client.num_draws());
624 EXPECT_FALSE(scheduler->RedrawPending()); 847 EXPECT_FALSE(scheduler->RedrawPending());
625 EXPECT_FALSE(scheduler->CommitPending()); 848 EXPECT_FALSE(scheduler->CommitPending());
626 EXPECT_FALSE(client.needs_begin_frame()); 849 EXPECT_FALSE(client.needs_begin_frame());
627 } 850 }
628 851
629 // Tests that when a draw fails then the pending commit should not be dropped. 852 // Tests that when a draw fails then the pending commit should not be dropped.
630 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { 853 TEST(SchedulerTest, RequestCommitInsideFailedDraw) {
631 SchedulerClientThatsetNeedsDrawInsideDraw client; 854 SchedulerClientThatsetNeedsDrawInsideDraw client;
632 SchedulerSettings default_scheduler_settings; 855 SchedulerSettings default_scheduler_settings;
633 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 856 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
634 scheduler->SetCanStart(); 857 scheduler->SetCanStart();
635 scheduler->SetVisible(true); 858 scheduler->SetVisible(true);
636 scheduler->SetCanDraw(true); 859 scheduler->SetCanDraw(true);
637 InitializeOutputSurfaceAndFirstCommit(scheduler); 860 InitializeOutputSurfaceAndFirstCommit(scheduler);
638 client.Reset(); 861 client.Reset();
639 862
640 client.SetDrawWillHappen(false); 863 client.SetDrawWillHappen(false);
641 864
642 scheduler->SetNeedsRedraw(); 865 scheduler->SetNeedsRedraw();
643 EXPECT_TRUE(scheduler->RedrawPending()); 866 EXPECT_TRUE(scheduler->RedrawPending());
644 EXPECT_TRUE(client.needs_begin_frame()); 867 EXPECT_TRUE(client.needs_begin_frame());
645 EXPECT_EQ(0, client.num_draws()); 868 EXPECT_EQ(0, client.num_draws());
646 869
647 // Fail the draw. 870 // Fail the draw.
648 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 871 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
872 scheduler->OnBeginFrameDeadline();
649 EXPECT_EQ(1, client.num_draws()); 873 EXPECT_EQ(1, client.num_draws());
650 874
651 // We have a commit pending and the draw failed, and we didn't lose the commit 875 // We have a commit pending and the draw failed, and we didn't lose the commit
652 // request. 876 // request.
653 EXPECT_TRUE(scheduler->CommitPending()); 877 EXPECT_TRUE(scheduler->CommitPending());
654 EXPECT_TRUE(scheduler->RedrawPending()); 878 EXPECT_TRUE(scheduler->RedrawPending());
655 EXPECT_TRUE(client.needs_begin_frame()); 879 EXPECT_TRUE(client.needs_begin_frame());
656 880
657 // Fail the draw again. 881 // Fail the draw again.
658 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 882 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
883 scheduler->OnBeginFrameDeadline();
659 EXPECT_EQ(2, client.num_draws()); 884 EXPECT_EQ(2, client.num_draws());
660 EXPECT_TRUE(scheduler->CommitPending()); 885 EXPECT_TRUE(scheduler->CommitPending());
661 EXPECT_TRUE(scheduler->RedrawPending()); 886 EXPECT_TRUE(scheduler->RedrawPending());
662 EXPECT_TRUE(client.needs_begin_frame()); 887 EXPECT_TRUE(client.needs_begin_frame());
663 888
664 // Draw successfully. 889 // Draw successfully.
665 client.SetDrawWillHappen(true); 890 client.SetDrawWillHappen(true);
666 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 891 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
892 scheduler->OnBeginFrameDeadline();
667 EXPECT_EQ(3, client.num_draws()); 893 EXPECT_EQ(3, client.num_draws());
668 EXPECT_TRUE(scheduler->CommitPending()); 894 EXPECT_TRUE(scheduler->CommitPending());
669 EXPECT_FALSE(scheduler->RedrawPending()); 895 EXPECT_FALSE(scheduler->RedrawPending());
670 EXPECT_TRUE(client.needs_begin_frame()); 896 EXPECT_TRUE(client.needs_begin_frame());
671 } 897 }
672 898
673 TEST(SchedulerTest, NoSwapWhenDrawFails) { 899 TEST(SchedulerTest, NoSwapWhenDrawFails) {
674 SchedulerClientThatSetNeedsCommitInsideDraw client; 900 SchedulerClientThatSetNeedsCommitInsideDraw client;
675 SchedulerSettings default_scheduler_settings; 901 SchedulerSettings default_scheduler_settings;
676 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 902 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
677 scheduler->SetCanStart(); 903 scheduler->SetCanStart();
678 scheduler->SetVisible(true); 904 scheduler->SetVisible(true);
679 scheduler->SetCanDraw(true); 905 scheduler->SetCanDraw(true);
680 InitializeOutputSurfaceAndFirstCommit(scheduler); 906 InitializeOutputSurfaceAndFirstCommit(scheduler);
681 client.Reset(); 907 client.Reset();
682 908
683 scheduler->SetNeedsRedraw(); 909 scheduler->SetNeedsRedraw();
684 EXPECT_TRUE(scheduler->RedrawPending()); 910 EXPECT_TRUE(scheduler->RedrawPending());
685 EXPECT_TRUE(client.needs_begin_frame()); 911 EXPECT_TRUE(client.needs_begin_frame());
686 EXPECT_EQ(0, client.num_draws()); 912 EXPECT_EQ(0, client.num_draws());
687 913
688 // Draw successfully, this starts a new frame. 914 // Draw successfully, this starts a new frame.
689 client.SetNeedsCommitOnNextDraw(); 915 client.SetNeedsCommitOnNextDraw();
690 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 916 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
917 scheduler->OnBeginFrameDeadline();
691 EXPECT_EQ(1, client.num_draws()); 918 EXPECT_EQ(1, client.num_draws());
692 919
693 scheduler->SetNeedsRedraw(); 920 scheduler->SetNeedsRedraw();
694 EXPECT_TRUE(scheduler->RedrawPending()); 921 EXPECT_TRUE(scheduler->RedrawPending());
695 EXPECT_TRUE(client.needs_begin_frame()); 922 EXPECT_TRUE(client.needs_begin_frame());
696 923
697 // Fail to draw, this should not start a frame. 924 // Fail to draw, this should not start a frame.
698 client.SetDrawWillHappen(false); 925 client.SetDrawWillHappen(false);
699 client.SetNeedsCommitOnNextDraw(); 926 client.SetNeedsCommitOnNextDraw();
700 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 927 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
928 scheduler->OnBeginFrameDeadline();
701 EXPECT_EQ(2, client.num_draws()); 929 EXPECT_EQ(2, client.num_draws());
702 } 930 }
703 931
704 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { 932 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) {
705 FakeSchedulerClient client; 933 FakeSchedulerClient client;
706 SchedulerSettings default_scheduler_settings; 934 SchedulerSettings default_scheduler_settings;
707 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 935 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
708 936
709 // Tell the client that it will fail to swap. 937 // Tell the client that it will fail to swap.
710 client.SetDrawWillHappen(true); 938 client.SetDrawWillHappen(true);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 // be trigged until BeginFrame. 995 // be trigged until BeginFrame.
768 client.Reset(); 996 client.Reset();
769 scheduler->SetNeedsManageTiles(); 997 scheduler->SetNeedsManageTiles();
770 scheduler->SetNeedsRedraw(); 998 scheduler->SetNeedsRedraw();
771 EXPECT_TRUE(scheduler->RedrawPending()); 999 EXPECT_TRUE(scheduler->RedrawPending());
772 EXPECT_TRUE(scheduler->ManageTilesPending()); 1000 EXPECT_TRUE(scheduler->ManageTilesPending());
773 EXPECT_TRUE(client.needs_begin_frame()); 1001 EXPECT_TRUE(client.needs_begin_frame());
774 EXPECT_EQ(0, client.num_draws()); 1002 EXPECT_EQ(0, client.num_draws());
775 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); 1003 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles"));
776 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1004 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
1005
1006 // We have no immediate actions to perform, so the BeginFrame should post
1007 // the deadline task.
1008 client.Reset();
777 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 1009 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
778 // The actions should have occured, in the right order. 1010 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
1011
1012 // On the deadline, he actions should have occured in the right order.
1013 client.Reset();
1014 scheduler->OnBeginFrameDeadline();
779 EXPECT_EQ(1, client.num_draws()); 1015 EXPECT_EQ(1, client.num_draws());
780 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1016 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
781 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 1017 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
782 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 1018 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
783 client.ActionIndex("ScheduledActionManageTiles")); 1019 client.ActionIndex("ScheduledActionManageTiles"));
784 EXPECT_FALSE(scheduler->RedrawPending()); 1020 EXPECT_FALSE(scheduler->RedrawPending());
785 EXPECT_FALSE(scheduler->ManageTilesPending()); 1021 EXPECT_FALSE(scheduler->ManageTilesPending());
786 1022
787 // Request a draw. We don't need a ManageTiles yet. 1023 // Request a draw. We don't need a ManageTiles yet.
788 client.Reset(); 1024 client.Reset();
789 scheduler->SetNeedsRedraw(); 1025 scheduler->SetNeedsRedraw();
790 EXPECT_TRUE(scheduler->RedrawPending()); 1026 EXPECT_TRUE(scheduler->RedrawPending());
791 EXPECT_FALSE(scheduler->ManageTilesPending()); 1027 EXPECT_FALSE(scheduler->ManageTilesPending());
792 EXPECT_TRUE(client.needs_begin_frame()); 1028 EXPECT_TRUE(client.needs_begin_frame());
793 EXPECT_EQ(0, client.num_draws()); 1029 EXPECT_EQ(0, client.num_draws());
794 1030
1031 // We have no immediate actions to perform, so the BeginFrame should post
1032 // the deadline task.
1033 client.Reset();
1034 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
1035 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
1036
795 // Draw. The draw will trigger SetNeedsManageTiles, and 1037 // Draw. The draw will trigger SetNeedsManageTiles, and
796 // then the ManageTiles action will be triggered after the Draw. 1038 // then the ManageTiles action will be triggered after the Draw.
797 // Afterwards, neither a draw nor ManageTiles are pending. 1039 // Afterwards, neither a draw nor ManageTiles are pending.
798 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 1040 client.Reset();
1041 scheduler->OnBeginFrameDeadline();
799 EXPECT_EQ(1, client.num_draws()); 1042 EXPECT_EQ(1, client.num_draws());
800 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1043 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
801 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 1044 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
802 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), 1045 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"),
803 client.ActionIndex("ScheduledActionManageTiles")); 1046 client.ActionIndex("ScheduledActionManageTiles"));
804 EXPECT_FALSE(scheduler->RedrawPending()); 1047 EXPECT_FALSE(scheduler->RedrawPending());
805 EXPECT_FALSE(scheduler->ManageTilesPending()); 1048 EXPECT_FALSE(scheduler->ManageTilesPending());
806 1049
807 // We need a BeginFrame where we don't swap to go idle. 1050 // We need a BeginFrame where we don't swap to go idle.
808 client.Reset(); 1051 client.Reset();
809 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 1052 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
810 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); 1053 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
1054 client.Reset();
1055 scheduler->OnBeginFrameDeadline();
1056 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client);;
811 EXPECT_EQ(0, client.num_draws()); 1057 EXPECT_EQ(0, client.num_draws());
812 1058
813 // Now trigger a ManageTiles outside of a draw. We will then need 1059 // Now trigger a ManageTiles outside of a draw. We will then need
814 // a begin-frame for the ManageTiles, but we don't need a draw. 1060 // a begin-frame for the ManageTiles, but we don't need a draw.
815 client.Reset(); 1061 client.Reset();
816 EXPECT_FALSE(client.needs_begin_frame()); 1062 EXPECT_FALSE(client.needs_begin_frame());
817 scheduler->SetNeedsManageTiles(); 1063 scheduler->SetNeedsManageTiles();
818 EXPECT_TRUE(client.needs_begin_frame()); 1064 EXPECT_TRUE(client.needs_begin_frame());
819 EXPECT_TRUE(scheduler->ManageTilesPending()); 1065 EXPECT_TRUE(scheduler->ManageTilesPending());
820 EXPECT_FALSE(scheduler->RedrawPending()); 1066 EXPECT_FALSE(scheduler->RedrawPending());
821 1067
822 // BeginFrame. There will be no draw, only ManageTiles. 1068 // BeginFrame. There will be no draw, only ManageTiles.
1069 client.Reset();
823 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); 1070 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting());
1071 EXPECT_SINGLE_ACTION("PostBeginFrameDeadlineTask", client);
1072 client.Reset();
1073 scheduler->OnBeginFrameDeadline();
824 EXPECT_EQ(0, client.num_draws()); 1074 EXPECT_EQ(0, client.num_draws());
825 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); 1075 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible"));
826 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); 1076 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles"));
827 } 1077 }
828 1078
829 } // namespace 1079 } // namespace
830 } // namespace cc 1080 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler_state_machine_unittest.cc ('k') | cc/trees/layer_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698