Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
| 5 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 namespace cc { | 40 namespace cc { |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 class FakeSchedulerClient; | 43 class FakeSchedulerClient; |
| 44 | 44 |
| 45 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 45 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
| 46 FakeSchedulerClient* client); | 46 FakeSchedulerClient* client); |
| 47 | 47 |
| 48 class FakeSchedulerClient : public SchedulerClient { | 48 class FakeSchedulerClient : public SchedulerClient { |
| 49 public: | 49 public: |
| 50 struct FakeBeginFrameSourceForFakeSchedulerClient | 50 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { |
| 51 : public FakeBeginFrameSource { | 51 public: |
| 52 FakeSchedulerClient* client_; | 52 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) |
| 53 | |
| 54 explicit FakeBeginFrameSourceForFakeSchedulerClient( | |
| 55 FakeSchedulerClient* client) | |
| 56 : client_(client) {} | 53 : client_(client) {} |
| 54 virtual ~FakeExternalBeginFrameSource() {} | |
| 57 | 55 |
| 58 virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) override { | 56 virtual void OnNeedsBeginFramesChange(bool needs_begin_frames) override { |
| 59 if (needs_begin_frames) { | 57 if (needs_begin_frames) { |
| 60 client_->actions_.push_back("SetNeedsBeginFrames(true)"); | 58 client_->actions_.push_back("SetNeedsBeginFrames(true)"); |
| 61 } else { | 59 } else { |
| 62 client_->actions_.push_back("SetNeedsBeginFrames(false)"); | 60 client_->actions_.push_back("SetNeedsBeginFrames(false)"); |
| 63 } | 61 } |
| 64 client_->states_.push_back(client_->scheduler_->AsValue()); | 62 client_->states_.push_back(client_->scheduler_->AsValue()); |
| 65 } | 63 } |
| 64 | |
| 65 void TestOnBeginFrame(const BeginFrameArgs& args) { | |
| 66 return CallOnBeginFrame(args); | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 FakeSchedulerClient* client_; | |
| 66 }; | 71 }; |
| 67 | 72 |
| 68 class FakePowerMonitorSource : public base::PowerMonitorSource { | 73 class FakePowerMonitorSource : public base::PowerMonitorSource { |
| 69 public: | 74 public: |
| 70 FakePowerMonitorSource() {} | 75 FakePowerMonitorSource() {} |
| 71 virtual ~FakePowerMonitorSource() {} | 76 virtual ~FakePowerMonitorSource() {} |
| 72 void GeneratePowerStateEvent(bool on_battery_power) { | 77 void GeneratePowerStateEvent(bool on_battery_power) { |
| 73 on_battery_power_impl_ = on_battery_power; | 78 on_battery_power_impl_ = on_battery_power; |
| 74 ProcessPowerEvent(POWER_STATE_EVENT); | 79 ProcessPowerEvent(POWER_STATE_EVENT); |
| 75 base::MessageLoop::current()->RunUntilIdle(); | 80 base::MessageLoop::current()->RunUntilIdle(); |
| 76 } | 81 } |
| 77 virtual bool IsOnBatteryPowerImpl() override { | 82 virtual bool IsOnBatteryPowerImpl() override { |
| 78 return on_battery_power_impl_; | 83 return on_battery_power_impl_; |
| 79 } | 84 } |
| 80 | 85 |
| 81 private: | 86 private: |
| 82 bool on_battery_power_impl_; | 87 bool on_battery_power_impl_; |
| 83 }; | 88 }; |
| 84 | 89 |
| 85 FakeSchedulerClient() | 90 FakeSchedulerClient() |
| 86 : automatic_swap_ack_(true), | 91 : automatic_swap_ack_(true), |
| 87 swap_contains_incomplete_tile_(false), | 92 swap_contains_incomplete_tile_(false), |
| 88 redraw_will_happen_if_update_visible_tiles_happens_(false), | 93 redraw_will_happen_if_update_visible_tiles_happens_(false), |
| 89 now_src_(TestNowSource::Create()), | 94 now_src_(TestNowSource::Create()), |
| 90 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), | 95 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), |
| 91 fake_frame_source_(this), | 96 fake_external_begin_frame_source_(nullptr), |
| 92 fake_power_monitor_source_(new FakePowerMonitorSource), | 97 fake_power_monitor_source_(new FakePowerMonitorSource), |
| 93 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( | 98 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( |
| 94 fake_power_monitor_source_)), | 99 fake_power_monitor_source_)), |
| 95 scheduler_(nullptr) { | 100 scheduler_(nullptr) { |
| 96 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() | 101 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() |
| 97 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | 102 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); |
| 98 // Fail if we need to run 100 tasks in a row. | 103 // Fail if we need to run 100 tasks in a row. |
| 99 task_runner_->SetRunTaskLimit(100); | 104 task_runner_->SetRunTaskLimit(100); |
| 100 Reset(); | 105 Reset(); |
| 101 } | 106 } |
| 102 | 107 |
| 103 void Reset() { | 108 void Reset() { |
| 104 actions_.clear(); | 109 actions_.clear(); |
| 105 states_.clear(); | 110 states_.clear(); |
| 106 draw_will_happen_ = true; | 111 draw_will_happen_ = true; |
| 107 swap_will_happen_if_draw_happens_ = true; | 112 swap_will_happen_if_draw_happens_ = true; |
| 108 num_draws_ = 0; | 113 num_draws_ = 0; |
| 109 log_anticipated_draw_time_change_ = false; | 114 log_anticipated_draw_time_change_ = false; |
| 110 } | 115 } |
| 111 | 116 |
| 112 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { | 117 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { |
| 113 scheduler_ = TestScheduler::Create( | 118 scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source; |
| 114 now_src_, this, settings, 0, task_runner_, &power_monitor_); | 119 if (settings.begin_frame_scheduling_enabled && |
| 120 settings.throttle_frame_production) { | |
| 121 fake_external_begin_frame_source.reset( | |
| 122 new FakeExternalBeginFrameSource(this)); | |
| 123 fake_external_begin_frame_source_ = | |
| 124 fake_external_begin_frame_source.get(); | |
| 125 } | |
| 126 scheduler_ = TestScheduler::Create(now_src_, | |
| 127 this, | |
| 128 settings, | |
| 129 0, | |
| 130 task_runner_, | |
| 131 &power_monitor_, | |
| 132 fake_external_begin_frame_source.Pass()); | |
| 115 DCHECK(scheduler_); | 133 DCHECK(scheduler_); |
| 116 return scheduler_.get(); | 134 return scheduler_.get(); |
| 117 } | 135 } |
| 118 | 136 |
| 119 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it | 137 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it |
| 120 // for tests that do. | 138 // for tests that do. |
| 121 void set_log_anticipated_draw_time_change(bool log) { | 139 void set_log_anticipated_draw_time_change(bool log) { |
| 122 log_anticipated_draw_time_change_ = log; | 140 log_anticipated_draw_time_change_ = log; |
| 123 } | 141 } |
| 124 bool needs_begin_frames() { return fake_frame_source_.NeedsBeginFrames(); } | 142 bool needs_begin_frames() { return scheduler_->NeedsBeginFrames(); } |
| 125 int num_draws() const { return num_draws_; } | 143 int num_draws() const { return num_draws_; } |
| 126 int num_actions_() const { return static_cast<int>(actions_.size()); } | 144 int num_actions_() const { return static_cast<int>(actions_.size()); } |
| 127 const char* Action(int i) const { return actions_[i]; } | 145 const char* Action(int i) const { return actions_[i]; } |
| 128 std::string StateForAction(int i) const { return states_[i]->ToString(); } | 146 std::string StateForAction(int i) const { return states_[i]->ToString(); } |
| 129 base::TimeTicks posted_begin_impl_frame_deadline() const { | 147 base::TimeTicks posted_begin_impl_frame_deadline() const { |
| 130 return posted_begin_impl_frame_deadline_; | 148 return posted_begin_impl_frame_deadline_; |
| 131 } | 149 } |
| 132 | 150 |
| 133 bool ExternalBeginFrame() { | 151 bool ExternalBeginFrame() { |
| 134 return scheduler_->settings().begin_frame_scheduling_enabled && | 152 return scheduler_->settings().begin_frame_scheduling_enabled && |
| 135 scheduler_->settings().throttle_frame_production; | 153 scheduler_->settings().throttle_frame_production; |
| 136 } | 154 } |
| 137 virtual FakeBeginFrameSource* ExternalBeginFrameSource() override { | 155 |
| 138 return &fake_frame_source_; | 156 FakeExternalBeginFrameSource* ExternalBeginFrameSource() { |
| 157 DCHECK(ExternalBeginFrame()); | |
| 158 return fake_external_begin_frame_source_; | |
| 139 } | 159 } |
| 140 | 160 |
| 141 base::PowerMonitor* PowerMonitor() { return &power_monitor_; } | 161 base::PowerMonitor* PowerMonitor() { return &power_monitor_; } |
| 142 | 162 |
| 143 FakePowerMonitorSource* PowerMonitorSource() { | 163 FakePowerMonitorSource* PowerMonitorSource() { |
| 144 return fake_power_monitor_source_; | 164 return fake_power_monitor_source_; |
| 145 } | 165 } |
| 146 | 166 |
| 147 void AdvanceFrame() { | 167 void AdvanceFrame() { |
| 148 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | 168 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
| 149 "FakeSchedulerClient::AdvanceFrame"); | 169 "FakeSchedulerClient::AdvanceFrame"); |
| 150 // EXPECT_TRUE(needs_begin_frames()); | |
| 151 if (ExternalBeginFrame()) { | 170 if (ExternalBeginFrame()) { |
| 152 // Creep the time forward so that any BeginFrameArgs is not equal to the | 171 // Creep the time forward so that any BeginFrameArgs is not equal to the |
| 153 // last one otherwise we violate the BeginFrameSource contract. | 172 // last one otherwise we violate the BeginFrameSource contract. |
| 154 now_src_->AdvanceNowMicroseconds(1); | 173 now_src_->AdvanceNowMicroseconds(1); |
| 155 fake_frame_source_.TestOnBeginFrame( | 174 fake_external_begin_frame_source_->TestOnBeginFrame( |
| 156 CreateBeginFrameArgsForTesting(now_src_)); | 175 CreateBeginFrameArgsForTesting(now_src_)); |
| 157 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 176 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 158 } | 177 } |
| 159 | 178 |
| 160 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); | 179 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); |
| 161 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 180 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 162 } | 181 } |
| 163 | 182 |
| 164 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } | 183 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } |
| 165 TestNowSource* now_src() { return now_src_.get(); } | 184 TestNowSource* now_src() { return now_src_.get(); } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 bool automatic_swap_ack_; | 304 bool automatic_swap_ack_; |
| 286 int num_draws_; | 305 int num_draws_; |
| 287 bool log_anticipated_draw_time_change_; | 306 bool log_anticipated_draw_time_change_; |
| 288 bool swap_contains_incomplete_tile_; | 307 bool swap_contains_incomplete_tile_; |
| 289 bool redraw_will_happen_if_update_visible_tiles_happens_; | 308 bool redraw_will_happen_if_update_visible_tiles_happens_; |
| 290 base::TimeTicks posted_begin_impl_frame_deadline_; | 309 base::TimeTicks posted_begin_impl_frame_deadline_; |
| 291 std::vector<const char*> actions_; | 310 std::vector<const char*> actions_; |
| 292 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; | 311 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; |
| 293 scoped_refptr<TestNowSource> now_src_; | 312 scoped_refptr<TestNowSource> now_src_; |
| 294 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 313 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
| 295 FakeBeginFrameSourceForFakeSchedulerClient fake_frame_source_; | 314 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; |
| 296 FakePowerMonitorSource* fake_power_monitor_source_; | 315 FakePowerMonitorSource* fake_power_monitor_source_; |
| 297 base::PowerMonitor power_monitor_; | 316 base::PowerMonitor power_monitor_; |
| 298 scoped_ptr<TestScheduler> scheduler_; | 317 scoped_ptr<TestScheduler> scheduler_; |
| 299 }; | 318 }; |
| 300 | 319 |
| 301 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 320 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
| 302 FakeSchedulerClient* client) { | 321 FakeSchedulerClient* client) { |
| 303 TRACE_EVENT0("cc", | 322 TRACE_EVENT0("cc", |
| 304 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); | 323 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); |
| 305 | 324 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 324 SCOPED_TRACE( | 343 SCOPED_TRACE( |
| 325 "We need another BeginImplFrame so Scheduler calls " | 344 "We need another BeginImplFrame so Scheduler calls " |
| 326 "SetNeedsBeginFrame(false)."); | 345 "SetNeedsBeginFrame(false)."); |
| 327 client->AdvanceFrame(); | 346 client->AdvanceFrame(); |
| 328 } | 347 } |
| 329 | 348 |
| 330 // Run the posted deadline task. | 349 // Run the posted deadline task. |
| 331 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 350 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 332 client->task_runner().RunTasksWhile(client->ImplFrameDeadlinePending(true)); | 351 client->task_runner().RunTasksWhile(client->ImplFrameDeadlinePending(true)); |
| 333 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 352 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 334 | |
| 335 // EXPECT_FALSE(client->needs_begin_frames()); | |
| 336 } | 353 } |
| 337 | 354 |
| 338 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 355 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
| 339 FakeSchedulerClient client; | 356 FakeSchedulerClient client; |
| 340 SchedulerSettings default_scheduler_settings; | 357 SchedulerSettings default_scheduler_settings; |
| 341 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 358 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 342 scheduler->SetCanStart(); | 359 scheduler->SetCanStart(); |
| 343 scheduler->SetVisible(true); | 360 scheduler->SetVisible(true); |
| 344 scheduler->SetCanDraw(true); | 361 scheduler->SetCanDraw(true); |
| 345 | 362 |
| (...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1414 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1431 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1415 scheduler->SetCanStart(); | 1432 scheduler->SetCanStart(); |
| 1416 scheduler->SetVisible(true); | 1433 scheduler->SetVisible(true); |
| 1417 scheduler->SetCanDraw(true); | 1434 scheduler->SetCanDraw(true); |
| 1418 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1435 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1419 | 1436 |
| 1420 // SetNeedsCommit should begin the frame on the next BeginImplFrame | 1437 // SetNeedsCommit should begin the frame on the next BeginImplFrame |
| 1421 // without calling SetNeedsBeginFrame. | 1438 // without calling SetNeedsBeginFrame. |
| 1422 client.Reset(); | 1439 client.Reset(); |
| 1423 scheduler->SetNeedsCommit(); | 1440 scheduler->SetNeedsCommit(); |
| 1424 EXPECT_FALSE(client.needs_begin_frames()); | 1441 EXPECT_TRUE(client.needs_begin_frames()); |
|
brianderson
2014/10/18 00:08:45
BeginFramesNotFromClient tests are meant to test c
simonhong
2014/10/23 01:03:08
All client.needs_begin_frames() in NotFromClient a
| |
| 1425 EXPECT_NO_ACTION(client); | 1442 EXPECT_NO_ACTION(client); |
| 1426 client.Reset(); | 1443 client.Reset(); |
| 1427 | 1444 |
| 1428 // When the client-driven BeginFrame are disabled, the scheduler posts it's | 1445 // When the client-driven BeginFrame are disabled, the scheduler posts it's |
| 1429 // own BeginFrame tasks. | 1446 // own BeginFrame tasks. |
| 1430 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1447 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1431 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1448 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1432 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1449 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1433 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1450 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1434 EXPECT_FALSE(client.needs_begin_frames()); | 1451 EXPECT_TRUE(client.needs_begin_frames()); |
| 1435 client.Reset(); | 1452 client.Reset(); |
| 1436 | 1453 |
| 1437 // If we don't swap on the deadline, we wait for the next BeginFrame. | 1454 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 1438 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1455 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1439 EXPECT_NO_ACTION(client); | 1456 EXPECT_NO_ACTION(client); |
| 1440 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1457 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1441 EXPECT_FALSE(client.needs_begin_frames()); | 1458 EXPECT_TRUE(client.needs_begin_frames()); |
| 1442 client.Reset(); | 1459 client.Reset(); |
| 1443 | 1460 |
| 1444 // NotifyReadyToCommit should trigger the commit. | 1461 // NotifyReadyToCommit should trigger the commit. |
| 1445 scheduler->NotifyBeginMainFrameStarted(); | 1462 scheduler->NotifyBeginMainFrameStarted(); |
| 1446 scheduler->NotifyReadyToCommit(); | 1463 scheduler->NotifyReadyToCommit(); |
| 1447 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1464 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1448 EXPECT_FALSE(client.needs_begin_frames()); | 1465 EXPECT_TRUE(client.needs_begin_frames()); |
| 1449 client.Reset(); | 1466 client.Reset(); |
| 1450 | 1467 |
| 1451 // BeginImplFrame should prepare the draw. | 1468 // BeginImplFrame should prepare the draw. |
| 1452 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1469 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1453 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1470 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1454 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1471 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1455 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1472 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1456 EXPECT_FALSE(client.needs_begin_frames()); | 1473 EXPECT_TRUE(client.needs_begin_frames()); |
| 1457 client.Reset(); | 1474 client.Reset(); |
| 1458 | 1475 |
| 1459 // BeginImplFrame deadline should draw. | 1476 // BeginImplFrame deadline should draw. |
| 1460 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1477 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); |
| 1461 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1478 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
| 1462 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1479 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1463 EXPECT_FALSE(client.needs_begin_frames()); | 1480 EXPECT_TRUE(client.needs_begin_frames()); |
| 1464 client.Reset(); | 1481 client.Reset(); |
| 1465 | 1482 |
| 1466 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1483 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 1467 // to avoid excessive toggles. | 1484 // to avoid excessive toggles. |
| 1468 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1485 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1469 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1486 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1470 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1487 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1471 client.Reset(); | 1488 client.Reset(); |
| 1472 | 1489 |
| 1473 // Make sure SetNeedsBeginFrame isn't called on the client | 1490 // Make sure SetNeedsBeginFrame isn't called on the client |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1512 scheduler->SetCanDraw(true); | 1529 scheduler->SetCanDraw(true); |
| 1513 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1530 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1514 | 1531 |
| 1515 // To test swap ack throttling, this test disables automatic swap acks. | 1532 // To test swap ack throttling, this test disables automatic swap acks. |
| 1516 scheduler->SetMaxSwapsPending(1); | 1533 scheduler->SetMaxSwapsPending(1); |
| 1517 client.SetAutomaticSwapAck(false); | 1534 client.SetAutomaticSwapAck(false); |
| 1518 | 1535 |
| 1519 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1536 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1520 client.Reset(); | 1537 client.Reset(); |
| 1521 scheduler->SetNeedsCommit(); | 1538 scheduler->SetNeedsCommit(); |
| 1522 EXPECT_FALSE(client.needs_begin_frames()); | 1539 EXPECT_TRUE(client.needs_begin_frames()); |
|
brianderson
2014/10/18 00:08:44
Ditto for this class of tests.
| |
| 1523 EXPECT_NO_ACTION(client); | 1540 EXPECT_NO_ACTION(client); |
| 1524 client.Reset(); | 1541 client.Reset(); |
| 1525 | 1542 |
| 1526 // Trigger the first BeginImplFrame and BeginMainFrame | 1543 // Trigger the first BeginImplFrame and BeginMainFrame |
| 1527 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1544 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1528 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1545 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1529 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1546 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1530 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1547 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1531 EXPECT_FALSE(client.needs_begin_frames()); | 1548 EXPECT_TRUE(client.needs_begin_frames()); |
| 1532 client.Reset(); | 1549 client.Reset(); |
| 1533 | 1550 |
| 1534 // NotifyReadyToCommit should trigger the pending commit and draw. | 1551 // NotifyReadyToCommit should trigger the pending commit and draw. |
| 1535 scheduler->NotifyBeginMainFrameStarted(); | 1552 scheduler->NotifyBeginMainFrameStarted(); |
| 1536 scheduler->NotifyReadyToCommit(); | 1553 scheduler->NotifyReadyToCommit(); |
| 1537 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1554 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1538 EXPECT_FALSE(client.needs_begin_frames()); | 1555 EXPECT_TRUE(client.needs_begin_frames()); |
| 1539 client.Reset(); | 1556 client.Reset(); |
| 1540 | 1557 |
| 1541 // Swapping will put us into a swap throttled state. | 1558 // Swapping will put us into a swap throttled state. |
| 1542 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1559 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1543 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1560 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 1544 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1561 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 1545 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1562 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1546 EXPECT_FALSE(client.needs_begin_frames()); | 1563 EXPECT_TRUE(client.needs_begin_frames()); |
| 1547 client.Reset(); | 1564 client.Reset(); |
| 1548 | 1565 |
| 1549 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 1566 // While swap throttled, BeginFrames should trigger BeginImplFrames, |
| 1550 // but not a BeginMainFrame or draw. | 1567 // but not a BeginMainFrame or draw. |
| 1551 scheduler->SetNeedsCommit(); | 1568 scheduler->SetNeedsCommit(); |
| 1552 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1569 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1553 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 1570 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
| 1554 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1571 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1555 EXPECT_FALSE(client.needs_begin_frames()); | 1572 EXPECT_TRUE(client.needs_begin_frames()); |
| 1556 client.Reset(); | 1573 client.Reset(); |
| 1557 | 1574 |
| 1558 // Take us out of a swap throttled state. | 1575 // Take us out of a swap throttled state. |
| 1559 scheduler->DidSwapBuffersComplete(); | 1576 scheduler->DidSwapBuffersComplete(); |
| 1560 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); | 1577 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
| 1561 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1578 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1562 EXPECT_FALSE(client.needs_begin_frames()); | 1579 EXPECT_TRUE(client.needs_begin_frames()); |
| 1563 client.Reset(); | 1580 client.Reset(); |
| 1564 | 1581 |
| 1565 // BeginImplFrame deadline should draw. | 1582 // BeginImplFrame deadline should draw. |
| 1566 scheduler->SetNeedsRedraw(); | 1583 scheduler->SetNeedsRedraw(); |
| 1567 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1584 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1568 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1585 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 1569 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1586 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 1570 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1587 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1571 EXPECT_FALSE(client.needs_begin_frames()); | 1588 EXPECT_TRUE(client.needs_begin_frames()); |
| 1572 client.Reset(); | 1589 client.Reset(); |
| 1573 } | 1590 } |
| 1574 | 1591 |
| 1575 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { | 1592 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { |
| 1576 bool begin_frame_scheduling_enabled = false; | 1593 bool begin_frame_scheduling_enabled = false; |
| 1577 bool throttle_frame_production = true; | 1594 bool throttle_frame_production = true; |
| 1578 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1595 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
| 1579 throttle_frame_production); | 1596 throttle_frame_production); |
| 1580 } | 1597 } |
| 1581 | 1598 |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2145 | 2162 |
| 2146 // Deadline task is pending | 2163 // Deadline task is pending |
| 2147 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2164 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 2148 client.task_runner().RunPendingTasks(); | 2165 client.task_runner().RunPendingTasks(); |
| 2149 // Deadline task runs immediately | 2166 // Deadline task runs immediately |
| 2150 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2167 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 2151 } | 2168 } |
| 2152 | 2169 |
| 2153 } // namespace | 2170 } // namespace |
| 2154 } // namespace cc | 2171 } // namespace cc |
| OLD | NEW |