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

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

Issue 222003007: cc: Advance commit state with a CancelableClosure (Closed) Base URL: http://git.chromium.org/chromium/src.git@schedAsValue
Patch Set: use default settings Created 6 years, 8 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.cc ('k') | no next file » | 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 #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"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/test/test_simple_task_runner.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "cc/test/scheduler_test_common.h" 15 #include "cc/test/scheduler_test_common.h"
15 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ 19 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \
19 EXPECT_EQ(expected_num_actions, client.num_actions_()); \ 20 EXPECT_EQ(expected_num_actions, client.num_actions_()); \
20 ASSERT_LT(action_index, client.num_actions_()); \ 21 ASSERT_LT(action_index, client.num_actions_()); \
21 do { \ 22 do { \
22 EXPECT_STREQ(action, client.Action(action_index)); \ 23 EXPECT_STREQ(action, client.Action(action_index)); \
23 for (int i = expected_num_actions; i < client.num_actions_(); ++i) \ 24 for (int i = expected_num_actions; i < client.num_actions_(); ++i) \
24 ADD_FAILURE() << "Unexpected action: " << client.Action(i) << \ 25 ADD_FAILURE() << "Unexpected action: " << client.Action(i) << \
25 " with state:\n" << client.StateForAction(action_index); \ 26 " with state:\n" << client.StateForAction(action_index); \
26 } while (false) 27 } while (false)
27 28
28 #define EXPECT_SINGLE_ACTION(action, client) \ 29 #define EXPECT_SINGLE_ACTION(action, client) \
29 EXPECT_ACTION(action, client, 0, 1) 30 EXPECT_ACTION(action, client, 0, 1)
30 31
31 namespace cc { 32 namespace cc {
32 namespace { 33 namespace {
33 34
34 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler) { 35 class FakeSchedulerClient;
35 scheduler->DidCreateAndInitializeOutputSurface(); 36
36 scheduler->SetNeedsCommit(); 37 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler,
37 scheduler->NotifyBeginMainFrameStarted(); 38 FakeSchedulerClient* client);
38 scheduler->NotifyReadyToCommit();
39 // Go through the motions to draw the commit.
40 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
41 scheduler->OnBeginImplFrameDeadline();
42 // We need another BeginImplFrame so Scheduler calls
43 // SetNeedsBeginImplFrame(false).
44 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
45 scheduler->OnBeginImplFrameDeadline();
46 }
47 39
48 class FakeSchedulerClient : public SchedulerClient { 40 class FakeSchedulerClient : public SchedulerClient {
49 public: 41 public:
50 FakeSchedulerClient() 42 FakeSchedulerClient()
51 : needs_begin_impl_frame_(false) { 43 : needs_begin_impl_frame_(false) {
52 Reset(); 44 Reset();
53 } 45 }
54 46
55 void Reset() { 47 void Reset() {
56 actions_.clear(); 48 actions_.clear();
57 states_.clear(); 49 states_.clear();
58 draw_will_happen_ = true; 50 draw_will_happen_ = true;
59 swap_will_happen_if_draw_happens_ = true; 51 swap_will_happen_if_draw_happens_ = true;
60 num_draws_ = 0; 52 num_draws_ = 0;
61 log_anticipated_draw_time_change_ = false; 53 log_anticipated_draw_time_change_ = false;
62 } 54 }
63 55
64 Scheduler* CreateScheduler(const SchedulerSettings& settings) { 56 Scheduler* CreateScheduler(const SchedulerSettings& settings) {
65 scheduler_ = 57 task_runner_ = new base::TestSimpleTaskRunner;
66 Scheduler::Create(this, settings, 0, base::MessageLoopProxy::current()); 58 scheduler_ = Scheduler::Create(this, settings, 0, task_runner_);
67 return scheduler_.get(); 59 return scheduler_.get();
68 } 60 }
69 61
70 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it 62 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it
71 // for tests that do. 63 // for tests that do.
72 void set_log_anticipated_draw_time_change(bool log) { 64 void set_log_anticipated_draw_time_change(bool log) {
73 log_anticipated_draw_time_change_ = log; 65 log_anticipated_draw_time_change_ = log;
74 } 66 }
75 bool needs_begin_impl_frame() { return needs_begin_impl_frame_; } 67 bool needs_begin_impl_frame() { return needs_begin_impl_frame_; }
76 int num_draws() const { return num_draws_; } 68 int num_draws() const { return num_draws_; }
77 int num_actions_() const { return static_cast<int>(actions_.size()); } 69 int num_actions_() const { return static_cast<int>(actions_.size()); }
78 const char* Action(int i) const { return actions_[i]; } 70 const char* Action(int i) const { return actions_[i]; }
79 base::Value& StateForAction(int i) const { return *states_[i]; } 71 base::Value& StateForAction(int i) const { return *states_[i]; }
80 base::TimeTicks posted_begin_impl_frame_deadline() const { 72 base::TimeTicks posted_begin_impl_frame_deadline() const {
81 return posted_begin_impl_frame_deadline_; 73 return posted_begin_impl_frame_deadline_;
82 } 74 }
83 75
76 base::TestSimpleTaskRunner& task_runner() { return *task_runner_; }
77
84 int ActionIndex(const char* action) const { 78 int ActionIndex(const char* action) const {
85 for (size_t i = 0; i < actions_.size(); i++) 79 for (size_t i = 0; i < actions_.size(); i++)
86 if (!strcmp(actions_[i], action)) 80 if (!strcmp(actions_[i], action))
87 return i; 81 return i;
88 return -1; 82 return -1;
89 } 83 }
90 84
91 bool HasAction(const char* action) const { 85 bool HasAction(const char* action) const {
92 return ActionIndex(action) >= 0; 86 return ActionIndex(action) >= 0;
93 } 87 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 protected: 177 protected:
184 bool needs_begin_impl_frame_; 178 bool needs_begin_impl_frame_;
185 bool draw_will_happen_; 179 bool draw_will_happen_;
186 bool swap_will_happen_if_draw_happens_; 180 bool swap_will_happen_if_draw_happens_;
187 int num_draws_; 181 int num_draws_;
188 bool log_anticipated_draw_time_change_; 182 bool log_anticipated_draw_time_change_;
189 base::TimeTicks posted_begin_impl_frame_deadline_; 183 base::TimeTicks posted_begin_impl_frame_deadline_;
190 std::vector<const char*> actions_; 184 std::vector<const char*> actions_;
191 ScopedVector<base::Value> states_; 185 ScopedVector<base::Value> states_;
192 scoped_ptr<Scheduler> scheduler_; 186 scoped_ptr<Scheduler> scheduler_;
187 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
193 }; 188 };
194 189
190 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler,
191 FakeSchedulerClient* client) {
192 scheduler->DidCreateAndInitializeOutputSurface();
193 scheduler->SetNeedsCommit();
194 scheduler->NotifyBeginMainFrameStarted();
195 scheduler->NotifyReadyToCommit();
196 // Go through the motions to draw the commit.
197 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
198
199 // Run the posted deadline task.
200 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
201 client->task_runner().RunPendingTasks();
202 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
203
204 // We need another BeginImplFrame so Scheduler calls
205 // SetNeedsBeginImplFrame(false).
206 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
207
208 // Run the posted deadline task.
209 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
210 client->task_runner().RunPendingTasks();
211 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
212 }
213
195 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { 214 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) {
196 FakeSchedulerClient client; 215 FakeSchedulerClient client;
197 SchedulerSettings default_scheduler_settings; 216 SchedulerSettings default_scheduler_settings;
198 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 217 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
199 scheduler->SetCanStart(); 218 scheduler->SetCanStart();
200 scheduler->SetVisible(true); 219 scheduler->SetVisible(true);
201 scheduler->SetCanDraw(true); 220 scheduler->SetCanDraw(true);
202 221
203 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 222 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
204 client.Reset(); 223 client.Reset();
205 scheduler->DidCreateAndInitializeOutputSurface(); 224 scheduler->DidCreateAndInitializeOutputSurface();
206 EXPECT_EQ(0, client.num_actions_()); 225 EXPECT_EQ(0, client.num_actions_());
207 } 226 }
208 227
209 TEST(SchedulerTest, RequestCommit) { 228 TEST(SchedulerTest, RequestCommit) {
210 FakeSchedulerClient client; 229 FakeSchedulerClient client;
211 SchedulerSettings scheduler_settings; 230 SchedulerSettings scheduler_settings;
212 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 231 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
213 scheduler->SetCanStart(); 232 scheduler->SetCanStart();
214 scheduler->SetVisible(true); 233 scheduler->SetVisible(true);
215 scheduler->SetCanDraw(true); 234 scheduler->SetCanDraw(true);
216 235
217 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 236 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
218 InitializeOutputSurfaceAndFirstCommit(scheduler); 237 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
219 238
220 // SetNeedsCommit should begin the frame on the next BeginImplFrame. 239 // SetNeedsCommit should begin the frame on the next BeginImplFrame.
221 client.Reset(); 240 client.Reset();
222 scheduler->SetNeedsCommit(); 241 scheduler->SetNeedsCommit();
223 EXPECT_TRUE(client.needs_begin_impl_frame()); 242 EXPECT_TRUE(client.needs_begin_impl_frame());
224 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 243 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
225 client.Reset(); 244 client.Reset();
226 245
227 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 246 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
228 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); 247 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 294
276 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { 295 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) {
277 FakeSchedulerClient client; 296 FakeSchedulerClient client;
278 SchedulerSettings scheduler_settings; 297 SchedulerSettings scheduler_settings;
279 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 298 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
280 scheduler->SetCanStart(); 299 scheduler->SetCanStart();
281 scheduler->SetVisible(true); 300 scheduler->SetVisible(true);
282 scheduler->SetCanDraw(true); 301 scheduler->SetCanDraw(true);
283 302
284 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 303 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
285 InitializeOutputSurfaceAndFirstCommit(scheduler); 304 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
286 client.Reset(); 305 client.Reset();
287 306
288 // SetNeedsCommit should begin the frame. 307 // SetNeedsCommit should begin the frame.
289 scheduler->SetNeedsCommit(); 308 scheduler->SetNeedsCommit();
290 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 309 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
291 310
292 client.Reset(); 311 client.Reset();
293 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 312 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
294 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); 313 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client);
295 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 314 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 368
350 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { 369 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) {
351 FakeSchedulerClient client; 370 FakeSchedulerClient client;
352 SchedulerSettings scheduler_settings; 371 SchedulerSettings scheduler_settings;
353 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 372 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
354 scheduler->SetCanStart(); 373 scheduler->SetCanStart();
355 scheduler->SetVisible(true); 374 scheduler->SetVisible(true);
356 scheduler->SetCanDraw(true); 375 scheduler->SetCanDraw(true);
357 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 376 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
358 377
359 InitializeOutputSurfaceAndFirstCommit(scheduler); 378 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
360 client.Reset(); 379 client.Reset();
361 scheduler->SetNeedsRedraw(); 380 scheduler->SetNeedsRedraw();
362 EXPECT_TRUE(scheduler->RedrawPending()); 381 EXPECT_TRUE(scheduler->RedrawPending());
363 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 382 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
364 EXPECT_TRUE(client.needs_begin_impl_frame()); 383 EXPECT_TRUE(client.needs_begin_impl_frame());
365 384
366 client.Reset(); 385 client.Reset();
367 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 386 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
368 EXPECT_EQ(client.num_actions_(), 0); 387 EXPECT_EQ(client.num_actions_(), 0);
369 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 388 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 468
450 TEST(SchedulerTest, TextureAcquisitionCollision) { 469 TEST(SchedulerTest, TextureAcquisitionCollision) {
451 FakeSchedulerClient client; 470 FakeSchedulerClient client;
452 SchedulerSettings scheduler_settings; 471 SchedulerSettings scheduler_settings;
453 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); 472 Scheduler* scheduler = client.CreateScheduler(scheduler_settings);
454 scheduler->SetCanStart(); 473 scheduler->SetCanStart();
455 scheduler->SetVisible(true); 474 scheduler->SetVisible(true);
456 scheduler->SetCanDraw(true); 475 scheduler->SetCanDraw(true);
457 476
458 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); 477 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client);
459 InitializeOutputSurfaceAndFirstCommit(scheduler); 478 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
460 479
461 client.Reset(); 480 client.Reset();
462 scheduler->SetNeedsCommit(); 481 scheduler->SetNeedsCommit();
463 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); 482 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client);
464 483
465 client.Reset(); 484 client.Reset();
466 scheduler->SetMainThreadNeedsLayerTextures(); 485 scheduler->SetMainThreadNeedsLayerTextures();
467 EXPECT_SINGLE_ACTION( 486 EXPECT_SINGLE_ACTION(
468 "ScheduledActionAcquireLayerTexturesForMainThread", client); 487 "ScheduledActionAcquireLayerTexturesForMainThread", client);
469 488
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside 636 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside
618 // a ScheduledActionDrawAndSwap 637 // a ScheduledActionDrawAndSwap
619 // 2. the scheduler drawing twice inside a single tick 638 // 2. the scheduler drawing twice inside a single tick
620 TEST(SchedulerTest, RequestRedrawInsideDraw) { 639 TEST(SchedulerTest, RequestRedrawInsideDraw) {
621 SchedulerClientThatsetNeedsDrawInsideDraw client; 640 SchedulerClientThatsetNeedsDrawInsideDraw client;
622 SchedulerSettings default_scheduler_settings; 641 SchedulerSettings default_scheduler_settings;
623 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 642 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
624 scheduler->SetCanStart(); 643 scheduler->SetCanStart();
625 scheduler->SetVisible(true); 644 scheduler->SetVisible(true);
626 scheduler->SetCanDraw(true); 645 scheduler->SetCanDraw(true);
627 InitializeOutputSurfaceAndFirstCommit(scheduler); 646 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
628 client.Reset(); 647 client.Reset();
629 648
630 scheduler->SetNeedsRedraw(); 649 scheduler->SetNeedsRedraw();
631 EXPECT_TRUE(scheduler->RedrawPending()); 650 EXPECT_TRUE(scheduler->RedrawPending());
632 EXPECT_TRUE(client.needs_begin_impl_frame()); 651 EXPECT_TRUE(client.needs_begin_impl_frame());
633 EXPECT_EQ(0, client.num_draws()); 652 EXPECT_EQ(0, client.num_draws());
634 653
635 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 654 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
636 scheduler->OnBeginImplFrameDeadline(); 655 scheduler->OnBeginImplFrameDeadline();
637 EXPECT_EQ(1, client.num_draws()); 656 EXPECT_EQ(1, client.num_draws());
(...skipping 16 matching lines...) Expand all
654 } 673 }
655 674
656 // Test that requesting redraw inside a failed draw doesn't lose the request. 675 // Test that requesting redraw inside a failed draw doesn't lose the request.
657 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { 676 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) {
658 SchedulerClientThatsetNeedsDrawInsideDraw client; 677 SchedulerClientThatsetNeedsDrawInsideDraw client;
659 SchedulerSettings default_scheduler_settings; 678 SchedulerSettings default_scheduler_settings;
660 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 679 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
661 scheduler->SetCanStart(); 680 scheduler->SetCanStart();
662 scheduler->SetVisible(true); 681 scheduler->SetVisible(true);
663 scheduler->SetCanDraw(true); 682 scheduler->SetCanDraw(true);
664 InitializeOutputSurfaceAndFirstCommit(scheduler); 683 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
665 client.Reset(); 684 client.Reset();
666 685
667 client.SetDrawWillHappen(false); 686 client.SetDrawWillHappen(false);
668 687
669 scheduler->SetNeedsRedraw(); 688 scheduler->SetNeedsRedraw();
670 EXPECT_TRUE(scheduler->RedrawPending()); 689 EXPECT_TRUE(scheduler->RedrawPending());
671 EXPECT_TRUE(client.needs_begin_impl_frame()); 690 EXPECT_TRUE(client.needs_begin_impl_frame());
672 EXPECT_EQ(0, client.num_draws()); 691 EXPECT_EQ(0, client.num_draws());
673 692
674 // Fail the draw. 693 // Fail the draw.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 755
737 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that 756 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that
738 // happen inside a ScheduledActionDrawAndSwap 757 // happen inside a ScheduledActionDrawAndSwap
739 TEST(SchedulerTest, RequestCommitInsideDraw) { 758 TEST(SchedulerTest, RequestCommitInsideDraw) {
740 SchedulerClientThatSetNeedsCommitInsideDraw client; 759 SchedulerClientThatSetNeedsCommitInsideDraw client;
741 SchedulerSettings default_scheduler_settings; 760 SchedulerSettings default_scheduler_settings;
742 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 761 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
743 scheduler->SetCanStart(); 762 scheduler->SetCanStart();
744 scheduler->SetVisible(true); 763 scheduler->SetVisible(true);
745 scheduler->SetCanDraw(true); 764 scheduler->SetCanDraw(true);
746 InitializeOutputSurfaceAndFirstCommit(scheduler); 765 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
747 client.Reset(); 766 client.Reset();
748 767
749 EXPECT_FALSE(client.needs_begin_impl_frame()); 768 EXPECT_FALSE(client.needs_begin_impl_frame());
750 scheduler->SetNeedsRedraw(); 769 scheduler->SetNeedsRedraw();
751 EXPECT_TRUE(scheduler->RedrawPending()); 770 EXPECT_TRUE(scheduler->RedrawPending());
752 EXPECT_EQ(0, client.num_draws()); 771 EXPECT_EQ(0, client.num_draws());
753 EXPECT_TRUE(client.needs_begin_impl_frame()); 772 EXPECT_TRUE(client.needs_begin_impl_frame());
754 773
755 client.SetNeedsCommitOnNextDraw(); 774 client.SetNeedsCommitOnNextDraw();
756 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 775 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
(...skipping 24 matching lines...) Expand all
781 } 800 }
782 801
783 // Tests that when a draw fails then the pending commit should not be dropped. 802 // Tests that when a draw fails then the pending commit should not be dropped.
784 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { 803 TEST(SchedulerTest, RequestCommitInsideFailedDraw) {
785 SchedulerClientThatsetNeedsDrawInsideDraw client; 804 SchedulerClientThatsetNeedsDrawInsideDraw client;
786 SchedulerSettings default_scheduler_settings; 805 SchedulerSettings default_scheduler_settings;
787 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 806 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
788 scheduler->SetCanStart(); 807 scheduler->SetCanStart();
789 scheduler->SetVisible(true); 808 scheduler->SetVisible(true);
790 scheduler->SetCanDraw(true); 809 scheduler->SetCanDraw(true);
791 InitializeOutputSurfaceAndFirstCommit(scheduler); 810 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
792 client.Reset(); 811 client.Reset();
793 812
794 client.SetDrawWillHappen(false); 813 client.SetDrawWillHappen(false);
795 814
796 scheduler->SetNeedsRedraw(); 815 scheduler->SetNeedsRedraw();
797 EXPECT_TRUE(scheduler->RedrawPending()); 816 EXPECT_TRUE(scheduler->RedrawPending());
798 EXPECT_TRUE(client.needs_begin_impl_frame()); 817 EXPECT_TRUE(client.needs_begin_impl_frame());
799 EXPECT_EQ(0, client.num_draws()); 818 EXPECT_EQ(0, client.num_draws());
800 819
801 // Fail the draw. 820 // Fail the draw.
(...skipping 25 matching lines...) Expand all
827 EXPECT_TRUE(client.needs_begin_impl_frame()); 846 EXPECT_TRUE(client.needs_begin_impl_frame());
828 } 847 }
829 848
830 TEST(SchedulerTest, NoSwapWhenDrawFails) { 849 TEST(SchedulerTest, NoSwapWhenDrawFails) {
831 SchedulerClientThatSetNeedsCommitInsideDraw client; 850 SchedulerClientThatSetNeedsCommitInsideDraw client;
832 SchedulerSettings default_scheduler_settings; 851 SchedulerSettings default_scheduler_settings;
833 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 852 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
834 scheduler->SetCanStart(); 853 scheduler->SetCanStart();
835 scheduler->SetVisible(true); 854 scheduler->SetVisible(true);
836 scheduler->SetCanDraw(true); 855 scheduler->SetCanDraw(true);
837 InitializeOutputSurfaceAndFirstCommit(scheduler); 856 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
838 client.Reset(); 857 client.Reset();
839 858
840 scheduler->SetNeedsRedraw(); 859 scheduler->SetNeedsRedraw();
841 EXPECT_TRUE(scheduler->RedrawPending()); 860 EXPECT_TRUE(scheduler->RedrawPending());
842 EXPECT_TRUE(client.needs_begin_impl_frame()); 861 EXPECT_TRUE(client.needs_begin_impl_frame());
843 EXPECT_EQ(0, client.num_draws()); 862 EXPECT_EQ(0, client.num_draws());
844 863
845 // Draw successfully, this starts a new frame. 864 // Draw successfully, this starts a new frame.
846 client.SetNeedsCommitOnNextDraw(); 865 client.SetNeedsCommitOnNextDraw();
847 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 866 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 }; 936 };
918 937
919 // Test manage tiles is independant of draws. 938 // Test manage tiles is independant of draws.
920 TEST(SchedulerTest, ManageTiles) { 939 TEST(SchedulerTest, ManageTiles) {
921 SchedulerClientNeedsManageTilesInDraw client; 940 SchedulerClientNeedsManageTilesInDraw client;
922 SchedulerSettings default_scheduler_settings; 941 SchedulerSettings default_scheduler_settings;
923 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 942 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
924 scheduler->SetCanStart(); 943 scheduler->SetCanStart();
925 scheduler->SetVisible(true); 944 scheduler->SetVisible(true);
926 scheduler->SetCanDraw(true); 945 scheduler->SetCanDraw(true);
927 InitializeOutputSurfaceAndFirstCommit(scheduler); 946 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
928 947
929 // Request both draw and manage tiles. ManageTiles shouldn't 948 // Request both draw and manage tiles. ManageTiles shouldn't
930 // be trigged until BeginImplFrame. 949 // be trigged until BeginImplFrame.
931 client.Reset(); 950 client.Reset();
932 scheduler->SetNeedsManageTiles(); 951 scheduler->SetNeedsManageTiles();
933 scheduler->SetNeedsRedraw(); 952 scheduler->SetNeedsRedraw();
934 EXPECT_TRUE(scheduler->RedrawPending()); 953 EXPECT_TRUE(scheduler->RedrawPending());
935 EXPECT_TRUE(scheduler->ManageTilesPending()); 954 EXPECT_TRUE(scheduler->ManageTilesPending());
936 EXPECT_TRUE(client.needs_begin_impl_frame()); 955 EXPECT_TRUE(client.needs_begin_impl_frame());
937 EXPECT_EQ(0, client.num_draws()); 956 EXPECT_EQ(0, client.num_draws());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 1040
1022 // Test that ManageTiles only happens once per frame. If an external caller 1041 // Test that ManageTiles only happens once per frame. If an external caller
1023 // initiates it, then the state machine should not ManageTiles on that frame. 1042 // initiates it, then the state machine should not ManageTiles on that frame.
1024 TEST(SchedulerTest, ManageTilesOncePerFrame) { 1043 TEST(SchedulerTest, ManageTilesOncePerFrame) {
1025 FakeSchedulerClient client; 1044 FakeSchedulerClient client;
1026 SchedulerSettings default_scheduler_settings; 1045 SchedulerSettings default_scheduler_settings;
1027 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 1046 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
1028 scheduler->SetCanStart(); 1047 scheduler->SetCanStart();
1029 scheduler->SetVisible(true); 1048 scheduler->SetVisible(true);
1030 scheduler->SetCanDraw(true); 1049 scheduler->SetCanDraw(true);
1031 InitializeOutputSurfaceAndFirstCommit(scheduler); 1050 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1032 1051
1033 // If DidManageTiles during a frame, then ManageTiles should not occur again. 1052 // If DidManageTiles during a frame, then ManageTiles should not occur again.
1034 scheduler->SetNeedsManageTiles(); 1053 scheduler->SetNeedsManageTiles();
1035 scheduler->SetNeedsRedraw(); 1054 scheduler->SetNeedsRedraw();
1036 client.Reset(); 1055 client.Reset();
1037 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1056 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
1038 EXPECT_EQ(client.num_actions_(), 0); 1057 EXPECT_EQ(client.num_actions_(), 0);
1039 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); 1058 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1040 1059
1041 EXPECT_TRUE(scheduler->ManageTilesPending()); 1060 EXPECT_TRUE(scheduler->ManageTilesPending());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles 1153 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles
1135 } 1154 }
1136 1155
1137 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { 1156 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) {
1138 SchedulerClientNeedsManageTilesInDraw client; 1157 SchedulerClientNeedsManageTilesInDraw client;
1139 SchedulerSettings default_scheduler_settings; 1158 SchedulerSettings default_scheduler_settings;
1140 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 1159 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
1141 scheduler->SetCanStart(); 1160 scheduler->SetCanStart();
1142 scheduler->SetVisible(true); 1161 scheduler->SetVisible(true);
1143 scheduler->SetCanDraw(true); 1162 scheduler->SetCanDraw(true);
1144 InitializeOutputSurfaceAndFirstCommit(scheduler); 1163 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1145 1164
1146 client.Reset(); 1165 client.Reset();
1147 BeginFrameArgs impl_frame_args = BeginFrameArgs::CreateForTesting(); 1166 BeginFrameArgs impl_frame_args = BeginFrameArgs::CreateForTesting();
1148 scheduler->SetNeedsRedraw(); 1167 scheduler->SetNeedsRedraw();
1149 scheduler->BeginImplFrame(impl_frame_args); 1168 scheduler->BeginImplFrame(impl_frame_args);
1150 1169
1151 // The deadline should be zero since there is no work other than drawing 1170 // The deadline should be zero since there is no work other than drawing
1152 // pending. 1171 // pending.
1153 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); 1172 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline());
1154 } 1173 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1189 base::TimeDelta::FromMilliseconds(1), 1208 base::TimeDelta::FromMilliseconds(1),
1190 base::TimeDelta::FromMilliseconds( 1209 base::TimeDelta::FromMilliseconds(
1191 begin_main_frame_to_commit_estimate_in_ms), 1210 begin_main_frame_to_commit_estimate_in_ms),
1192 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); 1211 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms));
1193 SchedulerSettings default_scheduler_settings; 1212 SchedulerSettings default_scheduler_settings;
1194 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); 1213 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
1195 scheduler->SetCanStart(); 1214 scheduler->SetCanStart();
1196 scheduler->SetVisible(true); 1215 scheduler->SetVisible(true);
1197 scheduler->SetCanDraw(true); 1216 scheduler->SetCanDraw(true);
1198 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); 1217 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority);
1199 InitializeOutputSurfaceAndFirstCommit(scheduler); 1218 InitializeOutputSurfaceAndFirstCommit(scheduler, &client);
1200 1219
1201 // Impl thread hits deadline before commit finishes. 1220 // Impl thread hits deadline before commit finishes.
1202 client.Reset(); 1221 client.Reset();
1203 scheduler->SetNeedsCommit(); 1222 scheduler->SetNeedsCommit();
1204 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); 1223 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode());
1205 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); 1224 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting());
1206 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); 1225 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode());
1207 scheduler->OnBeginImplFrameDeadline(); 1226 scheduler->OnBeginImplFrameDeadline();
1208 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); 1227 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode());
1209 scheduler->NotifyBeginMainFrameStarted(); 1228 scheduler->NotifyBeginMainFrameStarted();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 MainFrameInHighLatencyMode(1, 10, false, true); 1261 MainFrameInHighLatencyMode(1, 10, false, true);
1243 } 1262 }
1244 1263
1245 TEST(SchedulerTest, NotSkipMainFrameInPreferSmoothnessMode) { 1264 TEST(SchedulerTest, NotSkipMainFrameInPreferSmoothnessMode) {
1246 // Set up client so that estimates indicate that we can commit and activate 1265 // Set up client so that estimates indicate that we can commit and activate
1247 // before the deadline (~8ms by default), but also enable smoothness takes 1266 // before the deadline (~8ms by default), but also enable smoothness takes
1248 // priority mode. 1267 // priority mode.
1249 MainFrameInHighLatencyMode(1, 1, true, true); 1268 MainFrameInHighLatencyMode(1, 1, true, true);
1250 } 1269 }
1251 1270
1252 void SpinForMillis(int millis) {
1253 base::RunLoop run_loop;
1254 base::MessageLoop::current()->PostDelayedTask(
1255 FROM_HERE,
1256 run_loop.QuitClosure(),
1257 base::TimeDelta::FromMilliseconds(millis));
1258 run_loop.Run();
1259 }
1260
1261 TEST(SchedulerTest, PollForCommitCompletion) { 1271 TEST(SchedulerTest, PollForCommitCompletion) {
1262 // Since we are simulating a long commit, set up a client with draw duration 1272 // Since we are simulating a long commit, set up a client with draw duration
1263 // estimates that prevent skipping main frames to get to low latency mode. 1273 // estimates that prevent skipping main frames to get to low latency mode.
1264 SchedulerClientWithFixedEstimates client( 1274 SchedulerClientWithFixedEstimates client(
1265 base::TimeDelta::FromMilliseconds(1), 1275 base::TimeDelta::FromMilliseconds(1),
1266 base::TimeDelta::FromMilliseconds(32), 1276 base::TimeDelta::FromMilliseconds(32),
1267 base::TimeDelta::FromMilliseconds(32)); 1277 base::TimeDelta::FromMilliseconds(32));
1268 client.set_log_anticipated_draw_time_change(true); 1278 client.set_log_anticipated_draw_time_change(true);
1269 SchedulerSettings settings = SchedulerSettings(); 1279 SchedulerSettings default_scheduler_settings;
1270 settings.throttle_frame_production = false; 1280 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings);
1271 Scheduler* scheduler = client.CreateScheduler(settings);
1272 1281
1273 scheduler->SetCanDraw(true); 1282 scheduler->SetCanDraw(true);
1274 scheduler->SetCanStart(); 1283 scheduler->SetCanStart();
1275 scheduler->SetVisible(true); 1284 scheduler->SetVisible(true);
1276 scheduler->DidCreateAndInitializeOutputSurface(); 1285 scheduler->DidCreateAndInitializeOutputSurface();
1277 1286
1278 scheduler->SetNeedsCommit(); 1287 scheduler->SetNeedsCommit();
1279 EXPECT_TRUE(scheduler->CommitPending()); 1288 EXPECT_TRUE(scheduler->CommitPending());
1280 scheduler->NotifyBeginMainFrameStarted(); 1289 scheduler->NotifyBeginMainFrameStarted();
1281 scheduler->NotifyReadyToCommit(); 1290 scheduler->NotifyReadyToCommit();
1282 scheduler->SetNeedsRedraw(); 1291 scheduler->SetNeedsRedraw();
1292
1283 BeginFrameArgs impl_frame_args = BeginFrameArgs::CreateForTesting(); 1293 BeginFrameArgs impl_frame_args = BeginFrameArgs::CreateForTesting();
1284 const int interval = 1; 1294 impl_frame_args.interval = base::TimeDelta::FromMilliseconds(1000);
1285 impl_frame_args.interval = base::TimeDelta::FromMilliseconds(interval);
1286 scheduler->BeginImplFrame(impl_frame_args); 1295 scheduler->BeginImplFrame(impl_frame_args);
1287 scheduler->OnBeginImplFrameDeadline();
1288 1296
1289 // At this point, we've drawn a frame. Start another commit, but hold off on 1297 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending());
1298 client.task_runner().RunPendingTasks(); // Run posted deadline.
1299 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending());
1300
1301 // At this point, we've drawn a frame. Start another commit, but hold off on
1290 // the NotifyReadyToCommit for now. 1302 // the NotifyReadyToCommit for now.
1291 EXPECT_FALSE(scheduler->CommitPending()); 1303 EXPECT_FALSE(scheduler->CommitPending());
1292 scheduler->SetNeedsCommit(); 1304 scheduler->SetNeedsCommit();
1305 scheduler->BeginImplFrame(impl_frame_args);
1293 EXPECT_TRUE(scheduler->CommitPending()); 1306 EXPECT_TRUE(scheduler->CommitPending());
1294 1307
1295 // Spin the event loop a few times and make sure we get more 1308 // Spin the event loop a few times and make sure we get more
1296 // DidAnticipateDrawTimeChange calls every time. 1309 // DidAnticipateDrawTimeChange calls every time.
1297 int actions_so_far = client.num_actions_(); 1310 int actions_so_far = client.num_actions_();
1298 1311
1299 // Does three iterations to make sure that the timer is properly repeating. 1312 // Does three iterations to make sure that the timer is properly repeating.
1300 for (int i = 0; i < 3; ++i) { 1313 for (int i = 0; i < 3; ++i) {
1301 // Wait for 2x the frame interval to match 1314 EXPECT_EQ((impl_frame_args.interval * 2).InMicroseconds(),
1302 // Scheduler::advance_commit_state_timer_'s rate. 1315 client.task_runner().NextPendingTaskDelay().InMicroseconds())
1303 SpinForMillis(interval * 2); 1316 << *scheduler->StateAsValue();
1317 client.task_runner().RunPendingTasks();
1304 EXPECT_GT(client.num_actions_(), actions_so_far); 1318 EXPECT_GT(client.num_actions_(), actions_so_far);
1305 EXPECT_STREQ(client.Action(client.num_actions_() - 1), 1319 EXPECT_STREQ(client.Action(client.num_actions_() - 1),
1306 "DidAnticipatedDrawTimeChange"); 1320 "DidAnticipatedDrawTimeChange");
1321 actions_so_far = client.num_actions_();
1322 }
1323
1324 // Do the same thing after BeginMainFrame starts but still before activation.
1325 scheduler->NotifyBeginMainFrameStarted();
1326 for (int i = 0; i < 3; ++i) {
1327 EXPECT_EQ((impl_frame_args.interval * 2).InMicroseconds(),
1328 client.task_runner().NextPendingTaskDelay().InMicroseconds())
1329 << *scheduler->StateAsValue();
1330 client.task_runner().RunPendingTasks();
1331 EXPECT_GT(client.num_actions_(), actions_so_far);
1332 EXPECT_STREQ(client.Action(client.num_actions_() - 1),
1333 "DidAnticipatedDrawTimeChange");
1307 actions_so_far = client.num_actions_(); 1334 actions_so_far = client.num_actions_();
1308 } 1335 }
1309 } 1336 }
1310 1337
1311 } // namespace 1338 } // namespace
1312 } // namespace cc 1339 } // namespace cc
OLDNEW
« no previous file with comments | « cc/scheduler/scheduler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698