| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 #include "cc/scheduler/scheduler.h" | 4 #include "cc/scheduler/scheduler.h" |
| 5 | 5 |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) | 32 #define EXPECT_NO_ACTION(client) EXPECT_ACTION("", client, -1, 0) |
| 33 | 33 |
| 34 #define EXPECT_SINGLE_ACTION(action, client) \ | 34 #define EXPECT_SINGLE_ACTION(action, client) \ |
| 35 EXPECT_ACTION(action, client, 0, 1) | 35 EXPECT_ACTION(action, client, 0, 1) |
| 36 | 36 |
| 37 namespace cc { | 37 namespace cc { |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 class FakeSchedulerClient; | 40 class FakeSchedulerClient; |
| 41 | 41 |
| 42 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 42 class FakeBeginFrameSource : public BaseBeginFrameSource { |
| 43 FakeSchedulerClient* client); | 43 public: |
| 44 FakeSchedulerClient* fake_client_; |
| 45 |
| 46 explicit FakeBeginFrameSource(FakeSchedulerClient* fake_client) |
| 47 : BaseBeginFrameSource(0), fake_client_(fake_client) {} |
| 48 |
| 49 virtual void OnGenerateChange(bool generate_frames) OVERRIDE; |
| 50 |
| 51 virtual inline std::string TypeString() const OVERRIDE { |
| 52 return "FakeBeginFrameSource"; |
| 53 } |
| 54 |
| 55 void TestBeginFrame(BeginFrameArgs args) { frame_sink_->BeginFrame(args); } |
| 56 }; |
| 44 | 57 |
| 45 class TestScheduler : public Scheduler { | 58 class TestScheduler : public Scheduler { |
| 46 public: | 59 public: |
| 47 static scoped_ptr<TestScheduler> Create( | 60 static scoped_ptr<TestScheduler> Create( |
| 48 SchedulerClient* client, | 61 SchedulerClient* client, |
| 49 const SchedulerSettings& scheduler_settings, | 62 const SchedulerSettings& scheduler_settings, |
| 50 int layer_tree_host_id, | 63 int layer_tree_host_id, |
| 64 BeginFrameSource* external_frame_source, |
| 51 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner) { | 65 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner) { |
| 52 return make_scoped_ptr(new TestScheduler( | 66 return make_scoped_ptr(new TestScheduler(client, |
| 53 client, scheduler_settings, layer_tree_host_id, impl_task_runner)); | 67 scheduler_settings, |
| 68 layer_tree_host_id, |
| 69 external_frame_source, |
| 70 impl_task_runner)); |
| 54 } | 71 } |
| 55 | 72 |
| 56 virtual ~TestScheduler() {} | 73 virtual ~TestScheduler() {} |
| 57 | 74 |
| 58 bool IsBeginRetroFrameArgsEmpty() const { | 75 bool IsBeginRetroFrameArgsEmpty() const { |
| 59 return begin_retro_frame_args_.empty(); | 76 return begin_retro_frame_args_.empty(); |
| 60 } | 77 } |
| 61 | 78 |
| 62 bool IsSyntheticBeginFrameSourceActive() const { | 79 bool IsFrameSourceGeneratingFrames() const { |
| 63 return synthetic_begin_frame_source_->IsActive(); | 80 return frame_source_->IsGeneratingFrames(); |
| 64 } | 81 } |
| 65 | 82 |
| 66 private: | 83 private: |
| 67 TestScheduler( | 84 TestScheduler( |
| 68 SchedulerClient* client, | 85 SchedulerClient* client, |
| 69 const SchedulerSettings& scheduler_settings, | 86 const SchedulerSettings& scheduler_settings, |
| 70 int layer_tree_host_id, | 87 int layer_tree_host_id, |
| 71 const scoped_refptr<base::SingleThreadTaskRunner> & impl_task_runner) | 88 BeginFrameSource* external_frame_source, |
| 72 : Scheduler(client, | 89 const scoped_refptr<base::SingleThreadTaskRunner>& impl_task_runner) |
| 73 scheduler_settings, | 90 : Scheduler(client, |
| 74 layer_tree_host_id, | 91 scheduler_settings, |
| 75 impl_task_runner) { | 92 layer_tree_host_id, |
| 76 } | 93 external_frame_source, |
| 94 impl_task_runner) {} |
| 77 }; | 95 }; |
| 78 | 96 |
| 79 class FakeSchedulerClient : public SchedulerClient { | 97 class FakeSchedulerClient : public SchedulerClient { |
| 80 public: | 98 public: |
| 81 FakeSchedulerClient() | 99 FakeSchedulerClient() |
| 82 : needs_begin_frame_(false), | 100 : generate_frames_(false), |
| 83 automatic_swap_ack_(true), | 101 automatic_swap_ack_(true), |
| 84 swap_contains_incomplete_tile_(false), | 102 swap_contains_incomplete_tile_(false), |
| 85 redraw_will_happen_if_update_visible_tiles_happens_(false) { | 103 redraw_will_happen_if_update_visible_tiles_happens_(false), |
| 104 frame_source_(this) { |
| 86 Reset(); | 105 Reset(); |
| 87 } | 106 } |
| 88 | 107 |
| 89 void Reset() { | 108 void Reset() { |
| 90 actions_.clear(); | 109 actions_.clear(); |
| 91 states_.clear(); | 110 states_.clear(); |
| 92 draw_will_happen_ = true; | 111 draw_will_happen_ = true; |
| 93 swap_will_happen_if_draw_happens_ = true; | 112 swap_will_happen_if_draw_happens_ = true; |
| 94 num_draws_ = 0; | 113 num_draws_ = 0; |
| 95 log_anticipated_draw_time_change_ = false; | 114 log_anticipated_draw_time_change_ = false; |
| 96 } | 115 } |
| 97 | 116 |
| 98 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { | 117 TestScheduler* CreateScheduler(const SchedulerSettings& settings) { |
| 99 task_runner_ = new OrderedSimpleTaskRunner; | 118 task_runner_ = new OrderedSimpleTaskRunner; |
| 100 scheduler_ = TestScheduler::Create(this, settings, 0, task_runner_); | 119 |
| 120 scheduler_ = |
| 121 TestScheduler::Create(this, |
| 122 settings, |
| 123 0, |
| 124 static_cast<BeginFrameSource*>(&frame_source_), |
| 125 task_runner_); |
| 101 return scheduler_.get(); | 126 return scheduler_.get(); |
| 102 } | 127 } |
| 103 | 128 |
| 104 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it | 129 // Most tests don't care about DidAnticipatedDrawTimeChange, so only record it |
| 105 // for tests that do. | 130 // for tests that do. |
| 106 void set_log_anticipated_draw_time_change(bool log) { | 131 void set_log_anticipated_draw_time_change(bool log) { |
| 107 log_anticipated_draw_time_change_ = log; | 132 log_anticipated_draw_time_change_ = log; |
| 108 } | 133 } |
| 109 bool needs_begin_frame() { return needs_begin_frame_; } | 134 bool generate_frames() { return generate_frames_; } |
| 110 int num_draws() const { return num_draws_; } | 135 int num_draws() const { return num_draws_; } |
| 111 int num_actions_() const { return static_cast<int>(actions_.size()); } | 136 int num_actions_() const { return static_cast<int>(actions_.size()); } |
| 112 const char* Action(int i) const { return actions_[i]; } | 137 const char* Action(int i) const { return actions_[i]; } |
| 113 base::Value& StateForAction(int i) const { return *states_[i]; } | 138 base::Value& StateForAction(int i) const { return *states_[i]; } |
| 114 base::TimeTicks posted_begin_impl_frame_deadline() const { | 139 base::TimeTicks posted_begin_impl_frame_deadline() const { |
| 115 return posted_begin_impl_frame_deadline_; | 140 return posted_begin_impl_frame_deadline_; |
| 116 } | 141 } |
| 117 | 142 |
| 118 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } | 143 OrderedSimpleTaskRunner& task_runner() { return *task_runner_; } |
| 119 | 144 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 138 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 163 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
| 139 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 164 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
| 140 } | 165 } |
| 141 void SetAutomaticSwapAck(bool automatic_swap_ack) { | 166 void SetAutomaticSwapAck(bool automatic_swap_ack) { |
| 142 automatic_swap_ack_ = automatic_swap_ack; | 167 automatic_swap_ack_ = automatic_swap_ack; |
| 143 } | 168 } |
| 144 void SetRedrawWillHappenIfUpdateVisibleTilesHappens(bool redraw) { | 169 void SetRedrawWillHappenIfUpdateVisibleTilesHappens(bool redraw) { |
| 145 redraw_will_happen_if_update_visible_tiles_happens_ = redraw; | 170 redraw_will_happen_if_update_visible_tiles_happens_ = redraw; |
| 146 } | 171 } |
| 147 // SchedulerClient implementation. | 172 // SchedulerClient implementation. |
| 148 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { | |
| 149 actions_.push_back("SetNeedsBeginFrame"); | |
| 150 states_.push_back(scheduler_->AsValue().release()); | |
| 151 needs_begin_frame_ = enable; | |
| 152 } | |
| 153 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { | 173 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { |
| 154 actions_.push_back("WillBeginImplFrame"); | 174 actions_.push_back("WillBeginImplFrame"); |
| 155 states_.push_back(scheduler_->AsValue().release()); | 175 states_.push_back(scheduler_->AsValue().release()); |
| 156 } | 176 } |
| 157 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { | 177 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { |
| 158 actions_.push_back("ScheduledActionSendBeginMainFrame"); | 178 actions_.push_back("ScheduledActionSendBeginMainFrame"); |
| 159 states_.push_back(scheduler_->AsValue().release()); | 179 states_.push_back(scheduler_->AsValue().release()); |
| 160 } | 180 } |
| 161 virtual void ScheduledActionAnimate() OVERRIDE { | 181 virtual void ScheduledActionAnimate() OVERRIDE { |
| 162 actions_.push_back("ScheduledActionAnimate"); | 182 actions_.push_back("ScheduledActionAnimate"); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 240 } |
| 221 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE { | 241 virtual base::TimeDelta BeginMainFrameToCommitDurationEstimate() OVERRIDE { |
| 222 return base::TimeDelta(); | 242 return base::TimeDelta(); |
| 223 } | 243 } |
| 224 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { | 244 virtual base::TimeDelta CommitToActivateDurationEstimate() OVERRIDE { |
| 225 return base::TimeDelta(); | 245 return base::TimeDelta(); |
| 226 } | 246 } |
| 227 | 247 |
| 228 virtual void DidBeginImplFrameDeadline() OVERRIDE {} | 248 virtual void DidBeginImplFrameDeadline() OVERRIDE {} |
| 229 | 249 |
| 250 FakeBeginFrameSource& frame_source() { return frame_source_; } |
| 251 |
| 230 protected: | 252 protected: |
| 231 bool needs_begin_frame_; | 253 bool generate_frames_; |
| 232 bool draw_will_happen_; | 254 bool draw_will_happen_; |
| 233 bool swap_will_happen_if_draw_happens_; | 255 bool swap_will_happen_if_draw_happens_; |
| 234 bool automatic_swap_ack_; | 256 bool automatic_swap_ack_; |
| 235 int num_draws_; | 257 int num_draws_; |
| 236 bool log_anticipated_draw_time_change_; | 258 bool log_anticipated_draw_time_change_; |
| 237 bool swap_contains_incomplete_tile_; | 259 bool swap_contains_incomplete_tile_; |
| 238 bool redraw_will_happen_if_update_visible_tiles_happens_; | 260 bool redraw_will_happen_if_update_visible_tiles_happens_; |
| 239 base::TimeTicks posted_begin_impl_frame_deadline_; | 261 base::TimeTicks posted_begin_impl_frame_deadline_; |
| 240 std::vector<const char*> actions_; | 262 std::vector<const char*> actions_; |
| 241 ScopedVector<base::Value> states_; | 263 ScopedVector<base::Value> states_; |
| 242 scoped_ptr<TestScheduler> scheduler_; | 264 scoped_ptr<TestScheduler> scheduler_; |
| 243 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; | 265 scoped_refptr<OrderedSimpleTaskRunner> task_runner_; |
| 266 |
| 267 friend class FakeBeginFrameSource; |
| 268 FakeBeginFrameSource frame_source_; |
| 244 }; | 269 }; |
| 245 | 270 |
| 271 void FakeBeginFrameSource::OnGenerateChange(bool generate_frames) { |
| 272 fake_client_->actions_.push_back("SetGenerateFrames"); |
| 273 fake_client_->states_.push_back( |
| 274 fake_client_->scheduler_->AsValue().release()); |
| 275 fake_client_->generate_frames_ = generate_frames; |
| 276 } |
| 277 |
| 246 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 278 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
| 247 FakeSchedulerClient* client) { | 279 FakeSchedulerClient* client) { |
| 248 bool client_initiates_begin_frame = | 280 bool client_initiates_begin_frame = |
| 249 scheduler->settings().begin_frame_scheduling_enabled && | 281 scheduler->settings().begin_frame_scheduling_enabled && |
| 250 scheduler->settings().throttle_frame_production; | 282 scheduler->settings().throttle_frame_production; |
| 251 | 283 |
| 252 scheduler->DidCreateAndInitializeOutputSurface(); | 284 scheduler->DidCreateAndInitializeOutputSurface(); |
| 253 scheduler->SetNeedsCommit(); | 285 scheduler->SetNeedsCommit(); |
| 254 scheduler->NotifyBeginMainFrameStarted(); | 286 scheduler->NotifyBeginMainFrameStarted(); |
| 255 scheduler->NotifyReadyToCommit(); | 287 scheduler->NotifyReadyToCommit(); |
| 256 if (scheduler->settings().impl_side_painting) | 288 if (scheduler->settings().impl_side_painting) |
| 257 scheduler->NotifyReadyToActivate(); | 289 scheduler->NotifyReadyToActivate(); |
| 258 // Go through the motions to draw the commit. | 290 // Go through the motions to draw the commit. |
| 259 if (client_initiates_begin_frame) | 291 if (client_initiates_begin_frame) |
| 260 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 292 client->frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 261 else | 293 else |
| 262 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. | 294 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 263 | 295 |
| 264 // Run the posted deadline task. | 296 // Run the posted deadline task. |
| 265 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 297 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 266 client->task_runner().RunPendingTasks(); | 298 client->task_runner().RunPendingTasks(); |
| 267 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 299 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 268 | 300 |
| 301 // EXPECT_TRUE(client->generate_frames()); |
| 302 |
| 269 // We need another BeginImplFrame so Scheduler calls | 303 // We need another BeginImplFrame so Scheduler calls |
| 270 // SetNeedsBeginFrame(false). | 304 // SetGenerateFrames(false). |
| 271 if (client_initiates_begin_frame) | 305 if (client_initiates_begin_frame) |
| 272 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 306 client->frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 273 else | 307 else |
| 274 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. | 308 client->task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 275 | 309 |
| 310 // EXPECT_FALSE(client->generate_frames()); |
| 311 |
| 276 // Run the posted deadline task. | 312 // Run the posted deadline task. |
| 277 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 313 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 278 client->task_runner().RunPendingTasks(); | 314 client->task_runner().RunPendingTasks(); |
| 279 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 315 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 280 } | 316 } |
| 281 | 317 |
| 282 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 318 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
| 283 FakeSchedulerClient client; | 319 FakeSchedulerClient client; |
| 284 SchedulerSettings default_scheduler_settings; | 320 SchedulerSettings default_scheduler_settings; |
| 285 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 321 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 300 scheduler->SetCanStart(); | 336 scheduler->SetCanStart(); |
| 301 scheduler->SetVisible(true); | 337 scheduler->SetVisible(true); |
| 302 scheduler->SetCanDraw(true); | 338 scheduler->SetCanDraw(true); |
| 303 | 339 |
| 304 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 340 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 305 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 341 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 306 | 342 |
| 307 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 343 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 308 client.Reset(); | 344 client.Reset(); |
| 309 scheduler->SetNeedsCommit(); | 345 scheduler->SetNeedsCommit(); |
| 310 EXPECT_TRUE(client.needs_begin_frame()); | 346 EXPECT_TRUE(client.generate_frames()); |
| 311 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 347 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 312 client.Reset(); | 348 client.Reset(); |
| 313 | 349 |
| 314 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 350 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 315 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 351 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 316 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 352 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 317 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 353 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 318 EXPECT_TRUE(client.needs_begin_frame()); | 354 EXPECT_TRUE(client.generate_frames()); |
| 319 client.Reset(); | 355 client.Reset(); |
| 320 | 356 |
| 321 // If we don't swap on the deadline, we wait for the next BeginFrame. | 357 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 322 client.task_runner().RunPendingTasks(); // Run posted deadline. | 358 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 323 EXPECT_NO_ACTION(client); | 359 EXPECT_NO_ACTION(client); |
| 324 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 360 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 325 EXPECT_TRUE(client.needs_begin_frame()); | 361 EXPECT_TRUE(client.generate_frames()); |
| 326 client.Reset(); | 362 client.Reset(); |
| 327 | 363 |
| 328 // NotifyReadyToCommit should trigger the commit. | 364 // NotifyReadyToCommit should trigger the commit. |
| 329 scheduler->NotifyBeginMainFrameStarted(); | 365 scheduler->NotifyBeginMainFrameStarted(); |
| 330 scheduler->NotifyReadyToCommit(); | 366 scheduler->NotifyReadyToCommit(); |
| 331 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 367 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 332 EXPECT_TRUE(client.needs_begin_frame()); | 368 EXPECT_TRUE(client.generate_frames()); |
| 333 client.Reset(); | 369 client.Reset(); |
| 334 | 370 |
| 335 // BeginImplFrame should prepare the draw. | 371 // BeginImplFrame should prepare the draw. |
| 336 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 372 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 337 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 373 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 338 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 374 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 339 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 375 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 340 EXPECT_TRUE(client.needs_begin_frame()); | 376 EXPECT_TRUE(client.generate_frames()); |
| 341 client.Reset(); | 377 client.Reset(); |
| 342 | 378 |
| 343 // BeginImplFrame deadline should draw. | 379 // BeginImplFrame deadline should draw. |
| 344 client.task_runner().RunPendingTasks(); // Run posted deadline. | 380 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 345 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 381 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
| 346 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 382 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 347 EXPECT_TRUE(client.needs_begin_frame()); | 383 EXPECT_TRUE(client.generate_frames()); |
| 348 client.Reset(); | 384 client.Reset(); |
| 349 | 385 |
| 350 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 386 // The following BeginImplFrame deadline should SetGenerateFrames(false) |
| 351 // to avoid excessive toggles. | 387 // to avoid excessive toggles. |
| 352 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 388 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 353 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 389 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 354 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 390 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 355 client.Reset(); | 391 client.Reset(); |
| 356 | 392 |
| 357 client.task_runner().RunPendingTasks(); // Run posted deadline. | 393 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 358 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 394 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 359 EXPECT_FALSE(client.needs_begin_frame()); | 395 EXPECT_FALSE(client.generate_frames()); |
| 360 client.Reset(); | 396 client.Reset(); |
| 361 } | 397 } |
| 362 | 398 |
| 363 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 399 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| 364 FakeSchedulerClient client; | 400 FakeSchedulerClient client; |
| 365 SchedulerSettings scheduler_settings; | 401 SchedulerSettings scheduler_settings; |
| 366 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 402 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 367 scheduler->SetCanStart(); | 403 scheduler->SetCanStart(); |
| 368 scheduler->SetVisible(true); | 404 scheduler->SetVisible(true); |
| 369 scheduler->SetCanDraw(true); | 405 scheduler->SetCanDraw(true); |
| 370 | 406 |
| 371 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 407 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 372 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 408 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 373 client.Reset(); | 409 client.Reset(); |
| 374 | 410 |
| 375 // SetNeedsCommit should begin the frame. | 411 // SetNeedsCommit should begin the frame. |
| 376 scheduler->SetNeedsCommit(); | 412 scheduler->SetNeedsCommit(); |
| 377 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 413 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 378 | 414 |
| 379 client.Reset(); | 415 client.Reset(); |
| 380 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 416 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 381 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 417 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 382 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 418 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 383 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 419 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 384 | 420 |
| 385 EXPECT_TRUE(client.needs_begin_frame()); | 421 EXPECT_TRUE(client.generate_frames()); |
| 386 client.Reset(); | 422 client.Reset(); |
| 387 | 423 |
| 388 // Now SetNeedsCommit again. Calling here means we need a second commit. | 424 // Now SetNeedsCommit again. Calling here means we need a second commit. |
| 389 scheduler->SetNeedsCommit(); | 425 scheduler->SetNeedsCommit(); |
| 390 EXPECT_EQ(client.num_actions_(), 0); | 426 EXPECT_EQ(client.num_actions_(), 0); |
| 391 client.Reset(); | 427 client.Reset(); |
| 392 | 428 |
| 393 // Finish the first commit. | 429 // Finish the first commit. |
| 394 scheduler->NotifyBeginMainFrameStarted(); | 430 scheduler->NotifyBeginMainFrameStarted(); |
| 395 scheduler->NotifyReadyToCommit(); | 431 scheduler->NotifyReadyToCommit(); |
| 396 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 432 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 397 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 433 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 398 client.Reset(); | 434 client.Reset(); |
| 399 client.task_runner().RunPendingTasks(); // Run posted deadline. | 435 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 400 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 436 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 401 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 437 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 402 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 438 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 403 | 439 |
| 404 // Because we just swapped, the Scheduler should also request the next | 440 // Because we just swapped, the Scheduler should also request the next |
| 405 // BeginImplFrame from the OutputSurface. | 441 // BeginImplFrame from the OutputSurface. |
| 406 EXPECT_TRUE(client.needs_begin_frame()); | 442 EXPECT_TRUE(client.generate_frames()); |
| 407 client.Reset(); | 443 client.Reset(); |
| 408 // Since another commit is needed, the next BeginImplFrame should initiate | 444 // Since another commit is needed, the next BeginImplFrame should initiate |
| 409 // the second commit. | 445 // the second commit. |
| 410 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 446 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 411 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 447 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 412 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 448 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 413 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 449 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 414 client.Reset(); | 450 client.Reset(); |
| 415 | 451 |
| 416 // Finishing the commit before the deadline should post a new deadline task | 452 // Finishing the commit before the deadline should post a new deadline task |
| 417 // to trigger the deadline early. | 453 // to trigger the deadline early. |
| 418 scheduler->NotifyBeginMainFrameStarted(); | 454 scheduler->NotifyBeginMainFrameStarted(); |
| 419 scheduler->NotifyReadyToCommit(); | 455 scheduler->NotifyReadyToCommit(); |
| 420 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 456 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 421 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 457 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 422 client.Reset(); | 458 client.Reset(); |
| 423 client.task_runner().RunPendingTasks(); // Run posted deadline. | 459 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 424 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 460 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 425 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 461 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 426 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 462 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 427 EXPECT_TRUE(client.needs_begin_frame()); | 463 EXPECT_TRUE(client.generate_frames()); |
| 428 client.Reset(); | 464 client.Reset(); |
| 429 | 465 |
| 430 // On the next BeginImplFrame, verify we go back to a quiescent state and | 466 // On the next BeginImplFrame, verify we go back to a quiescent state and |
| 431 // no longer request BeginImplFrames. | 467 // no longer request BeginImplFrames. |
| 432 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 468 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 433 client.task_runner().RunPendingTasks(); // Run posted deadline. | 469 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 434 EXPECT_FALSE(client.needs_begin_frame()); | 470 EXPECT_FALSE(client.generate_frames()); |
| 435 client.Reset(); | 471 client.Reset(); |
| 436 } | 472 } |
| 437 | 473 |
| 438 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 474 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 439 public: | 475 public: |
| 440 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 476 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
| 441 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() | 477 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
| 442 OVERRIDE { | 478 OVERRIDE { |
| 443 // Only SetNeedsRedraw the first time this is called | 479 // Only SetNeedsRedraw the first time this is called |
| 444 if (!num_draws_) | 480 if (!num_draws_) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 465 SchedulerSettings default_scheduler_settings; | 501 SchedulerSettings default_scheduler_settings; |
| 466 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 502 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 467 scheduler->SetCanStart(); | 503 scheduler->SetCanStart(); |
| 468 scheduler->SetVisible(true); | 504 scheduler->SetVisible(true); |
| 469 scheduler->SetCanDraw(true); | 505 scheduler->SetCanDraw(true); |
| 470 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 506 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 471 client.Reset(); | 507 client.Reset(); |
| 472 | 508 |
| 473 scheduler->SetNeedsRedraw(); | 509 scheduler->SetNeedsRedraw(); |
| 474 EXPECT_TRUE(scheduler->RedrawPending()); | 510 EXPECT_TRUE(scheduler->RedrawPending()); |
| 475 EXPECT_TRUE(client.needs_begin_frame()); | 511 EXPECT_TRUE(client.generate_frames()); |
| 476 EXPECT_EQ(0, client.num_draws()); | 512 EXPECT_EQ(0, client.num_draws()); |
| 477 | 513 |
| 478 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 514 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 479 client.task_runner().RunPendingTasks(); // Run posted deadline. | 515 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 480 EXPECT_EQ(1, client.num_draws()); | 516 EXPECT_EQ(1, client.num_draws()); |
| 481 EXPECT_TRUE(scheduler->RedrawPending()); | 517 EXPECT_TRUE(scheduler->RedrawPending()); |
| 482 EXPECT_TRUE(client.needs_begin_frame()); | 518 EXPECT_TRUE(client.generate_frames()); |
| 483 | 519 |
| 484 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 520 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 485 client.task_runner().RunPendingTasks(); // Run posted deadline. | 521 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 486 EXPECT_EQ(2, client.num_draws()); | 522 EXPECT_EQ(2, client.num_draws()); |
| 487 EXPECT_FALSE(scheduler->RedrawPending()); | 523 EXPECT_FALSE(scheduler->RedrawPending()); |
| 488 EXPECT_TRUE(client.needs_begin_frame()); | 524 EXPECT_TRUE(client.generate_frames()); |
| 489 | 525 |
| 490 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 526 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| 491 // swap. | 527 // swap. |
| 492 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 528 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 493 client.task_runner().RunPendingTasks(); // Run posted deadline. | 529 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 494 EXPECT_EQ(2, client.num_draws()); | 530 EXPECT_EQ(2, client.num_draws()); |
| 495 EXPECT_FALSE(scheduler->RedrawPending()); | 531 EXPECT_FALSE(scheduler->RedrawPending()); |
| 496 EXPECT_FALSE(client.needs_begin_frame()); | 532 EXPECT_FALSE(client.generate_frames()); |
| 497 } | 533 } |
| 498 | 534 |
| 499 // Test that requesting redraw inside a failed draw doesn't lose the request. | 535 // Test that requesting redraw inside a failed draw doesn't lose the request. |
| 500 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 536 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| 501 SchedulerClientThatsetNeedsDrawInsideDraw client; | 537 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 502 SchedulerSettings default_scheduler_settings; | 538 SchedulerSettings default_scheduler_settings; |
| 503 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 539 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 504 scheduler->SetCanStart(); | 540 scheduler->SetCanStart(); |
| 505 scheduler->SetVisible(true); | 541 scheduler->SetVisible(true); |
| 506 scheduler->SetCanDraw(true); | 542 scheduler->SetCanDraw(true); |
| 507 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 543 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 508 client.Reset(); | 544 client.Reset(); |
| 509 | 545 |
| 510 client.SetDrawWillHappen(false); | 546 client.SetDrawWillHappen(false); |
| 511 | 547 |
| 512 scheduler->SetNeedsRedraw(); | 548 scheduler->SetNeedsRedraw(); |
| 513 EXPECT_TRUE(scheduler->RedrawPending()); | 549 EXPECT_TRUE(scheduler->RedrawPending()); |
| 514 EXPECT_TRUE(client.needs_begin_frame()); | 550 EXPECT_TRUE(client.generate_frames()); |
| 515 EXPECT_EQ(0, client.num_draws()); | 551 EXPECT_EQ(0, client.num_draws()); |
| 516 | 552 |
| 517 // Fail the draw. | 553 // Fail the draw. |
| 518 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 554 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 519 client.task_runner().RunPendingTasks(); // Run posted deadline. | 555 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 520 EXPECT_EQ(1, client.num_draws()); | 556 EXPECT_EQ(1, client.num_draws()); |
| 521 | 557 |
| 522 // We have a commit pending and the draw failed, and we didn't lose the redraw | 558 // We have a commit pending and the draw failed, and we didn't lose the redraw |
| 523 // request. | 559 // request. |
| 524 EXPECT_TRUE(scheduler->CommitPending()); | 560 EXPECT_TRUE(scheduler->CommitPending()); |
| 525 EXPECT_TRUE(scheduler->RedrawPending()); | 561 EXPECT_TRUE(scheduler->RedrawPending()); |
| 526 EXPECT_TRUE(client.needs_begin_frame()); | 562 EXPECT_TRUE(client.generate_frames()); |
| 527 | 563 |
| 528 // Fail the draw again. | 564 // Fail the draw again. |
| 529 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 565 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 530 client.task_runner().RunPendingTasks(); // Run posted deadline. | 566 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 531 EXPECT_EQ(2, client.num_draws()); | 567 EXPECT_EQ(2, client.num_draws()); |
| 532 EXPECT_TRUE(scheduler->CommitPending()); | 568 EXPECT_TRUE(scheduler->CommitPending()); |
| 533 EXPECT_TRUE(scheduler->RedrawPending()); | 569 EXPECT_TRUE(scheduler->RedrawPending()); |
| 534 EXPECT_TRUE(client.needs_begin_frame()); | 570 EXPECT_TRUE(client.generate_frames()); |
| 535 | 571 |
| 536 // Draw successfully. | 572 // Draw successfully. |
| 537 client.SetDrawWillHappen(true); | 573 client.SetDrawWillHappen(true); |
| 538 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 574 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 539 client.task_runner().RunPendingTasks(); // Run posted deadline. | 575 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 540 EXPECT_EQ(3, client.num_draws()); | 576 EXPECT_EQ(3, client.num_draws()); |
| 541 EXPECT_TRUE(scheduler->CommitPending()); | 577 EXPECT_TRUE(scheduler->CommitPending()); |
| 542 EXPECT_FALSE(scheduler->RedrawPending()); | 578 EXPECT_FALSE(scheduler->RedrawPending()); |
| 543 EXPECT_TRUE(client.needs_begin_frame()); | 579 EXPECT_TRUE(client.generate_frames()); |
| 544 } | 580 } |
| 545 | 581 |
| 546 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 582 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
| 547 public: | 583 public: |
| 548 SchedulerClientThatSetNeedsCommitInsideDraw() | 584 SchedulerClientThatSetNeedsCommitInsideDraw() |
| 549 : set_needs_commit_on_next_draw_(false) {} | 585 : set_needs_commit_on_next_draw_(false) {} |
| 550 | 586 |
| 551 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 587 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
| 552 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() | 588 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
| 553 OVERRIDE { | 589 OVERRIDE { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 579 TEST(SchedulerTest, RequestCommitInsideDraw) { | 615 TEST(SchedulerTest, RequestCommitInsideDraw) { |
| 580 SchedulerClientThatSetNeedsCommitInsideDraw client; | 616 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 581 SchedulerSettings default_scheduler_settings; | 617 SchedulerSettings default_scheduler_settings; |
| 582 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 618 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 583 scheduler->SetCanStart(); | 619 scheduler->SetCanStart(); |
| 584 scheduler->SetVisible(true); | 620 scheduler->SetVisible(true); |
| 585 scheduler->SetCanDraw(true); | 621 scheduler->SetCanDraw(true); |
| 586 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 622 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 587 client.Reset(); | 623 client.Reset(); |
| 588 | 624 |
| 589 EXPECT_FALSE(client.needs_begin_frame()); | 625 EXPECT_FALSE(client.generate_frames()); |
| 590 scheduler->SetNeedsRedraw(); | 626 scheduler->SetNeedsRedraw(); |
| 591 EXPECT_TRUE(scheduler->RedrawPending()); | 627 EXPECT_TRUE(scheduler->RedrawPending()); |
| 592 EXPECT_EQ(0, client.num_draws()); | 628 EXPECT_EQ(0, client.num_draws()); |
| 593 EXPECT_TRUE(client.needs_begin_frame()); | 629 EXPECT_TRUE(client.generate_frames()); |
| 594 | 630 |
| 595 client.SetNeedsCommitOnNextDraw(); | 631 client.SetNeedsCommitOnNextDraw(); |
| 596 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 632 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 597 client.SetNeedsCommitOnNextDraw(); | 633 client.SetNeedsCommitOnNextDraw(); |
| 598 client.task_runner().RunPendingTasks(); // Run posted deadline. | 634 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 599 EXPECT_EQ(1, client.num_draws()); | 635 EXPECT_EQ(1, client.num_draws()); |
| 600 EXPECT_TRUE(scheduler->CommitPending()); | 636 EXPECT_TRUE(scheduler->CommitPending()); |
| 601 EXPECT_TRUE(client.needs_begin_frame()); | 637 EXPECT_TRUE(client.generate_frames()); |
| 602 scheduler->NotifyBeginMainFrameStarted(); | 638 scheduler->NotifyBeginMainFrameStarted(); |
| 603 scheduler->NotifyReadyToCommit(); | 639 scheduler->NotifyReadyToCommit(); |
| 604 | 640 |
| 605 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 641 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 606 client.task_runner().RunPendingTasks(); // Run posted deadline. | 642 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 607 EXPECT_EQ(2, client.num_draws()); | 643 EXPECT_EQ(2, client.num_draws()); |
| 608 | 644 |
| 609 EXPECT_FALSE(scheduler->RedrawPending()); | 645 EXPECT_FALSE(scheduler->RedrawPending()); |
| 610 EXPECT_FALSE(scheduler->CommitPending()); | 646 EXPECT_FALSE(scheduler->CommitPending()); |
| 611 EXPECT_TRUE(client.needs_begin_frame()); | 647 EXPECT_TRUE(client.generate_frames()); |
| 612 | 648 |
| 613 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 649 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| 614 // swap. | 650 // swap. |
| 615 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 651 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 616 client.task_runner().RunPendingTasks(); // Run posted deadline. | 652 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 617 EXPECT_EQ(2, client.num_draws()); | 653 EXPECT_EQ(2, client.num_draws()); |
| 618 EXPECT_FALSE(scheduler->RedrawPending()); | 654 EXPECT_FALSE(scheduler->RedrawPending()); |
| 619 EXPECT_FALSE(scheduler->CommitPending()); | 655 EXPECT_FALSE(scheduler->CommitPending()); |
| 620 EXPECT_FALSE(client.needs_begin_frame()); | 656 EXPECT_FALSE(client.generate_frames()); |
| 621 } | 657 } |
| 622 | 658 |
| 623 // Tests that when a draw fails then the pending commit should not be dropped. | 659 // Tests that when a draw fails then the pending commit should not be dropped. |
| 624 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 660 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
| 625 SchedulerClientThatsetNeedsDrawInsideDraw client; | 661 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 626 SchedulerSettings default_scheduler_settings; | 662 SchedulerSettings default_scheduler_settings; |
| 627 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 663 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 628 scheduler->SetCanStart(); | 664 scheduler->SetCanStart(); |
| 629 scheduler->SetVisible(true); | 665 scheduler->SetVisible(true); |
| 630 scheduler->SetCanDraw(true); | 666 scheduler->SetCanDraw(true); |
| 631 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 667 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 632 client.Reset(); | 668 client.Reset(); |
| 633 | 669 |
| 634 client.SetDrawWillHappen(false); | 670 client.SetDrawWillHappen(false); |
| 635 | 671 |
| 636 scheduler->SetNeedsRedraw(); | 672 scheduler->SetNeedsRedraw(); |
| 637 EXPECT_TRUE(scheduler->RedrawPending()); | 673 EXPECT_TRUE(scheduler->RedrawPending()); |
| 638 EXPECT_TRUE(client.needs_begin_frame()); | 674 EXPECT_TRUE(client.generate_frames()); |
| 639 EXPECT_EQ(0, client.num_draws()); | 675 EXPECT_EQ(0, client.num_draws()); |
| 640 | 676 |
| 641 // Fail the draw. | 677 // Fail the draw. |
| 642 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 678 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 643 client.task_runner().RunPendingTasks(); // Run posted deadline. | 679 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 644 EXPECT_EQ(1, client.num_draws()); | 680 EXPECT_EQ(1, client.num_draws()); |
| 645 | 681 |
| 646 // We have a commit pending and the draw failed, and we didn't lose the commit | 682 // We have a commit pending and the draw failed, and we didn't lose the commit |
| 647 // request. | 683 // request. |
| 648 EXPECT_TRUE(scheduler->CommitPending()); | 684 EXPECT_TRUE(scheduler->CommitPending()); |
| 649 EXPECT_TRUE(scheduler->RedrawPending()); | 685 EXPECT_TRUE(scheduler->RedrawPending()); |
| 650 EXPECT_TRUE(client.needs_begin_frame()); | 686 EXPECT_TRUE(client.generate_frames()); |
| 651 | 687 |
| 652 // Fail the draw again. | 688 // Fail the draw again. |
| 653 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 689 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 654 | 690 |
| 655 client.task_runner().RunPendingTasks(); // Run posted deadline. | 691 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 656 EXPECT_EQ(2, client.num_draws()); | 692 EXPECT_EQ(2, client.num_draws()); |
| 657 EXPECT_TRUE(scheduler->CommitPending()); | 693 EXPECT_TRUE(scheduler->CommitPending()); |
| 658 EXPECT_TRUE(scheduler->RedrawPending()); | 694 EXPECT_TRUE(scheduler->RedrawPending()); |
| 659 EXPECT_TRUE(client.needs_begin_frame()); | 695 EXPECT_TRUE(client.generate_frames()); |
| 660 | 696 |
| 661 // Draw successfully. | 697 // Draw successfully. |
| 662 client.SetDrawWillHappen(true); | 698 client.SetDrawWillHappen(true); |
| 663 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 699 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 664 client.task_runner().RunPendingTasks(); // Run posted deadline. | 700 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 665 EXPECT_EQ(3, client.num_draws()); | 701 EXPECT_EQ(3, client.num_draws()); |
| 666 EXPECT_TRUE(scheduler->CommitPending()); | 702 EXPECT_TRUE(scheduler->CommitPending()); |
| 667 EXPECT_FALSE(scheduler->RedrawPending()); | 703 EXPECT_FALSE(scheduler->RedrawPending()); |
| 668 EXPECT_TRUE(client.needs_begin_frame()); | 704 EXPECT_TRUE(client.generate_frames()); |
| 669 } | 705 } |
| 670 | 706 |
| 671 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 707 TEST(SchedulerTest, NoSwapWhenDrawFails) { |
| 672 SchedulerClientThatSetNeedsCommitInsideDraw client; | 708 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 673 SchedulerSettings default_scheduler_settings; | 709 SchedulerSettings default_scheduler_settings; |
| 674 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 710 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 675 scheduler->SetCanStart(); | 711 scheduler->SetCanStart(); |
| 676 scheduler->SetVisible(true); | 712 scheduler->SetVisible(true); |
| 677 scheduler->SetCanDraw(true); | 713 scheduler->SetCanDraw(true); |
| 678 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 714 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 679 client.Reset(); | 715 client.Reset(); |
| 680 | 716 |
| 681 scheduler->SetNeedsRedraw(); | 717 scheduler->SetNeedsRedraw(); |
| 682 EXPECT_TRUE(scheduler->RedrawPending()); | 718 EXPECT_TRUE(scheduler->RedrawPending()); |
| 683 EXPECT_TRUE(client.needs_begin_frame()); | 719 EXPECT_TRUE(client.generate_frames()); |
| 684 EXPECT_EQ(0, client.num_draws()); | 720 EXPECT_EQ(0, client.num_draws()); |
| 685 | 721 |
| 686 // Draw successfully, this starts a new frame. | 722 // Draw successfully, this starts a new frame. |
| 687 client.SetNeedsCommitOnNextDraw(); | 723 client.SetNeedsCommitOnNextDraw(); |
| 688 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 724 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 689 client.task_runner().RunPendingTasks(); // Run posted deadline. | 725 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 690 EXPECT_EQ(1, client.num_draws()); | 726 EXPECT_EQ(1, client.num_draws()); |
| 691 | 727 |
| 692 scheduler->SetNeedsRedraw(); | 728 scheduler->SetNeedsRedraw(); |
| 693 EXPECT_TRUE(scheduler->RedrawPending()); | 729 EXPECT_TRUE(scheduler->RedrawPending()); |
| 694 EXPECT_TRUE(client.needs_begin_frame()); | 730 EXPECT_TRUE(client.generate_frames()); |
| 695 | 731 |
| 696 // Fail to draw, this should not start a frame. | 732 // Fail to draw, this should not start a frame. |
| 697 client.SetDrawWillHappen(false); | 733 client.SetDrawWillHappen(false); |
| 698 client.SetNeedsCommitOnNextDraw(); | 734 client.SetNeedsCommitOnNextDraw(); |
| 699 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 735 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 700 client.task_runner().RunPendingTasks(); // Run posted deadline. | 736 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 701 EXPECT_EQ(2, client.num_draws()); | 737 EXPECT_EQ(2, client.num_draws()); |
| 702 } | 738 } |
| 703 | 739 |
| 704 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { | 740 class SchedulerClientNeedsManageTilesInDraw : public FakeSchedulerClient { |
| 705 public: | 741 public: |
| 706 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() | 742 virtual DrawResult ScheduledActionDrawAndSwapIfPossible() |
| 707 OVERRIDE { | 743 OVERRIDE { |
| 708 scheduler_->SetNeedsManageTiles(); | 744 scheduler_->SetNeedsManageTiles(); |
| 709 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); | 745 return FakeSchedulerClient::ScheduledActionDrawAndSwapIfPossible(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 720 scheduler->SetCanDraw(true); | 756 scheduler->SetCanDraw(true); |
| 721 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 757 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 722 | 758 |
| 723 // Request both draw and manage tiles. ManageTiles shouldn't | 759 // Request both draw and manage tiles. ManageTiles shouldn't |
| 724 // be trigged until BeginImplFrame. | 760 // be trigged until BeginImplFrame. |
| 725 client.Reset(); | 761 client.Reset(); |
| 726 scheduler->SetNeedsManageTiles(); | 762 scheduler->SetNeedsManageTiles(); |
| 727 scheduler->SetNeedsRedraw(); | 763 scheduler->SetNeedsRedraw(); |
| 728 EXPECT_TRUE(scheduler->RedrawPending()); | 764 EXPECT_TRUE(scheduler->RedrawPending()); |
| 729 EXPECT_TRUE(scheduler->ManageTilesPending()); | 765 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 730 EXPECT_TRUE(client.needs_begin_frame()); | 766 EXPECT_TRUE(client.generate_frames()); |
| 731 EXPECT_EQ(0, client.num_draws()); | 767 EXPECT_EQ(0, client.num_draws()); |
| 732 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 768 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| 733 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 769 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 734 | 770 |
| 735 // We have no immediate actions to perform, so the BeginImplFrame should post | 771 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 736 // the deadline task. | 772 // the deadline task. |
| 737 client.Reset(); | 773 client.Reset(); |
| 738 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 774 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 739 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 775 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 740 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 776 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 741 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 777 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 742 | 778 |
| 743 // On the deadline, he actions should have occured in the right order. | 779 // On the deadline, he actions should have occured in the right order. |
| 744 client.Reset(); | 780 client.Reset(); |
| 745 client.task_runner().RunPendingTasks(); // Run posted deadline. | 781 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 746 EXPECT_EQ(1, client.num_draws()); | 782 EXPECT_EQ(1, client.num_draws()); |
| 747 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 783 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 748 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 784 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 749 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 785 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 750 client.ActionIndex("ScheduledActionManageTiles")); | 786 client.ActionIndex("ScheduledActionManageTiles")); |
| 751 EXPECT_FALSE(scheduler->RedrawPending()); | 787 EXPECT_FALSE(scheduler->RedrawPending()); |
| 752 EXPECT_FALSE(scheduler->ManageTilesPending()); | 788 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 753 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 789 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 754 | 790 |
| 755 // Request a draw. We don't need a ManageTiles yet. | 791 // Request a draw. We don't need a ManageTiles yet. |
| 756 client.Reset(); | 792 client.Reset(); |
| 757 scheduler->SetNeedsRedraw(); | 793 scheduler->SetNeedsRedraw(); |
| 758 EXPECT_TRUE(scheduler->RedrawPending()); | 794 EXPECT_TRUE(scheduler->RedrawPending()); |
| 759 EXPECT_FALSE(scheduler->ManageTilesPending()); | 795 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 760 EXPECT_TRUE(client.needs_begin_frame()); | 796 EXPECT_TRUE(client.generate_frames()); |
| 761 EXPECT_EQ(0, client.num_draws()); | 797 EXPECT_EQ(0, client.num_draws()); |
| 762 | 798 |
| 763 // We have no immediate actions to perform, so the BeginImplFrame should post | 799 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 764 // the deadline task. | 800 // the deadline task. |
| 765 client.Reset(); | 801 client.Reset(); |
| 766 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 802 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 767 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 803 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 768 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 804 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 769 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 805 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 770 | 806 |
| 771 // Draw. The draw will trigger SetNeedsManageTiles, and | 807 // Draw. The draw will trigger SetNeedsManageTiles, and |
| 772 // then the ManageTiles action will be triggered after the Draw. | 808 // then the ManageTiles action will be triggered after the Draw. |
| 773 // Afterwards, neither a draw nor ManageTiles are pending. | 809 // Afterwards, neither a draw nor ManageTiles are pending. |
| 774 client.Reset(); | 810 client.Reset(); |
| 775 client.task_runner().RunPendingTasks(); // Run posted deadline. | 811 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 776 EXPECT_EQ(1, client.num_draws()); | 812 EXPECT_EQ(1, client.num_draws()); |
| 777 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 813 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 778 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 814 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 779 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 815 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 780 client.ActionIndex("ScheduledActionManageTiles")); | 816 client.ActionIndex("ScheduledActionManageTiles")); |
| 781 EXPECT_FALSE(scheduler->RedrawPending()); | 817 EXPECT_FALSE(scheduler->RedrawPending()); |
| 782 EXPECT_FALSE(scheduler->ManageTilesPending()); | 818 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 783 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 819 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 784 | 820 |
| 785 // We need a BeginImplFrame where we don't swap to go idle. | 821 // We need a BeginImplFrame where we don't swap to go idle. |
| 786 client.Reset(); | 822 client.Reset(); |
| 787 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 823 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 788 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 824 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 789 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 825 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 790 client.Reset(); | 826 client.Reset(); |
| 791 client.task_runner().RunPendingTasks(); // Run posted deadline. | 827 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 792 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 828 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 793 EXPECT_FALSE(client.needs_begin_frame()); | 829 EXPECT_FALSE(client.generate_frames()); |
| 794 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 830 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 795 EXPECT_EQ(0, client.num_draws()); | 831 EXPECT_EQ(0, client.num_draws()); |
| 796 | 832 |
| 797 // Now trigger a ManageTiles outside of a draw. We will then need | 833 // Now trigger a ManageTiles outside of a draw. We will then need |
| 798 // a begin-frame for the ManageTiles, but we don't need a draw. | 834 // a begin-frame for the ManageTiles, but we don't need a draw. |
| 799 client.Reset(); | 835 client.Reset(); |
| 800 EXPECT_FALSE(client.needs_begin_frame()); | 836 EXPECT_FALSE(client.generate_frames()); |
| 801 scheduler->SetNeedsManageTiles(); | 837 scheduler->SetNeedsManageTiles(); |
| 802 EXPECT_TRUE(client.needs_begin_frame()); | 838 EXPECT_TRUE(client.generate_frames()); |
| 803 EXPECT_TRUE(scheduler->ManageTilesPending()); | 839 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 804 EXPECT_FALSE(scheduler->RedrawPending()); | 840 EXPECT_FALSE(scheduler->RedrawPending()); |
| 805 | 841 |
| 806 // BeginImplFrame. There will be no draw, only ManageTiles. | 842 // BeginImplFrame. There will be no draw, only ManageTiles. |
| 807 client.Reset(); | 843 client.Reset(); |
| 808 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 844 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 809 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 845 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 810 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 846 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 811 client.Reset(); | 847 client.Reset(); |
| 812 client.task_runner().RunPendingTasks(); // Run posted deadline. | 848 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 813 EXPECT_EQ(0, client.num_draws()); | 849 EXPECT_EQ(0, client.num_draws()); |
| 814 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 850 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 815 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 851 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 816 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 852 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 817 } | 853 } |
| 818 | 854 |
| 819 // Test that ManageTiles only happens once per frame. If an external caller | 855 // Test that ManageTiles only happens once per frame. If an external caller |
| 820 // initiates it, then the state machine should not ManageTiles on that frame. | 856 // initiates it, then the state machine should not ManageTiles on that frame. |
| 821 TEST(SchedulerTest, ManageTilesOncePerFrame) { | 857 TEST(SchedulerTest, ManageTilesOncePerFrame) { |
| 822 FakeSchedulerClient client; | 858 FakeSchedulerClient client; |
| 823 SchedulerSettings default_scheduler_settings; | 859 SchedulerSettings default_scheduler_settings; |
| 824 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 860 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 825 scheduler->SetCanStart(); | 861 scheduler->SetCanStart(); |
| 826 scheduler->SetVisible(true); | 862 scheduler->SetVisible(true); |
| 827 scheduler->SetCanDraw(true); | 863 scheduler->SetCanDraw(true); |
| 828 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 864 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 829 | 865 |
| 830 // If DidManageTiles during a frame, then ManageTiles should not occur again. | 866 // If DidManageTiles during a frame, then ManageTiles should not occur again. |
| 831 scheduler->SetNeedsManageTiles(); | 867 scheduler->SetNeedsManageTiles(); |
| 832 scheduler->SetNeedsRedraw(); | 868 scheduler->SetNeedsRedraw(); |
| 833 client.Reset(); | 869 client.Reset(); |
| 834 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 870 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 835 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 871 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 836 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 872 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 837 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 873 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 838 | 874 |
| 839 EXPECT_TRUE(scheduler->ManageTilesPending()); | 875 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 840 scheduler->DidManageTiles(); // An explicit ManageTiles. | 876 scheduler->DidManageTiles(); // An explicit ManageTiles. |
| 841 EXPECT_FALSE(scheduler->ManageTilesPending()); | 877 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 842 | 878 |
| 843 client.Reset(); | 879 client.Reset(); |
| 844 client.task_runner().RunPendingTasks(); // Run posted deadline. | 880 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 845 EXPECT_EQ(1, client.num_draws()); | 881 EXPECT_EQ(1, client.num_draws()); |
| 846 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 882 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 847 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 883 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| 848 EXPECT_FALSE(scheduler->RedrawPending()); | 884 EXPECT_FALSE(scheduler->RedrawPending()); |
| 849 EXPECT_FALSE(scheduler->ManageTilesPending()); | 885 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 850 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 886 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 851 | 887 |
| 852 // Next frame without DidManageTiles should ManageTiles with draw. | 888 // Next frame without DidManageTiles should ManageTiles with draw. |
| 853 scheduler->SetNeedsManageTiles(); | 889 scheduler->SetNeedsManageTiles(); |
| 854 scheduler->SetNeedsRedraw(); | 890 scheduler->SetNeedsRedraw(); |
| 855 client.Reset(); | 891 client.Reset(); |
| 856 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 892 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 857 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 893 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 858 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 894 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 859 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 895 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 860 | 896 |
| 861 client.Reset(); | 897 client.Reset(); |
| 862 client.task_runner().RunPendingTasks(); // Run posted deadline. | 898 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 863 EXPECT_EQ(1, client.num_draws()); | 899 EXPECT_EQ(1, client.num_draws()); |
| 864 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 900 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 865 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 901 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 866 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 902 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 867 client.ActionIndex("ScheduledActionManageTiles")); | 903 client.ActionIndex("ScheduledActionManageTiles")); |
| 868 EXPECT_FALSE(scheduler->RedrawPending()); | 904 EXPECT_FALSE(scheduler->RedrawPending()); |
| 869 EXPECT_FALSE(scheduler->ManageTilesPending()); | 905 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 870 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 906 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 871 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles | 907 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles |
| 872 | 908 |
| 873 // If we get another DidManageTiles within the same frame, we should | 909 // If we get another DidManageTiles within the same frame, we should |
| 874 // not ManageTiles on the next frame. | 910 // not ManageTiles on the next frame. |
| 875 scheduler->DidManageTiles(); // An explicit ManageTiles. | 911 scheduler->DidManageTiles(); // An explicit ManageTiles. |
| 876 scheduler->SetNeedsManageTiles(); | 912 scheduler->SetNeedsManageTiles(); |
| 877 scheduler->SetNeedsRedraw(); | 913 scheduler->SetNeedsRedraw(); |
| 878 client.Reset(); | 914 client.Reset(); |
| 879 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 915 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 880 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 916 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 881 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 917 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 882 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 918 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 883 | 919 |
| 884 EXPECT_TRUE(scheduler->ManageTilesPending()); | 920 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 885 | 921 |
| 886 client.Reset(); | 922 client.Reset(); |
| 887 client.task_runner().RunPendingTasks(); // Run posted deadline. | 923 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 888 EXPECT_EQ(1, client.num_draws()); | 924 EXPECT_EQ(1, client.num_draws()); |
| 889 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 925 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 890 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 926 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| 891 EXPECT_FALSE(scheduler->RedrawPending()); | 927 EXPECT_FALSE(scheduler->RedrawPending()); |
| 892 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 928 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 893 | 929 |
| 894 // If we get another DidManageTiles, we should not ManageTiles on the next | 930 // If we get another DidManageTiles, we should not ManageTiles on the next |
| 895 // frame. This verifies we don't alternate calling ManageTiles once and twice. | 931 // frame. This verifies we don't alternate calling ManageTiles once and twice. |
| 896 EXPECT_TRUE(scheduler->ManageTilesPending()); | 932 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 897 scheduler->DidManageTiles(); // An explicit ManageTiles. | 933 scheduler->DidManageTiles(); // An explicit ManageTiles. |
| 898 EXPECT_FALSE(scheduler->ManageTilesPending()); | 934 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 899 scheduler->SetNeedsManageTiles(); | 935 scheduler->SetNeedsManageTiles(); |
| 900 scheduler->SetNeedsRedraw(); | 936 scheduler->SetNeedsRedraw(); |
| 901 client.Reset(); | 937 client.Reset(); |
| 902 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 938 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 903 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 939 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 904 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 940 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 905 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 941 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 906 | 942 |
| 907 EXPECT_TRUE(scheduler->ManageTilesPending()); | 943 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 908 | 944 |
| 909 client.Reset(); | 945 client.Reset(); |
| 910 client.task_runner().RunPendingTasks(); // Run posted deadline. | 946 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 911 EXPECT_EQ(1, client.num_draws()); | 947 EXPECT_EQ(1, client.num_draws()); |
| 912 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 948 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 913 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 949 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| 914 EXPECT_FALSE(scheduler->RedrawPending()); | 950 EXPECT_FALSE(scheduler->RedrawPending()); |
| 915 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 951 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 916 | 952 |
| 917 // Next frame without DidManageTiles should ManageTiles with draw. | 953 // Next frame without DidManageTiles should ManageTiles with draw. |
| 918 scheduler->SetNeedsManageTiles(); | 954 scheduler->SetNeedsManageTiles(); |
| 919 scheduler->SetNeedsRedraw(); | 955 scheduler->SetNeedsRedraw(); |
| 920 client.Reset(); | 956 client.Reset(); |
| 921 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 957 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 922 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 958 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 923 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 959 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 924 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 960 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 925 | 961 |
| 926 client.Reset(); | 962 client.Reset(); |
| 927 client.task_runner().RunPendingTasks(); // Run posted deadline. | 963 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 928 EXPECT_EQ(1, client.num_draws()); | 964 EXPECT_EQ(1, client.num_draws()); |
| 929 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 965 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 930 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 966 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 931 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 967 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 944 scheduler->SetCanStart(); | 980 scheduler->SetCanStart(); |
| 945 scheduler->SetVisible(true); | 981 scheduler->SetVisible(true); |
| 946 scheduler->SetCanDraw(true); | 982 scheduler->SetCanDraw(true); |
| 947 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 983 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 948 | 984 |
| 949 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); | 985 client.SetRedrawWillHappenIfUpdateVisibleTilesHappens(true); |
| 950 | 986 |
| 951 // SetNeedsCommit should begin the frame. | 987 // SetNeedsCommit should begin the frame. |
| 952 client.Reset(); | 988 client.Reset(); |
| 953 scheduler->SetNeedsCommit(); | 989 scheduler->SetNeedsCommit(); |
| 954 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 990 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 955 | 991 |
| 956 client.Reset(); | 992 client.Reset(); |
| 957 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 993 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); |
| 958 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 994 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 959 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 995 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 960 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 996 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 961 | 997 |
| 962 client.Reset(); | 998 client.Reset(); |
| 963 scheduler->NotifyBeginMainFrameStarted(); | 999 scheduler->NotifyBeginMainFrameStarted(); |
| 964 scheduler->NotifyReadyToCommit(); | 1000 scheduler->NotifyReadyToCommit(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 987 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); | 1023 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 2, 3); |
| 988 | 1024 |
| 989 client.Reset(); | 1025 client.Reset(); |
| 990 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1026 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); |
| 991 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1027 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 992 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1028 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 993 | 1029 |
| 994 // No more UpdateVisibleTiles(). | 1030 // No more UpdateVisibleTiles(). |
| 995 client.Reset(); | 1031 client.Reset(); |
| 996 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1032 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 997 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1033 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 998 EXPECT_FALSE(client.needs_begin_frame()); | 1034 EXPECT_FALSE(client.generate_frames()); |
| 999 } | 1035 } |
| 1000 | 1036 |
| 1001 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 1037 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
| 1002 SchedulerClientNeedsManageTilesInDraw client; | 1038 SchedulerClientNeedsManageTilesInDraw client; |
| 1003 SchedulerSettings default_scheduler_settings; | 1039 SchedulerSettings default_scheduler_settings; |
| 1004 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 1040 TestScheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 1005 scheduler->SetCanStart(); | 1041 scheduler->SetCanStart(); |
| 1006 scheduler->SetVisible(true); | 1042 scheduler->SetVisible(true); |
| 1007 scheduler->SetCanDraw(true); | 1043 scheduler->SetCanDraw(true); |
| 1008 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1044 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1009 | 1045 |
| 1010 client.Reset(); | 1046 client.Reset(); |
| 1011 scheduler->SetNeedsRedraw(); | 1047 scheduler->SetNeedsRedraw(); |
| 1012 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1048 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 1013 | 1049 |
| 1014 // The deadline should be zero since there is no work other than drawing | 1050 // The deadline should be zero since there is no work other than drawing |
| 1015 // pending. | 1051 // pending. |
| 1016 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); | 1052 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); |
| 1017 } | 1053 } |
| 1018 | 1054 |
| 1019 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | 1055 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
| 1020 public: | 1056 public: |
| 1021 SchedulerClientWithFixedEstimates( | 1057 SchedulerClientWithFixedEstimates( |
| 1022 base::TimeDelta draw_duration, | 1058 base::TimeDelta draw_duration, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 scheduler->SetCanStart(); | 1094 scheduler->SetCanStart(); |
| 1059 scheduler->SetVisible(true); | 1095 scheduler->SetVisible(true); |
| 1060 scheduler->SetCanDraw(true); | 1096 scheduler->SetCanDraw(true); |
| 1061 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); | 1097 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); |
| 1062 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1098 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1063 | 1099 |
| 1064 // Impl thread hits deadline before commit finishes. | 1100 // Impl thread hits deadline before commit finishes. |
| 1065 client.Reset(); | 1101 client.Reset(); |
| 1066 scheduler->SetNeedsCommit(); | 1102 scheduler->SetNeedsCommit(); |
| 1067 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1103 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1068 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1104 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 1069 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 1105 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1070 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1106 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1071 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1107 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1072 scheduler->NotifyBeginMainFrameStarted(); | 1108 scheduler->NotifyBeginMainFrameStarted(); |
| 1073 scheduler->NotifyReadyToCommit(); | 1109 scheduler->NotifyReadyToCommit(); |
| 1074 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1110 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1075 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); | 1111 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); |
| 1076 | 1112 |
| 1077 client.Reset(); | 1113 client.Reset(); |
| 1078 scheduler->SetNeedsCommit(); | 1114 scheduler->SetNeedsCommit(); |
| 1079 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1115 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1080 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1116 client.frame_source().TestBeginFrame(CreateBeginFrameArgsForTesting()); |
| 1081 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 1117 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 1082 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1118 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1083 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), | 1119 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), |
| 1084 should_send_begin_main_frame); | 1120 should_send_begin_main_frame); |
| 1085 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), | 1121 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), |
| 1086 should_send_begin_main_frame); | 1122 should_send_begin_main_frame); |
| 1087 } | 1123 } |
| 1088 | 1124 |
| 1089 TEST(SchedulerTest, | 1125 TEST(SchedulerTest, |
| 1090 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 1126 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 scheduler->DidCreateAndInitializeOutputSurface(); | 1165 scheduler->DidCreateAndInitializeOutputSurface(); |
| 1130 | 1166 |
| 1131 scheduler->SetNeedsCommit(); | 1167 scheduler->SetNeedsCommit(); |
| 1132 EXPECT_TRUE(scheduler->CommitPending()); | 1168 EXPECT_TRUE(scheduler->CommitPending()); |
| 1133 scheduler->NotifyBeginMainFrameStarted(); | 1169 scheduler->NotifyBeginMainFrameStarted(); |
| 1134 scheduler->NotifyReadyToCommit(); | 1170 scheduler->NotifyReadyToCommit(); |
| 1135 scheduler->SetNeedsRedraw(); | 1171 scheduler->SetNeedsRedraw(); |
| 1136 | 1172 |
| 1137 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(); | 1173 BeginFrameArgs frame_args = CreateBeginFrameArgsForTesting(); |
| 1138 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1174 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
| 1139 scheduler->BeginFrame(frame_args); | 1175 client.frame_source().TestBeginFrame(frame_args); |
| 1140 | 1176 |
| 1141 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1177 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1142 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1178 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1143 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1179 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1144 | 1180 |
| 1145 scheduler->DidSwapBuffers(); | 1181 scheduler->DidSwapBuffers(); |
| 1146 scheduler->DidSwapBuffersComplete(); | 1182 scheduler->DidSwapBuffersComplete(); |
| 1147 | 1183 |
| 1148 // At this point, we've drawn a frame. Start another commit, but hold off on | 1184 // At this point, we've drawn a frame. Start another commit, but hold off on |
| 1149 // the NotifyReadyToCommit for now. | 1185 // the NotifyReadyToCommit for now. |
| 1150 EXPECT_FALSE(scheduler->CommitPending()); | 1186 EXPECT_FALSE(scheduler->CommitPending()); |
| 1151 scheduler->SetNeedsCommit(); | 1187 scheduler->SetNeedsCommit(); |
| 1152 scheduler->BeginFrame(frame_args); | 1188 client.frame_source().TestBeginFrame(frame_args); |
| 1153 EXPECT_TRUE(scheduler->CommitPending()); | 1189 EXPECT_TRUE(scheduler->CommitPending()); |
| 1154 | 1190 |
| 1155 // Draw and swap the frame, but don't ack the swap to simulate the Browser | 1191 // Draw and swap the frame, but don't ack the swap to simulate the Browser |
| 1156 // blocking on the renderer. | 1192 // blocking on the renderer. |
| 1157 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1193 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1158 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1194 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1159 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1195 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1160 scheduler->DidSwapBuffers(); | 1196 scheduler->DidSwapBuffers(); |
| 1161 | 1197 |
| 1162 // Spin the event loop a few times and make sure we get more | 1198 // Spin the event loop a few times and make sure we get more |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 SchedulerSettings scheduler_settings; | 1230 SchedulerSettings scheduler_settings; |
| 1195 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1231 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1196 scheduler->SetCanStart(); | 1232 scheduler->SetCanStart(); |
| 1197 scheduler->SetVisible(true); | 1233 scheduler->SetVisible(true); |
| 1198 scheduler->SetCanDraw(true); | 1234 scheduler->SetCanDraw(true); |
| 1199 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1235 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1200 | 1236 |
| 1201 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1237 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1202 client.Reset(); | 1238 client.Reset(); |
| 1203 scheduler->SetNeedsCommit(); | 1239 scheduler->SetNeedsCommit(); |
| 1204 EXPECT_TRUE(client.needs_begin_frame()); | 1240 EXPECT_TRUE(client.generate_frames()); |
| 1205 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1241 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 1206 client.Reset(); | 1242 client.Reset(); |
| 1207 | 1243 |
| 1208 // Create a BeginFrame with a long deadline to avoid race conditions. | 1244 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1209 // This is the first BeginFrame, which will be handled immediately. | 1245 // This is the first BeginFrame, which will be handled immediately. |
| 1210 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1246 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); |
| 1211 args.deadline += base::TimeDelta::FromHours(1); | 1247 args.deadline += base::TimeDelta::FromHours(1); |
| 1212 scheduler->BeginFrame(args); | 1248 client.frame_source().TestBeginFrame(args); |
| 1213 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1249 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1214 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1250 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1215 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1251 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1216 EXPECT_TRUE(client.needs_begin_frame()); | 1252 EXPECT_TRUE(client.generate_frames()); |
| 1217 client.Reset(); | 1253 client.Reset(); |
| 1218 | 1254 |
| 1219 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1255 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1220 args.frame_time += base::TimeDelta::FromSeconds(1); | 1256 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1221 scheduler->BeginFrame(args); | 1257 client.frame_source().TestBeginFrame(args); |
| 1222 args.frame_time += base::TimeDelta::FromSeconds(1); | 1258 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1223 scheduler->BeginFrame(args); | 1259 client.frame_source().TestBeginFrame(args); |
| 1224 | 1260 |
| 1225 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1261 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 1226 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1262 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1227 EXPECT_NO_ACTION(client); | 1263 EXPECT_NO_ACTION(client); |
| 1228 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1264 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1229 EXPECT_TRUE(client.needs_begin_frame()); | 1265 EXPECT_TRUE(client.generate_frames()); |
| 1230 client.Reset(); | 1266 client.Reset(); |
| 1231 | 1267 |
| 1232 // NotifyReadyToCommit should trigger the commit. | 1268 // NotifyReadyToCommit should trigger the commit. |
| 1233 scheduler->NotifyBeginMainFrameStarted(); | 1269 scheduler->NotifyBeginMainFrameStarted(); |
| 1234 scheduler->NotifyReadyToCommit(); | 1270 scheduler->NotifyReadyToCommit(); |
| 1235 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1271 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1236 EXPECT_TRUE(client.needs_begin_frame()); | 1272 EXPECT_TRUE(client.generate_frames()); |
| 1237 client.Reset(); | 1273 client.Reset(); |
| 1238 | 1274 |
| 1239 // BeginImplFrame should prepare the draw. | 1275 // BeginImplFrame should prepare the draw. |
| 1240 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1276 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1241 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1277 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1242 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1278 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1243 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1279 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1244 EXPECT_TRUE(client.needs_begin_frame()); | 1280 EXPECT_TRUE(client.generate_frames()); |
| 1245 client.Reset(); | 1281 client.Reset(); |
| 1246 | 1282 |
| 1247 // BeginImplFrame deadline should draw. | 1283 // BeginImplFrame deadline should draw. |
| 1248 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1284 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1249 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1285 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
| 1250 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1286 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1251 EXPECT_TRUE(client.needs_begin_frame()); | 1287 EXPECT_TRUE(client.generate_frames()); |
| 1252 client.Reset(); | 1288 client.Reset(); |
| 1253 | 1289 |
| 1254 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1290 // The following BeginImplFrame deadline should SetGenerateFrames(false) |
| 1255 // to avoid excessive toggles. | 1291 // to avoid excessive toggles. |
| 1256 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1292 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1257 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1293 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1258 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1294 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1259 client.Reset(); | 1295 client.Reset(); |
| 1260 | 1296 |
| 1261 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1297 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1262 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1298 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 1263 EXPECT_FALSE(client.needs_begin_frame()); | 1299 EXPECT_FALSE(client.generate_frames()); |
| 1264 client.Reset(); | 1300 client.Reset(); |
| 1265 } | 1301 } |
| 1266 | 1302 |
| 1267 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { | 1303 TEST(SchedulerTest, BeginRetroFrame_SwapThrottled) { |
| 1268 FakeSchedulerClient client; | 1304 FakeSchedulerClient client; |
| 1269 SchedulerSettings scheduler_settings; | 1305 SchedulerSettings scheduler_settings; |
| 1270 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1306 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1271 scheduler->SetCanStart(); | 1307 scheduler->SetCanStart(); |
| 1272 scheduler->SetVisible(true); | 1308 scheduler->SetVisible(true); |
| 1273 scheduler->SetCanDraw(true); | 1309 scheduler->SetCanDraw(true); |
| 1274 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1310 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1275 | 1311 |
| 1276 // To test swap ack throttling, this test disables automatic swap acks. | 1312 // To test swap ack throttling, this test disables automatic swap acks. |
| 1277 scheduler->SetMaxSwapsPending(1); | 1313 scheduler->SetMaxSwapsPending(1); |
| 1278 client.SetAutomaticSwapAck(false); | 1314 client.SetAutomaticSwapAck(false); |
| 1279 | 1315 |
| 1280 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1316 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1281 client.Reset(); | 1317 client.Reset(); |
| 1282 scheduler->SetNeedsCommit(); | 1318 scheduler->SetNeedsCommit(); |
| 1283 EXPECT_TRUE(client.needs_begin_frame()); | 1319 EXPECT_TRUE(client.generate_frames()); |
| 1284 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1320 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 1285 client.Reset(); | 1321 client.Reset(); |
| 1286 | 1322 |
| 1287 // Create a BeginFrame with a long deadline to avoid race conditions. | 1323 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1288 // This is the first BeginFrame, which will be handled immediately. | 1324 // This is the first BeginFrame, which will be handled immediately. |
| 1289 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1325 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); |
| 1290 args.deadline += base::TimeDelta::FromHours(1); | 1326 args.deadline += base::TimeDelta::FromHours(1); |
| 1291 scheduler->BeginFrame(args); | 1327 client.frame_source().TestBeginFrame(args); |
| 1292 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1328 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1293 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1329 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1294 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1330 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1295 EXPECT_TRUE(client.needs_begin_frame()); | 1331 EXPECT_TRUE(client.generate_frames()); |
| 1296 client.Reset(); | 1332 client.Reset(); |
| 1297 | 1333 |
| 1298 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1334 // Queue BeginFrame while we are still handling the previous BeginFrame. |
| 1299 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1335 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1300 args.frame_time += base::TimeDelta::FromSeconds(1); | 1336 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1301 scheduler->BeginFrame(args); | 1337 client.frame_source().TestBeginFrame(args); |
| 1302 EXPECT_NO_ACTION(client); | 1338 EXPECT_NO_ACTION(client); |
| 1303 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1339 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1304 client.Reset(); | 1340 client.Reset(); |
| 1305 | 1341 |
| 1306 // NotifyReadyToCommit should trigger the pending commit and draw. | 1342 // NotifyReadyToCommit should trigger the pending commit and draw. |
| 1307 scheduler->NotifyBeginMainFrameStarted(); | 1343 scheduler->NotifyBeginMainFrameStarted(); |
| 1308 scheduler->NotifyReadyToCommit(); | 1344 scheduler->NotifyReadyToCommit(); |
| 1309 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1345 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1310 EXPECT_TRUE(client.needs_begin_frame()); | 1346 EXPECT_TRUE(client.generate_frames()); |
| 1311 client.Reset(); | 1347 client.Reset(); |
| 1312 | 1348 |
| 1313 // Swapping will put us into a swap throttled state. | 1349 // Swapping will put us into a swap throttled state. |
| 1314 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1350 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1315 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1351 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 1316 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1352 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 1317 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1353 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1318 EXPECT_TRUE(client.needs_begin_frame()); | 1354 EXPECT_TRUE(client.generate_frames()); |
| 1319 client.Reset(); | 1355 client.Reset(); |
| 1320 | 1356 |
| 1321 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames | 1357 // While swap throttled, BeginRetroFrames should trigger BeginImplFrames |
| 1322 // but not a BeginMainFrame or draw. | 1358 // but not a BeginMainFrame or draw. |
| 1323 scheduler->SetNeedsCommit(); | 1359 scheduler->SetNeedsCommit(); |
| 1324 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1360 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1325 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 1361 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
| 1326 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1362 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1327 EXPECT_TRUE(client.needs_begin_frame()); | 1363 EXPECT_TRUE(client.generate_frames()); |
| 1328 client.Reset(); | 1364 client.Reset(); |
| 1329 | 1365 |
| 1330 // Queue BeginFrame while we are still handling the previous BeginFrame. | 1366 // Queue BeginFrame while we are still handling the previous BeginFrame. |
| 1331 args.frame_time += base::TimeDelta::FromSeconds(1); | 1367 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1332 scheduler->BeginFrame(args); | 1368 client.frame_source().TestBeginFrame(args); |
| 1333 EXPECT_NO_ACTION(client); | 1369 EXPECT_NO_ACTION(client); |
| 1334 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1370 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1335 EXPECT_TRUE(client.needs_begin_frame()); | 1371 EXPECT_TRUE(client.generate_frames()); |
| 1336 client.Reset(); | 1372 client.Reset(); |
| 1337 | 1373 |
| 1338 // Take us out of a swap throttled state. | 1374 // Take us out of a swap throttled state. |
| 1339 scheduler->DidSwapBuffersComplete(); | 1375 scheduler->DidSwapBuffersComplete(); |
| 1340 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); | 1376 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
| 1341 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1377 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1342 EXPECT_TRUE(client.needs_begin_frame()); | 1378 EXPECT_TRUE(client.generate_frames()); |
| 1343 client.Reset(); | 1379 client.Reset(); |
| 1344 | 1380 |
| 1345 // BeginImplFrame deadline should draw. | 1381 // BeginImplFrame deadline should draw. |
| 1346 scheduler->SetNeedsRedraw(); | 1382 scheduler->SetNeedsRedraw(); |
| 1347 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1383 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1348 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1384 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 1349 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1385 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 1350 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1386 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1351 EXPECT_TRUE(client.needs_begin_frame()); | 1387 EXPECT_TRUE(client.generate_frames()); |
| 1352 client.Reset(); | 1388 client.Reset(); |
| 1353 } | 1389 } |
| 1354 | 1390 |
| 1355 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, | 1391 void BeginFramesNotFromClient(bool begin_frame_scheduling_enabled, |
| 1356 bool throttle_frame_production) { | 1392 bool throttle_frame_production) { |
| 1357 FakeSchedulerClient client; | 1393 FakeSchedulerClient client; |
| 1358 SchedulerSettings scheduler_settings; | 1394 SchedulerSettings scheduler_settings; |
| 1359 scheduler_settings.begin_frame_scheduling_enabled = | 1395 scheduler_settings.begin_frame_scheduling_enabled = |
| 1360 begin_frame_scheduling_enabled; | 1396 begin_frame_scheduling_enabled; |
| 1361 scheduler_settings.throttle_frame_production = throttle_frame_production; | 1397 scheduler_settings.throttle_frame_production = throttle_frame_production; |
| 1362 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1398 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1363 scheduler->SetCanStart(); | 1399 scheduler->SetCanStart(); |
| 1364 scheduler->SetVisible(true); | 1400 scheduler->SetVisible(true); |
| 1365 scheduler->SetCanDraw(true); | 1401 scheduler->SetCanDraw(true); |
| 1366 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1402 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1367 | 1403 |
| 1368 // SetNeedsCommit should begin the frame on the next BeginImplFrame | 1404 // SetNeedsCommit should begin the frame on the next BeginImplFrame |
| 1369 // without calling SetNeedsBeginFrame. | 1405 // without calling SetGenerateFrames. |
| 1370 client.Reset(); | 1406 client.Reset(); |
| 1371 scheduler->SetNeedsCommit(); | 1407 scheduler->SetNeedsCommit(); |
| 1372 EXPECT_FALSE(client.needs_begin_frame()); | 1408 EXPECT_FALSE(client.generate_frames()); |
| 1373 EXPECT_NO_ACTION(client); | 1409 EXPECT_NO_ACTION(client); |
| 1374 client.Reset(); | 1410 client.Reset(); |
| 1375 | 1411 |
| 1376 // When the client-driven BeginFrame are disabled, the scheduler posts it's | 1412 // When the client-driven BeginFrame are disabled, the scheduler posts it's |
| 1377 // own BeginFrame tasks. | 1413 // own BeginFrame tasks. |
| 1378 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1414 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1379 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1415 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1380 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1416 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1381 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1417 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1382 EXPECT_FALSE(client.needs_begin_frame()); | 1418 EXPECT_FALSE(client.generate_frames()); |
| 1383 client.Reset(); | 1419 client.Reset(); |
| 1384 | 1420 |
| 1385 // If we don't swap on the deadline, we wait for the next BeginFrame. | 1421 // If we don't swap on the deadline, we wait for the next BeginFrame. |
| 1386 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1422 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1387 EXPECT_NO_ACTION(client); | 1423 EXPECT_NO_ACTION(client); |
| 1388 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1424 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1389 EXPECT_FALSE(client.needs_begin_frame()); | 1425 EXPECT_FALSE(client.generate_frames()); |
| 1390 client.Reset(); | 1426 client.Reset(); |
| 1391 | 1427 |
| 1392 // NotifyReadyToCommit should trigger the commit. | 1428 // NotifyReadyToCommit should trigger the commit. |
| 1393 scheduler->NotifyBeginMainFrameStarted(); | 1429 scheduler->NotifyBeginMainFrameStarted(); |
| 1394 scheduler->NotifyReadyToCommit(); | 1430 scheduler->NotifyReadyToCommit(); |
| 1395 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1431 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1396 EXPECT_FALSE(client.needs_begin_frame()); | 1432 EXPECT_FALSE(client.generate_frames()); |
| 1397 client.Reset(); | 1433 client.Reset(); |
| 1398 | 1434 |
| 1399 // BeginImplFrame should prepare the draw. | 1435 // BeginImplFrame should prepare the draw. |
| 1400 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1436 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1401 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1437 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1402 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1438 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1403 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1439 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1404 EXPECT_FALSE(client.needs_begin_frame()); | 1440 EXPECT_FALSE(client.generate_frames()); |
| 1405 client.Reset(); | 1441 client.Reset(); |
| 1406 | 1442 |
| 1407 // BeginImplFrame deadline should draw. | 1443 // BeginImplFrame deadline should draw. |
| 1408 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1444 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1409 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); | 1445 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 1); |
| 1410 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1446 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1411 EXPECT_FALSE(client.needs_begin_frame()); | 1447 EXPECT_FALSE(client.generate_frames()); |
| 1412 client.Reset(); | 1448 client.Reset(); |
| 1413 | 1449 |
| 1414 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) | 1450 // The following BeginImplFrame deadline should SetGenerateFrames(false) |
| 1415 // to avoid excessive toggles. | 1451 // to avoid excessive toggles. |
| 1416 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1452 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1417 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); | 1453 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1418 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1454 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1419 client.Reset(); | 1455 client.Reset(); |
| 1420 | 1456 |
| 1421 // Make sure SetNeedsBeginFrame isn't called on the client | 1457 // Make sure SetGenerateFrames isn't called on the client |
| 1422 // when the BeginFrame is no longer needed. | 1458 // when the BeginFrame is no longer needed. |
| 1423 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1459 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1424 EXPECT_NO_ACTION(client); | 1460 EXPECT_NO_ACTION(client); |
| 1425 EXPECT_FALSE(client.needs_begin_frame()); | 1461 EXPECT_FALSE(client.generate_frames()); |
| 1426 client.Reset(); | 1462 client.Reset(); |
| 1427 } | 1463 } |
| 1428 | 1464 |
| 1429 TEST(SchedulerTest, SyntheticBeginFrames) { | 1465 TEST(SchedulerTest, SyntheticBeginFrames) { |
| 1430 bool begin_frame_scheduling_enabled = false; | 1466 bool begin_frame_scheduling_enabled = false; |
| 1431 bool throttle_frame_production = true; | 1467 bool throttle_frame_production = true; |
| 1432 BeginFramesNotFromClient(begin_frame_scheduling_enabled, | 1468 BeginFramesNotFromClient(begin_frame_scheduling_enabled, |
| 1433 throttle_frame_production); | 1469 throttle_frame_production); |
| 1434 } | 1470 } |
| 1435 | 1471 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1460 scheduler->SetCanDraw(true); | 1496 scheduler->SetCanDraw(true); |
| 1461 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1497 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1462 | 1498 |
| 1463 // To test swap ack throttling, this test disables automatic swap acks. | 1499 // To test swap ack throttling, this test disables automatic swap acks. |
| 1464 scheduler->SetMaxSwapsPending(1); | 1500 scheduler->SetMaxSwapsPending(1); |
| 1465 client.SetAutomaticSwapAck(false); | 1501 client.SetAutomaticSwapAck(false); |
| 1466 | 1502 |
| 1467 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1503 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1468 client.Reset(); | 1504 client.Reset(); |
| 1469 scheduler->SetNeedsCommit(); | 1505 scheduler->SetNeedsCommit(); |
| 1470 EXPECT_FALSE(client.needs_begin_frame()); | 1506 EXPECT_FALSE(client.generate_frames()); |
| 1471 EXPECT_NO_ACTION(client); | 1507 EXPECT_NO_ACTION(client); |
| 1472 client.Reset(); | 1508 client.Reset(); |
| 1473 | 1509 |
| 1474 // Trigger the first BeginImplFrame and BeginMainFrame | 1510 // Trigger the first BeginImplFrame and BeginMainFrame |
| 1475 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1511 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1476 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1512 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1477 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1513 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1478 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1514 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1479 EXPECT_FALSE(client.needs_begin_frame()); | 1515 EXPECT_FALSE(client.generate_frames()); |
| 1480 client.Reset(); | 1516 client.Reset(); |
| 1481 | 1517 |
| 1482 // NotifyReadyToCommit should trigger the pending commit and draw. | 1518 // NotifyReadyToCommit should trigger the pending commit and draw. |
| 1483 scheduler->NotifyBeginMainFrameStarted(); | 1519 scheduler->NotifyBeginMainFrameStarted(); |
| 1484 scheduler->NotifyReadyToCommit(); | 1520 scheduler->NotifyReadyToCommit(); |
| 1485 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1521 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1486 EXPECT_FALSE(client.needs_begin_frame()); | 1522 EXPECT_FALSE(client.generate_frames()); |
| 1487 client.Reset(); | 1523 client.Reset(); |
| 1488 | 1524 |
| 1489 // Swapping will put us into a swap throttled state. | 1525 // Swapping will put us into a swap throttled state. |
| 1490 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1526 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1491 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1527 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 1492 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1528 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 1493 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1529 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1494 EXPECT_FALSE(client.needs_begin_frame()); | 1530 EXPECT_FALSE(client.generate_frames()); |
| 1495 client.Reset(); | 1531 client.Reset(); |
| 1496 | 1532 |
| 1497 // While swap throttled, BeginFrames should trigger BeginImplFrames, | 1533 // While swap throttled, BeginFrames should trigger BeginImplFrames, |
| 1498 // but not a BeginMainFrame or draw. | 1534 // but not a BeginMainFrame or draw. |
| 1499 scheduler->SetNeedsCommit(); | 1535 scheduler->SetNeedsCommit(); |
| 1500 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. | 1536 client.task_runner().RunPendingTasks(); // Run posted BeginFrame. |
| 1501 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); | 1537 EXPECT_ACTION("WillBeginImplFrame", client, 0, 1); |
| 1502 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1538 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1503 EXPECT_FALSE(client.needs_begin_frame()); | 1539 EXPECT_FALSE(client.generate_frames()); |
| 1504 client.Reset(); | 1540 client.Reset(); |
| 1505 | 1541 |
| 1506 // Take us out of a swap throttled state. | 1542 // Take us out of a swap throttled state. |
| 1507 scheduler->DidSwapBuffersComplete(); | 1543 scheduler->DidSwapBuffersComplete(); |
| 1508 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); | 1544 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 0, 1); |
| 1509 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1545 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1510 EXPECT_FALSE(client.needs_begin_frame()); | 1546 EXPECT_FALSE(client.generate_frames()); |
| 1511 client.Reset(); | 1547 client.Reset(); |
| 1512 | 1548 |
| 1513 // BeginImplFrame deadline should draw. | 1549 // BeginImplFrame deadline should draw. |
| 1514 scheduler->SetNeedsRedraw(); | 1550 scheduler->SetNeedsRedraw(); |
| 1515 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1551 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1516 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); | 1552 EXPECT_ACTION("ScheduledActionAnimate", client, 0, 2); |
| 1517 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); | 1553 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 1, 2); |
| 1518 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1554 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1519 EXPECT_FALSE(client.needs_begin_frame()); | 1555 EXPECT_FALSE(client.generate_frames()); |
| 1520 client.Reset(); | 1556 client.Reset(); |
| 1521 } | 1557 } |
| 1522 | 1558 |
| 1523 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { | 1559 TEST(SchedulerTest, SyntheticBeginFrames_SwapThrottled) { |
| 1524 bool begin_frame_scheduling_enabled = false; | 1560 bool begin_frame_scheduling_enabled = false; |
| 1525 bool throttle_frame_production = true; | 1561 bool throttle_frame_production = true; |
| 1526 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, | 1562 BeginFramesNotFromClient_SwapThrottled(begin_frame_scheduling_enabled, |
| 1527 throttle_frame_production); | 1563 throttle_frame_production); |
| 1528 } | 1564 } |
| 1529 | 1565 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1565 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1601 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1566 scheduler->SetCanStart(); | 1602 scheduler->SetCanStart(); |
| 1567 scheduler->SetVisible(true); | 1603 scheduler->SetVisible(true); |
| 1568 scheduler->SetCanDraw(true); | 1604 scheduler->SetCanDraw(true); |
| 1569 | 1605 |
| 1570 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1606 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1571 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1607 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1572 // SetNeedsCommit should begin the frame. | 1608 // SetNeedsCommit should begin the frame. |
| 1573 client.Reset(); | 1609 client.Reset(); |
| 1574 scheduler->SetNeedsCommit(); | 1610 scheduler->SetNeedsCommit(); |
| 1575 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1611 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 1576 | 1612 |
| 1577 client.Reset(); | 1613 client.Reset(); |
| 1578 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1614 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); |
| 1579 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1615 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1580 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1616 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1581 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1617 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1582 | 1618 |
| 1583 client.Reset(); | 1619 client.Reset(); |
| 1584 scheduler->DidLoseOutputSurface(); | 1620 scheduler->DidLoseOutputSurface(); |
| 1585 // Do nothing when impl frame is in deadine pending state. | 1621 // Do nothing when impl frame is in deadine pending state. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1604 scheduler->SetCanStart(); | 1640 scheduler->SetCanStart(); |
| 1605 scheduler->SetVisible(true); | 1641 scheduler->SetVisible(true); |
| 1606 scheduler->SetCanDraw(true); | 1642 scheduler->SetCanDraw(true); |
| 1607 | 1643 |
| 1608 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1644 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1609 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1645 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1610 | 1646 |
| 1611 // SetNeedsCommit should begin the frame. | 1647 // SetNeedsCommit should begin the frame. |
| 1612 client.Reset(); | 1648 client.Reset(); |
| 1613 scheduler->SetNeedsCommit(); | 1649 scheduler->SetNeedsCommit(); |
| 1614 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1650 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 1615 | 1651 |
| 1616 client.Reset(); | 1652 client.Reset(); |
| 1617 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1653 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); |
| 1618 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1654 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1619 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1655 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1620 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1656 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1621 | 1657 |
| 1622 client.Reset(); | 1658 client.Reset(); |
| 1623 scheduler->DidLoseOutputSurface(); | 1659 scheduler->DidLoseOutputSurface(); |
| 1624 // Do nothing when impl frame is in deadine pending state. | 1660 // Do nothing when impl frame is in deadine pending state. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 scheduler->SetCanStart(); | 1703 scheduler->SetCanStart(); |
| 1668 scheduler->SetVisible(true); | 1704 scheduler->SetVisible(true); |
| 1669 scheduler->SetCanDraw(true); | 1705 scheduler->SetCanDraw(true); |
| 1670 | 1706 |
| 1671 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1707 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1672 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1708 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1673 | 1709 |
| 1674 // SetNeedsCommit should begin the frame. | 1710 // SetNeedsCommit should begin the frame. |
| 1675 client.Reset(); | 1711 client.Reset(); |
| 1676 scheduler->SetNeedsCommit(); | 1712 scheduler->SetNeedsCommit(); |
| 1677 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1713 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 1678 | 1714 |
| 1679 client.Reset(); | 1715 client.Reset(); |
| 1680 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1716 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); |
| 1681 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1717 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1682 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1718 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1683 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1719 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1684 | 1720 |
| 1685 client.Reset(); | 1721 client.Reset(); |
| 1686 scheduler->NotifyBeginMainFrameStarted(); | 1722 scheduler->NotifyBeginMainFrameStarted(); |
| 1687 scheduler->NotifyReadyToCommit(); | 1723 scheduler->NotifyReadyToCommit(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1715 SchedulerSettings scheduler_settings; | 1751 SchedulerSettings scheduler_settings; |
| 1716 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1752 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1717 scheduler->SetCanStart(); | 1753 scheduler->SetCanStart(); |
| 1718 scheduler->SetVisible(true); | 1754 scheduler->SetVisible(true); |
| 1719 scheduler->SetCanDraw(true); | 1755 scheduler->SetCanDraw(true); |
| 1720 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1756 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1721 | 1757 |
| 1722 client.Reset(); | 1758 client.Reset(); |
| 1723 scheduler->SetNeedsManageTiles(); | 1759 scheduler->SetNeedsManageTiles(); |
| 1724 scheduler->SetNeedsRedraw(); | 1760 scheduler->SetNeedsRedraw(); |
| 1725 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1761 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 1726 EXPECT_TRUE(client.needs_begin_frame()); | 1762 EXPECT_TRUE(client.generate_frames()); |
| 1727 | 1763 |
| 1728 client.Reset(); | 1764 client.Reset(); |
| 1729 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); | 1765 scheduler->BeginFrame(CreateBeginFrameArgsForTesting()); |
| 1730 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1766 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1731 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1767 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1732 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1768 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1733 | 1769 |
| 1734 client.Reset(); | 1770 client.Reset(); |
| 1735 scheduler->DidLoseOutputSurface(); | 1771 scheduler->DidLoseOutputSurface(); |
| 1736 EXPECT_NO_ACTION(client); | 1772 EXPECT_NO_ACTION(client); |
| 1737 | 1773 |
| 1738 client.Reset(); | 1774 client.Reset(); |
| 1739 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1775 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1740 EXPECT_ACTION("ScheduledActionManageTiles", client, 0, 2); | 1776 EXPECT_ACTION("ScheduledActionManageTiles", client, 0, 2); |
| 1741 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); | 1777 EXPECT_ACTION("ScheduledActionBeginOutputSurfaceCreation", client, 1, 2); |
| 1742 } | 1778 } |
| 1743 | 1779 |
| 1744 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { | 1780 TEST(SchedulerTest, DidLoseOutputSurfaceAfterBeginRetroFramePosted) { |
| 1745 FakeSchedulerClient client; | 1781 FakeSchedulerClient client; |
| 1746 SchedulerSettings scheduler_settings; | 1782 SchedulerSettings scheduler_settings; |
| 1747 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1783 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1748 scheduler->SetCanStart(); | 1784 scheduler->SetCanStart(); |
| 1749 scheduler->SetVisible(true); | 1785 scheduler->SetVisible(true); |
| 1750 scheduler->SetCanDraw(true); | 1786 scheduler->SetCanDraw(true); |
| 1751 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1787 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1752 | 1788 |
| 1753 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1789 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1754 client.Reset(); | 1790 client.Reset(); |
| 1755 scheduler->SetNeedsCommit(); | 1791 scheduler->SetNeedsCommit(); |
| 1756 EXPECT_TRUE(client.needs_begin_frame()); | 1792 EXPECT_TRUE(client.generate_frames()); |
| 1757 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1793 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 1758 | 1794 |
| 1759 // Create a BeginFrame with a long deadline to avoid race conditions. | 1795 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1760 // This is the first BeginFrame, which will be handled immediately. | 1796 // This is the first BeginFrame, which will be handled immediately. |
| 1761 client.Reset(); | 1797 client.Reset(); |
| 1762 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1798 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); |
| 1763 args.deadline += base::TimeDelta::FromHours(1); | 1799 args.deadline += base::TimeDelta::FromHours(1); |
| 1764 scheduler->BeginFrame(args); | 1800 scheduler->BeginFrame(args); |
| 1765 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1801 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1766 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1802 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1767 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1803 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1768 EXPECT_TRUE(client.needs_begin_frame()); | 1804 EXPECT_TRUE(client.generate_frames()); |
| 1769 | 1805 |
| 1770 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1806 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1771 args.frame_time += base::TimeDelta::FromSeconds(1); | 1807 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1772 scheduler->BeginFrame(args); | 1808 scheduler->BeginFrame(args); |
| 1773 args.frame_time += base::TimeDelta::FromSeconds(1); | 1809 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1774 scheduler->BeginFrame(args); | 1810 scheduler->BeginFrame(args); |
| 1775 | 1811 |
| 1776 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1812 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 1777 client.Reset(); | 1813 client.Reset(); |
| 1778 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1814 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1779 EXPECT_NO_ACTION(client); | 1815 EXPECT_NO_ACTION(client); |
| 1780 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1816 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1781 EXPECT_TRUE(client.needs_begin_frame()); | 1817 EXPECT_TRUE(client.generate_frames()); |
| 1782 | 1818 |
| 1783 // NotifyReadyToCommit should trigger the commit. | 1819 // NotifyReadyToCommit should trigger the commit. |
| 1784 client.Reset(); | 1820 client.Reset(); |
| 1785 scheduler->NotifyBeginMainFrameStarted(); | 1821 scheduler->NotifyBeginMainFrameStarted(); |
| 1786 scheduler->NotifyReadyToCommit(); | 1822 scheduler->NotifyReadyToCommit(); |
| 1787 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1823 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1788 EXPECT_TRUE(client.needs_begin_frame()); | 1824 EXPECT_TRUE(client.generate_frames()); |
| 1789 | 1825 |
| 1790 client.Reset(); | 1826 client.Reset(); |
| 1791 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1827 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); |
| 1792 scheduler->DidLoseOutputSurface(); | 1828 scheduler->DidLoseOutputSurface(); |
| 1793 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1829 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1794 EXPECT_TRUE(client.needs_begin_frame()); | 1830 EXPECT_TRUE(client.generate_frames()); |
| 1795 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1831 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); |
| 1796 | 1832 |
| 1797 // Posted BeginRetroFrame is aborted. | 1833 // Posted BeginRetroFrame is aborted. |
| 1798 client.Reset(); | 1834 client.Reset(); |
| 1799 client.task_runner().RunPendingTasks(); | 1835 client.task_runner().RunPendingTasks(); |
| 1800 EXPECT_NO_ACTION(client); | 1836 EXPECT_NO_ACTION(client); |
| 1801 } | 1837 } |
| 1802 | 1838 |
| 1803 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { | 1839 TEST(SchedulerTest, DidLoseOutputSurfaceDuringBeginRetroFrameRunning) { |
| 1804 FakeSchedulerClient client; | 1840 FakeSchedulerClient client; |
| 1805 SchedulerSettings scheduler_settings; | 1841 SchedulerSettings scheduler_settings; |
| 1806 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1842 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1807 scheduler->SetCanStart(); | 1843 scheduler->SetCanStart(); |
| 1808 scheduler->SetVisible(true); | 1844 scheduler->SetVisible(true); |
| 1809 scheduler->SetCanDraw(true); | 1845 scheduler->SetCanDraw(true); |
| 1810 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1846 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1811 | 1847 |
| 1812 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1848 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1813 client.Reset(); | 1849 client.Reset(); |
| 1814 scheduler->SetNeedsCommit(); | 1850 scheduler->SetNeedsCommit(); |
| 1815 EXPECT_TRUE(client.needs_begin_frame()); | 1851 EXPECT_TRUE(client.generate_frames()); |
| 1816 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); | 1852 EXPECT_SINGLE_ACTION("SetGenerateFrames", client); |
| 1817 | 1853 |
| 1818 // Create a BeginFrame with a long deadline to avoid race conditions. | 1854 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1819 // This is the first BeginFrame, which will be handled immediately. | 1855 // This is the first BeginFrame, which will be handled immediately. |
| 1820 client.Reset(); | 1856 client.Reset(); |
| 1821 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); | 1857 BeginFrameArgs args = CreateBeginFrameArgsForTesting(); |
| 1822 args.deadline += base::TimeDelta::FromHours(1); | 1858 args.deadline += base::TimeDelta::FromHours(1); |
| 1823 scheduler->BeginFrame(args); | 1859 scheduler->BeginFrame(args); |
| 1824 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1860 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1825 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1861 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1826 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1862 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1827 EXPECT_TRUE(client.needs_begin_frame()); | 1863 EXPECT_TRUE(client.generate_frames()); |
| 1828 | 1864 |
| 1829 // Queue BeginFrames while we are still handling the previous BeginFrame. | 1865 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1830 args.frame_time += base::TimeDelta::FromSeconds(1); | 1866 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1831 scheduler->BeginFrame(args); | 1867 scheduler->BeginFrame(args); |
| 1832 args.frame_time += base::TimeDelta::FromSeconds(1); | 1868 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1833 scheduler->BeginFrame(args); | 1869 scheduler->BeginFrame(args); |
| 1834 | 1870 |
| 1835 // If we don't swap on the deadline, we wait for the next BeginImplFrame. | 1871 // If we don't swap on the deadline, we wait for the next BeginImplFrame. |
| 1836 client.Reset(); | 1872 client.Reset(); |
| 1837 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1873 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1838 EXPECT_NO_ACTION(client); | 1874 EXPECT_NO_ACTION(client); |
| 1839 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1875 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1840 EXPECT_TRUE(client.needs_begin_frame()); | 1876 EXPECT_TRUE(client.generate_frames()); |
| 1841 | 1877 |
| 1842 // NotifyReadyToCommit should trigger the commit. | 1878 // NotifyReadyToCommit should trigger the commit. |
| 1843 client.Reset(); | 1879 client.Reset(); |
| 1844 scheduler->NotifyBeginMainFrameStarted(); | 1880 scheduler->NotifyBeginMainFrameStarted(); |
| 1845 scheduler->NotifyReadyToCommit(); | 1881 scheduler->NotifyReadyToCommit(); |
| 1846 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1882 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1847 EXPECT_TRUE(client.needs_begin_frame()); | 1883 EXPECT_TRUE(client.generate_frames()); |
| 1848 | 1884 |
| 1849 // BeginImplFrame should prepare the draw. | 1885 // BeginImplFrame should prepare the draw. |
| 1850 client.Reset(); | 1886 client.Reset(); |
| 1851 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. | 1887 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1852 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1888 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1853 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); | 1889 EXPECT_ACTION("ScheduledActionAnimate", client, 1, 2); |
| 1854 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1890 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1855 EXPECT_TRUE(client.needs_begin_frame()); | 1891 EXPECT_TRUE(client.generate_frames()); |
| 1856 | 1892 |
| 1857 client.Reset(); | 1893 client.Reset(); |
| 1858 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1894 EXPECT_FALSE(scheduler->IsBeginRetroFrameArgsEmpty()); |
| 1859 scheduler->DidLoseOutputSurface(); | 1895 scheduler->DidLoseOutputSurface(); |
| 1860 EXPECT_NO_ACTION(client); | 1896 EXPECT_NO_ACTION(client); |
| 1861 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); | 1897 EXPECT_TRUE(scheduler->IsBeginRetroFrameArgsEmpty()); |
| 1862 | 1898 |
| 1863 // BeginImplFrame deadline should abort drawing. | 1899 // BeginImplFrame deadline should abort drawing. |
| 1864 client.Reset(); | 1900 client.Reset(); |
| 1865 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1901 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1866 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1902 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1867 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1903 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1868 EXPECT_TRUE(client.needs_begin_frame()); | 1904 EXPECT_TRUE(client.generate_frames()); |
| 1869 | 1905 |
| 1870 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. | 1906 // No more BeginRetroFrame because BeginRetroFrame queue is cleared. |
| 1871 client.Reset(); | 1907 client.Reset(); |
| 1872 client.task_runner().RunPendingTasks(); | 1908 client.task_runner().RunPendingTasks(); |
| 1873 EXPECT_NO_ACTION(client); | 1909 EXPECT_NO_ACTION(client); |
| 1874 } | 1910 } |
| 1875 | 1911 |
| 1876 TEST(SchedulerTest, | 1912 TEST(SchedulerTest, |
| 1877 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { | 1913 StopBeginFrameAfterDidLoseOutputSurfaceWithSyntheticBeginFrameSource) { |
| 1878 FakeSchedulerClient client; | 1914 FakeSchedulerClient client; |
| 1879 SchedulerSettings scheduler_settings; | 1915 SchedulerSettings scheduler_settings; |
| 1880 scheduler_settings.begin_frame_scheduling_enabled = false; | 1916 scheduler_settings.begin_frame_scheduling_enabled = false; |
| 1881 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); | 1917 TestScheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1882 scheduler->SetCanStart(); | 1918 scheduler->SetCanStart(); |
| 1883 scheduler->SetVisible(true); | 1919 scheduler->SetVisible(true); |
| 1884 scheduler->SetCanDraw(true); | 1920 scheduler->SetCanDraw(true); |
| 1885 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 1921 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1886 | 1922 |
| 1887 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 1923 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1888 client.Reset(); | 1924 client.Reset(); |
| 1889 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1925 EXPECT_FALSE(scheduler->IsFrameSourceGeneratingFrames()); |
| 1890 scheduler->SetNeedsCommit(); | 1926 scheduler->SetNeedsCommit(); |
| 1891 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1927 EXPECT_TRUE(scheduler->IsFrameSourceGeneratingFrames()); |
| 1892 | 1928 |
| 1893 client.Reset(); | 1929 client.Reset(); |
| 1894 client.task_runner().RunPendingTasks(); // Run posted Tick. | 1930 client.task_runner().RunPendingTasks(); // Run posted Tick. |
| 1895 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); | 1931 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1896 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); | 1932 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1897 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1933 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1898 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1934 EXPECT_TRUE(scheduler->IsFrameSourceGeneratingFrames()); |
| 1899 | 1935 |
| 1900 // NotifyReadyToCommit should trigger the commit. | 1936 // NotifyReadyToCommit should trigger the commit. |
| 1901 client.Reset(); | 1937 client.Reset(); |
| 1902 scheduler->NotifyBeginMainFrameStarted(); | 1938 scheduler->NotifyBeginMainFrameStarted(); |
| 1903 scheduler->NotifyReadyToCommit(); | 1939 scheduler->NotifyReadyToCommit(); |
| 1904 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 1940 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1905 EXPECT_TRUE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1941 EXPECT_TRUE(scheduler->IsFrameSourceGeneratingFrames()); |
| 1906 | 1942 |
| 1907 client.Reset(); | 1943 client.Reset(); |
| 1908 scheduler->DidLoseOutputSurface(); | 1944 scheduler->DidLoseOutputSurface(); |
| 1909 EXPECT_EQ(0, client.num_actions_()); | 1945 EXPECT_EQ(0, client.num_actions_()); |
| 1910 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1946 EXPECT_FALSE(scheduler->IsFrameSourceGeneratingFrames()); |
| 1911 | 1947 |
| 1912 client.Reset(); | 1948 client.Reset(); |
| 1913 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1949 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1914 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 1950 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 1915 EXPECT_FALSE(scheduler->IsSyntheticBeginFrameSourceActive()); | 1951 EXPECT_FALSE(scheduler->IsFrameSourceGeneratingFrames()); |
| 1916 } | 1952 } |
| 1917 | 1953 |
| 1918 } // namespace | 1954 } // namespace |
| 1919 } // namespace cc | 1955 } // namespace cc |
| OLD | NEW |