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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 needs_begin_frame_ = enable; | 102 needs_begin_frame_ = enable; |
103 } | 103 } |
104 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { | 104 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { |
105 actions_.push_back("WillBeginImplFrame"); | 105 actions_.push_back("WillBeginImplFrame"); |
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 DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 112 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() OVERRIDE { |
113 OVERRIDE { | |
114 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | 113 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); |
115 states_.push_back(scheduler_->StateAsValue().release()); | 114 states_.push_back(scheduler_->StateAsValue().release()); |
116 num_draws_++; | 115 num_draws_++; |
117 bool did_readback = false; | 116 DrawResult result = |
118 DrawSwapReadbackResult::DrawResult result = | 117 draw_will_happen_ ? DRAW_SUCCESS : DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; |
119 draw_will_happen_ | |
120 ? DrawSwapReadbackResult::DRAW_SUCCESS | |
121 : DrawSwapReadbackResult::DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | |
122 bool swap_will_happen = | 118 bool swap_will_happen = |
123 draw_will_happen_ && swap_will_happen_if_draw_happens_; | 119 draw_will_happen_ && swap_will_happen_if_draw_happens_; |
124 if (swap_will_happen) { | 120 if (swap_will_happen) { |
125 scheduler_->DidSwapBuffers(); | 121 scheduler_->DidSwapBuffers(); |
126 if (automatic_swap_ack_) | 122 if (automatic_swap_ack_) |
127 scheduler_->DidSwapBuffersComplete(); | 123 scheduler_->DidSwapBuffersComplete(); |
128 } | 124 } |
129 return DrawSwapReadbackResult( | 125 return result; |
130 result, | |
131 draw_will_happen_ && swap_will_happen_if_draw_happens_, | |
132 did_readback); | |
133 } | 126 } |
134 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { | 127 virtual DrawResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
135 actions_.push_back("ScheduledActionDrawAndSwapForced"); | 128 actions_.push_back("ScheduledActionDrawAndSwapForced"); |
136 states_.push_back(scheduler_->StateAsValue().release()); | 129 states_.push_back(scheduler_->StateAsValue().release()); |
137 bool did_request_swap = swap_will_happen_if_draw_happens_; | 130 return DRAW_SUCCESS; |
138 bool did_readback = false; | |
139 return DrawSwapReadbackResult( | |
140 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); | |
141 } | 131 } |
142 virtual DrawSwapReadbackResult ScheduledActionDrawAndReadback() OVERRIDE { | 132 virtual DrawResult ScheduledActionDrawAndReadback() OVERRIDE { |
143 actions_.push_back("ScheduledActionDrawAndReadback"); | 133 actions_.push_back("ScheduledActionDrawAndReadback"); |
144 states_.push_back(scheduler_->StateAsValue().release()); | 134 states_.push_back(scheduler_->StateAsValue().release()); |
145 bool did_request_swap = false; | 135 return DRAW_SUCCESS; |
146 bool did_readback = true; | |
147 return DrawSwapReadbackResult( | |
148 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); | |
149 } | 136 } |
150 virtual void ScheduledActionCommit() OVERRIDE { | 137 virtual void ScheduledActionCommit() OVERRIDE { |
151 actions_.push_back("ScheduledActionCommit"); | 138 actions_.push_back("ScheduledActionCommit"); |
152 states_.push_back(scheduler_->StateAsValue().release()); | 139 states_.push_back(scheduler_->StateAsValue().release()); |
153 } | 140 } |
154 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { | 141 virtual void ScheduledActionUpdateVisibleTiles() OVERRIDE { |
155 actions_.push_back("ScheduledActionUpdateVisibleTiles"); | 142 actions_.push_back("ScheduledActionUpdateVisibleTiles"); |
156 states_.push_back(scheduler_->StateAsValue().release()); | 143 states_.push_back(scheduler_->StateAsValue().release()); |
157 } | 144 } |
158 virtual void ScheduledActionActivatePendingTree() OVERRIDE { | 145 virtual void ScheduledActionActivatePendingTree() OVERRIDE { |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 // no longer request BeginImplFrames. | 367 // no longer request BeginImplFrames. |
381 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 368 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
382 client.task_runner().RunPendingTasks(); // Run posted deadline. | 369 client.task_runner().RunPendingTasks(); // Run posted deadline. |
383 EXPECT_FALSE(client.needs_begin_frame()); | 370 EXPECT_FALSE(client.needs_begin_frame()); |
384 client.Reset(); | 371 client.Reset(); |
385 } | 372 } |
386 | 373 |
387 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 374 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
388 public: | 375 public: |
389 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 376 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
390 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 377 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
391 OVERRIDE { | 378 OVERRIDE { |
392 // Only SetNeedsRedraw the first time this is called | 379 // Only SetNeedsRedraw the first time this is called |
393 if (!num_draws_) | 380 if (!num_draws_) |
394 scheduler_->SetNeedsRedraw(); | 381 scheduler_->SetNeedsRedraw(); |
395 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 382 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
396 } | 383 } |
397 | 384 |
398 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { | 385 virtual DrawResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
399 NOTREACHED(); | 386 NOTREACHED(); |
400 bool did_request_swap = true; | 387 return DRAW_SUCCESS; |
401 bool did_readback = false; | |
402 return DrawSwapReadbackResult( | |
403 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); | |
404 } | 388 } |
405 | 389 |
406 virtual void ScheduledActionCommit() OVERRIDE {} | 390 virtual void ScheduledActionCommit() OVERRIDE {} |
407 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} | 391 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} |
408 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} | 392 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} |
409 }; | 393 }; |
410 | 394 |
411 // Tests for two different situations: | 395 // Tests for two different situations: |
412 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 396 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
413 // a ScheduledActionDrawAndSwap | 397 // a ScheduledActionDrawAndSwap |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 EXPECT_FALSE(scheduler->RedrawPending()); | 478 EXPECT_FALSE(scheduler->RedrawPending()); |
495 EXPECT_TRUE(client.needs_begin_frame()); | 479 EXPECT_TRUE(client.needs_begin_frame()); |
496 } | 480 } |
497 | 481 |
498 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 482 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
499 public: | 483 public: |
500 SchedulerClientThatSetNeedsCommitInsideDraw() | 484 SchedulerClientThatSetNeedsCommitInsideDraw() |
501 : set_needs_commit_on_next_draw_(false) {} | 485 : set_needs_commit_on_next_draw_(false) {} |
502 | 486 |
503 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 487 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
504 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 488 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
505 OVERRIDE { | 489 OVERRIDE { |
506 // Only SetNeedsCommit the first time this is called | 490 // Only SetNeedsCommit the first time this is called |
507 if (set_needs_commit_on_next_draw_) { | 491 if (set_needs_commit_on_next_draw_) { |
508 scheduler_->SetNeedsCommit(); | 492 scheduler_->SetNeedsCommit(); |
509 set_needs_commit_on_next_draw_ = false; | 493 set_needs_commit_on_next_draw_ = false; |
510 } | 494 } |
511 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 495 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
512 } | 496 } |
513 | 497 |
514 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapForced() OVERRIDE { | 498 virtual DrawResult ScheduledActionDrawAndSwapForced() OVERRIDE { |
515 NOTREACHED(); | 499 NOTREACHED(); |
516 bool did_request_swap = false; | 500 return DRAW_SUCCESS; |
517 bool did_readback = false; | |
518 return DrawSwapReadbackResult( | |
519 DrawSwapReadbackResult::DRAW_SUCCESS, did_request_swap, did_readback); | |
520 } | 501 } |
521 | 502 |
522 virtual void ScheduledActionCommit() OVERRIDE {} | 503 virtual void ScheduledActionCommit() OVERRIDE {} |
523 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} | 504 virtual void ScheduledActionBeginOutputSurfaceCreation() OVERRIDE {} |
524 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} | 505 virtual void DidAnticipatedDrawTimeChange(base::TimeTicks) OVERRIDE {} |
525 | 506 |
526 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } | 507 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } |
527 | 508 |
528 private: | 509 private: |
529 bool set_needs_commit_on_next_draw_; | 510 bool set_needs_commit_on_next_draw_; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 | 679 |
699 // The replacement commit comes in after 2 readbacks. | 680 // The replacement commit comes in after 2 readbacks. |
700 client.Reset(); | 681 client.Reset(); |
701 scheduler->NotifyBeginMainFrameStarted(); | 682 scheduler->NotifyBeginMainFrameStarted(); |
702 scheduler->NotifyReadyToCommit(); | 683 scheduler->NotifyReadyToCommit(); |
703 } | 684 } |
704 | 685 |
705 | 686 |
706 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { | 687 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { |
707 public: | 688 public: |
708 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 689 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
709 OVERRIDE { | 690 OVERRIDE { |
710 scheduler_->SetNeedsManageTiles(); | 691 scheduler_->SetNeedsManageTiles(); |
711 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 692 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
712 } | 693 } |
713 }; | 694 }; |
714 | 695 |
715 // Test manage tiles is independant of draws. | 696 // Test manage tiles is independant of draws. |
716 TEST(SchedulerTest, ManageTiles) { | 697 TEST(SchedulerTest, ManageTiles) { |
717 SchedulerClientNeedsManageTilesInDraw client; | 698 SchedulerClientNeedsManageTilesInDraw client; |
718 SchedulerSettings default_scheduler_settings; | 699 SchedulerSettings default_scheduler_settings; |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1464 TEST(SchedulerTest, | 1445 TEST(SchedulerTest, |
1465 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { | 1446 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { |
1466 bool begin_frame_scheduling_enabled = false; | 1447 bool begin_frame_scheduling_enabled = false; |
1467 bool throttle_frame_production = false; | 1448 bool throttle_frame_production = false; |
1468 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1449 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
1469 throttle_frame_production); | 1450 throttle_frame_production); |
1470 } | 1451 } |
1471 | 1452 |
1472 } // namespace | 1453 } // namespace |
1473 } // namespace cc | 1454 } // namespace cc |
OLD | NEW |