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