| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler) { | 34 void InitializeOutputSurfaceAndFirstCommit(Scheduler* scheduler) { |
| 35 scheduler->DidCreateAndInitializeOutputSurface(); | 35 scheduler->DidCreateAndInitializeOutputSurface(); |
| 36 scheduler->SetNeedsCommit(); | 36 scheduler->SetNeedsCommit(); |
| 37 scheduler->NotifyBeginMainFrameStarted(); | 37 scheduler->NotifyBeginMainFrameStarted(); |
| 38 scheduler->NotifyReadyToCommit(); | 38 scheduler->NotifyReadyToCommit(); |
| 39 // Go through the motions to draw the commit. | 39 // Go through the motions to draw the commit. |
| 40 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 40 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 41 scheduler->OnBeginImplFrameDeadline(); | 41 scheduler->OnBeginImplFrameDeadline(); |
| 42 // We need another BeginImplFrame so Scheduler calls | 42 // We need another BeginImplFrame so Scheduler calls |
| 43 // SetNeedsBeginImplFrame(false). | 43 // SetNeedsBeginFrame(false). |
| 44 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 44 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 45 scheduler->OnBeginImplFrameDeadline(); | 45 scheduler->OnBeginImplFrameDeadline(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 class FakeSchedulerClient : public SchedulerClient { | 48 class FakeSchedulerClient : public SchedulerClient { |
| 49 public: | 49 public: |
| 50 FakeSchedulerClient() | 50 FakeSchedulerClient() |
| 51 : needs_begin_impl_frame_(false) { | 51 : needs_begin_impl_frame_(false) { |
| 52 Reset(); | 52 Reset(); |
| 53 } | 53 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 void SetDrawWillHappen(bool draw_will_happen) { | 95 void SetDrawWillHappen(bool draw_will_happen) { |
| 96 draw_will_happen_ = draw_will_happen; | 96 draw_will_happen_ = draw_will_happen; |
| 97 } | 97 } |
| 98 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { | 98 void SetSwapWillHappenIfDrawHappens(bool swap_will_happen_if_draw_happens) { |
| 99 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; | 99 swap_will_happen_if_draw_happens_ = swap_will_happen_if_draw_happens; |
| 100 } | 100 } |
| 101 | 101 |
| 102 // SchedulerClient implementation. | 102 // SchedulerClient implementation. |
| 103 virtual void SetNeedsBeginImplFrame(bool enable) OVERRIDE { | 103 virtual void SetNeedsBeginFrame(bool enable) OVERRIDE { |
| 104 actions_.push_back("SetNeedsBeginImplFrame"); | 104 actions_.push_back("SetNeedsBeginFrame"); |
| 105 states_.push_back(scheduler_->StateAsValue().release()); | 105 states_.push_back(scheduler_->StateAsValue().release()); |
| 106 needs_begin_impl_frame_ = enable; | 106 needs_begin_impl_frame_ = enable; |
| 107 } | 107 } |
| 108 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { | 108 virtual void ScheduledActionSendBeginMainFrame() OVERRIDE { |
| 109 actions_.push_back("ScheduledActionSendBeginMainFrame"); | 109 actions_.push_back("ScheduledActionSendBeginMainFrame"); |
| 110 states_.push_back(scheduler_->StateAsValue().release()); | 110 states_.push_back(scheduler_->StateAsValue().release()); |
| 111 } | 111 } |
| 112 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() | 112 virtual DrawSwapReadbackResult ScheduledActionDrawAndSwapIfPossible() |
| 113 OVERRIDE { | 113 OVERRIDE { |
| 114 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); | 114 actions_.push_back("ScheduledActionDrawAndSwapIfPossible"); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 scheduler->SetVisible(true); | 214 scheduler->SetVisible(true); |
| 215 scheduler->SetCanDraw(true); | 215 scheduler->SetCanDraw(true); |
| 216 | 216 |
| 217 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 217 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 218 InitializeOutputSurfaceAndFirstCommit(scheduler); | 218 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 219 | 219 |
| 220 // SetNeedsCommit should begin the frame on the next BeginImplFrame. | 220 // SetNeedsCommit should begin the frame on the next BeginImplFrame. |
| 221 client.Reset(); | 221 client.Reset(); |
| 222 scheduler->SetNeedsCommit(); | 222 scheduler->SetNeedsCommit(); |
| 223 EXPECT_TRUE(client.needs_begin_impl_frame()); | 223 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 224 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 224 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 225 client.Reset(); | 225 client.Reset(); |
| 226 | 226 |
| 227 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 227 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 228 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 228 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| 229 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 229 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 230 EXPECT_TRUE(client.needs_begin_impl_frame()); | 230 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 231 client.Reset(); | 231 client.Reset(); |
| 232 | 232 |
| 233 // If we don't swap on the deadline, we need to request another | 233 // If we don't swap on the deadline, we need to request another |
| 234 // BeginImplFrame. | 234 // BeginImplFrame. |
| 235 scheduler->OnBeginImplFrameDeadline(); | 235 scheduler->OnBeginImplFrameDeadline(); |
| 236 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 236 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 237 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 237 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 238 EXPECT_TRUE(client.needs_begin_impl_frame()); | 238 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 239 client.Reset(); | 239 client.Reset(); |
| 240 | 240 |
| 241 // NotifyReadyToCommit should trigger the commit. | 241 // NotifyReadyToCommit should trigger the commit. |
| 242 scheduler->NotifyBeginMainFrameStarted(); | 242 scheduler->NotifyBeginMainFrameStarted(); |
| 243 scheduler->NotifyReadyToCommit(); | 243 scheduler->NotifyReadyToCommit(); |
| 244 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 244 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 245 EXPECT_TRUE(client.needs_begin_impl_frame()); | 245 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 246 client.Reset(); | 246 client.Reset(); |
| 247 | 247 |
| 248 // BeginImplFrame should prepare the draw. | 248 // BeginImplFrame should prepare the draw. |
| 249 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 249 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 250 EXPECT_EQ(client.num_actions_(), 0); | 250 EXPECT_EQ(client.num_actions_(), 0); |
| 251 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 251 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 252 EXPECT_TRUE(client.needs_begin_impl_frame()); | 252 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 253 client.Reset(); | 253 client.Reset(); |
| 254 | 254 |
| 255 // BeginImplFrame deadline should draw. | 255 // BeginImplFrame deadline should draw. |
| 256 scheduler->OnBeginImplFrameDeadline(); | 256 scheduler->OnBeginImplFrameDeadline(); |
| 257 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 257 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 258 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 258 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| 259 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 259 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 260 EXPECT_TRUE(client.needs_begin_impl_frame()); | 260 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 261 client.Reset(); | 261 client.Reset(); |
| 262 | 262 |
| 263 // The following BeginImplFrame deadline should SetNeedsBeginImplFrame(false) | 263 // The following BeginImplFrame deadline should SetNeedsBeginFrame(false) |
| 264 // to avoid excessive toggles. | 264 // to avoid excessive toggles. |
| 265 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 265 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 266 EXPECT_EQ(client.num_actions_(), 0); | 266 EXPECT_EQ(client.num_actions_(), 0); |
| 267 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 267 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 268 client.Reset(); | 268 client.Reset(); |
| 269 | 269 |
| 270 scheduler->OnBeginImplFrameDeadline(); | 270 scheduler->OnBeginImplFrameDeadline(); |
| 271 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 271 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 272 EXPECT_FALSE(client.needs_begin_impl_frame()); | 272 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 273 client.Reset(); | 273 client.Reset(); |
| 274 } | 274 } |
| 275 | 275 |
| 276 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { | 276 TEST(SchedulerTest, RequestCommitAfterBeginMainFrameSent) { |
| 277 FakeSchedulerClient client; | 277 FakeSchedulerClient client; |
| 278 SchedulerSettings scheduler_settings; | 278 SchedulerSettings scheduler_settings; |
| 279 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | 279 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 280 scheduler->SetCanStart(); | 280 scheduler->SetCanStart(); |
| 281 scheduler->SetVisible(true); | 281 scheduler->SetVisible(true); |
| 282 scheduler->SetCanDraw(true); | 282 scheduler->SetCanDraw(true); |
| 283 | 283 |
| 284 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 284 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 285 InitializeOutputSurfaceAndFirstCommit(scheduler); | 285 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 286 client.Reset(); | 286 client.Reset(); |
| 287 | 287 |
| 288 // SetNeedsCommit should begin the frame. | 288 // SetNeedsCommit should begin the frame. |
| 289 scheduler->SetNeedsCommit(); | 289 scheduler->SetNeedsCommit(); |
| 290 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 290 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 291 | 291 |
| 292 client.Reset(); | 292 client.Reset(); |
| 293 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 293 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 294 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 294 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| 295 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 295 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 296 | 296 |
| 297 EXPECT_TRUE(client.needs_begin_impl_frame()); | 297 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 298 client.Reset(); | 298 client.Reset(); |
| 299 | 299 |
| 300 // Now SetNeedsCommit again. Calling here means we need a second commit. | 300 // Now SetNeedsCommit again. Calling here means we need a second commit. |
| 301 scheduler->SetNeedsCommit(); | 301 scheduler->SetNeedsCommit(); |
| 302 EXPECT_EQ(client.num_actions_(), 0); | 302 EXPECT_EQ(client.num_actions_(), 0); |
| 303 client.Reset(); | 303 client.Reset(); |
| 304 | 304 |
| 305 // Finish the first commit. | 305 // Finish the first commit. |
| 306 scheduler->NotifyBeginMainFrameStarted(); | 306 scheduler->NotifyBeginMainFrameStarted(); |
| 307 scheduler->NotifyReadyToCommit(); | 307 scheduler->NotifyReadyToCommit(); |
| 308 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 308 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 309 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 309 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 310 client.Reset(); | 310 client.Reset(); |
| 311 scheduler->OnBeginImplFrameDeadline(); | 311 scheduler->OnBeginImplFrameDeadline(); |
| 312 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 312 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 313 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 313 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| 314 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 314 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 315 | 315 |
| 316 // Because we just swapped, the Scheduler should also request the next | 316 // Because we just swapped, the Scheduler should also request the next |
| 317 // BeginImplFrame from the OutputSurface. | 317 // BeginImplFrame from the OutputSurface. |
| 318 EXPECT_TRUE(client.needs_begin_impl_frame()); | 318 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 319 client.Reset(); | 319 client.Reset(); |
| 320 | 320 |
| 321 // Since another commit is needed, the next BeginImplFrame should initiate | 321 // Since another commit is needed, the next BeginImplFrame should initiate |
| 322 // the second commit. | 322 // the second commit. |
| 323 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 323 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 324 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 324 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| 325 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 325 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 326 client.Reset(); | 326 client.Reset(); |
| 327 | 327 |
| 328 // Finishing the commit before the deadline should post a new deadline task | 328 // Finishing the commit before the deadline should post a new deadline task |
| 329 // to trigger the deadline early. | 329 // to trigger the deadline early. |
| 330 scheduler->NotifyBeginMainFrameStarted(); | 330 scheduler->NotifyBeginMainFrameStarted(); |
| 331 scheduler->NotifyReadyToCommit(); | 331 scheduler->NotifyReadyToCommit(); |
| 332 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 332 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 333 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 333 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 334 client.Reset(); | 334 client.Reset(); |
| 335 scheduler->OnBeginImplFrameDeadline(); | 335 scheduler->OnBeginImplFrameDeadline(); |
| 336 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 336 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 337 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 337 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| 338 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 338 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 339 EXPECT_TRUE(client.needs_begin_impl_frame()); | 339 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 340 client.Reset(); | 340 client.Reset(); |
| 341 | 341 |
| 342 // On the next BeginImplFrame, verify we go back to a quiescent state and | 342 // On the next BeginImplFrame, verify we go back to a quiescent state and |
| 343 // no longer request BeginImplFrames. | 343 // no longer request BeginImplFrames. |
| 344 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 344 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 345 scheduler->OnBeginImplFrameDeadline(); | 345 scheduler->OnBeginImplFrameDeadline(); |
| 346 EXPECT_FALSE(client.needs_begin_impl_frame()); | 346 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 347 client.Reset(); | 347 client.Reset(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { | 350 TEST(SchedulerTest, TextureAcquisitionCausesCommitInsteadOfDraw) { |
| 351 FakeSchedulerClient client; | 351 FakeSchedulerClient client; |
| 352 SchedulerSettings scheduler_settings; | 352 SchedulerSettings scheduler_settings; |
| 353 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | 353 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 354 scheduler->SetCanStart(); | 354 scheduler->SetCanStart(); |
| 355 scheduler->SetVisible(true); | 355 scheduler->SetVisible(true); |
| 356 scheduler->SetCanDraw(true); | 356 scheduler->SetCanDraw(true); |
| 357 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 357 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 358 | 358 |
| 359 InitializeOutputSurfaceAndFirstCommit(scheduler); | 359 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 360 client.Reset(); | 360 client.Reset(); |
| 361 scheduler->SetNeedsRedraw(); | 361 scheduler->SetNeedsRedraw(); |
| 362 EXPECT_TRUE(scheduler->RedrawPending()); | 362 EXPECT_TRUE(scheduler->RedrawPending()); |
| 363 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 363 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 364 EXPECT_TRUE(client.needs_begin_impl_frame()); | 364 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 365 | 365 |
| 366 client.Reset(); | 366 client.Reset(); |
| 367 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 367 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 368 EXPECT_EQ(client.num_actions_(), 0); | 368 EXPECT_EQ(client.num_actions_(), 0); |
| 369 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 369 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 370 client.Reset(); | 370 client.Reset(); |
| 371 scheduler->OnBeginImplFrameDeadline(); | 371 scheduler->OnBeginImplFrameDeadline(); |
| 372 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 372 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 373 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 373 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| 374 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 374 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 375 EXPECT_FALSE(scheduler->RedrawPending()); | 375 EXPECT_FALSE(scheduler->RedrawPending()); |
| 376 EXPECT_TRUE(client.needs_begin_impl_frame()); | 376 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 377 | 377 |
| 378 client.Reset(); | 378 client.Reset(); |
| 379 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 379 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 380 EXPECT_EQ(client.num_actions_(), 0); | 380 EXPECT_EQ(client.num_actions_(), 0); |
| 381 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 381 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 382 client.Reset(); | 382 client.Reset(); |
| 383 scheduler->OnBeginImplFrameDeadline(); | 383 scheduler->OnBeginImplFrameDeadline(); |
| 384 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 384 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 385 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 385 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 386 EXPECT_FALSE(scheduler->RedrawPending()); | 386 EXPECT_FALSE(scheduler->RedrawPending()); |
| 387 EXPECT_FALSE(client.needs_begin_impl_frame()); | 387 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 388 | 388 |
| 389 client.Reset(); | 389 client.Reset(); |
| 390 scheduler->SetMainThreadNeedsLayerTextures(); | 390 scheduler->SetMainThreadNeedsLayerTextures(); |
| 391 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 391 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
| 392 client); | 392 client); |
| 393 | 393 |
| 394 // We should request a BeginImplFrame in anticipation of a draw. | 394 // We should request a BeginImplFrame in anticipation of a draw. |
| 395 client.Reset(); | 395 client.Reset(); |
| 396 scheduler->SetNeedsRedraw(); | 396 scheduler->SetNeedsRedraw(); |
| 397 EXPECT_TRUE(scheduler->RedrawPending()); | 397 EXPECT_TRUE(scheduler->RedrawPending()); |
| 398 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 398 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 399 EXPECT_TRUE(client.needs_begin_impl_frame()); | 399 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 400 | 400 |
| 401 // No draw happens since the textures are acquired by the main thread. | 401 // No draw happens since the textures are acquired by the main thread. |
| 402 client.Reset(); | 402 client.Reset(); |
| 403 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 403 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 404 EXPECT_EQ(client.num_actions_(), 0); | 404 EXPECT_EQ(client.num_actions_(), 0); |
| 405 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 405 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 406 client.Reset(); | 406 client.Reset(); |
| 407 scheduler->OnBeginImplFrameDeadline(); | 407 scheduler->OnBeginImplFrameDeadline(); |
| 408 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 408 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 409 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 409 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 410 EXPECT_TRUE(scheduler->RedrawPending()); | 410 EXPECT_TRUE(scheduler->RedrawPending()); |
| 411 EXPECT_TRUE(client.needs_begin_impl_frame()); | 411 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 412 | 412 |
| 413 client.Reset(); | 413 client.Reset(); |
| 414 scheduler->SetNeedsCommit(); | 414 scheduler->SetNeedsCommit(); |
| 415 EXPECT_EQ(0, client.num_actions_()); | 415 EXPECT_EQ(0, client.num_actions_()); |
| 416 | 416 |
| 417 client.Reset(); | 417 client.Reset(); |
| 418 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 418 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 419 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 419 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| 420 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 420 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 421 | 421 |
| 422 // Commit will release the texture. | 422 // Commit will release the texture. |
| 423 client.Reset(); | 423 client.Reset(); |
| 424 scheduler->NotifyBeginMainFrameStarted(); | 424 scheduler->NotifyBeginMainFrameStarted(); |
| 425 scheduler->NotifyReadyToCommit(); | 425 scheduler->NotifyReadyToCommit(); |
| 426 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 426 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 427 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 427 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 428 EXPECT_TRUE(scheduler->RedrawPending()); | 428 EXPECT_TRUE(scheduler->RedrawPending()); |
| 429 | 429 |
| 430 // Now we can draw again after the commit happens. | 430 // Now we can draw again after the commit happens. |
| 431 client.Reset(); | 431 client.Reset(); |
| 432 scheduler->OnBeginImplFrameDeadline(); | 432 scheduler->OnBeginImplFrameDeadline(); |
| 433 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 433 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 434 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 434 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| 435 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 435 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 436 EXPECT_FALSE(scheduler->RedrawPending()); | 436 EXPECT_FALSE(scheduler->RedrawPending()); |
| 437 EXPECT_TRUE(client.needs_begin_impl_frame()); | 437 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 438 | 438 |
| 439 // Make sure we stop requesting BeginImplFrames if we don't swap. | 439 // Make sure we stop requesting BeginImplFrames if we don't swap. |
| 440 client.Reset(); | 440 client.Reset(); |
| 441 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 441 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 442 EXPECT_EQ(client.num_actions_(), 0); | 442 EXPECT_EQ(client.num_actions_(), 0); |
| 443 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 443 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 444 client.Reset(); | 444 client.Reset(); |
| 445 scheduler->OnBeginImplFrameDeadline(); | 445 scheduler->OnBeginImplFrameDeadline(); |
| 446 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 446 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 447 EXPECT_FALSE(client.needs_begin_impl_frame()); | 447 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 448 } | 448 } |
| 449 | 449 |
| 450 TEST(SchedulerTest, TextureAcquisitionCollision) { | 450 TEST(SchedulerTest, TextureAcquisitionCollision) { |
| 451 FakeSchedulerClient client; | 451 FakeSchedulerClient client; |
| 452 SchedulerSettings scheduler_settings; | 452 SchedulerSettings scheduler_settings; |
| 453 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | 453 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 454 scheduler->SetCanStart(); | 454 scheduler->SetCanStart(); |
| 455 scheduler->SetVisible(true); | 455 scheduler->SetVisible(true); |
| 456 scheduler->SetCanDraw(true); | 456 scheduler->SetCanDraw(true); |
| 457 | 457 |
| 458 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 458 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 459 InitializeOutputSurfaceAndFirstCommit(scheduler); | 459 InitializeOutputSurfaceAndFirstCommit(scheduler); |
| 460 | 460 |
| 461 client.Reset(); | 461 client.Reset(); |
| 462 scheduler->SetNeedsCommit(); | 462 scheduler->SetNeedsCommit(); |
| 463 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 463 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 464 | 464 |
| 465 client.Reset(); | 465 client.Reset(); |
| 466 scheduler->SetMainThreadNeedsLayerTextures(); | 466 scheduler->SetMainThreadNeedsLayerTextures(); |
| 467 EXPECT_SINGLE_ACTION( | 467 EXPECT_SINGLE_ACTION( |
| 468 "ScheduledActionAcquireLayerTexturesForMainThread", client); | 468 "ScheduledActionAcquireLayerTexturesForMainThread", client); |
| 469 | 469 |
| 470 client.Reset(); | 470 client.Reset(); |
| 471 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 471 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 472 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 472 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| 473 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 473 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 474 | 474 |
| 475 client.Reset(); | 475 client.Reset(); |
| 476 scheduler->OnBeginImplFrameDeadline(); | 476 scheduler->OnBeginImplFrameDeadline(); |
| 477 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 477 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 478 | 478 |
| 479 // Although the compositor cannot draw because textures are locked by main | 479 // Although the compositor cannot draw because textures are locked by main |
| 480 // thread, we continue requesting SetNeedsBeginImplFrame in anticipation of | 480 // thread, we continue requesting SetNeedsBeginFrame in anticipation of |
| 481 // the unlock. | 481 // the unlock. |
| 482 EXPECT_TRUE(client.needs_begin_impl_frame()); | 482 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 483 | 483 |
| 484 // Trigger the commit. | 484 // Trigger the commit. |
| 485 scheduler->NotifyBeginMainFrameStarted(); | 485 scheduler->NotifyBeginMainFrameStarted(); |
| 486 scheduler->NotifyReadyToCommit(); | 486 scheduler->NotifyReadyToCommit(); |
| 487 EXPECT_TRUE(client.needs_begin_impl_frame()); | 487 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 488 | 488 |
| 489 // Between commit and draw, texture acquisition for main thread delayed, | 489 // Between commit and draw, texture acquisition for main thread delayed, |
| 490 // and main thread blocks. | 490 // and main thread blocks. |
| 491 client.Reset(); | 491 client.Reset(); |
| 492 scheduler->SetMainThreadNeedsLayerTextures(); | 492 scheduler->SetMainThreadNeedsLayerTextures(); |
| 493 EXPECT_EQ(0, client.num_actions_()); | 493 EXPECT_EQ(0, client.num_actions_()); |
| 494 | 494 |
| 495 // No implicit commit is expected. | 495 // No implicit commit is expected. |
| 496 client.Reset(); | 496 client.Reset(); |
| 497 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 497 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 498 EXPECT_EQ(client.num_actions_(), 0); | 498 EXPECT_EQ(client.num_actions_(), 0); |
| 499 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 499 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 500 | 500 |
| 501 client.Reset(); | 501 client.Reset(); |
| 502 scheduler->OnBeginImplFrameDeadline(); | 502 scheduler->OnBeginImplFrameDeadline(); |
| 503 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); | 503 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); |
| 504 EXPECT_ACTION( | 504 EXPECT_ACTION( |
| 505 "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3); | 505 "ScheduledActionAcquireLayerTexturesForMainThread", client, 1, 3); |
| 506 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 2, 3); | 506 EXPECT_ACTION("SetNeedsBeginFrame", client, 2, 3); |
| 507 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 507 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 508 EXPECT_TRUE(client.needs_begin_impl_frame()); | 508 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 509 | 509 |
| 510 // The compositor should not draw because textures are locked by main | 510 // The compositor should not draw because textures are locked by main |
| 511 // thread. | 511 // thread. |
| 512 client.Reset(); | 512 client.Reset(); |
| 513 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 513 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 514 EXPECT_EQ(client.num_actions_(), 0); | 514 EXPECT_EQ(client.num_actions_(), 0); |
| 515 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 515 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 516 client.Reset(); | 516 client.Reset(); |
| 517 scheduler->OnBeginImplFrameDeadline(); | 517 scheduler->OnBeginImplFrameDeadline(); |
| 518 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 518 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 519 EXPECT_FALSE(client.needs_begin_impl_frame()); | 519 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 520 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 520 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 521 | 521 |
| 522 // The impl thread need an explicit commit from the main thread to lock | 522 // The impl thread need an explicit commit from the main thread to lock |
| 523 // the textures. | 523 // the textures. |
| 524 client.Reset(); | 524 client.Reset(); |
| 525 scheduler->SetNeedsCommit(); | 525 scheduler->SetNeedsCommit(); |
| 526 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 526 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 527 EXPECT_TRUE(client.needs_begin_impl_frame()); | 527 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 528 | 528 |
| 529 client.Reset(); | 529 client.Reset(); |
| 530 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 530 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 531 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); | 531 EXPECT_SINGLE_ACTION("ScheduledActionSendBeginMainFrame", client); |
| 532 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 532 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 533 client.Reset(); | 533 client.Reset(); |
| 534 | 534 |
| 535 // Trigger the commit, which will trigger the deadline task early. | 535 // Trigger the commit, which will trigger the deadline task early. |
| 536 scheduler->NotifyBeginMainFrameStarted(); | 536 scheduler->NotifyBeginMainFrameStarted(); |
| 537 scheduler->NotifyReadyToCommit(); | 537 scheduler->NotifyReadyToCommit(); |
| 538 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 538 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 539 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 539 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 540 EXPECT_TRUE(client.needs_begin_impl_frame()); | 540 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 541 client.Reset(); | 541 client.Reset(); |
| 542 | 542 |
| 543 // Verify we draw on the next BeginImplFrame deadline | 543 // Verify we draw on the next BeginImplFrame deadline |
| 544 scheduler->OnBeginImplFrameDeadline(); | 544 scheduler->OnBeginImplFrameDeadline(); |
| 545 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 545 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 546 EXPECT_ACTION("SetNeedsBeginImplFrame", client, 1, 2); | 546 EXPECT_ACTION("SetNeedsBeginFrame", client, 1, 2); |
| 547 EXPECT_TRUE(client.needs_begin_impl_frame()); | 547 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 548 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 548 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 549 client.Reset(); | 549 client.Reset(); |
| 550 } | 550 } |
| 551 | 551 |
| 552 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { | 552 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { |
| 553 FakeSchedulerClient client; | 553 FakeSchedulerClient client; |
| 554 SchedulerSettings scheduler_settings; | 554 SchedulerSettings scheduler_settings; |
| 555 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); | 555 Scheduler* scheduler = client.CreateScheduler(scheduler_settings); |
| 556 scheduler->SetCanStart(); | 556 scheduler->SetCanStart(); |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 EXPECT_FALSE(scheduler->ManageTilesPending()); | 986 EXPECT_FALSE(scheduler->ManageTilesPending()); |
| 987 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 987 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 988 | 988 |
| 989 // We need a BeginImplFrame where we don't swap to go idle. | 989 // We need a BeginImplFrame where we don't swap to go idle. |
| 990 client.Reset(); | 990 client.Reset(); |
| 991 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); | 991 scheduler->BeginImplFrame(BeginFrameArgs::CreateForTesting()); |
| 992 EXPECT_EQ(client.num_actions_(), 0); | 992 EXPECT_EQ(client.num_actions_(), 0); |
| 993 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); | 993 EXPECT_TRUE(scheduler->BeginImplFrameDeadlinePending()); |
| 994 client.Reset(); | 994 client.Reset(); |
| 995 scheduler->OnBeginImplFrameDeadline(); | 995 scheduler->OnBeginImplFrameDeadline(); |
| 996 EXPECT_SINGLE_ACTION("SetNeedsBeginImplFrame", client); | 996 EXPECT_SINGLE_ACTION("SetNeedsBeginFrame", client); |
| 997 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); | 997 EXPECT_FALSE(scheduler->BeginImplFrameDeadlinePending()); |
| 998 EXPECT_EQ(0, client.num_draws()); | 998 EXPECT_EQ(0, client.num_draws()); |
| 999 | 999 |
| 1000 // Now trigger a ManageTiles outside of a draw. We will then need | 1000 // Now trigger a ManageTiles outside of a draw. We will then need |
| 1001 // a begin-frame for the ManageTiles, but we don't need a draw. | 1001 // a begin-frame for the ManageTiles, but we don't need a draw. |
| 1002 client.Reset(); | 1002 client.Reset(); |
| 1003 EXPECT_FALSE(client.needs_begin_impl_frame()); | 1003 EXPECT_FALSE(client.needs_begin_impl_frame()); |
| 1004 scheduler->SetNeedsManageTiles(); | 1004 scheduler->SetNeedsManageTiles(); |
| 1005 EXPECT_TRUE(client.needs_begin_impl_frame()); | 1005 EXPECT_TRUE(client.needs_begin_impl_frame()); |
| 1006 EXPECT_TRUE(scheduler->ManageTilesPending()); | 1006 EXPECT_TRUE(scheduler->ManageTilesPending()); |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 SpinForMillis(interval * 2); | 1303 SpinForMillis(interval * 2); |
| 1304 EXPECT_GT(client.num_actions_(), actions_so_far); | 1304 EXPECT_GT(client.num_actions_(), actions_so_far); |
| 1305 EXPECT_STREQ(client.Action(client.num_actions_() - 1), | 1305 EXPECT_STREQ(client.Action(client.num_actions_() - 1), |
| 1306 "DidAnticipatedDrawTimeChange"); | 1306 "DidAnticipatedDrawTimeChange"); |
| 1307 actions_so_far = client.num_actions_(); | 1307 actions_so_far = client.num_actions_(); |
| 1308 } | 1308 } |
| 1309 } | 1309 } |
| 1310 | 1310 |
| 1311 } // namespace | 1311 } // namespace |
| 1312 } // namespace cc | 1312 } // namespace cc |
| OLD | NEW |