| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 87 } |
| 88 | 88 |
| 89 void SetDrawWillHappen(bool draw_will_happen) { | 89 void SetDrawWillHappen(bool draw_will_happen) { |
| 90 draw_will_happen_ = draw_will_happen; | 90 draw_will_happen_ = draw_will_happen; |
| 91 } | 91 } |
| 92 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 92 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
| 93 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 93 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
| 94 } | 94 } |
| 95 | 95 |
| 96 // SchedulerClient implementation. | 96 // SchedulerClient implementation. |
| 97 virtual void SetNeedsBeginImplFrame(bool enable) OVERRIDE { | 97 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { |
| 98 actions_.push_back("SetNeedsBeginImplFrame"); | 98 actions_.push_back("SetNeedsBeginFrame"); |
| 99 states_.push_back(scheduler_->StateAsValue().release()); | 99 states_.push_back(scheduler_->StateAsValue().release()); |
| 100 needs_begin_impl_frame_ = enable; | 100 needs_begin_impl_frame_ = enable; |
| 101 } | 101 } |
| 102 virtual void WillBeginImplFrame(const BeginFrameArgs& args) OVERRIDE { |
| 103 actions_.push_back("WillBeginImplFrame"); |
| 104 states_.push_back(scheduler_->StateAsValue().release()); |
| 105 } |
| 102 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { | 106 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { |
| 103 actions_.push_back("ScheduledActionSendBeginMainFrame"); | 107 actions_.push_back("ScheduledActionSendBeginMainFrame"); |
| 104 states_.push_back(scheduler_->StateAsValue().release()); | 108 states_.push_back(scheduler_->StateAsValue().release()); |
| 105 } | 109 } |
| 106 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 110 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
| 107 OVERRIDE { | 111 OVERRIDE { |
| 108 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | 112 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); |
| 109 states_.push_back(scheduler_->StateAsValue().release()); | 113 states_.push_back(scheduler_->StateAsValue().release()); |
| 110 num_draws_++; | 114 num_draws_++; |
| 111 bool did_readback = false; | 115 bool did_readback = false; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 187 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 184 }; | 188 }; |
| 185 | 189 |
| 186 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, | 190 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler, |
| 187 FakeSchedulerClient* client) { | 191 FakeSchedulerClient* client) { |
| 188 scheduler->DidCreateAndInitializeOutputSurface(); | 192 scheduler->DidCreateAndInitializeOutputSurface(); |
| 189 scheduler->SetNeedsCommit(); | 193 scheduler->SetNeedsCommit(); |
| 190 scheduler->NotifyBeginMainFrameStarted(); | 194 scheduler->NotifyBeginMainFrameStarted(); |
| 191 scheduler->NotifyReadyToCommit(); | 195 scheduler->NotifyReadyToCommit(); |
| 192 // Go through the motions to draw the commit. | 196 // Go through the motions to draw the commit. |
| 193 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 197 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 194 | 198 |
| 195 // Run the posted deadline task. | 199 // Run the posted deadline task. |
| 196 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 200 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 197 client->task_runner().RunPendingTasks(); | 201 client->task_runner().RunPendingTasks(); |
| 198 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 202 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 199 | 203 |
| 200 // We need another BeginImplFrame so Scheduler calls | 204 // We need another BeginImplFrame so Scheduler calls |
| 201 // SetNeedsBeginImplFrame(false). | 205 // SetNeedsBeginFrame(false). |
| 202 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 206 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 203 | 207 |
| 204 // Run the posted deadline task. | 208 // Run the posted deadline task. |
| 205 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 209 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 206 client->task_runner().RunPendingTasks(); | 210 client->task_runner().RunPendingTasks(); |
| 207 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 211 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 208 } | 212 } |
| 209 | 213 |
| 210 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { | 214 TEST(SchedulerTest, InitializeOutputSurfaceDoesNotBeginImplFrame) { |
| 211 FakeSchedulerClient client; | 215 FakeSchedulerClient client; |
| 212 SchedulerSettings default_scheduler_settings; | 216 SchedulerSettings default_scheduler_settings; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 229 scheduler->SetVisible(true); | 233 scheduler->SetVisible(true); |
| 230 scheduler->SetCanDraw(true); | 234 scheduler->SetCanDraw(true); |
| 231 | 235 |
| 232 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 236 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 233 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 237 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 234 | 238 |
| 235 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 239 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 236 client.Reset(); | 240 client.Reset(); |
| 237 scheduler->SetNeedsCommit(); | 241 scheduler->SetNeedsCommit(); |
| 238 EXPECT_TRUE(client.needs_begin_impl_frame()); | 242 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 239 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 243 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 240 client.Reset(); | 244 client.Reset(); |
| 241 | 245 |
| 242 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 246 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 243 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 247 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 248 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 244 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 249 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 245 EXPECT_TRUE(client.needs_begin_impl_frame()); | 250 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 246 client.Reset(); | 251 client.Reset(); |
| 247 | 252 |
| 248 // If we don't swap on the deadline, we need to request another | 253 // If we don't swap on the deadline, we need to request another |
| 249 // BeginImplFrame. | 254 // BeginImplFrame. |
| 250 scheduler->OnBeginImplFrameDeadline(); | 255 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 251 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 256 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 252 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 257 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 253 EXPECT_TRUE(client.needs_begin_impl_frame()); | 258 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 254 client.Reset(); | 259 client.Reset(); |
| 255 | 260 |
| 256 // NotifyReadyToCommit should trigger the commit. | 261 // NotifyReadyToCommit should trigger the commit. |
| 257 scheduler->NotifyBeginMainFrameStarted(); | 262 scheduler->NotifyBeginMainFrameStarted(); |
| 258 scheduler->NotifyReadyToCommit(); | 263 scheduler->NotifyReadyToCommit(); |
| 259 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 264 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 260 EXPECT_TRUE(client.needs_begin_impl_frame()); | 265 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 261 client.Reset(); | 266 client.Reset(); |
| 262 | 267 |
| 263 // BeginImplFrame should prepare the draw. | 268 // BeginImplFrame should prepare the draw. |
| 264 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 269 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 265 EXPECT_EQ(client.num_actions_(), 0); | 270 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 266 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 271 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 267 EXPECT_TRUE(client.needs_begin_impl_frame()); | 272 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 268 client.Reset(); | 273 client.Reset(); |
| 269 | 274 |
| 270 // BeginImplFrame deadline should draw. | 275 // BeginImplFrame deadline should draw. |
| 271 scheduler->OnBeginImplFrameDeadline(); | 276 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 272 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 277 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 273 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 278 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| 274 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 279 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 275 EXPECT_TRUE(client.needs_begin_impl_frame()); | 280 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 276 client.Reset(); | 281 client.Reset(); |
| 277 | 282 |
| 278 // The following BeginImplFrame deadline should SetNeedsBeginImplFrame(false) | 283 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 279 // to avoid excessive toggles. | 284 // to avoid excessive toggles. |
| 280 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 285 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 281 EXPECT_EQ(client.num_actions_(), 0); | 286 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 282 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 287 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 283 client.Reset(); | 288 client.Reset(); |
| 284 | 289 |
| 285 scheduler->OnBeginImplFrameDeadline(); | 290 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 286 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 291 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 287 EXPECT_FALSE(client.needs_begin_impl_frame()); | 292 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 288 client.Reset(); | 293 client.Reset(); |
| 289 } | 294 } |
| 290 | 295 |
| 291 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 296 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| 292 FakeSchedulerClient client; | 297 FakeSchedulerClient client; |
| 293 SchedulerSettings scheduler_settings; | 298 SchedulerSettings scheduler_settings; |
| 294 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | 299 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 295 scheduler->SetCanStart(); | 300 scheduler->SetCanStart(); |
| 296 scheduler->SetVisible(true); | 301 scheduler->SetVisible(true); |
| 297 scheduler->SetCanDraw(true); | 302 scheduler->SetCanDraw(true); |
| 298 | 303 |
| 299 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 304 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 300 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 305 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 301 client.Reset(); | 306 client.Reset(); |
| 302 | 307 |
| 303 // SetNeedsCommit should begin the frame. | 308 // SetNeedsCommit should begin the frame. |
| 304 scheduler->SetNeedsCommit(); | 309 scheduler->SetNeedsCommit(); |
| 305 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 310 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 306 | 311 |
| 307 client.Reset(); | 312 client.Reset(); |
| 308 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 313 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 309 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 314 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 315 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 310 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 316 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 311 | 317 |
| 312 EXPECT_TRUE(client.needs_begin_impl_frame()); | 318 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 313 client.Reset(); | 319 client.Reset(); |
| 314 | 320 |
| 315 // Now SetNeedsCommit again. Calling here means we need a second commit. | 321 // Now SetNeedsCommit again. Calling here means we need a second commit. |
| 316 scheduler->SetNeedsCommit(); | 322 scheduler->SetNeedsCommit(); |
| 317 EXPECT_EQ(client.num_actions_(), 0); | 323 EXPECT_EQ(client.num_actions_(), 0); |
| 318 client.Reset(); | 324 client.Reset(); |
| 319 | 325 |
| 320 // Finish the first commit. | 326 // Finish the first commit. |
| 321 scheduler->NotifyBeginMainFrameStarted(); | 327 scheduler->NotifyBeginMainFrameStarted(); |
| 322 scheduler->NotifyReadyToCommit(); | 328 scheduler->NotifyReadyToCommit(); |
| 323 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 329 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 324 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 330 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 325 client.Reset(); | 331 client.Reset(); |
| 326 scheduler->OnBeginImplFrameDeadline(); | 332 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 327 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 333 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 328 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 334 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| 329 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 335 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 330 | 336 |
| 331 // Because we just swapped, the Scheduler should also request the next | 337 // Because we just swapped, the Scheduler should also request the next |
| 332 // BeginImplFrame from the OutputSurface. | 338 // BeginImplFrame from the OutputSurface. |
| 333 EXPECT_TRUE(client.needs_begin_impl_frame()); | 339 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 334 client.Reset(); | 340 client.Reset(); |
| 335 | |
| 336 // Since another commit is needed, the next BeginImplFrame should initiate | 341 // Since another commit is needed, the next BeginImplFrame should initiate |
| 337 // the second commit. | 342 // the second commit. |
| 338 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 343 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 339 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 344 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 345 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 340 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 346 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 341 client.Reset(); | 347 client.Reset(); |
| 342 | 348 |
| 343 // Finishing the commit before the deadline should post a new deadline task | 349 // Finishing the commit before the deadline should post a new deadline task |
| 344 // to trigger the deadline early. | 350 // to trigger the deadline early. |
| 345 scheduler->NotifyBeginMainFrameStarted(); | 351 scheduler->NotifyBeginMainFrameStarted(); |
| 346 scheduler->NotifyReadyToCommit(); | 352 scheduler->NotifyReadyToCommit(); |
| 347 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 353 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 348 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 354 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 349 client.Reset(); | 355 client.Reset(); |
| 350 scheduler->OnBeginImplFrameDeadline(); | 356 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 351 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 357 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 352 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 358 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| 353 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 359 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 354 EXPECT_TRUE(client.needs_begin_impl_frame()); | 360 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 355 client.Reset(); | 361 client.Reset(); |
| 356 | 362 |
| 357 // On the next BeginImplFrame, verify we go back to a quiescent state and | 363 // On the next BeginImplFrame, verify we go back to a quiescent state and |
| 358 // no longer request BeginImplFrames. | 364 // no longer request BeginImplFrames. |
| 359 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 365 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 360 scheduler->OnBeginImplFrameDeadline(); | 366 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 361 EXPECT_FALSE(client.needs_begin_impl_frame()); | 367 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 362 client.Reset(); | 368 client.Reset(); |
| 363 } | 369 } |
| 364 | 370 |
| 365 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { | 371 class SchedulerClientThatsetNeedsDrawInsideDraw : public FakeSchedulerClient { |
| 366 public: | 372 public: |
| 367 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} | 373 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE {} |
| 368 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 374 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
| 369 OVERRIDE { | 375 OVERRIDE { |
| 370 // Only SetNeedsRedraw the first time this is called | 376 // Only SetNeedsRedraw the first time this is called |
| (...skipping 27 matching lines...) Expand all Loading... |
| 398 scheduler->SetVisible(true); | 404 scheduler->SetVisible(true); |
| 399 scheduler->SetCanDraw(true); | 405 scheduler->SetCanDraw(true); |
| 400 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 406 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 401 client.Reset(); | 407 client.Reset(); |
| 402 | 408 |
| 403 scheduler->SetNeedsRedraw(); | 409 scheduler->SetNeedsRedraw(); |
| 404 EXPECT_TRUE(scheduler->RedrawPending()); | 410 EXPECT_TRUE(scheduler->RedrawPending()); |
| 405 EXPECT_TRUE(client.needs_begin_impl_frame()); | 411 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 406 EXPECT_EQ(0, client.num_draws()); | 412 EXPECT_EQ(0, client.num_draws()); |
| 407 | 413 |
| 408 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 414 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 409 scheduler->OnBeginImplFrameDeadline(); | 415 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 410 EXPECT_EQ(1, client.num_draws()); | 416 EXPECT_EQ(1, client.num_draws()); |
| 411 EXPECT_TRUE(scheduler->RedrawPending()); | 417 EXPECT_TRUE(scheduler->RedrawPending()); |
| 412 EXPECT_TRUE(client.needs_begin_impl_frame()); | 418 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 413 | 419 |
| 414 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 420 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 415 scheduler->OnBeginImplFrameDeadline(); | 421 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 416 EXPECT_EQ(2, client.num_draws()); | 422 EXPECT_EQ(2, client.num_draws()); |
| 417 EXPECT_FALSE(scheduler->RedrawPending()); | 423 EXPECT_FALSE(scheduler->RedrawPending()); |
| 418 EXPECT_TRUE(client.needs_begin_impl_frame()); | 424 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 419 | 425 |
| 420 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 426 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| 421 // swap. | 427 // swap. |
| 422 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 428 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 423 scheduler->OnBeginImplFrameDeadline(); | 429 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 424 EXPECT_EQ(2, client.num_draws()); | 430 EXPECT_EQ(2, client.num_draws()); |
| 425 EXPECT_FALSE(scheduler->RedrawPending()); | 431 EXPECT_FALSE(scheduler->RedrawPending()); |
| 426 EXPECT_FALSE(client.needs_begin_impl_frame()); | 432 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 427 } | 433 } |
| 428 | 434 |
| 429 // Test that requesting redraw inside a failed draw doesn't lose the request. | 435 // Test that requesting redraw inside a failed draw doesn't lose the request. |
| 430 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { | 436 TEST(SchedulerTest, RequestRedrawInsideFailedDraw) { |
| 431 SchedulerClientThatsetNeedsDrawInsideDraw client; | 437 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 432 SchedulerSettings default_scheduler_settings; | 438 SchedulerSettings default_scheduler_settings; |
| 433 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 439 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 434 scheduler->SetCanStart(); | 440 scheduler->SetCanStart(); |
| 435 scheduler->SetVisible(true); | 441 scheduler->SetVisible(true); |
| 436 scheduler->SetCanDraw(true); | 442 scheduler->SetCanDraw(true); |
| 437 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 443 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 438 client.Reset(); | 444 client.Reset(); |
| 439 | 445 |
| 440 client.SetDrawWillHappen(false); | 446 client.SetDrawWillHappen(false); |
| 441 | 447 |
| 442 scheduler->SetNeedsRedraw(); | 448 scheduler->SetNeedsRedraw(); |
| 443 EXPECT_TRUE(scheduler->RedrawPending()); | 449 EXPECT_TRUE(scheduler->RedrawPending()); |
| 444 EXPECT_TRUE(client.needs_begin_impl_frame()); | 450 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 445 EXPECT_EQ(0, client.num_draws()); | 451 EXPECT_EQ(0, client.num_draws()); |
| 446 | 452 |
| 447 // Fail the draw. | 453 // Fail the draw. |
| 448 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 454 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 449 scheduler->OnBeginImplFrameDeadline(); | 455 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 450 EXPECT_EQ(1, client.num_draws()); | 456 EXPECT_EQ(1, client.num_draws()); |
| 451 | 457 |
| 452 // We have a commit pending and the draw failed, and we didn't lose the redraw | 458 // We have a commit pending and the draw failed, and we didn't lose the redraw |
| 453 // request. | 459 // request. |
| 454 EXPECT_TRUE(scheduler->CommitPending()); | 460 EXPECT_TRUE(scheduler->CommitPending()); |
| 455 EXPECT_TRUE(scheduler->RedrawPending()); | 461 EXPECT_TRUE(scheduler->RedrawPending()); |
| 456 EXPECT_TRUE(client.needs_begin_impl_frame()); | 462 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 457 | 463 |
| 458 // Fail the draw again. | 464 // Fail the draw again. |
| 459 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 465 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 460 scheduler->OnBeginImplFrameDeadline(); | 466 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 461 EXPECT_EQ(2, client.num_draws()); | 467 EXPECT_EQ(2, client.num_draws()); |
| 462 EXPECT_TRUE(scheduler->CommitPending()); | 468 EXPECT_TRUE(scheduler->CommitPending()); |
| 463 EXPECT_TRUE(scheduler->RedrawPending()); | 469 EXPECT_TRUE(scheduler->RedrawPending()); |
| 464 EXPECT_TRUE(client.needs_begin_impl_frame()); | 470 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 465 | 471 |
| 466 // Draw successfully. | 472 // Draw successfully. |
| 467 client.SetDrawWillHappen(true); | 473 client.SetDrawWillHappen(true); |
| 468 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 474 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 469 scheduler->OnBeginImplFrameDeadline(); | 475 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 470 EXPECT_EQ(3, client.num_draws()); | 476 EXPECT_EQ(3, client.num_draws()); |
| 471 EXPECT_TRUE(scheduler->CommitPending()); | 477 EXPECT_TRUE(scheduler->CommitPending()); |
| 472 EXPECT_FALSE(scheduler->RedrawPending()); | 478 EXPECT_FALSE(scheduler->RedrawPending()); |
| 473 EXPECT_TRUE(client.needs_begin_impl_frame()); | 479 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 474 } | 480 } |
| 475 | 481 |
| 476 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { | 482 class SchedulerClientThatSetNeedsCommitInsideDraw : public FakeSchedulerClient { |
| 477 public: | 483 public: |
| 478 SchedulerClientThatSetNeedsCommitInsideDraw() | 484 SchedulerClientThatSetNeedsCommitInsideDraw() |
| 479 : set_needs_commit_on_next_draw_(false) {} | 485 : set_needs_commit_on_next_draw_(false) {} |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 525 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 520 client.Reset(); | 526 client.Reset(); |
| 521 | 527 |
| 522 EXPECT_FALSE(client.needs_begin_impl_frame()); | 528 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 523 scheduler->SetNeedsRedraw(); | 529 scheduler->SetNeedsRedraw(); |
| 524 EXPECT_TRUE(scheduler->RedrawPending()); | 530 EXPECT_TRUE(scheduler->RedrawPending()); |
| 525 EXPECT_EQ(0, client.num_draws()); | 531 EXPECT_EQ(0, client.num_draws()); |
| 526 EXPECT_TRUE(client.needs_begin_impl_frame()); | 532 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 527 | 533 |
| 528 client.SetNeedsCommitOnNextDraw(); | 534 client.SetNeedsCommitOnNextDraw(); |
| 529 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 535 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 530 client.SetNeedsCommitOnNextDraw(); | 536 client.SetNeedsCommitOnNextDraw(); |
| 531 scheduler->OnBeginImplFrameDeadline(); | 537 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 532 EXPECT_EQ(1, client.num_draws()); | 538 EXPECT_EQ(1, client.num_draws()); |
| 533 EXPECT_TRUE(scheduler->CommitPending()); | 539 EXPECT_TRUE(scheduler->CommitPending()); |
| 534 EXPECT_TRUE(client.needs_begin_impl_frame()); | 540 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 535 scheduler->NotifyBeginMainFrameStarted(); | 541 scheduler->NotifyBeginMainFrameStarted(); |
| 536 scheduler->NotifyReadyToCommit(); | 542 scheduler->NotifyReadyToCommit(); |
| 537 | 543 |
| 538 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 544 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 539 scheduler->OnBeginImplFrameDeadline(); | 545 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 540 EXPECT_EQ(2, client.num_draws()); | 546 EXPECT_EQ(2, client.num_draws()); |
| 541 | 547 |
| 542 EXPECT_FALSE(scheduler->RedrawPending()); | 548 EXPECT_FALSE(scheduler->RedrawPending()); |
| 543 EXPECT_FALSE(scheduler->CommitPending()); | 549 EXPECT_FALSE(scheduler->CommitPending()); |
| 544 EXPECT_TRUE(client.needs_begin_impl_frame()); | 550 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 545 | 551 |
| 546 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't | 552 // We stop requesting BeginImplFrames after a BeginImplFrame where we don't |
| 547 // swap. | 553 // swap. |
| 548 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 554 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 549 scheduler->OnBeginImplFrameDeadline(); | 555 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 550 EXPECT_EQ(2, client.num_draws()); | 556 EXPECT_EQ(2, client.num_draws()); |
| 551 EXPECT_FALSE(scheduler->RedrawPending()); | 557 EXPECT_FALSE(scheduler->RedrawPending()); |
| 552 EXPECT_FALSE(scheduler->CommitPending()); | 558 EXPECT_FALSE(scheduler->CommitPending()); |
| 553 EXPECT_FALSE(client.needs_begin_impl_frame()); | 559 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 554 } | 560 } |
| 555 | 561 |
| 556 // Tests that when a draw fails then the pending commit should not be dropped. | 562 // Tests that when a draw fails then the pending commit should not be dropped. |
| 557 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { | 563 TEST(SchedulerTest, RequestCommitInsideFailedDraw) { |
| 558 SchedulerClientThatsetNeedsDrawInsideDraw client; | 564 SchedulerClientThatsetNeedsDrawInsideDraw client; |
| 559 SchedulerSettings default_scheduler_settings; | 565 SchedulerSettings default_scheduler_settings; |
| 560 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 566 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 561 scheduler->SetCanStart(); | 567 scheduler->SetCanStart(); |
| 562 scheduler->SetVisible(true); | 568 scheduler->SetVisible(true); |
| 563 scheduler->SetCanDraw(true); | 569 scheduler->SetCanDraw(true); |
| 564 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 570 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 565 client.Reset(); | 571 client.Reset(); |
| 566 | 572 |
| 567 client.SetDrawWillHappen(false); | 573 client.SetDrawWillHappen(false); |
| 568 | 574 |
| 569 scheduler->SetNeedsRedraw(); | 575 scheduler->SetNeedsRedraw(); |
| 570 EXPECT_TRUE(scheduler->RedrawPending()); | 576 EXPECT_TRUE(scheduler->RedrawPending()); |
| 571 EXPECT_TRUE(client.needs_begin_impl_frame()); | 577 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 572 EXPECT_EQ(0, client.num_draws()); | 578 EXPECT_EQ(0, client.num_draws()); |
| 573 | 579 |
| 574 // Fail the draw. | 580 // Fail the draw. |
| 575 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 581 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 576 scheduler->OnBeginImplFrameDeadline(); | 582 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 577 EXPECT_EQ(1, client.num_draws()); | 583 EXPECT_EQ(1, client.num_draws()); |
| 578 | 584 |
| 579 // We have a commit pending and the draw failed, and we didn't lose the commit | 585 // We have a commit pending and the draw failed, and we didn't lose the commit |
| 580 // request. | 586 // request. |
| 581 EXPECT_TRUE(scheduler->CommitPending()); | 587 EXPECT_TRUE(scheduler->CommitPending()); |
| 582 EXPECT_TRUE(scheduler->RedrawPending()); | 588 EXPECT_TRUE(scheduler->RedrawPending()); |
| 583 EXPECT_TRUE(client.needs_begin_impl_frame()); | 589 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 584 | 590 |
| 585 // Fail the draw again. | 591 // Fail the draw again. |
| 586 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 592 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 587 scheduler->OnBeginImplFrameDeadline(); | 593 |
| 594 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 588 EXPECT_EQ(2, client.num_draws()); | 595 EXPECT_EQ(2, client.num_draws()); |
| 589 EXPECT_TRUE(scheduler->CommitPending()); | 596 EXPECT_TRUE(scheduler->CommitPending()); |
| 590 EXPECT_TRUE(scheduler->RedrawPending()); | 597 EXPECT_TRUE(scheduler->RedrawPending()); |
| 591 EXPECT_TRUE(client.needs_begin_impl_frame()); | 598 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 592 | 599 |
| 593 // Draw successfully. | 600 // Draw successfully. |
| 594 client.SetDrawWillHappen(true); | 601 client.SetDrawWillHappen(true); |
| 595 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 602 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 596 scheduler->OnBeginImplFrameDeadline(); | 603 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 597 EXPECT_EQ(3, client.num_draws()); | 604 EXPECT_EQ(3, client.num_draws()); |
| 598 EXPECT_TRUE(scheduler->CommitPending()); | 605 EXPECT_TRUE(scheduler->CommitPending()); |
| 599 EXPECT_FALSE(scheduler->RedrawPending()); | 606 EXPECT_FALSE(scheduler->RedrawPending()); |
| 600 EXPECT_TRUE(client.needs_begin_impl_frame()); | 607 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 601 } | 608 } |
| 602 | 609 |
| 603 TEST(SchedulerTest, NoSwapWhenDrawFails) { | 610 TEST(SchedulerTest, NoSwapWhenDrawFails) { |
| 604 SchedulerClientThatSetNeedsCommitInsideDraw client; | 611 SchedulerClientThatSetNeedsCommitInsideDraw client; |
| 605 SchedulerSettings default_scheduler_settings; | 612 SchedulerSettings default_scheduler_settings; |
| 606 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 613 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 607 scheduler->SetCanStart(); | 614 scheduler->SetCanStart(); |
| 608 scheduler->SetVisible(true); | 615 scheduler->SetVisible(true); |
| 609 scheduler->SetCanDraw(true); | 616 scheduler->SetCanDraw(true); |
| 610 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 617 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 611 client.Reset(); | 618 client.Reset(); |
| 612 | 619 |
| 613 scheduler->SetNeedsRedraw(); | 620 scheduler->SetNeedsRedraw(); |
| 614 EXPECT_TRUE(scheduler->RedrawPending()); | 621 EXPECT_TRUE(scheduler->RedrawPending()); |
| 615 EXPECT_TRUE(client.needs_begin_impl_frame()); | 622 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 616 EXPECT_EQ(0, client.num_draws()); | 623 EXPECT_EQ(0, client.num_draws()); |
| 617 | 624 |
| 618 // Draw successfully, this starts a new frame. | 625 // Draw successfully, this starts a new frame. |
| 619 client.SetNeedsCommitOnNextDraw(); | 626 client.SetNeedsCommitOnNextDraw(); |
| 620 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 627 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 621 scheduler->OnBeginImplFrameDeadline(); | 628 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 622 EXPECT_EQ(1, client.num_draws()); | 629 EXPECT_EQ(1, client.num_draws()); |
| 623 | 630 |
| 624 scheduler->SetNeedsRedraw(); | 631 scheduler->SetNeedsRedraw(); |
| 625 EXPECT_TRUE(scheduler->RedrawPending()); | 632 EXPECT_TRUE(scheduler->RedrawPending()); |
| 626 EXPECT_TRUE(client.needs_begin_impl_frame()); | 633 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 627 | 634 |
| 628 // Fail to draw, this should not start a frame. | 635 // Fail to draw, this should not start a frame. |
| 629 client.SetDrawWillHappen(false); | 636 client.SetDrawWillHappen(false); |
| 630 client.SetNeedsCommitOnNextDraw(); | 637 client.SetNeedsCommitOnNextDraw(); |
| 631 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 638 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 632 scheduler->OnBeginImplFrameDeadline(); | 639 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 633 EXPECT_EQ(2, client.num_draws()); | 640 EXPECT_EQ(2, client.num_draws()); |
| 634 } | 641 } |
| 635 | 642 |
| 636 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { | 643 TEST(SchedulerTest, NoSwapWhenSwapFailsDuringForcedCommit) { |
| 637 FakeSchedulerClient client; | 644 FakeSchedulerClient client; |
| 638 SchedulerSettings default_scheduler_settings; | 645 SchedulerSettings default_scheduler_settings; |
| 639 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 646 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 640 | 647 |
| 641 // Tell the client that it will fail to swap. | 648 // Tell the client that it will fail to swap. |
| 642 client.SetDrawWillHappen(true); | 649 client.SetDrawWillHappen(true); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 EXPECT_TRUE(scheduler->RedrawPending()); | 714 EXPECT_TRUE(scheduler->RedrawPending()); |
| 708 EXPECT_TRUE(scheduler->ManageTilesPending()); | 715 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 709 EXPECT_TRUE(client.needs_begin_impl_frame()); | 716 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 710 EXPECT_EQ(0, client.num_draws()); | 717 EXPECT_EQ(0, client.num_draws()); |
| 711 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 718 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| 712 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 719 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 713 | 720 |
| 714 // We have no immediate actions to perform, so the BeginImplFrame should post | 721 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 715 // the deadline task. | 722 // the deadline task. |
| 716 client.Reset(); | 723 client.Reset(); |
| 717 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 724 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 718 EXPECT_EQ(client.num_actions_(), 0); | 725 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 719 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 726 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 720 | 727 |
| 721 // On the deadline, he actions should have occured in the right order. | 728 // On the deadline, he actions should have occured in the right order. |
| 722 client.Reset(); | 729 client.Reset(); |
| 723 scheduler->OnBeginImplFrameDeadline(); | 730 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 724 EXPECT_EQ(1, client.num_draws()); | 731 EXPECT_EQ(1, client.num_draws()); |
| 725 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 732 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 726 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 733 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 727 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 734 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 728 client.ActionIndex("ScheduledActionManageTiles")); | 735 client.ActionIndex("ScheduledActionManageTiles")); |
| 729 EXPECT_FALSE(scheduler->RedrawPending()); | 736 EXPECT_FALSE(scheduler->RedrawPending()); |
| 730 EXPECT_FALSE(scheduler->ManageTilesPending()); | 737 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 731 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 738 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 732 | 739 |
| 733 // Request a draw. We don't need a ManageTiles yet. | 740 // Request a draw. We don't need a ManageTiles yet. |
| 734 client.Reset(); | 741 client.Reset(); |
| 735 scheduler->SetNeedsRedraw(); | 742 scheduler->SetNeedsRedraw(); |
| 736 EXPECT_TRUE(scheduler->RedrawPending()); | 743 EXPECT_TRUE(scheduler->RedrawPending()); |
| 737 EXPECT_FALSE(scheduler->ManageTilesPending()); | 744 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 738 EXPECT_TRUE(client.needs_begin_impl_frame()); | 745 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 739 EXPECT_EQ(0, client.num_draws()); | 746 EXPECT_EQ(0, client.num_draws()); |
| 740 | 747 |
| 741 // We have no immediate actions to perform, so the BeginImplFrame should post | 748 // We have no immediate actions to perform, so the BeginImplFrame should post |
| 742 // the deadline task. | 749 // the deadline task. |
| 743 client.Reset(); | 750 client.Reset(); |
| 744 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 751 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 745 EXPECT_EQ(client.num_actions_(), 0); | 752 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 746 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 753 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 747 | 754 |
| 748 // Draw. The draw will trigger SetNeedsManageTiles, and | 755 // Draw. The draw will trigger SetNeedsManageTiles, and |
| 749 // then the ManageTiles action will be triggered after the Draw. | 756 // then the ManageTiles action will be triggered after the Draw. |
| 750 // Afterwards, neither a draw nor ManageTiles are pending. | 757 // Afterwards, neither a draw nor ManageTiles are pending. |
| 751 client.Reset(); | 758 client.Reset(); |
| 752 scheduler->OnBeginImplFrameDeadline(); | 759 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 753 EXPECT_EQ(1, client.num_draws()); | 760 EXPECT_EQ(1, client.num_draws()); |
| 754 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 761 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 755 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 762 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 756 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 763 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 757 client.ActionIndex("ScheduledActionManageTiles")); | 764 client.ActionIndex("ScheduledActionManageTiles")); |
| 758 EXPECT_FALSE(scheduler->RedrawPending()); | 765 EXPECT_FALSE(scheduler->RedrawPending()); |
| 759 EXPECT_FALSE(scheduler->ManageTilesPending()); | 766 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 760 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 767 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 761 | 768 |
| 762 // We need a BeginImplFrame where we don't swap to go idle. | 769 // We need a BeginImplFrame where we don't swap to go idle. |
| 763 client.Reset(); | 770 client.Reset(); |
| 764 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 771 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 765 EXPECT_EQ(client.num_actions_(), 0); | 772 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 766 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 773 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 767 client.Reset(); | 774 client.Reset(); |
| 768 scheduler->OnBeginImplFrameDeadline(); | 775 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 769 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 776 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 770 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 777 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 771 EXPECT_EQ(0, client.num_draws()); | 778 EXPECT_EQ(0, client.num_draws()); |
| 772 | 779 |
| 773 // Now trigger a ManageTiles outside of a draw. We will then need | 780 // Now trigger a ManageTiles outside of a draw. We will then need |
| 774 // a begin-frame for the ManageTiles, but we don't need a draw. | 781 // a begin-frame for the ManageTiles, but we don't need a draw. |
| 775 client.Reset(); | 782 client.Reset(); |
| 776 EXPECT_FALSE(client.needs_begin_impl_frame()); | 783 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 777 scheduler->SetNeedsManageTiles(); | 784 scheduler->SetNeedsManageTiles(); |
| 778 EXPECT_TRUE(client.needs_begin_impl_frame()); | 785 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 779 EXPECT_TRUE(scheduler->ManageTilesPending()); | 786 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 780 EXPECT_FALSE(scheduler->RedrawPending()); | 787 EXPECT_FALSE(scheduler->RedrawPending()); |
| 781 | 788 |
| 782 // BeginImplFrame. There will be no draw, only ManageTiles. | 789 // BeginImplFrame. There will be no draw, only ManageTiles. |
| 783 client.Reset(); | 790 client.Reset(); |
| 784 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 791 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 785 EXPECT_EQ(client.num_actions_(), 0); | 792 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 786 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 793 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 787 client.Reset(); | 794 client.Reset(); |
| 788 scheduler->OnBeginImplFrameDeadline(); | 795 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 789 EXPECT_EQ(0, client.num_draws()); | 796 EXPECT_EQ(0, client.num_draws()); |
| 790 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 797 EXPECT_FALSE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 791 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 798 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 792 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 799 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 793 } | 800 } |
| 794 | 801 |
| 795 // Test that ManageTiles only happens once per frame. If an external caller | 802 // Test that ManageTiles only happens once per frame. If an external caller |
| 796 // initiates it, then the state machine should not ManageTiles on that frame. | 803 // initiates it, then the state machine should not ManageTiles on that frame. |
| 797 TEST(SchedulerTest, ManageTilesOncePerFrame) { | 804 TEST(SchedulerTest, ManageTilesOncePerFrame) { |
| 798 FakeSchedulerClient client; | 805 FakeSchedulerClient client; |
| 799 SchedulerSettings default_scheduler_settings; | 806 SchedulerSettings default_scheduler_settings; |
| 800 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 807 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 801 scheduler->SetCanStart(); | 808 scheduler->SetCanStart(); |
| 802 scheduler->SetVisible(true); | 809 scheduler->SetVisible(true); |
| 803 scheduler->SetCanDraw(true); | 810 scheduler->SetCanDraw(true); |
| 804 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 811 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 805 | 812 |
| 806 // If DidManageTiles during a frame, then ManageTiles should not occur again. | 813 // If DidManageTiles during a frame, then ManageTiles should not occur again. |
| 807 scheduler->SetNeedsManageTiles(); | 814 scheduler->SetNeedsManageTiles(); |
| 808 scheduler->SetNeedsRedraw(); | 815 scheduler->SetNeedsRedraw(); |
| 809 client.Reset(); | 816 client.Reset(); |
| 810 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 817 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 811 EXPECT_EQ(client.num_actions_(), 0); | 818 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 812 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 819 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 813 | 820 |
| 814 EXPECT_TRUE(scheduler->ManageTilesPending()); | 821 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 815 scheduler->DidManageTiles(); // An explicit ManageTiles. | 822 scheduler->DidManageTiles(); // An explicit ManageTiles. |
| 816 EXPECT_FALSE(scheduler->ManageTilesPending()); | 823 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 817 | 824 |
| 818 client.Reset(); | 825 client.Reset(); |
| 819 scheduler->OnBeginImplFrameDeadline(); | 826 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 820 EXPECT_EQ(1, client.num_draws()); | 827 EXPECT_EQ(1, client.num_draws()); |
| 821 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 828 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 822 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 829 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| 823 EXPECT_FALSE(scheduler->RedrawPending()); | 830 EXPECT_FALSE(scheduler->RedrawPending()); |
| 824 EXPECT_FALSE(scheduler->ManageTilesPending()); | 831 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 825 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 832 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 826 | 833 |
| 827 // Next frame without DidManageTiles should ManageTiles with draw. | 834 // Next frame without DidManageTiles should ManageTiles with draw. |
| 828 scheduler->SetNeedsManageTiles(); | 835 scheduler->SetNeedsManageTiles(); |
| 829 scheduler->SetNeedsRedraw(); | 836 scheduler->SetNeedsRedraw(); |
| 830 client.Reset(); | 837 client.Reset(); |
| 831 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 838 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 832 EXPECT_EQ(client.num_actions_(), 0); | 839 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 833 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 840 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 834 | 841 |
| 835 client.Reset(); | 842 client.Reset(); |
| 836 scheduler->OnBeginImplFrameDeadline(); | 843 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 837 EXPECT_EQ(1, client.num_draws()); | 844 EXPECT_EQ(1, client.num_draws()); |
| 838 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 845 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 839 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 846 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 840 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 847 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 841 client.ActionIndex("ScheduledActionManageTiles")); | 848 client.ActionIndex("ScheduledActionManageTiles")); |
| 842 EXPECT_FALSE(scheduler->RedrawPending()); | 849 EXPECT_FALSE(scheduler->RedrawPending()); |
| 843 EXPECT_FALSE(scheduler->ManageTilesPending()); | 850 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 844 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 851 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 845 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles | 852 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles |
| 846 | 853 |
| 847 // If we get another DidManageTiles within the same frame, we should | 854 // If we get another DidManageTiles within the same frame, we should |
| 848 // not ManageTiles on the next frame. | 855 // not ManageTiles on the next frame. |
| 849 scheduler->DidManageTiles(); // An explicit ManageTiles. | 856 scheduler->DidManageTiles(); // An explicit ManageTiles. |
| 850 scheduler->SetNeedsManageTiles(); | 857 scheduler->SetNeedsManageTiles(); |
| 851 scheduler->SetNeedsRedraw(); | 858 scheduler->SetNeedsRedraw(); |
| 852 client.Reset(); | 859 client.Reset(); |
| 853 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 860 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 854 EXPECT_EQ(client.num_actions_(), 0); | 861 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 855 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 862 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 856 | 863 |
| 857 EXPECT_TRUE(scheduler->ManageTilesPending()); | 864 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 858 | 865 |
| 859 client.Reset(); | 866 client.Reset(); |
| 860 scheduler->OnBeginImplFrameDeadline(); | 867 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 861 EXPECT_EQ(1, client.num_draws()); | 868 EXPECT_EQ(1, client.num_draws()); |
| 862 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 869 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 863 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 870 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| 864 EXPECT_FALSE(scheduler->RedrawPending()); | 871 EXPECT_FALSE(scheduler->RedrawPending()); |
| 865 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 872 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 866 | 873 |
| 867 // If we get another DidManageTiles, we should not ManageTiles on the next | 874 // If we get another DidManageTiles, we should not ManageTiles on the next |
| 868 // frame. This verifies we don't alternate calling ManageTiles once and twice. | 875 // frame. This verifies we don't alternate calling ManageTiles once and twice. |
| 869 EXPECT_TRUE(scheduler->ManageTilesPending()); | 876 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 870 scheduler->DidManageTiles(); // An explicit ManageTiles. | 877 scheduler->DidManageTiles(); // An explicit ManageTiles. |
| 871 EXPECT_FALSE(scheduler->ManageTilesPending()); | 878 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 872 scheduler->SetNeedsManageTiles(); | 879 scheduler->SetNeedsManageTiles(); |
| 873 scheduler->SetNeedsRedraw(); | 880 scheduler->SetNeedsRedraw(); |
| 874 client.Reset(); | 881 client.Reset(); |
| 875 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 882 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 876 EXPECT_EQ(client.num_actions_(), 0); | 883 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 877 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 884 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 878 | 885 |
| 879 EXPECT_TRUE(scheduler->ManageTilesPending()); | 886 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| 880 | 887 |
| 881 client.Reset(); | 888 client.Reset(); |
| 882 scheduler->OnBeginImplFrameDeadline(); | 889 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 883 EXPECT_EQ(1, client.num_draws()); | 890 EXPECT_EQ(1, client.num_draws()); |
| 884 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 891 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 885 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); | 892 EXPECT_FALSE(client.HasAction("ScheduledActionManageTiles")); |
| 886 EXPECT_FALSE(scheduler->RedrawPending()); | 893 EXPECT_FALSE(scheduler->RedrawPending()); |
| 887 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 894 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 888 | 895 |
| 889 // Next frame without DidManageTiles should ManageTiles with draw. | 896 // Next frame without DidManageTiles should ManageTiles with draw. |
| 890 scheduler->SetNeedsManageTiles(); | 897 scheduler->SetNeedsManageTiles(); |
| 891 scheduler->SetNeedsRedraw(); | 898 scheduler->SetNeedsRedraw(); |
| 892 client.Reset(); | 899 client.Reset(); |
| 893 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 900 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 894 EXPECT_EQ(client.num_actions_(), 0); | 901 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 895 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 902 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 896 | 903 |
| 897 client.Reset(); | 904 client.Reset(); |
| 898 scheduler->OnBeginImplFrameDeadline(); | 905 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 899 EXPECT_EQ(1, client.num_draws()); | 906 EXPECT_EQ(1, client.num_draws()); |
| 900 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); | 907 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapIfPossible")); |
| 901 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); | 908 EXPECT_TRUE(client.HasAction("ScheduledActionManageTiles")); |
| 902 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), | 909 EXPECT_LT(client.ActionIndex("ScheduledActionDrawAndSwapIfPossible"), |
| 903 client.ActionIndex("ScheduledActionManageTiles")); | 910 client.ActionIndex("ScheduledActionManageTiles")); |
| 904 EXPECT_FALSE(scheduler->RedrawPending()); | 911 EXPECT_FALSE(scheduler->RedrawPending()); |
| 905 EXPECT_FALSE(scheduler->ManageTilesPending()); | 912 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 906 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 913 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 907 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles | 914 scheduler->DidManageTiles(); // Corresponds to ScheduledActionManageTiles |
| 908 } | 915 } |
| 909 | 916 |
| 910 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { | 917 TEST(SchedulerTest, TriggerBeginFrameDeadlineEarly) { |
| 911 SchedulerClientNeedsManageTilesInDraw client; | 918 SchedulerClientNeedsManageTilesInDraw client; |
| 912 SchedulerSettings default_scheduler_settings; | 919 SchedulerSettings default_scheduler_settings; |
| 913 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 920 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 914 scheduler->SetCanStart(); | 921 scheduler->SetCanStart(); |
| 915 scheduler->SetVisible(true); | 922 scheduler->SetVisible(true); |
| 916 scheduler->SetCanDraw(true); | 923 scheduler->SetCanDraw(true); |
| 917 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 924 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 918 | 925 |
| 919 client.Reset(); | 926 client.Reset(); |
| 920 BeginFrameArgs impl_frame_args = BeginFrameArgs::CreateForTesting(); | |
| 921 scheduler->SetNeedsRedraw(); | 927 scheduler->SetNeedsRedraw(); |
| 922 scheduler->BeginImplFrame(impl_frame_args); | 928 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 923 | 929 |
| 924 // The deadline should be zero since there is no work other than drawing | 930 // The deadline should be zero since there is no work other than drawing |
| 925 // pending. | 931 // pending. |
| 926 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); | 932 EXPECT_EQ(base::TimeTicks(), client.posted_begin_impl_frame_deadline()); |
| 927 } | 933 } |
| 928 | 934 |
| 929 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { | 935 class SchedulerClientWithFixedEstimates : public FakeSchedulerClient { |
| 930 public: | 936 public: |
| 931 SchedulerClientWithFixedEstimates( | 937 SchedulerClientWithFixedEstimates( |
| 932 base::TimeDelta draw_duration, | 938 base::TimeDelta draw_duration, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 scheduler->SetCanStart(); | 974 scheduler->SetCanStart(); |
| 969 scheduler->SetVisible(true); | 975 scheduler->SetVisible(true); |
| 970 scheduler->SetCanDraw(true); | 976 scheduler->SetCanDraw(true); |
| 971 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); | 977 scheduler->SetSmoothnessTakesPriority(smoothness_takes_priority); |
| 972 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); | 978 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 973 | 979 |
| 974 // Impl thread hits deadline before commit finishes. | 980 // Impl thread hits deadline before commit finishes. |
| 975 client.Reset(); | 981 client.Reset(); |
| 976 scheduler->SetNeedsCommit(); | 982 scheduler->SetNeedsCommit(); |
| 977 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 983 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
| 978 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 984 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 979 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); | 985 EXPECT_FALSE(scheduler->MainThreadIsInHighLatencyMode()); |
| 980 scheduler->OnBeginImplFrameDeadline(); | 986 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 981 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 987 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 982 scheduler->NotifyBeginMainFrameStarted(); | 988 scheduler->NotifyBeginMainFrameStarted(); |
| 983 scheduler->NotifyReadyToCommit(); | 989 scheduler->NotifyReadyToCommit(); |
| 984 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 990 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 985 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); | 991 EXPECT_TRUE(client.HasAction("ScheduledActionSendBeginMainFrame")); |
| 986 | 992 |
| 987 client.Reset(); | 993 client.Reset(); |
| 988 scheduler->SetNeedsCommit(); | 994 scheduler->SetNeedsCommit(); |
| 989 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 995 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 990 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 996 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 991 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); | 997 EXPECT_TRUE(scheduler->MainThreadIsInHighLatencyMode()); |
| 992 scheduler->OnBeginImplFrameDeadline(); | 998 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 993 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), | 999 EXPECT_EQ(scheduler->MainThreadIsInHighLatencyMode(), |
| 994 should_send_begin_main_frame); | 1000 should_send_begin_main_frame); |
| 995 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), | 1001 EXPECT_EQ(client.HasAction("ScheduledActionSendBeginMainFrame"), |
| 996 should_send_begin_main_frame); | 1002 should_send_begin_main_frame); |
| 997 } | 1003 } |
| 998 | 1004 |
| 999 TEST(SchedulerTest, | 1005 TEST(SchedulerTest, |
| 1000 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { | 1006 SkipMainFrameIfHighLatencyAndCanCommitAndActivateBeforeDeadline) { |
| 1001 // Set up client so that estimates indicate that we can commit and activate | 1007 // Set up client so that estimates indicate that we can commit and activate |
| 1002 // before the deadline (~8ms by default). | 1008 // before the deadline (~8ms by default). |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 scheduler->SetCanStart(); | 1043 scheduler->SetCanStart(); |
| 1038 scheduler->SetVisible(true); | 1044 scheduler->SetVisible(true); |
| 1039 scheduler->DidCreateAndInitializeOutputSurface(); | 1045 scheduler->DidCreateAndInitializeOutputSurface(); |
| 1040 | 1046 |
| 1041 scheduler->SetNeedsCommit(); | 1047 scheduler->SetNeedsCommit(); |
| 1042 EXPECT_TRUE(scheduler->CommitPending()); | 1048 EXPECT_TRUE(scheduler->CommitPending()); |
| 1043 scheduler->NotifyBeginMainFrameStarted(); | 1049 scheduler->NotifyBeginMainFrameStarted(); |
| 1044 scheduler->NotifyReadyToCommit(); | 1050 scheduler->NotifyReadyToCommit(); |
| 1045 scheduler->SetNeedsRedraw(); | 1051 scheduler->SetNeedsRedraw(); |
| 1046 | 1052 |
| 1047 BeginFrameArgs impl_frame_args = BeginFrameArgs::CreateForTesting(); | 1053 BeginFrameArgs frame_args = BeginFrameArgs::CreateForTesting(); |
| 1048 impl_frame_args.interval = base::TimeDelta::FromMilliseconds(1000); | 1054 frame_args.interval = base::TimeDelta::FromMilliseconds(1000); |
| 1049 scheduler->BeginImplFrame(impl_frame_args); | 1055 scheduler->BeginFrame(frame_args); |
| 1050 | 1056 |
| 1051 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 1057 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1052 client.task_runner().RunPendingTasks(); // Run posted deadline. | 1058 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1053 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 1059 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1054 | 1060 |
| 1055 // At this point, we've drawn a frame. Start another commit, but hold off on | 1061 // At this point, we've drawn a frame. Start another commit, but hold off on |
| 1056 // the NotifyReadyToCommit for now. | 1062 // the NotifyReadyToCommit for now. |
| 1057 EXPECT_FALSE(scheduler->CommitPending()); | 1063 EXPECT_FALSE(scheduler->CommitPending()); |
| 1058 scheduler->SetNeedsCommit(); | 1064 scheduler->SetNeedsCommit(); |
| 1059 scheduler->BeginImplFrame(impl_frame_args); | 1065 scheduler->BeginFrame(frame_args); |
| 1060 EXPECT_TRUE(scheduler->CommitPending()); | 1066 EXPECT_TRUE(scheduler->CommitPending()); |
| 1061 | 1067 |
| 1062 // Spin the event loop a few times and make sure we get more | 1068 // Spin the event loop a few times and make sure we get more |
| 1063 // DidAnticipateDrawTimeChange calls every time. | 1069 // DidAnticipateDrawTimeChange calls every time. |
| 1064 int actions_so_far = client.num_actions_(); | 1070 int actions_so_far = client.num_actions_(); |
| 1065 | 1071 |
| 1066 // Does three iterations to make sure that the timer is properly repeating. | 1072 // Does three iterations to make sure that the timer is properly repeating. |
| 1067 for (int i = 0; i < 3; ++i) { | 1073 for (int i = 0; i < 3; ++i) { |
| 1068 EXPECT_EQ((impl_frame_args.interval * 2).InMicroseconds(), | 1074 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
| 1069 client.task_runner().NextPendingTaskDelay().InMicroseconds()) | 1075 client.task_runner().NextPendingTaskDelay().InMicroseconds()) |
| 1070 << *scheduler->StateAsValue(); | 1076 << *scheduler->StateAsValue(); |
| 1071 client.task_runner().RunPendingTasks(); | 1077 client.task_runner().RunPendingTasks(); |
| 1072 EXPECT_GT(client.num_actions_(), actions_so_far); | 1078 EXPECT_GT(client.num_actions_(), actions_so_far); |
| 1073 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1079 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
| 1074 "DidAnticipatedDrawTimeChange"); | 1080 "DidAnticipatedDrawTimeChange"); |
| 1075 actions_so_far = client.num_actions_(); | 1081 actions_so_far = client.num_actions_(); |
| 1076 } | 1082 } |
| 1077 | 1083 |
| 1078 // Do the same thing after BeginMainFrame starts but still before activation. | 1084 // Do the same thing after BeginMainFrame starts but still before activation. |
| 1079 scheduler->NotifyBeginMainFrameStarted(); | 1085 scheduler->NotifyBeginMainFrameStarted(); |
| 1080 for (int i = 0; i < 3; ++i) { | 1086 for (int i = 0; i < 3; ++i) { |
| 1081 EXPECT_EQ((impl_frame_args.interval * 2).InMicroseconds(), | 1087 EXPECT_EQ((frame_args.interval * 2).InMicroseconds(), |
| 1082 client.task_runner().NextPendingTaskDelay().InMicroseconds()) | 1088 client.task_runner().NextPendingTaskDelay().InMicroseconds()) |
| 1083 << *scheduler->StateAsValue(); | 1089 << *scheduler->StateAsValue(); |
| 1084 client.task_runner().RunPendingTasks(); | 1090 client.task_runner().RunPendingTasks(); |
| 1085 EXPECT_GT(client.num_actions_(), actions_so_far); | 1091 EXPECT_GT(client.num_actions_(), actions_so_far); |
| 1086 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1092 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
| 1087 "DidAnticipatedDrawTimeChange"); | 1093 "DidAnticipatedDrawTimeChange"); |
| 1088 actions_so_far = client.num_actions_(); | 1094 actions_so_far = client.num_actions_(); |
| 1089 } | 1095 } |
| 1090 } | 1096 } |
| 1091 | 1097 |
| 1098 TEST(SchedulerTest, BeginRetroFrame) { |
| 1099 FakeSchedulerClient client; |
| 1100 SchedulerSettings scheduler_settings; |
| 1101 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 1102 scheduler->SetCanStart(); |
| 1103 scheduler->SetVisible(true); |
| 1104 scheduler->SetCanDraw(true); |
| 1105 InitializeOutputSurfaceAndFirstCommit(scheduler, &client); |
| 1106 |
| 1107 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 1108 client.Reset(); |
| 1109 scheduler->SetNeedsCommit(); |
| 1110 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1111 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 1112 client.Reset(); |
| 1113 |
| 1114 // Create a BeginFrame with a long deadline to avoid race conditions. |
| 1115 // This is the first BeginFrame, which will be handled immediately. |
| 1116 BeginFrameArgs args = BeginFrameArgs::CreateForTesting(); |
| 1117 args.deadline += base::TimeDelta::FromHours(1); |
| 1118 scheduler->BeginFrame(args); |
| 1119 |
| 1120 EXPECT_ACTION("WillBeginImplFrame", client, 0, 2); |
| 1121 EXPECT_ACTION("ScheduledActionSendBeginMainFrame", client, 1, 2); |
| 1122 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1123 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1124 client.Reset(); |
| 1125 |
| 1126 // Queue BeginFrames while we are still handling the previous BeginFrame. |
| 1127 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1128 scheduler->BeginFrame(args); |
| 1129 args.frame_time += base::TimeDelta::FromSeconds(1); |
| 1130 scheduler->BeginFrame(args); |
| 1131 |
| 1132 // If we don't swap on the deadline, we need to request another |
| 1133 // BeginImplFrame. |
| 1134 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1135 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 1136 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1137 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1138 client.Reset(); |
| 1139 |
| 1140 // NotifyReadyToCommit should trigger the commit. |
| 1141 scheduler->NotifyBeginMainFrameStarted(); |
| 1142 scheduler->NotifyReadyToCommit(); |
| 1143 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 1144 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1145 client.Reset(); |
| 1146 |
| 1147 // BeginImplFrame should prepare the draw. |
| 1148 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1149 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1150 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1151 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1152 client.Reset(); |
| 1153 |
| 1154 // BeginImplFrame deadline should draw. |
| 1155 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1156 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 1157 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| 1158 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 1159 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1160 client.Reset(); |
| 1161 |
| 1162 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 1163 // to avoid excessive toggles. |
| 1164 client.task_runner().RunPendingTasks(); // Run posted BeginRetroFrame. |
| 1165 EXPECT_SINGLE_ACTION("WillBeginImplFrame", client); |
| 1166 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 1167 client.Reset(); |
| 1168 |
| 1169 client.task_runner().RunPendingTasks(); // Run posted deadline. |
| 1170 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 1171 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 1172 client.Reset(); |
| 1173 } |
| 1174 |
| 1092 } // namespace | 1175 } // namespace |
| 1093 } // namespace cc | 1176 } // namespace cc |
| OLD | NEW |