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 #include "cc/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" |
5 | 6 |
6 #include <string> | 7 #include <string> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
13 #include "base/power_monitor/power_monitor.h" | 14 #include "base/power_monitor/power_monitor.h" |
(...skipping 26 matching lines...) Expand all Loading... |
40 namespace cc { | 41 namespace cc { |
41 namespace { | 42 namespace { |
42 | 43 |
43 class FakeSchedulerClient; | 44 class FakeSchedulerClient; |
44 | 45 |
45 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 46 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
46 FakeSchedulerClient* client); | 47 FakeSchedulerClient* client); |
47 | 48 |
48 class FakeSchedulerClient : public SchedulerClient { | 49 class FakeSchedulerClient : public SchedulerClient { |
49 public: | 50 public: |
50 struct FakeBeginFrameSourceForFakeSchedulerClient | 51 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { |
51 : public FakeBeginFrameSource { | 52 public: |
52 FakeSchedulerClient* client_; | 53 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) |
53 | |
54 explicit FakeBeginFrameSourceForFakeSchedulerClient( | |
55 FakeSchedulerClient* client) | |
56 : client_(client) {} | 54 : client_(client) {} |
| 55 virtual ~FakeExternalBeginFrameSource() {} |
57 | 56 |
58 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { | 57 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { |
59 if (needs_begin_frames) { | 58 if (needs_begin_frames) { |
60 client_->actions_.push_back("SetNeedsBeginFrames(true)"); | 59 client_->actions_.push_back("SetNeedsBeginFrames(true)"); |
61 } else { | 60 } else { |
62 client_->actions_.push_back("SetNeedsBeginFrames(false)"); | 61 client_->actions_.push_back("SetNeedsBeginFrames(false)"); |
63 } | 62 } |
64 client_->states_.push_back(client_->scheduler_->AsValue()); | 63 client_->states_.push_back(client_->scheduler_->AsValue()); |
65 } | 64 } |
| 65 |
| 66 void TestOnBeginFrame(const BeginFrameArgs& args) { |
| 67 return CallOnBeginFrame(args); |
| 68 } |
| 69 |
| 70 private: |
| 71 FakeSchedulerClient* client_; |
66 }; | 72 }; |
67 | 73 |
68 class FakePowerMonitorSource : public base::PowerMonitorSource { | 74 class FakePowerMonitorSource : public base::PowerMonitorSource { |
69 public: | 75 public: |
70 FakePowerMonitorSource() {} | 76 FakePowerMonitorSource() {} |
71 ~FakePowerMonitorSource() override {} | 77 ~FakePowerMonitorSource() override {} |
72 void GeneratePowerStateEvent(bool on_battery_power) { | 78 void GeneratePowerStateEvent(bool on_battery_power) { |
73 on_battery_power_impl_ = on_battery_power; | 79 on_battery_power_impl_ = on_battery_power; |
74 ProcessPowerEvent(POWER_STATE_EVENT); | 80 ProcessPowerEvent(POWER_STATE_EVENT); |
75 base::MessageLoop::current()->RunUntilIdle(); | 81 base::MessageLoop::current()->RunUntilIdle(); |
76 } | 82 } |
77 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; } | 83 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; } |
78 | 84 |
79 private: | 85 private: |
80 bool on_battery_power_impl_; | 86 bool on_battery_power_impl_; |
81 }; | 87 }; |
82 | 88 |
83 FakeSchedulerClient() | 89 FakeSchedulerClient() |
84 : automatic_swap_ack_(true), | 90 : automatic_swap_ack_(true), |
85 swap_contains_incomplete_tile_(false), | 91 swap_contains_incomplete_tile_(false), |
86 redraw_will_happen_if_update_visible_tiles_happens_(false), | 92 redraw_will_happen_if_update_visible_tiles_happens_(false), |
87 now_src_(TestNowSource::Create()), | 93 now_src_(TestNowSource::Create()), |
88 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), | 94 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), |
89 fake_frame_source_(this), | 95 fake_external_begin_frame_source_(nullptr), |
90 fake_power_monitor_source_(new FakePowerMonitorSource), | 96 fake_power_monitor_source_(new FakePowerMonitorSource), |
91 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( | 97 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( |
92 fake_power_monitor_source_)), | 98 fake_power_monitor_source_)), |
93 scheduler_(nullptr) { | 99 scheduler_(nullptr) { |
94 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() | 100 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() |
95 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | 101 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); |
96 // Fail if we need to run 100 tasks in a row. | 102 // Fail if we need to run 100 tasks in a row. |
97 task_runner_->SetRunTaskLimit(100); | 103 task_runner_->SetRunTaskLimit(100); |
98 Reset(); | 104 Reset(); |
99 } | 105 } |
100 | 106 |
101 void Reset() { | 107 void Reset() { |
102 actions_.clear(); | 108 actions_.clear(); |
103 states_.clear(); | 109 states_.clear(); |
104 draw_will_happen_ = true; | 110 draw_will_happen_ = true; |
105 swap_will_happen_if_draw_happens_ = true; | 111 swap_will_happen_if_draw_happens_ = true; |
106 num_draws_ = 0; | 112 num_draws_ = 0; |
107 log_anticipated_draw_time_change_ = false; | 113 log_anticipated_draw_time_change_ = false; |
108 } | 114 } |
109 | 115 |
110 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { | 116 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { |
111 scheduler_ = TestScheduler::Create( | 117 scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source; |
112 now_src_, this, settings, 0, task_runner_, &power_monitor_); | 118 if (settings.use_external_begin_frame_source && |
| 119 settings.throttle_frame_production) { |
| 120 fake_external_begin_frame_source.reset( |
| 121 new FakeExternalBeginFrameSource(this)); |
| 122 fake_external_begin_frame_source_ = |
| 123 fake_external_begin_frame_source.get(); |
| 124 } |
| 125 scheduler_ = TestScheduler::Create(now_src_, |
| 126 this, |
| 127 settings, |
| 128 0, |
| 129 task_runner_, |
| 130 &power_monitor_, |
| 131 fake_external_begin_frame_source.Pass()); |
113 DCHECK(scheduler_); | 132 DCHECK(scheduler_); |
114 return scheduler_.get(); | 133 return scheduler_.get(); |
115 } | 134 } |
116 | 135 |
117 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it | 136 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it |
118 // for tests that do. | 137 // for tests that do. |
119 void set_log_anticipated_draw_time_change(bool log) { | 138 void set_log_anticipated_draw_time_change(bool log) { |
120 log_anticipated_draw_time_change_ = log; | 139 log_anticipated_draw_time_change_ = log; |
121 } | 140 } |
122 bool needs_begin_frames() { return fake_frame_source_.NeedsBeginFrames(); } | 141 bool needs_begin_frames() { |
| 142 DCHECK(ExternalBeginFrame()); |
| 143 return fake_external_begin_frame_source_->NeedsBeginFrames(); |
| 144 } |
123 int num_draws() const { return num_draws_; } | 145 int num_draws() const { return num_draws_; } |
124 int num_actions_() const { return static_cast<int>(actions_.size()); } | 146 int num_actions_() const { return static_cast<int>(actions_.size()); } |
125 const char* Action(int i) const { return actions_[i]; } | 147 const char* Action(int i) const { return actions_[i]; } |
126 std::string StateForAction(int i) const { return states_[i]->ToString(); } | 148 std::string StateForAction(int i) const { return states_[i]->ToString(); } |
127 base::TimeTicks posted_begin_impl_frame_deadline() const { | 149 base::TimeTicks posted_begin_impl_frame_deadline() const { |
128 return posted_begin_impl_frame_deadline_; | 150 return posted_begin_impl_frame_deadline_; |
129 } | 151 } |
130 | 152 |
131 bool ExternalBeginFrame() { | 153 bool ExternalBeginFrame() { |
132 return scheduler_->settings().begin_frame_scheduling_enabled && | 154 return scheduler_->settings().use_external_begin_frame_source && |
133 scheduler_->settings().throttle_frame_production; | 155 scheduler_->settings().throttle_frame_production; |
134 } | 156 } |
135 FakeBeginFrameSource* ExternalBeginFrameSource() override { | 157 |
136 return &fake_frame_source_; | 158 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { |
| 159 return fake_external_begin_frame_source_; |
137 } | 160 } |
138 | 161 |
139 base::PowerMonitor* PowerMonitor() { return &power_monitor_; } | 162 base::PowerMonitor* PowerMonitor() { return &power_monitor_; } |
140 | 163 |
141 FakePowerMonitorSource* PowerMonitorSource() { | 164 FakePowerMonitorSource* PowerMonitorSource() { |
142 return fake_power_monitor_source_; | 165 return fake_power_monitor_source_; |
143 } | 166 } |
144 | 167 |
145 void AdvanceFrame() { | 168 void AdvanceFrame() { |
146 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | 169 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
147 "FakeSchedulerClient::AdvanceFrame"); | 170 "FakeSchedulerClient::AdvanceFrame"); |
148 // EXPECT_TRUE(needs_begin_frames()); | |
149 if (ExternalBeginFrame()) { | 171 if (ExternalBeginFrame()) { |
150 // Creep the time forward so that any BeginFrameArgs is not equal to the | 172 // Creep the time forward so that any BeginFrameArgs is not equal to the |
151 // last one otherwise we violate the BeginFrameSource contract. | 173 // last one otherwise we violate the BeginFrameSource contract. |
152 now_src_->AdvanceNowMicroseconds(1); | 174 now_src_->AdvanceNowMicroseconds(1); |
153 fake_frame_source_.TestOnBeginFrame( | 175 fake_external_begin_frame_source_->TestOnBeginFrame( |
154 CreateBeginFrameArgsForTesting(now_src_)); | 176 CreateBeginFrameArgsForTesting(now_src_)); |
155 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 177 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
156 } | 178 } |
157 | 179 |
158 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); | 180 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); |
159 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 181 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
160 } | 182 } |
161 | 183 |
162 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } | 184 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } |
163 TestNowSource* now_src() { return now_src_.get(); } | 185 TestNowSource* now_src() { return now_src_.get(); } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 bool automatic_swap_ack_; | 303 bool automatic_swap_ack_; |
282 int num_draws_; | 304 int num_draws_; |
283 bool log_anticipated_draw_time_change_; | 305 bool log_anticipated_draw_time_change_; |
284 bool swap_contains_incomplete_tile_; | 306 bool swap_contains_incomplete_tile_; |
285 bool redraw_will_happen_if_update_visible_tiles_happens_; | 307 bool redraw_will_happen_if_update_visible_tiles_happens_; |
286 base::TimeTicks posted_begin_impl_frame_deadline_; | 308 base::TimeTicks posted_begin_impl_frame_deadline_; |
287 std::vector<const char*> actions_; | 309 std::vector<const char*> actions_; |
288 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; | 310 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; |
289 scoped_refptr<TestNowSource> now_src_; | 311 scoped_refptr<TestNowSource> now_src_; |
290 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 312 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
291 FakeBeginFrameSourceForFakeSchedulerClient fake_frame_source_; | 313 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; |
292 FakePowerMonitorSource* fake_power_monitor_source_; | 314 FakePowerMonitorSource* fake_power_monitor_source_; |
293 base::PowerMonitor power_monitor_; | 315 base::PowerMonitor power_monitor_; |
294 scoped_ptr<TestScheduler> scheduler_; | 316 scoped_ptr<TestScheduler> scheduler_; |
295 }; | 317 }; |
296 | 318 |
297 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 319 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
298 FakeSchedulerClient* client) { | 320 FakeSchedulerClient* client) { |
299 TRACE_EVENT0("cc", | 321 TRACE_EVENT0("cc", |
300 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); | 322 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); |
301 | 323 |
(...skipping 18 matching lines...) Expand all Loading... |
320 SCOPED_TRACE( | 342 SCOPED_TRACE( |
321 "We need another BeginImplFrame so Scheduler calls " | 343 "We need another BeginImplFrame so Scheduler calls " |
322 "SetNeedsBeginFrame(false)."); | 344 "SetNeedsBeginFrame(false)."); |
323 client->AdvanceFrame(); | 345 client->AdvanceFrame(); |
324 } | 346 } |
325 | 347 |
326 // Run the posted deadline task. | 348 // Run the posted deadline task. |
327 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 349 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
328 client->task_runner().RunTasksWhile(client->ImplFrameDeadlinePending(true)); | 350 client->task_runner().RunTasksWhile(client->ImplFrameDeadlinePending(true)); |
329 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 351 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
330 | |
331 // EXPECT_FALSE(client->needs_begin_frames()); | |
332 } | 352 } |
333 | 353 |
334 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 354 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
335 FakeSchedulerClient client; | 355 FakeSchedulerClient client; |
336 SchedulerSettings default_scheduler_settings; | 356 SchedulerSettings scheduler_settings; |
337 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 357 scheduler_settings.use_external_begin_frame_source = true; |
| 358 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
338 scheduler->SetCanStart(); | 359 scheduler->SetCanStart(); |
339 scheduler->SetVisible(true); | 360 scheduler->SetVisible(true); |
340 scheduler->SetCanDraw(true); | 361 scheduler->SetCanDraw(true); |
341 | 362 |
342 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 363 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
343 client.Reset(); | 364 client.Reset(); |
344 scheduler->DidCreateAndInitializeOutputSurface(); | 365 scheduler->DidCreateAndInitializeOutputSurface(); |
345 EXPECT_NO_ACTION(client); | 366 EXPECT_NO_ACTION(client); |
346 } | 367 } |
347 | 368 |
348 TEST(SchedulerTest, RequestCommit) { | 369 TEST(SchedulerTest, RequestCommit) { |
349 FakeSchedulerClient client; | 370 FakeSchedulerClient client; |
350 SchedulerSettings scheduler_settings; | 371 SchedulerSettings scheduler_settings; |
| 372 scheduler_settings.use_external_begin_frame_source = true; |
351 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 373 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
352 scheduler->SetCanStart(); | 374 scheduler->SetCanStart(); |
353 scheduler->SetVisible(true); | 375 scheduler->SetVisible(true); |
354 scheduler->SetCanDraw(true); | 376 scheduler->SetCanDraw(true); |
355 | 377 |
356 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 378 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
357 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 379 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
358 | 380 |
359 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 381 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
360 client.Reset(); | 382 client.Reset(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 client.Reset(); | 428 client.Reset(); |
407 | 429 |
408 client.task_runner().RunPendingTasks(); // Run posted deadline. | 430 client.task_runner().RunPendingTasks(); // Run posted deadline. |
409 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 431 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); |
410 client.Reset(); | 432 client.Reset(); |
411 } | 433 } |
412 | 434 |
413 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 435 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
414 FakeSchedulerClient client; | 436 FakeSchedulerClient client; |
415 SchedulerSettings scheduler_settings; | 437 SchedulerSettings scheduler_settings; |
| 438 scheduler_settings.use_external_begin_frame_source = true; |
416 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 439 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
417 scheduler->SetCanStart(); | 440 scheduler->SetCanStart(); |
418 scheduler->SetVisible(true); | 441 scheduler->SetVisible(true); |
419 scheduler->SetCanDraw(true); | 442 scheduler->SetCanDraw(true); |
420 | 443 |
421 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 444 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
422 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 445 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
423 client.Reset(); | 446 client.Reset(); |
424 | 447 |
425 // SetNeedsCommit should begin the frame. | 448 // SetNeedsCommit should begin the frame. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 void ScheduledActionBeginOutputSurfaceCreation() override {} | 527 void ScheduledActionBeginOutputSurfaceCreation() override {} |
505 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} | 528 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} |
506 }; | 529 }; |
507 | 530 |
508 // Tests for two different situations: | 531 // Tests for two different situations: |
509 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 532 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
510 // a ScheduledActionDrawAndSwap | 533 // a ScheduledActionDrawAndSwap |
511 // 2. the scheduler drawing twice inside a single tick | 534 // 2. the scheduler drawing twice inside a single tick |
512 TEST(SchedulerTest, RequestRedrawInsideDraw) { | 535 TEST(SchedulerTest, RequestRedrawInsideDraw) { |
513 SchedulerClientThatsetNeedsDrawInsideDraw client; | 536 SchedulerClientThatsetNeedsDrawInsideDraw client; |
514 SchedulerSettings default_scheduler_settings; | 537 SchedulerSettings scheduler_settings; |
515 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 538 scheduler_settings.use_external_begin_frame_source = true; |
| 539 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
516 scheduler->SetCanStart(); | 540 scheduler->SetCanStart(); |
517 scheduler->SetVisible(true); | 541 scheduler->SetVisible(true); |
518 scheduler->SetCanDraw(true); | 542 scheduler->SetCanDraw(true); |
519 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 543 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
520 client.Reset(); | 544 client.Reset(); |
521 | 545 |
522 scheduler->SetNeedsRedraw(); | 546 scheduler->SetNeedsRedraw(); |
523 EXPECT_TRUE(scheduler->RedrawPending()); | 547 EXPECT_TRUE(scheduler->RedrawPending()); |
524 EXPECT_TRUE(client.needs_begin_frames()); | 548 EXPECT_TRUE(client.needs_begin_frames()); |
525 EXPECT_EQ(0, client.num_draws()); | 549 EXPECT_EQ(0, client.num_draws()); |
(...skipping 15 matching lines...) Expand all Loading... |
541 client.AdvanceFrame(); | 565 client.AdvanceFrame(); |
542 client.task_runner().RunPendingTasks(); // Run posted deadline. | 566 client.task_runner().RunPendingTasks(); // Run posted deadline. |
543 EXPECT_EQ(2, client.num_draws()); | 567 EXPECT_EQ(2, client.num_draws()); |
544 EXPECT_FALSE(scheduler->RedrawPending()); | 568 EXPECT_FALSE(scheduler->RedrawPending()); |
545 EXPECT_FALSE(client.needs_begin_frames()); | 569 EXPECT_FALSE(client.needs_begin_frames()); |
546 } | 570 } |
547 | 571 |
548 // Test that requesting redraw inside a failed draw doesn't lose the request. | 572 // Test that requesting redraw inside a failed draw doesn't lose the request. |
549 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 573 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
550 SchedulerClientThatsetNeedsDrawInsideDraw client; | 574 SchedulerClientThatsetNeedsDrawInsideDraw client; |
551 SchedulerSettings default_scheduler_settings; | 575 SchedulerSettings scheduler_settings; |
552 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 576 scheduler_settings.use_external_begin_frame_source = true; |
| 577 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
553 scheduler->SetCanStart(); | 578 scheduler->SetCanStart(); |
554 scheduler->SetVisible(true); | 579 scheduler->SetVisible(true); |
555 scheduler->SetCanDraw(true); | 580 scheduler->SetCanDraw(true); |
556 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 581 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
557 client.Reset(); | 582 client.Reset(); |
558 | 583 |
559 client.SetDrawWillHappen(false); | 584 client.SetDrawWillHappen(false); |
560 | 585 |
561 scheduler->SetNeedsRedraw(); | 586 scheduler->SetNeedsRedraw(); |
562 EXPECT_TRUE(scheduler->RedrawPending()); | 587 EXPECT_TRUE(scheduler->RedrawPending()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } | 644 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } |
620 | 645 |
621 private: | 646 private: |
622 bool set_needs_commit_on_next_draw_; | 647 bool set_needs_commit_on_next_draw_; |
623 }; | 648 }; |
624 | 649 |
625 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that | 650 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that |
626 // happen inside a ScheduledActionDrawAndSwap | 651 // happen inside a ScheduledActionDrawAndSwap |
627 TEST(SchedulerTest, RequestCommitInsideDraw) { | 652 TEST(SchedulerTest, RequestCommitInsideDraw) { |
628 SchedulerClientThatSetNeedsCommitInsideDraw client; | 653 SchedulerClientThatSetNeedsCommitInsideDraw client; |
629 SchedulerSettings default_scheduler_settings; | 654 SchedulerSettings scheduler_settings; |
630 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 655 scheduler_settings.use_external_begin_frame_source = true; |
| 656 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
631 scheduler->SetCanStart(); | 657 scheduler->SetCanStart(); |
632 scheduler->SetVisible(true); | 658 scheduler->SetVisible(true); |
633 scheduler->SetCanDraw(true); | 659 scheduler->SetCanDraw(true); |
634 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 660 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
635 client.Reset(); | 661 client.Reset(); |
636 | 662 |
637 EXPECT_FALSE(client.needs_begin_frames()); | 663 EXPECT_FALSE(client.needs_begin_frames()); |
638 scheduler->SetNeedsRedraw(); | 664 scheduler->SetNeedsRedraw(); |
639 EXPECT_TRUE(scheduler->RedrawPending()); | 665 EXPECT_TRUE(scheduler->RedrawPending()); |
640 EXPECT_EQ(0, client.num_draws()); | 666 EXPECT_EQ(0, client.num_draws()); |
(...skipping 23 matching lines...) Expand all Loading... |
664 client.task_runner().RunPendingTasks(); // Run posted deadline. | 690 client.task_runner().RunPendingTasks(); // Run posted deadline. |
665 EXPECT_EQ(2, client.num_draws()); | 691 EXPECT_EQ(2, client.num_draws()); |
666 EXPECT_FALSE(scheduler->RedrawPending()); | 692 EXPECT_FALSE(scheduler->RedrawPending()); |
667 EXPECT_FALSE(scheduler->CommitPending()); | 693 EXPECT_FALSE(scheduler->CommitPending()); |
668 EXPECT_FALSE(client.needs_begin_frames()); | 694 EXPECT_FALSE(client.needs_begin_frames()); |
669 } | 695 } |
670 | 696 |
671 // Tests that when a draw fails then the pending commit should not be dropped. | 697 // Tests that when a draw fails then the pending commit should not be dropped. |
672 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 698 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
673 SchedulerClientThatsetNeedsDrawInsideDraw client; | 699 SchedulerClientThatsetNeedsDrawInsideDraw client; |
674 SchedulerSettings default_scheduler_settings; | 700 SchedulerSettings scheduler_settings; |
675 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 701 scheduler_settings.use_external_begin_frame_source = true; |
| 702 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
676 scheduler->SetCanStart(); | 703 scheduler->SetCanStart(); |
677 scheduler->SetVisible(true); | 704 scheduler->SetVisible(true); |
678 scheduler->SetCanDraw(true); | 705 scheduler->SetCanDraw(true); |
679 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 706 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
680 client.Reset(); | 707 client.Reset(); |
681 | 708 |
682 client.SetDrawWillHappen(false); | 709 client.SetDrawWillHappen(false); |
683 | 710 |
684 scheduler->SetNeedsRedraw(); | 711 scheduler->SetNeedsRedraw(); |
685 EXPECT_TRUE(scheduler->RedrawPending()); | 712 EXPECT_TRUE(scheduler->RedrawPending()); |
(...skipping 25 matching lines...) Expand all Loading... |
711 client.AdvanceFrame(); | 738 client.AdvanceFrame(); |
712 client.task_runner().RunPendingTasks(); // Run posted deadline. | 739 client.task_runner().RunPendingTasks(); // Run posted deadline. |
713 EXPECT_EQ(3, client.num_draws()); | 740 EXPECT_EQ(3, client.num_draws()); |
714 EXPECT_TRUE(scheduler->CommitPending()); | 741 EXPECT_TRUE(scheduler->CommitPending()); |
715 EXPECT_FALSE(scheduler->RedrawPending()); | 742 EXPECT_FALSE(scheduler->RedrawPending()); |
716 EXPECT_TRUE(client.needs_begin_frames()); | 743 EXPECT_TRUE(client.needs_begin_frames()); |
717 } | 744 } |
718 | 745 |
719 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 746 TEST(SchedulerTest, NoSwapWhenDrawFails) { |
720 SchedulerClientThatSetNeedsCommitInsideDraw client; | 747 SchedulerClientThatSetNeedsCommitInsideDraw client; |
721 SchedulerSettings default_scheduler_settings; | 748 SchedulerSettings scheduler_settings; |
722 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 749 scheduler_settings.use_external_begin_frame_source = true; |
| 750 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
723 scheduler->SetCanStart(); | 751 scheduler->SetCanStart(); |
724 scheduler->SetVisible(true); | 752 scheduler->SetVisible(true); |
725 scheduler->SetCanDraw(true); | 753 scheduler->SetCanDraw(true); |
726 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 754 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
727 client.Reset(); | 755 client.Reset(); |
728 | 756 |
729 scheduler->SetNeedsRedraw(); | 757 scheduler->SetNeedsRedraw(); |
730 EXPECT_TRUE(scheduler->RedrawPending()); | 758 EXPECT_TRUE(scheduler->RedrawPending()); |
731 EXPECT_TRUE(client.needs_begin_frames()); | 759 EXPECT_TRUE(client.needs_begin_frames()); |
732 EXPECT_EQ(0, client.num_draws()); | 760 EXPECT_EQ(0, client.num_draws()); |
(...skipping 20 matching lines...) Expand all Loading... |
753 public: | 781 public: |
754 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 782 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
755 scheduler_->SetNeedsManageTiles(); | 783 scheduler_->SetNeedsManageTiles(); |
756 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 784 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
757 } | 785 } |
758 }; | 786 }; |
759 | 787 |
760 // Test manage tiles is independant of draws. | 788 // Test manage tiles is independant of draws. |
761 TEST(SchedulerTest, ManageTiles) { | 789 TEST(SchedulerTest, ManageTiles) { |
762 SchedulerClientNeedsManageTilesInDraw client; | 790 SchedulerClientNeedsManageTilesInDraw client; |
763 SchedulerSettings default_scheduler_settings; | 791 SchedulerSettings scheduler_settings; |
764 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 792 scheduler_settings.use_external_begin_frame_source = true; |
| 793 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
765 scheduler->SetCanStart(); | 794 scheduler->SetCanStart(); |
766 scheduler->SetVisible(true); | 795 scheduler->SetVisible(true); |
767 scheduler->SetCanDraw(true); | 796 scheduler->SetCanDraw(true); |
768 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 797 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
769 | 798 |
770 // Request both draw and manage tiles. ManageTiles shouldn't | 799 // Request both draw and manage tiles. ManageTiles shouldn't |
771 // be trigged until BeginImplFrame. | 800 // be trigged until BeginImplFrame. |
772 client.Reset(); | 801 client.Reset(); |
773 scheduler->SetNeedsManageTiles(); | 802 scheduler->SetNeedsManageTiles(); |
774 scheduler->SetNeedsRedraw(); | 803 scheduler->SetNeedsRedraw(); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 EXPECT_EQ(0, client.num_draws()); | 888 EXPECT_EQ(0, client.num_draws()); |
860 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 889 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
861 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 890 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
862 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 891 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
863 } | 892 } |
864 | 893 |
865 // Test that ManageTiles only happens once per frame. If an external caller | 894 // Test that ManageTiles only happens once per frame. If an external caller |
866 // initiates it, then the state machine should not ManageTiles on that frame. | 895 // initiates it, then the state machine should not ManageTiles on that frame. |
867 TEST(SchedulerTest, ManageTilesOncePerFrame) { | 896 TEST(SchedulerTest, ManageTilesOncePerFrame) { |
868 FakeSchedulerClient client; | 897 FakeSchedulerClient client; |
869 SchedulerSettings default_scheduler_settings; | 898 SchedulerSettings scheduler_settings; |
870 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 899 scheduler_settings.use_external_begin_frame_source = true; |
| 900 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
871 scheduler->SetCanStart(); | 901 scheduler->SetCanStart(); |
872 scheduler->SetVisible(true); | 902 scheduler->SetVisible(true); |
873 scheduler->SetCanDraw(true); | 903 scheduler->SetCanDraw(true); |
874 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 904 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
875 | 905 |
876 // If DidManageTiles during a frame, then ManageTiles should not occur again. | 906 // If DidManageTiles during a frame, then ManageTiles should not occur again. |
877 scheduler->SetNeedsManageTiles(); | 907 scheduler->SetNeedsManageTiles(); |
878 scheduler->SetNeedsRedraw(); | 908 scheduler->SetNeedsRedraw(); |
879 client.Reset(); | 909 client.Reset(); |
880 client.AdvanceFrame(); | 910 client.AdvanceFrame(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 EXPECT_FALSE(scheduler->RedrawPending()); | 1009 EXPECT_FALSE(scheduler->RedrawPending()); |
980 EXPECT_FALSE(scheduler->ManageTilesPending()); | 1010 EXPECT_FALSE(scheduler->ManageTilesPending()); |
981 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1011 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
982 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles | 1012 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles |
983 } | 1013 } |
984 | 1014 |
985 TEST(SchedulerTest, ShouldUpdateVisibleTiles) { | 1015 TEST(SchedulerTest, ShouldUpdateVisibleTiles) { |
986 FakeSchedulerClient client; | 1016 FakeSchedulerClient client; |
987 SchedulerSettings scheduler_settings; | 1017 SchedulerSettings scheduler_settings; |
988 scheduler_settings.impl_side_painting = true; | 1018 scheduler_settings.impl_side_painting = true; |
| 1019 scheduler_settings.use_external_begin_frame_source = true; |
989 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1020 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
990 scheduler->SetCanStart(); | 1021 scheduler->SetCanStart(); |
991 scheduler->SetVisible(true); | 1022 scheduler->SetVisible(true); |
992 scheduler->SetCanDraw(true); | 1023 scheduler->SetCanDraw(true); |
993 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1024 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
994 | 1025 |
995 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); | 1026 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); |
996 | 1027 |
997 // SetNeedsCommit should begin the frame. | 1028 // SetNeedsCommit should begin the frame. |
998 client.Reset(); | 1029 client.Reset(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1069 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1039 | 1070 |
1040 // No more UpdateVisibleTiles(). | 1071 // No more UpdateVisibleTiles(). |
1041 client.Reset(); | 1072 client.Reset(); |
1042 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1073 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1043 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1074 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); |
1044 } | 1075 } |
1045 | 1076 |
1046 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1077 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
1047 SchedulerClientNeedsManageTilesInDraw client; | 1078 SchedulerClientNeedsManageTilesInDraw client; |
1048 SchedulerSettings default_scheduler_settings; | 1079 SchedulerSettings scheduler_settings; |
1049 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 1080 scheduler_settings.use_external_begin_frame_source = true; |
| 1081 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1050 scheduler->SetCanStart(); | 1082 scheduler->SetCanStart(); |
1051 scheduler->SetVisible(true); | 1083 scheduler->SetVisible(true); |
1052 scheduler->SetCanDraw(true); | 1084 scheduler->SetCanDraw(true); |
1053 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1085 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1054 | 1086 |
1055 client.Reset(); | 1087 client.Reset(); |
1056 scheduler->SetNeedsRedraw(); | 1088 scheduler->SetNeedsRedraw(); |
1057 client.AdvanceFrame(); | 1089 client.AdvanceFrame(); |
1058 | 1090 |
1059 // The deadline should be zero since there is no work other than drawing | 1091 // The deadline should be zero since there is no work other than drawing |
(...skipping 29 matching lines...) Expand all Loading... |
1089 void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms, | 1121 void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms, |
1090 int64 commit_to_activate_estimate_in_ms, | 1122 int64 commit_to_activate_estimate_in_ms, |
1091 bool impl_latency_takes_priority, | 1123 bool impl_latency_takes_priority, |
1092 bool should_send_begin_main_frame) { | 1124 bool should_send_begin_main_frame) { |
1093 // Set up client with specified estimates (draw duration is set to 1). | 1125 // Set up client with specified estimates (draw duration is set to 1). |
1094 SchedulerClientWithFixedEstimates client( | 1126 SchedulerClientWithFixedEstimates client( |
1095 base::TimeDelta::FromMilliseconds(1), | 1127 base::TimeDelta::FromMilliseconds(1), |
1096 base::TimeDelta::FromMilliseconds( | 1128 base::TimeDelta::FromMilliseconds( |
1097 begin_main_frame_to_commit_estimate_in_ms), | 1129 begin_main_frame_to_commit_estimate_in_ms), |
1098 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); | 1130 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); |
1099 SchedulerSettings default_scheduler_settings; | 1131 SchedulerSettings scheduler_settings; |
1100 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 1132 scheduler_settings.use_external_begin_frame_source = true; |
| 1133 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1101 scheduler->SetCanStart(); | 1134 scheduler->SetCanStart(); |
1102 scheduler->SetVisible(true); | 1135 scheduler->SetVisible(true); |
1103 scheduler->SetCanDraw(true); | 1136 scheduler->SetCanDraw(true); |
1104 scheduler->SetImplLatencyTakesPriority(impl_latency_takes_priority); | 1137 scheduler->SetImplLatencyTakesPriority(impl_latency_takes_priority); |
1105 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1138 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1106 | 1139 |
1107 // Impl thread hits deadline before commit finishes. | 1140 // Impl thread hits deadline before commit finishes. |
1108 client.Reset(); | 1141 client.Reset(); |
1109 scheduler->SetNeedsCommit(); | 1142 scheduler->SetNeedsCommit(); |
1110 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1143 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 } | 1189 } |
1157 | 1190 |
1158 TEST(SchedulerTest, PollForCommitCompletion) { | 1191 TEST(SchedulerTest, PollForCommitCompletion) { |
1159 // Since we are simulating a long commit, set up a client with draw duration | 1192 // Since we are simulating a long commit, set up a client with draw duration |
1160 // estimates that prevent skipping main frames to get to low latency mode. | 1193 // estimates that prevent skipping main frames to get to low latency mode. |
1161 SchedulerClientWithFixedEstimates client( | 1194 SchedulerClientWithFixedEstimates client( |
1162 base::TimeDelta::FromMilliseconds(1), | 1195 base::TimeDelta::FromMilliseconds(1), |
1163 base::TimeDelta::FromMilliseconds(32), | 1196 base::TimeDelta::FromMilliseconds(32), |
1164 base::TimeDelta::FromMilliseconds(32)); | 1197 base::TimeDelta::FromMilliseconds(32)); |
1165 client.set_log_anticipated_draw_time_change(true); | 1198 client.set_log_anticipated_draw_time_change(true); |
1166 SchedulerSettings default_scheduler_settings; | 1199 SchedulerSettings scheduler_settings; |
1167 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 1200 scheduler_settings.use_external_begin_frame_source = true; |
| 1201 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1168 | 1202 |
1169 scheduler->SetCanDraw(true); | 1203 scheduler->SetCanDraw(true); |
1170 scheduler->SetCanStart(); | 1204 scheduler->SetCanStart(); |
1171 scheduler->SetVisible(true); | 1205 scheduler->SetVisible(true); |
1172 scheduler->DidCreateAndInitializeOutputSurface(); | 1206 scheduler->DidCreateAndInitializeOutputSurface(); |
1173 | 1207 |
1174 scheduler->SetNeedsCommit(); | 1208 scheduler->SetNeedsCommit(); |
1175 EXPECT_TRUE(scheduler->CommitPending()); | 1209 EXPECT_TRUE(scheduler->CommitPending()); |
1176 scheduler->NotifyBeginMainFrameStarted(); | 1210 scheduler->NotifyBeginMainFrameStarted(); |
1177 scheduler->NotifyReadyToCommit(); | 1211 scheduler->NotifyReadyToCommit(); |
1178 scheduler->SetNeedsRedraw(); | 1212 scheduler->SetNeedsRedraw(); |
1179 | 1213 |
1180 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(client.now_src()); | 1214 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(client.now_src()); |
1181 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1215 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
1182 client.ExternalBeginFrameSource()->TestOnBeginFrame(frame_args); | 1216 client.fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); |
1183 | 1217 |
1184 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1218 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1185 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1219 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1186 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1220 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1187 | 1221 |
1188 scheduler->DidSwapBuffers(); | 1222 scheduler->DidSwapBuffers(); |
1189 scheduler->DidSwapBuffersComplete(); | 1223 scheduler->DidSwapBuffersComplete(); |
1190 | 1224 |
1191 // At this point, we've drawn a frame. Start another commit, but hold off on | 1225 // At this point, we've drawn a frame. Start another commit, but hold off on |
1192 // the NotifyReadyToCommit for now. | 1226 // the NotifyReadyToCommit for now. |
1193 EXPECT_FALSE(scheduler->CommitPending()); | 1227 EXPECT_FALSE(scheduler->CommitPending()); |
1194 scheduler->SetNeedsCommit(); | 1228 scheduler->SetNeedsCommit(); |
1195 client.ExternalBeginFrameSource()->TestOnBeginFrame(frame_args); | 1229 client.fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); |
1196 EXPECT_TRUE(scheduler->CommitPending()); | 1230 EXPECT_TRUE(scheduler->CommitPending()); |
1197 | 1231 |
1198 // Draw and swap the frame, but don't ack the swap to simulate the Browser | 1232 // Draw and swap the frame, but don't ack the swap to simulate the Browser |
1199 // blocking on the renderer. | 1233 // blocking on the renderer. |
1200 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1234 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1201 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1235 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1202 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1236 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1203 scheduler->DidSwapBuffers(); | 1237 scheduler->DidSwapBuffers(); |
1204 | 1238 |
1205 // Spin the event loop a few times and make sure we get more | 1239 // Spin the event loop a few times and make sure we get more |
(...skipping 22 matching lines...) Expand all Loading... |
1228 EXPECT_GT(client.num_actions_(), actions_so_far); | 1262 EXPECT_GT(client.num_actions_(), actions_so_far); |
1229 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1263 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
1230 "DidAnticipatedDrawTimeChange"); | 1264 "DidAnticipatedDrawTimeChange"); |
1231 actions_so_far = client.num_actions_(); | 1265 actions_so_far = client.num_actions_(); |
1232 } | 1266 } |
1233 } | 1267 } |
1234 | 1268 |
1235 TEST(SchedulerTest, BeginRetroFrame) { | 1269 TEST(SchedulerTest, BeginRetroFrame) { |
1236 FakeSchedulerClient client; | 1270 FakeSchedulerClient client; |
1237 SchedulerSettings scheduler_settings; | 1271 SchedulerSettings scheduler_settings; |
| 1272 scheduler_settings.use_external_begin_frame_source = true; |
1238 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1273 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1239 scheduler->SetCanStart(); | 1274 scheduler->SetCanStart(); |
1240 scheduler->SetVisible(true); | 1275 scheduler->SetVisible(true); |
1241 scheduler->SetCanDraw(true); | 1276 scheduler->SetCanDraw(true); |
1242 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1277 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1243 | 1278 |
1244 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1279 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1245 client.Reset(); | 1280 client.Reset(); |
1246 scheduler->SetNeedsCommit(); | 1281 scheduler->SetNeedsCommit(); |
1247 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1282 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
1248 client.Reset(); | 1283 client.Reset(); |
1249 | 1284 |
1250 // Create a BeginFrame with a long deadline to avoid race conditions. | 1285 // Create a BeginFrame with a long deadline to avoid race conditions. |
1251 // This is the first BeginFrame, which will be handled immediately. | 1286 // This is the first BeginFrame, which will be handled immediately. |
1252 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); | 1287 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1253 args.deadline += base::TimeDelta::FromHours(1); | 1288 args.deadline += base::TimeDelta::FromHours(1); |
1254 client.ExternalBeginFrameSource()->TestOnBeginFrame(args); | 1289 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1255 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1290 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1256 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1291 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1257 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1292 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1258 EXPECT_TRUE(client.needs_begin_frames()); | 1293 EXPECT_TRUE(client.needs_begin_frames()); |
1259 client.Reset(); | 1294 client.Reset(); |
1260 | 1295 |
1261 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1296 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1262 args.frame_time += base::TimeDelta::FromSeconds(1); | 1297 args.frame_time += base::TimeDelta::FromSeconds(1); |
1263 client.ExternalBeginFrameSource()->TestOnBeginFrame(args); | 1298 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1264 args.frame_time += base::TimeDelta::FromSeconds(1); | 1299 args.frame_time += base::TimeDelta::FromSeconds(1); |
1265 client.ExternalBeginFrameSource()->TestOnBeginFrame(args); | 1300 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1266 | 1301 |
1267 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1302 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1268 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1303 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1269 EXPECT_NO_ACTION(client); | 1304 EXPECT_NO_ACTION(client); |
1270 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1305 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1271 EXPECT_TRUE(client.needs_begin_frames()); | 1306 EXPECT_TRUE(client.needs_begin_frames()); |
1272 client.Reset(); | 1307 client.Reset(); |
1273 | 1308 |
1274 // NotifyReadyToCommit should trigger the commit. | 1309 // NotifyReadyToCommit should trigger the commit. |
1275 scheduler->NotifyBeginMainFrameStarted(); | 1310 scheduler->NotifyBeginMainFrameStarted(); |
(...skipping 25 matching lines...) Expand all Loading... |
1301 client.Reset(); | 1336 client.Reset(); |
1302 | 1337 |
1303 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1338 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1304 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1339 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); |
1305 client.Reset(); | 1340 client.Reset(); |
1306 } | 1341 } |
1307 | 1342 |
1308 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { | 1343 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { |
1309 FakeSchedulerClient client; | 1344 FakeSchedulerClient client; |
1310 SchedulerSettings scheduler_settings; | 1345 SchedulerSettings scheduler_settings; |
| 1346 scheduler_settings.use_external_begin_frame_source = true; |
1311 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1347 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1312 scheduler->SetCanStart(); | 1348 scheduler->SetCanStart(); |
1313 scheduler->SetVisible(true); | 1349 scheduler->SetVisible(true); |
1314 scheduler->SetCanDraw(true); | 1350 scheduler->SetCanDraw(true); |
1315 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1351 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1316 | 1352 |
1317 // To test swap ack throttling, this test disables automatic swap acks. | 1353 // To test swap ack throttling, this test disables automatic swap acks. |
1318 scheduler->SetMaxSwapsPending(1); | 1354 scheduler->SetMaxSwapsPending(1); |
1319 client.SetAutomaticSwapAck(false); | 1355 client.SetAutomaticSwapAck(false); |
1320 | 1356 |
1321 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1357 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1322 client.Reset(); | 1358 client.Reset(); |
1323 scheduler->SetNeedsCommit(); | 1359 scheduler->SetNeedsCommit(); |
1324 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1360 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
1325 client.Reset(); | 1361 client.Reset(); |
1326 | 1362 |
1327 // Create a BeginFrame with a long deadline to avoid race conditions. | 1363 // Create a BeginFrame with a long deadline to avoid race conditions. |
1328 // This is the first BeginFrame, which will be handled immediately. | 1364 // This is the first BeginFrame, which will be handled immediately. |
1329 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); | 1365 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1330 args.deadline += base::TimeDelta::FromHours(1); | 1366 args.deadline += base::TimeDelta::FromHours(1); |
1331 client.ExternalBeginFrameSource()->TestOnBeginFrame(args); | 1367 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1332 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1368 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1333 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1369 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1334 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1370 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1335 EXPECT_TRUE(client.needs_begin_frames()); | 1371 EXPECT_TRUE(client.needs_begin_frames()); |
1336 client.Reset(); | 1372 client.Reset(); |
1337 | 1373 |
1338 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1374 // Queue BeginFrame while we are still handling the previous BeginFrame. |
1339 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1375 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1340 args.frame_time += base::TimeDelta::FromSeconds(1); | 1376 args.frame_time += base::TimeDelta::FromSeconds(1); |
1341 client.ExternalBeginFrameSource()->TestOnBeginFrame(args); | 1377 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1342 EXPECT_NO_ACTION(client); | 1378 EXPECT_NO_ACTION(client); |
1343 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1379 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1344 client.Reset(); | 1380 client.Reset(); |
1345 | 1381 |
1346 // NotifyReadyToCommit should trigger the pending commit and draw. | 1382 // NotifyReadyToCommit should trigger the pending commit and draw. |
1347 scheduler->NotifyBeginMainFrameStarted(); | 1383 scheduler->NotifyBeginMainFrameStarted(); |
1348 scheduler->NotifyReadyToCommit(); | 1384 scheduler->NotifyReadyToCommit(); |
1349 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1385 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
1350 EXPECT_TRUE(client.needs_begin_frames()); | 1386 EXPECT_TRUE(client.needs_begin_frames()); |
1351 client.Reset(); | 1387 client.Reset(); |
(...skipping 10 matching lines...) Expand all Loading... |
1362 // but not a BeginMainFrame or draw. | 1398 // but not a BeginMainFrame or draw. |
1363 scheduler->SetNeedsCommit(); | 1399 scheduler->SetNeedsCommit(); |
1364 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1400 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
1365 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 1401 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
1366 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1402 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1367 EXPECT_TRUE(client.needs_begin_frames()); | 1403 EXPECT_TRUE(client.needs_begin_frames()); |
1368 client.Reset(); | 1404 client.Reset(); |
1369 | 1405 |
1370 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1406 // Queue BeginFrame while we are still handling the previous BeginFrame. |
1371 args.frame_time += base::TimeDelta::FromSeconds(1); | 1407 args.frame_time += base::TimeDelta::FromSeconds(1); |
1372 client.ExternalBeginFrameSource()->TestOnBeginFrame(args); | 1408 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1373 EXPECT_NO_ACTION(client); | 1409 EXPECT_NO_ACTION(client); |
1374 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1410 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1375 EXPECT_TRUE(client.needs_begin_frames()); | 1411 EXPECT_TRUE(client.needs_begin_frames()); |
1376 client.Reset(); | 1412 client.Reset(); |
1377 | 1413 |
1378 // Take us out of a swap throttled state. | 1414 // Take us out of a swap throttled state. |
1379 scheduler->DidSwapBuffersComplete(); | 1415 scheduler->DidSwapBuffersComplete(); |
1380 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); | 1416 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
1381 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1417 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1382 EXPECT_TRUE(client.needs_begin_frames()); | 1418 EXPECT_TRUE(client.needs_begin_frames()); |
1383 client.Reset(); | 1419 client.Reset(); |
1384 | 1420 |
1385 // BeginImplFrame deadline should draw. | 1421 // BeginImplFrame deadline should draw. |
1386 scheduler->SetNeedsRedraw(); | 1422 scheduler->SetNeedsRedraw(); |
1387 | 1423 |
1388 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 1424 EXPECT_TRUE(client.task_runner().RunTasksWhile( |
1389 client.ImplFrameDeadlinePending(true))); | 1425 client.ImplFrameDeadlinePending(true))); |
1390 | 1426 |
1391 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1427 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
1392 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1428 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
1393 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1429 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1394 EXPECT_TRUE(client.needs_begin_frames()); | 1430 EXPECT_TRUE(client.needs_begin_frames()); |
1395 client.Reset(); | 1431 client.Reset(); |
1396 } | 1432 } |
1397 | 1433 |
1398 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, | 1434 void BeginFramesNotFromClient(bool use_external_begin_frame_source, |
1399 bool throttle_frame_production) { | 1435 bool throttle_frame_production) { |
1400 FakeSchedulerClient client; | 1436 FakeSchedulerClient client; |
1401 SchedulerSettings scheduler_settings; | 1437 SchedulerSettings scheduler_settings; |
1402 scheduler_settings.begin_frame_scheduling_enabled = | 1438 scheduler_settings.use_external_begin_frame_source = |
1403 begin_frame_scheduling_enabled; | 1439 use_external_begin_frame_source; |
1404 scheduler_settings.throttle_frame_production = throttle_frame_production; | 1440 scheduler_settings.throttle_frame_production = throttle_frame_production; |
1405 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1441 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1406 scheduler->SetCanStart(); | 1442 scheduler->SetCanStart(); |
1407 scheduler->SetVisible(true); | 1443 scheduler->SetVisible(true); |
1408 scheduler->SetCanDraw(true); | 1444 scheduler->SetCanDraw(true); |
1409 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1445 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1410 | 1446 |
| 1447 DCHECK(!client.fake_external_begin_frame_source()); |
| 1448 |
1411 // SetNeedsCommit should begin the frame on the next BeginImplFrame | 1449 // SetNeedsCommit should begin the frame on the next BeginImplFrame |
1412 // without calling SetNeedsBeginFrame. | 1450 // without calling SetNeedsBeginFrame. |
1413 client.Reset(); | 1451 client.Reset(); |
1414 scheduler->SetNeedsCommit(); | 1452 scheduler->SetNeedsCommit(); |
1415 EXPECT_FALSE(client.needs_begin_frames()); | |
1416 EXPECT_NO_ACTION(client); | 1453 EXPECT_NO_ACTION(client); |
1417 client.Reset(); | 1454 client.Reset(); |
1418 | 1455 |
1419 // When the client-driven BeginFrame are disabled, the scheduler posts it's | 1456 // When the client-driven BeginFrame are disabled, the scheduler posts it's |
1420 // own BeginFrame tasks. | 1457 // own BeginFrame tasks. |
1421 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1458 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
1422 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1459 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1423 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1460 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1424 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1461 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1425 EXPECT_FALSE(client.needs_begin_frames()); | |
1426 client.Reset(); | 1462 client.Reset(); |
1427 | 1463 |
1428 // If we don't swap on the deadline, we wait for the next BeginFrame. | 1464 // If we don't swap on the deadline, we wait for the next BeginFrame. |
1429 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1465 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1430 EXPECT_NO_ACTION(client); | 1466 EXPECT_NO_ACTION(client); |
1431 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1467 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1432 EXPECT_FALSE(client.needs_begin_frames()); | |
1433 client.Reset(); | 1468 client.Reset(); |
1434 | 1469 |
1435 // NotifyReadyToCommit should trigger the commit. | 1470 // NotifyReadyToCommit should trigger the commit. |
1436 scheduler->NotifyBeginMainFrameStarted(); | 1471 scheduler->NotifyBeginMainFrameStarted(); |
1437 scheduler->NotifyReadyToCommit(); | 1472 scheduler->NotifyReadyToCommit(); |
1438 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1473 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
1439 EXPECT_FALSE(client.needs_begin_frames()); | |
1440 client.Reset(); | 1474 client.Reset(); |
1441 | 1475 |
1442 // BeginImplFrame should prepare the draw. | 1476 // BeginImplFrame should prepare the draw. |
1443 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1477 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
1444 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1478 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1445 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1479 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
1446 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1480 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1447 EXPECT_FALSE(client.needs_begin_frames()); | |
1448 client.Reset(); | 1481 client.Reset(); |
1449 | 1482 |
1450 // BeginImplFrame deadline should draw. | 1483 // BeginImplFrame deadline should draw. |
1451 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1484 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); |
1452 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1485 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
1453 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1486 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1454 EXPECT_FALSE(client.needs_begin_frames()); | |
1455 client.Reset(); | 1487 client.Reset(); |
1456 | 1488 |
1457 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1489 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
1458 // to avoid excessive toggles. | 1490 // to avoid excessive toggles. |
1459 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1491 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
1460 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1492 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
1461 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1493 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1462 client.Reset(); | 1494 client.Reset(); |
1463 | 1495 |
1464 // Make sure SetNeedsBeginFrame isn't called on the client | 1496 // Make sure SetNeedsBeginFrame isn't called on the client |
1465 // when the BeginFrame is no longer needed. | 1497 // when the BeginFrame is no longer needed. |
1466 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1498 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1467 EXPECT_NO_ACTION(client); | 1499 EXPECT_NO_ACTION(client); |
1468 EXPECT_FALSE(client.needs_begin_frames()); | |
1469 client.Reset(); | 1500 client.Reset(); |
1470 } | 1501 } |
1471 | 1502 |
1472 TEST(SchedulerTest, SyntheticBeginFrames) { | 1503 TEST(SchedulerTest, SyntheticBeginFrames) { |
1473 bool begin_frame_scheduling_enabled = false; | 1504 bool use_external_begin_frame_source = false; |
1474 bool throttle_frame_production = true; | 1505 bool throttle_frame_production = true; |
1475 BeginFramesNotFromClient(begin_frame_scheduling_enabled, | 1506 BeginFramesNotFromClient(use_external_begin_frame_source, |
1476 throttle_frame_production); | 1507 throttle_frame_production); |
1477 } | 1508 } |
1478 | 1509 |
1479 TEST(SchedulerTest, VSyncThrottlingDisabled) { | 1510 TEST(SchedulerTest, VSyncThrottlingDisabled) { |
1480 bool begin_frame_scheduling_enabled = true; | 1511 bool use_external_begin_frame_source = true; |
1481 bool throttle_frame_production = false; | 1512 bool throttle_frame_production = false; |
1482 BeginFramesNotFromClient(begin_frame_scheduling_enabled, | 1513 BeginFramesNotFromClient(use_external_begin_frame_source, |
1483 throttle_frame_production); | 1514 throttle_frame_production); |
1484 } | 1515 } |
1485 | 1516 |
1486 TEST(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) { | 1517 TEST(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) { |
1487 bool begin_frame_scheduling_enabled = false; | 1518 bool use_external_begin_frame_source = false; |
1488 bool throttle_frame_production = false; | 1519 bool throttle_frame_production = false; |
1489 BeginFramesNotFromClient(begin_frame_scheduling_enabled, | 1520 BeginFramesNotFromClient(use_external_begin_frame_source, |
1490 throttle_frame_production); | 1521 throttle_frame_production); |
1491 } | 1522 } |
1492 | 1523 |
1493 void BeginFramesNotFromClient_SwapThrottled(bool begin_frame_scheduling_enabled, | 1524 void BeginFramesNotFromClient_SwapThrottled( |
1494 bool throttle_frame_production) { | 1525 bool use_external_begin_frame_source, |
| 1526 bool throttle_frame_production) { |
1495 FakeSchedulerClient client; | 1527 FakeSchedulerClient client; |
1496 SchedulerSettings scheduler_settings; | 1528 SchedulerSettings scheduler_settings; |
1497 scheduler_settings.begin_frame_scheduling_enabled = | 1529 scheduler_settings.use_external_begin_frame_source = |
1498 begin_frame_scheduling_enabled; | 1530 use_external_begin_frame_source; |
1499 scheduler_settings.throttle_frame_production = throttle_frame_production; | 1531 scheduler_settings.throttle_frame_production = throttle_frame_production; |
1500 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1532 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1501 scheduler->SetCanStart(); | 1533 scheduler->SetCanStart(); |
1502 scheduler->SetVisible(true); | 1534 scheduler->SetVisible(true); |
1503 scheduler->SetCanDraw(true); | 1535 scheduler->SetCanDraw(true); |
1504 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1536 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1505 | 1537 |
| 1538 DCHECK(!client.fake_external_begin_frame_source()); |
| 1539 |
1506 // To test swap ack throttling, this test disables automatic swap acks. | 1540 // To test swap ack throttling, this test disables automatic swap acks. |
1507 scheduler->SetMaxSwapsPending(1); | 1541 scheduler->SetMaxSwapsPending(1); |
1508 client.SetAutomaticSwapAck(false); | 1542 client.SetAutomaticSwapAck(false); |
1509 | 1543 |
1510 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1544 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1511 client.Reset(); | 1545 client.Reset(); |
1512 scheduler->SetNeedsCommit(); | 1546 scheduler->SetNeedsCommit(); |
1513 EXPECT_FALSE(client.needs_begin_frames()); | |
1514 EXPECT_NO_ACTION(client); | 1547 EXPECT_NO_ACTION(client); |
1515 client.Reset(); | 1548 client.Reset(); |
1516 | 1549 |
1517 // Trigger the first BeginImplFrame and BeginMainFrame | 1550 // Trigger the first BeginImplFrame and BeginMainFrame |
1518 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1551 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
1519 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1552 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1520 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1553 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1521 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1554 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1522 EXPECT_FALSE(client.needs_begin_frames()); | |
1523 client.Reset(); | 1555 client.Reset(); |
1524 | 1556 |
1525 // NotifyReadyToCommit should trigger the pending commit and draw. | 1557 // NotifyReadyToCommit should trigger the pending commit and draw. |
1526 scheduler->NotifyBeginMainFrameStarted(); | 1558 scheduler->NotifyBeginMainFrameStarted(); |
1527 scheduler->NotifyReadyToCommit(); | 1559 scheduler->NotifyReadyToCommit(); |
1528 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1560 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
1529 EXPECT_FALSE(client.needs_begin_frames()); | |
1530 client.Reset(); | 1561 client.Reset(); |
1531 | 1562 |
1532 // Swapping will put us into a swap throttled state. | 1563 // Swapping will put us into a swap throttled state. |
1533 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1564 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1534 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1565 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
1535 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1566 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
1536 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1567 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1537 EXPECT_FALSE(client.needs_begin_frames()); | |
1538 client.Reset(); | 1568 client.Reset(); |
1539 | 1569 |
1540 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 1570 // While swap throttled, BeginFrames should trigger BeginImplFrames, |
1541 // but not a BeginMainFrame or draw. | 1571 // but not a BeginMainFrame or draw. |
1542 scheduler->SetNeedsCommit(); | 1572 scheduler->SetNeedsCommit(); |
1543 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1573 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
1544 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 1574 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
1545 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1575 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1546 EXPECT_FALSE(client.needs_begin_frames()); | |
1547 client.Reset(); | 1576 client.Reset(); |
1548 | 1577 |
1549 // Take us out of a swap throttled state. | 1578 // Take us out of a swap throttled state. |
1550 scheduler->DidSwapBuffersComplete(); | 1579 scheduler->DidSwapBuffersComplete(); |
1551 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); | 1580 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
1552 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1581 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1553 EXPECT_FALSE(client.needs_begin_frames()); | |
1554 client.Reset(); | 1582 client.Reset(); |
1555 | 1583 |
1556 // BeginImplFrame deadline should draw. | 1584 // BeginImplFrame deadline should draw. |
1557 scheduler->SetNeedsRedraw(); | 1585 scheduler->SetNeedsRedraw(); |
1558 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1586 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1559 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1587 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
1560 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1588 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
1561 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1589 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1562 EXPECT_FALSE(client.needs_begin_frames()); | |
1563 client.Reset(); | 1590 client.Reset(); |
1564 } | 1591 } |
1565 | 1592 |
1566 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { | 1593 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { |
1567 bool begin_frame_scheduling_enabled = false; | 1594 bool use_external_begin_frame_source = false; |
1568 bool throttle_frame_production = true; | 1595 bool throttle_frame_production = true; |
1569 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1596 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
1570 throttle_frame_production); | 1597 throttle_frame_production); |
1571 } | 1598 } |
1572 | 1599 |
1573 TEST(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { | 1600 TEST(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { |
1574 bool begin_frame_scheduling_enabled = true; | 1601 bool use_external_begin_frame_source = true; |
1575 bool throttle_frame_production = false; | 1602 bool throttle_frame_production = false; |
1576 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1603 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
1577 throttle_frame_production); | 1604 throttle_frame_production); |
1578 } | 1605 } |
1579 | 1606 |
1580 TEST(SchedulerTest, | 1607 TEST(SchedulerTest, |
1581 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { | 1608 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { |
1582 bool begin_frame_scheduling_enabled = false; | 1609 bool use_external_begin_frame_source = false; |
1583 bool throttle_frame_production = false; | 1610 bool throttle_frame_production = false; |
1584 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1611 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
1585 throttle_frame_production); | 1612 throttle_frame_production); |
1586 } | 1613 } |
1587 | 1614 |
1588 TEST(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { | 1615 TEST(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { |
1589 FakeSchedulerClient client; | 1616 FakeSchedulerClient client; |
1590 SchedulerSettings scheduler_settings; | 1617 SchedulerSettings scheduler_settings; |
| 1618 scheduler_settings.use_external_begin_frame_source = true; |
1591 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1619 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1592 scheduler->SetCanStart(); | 1620 scheduler->SetCanStart(); |
1593 scheduler->SetVisible(true); | 1621 scheduler->SetVisible(true); |
1594 scheduler->SetCanDraw(true); | 1622 scheduler->SetCanDraw(true); |
1595 | 1623 |
1596 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1624 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1597 client.Reset(); | 1625 client.Reset(); |
1598 scheduler->DidCreateAndInitializeOutputSurface(); | 1626 scheduler->DidCreateAndInitializeOutputSurface(); |
1599 EXPECT_NO_ACTION(client); | 1627 EXPECT_NO_ACTION(client); |
1600 | 1628 |
1601 scheduler->DidLoseOutputSurface(); | 1629 scheduler->DidLoseOutputSurface(); |
1602 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1630 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1603 } | 1631 } |
1604 | 1632 |
1605 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStarted) { | 1633 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStarted) { |
1606 FakeSchedulerClient client; | 1634 FakeSchedulerClient client; |
1607 SchedulerSettings scheduler_settings; | 1635 SchedulerSettings scheduler_settings; |
| 1636 scheduler_settings.use_external_begin_frame_source = true; |
1608 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1637 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1609 scheduler->SetCanStart(); | 1638 scheduler->SetCanStart(); |
1610 scheduler->SetVisible(true); | 1639 scheduler->SetVisible(true); |
1611 scheduler->SetCanDraw(true); | 1640 scheduler->SetCanDraw(true); |
1612 | 1641 |
1613 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1642 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1614 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1643 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1615 // SetNeedsCommit should begin the frame. | 1644 // SetNeedsCommit should begin the frame. |
1616 client.Reset(); | 1645 client.Reset(); |
1617 scheduler->SetNeedsCommit(); | 1646 scheduler->SetNeedsCommit(); |
(...skipping 18 matching lines...) Expand all Loading... |
1636 client.Reset(); | 1665 client.Reset(); |
1637 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1666 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1638 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1667 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1639 } | 1668 } |
1640 | 1669 |
1641 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( | 1670 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( |
1642 bool impl_side_painting) { | 1671 bool impl_side_painting) { |
1643 FakeSchedulerClient client; | 1672 FakeSchedulerClient client; |
1644 SchedulerSettings scheduler_settings; | 1673 SchedulerSettings scheduler_settings; |
1645 scheduler_settings.impl_side_painting = impl_side_painting; | 1674 scheduler_settings.impl_side_painting = impl_side_painting; |
| 1675 scheduler_settings.use_external_begin_frame_source = true; |
1646 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1676 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1647 scheduler->SetCanStart(); | 1677 scheduler->SetCanStart(); |
1648 scheduler->SetVisible(true); | 1678 scheduler->SetVisible(true); |
1649 scheduler->SetCanDraw(true); | 1679 scheduler->SetCanDraw(true); |
1650 | 1680 |
1651 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1681 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1652 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1682 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1653 | 1683 |
1654 // SetNeedsCommit should begin the frame. | 1684 // SetNeedsCommit should begin the frame. |
1655 client.Reset(); | 1685 client.Reset(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 TEST(SchedulerTest, | 1733 TEST(SchedulerTest, |
1704 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatencyWithImplPaint) { | 1734 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatencyWithImplPaint) { |
1705 bool impl_side_painting = true; | 1735 bool impl_side_painting = true; |
1706 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); | 1736 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); |
1707 } | 1737 } |
1708 | 1738 |
1709 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting) { | 1739 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting) { |
1710 FakeSchedulerClient client; | 1740 FakeSchedulerClient client; |
1711 SchedulerSettings scheduler_settings; | 1741 SchedulerSettings scheduler_settings; |
1712 scheduler_settings.impl_side_painting = impl_side_painting; | 1742 scheduler_settings.impl_side_painting = impl_side_painting; |
| 1743 scheduler_settings.use_external_begin_frame_source = true; |
1713 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1744 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1714 scheduler->SetCanStart(); | 1745 scheduler->SetCanStart(); |
1715 scheduler->SetVisible(true); | 1746 scheduler->SetVisible(true); |
1716 scheduler->SetCanDraw(true); | 1747 scheduler->SetCanDraw(true); |
1717 | 1748 |
1718 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1749 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1719 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1750 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1720 | 1751 |
1721 // SetNeedsCommit should begin the frame. | 1752 // SetNeedsCommit should begin the frame. |
1722 client.Reset(); | 1753 client.Reset(); |
(...skipping 30 matching lines...) Expand all Loading... |
1753 DidLoseOutputSurfaceAfterReadyToCommit(false); | 1784 DidLoseOutputSurfaceAfterReadyToCommit(false); |
1754 } | 1785 } |
1755 | 1786 |
1756 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { | 1787 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { |
1757 DidLoseOutputSurfaceAfterReadyToCommit(true); | 1788 DidLoseOutputSurfaceAfterReadyToCommit(true); |
1758 } | 1789 } |
1759 | 1790 |
1760 TEST(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsManageTiles) { | 1791 TEST(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsManageTiles) { |
1761 FakeSchedulerClient client; | 1792 FakeSchedulerClient client; |
1762 SchedulerSettings scheduler_settings; | 1793 SchedulerSettings scheduler_settings; |
| 1794 scheduler_settings.use_external_begin_frame_source = true; |
1763 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1795 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1764 scheduler->SetCanStart(); | 1796 scheduler->SetCanStart(); |
1765 scheduler->SetVisible(true); | 1797 scheduler->SetVisible(true); |
1766 scheduler->SetCanDraw(true); | 1798 scheduler->SetCanDraw(true); |
1767 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1799 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1768 | 1800 |
1769 client.Reset(); | 1801 client.Reset(); |
1770 scheduler->SetNeedsManageTiles(); | 1802 scheduler->SetNeedsManageTiles(); |
1771 scheduler->SetNeedsRedraw(); | 1803 scheduler->SetNeedsRedraw(); |
1772 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1804 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
(...skipping 10 matching lines...) Expand all Loading... |
1783 | 1815 |
1784 client.Reset(); | 1816 client.Reset(); |
1785 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1817 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1786 EXPECT_ACTION("ScheduledActionManageTiles", client, 0, 2); | 1818 EXPECT_ACTION("ScheduledActionManageTiles", client, 0, 2); |
1787 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); | 1819 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); |
1788 } | 1820 } |
1789 | 1821 |
1790 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { | 1822 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { |
1791 FakeSchedulerClient client; | 1823 FakeSchedulerClient client; |
1792 SchedulerSettings scheduler_settings; | 1824 SchedulerSettings scheduler_settings; |
| 1825 scheduler_settings.use_external_begin_frame_source = true; |
1793 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1826 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1794 scheduler->SetCanStart(); | 1827 scheduler->SetCanStart(); |
1795 scheduler->SetVisible(true); | 1828 scheduler->SetVisible(true); |
1796 scheduler->SetCanDraw(true); | 1829 scheduler->SetCanDraw(true); |
1797 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1830 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1798 | 1831 |
1799 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1832 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1800 client.Reset(); | 1833 client.Reset(); |
1801 scheduler->SetNeedsCommit(); | 1834 scheduler->SetNeedsCommit(); |
1802 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1835 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
1803 | 1836 |
1804 // Create a BeginFrame with a long deadline to avoid race conditions. | 1837 // Create a BeginFrame with a long deadline to avoid race conditions. |
1805 // This is the first BeginFrame, which will be handled immediately. | 1838 // This is the first BeginFrame, which will be handled immediately. |
1806 client.Reset(); | 1839 client.Reset(); |
1807 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); | 1840 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1808 args.deadline += base::TimeDelta::FromHours(1); | 1841 args.deadline += base::TimeDelta::FromHours(1); |
1809 client.ExternalBeginFrameSource()->TestOnBeginFrame(args); | 1842 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1810 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1843 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1811 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1844 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1812 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1845 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1813 EXPECT_TRUE(client.needs_begin_frames()); | 1846 EXPECT_TRUE(client.needs_begin_frames()); |
1814 | 1847 |
1815 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1848 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1816 args.frame_time += base::TimeDelta::FromSeconds(1); | 1849 args.frame_time += base::TimeDelta::FromSeconds(1); |
1817 client.ExternalBeginFrameSource()->TestOnBeginFrame(args); | 1850 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1818 args.frame_time += base::TimeDelta::FromSeconds(1); | 1851 args.frame_time += base::TimeDelta::FromSeconds(1); |
1819 client.ExternalBeginFrameSource()->TestOnBeginFrame(args); | 1852 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1820 | 1853 |
1821 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1854 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1822 client.Reset(); | 1855 client.Reset(); |
1823 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1856 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1824 EXPECT_NO_ACTION(client); | 1857 EXPECT_NO_ACTION(client); |
1825 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1858 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1826 EXPECT_TRUE(client.needs_begin_frames()); | 1859 EXPECT_TRUE(client.needs_begin_frames()); |
1827 | 1860 |
1828 // NotifyReadyToCommit should trigger the commit. | 1861 // NotifyReadyToCommit should trigger the commit. |
1829 client.Reset(); | 1862 client.Reset(); |
(...skipping 11 matching lines...) Expand all Loading... |
1841 | 1874 |
1842 // Posted BeginRetroFrame is aborted. | 1875 // Posted BeginRetroFrame is aborted. |
1843 client.Reset(); | 1876 client.Reset(); |
1844 client.task_runner().RunPendingTasks(); | 1877 client.task_runner().RunPendingTasks(); |
1845 EXPECT_NO_ACTION(client); | 1878 EXPECT_NO_ACTION(client); |
1846 } | 1879 } |
1847 | 1880 |
1848 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { | 1881 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { |
1849 FakeSchedulerClient client; | 1882 FakeSchedulerClient client; |
1850 SchedulerSettings scheduler_settings; | 1883 SchedulerSettings scheduler_settings; |
| 1884 scheduler_settings.use_external_begin_frame_source = true; |
1851 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1885 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1852 scheduler->SetCanStart(); | 1886 scheduler->SetCanStart(); |
1853 scheduler->SetVisible(true); | 1887 scheduler->SetVisible(true); |
1854 scheduler->SetCanDraw(true); | 1888 scheduler->SetCanDraw(true); |
1855 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1889 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1856 | 1890 |
1857 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1891 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1858 client.Reset(); | 1892 client.Reset(); |
1859 scheduler->SetNeedsCommit(); | 1893 scheduler->SetNeedsCommit(); |
1860 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1894 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); |
1861 | 1895 |
1862 // Create a BeginFrame with a long deadline to avoid race conditions. | 1896 // Create a BeginFrame with a long deadline to avoid race conditions. |
1863 // This is the first BeginFrame, which will be handled immediately. | 1897 // This is the first BeginFrame, which will be handled immediately. |
1864 client.Reset(); | 1898 client.Reset(); |
1865 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); | 1899 BeginFrameArgs args = CreateBeginFrameArgsForTesting(client.now_src()); |
1866 args.deadline += base::TimeDelta::FromHours(1); | 1900 args.deadline += base::TimeDelta::FromHours(1); |
1867 client.ExternalBeginFrameSource()->TestOnBeginFrame(args); | 1901 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1868 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1902 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
1869 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1903 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
1870 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1904 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
1871 EXPECT_TRUE(client.needs_begin_frames()); | 1905 EXPECT_TRUE(client.needs_begin_frames()); |
1872 | 1906 |
1873 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1907 // Queue BeginFrames while we are still handling the previous BeginFrame. |
1874 args.frame_time += base::TimeDelta::FromSeconds(1); | 1908 args.frame_time += base::TimeDelta::FromSeconds(1); |
1875 client.ExternalBeginFrameSource()->TestOnBeginFrame(args); | 1909 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1876 args.frame_time += base::TimeDelta::FromSeconds(1); | 1910 args.frame_time += base::TimeDelta::FromSeconds(1); |
1877 client.ExternalBeginFrameSource()->TestOnBeginFrame(args); | 1911 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); |
1878 | 1912 |
1879 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1913 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
1880 client.Reset(); | 1914 client.Reset(); |
1881 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1915 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1882 EXPECT_NO_ACTION(client); | 1916 EXPECT_NO_ACTION(client); |
1883 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1917 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
1884 EXPECT_TRUE(client.needs_begin_frames()); | 1918 EXPECT_TRUE(client.needs_begin_frames()); |
1885 | 1919 |
1886 // NotifyReadyToCommit should trigger the commit. | 1920 // NotifyReadyToCommit should trigger the commit. |
1887 client.Reset(); | 1921 client.Reset(); |
(...skipping 26 matching lines...) Expand all Loading... |
1914 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 1948 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. |
1915 client.Reset(); | 1949 client.Reset(); |
1916 client.task_runner().RunPendingTasks(); | 1950 client.task_runner().RunPendingTasks(); |
1917 EXPECT_NO_ACTION(client); | 1951 EXPECT_NO_ACTION(client); |
1918 } | 1952 } |
1919 | 1953 |
1920 TEST(SchedulerTest, | 1954 TEST(SchedulerTest, |
1921 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { | 1955 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { |
1922 FakeSchedulerClient client; | 1956 FakeSchedulerClient client; |
1923 SchedulerSettings scheduler_settings; | 1957 SchedulerSettings scheduler_settings; |
1924 scheduler_settings.begin_frame_scheduling_enabled = false; | |
1925 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1958 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1926 scheduler->SetCanStart(); | 1959 scheduler->SetCanStart(); |
1927 scheduler->SetVisible(true); | 1960 scheduler->SetVisible(true); |
1928 scheduler->SetCanDraw(true); | 1961 scheduler->SetCanDraw(true); |
1929 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1962 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1930 | 1963 |
1931 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1964 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
1932 client.Reset(); | 1965 client.Reset(); |
1933 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 1966 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); |
1934 scheduler->SetNeedsCommit(); | 1967 scheduler->SetNeedsCommit(); |
(...skipping 21 matching lines...) Expand all Loading... |
1956 client.Reset(); | 1989 client.Reset(); |
1957 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1990 client.task_runner().RunPendingTasks(); // Run posted deadline. |
1958 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1991 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1959 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 1992 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); |
1960 } | 1993 } |
1961 | 1994 |
1962 TEST(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { | 1995 TEST(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { |
1963 FakeSchedulerClient client; | 1996 FakeSchedulerClient client; |
1964 SchedulerSettings scheduler_settings; | 1997 SchedulerSettings scheduler_settings; |
1965 scheduler_settings.impl_side_painting = true; | 1998 scheduler_settings.impl_side_painting = true; |
| 1999 scheduler_settings.use_external_begin_frame_source = true; |
1966 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 2000 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
1967 scheduler->SetCanStart(); | 2001 scheduler->SetCanStart(); |
1968 scheduler->SetVisible(true); | 2002 scheduler->SetVisible(true); |
1969 scheduler->SetCanDraw(true); | 2003 scheduler->SetCanDraw(true); |
1970 | 2004 |
1971 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 2005 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
1972 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 2006 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
1973 | 2007 |
1974 // SetNeedsCommit should begin the frame. | 2008 // SetNeedsCommit should begin the frame. |
1975 client.Reset(); | 2009 client.Reset(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2056 before_deadline = client.now_src()->Now(); | 2090 before_deadline = client.now_src()->Now(); |
2057 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2091 EXPECT_TRUE(client.task_runner().RunTasksWhile( |
2058 client.ImplFrameDeadlinePending(true))); | 2092 client.ImplFrameDeadlinePending(true))); |
2059 after_deadline = client.now_src()->Now(); | 2093 after_deadline = client.now_src()->Now(); |
2060 } | 2094 } |
2061 | 2095 |
2062 TEST(SchedulerTest, | 2096 TEST(SchedulerTest, |
2063 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) { | 2097 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) { |
2064 FakeSchedulerClient client; | 2098 FakeSchedulerClient client; |
2065 SchedulerSettings settings; | 2099 SchedulerSettings settings; |
| 2100 settings.use_external_begin_frame_source = true; |
2066 TestScheduler* scheduler = client.CreateScheduler(settings); | 2101 TestScheduler* scheduler = client.CreateScheduler(settings); |
2067 | 2102 |
2068 scheduler->SetCanStart(); | 2103 scheduler->SetCanStart(); |
2069 scheduler->SetVisible(true); | 2104 scheduler->SetVisible(true); |
2070 scheduler->SetCanDraw(true); | 2105 scheduler->SetCanDraw(true); |
2071 | 2106 |
2072 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 2107 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
2073 | 2108 |
2074 // Set needs commit so that the scheduler tries to wait for the main thread | 2109 // Set needs commit so that the scheduler tries to wait for the main thread |
2075 scheduler->SetNeedsCommit(); | 2110 scheduler->SetNeedsCommit(); |
(...skipping 25 matching lines...) Expand all Loading... |
2101 client.task_runner().RunPendingTasks(); | 2136 client.task_runner().RunPendingTasks(); |
2102 // Deadline task finally completes | 2137 // Deadline task finally completes |
2103 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2138 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
2104 } | 2139 } |
2105 | 2140 |
2106 TEST(SchedulerTest, | 2141 TEST(SchedulerTest, |
2107 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) { | 2142 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) { |
2108 FakeSchedulerClient client; | 2143 FakeSchedulerClient client; |
2109 SchedulerSettings settings; | 2144 SchedulerSettings settings; |
2110 settings.disable_hi_res_timer_tasks_on_battery = true; | 2145 settings.disable_hi_res_timer_tasks_on_battery = true; |
| 2146 settings.use_external_begin_frame_source = true; |
2111 TestScheduler* scheduler = client.CreateScheduler(settings); | 2147 TestScheduler* scheduler = client.CreateScheduler(settings); |
2112 | 2148 |
2113 scheduler->SetCanStart(); | 2149 scheduler->SetCanStart(); |
2114 scheduler->SetVisible(true); | 2150 scheduler->SetVisible(true); |
2115 scheduler->SetCanDraw(true); | 2151 scheduler->SetCanDraw(true); |
2116 | 2152 |
2117 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 2153 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
2118 | 2154 |
2119 // Set needs commit so that the scheduler tries to wait for the main thread | 2155 // Set needs commit so that the scheduler tries to wait for the main thread |
2120 scheduler->SetNeedsCommit(); | 2156 scheduler->SetNeedsCommit(); |
(...skipping 15 matching lines...) Expand all Loading... |
2136 | 2172 |
2137 // Deadline task is pending | 2173 // Deadline task is pending |
2138 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2174 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
2139 client.task_runner().RunPendingTasks(); | 2175 client.task_runner().RunPendingTasks(); |
2140 // Deadline task runs immediately | 2176 // Deadline task runs immediately |
2141 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2177 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
2142 } | 2178 } |
2143 | 2179 |
2144 } // namespace | 2180 } // namespace |
2145 } // namespace cc | 2181 } // namespace cc |
OLD | NEW |