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 | 4 |
| 5 #include "cc/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/power_monitor/power_monitor.h" | 14 #include "base/power_monitor/power_monitor.h" |
| 15 #include "base/power_monitor/power_monitor_source.h" | 15 #include "base/power_monitor/power_monitor_source.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "cc/test/begin_frame_args_test.h" | 18 #include "cc/test/begin_frame_args_test.h" |
| 19 #include "cc/test/ordered_simple_task_runner.h" | 19 #include "cc/test/ordered_simple_task_runner.h" |
| 20 #include "cc/test/scheduler_test_common.h" | 20 #include "cc/test/scheduler_test_common.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ | 24 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ |
| 25 do { \ | 25 client->ExpectAction(action, action_index, expected_num_actions, \ |
|
brianderson
2015/01/27 01:08:25
Please keep the implementation in the macro. I kno
Jimmy Jo
2015/01/28 00:53:47
Done.
| |
| 26 EXPECT_EQ(expected_num_actions, client.num_actions_()); \ | 26 scheduler_.get()); |
| 27 if (action_index >= 0) { \ | |
| 28 ASSERT_LT(action_index, client.num_actions_()) << scheduler; \ | |
| 29 EXPECT_STREQ(action, client.Action(action_index)); \ | |
| 30 } \ | |
| 31 for (int i = expected_num_actions; i < client.num_actions_(); ++i) \ | |
| 32 ADD_FAILURE() << "Unexpected action: " << client.Action(i) \ | |
| 33 << " with state:\n" << client.StateForAction(i); \ | |
| 34 } while (false) | |
| 35 | 27 |
| 36 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) | 28 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) |
| 37 | 29 |
| 38 #define EXPECT_SINGLE_ACTION(action, client) \ | 30 #define EXPECT_SINGLE_ACTION(action, client) \ |
| 39 EXPECT_ACTION(action, client, 0, 1) | 31 EXPECT_ACTION(action, client, 0, 1) |
| 40 | 32 |
| 41 #define EXPECT_SCOPED(statements) \ | 33 #define EXPECT_SCOPED(statements) \ |
| 42 { \ | 34 { \ |
| 43 SCOPED_TRACE(""); \ | 35 SCOPED_TRACE(""); \ |
| 44 statements; \ | 36 statements; \ |
| 45 } | 37 } |
| 46 | 38 |
| 47 #define CREATE_SCHEDULER_AND_INIT_SURFACE(settings) \ | |
| 48 TestScheduler* scheduler = client.CreateScheduler(settings); \ | |
| 49 EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler)); | |
| 50 | |
| 51 namespace cc { | 39 namespace cc { |
| 52 namespace { | 40 namespace { |
| 53 | 41 |
| 54 class FakeSchedulerClient; | |
| 55 | |
| 56 class FakeSchedulerClient : public SchedulerClient { | 42 class FakeSchedulerClient : public SchedulerClient { |
| 57 public: | 43 public: |
| 58 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { | |
| 59 public: | |
| 60 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) | |
| 61 : client_(client) {} | |
| 62 ~FakeExternalBeginFrameSource() override {} | |
| 63 | |
| 64 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { | |
| 65 if (needs_begin_frames) { | |
| 66 client_->PushAction("SetNeedsBeginFrames(true)"); | |
| 67 } else { | |
| 68 client_->PushAction("SetNeedsBeginFrames(false)"); | |
| 69 } | |
| 70 client_->states_.push_back(client_->scheduler_->AsValue()); | |
| 71 } | |
| 72 | |
| 73 void TestOnBeginFrame(const BeginFrameArgs& args) { | |
| 74 return CallOnBeginFrame(args); | |
| 75 } | |
| 76 | |
| 77 private: | |
| 78 FakeSchedulerClient* client_; | |
| 79 }; | |
| 80 | |
| 81 class FakePowerMonitorSource : public base::PowerMonitorSource { | |
| 82 public: | |
| 83 FakePowerMonitorSource() {} | |
| 84 ~FakePowerMonitorSource() override {} | |
| 85 void GeneratePowerStateEvent(bool on_battery_power) { | |
| 86 on_battery_power_impl_ = on_battery_power; | |
| 87 ProcessPowerEvent(POWER_STATE_EVENT); | |
| 88 base::MessageLoop::current()->RunUntilIdle(); | |
| 89 } | |
| 90 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; } | |
| 91 | |
| 92 private: | |
| 93 bool on_battery_power_impl_; | |
| 94 }; | |
| 95 | |
| 96 FakeSchedulerClient() | 44 FakeSchedulerClient() |
| 97 : automatic_swap_ack_(true), | 45 : automatic_swap_ack_(true), |
| 98 begin_frame_is_sent_to_children_(false), | 46 begin_frame_is_sent_to_children_(false), |
| 99 now_src_(TestNowSource::Create()), | 47 now_src_(TestNowSource::Create()), |
|
brianderson
2015/01/27 01:08:25
Should now_src_ and task_runner_ also move to the
Jimmy Jo
2015/01/28 00:53:48
Done.
| |
| 100 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), | 48 task_runner_(new OrderedSimpleTaskRunner(now_src_, true)), |
| 101 fake_external_begin_frame_source_(nullptr), | |
| 102 fake_power_monitor_source_(new FakePowerMonitorSource), | |
| 103 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( | |
| 104 fake_power_monitor_source_)), | |
| 105 scheduler_(nullptr) { | 49 scheduler_(nullptr) { |
| 106 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() | 50 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() |
| 107 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | 51 now_src_->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); |
| 108 // Fail if we need to run 100 tasks in a row. | 52 // Fail if we need to run 100 tasks in a row. |
| 109 task_runner_->SetRunTaskLimit(100); | 53 task_runner_->SetRunTaskLimit(100); |
| 110 Reset(); | 54 Reset(); |
| 111 } | 55 } |
| 112 | 56 |
| 113 void Reset() { | 57 void Reset() { |
| 114 actions_.clear(); | 58 actions_.clear(); |
| 115 states_.clear(); | 59 states_.clear(); |
| 116 draw_will_happen_ = true; | 60 draw_will_happen_ = true; |
| 117 swap_will_happen_if_draw_happens_ = true; | 61 swap_will_happen_if_draw_happens_ = true; |
| 118 num_draws_ = 0; | 62 num_draws_ = 0; |
| 119 log_anticipated_draw_time_change_ = false; | 63 log_anticipated_draw_time_change_ = false; |
| 120 begin_frame_is_sent_to_children_ = false; | 64 begin_frame_is_sent_to_children_ = false; |
| 121 } | 65 } |
| 122 | 66 |
| 123 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { | 67 void set_scheduler(TestScheduler* scheduler) { scheduler_ = scheduler; } |
| 124 scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source; | |
| 125 if (settings.use_external_begin_frame_source) { | |
| 126 fake_external_begin_frame_source.reset( | |
| 127 new FakeExternalBeginFrameSource(this)); | |
| 128 fake_external_begin_frame_source_ = | |
| 129 fake_external_begin_frame_source.get(); | |
| 130 } | |
| 131 scheduler_ = TestScheduler::Create(now_src_, | |
| 132 this, | |
| 133 settings, | |
| 134 0, | |
| 135 task_runner_, | |
| 136 &power_monitor_, | |
| 137 fake_external_begin_frame_source.Pass()); | |
| 138 DCHECK(scheduler_); | |
| 139 return scheduler_.get(); | |
| 140 } | |
| 141 | 68 |
| 142 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it | 69 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it |
| 143 // for tests that do. | 70 // for tests that do. |
| 144 void set_log_anticipated_draw_time_change(bool log) { | 71 void set_log_anticipated_draw_time_change(bool log) { |
| 145 log_anticipated_draw_time_change_ = log; | 72 log_anticipated_draw_time_change_ = log; |
| 146 } | 73 } |
| 147 bool needs_begin_frames() { | 74 bool needs_begin_frames() { |
| 148 return scheduler_->frame_source().NeedsBeginFrames(); | 75 return scheduler_->frame_source().NeedsBeginFrames(); |
| 149 } | 76 } |
| 150 int num_draws() const { return num_draws_; } | 77 int num_draws() const { return num_draws_; } |
| 151 int num_actions_() const { return static_cast<int>(actions_.size()); } | 78 int num_actions_() const { return static_cast<int>(actions_.size()); } |
| 152 const char* Action(int i) const { return actions_[i]; } | 79 const char* Action(int i) const { return actions_[i]; } |
| 153 std::string StateForAction(int i) const { return states_[i]->ToString(); } | 80 std::string StateForAction(int i) const { return states_[i]->ToString(); } |
| 154 base::TimeTicks posted_begin_impl_frame_deadline() const { | 81 base::TimeTicks posted_begin_impl_frame_deadline() const { |
| 155 return posted_begin_impl_frame_deadline_; | 82 return posted_begin_impl_frame_deadline_; |
| 156 } | 83 } |
| 157 | 84 |
| 158 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { | |
| 159 return fake_external_begin_frame_source_; | |
| 160 } | |
| 161 | |
| 162 base::PowerMonitor* PowerMonitor() { return &power_monitor_; } | |
| 163 | |
| 164 FakePowerMonitorSource* PowerMonitorSource() { | |
| 165 return fake_power_monitor_source_; | |
| 166 } | |
| 167 | |
| 168 // As this function contains EXPECT macros, to allow debugging it should be | |
| 169 // called inside EXPECT_SCOPED like so; | |
| 170 // EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler)); | |
| 171 void InitializeOutputSurfaceAndFirstCommit(TestScheduler* scheduler) { | |
| 172 TRACE_EVENT0("cc", | |
| 173 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); | |
| 174 DCHECK(scheduler); | |
| 175 | |
| 176 // Check the client doesn't have any actions queued when calling this | |
| 177 // function. | |
| 178 EXPECT_NO_ACTION((*this)); | |
| 179 EXPECT_FALSE(needs_begin_frames()); | |
| 180 | |
| 181 // Start the initial output surface creation. | |
| 182 EXPECT_FALSE(scheduler->CanStart()); | |
| 183 scheduler->SetCanStart(); | |
| 184 scheduler->SetVisible(true); | |
| 185 scheduler->SetCanDraw(true); | |
| 186 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", (*this)); | |
| 187 Reset(); | |
| 188 | |
| 189 // We don't see anything happening until the first impl frame. | |
| 190 scheduler->DidCreateAndInitializeOutputSurface(); | |
| 191 scheduler->SetNeedsCommit(); | |
| 192 EXPECT_TRUE(needs_begin_frames()); | |
| 193 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
| 194 Reset(); | |
| 195 | |
| 196 { | |
| 197 SCOPED_TRACE("Do first frame to commit after initialize."); | |
| 198 AdvanceFrame(); | |
| 199 | |
| 200 scheduler->NotifyBeginMainFrameStarted(); | |
| 201 scheduler->NotifyReadyToCommitThenActivateIfNeeded(); | |
| 202 | |
| 203 // Run the posted deadline task. | |
| 204 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
| 205 task_runner().RunTasksWhile(ImplFrameDeadlinePending(true)); | |
| 206 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
| 207 | |
| 208 EXPECT_FALSE(scheduler->CommitPending()); | |
| 209 } | |
| 210 | |
| 211 Reset(); | |
| 212 | |
| 213 { | |
| 214 SCOPED_TRACE( | |
| 215 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); | |
| 216 AdvanceFrame(); | |
| 217 | |
| 218 // Run the posted deadline task. | |
| 219 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | |
| 220 task_runner().RunTasksWhile(ImplFrameDeadlinePending(true)); | |
| 221 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
| 222 } | |
| 223 | |
| 224 EXPECT_FALSE(needs_begin_frames()); | |
| 225 Reset(); | |
| 226 } | |
| 227 | |
| 228 // As this function contains EXPECT macros, to allow debugging it should be | |
| 229 // called inside EXPECT_SCOPED like so; | |
| 230 // EXPECT_SCOPED(client.AdvanceFrame()); | |
| 231 void AdvanceFrame() { | |
| 232 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | |
| 233 "FakeSchedulerClient::AdvanceFrame"); | |
| 234 // Consume any previous deadline first, if no deadline is currently | |
| 235 // pending, ImplFrameDeadlinePending will return false straight away and we | |
| 236 // will run no tasks. | |
| 237 task_runner().RunTasksWhile(ImplFrameDeadlinePending(true)); | |
| 238 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 239 | |
| 240 // Send the next BeginFrame message if using an external source, otherwise | |
| 241 // it will be already in the task queue. | |
| 242 if (scheduler_->settings().use_external_begin_frame_source && | |
| 243 scheduler_->FrameProductionThrottled()) { | |
| 244 SendNextBeginFrame(); | |
| 245 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 246 } | |
| 247 | |
| 248 // Then run tasks until new deadline is scheduled. | |
| 249 EXPECT_TRUE(task_runner().RunTasksWhile(ImplFrameDeadlinePending(false))); | |
| 250 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 251 } | |
| 252 | |
| 253 void SendNextBeginFrame() { | |
| 254 DCHECK(scheduler_->settings().use_external_begin_frame_source); | |
| 255 // Creep the time forward so that any BeginFrameArgs is not equal to the | |
| 256 // last one otherwise we violate the BeginFrameSource contract. | |
| 257 now_src_->AdvanceNow(BeginFrameArgs::DefaultInterval()); | |
| 258 fake_external_begin_frame_source_->TestOnBeginFrame( | |
| 259 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src_)); | |
| 260 } | |
| 261 | |
| 262 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } | 85 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } |
| 263 TestNowSource* now_src() { return now_src_.get(); } | 86 TestNowSource* now_src() { return now_src_.get(); } |
| 264 | 87 |
| 265 int ActionIndex(const char* action) const { | 88 int ActionIndex(const char* action) const { |
| 266 for (size_t i = 0; i < actions_.size(); i++) | 89 for (size_t i = 0; i < actions_.size(); i++) |
| 267 if (!strcmp(actions_[i], action)) | 90 if (!strcmp(actions_[i], action)) |
| 268 return i; | 91 return i; |
| 269 return -1; | 92 return -1; |
| 270 } | 93 } |
| 271 | 94 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { | 165 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { |
| 343 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, | 166 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, |
| 344 base::Unretained(this), | 167 base::Unretained(this), |
| 345 state); | 168 state); |
| 346 } | 169 } |
| 347 | 170 |
| 348 bool begin_frame_is_sent_to_children() const { | 171 bool begin_frame_is_sent_to_children() const { |
| 349 return begin_frame_is_sent_to_children_; | 172 return begin_frame_is_sent_to_children_; |
| 350 } | 173 } |
| 351 | 174 |
| 352 protected: | 175 void ExpectAction(const char* action, |
| 353 bool ImplFrameDeadlinePendingCallback(bool state) { | 176 int action_index, |
| 354 return scheduler_->BeginImplFrameDeadlinePending() == state; | 177 int expected_num_actions, |
| 178 const TestScheduler* scheduler) { | |
| 179 EXPECT_EQ(expected_num_actions, num_actions_()); | |
| 180 if (action_index >= 0) { | |
| 181 ASSERT_LT(action_index, num_actions_()) << scheduler; | |
| 182 EXPECT_STREQ(action, Action(action_index)); | |
| 183 } | |
| 184 for (int i = expected_num_actions; i < num_actions_(); ++i) | |
| 185 ADD_FAILURE() << "Unexpected action: " << Action(i) << " with state:\n" | |
| 186 << StateForAction(i); | |
| 355 } | 187 } |
| 356 | 188 |
| 357 void PushAction(const char* description) { | 189 void PushAction(const char* description) { |
|
brianderson
2015/01/27 01:08:25
Does PushAction need to be public now?
Jimmy Jo
2015/01/28 00:53:47
This is placed in FakeSchedulerClient Class but th
| |
| 358 actions_.push_back(description); | 190 actions_.push_back(description); |
| 359 states_.push_back(scheduler_->AsValue()); | 191 states_.push_back(scheduler_->AsValue()); |
| 360 } | 192 } |
| 361 | 193 |
| 194 protected: | |
| 195 bool ImplFrameDeadlinePendingCallback(bool state) { | |
| 196 return scheduler_->BeginImplFrameDeadlinePending() == state; | |
| 197 } | |
| 198 | |
| 362 bool draw_will_happen_; | 199 bool draw_will_happen_; |
| 363 bool swap_will_happen_if_draw_happens_; | 200 bool swap_will_happen_if_draw_happens_; |
| 364 bool automatic_swap_ack_; | 201 bool automatic_swap_ack_; |
| 365 int num_draws_; | 202 int num_draws_; |
| 366 bool log_anticipated_draw_time_change_; | 203 bool log_anticipated_draw_time_change_; |
| 367 bool begin_frame_is_sent_to_children_; | 204 bool begin_frame_is_sent_to_children_; |
| 368 base::TimeTicks posted_begin_impl_frame_deadline_; | 205 base::TimeTicks posted_begin_impl_frame_deadline_; |
| 369 std::vector<const char*> actions_; | 206 std::vector<const char*> actions_; |
| 370 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; | 207 std::vector<scoped_refptr<base::debug::ConvertableToTraceFormat>> states_; |
| 371 scoped_refptr<TestNowSource> now_src_; | 208 scoped_refptr<TestNowSource> now_src_; |
| 372 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 209 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
| 210 TestScheduler* scheduler_; | |
| 211 }; | |
| 212 | |
| 213 class FakePowerMonitorSource : public base::PowerMonitorSource { | |
| 214 public: | |
| 215 FakePowerMonitorSource() {} | |
| 216 ~FakePowerMonitorSource() override {} | |
| 217 void GeneratePowerStateEvent(bool on_battery_power) { | |
| 218 on_battery_power_impl_ = on_battery_power; | |
| 219 ProcessPowerEvent(POWER_STATE_EVENT); | |
| 220 base::MessageLoop::current()->RunUntilIdle(); | |
| 221 } | |
| 222 bool IsOnBatteryPowerImpl() override { return on_battery_power_impl_; } | |
| 223 | |
| 224 private: | |
| 225 bool on_battery_power_impl_; | |
| 226 }; | |
| 227 | |
| 228 class FakeExternalBeginFrameSource : public BeginFrameSourceMixIn { | |
| 229 public: | |
| 230 explicit FakeExternalBeginFrameSource(FakeSchedulerClient* client) | |
| 231 : client_(client) {} | |
| 232 ~FakeExternalBeginFrameSource() override {} | |
| 233 | |
| 234 void OnNeedsBeginFramesChange(bool needs_begin_frames) override { | |
| 235 if (needs_begin_frames) { | |
| 236 client_->PushAction("SetNeedsBeginFrames(true)"); | |
| 237 } else { | |
| 238 client_->PushAction("SetNeedsBeginFrames(false)"); | |
| 239 } | |
| 240 } | |
| 241 | |
| 242 void TestOnBeginFrame(const BeginFrameArgs& args) { | |
| 243 return CallOnBeginFrame(args); | |
| 244 } | |
| 245 | |
| 246 private: | |
| 247 FakeSchedulerClient* client_; | |
| 248 }; | |
| 249 | |
| 250 class SchedulerTest : public testing::Test { | |
| 251 public: | |
| 252 SchedulerTest() | |
| 253 : fake_power_monitor_source_(new FakePowerMonitorSource), | |
| 254 fake_external_begin_frame_source_(nullptr), | |
| 255 power_monitor_(make_scoped_ptr<base::PowerMonitorSource>( | |
| 256 fake_power_monitor_source_)) {} | |
| 257 | |
| 258 ~SchedulerTest() override {} | |
| 259 | |
| 260 protected: | |
| 261 TestScheduler* CreateScheduler() { | |
| 262 scoped_ptr<FakeExternalBeginFrameSource> fake_external_begin_frame_source; | |
| 263 if (scheduler_settings_.use_external_begin_frame_source) { | |
| 264 fake_external_begin_frame_source.reset( | |
| 265 new FakeExternalBeginFrameSource(client_.get())); | |
| 266 fake_external_begin_frame_source_ = | |
| 267 fake_external_begin_frame_source.get(); | |
| 268 } | |
| 269 scheduler_ = TestScheduler::Create( | |
| 270 client_->now_src(), client_.get(), scheduler_settings_, 0, | |
| 271 make_scoped_refptr(&client_->task_runner()), &power_monitor_, | |
| 272 fake_external_begin_frame_source.Pass()); | |
| 273 DCHECK(scheduler_); | |
| 274 client_->set_scheduler(scheduler_.get()); | |
| 275 return scheduler_.get(); | |
| 276 } | |
| 277 | |
| 278 void CreateSchedulerAndInitSurface() { | |
| 279 CreateScheduler(); | |
| 280 EXPECT_SCOPED(InitializeOutputSurfaceAndFirstCommit()); | |
| 281 } | |
| 282 | |
| 283 void SetUpScheduler(bool initSurface) { | |
| 284 SetUpScheduler((new FakeSchedulerClient), initSurface); | |
| 285 } | |
| 286 | |
| 287 void SetUpScheduler(FakeSchedulerClient* client, bool initSurface) { | |
|
brianderson
2015/01/27 01:08:25
Please make the client argument a scoped_ptr so it
| |
| 288 client_.reset(client); | |
| 289 if (initSurface) | |
| 290 CreateSchedulerAndInitSurface(); | |
| 291 else | |
| 292 CreateScheduler(); | |
| 293 } | |
| 294 | |
| 295 // As this function contains EXPECT macros, to allow debugging it should be | |
| 296 // called inside EXPECT_SCOPED like so; | |
| 297 // EXPECT_SCOPED(client.InitializeOutputSurfaceAndFirstCommit(scheduler)); | |
| 298 void InitializeOutputSurfaceAndFirstCommit() { | |
| 299 TRACE_EVENT0("cc", | |
| 300 "SchedulerUnitTest::InitializeOutputSurfaceAndFirstCommit"); | |
| 301 DCHECK(scheduler_); | |
| 302 | |
| 303 // Check the client doesn't have any actions queued when calling this | |
| 304 // function. | |
| 305 EXPECT_NO_ACTION(client_); | |
| 306 EXPECT_FALSE(client_->needs_begin_frames()); | |
| 307 | |
| 308 // Start the initial output surface creation. | |
| 309 EXPECT_FALSE(scheduler_->CanStart()); | |
| 310 scheduler_->SetCanStart(); | |
| 311 scheduler_->SetVisible(true); | |
| 312 scheduler_->SetCanDraw(true); | |
| 313 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); | |
| 314 | |
| 315 client_->Reset(); | |
| 316 | |
| 317 // We don't see anything happening until the first impl frame. | |
| 318 scheduler_->DidCreateAndInitializeOutputSurface(); | |
| 319 scheduler_->SetNeedsCommit(); | |
| 320 EXPECT_TRUE(client_->needs_begin_frames()); | |
| 321 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 322 client_->Reset(); | |
| 323 | |
| 324 { | |
| 325 SCOPED_TRACE("Do first frame to commit after initialize."); | |
| 326 AdvanceFrame(); | |
| 327 | |
| 328 scheduler_->NotifyBeginMainFrameStarted(); | |
| 329 scheduler_->NotifyReadyToCommitThenActivateIfNeeded(); | |
| 330 | |
| 331 // Run the posted deadline task. | |
| 332 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 333 client_->task_runner().RunTasksWhile( | |
| 334 client_->ImplFrameDeadlinePending(true)); | |
| 335 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 336 | |
| 337 EXPECT_FALSE(scheduler_->CommitPending()); | |
| 338 } | |
| 339 | |
| 340 client_->Reset(); | |
| 341 | |
| 342 { | |
| 343 SCOPED_TRACE( | |
| 344 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); | |
| 345 AdvanceFrame(); | |
| 346 | |
| 347 // Run the posted deadline task. | |
| 348 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 349 client_->task_runner().RunTasksWhile( | |
| 350 client_->ImplFrameDeadlinePending(true)); | |
| 351 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 352 } | |
| 353 | |
| 354 EXPECT_FALSE(client_->needs_begin_frames()); | |
| 355 client_->Reset(); | |
| 356 } | |
| 357 | |
| 358 // As this function contains EXPECT macros, to allow debugging it should be | |
| 359 // called inside EXPECT_SCOPED like so; | |
| 360 // EXPECT_SCOPED(client.AdvanceFrame()); | |
| 361 void AdvanceFrame() { | |
| 362 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | |
| 363 "FakeSchedulerClient::AdvanceFrame"); | |
| 364 // Consume any previous deadline first, if no deadline is currently | |
| 365 // pending, ImplFrameDeadlinePending will return false straight away and we | |
| 366 // will run no tasks. | |
| 367 client_->task_runner().RunTasksWhile( | |
| 368 client_->ImplFrameDeadlinePending(true)); | |
| 369 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 370 | |
| 371 // Send the next BeginFrame message if using an external source, otherwise | |
| 372 // it will be already in the task queue. | |
| 373 if (scheduler_->settings().use_external_begin_frame_source && | |
| 374 scheduler_->FrameProductionThrottled()) { | |
| 375 SendNextBeginFrame(); | |
| 376 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 377 } | |
| 378 | |
| 379 // Then run tasks until new deadline is scheduled. | |
| 380 EXPECT_TRUE(client_->task_runner().RunTasksWhile( | |
| 381 client_->ImplFrameDeadlinePending(false))); | |
| 382 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 383 } | |
| 384 | |
| 385 void SendNextBeginFrame() { | |
| 386 DCHECK(scheduler_->settings().use_external_begin_frame_source); | |
| 387 // Creep the time forward so that any BeginFrameArgs is not equal to the | |
| 388 // last one otherwise we violate the BeginFrameSource contract. | |
| 389 client_->now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval()); | |
| 390 fake_external_begin_frame_source_->TestOnBeginFrame( | |
| 391 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, | |
| 392 client_->now_src())); | |
| 393 } | |
| 394 | |
| 395 base::PowerMonitor* PowerMonitor() { return &power_monitor_; } | |
| 396 FakePowerMonitorSource* PowerMonitorSource() { | |
| 397 return fake_power_monitor_source_; | |
| 398 } | |
| 399 | |
| 400 FakeExternalBeginFrameSource* fake_external_begin_frame_source() const { | |
| 401 return fake_external_begin_frame_source_; | |
| 402 } | |
| 403 | |
| 404 void MainFrameInHighLatencyMode( | |
| 405 int64 begin_main_frame_to_commit_estimate_in_ms, | |
| 406 int64 commit_to_activate_estimate_in_ms, | |
| 407 bool impl_latency_takes_priority, | |
| 408 bool should_send_begin_main_frame); | |
| 409 void BeginFramesNotFromClient(bool use_external_begin_frame_source, | |
| 410 bool throttle_frame_production); | |
| 411 void BeginFramesNotFromClient_SwapThrottled( | |
| 412 bool use_external_begin_frame_source, | |
| 413 bool throttle_frame_production); | |
| 414 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( | |
| 415 bool impl_side_painting); | |
| 416 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting); | |
| 417 | |
| 418 FakePowerMonitorSource* fake_power_monitor_source_; | |
| 373 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; | 419 FakeExternalBeginFrameSource* fake_external_begin_frame_source_; |
| 374 FakePowerMonitorSource* fake_power_monitor_source_; | |
| 375 base::PowerMonitor power_monitor_; | 420 base::PowerMonitor power_monitor_; |
| 421 SchedulerSettings scheduler_settings_; | |
| 422 scoped_ptr<FakeSchedulerClient> client_; | |
| 376 scoped_ptr<TestScheduler> scheduler_; | 423 scoped_ptr<TestScheduler> scheduler_; |
| 377 }; | 424 }; |
| 378 | 425 |
| 379 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 426 TEST_F(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
| 380 FakeSchedulerClient client; | 427 scheduler_settings_.use_external_begin_frame_source = true; |
| 381 SchedulerSettings scheduler_settings; | 428 SetUpScheduler(false); |
| 382 scheduler_settings.use_external_begin_frame_source = true; | 429 scheduler_->SetCanStart(); |
| 383 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 430 scheduler_->SetVisible(true); |
| 384 scheduler->SetCanStart(); | 431 scheduler_->SetCanDraw(true); |
| 385 scheduler->SetVisible(true); | 432 |
| 386 scheduler->SetCanDraw(true); | 433 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 387 | 434 client_->Reset(); |
| 388 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 435 scheduler_->DidCreateAndInitializeOutputSurface(); |
| 389 client.Reset(); | 436 EXPECT_NO_ACTION(client_); |
| 390 scheduler->DidCreateAndInitializeOutputSurface(); | 437 } |
| 391 EXPECT_NO_ACTION(client); | 438 |
| 392 } | 439 TEST_F(SchedulerTest, SendBeginFramesToChildren) { |
| 393 | 440 scheduler_settings_.use_external_begin_frame_source = true; |
| 394 TEST(SchedulerTest, SendBeginFramesToChildren) { | 441 scheduler_settings_.forward_begin_frames_to_children = true; |
| 395 FakeSchedulerClient client; | 442 SetUpScheduler(true); |
| 396 SchedulerSettings scheduler_settings; | 443 |
| 397 scheduler_settings.use_external_begin_frame_source = true; | 444 EXPECT_FALSE(client_->begin_frame_is_sent_to_children()); |
| 398 scheduler_settings.forward_begin_frames_to_children = true; | 445 scheduler_->SetNeedsCommit(); |
| 399 | 446 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 400 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 447 EXPECT_TRUE(client_->needs_begin_frames()); |
| 401 | 448 |
| 402 EXPECT_FALSE(client.begin_frame_is_sent_to_children()); | 449 scheduler_->SetChildrenNeedBeginFrames(true); |
| 403 scheduler->SetNeedsCommit(); | 450 |
| 404 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 451 client_->Reset(); |
| 405 EXPECT_TRUE(client.needs_begin_frames()); | 452 EXPECT_SCOPED(AdvanceFrame()); |
| 406 | 453 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); |
| 407 scheduler->SetChildrenNeedBeginFrames(true); | 454 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 408 | 455 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 409 client.Reset(); | 456 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 410 EXPECT_SCOPED(client.AdvanceFrame()); | 457 EXPECT_TRUE(client_->needs_begin_frames()); |
| 411 EXPECT_TRUE(client.begin_frame_is_sent_to_children()); | 458 } |
| 412 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 459 |
| 413 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 460 TEST_F(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { |
| 414 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 461 scheduler_settings_.use_external_begin_frame_source = true; |
| 415 EXPECT_TRUE(client.needs_begin_frames()); | 462 scheduler_settings_.forward_begin_frames_to_children = true; |
| 416 } | 463 SetUpScheduler(true); |
| 417 | 464 |
| 418 TEST(SchedulerTest, SendBeginFramesToChildrenWithoutCommit) { | 465 EXPECT_FALSE(client_->needs_begin_frames()); |
| 419 FakeSchedulerClient client; | 466 scheduler_->SetChildrenNeedBeginFrames(true); |
| 420 SchedulerSettings scheduler_settings; | 467 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 421 scheduler_settings.use_external_begin_frame_source = true; | 468 EXPECT_TRUE(client_->needs_begin_frames()); |
| 422 scheduler_settings.forward_begin_frames_to_children = true; | 469 |
| 423 | 470 client_->Reset(); |
| 424 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 471 EXPECT_SCOPED(AdvanceFrame()); |
| 425 | 472 EXPECT_TRUE(client_->begin_frame_is_sent_to_children()); |
| 426 EXPECT_FALSE(client.needs_begin_frames()); | 473 } |
| 427 scheduler->SetChildrenNeedBeginFrames(true); | 474 |
| 428 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 475 TEST_F(SchedulerTest, RequestCommit) { |
| 429 EXPECT_TRUE(client.needs_begin_frames()); | 476 scheduler_settings_.use_external_begin_frame_source = true; |
| 430 | 477 SetUpScheduler(true); |
| 431 client.Reset(); | |
| 432 EXPECT_SCOPED(client.AdvanceFrame()); | |
| 433 EXPECT_TRUE(client.begin_frame_is_sent_to_children()); | |
| 434 } | |
| 435 | |
| 436 TEST(SchedulerTest, RequestCommit) { | |
| 437 FakeSchedulerClient client; | |
| 438 SchedulerSettings scheduler_settings; | |
| 439 scheduler_settings.use_external_begin_frame_source = true; | |
| 440 | |
| 441 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 442 | 478 |
| 443 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 479 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 444 scheduler->SetNeedsCommit(); | 480 scheduler_->SetNeedsCommit(); |
| 445 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 481 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 446 client.Reset(); | 482 client_->Reset(); |
| 447 | 483 |
| 448 EXPECT_SCOPED(client.AdvanceFrame()); | 484 EXPECT_SCOPED(AdvanceFrame()); |
| 449 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 485 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 450 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 486 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 451 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 487 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 452 EXPECT_TRUE(client.needs_begin_frames()); | 488 EXPECT_TRUE(client_->needs_begin_frames()); |
| 453 client.Reset(); | 489 client_->Reset(); |
| 454 | 490 |
| 455 // If we don't swap on the deadline, we wait for the next BeginFrame. | 491 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 456 client.task_runner().RunPendingTasks(); // Run posted deadline. | 492 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 457 EXPECT_NO_ACTION(client); | 493 EXPECT_NO_ACTION(client_); |
| 458 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 494 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 459 EXPECT_TRUE(client.needs_begin_frames()); | 495 EXPECT_TRUE(client_->needs_begin_frames()); |
| 460 client.Reset(); | 496 client_->Reset(); |
| 461 | 497 |
| 462 // NotifyReadyToCommit should trigger the commit. | 498 // NotifyReadyToCommit should trigger the commit. |
| 463 scheduler->NotifyBeginMainFrameStarted(); | 499 scheduler_->NotifyBeginMainFrameStarted(); |
| 464 scheduler->NotifyReadyToCommit(); | 500 scheduler_->NotifyReadyToCommit(); |
| 465 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 501 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 466 EXPECT_TRUE(client.needs_begin_frames()); | 502 EXPECT_TRUE(client_->needs_begin_frames()); |
| 467 client.Reset(); | 503 client_->Reset(); |
| 468 | 504 |
| 469 // BeginImplFrame should prepare the draw. | 505 // BeginImplFrame should prepare the draw. |
| 470 EXPECT_SCOPED(client.AdvanceFrame()); | 506 EXPECT_SCOPED(AdvanceFrame()); |
| 471 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 507 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 472 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 508 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 473 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 509 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 474 EXPECT_TRUE(client.needs_begin_frames()); | 510 EXPECT_TRUE(client_->needs_begin_frames()); |
| 475 client.Reset(); | 511 client_->Reset(); |
| 476 | 512 |
| 477 // BeginImplFrame deadline should draw. | 513 // BeginImplFrame deadline should draw. |
| 478 client.task_runner().RunPendingTasks(); // Run posted deadline. | 514 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 479 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 515 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 480 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 516 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 481 EXPECT_TRUE(client.needs_begin_frames()); | 517 EXPECT_TRUE(client_->needs_begin_frames()); |
| 482 client.Reset(); | 518 client_->Reset(); |
| 483 | 519 |
| 484 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 520 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 485 // to avoid excessive toggles. | 521 // to avoid excessive toggles. |
| 486 EXPECT_SCOPED(client.AdvanceFrame()); | 522 EXPECT_SCOPED(AdvanceFrame()); |
| 487 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 523 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 488 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 524 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 489 client.Reset(); | 525 client_->Reset(); |
| 490 | 526 |
| 491 client.task_runner().RunPendingTasks(); // Run posted deadline. | 527 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 492 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 528 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 493 client.Reset(); | 529 client_->Reset(); |
| 494 } | 530 } |
| 495 | 531 |
| 496 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 532 TEST_F(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| 497 FakeSchedulerClient client; | 533 scheduler_settings_.use_external_begin_frame_source = true; |
| 498 SchedulerSettings scheduler_settings; | 534 SetUpScheduler(true); |
| 499 scheduler_settings.use_external_begin_frame_source = true; | |
| 500 | |
| 501 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 502 | 535 |
| 503 // SetNeedsCommit should begin the frame. | 536 // SetNeedsCommit should begin the frame. |
| 504 scheduler->SetNeedsCommit(); | 537 scheduler_->SetNeedsCommit(); |
| 505 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 538 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 506 | 539 |
| 507 client.Reset(); | 540 client_->Reset(); |
| 508 EXPECT_SCOPED(client.AdvanceFrame()); | 541 EXPECT_SCOPED(AdvanceFrame()); |
| 509 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 542 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 510 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 543 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 511 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 544 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 512 | 545 |
| 513 EXPECT_TRUE(client.needs_begin_frames()); | 546 EXPECT_TRUE(client_->needs_begin_frames()); |
| 514 client.Reset(); | 547 client_->Reset(); |
| 515 | 548 |
| 516 // Now SetNeedsCommit again. Calling here means we need a second commit. | 549 // Now SetNeedsCommit again. Calling here means we need a second commit. |
| 517 scheduler->SetNeedsCommit(); | 550 scheduler_->SetNeedsCommit(); |
| 518 EXPECT_EQ(client.num_actions_(), 0); | 551 EXPECT_EQ(client_->num_actions_(), 0); |
| 519 client.Reset(); | 552 client_->Reset(); |
| 520 | 553 |
| 521 // Finish the first commit. | 554 // Finish the first commit. |
| 522 scheduler->NotifyBeginMainFrameStarted(); | 555 scheduler_->NotifyBeginMainFrameStarted(); |
| 523 scheduler->NotifyReadyToCommit(); | 556 scheduler_->NotifyReadyToCommit(); |
| 524 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 557 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 525 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 558 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 526 client.Reset(); | 559 client_->Reset(); |
| 527 client.task_runner().RunPendingTasks(); // Run posted deadline. | 560 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 528 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 561 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 529 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 562 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 530 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 563 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 531 | 564 |
| 532 // Because we just swapped, the Scheduler should also request the next | 565 // Because we just swapped, the Scheduler should also request the next |
| 533 // BeginImplFrame from the OutputSurface. | 566 // BeginImplFrame from the OutputSurface. |
| 534 EXPECT_TRUE(client.needs_begin_frames()); | 567 EXPECT_TRUE(client_->needs_begin_frames()); |
| 535 client.Reset(); | 568 client_->Reset(); |
| 536 // Since another commit is needed, the next BeginImplFrame should initiate | 569 // Since another commit is needed, the next BeginImplFrame should initiate |
| 537 // the second commit. | 570 // the second commit. |
| 538 EXPECT_SCOPED(client.AdvanceFrame()); | 571 EXPECT_SCOPED(AdvanceFrame()); |
| 539 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 572 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 540 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 573 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 541 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 574 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 542 client.Reset(); | 575 client_->Reset(); |
| 543 | 576 |
| 544 // Finishing the commit before the deadline should post a new deadline task | 577 // Finishing the commit before the deadline should post a new deadline task |
| 545 // to trigger the deadline early. | 578 // to trigger the deadline early. |
| 546 scheduler->NotifyBeginMainFrameStarted(); | 579 scheduler_->NotifyBeginMainFrameStarted(); |
| 547 scheduler->NotifyReadyToCommit(); | 580 scheduler_->NotifyReadyToCommit(); |
| 548 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 581 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 549 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 582 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 550 client.Reset(); | 583 client_->Reset(); |
| 551 client.task_runner().RunPendingTasks(); // Run posted deadline. | 584 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 552 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 585 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 553 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 586 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 554 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 587 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 555 EXPECT_TRUE(client.needs_begin_frames()); | 588 EXPECT_TRUE(client_->needs_begin_frames()); |
| 556 client.Reset(); | 589 client_->Reset(); |
| 557 | 590 |
| 558 // On the next BeginImplFrame, verify we go back to a quiescent state and | 591 // On the next BeginImplFrame, verify we go back to a quiescent state and |
| 559 // no longer request BeginImplFrames. | 592 // no longer request BeginImplFrames. |
| 560 EXPECT_SCOPED(client.AdvanceFrame()); | 593 EXPECT_SCOPED(AdvanceFrame()); |
| 561 client.task_runner().RunPendingTasks(); // Run posted deadline. | 594 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 562 EXPECT_FALSE(client.needs_begin_frames()); | 595 EXPECT_FALSE(client_->needs_begin_frames()); |
| 563 client.Reset(); | 596 client_->Reset(); |
| 564 } | 597 } |
| 565 | 598 |
| 566 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 599 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 567 public: | 600 public: |
| 568 SchedulerClientThatsetNeedsDrawInsideDraw() | 601 SchedulerClientThatsetNeedsDrawInsideDraw() |
| 569 : FakeSchedulerClient(), request_redraws_(false) {} | 602 : FakeSchedulerClient(), request_redraws_(false) {} |
| 570 | 603 |
| 571 void ScheduledActionSendBeginMainFrame() override {} | 604 void ScheduledActionSendBeginMainFrame() override {} |
| 572 | 605 |
| 573 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } | 606 void SetRequestRedrawsInsideDraw(bool enable) { request_redraws_ = enable; } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 589 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} | 622 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} |
| 590 | 623 |
| 591 private: | 624 private: |
| 592 bool request_redraws_; | 625 bool request_redraws_; |
| 593 }; | 626 }; |
| 594 | 627 |
| 595 // Tests for two different situations: | 628 // Tests for two different situations: |
| 596 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside | 629 // 1. the scheduler dropping SetNeedsRedraw requests that happen inside |
| 597 // a ScheduledActionDrawAndSwap | 630 // a ScheduledActionDrawAndSwap |
| 598 // 2. the scheduler drawing twice inside a single tick | 631 // 2. the scheduler drawing twice inside a single tick |
| 599 TEST(SchedulerTest, RequestRedrawInsideDraw) { | 632 TEST_F(SchedulerTest, RequestRedrawInsideDraw) { |
| 600 SchedulerClientThatsetNeedsDrawInsideDraw client; | 633 SchedulerClientThatsetNeedsDrawInsideDraw* client = |
| 601 SchedulerSettings scheduler_settings; | 634 new SchedulerClientThatsetNeedsDrawInsideDraw; |
| 602 scheduler_settings.use_external_begin_frame_source = true; | 635 scheduler_settings_.use_external_begin_frame_source = true; |
| 636 SetUpScheduler(client, true); | |
|
Jimmy Jo
2015/01/28 00:53:47
when I make SetUpScheduler 1st arugment a scoped_p
brianderson
2015/01/28 01:09:14
Does casting the argument inline work?
If not, you
| |
| 637 client->SetRequestRedrawsInsideDraw(true); | |
| 603 | 638 |
| 604 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 639 scheduler_->SetNeedsRedraw(); |
| 605 client.SetRequestRedrawsInsideDraw(true); | 640 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 641 EXPECT_TRUE(client->needs_begin_frames()); | |
| 642 EXPECT_EQ(0, client->num_draws()); | |
| 606 | 643 |
| 607 scheduler->SetNeedsRedraw(); | 644 EXPECT_SCOPED(AdvanceFrame()); |
| 608 EXPECT_TRUE(scheduler->RedrawPending()); | 645 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 609 EXPECT_TRUE(client.needs_begin_frames()); | 646 EXPECT_EQ(1, client->num_draws()); |
| 610 EXPECT_EQ(0, client.num_draws()); | 647 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 648 EXPECT_TRUE(client->needs_begin_frames()); | |
| 611 | 649 |
| 612 EXPECT_SCOPED(client.AdvanceFrame()); | 650 client->SetRequestRedrawsInsideDraw(false); |
| 613 client.task_runner().RunPendingTasks(); // Run posted deadline. | |
| 614 EXPECT_EQ(1, client.num_draws()); | |
| 615 EXPECT_TRUE(scheduler->RedrawPending()); | |
| 616 EXPECT_TRUE(client.needs_begin_frames()); | |
| 617 | 651 |
| 618 client.SetRequestRedrawsInsideDraw(false); | 652 EXPECT_SCOPED(AdvanceFrame()); |
| 619 | 653 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 620 EXPECT_SCOPED(client.AdvanceFrame()); | 654 EXPECT_EQ(2, client_->num_draws()); |
| 621 client.task_runner().RunPendingTasks(); // Run posted deadline. | 655 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 622 EXPECT_EQ(2, client.num_draws()); | 656 EXPECT_TRUE(client->needs_begin_frames()); |
| 623 EXPECT_FALSE(scheduler->RedrawPending()); | |
| 624 EXPECT_TRUE(client.needs_begin_frames()); | |
| 625 | 657 |
| 626 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 658 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| 627 // swap. | 659 // swap. |
| 628 EXPECT_SCOPED(client.AdvanceFrame()); | 660 EXPECT_SCOPED(AdvanceFrame()); |
| 629 client.task_runner().RunPendingTasks(); // Run posted deadline. | 661 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 630 EXPECT_EQ(2, client.num_draws()); | 662 EXPECT_EQ(2, client->num_draws()); |
| 631 EXPECT_FALSE(scheduler->RedrawPending()); | 663 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 632 EXPECT_FALSE(client.needs_begin_frames()); | 664 EXPECT_FALSE(client->needs_begin_frames()); |
| 633 } | 665 } |
| 634 | 666 |
| 635 // Test that requesting redraw inside a failed draw doesn't lose the request. | 667 // Test that requesting redraw inside a failed draw doesn't lose the request. |
| 636 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 668 TEST_F(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| 637 SchedulerClientThatsetNeedsDrawInsideDraw client; | 669 SchedulerClientThatsetNeedsDrawInsideDraw* client = |
| 638 SchedulerSettings scheduler_settings; | 670 new SchedulerClientThatsetNeedsDrawInsideDraw; |
| 639 scheduler_settings.use_external_begin_frame_source = true; | 671 scheduler_settings_.use_external_begin_frame_source = true; |
| 672 SetUpScheduler(client, true); | |
| 640 | 673 |
| 641 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 674 client->SetRequestRedrawsInsideDraw(true); |
| 642 client.SetRequestRedrawsInsideDraw(true); | 675 client->SetDrawWillHappen(false); |
| 643 client.SetDrawWillHappen(false); | |
| 644 | 676 |
| 645 scheduler->SetNeedsRedraw(); | 677 scheduler_->SetNeedsRedraw(); |
| 646 EXPECT_TRUE(scheduler->RedrawPending()); | 678 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 647 EXPECT_TRUE(client.needs_begin_frames()); | 679 EXPECT_TRUE(client->needs_begin_frames()); |
| 648 EXPECT_EQ(0, client.num_draws()); | 680 EXPECT_EQ(0, client->num_draws()); |
| 649 | 681 |
| 650 // Fail the draw. | 682 // Fail the draw. |
| 651 EXPECT_SCOPED(client.AdvanceFrame()); | 683 EXPECT_SCOPED(AdvanceFrame()); |
| 652 client.task_runner().RunPendingTasks(); // Run posted deadline. | 684 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 653 EXPECT_EQ(1, client.num_draws()); | 685 EXPECT_EQ(1, client->num_draws()); |
| 654 | 686 |
| 655 // We have a commit pending and the draw failed, and we didn't lose the redraw | 687 // We have a commit pending and the draw failed, and we didn't lose the redraw |
| 656 // request. | 688 // request. |
| 657 EXPECT_TRUE(scheduler->CommitPending()); | 689 EXPECT_TRUE(scheduler_->CommitPending()); |
| 658 EXPECT_TRUE(scheduler->RedrawPending()); | 690 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 659 EXPECT_TRUE(client.needs_begin_frames()); | 691 EXPECT_TRUE(client->needs_begin_frames()); |
| 660 | 692 |
| 661 client.SetRequestRedrawsInsideDraw(false); | 693 client->SetRequestRedrawsInsideDraw(false); |
| 662 | 694 |
| 663 // Fail the draw again. | 695 // Fail the draw again. |
| 664 EXPECT_SCOPED(client.AdvanceFrame()); | 696 EXPECT_SCOPED(AdvanceFrame()); |
| 665 client.task_runner().RunPendingTasks(); // Run posted deadline. | 697 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 666 EXPECT_EQ(2, client.num_draws()); | 698 EXPECT_EQ(2, client->num_draws()); |
| 667 EXPECT_TRUE(scheduler->CommitPending()); | 699 EXPECT_TRUE(scheduler_->CommitPending()); |
| 668 EXPECT_TRUE(scheduler->RedrawPending()); | 700 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 669 EXPECT_TRUE(client.needs_begin_frames()); | 701 EXPECT_TRUE(client->needs_begin_frames()); |
| 670 | 702 |
| 671 // Draw successfully. | 703 // Draw successfully. |
| 672 client.SetDrawWillHappen(true); | 704 client->SetDrawWillHappen(true); |
| 673 EXPECT_SCOPED(client.AdvanceFrame()); | 705 EXPECT_SCOPED(AdvanceFrame()); |
| 674 client.task_runner().RunPendingTasks(); // Run posted deadline. | 706 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 675 EXPECT_EQ(3, client.num_draws()); | 707 EXPECT_EQ(3, client->num_draws()); |
| 676 EXPECT_TRUE(scheduler->CommitPending()); | 708 EXPECT_TRUE(scheduler_->CommitPending()); |
| 677 EXPECT_FALSE(scheduler->RedrawPending()); | 709 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 678 EXPECT_TRUE(client.needs_begin_frames()); | 710 EXPECT_TRUE(client->needs_begin_frames()); |
| 679 } | 711 } |
| 680 | 712 |
| 681 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 713 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
| 682 public: | 714 public: |
| 683 SchedulerClientThatSetNeedsCommitInsideDraw() | 715 SchedulerClientThatSetNeedsCommitInsideDraw() |
| 684 : set_needs_commit_on_next_draw_(false) {} | 716 : set_needs_commit_on_next_draw_(false) {} |
| 685 | 717 |
| 686 void ScheduledActionSendBeginMainFrame() override {} | 718 void ScheduledActionSendBeginMainFrame() override {} |
| 687 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 719 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
| 688 // Only SetNeedsCommit the first time this is called | 720 // Only SetNeedsCommit the first time this is called |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 702 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} | 734 void DidAnticipatedDrawTimeChange(base::TimeTicks) override {} |
| 703 | 735 |
| 704 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } | 736 void SetNeedsCommitOnNextDraw() { set_needs_commit_on_next_draw_ = true; } |
| 705 | 737 |
| 706 private: | 738 private: |
| 707 bool set_needs_commit_on_next_draw_; | 739 bool set_needs_commit_on_next_draw_; |
| 708 }; | 740 }; |
| 709 | 741 |
| 710 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that | 742 // Tests for the scheduler infinite-looping on SetNeedsCommit requests that |
| 711 // happen inside a ScheduledActionDrawAndSwap | 743 // happen inside a ScheduledActionDrawAndSwap |
| 712 TEST(SchedulerTest, RequestCommitInsideDraw) { | 744 TEST_F(SchedulerTest, RequestCommitInsideDraw) { |
| 713 SchedulerClientThatSetNeedsCommitInsideDraw client; | 745 SchedulerClientThatSetNeedsCommitInsideDraw* client = |
| 714 SchedulerSettings scheduler_settings; | 746 new SchedulerClientThatSetNeedsCommitInsideDraw; |
| 715 scheduler_settings.use_external_begin_frame_source = true; | |
| 716 | 747 |
| 717 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 748 scheduler_settings_.use_external_begin_frame_source = true; |
| 749 SetUpScheduler(client, true); | |
| 718 | 750 |
| 719 EXPECT_FALSE(client.needs_begin_frames()); | 751 EXPECT_FALSE(client->needs_begin_frames()); |
| 720 scheduler->SetNeedsRedraw(); | 752 scheduler_->SetNeedsRedraw(); |
| 721 EXPECT_TRUE(scheduler->RedrawPending()); | 753 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 722 EXPECT_EQ(0, client.num_draws()); | 754 EXPECT_EQ(0, client->num_draws()); |
| 723 EXPECT_TRUE(client.needs_begin_frames()); | 755 EXPECT_TRUE(client->needs_begin_frames()); |
| 724 | 756 |
| 725 client.SetNeedsCommitOnNextDraw(); | 757 client->SetNeedsCommitOnNextDraw(); |
| 726 EXPECT_SCOPED(client.AdvanceFrame()); | 758 EXPECT_SCOPED(AdvanceFrame()); |
| 727 client.SetNeedsCommitOnNextDraw(); | 759 client->SetNeedsCommitOnNextDraw(); |
| 728 client.task_runner().RunPendingTasks(); // Run posted deadline. | 760 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 729 EXPECT_EQ(1, client.num_draws()); | 761 EXPECT_EQ(1, client->num_draws()); |
| 730 EXPECT_TRUE(scheduler->CommitPending()); | 762 EXPECT_TRUE(scheduler_->CommitPending()); |
| 731 EXPECT_TRUE(client.needs_begin_frames()); | 763 EXPECT_TRUE(client->needs_begin_frames()); |
| 732 scheduler->NotifyBeginMainFrameStarted(); | 764 scheduler_->NotifyBeginMainFrameStarted(); |
| 733 scheduler->NotifyReadyToCommit(); | 765 scheduler_->NotifyReadyToCommit(); |
| 734 | 766 |
| 735 EXPECT_SCOPED(client.AdvanceFrame()); | 767 EXPECT_SCOPED(AdvanceFrame()); |
| 736 client.task_runner().RunPendingTasks(); // Run posted deadline. | 768 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 737 EXPECT_EQ(2, client.num_draws()); | 769 EXPECT_EQ(2, client->num_draws()); |
| 738 | 770 |
| 739 EXPECT_FALSE(scheduler->RedrawPending()); | 771 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 740 EXPECT_FALSE(scheduler->CommitPending()); | 772 EXPECT_FALSE(scheduler_->CommitPending()); |
| 741 EXPECT_TRUE(client.needs_begin_frames()); | 773 EXPECT_TRUE(client->needs_begin_frames()); |
| 742 | 774 |
| 743 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 775 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| 744 // swap. | 776 // swap. |
| 745 EXPECT_SCOPED(client.AdvanceFrame()); | 777 EXPECT_SCOPED(AdvanceFrame()); |
| 746 client.task_runner().RunPendingTasks(); // Run posted deadline. | 778 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 747 EXPECT_EQ(2, client.num_draws()); | 779 EXPECT_EQ(2, client->num_draws()); |
| 748 EXPECT_FALSE(scheduler->RedrawPending()); | 780 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 749 EXPECT_FALSE(scheduler->CommitPending()); | 781 EXPECT_FALSE(scheduler_->CommitPending()); |
| 750 EXPECT_FALSE(client.needs_begin_frames()); | 782 EXPECT_FALSE(client->needs_begin_frames()); |
| 751 } | 783 } |
| 752 | 784 |
| 753 // Tests that when a draw fails then the pending commit should not be dropped. | 785 // Tests that when a draw fails then the pending commit should not be dropped. |
| 754 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 786 TEST_F(SchedulerTest, RequestCommitInsideFailedDraw) { |
| 755 SchedulerClientThatsetNeedsDrawInsideDraw client; | 787 SchedulerClientThatsetNeedsDrawInsideDraw* client = |
| 756 SchedulerSettings scheduler_settings; | 788 new SchedulerClientThatsetNeedsDrawInsideDraw; |
| 757 scheduler_settings.use_external_begin_frame_source = true; | 789 scheduler_settings_.use_external_begin_frame_source = true; |
| 790 SetUpScheduler(client, true); | |
| 758 | 791 |
| 759 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 792 client->SetDrawWillHappen(false); |
| 760 | 793 |
| 761 client.SetDrawWillHappen(false); | 794 scheduler_->SetNeedsRedraw(); |
| 762 | 795 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 763 scheduler->SetNeedsRedraw(); | 796 EXPECT_TRUE(client->needs_begin_frames()); |
| 764 EXPECT_TRUE(scheduler->RedrawPending()); | 797 EXPECT_EQ(0, client->num_draws()); |
| 765 EXPECT_TRUE(client.needs_begin_frames()); | |
| 766 EXPECT_EQ(0, client.num_draws()); | |
| 767 | 798 |
| 768 // Fail the draw. | 799 // Fail the draw. |
| 769 EXPECT_SCOPED(client.AdvanceFrame()); | 800 EXPECT_SCOPED(AdvanceFrame()); |
| 770 client.task_runner().RunPendingTasks(); // Run posted deadline. | 801 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 771 EXPECT_EQ(1, client.num_draws()); | 802 EXPECT_EQ(1, client->num_draws()); |
| 772 | 803 |
| 773 // We have a commit pending and the draw failed, and we didn't lose the commit | 804 // We have a commit pending and the draw failed, and we didn't lose the commit |
| 774 // request. | 805 // request. |
| 775 EXPECT_TRUE(scheduler->CommitPending()); | 806 EXPECT_TRUE(scheduler_->CommitPending()); |
| 776 EXPECT_TRUE(scheduler->RedrawPending()); | 807 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 777 EXPECT_TRUE(client.needs_begin_frames()); | 808 EXPECT_TRUE(client->needs_begin_frames()); |
| 778 | 809 |
| 779 // Fail the draw again. | 810 // Fail the draw again. |
| 780 EXPECT_SCOPED(client.AdvanceFrame()); | 811 EXPECT_SCOPED(AdvanceFrame()); |
| 781 | 812 |
| 782 client.task_runner().RunPendingTasks(); // Run posted deadline. | 813 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 783 EXPECT_EQ(2, client.num_draws()); | 814 EXPECT_EQ(2, client->num_draws()); |
| 784 EXPECT_TRUE(scheduler->CommitPending()); | 815 EXPECT_TRUE(scheduler_->CommitPending()); |
| 785 EXPECT_TRUE(scheduler->RedrawPending()); | 816 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 786 EXPECT_TRUE(client.needs_begin_frames()); | 817 EXPECT_TRUE(client->needs_begin_frames()); |
| 787 | 818 |
| 788 // Draw successfully. | 819 // Draw successfully. |
| 789 client.SetDrawWillHappen(true); | 820 client->SetDrawWillHappen(true); |
| 790 EXPECT_SCOPED(client.AdvanceFrame()); | 821 EXPECT_SCOPED(AdvanceFrame()); |
| 791 client.task_runner().RunPendingTasks(); // Run posted deadline. | 822 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 792 EXPECT_EQ(3, client.num_draws()); | 823 EXPECT_EQ(3, client->num_draws()); |
| 793 EXPECT_TRUE(scheduler->CommitPending()); | 824 EXPECT_TRUE(scheduler_->CommitPending()); |
| 794 EXPECT_FALSE(scheduler->RedrawPending()); | 825 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 795 EXPECT_TRUE(client.needs_begin_frames()); | 826 EXPECT_TRUE(client->needs_begin_frames()); |
| 796 } | 827 } |
| 797 | 828 |
| 798 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 829 TEST_F(SchedulerTest, NoSwapWhenDrawFails) { |
| 799 SchedulerClientThatSetNeedsCommitInsideDraw client; | 830 SchedulerClientThatSetNeedsCommitInsideDraw* client = |
| 800 SchedulerSettings scheduler_settings; | 831 new SchedulerClientThatSetNeedsCommitInsideDraw; |
| 801 scheduler_settings.use_external_begin_frame_source = true; | 832 scheduler_settings_.use_external_begin_frame_source = true; |
| 833 SetUpScheduler(client, true); | |
| 802 | 834 |
| 803 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 835 scheduler_->SetNeedsRedraw(); |
| 804 | 836 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 805 scheduler->SetNeedsRedraw(); | 837 EXPECT_TRUE(client->needs_begin_frames()); |
| 806 EXPECT_TRUE(scheduler->RedrawPending()); | 838 EXPECT_EQ(0, client->num_draws()); |
| 807 EXPECT_TRUE(client.needs_begin_frames()); | |
| 808 EXPECT_EQ(0, client.num_draws()); | |
| 809 | 839 |
| 810 // Draw successfully, this starts a new frame. | 840 // Draw successfully, this starts a new frame. |
| 811 client.SetNeedsCommitOnNextDraw(); | 841 client->SetNeedsCommitOnNextDraw(); |
| 812 EXPECT_SCOPED(client.AdvanceFrame()); | 842 EXPECT_SCOPED(AdvanceFrame()); |
| 813 client.task_runner().RunPendingTasks(); // Run posted deadline. | 843 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 814 EXPECT_EQ(1, client.num_draws()); | 844 EXPECT_EQ(1, client->num_draws()); |
| 815 | 845 |
| 816 scheduler->SetNeedsRedraw(); | 846 scheduler_->SetNeedsRedraw(); |
| 817 EXPECT_TRUE(scheduler->RedrawPending()); | 847 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 818 EXPECT_TRUE(client.needs_begin_frames()); | 848 EXPECT_TRUE(client->needs_begin_frames()); |
| 819 | 849 |
| 820 // Fail to draw, this should not start a frame. | 850 // Fail to draw, this should not start a frame. |
| 821 client.SetDrawWillHappen(false); | 851 client->SetDrawWillHappen(false); |
| 822 client.SetNeedsCommitOnNextDraw(); | 852 client->SetNeedsCommitOnNextDraw(); |
| 823 EXPECT_SCOPED(client.AdvanceFrame()); | 853 EXPECT_SCOPED(AdvanceFrame()); |
| 824 client.task_runner().RunPendingTasks(); // Run posted deadline. | 854 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 825 EXPECT_EQ(2, client.num_draws()); | 855 EXPECT_EQ(2, client->num_draws()); |
| 826 } | 856 } |
| 827 | 857 |
| 828 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { | 858 class SchedulerClientNeedsPrepareTilesInDraw : public FakeSchedulerClient { |
| 829 public: | 859 public: |
| 830 DrawResult ScheduledActionDrawAndSwapIfPossible() override { | 860 DrawResult ScheduledActionDrawAndSwapIfPossible() override { |
| 831 scheduler_->SetNeedsPrepareTiles(); | 861 scheduler_->SetNeedsPrepareTiles(); |
| 832 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 862 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| 833 } | 863 } |
| 834 }; | 864 }; |
| 835 | 865 |
| 836 // Test prepare tiles is independant of draws. | 866 // Test prepare tiles is independant of draws. |
| 837 TEST(SchedulerTest, PrepareTiles) { | 867 TEST_F(SchedulerTest, PrepareTiles) { |
| 838 SchedulerClientNeedsPrepareTilesInDraw client; | 868 SchedulerClientNeedsPrepareTilesInDraw* client = |
| 839 SchedulerSettings scheduler_settings; | 869 new SchedulerClientNeedsPrepareTilesInDraw; |
| 840 scheduler_settings.use_external_begin_frame_source = true; | 870 scheduler_settings_.use_external_begin_frame_source = true; |
| 841 | 871 SetUpScheduler(client, true); |
| 842 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 843 | 872 |
| 844 // Request both draw and prepare tiles. PrepareTiles shouldn't | 873 // Request both draw and prepare tiles. PrepareTiles shouldn't |
| 845 // be trigged until BeginImplFrame. | 874 // be trigged until BeginImplFrame. |
| 846 client.Reset(); | 875 client->Reset(); |
| 847 scheduler->SetNeedsPrepareTiles(); | 876 scheduler_->SetNeedsPrepareTiles(); |
| 848 scheduler->SetNeedsRedraw(); | 877 scheduler_->SetNeedsRedraw(); |
| 849 EXPECT_TRUE(scheduler->RedrawPending()); | 878 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 850 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 879 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 851 EXPECT_TRUE(client.needs_begin_frames()); | 880 EXPECT_TRUE(client->needs_begin_frames()); |
| 852 EXPECT_EQ(0, client.num_draws()); | 881 EXPECT_EQ(0, client->num_draws()); |
| 853 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 882 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles")); |
| 854 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 883 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 855 | 884 |
| 856 // We have no immediate actions to perform, so the BeginImplFrame should post | 885 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 857 // the deadline task. | 886 // the deadline task. |
| 858 client.Reset(); | 887 client->Reset(); |
| 859 EXPECT_SCOPED(client.AdvanceFrame()); | 888 EXPECT_SCOPED(AdvanceFrame()); |
| 860 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 889 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 861 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 890 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 862 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 891 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 863 | 892 |
| 864 // On the deadline, he actions should have occured in the right order. | 893 // On the deadline, he actions should have occured in the right order. |
| 865 client.Reset(); | 894 client->Reset(); |
| 866 client.task_runner().RunPendingTasks(); // Run posted deadline. | 895 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 867 EXPECT_EQ(1, client.num_draws()); | 896 EXPECT_EQ(1, client->num_draws()); |
| 868 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 897 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 869 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 898 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 870 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 899 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 871 client.ActionIndex("ScheduledActionPrepareTiles")); | 900 client->ActionIndex("ScheduledActionPrepareTiles")); |
| 872 EXPECT_FALSE(scheduler->RedrawPending()); | 901 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 873 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 902 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 874 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 903 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 875 | 904 |
| 876 // Request a draw. We don't need a PrepareTiles yet. | 905 // Request a draw. We don't need a PrepareTiles yet. |
| 877 client.Reset(); | 906 client->Reset(); |
| 878 scheduler->SetNeedsRedraw(); | 907 scheduler_->SetNeedsRedraw(); |
| 879 EXPECT_TRUE(scheduler->RedrawPending()); | 908 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 880 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 909 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 881 EXPECT_TRUE(client.needs_begin_frames()); | 910 EXPECT_TRUE(client->needs_begin_frames()); |
| 882 EXPECT_EQ(0, client.num_draws()); | 911 EXPECT_EQ(0, client->num_draws()); |
| 883 | 912 |
| 884 // We have no immediate actions to perform, so the BeginImplFrame should post | 913 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 885 // the deadline task. | 914 // the deadline task. |
| 886 client.Reset(); | 915 client->Reset(); |
| 887 EXPECT_SCOPED(client.AdvanceFrame()); | 916 EXPECT_SCOPED(AdvanceFrame()); |
| 888 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 917 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 889 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 918 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 890 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 919 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 891 | 920 |
| 892 // Draw. The draw will trigger SetNeedsPrepareTiles, and | 921 // Draw. The draw will trigger SetNeedsPrepareTiles, and |
| 893 // then the PrepareTiles action will be triggered after the Draw. | 922 // then the PrepareTiles action will be triggered after the Draw. |
| 894 // Afterwards, neither a draw nor PrepareTiles are pending. | 923 // Afterwards, neither a draw nor PrepareTiles are pending. |
| 895 client.Reset(); | 924 client->Reset(); |
| 896 client.task_runner().RunPendingTasks(); // Run posted deadline. | 925 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 897 EXPECT_EQ(1, client.num_draws()); | 926 EXPECT_EQ(1, client->num_draws()); |
| 898 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 927 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 899 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 928 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 900 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 929 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 901 client.ActionIndex("ScheduledActionPrepareTiles")); | 930 client->ActionIndex("ScheduledActionPrepareTiles")); |
| 902 EXPECT_FALSE(scheduler->RedrawPending()); | 931 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 903 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 932 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 904 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 933 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 905 | 934 |
| 906 // We need a BeginImplFrame where we don't swap to go idle. | 935 // We need a BeginImplFrame where we don't swap to go idle. |
| 907 client.Reset(); | 936 client->Reset(); |
| 908 EXPECT_SCOPED(client.AdvanceFrame()); | 937 EXPECT_SCOPED(AdvanceFrame()); |
| 909 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 938 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 910 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 939 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 911 client.Reset(); | 940 client->Reset(); |
| 912 client.task_runner().RunPendingTasks(); // Run posted deadline. | 941 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 913 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 942 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); |
| 914 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 943 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 915 EXPECT_EQ(0, client.num_draws()); | 944 EXPECT_EQ(0, client->num_draws()); |
| 916 | 945 |
| 917 // Now trigger a PrepareTiles outside of a draw. We will then need | 946 // Now trigger a PrepareTiles outside of a draw. We will then need |
| 918 // a begin-frame for the PrepareTiles, but we don't need a draw. | 947 // a begin-frame for the PrepareTiles, but we don't need a draw. |
| 919 client.Reset(); | 948 client->Reset(); |
| 920 EXPECT_FALSE(client.needs_begin_frames()); | 949 EXPECT_FALSE(client->needs_begin_frames()); |
| 921 scheduler->SetNeedsPrepareTiles(); | 950 scheduler_->SetNeedsPrepareTiles(); |
| 922 EXPECT_TRUE(client.needs_begin_frames()); | 951 EXPECT_TRUE(client->needs_begin_frames()); |
| 923 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 952 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 924 EXPECT_FALSE(scheduler->RedrawPending()); | 953 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 925 | 954 |
| 926 // BeginImplFrame. There will be no draw, only PrepareTiles. | 955 // BeginImplFrame. There will be no draw, only PrepareTiles. |
| 927 client.Reset(); | 956 client->Reset(); |
| 928 EXPECT_SCOPED(client.AdvanceFrame()); | 957 EXPECT_SCOPED(AdvanceFrame()); |
| 929 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 958 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 930 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 959 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 931 client.Reset(); | 960 client->Reset(); |
| 932 client.task_runner().RunPendingTasks(); // Run posted deadline. | 961 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 933 EXPECT_EQ(0, client.num_draws()); | 962 EXPECT_EQ(0, client->num_draws()); |
| 934 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 963 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 935 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 964 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 936 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 965 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 937 } | 966 } |
| 938 | 967 |
| 939 // Test that PrepareTiles only happens once per frame. If an external caller | 968 // Test that PrepareTiles only happens once per frame. If an external caller |
| 940 // initiates it, then the state machine should not PrepareTiles on that frame. | 969 // initiates it, then the state machine should not PrepareTiles on that frame. |
| 941 TEST(SchedulerTest, PrepareTilesOncePerFrame) { | 970 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { |
| 942 FakeSchedulerClient client; | 971 scheduler_settings_.use_external_begin_frame_source = true; |
| 943 SchedulerSettings scheduler_settings; | 972 SetUpScheduler(true); |
| 944 scheduler_settings.use_external_begin_frame_source = true; | |
| 945 | |
| 946 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 947 | 973 |
| 948 // If DidPrepareTiles during a frame, then PrepareTiles should not occur | 974 // If DidPrepareTiles during a frame, then PrepareTiles should not occur |
| 949 // again. | 975 // again. |
| 950 scheduler->SetNeedsPrepareTiles(); | 976 scheduler_->SetNeedsPrepareTiles(); |
| 951 scheduler->SetNeedsRedraw(); | 977 scheduler_->SetNeedsRedraw(); |
| 952 client.Reset(); | 978 client_->Reset(); |
| 953 EXPECT_SCOPED(client.AdvanceFrame()); | 979 EXPECT_SCOPED(AdvanceFrame()); |
| 954 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 980 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 955 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 981 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 956 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 982 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 957 | 983 |
| 958 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 984 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 959 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. | 985 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 960 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 986 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 961 | 987 |
| 962 client.Reset(); | 988 client_->Reset(); |
| 963 client.task_runner().RunPendingTasks(); // Run posted deadline. | 989 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 964 EXPECT_EQ(1, client.num_draws()); | 990 EXPECT_EQ(1, client_->num_draws()); |
| 965 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 991 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 966 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 992 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 967 EXPECT_FALSE(scheduler->RedrawPending()); | 993 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 968 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 994 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 969 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 995 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 970 | 996 |
| 971 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 997 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
| 972 scheduler->SetNeedsPrepareTiles(); | 998 scheduler_->SetNeedsPrepareTiles(); |
| 973 scheduler->SetNeedsRedraw(); | 999 scheduler_->SetNeedsRedraw(); |
| 974 client.Reset(); | 1000 client_->Reset(); |
| 975 EXPECT_SCOPED(client.AdvanceFrame()); | 1001 EXPECT_SCOPED(AdvanceFrame()); |
| 976 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1002 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 977 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1003 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 978 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1004 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 979 | 1005 |
| 980 client.Reset(); | 1006 client_->Reset(); |
| 981 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1007 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 982 EXPECT_EQ(1, client.num_draws()); | 1008 EXPECT_EQ(1, client_->num_draws()); |
| 983 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1009 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 984 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 1010 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 985 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1011 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 986 client.ActionIndex("ScheduledActionPrepareTiles")); | 1012 client_->ActionIndex("ScheduledActionPrepareTiles")); |
| 987 EXPECT_FALSE(scheduler->RedrawPending()); | 1013 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 988 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 1014 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 989 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1015 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 990 scheduler->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | 1016 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles |
| 991 | 1017 |
| 992 // If we get another DidPrepareTiles within the same frame, we should | 1018 // If we get another DidPrepareTiles within the same frame, we should |
| 993 // not PrepareTiles on the next frame. | 1019 // not PrepareTiles on the next frame. |
| 994 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. | 1020 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 995 scheduler->SetNeedsPrepareTiles(); | 1021 scheduler_->SetNeedsPrepareTiles(); |
| 996 scheduler->SetNeedsRedraw(); | 1022 scheduler_->SetNeedsRedraw(); |
| 997 client.Reset(); | 1023 client_->Reset(); |
| 998 EXPECT_SCOPED(client.AdvanceFrame()); | 1024 EXPECT_SCOPED(AdvanceFrame()); |
| 999 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1025 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1000 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1026 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1001 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1027 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1002 | 1028 |
| 1003 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 1029 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1004 | 1030 |
| 1005 client.Reset(); | 1031 client_->Reset(); |
| 1006 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1032 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1007 EXPECT_EQ(1, client.num_draws()); | 1033 EXPECT_EQ(1, client_->num_draws()); |
| 1008 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1034 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1009 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 1035 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1010 EXPECT_FALSE(scheduler->RedrawPending()); | 1036 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1011 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1037 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1012 | 1038 |
| 1013 // If we get another DidPrepareTiles, we should not PrepareTiles on the next | 1039 // If we get another DidPrepareTiles, we should not PrepareTiles on the next |
| 1014 // frame. This verifies we don't alternate calling PrepareTiles once and | 1040 // frame. This verifies we don't alternate calling PrepareTiles once and |
| 1015 // twice. | 1041 // twice. |
| 1016 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 1042 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1017 scheduler->DidPrepareTiles(); // An explicit PrepareTiles. | 1043 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1018 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 1044 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1019 scheduler->SetNeedsPrepareTiles(); | 1045 scheduler_->SetNeedsPrepareTiles(); |
| 1020 scheduler->SetNeedsRedraw(); | 1046 scheduler_->SetNeedsRedraw(); |
| 1021 client.Reset(); | 1047 client_->Reset(); |
| 1022 EXPECT_SCOPED(client.AdvanceFrame()); | 1048 EXPECT_SCOPED(AdvanceFrame()); |
| 1023 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1049 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1024 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1050 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1025 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1051 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1026 | 1052 |
| 1027 EXPECT_TRUE(scheduler->PrepareTilesPending()); | 1053 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1028 | 1054 |
| 1029 client.Reset(); | 1055 client_->Reset(); |
| 1030 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1056 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1031 EXPECT_EQ(1, client.num_draws()); | 1057 EXPECT_EQ(1, client_->num_draws()); |
| 1032 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1058 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1033 EXPECT_FALSE(client.HasAction("ScheduledActionPrepareTiles")); | 1059 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1034 EXPECT_FALSE(scheduler->RedrawPending()); | 1060 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1035 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1061 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1036 | 1062 |
| 1037 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1063 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
| 1038 scheduler->SetNeedsPrepareTiles(); | 1064 scheduler_->SetNeedsPrepareTiles(); |
| 1039 scheduler->SetNeedsRedraw(); | 1065 scheduler_->SetNeedsRedraw(); |
| 1040 client.Reset(); | 1066 client_->Reset(); |
| 1041 EXPECT_SCOPED(client.AdvanceFrame()); | 1067 EXPECT_SCOPED(AdvanceFrame()); |
| 1042 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1068 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1043 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1069 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1044 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1070 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1045 | 1071 |
| 1046 client.Reset(); | 1072 client_->Reset(); |
| 1047 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1073 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1048 EXPECT_EQ(1, client.num_draws()); | 1074 EXPECT_EQ(1, client_->num_draws()); |
| 1049 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1075 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1050 EXPECT_TRUE(client.HasAction("ScheduledActionPrepareTiles")); | 1076 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1051 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1077 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 1052 client.ActionIndex("ScheduledActionPrepareTiles")); | 1078 client_->ActionIndex("ScheduledActionPrepareTiles")); |
| 1053 EXPECT_FALSE(scheduler->RedrawPending()); | 1079 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1054 EXPECT_FALSE(scheduler->PrepareTilesPending()); | 1080 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1055 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1081 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1056 scheduler->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles | 1082 scheduler_->DidPrepareTiles(); // Corresponds to ScheduledActionPrepareTiles |
| 1057 } | 1083 } |
| 1058 | 1084 |
| 1059 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1085 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
| 1060 SchedulerClientNeedsPrepareTilesInDraw client; | 1086 SchedulerClientNeedsPrepareTilesInDraw* client = |
| 1061 SchedulerSettings scheduler_settings; | 1087 new SchedulerClientNeedsPrepareTilesInDraw; |
| 1062 scheduler_settings.use_external_begin_frame_source = true; | 1088 scheduler_settings_.use_external_begin_frame_source = true; |
| 1063 | 1089 SetUpScheduler(client, true); |
| 1064 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1090 |
| 1065 | 1091 scheduler_->SetNeedsRedraw(); |
| 1066 scheduler->SetNeedsRedraw(); | 1092 EXPECT_SCOPED(AdvanceFrame()); |
| 1067 EXPECT_SCOPED(client.AdvanceFrame()); | |
| 1068 | 1093 |
| 1069 // The deadline should be zero since there is no work other than drawing | 1094 // The deadline should be zero since there is no work other than drawing |
| 1070 // pending. | 1095 // pending. |
| 1071 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); | 1096 EXPECT_EQ(base::TimeTicks(), client->posted_begin_impl_frame_deadline()); |
| 1072 } | 1097 } |
| 1073 | 1098 |
| 1074 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | 1099 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
| 1075 public: | 1100 public: |
| 1076 SchedulerClientWithFixedEstimates( | 1101 SchedulerClientWithFixedEstimates( |
| 1077 base::TimeDelta draw_duration, | 1102 base::TimeDelta draw_duration, |
| 1078 base::TimeDelta begin_main_frame_to_commit_duration, | 1103 base::TimeDelta begin_main_frame_to_commit_duration, |
| 1079 base::TimeDelta commit_to_activate_duration) | 1104 base::TimeDelta commit_to_activate_duration) |
| 1080 : draw_duration_(draw_duration), | 1105 : draw_duration_(draw_duration), |
| 1081 begin_main_frame_to_commit_duration_( | 1106 begin_main_frame_to_commit_duration_( |
| 1082 begin_main_frame_to_commit_duration), | 1107 begin_main_frame_to_commit_duration), |
| 1083 commit_to_activate_duration_(commit_to_activate_duration) {} | 1108 commit_to_activate_duration_(commit_to_activate_duration) {} |
| 1084 | 1109 |
| 1085 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; } | 1110 base::TimeDelta DrawDurationEstimate() override { return draw_duration_; } |
| 1086 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { | 1111 base::TimeDelta BeginMainFrameToCommitDurationEstimate() override { |
| 1087 return begin_main_frame_to_commit_duration_; | 1112 return begin_main_frame_to_commit_duration_; |
| 1088 } | 1113 } |
| 1089 base::TimeDelta CommitToActivateDurationEstimate() override { | 1114 base::TimeDelta CommitToActivateDurationEstimate() override { |
| 1090 return commit_to_activate_duration_; | 1115 return commit_to_activate_duration_; |
| 1091 } | 1116 } |
| 1092 | 1117 |
| 1093 private: | 1118 private: |
| 1094 base::TimeDelta draw_duration_; | 1119 base::TimeDelta draw_duration_; |
| 1095 base::TimeDelta begin_main_frame_to_commit_duration_; | 1120 base::TimeDelta begin_main_frame_to_commit_duration_; |
| 1096 base::TimeDelta commit_to_activate_duration_; | 1121 base::TimeDelta commit_to_activate_duration_; |
| 1097 }; | 1122 }; |
| 1098 | 1123 |
| 1099 void MainFrameInHighLatencyMode(int64 begin_main_frame_to_commit_estimate_in_ms, | 1124 void SchedulerTest::MainFrameInHighLatencyMode( |
| 1100 int64 commit_to_activate_estimate_in_ms, | 1125 int64 begin_main_frame_to_commit_estimate_in_ms, |
| 1101 bool impl_latency_takes_priority, | 1126 int64 commit_to_activate_estimate_in_ms, |
| 1102 bool should_send_begin_main_frame) { | 1127 bool impl_latency_takes_priority, |
| 1128 bool should_send_begin_main_frame) { | |
| 1103 // Set up client with specified estimates (draw duration is set to 1). | 1129 // Set up client with specified estimates (draw duration is set to 1). |
| 1104 SchedulerClientWithFixedEstimates client( | 1130 SchedulerClientWithFixedEstimates* client = |
| 1105 base::TimeDelta::FromMilliseconds(1), | 1131 new SchedulerClientWithFixedEstimates( |
| 1106 base::TimeDelta::FromMilliseconds( | 1132 base::TimeDelta::FromMilliseconds(1), |
| 1107 begin_main_frame_to_commit_estimate_in_ms), | 1133 base::TimeDelta::FromMilliseconds( |
| 1108 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); | 1134 begin_main_frame_to_commit_estimate_in_ms), |
| 1109 SchedulerSettings scheduler_settings; | 1135 base::TimeDelta::FromMilliseconds(commit_to_activate_estimate_in_ms)); |
| 1110 scheduler_settings.use_external_begin_frame_source = true; | 1136 |
| 1111 | 1137 scheduler_settings_.use_external_begin_frame_source = true; |
| 1112 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1138 SetUpScheduler(client, true); |
| 1113 | 1139 |
| 1114 scheduler->SetImplLatencyTakesPriority(impl_latency_takes_priority); | 1140 scheduler_->SetImplLatencyTakesPriority(impl_latency_takes_priority); |
| 1115 | 1141 |
| 1116 // Impl thread hits deadline before commit finishes. | 1142 // Impl thread hits deadline before commit finishes. |
| 1117 scheduler->SetNeedsCommit(); | 1143 scheduler_->SetNeedsCommit(); |
| 1118 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1144 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1119 EXPECT_SCOPED(client.AdvanceFrame()); | 1145 EXPECT_SCOPED(AdvanceFrame()); |
| 1120 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1146 EXPECT_FALSE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1121 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1147 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1122 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1148 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1123 scheduler->NotifyBeginMainFrameStarted(); | 1149 scheduler_->NotifyBeginMainFrameStarted(); |
| 1124 scheduler->NotifyReadyToCommit(); | 1150 scheduler_->NotifyReadyToCommit(); |
| 1125 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1151 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1126 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); | 1152 EXPECT_TRUE(client->HasAction("ScheduledActionSendBeginMainFrame")); |
| 1127 | 1153 |
| 1128 client.Reset(); | 1154 client->Reset(); |
| 1129 scheduler->SetNeedsCommit(); | 1155 scheduler_->SetNeedsCommit(); |
| 1130 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1156 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1131 EXPECT_SCOPED(client.AdvanceFrame()); | 1157 EXPECT_SCOPED(AdvanceFrame()); |
| 1132 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1158 EXPECT_TRUE(scheduler_->MainThreadIsInHighLatencyMode()); |
| 1133 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1159 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1134 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), | 1160 EXPECT_EQ(scheduler_->MainThreadIsInHighLatencyMode(), |
| 1135 should_send_begin_main_frame); | 1161 should_send_begin_main_frame); |
| 1136 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), | 1162 EXPECT_EQ(client->HasAction("ScheduledActionSendBeginMainFrame"), |
| 1137 should_send_begin_main_frame); | 1163 should_send_begin_main_frame); |
| 1138 } | 1164 } |
| 1139 | 1165 |
| 1140 TEST(SchedulerTest, | 1166 TEST_F(SchedulerTest, |
| 1141 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 1167 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
| 1142 // Set up client so that estimates indicate that we can commit and activate | 1168 // Set up client so that estimates indicate that we can commit and activate |
| 1143 // before the deadline (~8ms by default). | 1169 // before the deadline (~8ms by default). |
| 1144 MainFrameInHighLatencyMode(1, 1, false, false); | 1170 MainFrameInHighLatencyMode(1, 1, false, false); |
| 1145 } | 1171 } |
| 1146 | 1172 |
| 1147 TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanCommitTooLong) { | 1173 TEST_F(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanCommitTooLong) { |
| 1148 // Set up client so that estimates indicate that the commit cannot finish | 1174 // Set up client so that estimates indicate that the commit cannot finish |
| 1149 // before the deadline (~8ms by default). | 1175 // before the deadline (~8ms by default). |
| 1150 MainFrameInHighLatencyMode(10, 1, false, true); | 1176 MainFrameInHighLatencyMode(10, 1, false, true); |
| 1151 } | 1177 } |
| 1152 | 1178 |
| 1153 TEST(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanActivateTooLong) { | 1179 TEST_F(SchedulerTest, NotSkipMainFrameIfHighLatencyAndCanActivateTooLong) { |
| 1154 // Set up client so that estimates indicate that the activate cannot finish | 1180 // Set up client so that estimates indicate that the activate cannot finish |
| 1155 // before the deadline (~8ms by default). | 1181 // before the deadline (~8ms by default). |
| 1156 MainFrameInHighLatencyMode(1, 10, false, true); | 1182 MainFrameInHighLatencyMode(1, 10, false, true); |
| 1157 } | 1183 } |
| 1158 | 1184 |
| 1159 TEST(SchedulerTest, NotSkipMainFrameInPreferImplLatencyMode) { | 1185 TEST_F(SchedulerTest, NotSkipMainFrameInPreferImplLatencyMode) { |
| 1160 // Set up client so that estimates indicate that we can commit and activate | 1186 // Set up client so that estimates indicate that we can commit and activate |
| 1161 // before the deadline (~8ms by default), but also enable impl latency takes | 1187 // before the deadline (~8ms by default), but also enable impl latency takes |
| 1162 // priority mode. | 1188 // priority mode. |
| 1163 MainFrameInHighLatencyMode(1, 1, true, true); | 1189 MainFrameInHighLatencyMode(1, 1, true, true); |
| 1164 } | 1190 } |
| 1165 | 1191 |
| 1166 TEST(SchedulerTest, PollForCommitCompletion) { | 1192 TEST_F(SchedulerTest, PollForCommitCompletion) { |
| 1167 // Since we are simulating a long commit, set up a client with draw duration | 1193 // Since we are simulating a long commit, set up a client with draw duration |
| 1168 // estimates that prevent skipping main frames to get to low latency mode. | 1194 // estimates that prevent skipping main frames to get to low latency mode. |
| 1169 SchedulerClientWithFixedEstimates client( | 1195 SchedulerClientWithFixedEstimates* client = |
| 1170 base::TimeDelta::FromMilliseconds(1), | 1196 new SchedulerClientWithFixedEstimates( |
| 1171 base::TimeDelta::FromMilliseconds(32), | 1197 base::TimeDelta::FromMilliseconds(1), |
| 1172 base::TimeDelta::FromMilliseconds(32)); | 1198 base::TimeDelta::FromMilliseconds(32), |
| 1173 SchedulerSettings scheduler_settings; | 1199 base::TimeDelta::FromMilliseconds(32)); |
| 1174 scheduler_settings.use_external_begin_frame_source = true; | 1200 scheduler_settings_.use_external_begin_frame_source = true; |
| 1175 | 1201 SetUpScheduler(client, true); |
| 1176 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1202 |
| 1177 | 1203 client->set_log_anticipated_draw_time_change(true); |
| 1178 client.set_log_anticipated_draw_time_change(true); | |
| 1179 | 1204 |
| 1180 BeginFrameArgs frame_args = | 1205 BeginFrameArgs frame_args = |
| 1181 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1206 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client->now_src()); |
| 1182 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1207 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
| 1183 | 1208 |
| 1184 // At this point, we've drawn a frame. Start another commit, but hold off on | 1209 // At this point, we've drawn a frame. Start another commit, but hold off on |
| 1185 // the NotifyReadyToCommit for now. | 1210 // the NotifyReadyToCommit for now. |
| 1186 EXPECT_FALSE(scheduler->CommitPending()); | 1211 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1187 scheduler->SetNeedsCommit(); | 1212 scheduler_->SetNeedsCommit(); |
| 1188 client.fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); | 1213 fake_external_begin_frame_source()->TestOnBeginFrame(frame_args); |
| 1189 EXPECT_TRUE(scheduler->CommitPending()); | 1214 EXPECT_TRUE(scheduler_->CommitPending()); |
| 1190 | 1215 |
| 1191 // Draw and swap the frame, but don't ack the swap to simulate the Browser | 1216 // Draw and swap the frame, but don't ack the swap to simulate the Browser |
| 1192 // blocking on the renderer. | 1217 // blocking on the renderer. |
| 1193 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1218 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1194 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1219 client->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1195 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1220 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1196 scheduler->DidSwapBuffers(); | 1221 scheduler_->DidSwapBuffers(); |
| 1197 | 1222 |
| 1198 // Spin the event loop a few times and make sure we get more | 1223 // Spin the event loop a few times and make sure we get more |
| 1199 // DidAnticipateDrawTimeChange calls every time. | 1224 // DidAnticipateDrawTimeChange calls every time. |
| 1200 int actions_so_far = client.num_actions_(); | 1225 int actions_so_far = client->num_actions_(); |
| 1201 | 1226 |
| 1202 // Does three iterations to make sure that the timer is properly repeating. | 1227 // Does three iterations to make sure that the timer is properly repeating. |
| 1203 for (int i = 0; i < 3; ++i) { | 1228 for (int i = 0; i < 3; ++i) { |
| 1204 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1229 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
| 1205 client.task_runner().DelayToNextTaskTime().InMicroseconds()) | 1230 client->task_runner().DelayToNextTaskTime().InMicroseconds()) |
| 1206 << scheduler->AsValue()->ToString(); | 1231 << scheduler_->AsValue()->ToString(); |
| 1207 client.task_runner().RunPendingTasks(); | 1232 client->task_runner().RunPendingTasks(); |
| 1208 EXPECT_GT(client.num_actions_(), actions_so_far); | 1233 EXPECT_GT(client->num_actions_(), actions_so_far); |
| 1209 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1234 EXPECT_STREQ(client->Action(client->num_actions_() - 1), |
| 1210 "DidAnticipatedDrawTimeChange"); | 1235 "DidAnticipatedDrawTimeChange"); |
| 1211 actions_so_far = client.num_actions_(); | 1236 actions_so_far = client->num_actions_(); |
| 1212 } | 1237 } |
| 1213 | 1238 |
| 1214 // Do the same thing after BeginMainFrame starts but still before activation. | 1239 // Do the same thing after BeginMainFrame starts but still before activation. |
| 1215 scheduler->NotifyBeginMainFrameStarted(); | 1240 scheduler_->NotifyBeginMainFrameStarted(); |
| 1216 for (int i = 0; i < 3; ++i) { | 1241 for (int i = 0; i < 3; ++i) { |
| 1217 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), | 1242 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
| 1218 client.task_runner().DelayToNextTaskTime().InMicroseconds()) | 1243 client->task_runner().DelayToNextTaskTime().InMicroseconds()) |
| 1219 << scheduler->AsValue()->ToString(); | 1244 << scheduler_->AsValue()->ToString(); |
| 1220 client.task_runner().RunPendingTasks(); | 1245 client->task_runner().RunPendingTasks(); |
| 1221 EXPECT_GT(client.num_actions_(), actions_so_far); | 1246 EXPECT_GT(client->num_actions_(), actions_so_far); |
| 1222 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1247 EXPECT_STREQ(client->Action(client->num_actions_() - 1), |
| 1223 "DidAnticipatedDrawTimeChange"); | 1248 "DidAnticipatedDrawTimeChange"); |
| 1224 actions_so_far = client.num_actions_(); | 1249 actions_so_far = client->num_actions_(); |
| 1225 } | 1250 } |
| 1226 } | 1251 } |
| 1227 | 1252 |
| 1228 TEST(SchedulerTest, BeginRetroFrame) { | 1253 TEST_F(SchedulerTest, BeginRetroFrame) { |
| 1229 FakeSchedulerClient client; | 1254 scheduler_settings_.use_external_begin_frame_source = true; |
| 1230 SchedulerSettings scheduler_settings; | 1255 SetUpScheduler(true); |
| 1231 scheduler_settings.use_external_begin_frame_source = true; | |
| 1232 | |
| 1233 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1234 | 1256 |
| 1235 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1257 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1236 scheduler->SetNeedsCommit(); | 1258 scheduler_->SetNeedsCommit(); |
| 1237 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1259 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1238 client.Reset(); | 1260 client_->Reset(); |
| 1239 | 1261 |
| 1240 // Create a BeginFrame with a long deadline to avoid race conditions. | 1262 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1241 // This is the first BeginFrame, which will be handled immediately. | 1263 // This is the first BeginFrame, which will be handled immediately. |
| 1242 BeginFrameArgs args = | 1264 BeginFrameArgs args = |
| 1243 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1265 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client_->now_src()); |
| 1244 args.deadline += base::TimeDelta::FromHours(1); | 1266 args.deadline += base::TimeDelta::FromHours(1); |
| 1245 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1267 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1246 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1268 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1247 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1269 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1248 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1270 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1249 EXPECT_TRUE(client.needs_begin_frames()); | 1271 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1250 client.Reset(); | 1272 client_->Reset(); |
| 1251 | 1273 |
| 1252 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1274 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1253 args.frame_time += base::TimeDelta::FromSeconds(1); | 1275 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1254 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1276 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1255 args.frame_time += base::TimeDelta::FromSeconds(1); | 1277 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1256 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1278 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1257 | 1279 |
| 1258 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1280 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 1259 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1281 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1260 EXPECT_NO_ACTION(client); | 1282 EXPECT_NO_ACTION(client_); |
| 1261 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1283 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1262 EXPECT_TRUE(client.needs_begin_frames()); | 1284 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1263 client.Reset(); | 1285 client_->Reset(); |
| 1264 | 1286 |
| 1265 // NotifyReadyToCommit should trigger the commit. | 1287 // NotifyReadyToCommit should trigger the commit. |
| 1266 scheduler->NotifyBeginMainFrameStarted(); | 1288 scheduler_->NotifyBeginMainFrameStarted(); |
| 1267 scheduler->NotifyReadyToCommit(); | 1289 scheduler_->NotifyReadyToCommit(); |
| 1268 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1290 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1269 EXPECT_TRUE(client.needs_begin_frames()); | 1291 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1270 client.Reset(); | 1292 client_->Reset(); |
| 1271 | 1293 |
| 1272 // BeginImplFrame should prepare the draw. | 1294 // BeginImplFrame should prepare the draw. |
| 1273 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1295 client_->task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1274 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1296 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1275 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1297 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1276 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1298 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1277 EXPECT_TRUE(client.needs_begin_frames()); | 1299 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1278 client.Reset(); | 1300 client_->Reset(); |
| 1279 | 1301 |
| 1280 // BeginImplFrame deadline should draw. | 1302 // BeginImplFrame deadline should draw. |
| 1281 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1303 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1282 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1304 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 1283 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1305 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1284 EXPECT_TRUE(client.needs_begin_frames()); | 1306 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1285 client.Reset(); | 1307 client_->Reset(); |
| 1286 | 1308 |
| 1287 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1309 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 1288 // to avoid excessive toggles. | 1310 // to avoid excessive toggles. |
| 1289 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1311 client_->task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1290 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1312 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 1291 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1313 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1292 client.Reset(); | 1314 client_->Reset(); |
| 1293 | 1315 |
| 1294 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1316 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1295 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1317 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 1296 client.Reset(); | 1318 client_->Reset(); |
| 1297 } | 1319 } |
| 1298 | 1320 |
| 1299 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { | 1321 TEST_F(SchedulerTest, BeginRetroFrame_SwapThrottled) { |
| 1300 FakeSchedulerClient client; | 1322 scheduler_settings_.use_external_begin_frame_source = true; |
| 1301 SchedulerSettings scheduler_settings; | 1323 SetUpScheduler(true); |
| 1302 scheduler_settings.use_external_begin_frame_source = true; | 1324 |
| 1303 | 1325 scheduler_->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); |
| 1304 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1305 scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); | |
| 1306 | 1326 |
| 1307 // To test swap ack throttling, this test disables automatic swap acks. | 1327 // To test swap ack throttling, this test disables automatic swap acks. |
| 1308 scheduler->SetMaxSwapsPending(1); | 1328 scheduler_->SetMaxSwapsPending(1); |
| 1309 client.SetAutomaticSwapAck(false); | 1329 client_->SetAutomaticSwapAck(false); |
| 1310 | 1330 |
| 1311 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1331 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1312 client.Reset(); | 1332 client_->Reset(); |
| 1313 scheduler->SetNeedsCommit(); | 1333 scheduler_->SetNeedsCommit(); |
| 1314 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1334 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1315 client.Reset(); | 1335 client_->Reset(); |
| 1316 | 1336 |
| 1317 EXPECT_SCOPED(client.AdvanceFrame()); | 1337 EXPECT_SCOPED(AdvanceFrame()); |
| 1318 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1338 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1319 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1339 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1320 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1340 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1321 EXPECT_TRUE(client.needs_begin_frames()); | 1341 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1322 client.Reset(); | 1342 client_->Reset(); |
| 1323 | 1343 |
| 1324 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1344 // Queue BeginFrame while we are still handling the previous BeginFrame. |
| 1325 client.SendNextBeginFrame(); | 1345 SendNextBeginFrame(); |
| 1326 EXPECT_NO_ACTION(client); | 1346 EXPECT_NO_ACTION(client_); |
| 1327 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1347 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1328 EXPECT_TRUE(client.needs_begin_frames()); | 1348 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1329 client.Reset(); | 1349 client_->Reset(); |
| 1330 | 1350 |
| 1331 // NotifyReadyToCommit should trigger the pending commit and draw. | 1351 // NotifyReadyToCommit should trigger the pending commit and draw. |
| 1332 scheduler->NotifyBeginMainFrameStarted(); | 1352 scheduler_->NotifyBeginMainFrameStarted(); |
| 1333 scheduler->NotifyReadyToCommit(); | 1353 scheduler_->NotifyReadyToCommit(); |
| 1334 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1354 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1335 EXPECT_TRUE(client.needs_begin_frames()); | 1355 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1336 client.Reset(); | 1356 client_->Reset(); |
| 1337 | 1357 |
| 1338 // Swapping will put us into a swap throttled state. | 1358 // Swapping will put us into a swap throttled state. |
| 1339 // Run posted deadline. | 1359 // Run posted deadline. |
| 1340 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1360 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1341 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1361 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 1342 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1362 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 1343 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1363 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1344 EXPECT_TRUE(client.needs_begin_frames()); | 1364 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1345 client.Reset(); | 1365 client_->Reset(); |
| 1346 | 1366 |
| 1347 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames | 1367 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames |
| 1348 // but not a BeginMainFrame or draw. | 1368 // but not a BeginMainFrame or draw. |
| 1349 scheduler->SetNeedsCommit(); | 1369 scheduler_->SetNeedsCommit(); |
| 1350 scheduler->SetNeedsRedraw(); | 1370 scheduler_->SetNeedsRedraw(); |
| 1351 // Run posted BeginRetroFrame. | 1371 // Run posted BeginRetroFrame. |
| 1352 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(false)); | 1372 client_->task_runner().RunTasksWhile( |
| 1353 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1373 client_->ImplFrameDeadlinePending(false)); |
| 1354 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1374 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1355 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1375 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1356 EXPECT_TRUE(client.needs_begin_frames()); | 1376 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1357 client.Reset(); | 1377 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1378 client_->Reset(); | |
| 1358 | 1379 |
| 1359 // Let time pass sufficiently beyond the regular deadline but not beyond the | 1380 // Let time pass sufficiently beyond the regular deadline but not beyond the |
| 1360 // late deadline. | 1381 // late deadline. |
| 1361 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 1382 client_->now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - |
| 1362 base::TimeDelta::FromMicroseconds(1)); | 1383 base::TimeDelta::FromMicroseconds(1)); |
| 1363 client.task_runner().RunUntilTime(client.now_src()->Now()); | 1384 client_->task_runner().RunUntilTime(client_->now_src()->Now()); |
| 1364 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1385 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1365 | 1386 |
| 1366 // Take us out of a swap throttled state. | 1387 // Take us out of a swap throttled state. |
| 1367 scheduler->DidSwapBuffersComplete(); | 1388 scheduler_->DidSwapBuffersComplete(); |
| 1368 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 1389 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 1369 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1390 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1370 EXPECT_TRUE(client.needs_begin_frames()); | 1391 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1371 client.Reset(); | 1392 client_->Reset(); |
| 1372 | 1393 |
| 1373 // Verify that the deadline was rescheduled. | 1394 // Verify that the deadline was rescheduled. |
| 1374 client.task_runner().RunUntilTime(client.now_src()->Now()); | 1395 client_->task_runner().RunUntilTime(client_->now_src()->Now()); |
| 1375 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); | 1396 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 1376 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1397 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1377 EXPECT_TRUE(client.needs_begin_frames()); | 1398 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1378 client.Reset(); | 1399 client_->Reset(); |
| 1379 } | 1400 } |
| 1380 | 1401 |
| 1381 TEST(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { | 1402 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { |
| 1382 FakeSchedulerClient client; | 1403 scheduler_settings_.use_external_begin_frame_source = true; |
| 1383 SchedulerSettings scheduler_settings; | 1404 SetUpScheduler(true); |
| 1384 scheduler_settings.use_external_begin_frame_source = true; | 1405 |
| 1385 | 1406 scheduler_->SetNeedsCommit(); |
| 1386 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1407 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1387 | 1408 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1388 scheduler->SetNeedsCommit(); | 1409 |
| 1389 EXPECT_TRUE(client.needs_begin_frames()); | 1410 client_->Reset(); |
| 1390 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1411 EXPECT_SCOPED(AdvanceFrame()); |
| 1391 | 1412 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1392 client.Reset(); | 1413 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1393 EXPECT_SCOPED(client.AdvanceFrame()); | 1414 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1394 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1415 |
| 1395 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1416 client_->Reset(); |
| 1396 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1417 scheduler_->NotifyBeginMainFrameStarted(); |
| 1397 | 1418 |
| 1398 client.Reset(); | 1419 client_->Reset(); |
| 1399 scheduler->NotifyBeginMainFrameStarted(); | 1420 SendNextBeginFrame(); |
| 1400 | |
| 1401 client.Reset(); | |
| 1402 client.SendNextBeginFrame(); | |
| 1403 // This BeginFrame is queued up as a retro frame. | 1421 // This BeginFrame is queued up as a retro frame. |
| 1404 EXPECT_NO_ACTION(client); | 1422 EXPECT_NO_ACTION(client_); |
| 1405 // The previous deadline is still pending. | 1423 // The previous deadline is still pending. |
| 1406 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1424 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1407 | 1425 |
| 1408 client.Reset(); | 1426 client_->Reset(); |
| 1409 // This commit should schedule the (previous) deadline to trigger immediately. | 1427 // This commit should schedule the (previous) deadline to trigger immediately. |
| 1410 scheduler->NotifyReadyToCommit(); | 1428 scheduler_->NotifyReadyToCommit(); |
| 1411 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1429 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1412 | 1430 |
| 1413 client.Reset(); | 1431 client_->Reset(); |
| 1414 // The deadline task should trigger causing a draw. | 1432 // The deadline task should trigger causing a draw. |
| 1415 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1433 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1416 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1434 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1417 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1435 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 1418 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1436 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 1419 | 1437 |
| 1420 // Keep animating. | 1438 // Keep animating. |
| 1421 client.Reset(); | 1439 client_->Reset(); |
| 1422 scheduler->SetNeedsAnimate(); | 1440 scheduler_->SetNeedsAnimate(); |
| 1423 scheduler->SetNeedsRedraw(); | 1441 scheduler_->SetNeedsRedraw(); |
| 1424 EXPECT_NO_ACTION(client); | 1442 EXPECT_NO_ACTION(client_); |
| 1425 | 1443 |
| 1426 // Let's advance sufficiently past the next frame's deadline. | 1444 // Let's advance sufficiently past the next frame's deadline. |
| 1427 client.now_src()->AdvanceNow( | 1445 client_->now_src()->AdvanceNow( |
| 1428 BeginFrameArgs::DefaultInterval() - | 1446 BeginFrameArgs::DefaultInterval() - |
| 1429 BeginFrameArgs::DefaultEstimatedParentDrawTime() + | 1447 BeginFrameArgs::DefaultEstimatedParentDrawTime() + |
| 1430 base::TimeDelta::FromMicroseconds(1)); | 1448 base::TimeDelta::FromMicroseconds(1)); |
| 1431 | 1449 |
| 1432 // The retro frame hasn't expired yet. | 1450 // The retro frame hasn't expired yet. |
| 1433 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(false)); | 1451 client_->task_runner().RunTasksWhile( |
| 1434 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1452 client_->ImplFrameDeadlinePending(false)); |
| 1435 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1453 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1436 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1454 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1455 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | |
| 1437 | 1456 |
| 1438 // This is an immediate deadline case. | 1457 // This is an immediate deadline case. |
| 1439 client.Reset(); | 1458 client_->Reset(); |
| 1440 client.task_runner().RunPendingTasks(); | 1459 client_->task_runner().RunPendingTasks(); |
| 1441 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1460 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1442 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client); | 1461 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 1443 } | 1462 } |
| 1444 | 1463 |
| 1445 TEST(SchedulerTest, RetroFrameDoesNotExpireTooLate) { | 1464 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooLate) { |
| 1446 FakeSchedulerClient client; | 1465 scheduler_settings_.use_external_begin_frame_source = true; |
| 1447 SchedulerSettings scheduler_settings; | 1466 SetUpScheduler(true); |
| 1448 scheduler_settings.use_external_begin_frame_source = true; | 1467 |
| 1449 | 1468 scheduler_->SetNeedsCommit(); |
| 1450 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1469 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1451 | 1470 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1452 scheduler->SetNeedsCommit(); | 1471 |
| 1453 EXPECT_TRUE(client.needs_begin_frames()); | 1472 client_->Reset(); |
| 1454 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1473 EXPECT_SCOPED(AdvanceFrame()); |
| 1455 | 1474 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1456 client.Reset(); | 1475 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1457 EXPECT_SCOPED(client.AdvanceFrame()); | 1476 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1458 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1477 |
| 1459 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1478 client_->Reset(); |
| 1460 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1479 scheduler_->NotifyBeginMainFrameStarted(); |
| 1461 | 1480 |
| 1462 client.Reset(); | 1481 client_->Reset(); |
| 1463 scheduler->NotifyBeginMainFrameStarted(); | 1482 SendNextBeginFrame(); |
| 1464 | |
| 1465 client.Reset(); | |
| 1466 client.SendNextBeginFrame(); | |
| 1467 // This BeginFrame is queued up as a retro frame. | 1483 // This BeginFrame is queued up as a retro frame. |
| 1468 EXPECT_NO_ACTION(client); | 1484 EXPECT_NO_ACTION(client_); |
| 1469 // The previous deadline is still pending. | 1485 // The previous deadline is still pending. |
| 1470 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1486 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1471 | 1487 |
| 1472 client.Reset(); | 1488 client_->Reset(); |
| 1473 // This commit should schedule the (previous) deadline to trigger immediately. | 1489 // This commit should schedule the (previous) deadline to trigger immediately. |
| 1474 scheduler->NotifyReadyToCommit(); | 1490 scheduler_->NotifyReadyToCommit(); |
| 1475 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1491 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1476 | 1492 |
| 1477 client.Reset(); | 1493 client_->Reset(); |
| 1478 // The deadline task should trigger causing a draw. | 1494 // The deadline task should trigger causing a draw. |
| 1479 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1495 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1480 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1496 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1481 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1497 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 1482 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1498 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 1483 | 1499 |
| 1484 // Keep animating. | 1500 // Keep animating. |
| 1485 client.Reset(); | 1501 client_->Reset(); |
| 1486 scheduler->SetNeedsAnimate(); | 1502 scheduler_->SetNeedsAnimate(); |
| 1487 scheduler->SetNeedsRedraw(); | 1503 scheduler_->SetNeedsRedraw(); |
| 1488 EXPECT_NO_ACTION(client); | 1504 EXPECT_NO_ACTION(client_); |
| 1489 | 1505 |
| 1490 // Let's advance sufficiently past the next frame's deadline. | 1506 // Let's advance sufficiently past the next frame's deadline. |
| 1491 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() + | 1507 client_->now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() + |
| 1492 base::TimeDelta::FromMicroseconds(1)); | 1508 base::TimeDelta::FromMicroseconds(1)); |
| 1493 | 1509 |
| 1494 // The retro frame should've expired. | 1510 // The retro frame should've expired. |
| 1495 EXPECT_NO_ACTION(client); | 1511 EXPECT_NO_ACTION(client_); |
| 1496 } | 1512 } |
| 1497 | 1513 |
| 1498 void BeginFramesNotFromClient(bool use_external_begin_frame_source, | 1514 void SchedulerTest::BeginFramesNotFromClient( |
| 1499 bool throttle_frame_production) { | 1515 bool use_external_begin_frame_source, |
| 1500 FakeSchedulerClient client; | 1516 bool throttle_frame_production) { |
| 1501 SchedulerSettings scheduler_settings; | 1517 scheduler_settings_.use_external_begin_frame_source = |
| 1502 scheduler_settings.use_external_begin_frame_source = | |
| 1503 use_external_begin_frame_source; | 1518 use_external_begin_frame_source; |
| 1504 scheduler_settings.throttle_frame_production = throttle_frame_production; | 1519 scheduler_settings_.throttle_frame_production = throttle_frame_production; |
| 1505 | 1520 SetUpScheduler(true); |
| 1506 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1507 | 1521 |
| 1508 // SetNeedsCommit should begin the frame on the next BeginImplFrame | 1522 // SetNeedsCommit should begin the frame on the next BeginImplFrame |
| 1509 // without calling SetNeedsBeginFrame. | 1523 // without calling SetNeedsBeginFrame. |
| 1510 scheduler->SetNeedsCommit(); | 1524 scheduler_->SetNeedsCommit(); |
| 1511 EXPECT_NO_ACTION(client); | 1525 EXPECT_NO_ACTION(client_); |
| 1512 client.Reset(); | 1526 client_->Reset(); |
| 1513 | 1527 |
| 1514 // When the client-driven BeginFrame are disabled, the scheduler posts it's | 1528 // When the client-driven BeginFrame are disabled, the scheduler posts it's |
| 1515 // own BeginFrame tasks. | 1529 // own BeginFrame tasks. |
| 1516 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1530 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1517 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1531 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1518 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1532 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1519 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1533 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1520 client.Reset(); | 1534 client_->Reset(); |
| 1521 | 1535 |
| 1522 // If we don't swap on the deadline, we wait for the next BeginFrame. | 1536 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 1523 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1537 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1524 EXPECT_NO_ACTION(client); | 1538 EXPECT_NO_ACTION(client_); |
| 1525 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1539 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1526 client.Reset(); | 1540 client_->Reset(); |
| 1527 | 1541 |
| 1528 // NotifyReadyToCommit should trigger the commit. | 1542 // NotifyReadyToCommit should trigger the commit. |
| 1529 scheduler->NotifyBeginMainFrameStarted(); | 1543 scheduler_->NotifyBeginMainFrameStarted(); |
| 1530 scheduler->NotifyReadyToCommit(); | 1544 scheduler_->NotifyReadyToCommit(); |
| 1531 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1545 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1532 client.Reset(); | 1546 client_->Reset(); |
| 1533 | 1547 |
| 1534 // BeginImplFrame should prepare the draw. | 1548 // BeginImplFrame should prepare the draw. |
| 1535 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1549 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1536 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1550 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1537 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1551 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1538 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1552 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1539 client.Reset(); | 1553 client_->Reset(); |
| 1540 | 1554 |
| 1541 // BeginImplFrame deadline should draw. | 1555 // BeginImplFrame deadline should draw. |
| 1542 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1556 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1543 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1557 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 1544 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1558 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1545 client.Reset(); | 1559 client_->Reset(); |
| 1546 | 1560 |
| 1547 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1561 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 1548 // to avoid excessive toggles. | 1562 // to avoid excessive toggles. |
| 1549 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1563 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1550 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1564 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 1551 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1565 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1552 client.Reset(); | 1566 client_->Reset(); |
| 1553 | 1567 |
| 1554 // Make sure SetNeedsBeginFrame isn't called on the client | 1568 // Make sure SetNeedsBeginFrame isn't called on the client |
| 1555 // when the BeginFrame is no longer needed. | 1569 // when the BeginFrame is no longer needed. |
| 1556 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1570 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1557 EXPECT_NO_ACTION(client); | 1571 EXPECT_NO_ACTION(client_); |
| 1558 client.Reset(); | 1572 client_->Reset(); |
| 1559 } | 1573 } |
| 1560 | 1574 |
| 1561 TEST(SchedulerTest, SyntheticBeginFrames) { | 1575 TEST_F(SchedulerTest, SyntheticBeginFrames) { |
| 1562 bool use_external_begin_frame_source = false; | 1576 bool use_external_begin_frame_source = false; |
| 1563 bool throttle_frame_production = true; | 1577 bool throttle_frame_production = true; |
| 1564 BeginFramesNotFromClient(use_external_begin_frame_source, | 1578 BeginFramesNotFromClient(use_external_begin_frame_source, |
| 1565 throttle_frame_production); | 1579 throttle_frame_production); |
| 1566 } | 1580 } |
| 1567 | 1581 |
| 1568 TEST(SchedulerTest, VSyncThrottlingDisabled) { | 1582 TEST_F(SchedulerTest, VSyncThrottlingDisabled) { |
| 1569 bool use_external_begin_frame_source = true; | 1583 bool use_external_begin_frame_source = true; |
| 1570 bool throttle_frame_production = false; | 1584 bool throttle_frame_production = false; |
| 1571 BeginFramesNotFromClient(use_external_begin_frame_source, | 1585 BeginFramesNotFromClient(use_external_begin_frame_source, |
| 1572 throttle_frame_production); | 1586 throttle_frame_production); |
| 1573 } | 1587 } |
| 1574 | 1588 |
| 1575 TEST(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) { | 1589 TEST_F(SchedulerTest, SyntheticBeginFrames_And_VSyncThrottlingDisabled) { |
| 1576 bool use_external_begin_frame_source = false; | 1590 bool use_external_begin_frame_source = false; |
| 1577 bool throttle_frame_production = false; | 1591 bool throttle_frame_production = false; |
| 1578 BeginFramesNotFromClient(use_external_begin_frame_source, | 1592 BeginFramesNotFromClient(use_external_begin_frame_source, |
| 1579 throttle_frame_production); | 1593 throttle_frame_production); |
| 1580 } | 1594 } |
| 1581 | 1595 |
| 1582 void BeginFramesNotFromClient_SwapThrottled( | 1596 void SchedulerTest::BeginFramesNotFromClient_SwapThrottled( |
| 1583 bool use_external_begin_frame_source, | 1597 bool use_external_begin_frame_source, |
| 1584 bool throttle_frame_production) { | 1598 bool throttle_frame_production) { |
| 1585 FakeSchedulerClient client; | 1599 scheduler_settings_.use_external_begin_frame_source = |
| 1586 SchedulerSettings scheduler_settings; | |
| 1587 scheduler_settings.use_external_begin_frame_source = | |
| 1588 use_external_begin_frame_source; | 1600 use_external_begin_frame_source; |
| 1589 scheduler_settings.throttle_frame_production = throttle_frame_production; | 1601 scheduler_settings_.throttle_frame_production = throttle_frame_production; |
| 1590 | 1602 SetUpScheduler(true); |
| 1591 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1603 |
| 1592 scheduler->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); | 1604 scheduler_->SetEstimatedParentDrawTime(base::TimeDelta::FromMicroseconds(1)); |
| 1593 | 1605 |
| 1594 // To test swap ack throttling, this test disables automatic swap acks. | 1606 // To test swap ack throttling, this test disables automatic swap acks. |
| 1595 scheduler->SetMaxSwapsPending(1); | 1607 scheduler_->SetMaxSwapsPending(1); |
| 1596 client.SetAutomaticSwapAck(false); | 1608 client_->SetAutomaticSwapAck(false); |
| 1597 | 1609 |
| 1598 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1610 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1599 client.Reset(); | 1611 client_->Reset(); |
| 1600 scheduler->SetNeedsCommit(); | 1612 scheduler_->SetNeedsCommit(); |
| 1601 EXPECT_NO_ACTION(client); | 1613 EXPECT_NO_ACTION(client_); |
| 1602 client.Reset(); | 1614 client_->Reset(); |
| 1603 | 1615 |
| 1604 // Trigger the first BeginImplFrame and BeginMainFrame | 1616 // Trigger the first BeginImplFrame and BeginMainFrame |
| 1605 EXPECT_SCOPED(client.AdvanceFrame()); | 1617 EXPECT_SCOPED(AdvanceFrame()); |
| 1606 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1618 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1607 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1619 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1608 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1620 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1609 client.Reset(); | 1621 client_->Reset(); |
| 1610 | 1622 |
| 1611 // NotifyReadyToCommit should trigger the pending commit and draw. | 1623 // NotifyReadyToCommit should trigger the pending commit and draw. |
| 1612 scheduler->NotifyBeginMainFrameStarted(); | 1624 scheduler_->NotifyBeginMainFrameStarted(); |
| 1613 scheduler->NotifyReadyToCommit(); | 1625 scheduler_->NotifyReadyToCommit(); |
| 1614 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1626 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1615 client.Reset(); | 1627 client_->Reset(); |
| 1616 | 1628 |
| 1617 // Swapping will put us into a swap throttled state. | 1629 // Swapping will put us into a swap throttled state. |
| 1618 // Run posted deadline. | 1630 // Run posted deadline. |
| 1619 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1631 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1620 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1632 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 1621 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1633 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 1622 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1634 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1623 client.Reset(); | 1635 client_->Reset(); |
| 1624 | 1636 |
| 1625 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 1637 // While swap throttled, BeginFrames should trigger BeginImplFrames, |
| 1626 // but not a BeginMainFrame or draw. | 1638 // but not a BeginMainFrame or draw. |
| 1627 scheduler->SetNeedsCommit(); | 1639 scheduler_->SetNeedsCommit(); |
| 1628 scheduler->SetNeedsRedraw(); | 1640 scheduler_->SetNeedsRedraw(); |
| 1629 EXPECT_SCOPED(client.AdvanceFrame()); // Run posted BeginFrame. | 1641 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. |
| 1630 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1642 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1631 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1643 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1632 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1644 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1633 client.Reset(); | 1645 client_->Reset(); |
| 1634 | 1646 |
| 1635 // Let time pass sufficiently beyond the regular deadline but not beyond the | 1647 // Let time pass sufficiently beyond the regular deadline but not beyond the |
| 1636 // late deadline. | 1648 // late deadline. |
| 1637 client.now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - | 1649 client_->now_src()->AdvanceNow(BeginFrameArgs::DefaultInterval() - |
| 1638 base::TimeDelta::FromMicroseconds(1)); | 1650 base::TimeDelta::FromMicroseconds(1)); |
| 1639 client.task_runner().RunUntilTime(client.now_src()->Now()); | 1651 client_->task_runner().RunUntilTime(client_->now_src()->Now()); |
| 1640 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1652 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1641 | 1653 |
| 1642 // Take us out of a swap throttled state. | 1654 // Take us out of a swap throttled state. |
| 1643 scheduler->DidSwapBuffersComplete(); | 1655 scheduler_->DidSwapBuffersComplete(); |
| 1644 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 1656 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 1645 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1657 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1646 client.Reset(); | 1658 client_->Reset(); |
| 1647 | 1659 |
| 1648 // Verify that the deadline was rescheduled. | 1660 // Verify that the deadline was rescheduled. |
| 1649 // We can't use RunUntilTime(now) here because the next frame is also | 1661 // We can't use RunUntilTime(now) here because the next frame is also |
| 1650 // scheduled if throttle_frame_production = false. | 1662 // scheduled if throttle_frame_production = false. |
| 1651 base::TimeTicks before_deadline = client.now_src()->Now(); | 1663 base::TimeTicks before_deadline = client_->now_src()->Now(); |
| 1652 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1664 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1653 base::TimeTicks after_deadline = client.now_src()->Now(); | 1665 base::TimeTicks after_deadline = client_->now_src()->Now(); |
| 1654 EXPECT_EQ(after_deadline, before_deadline); | 1666 EXPECT_EQ(after_deadline, before_deadline); |
| 1655 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1667 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1656 client.Reset(); | 1668 client_->Reset(); |
| 1657 } | 1669 } |
| 1658 | 1670 |
| 1659 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { | 1671 TEST_F(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { |
| 1660 bool use_external_begin_frame_source = false; | 1672 bool use_external_begin_frame_source = false; |
| 1661 bool throttle_frame_production = true; | 1673 bool throttle_frame_production = true; |
| 1662 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, | 1674 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
| 1663 throttle_frame_production); | 1675 throttle_frame_production); |
| 1664 } | 1676 } |
| 1665 | 1677 |
| 1666 TEST(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { | 1678 TEST_F(SchedulerTest, VSyncThrottlingDisabled_SwapThrottled) { |
| 1667 bool use_external_begin_frame_source = true; | 1679 bool use_external_begin_frame_source = true; |
| 1668 bool throttle_frame_production = false; | 1680 bool throttle_frame_production = false; |
| 1669 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, | 1681 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
| 1670 throttle_frame_production); | 1682 throttle_frame_production); |
| 1671 } | 1683 } |
| 1672 | 1684 |
| 1673 TEST(SchedulerTest, | 1685 TEST_F(SchedulerTest, |
| 1674 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { | 1686 SyntheticBeginFrames_And_VSyncThrottlingDisabled_SwapThrottled) { |
| 1675 bool use_external_begin_frame_source = false; | 1687 bool use_external_begin_frame_source = false; |
| 1676 bool throttle_frame_production = false; | 1688 bool throttle_frame_production = false; |
| 1677 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, | 1689 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
| 1678 throttle_frame_production); | 1690 throttle_frame_production); |
| 1679 } | 1691 } |
| 1680 | 1692 |
| 1681 TEST(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { | 1693 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterOutputSurfaceIsInitialized) { |
| 1682 FakeSchedulerClient client; | 1694 scheduler_settings_.use_external_begin_frame_source = true; |
| 1683 SchedulerSettings scheduler_settings; | 1695 SetUpScheduler(false); |
| 1684 scheduler_settings.use_external_begin_frame_source = true; | 1696 |
| 1685 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1697 scheduler_->SetCanStart(); |
| 1686 scheduler->SetCanStart(); | 1698 scheduler_->SetVisible(true); |
| 1687 scheduler->SetVisible(true); | 1699 scheduler_->SetCanDraw(true); |
| 1688 scheduler->SetCanDraw(true); | 1700 |
| 1689 | 1701 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 1690 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1702 client_->Reset(); |
| 1691 client.Reset(); | 1703 scheduler_->DidCreateAndInitializeOutputSurface(); |
| 1692 scheduler->DidCreateAndInitializeOutputSurface(); | 1704 EXPECT_NO_ACTION(client_); |
| 1693 EXPECT_NO_ACTION(client); | 1705 |
| 1694 | 1706 scheduler_->DidLoseOutputSurface(); |
| 1695 scheduler->DidLoseOutputSurface(); | 1707 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 1696 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1708 } |
| 1697 } | 1709 |
| 1698 | 1710 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStarted) { |
| 1699 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStarted) { | 1711 scheduler_settings_.use_external_begin_frame_source = true; |
| 1700 FakeSchedulerClient client; | 1712 SetUpScheduler(true); |
| 1701 SchedulerSettings scheduler_settings; | |
| 1702 scheduler_settings.use_external_begin_frame_source = true; | |
| 1703 | |
| 1704 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1705 | 1713 |
| 1706 // SetNeedsCommit should begin the frame. | 1714 // SetNeedsCommit should begin the frame. |
| 1707 scheduler->SetNeedsCommit(); | 1715 scheduler_->SetNeedsCommit(); |
| 1708 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1716 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1709 | 1717 |
| 1710 client.Reset(); | 1718 client_->Reset(); |
| 1711 EXPECT_SCOPED(client.AdvanceFrame()); | 1719 EXPECT_SCOPED(AdvanceFrame()); |
| 1712 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1720 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1713 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1721 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1714 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1722 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1715 | 1723 |
| 1716 client.Reset(); | 1724 client_->Reset(); |
| 1717 scheduler->DidLoseOutputSurface(); | 1725 scheduler_->DidLoseOutputSurface(); |
| 1718 // Do nothing when impl frame is in deadine pending state. | 1726 // Do nothing when impl frame is in deadine pending state. |
| 1719 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1727 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 1720 | 1728 |
| 1721 client.Reset(); | 1729 client_->Reset(); |
| 1722 scheduler->NotifyBeginMainFrameStarted(); | 1730 scheduler_->NotifyBeginMainFrameStarted(); |
| 1723 scheduler->NotifyReadyToCommit(); | 1731 scheduler_->NotifyReadyToCommit(); |
| 1724 EXPECT_ACTION("ScheduledActionCommit", client, 0, 1); | 1732 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 1); |
| 1725 | 1733 |
| 1726 client.Reset(); | 1734 client_->Reset(); |
| 1727 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1735 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1728 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1736 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 1729 } | 1737 } |
| 1730 | 1738 |
| 1731 void DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( | 1739 void SchedulerTest::DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency( |
| 1732 bool impl_side_painting) { | 1740 bool impl_side_painting) { |
| 1733 FakeSchedulerClient client; | 1741 scheduler_settings_.impl_side_painting = impl_side_painting; |
| 1734 SchedulerSettings scheduler_settings; | 1742 scheduler_settings_.use_external_begin_frame_source = true; |
| 1735 scheduler_settings.impl_side_painting = impl_side_painting; | 1743 SetUpScheduler(true); |
| 1736 scheduler_settings.use_external_begin_frame_source = true; | |
| 1737 | |
| 1738 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1739 | 1744 |
| 1740 // SetNeedsCommit should begin the frame. | 1745 // SetNeedsCommit should begin the frame. |
| 1741 scheduler->SetNeedsCommit(); | 1746 scheduler_->SetNeedsCommit(); |
| 1742 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1747 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1743 | 1748 |
| 1744 client.Reset(); | 1749 client_->Reset(); |
| 1745 EXPECT_SCOPED(client.AdvanceFrame()); | 1750 EXPECT_SCOPED(AdvanceFrame()); |
| 1746 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1751 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1747 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1752 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1748 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1753 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1749 | 1754 |
| 1750 client.Reset(); | 1755 client_->Reset(); |
| 1751 scheduler->DidLoseOutputSurface(); | 1756 scheduler_->DidLoseOutputSurface(); |
| 1752 // Do nothing when impl frame is in deadine pending state. | 1757 // Do nothing when impl frame is in deadine pending state. |
| 1753 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1758 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 1754 | 1759 |
| 1755 client.Reset(); | 1760 client_->Reset(); |
| 1756 // Run posted deadline. | 1761 // Run posted deadline. |
| 1757 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1762 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1758 client.task_runner().RunTasksWhile(client.ImplFrameDeadlinePending(true)); | 1763 client_->task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); |
| 1759 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is | 1764 // OnBeginImplFrameDeadline didn't schedule any actions because main frame is |
| 1760 // not yet completed. | 1765 // not yet completed. |
| 1761 EXPECT_NO_ACTION(client); | 1766 EXPECT_NO_ACTION(client_); |
| 1762 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1767 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1763 | 1768 |
| 1764 // BeginImplFrame is not started. | 1769 // BeginImplFrame is not started. |
| 1765 client.task_runner().RunUntilTime(client.now_src()->Now() + | 1770 client_->task_runner().RunUntilTime(client_->now_src()->Now() + |
| 1766 base::TimeDelta::FromMilliseconds(10)); | 1771 base::TimeDelta::FromMilliseconds(10)); |
| 1767 EXPECT_NO_ACTION(client); | 1772 EXPECT_NO_ACTION(client_); |
| 1768 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1773 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1769 | 1774 |
| 1770 client.Reset(); | 1775 client_->Reset(); |
| 1771 scheduler->NotifyBeginMainFrameStarted(); | 1776 scheduler_->NotifyBeginMainFrameStarted(); |
| 1772 scheduler->NotifyReadyToCommit(); | 1777 scheduler_->NotifyReadyToCommit(); |
| 1773 if (impl_side_painting) { | 1778 if (impl_side_painting) { |
| 1774 EXPECT_ACTION("ScheduledActionCommit", client, 0, 3); | 1779 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
| 1775 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 3); | 1780 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
| 1776 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 2, 3); | 1781 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 2, 3); |
| 1777 } else { | 1782 } else { |
| 1778 EXPECT_ACTION("ScheduledActionCommit", client, 0, 2); | 1783 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); |
| 1779 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); | 1784 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 2); |
| 1780 } | 1785 } |
| 1781 } | 1786 } |
| 1782 | 1787 |
| 1783 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency) { | 1788 TEST_F(SchedulerTest, |
| 1789 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency) { | |
| 1784 bool impl_side_painting = false; | 1790 bool impl_side_painting = false; |
| 1785 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); | 1791 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); |
| 1786 } | 1792 } |
| 1787 | 1793 |
| 1788 TEST(SchedulerTest, | 1794 TEST_F(SchedulerTest, |
| 1789 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatencyWithImplPaint) { | 1795 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatencyWithImplPaint) { |
| 1790 bool impl_side_painting = true; | 1796 bool impl_side_painting = true; |
| 1791 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); | 1797 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency(impl_side_painting); |
| 1792 } | 1798 } |
| 1793 | 1799 |
| 1794 void DidLoseOutputSurfaceAfterReadyToCommit(bool impl_side_painting) { | 1800 void SchedulerTest::DidLoseOutputSurfaceAfterReadyToCommit( |
| 1795 FakeSchedulerClient client; | 1801 bool impl_side_painting) { |
| 1796 SchedulerSettings scheduler_settings; | 1802 scheduler_settings_.impl_side_painting = impl_side_painting; |
| 1797 scheduler_settings.impl_side_painting = impl_side_painting; | 1803 scheduler_settings_.use_external_begin_frame_source = true; |
| 1798 scheduler_settings.use_external_begin_frame_source = true; | 1804 SetUpScheduler(true); |
| 1799 | |
| 1800 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1801 | 1805 |
| 1802 // SetNeedsCommit should begin the frame. | 1806 // SetNeedsCommit should begin the frame. |
| 1803 scheduler->SetNeedsCommit(); | 1807 scheduler_->SetNeedsCommit(); |
| 1804 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1808 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1805 | 1809 |
| 1806 client.Reset(); | 1810 client_->Reset(); |
| 1807 EXPECT_SCOPED(client.AdvanceFrame()); | 1811 EXPECT_SCOPED(AdvanceFrame()); |
| 1808 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1812 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1809 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1813 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1810 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1814 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1811 | 1815 |
| 1812 client.Reset(); | 1816 client_->Reset(); |
| 1813 scheduler->NotifyBeginMainFrameStarted(); | 1817 scheduler_->NotifyBeginMainFrameStarted(); |
| 1814 scheduler->NotifyReadyToCommit(); | 1818 scheduler_->NotifyReadyToCommit(); |
| 1815 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1819 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1816 | 1820 |
| 1817 client.Reset(); | 1821 client_->Reset(); |
| 1818 scheduler->DidLoseOutputSurface(); | 1822 scheduler_->DidLoseOutputSurface(); |
| 1819 if (impl_side_painting) { | 1823 if (impl_side_painting) { |
| 1820 // Sync tree should be forced to activate. | 1824 // Sync tree should be forced to activate. |
| 1821 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 0, 2); | 1825 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 2); |
| 1822 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 1, 2); | 1826 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 2); |
| 1823 } else { | 1827 } else { |
| 1824 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1828 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 1825 } | 1829 } |
| 1826 | 1830 |
| 1827 client.Reset(); | 1831 client_->Reset(); |
| 1828 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1832 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1829 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1833 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 1830 } | 1834 } |
| 1831 | 1835 |
| 1832 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { | 1836 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { |
| 1833 DidLoseOutputSurfaceAfterReadyToCommit(false); | 1837 DidLoseOutputSurfaceAfterReadyToCommit(false); |
| 1834 } | 1838 } |
| 1835 | 1839 |
| 1836 TEST(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { | 1840 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommitWithImplPainting) { |
| 1837 DidLoseOutputSurfaceAfterReadyToCommit(true); | 1841 DidLoseOutputSurfaceAfterReadyToCommit(true); |
| 1838 } | 1842 } |
| 1839 | 1843 |
| 1840 TEST(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { | 1844 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { |
| 1841 FakeSchedulerClient client; | 1845 scheduler_settings_.use_external_begin_frame_source = true; |
| 1842 SchedulerSettings scheduler_settings; | 1846 SetUpScheduler(true); |
| 1843 scheduler_settings.use_external_begin_frame_source = true; | 1847 |
| 1844 | 1848 scheduler_->SetNeedsPrepareTiles(); |
| 1845 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 1849 scheduler_->SetNeedsRedraw(); |
| 1846 | 1850 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1847 scheduler->SetNeedsPrepareTiles(); | 1851 |
| 1848 scheduler->SetNeedsRedraw(); | 1852 client_->Reset(); |
| 1849 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1853 EXPECT_SCOPED(AdvanceFrame()); |
| 1850 | 1854 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1851 client.Reset(); | 1855 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1852 EXPECT_SCOPED(client.AdvanceFrame()); | 1856 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1853 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1857 |
| 1854 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1858 client_->Reset(); |
| 1855 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1859 scheduler_->DidLoseOutputSurface(); |
| 1856 | 1860 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 1857 client.Reset(); | 1861 |
| 1858 scheduler->DidLoseOutputSurface(); | 1862 client_->Reset(); |
| 1859 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1863 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1860 | 1864 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 2); |
| 1861 client.Reset(); | 1865 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 2); |
| 1862 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1866 } |
| 1863 EXPECT_ACTION("ScheduledActionPrepareTiles", client, 0, 2); | 1867 |
| 1864 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); | 1868 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { |
| 1865 } | 1869 scheduler_settings_.use_external_begin_frame_source = true; |
| 1866 | 1870 SetUpScheduler(true); |
| 1867 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { | |
| 1868 FakeSchedulerClient client; | |
| 1869 SchedulerSettings scheduler_settings; | |
| 1870 scheduler_settings.use_external_begin_frame_source = true; | |
| 1871 | |
| 1872 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1873 | 1871 |
| 1874 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1872 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1875 scheduler->SetNeedsCommit(); | 1873 scheduler_->SetNeedsCommit(); |
| 1876 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1874 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1877 | 1875 |
| 1878 // Create a BeginFrame with a long deadline to avoid race conditions. | 1876 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1879 // This is the first BeginFrame, which will be handled immediately. | 1877 // This is the first BeginFrame, which will be handled immediately. |
| 1880 client.Reset(); | 1878 client_->Reset(); |
| 1881 BeginFrameArgs args = | 1879 BeginFrameArgs args = |
| 1882 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1880 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client_->now_src()); |
| 1883 args.deadline += base::TimeDelta::FromHours(1); | 1881 args.deadline += base::TimeDelta::FromHours(1); |
| 1884 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1882 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1885 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1883 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1886 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1884 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1887 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1885 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1888 EXPECT_TRUE(client.needs_begin_frames()); | 1886 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1889 | 1887 |
| 1890 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1888 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1891 args.frame_time += base::TimeDelta::FromSeconds(1); | 1889 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1892 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1890 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1893 args.frame_time += base::TimeDelta::FromSeconds(1); | 1891 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1894 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1892 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1895 | 1893 |
| 1896 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1894 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 1897 client.Reset(); | 1895 client_->Reset(); |
| 1898 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1896 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1899 EXPECT_NO_ACTION(client); | 1897 EXPECT_NO_ACTION(client_); |
| 1900 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1898 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1901 EXPECT_TRUE(client.needs_begin_frames()); | 1899 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1902 | 1900 |
| 1903 // NotifyReadyToCommit should trigger the commit. | 1901 // NotifyReadyToCommit should trigger the commit. |
| 1904 client.Reset(); | 1902 client_->Reset(); |
| 1905 scheduler->NotifyBeginMainFrameStarted(); | 1903 scheduler_->NotifyBeginMainFrameStarted(); |
| 1906 scheduler->NotifyReadyToCommit(); | 1904 scheduler_->NotifyReadyToCommit(); |
| 1907 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1905 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1908 EXPECT_TRUE(client.needs_begin_frames()); | 1906 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1909 | 1907 |
| 1910 client.Reset(); | 1908 client_->Reset(); |
| 1911 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1909 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
| 1912 scheduler->DidLoseOutputSurface(); | 1910 scheduler_->DidLoseOutputSurface(); |
| 1913 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 0, 2); | 1911 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 2); |
| 1914 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 1, 2); | 1912 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 1, 2); |
| 1915 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1913 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
| 1916 | 1914 |
| 1917 // Posted BeginRetroFrame is aborted. | 1915 // Posted BeginRetroFrame is aborted. |
| 1918 client.Reset(); | 1916 client_->Reset(); |
| 1919 client.task_runner().RunPendingTasks(); | 1917 client_->task_runner().RunPendingTasks(); |
| 1920 EXPECT_NO_ACTION(client); | 1918 EXPECT_NO_ACTION(client_); |
| 1921 } | 1919 } |
| 1922 | 1920 |
| 1923 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { | 1921 TEST_F(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { |
| 1924 FakeSchedulerClient client; | 1922 scheduler_settings_.use_external_begin_frame_source = true; |
| 1925 SchedulerSettings scheduler_settings; | 1923 SetUpScheduler(true); |
| 1926 scheduler_settings.use_external_begin_frame_source = true; | |
| 1927 | |
| 1928 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1929 | 1924 |
| 1930 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1925 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1931 scheduler->SetNeedsCommit(); | 1926 scheduler_->SetNeedsCommit(); |
| 1932 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 1927 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 1933 | 1928 |
| 1934 // Create a BeginFrame with a long deadline to avoid race conditions. | 1929 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1935 // This is the first BeginFrame, which will be handled immediately. | 1930 // This is the first BeginFrame, which will be handled immediately. |
| 1936 client.Reset(); | 1931 client_->Reset(); |
| 1937 BeginFrameArgs args = | 1932 BeginFrameArgs args = |
| 1938 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client.now_src()); | 1933 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, client_->now_src()); |
| 1939 args.deadline += base::TimeDelta::FromHours(1); | 1934 args.deadline += base::TimeDelta::FromHours(1); |
| 1940 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1935 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1941 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1936 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1942 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1937 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1943 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1938 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1944 EXPECT_TRUE(client.needs_begin_frames()); | 1939 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1945 | 1940 |
| 1946 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1941 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1947 args.frame_time += base::TimeDelta::FromSeconds(1); | 1942 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1948 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1943 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1949 args.frame_time += base::TimeDelta::FromSeconds(1); | 1944 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1950 client.fake_external_begin_frame_source()->TestOnBeginFrame(args); | 1945 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 1951 | 1946 |
| 1952 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1947 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 1953 client.Reset(); | 1948 client_->Reset(); |
| 1954 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1949 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1955 EXPECT_NO_ACTION(client); | 1950 EXPECT_NO_ACTION(client_); |
| 1956 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1951 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1957 EXPECT_TRUE(client.needs_begin_frames()); | 1952 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1958 | 1953 |
| 1959 // NotifyReadyToCommit should trigger the commit. | 1954 // NotifyReadyToCommit should trigger the commit. |
| 1960 client.Reset(); | 1955 client_->Reset(); |
| 1961 scheduler->NotifyBeginMainFrameStarted(); | 1956 scheduler_->NotifyBeginMainFrameStarted(); |
| 1962 scheduler->NotifyReadyToCommit(); | 1957 scheduler_->NotifyReadyToCommit(); |
| 1963 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1958 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 1964 EXPECT_TRUE(client.needs_begin_frames()); | 1959 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1965 | 1960 |
| 1966 // BeginImplFrame should prepare the draw. | 1961 // BeginImplFrame should prepare the draw. |
| 1967 client.Reset(); | 1962 client_->Reset(); |
| 1968 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1963 client_->task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1969 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1964 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1970 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1965 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 1971 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1966 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1972 EXPECT_TRUE(client.needs_begin_frames()); | 1967 EXPECT_TRUE(client_->needs_begin_frames()); |
| 1973 | 1968 |
| 1974 client.Reset(); | 1969 client_->Reset(); |
| 1975 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1970 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
| 1976 scheduler->DidLoseOutputSurface(); | 1971 scheduler_->DidLoseOutputSurface(); |
| 1977 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client); | 1972 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(false)", client_); |
| 1978 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1973 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
| 1979 | 1974 |
| 1980 // BeginImplFrame deadline should abort drawing. | 1975 // BeginImplFrame deadline should abort drawing. |
| 1981 client.Reset(); | 1976 client_->Reset(); |
| 1982 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1977 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 1983 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1978 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 1984 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1979 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 1985 EXPECT_FALSE(client.needs_begin_frames()); | 1980 EXPECT_FALSE(client_->needs_begin_frames()); |
| 1986 | 1981 |
| 1987 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 1982 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. |
| 1988 client.Reset(); | 1983 client_->Reset(); |
| 1989 client.task_runner().RunPendingTasks(); | 1984 client_->task_runner().RunPendingTasks(); |
| 1990 EXPECT_NO_ACTION(client); | 1985 EXPECT_NO_ACTION(client_); |
| 1991 } | 1986 } |
| 1992 | 1987 |
| 1993 TEST(SchedulerTest, | 1988 TEST_F(SchedulerTest, |
| 1994 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { | 1989 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { |
| 1995 FakeSchedulerClient client; | 1990 SetUpScheduler(true); |
| 1996 SchedulerSettings scheduler_settings; | |
| 1997 | |
| 1998 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 1999 | 1991 |
| 2000 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1992 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 2001 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 1993 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); |
| 2002 scheduler->SetNeedsCommit(); | 1994 scheduler_->SetNeedsCommit(); |
| 2003 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); | 1995 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); |
| 2004 | 1996 |
| 2005 client.Reset(); | 1997 client_->Reset(); |
| 2006 client.task_runner().RunPendingTasks(); // Run posted Tick. | 1998 client_->task_runner().RunPendingTasks(); // Run posted Tick. |
| 2007 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1999 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2008 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 2000 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2009 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2001 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2010 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); | 2002 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); |
| 2011 | 2003 |
| 2012 // NotifyReadyToCommit should trigger the commit. | 2004 // NotifyReadyToCommit should trigger the commit. |
| 2013 client.Reset(); | 2005 client_->Reset(); |
| 2014 scheduler->NotifyBeginMainFrameStarted(); | 2006 scheduler_->NotifyBeginMainFrameStarted(); |
| 2015 scheduler->NotifyReadyToCommit(); | 2007 scheduler_->NotifyReadyToCommit(); |
| 2016 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 2008 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2017 EXPECT_TRUE(scheduler->frame_source().NeedsBeginFrames()); | 2009 EXPECT_TRUE(scheduler_->frame_source().NeedsBeginFrames()); |
| 2018 | 2010 |
| 2019 client.Reset(); | 2011 client_->Reset(); |
| 2020 scheduler->DidLoseOutputSurface(); | 2012 scheduler_->DidLoseOutputSurface(); |
| 2021 EXPECT_NO_ACTION(client); | 2013 EXPECT_NO_ACTION(client_); |
| 2022 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 2014 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); |
| 2023 | 2015 |
| 2024 client.Reset(); | 2016 client_->Reset(); |
| 2025 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2017 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 2026 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 2018 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 2027 EXPECT_FALSE(scheduler->frame_source().NeedsBeginFrames()); | 2019 EXPECT_FALSE(scheduler_->frame_source().NeedsBeginFrames()); |
| 2028 } | 2020 } |
| 2029 | 2021 |
| 2030 TEST(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { | 2022 TEST_F(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { |
| 2031 FakeSchedulerClient client; | 2023 scheduler_settings_.impl_side_painting = true; |
| 2032 SchedulerSettings scheduler_settings; | 2024 scheduler_settings_.use_external_begin_frame_source = true; |
| 2033 scheduler_settings.impl_side_painting = true; | 2025 SetUpScheduler(true); |
| 2034 scheduler_settings.use_external_begin_frame_source = true; | |
| 2035 | |
| 2036 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 2037 | 2026 |
| 2038 // SetNeedsCommit should begin the frame. | 2027 // SetNeedsCommit should begin the frame. |
| 2039 scheduler->SetNeedsCommit(); | 2028 scheduler_->SetNeedsCommit(); |
| 2040 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 2029 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 2041 | 2030 |
| 2042 client.Reset(); | 2031 client_->Reset(); |
| 2043 EXPECT_SCOPED(client.AdvanceFrame()); | 2032 EXPECT_SCOPED(AdvanceFrame()); |
| 2044 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2033 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2045 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 2034 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2046 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2035 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2047 | 2036 |
| 2048 client.Reset(); | 2037 client_->Reset(); |
| 2049 scheduler->NotifyBeginMainFrameStarted(); | 2038 scheduler_->NotifyBeginMainFrameStarted(); |
| 2050 scheduler->NotifyReadyToCommit(); | 2039 scheduler_->NotifyReadyToCommit(); |
| 2051 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 2040 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2052 | 2041 |
| 2053 client.Reset(); | 2042 client_->Reset(); |
| 2054 scheduler->SetVisible(false); | 2043 scheduler_->SetVisible(false); |
| 2055 // Sync tree should be forced to activate. | 2044 // Sync tree should be forced to activate. |
| 2056 EXPECT_ACTION("SetNeedsBeginFrames(false)", client, 0, 2); | 2045 EXPECT_ACTION("SetNeedsBeginFrames(false)", client_, 0, 2); |
| 2057 EXPECT_ACTION("ScheduledActionActivateSyncTree", client, 1, 2); | 2046 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); |
| 2058 } | 2047 } |
| 2059 | 2048 |
| 2060 TEST(SchedulerTest, SchedulerPowerMonitoring) { | 2049 TEST_F(SchedulerTest, SchedulerPowerMonitoring) { |
| 2061 FakeSchedulerClient client; | 2050 scheduler_settings_.disable_hi_res_timer_tasks_on_battery = true; |
| 2062 SchedulerSettings settings; | 2051 SetUpScheduler(true); |
| 2063 settings.disable_hi_res_timer_tasks_on_battery = true; | |
| 2064 | |
| 2065 CREATE_SCHEDULER_AND_INIT_SURFACE(settings); | |
| 2066 | 2052 |
| 2067 base::TimeTicks before_deadline, after_deadline; | 2053 base::TimeTicks before_deadline, after_deadline; |
| 2068 | 2054 |
| 2069 scheduler->SetNeedsCommit(); | 2055 scheduler_->SetNeedsCommit(); |
| 2070 scheduler->SetNeedsRedraw(); | 2056 scheduler_->SetNeedsRedraw(); |
| 2071 client.Reset(); | 2057 client_->Reset(); |
| 2072 | 2058 |
| 2073 // On non-battery power | 2059 // On non-battery power |
| 2074 EXPECT_FALSE(client.PowerMonitor()->IsOnBatteryPower()); | 2060 EXPECT_FALSE(PowerMonitor()->IsOnBatteryPower()); |
| 2075 | 2061 |
| 2076 EXPECT_SCOPED(client.AdvanceFrame()); | 2062 EXPECT_SCOPED(AdvanceFrame()); |
| 2077 client.Reset(); | 2063 client_->Reset(); |
| 2078 | 2064 |
| 2079 before_deadline = client.now_src()->Now(); | 2065 before_deadline = client_->now_src()->Now(); |
| 2080 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2066 EXPECT_TRUE(client_->task_runner().RunTasksWhile( |
| 2081 client.ImplFrameDeadlinePending(true))); | 2067 client_->ImplFrameDeadlinePending(true))); |
| 2082 after_deadline = client.now_src()->Now(); | 2068 after_deadline = client_->now_src()->Now(); |
| 2083 | 2069 |
| 2084 // We post a non-zero deadline task when not on battery | 2070 // We post a non-zero deadline task when not on battery |
| 2085 EXPECT_LT(before_deadline, after_deadline); | 2071 EXPECT_LT(before_deadline, after_deadline); |
| 2086 | 2072 |
| 2087 // Switch to battery power | 2073 // Switch to battery power |
| 2088 client.PowerMonitorSource()->GeneratePowerStateEvent(true); | 2074 PowerMonitorSource()->GeneratePowerStateEvent(true); |
| 2089 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); | 2075 EXPECT_TRUE(PowerMonitor()->IsOnBatteryPower()); |
| 2090 | 2076 |
| 2091 EXPECT_SCOPED(client.AdvanceFrame()); | 2077 EXPECT_SCOPED(AdvanceFrame()); |
| 2092 scheduler->SetNeedsCommit(); | 2078 scheduler_->SetNeedsCommit(); |
| 2093 scheduler->SetNeedsRedraw(); | 2079 scheduler_->SetNeedsRedraw(); |
| 2094 client.Reset(); | 2080 client_->Reset(); |
| 2095 | 2081 |
| 2096 before_deadline = client.now_src()->Now(); | 2082 before_deadline = client_->now_src()->Now(); |
| 2097 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2083 EXPECT_TRUE(client_->task_runner().RunTasksWhile( |
| 2098 client.ImplFrameDeadlinePending(true))); | 2084 client_->ImplFrameDeadlinePending(true))); |
| 2099 after_deadline = client.now_src()->Now(); | 2085 after_deadline = client_->now_src()->Now(); |
| 2100 | 2086 |
| 2101 // We post a zero deadline task when on battery | 2087 // We post a zero deadline task when on battery |
| 2102 EXPECT_EQ(before_deadline, after_deadline); | 2088 EXPECT_EQ(before_deadline, after_deadline); |
| 2103 | 2089 |
| 2104 // Switch to non-battery power | 2090 // Switch to non-battery power |
| 2105 client.PowerMonitorSource()->GeneratePowerStateEvent(false); | 2091 PowerMonitorSource()->GeneratePowerStateEvent(false); |
| 2106 EXPECT_FALSE(client.PowerMonitor()->IsOnBatteryPower()); | 2092 EXPECT_FALSE(PowerMonitor()->IsOnBatteryPower()); |
| 2107 | 2093 |
| 2108 EXPECT_SCOPED(client.AdvanceFrame()); | 2094 EXPECT_SCOPED(AdvanceFrame()); |
| 2109 scheduler->SetNeedsCommit(); | 2095 scheduler_->SetNeedsCommit(); |
| 2110 scheduler->SetNeedsRedraw(); | 2096 scheduler_->SetNeedsRedraw(); |
| 2111 client.Reset(); | 2097 client_->Reset(); |
| 2112 | 2098 |
| 2113 // Same as before | 2099 // Same as before |
| 2114 before_deadline = client.now_src()->Now(); | 2100 before_deadline = client_->now_src()->Now(); |
| 2115 EXPECT_TRUE(client.task_runner().RunTasksWhile( | 2101 EXPECT_TRUE(client_->task_runner().RunTasksWhile( |
| 2116 client.ImplFrameDeadlinePending(true))); | 2102 client_->ImplFrameDeadlinePending(true))); |
| 2117 after_deadline = client.now_src()->Now(); | 2103 after_deadline = client_->now_src()->Now(); |
| 2118 } | 2104 } |
| 2119 | 2105 |
| 2120 TEST(SchedulerTest, | 2106 TEST_F(SchedulerTest, |
| 2121 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) { | 2107 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOff) { |
| 2122 FakeSchedulerClient client; | 2108 scheduler_settings_.use_external_begin_frame_source = true; |
| 2123 SchedulerSettings settings; | 2109 SetUpScheduler(true); |
| 2124 settings.use_external_begin_frame_source = true; | |
| 2125 | |
| 2126 CREATE_SCHEDULER_AND_INIT_SURFACE(settings); | |
| 2127 | 2110 |
| 2128 // Set needs commit so that the scheduler tries to wait for the main thread | 2111 // Set needs commit so that the scheduler tries to wait for the main thread |
| 2129 scheduler->SetNeedsCommit(); | 2112 scheduler_->SetNeedsCommit(); |
| 2130 // Set needs redraw so that the scheduler doesn't wait too long | 2113 // Set needs redraw so that the scheduler doesn't wait too long |
| 2131 scheduler->SetNeedsRedraw(); | 2114 scheduler_->SetNeedsRedraw(); |
| 2132 client.Reset(); | 2115 client_->Reset(); |
| 2133 | 2116 |
| 2134 // Switch to battery power | 2117 // Switch to battery power |
| 2135 client.PowerMonitorSource()->GeneratePowerStateEvent(true); | 2118 PowerMonitorSource()->GeneratePowerStateEvent(true); |
| 2136 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); | 2119 EXPECT_TRUE(PowerMonitor()->IsOnBatteryPower()); |
| 2137 | 2120 |
| 2138 EXPECT_SCOPED(client.AdvanceFrame()); | 2121 EXPECT_SCOPED(AdvanceFrame()); |
| 2139 scheduler->SetNeedsCommit(); | 2122 scheduler_->SetNeedsCommit(); |
| 2140 scheduler->SetNeedsRedraw(); | 2123 scheduler_->SetNeedsRedraw(); |
| 2141 client.Reset(); | 2124 client_->Reset(); |
| 2142 | 2125 |
| 2143 // Disable auto-advancing of now_src | 2126 // Disable auto-advancing of now_src |
| 2144 client.task_runner().SetAutoAdvanceNowToPendingTasks(false); | 2127 client_->task_runner().SetAutoAdvanceNowToPendingTasks(false); |
| 2145 | 2128 |
| 2146 // Deadline task is pending | 2129 // Deadline task is pending |
| 2147 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2130 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2148 client.task_runner().RunPendingTasks(); | 2131 client_->task_runner().RunPendingTasks(); |
| 2149 // Deadline task is still pending | 2132 // Deadline task is still pending |
| 2150 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2133 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2151 | 2134 |
| 2152 // Advance now by 15 ms - same as windows low res timer | 2135 // Advance now by 15 ms - same as windows low res timer |
| 2153 client.now_src()->AdvanceNowMicroseconds(15000); | 2136 client_->now_src()->AdvanceNowMicroseconds(15000); |
| 2154 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2137 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2155 client.task_runner().RunPendingTasks(); | 2138 client_->task_runner().RunPendingTasks(); |
| 2156 // Deadline task finally completes | 2139 // Deadline task finally completes |
| 2157 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2140 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2158 } | 2141 } |
| 2159 | 2142 |
| 2160 TEST(SchedulerTest, | 2143 TEST_F(SchedulerTest, |
| 2161 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) { | 2144 SimulateWindowsLowResolutionTimerOnBattery_PrioritizeImplLatencyOn) { |
| 2162 FakeSchedulerClient client; | 2145 scheduler_settings_.disable_hi_res_timer_tasks_on_battery = true; |
| 2163 SchedulerSettings settings; | 2146 scheduler_settings_.use_external_begin_frame_source = true; |
| 2164 settings.disable_hi_res_timer_tasks_on_battery = true; | 2147 SetUpScheduler(true); |
| 2165 settings.use_external_begin_frame_source = true; | |
| 2166 | |
| 2167 CREATE_SCHEDULER_AND_INIT_SURFACE(settings); | |
| 2168 | 2148 |
| 2169 // Set needs commit so that the scheduler tries to wait for the main thread | 2149 // Set needs commit so that the scheduler tries to wait for the main thread |
| 2170 scheduler->SetNeedsCommit(); | 2150 scheduler_->SetNeedsCommit(); |
| 2171 // Set needs redraw so that the scheduler doesn't wait too long | 2151 // Set needs redraw so that the scheduler doesn't wait too long |
| 2172 scheduler->SetNeedsRedraw(); | 2152 scheduler_->SetNeedsRedraw(); |
| 2173 client.Reset(); | 2153 client_->Reset(); |
| 2174 | 2154 |
| 2175 // Switch to battery power | 2155 // Switch to battery power |
| 2176 client.PowerMonitorSource()->GeneratePowerStateEvent(true); | 2156 PowerMonitorSource()->GeneratePowerStateEvent(true); |
| 2177 EXPECT_TRUE(client.PowerMonitor()->IsOnBatteryPower()); | 2157 EXPECT_TRUE(PowerMonitor()->IsOnBatteryPower()); |
| 2178 | 2158 |
| 2179 EXPECT_SCOPED(client.AdvanceFrame()); | 2159 EXPECT_SCOPED(AdvanceFrame()); |
| 2180 scheduler->SetNeedsCommit(); | 2160 scheduler_->SetNeedsCommit(); |
| 2181 scheduler->SetNeedsRedraw(); | 2161 scheduler_->SetNeedsRedraw(); |
| 2182 client.Reset(); | 2162 client_->Reset(); |
| 2183 | 2163 |
| 2184 // Disable auto-advancing of now_src | 2164 // Disable auto-advancing of now_src |
| 2185 client.task_runner().SetAutoAdvanceNowToPendingTasks(false); | 2165 client_->task_runner().SetAutoAdvanceNowToPendingTasks(false); |
| 2186 | 2166 |
| 2187 // Deadline task is pending | 2167 // Deadline task is pending |
| 2188 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2168 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2189 client.task_runner().RunPendingTasks(); | 2169 client_->task_runner().RunPendingTasks(); |
| 2190 // Deadline task runs immediately | 2170 // Deadline task runs immediately |
| 2191 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2171 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2192 } | 2172 } |
| 2193 | 2173 |
| 2194 // Tests to ensure frame sources can be successfully changed while drawing. | 2174 // Tests to ensure frame sources can be successfully changed while drawing. |
| 2195 TEST(SchedulerTest, SwitchFrameSourceToUnthrottled) { | 2175 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottled) { |
| 2196 FakeSchedulerClient client; | 2176 scheduler_settings_.use_external_begin_frame_source = true; |
| 2197 SchedulerSettings scheduler_settings; | 2177 SetUpScheduler(true); |
| 2198 scheduler_settings.use_external_begin_frame_source = true; | |
| 2199 | |
| 2200 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 2201 | 2178 |
| 2202 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2179 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2203 scheduler->SetNeedsRedraw(); | 2180 scheduler_->SetNeedsRedraw(); |
| 2204 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 2181 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 2205 client.Reset(); | 2182 client_->Reset(); |
| 2206 | 2183 |
| 2207 EXPECT_SCOPED(client.AdvanceFrame()); | 2184 EXPECT_SCOPED(AdvanceFrame()); |
| 2208 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2185 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2209 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2186 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 2210 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2187 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2211 EXPECT_TRUE(client.needs_begin_frames()); | 2188 EXPECT_TRUE(client_->needs_begin_frames()); |
| 2212 client.Reset(); | 2189 client_->Reset(); |
| 2213 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2190 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 2214 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 2191 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2215 scheduler->SetNeedsRedraw(); | 2192 scheduler_->SetNeedsRedraw(); |
| 2216 | 2193 |
| 2217 // Switch to an unthrottled frame source. | 2194 // Switch to an unthrottled frame source. |
| 2218 scheduler->SetThrottleFrameProduction(false); | 2195 scheduler_->SetThrottleFrameProduction(false); |
| 2219 client.Reset(); | 2196 client_->Reset(); |
| 2220 | 2197 |
| 2221 // Unthrottled frame source will immediately begin a new frame. | 2198 // Unthrottled frame source will immediately begin a new frame. |
| 2222 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2199 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2223 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2200 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2224 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2201 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 2225 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2202 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2226 client.Reset(); | 2203 client_->Reset(); |
| 2227 | 2204 |
| 2228 // If we don't swap on the deadline, we wait for the next BeginFrame. | 2205 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 2229 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2206 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 2230 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 2207 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2231 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2208 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2232 client.Reset(); | 2209 client_->Reset(); |
| 2233 } | 2210 } |
| 2234 | 2211 |
| 2235 // Tests to ensure frame sources can be successfully changed while a frame | 2212 // Tests to ensure frame sources can be successfully changed while a frame |
| 2236 // deadline is pending. | 2213 // deadline is pending. |
| 2237 TEST(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { | 2214 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { |
| 2238 FakeSchedulerClient client; | 2215 scheduler_settings_.use_external_begin_frame_source = true; |
| 2239 SchedulerSettings scheduler_settings; | 2216 SetUpScheduler(true); |
| 2240 scheduler_settings.use_external_begin_frame_source = true; | |
| 2241 | |
| 2242 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | |
| 2243 | 2217 |
| 2244 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2218 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2245 scheduler->SetNeedsRedraw(); | 2219 scheduler_->SetNeedsRedraw(); |
| 2246 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client); | 2220 EXPECT_SINGLE_ACTION("SetNeedsBeginFrames(true)", client_); |
| 2247 client.Reset(); | 2221 client_->Reset(); |
| 2248 | 2222 |
| 2249 EXPECT_SCOPED(client.AdvanceFrame()); | 2223 EXPECT_SCOPED(AdvanceFrame()); |
| 2250 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2224 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2251 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2225 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 2252 | 2226 |
| 2253 // Switch to an unthrottled frame source before the frame deadline is hit. | 2227 // Switch to an unthrottled frame source before the frame deadline is hit. |
| 2254 scheduler->SetThrottleFrameProduction(false); | 2228 scheduler_->SetThrottleFrameProduction(false); |
| 2255 client.Reset(); | 2229 client_->Reset(); |
| 2256 | 2230 |
| 2257 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2231 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2258 EXPECT_TRUE(client.needs_begin_frames()); | 2232 EXPECT_TRUE(client_->needs_begin_frames()); |
| 2259 client.Reset(); | 2233 client_->Reset(); |
| 2260 | 2234 |
| 2261 client.task_runner() | 2235 client_->task_runner() |
| 2262 .RunPendingTasks(); // Run posted deadline and BeginFrame. | 2236 .RunPendingTasks(); // Run posted deadline and BeginFrame. |
| 2263 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 2237 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); |
| 2264 // Unthrottled frame source will immediately begin a new frame. | 2238 // Unthrottled frame source will immediately begin a new frame. |
| 2265 EXPECT_ACTION("WillBeginImplFrame", client, 1, 2); | 2239 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); |
| 2266 scheduler->SetNeedsRedraw(); | 2240 scheduler_->SetNeedsRedraw(); |
| 2267 client.Reset(); | 2241 client_->Reset(); |
| 2268 | 2242 |
| 2269 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2243 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 2270 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 2244 EXPECT_ACTION("ScheduledActionAnimate", client_, 0, 2); |
| 2271 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 2245 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 2272 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 2246 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2273 client.Reset(); | 2247 client_->Reset(); |
| 2274 } | 2248 } |
| 2275 | 2249 |
| 2276 // Tests to ensure that the active frame source can successfully be changed from | 2250 // Tests to ensure that the active frame source can successfully be changed from |
| 2277 // unthrottled to throttled. | 2251 // unthrottled to throttled. |
| 2278 TEST(SchedulerTest, SwitchFrameSourceToThrottled) { | 2252 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) { |
| 2279 FakeSchedulerClient client; | 2253 scheduler_settings_.throttle_frame_production = false; |
| 2280 SchedulerSettings scheduler_settings; | 2254 scheduler_settings_.use_external_begin_frame_source = true; |
| 2281 scheduler_settings.throttle_frame_production = false; | 2255 SetUpScheduler(true); |
| 2282 scheduler_settings.use_external_begin_frame_source = true; | 2256 |
| 2283 | 2257 scheduler_->SetNeedsRedraw(); |
| 2284 CREATE_SCHEDULER_AND_INIT_SURFACE(scheduler_settings); | 2258 EXPECT_NO_ACTION(client_); |
| 2285 | 2259 client_->Reset(); |
| 2286 scheduler->SetNeedsRedraw(); | 2260 |
| 2287 EXPECT_NO_ACTION(client); | 2261 client_->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2288 client.Reset(); | 2262 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2289 | 2263 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 2290 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2264 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2291 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2265 client_->Reset(); |
| 2292 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2266 |
| 2293 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2267 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 2294 client.Reset(); | 2268 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2295 | 2269 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2296 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2270 client_->Reset(); |
| 2297 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | |
| 2298 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | |
| 2299 client.Reset(); | |
| 2300 | 2271 |
| 2301 // Switch to a throttled frame source. | 2272 // Switch to a throttled frame source. |
| 2302 scheduler->SetThrottleFrameProduction(true); | 2273 scheduler_->SetThrottleFrameProduction(true); |
| 2303 client.Reset(); | 2274 client_->Reset(); |
| 2304 | 2275 |
| 2305 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2276 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2306 scheduler->SetNeedsRedraw(); | 2277 scheduler_->SetNeedsRedraw(); |
| 2307 client.task_runner().RunPendingTasks(); | 2278 client_->task_runner().RunPendingTasks(); |
| 2308 EXPECT_NO_ACTION(client); | 2279 EXPECT_NO_ACTION(client_); |
| 2309 client.Reset(); | 2280 client_->Reset(); |
| 2310 | 2281 |
| 2311 EXPECT_SCOPED(client.AdvanceFrame()); | 2282 EXPECT_SCOPED(AdvanceFrame()); |
| 2312 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 2283 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2313 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 2284 EXPECT_ACTION("ScheduledActionAnimate", client_, 1, 2); |
| 2314 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 2285 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); |
| 2315 EXPECT_TRUE(client.needs_begin_frames()); | 2286 EXPECT_TRUE(client_->needs_begin_frames()); |
| 2316 client.Reset(); | 2287 client_->Reset(); |
| 2317 client.task_runner().RunPendingTasks(); // Run posted deadline. | 2288 client_->task_runner().RunPendingTasks(); // Run posted deadline. |
| 2318 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 2289 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2319 } | 2290 } |
| 2320 | 2291 |
| 2321 } // namespace | 2292 } // namespace |
| 2322 } // namespace cc | 2293 } // namespace cc |
| OLD | NEW |