| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/scheduler/scheduler.h" | 5 #include "cc/scheduler/scheduler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 client.Reset(); | 239 client.Reset(); |
| 240 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 240 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 241 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); | 241 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 2); |
| 242 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); | 242 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 243 EXPECT_FALSE(scheduler->RedrawPending()); | 243 EXPECT_FALSE(scheduler->RedrawPending()); |
| 244 EXPECT_FALSE(client.needs_begin_frame()); | 244 EXPECT_FALSE(client.needs_begin_frame()); |
| 245 | 245 |
| 246 client.Reset(); | 246 client.Reset(); |
| 247 scheduler->SetMainThreadNeedsLayerTextures(); | 247 scheduler->SetMainThreadNeedsLayerTextures(); |
| 248 EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 248 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
| 249 client, | 249 client); |
| 250 0, | |
| 251 3); | |
| 252 // A commit was started by SetMainThreadNeedsLayerTextures(). | |
| 253 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 3); | |
| 254 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); | |
| 255 | 250 |
| 256 // We should request a BeginFrame in anticipation of a draw. | 251 // We should request a BeginFrame in anticipation of a draw. |
| 257 client.Reset(); | 252 client.Reset(); |
| 258 scheduler->SetNeedsRedraw(); | 253 scheduler->SetNeedsRedraw(); |
| 259 EXPECT_TRUE(scheduler->RedrawPending()); | 254 EXPECT_TRUE(scheduler->RedrawPending()); |
| 255 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 260 EXPECT_TRUE(client.needs_begin_frame()); | 256 EXPECT_TRUE(client.needs_begin_frame()); |
| 261 | 257 |
| 262 // No draw happens since the textures are acquired by the main thread. | 258 // No draw happens since the textures are acquired by the main thread. |
| 263 client.Reset(); | 259 client.Reset(); |
| 264 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 260 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 265 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); | 261 EXPECT_SINGLE_ACTION("SetNeedsBeginFrameOnImplThread", client); |
| 266 EXPECT_TRUE(scheduler->RedrawPending()); | 262 EXPECT_TRUE(scheduler->RedrawPending()); |
| 267 EXPECT_TRUE(client.needs_begin_frame()); | 263 EXPECT_TRUE(client.needs_begin_frame()); |
| 268 | 264 |
| 265 scheduler->SetNeedsCommit(); |
| 266 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 0, 2); |
| 267 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 1, 2); |
| 268 EXPECT_TRUE(client.needs_begin_frame()); |
| 269 |
| 269 // Commit will release the texture. | 270 // Commit will release the texture. |
| 270 client.Reset(); | 271 client.Reset(); |
| 271 scheduler->FinishCommit(); | 272 scheduler->FinishCommit(); |
| 272 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); | 273 EXPECT_SINGLE_ACTION("ScheduledActionCommit", client); |
| 273 EXPECT_TRUE(scheduler->RedrawPending()); | 274 EXPECT_TRUE(scheduler->RedrawPending()); |
| 274 EXPECT_TRUE(client.needs_begin_frame()); | 275 EXPECT_TRUE(client.needs_begin_frame()); |
| 275 | 276 |
| 276 // Now we can draw again after the commit happens. | 277 // Now we can draw again after the commit happens. |
| 277 client.Reset(); | 278 client.Reset(); |
| 278 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 279 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 scheduler->FinishCommit(); | 316 scheduler->FinishCommit(); |
| 316 EXPECT_TRUE(client.needs_begin_frame()); | 317 EXPECT_TRUE(client.needs_begin_frame()); |
| 317 client.Reset(); | 318 client.Reset(); |
| 318 | 319 |
| 319 // Between commit and draw, texture acquisition for main thread delayed, | 320 // Between commit and draw, texture acquisition for main thread delayed, |
| 320 // and main thread blocks. | 321 // and main thread blocks. |
| 321 scheduler->SetMainThreadNeedsLayerTextures(); | 322 scheduler->SetMainThreadNeedsLayerTextures(); |
| 322 EXPECT_EQ(0, client.num_actions_()); | 323 EXPECT_EQ(0, client.num_actions_()); |
| 323 client.Reset(); | 324 client.Reset(); |
| 324 | 325 |
| 325 // Once compositor draw complete, the delayed texture acquisition fires. | 326 // No implicit commit is expected. |
| 326 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); | 327 scheduler->BeginFrame(BeginFrameArgs::CreateForTesting()); |
| 327 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); | 328 EXPECT_ACTION("ScheduledActionDrawAndSwapIfPossible", client, 0, 3); |
| 328 EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 329 EXPECT_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
| 329 client, | 330 client, |
| 330 1, | 331 1, |
| 331 3); | 332 3); |
| 332 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 2, 3); | 333 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 2, 3); |
| 333 client.Reset(); | 334 client.Reset(); |
| 335 |
| 336 // Compositor not scheduled to draw because textures are locked by main |
| 337 // thread. |
| 338 EXPECT_FALSE(client.needs_begin_frame()); |
| 339 |
| 340 // Needs an explicit commit from the main thread. |
| 341 scheduler->SetNeedsCommit(); |
| 342 EXPECT_ACTION("ScheduledActionSendBeginFrameToMainThread", client, 0, 2); |
| 343 EXPECT_ACTION("SetNeedsBeginFrameOnImplThread", client, 1, 2); |
| 344 client.Reset(); |
| 345 |
| 346 // Trigger the commit |
| 347 scheduler->FinishCommit(); |
| 348 EXPECT_TRUE(client.needs_begin_frame()); |
| 334 } | 349 } |
| 335 | 350 |
| 336 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { | 351 TEST(SchedulerTest, VisibilitySwitchWithTextureAcquisition) { |
| 337 FakeSchedulerClient client; | 352 FakeSchedulerClient client; |
| 338 SchedulerSettings default_scheduler_settings; | 353 SchedulerSettings default_scheduler_settings; |
| 339 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); | 354 Scheduler* scheduler = client.CreateScheduler(default_scheduler_settings); |
| 340 scheduler->SetCanStart(); | 355 scheduler->SetCanStart(); |
| 341 scheduler->SetVisible(true); | 356 scheduler->SetVisible(true); |
| 342 scheduler->SetCanDraw(true); | 357 scheduler->SetCanDraw(true); |
| 343 | 358 |
| 344 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); | 359 EXPECT_SINGLE_ACTION("ScheduledActionBeginOutputSurfaceCreation", client); |
| 345 client.Reset(); | 360 client.Reset(); |
| 346 scheduler->DidCreateAndInitializeOutputSurface(); | 361 scheduler->DidCreateAndInitializeOutputSurface(); |
| 347 | 362 |
| 348 scheduler->SetNeedsCommit(); | 363 scheduler->SetNeedsCommit(); |
| 349 scheduler->FinishCommit(); | 364 scheduler->FinishCommit(); |
| 350 scheduler->SetMainThreadNeedsLayerTextures(); | 365 scheduler->SetMainThreadNeedsLayerTextures(); |
| 366 scheduler->SetNeedsCommit(); |
| 351 client.Reset(); | 367 client.Reset(); |
| 352 // Verify that pending texture acquisition fires when visibility | 368 // Verify that pending texture acquisition fires when visibility |
| 353 // is lost in order to avoid a deadlock. | 369 // is lost in order to avoid a deadlock. |
| 354 scheduler->SetVisible(false); | 370 scheduler->SetVisible(false); |
| 355 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", | 371 EXPECT_SINGLE_ACTION("ScheduledActionAcquireLayerTexturesForMainThread", |
| 356 client); | 372 client); |
| 357 client.Reset(); | 373 client.Reset(); |
| 358 | 374 |
| 359 // Regaining visibility with textures acquired by main thread while | 375 // Regaining visibility with textures acquired by main thread while |
| 360 // compositor is waiting for first draw should result in a request | 376 // compositor is waiting for first draw should result in a request |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 607 |
| 592 // Get the compositor to do a ScheduledActionDrawAndSwapForced. | 608 // Get the compositor to do a ScheduledActionDrawAndSwapForced. |
| 593 scheduler->SetCanDraw(true); | 609 scheduler->SetCanDraw(true); |
| 594 scheduler->SetNeedsRedraw(); | 610 scheduler->SetNeedsRedraw(); |
| 595 scheduler->SetNeedsForcedRedraw(); | 611 scheduler->SetNeedsForcedRedraw(); |
| 596 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapForced")); | 612 EXPECT_TRUE(client.HasAction("ScheduledActionDrawAndSwapForced")); |
| 597 } | 613 } |
| 598 | 614 |
| 599 } // namespace | 615 } // namespace |
| 600 } // namespace cc | 616 } // namespace cc |
| OLD | NEW |