| 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 #include "cc/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 // FinishCommit should commit | 194 // FinishCommit should commit |
| 195 scheduler->FinishCommit(); | 195 scheduler->FinishCommit(); |
| 196 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 196 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 197 EXPECT_TRUE(client.needs_begin_frame()); | 197 EXPECT_TRUE(client.needs_begin_frame()); |
| 198 client.Reset(); | 198 client.Reset(); |
| 199 | 199 |
| 200 // BeginFrame should draw. | 200 // BeginFrame should draw. |
| 201 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 201 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 202 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 202 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 203 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 203 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 204 EXPECT_FALSE(client.needs_begin_frame()); | 204 EXPECT_TRUE(client.needs_begin_frame()); |
| 205 client.Reset(); | 205 client.Reset(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 TEST(SchedulerTest, RequestCommitAfterBeginFrameSentToMainThread) { | 208 TEST(SchedulerTest, RequestCommitAfterBeginFrameSentToMainThread) { |
| 209 FakeSchedulerClient client; | 209 FakeSchedulerClient client; |
| 210 SchedulerSettings default_scheduler_settings; | 210 SchedulerSettings default_scheduler_settings; |
| 211 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 211 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 212 scheduler->SetCanStart(); | 212 scheduler->SetCanStart(); |
| 213 scheduler->SetVisible(true); | 213 scheduler->SetVisible(true); |
| 214 scheduler->SetCanDraw(true); | 214 scheduler->SetCanDraw(true); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 225 | 225 |
| 226 // Now SetNeedsCommit again. Calling here means we need a second frame. | 226 // Now SetNeedsCommit again. Calling here means we need a second frame. |
| 227 scheduler->SetNeedsCommit(); | 227 scheduler->SetNeedsCommit(); |
| 228 | 228 |
| 229 // Finish the commit for the first frame. | 229 // Finish the commit for the first frame. |
| 230 scheduler->FinishCommit(); | 230 scheduler->FinishCommit(); |
| 231 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 231 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 232 client.Reset(); | 232 client.Reset(); |
| 233 | 233 |
| 234 // Tick should draw but then begin another frame for the second commit. | 234 // Tick should draw but then begin another frame for the second commit. |
| 235 // Because we just swapped, the Scheduler should also request the next |
| 236 // BeginFrame from the OutputSurface. |
| 235 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 237 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 236 EXPECT_TRUE(client.needs_begin_frame()); | 238 EXPECT_TRUE(client.needs_begin_frame()); |
| 237 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 239 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); |
| 238 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 2); | 240 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 3); |
| 241 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); |
| 239 client.Reset(); | 242 client.Reset(); |
| 240 | 243 |
| 241 // Finish the second commit to go back to quiescent state and verify we no | 244 // Finish the second commit. |
| 242 // longer request BeginFrames. | |
| 243 scheduler->FinishCommit(); | 245 scheduler->FinishCommit(); |
| 244 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 246 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 247 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); |
| 248 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 3); |
| 249 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); |
| 250 EXPECT_TRUE(client.needs_begin_frame()); |
| 251 client.Reset(); |
| 252 |
| 253 // On the next BeginFrame, verify we go back to a quiescent state and |
| 254 // no longer request BeginFrames. |
| 255 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 245 EXPECT_FALSE(client.needs_begin_frame()); | 256 EXPECT_FALSE(client.needs_begin_frame()); |
| 246 } | 257 } |
| 247 | 258 |
| 248 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { | 259 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { |
| 249 FakeSchedulerClient client; | 260 FakeSchedulerClient client; |
| 250 SchedulerSettings default_scheduler_settings; | 261 SchedulerSettings default_scheduler_settings; |
| 251 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 262 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 252 scheduler->SetCanStart(); | 263 scheduler->SetCanStart(); |
| 253 scheduler->SetVisible(true); | 264 scheduler->SetVisible(true); |
| 254 scheduler->SetCanDraw(true); | 265 scheduler->SetCanDraw(true); |
| 255 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 266 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 256 | 267 |
| 257 InitializeOutputSurfaceAndFirstCommit(scheduler); | 268 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 258 client.Reset(); | 269 client.Reset(); |
| 259 scheduler->SetNeedsRedraw(); | 270 scheduler->SetNeedsRedraw(); |
| 260 EXPECT_TRUE(scheduler->RedrawPending()); | 271 EXPECT_TRUE(scheduler->RedrawPending()); |
| 261 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 272 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 262 EXPECT_TRUE(client.needs_begin_frame()); | 273 EXPECT_TRUE(client.needs_begin_frame()); |
| 263 | 274 |
| 264 client.Reset(); | 275 client.Reset(); |
| 265 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 276 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 266 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 277 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 267 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 278 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 268 EXPECT_FALSE(scheduler->RedrawPending()); | 279 EXPECT_FALSE(scheduler->RedrawPending()); |
| 280 EXPECT_TRUE(client.needs_begin_frame()); |
| 281 |
| 282 client.Reset(); |
| 283 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 284 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 285 EXPECT_FALSE(scheduler->RedrawPending()); |
| 269 EXPECT_FALSE(client.needs_begin_frame()); | 286 EXPECT_FALSE(client.needs_begin_frame()); |
| 270 | 287 |
| 271 client.Reset(); | 288 client.Reset(); |
| 272 scheduler->SetMainThreadNeedsLayerTextures(); | 289 scheduler->SetMainThreadNeedsLayerTextures(); |
| 273 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 290 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
| 274 client); | 291 client); |
| 275 | 292 |
| 276 // We should request a BeginFrame in anticipation of a draw. | 293 // We should request a BeginFrame in anticipation of a draw. |
| 277 client.Reset(); | 294 client.Reset(); |
| 278 scheduler->SetNeedsRedraw(); | 295 scheduler->SetNeedsRedraw(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 298 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 315 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 299 EXPECT_TRUE(scheduler->RedrawPending()); | 316 EXPECT_TRUE(scheduler->RedrawPending()); |
| 300 EXPECT_TRUE(client.needs_begin_frame()); | 317 EXPECT_TRUE(client.needs_begin_frame()); |
| 301 | 318 |
| 302 // Now we can draw again after the commit happens. | 319 // Now we can draw again after the commit happens. |
| 303 client.Reset(); | 320 client.Reset(); |
| 304 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 321 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 305 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 322 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 306 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 323 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 307 EXPECT_FALSE(scheduler->RedrawPending()); | 324 EXPECT_FALSE(scheduler->RedrawPending()); |
| 325 EXPECT_TRUE(client.needs_begin_frame()); |
| 326 |
| 327 // Make sure we stop requesting BeginFrames if we don't swap. |
| 328 client.Reset(); |
| 329 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 330 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 308 EXPECT_FALSE(client.needs_begin_frame()); | 331 EXPECT_FALSE(client.needs_begin_frame()); |
| 309 client.Reset(); | |
| 310 } | 332 } |
| 311 | 333 |
| 312 TEST(SchedulerTest, TextureAcquisitionCollision) { | 334 TEST(SchedulerTest, TextureAcquisitionCollision) { |
| 313 FakeSchedulerClient client; | 335 FakeSchedulerClient client; |
| 314 SchedulerSettings default_scheduler_settings; | 336 SchedulerSettings default_scheduler_settings; |
| 315 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 337 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 316 scheduler->SetCanStart(); | 338 scheduler->SetCanStart(); |
| 317 scheduler->SetVisible(true); | 339 scheduler->SetVisible(true); |
| 318 scheduler->SetCanDraw(true); | 340 scheduler->SetCanDraw(true); |
| 319 | 341 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 346 client.Reset(); | 368 client.Reset(); |
| 347 | 369 |
| 348 // No implicit commit is expected. | 370 // No implicit commit is expected. |
| 349 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 371 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 350 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); | 372 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); |
| 351 EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 373 EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
| 352 client, | 374 client, |
| 353 1, | 375 1, |
| 354 3); | 376 3); |
| 355 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); | 377 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); |
| 378 EXPECT_TRUE(client.needs_begin_frame()); |
| 356 client.Reset(); | 379 client.Reset(); |
| 357 | 380 |
| 358 // Compositor not scheduled to draw because textures are locked by main | 381 // Compositor not scheduled to draw because textures are locked by main |
| 359 // thread. | 382 // thread. |
| 383 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 384 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 360 EXPECT_FALSE(client.needs_begin_frame()); | 385 EXPECT_FALSE(client.needs_begin_frame()); |
| 386 client.Reset(); |
| 361 | 387 |
| 362 // Needs an explicit commit from the main thread. | 388 // Needs an explicit commit from the main thread. |
| 363 scheduler->SetNeedsCommit(); | 389 scheduler->SetNeedsCommit(); |
| 364 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); | 390 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 365 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 391 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 366 client.Reset(); | 392 client.Reset(); |
| 367 | 393 |
| 368 // Trigger the commit | 394 // Trigger the commit |
| 369 scheduler->FinishCommit(); | 395 scheduler->FinishCommit(); |
| 396 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 370 EXPECT_TRUE(client.needs_begin_frame()); | 397 EXPECT_TRUE(client.needs_begin_frame()); |
| 398 client.Reset(); |
| 399 |
| 400 // Verify we draw on the next BeginFrame. |
| 401 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 402 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 403 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 404 EXPECT_TRUE(client.needs_begin_frame()); |
| 405 client.Reset(); |
| 371 } | 406 } |
| 372 | 407 |
| 373 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { | 408 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { |
| 374 FakeSchedulerClient client; | 409 FakeSchedulerClient client; |
| 375 SchedulerSettings default_scheduler_settings; | 410 SchedulerSettings default_scheduler_settings; |
| 376 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 411 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 377 scheduler->SetCanStart(); | 412 scheduler->SetCanStart(); |
| 378 scheduler->SetVisible(true); | 413 scheduler->SetVisible(true); |
| 379 scheduler->SetCanDraw(true); | 414 scheduler->SetCanDraw(true); |
| 380 | 415 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 EXPECT_EQ(0, client.num_draws()); | 486 EXPECT_EQ(0, client.num_draws()); |
| 452 | 487 |
| 453 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 488 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 454 EXPECT_EQ(1, client.num_draws()); | 489 EXPECT_EQ(1, client.num_draws()); |
| 455 EXPECT_TRUE(scheduler->RedrawPending()); | 490 EXPECT_TRUE(scheduler->RedrawPending()); |
| 456 EXPECT_TRUE(client.needs_begin_frame()); | 491 EXPECT_TRUE(client.needs_begin_frame()); |
| 457 | 492 |
| 458 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 493 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 459 EXPECT_EQ(2, client.num_draws()); | 494 EXPECT_EQ(2, client.num_draws()); |
| 460 EXPECT_FALSE(scheduler->RedrawPending()); | 495 EXPECT_FALSE(scheduler->RedrawPending()); |
| 496 EXPECT_TRUE(client.needs_begin_frame()); |
| 497 |
| 498 // We stop requesting BeginFrames after a BeginFrame where we don't swap. |
| 499 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 500 EXPECT_EQ(2, client.num_draws()); |
| 501 EXPECT_FALSE(scheduler->RedrawPending()); |
| 461 EXPECT_FALSE(client.needs_begin_frame()); | 502 EXPECT_FALSE(client.needs_begin_frame()); |
| 462 } | 503 } |
| 463 | 504 |
| 464 // Test that requesting redraw inside a failed draw doesn't lose the request. | 505 // Test that requesting redraw inside a failed draw doesn't lose the request. |
| 465 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 506 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| 466 SchedulerClientThatsetNeedsDrawInsideDraw client; | 507 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 467 SchedulerSettings default_scheduler_settings; | 508 SchedulerSettings default_scheduler_settings; |
| 468 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 509 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 469 scheduler->SetCanStart(); | 510 scheduler->SetCanStart(); |
| 470 scheduler->SetVisible(true); | 511 scheduler->SetVisible(true); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 601 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 561 EXPECT_EQ(1, client.num_draws()); | 602 EXPECT_EQ(1, client.num_draws()); |
| 562 EXPECT_TRUE(scheduler->CommitPending()); | 603 EXPECT_TRUE(scheduler->CommitPending()); |
| 563 EXPECT_TRUE(client.needs_begin_frame()); | 604 EXPECT_TRUE(client.needs_begin_frame()); |
| 564 scheduler->FinishCommit(); | 605 scheduler->FinishCommit(); |
| 565 | 606 |
| 566 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 607 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 567 EXPECT_EQ(2, client.num_draws());; | 608 EXPECT_EQ(2, client.num_draws());; |
| 568 EXPECT_FALSE(scheduler->RedrawPending()); | 609 EXPECT_FALSE(scheduler->RedrawPending()); |
| 569 EXPECT_FALSE(scheduler->CommitPending()); | 610 EXPECT_FALSE(scheduler->CommitPending()); |
| 611 EXPECT_TRUE(client.needs_begin_frame()); |
| 612 |
| 613 // We stop requesting BeginFrames after a BeginFrame where we don't swap. |
| 614 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 615 EXPECT_EQ(2, client.num_draws()); |
| 616 EXPECT_FALSE(scheduler->RedrawPending()); |
| 617 EXPECT_FALSE(scheduler->CommitPending()); |
| 570 EXPECT_FALSE(client.needs_begin_frame()); | 618 EXPECT_FALSE(client.needs_begin_frame()); |
| 571 } | 619 } |
| 572 | 620 |
| 573 // Tests that when a draw fails then the pending commit should not be dropped. | 621 // Tests that when a draw fails then the pending commit should not be dropped. |
| 574 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 622 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
| 575 SchedulerClientThatsetNeedsDrawInsideDraw client; | 623 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 576 SchedulerSettings default_scheduler_settings; | 624 SchedulerSettings default_scheduler_settings; |
| 577 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 625 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 578 scheduler->SetCanStart(); | 626 scheduler->SetCanStart(); |
| 579 scheduler->SetVisible(true); | 627 scheduler->SetVisible(true); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 scheduler->FinishCommit(); | 730 scheduler->FinishCommit(); |
| 683 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndReadback")); | 731 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndReadback")); |
| 684 | 732 |
| 685 // The replacement commit comes in after 2 readbacks. | 733 // The replacement commit comes in after 2 readbacks. |
| 686 client.Reset(); | 734 client.Reset(); |
| 687 scheduler->FinishCommit(); | 735 scheduler->FinishCommit(); |
| 688 } | 736 } |
| 689 | 737 |
| 690 } // namespace | 738 } // namespace |
| 691 } // namespace cc | 739 } // namespace cc |
| OLD | NEW |