| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ | 26 #define EXPECT_ACTION(action, client, action_index, expected_num_actions) \ |
| 27 do { \ | 27 do { \ |
| 28 EXPECT_EQ(expected_num_actions, client->num_actions_()); \ | 28 EXPECT_EQ(expected_num_actions, client->num_actions_()); \ |
| 29 if (action_index >= 0) { \ | 29 if (action_index >= 0) { \ |
| 30 ASSERT_LT(action_index, client->num_actions_()) << scheduler_.get(); \ | 30 ASSERT_LT(action_index, client->num_actions_()) << scheduler_.get(); \ |
| 31 EXPECT_STREQ(action, client->Action(action_index)); \ | 31 EXPECT_STREQ(action, client->Action(action_index)); \ |
| 32 } \ | 32 } \ |
| 33 for (int i = expected_num_actions; i < client->num_actions_(); ++i) \ | 33 for (int i = expected_num_actions; i < client->num_actions_(); ++i) \ |
| 34 ADD_FAILURE() << "Unexpected action: " << client->Action(i) \ | 34 ADD_FAILURE() << "Unexpected action: " << client->Action(i) \ |
| 35 << " with state:\n" << client->StateForAction(i); \ | 35 << " with state:\n" \ |
| 36 << client->StateForAction(i); \ |
| 36 } while (false) | 37 } while (false) |
| 37 | 38 |
| 38 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) | 39 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) |
| 39 | 40 |
| 40 #define EXPECT_SINGLE_ACTION(action, client) \ | 41 #define EXPECT_SINGLE_ACTION(action, client) EXPECT_ACTION(action, client, 0, 1) |
| 41 EXPECT_ACTION(action, client, 0, 1) | |
| 42 | 42 |
| 43 #define EXPECT_SCOPED(statements) \ | 43 #define EXPECT_SCOPED(statements) \ |
| 44 { \ | 44 { \ |
| 45 SCOPED_TRACE(""); \ | 45 SCOPED_TRACE(""); \ |
| 46 statements; \ | 46 statements; \ |
| 47 } | 47 } |
| 48 | 48 |
| 49 namespace cc { | 49 namespace cc { |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 base::TimeDelta kSlowDuration = base::TimeDelta::FromSeconds(1); | 52 base::TimeDelta kSlowDuration = base::TimeDelta::FromSeconds(1); |
| 53 base::TimeDelta kFastDuration = base::TimeDelta::FromMilliseconds(1); | 53 base::TimeDelta kFastDuration = base::TimeDelta::FromMilliseconds(1); |
| 54 | 54 |
| 55 class FakeSchedulerClient : public SchedulerClient, | 55 class FakeSchedulerClient : public SchedulerClient, |
| 56 public FakeExternalBeginFrameSource::Client { | 56 public FakeExternalBeginFrameSource::Client { |
| 57 public: | 57 public: |
| 58 FakeSchedulerClient() | 58 FakeSchedulerClient() |
| 59 : automatic_swap_ack_(true), | 59 : inside_begin_impl_frame_(false), |
| 60 automatic_swap_ack_(true), |
| 60 scheduler_(nullptr) { | 61 scheduler_(nullptr) { |
| 61 Reset(); | 62 Reset(); |
| 62 } | 63 } |
| 63 | 64 |
| 64 void Reset() { | 65 void Reset() { |
| 65 actions_.clear(); | 66 actions_.clear(); |
| 66 states_.clear(); | 67 states_.clear(); |
| 67 will_begin_impl_frame_causes_redraw_ = false; | 68 will_begin_impl_frame_causes_redraw_ = false; |
| 68 will_begin_impl_frame_requests_one_begin_impl_frame_ = false; | 69 will_begin_impl_frame_requests_one_begin_impl_frame_ = false; |
| 69 draw_will_happen_ = true; | 70 draw_will_happen_ = true; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 83 return posted_begin_impl_frame_deadline_; | 84 return posted_begin_impl_frame_deadline_; |
| 84 } | 85 } |
| 85 | 86 |
| 86 int ActionIndex(const char* action) const { | 87 int ActionIndex(const char* action) const { |
| 87 for (size_t i = 0; i < actions_.size(); i++) | 88 for (size_t i = 0; i < actions_.size(); i++) |
| 88 if (!strcmp(actions_[i], action)) | 89 if (!strcmp(actions_[i], action)) |
| 89 return base::checked_cast<int>(i); | 90 return base::checked_cast<int>(i); |
| 90 return -1; | 91 return -1; |
| 91 } | 92 } |
| 92 | 93 |
| 93 bool HasAction(const char* action) const { | 94 bool HasAction(const char* action) const { return ActionIndex(action) >= 0; } |
| 94 return ActionIndex(action) >= 0; | |
| 95 } | |
| 96 | 95 |
| 97 void SetWillBeginImplFrameRequestsOneBeginImplFrame(bool request) { | 96 void SetWillBeginImplFrameRequestsOneBeginImplFrame(bool request) { |
| 98 will_begin_impl_frame_requests_one_begin_impl_frame_ = request; | 97 will_begin_impl_frame_requests_one_begin_impl_frame_ = request; |
| 99 } | 98 } |
| 100 void SetWillBeginImplFrameCausesRedraw(bool causes_redraw) { | 99 void SetWillBeginImplFrameCausesRedraw(bool causes_redraw) { |
| 101 will_begin_impl_frame_causes_redraw_ = causes_redraw; | 100 will_begin_impl_frame_causes_redraw_ = causes_redraw; |
| 102 } | 101 } |
| 103 void SetDrawWillHappen(bool draw_will_happen) { | 102 void SetDrawWillHappen(bool draw_will_happen) { |
| 104 draw_will_happen_ = draw_will_happen; | 103 draw_will_happen_ = draw_will_happen; |
| 105 } | 104 } |
| 106 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 105 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
| 107 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 106 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
| 108 } | 107 } |
| 109 void SetAutomaticSwapAck(bool automatic_swap_ack) { | 108 void SetAutomaticSwapAck(bool automatic_swap_ack) { |
| 110 automatic_swap_ack_ = automatic_swap_ack; | 109 automatic_swap_ack_ = automatic_swap_ack; |
| 111 } | 110 } |
| 112 // SchedulerClient implementation. | 111 // SchedulerClient implementation. |
| 113 void WillBeginImplFrame(const BeginFrameArgs& args) override { | 112 void WillBeginImplFrame(const BeginFrameArgs& args) override { |
| 113 EXPECT_FALSE(inside_begin_impl_frame_); |
| 114 inside_begin_impl_frame_ = true; |
| 114 PushAction("WillBeginImplFrame"); | 115 PushAction("WillBeginImplFrame"); |
| 115 if (will_begin_impl_frame_requests_one_begin_impl_frame_) | 116 if (will_begin_impl_frame_requests_one_begin_impl_frame_) |
| 116 scheduler_->SetNeedsOneBeginImplFrame(); | 117 scheduler_->SetNeedsOneBeginImplFrame(); |
| 117 if (will_begin_impl_frame_causes_redraw_) | 118 if (will_begin_impl_frame_causes_redraw_) |
| 118 scheduler_->SetNeedsRedraw(); | 119 scheduler_->SetNeedsRedraw(); |
| 119 } | 120 } |
| 120 void DidFinishImplFrame() override {} | 121 void DidFinishImplFrame() override { |
| 122 EXPECT_TRUE(inside_begin_impl_frame_); |
| 123 inside_begin_impl_frame_ = false; |
| 124 } |
| 121 | 125 |
| 122 void ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) override { | 126 void ScheduledActionSendBeginMainFrame(const BeginFrameArgs& args) override { |
| 123 PushAction("ScheduledActionSendBeginMainFrame"); | 127 PushAction("ScheduledActionSendBeginMainFrame"); |
| 124 last_begin_main_frame_args_ = args; | 128 last_begin_main_frame_args_ = args; |
| 125 } | 129 } |
| 126 | 130 |
| 127 const BeginFrameArgs& last_begin_main_frame_args() { | 131 const BeginFrameArgs& last_begin_main_frame_args() { |
| 128 return last_begin_main_frame_args_; | 132 return last_begin_main_frame_args_; |
| 129 } | 133 } |
| 130 | 134 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 } | 168 } |
| 165 void ScheduledActionInvalidateOutputSurface() override { | 169 void ScheduledActionInvalidateOutputSurface() override { |
| 166 actions_.push_back("ScheduledActionInvalidateOutputSurface"); | 170 actions_.push_back("ScheduledActionInvalidateOutputSurface"); |
| 167 states_.push_back(scheduler_->AsValue()); | 171 states_.push_back(scheduler_->AsValue()); |
| 168 } | 172 } |
| 169 | 173 |
| 170 void SendBeginMainFrameNotExpectedSoon() override { | 174 void SendBeginMainFrameNotExpectedSoon() override { |
| 171 PushAction("SendBeginMainFrameNotExpectedSoon"); | 175 PushAction("SendBeginMainFrameNotExpectedSoon"); |
| 172 } | 176 } |
| 173 | 177 |
| 174 base::Callback<bool(void)> ImplFrameDeadlinePending(bool state) { | 178 bool IsInsideBeginImplFrame() const { return inside_begin_impl_frame_; } |
| 175 return base::Bind(&FakeSchedulerClient::ImplFrameDeadlinePendingCallback, | 179 |
| 176 base::Unretained(this), | 180 base::Callback<bool(void)> InsideBeginImplFrame(bool state) { |
| 177 state); | 181 return base::Bind(&FakeSchedulerClient::InsideBeginImplFrameCallback, |
| 182 base::Unretained(this), state); |
| 178 } | 183 } |
| 179 | 184 |
| 180 void PushAction(const char* description) { | 185 void PushAction(const char* description) { |
| 181 actions_.push_back(description); | 186 actions_.push_back(description); |
| 182 states_.push_back(scheduler_->AsValue()); | 187 states_.push_back(scheduler_->AsValue()); |
| 183 } | 188 } |
| 184 | 189 |
| 185 // FakeExternalBeginFrameSource::Client implementation. | 190 // FakeExternalBeginFrameSource::Client implementation. |
| 186 void OnAddObserver(BeginFrameObserver* obs) override { | 191 void OnAddObserver(BeginFrameObserver* obs) override { |
| 187 PushAction("AddObserver(this)"); | 192 PushAction("AddObserver(this)"); |
| 188 } | 193 } |
| 189 void OnRemoveObserver(BeginFrameObserver* obs) override { | 194 void OnRemoveObserver(BeginFrameObserver* obs) override { |
| 190 PushAction("RemoveObserver(this)"); | 195 PushAction("RemoveObserver(this)"); |
| 191 } | 196 } |
| 192 | 197 |
| 193 protected: | 198 protected: |
| 194 bool ImplFrameDeadlinePendingCallback(bool state) { | 199 bool InsideBeginImplFrameCallback(bool state) { |
| 195 return scheduler_->BeginImplFrameDeadlinePending() == state; | 200 return inside_begin_impl_frame_ == state; |
| 196 } | 201 } |
| 197 | 202 |
| 203 bool inside_begin_impl_frame_; |
| 198 bool will_begin_impl_frame_causes_redraw_; | 204 bool will_begin_impl_frame_causes_redraw_; |
| 199 bool will_begin_impl_frame_requests_one_begin_impl_frame_; | 205 bool will_begin_impl_frame_requests_one_begin_impl_frame_; |
| 200 bool draw_will_happen_; | 206 bool draw_will_happen_; |
| 201 bool swap_will_happen_if_draw_happens_; | 207 bool swap_will_happen_if_draw_happens_; |
| 202 bool automatic_swap_ack_; | 208 bool automatic_swap_ack_; |
| 203 int num_draws_; | 209 int num_draws_; |
| 204 BeginFrameArgs last_begin_main_frame_args_; | 210 BeginFrameArgs last_begin_main_frame_args_; |
| 205 base::TimeTicks posted_begin_impl_frame_deadline_; | 211 base::TimeTicks posted_begin_impl_frame_deadline_; |
| 206 std::vector<const char*> actions_; | 212 std::vector<const char*> actions_; |
| 207 std::vector<std::unique_ptr<base::trace_event::ConvertableToTraceFormat>> | 213 std::vector<std::unique_ptr<base::trace_event::ConvertableToTraceFormat>> |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 scheduler_->SetVisible(true); | 307 scheduler_->SetVisible(true); |
| 302 scheduler_->SetCanDraw(true); | 308 scheduler_->SetCanDraw(true); |
| 303 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); | 309 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 304 | 310 |
| 305 client_->Reset(); | 311 client_->Reset(); |
| 306 | 312 |
| 307 // We don't see anything happening until the first impl frame. | 313 // We don't see anything happening until the first impl frame. |
| 308 scheduler_->DidCreateAndInitializeOutputSurface(); | 314 scheduler_->DidCreateAndInitializeOutputSurface(); |
| 309 scheduler_->SetNeedsBeginMainFrame(); | 315 scheduler_->SetNeedsBeginMainFrame(); |
| 310 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 316 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 311 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 317 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 312 client_->Reset(); | 318 client_->Reset(); |
| 313 | 319 |
| 314 { | 320 { |
| 315 SCOPED_TRACE("Do first frame to commit after initialize."); | 321 SCOPED_TRACE("Do first frame to commit after initialize."); |
| 316 AdvanceFrame(); | 322 AdvanceFrame(); |
| 317 | 323 |
| 318 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 324 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 319 scheduler_->NotifyReadyToCommit(); | 325 scheduler_->NotifyReadyToCommit(); |
| 320 scheduler_->NotifyReadyToActivate(); | 326 scheduler_->NotifyReadyToActivate(); |
| 321 scheduler_->NotifyReadyToDraw(); | 327 scheduler_->NotifyReadyToDraw(); |
| 322 | 328 |
| 323 EXPECT_FALSE(scheduler_->CommitPending()); | 329 EXPECT_FALSE(scheduler_->CommitPending()); |
| 324 | 330 |
| 325 if (scheduler_settings_.using_synchronous_renderer_compositor) { | 331 if (scheduler_settings_.using_synchronous_renderer_compositor) { |
| 326 scheduler_->SetNeedsRedraw(); | 332 scheduler_->SetNeedsRedraw(); |
| 327 bool resourceless_software_draw = false; | 333 bool resourceless_software_draw = false; |
| 328 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); | 334 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); |
| 329 } else { | 335 } else { |
| 330 // Run the posted deadline task. | 336 // Run the posted deadline task. |
| 331 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 337 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 332 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 338 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 333 } | 339 } |
| 334 | 340 |
| 335 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 341 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 336 } | 342 } |
| 337 | 343 |
| 338 client_->Reset(); | 344 client_->Reset(); |
| 339 | 345 |
| 340 { | 346 { |
| 341 SCOPED_TRACE( | 347 SCOPED_TRACE( |
| 342 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); | 348 "Run second frame so Scheduler calls SetNeedsBeginFrame(false)."); |
| 343 AdvanceFrame(); | 349 AdvanceFrame(); |
| 344 | 350 |
| 345 if (!scheduler_settings_.using_synchronous_renderer_compositor) { | 351 if (!scheduler_settings_.using_synchronous_renderer_compositor) { |
| 346 // Run the posted deadline task. | 352 // Run the posted deadline task. |
| 347 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 353 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 348 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 354 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 349 } | 355 } |
| 350 | 356 |
| 351 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 357 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 352 } | 358 } |
| 353 | 359 |
| 354 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 360 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 355 client_->Reset(); | 361 client_->Reset(); |
| 356 } | 362 } |
| 357 | 363 |
| 358 // As this function contains EXPECT macros, to allow debugging it should be | 364 // As this function contains EXPECT macros, to allow debugging it should be |
| 359 // called inside EXPECT_SCOPED like so; | 365 // called inside EXPECT_SCOPED like so; |
| 360 // EXPECT_SCOPED(client.AdvanceFrame()); | 366 // EXPECT_SCOPED(client.AdvanceFrame()); |
| 361 void AdvanceFrame() { | 367 void AdvanceFrame() { |
| 362 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), | 368 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug.scheduler.frames"), |
| 363 "FakeSchedulerClient::AdvanceFrame"); | 369 "FakeSchedulerClient::AdvanceFrame"); |
| 364 // Consume any previous deadline first, if no deadline is currently | 370 // Consume any previous deadline first, if no deadline is currently |
| 365 // pending, ImplFrameDeadlinePending will return false straight away and we | 371 // pending, InsideBeginImplFrame will return false straight away and we |
| 366 // will run no tasks. | 372 // will run no tasks. |
| 367 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 373 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 368 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 374 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 369 | 375 |
| 370 // Send the next BeginFrame message if using an external source, otherwise | 376 // Send the next BeginFrame message if using an external source, otherwise |
| 371 // it will be already in the task queue. | 377 // it will be already in the task queue. |
| 372 if (scheduler_->begin_frame_source() == | 378 if (scheduler_->begin_frame_source() == |
| 373 fake_external_begin_frame_source_.get()) { | 379 fake_external_begin_frame_source_.get()) { |
| 374 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 380 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 375 SendNextBeginFrame(); | 381 SendNextBeginFrame(); |
| 376 } | 382 } |
| 377 | 383 |
| 378 if (!scheduler_->settings().using_synchronous_renderer_compositor) { | 384 if (!scheduler_->settings().using_synchronous_renderer_compositor) { |
| 379 // Then run tasks until new deadline is scheduled. | 385 // Then run tasks until new deadline is scheduled. |
| 380 EXPECT_TRUE(task_runner_->RunTasksWhile( | 386 EXPECT_TRUE( |
| 381 client_->ImplFrameDeadlinePending(false))); | 387 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(false))); |
| 382 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 388 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 383 } | 389 } |
| 384 } | 390 } |
| 385 | 391 |
| 386 BeginFrameArgs SendNextBeginFrame() { | 392 BeginFrameArgs SendNextBeginFrame() { |
| 387 DCHECK_EQ(scheduler_->begin_frame_source(), | 393 DCHECK_EQ(scheduler_->begin_frame_source(), |
| 388 fake_external_begin_frame_source_.get()); | 394 fake_external_begin_frame_source_.get()); |
| 389 // Creep the time forward so that any BeginFrameArgs is not equal to the | 395 // Creep the time forward so that any BeginFrameArgs is not equal to the |
| 390 // last one otherwise we violate the BeginFrameSource contract. | 396 // last one otherwise we violate the BeginFrameSource contract. |
| 391 now_src_->Advance(BeginFrameArgs::DefaultInterval()); | 397 now_src_->Advance(BeginFrameArgs::DefaultInterval()); |
| 392 BeginFrameArgs args = | 398 BeginFrameArgs args = |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 TEST_F(SchedulerTest, VideoNeedsBeginFrames) { | 444 TEST_F(SchedulerTest, VideoNeedsBeginFrames) { |
| 439 scheduler_settings_.use_external_begin_frame_source = true; | 445 scheduler_settings_.use_external_begin_frame_source = true; |
| 440 SetUpScheduler(true); | 446 SetUpScheduler(true); |
| 441 | 447 |
| 442 scheduler_->SetVideoNeedsBeginFrames(true); | 448 scheduler_->SetVideoNeedsBeginFrames(true); |
| 443 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 449 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 444 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 450 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 445 | 451 |
| 446 client_->Reset(); | 452 client_->Reset(); |
| 447 EXPECT_SCOPED(AdvanceFrame()); | 453 EXPECT_SCOPED(AdvanceFrame()); |
| 448 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 454 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 449 // WillBeginImplFrame is responsible for sending BeginFrames to video. | 455 // WillBeginImplFrame is responsible for sending BeginFrames to video. |
| 450 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 456 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 451 | 457 |
| 452 client_->Reset(); | 458 client_->Reset(); |
| 453 EXPECT_SCOPED(AdvanceFrame()); | 459 EXPECT_SCOPED(AdvanceFrame()); |
| 454 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 460 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 455 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 461 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 456 | 462 |
| 457 client_->Reset(); | 463 client_->Reset(); |
| 458 scheduler_->SetVideoNeedsBeginFrames(false); | 464 scheduler_->SetVideoNeedsBeginFrames(false); |
| 459 EXPECT_NO_ACTION(client_); | 465 EXPECT_NO_ACTION(client_); |
| 460 | 466 |
| 461 client_->Reset(); | 467 client_->Reset(); |
| 462 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 468 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 463 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 469 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 464 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); | 470 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); |
| 465 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 471 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); |
| 466 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 472 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 467 } | 473 } |
| 468 | 474 |
| 469 TEST_F(SchedulerTest, RequestCommit) { | 475 TEST_F(SchedulerTest, RequestCommit) { |
| 470 scheduler_settings_.use_external_begin_frame_source = true; | 476 scheduler_settings_.use_external_begin_frame_source = true; |
| 471 SetUpScheduler(true); | 477 SetUpScheduler(true); |
| 472 | 478 |
| 473 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 479 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| 474 scheduler_->SetNeedsBeginMainFrame(); | 480 scheduler_->SetNeedsBeginMainFrame(); |
| 475 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 481 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 476 client_->Reset(); | 482 client_->Reset(); |
| 477 | 483 |
| 478 EXPECT_SCOPED(AdvanceFrame()); | 484 EXPECT_SCOPED(AdvanceFrame()); |
| 479 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 485 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 480 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 486 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 481 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 487 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 482 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 488 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 483 client_->Reset(); | 489 client_->Reset(); |
| 484 | 490 |
| 485 // 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. |
| 486 task_runner().RunPendingTasks(); // Run posted deadline. | 492 task_runner().RunPendingTasks(); // Run posted deadline. |
| 487 EXPECT_NO_ACTION(client_); | 493 EXPECT_NO_ACTION(client_); |
| 488 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 494 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 489 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 495 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 490 client_->Reset(); | 496 client_->Reset(); |
| 491 | 497 |
| 492 // NotifyReadyToCommit should trigger the commit. | 498 // NotifyReadyToCommit should trigger the commit. |
| 493 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 499 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 494 scheduler_->NotifyReadyToCommit(); | 500 scheduler_->NotifyReadyToCommit(); |
| 495 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 501 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 496 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 502 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 497 client_->Reset(); | 503 client_->Reset(); |
| 498 | 504 |
| 499 // NotifyReadyToActivate should trigger the activation. | 505 // NotifyReadyToActivate should trigger the activation. |
| 500 scheduler_->NotifyReadyToActivate(); | 506 scheduler_->NotifyReadyToActivate(); |
| 501 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 507 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 502 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 508 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 503 client_->Reset(); | 509 client_->Reset(); |
| 504 | 510 |
| 505 // BeginImplFrame should prepare the draw. | 511 // BeginImplFrame should prepare the draw. |
| 506 EXPECT_SCOPED(AdvanceFrame()); | 512 EXPECT_SCOPED(AdvanceFrame()); |
| 507 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 513 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 508 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 514 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 509 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 515 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 510 client_->Reset(); | 516 client_->Reset(); |
| 511 | 517 |
| 512 // BeginImplFrame deadline should draw. | 518 // BeginImplFrame deadline should draw. |
| 513 task_runner().RunPendingTasks(); // Run posted deadline. | 519 task_runner().RunPendingTasks(); // Run posted deadline. |
| 514 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 520 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 515 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 521 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 516 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 522 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 517 client_->Reset(); | 523 client_->Reset(); |
| 518 | 524 |
| 519 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 525 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 520 // to avoid excessive toggles. | 526 // to avoid excessive toggles. |
| 521 EXPECT_SCOPED(AdvanceFrame()); | 527 EXPECT_SCOPED(AdvanceFrame()); |
| 522 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 528 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 523 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 529 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 524 client_->Reset(); | 530 client_->Reset(); |
| 525 | 531 |
| 526 task_runner().RunPendingTasks(); // Run posted deadline. | 532 task_runner().RunPendingTasks(); // Run posted deadline. |
| 527 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); | 533 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); |
| 528 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 534 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); |
| 529 client_->Reset(); | 535 client_->Reset(); |
| 530 } | 536 } |
| 531 | 537 |
| 532 TEST_F(SchedulerTest, RequestCommitAfterSetDeferCommit) { | 538 TEST_F(SchedulerTest, RequestCommitAfterSetDeferCommit) { |
| 533 scheduler_settings_.use_external_begin_frame_source = true; | 539 scheduler_settings_.use_external_begin_frame_source = true; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 546 | 552 |
| 547 client_->Reset(); | 553 client_->Reset(); |
| 548 scheduler_->SetDeferCommits(false); | 554 scheduler_->SetDeferCommits(false); |
| 549 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 555 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 550 | 556 |
| 551 // Start new BeginMainFrame after defer commit is off. | 557 // Start new BeginMainFrame after defer commit is off. |
| 552 client_->Reset(); | 558 client_->Reset(); |
| 553 EXPECT_SCOPED(AdvanceFrame()); | 559 EXPECT_SCOPED(AdvanceFrame()); |
| 554 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 560 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 555 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 561 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 556 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 562 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 557 } | 563 } |
| 558 | 564 |
| 559 TEST_F(SchedulerTest, DeferCommitWithRedraw) { | 565 TEST_F(SchedulerTest, DeferCommitWithRedraw) { |
| 560 scheduler_settings_.use_external_begin_frame_source = true; | 566 scheduler_settings_.use_external_begin_frame_source = true; |
| 561 SetUpScheduler(true); | 567 SetUpScheduler(true); |
| 562 | 568 |
| 563 scheduler_->SetDeferCommits(true); | 569 scheduler_->SetDeferCommits(true); |
| 564 | 570 |
| 565 scheduler_->SetNeedsBeginMainFrame(); | 571 scheduler_->SetNeedsBeginMainFrame(); |
| 566 EXPECT_NO_ACTION(client_); | 572 EXPECT_NO_ACTION(client_); |
| 567 | 573 |
| 568 // The SetNeedsRedraw will override the SetDeferCommits(true), to allow a | 574 // The SetNeedsRedraw will override the SetDeferCommits(true), to allow a |
| 569 // begin frame to be needed. | 575 // begin frame to be needed. |
| 570 client_->Reset(); | 576 client_->Reset(); |
| 571 scheduler_->SetNeedsRedraw(); | 577 scheduler_->SetNeedsRedraw(); |
| 572 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 578 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 573 | 579 |
| 574 client_->Reset(); | 580 client_->Reset(); |
| 575 AdvanceFrame(); | 581 AdvanceFrame(); |
| 576 // BeginMainFrame is not sent during the defer commit is on. | 582 // BeginMainFrame is not sent during the defer commit is on. |
| 577 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 583 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 578 | 584 |
| 579 client_->Reset(); | 585 client_->Reset(); |
| 580 task_runner().RunPendingTasks(); // Run posted deadline. | 586 task_runner().RunPendingTasks(); // Run posted deadline. |
| 581 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 587 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 582 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 588 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 583 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 589 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 584 | 590 |
| 585 client_->Reset(); | 591 client_->Reset(); |
| 586 AdvanceFrame(); | 592 AdvanceFrame(); |
| 587 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 593 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 588 } | 594 } |
| 589 | 595 |
| 590 TEST_F(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 596 TEST_F(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| 591 scheduler_settings_.use_external_begin_frame_source = true; | 597 scheduler_settings_.use_external_begin_frame_source = true; |
| 592 SetUpScheduler(true); | 598 SetUpScheduler(true); |
| 593 | 599 |
| 594 // SetNeedsBeginMainFrame should begin the frame. | 600 // SetNeedsBeginMainFrame should begin the frame. |
| 595 scheduler_->SetNeedsBeginMainFrame(); | 601 scheduler_->SetNeedsBeginMainFrame(); |
| 596 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 602 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 597 | 603 |
| 598 client_->Reset(); | 604 client_->Reset(); |
| 599 EXPECT_SCOPED(AdvanceFrame()); | 605 EXPECT_SCOPED(AdvanceFrame()); |
| 600 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 606 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 601 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 607 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 602 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 608 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 603 | 609 |
| 604 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 610 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 605 client_->Reset(); | 611 client_->Reset(); |
| 606 | 612 |
| 607 // Now SetNeedsBeginMainFrame again. Calling here means we need a second | 613 // Now SetNeedsBeginMainFrame again. Calling here means we need a second |
| 608 // commit. | 614 // commit. |
| 609 scheduler_->SetNeedsBeginMainFrame(); | 615 scheduler_->SetNeedsBeginMainFrame(); |
| 610 EXPECT_EQ(client_->num_actions_(), 0); | 616 EXPECT_EQ(client_->num_actions_(), 0); |
| 611 client_->Reset(); | 617 client_->Reset(); |
| 612 | 618 |
| 613 // Finish the first commit. | 619 // Finish the first commit. |
| 614 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 620 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 615 scheduler_->NotifyReadyToCommit(); | 621 scheduler_->NotifyReadyToCommit(); |
| 616 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 622 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 617 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 623 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 618 client_->Reset(); | 624 client_->Reset(); |
| 619 | 625 |
| 620 // Activate it. | 626 // Activate it. |
| 621 scheduler_->NotifyReadyToActivate(); | 627 scheduler_->NotifyReadyToActivate(); |
| 622 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 628 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 623 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 629 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 624 client_->Reset(); | 630 client_->Reset(); |
| 625 | 631 |
| 626 task_runner().RunPendingTasks(); // Run posted deadline. | 632 task_runner().RunPendingTasks(); // Run posted deadline. |
| 627 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 633 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 628 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 634 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 629 | 635 |
| 630 // Because we just swapped, the Scheduler should also request the next | 636 // Because we just swapped, the Scheduler should also request the next |
| 631 // BeginImplFrame from the OutputSurface. | 637 // BeginImplFrame from the OutputSurface. |
| 632 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 638 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 633 client_->Reset(); | 639 client_->Reset(); |
| 634 // Since another commit is needed, the next BeginImplFrame should initiate | 640 // Since another commit is needed, the next BeginImplFrame should initiate |
| 635 // the second commit. | 641 // the second commit. |
| 636 EXPECT_SCOPED(AdvanceFrame()); | 642 EXPECT_SCOPED(AdvanceFrame()); |
| 637 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 643 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 638 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 644 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 639 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 645 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 640 client_->Reset(); | 646 client_->Reset(); |
| 641 | 647 |
| 642 // Finishing the commit before the deadline should post a new deadline task | 648 // Finishing the commit before the deadline should post a new deadline task |
| 643 // to trigger the deadline early. | 649 // to trigger the deadline early. |
| 644 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 650 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 645 scheduler_->NotifyReadyToCommit(); | 651 scheduler_->NotifyReadyToCommit(); |
| 646 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 652 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 647 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 653 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 648 client_->Reset(); | 654 client_->Reset(); |
| 649 scheduler_->NotifyReadyToActivate(); | 655 scheduler_->NotifyReadyToActivate(); |
| 650 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 656 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 651 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 657 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 652 client_->Reset(); | 658 client_->Reset(); |
| 653 task_runner().RunPendingTasks(); // Run posted deadline. | 659 task_runner().RunPendingTasks(); // Run posted deadline. |
| 654 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 660 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 655 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 661 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 656 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 662 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 657 client_->Reset(); | 663 client_->Reset(); |
| 658 | 664 |
| 659 // On the next BeginImplFrame, verify we go back to a quiescent state and | 665 // On the next BeginImplFrame, verify we go back to a quiescent state and |
| 660 // no longer request BeginImplFrames. | 666 // no longer request BeginImplFrames. |
| 661 EXPECT_SCOPED(AdvanceFrame()); | 667 EXPECT_SCOPED(AdvanceFrame()); |
| 662 task_runner().RunPendingTasks(); // Run posted deadline. | 668 task_runner().RunPendingTasks(); // Run posted deadline. |
| 663 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 669 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 664 client_->Reset(); | 670 client_->Reset(); |
| 665 } | 671 } |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 EXPECT_TRUE(client->needs_begin_frames()); | 949 EXPECT_TRUE(client->needs_begin_frames()); |
| 944 EXPECT_EQ(0, client->num_draws()); | 950 EXPECT_EQ(0, client->num_draws()); |
| 945 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles")); | 951 EXPECT_FALSE(client->HasAction("ScheduledActionPrepareTiles")); |
| 946 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 952 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 947 | 953 |
| 948 // We have no immediate actions to perform, so the BeginImplFrame should post | 954 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 949 // the deadline task. | 955 // the deadline task. |
| 950 client->Reset(); | 956 client->Reset(); |
| 951 EXPECT_SCOPED(AdvanceFrame()); | 957 EXPECT_SCOPED(AdvanceFrame()); |
| 952 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 958 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
| 953 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 959 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 954 | 960 |
| 955 // On the deadline, the actions should have occured in the right order. | 961 // On the deadline, the actions should have occured in the right order. |
| 956 client->Reset(); | 962 client->Reset(); |
| 957 task_runner().RunPendingTasks(); // Run posted deadline. | 963 task_runner().RunPendingTasks(); // Run posted deadline. |
| 958 EXPECT_EQ(1, client->num_draws()); | 964 EXPECT_EQ(1, client->num_draws()); |
| 959 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 965 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 960 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 966 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 961 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 967 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 962 client->ActionIndex("ScheduledActionPrepareTiles")); | 968 client->ActionIndex("ScheduledActionPrepareTiles")); |
| 963 EXPECT_FALSE(scheduler_->RedrawPending()); | 969 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 964 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 970 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 965 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 971 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 966 | 972 |
| 967 // Request a draw. We don't need a PrepareTiles yet. | 973 // Request a draw. We don't need a PrepareTiles yet. |
| 968 client->Reset(); | 974 client->Reset(); |
| 969 scheduler_->SetNeedsRedraw(); | 975 scheduler_->SetNeedsRedraw(); |
| 970 EXPECT_TRUE(scheduler_->RedrawPending()); | 976 EXPECT_TRUE(scheduler_->RedrawPending()); |
| 971 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 977 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 972 EXPECT_TRUE(client->needs_begin_frames()); | 978 EXPECT_TRUE(client->needs_begin_frames()); |
| 973 EXPECT_EQ(0, client->num_draws()); | 979 EXPECT_EQ(0, client->num_draws()); |
| 974 | 980 |
| 975 // We have no immediate actions to perform, so the BeginImplFrame should post | 981 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 976 // the deadline task. | 982 // the deadline task. |
| 977 client->Reset(); | 983 client->Reset(); |
| 978 EXPECT_SCOPED(AdvanceFrame()); | 984 EXPECT_SCOPED(AdvanceFrame()); |
| 979 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 985 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
| 980 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 986 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 981 | 987 |
| 982 // Draw. The draw will trigger SetNeedsPrepareTiles, and | 988 // Draw. The draw will trigger SetNeedsPrepareTiles, and |
| 983 // then the PrepareTiles action will be triggered after the Draw. | 989 // then the PrepareTiles action will be triggered after the Draw. |
| 984 // Afterwards, neither a draw nor PrepareTiles are pending. | 990 // Afterwards, neither a draw nor PrepareTiles are pending. |
| 985 client->Reset(); | 991 client->Reset(); |
| 986 task_runner().RunPendingTasks(); // Run posted deadline. | 992 task_runner().RunPendingTasks(); // Run posted deadline. |
| 987 EXPECT_EQ(1, client->num_draws()); | 993 EXPECT_EQ(1, client->num_draws()); |
| 988 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 994 EXPECT_TRUE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 989 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 995 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 990 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 996 EXPECT_LT(client->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 991 client->ActionIndex("ScheduledActionPrepareTiles")); | 997 client->ActionIndex("ScheduledActionPrepareTiles")); |
| 992 EXPECT_FALSE(scheduler_->RedrawPending()); | 998 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 993 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 999 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 994 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1000 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 995 | 1001 |
| 996 // We need a BeginImplFrame where we don't swap to go idle. | 1002 // We need a BeginImplFrame where we don't swap to go idle. |
| 997 client->Reset(); | 1003 client->Reset(); |
| 998 EXPECT_SCOPED(AdvanceFrame()); | 1004 EXPECT_SCOPED(AdvanceFrame()); |
| 999 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1005 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1000 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1006 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1001 client->Reset(); | 1007 client->Reset(); |
| 1002 task_runner().RunPendingTasks(); // Run posted deadline. | 1008 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1003 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); | 1009 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); |
| 1004 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 1010 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); |
| 1005 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1011 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1006 EXPECT_EQ(0, client->num_draws()); | 1012 EXPECT_EQ(0, client->num_draws()); |
| 1007 | 1013 |
| 1008 // Now trigger a PrepareTiles outside of a draw. We will then need | 1014 // Now trigger a PrepareTiles outside of a draw. We will then need |
| 1009 // a begin-frame for the PrepareTiles, but we don't need a draw. | 1015 // a begin-frame for the PrepareTiles, but we don't need a draw. |
| 1010 client->Reset(); | 1016 client->Reset(); |
| 1011 EXPECT_FALSE(client->needs_begin_frames()); | 1017 EXPECT_FALSE(client->needs_begin_frames()); |
| 1012 scheduler_->SetNeedsPrepareTiles(); | 1018 scheduler_->SetNeedsPrepareTiles(); |
| 1013 EXPECT_TRUE(client->needs_begin_frames()); | 1019 EXPECT_TRUE(client->needs_begin_frames()); |
| 1014 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1020 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1015 EXPECT_FALSE(scheduler_->RedrawPending()); | 1021 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1016 | 1022 |
| 1017 // BeginImplFrame. There will be no draw, only PrepareTiles. | 1023 // BeginImplFrame. There will be no draw, only PrepareTiles. |
| 1018 client->Reset(); | 1024 client->Reset(); |
| 1019 EXPECT_SCOPED(AdvanceFrame()); | 1025 EXPECT_SCOPED(AdvanceFrame()); |
| 1020 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1026 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1021 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1027 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1022 client->Reset(); | 1028 client->Reset(); |
| 1023 task_runner().RunPendingTasks(); // Run posted deadline. | 1029 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1024 EXPECT_EQ(0, client->num_draws()); | 1030 EXPECT_EQ(0, client->num_draws()); |
| 1025 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1031 EXPECT_FALSE(client->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1026 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); | 1032 EXPECT_TRUE(client->HasAction("ScheduledActionPrepareTiles")); |
| 1027 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1033 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1028 } | 1034 } |
| 1029 | 1035 |
| 1030 // Test that PrepareTiles only happens once per frame. If an external caller | 1036 // Test that PrepareTiles only happens once per frame. If an external caller |
| 1031 // initiates it, then the state machine should not PrepareTiles on that frame. | 1037 // initiates it, then the state machine should not PrepareTiles on that frame. |
| 1032 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { | 1038 TEST_F(SchedulerTest, PrepareTilesOncePerFrame) { |
| 1033 scheduler_settings_.use_external_begin_frame_source = true; | 1039 scheduler_settings_.use_external_begin_frame_source = true; |
| 1034 SetUpScheduler(true); | 1040 SetUpScheduler(true); |
| 1035 | 1041 |
| 1036 // If DidPrepareTiles during a frame, then PrepareTiles should not occur | 1042 // If DidPrepareTiles during a frame, then PrepareTiles should not occur |
| 1037 // again. | 1043 // again. |
| 1038 scheduler_->SetNeedsPrepareTiles(); | 1044 scheduler_->SetNeedsPrepareTiles(); |
| 1039 scheduler_->SetNeedsRedraw(); | 1045 scheduler_->SetNeedsRedraw(); |
| 1040 client_->Reset(); | 1046 client_->Reset(); |
| 1041 EXPECT_SCOPED(AdvanceFrame()); | 1047 EXPECT_SCOPED(AdvanceFrame()); |
| 1042 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1048 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1043 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1049 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1044 | 1050 |
| 1045 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1051 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1046 scheduler_->WillPrepareTiles(); | 1052 scheduler_->WillPrepareTiles(); |
| 1047 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1053 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1048 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1054 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1049 | 1055 |
| 1050 client_->Reset(); | 1056 client_->Reset(); |
| 1051 task_runner().RunPendingTasks(); // Run posted deadline. | 1057 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1052 EXPECT_EQ(1, client_->num_draws()); | 1058 EXPECT_EQ(1, client_->num_draws()); |
| 1053 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1059 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1054 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1060 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1055 EXPECT_FALSE(scheduler_->RedrawPending()); | 1061 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1056 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1062 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1057 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1063 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1058 | 1064 |
| 1059 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1065 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
| 1060 scheduler_->SetNeedsPrepareTiles(); | 1066 scheduler_->SetNeedsPrepareTiles(); |
| 1061 scheduler_->SetNeedsRedraw(); | 1067 scheduler_->SetNeedsRedraw(); |
| 1062 client_->Reset(); | 1068 client_->Reset(); |
| 1063 EXPECT_SCOPED(AdvanceFrame()); | 1069 EXPECT_SCOPED(AdvanceFrame()); |
| 1064 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1070 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1065 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1071 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1066 | 1072 |
| 1067 client_->Reset(); | 1073 client_->Reset(); |
| 1068 task_runner().RunPendingTasks(); // Run posted deadline. | 1074 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1069 EXPECT_EQ(1, client_->num_draws()); | 1075 EXPECT_EQ(1, client_->num_draws()); |
| 1070 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1076 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1071 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); | 1077 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1072 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1078 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 1073 client_->ActionIndex("ScheduledActionPrepareTiles")); | 1079 client_->ActionIndex("ScheduledActionPrepareTiles")); |
| 1074 EXPECT_FALSE(scheduler_->RedrawPending()); | 1080 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1075 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1081 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1076 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1082 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1077 | 1083 |
| 1078 // If we get another DidPrepareTiles within the same frame, we should | 1084 // If we get another DidPrepareTiles within the same frame, we should |
| 1079 // not PrepareTiles on the next frame. | 1085 // not PrepareTiles on the next frame. |
| 1080 scheduler_->WillPrepareTiles(); | 1086 scheduler_->WillPrepareTiles(); |
| 1081 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1087 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1082 scheduler_->SetNeedsPrepareTiles(); | 1088 scheduler_->SetNeedsPrepareTiles(); |
| 1083 scheduler_->SetNeedsRedraw(); | 1089 scheduler_->SetNeedsRedraw(); |
| 1084 client_->Reset(); | 1090 client_->Reset(); |
| 1085 EXPECT_SCOPED(AdvanceFrame()); | 1091 EXPECT_SCOPED(AdvanceFrame()); |
| 1086 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1092 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1087 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1093 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1088 | 1094 |
| 1089 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1095 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1090 | 1096 |
| 1091 client_->Reset(); | 1097 client_->Reset(); |
| 1092 task_runner().RunPendingTasks(); // Run posted deadline. | 1098 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1093 EXPECT_EQ(1, client_->num_draws()); | 1099 EXPECT_EQ(1, client_->num_draws()); |
| 1094 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1100 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1095 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1101 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1096 EXPECT_FALSE(scheduler_->RedrawPending()); | 1102 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1097 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1103 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1098 | 1104 |
| 1099 // If we get another DidPrepareTiles, we should not PrepareTiles on the next | 1105 // If we get another DidPrepareTiles, we should not PrepareTiles on the next |
| 1100 // frame. This verifies we don't alternate calling PrepareTiles once and | 1106 // frame. This verifies we don't alternate calling PrepareTiles once and |
| 1101 // twice. | 1107 // twice. |
| 1102 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1108 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1103 scheduler_->WillPrepareTiles(); | 1109 scheduler_->WillPrepareTiles(); |
| 1104 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. | 1110 scheduler_->DidPrepareTiles(); // An explicit PrepareTiles. |
| 1105 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1111 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1106 scheduler_->SetNeedsPrepareTiles(); | 1112 scheduler_->SetNeedsPrepareTiles(); |
| 1107 scheduler_->SetNeedsRedraw(); | 1113 scheduler_->SetNeedsRedraw(); |
| 1108 client_->Reset(); | 1114 client_->Reset(); |
| 1109 EXPECT_SCOPED(AdvanceFrame()); | 1115 EXPECT_SCOPED(AdvanceFrame()); |
| 1110 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1116 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1111 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1117 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1112 | 1118 |
| 1113 EXPECT_TRUE(scheduler_->PrepareTilesPending()); | 1119 EXPECT_TRUE(scheduler_->PrepareTilesPending()); |
| 1114 | 1120 |
| 1115 client_->Reset(); | 1121 client_->Reset(); |
| 1116 task_runner().RunPendingTasks(); // Run posted deadline. | 1122 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1117 EXPECT_EQ(1, client_->num_draws()); | 1123 EXPECT_EQ(1, client_->num_draws()); |
| 1118 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1124 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1119 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); | 1125 EXPECT_FALSE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1120 EXPECT_FALSE(scheduler_->RedrawPending()); | 1126 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1121 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1127 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1122 | 1128 |
| 1123 // Next frame without DidPrepareTiles should PrepareTiles with draw. | 1129 // Next frame without DidPrepareTiles should PrepareTiles with draw. |
| 1124 scheduler_->SetNeedsPrepareTiles(); | 1130 scheduler_->SetNeedsPrepareTiles(); |
| 1125 scheduler_->SetNeedsRedraw(); | 1131 scheduler_->SetNeedsRedraw(); |
| 1126 client_->Reset(); | 1132 client_->Reset(); |
| 1127 EXPECT_SCOPED(AdvanceFrame()); | 1133 EXPECT_SCOPED(AdvanceFrame()); |
| 1128 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1134 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1129 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1135 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1130 | 1136 |
| 1131 client_->Reset(); | 1137 client_->Reset(); |
| 1132 task_runner().RunPendingTasks(); // Run posted deadline. | 1138 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1133 EXPECT_EQ(1, client_->num_draws()); | 1139 EXPECT_EQ(1, client_->num_draws()); |
| 1134 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1140 EXPECT_TRUE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1135 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); | 1141 EXPECT_TRUE(client_->HasAction("ScheduledActionPrepareTiles")); |
| 1136 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 1142 EXPECT_LT(client_->ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 1137 client_->ActionIndex("ScheduledActionPrepareTiles")); | 1143 client_->ActionIndex("ScheduledActionPrepareTiles")); |
| 1138 EXPECT_FALSE(scheduler_->RedrawPending()); | 1144 EXPECT_FALSE(scheduler_->RedrawPending()); |
| 1139 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 1145 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 1140 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1146 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1141 } | 1147 } |
| 1142 | 1148 |
| 1143 TEST_F(SchedulerTest, PrepareTilesFunnelResetOnVisibilityChange) { | 1149 TEST_F(SchedulerTest, PrepareTilesFunnelResetOnVisibilityChange) { |
| 1144 std::unique_ptr<SchedulerClientNeedsPrepareTilesInDraw> client = | 1150 std::unique_ptr<SchedulerClientNeedsPrepareTilesInDraw> client = |
| 1145 base::WrapUnique(new SchedulerClientNeedsPrepareTilesInDraw); | 1151 base::WrapUnique(new SchedulerClientNeedsPrepareTilesInDraw); |
| 1146 scheduler_settings_.use_external_begin_frame_source = true; | 1152 scheduler_settings_.use_external_begin_frame_source = true; |
| 1147 SetUpScheduler(std::move(client), true); | 1153 SetUpScheduler(std::move(client), true); |
| 1148 | 1154 |
| 1149 // Simulate a few visibility changes and associated PrepareTiles. | 1155 // Simulate a few visibility changes and associated PrepareTiles. |
| 1150 for (int i = 0; i < 10; i++) { | 1156 for (int i = 0; i < 10; i++) { |
| 1151 scheduler_->SetVisible(false); | 1157 scheduler_->SetVisible(false); |
| 1152 scheduler_->WillPrepareTiles(); | 1158 scheduler_->WillPrepareTiles(); |
| 1153 scheduler_->DidPrepareTiles(); | 1159 scheduler_->DidPrepareTiles(); |
| 1154 | 1160 |
| 1155 scheduler_->SetVisible(true); | 1161 scheduler_->SetVisible(true); |
| 1156 scheduler_->WillPrepareTiles(); | 1162 scheduler_->WillPrepareTiles(); |
| 1157 scheduler_->DidPrepareTiles(); | 1163 scheduler_->DidPrepareTiles(); |
| 1158 } | 1164 } |
| 1159 | 1165 |
| 1160 client_->Reset(); | 1166 client_->Reset(); |
| 1161 scheduler_->SetNeedsRedraw(); | 1167 scheduler_->SetNeedsRedraw(); |
| 1162 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 1168 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 1163 | 1169 |
| 1164 client_->Reset(); | 1170 client_->Reset(); |
| 1165 AdvanceFrame(); | 1171 AdvanceFrame(); |
| 1166 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1172 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1167 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1173 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1168 | 1174 |
| 1169 client_->Reset(); | 1175 client_->Reset(); |
| 1170 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1176 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1171 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1177 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1172 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 1178 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); |
| 1173 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); | 1179 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); |
| 1174 } | 1180 } |
| 1175 | 1181 |
| 1176 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1182 TEST_F(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
| 1177 SchedulerClientNeedsPrepareTilesInDraw* client = | 1183 SchedulerClientNeedsPrepareTilesInDraw* client = |
| 1178 new SchedulerClientNeedsPrepareTilesInDraw; | 1184 new SchedulerClientNeedsPrepareTilesInDraw; |
| 1179 scheduler_settings_.use_external_begin_frame_source = true; | 1185 scheduler_settings_.use_external_begin_frame_source = true; |
| 1180 SetUpScheduler(base::WrapUnique(client), true); | 1186 SetUpScheduler(base::WrapUnique(client), true); |
| 1181 | 1187 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1255 | 1261 |
| 1256 // Scheduler won't post deadline in the mode. | 1262 // Scheduler won't post deadline in the mode. |
| 1257 client_->Reset(); | 1263 client_->Reset(); |
| 1258 task_runner().RunPendingTasks(); // Try to run posted deadline. | 1264 task_runner().RunPendingTasks(); // Try to run posted deadline. |
| 1259 // There is no posted deadline. | 1265 // There is no posted deadline. |
| 1260 EXPECT_NO_ACTION(client_); | 1266 EXPECT_NO_ACTION(client_); |
| 1261 | 1267 |
| 1262 // Scheduler loses output surface, and stops waiting for ready to draw signal. | 1268 // Scheduler loses output surface, and stops waiting for ready to draw signal. |
| 1263 client_->Reset(); | 1269 client_->Reset(); |
| 1264 scheduler_->DidLoseOutputSurface(); | 1270 scheduler_->DidLoseOutputSurface(); |
| 1265 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1271 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1266 task_runner().RunPendingTasks(); // Run posted deadline. | 1272 task_runner().RunPendingTasks(); // Run posted deadline. |
| 1267 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | 1273 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); |
| 1268 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 1274 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 1269 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 1275 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 1270 } | 1276 } |
| 1271 | 1277 |
| 1272 void SchedulerTest::CheckMainFrameSkippedAfterLateCommit( | 1278 void SchedulerTest::CheckMainFrameSkippedAfterLateCommit( |
| 1273 bool expect_send_begin_main_frame) { | 1279 bool expect_send_begin_main_frame) { |
| 1274 // Impl thread hits deadline before commit finishes. | 1280 // Impl thread hits deadline before commit finishes. |
| 1275 scheduler_->SetNeedsBeginMainFrame(); | 1281 scheduler_->SetNeedsBeginMainFrame(); |
| 1276 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1282 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1277 EXPECT_SCOPED(AdvanceFrame()); | 1283 EXPECT_SCOPED(AdvanceFrame()); |
| 1278 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1284 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1279 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1285 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1280 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1286 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1281 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1287 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1282 scheduler_->NotifyReadyToCommit(); | 1288 scheduler_->NotifyReadyToCommit(); |
| 1283 scheduler_->NotifyReadyToActivate(); | 1289 scheduler_->NotifyReadyToActivate(); |
| 1284 EXPECT_ACTION("AddObserver(this)", client_, 0, 5); | 1290 EXPECT_ACTION("AddObserver(this)", client_, 0, 5); |
| 1285 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); | 1291 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); |
| 1286 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); | 1292 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); |
| 1287 EXPECT_ACTION("ScheduledActionCommit", client_, 3, 5); | 1293 EXPECT_ACTION("ScheduledActionCommit", client_, 3, 5); |
| 1288 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 4, 5); | 1294 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 4, 5); |
| 1289 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1295 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1290 | 1296 |
| 1291 client_->Reset(); | 1297 client_->Reset(); |
| 1292 scheduler_->SetNeedsBeginMainFrame(); | 1298 scheduler_->SetNeedsBeginMainFrame(); |
| 1293 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1299 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1294 EXPECT_SCOPED(AdvanceFrame()); | 1300 EXPECT_SCOPED(AdvanceFrame()); |
| 1295 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1301 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1296 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1302 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1297 EXPECT_EQ(expect_send_begin_main_frame, | 1303 EXPECT_EQ(expect_send_begin_main_frame, |
| 1298 scheduler_->MainThreadMissedLastDeadline()); | 1304 scheduler_->MainThreadMissedLastDeadline()); |
| 1299 EXPECT_TRUE(client_->HasAction("WillBeginImplFrame")); | 1305 EXPECT_TRUE(client_->HasAction("WillBeginImplFrame")); |
| 1300 EXPECT_EQ(expect_send_begin_main_frame, | 1306 EXPECT_EQ(expect_send_begin_main_frame, |
| 1301 client_->HasAction("ScheduledActionSendBeginMainFrame")); | 1307 client_->HasAction("ScheduledActionSendBeginMainFrame")); |
| 1302 } | 1308 } |
| 1303 | 1309 |
| 1304 TEST_F(SchedulerTest, MainFrameSkippedAfterLateCommit) { | 1310 TEST_F(SchedulerTest, MainFrameSkippedAfterLateCommit) { |
| 1305 scheduler_settings_.use_external_begin_frame_source = true; | 1311 scheduler_settings_.use_external_begin_frame_source = true; |
| 1306 SetUpScheduler(true); | 1312 SetUpScheduler(true); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1416 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1422 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1417 | 1423 |
| 1418 // Impl thread hits deadline before BeginMainFrame aborts. | 1424 // Impl thread hits deadline before BeginMainFrame aborts. |
| 1419 scheduler_->SetNeedsBeginMainFrame(); | 1425 scheduler_->SetNeedsBeginMainFrame(); |
| 1420 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1426 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1421 EXPECT_SCOPED(AdvanceFrame()); | 1427 EXPECT_SCOPED(AdvanceFrame()); |
| 1422 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); | 1428 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); |
| 1423 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); | 1429 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); |
| 1424 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); | 1430 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); |
| 1425 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1431 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1426 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1432 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1427 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1433 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1428 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1434 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1429 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1435 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1430 | 1436 |
| 1431 // After aborting the frame, make sure we don't skip the | 1437 // After aborting the frame, make sure we don't skip the |
| 1432 // next BeginMainFrame. | 1438 // next BeginMainFrame. |
| 1433 client_->Reset(); | 1439 client_->Reset(); |
| 1434 scheduler_->BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); | 1440 scheduler_->BeginMainFrameAborted(CommitEarlyOutReason::FINISHED_NO_UPDATES); |
| 1435 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1441 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1436 scheduler_->SetNeedsBeginMainFrame(); | 1442 scheduler_->SetNeedsBeginMainFrame(); |
| 1437 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1443 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1438 EXPECT_SCOPED(AdvanceFrame()); | 1444 EXPECT_SCOPED(AdvanceFrame()); |
| 1439 EXPECT_TRUE(client_->HasAction("WillBeginImplFrame")); | 1445 EXPECT_TRUE(client_->HasAction("WillBeginImplFrame")); |
| 1440 EXPECT_TRUE(client_->HasAction("ScheduledActionSendBeginMainFrame")); | 1446 EXPECT_TRUE(client_->HasAction("ScheduledActionSendBeginMainFrame")); |
| 1441 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1447 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1442 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1448 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1443 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1449 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1444 } | 1450 } |
| 1445 | 1451 |
| 1446 // If the BeginMainFrame aborts, it doesn't actually insert a frame into the | 1452 // If the BeginMainFrame aborts, it doesn't actually insert a frame into the |
| 1447 // queue, which means there is no latency to recover. | 1453 // queue, which means there is no latency to recover. |
| 1448 TEST_F(SchedulerTest, MainFrameNotSkippedAfterCanDrawChanges) { | 1454 TEST_F(SchedulerTest, MainFrameNotSkippedAfterCanDrawChanges) { |
| 1449 scheduler_settings_.use_external_begin_frame_source = true; | 1455 scheduler_settings_.use_external_begin_frame_source = true; |
| 1450 SetUpScheduler(true); | 1456 SetUpScheduler(true); |
| 1451 | 1457 |
| 1452 // Use fast estimates so we think we can recover latency if needed. | 1458 // Use fast estimates so we think we can recover latency if needed. |
| 1453 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1459 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1454 | 1460 |
| 1455 // Impl thread hits deadline before BeginMainFrame aborts. | 1461 // Impl thread hits deadline before BeginMainFrame aborts. |
| 1456 scheduler_->SetNeedsBeginMainFrame(); | 1462 scheduler_->SetNeedsBeginMainFrame(); |
| 1457 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1463 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1458 EXPECT_SCOPED(AdvanceFrame()); | 1464 EXPECT_SCOPED(AdvanceFrame()); |
| 1459 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); | 1465 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); |
| 1460 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); | 1466 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); |
| 1461 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); | 1467 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); |
| 1462 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1468 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1463 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1469 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1464 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1470 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1465 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1471 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1466 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1472 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1467 | 1473 |
| 1468 // Make us abort the upcoming draw. | 1474 // Make us abort the upcoming draw. |
| 1469 client_->Reset(); | 1475 client_->Reset(); |
| 1470 scheduler_->NotifyReadyToCommit(); | 1476 scheduler_->NotifyReadyToCommit(); |
| 1471 scheduler_->NotifyReadyToActivate(); | 1477 scheduler_->NotifyReadyToActivate(); |
| 1472 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); | 1478 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); |
| 1473 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); | 1479 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); |
| 1474 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1480 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1475 scheduler_->SetCanDraw(false); | 1481 scheduler_->SetCanDraw(false); |
| 1476 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1482 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1477 | 1483 |
| 1478 // Make CanDraw true after activation. | 1484 // Make CanDraw true after activation. |
| 1479 client_->Reset(); | 1485 client_->Reset(); |
| 1480 scheduler_->SetCanDraw(true); | 1486 scheduler_->SetCanDraw(true); |
| 1481 EXPECT_NO_ACTION(client_); | 1487 EXPECT_NO_ACTION(client_); |
| 1482 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1488 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1483 | 1489 |
| 1484 // Make sure we don't skip the next BeginMainFrame. | 1490 // Make sure we don't skip the next BeginMainFrame. |
| 1485 client_->Reset(); | 1491 client_->Reset(); |
| 1486 scheduler_->SetNeedsBeginMainFrame(); | 1492 scheduler_->SetNeedsBeginMainFrame(); |
| 1487 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1493 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1488 EXPECT_SCOPED(AdvanceFrame()); | 1494 EXPECT_SCOPED(AdvanceFrame()); |
| 1489 EXPECT_TRUE(client_->HasAction("WillBeginImplFrame")); | 1495 EXPECT_TRUE(client_->HasAction("WillBeginImplFrame")); |
| 1490 EXPECT_TRUE(client_->HasAction("ScheduledActionSendBeginMainFrame")); | 1496 EXPECT_TRUE(client_->HasAction("ScheduledActionSendBeginMainFrame")); |
| 1491 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1497 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1492 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1498 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1493 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1499 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1494 } | 1500 } |
| 1495 | 1501 |
| 1496 void SchedulerTest::ImplFrameSkippedAfterLateSwapAck( | 1502 void SchedulerTest::ImplFrameSkippedAfterLateSwapAck( |
| 1497 bool swap_ack_before_deadline) { | 1503 bool swap_ack_before_deadline) { |
| 1498 // To get into a high latency state, this test disables automatic swap acks. | 1504 // To get into a high latency state, this test disables automatic swap acks. |
| 1499 client_->SetAutomaticSwapAck(false); | 1505 client_->SetAutomaticSwapAck(false); |
| 1500 | 1506 |
| 1501 // Draw and swap for first BeginFrame | 1507 // Draw and swap for first BeginFrame |
| 1502 client_->Reset(); | 1508 client_->Reset(); |
| 1503 scheduler_->SetNeedsBeginMainFrame(); | 1509 scheduler_->SetNeedsBeginMainFrame(); |
| 1504 scheduler_->SetNeedsRedraw(); | 1510 scheduler_->SetNeedsRedraw(); |
| 1505 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1511 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1506 SendNextBeginFrame(); | 1512 SendNextBeginFrame(); |
| 1507 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); | 1513 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); |
| 1508 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); | 1514 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); |
| 1509 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); | 1515 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); |
| 1510 | 1516 |
| 1511 client_->Reset(); | 1517 client_->Reset(); |
| 1512 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1518 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1513 scheduler_->NotifyReadyToCommit(); | 1519 scheduler_->NotifyReadyToCommit(); |
| 1514 scheduler_->NotifyReadyToActivate(); | 1520 scheduler_->NotifyReadyToActivate(); |
| 1515 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1521 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1516 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1522 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1517 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); | 1523 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
| 1518 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); | 1524 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
| 1519 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 1525 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); |
| 1520 | 1526 |
| 1521 // Verify we skip every other frame if the swap ack consistently | 1527 // Verify we skip every other frame if the swap ack consistently |
| 1522 // comes back late. | 1528 // comes back late. |
| 1523 for (int i = 0; i < 10; i++) { | 1529 for (int i = 0; i < 10; i++) { |
| 1524 // Not calling scheduler_->DidSwapBuffersComplete() until after next | 1530 // Not calling scheduler_->DidSwapBuffersComplete() until after next |
| 1525 // BeginImplFrame puts the impl thread in high latency mode. | 1531 // BeginImplFrame puts the impl thread in high latency mode. |
| 1526 client_->Reset(); | 1532 client_->Reset(); |
| 1527 scheduler_->SetNeedsBeginMainFrame(); | 1533 scheduler_->SetNeedsBeginMainFrame(); |
| 1528 scheduler_->SetNeedsRedraw(); | 1534 scheduler_->SetNeedsRedraw(); |
| 1529 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1535 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1530 SendNextBeginFrame(); | 1536 SendNextBeginFrame(); |
| 1531 // Verify that we skip the BeginImplFrame | 1537 // Verify that we skip the BeginImplFrame |
| 1532 EXPECT_NO_ACTION(client_); | 1538 EXPECT_NO_ACTION(client_); |
| 1533 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1539 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1534 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1540 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1535 | 1541 |
| 1536 // Verify that we do not perform any actions after we are no longer | 1542 // Verify that we do not perform any actions after we are no longer |
| 1537 // swap throttled. | 1543 // swap throttled. |
| 1538 client_->Reset(); | 1544 client_->Reset(); |
| 1539 if (swap_ack_before_deadline) { | 1545 if (swap_ack_before_deadline) { |
| 1540 // It shouldn't matter if the swap ack comes back before the deadline... | 1546 // It shouldn't matter if the swap ack comes back before the deadline... |
| 1541 scheduler_->DidSwapBuffersComplete(); | 1547 scheduler_->DidSwapBuffersComplete(); |
| 1542 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1548 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1543 } else { | 1549 } else { |
| 1544 // ... or after the deadline. | 1550 // ... or after the deadline. |
| 1545 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1551 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1546 scheduler_->DidSwapBuffersComplete(); | 1552 scheduler_->DidSwapBuffersComplete(); |
| 1547 } | 1553 } |
| 1548 EXPECT_NO_ACTION(client_); | 1554 EXPECT_NO_ACTION(client_); |
| 1549 | 1555 |
| 1550 // Verify that we start the next BeginImplFrame and continue normally | 1556 // Verify that we start the next BeginImplFrame and continue normally |
| 1551 // after having just skipped a BeginImplFrame. | 1557 // after having just skipped a BeginImplFrame. |
| 1552 client_->Reset(); | 1558 client_->Reset(); |
| 1553 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1559 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1554 SendNextBeginFrame(); | 1560 SendNextBeginFrame(); |
| 1555 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1561 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1556 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 1562 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 1557 | 1563 |
| 1558 client_->Reset(); | 1564 client_->Reset(); |
| 1559 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1565 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1560 scheduler_->NotifyReadyToCommit(); | 1566 scheduler_->NotifyReadyToCommit(); |
| 1561 scheduler_->NotifyReadyToActivate(); | 1567 scheduler_->NotifyReadyToActivate(); |
| 1562 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1568 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1563 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); | 1569 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
| 1564 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); | 1570 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
| 1565 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 1571 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); |
| 1566 } | 1572 } |
| 1567 } | 1573 } |
| 1568 | 1574 |
| 1569 TEST_F(SchedulerTest, | 1575 TEST_F(SchedulerTest, |
| 1570 ImplFrameSkippedAfterLateSwapAck_FastEstimates_SwapAckThenDeadline) { | 1576 ImplFrameSkippedAfterLateSwapAck_FastEstimates_SwapAckThenDeadline) { |
| 1571 scheduler_settings_.use_external_begin_frame_source = true; | 1577 scheduler_settings_.use_external_begin_frame_source = true; |
| 1572 SetUpScheduler(true); | 1578 SetUpScheduler(true); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 // Draw and swap for first BeginFrame | 1640 // Draw and swap for first BeginFrame |
| 1635 client_->Reset(); | 1641 client_->Reset(); |
| 1636 scheduler_->SetNeedsRedraw(); | 1642 scheduler_->SetNeedsRedraw(); |
| 1637 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1643 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1638 SendNextBeginFrame(); | 1644 SendNextBeginFrame(); |
| 1639 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); | 1645 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); |
| 1640 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); | 1646 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); |
| 1641 | 1647 |
| 1642 client_->Reset(); | 1648 client_->Reset(); |
| 1643 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1649 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1644 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1650 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1645 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 1651 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 1646 | 1652 |
| 1647 // Verify we skip every other frame if the swap ack consistently | 1653 // Verify we skip every other frame if the swap ack consistently |
| 1648 // comes back late. | 1654 // comes back late. |
| 1649 for (int i = 0; i < 10; i++) { | 1655 for (int i = 0; i < 10; i++) { |
| 1650 // Not calling scheduler_->DidSwapBuffersComplete() until after next | 1656 // Not calling scheduler_->DidSwapBuffersComplete() until after next |
| 1651 // BeginImplFrame puts the impl thread in high latency mode. | 1657 // BeginImplFrame puts the impl thread in high latency mode. |
| 1652 client_->Reset(); | 1658 client_->Reset(); |
| 1653 scheduler_->SetNeedsRedraw(); | 1659 scheduler_->SetNeedsRedraw(); |
| 1654 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1660 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1655 SendNextBeginFrame(); | 1661 SendNextBeginFrame(); |
| 1656 // Verify that we skip the BeginImplFrame | 1662 // Verify that we skip the BeginImplFrame |
| 1657 EXPECT_NO_ACTION(client_); | 1663 EXPECT_NO_ACTION(client_); |
| 1658 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1664 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1659 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1665 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1660 | 1666 |
| 1661 // Verify that we do not perform any actions after we are no longer | 1667 // Verify that we do not perform any actions after we are no longer |
| 1662 // swap throttled. | 1668 // swap throttled. |
| 1663 client_->Reset(); | 1669 client_->Reset(); |
| 1664 scheduler_->DidSwapBuffersComplete(); | 1670 scheduler_->DidSwapBuffersComplete(); |
| 1665 EXPECT_NO_ACTION(client_); | 1671 EXPECT_NO_ACTION(client_); |
| 1666 | 1672 |
| 1667 // Verify that we start the next BeginImplFrame and continue normally | 1673 // Verify that we start the next BeginImplFrame and continue normally |
| 1668 // after having just skipped a BeginImplFrame. | 1674 // after having just skipped a BeginImplFrame. |
| 1669 client_->Reset(); | 1675 client_->Reset(); |
| 1670 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1676 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1671 SendNextBeginFrame(); | 1677 SendNextBeginFrame(); |
| 1672 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1678 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1673 | 1679 |
| 1674 client_->Reset(); | 1680 client_->Reset(); |
| 1675 // Deadline should be immediate. | 1681 // Deadline should be immediate. |
| 1676 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1682 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1677 task_runner().RunUntilTime(now_src_->NowTicks()); | 1683 task_runner().RunUntilTime(now_src_->NowTicks()); |
| 1678 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1684 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1679 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 1685 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 1680 } | 1686 } |
| 1681 } | 1687 } |
| 1682 | 1688 |
| 1683 void SchedulerTest::ImplFrameNotSkippedAfterLateSwapAck() { | 1689 void SchedulerTest::ImplFrameNotSkippedAfterLateSwapAck() { |
| 1684 // To get into a high latency state, this test disables automatic swap acks. | 1690 // To get into a high latency state, this test disables automatic swap acks. |
| 1685 client_->SetAutomaticSwapAck(false); | 1691 client_->SetAutomaticSwapAck(false); |
| 1686 | 1692 |
| 1687 // Draw and swap for first BeginFrame | 1693 // Draw and swap for first BeginFrame |
| 1688 client_->Reset(); | 1694 client_->Reset(); |
| 1689 scheduler_->SetNeedsBeginMainFrame(); | 1695 scheduler_->SetNeedsBeginMainFrame(); |
| 1690 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1696 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1691 SendNextBeginFrame(); | 1697 SendNextBeginFrame(); |
| 1692 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); | 1698 EXPECT_ACTION("AddObserver(this)", client_, 0, 3); |
| 1693 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); | 1699 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 3); |
| 1694 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); | 1700 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 3); |
| 1695 | 1701 |
| 1696 client_->Reset(); | 1702 client_->Reset(); |
| 1697 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1703 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1698 scheduler_->NotifyReadyToCommit(); | 1704 scheduler_->NotifyReadyToCommit(); |
| 1699 scheduler_->NotifyReadyToActivate(); | 1705 scheduler_->NotifyReadyToActivate(); |
| 1700 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1706 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1701 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1707 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1702 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); | 1708 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
| 1703 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); | 1709 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
| 1704 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 1710 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); |
| 1705 | 1711 |
| 1706 // Verify impl thread consistently operates in high latency mode | 1712 // Verify impl thread consistently operates in high latency mode |
| 1707 // without skipping any frames. | 1713 // without skipping any frames. |
| 1708 for (int i = 0; i < 10; i++) { | 1714 for (int i = 0; i < 10; i++) { |
| 1709 // Not calling scheduler_->DidSwapBuffersComplete() until after next frame | 1715 // Not calling scheduler_->DidSwapBuffersComplete() until after next frame |
| 1710 // puts the impl thread in high latency mode. | 1716 // puts the impl thread in high latency mode. |
| 1711 client_->Reset(); | 1717 client_->Reset(); |
| 1712 scheduler_->SetNeedsBeginMainFrame(); | 1718 scheduler_->SetNeedsBeginMainFrame(); |
| 1713 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1719 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1714 SendNextBeginFrame(); | 1720 SendNextBeginFrame(); |
| 1715 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 1721 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 1716 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1722 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1717 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1723 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1718 | 1724 |
| 1719 client_->Reset(); | 1725 client_->Reset(); |
| 1720 scheduler_->DidSwapBuffersComplete(); | 1726 scheduler_->DidSwapBuffersComplete(); |
| 1721 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1727 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1722 scheduler_->NotifyReadyToCommit(); | 1728 scheduler_->NotifyReadyToCommit(); |
| 1723 scheduler_->NotifyReadyToActivate(); | 1729 scheduler_->NotifyReadyToActivate(); |
| 1724 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1730 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1725 | 1731 |
| 1726 // Verify that we don't skip the actions of the BeginImplFrame | 1732 // Verify that we don't skip the actions of the BeginImplFrame |
| 1727 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 0, 4); | 1733 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 0, 4); |
| 1728 EXPECT_ACTION("ScheduledActionCommit", client_, 1, 4); | 1734 EXPECT_ACTION("ScheduledActionCommit", client_, 1, 4); |
| 1729 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 2, 4); | 1735 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 2, 4); |
| 1730 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 4); | 1736 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 4); |
| 1731 } | 1737 } |
| 1732 } | 1738 } |
| 1733 | 1739 |
| 1734 TEST_F( | 1740 TEST_F( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1794 // To get into a high latency state, this test disables automatic swap acks. | 1800 // To get into a high latency state, this test disables automatic swap acks. |
| 1795 client_->SetAutomaticSwapAck(false); | 1801 client_->SetAutomaticSwapAck(false); |
| 1796 | 1802 |
| 1797 // Impl thread hits deadline before commit finishes to make | 1803 // Impl thread hits deadline before commit finishes to make |
| 1798 // MainThreadMissedLastDeadline true | 1804 // MainThreadMissedLastDeadline true |
| 1799 client_->Reset(); | 1805 client_->Reset(); |
| 1800 scheduler_->SetNeedsBeginMainFrame(); | 1806 scheduler_->SetNeedsBeginMainFrame(); |
| 1801 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1807 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1802 EXPECT_SCOPED(AdvanceFrame()); | 1808 EXPECT_SCOPED(AdvanceFrame()); |
| 1803 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1809 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1804 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1810 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1805 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1811 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1806 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1812 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1807 scheduler_->NotifyReadyToCommit(); | 1813 scheduler_->NotifyReadyToCommit(); |
| 1808 scheduler_->NotifyReadyToActivate(); | 1814 scheduler_->NotifyReadyToActivate(); |
| 1809 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1815 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1810 | 1816 |
| 1811 EXPECT_ACTION("AddObserver(this)", client_, 0, 5); | 1817 EXPECT_ACTION("AddObserver(this)", client_, 0, 5); |
| 1812 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); | 1818 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); |
| 1813 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); | 1819 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); |
| 1814 EXPECT_ACTION("ScheduledActionCommit", client_, 3, 5); | 1820 EXPECT_ACTION("ScheduledActionCommit", client_, 3, 5); |
| 1815 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 4, 5); | 1821 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 4, 5); |
| 1816 | 1822 |
| 1817 // Draw and swap for first commit, start second commit. | 1823 // Draw and swap for first commit, start second commit. |
| 1818 client_->Reset(); | 1824 client_->Reset(); |
| 1819 scheduler_->SetNeedsBeginMainFrame(); | 1825 scheduler_->SetNeedsBeginMainFrame(); |
| 1820 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1826 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1821 EXPECT_SCOPED(AdvanceFrame()); | 1827 EXPECT_SCOPED(AdvanceFrame()); |
| 1822 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1828 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1823 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1829 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1824 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1830 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1825 scheduler_->NotifyReadyToCommit(); | 1831 scheduler_->NotifyReadyToCommit(); |
| 1826 scheduler_->NotifyReadyToActivate(); | 1832 scheduler_->NotifyReadyToActivate(); |
| 1827 | 1833 |
| 1828 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); | 1834 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); |
| 1829 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); | 1835 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); |
| 1830 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 5); | 1836 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 5); |
| 1831 EXPECT_ACTION("ScheduledActionCommit", client_, 3, 5); | 1837 EXPECT_ACTION("ScheduledActionCommit", client_, 3, 5); |
| 1832 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 4, 5); | 1838 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 4, 5); |
| 1833 | 1839 |
| 1834 // Don't call scheduler_->DidSwapBuffersComplete() until after next frame | 1840 // Don't call scheduler_->DidSwapBuffersComplete() until after next frame |
| 1835 // to put the impl thread in a high latency mode. | 1841 // to put the impl thread in a high latency mode. |
| 1836 client_->Reset(); | 1842 client_->Reset(); |
| 1837 scheduler_->SetNeedsBeginMainFrame(); | 1843 scheduler_->SetNeedsBeginMainFrame(); |
| 1838 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1844 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1839 EXPECT_SCOPED(AdvanceFrame()); | 1845 EXPECT_SCOPED(AdvanceFrame()); |
| 1840 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1846 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1841 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1847 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1842 | 1848 |
| 1843 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 1849 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 1844 // Note: BeginMainFrame and swap are skipped here because of | 1850 // Note: BeginMainFrame and swap are skipped here because of |
| 1845 // swap ack backpressure, not because of latency recovery. | 1851 // swap ack backpressure, not because of latency recovery. |
| 1846 EXPECT_FALSE(client_->HasAction("ScheduledActionSendBeginMainFrame")); | 1852 EXPECT_FALSE(client_->HasAction("ScheduledActionSendBeginMainFrame")); |
| 1847 EXPECT_FALSE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); | 1853 EXPECT_FALSE(client_->HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 1848 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1854 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1849 | 1855 |
| 1850 // Lower estimates so that the scheduler will attempt latency recovery. | 1856 // Lower estimates so that the scheduler will attempt latency recovery. |
| 1851 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); | 1857 fake_compositor_timing_history_->SetAllEstimatesTo(kFastDuration); |
| 1852 | 1858 |
| 1853 // Now that both threads are in a high latency mode, make sure we | 1859 // Now that both threads are in a high latency mode, make sure we |
| 1854 // skip the BeginMainFrame, then the BeginImplFrame, but not both | 1860 // skip the BeginMainFrame, then the BeginImplFrame, but not both |
| 1855 // at the same time. | 1861 // at the same time. |
| 1856 | 1862 |
| 1857 // Verify we skip BeginMainFrame first. | 1863 // Verify we skip BeginMainFrame first. |
| 1858 client_->Reset(); | 1864 client_->Reset(); |
| 1859 // Previous commit request is still outstanding. | 1865 // Previous commit request is still outstanding. |
| 1860 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); | 1866 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); |
| 1861 EXPECT_TRUE(scheduler_->SwapThrottled()); | 1867 EXPECT_TRUE(scheduler_->SwapThrottled()); |
| 1862 SendNextBeginFrame(); | 1868 SendNextBeginFrame(); |
| 1863 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); | 1869 EXPECT_TRUE(scheduler_->MainThreadMissedLastDeadline()); |
| 1864 scheduler_->DidSwapBuffersComplete(); | 1870 scheduler_->DidSwapBuffersComplete(); |
| 1865 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1871 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1866 | 1872 |
| 1867 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1873 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1868 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 1874 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 1869 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 1875 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 1870 | 1876 |
| 1871 // Verify we skip the BeginImplFrame second. | 1877 // Verify we skip the BeginImplFrame second. |
| 1872 client_->Reset(); | 1878 client_->Reset(); |
| 1873 // Previous commit request is still outstanding. | 1879 // Previous commit request is still outstanding. |
| 1874 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); | 1880 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); |
| 1875 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1881 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1876 SendNextBeginFrame(); | 1882 SendNextBeginFrame(); |
| 1877 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1883 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1878 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1884 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1879 scheduler_->DidSwapBuffersComplete(); | 1885 scheduler_->DidSwapBuffersComplete(); |
| 1880 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1886 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1881 | 1887 |
| 1882 EXPECT_NO_ACTION(client_); | 1888 EXPECT_NO_ACTION(client_); |
| 1883 | 1889 |
| 1884 // Then verify we operate in a low latency mode. | 1890 // Then verify we operate in a low latency mode. |
| 1885 client_->Reset(); | 1891 client_->Reset(); |
| 1886 // Previous commit request is still outstanding. | 1892 // Previous commit request is still outstanding. |
| 1887 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); | 1893 EXPECT_TRUE(scheduler_->NeedsBeginMainFrame()); |
| 1888 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1894 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1889 SendNextBeginFrame(); | 1895 SendNextBeginFrame(); |
| 1890 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1896 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1891 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1897 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1892 scheduler_->NotifyReadyToCommit(); | 1898 scheduler_->NotifyReadyToCommit(); |
| 1893 scheduler_->NotifyReadyToActivate(); | 1899 scheduler_->NotifyReadyToActivate(); |
| 1894 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1900 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1895 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1901 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1896 scheduler_->DidSwapBuffersComplete(); | 1902 scheduler_->DidSwapBuffersComplete(); |
| 1897 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); | 1903 EXPECT_FALSE(scheduler_->MainThreadMissedLastDeadline()); |
| 1898 | 1904 |
| 1899 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); | 1905 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 5); |
| 1900 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); | 1906 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); |
| 1901 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); | 1907 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); |
| 1902 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); | 1908 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); |
| 1903 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 4, 5); | 1909 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 4, 5); |
| 1904 } | 1910 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1918 client_->SetAutomaticSwapAck(false); | 1924 client_->SetAutomaticSwapAck(false); |
| 1919 | 1925 |
| 1920 // Get a new active tree in main-thread high latency mode and put us | 1926 // Get a new active tree in main-thread high latency mode and put us |
| 1921 // in a swap throttled state. | 1927 // in a swap throttled state. |
| 1922 client_->Reset(); | 1928 client_->Reset(); |
| 1923 EXPECT_FALSE(scheduler_->CommitPending()); | 1929 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1924 scheduler_->SetNeedsBeginMainFrame(); | 1930 scheduler_->SetNeedsBeginMainFrame(); |
| 1925 scheduler_->SetNeedsRedraw(); | 1931 scheduler_->SetNeedsRedraw(); |
| 1926 EXPECT_SCOPED(AdvanceFrame()); | 1932 EXPECT_SCOPED(AdvanceFrame()); |
| 1927 EXPECT_TRUE(scheduler_->CommitPending()); | 1933 EXPECT_TRUE(scheduler_->CommitPending()); |
| 1928 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1934 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1929 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1935 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1930 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1936 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1931 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1937 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1932 scheduler_->NotifyReadyToCommit(); | 1938 scheduler_->NotifyReadyToCommit(); |
| 1933 scheduler_->NotifyReadyToActivate(); | 1939 scheduler_->NotifyReadyToActivate(); |
| 1934 EXPECT_FALSE(scheduler_->CommitPending()); | 1940 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1935 EXPECT_ACTION("AddObserver(this)", client_, 0, 6); | 1941 EXPECT_ACTION("AddObserver(this)", client_, 0, 6); |
| 1936 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 6); | 1942 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 6); |
| 1937 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 6); | 1943 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 6); |
| 1938 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 6); | 1944 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 6); |
| 1939 EXPECT_ACTION("ScheduledActionCommit", client_, 4, 6); | 1945 EXPECT_ACTION("ScheduledActionCommit", client_, 4, 6); |
| 1940 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 5, 6); | 1946 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 5, 6); |
| 1941 | 1947 |
| 1942 // Make sure that we can finish the next commit even while swap throttled. | 1948 // Make sure that we can finish the next commit even while swap throttled. |
| 1943 client_->Reset(); | 1949 client_->Reset(); |
| 1944 EXPECT_FALSE(scheduler_->CommitPending()); | 1950 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1945 scheduler_->SetNeedsBeginMainFrame(); | 1951 scheduler_->SetNeedsBeginMainFrame(); |
| 1946 EXPECT_SCOPED(AdvanceFrame()); | 1952 EXPECT_SCOPED(AdvanceFrame()); |
| 1947 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 1953 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1948 scheduler_->NotifyReadyToCommit(); | 1954 scheduler_->NotifyReadyToCommit(); |
| 1949 scheduler_->NotifyReadyToActivate(); | 1955 scheduler_->NotifyReadyToActivate(); |
| 1950 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1956 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1951 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 1957 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1952 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 1958 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1953 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 1959 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 1954 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); | 1960 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); |
| 1955 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 3); | 1961 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 3); |
| 1956 | 1962 |
| 1957 // Make sure we do not send a BeginMainFrame while swap throttled and | 1963 // Make sure we do not send a BeginMainFrame while swap throttled and |
| 1958 // we have both a pending tree and an active tree. | 1964 // we have both a pending tree and an active tree. |
| 1959 client_->Reset(); | 1965 client_->Reset(); |
| 1960 EXPECT_FALSE(scheduler_->CommitPending()); | 1966 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1961 scheduler_->SetNeedsBeginMainFrame(); | 1967 scheduler_->SetNeedsBeginMainFrame(); |
| 1962 EXPECT_SCOPED(AdvanceFrame()); | 1968 EXPECT_SCOPED(AdvanceFrame()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1983 client_->SetAutomaticSwapAck(false); | 1989 client_->SetAutomaticSwapAck(false); |
| 1984 | 1990 |
| 1985 // Start a new commit in main-thread high latency mode and hold off on | 1991 // Start a new commit in main-thread high latency mode and hold off on |
| 1986 // activation. | 1992 // activation. |
| 1987 client_->Reset(); | 1993 client_->Reset(); |
| 1988 EXPECT_FALSE(scheduler_->CommitPending()); | 1994 EXPECT_FALSE(scheduler_->CommitPending()); |
| 1989 scheduler_->SetNeedsBeginMainFrame(); | 1995 scheduler_->SetNeedsBeginMainFrame(); |
| 1990 scheduler_->SetNeedsRedraw(); | 1996 scheduler_->SetNeedsRedraw(); |
| 1991 EXPECT_SCOPED(AdvanceFrame()); | 1997 EXPECT_SCOPED(AdvanceFrame()); |
| 1992 EXPECT_TRUE(scheduler_->CommitPending()); | 1998 EXPECT_TRUE(scheduler_->CommitPending()); |
| 1993 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 1999 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 1994 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2000 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 1995 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2001 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 1996 scheduler_->DidSwapBuffersComplete(); | 2002 scheduler_->DidSwapBuffersComplete(); |
| 1997 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2003 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 1998 scheduler_->NotifyReadyToCommit(); | 2004 scheduler_->NotifyReadyToCommit(); |
| 1999 EXPECT_FALSE(scheduler_->CommitPending()); | 2005 EXPECT_FALSE(scheduler_->CommitPending()); |
| 2000 EXPECT_ACTION("AddObserver(this)", client_, 0, 5); | 2006 EXPECT_ACTION("AddObserver(this)", client_, 0, 5); |
| 2001 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); | 2007 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 5); |
| 2002 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); | 2008 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 2, 5); |
| 2003 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 5); | 2009 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 3, 5); |
| 2004 EXPECT_ACTION("ScheduledActionCommit", client_, 4, 5); | 2010 EXPECT_ACTION("ScheduledActionCommit", client_, 4, 5); |
| 2005 | 2011 |
| 2006 // Start another commit while we still have an active tree. | 2012 // Start another commit while we still have an active tree. |
| 2007 client_->Reset(); | 2013 client_->Reset(); |
| 2008 EXPECT_FALSE(scheduler_->CommitPending()); | 2014 EXPECT_FALSE(scheduler_->CommitPending()); |
| 2009 scheduler_->SetNeedsBeginMainFrame(); | 2015 scheduler_->SetNeedsBeginMainFrame(); |
| 2010 scheduler_->SetNeedsRedraw(); | 2016 scheduler_->SetNeedsRedraw(); |
| 2011 EXPECT_SCOPED(AdvanceFrame()); | 2017 EXPECT_SCOPED(AdvanceFrame()); |
| 2012 EXPECT_TRUE(scheduler_->CommitPending()); | 2018 EXPECT_TRUE(scheduler_->CommitPending()); |
| 2013 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2019 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2014 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2020 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2015 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2021 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2016 scheduler_->DidSwapBuffersComplete(); | 2022 scheduler_->DidSwapBuffersComplete(); |
| 2017 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2023 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2018 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 2024 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 2019 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); | 2025 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); |
| 2020 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); | 2026 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 2, 3); |
| 2021 | 2027 |
| 2022 // Can't commit yet because there's still a pending tree. | 2028 // Can't commit yet because there's still a pending tree. |
| 2023 client_->Reset(); | 2029 client_->Reset(); |
| 2024 scheduler_->NotifyReadyToCommit(); | 2030 scheduler_->NotifyReadyToCommit(); |
| 2025 EXPECT_NO_ACTION(client_); | 2031 EXPECT_NO_ACTION(client_); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2042 client_->Reset(); | 2048 client_->Reset(); |
| 2043 | 2049 |
| 2044 // Create a BeginFrame with a long deadline to avoid race conditions. | 2050 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 2045 // This is the first BeginFrame, which will be handled immediately. | 2051 // This is the first BeginFrame, which will be handled immediately. |
| 2046 BeginFrameArgs args = | 2052 BeginFrameArgs args = |
| 2047 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 2053 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
| 2048 args.deadline += base::TimeDelta::FromHours(1); | 2054 args.deadline += base::TimeDelta::FromHours(1); |
| 2049 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2055 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 2050 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2056 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2051 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2057 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2052 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2058 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2053 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2059 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2054 client_->Reset(); | 2060 client_->Reset(); |
| 2055 | 2061 |
| 2056 // Queue BeginFrames while we are still handling the previous BeginFrame. | 2062 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 2057 args.frame_time += base::TimeDelta::FromSeconds(1); | 2063 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 2058 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2064 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 2059 args.frame_time += base::TimeDelta::FromSeconds(1); | 2065 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 2060 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2066 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 2061 | 2067 |
| 2062 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 2068 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 2063 task_runner().RunPendingTasks(); // Run posted deadline. | 2069 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2064 EXPECT_NO_ACTION(client_); | 2070 EXPECT_NO_ACTION(client_); |
| 2065 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2071 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2066 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2072 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2067 client_->Reset(); | 2073 client_->Reset(); |
| 2068 | 2074 |
| 2069 // NotifyReadyToCommit should trigger the commit. | 2075 // NotifyReadyToCommit should trigger the commit. |
| 2070 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2076 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2071 scheduler_->NotifyReadyToCommit(); | 2077 scheduler_->NotifyReadyToCommit(); |
| 2072 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2078 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2073 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2079 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2074 client_->Reset(); | 2080 client_->Reset(); |
| 2075 | 2081 |
| 2076 // NotifyReadyToActivate should trigger the activation. | 2082 // NotifyReadyToActivate should trigger the activation. |
| 2077 scheduler_->NotifyReadyToActivate(); | 2083 scheduler_->NotifyReadyToActivate(); |
| 2078 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2084 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2079 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2085 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2080 client_->Reset(); | 2086 client_->Reset(); |
| 2081 | 2087 |
| 2082 // BeginImplFrame should prepare the draw. | 2088 // BeginImplFrame should prepare the draw. |
| 2083 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 2089 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 2084 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2090 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2085 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2091 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2086 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2092 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2087 client_->Reset(); | 2093 client_->Reset(); |
| 2088 | 2094 |
| 2089 // BeginImplFrame deadline should draw. | 2095 // BeginImplFrame deadline should draw. |
| 2090 task_runner().RunPendingTasks(); // Run posted deadline. | 2096 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2091 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2097 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2092 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2098 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2093 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2099 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2094 client_->Reset(); | 2100 client_->Reset(); |
| 2095 | 2101 |
| 2096 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 2102 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 2097 // to avoid excessive toggles. | 2103 // to avoid excessive toggles. |
| 2098 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 2104 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 2099 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2105 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2100 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2106 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2101 client_->Reset(); | 2107 client_->Reset(); |
| 2102 | 2108 |
| 2103 task_runner().RunPendingTasks(); // Run posted deadline. | 2109 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2104 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); | 2110 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); |
| 2105 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 2111 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); |
| 2106 client_->Reset(); | 2112 client_->Reset(); |
| 2107 } | 2113 } |
| 2108 | 2114 |
| 2109 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { | 2115 TEST_F(SchedulerTest, RetroFrameDoesNotExpireTooEarly) { |
| 2110 scheduler_settings_.use_external_begin_frame_source = true; | 2116 scheduler_settings_.use_external_begin_frame_source = true; |
| 2111 SetUpScheduler(true); | 2117 SetUpScheduler(true); |
| 2112 | 2118 |
| 2113 scheduler_->SetNeedsBeginMainFrame(); | 2119 scheduler_->SetNeedsBeginMainFrame(); |
| 2114 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2120 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2115 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2121 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2116 | 2122 |
| 2117 client_->Reset(); | 2123 client_->Reset(); |
| 2118 EXPECT_SCOPED(AdvanceFrame()); | 2124 EXPECT_SCOPED(AdvanceFrame()); |
| 2119 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2125 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2120 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2126 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2121 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2127 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2122 | 2128 |
| 2123 client_->Reset(); | 2129 client_->Reset(); |
| 2124 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2130 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2125 | 2131 |
| 2126 client_->Reset(); | 2132 client_->Reset(); |
| 2127 BeginFrameArgs retro_frame_args = SendNextBeginFrame(); | 2133 BeginFrameArgs retro_frame_args = SendNextBeginFrame(); |
| 2128 // This BeginFrame is queued up as a retro frame. | 2134 // This BeginFrame is queued up as a retro frame. |
| 2129 EXPECT_NO_ACTION(client_); | 2135 EXPECT_NO_ACTION(client_); |
| 2130 // The previous deadline is still pending. | 2136 // The previous deadline is still pending. |
| 2131 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2137 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2132 | 2138 |
| 2133 client_->Reset(); | 2139 client_->Reset(); |
| 2134 // This main frame activating should schedule the (previous) deadline to | 2140 // This main frame activating should schedule the (previous) deadline to |
| 2135 // trigger immediately. | 2141 // trigger immediately. |
| 2136 scheduler_->NotifyReadyToCommit(); | 2142 scheduler_->NotifyReadyToCommit(); |
| 2137 scheduler_->NotifyReadyToActivate(); | 2143 scheduler_->NotifyReadyToActivate(); |
| 2138 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); | 2144 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); |
| 2139 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); | 2145 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); |
| 2140 | 2146 |
| 2141 client_->Reset(); | 2147 client_->Reset(); |
| 2142 // The deadline task should trigger causing a draw. | 2148 // The deadline task should trigger causing a draw. |
| 2143 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2149 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2144 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2150 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2145 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2151 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2146 | 2152 |
| 2147 // Keep animating. | 2153 // Keep animating. |
| 2148 client_->Reset(); | 2154 client_->Reset(); |
| 2149 scheduler_->SetNeedsOneBeginImplFrame(); | 2155 scheduler_->SetNeedsOneBeginImplFrame(); |
| 2150 scheduler_->SetNeedsRedraw(); | 2156 scheduler_->SetNeedsRedraw(); |
| 2151 EXPECT_NO_ACTION(client_); | 2157 EXPECT_NO_ACTION(client_); |
| 2152 | 2158 |
| 2153 // Let's advance to the retro frame's deadline. | 2159 // Let's advance to the retro frame's deadline. |
| 2154 now_src()->Advance(retro_frame_args.deadline - now_src()->NowTicks()); | 2160 now_src()->Advance(retro_frame_args.deadline - now_src()->NowTicks()); |
| 2155 | 2161 |
| 2156 // The retro frame hasn't expired yet. | 2162 // The retro frame hasn't expired yet. |
| 2157 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(false)); | 2163 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(false)); |
| 2158 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2164 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2159 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2165 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2160 | 2166 |
| 2161 // This is an immediate deadline case. | 2167 // This is an immediate deadline case. |
| 2162 client_->Reset(); | 2168 client_->Reset(); |
| 2163 task_runner().RunPendingTasks(); | 2169 task_runner().RunPendingTasks(); |
| 2164 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2170 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2165 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2171 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 2166 } | 2172 } |
| 2167 | 2173 |
| 2168 TEST_F(SchedulerTest, RetroFrameExpiresOnTime) { | 2174 TEST_F(SchedulerTest, RetroFrameExpiresOnTime) { |
| 2169 scheduler_settings_.use_external_begin_frame_source = true; | 2175 scheduler_settings_.use_external_begin_frame_source = true; |
| 2170 SetUpScheduler(true); | 2176 SetUpScheduler(true); |
| 2171 | 2177 |
| 2172 scheduler_->SetNeedsBeginMainFrame(); | 2178 scheduler_->SetNeedsBeginMainFrame(); |
| 2173 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2179 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2174 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2180 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2175 | 2181 |
| 2176 client_->Reset(); | 2182 client_->Reset(); |
| 2177 EXPECT_SCOPED(AdvanceFrame()); | 2183 EXPECT_SCOPED(AdvanceFrame()); |
| 2178 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2184 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2179 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2185 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2180 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2186 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2181 | 2187 |
| 2182 client_->Reset(); | 2188 client_->Reset(); |
| 2183 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2189 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2184 | 2190 |
| 2185 client_->Reset(); | 2191 client_->Reset(); |
| 2186 BeginFrameArgs retro_frame_args = SendNextBeginFrame(); | 2192 BeginFrameArgs retro_frame_args = SendNextBeginFrame(); |
| 2187 // This BeginFrame is queued up as a retro frame. | 2193 // This BeginFrame is queued up as a retro frame. |
| 2188 EXPECT_NO_ACTION(client_); | 2194 EXPECT_NO_ACTION(client_); |
| 2189 // The previous deadline is still pending. | 2195 // The previous deadline is still pending. |
| 2190 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2196 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2191 | 2197 |
| 2192 client_->Reset(); | 2198 client_->Reset(); |
| 2193 // This main frame activating should schedule the (previous) deadline to | 2199 // This main frame activating should schedule the (previous) deadline to |
| 2194 // trigger immediately. | 2200 // trigger immediately. |
| 2195 scheduler_->NotifyReadyToCommit(); | 2201 scheduler_->NotifyReadyToCommit(); |
| 2196 scheduler_->NotifyReadyToActivate(); | 2202 scheduler_->NotifyReadyToActivate(); |
| 2197 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); | 2203 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); |
| 2198 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); | 2204 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); |
| 2199 | 2205 |
| 2200 client_->Reset(); | 2206 client_->Reset(); |
| 2201 // The deadline task should trigger causing a draw. | 2207 // The deadline task should trigger causing a draw. |
| 2202 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2208 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2203 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2209 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2204 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2210 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2205 | 2211 |
| 2206 // Keep animating. | 2212 // Keep animating. |
| 2207 client_->Reset(); | 2213 client_->Reset(); |
| 2208 scheduler_->SetNeedsOneBeginImplFrame(); | 2214 scheduler_->SetNeedsOneBeginImplFrame(); |
| 2209 scheduler_->SetNeedsRedraw(); | 2215 scheduler_->SetNeedsRedraw(); |
| 2210 EXPECT_NO_ACTION(client_); | 2216 EXPECT_NO_ACTION(client_); |
| 2211 | 2217 |
| 2212 // Let's advance sufficiently past the retro frame's deadline. | 2218 // Let's advance sufficiently past the retro frame's deadline. |
| 2213 now_src()->Advance(retro_frame_args.deadline - now_src()->NowTicks() + | 2219 now_src()->Advance(retro_frame_args.deadline - now_src()->NowTicks() + |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2229 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 2235 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
| 2230 missed_frame_args.type = BeginFrameArgs::MISSED; | 2236 missed_frame_args.type = BeginFrameArgs::MISSED; |
| 2231 | 2237 |
| 2232 // Advance to the deadline. | 2238 // Advance to the deadline. |
| 2233 now_src()->Advance(missed_frame_args.deadline - now_src()->NowTicks()); | 2239 now_src()->Advance(missed_frame_args.deadline - now_src()->NowTicks()); |
| 2234 | 2240 |
| 2235 // Missed frame is handled because it's on time. | 2241 // Missed frame is handled because it's on time. |
| 2236 client_->Reset(); | 2242 client_->Reset(); |
| 2237 fake_external_begin_frame_source_->TestOnBeginFrame(missed_frame_args); | 2243 fake_external_begin_frame_source_->TestOnBeginFrame(missed_frame_args); |
| 2238 EXPECT_TRUE( | 2244 EXPECT_TRUE( |
| 2239 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(false))); | 2245 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(false))); |
| 2240 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2246 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2241 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2247 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2242 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2248 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2243 } | 2249 } |
| 2244 | 2250 |
| 2245 TEST_F(SchedulerTest, MissedFrameExpiresOnTime) { | 2251 TEST_F(SchedulerTest, MissedFrameExpiresOnTime) { |
| 2246 scheduler_settings_.use_external_begin_frame_source = true; | 2252 scheduler_settings_.use_external_begin_frame_source = true; |
| 2247 SetUpScheduler(true); | 2253 SetUpScheduler(true); |
| 2248 | 2254 |
| 2249 scheduler_->SetNeedsBeginMainFrame(); | 2255 scheduler_->SetNeedsBeginMainFrame(); |
| 2250 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2256 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2251 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2257 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2252 | 2258 |
| 2253 BeginFrameArgs missed_frame_args = | 2259 BeginFrameArgs missed_frame_args = |
| 2254 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 2260 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
| 2255 missed_frame_args.type = BeginFrameArgs::MISSED; | 2261 missed_frame_args.type = BeginFrameArgs::MISSED; |
| 2256 | 2262 |
| 2257 // Advance sufficiently past the deadline. | 2263 // Advance sufficiently past the deadline. |
| 2258 now_src()->Advance(missed_frame_args.deadline - now_src()->NowTicks() + | 2264 now_src()->Advance(missed_frame_args.deadline - now_src()->NowTicks() + |
| 2259 base::TimeDelta::FromMicroseconds(1)); | 2265 base::TimeDelta::FromMicroseconds(1)); |
| 2260 | 2266 |
| 2261 // Missed frame is dropped because it's too late. | 2267 // Missed frame is dropped because it's too late. |
| 2262 client_->Reset(); | 2268 client_->Reset(); |
| 2263 fake_external_begin_frame_source_->TestOnBeginFrame(missed_frame_args); | 2269 fake_external_begin_frame_source_->TestOnBeginFrame(missed_frame_args); |
| 2264 EXPECT_FALSE( | 2270 EXPECT_FALSE( |
| 2265 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(false))); | 2271 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(false))); |
| 2266 EXPECT_NO_ACTION(client_); | 2272 EXPECT_NO_ACTION(client_); |
| 2267 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2273 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2268 } | 2274 } |
| 2269 | 2275 |
| 2270 void SchedulerTest::BeginFramesNotFromClient( | 2276 void SchedulerTest::BeginFramesNotFromClient( |
| 2271 bool use_external_begin_frame_source, | 2277 bool use_external_begin_frame_source, |
| 2272 bool throttle_frame_production) { | 2278 bool throttle_frame_production) { |
| 2273 scheduler_settings_.use_external_begin_frame_source = | 2279 scheduler_settings_.use_external_begin_frame_source = |
| 2274 use_external_begin_frame_source; | 2280 use_external_begin_frame_source; |
| 2275 scheduler_settings_.throttle_frame_production = throttle_frame_production; | 2281 scheduler_settings_.throttle_frame_production = throttle_frame_production; |
| 2276 SetUpScheduler(true); | 2282 SetUpScheduler(true); |
| 2277 | 2283 |
| 2278 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame | 2284 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame |
| 2279 // without calling SetNeedsBeginFrame. | 2285 // without calling SetNeedsBeginFrame. |
| 2280 scheduler_->SetNeedsBeginMainFrame(); | 2286 scheduler_->SetNeedsBeginMainFrame(); |
| 2281 EXPECT_NO_ACTION(client_); | 2287 EXPECT_NO_ACTION(client_); |
| 2282 client_->Reset(); | 2288 client_->Reset(); |
| 2283 | 2289 |
| 2284 // When the client-driven BeginFrame are disabled, the scheduler posts it's | 2290 // When the client-driven BeginFrame are disabled, the scheduler posts it's |
| 2285 // own BeginFrame tasks. | 2291 // own BeginFrame tasks. |
| 2286 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2292 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2287 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2293 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2288 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2294 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2289 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2295 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2290 client_->Reset(); | 2296 client_->Reset(); |
| 2291 | 2297 |
| 2292 // If we don't swap on the deadline, we wait for the next BeginFrame. | 2298 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 2293 task_runner().RunPendingTasks(); // Run posted deadline. | 2299 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2294 EXPECT_NO_ACTION(client_); | 2300 EXPECT_NO_ACTION(client_); |
| 2295 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2301 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2296 client_->Reset(); | 2302 client_->Reset(); |
| 2297 | 2303 |
| 2298 // NotifyReadyToCommit should trigger the commit. | 2304 // NotifyReadyToCommit should trigger the commit. |
| 2299 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2305 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2300 scheduler_->NotifyReadyToCommit(); | 2306 scheduler_->NotifyReadyToCommit(); |
| 2301 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2307 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2302 client_->Reset(); | 2308 client_->Reset(); |
| 2303 | 2309 |
| 2304 // NotifyReadyToActivate should trigger the activation. | 2310 // NotifyReadyToActivate should trigger the activation. |
| 2305 scheduler_->NotifyReadyToActivate(); | 2311 scheduler_->NotifyReadyToActivate(); |
| 2306 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2312 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2307 client_->Reset(); | 2313 client_->Reset(); |
| 2308 | 2314 |
| 2309 // BeginImplFrame should prepare the draw. | 2315 // BeginImplFrame should prepare the draw. |
| 2310 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2316 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2311 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2317 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2312 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2318 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2313 client_->Reset(); | 2319 client_->Reset(); |
| 2314 | 2320 |
| 2315 // BeginImplFrame deadline should draw. | 2321 // BeginImplFrame deadline should draw. |
| 2316 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2322 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2317 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2323 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2318 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2324 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2319 client_->Reset(); | 2325 client_->Reset(); |
| 2320 | 2326 |
| 2321 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 2327 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 2322 // to avoid excessive toggles. | 2328 // to avoid excessive toggles. |
| 2323 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2329 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2324 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2330 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2325 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2331 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2326 client_->Reset(); | 2332 client_->Reset(); |
| 2327 | 2333 |
| 2328 // Make sure SetNeedsBeginFrame isn't called on the client | 2334 // Make sure SetNeedsBeginFrame isn't called on the client |
| 2329 // when the BeginFrame is no longer needed. | 2335 // when the BeginFrame is no longer needed. |
| 2330 task_runner().RunPendingTasks(); // Run posted deadline. | 2336 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2331 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); | 2337 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); |
| 2332 client_->Reset(); | 2338 client_->Reset(); |
| 2333 } | 2339 } |
| 2334 | 2340 |
| 2335 TEST_F(SchedulerTest, SyntheticBeginFrames) { | 2341 TEST_F(SchedulerTest, SyntheticBeginFrames) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2373 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 2379 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| 2374 client_->Reset(); | 2380 client_->Reset(); |
| 2375 scheduler_->SetNeedsBeginMainFrame(); | 2381 scheduler_->SetNeedsBeginMainFrame(); |
| 2376 EXPECT_NO_ACTION(client_); | 2382 EXPECT_NO_ACTION(client_); |
| 2377 client_->Reset(); | 2383 client_->Reset(); |
| 2378 | 2384 |
| 2379 // Trigger the first BeginImplFrame and BeginMainFrame | 2385 // Trigger the first BeginImplFrame and BeginMainFrame |
| 2380 EXPECT_SCOPED(AdvanceFrame()); | 2386 EXPECT_SCOPED(AdvanceFrame()); |
| 2381 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2387 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2382 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2388 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2383 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2389 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2384 client_->Reset(); | 2390 client_->Reset(); |
| 2385 | 2391 |
| 2386 // NotifyReadyToCommit should trigger the pending commit. | 2392 // NotifyReadyToCommit should trigger the pending commit. |
| 2387 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2393 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2388 scheduler_->NotifyReadyToCommit(); | 2394 scheduler_->NotifyReadyToCommit(); |
| 2389 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2395 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2390 client_->Reset(); | 2396 client_->Reset(); |
| 2391 | 2397 |
| 2392 // NotifyReadyToActivate should trigger the activation and draw. | 2398 // NotifyReadyToActivate should trigger the activation and draw. |
| 2393 scheduler_->NotifyReadyToActivate(); | 2399 scheduler_->NotifyReadyToActivate(); |
| 2394 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2400 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2395 client_->Reset(); | 2401 client_->Reset(); |
| 2396 | 2402 |
| 2397 // Swapping will put us into a swap throttled state. | 2403 // Swapping will put us into a swap throttled state. |
| 2398 // Run posted deadline. | 2404 // Run posted deadline. |
| 2399 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2405 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2400 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2406 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2401 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2407 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2402 client_->Reset(); | 2408 client_->Reset(); |
| 2403 | 2409 |
| 2404 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 2410 // While swap throttled, BeginFrames should trigger BeginImplFrames, |
| 2405 // but not a BeginMainFrame or draw. | 2411 // but not a BeginMainFrame or draw. |
| 2406 scheduler_->SetNeedsBeginMainFrame(); | 2412 scheduler_->SetNeedsBeginMainFrame(); |
| 2407 scheduler_->SetNeedsRedraw(); | 2413 scheduler_->SetNeedsRedraw(); |
| 2408 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. | 2414 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. |
| 2409 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2415 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2410 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2416 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2411 client_->Reset(); | 2417 client_->Reset(); |
| 2412 | 2418 |
| 2413 base::TimeTicks before_deadline, after_deadline; | 2419 base::TimeTicks before_deadline, after_deadline; |
| 2414 | 2420 |
| 2415 // The deadline is set to the regular deadline. | 2421 // The deadline is set to the regular deadline. |
| 2416 before_deadline = now_src()->NowTicks(); | 2422 before_deadline = now_src()->NowTicks(); |
| 2417 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2423 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2418 after_deadline = now_src()->NowTicks(); | 2424 after_deadline = now_src()->NowTicks(); |
| 2419 // We can't do an equality comparison here because the scheduler uses a fudge | 2425 // We can't do an equality comparison here because the scheduler uses a fudge |
| 2420 // factor that's an internal implementation detail. | 2426 // factor that's an internal implementation detail. |
| 2421 EXPECT_GT(after_deadline, before_deadline); | 2427 EXPECT_GT(after_deadline, before_deadline); |
| 2422 EXPECT_LT(after_deadline, | 2428 EXPECT_LT(after_deadline, |
| 2423 before_deadline + BeginFrameArgs::DefaultInterval()); | 2429 before_deadline + BeginFrameArgs::DefaultInterval()); |
| 2424 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2430 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2425 client_->Reset(); | 2431 client_->Reset(); |
| 2426 | 2432 |
| 2427 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. | 2433 EXPECT_SCOPED(AdvanceFrame()); // Run posted BeginFrame. |
| 2428 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2434 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2429 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2435 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2430 client_->Reset(); | 2436 client_->Reset(); |
| 2431 | 2437 |
| 2432 // Take us out of a swap throttled state. | 2438 // Take us out of a swap throttled state. |
| 2433 scheduler_->DidSwapBuffersComplete(); | 2439 scheduler_->DidSwapBuffersComplete(); |
| 2434 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 2440 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 2435 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2441 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2436 client_->Reset(); | 2442 client_->Reset(); |
| 2437 | 2443 |
| 2438 // The deadline is set to the regular deadline. | 2444 // The deadline is set to the regular deadline. |
| 2439 before_deadline = now_src()->NowTicks(); | 2445 before_deadline = now_src()->NowTicks(); |
| 2440 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2446 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2441 after_deadline = now_src()->NowTicks(); | 2447 after_deadline = now_src()->NowTicks(); |
| 2442 // We can't do an equality comparison here because the scheduler uses a fudge | 2448 // We can't do an equality comparison here because the scheduler uses a fudge |
| 2443 // factor that's an internal implementation detail. | 2449 // factor that's an internal implementation detail. |
| 2444 EXPECT_GT(after_deadline, before_deadline); | 2450 EXPECT_GT(after_deadline, before_deadline); |
| 2445 EXPECT_LT(after_deadline, | 2451 EXPECT_LT(after_deadline, |
| 2446 before_deadline + BeginFrameArgs::DefaultInterval()); | 2452 before_deadline + BeginFrameArgs::DefaultInterval()); |
| 2447 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2453 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2448 client_->Reset(); | 2454 client_->Reset(); |
| 2449 } | 2455 } |
| 2450 | 2456 |
| 2451 TEST_F(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { | 2457 TEST_F(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { |
| 2452 bool use_external_begin_frame_source = false; | 2458 bool use_external_begin_frame_source = false; |
| 2453 bool throttle_frame_production = true; | 2459 bool throttle_frame_production = true; |
| 2454 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, | 2460 BeginFramesNotFromClient_SwapThrottled(use_external_begin_frame_source, |
| 2455 throttle_frame_production); | 2461 throttle_frame_production); |
| 2456 } | 2462 } |
| 2457 | 2463 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2491 SetUpScheduler(true); | 2497 SetUpScheduler(true); |
| 2492 | 2498 |
| 2493 // SetNeedsBeginMainFrame should begin the frame. | 2499 // SetNeedsBeginMainFrame should begin the frame. |
| 2494 scheduler_->SetNeedsBeginMainFrame(); | 2500 scheduler_->SetNeedsBeginMainFrame(); |
| 2495 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2501 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2496 | 2502 |
| 2497 client_->Reset(); | 2503 client_->Reset(); |
| 2498 EXPECT_SCOPED(AdvanceFrame()); | 2504 EXPECT_SCOPED(AdvanceFrame()); |
| 2499 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2505 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2500 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2506 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2501 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2507 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2502 | 2508 |
| 2503 client_->Reset(); | 2509 client_->Reset(); |
| 2504 scheduler_->DidLoseOutputSurface(); | 2510 scheduler_->DidLoseOutputSurface(); |
| 2505 // RemoveObserver(this) is not called until the end of the frame. | 2511 // RemoveObserver(this) is not called until the end of the frame. |
| 2506 EXPECT_NO_ACTION(client_); | 2512 EXPECT_NO_ACTION(client_); |
| 2507 | 2513 |
| 2508 client_->Reset(); | 2514 client_->Reset(); |
| 2509 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2515 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2510 scheduler_->NotifyReadyToCommit(); | 2516 scheduler_->NotifyReadyToCommit(); |
| 2511 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); | 2517 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 2); |
| 2512 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); | 2518 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 2); |
| 2513 | 2519 |
| 2514 client_->Reset(); | 2520 client_->Reset(); |
| 2515 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2521 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2516 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | 2522 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); |
| 2517 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2523 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2518 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2524 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2519 } | 2525 } |
| 2520 | 2526 |
| 2521 TEST_F(SchedulerTest, | 2527 TEST_F(SchedulerTest, |
| 2522 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency) { | 2528 DidLoseOutputSurfaceAfterBeginFrameStartedWithHighLatency) { |
| 2523 scheduler_settings_.use_external_begin_frame_source = true; | 2529 scheduler_settings_.use_external_begin_frame_source = true; |
| 2524 SetUpScheduler(true); | 2530 SetUpScheduler(true); |
| 2525 | 2531 |
| 2526 // SetNeedsBeginMainFrame should begin the frame. | 2532 // SetNeedsBeginMainFrame should begin the frame. |
| 2527 scheduler_->SetNeedsBeginMainFrame(); | 2533 scheduler_->SetNeedsBeginMainFrame(); |
| 2528 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2534 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2529 | 2535 |
| 2530 client_->Reset(); | 2536 client_->Reset(); |
| 2531 EXPECT_SCOPED(AdvanceFrame()); | 2537 EXPECT_SCOPED(AdvanceFrame()); |
| 2532 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2538 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2533 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2539 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2534 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2540 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2535 | 2541 |
| 2536 client_->Reset(); | 2542 client_->Reset(); |
| 2537 scheduler_->DidLoseOutputSurface(); | 2543 scheduler_->DidLoseOutputSurface(); |
| 2538 // Do nothing when impl frame is in deadine pending state. | 2544 // Do nothing when impl frame is in deadine pending state. |
| 2539 EXPECT_NO_ACTION(client_); | 2545 EXPECT_NO_ACTION(client_); |
| 2540 | 2546 |
| 2541 client_->Reset(); | 2547 client_->Reset(); |
| 2542 // Run posted deadline. | 2548 // Run posted deadline. |
| 2543 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2549 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2544 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2550 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2545 // OnBeginImplFrameDeadline didn't schedule output surface creation because | 2551 // OnBeginImplFrameDeadline didn't schedule output surface creation because |
| 2546 // main frame is not yet completed. | 2552 // main frame is not yet completed. |
| 2547 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); | 2553 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); |
| 2548 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 2554 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); |
| 2549 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2555 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2550 | 2556 |
| 2551 // BeginImplFrame is not started. | 2557 // BeginImplFrame is not started. |
| 2552 client_->Reset(); | 2558 client_->Reset(); |
| 2553 task_runner().RunUntilTime(now_src()->NowTicks() + | 2559 task_runner().RunUntilTime(now_src()->NowTicks() + |
| 2554 base::TimeDelta::FromMilliseconds(10)); | 2560 base::TimeDelta::FromMilliseconds(10)); |
| 2555 EXPECT_NO_ACTION(client_); | 2561 EXPECT_NO_ACTION(client_); |
| 2556 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2562 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2557 | 2563 |
| 2558 client_->Reset(); | 2564 client_->Reset(); |
| 2559 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2565 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2560 scheduler_->NotifyReadyToCommit(); | 2566 scheduler_->NotifyReadyToCommit(); |
| 2561 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); | 2567 EXPECT_ACTION("ScheduledActionCommit", client_, 0, 3); |
| 2562 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); | 2568 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 1, 3); |
| 2563 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 2, 3); | 2569 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 2, 3); |
| 2564 } | 2570 } |
| 2565 | 2571 |
| 2566 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { | 2572 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterReadyToCommit) { |
| 2567 scheduler_settings_.use_external_begin_frame_source = true; | 2573 scheduler_settings_.use_external_begin_frame_source = true; |
| 2568 SetUpScheduler(true); | 2574 SetUpScheduler(true); |
| 2569 | 2575 |
| 2570 // SetNeedsBeginMainFrame should begin the frame. | 2576 // SetNeedsBeginMainFrame should begin the frame. |
| 2571 scheduler_->SetNeedsBeginMainFrame(); | 2577 scheduler_->SetNeedsBeginMainFrame(); |
| 2572 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2578 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2573 | 2579 |
| 2574 client_->Reset(); | 2580 client_->Reset(); |
| 2575 EXPECT_SCOPED(AdvanceFrame()); | 2581 EXPECT_SCOPED(AdvanceFrame()); |
| 2576 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2582 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2577 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2583 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2578 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2584 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2579 | 2585 |
| 2580 client_->Reset(); | 2586 client_->Reset(); |
| 2581 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2587 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2582 scheduler_->NotifyReadyToCommit(); | 2588 scheduler_->NotifyReadyToCommit(); |
| 2583 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2589 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2584 | 2590 |
| 2585 client_->Reset(); | 2591 client_->Reset(); |
| 2586 scheduler_->DidLoseOutputSurface(); | 2592 scheduler_->DidLoseOutputSurface(); |
| 2587 // Sync tree should be forced to activate. | 2593 // Sync tree should be forced to activate. |
| 2588 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2594 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2589 | 2595 |
| 2590 // RemoveObserver(this) is not called until the end of the frame. | 2596 // RemoveObserver(this) is not called until the end of the frame. |
| 2591 client_->Reset(); | 2597 client_->Reset(); |
| 2592 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2598 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2593 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | 2599 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); |
| 2594 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2600 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2595 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2601 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2596 } | 2602 } |
| 2597 | 2603 |
| 2598 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { | 2604 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterSetNeedsPrepareTiles) { |
| 2599 scheduler_settings_.use_external_begin_frame_source = true; | 2605 scheduler_settings_.use_external_begin_frame_source = true; |
| 2600 SetUpScheduler(true); | 2606 SetUpScheduler(true); |
| 2601 | 2607 |
| 2602 scheduler_->SetNeedsPrepareTiles(); | 2608 scheduler_->SetNeedsPrepareTiles(); |
| 2603 scheduler_->SetNeedsRedraw(); | 2609 scheduler_->SetNeedsRedraw(); |
| 2604 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2610 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2605 | 2611 |
| 2606 client_->Reset(); | 2612 client_->Reset(); |
| 2607 EXPECT_SCOPED(AdvanceFrame()); | 2613 EXPECT_SCOPED(AdvanceFrame()); |
| 2608 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2614 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2609 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2615 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2610 | 2616 |
| 2611 client_->Reset(); | 2617 client_->Reset(); |
| 2612 scheduler_->DidLoseOutputSurface(); | 2618 scheduler_->DidLoseOutputSurface(); |
| 2613 // RemoveObserver(this) is not called until the end of the frame. | 2619 // RemoveObserver(this) is not called until the end of the frame. |
| 2614 EXPECT_NO_ACTION(client_); | 2620 EXPECT_NO_ACTION(client_); |
| 2615 | 2621 |
| 2616 client_->Reset(); | 2622 client_->Reset(); |
| 2617 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2623 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2618 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 4); | 2624 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 0, 4); |
| 2619 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 4); | 2625 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 1, 4); |
| 2620 EXPECT_ACTION("RemoveObserver(this)", client_, 2, 4); | 2626 EXPECT_ACTION("RemoveObserver(this)", client_, 2, 4); |
| 2621 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 3, 4); | 2627 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 3, 4); |
| 2622 } | 2628 } |
| 2623 | 2629 |
| 2624 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { | 2630 TEST_F(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { |
| 2625 scheduler_settings_.use_external_begin_frame_source = true; | 2631 scheduler_settings_.use_external_begin_frame_source = true; |
| 2626 SetUpScheduler(true); | 2632 SetUpScheduler(true); |
| 2627 | 2633 |
| 2628 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 2634 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| 2629 scheduler_->SetNeedsBeginMainFrame(); | 2635 scheduler_->SetNeedsBeginMainFrame(); |
| 2630 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2636 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2631 | 2637 |
| 2632 // Create a BeginFrame with a long deadline to avoid race conditions. | 2638 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 2633 // This is the first BeginFrame, which will be handled immediately. | 2639 // This is the first BeginFrame, which will be handled immediately. |
| 2634 client_->Reset(); | 2640 client_->Reset(); |
| 2635 BeginFrameArgs args = | 2641 BeginFrameArgs args = |
| 2636 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 2642 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
| 2637 args.deadline += base::TimeDelta::FromHours(1); | 2643 args.deadline += base::TimeDelta::FromHours(1); |
| 2638 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2644 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 2639 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2645 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2640 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2646 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2641 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2647 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2642 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2648 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2643 | 2649 |
| 2644 // Queue BeginFrames while we are still handling the previous BeginFrame. | 2650 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 2645 args.frame_time += base::TimeDelta::FromSeconds(1); | 2651 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 2646 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2652 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 2647 args.frame_time += base::TimeDelta::FromSeconds(1); | 2653 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 2648 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2654 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 2649 | 2655 |
| 2650 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 2656 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 2651 client_->Reset(); | 2657 client_->Reset(); |
| 2652 task_runner().RunPendingTasks(); // Run posted deadline. | 2658 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2653 EXPECT_NO_ACTION(client_); | 2659 EXPECT_NO_ACTION(client_); |
| 2654 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2660 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2655 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2661 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2656 | 2662 |
| 2657 // NotifyReadyToCommit should trigger the commit. | 2663 // NotifyReadyToCommit should trigger the commit. |
| 2658 client_->Reset(); | 2664 client_->Reset(); |
| 2659 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2665 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2660 scheduler_->NotifyReadyToCommit(); | 2666 scheduler_->NotifyReadyToCommit(); |
| 2661 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2667 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2662 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2668 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2663 | 2669 |
| 2664 // NotifyReadyToActivate should trigger the activation. | 2670 // NotifyReadyToActivate should trigger the activation. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2691 | 2697 |
| 2692 // Create a BeginFrame with a long deadline to avoid race conditions. | 2698 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 2693 // This is the first BeginFrame, which will be handled immediately. | 2699 // This is the first BeginFrame, which will be handled immediately. |
| 2694 client_->Reset(); | 2700 client_->Reset(); |
| 2695 BeginFrameArgs args = | 2701 BeginFrameArgs args = |
| 2696 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); | 2702 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, now_src()); |
| 2697 args.deadline += base::TimeDelta::FromHours(1); | 2703 args.deadline += base::TimeDelta::FromHours(1); |
| 2698 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2704 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 2699 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2705 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2700 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2706 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2701 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2707 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2702 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2708 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2703 | 2709 |
| 2704 // Queue BeginFrames while we are still handling the previous BeginFrame. | 2710 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 2705 args.frame_time += base::TimeDelta::FromSeconds(1); | 2711 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 2706 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2712 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 2707 args.frame_time += base::TimeDelta::FromSeconds(1); | 2713 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 2708 fake_external_begin_frame_source()->TestOnBeginFrame(args); | 2714 fake_external_begin_frame_source()->TestOnBeginFrame(args); |
| 2709 | 2715 |
| 2710 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 2716 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 2711 client_->Reset(); | 2717 client_->Reset(); |
| 2712 task_runner().RunPendingTasks(); // Run posted deadline. | 2718 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2713 EXPECT_NO_ACTION(client_); | 2719 EXPECT_NO_ACTION(client_); |
| 2714 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2720 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2715 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2721 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2716 | 2722 |
| 2717 // NotifyReadyToCommit should trigger the commit. | 2723 // NotifyReadyToCommit should trigger the commit. |
| 2718 client_->Reset(); | 2724 client_->Reset(); |
| 2719 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2725 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2720 scheduler_->NotifyReadyToCommit(); | 2726 scheduler_->NotifyReadyToCommit(); |
| 2721 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2727 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2722 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2728 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2723 | 2729 |
| 2724 // NotifyReadyToActivate should trigger the activation. | 2730 // NotifyReadyToActivate should trigger the activation. |
| 2725 client_->Reset(); | 2731 client_->Reset(); |
| 2726 scheduler_->NotifyReadyToActivate(); | 2732 scheduler_->NotifyReadyToActivate(); |
| 2727 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2733 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2728 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2734 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2729 | 2735 |
| 2730 // BeginImplFrame should prepare the draw. | 2736 // BeginImplFrame should prepare the draw. |
| 2731 client_->Reset(); | 2737 client_->Reset(); |
| 2732 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 2738 task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 2733 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2739 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2734 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2740 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2735 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2741 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2736 | 2742 |
| 2737 client_->Reset(); | 2743 client_->Reset(); |
| 2738 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty()); | 2744 EXPECT_FALSE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
| 2739 scheduler_->DidLoseOutputSurface(); | 2745 scheduler_->DidLoseOutputSurface(); |
| 2740 EXPECT_NO_ACTION(client_); | 2746 EXPECT_NO_ACTION(client_); |
| 2741 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty()); | 2747 EXPECT_TRUE(scheduler_->IsBeginRetroFrameArgsEmpty()); |
| 2742 | 2748 |
| 2743 // BeginImplFrame deadline should abort drawing. | 2749 // BeginImplFrame deadline should abort drawing. |
| 2744 client_->Reset(); | 2750 client_->Reset(); |
| 2745 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2751 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2746 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | 2752 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); |
| 2747 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2753 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2748 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2754 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2749 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2755 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2750 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 2756 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 2751 | 2757 |
| 2752 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 2758 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. |
| 2753 client_->Reset(); | 2759 client_->Reset(); |
| 2754 task_runner().RunPendingTasks(); | 2760 task_runner().RunPendingTasks(); |
| 2755 EXPECT_NO_ACTION(client_); | 2761 EXPECT_NO_ACTION(client_); |
| 2756 } | 2762 } |
| 2757 | 2763 |
| 2758 TEST_F(SchedulerTest, DidLoseOutputSurfaceWithDelayBasedBeginFrameSource) { | 2764 TEST_F(SchedulerTest, DidLoseOutputSurfaceWithDelayBasedBeginFrameSource) { |
| 2759 SetUpScheduler(true); | 2765 SetUpScheduler(true); |
| 2760 | 2766 |
| 2761 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. | 2767 // SetNeedsBeginMainFrame should begin the frame on the next BeginImplFrame. |
| 2762 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 2768 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 2763 scheduler_->SetNeedsBeginMainFrame(); | 2769 scheduler_->SetNeedsBeginMainFrame(); |
| 2764 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2770 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2765 | 2771 |
| 2766 client_->Reset(); | 2772 client_->Reset(); |
| 2767 AdvanceFrame(); | 2773 AdvanceFrame(); |
| 2768 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2774 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2769 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2775 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2770 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2776 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2771 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2777 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2772 | 2778 |
| 2773 // NotifyReadyToCommit should trigger the commit. | 2779 // NotifyReadyToCommit should trigger the commit. |
| 2774 client_->Reset(); | 2780 client_->Reset(); |
| 2775 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2781 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2776 scheduler_->NotifyReadyToCommit(); | 2782 scheduler_->NotifyReadyToCommit(); |
| 2777 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2783 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2778 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2784 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2779 | 2785 |
| 2780 // NotifyReadyToActivate should trigger the activation. | 2786 // NotifyReadyToActivate should trigger the activation. |
| 2781 client_->Reset(); | 2787 client_->Reset(); |
| 2782 scheduler_->NotifyReadyToActivate(); | 2788 scheduler_->NotifyReadyToActivate(); |
| 2783 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2789 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2784 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2790 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2785 | 2791 |
| 2786 client_->Reset(); | 2792 client_->Reset(); |
| 2787 scheduler_->DidLoseOutputSurface(); | 2793 scheduler_->DidLoseOutputSurface(); |
| 2788 // RemoveObserver(this) is not called until the end of the frame. | 2794 // RemoveObserver(this) is not called until the end of the frame. |
| 2789 EXPECT_NO_ACTION(client_); | 2795 EXPECT_NO_ACTION(client_); |
| 2790 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2796 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2791 | 2797 |
| 2792 client_->Reset(); | 2798 client_->Reset(); |
| 2793 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2799 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2794 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 2); | 2800 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 2); |
| 2795 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 2801 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); |
| 2796 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 2802 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 2797 } | 2803 } |
| 2798 | 2804 |
| 2799 TEST_F(SchedulerTest, DidLoseOutputSurfaceWhenIdle) { | 2805 TEST_F(SchedulerTest, DidLoseOutputSurfaceWhenIdle) { |
| 2800 scheduler_settings_.use_external_begin_frame_source = true; | 2806 scheduler_settings_.use_external_begin_frame_source = true; |
| 2801 SetUpScheduler(true); | 2807 SetUpScheduler(true); |
| 2802 | 2808 |
| 2803 // SetNeedsBeginMainFrame should begin the frame. | 2809 // SetNeedsBeginMainFrame should begin the frame. |
| 2804 scheduler_->SetNeedsBeginMainFrame(); | 2810 scheduler_->SetNeedsBeginMainFrame(); |
| 2805 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2811 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2806 | 2812 |
| 2807 client_->Reset(); | 2813 client_->Reset(); |
| 2808 EXPECT_SCOPED(AdvanceFrame()); | 2814 EXPECT_SCOPED(AdvanceFrame()); |
| 2809 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2815 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2810 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2816 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2811 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2817 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2812 | 2818 |
| 2813 client_->Reset(); | 2819 client_->Reset(); |
| 2814 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2820 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2815 scheduler_->NotifyReadyToCommit(); | 2821 scheduler_->NotifyReadyToCommit(); |
| 2816 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2822 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2817 | 2823 |
| 2818 client_->Reset(); | 2824 client_->Reset(); |
| 2819 scheduler_->NotifyReadyToActivate(); | 2825 scheduler_->NotifyReadyToActivate(); |
| 2820 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2826 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2821 | 2827 |
| 2822 client_->Reset(); | 2828 client_->Reset(); |
| 2823 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 2829 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 2824 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2830 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2825 | 2831 |
| 2826 // Idle time between BeginFrames. | 2832 // Idle time between BeginFrames. |
| 2827 client_->Reset(); | 2833 client_->Reset(); |
| 2828 scheduler_->DidLoseOutputSurface(); | 2834 scheduler_->DidLoseOutputSurface(); |
| 2829 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | 2835 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); |
| 2830 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2836 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2831 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2837 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2832 } | 2838 } |
| 2833 | 2839 |
| 2834 TEST_F(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { | 2840 TEST_F(SchedulerTest, ScheduledActionActivateAfterBecomingInvisible) { |
| 2835 scheduler_settings_.use_external_begin_frame_source = true; | 2841 scheduler_settings_.use_external_begin_frame_source = true; |
| 2836 SetUpScheduler(true); | 2842 SetUpScheduler(true); |
| 2837 | 2843 |
| 2838 // SetNeedsBeginMainFrame should begin the frame. | 2844 // SetNeedsBeginMainFrame should begin the frame. |
| 2839 scheduler_->SetNeedsBeginMainFrame(); | 2845 scheduler_->SetNeedsBeginMainFrame(); |
| 2840 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2846 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2841 | 2847 |
| 2842 client_->Reset(); | 2848 client_->Reset(); |
| 2843 EXPECT_SCOPED(AdvanceFrame()); | 2849 EXPECT_SCOPED(AdvanceFrame()); |
| 2844 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2850 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2845 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2851 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2846 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2852 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2847 | 2853 |
| 2848 client_->Reset(); | 2854 client_->Reset(); |
| 2849 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2855 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2850 scheduler_->NotifyReadyToCommit(); | 2856 scheduler_->NotifyReadyToCommit(); |
| 2851 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2857 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2852 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2858 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2853 | 2859 |
| 2854 client_->Reset(); | 2860 client_->Reset(); |
| 2855 scheduler_->SetVisible(false); | 2861 scheduler_->SetVisible(false); |
| 2856 task_runner().RunPendingTasks(); // Run posted deadline. | 2862 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2857 | 2863 |
| 2858 // Sync tree should be forced to activate. | 2864 // Sync tree should be forced to activate. |
| 2859 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 3); | 2865 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 0, 3); |
| 2860 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 2866 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 2861 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 2867 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 2862 } | 2868 } |
| 2863 | 2869 |
| 2864 TEST_F(SchedulerTest, ScheduledActionActivateAfterBeginFrameSourcePaused) { | 2870 TEST_F(SchedulerTest, ScheduledActionActivateAfterBeginFrameSourcePaused) { |
| 2865 scheduler_settings_.use_external_begin_frame_source = true; | 2871 scheduler_settings_.use_external_begin_frame_source = true; |
| 2866 SetUpScheduler(true); | 2872 SetUpScheduler(true); |
| 2867 | 2873 |
| 2868 // SetNeedsBeginMainFrame should begin the frame. | 2874 // SetNeedsBeginMainFrame should begin the frame. |
| 2869 scheduler_->SetNeedsBeginMainFrame(); | 2875 scheduler_->SetNeedsBeginMainFrame(); |
| 2870 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2876 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2871 | 2877 |
| 2872 client_->Reset(); | 2878 client_->Reset(); |
| 2873 EXPECT_SCOPED(AdvanceFrame()); | 2879 EXPECT_SCOPED(AdvanceFrame()); |
| 2874 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 2880 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 2875 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 2881 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 2876 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2882 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2877 | 2883 |
| 2878 client_->Reset(); | 2884 client_->Reset(); |
| 2879 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 2885 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 2880 scheduler_->NotifyReadyToCommit(); | 2886 scheduler_->NotifyReadyToCommit(); |
| 2881 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 2887 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 2882 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2888 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2883 | 2889 |
| 2884 client_->Reset(); | 2890 client_->Reset(); |
| 2885 fake_external_begin_frame_source_->SetPaused(true); | 2891 fake_external_begin_frame_source_->SetPaused(true); |
| 2886 task_runner().RunPendingTasks(); // Run posted deadline. | 2892 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2887 | 2893 |
| 2888 // Sync tree should be forced to activate. | 2894 // Sync tree should be forced to activate. |
| 2889 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 2895 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 2890 } | 2896 } |
| 2891 | 2897 |
| 2892 // Tests to ensure frame sources can be successfully changed while drawing. | 2898 // Tests to ensure frame sources can be successfully changed while drawing. |
| 2893 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottled) { | 2899 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottled) { |
| 2894 scheduler_settings_.use_external_begin_frame_source = true; | 2900 scheduler_settings_.use_external_begin_frame_source = true; |
| 2895 SetUpScheduler(true); | 2901 SetUpScheduler(true); |
| 2896 | 2902 |
| 2897 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2903 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2898 scheduler_->SetNeedsRedraw(); | 2904 scheduler_->SetNeedsRedraw(); |
| 2899 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2905 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2900 client_->Reset(); | 2906 client_->Reset(); |
| 2901 | 2907 |
| 2902 EXPECT_SCOPED(AdvanceFrame()); | 2908 EXPECT_SCOPED(AdvanceFrame()); |
| 2903 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2909 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2904 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2910 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2905 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2911 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2906 client_->Reset(); | 2912 client_->Reset(); |
| 2907 task_runner().RunPendingTasks(); // Run posted deadline. | 2913 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2908 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2914 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2909 scheduler_->SetNeedsRedraw(); | 2915 scheduler_->SetNeedsRedraw(); |
| 2910 | 2916 |
| 2911 // Switch to an unthrottled frame source. | 2917 // Switch to an unthrottled frame source. |
| 2912 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); | 2918 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); |
| 2913 client_->Reset(); | 2919 client_->Reset(); |
| 2914 | 2920 |
| 2915 // Unthrottled frame source will immediately begin a new frame. | 2921 // Unthrottled frame source will immediately begin a new frame. |
| 2916 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2922 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2917 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2923 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2918 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2924 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2919 client_->Reset(); | 2925 client_->Reset(); |
| 2920 | 2926 |
| 2921 // If we don't swap on the deadline, we wait for the next BeginFrame. | 2927 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 2922 task_runner().RunPendingTasks(); // Run posted deadline. | 2928 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2923 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2929 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2924 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2930 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2925 client_->Reset(); | 2931 client_->Reset(); |
| 2926 } | 2932 } |
| 2927 | 2933 |
| 2928 // Tests to ensure frame sources can be successfully changed while a frame | 2934 // Tests to ensure frame sources can be successfully changed while a frame |
| 2929 // deadline is pending. | 2935 // deadline is pending. |
| 2930 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { | 2936 TEST_F(SchedulerTest, SwitchFrameSourceToUnthrottledBeforeDeadline) { |
| 2931 scheduler_settings_.use_external_begin_frame_source = true; | 2937 scheduler_settings_.use_external_begin_frame_source = true; |
| 2932 SetUpScheduler(true); | 2938 SetUpScheduler(true); |
| 2933 | 2939 |
| 2934 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2940 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2935 scheduler_->SetNeedsRedraw(); | 2941 scheduler_->SetNeedsRedraw(); |
| 2936 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 2942 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 2937 client_->Reset(); | 2943 client_->Reset(); |
| 2938 | 2944 |
| 2939 EXPECT_SCOPED(AdvanceFrame()); | 2945 EXPECT_SCOPED(AdvanceFrame()); |
| 2940 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 2946 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 2941 | 2947 |
| 2942 // Switch to an unthrottled frame source before the frame deadline is hit. | 2948 // Switch to an unthrottled frame source before the frame deadline is hit. |
| 2943 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); | 2949 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); |
| 2944 client_->Reset(); | 2950 client_->Reset(); |
| 2945 | 2951 |
| 2946 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2952 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2947 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 2953 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2948 client_->Reset(); | 2954 client_->Reset(); |
| 2949 | 2955 |
| 2950 task_runner().RunPendingTasks(); // Run posted deadline. | 2956 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2951 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 2957 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); |
| 2952 // Unthrottled frame source will immediately begin a new frame. | 2958 // Unthrottled frame source will immediately begin a new frame. |
| 2953 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); | 2959 EXPECT_ACTION("WillBeginImplFrame", client_, 1, 2); |
| 2954 scheduler_->SetNeedsRedraw(); | 2960 scheduler_->SetNeedsRedraw(); |
| 2955 client_->Reset(); | 2961 client_->Reset(); |
| 2956 | 2962 |
| 2957 task_runner().RunPendingTasks(); // Run posted deadline. | 2963 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2958 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 2964 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 2959 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2965 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2960 client_->Reset(); | 2966 client_->Reset(); |
| 2961 } | 2967 } |
| 2962 | 2968 |
| 2963 // Tests to ensure that the active frame source can successfully be changed from | 2969 // Tests to ensure that the active frame source can successfully be changed from |
| 2964 // unthrottled to throttled. | 2970 // unthrottled to throttled. |
| 2965 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) { | 2971 TEST_F(SchedulerTest, SwitchFrameSourceToThrottled) { |
| 2966 scheduler_settings_.throttle_frame_production = false; | 2972 scheduler_settings_.throttle_frame_production = false; |
| 2967 scheduler_settings_.use_external_begin_frame_source = true; | 2973 scheduler_settings_.use_external_begin_frame_source = true; |
| 2968 SetUpScheduler(true); | 2974 SetUpScheduler(true); |
| 2969 | 2975 |
| 2970 scheduler_->SetNeedsRedraw(); | 2976 scheduler_->SetNeedsRedraw(); |
| 2971 EXPECT_NO_ACTION(client_); | 2977 EXPECT_NO_ACTION(client_); |
| 2972 client_->Reset(); | 2978 client_->Reset(); |
| 2973 | 2979 |
| 2974 task_runner().RunPendingTasks(); // Run posted BeginFrame. | 2980 task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 2975 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 2981 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2976 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 2982 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2977 client_->Reset(); | 2983 client_->Reset(); |
| 2978 | 2984 |
| 2979 task_runner().RunPendingTasks(); // Run posted deadline. | 2985 task_runner().RunPendingTasks(); // Run posted deadline. |
| 2980 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 2986 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 2981 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 2987 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 2982 client_->Reset(); | 2988 client_->Reset(); |
| 2983 | 2989 |
| 2984 // Switch to a throttled frame source. | 2990 // Switch to a throttled frame source. |
| 2985 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); | 2991 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); |
| 2986 client_->Reset(); | 2992 client_->Reset(); |
| 2987 | 2993 |
| 2988 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. | 2994 // SetNeedsRedraw should begin the frame on the next BeginImplFrame. |
| 2989 scheduler_->SetNeedsRedraw(); | 2995 scheduler_->SetNeedsRedraw(); |
| 2990 task_runner().RunPendingTasks(); | 2996 task_runner().RunPendingTasks(); |
| 2991 EXPECT_NO_ACTION(client_); | 2997 EXPECT_NO_ACTION(client_); |
| 2992 client_->Reset(); | 2998 client_->Reset(); |
| 2993 | 2999 |
| 2994 EXPECT_SCOPED(AdvanceFrame()); | 3000 EXPECT_SCOPED(AdvanceFrame()); |
| 2995 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 3001 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 2996 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 3002 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 2997 EXPECT_TRUE(scheduler_->begin_frames_expected()); | 3003 EXPECT_TRUE(scheduler_->begin_frames_expected()); |
| 2998 client_->Reset(); | 3004 client_->Reset(); |
| 2999 task_runner().RunPendingTasks(); // Run posted deadline. | 3005 task_runner().RunPendingTasks(); // Run posted deadline. |
| 3000 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 3006 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 3001 } | 3007 } |
| 3002 | 3008 |
| 3003 TEST_F(SchedulerTest, SwitchFrameSourceToNullInsideDeadline) { | 3009 TEST_F(SchedulerTest, SwitchFrameSourceToNullInsideDeadline) { |
| 3004 scheduler_settings_.use_external_begin_frame_source = true; | 3010 scheduler_settings_.use_external_begin_frame_source = true; |
| 3005 SetUpScheduler(true); | 3011 SetUpScheduler(true); |
| 3006 | 3012 |
| 3007 scheduler_->SetNeedsRedraw(); | 3013 scheduler_->SetNeedsRedraw(); |
| 3008 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 3014 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 3009 client_->Reset(); | 3015 client_->Reset(); |
| 3010 | 3016 |
| 3011 EXPECT_SCOPED(AdvanceFrame()); | 3017 EXPECT_SCOPED(AdvanceFrame()); |
| 3012 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 3018 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 3013 client_->Reset(); | 3019 client_->Reset(); |
| 3014 | 3020 |
| 3015 // Switch to a null frame source. | 3021 // Switch to a null frame source. |
| 3016 scheduler_->SetBeginFrameSource(nullptr); | 3022 scheduler_->SetBeginFrameSource(nullptr); |
| 3017 EXPECT_SINGLE_ACTION("RemoveObserver(this)", client_); | 3023 EXPECT_SINGLE_ACTION("RemoveObserver(this)", client_); |
| 3018 client_->Reset(); | 3024 client_->Reset(); |
| 3019 | 3025 |
| 3020 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 3026 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 3021 task_runner().RunPendingTasks(); // Run posted deadline. | 3027 task_runner().RunPendingTasks(); // Run posted deadline. |
| 3022 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 3028 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 3023 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 3029 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 3024 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3030 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3025 client_->Reset(); | 3031 client_->Reset(); |
| 3026 | 3032 |
| 3027 // AdvanceFrame helper can't be used here because there's no deadline posted. | 3033 // AdvanceFrame helper can't be used here because there's no deadline posted. |
| 3028 scheduler_->SetNeedsRedraw(); | 3034 scheduler_->SetNeedsRedraw(); |
| 3029 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3035 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3030 EXPECT_NO_ACTION(client_); | 3036 EXPECT_NO_ACTION(client_); |
| 3031 client_->Reset(); | 3037 client_->Reset(); |
| 3032 | 3038 |
| 3033 scheduler_->SetNeedsBeginMainFrame(); | 3039 scheduler_->SetNeedsBeginMainFrame(); |
| 3034 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3040 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3035 EXPECT_NO_ACTION(client_); | 3041 EXPECT_NO_ACTION(client_); |
| 3036 client_->Reset(); | 3042 client_->Reset(); |
| 3037 | 3043 |
| 3038 // Switch back to the same source, make sure frames continue to be produced. | 3044 // Switch back to the same source, make sure frames continue to be produced. |
| 3039 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); | 3045 scheduler_->SetBeginFrameSource(fake_external_begin_frame_source_.get()); |
| 3040 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 3046 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 3041 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3047 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3042 client_->Reset(); | 3048 client_->Reset(); |
| 3043 | 3049 |
| 3044 EXPECT_SCOPED(AdvanceFrame()); | 3050 EXPECT_SCOPED(AdvanceFrame()); |
| 3045 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3051 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3046 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 3052 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 3047 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 3053 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 3048 client_->Reset(); | 3054 client_->Reset(); |
| 3049 | 3055 |
| 3050 task_runner().RunPendingTasks(); | 3056 task_runner().RunPendingTasks(); |
| 3051 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 3057 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 3052 } | 3058 } |
| 3053 | 3059 |
| 3054 // This test maskes sure that switching a frame source when not observing | 3060 // This test maskes sure that switching a frame source when not observing |
| 3055 // such as when not visible also works. | 3061 // such as when not visible also works. |
| 3056 TEST_F(SchedulerTest, SwitchFrameSourceWhenNotObserving) { | 3062 TEST_F(SchedulerTest, SwitchFrameSourceWhenNotObserving) { |
| 3057 scheduler_settings_.use_external_begin_frame_source = true; | 3063 scheduler_settings_.use_external_begin_frame_source = true; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3072 scheduler_->NotifyReadyToCommit(); | 3078 scheduler_->NotifyReadyToCommit(); |
| 3073 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 3079 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 3074 | 3080 |
| 3075 client_->Reset(); | 3081 client_->Reset(); |
| 3076 scheduler_->NotifyReadyToActivate(); | 3082 scheduler_->NotifyReadyToActivate(); |
| 3077 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 3083 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 3078 | 3084 |
| 3079 // Scheduler loses output surface, and stops waiting for ready to draw signal. | 3085 // Scheduler loses output surface, and stops waiting for ready to draw signal. |
| 3080 client_->Reset(); | 3086 client_->Reset(); |
| 3081 scheduler_->DidLoseOutputSurface(); | 3087 scheduler_->DidLoseOutputSurface(); |
| 3082 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 3088 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 3083 task_runner().RunPendingTasks(); | 3089 task_runner().RunPendingTasks(); |
| 3084 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); | 3090 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 3); |
| 3085 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 3091 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 3086 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 3092 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 3087 | 3093 |
| 3088 // Changing begin frame source doesn't do anything. | 3094 // Changing begin frame source doesn't do anything. |
| 3089 // The unthrottled source doesn't print Add/RemoveObserver like the fake one. | 3095 // The unthrottled source doesn't print Add/RemoveObserver like the fake one. |
| 3090 client_->Reset(); | 3096 client_->Reset(); |
| 3091 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); | 3097 scheduler_->SetBeginFrameSource(unthrottled_frame_source_.get()); |
| 3092 EXPECT_NO_ACTION(client_); | 3098 EXPECT_NO_ACTION(client_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3125 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); | 3131 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 5); |
| 3126 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); | 3132 EXPECT_ACTION("ScheduledActionCommit", client_, 2, 5); |
| 3127 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); | 3133 EXPECT_ACTION("ScheduledActionActivateSyncTree", client_, 3, 5); |
| 3128 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 4, 5); | 3134 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 4, 5); |
| 3129 client_->Reset(); | 3135 client_->Reset(); |
| 3130 | 3136 |
| 3131 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 3137 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 3132 // and send a SendBeginMainFrameNotExpectedSoon. | 3138 // and send a SendBeginMainFrameNotExpectedSoon. |
| 3133 EXPECT_SCOPED(AdvanceFrame()); | 3139 EXPECT_SCOPED(AdvanceFrame()); |
| 3134 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 3140 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 3135 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 3141 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 3136 client_->Reset(); | 3142 client_->Reset(); |
| 3137 | 3143 |
| 3138 task_runner().RunPendingTasks(); // Run posted deadline. | 3144 task_runner().RunPendingTasks(); // Run posted deadline. |
| 3139 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); | 3145 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); |
| 3140 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 3146 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); |
| 3141 client_->Reset(); | 3147 client_->Reset(); |
| 3142 } | 3148 } |
| 3143 | 3149 |
| 3144 TEST_F(SchedulerTest, SynchronousCompositorAnimation) { | 3150 TEST_F(SchedulerTest, SynchronousCompositorAnimation) { |
| 3145 scheduler_settings_.using_synchronous_renderer_compositor = true; | 3151 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 3146 scheduler_settings_.use_external_begin_frame_source = true; | 3152 scheduler_settings_.use_external_begin_frame_source = true; |
| 3147 SetUpScheduler(true); | 3153 SetUpScheduler(true); |
| 3148 | 3154 |
| 3149 scheduler_->SetNeedsOneBeginImplFrame(); | 3155 scheduler_->SetNeedsOneBeginImplFrame(); |
| 3150 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 3156 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 3151 client_->Reset(); | 3157 client_->Reset(); |
| 3152 | 3158 |
| 3153 // Testing the case where animation ticks a fling scroll. | 3159 // Testing the case where animation ticks a fling scroll. |
| 3154 client_->SetWillBeginImplFrameCausesRedraw(true); | 3160 client_->SetWillBeginImplFrameCausesRedraw(true); |
| 3155 // The animation isn't done so it'll cause another tick in the future. | 3161 // The animation isn't done so it'll cause another tick in the future. |
| 3156 client_->SetWillBeginImplFrameRequestsOneBeginImplFrame(true); | 3162 client_->SetWillBeginImplFrameRequestsOneBeginImplFrame(true); |
| 3157 | 3163 |
| 3158 // Next vsync. | 3164 // Next vsync. |
| 3159 AdvanceFrame(); | 3165 AdvanceFrame(); |
| 3160 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3166 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3161 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 1, 2); | 3167 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 1, 2); |
| 3162 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3168 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3163 client_->Reset(); | 3169 client_->Reset(); |
| 3164 | 3170 |
| 3165 // Android onDraw. This doesn't consume the single begin frame request. | 3171 // Android onDraw. This doesn't consume the single begin frame request. |
| 3166 scheduler_->SetNeedsRedraw(); | 3172 scheduler_->SetNeedsRedraw(); |
| 3167 bool resourceless_software_draw = false; | 3173 bool resourceless_software_draw = false; |
| 3168 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); | 3174 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); |
| 3169 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 3175 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 3170 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3176 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3171 client_->Reset(); | 3177 client_->Reset(); |
| 3172 | 3178 |
| 3173 // The animation inside of WillBeginImplFrame changes stuff on the screen, but | 3179 // The animation inside of WillBeginImplFrame changes stuff on the screen, but |
| 3174 // ends here, so does not cause another frame to happen. | 3180 // ends here, so does not cause another frame to happen. |
| 3175 client_->SetWillBeginImplFrameCausesRedraw(true); | 3181 client_->SetWillBeginImplFrameCausesRedraw(true); |
| 3176 | 3182 |
| 3177 // Next vsync. | 3183 // Next vsync. |
| 3178 AdvanceFrame(); | 3184 AdvanceFrame(); |
| 3179 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3185 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3180 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 1, 2); | 3186 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 1, 2); |
| 3181 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3187 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3182 client_->Reset(); | 3188 client_->Reset(); |
| 3183 | 3189 |
| 3184 // Android onDraw. | 3190 // Android onDraw. |
| 3185 scheduler_->SetNeedsRedraw(); | 3191 scheduler_->SetNeedsRedraw(); |
| 3186 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); | 3192 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); |
| 3187 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 3193 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 3188 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3194 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3189 client_->Reset(); | 3195 client_->Reset(); |
| 3190 | 3196 |
| 3191 // Idle on next vsync, as the animation has completed. | 3197 // Idle on next vsync, as the animation has completed. |
| 3192 AdvanceFrame(); | 3198 AdvanceFrame(); |
| 3193 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 3199 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 3194 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 3200 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 3195 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 3201 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 3196 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3202 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3197 client_->Reset(); | 3203 client_->Reset(); |
| 3198 } | 3204 } |
| 3199 | 3205 |
| 3200 TEST_F(SchedulerTest, SynchronousCompositorOnDrawDuringIdle) { | 3206 TEST_F(SchedulerTest, SynchronousCompositorOnDrawDuringIdle) { |
| 3201 scheduler_settings_.using_synchronous_renderer_compositor = true; | 3207 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 3202 scheduler_settings_.use_external_begin_frame_source = true; | 3208 scheduler_settings_.use_external_begin_frame_source = true; |
| 3203 SetUpScheduler(true); | 3209 SetUpScheduler(true); |
| 3204 | 3210 |
| 3205 scheduler_->SetNeedsRedraw(); | 3211 scheduler_->SetNeedsRedraw(); |
| 3206 bool resourceless_software_draw = false; | 3212 bool resourceless_software_draw = false; |
| 3207 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); | 3213 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); |
| 3208 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); | 3214 EXPECT_ACTION("AddObserver(this)", client_, 0, 2); |
| 3209 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); | 3215 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 1, 2); |
| 3210 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3216 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3211 client_->Reset(); | 3217 client_->Reset(); |
| 3212 | 3218 |
| 3213 // Idle on next vsync. | 3219 // Idle on next vsync. |
| 3214 AdvanceFrame(); | 3220 AdvanceFrame(); |
| 3215 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 3221 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 3216 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 3222 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 3217 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 3223 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 3218 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3224 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3219 client_->Reset(); | 3225 client_->Reset(); |
| 3220 } | 3226 } |
| 3221 | 3227 |
| 3222 TEST_F(SchedulerTest, SetNeedsOneBeginImplFrame) { | 3228 TEST_F(SchedulerTest, SetNeedsOneBeginImplFrame) { |
| 3223 scheduler_settings_.use_external_begin_frame_source = true; | 3229 scheduler_settings_.use_external_begin_frame_source = true; |
| 3224 SetUpScheduler(true); | 3230 SetUpScheduler(true); |
| 3225 | 3231 |
| 3226 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 3232 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| 3227 | 3233 |
| 3228 // Request a frame, should kick the source. | 3234 // Request a frame, should kick the source. |
| 3229 scheduler_->SetNeedsOneBeginImplFrame(); | 3235 scheduler_->SetNeedsOneBeginImplFrame(); |
| 3230 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 3236 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 3231 client_->Reset(); | 3237 client_->Reset(); |
| 3232 | 3238 |
| 3233 // The incoming WillBeginImplFrame will request another one. | 3239 // The incoming WillBeginImplFrame will request another one. |
| 3234 client_->SetWillBeginImplFrameRequestsOneBeginImplFrame(true); | 3240 client_->SetWillBeginImplFrameRequestsOneBeginImplFrame(true); |
| 3235 | 3241 |
| 3236 // Next vsync, the first requested frame happens. | 3242 // Next vsync, the first requested frame happens. |
| 3237 EXPECT_SCOPED(AdvanceFrame()); | 3243 EXPECT_SCOPED(AdvanceFrame()); |
| 3238 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 3244 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 3239 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 3245 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 3240 client_->Reset(); | 3246 client_->Reset(); |
| 3241 | 3247 |
| 3242 // We don't request another frame here. | 3248 // We don't request another frame here. |
| 3243 | 3249 |
| 3244 // Next vsync, the second requested frame happens (the one requested inside | 3250 // Next vsync, the second requested frame happens (the one requested inside |
| 3245 // the previous frame's begin impl frame step). | 3251 // the previous frame's begin impl frame step). |
| 3246 EXPECT_SCOPED(AdvanceFrame()); | 3252 EXPECT_SCOPED(AdvanceFrame()); |
| 3247 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); | 3253 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 1); |
| 3248 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 3254 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 3249 client_->Reset(); | 3255 client_->Reset(); |
| 3250 | 3256 |
| 3251 // End that frame's deadline. | 3257 // End that frame's deadline. |
| 3252 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 3258 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 3253 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3259 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3254 | 3260 |
| 3255 // Scheduler shuts down the source now that no begin frame is requested. | 3261 // Scheduler shuts down the source now that no begin frame is requested. |
| 3256 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); | 3262 EXPECT_ACTION("RemoveObserver(this)", client_, 0, 2); |
| 3257 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 3263 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); |
| 3258 } | 3264 } |
| 3259 | 3265 |
| 3260 TEST_F(SchedulerTest, SynchronousCompositorCommit) { | 3266 TEST_F(SchedulerTest, SynchronousCompositorCommit) { |
| 3261 scheduler_settings_.using_synchronous_renderer_compositor = true; | 3267 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 3262 scheduler_settings_.use_external_begin_frame_source = true; | 3268 scheduler_settings_.use_external_begin_frame_source = true; |
| 3263 SetUpScheduler(true); | 3269 SetUpScheduler(true); |
| 3264 | 3270 |
| 3265 scheduler_->SetNeedsBeginMainFrame(); | 3271 scheduler_->SetNeedsBeginMainFrame(); |
| 3266 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 3272 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 3267 client_->Reset(); | 3273 client_->Reset(); |
| 3268 | 3274 |
| 3269 // Next vsync. | 3275 // Next vsync. |
| 3270 AdvanceFrame(); | 3276 AdvanceFrame(); |
| 3271 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3277 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3272 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 3278 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 3273 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3279 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3274 client_->Reset(); | 3280 client_->Reset(); |
| 3275 | 3281 |
| 3276 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 3282 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 3277 EXPECT_NO_ACTION(client_); | 3283 EXPECT_NO_ACTION(client_); |
| 3278 | 3284 |
| 3279 // Next vsync. | 3285 // Next vsync. |
| 3280 AdvanceFrame(); | 3286 AdvanceFrame(); |
| 3281 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); | 3287 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client_); |
| 3282 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3288 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3283 client_->Reset(); | 3289 client_->Reset(); |
| 3284 | 3290 |
| 3285 scheduler_->NotifyReadyToCommit(); | 3291 scheduler_->NotifyReadyToCommit(); |
| 3286 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 3292 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 3287 client_->Reset(); | 3293 client_->Reset(); |
| 3288 | 3294 |
| 3289 scheduler_->NotifyReadyToActivate(); | 3295 scheduler_->NotifyReadyToActivate(); |
| 3290 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 3296 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 3291 client_->Reset(); | 3297 client_->Reset(); |
| 3292 | 3298 |
| 3293 // Next vsync. | 3299 // Next vsync. |
| 3294 AdvanceFrame(); | 3300 AdvanceFrame(); |
| 3295 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3301 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3296 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 1, 2); | 3302 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 1, 2); |
| 3297 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3303 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3298 client_->Reset(); | 3304 client_->Reset(); |
| 3299 | 3305 |
| 3300 // Android onDraw. | 3306 // Android onDraw. |
| 3301 scheduler_->SetNeedsRedraw(); | 3307 scheduler_->SetNeedsRedraw(); |
| 3302 bool resourceless_software_draw = false; | 3308 bool resourceless_software_draw = false; |
| 3303 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); | 3309 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); |
| 3304 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 3310 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 3305 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3311 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3306 client_->Reset(); | 3312 client_->Reset(); |
| 3307 | 3313 |
| 3308 // Idle on next vsync. | 3314 // Idle on next vsync. |
| 3309 AdvanceFrame(); | 3315 AdvanceFrame(); |
| 3310 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 3316 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 3311 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 3317 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 3312 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 3318 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 3313 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3319 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3314 client_->Reset(); | 3320 client_->Reset(); |
| 3315 } | 3321 } |
| 3316 | 3322 |
| 3317 TEST_F(SchedulerTest, SynchronousCompositorDoubleCommitWithoutDraw) { | 3323 TEST_F(SchedulerTest, SynchronousCompositorDoubleCommitWithoutDraw) { |
| 3318 scheduler_settings_.using_synchronous_renderer_compositor = true; | 3324 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 3319 scheduler_settings_.use_external_begin_frame_source = true; | 3325 scheduler_settings_.use_external_begin_frame_source = true; |
| 3320 SetUpScheduler(true); | 3326 SetUpScheduler(true); |
| 3321 | 3327 |
| 3322 scheduler_->SetNeedsBeginMainFrame(); | 3328 scheduler_->SetNeedsBeginMainFrame(); |
| 3323 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); | 3329 EXPECT_SINGLE_ACTION("AddObserver(this)", client_); |
| 3324 client_->Reset(); | 3330 client_->Reset(); |
| 3325 | 3331 |
| 3326 // Next vsync. | 3332 // Next vsync. |
| 3327 AdvanceFrame(); | 3333 AdvanceFrame(); |
| 3328 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3334 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3329 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 3335 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 3330 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3336 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3331 client_->Reset(); | 3337 client_->Reset(); |
| 3332 | 3338 |
| 3333 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 3339 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 3334 EXPECT_NO_ACTION(client_); | 3340 EXPECT_NO_ACTION(client_); |
| 3335 | 3341 |
| 3336 scheduler_->NotifyReadyToCommit(); | 3342 scheduler_->NotifyReadyToCommit(); |
| 3337 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 3343 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 3338 client_->Reset(); | 3344 client_->Reset(); |
| 3339 | 3345 |
| 3340 scheduler_->NotifyReadyToActivate(); | 3346 scheduler_->NotifyReadyToActivate(); |
| 3341 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 3347 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 3342 client_->Reset(); | 3348 client_->Reset(); |
| 3343 | 3349 |
| 3344 // Ask for another commit. | 3350 // Ask for another commit. |
| 3345 scheduler_->SetNeedsBeginMainFrame(); | 3351 scheduler_->SetNeedsBeginMainFrame(); |
| 3346 | 3352 |
| 3347 AdvanceFrame(); | 3353 AdvanceFrame(); |
| 3348 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 3354 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 3349 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); | 3355 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 3); |
| 3350 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); | 3356 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 2, 3); |
| 3351 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3357 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3352 client_->Reset(); | 3358 client_->Reset(); |
| 3353 | 3359 |
| 3354 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 3360 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 3355 EXPECT_NO_ACTION(client_); | 3361 EXPECT_NO_ACTION(client_); |
| 3356 | 3362 |
| 3357 // Allow new commit even though previous commit hasn't been drawn. | 3363 // Allow new commit even though previous commit hasn't been drawn. |
| 3358 scheduler_->NotifyReadyToCommit(); | 3364 scheduler_->NotifyReadyToCommit(); |
| 3359 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 3365 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 3360 client_->Reset(); | 3366 client_->Reset(); |
| 3361 } | 3367 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3388 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3394 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3389 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 1, 2); | 3395 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 1, 2); |
| 3390 client_->Reset(); | 3396 client_->Reset(); |
| 3391 | 3397 |
| 3392 // Android onDraw. | 3398 // Android onDraw. |
| 3393 scheduler_->SetNeedsRedraw(); | 3399 scheduler_->SetNeedsRedraw(); |
| 3394 bool resourceless_software_draw = false; | 3400 bool resourceless_software_draw = false; |
| 3395 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); | 3401 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); |
| 3396 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 3402 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); |
| 3397 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); | 3403 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); |
| 3398 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3404 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3399 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 3405 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 3400 client_->Reset(); | 3406 client_->Reset(); |
| 3401 | 3407 |
| 3402 // Android onDraw. | 3408 // Android onDraw. |
| 3403 scheduler_->SetNeedsRedraw(); | 3409 scheduler_->SetNeedsRedraw(); |
| 3404 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); | 3410 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); |
| 3405 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); | 3411 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 2); |
| 3406 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); | 3412 EXPECT_ACTION("ScheduledActionPrepareTiles", client_, 1, 2); |
| 3407 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3413 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3408 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 3414 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 3409 client_->Reset(); | 3415 client_->Reset(); |
| 3410 | 3416 |
| 3411 // Next vsync. | 3417 // Next vsync. |
| 3412 EXPECT_SCOPED(AdvanceFrame()); | 3418 EXPECT_SCOPED(AdvanceFrame()); |
| 3413 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 3419 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 3414 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); | 3420 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 3); |
| 3415 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); | 3421 EXPECT_ACTION("RemoveObserver(this)", client_, 1, 3); |
| 3416 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); | 3422 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 2, 3); |
| 3417 EXPECT_FALSE(scheduler_->begin_frames_expected()); | 3423 EXPECT_FALSE(scheduler_->begin_frames_expected()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3432 EXPECT_SCOPED(AdvanceFrame()); | 3438 EXPECT_SCOPED(AdvanceFrame()); |
| 3433 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3439 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3434 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 1, 2); | 3440 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 1, 2); |
| 3435 client_->Reset(); | 3441 client_->Reset(); |
| 3436 | 3442 |
| 3437 // Android onDraw. | 3443 // Android onDraw. |
| 3438 scheduler_->SetNeedsRedraw(); | 3444 scheduler_->SetNeedsRedraw(); |
| 3439 bool resourceless_software_draw = false; | 3445 bool resourceless_software_draw = false; |
| 3440 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); | 3446 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); |
| 3441 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 3447 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 3442 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3448 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3443 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 3449 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 3444 client_->Reset(); | 3450 client_->Reset(); |
| 3445 | 3451 |
| 3446 // Simulate SetNeedsBeginMainFrame due to input event. | 3452 // Simulate SetNeedsBeginMainFrame due to input event. |
| 3447 scheduler_->SetNeedsBeginMainFrame(); | 3453 scheduler_->SetNeedsBeginMainFrame(); |
| 3448 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 3454 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 3449 client_->Reset(); | 3455 client_->Reset(); |
| 3450 | 3456 |
| 3451 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 3457 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 3452 scheduler_->NotifyReadyToCommit(); | 3458 scheduler_->NotifyReadyToCommit(); |
| 3453 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); | 3459 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client_); |
| 3454 client_->Reset(); | 3460 client_->Reset(); |
| 3455 | 3461 |
| 3456 scheduler_->NotifyReadyToActivate(); | 3462 scheduler_->NotifyReadyToActivate(); |
| 3457 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); | 3463 EXPECT_SINGLE_ACTION("ScheduledActionActivateSyncTree", client_); |
| 3458 client_->Reset(); | 3464 client_->Reset(); |
| 3459 | 3465 |
| 3460 // Next vsync. | 3466 // Next vsync. |
| 3461 EXPECT_SCOPED(AdvanceFrame()); | 3467 EXPECT_SCOPED(AdvanceFrame()); |
| 3462 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3468 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3463 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 1, 2); | 3469 EXPECT_ACTION("ScheduledActionInvalidateOutputSurface", client_, 1, 2); |
| 3464 client_->Reset(); | 3470 client_->Reset(); |
| 3465 | 3471 |
| 3466 // Android onDraw. | 3472 // Android onDraw. |
| 3467 scheduler_->SetNeedsRedraw(); | 3473 scheduler_->SetNeedsRedraw(); |
| 3468 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); | 3474 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); |
| 3469 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); | 3475 EXPECT_SINGLE_ACTION("ScheduledActionDrawAndSwapIfPossible", client_); |
| 3470 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3476 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3471 EXPECT_FALSE(scheduler_->PrepareTilesPending()); | 3477 EXPECT_FALSE(scheduler_->PrepareTilesPending()); |
| 3472 client_->Reset(); | 3478 client_->Reset(); |
| 3473 | 3479 |
| 3474 // Simulate SetNeedsBeginMainFrame due to input event. | 3480 // Simulate SetNeedsBeginMainFrame due to input event. |
| 3475 scheduler_->SetNeedsBeginMainFrame(); | 3481 scheduler_->SetNeedsBeginMainFrame(); |
| 3476 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); | 3482 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client_); |
| 3477 client_->Reset(); | 3483 client_->Reset(); |
| 3478 } | 3484 } |
| 3479 | 3485 |
| 3480 TEST_F(SchedulerTest, SynchronousCompositorResourcelessOnDrawWhenInvisible) { | 3486 TEST_F(SchedulerTest, SynchronousCompositorResourcelessOnDrawWhenInvisible) { |
| 3481 scheduler_settings_.using_synchronous_renderer_compositor = true; | 3487 scheduler_settings_.using_synchronous_renderer_compositor = true; |
| 3482 scheduler_settings_.use_external_begin_frame_source = true; | 3488 scheduler_settings_.use_external_begin_frame_source = true; |
| 3483 SetUpScheduler(true); | 3489 SetUpScheduler(true); |
| 3484 | 3490 |
| 3485 scheduler_->SetVisible(false); | 3491 scheduler_->SetVisible(false); |
| 3486 | 3492 |
| 3487 scheduler_->SetNeedsRedraw(); | 3493 scheduler_->SetNeedsRedraw(); |
| 3488 bool resourceless_software_draw = true; | 3494 bool resourceless_software_draw = true; |
| 3489 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); | 3495 scheduler_->OnDrawForOutputSurface(resourceless_software_draw); |
| 3490 // SynchronousCompositor has to draw regardless of visibility. | 3496 // SynchronousCompositor has to draw regardless of visibility. |
| 3491 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); | 3497 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client_, 0, 1); |
| 3492 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3498 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3493 client_->Reset(); | 3499 client_->Reset(); |
| 3494 } | 3500 } |
| 3495 | 3501 |
| 3496 TEST_F(SchedulerTest, AuthoritativeVSyncInterval) { | 3502 TEST_F(SchedulerTest, AuthoritativeVSyncInterval) { |
| 3497 SetUpScheduler(true); | 3503 SetUpScheduler(true); |
| 3498 base::TimeDelta initial_interval = scheduler_->BeginImplFrameInterval(); | 3504 base::TimeDelta initial_interval = scheduler_->BeginImplFrameInterval(); |
| 3499 base::TimeDelta authoritative_interval = | 3505 base::TimeDelta authoritative_interval = |
| 3500 base::TimeDelta::FromMilliseconds(33); | 3506 base::TimeDelta::FromMilliseconds(33); |
| 3501 | 3507 |
| 3502 scheduler_->SetNeedsBeginMainFrame(); | 3508 scheduler_->SetNeedsBeginMainFrame(); |
| 3503 EXPECT_SCOPED(AdvanceFrame()); | 3509 EXPECT_SCOPED(AdvanceFrame()); |
| 3504 | 3510 |
| 3505 EXPECT_EQ(initial_interval, scheduler_->BeginImplFrameInterval()); | 3511 EXPECT_EQ(initial_interval, scheduler_->BeginImplFrameInterval()); |
| 3506 | 3512 |
| 3507 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); | 3513 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks()); |
| 3508 scheduler_->NotifyReadyToCommit(); | 3514 scheduler_->NotifyReadyToCommit(); |
| 3509 scheduler_->NotifyReadyToActivate(); | 3515 scheduler_->NotifyReadyToActivate(); |
| 3510 task_runner().RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 3516 task_runner().RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 3511 | 3517 |
| 3512 // Test changing the interval on the frame source external to the scheduler. | 3518 // Test changing the interval on the frame source external to the scheduler. |
| 3513 synthetic_frame_source_->OnUpdateVSyncParameters(now_src_->NowTicks(), | 3519 synthetic_frame_source_->OnUpdateVSyncParameters(now_src_->NowTicks(), |
| 3514 authoritative_interval); | 3520 authoritative_interval); |
| 3515 | 3521 |
| 3516 EXPECT_SCOPED(AdvanceFrame()); | 3522 EXPECT_SCOPED(AdvanceFrame()); |
| 3517 | 3523 |
| 3518 // At the next BeginFrame, authoritative interval is used instead of previous | 3524 // At the next BeginFrame, authoritative interval is used instead of previous |
| 3519 // interval. | 3525 // interval. |
| 3520 EXPECT_NE(initial_interval, scheduler_->BeginImplFrameInterval()); | 3526 EXPECT_NE(initial_interval, scheduler_->BeginImplFrameInterval()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3563 // SetNeedsBeginMainFrame should begin the frame. | 3569 // SetNeedsBeginMainFrame should begin the frame. |
| 3564 scheduler_->SetNeedsBeginMainFrame(); | 3570 scheduler_->SetNeedsBeginMainFrame(); |
| 3565 client_->Reset(); | 3571 client_->Reset(); |
| 3566 EXPECT_SCOPED(AdvanceFrame()); | 3572 EXPECT_SCOPED(AdvanceFrame()); |
| 3567 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3573 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3568 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 3574 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 3569 | 3575 |
| 3570 // Lose the output surface and trigger the deadline. | 3576 // Lose the output surface and trigger the deadline. |
| 3571 client_->Reset(); | 3577 client_->Reset(); |
| 3572 scheduler_->DidLoseOutputSurface(); | 3578 scheduler_->DidLoseOutputSurface(); |
| 3573 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 3579 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 3574 EXPECT_NO_ACTION(client_); | 3580 EXPECT_NO_ACTION(client_); |
| 3575 | 3581 |
| 3576 // The scheduler should not trigger the output surface creation till the | 3582 // The scheduler should not trigger the output surface creation till the |
| 3577 // commit is aborted. | 3583 // commit is aborted. |
| 3578 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 3584 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 3579 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3585 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3580 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); | 3586 EXPECT_SINGLE_ACTION("SendBeginMainFrameNotExpectedSoon", client_); |
| 3581 | 3587 |
| 3582 // Abort the commit. | 3588 // Abort the commit. |
| 3583 client_->Reset(); | 3589 client_->Reset(); |
| 3584 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks::Now()); | 3590 scheduler_->NotifyBeginMainFrameStarted(base::TimeTicks::Now()); |
| 3585 scheduler_->BeginMainFrameAborted( | 3591 scheduler_->BeginMainFrameAborted( |
| 3586 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); | 3592 CommitEarlyOutReason::ABORTED_OUTPUT_SURFACE_LOST); |
| 3587 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); | 3593 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_); |
| 3588 } | 3594 } |
| 3589 | 3595 |
| 3590 TEST_F(SchedulerTest, OutputSurfaceCreationWhileCommitPending) { | 3596 TEST_F(SchedulerTest, OutputSurfaceCreationWhileCommitPending) { |
| 3591 scheduler_settings_.abort_commit_before_output_surface_creation = false; | 3597 scheduler_settings_.abort_commit_before_output_surface_creation = false; |
| 3592 SetUpScheduler(true); | 3598 SetUpScheduler(true); |
| 3593 | 3599 |
| 3594 // SetNeedsBeginMainFrame should begin the frame. | 3600 // SetNeedsBeginMainFrame should begin the frame. |
| 3595 scheduler_->SetNeedsBeginMainFrame(); | 3601 scheduler_->SetNeedsBeginMainFrame(); |
| 3596 client_->Reset(); | 3602 client_->Reset(); |
| 3597 EXPECT_SCOPED(AdvanceFrame()); | 3603 EXPECT_SCOPED(AdvanceFrame()); |
| 3598 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); | 3604 EXPECT_ACTION("WillBeginImplFrame", client_, 0, 2); |
| 3599 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); | 3605 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client_, 1, 2); |
| 3600 | 3606 |
| 3601 // Lose the output surface and trigger the deadline. | 3607 // Lose the output surface and trigger the deadline. |
| 3602 client_->Reset(); | 3608 client_->Reset(); |
| 3603 scheduler_->DidLoseOutputSurface(); | 3609 scheduler_->DidLoseOutputSurface(); |
| 3604 EXPECT_TRUE(scheduler_->BeginImplFrameDeadlinePending()); | 3610 EXPECT_TRUE(client_->IsInsideBeginImplFrame()); |
| 3605 EXPECT_NO_ACTION(client_); | 3611 EXPECT_NO_ACTION(client_); |
| 3606 | 3612 |
| 3607 // The scheduler should trigger the output surface creation immediately after | 3613 // The scheduler should trigger the output surface creation immediately after |
| 3608 // the begin_impl_frame_state_ is cleared. | 3614 // the begin_impl_frame_state_ is cleared. |
| 3609 task_runner_->RunTasksWhile(client_->ImplFrameDeadlinePending(true)); | 3615 task_runner_->RunTasksWhile(client_->InsideBeginImplFrame(true)); |
| 3610 EXPECT_FALSE(scheduler_->BeginImplFrameDeadlinePending()); | 3616 EXPECT_FALSE(client_->IsInsideBeginImplFrame()); |
| 3611 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 2); | 3617 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client_, 0, 2); |
| 3612 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); | 3618 EXPECT_ACTION("SendBeginMainFrameNotExpectedSoon", client_, 1, 2); |
| 3613 } | 3619 } |
| 3614 | 3620 |
| 3615 // The three letters appeneded to each version of this test mean the following:s | 3621 // The three letters appeneded to each version of this test mean the following:s |
| 3616 // tree_priority: B = both trees same priority; A = active tree priority; | 3622 // tree_priority: B = both trees same priority; A = active tree priority; |
| 3617 // scroll_handler_state: H = affects scroll handler; N = does not affect scroll | 3623 // scroll_handler_state: H = affects scroll handler; N = does not affect scroll |
| 3618 // handler; | 3624 // handler; |
| 3619 // durations: F = fast durations; S = slow durations | 3625 // durations: F = fast durations; S = slow durations |
| 3620 bool SchedulerTest::BeginMainFrameOnCriticalPath( | 3626 bool SchedulerTest::BeginMainFrameOnCriticalPath( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3681 } | 3687 } |
| 3682 | 3688 |
| 3683 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { | 3689 TEST_F(SchedulerTest, BeginMainFrameOnCriticalPath_AHS) { |
| 3684 EXPECT_FALSE(BeginMainFrameOnCriticalPath( | 3690 EXPECT_FALSE(BeginMainFrameOnCriticalPath( |
| 3685 SMOOTHNESS_TAKES_PRIORITY, | 3691 SMOOTHNESS_TAKES_PRIORITY, |
| 3686 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); | 3692 ScrollHandlerState::SCROLL_AFFECTS_SCROLL_HANDLER, kSlowDuration)); |
| 3687 } | 3693 } |
| 3688 | 3694 |
| 3689 } // namespace | 3695 } // namespace |
| 3690 } // namespace cc | 3696 } // namespace cc |
| OLD | NEW |