| 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 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
| 5 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 states_.push_back(scheduler_->AsValue().release()); | 107 states_.push_back(scheduler_->AsValue().release()); |
| 108 } | 108 } |
| 109 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { | 109 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { |
| 110 actions_.push_back("ScheduledActionSendBeginMainFrame"); | 110 actions_.push_back("ScheduledActionSendBeginMainFrame"); |
| 111 states_.push_back(scheduler_->AsValue().release()); | 111 states_.push_back(scheduler_->AsValue().release()); |
| 112 } | 112 } |
| 113 virtual void ScheduledActionAnimate() OVERRIDE { | 113 virtual void ScheduledActionAnimate() OVERRIDE { |
| 114 actions_.push_back("ScheduledActionAnimate"); | 114 actions_.push_back("ScheduledActionAnimate"); |
| 115 states_.push_back(scheduler_->AsValue().release()); | 115 states_.push_back(scheduler_->AsValue().release()); |
| 116 } | 116 } |
| 117 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 117 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() OVERRIDE { |
| 118 OVERRIDE { | |
| 119 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | 118 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); |
| 120 states_.push_back(scheduler_->AsValue().release()); | 119 states_.push_back(scheduler_->AsValue().release()); |
| 121 num_draws_++; | 120 num_draws_++; |
| 122 bool did_readback = false; | 121 DrawResult result = |
| 123 DrawSwapReadbackResult::DrawResult result = | 122 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
| 124 draw_will_happen_ | |
| 125 ? DrawSwapReadbackResult::DRAW_SUCCESS | |
| 126 : DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | |
| 127 bool swap_will_happen = | 123 bool swap_will_happen = |
| 128 draw_will_happen_ && swap_will_happen_if_draw_happens_; | 124 draw_will_happen_ && swap_will_happen_if_draw_happens_; |
| 129 if (swap_will_happen) { | 125 if (swap_will_happen) { |
| 130 scheduler_->DidSwapBuffers(); | 126 scheduler_->DidSwapBuffers(); |
| 131 if (automatic_swap_ack_) | 127 if (automatic_swap_ack_) |
| 132 scheduler_->DidSwapBuffersComplete(); | 128 scheduler_->DidSwapBuffersComplete(); |
| 133 } | 129 } |
| 134 return DrawSwapReadbackResult( | 130 return result; |
| 135 result, | |
| 136 draw_will_happen_ && swap_will_happen_if_draw_happens_, | |
| 137 did_readback); | |
| 138 } | 131 } |
| 139 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { | 132 virtual DrawResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
| 140 actions_.push_back("ScheduledActionDrawAndSwapForced"); | 133 actions_.push_back("ScheduledActionDrawAndSwapForced"); |
| 141 states_.push_back(scheduler_->AsValue().release()); | 134 states_.push_back(scheduler_->AsValue().release()); |
| 142 bool did_request_swap = swap_will_happen_if_draw_happens_; | 135 return DRAW_SUCCESS; |
| 143 bool did_readback = false; | |
| 144 return DrawSwapReadbackResult( | |
| 145 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); | |
| 146 } | 136 } |
| 147 virtual DrawSwapReadbackResult ScheduledActionDrawAndReadback() OVERRIDE { | 137 virtual DrawResult ScheduledActionDrawAndReadback() OVERRIDE { |
| 148 actions_.push_back("ScheduledActionDrawAndReadback"); | 138 actions_.push_back("ScheduledActionDrawAndReadback"); |
| 149 states_.push_back(scheduler_->AsValue().release()); | 139 states_.push_back(scheduler_->AsValue().release()); |
| 150 bool did_request_swap = false; | 140 return DRAW_SUCCESS; |
| 151 bool did_readback = true; | |
| 152 return DrawSwapReadbackResult( | |
| 153 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); | |
| 154 } | 141 } |
| 155 virtual void ScheduledActionCommit() OVERRIDE { | 142 virtual void ScheduledActionCommit() OVERRIDE { |
| 156 actions_.push_back("ScheduledActionCommit"); | 143 actions_.push_back("ScheduledActionCommit"); |
| 157 states_.push_back(scheduler_->AsValue().release()); | 144 states_.push_back(scheduler_->AsValue().release()); |
| 158 } | 145 } |
| 159 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { | 146 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { |
| 160 actions_.push_back("ScheduledActionUpdateVisibleTiles"); | 147 actions_.push_back("ScheduledActionUpdateVisibleTiles"); |
| 161 states_.push_back(scheduler_->AsValue().release()); | 148 states_.push_back(scheduler_->AsValue().release()); |
| 162 } | 149 } |
| 163 virtual void ScheduledActionActivatePendingTree() OVERRIDE { | 150 virtual void ScheduledActionActivatePendingTree() OVERRIDE { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 // no longer request BeginImplFrames. | 375 // no longer request BeginImplFrames. |
| 389 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 376 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); |
| 390 client.task_runner().RunPendingTasks(); // Run posted deadline. | 377 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 391 EXPECT_FALSE(client.needs_begin_frame()); | 378 EXPECT_FALSE(client.needs_begin_frame()); |
| 392 client.Reset(); | 379 client.Reset(); |
| 393 } | 380 } |
| 394 | 381 |
| 395 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 382 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 396 public: | 383 public: |
| 397 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 384 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
| 398 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 385 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
| 399 OVERRIDE { | 386 OVERRIDE { |
| 400 // Only SetNeedsRedraw the first time this is called | 387 // Only SetNeedsRedraw the first time this is called |
| 401 if (!num_draws_) | 388 if (!num_draws_) |
| 402 scheduler_->SetNeedsRedraw(); | 389 scheduler_->SetNeedsRedraw(); |
| 403 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 390 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 404 } | 391 } |
| 405 | 392 |
| 406 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { | 393 virtual DrawResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
| 407 NOTREACHED(); | 394 NOTREACHED(); |
| 408 bool did_request_swap = true; | 395 return DRAW_SUCCESS; |
| 409 bool did_readback = false; | |
| 410 return DrawSwapReadbackResult( | |
| 411 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); | |
| 412 } | 396 } |
| 413 | 397 |
| 414 virtual void ScheduledActionCommit() OVERRIDE {} | 398 virtual void ScheduledActionCommit() OVERRIDE {} |
| 415 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} | 399 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} |
| 416 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} | 400 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} |
| 417 }; | 401 }; |
| 418 | 402 |
| 419 // Tests for two different situations: | 403 // Tests for two different situations: |
| 420 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 404 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
| 421 // a ScheduledActionDrawAndSwap | 405 // a ScheduledActionDrawAndSwap |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 EXPECT_FALSE(scheduler->RedrawPending()); | 486 EXPECT_FALSE(scheduler->RedrawPending()); |
| 503 EXPECT_TRUE(client.needs_begin_frame()); | 487 EXPECT_TRUE(client.needs_begin_frame()); |
| 504 } | 488 } |
| 505 | 489 |
| 506 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 490 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
| 507 public: | 491 public: |
| 508 SchedulerClientThatSetNeedsCommitInsideDraw() | 492 SchedulerClientThatSetNeedsCommitInsideDraw() |
| 509 : set_needs_commit_on_next_draw_(false) {} | 493 : set_needs_commit_on_next_draw_(false) {} |
| 510 | 494 |
| 511 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 495 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
| 512 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 496 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
| 513 OVERRIDE { | 497 OVERRIDE { |
| 514 // Only SetNeedsCommit the first time this is called | 498 // Only SetNeedsCommit the first time this is called |
| 515 if (set_needs_commit_on_next_draw_) { | 499 if (set_needs_commit_on_next_draw_) { |
| 516 scheduler_->SetNeedsCommit(); | 500 scheduler_->SetNeedsCommit(); |
| 517 set_needs_commit_on_next_draw_ = false; | 501 set_needs_commit_on_next_draw_ = false; |
| 518 } | 502 } |
| 519 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 503 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 520 } | 504 } |
| 521 | 505 |
| 522 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { | 506 virtual DrawResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
| 523 NOTREACHED(); | 507 NOTREACHED(); |
| 524 bool did_request_swap = false; | 508 return DRAW_SUCCESS; |
| 525 bool did_readback = false; | |
| 526 return DrawSwapReadbackResult( | |
| 527 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); | |
| 528 } | 509 } |
| 529 | 510 |
| 530 virtual void ScheduledActionCommit() OVERRIDE {} | 511 virtual void ScheduledActionCommit() OVERRIDE {} |
| 531 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} | 512 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} |
| 532 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} | 513 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} |
| 533 | 514 |
| 534 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } | 515 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } |
| 535 | 516 |
| 536 private: | 517 private: |
| 537 bool set_needs_commit_on_next_draw_; | 518 bool set_needs_commit_on_next_draw_; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 | 687 |
| 707 // The replacement commit comes in after 2 readbacks. | 688 // The replacement commit comes in after 2 readbacks. |
| 708 client.Reset(); | 689 client.Reset(); |
| 709 scheduler->NotifyBeginMainFrameStarted(); | 690 scheduler->NotifyBeginMainFrameStarted(); |
| 710 scheduler->NotifyReadyToCommit(); | 691 scheduler->NotifyReadyToCommit(); |
| 711 } | 692 } |
| 712 | 693 |
| 713 | 694 |
| 714 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { | 695 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { |
| 715 public: | 696 public: |
| 716 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 697 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
| 717 OVERRIDE { | 698 OVERRIDE { |
| 718 scheduler_->SetNeedsManageTiles(); | 699 scheduler_->SetNeedsManageTiles(); |
| 719 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 700 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 720 } | 701 } |
| 721 }; | 702 }; |
| 722 | 703 |
| 723 // Test manage tiles is independant of draws. | 704 // Test manage tiles is independant of draws. |
| 724 TEST(SchedulerTest, ManageTiles) { | 705 TEST(SchedulerTest, ManageTiles) { |
| 725 SchedulerClientNeedsManageTilesInDraw client; | 706 SchedulerClientNeedsManageTilesInDraw client; |
| 726 SchedulerSettings default_scheduler_settings; | 707 SchedulerSettings default_scheduler_settings; |
| (...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1485 TEST(SchedulerTest, | 1466 TEST(SchedulerTest, |
| 1486 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { | 1467 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { |
| 1487 bool begin_frame_scheduling_enabled = false; | 1468 bool begin_frame_scheduling_enabled = false; |
| 1488 bool throttle_frame_production = false; | 1469 bool throttle_frame_production = false; |
| 1489 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1470 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
| 1490 throttle_frame_production); | 1471 throttle_frame_production); |
| 1491 } | 1472 } |
| 1492 | 1473 |
| 1493 } // namespace | 1474 } // namespace |
| 1494 } // namespace cc | 1475 } // namespace cc |
| OLD | NEW |