OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/atomic_ref_count.h" |
5 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
6 #include "base/macros.h" | 7 #include "base/macros.h" |
7 #include "cc/test/fake_content_layer_client.h" | 8 #include "cc/test/fake_content_layer_client.h" |
8 #include "cc/test/fake_picture_layer.h" | 9 #include "cc/test/fake_picture_layer.h" |
9 #include "cc/test/layer_tree_test.h" | 10 #include "cc/test/layer_tree_test.h" |
10 #include "cc/trees/proxy_impl.h" | 11 #include "cc/trees/proxy_impl.h" |
11 #include "cc/trees/proxy_main.h" | 12 #include "cc/trees/proxy_main.h" |
12 | 13 |
13 #define PROXY_MAIN_THREADED_TEST_F(TEST_FIXTURE_NAME) \ | 14 #define PROXY_MAIN_THREADED_TEST_F(TEST_FIXTURE_NAME) \ |
14 TEST_F(TEST_FIXTURE_NAME, MultiThread) { Run(true); } | 15 TEST_F(TEST_FIXTURE_NAME, MultiThread) { Run(true); } |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 274 } |
274 | 275 |
275 private: | 276 private: |
276 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsCommitWhileAnimating); | 277 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsCommitWhileAnimating); |
277 }; | 278 }; |
278 | 279 |
279 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsCommitWhileAnimating); | 280 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsCommitWhileAnimating); |
280 | 281 |
281 class ProxyMainThreadedCommitWaitsForActivation : public ProxyMainThreaded { | 282 class ProxyMainThreadedCommitWaitsForActivation : public ProxyMainThreaded { |
282 protected: | 283 protected: |
283 ProxyMainThreadedCommitWaitsForActivation() : commits_completed_(0) {} | 284 ProxyMainThreadedCommitWaitsForActivation() |
| 285 : num_commits_(0), commit_blocked_on_activation_(0) {} |
284 ~ProxyMainThreadedCommitWaitsForActivation() override {} | 286 ~ProxyMainThreadedCommitWaitsForActivation() override {} |
285 | 287 |
286 void BeginTest() override { proxy()->SetNeedsCommit(); } | 288 void BeginTest() override { proxy()->SetNeedsCommit(); } |
287 | 289 |
| 290 void DidBeginMainFrame() override { |
| 291 // Check that commit is not blocked on activation after it finishes on the |
| 292 // impl thread. |
| 293 bool commit_blocked_on_activation = |
| 294 !base::AtomicRefCountIsZero(&commit_blocked_on_activation_); |
| 295 EXPECT_FALSE(commit_blocked_on_activation); |
| 296 } |
| 297 |
288 void ScheduledActionCommit() override { | 298 void ScheduledActionCommit() override { |
289 switch (commits_completed_) { | 299 switch (num_commits_) { |
290 case 0: | 300 case 0: |
291 // The first commit does not wait for activation. Verify that the | 301 // The next commit is marked as blocked on activation. |
292 // completion event is cleared. | 302 EXPECT_TRUE(base::AtomicRefCountIsZero(&commit_blocked_on_activation_)); |
293 EXPECT_FALSE(GetProxyImplForTest()->HasCommitCompletionEvent()); | 303 base::AtomicRefCountInc(&commit_blocked_on_activation_); |
294 EXPECT_FALSE(GetProxyImplForTest()->GetNextCommitWaitsForActivation()); | |
295 | |
296 // Set next commit waits for activation and start another commit. | 304 // Set next commit waits for activation and start another commit. |
297 commits_completed_++; | |
298 PostNextCommitWaitsForActivationToMainThread(); | 305 PostNextCommitWaitsForActivationToMainThread(); |
| 306 // Fallthrough. |
| 307 case 1: |
299 PostSetNeedsCommitToMainThread(); | 308 PostSetNeedsCommitToMainThread(); |
300 break; | 309 break; |
301 case 1: | 310 } |
302 // The second commit should be held until activation. | 311 num_commits_++; |
303 EXPECT_TRUE(GetProxyImplForTest()->HasCommitCompletionEvent()); | 312 } |
304 EXPECT_TRUE(GetProxyImplForTest()->GetNextCommitWaitsForActivation()); | |
305 | 313 |
306 // Start another commit to verify that this is not held until | 314 void DidActivateSyncTree() override { |
307 // activation. | 315 switch (num_commits_) { |
308 commits_completed_++; | 316 case 2: |
309 PostSetNeedsCommitToMainThread(); | 317 // Mark commit as unblocked since activation is done. |
| 318 EXPECT_TRUE(base::AtomicRefCountIsOne(&commit_blocked_on_activation_)); |
| 319 base::AtomicRefCountDec(&commit_blocked_on_activation_); |
310 break; | 320 break; |
311 case 2: | 321 case 3: |
312 // The third commit should not wait for activation. | 322 EndTest(); |
313 EXPECT_FALSE(GetProxyImplForTest()->HasCommitCompletionEvent()); | 323 break; |
314 EXPECT_FALSE(GetProxyImplForTest()->GetNextCommitWaitsForActivation()); | |
315 | |
316 commits_completed_++; | |
317 } | 324 } |
318 } | 325 } |
319 | 326 |
320 void DidActivateSyncTree() override { | |
321 // The next_commit_waits_for_activation should have been cleared after the | |
322 // sync tree is activated. | |
323 EXPECT_FALSE(GetProxyImplForTest()->GetNextCommitWaitsForActivation()); | |
324 if (commits_completed_ == 3) | |
325 EndTest(); | |
326 } | |
327 | |
328 void AfterTest() override { | 327 void AfterTest() override { |
329 // It is safe to read commits_completed_ on the main thread now since | 328 // It is safe to read num_commits_ on the main thread now since AfterTest() |
330 // AfterTest() runs after the LayerTreeHost is destroyed and the impl thread | 329 // runs after the LayerTreeHost is destroyed and the impl thread tear down |
331 // tear down is finished. | 330 // is finished. |
332 EXPECT_EQ(3, commits_completed_); | 331 EXPECT_EQ(3, num_commits_); |
333 } | 332 } |
334 | 333 |
335 private: | 334 private: |
336 int commits_completed_; | 335 int num_commits_; |
| 336 base::AtomicRefCount commit_blocked_on_activation_; |
337 | 337 |
338 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedCommitWaitsForActivation); | 338 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedCommitWaitsForActivation); |
339 }; | 339 }; |
340 | 340 |
341 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedCommitWaitsForActivation); | 341 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedCommitWaitsForActivation); |
342 | 342 |
| 343 // Test for a corner case of main frame before activation (MFBA) and commit |
| 344 // waits for activation. If a commit (with wait for activation flag set) |
| 345 // is ready before the activation for a previous commit then the activation |
| 346 // should not signal the completion event of the second commit. |
| 347 class ProxyMainThreadedCommitWaitsForActivationMFBA : public ProxyMainThreaded { |
| 348 protected: |
| 349 ProxyMainThreadedCommitWaitsForActivationMFBA() |
| 350 : num_commits_(0), commit_blocked_on_activation_(0) {} |
| 351 ~ProxyMainThreadedCommitWaitsForActivationMFBA() override {} |
| 352 |
| 353 void InitializeSettings(LayerTreeSettings* settings) override { |
| 354 settings->main_frame_before_activation_enabled = true; |
| 355 ProxyMainThreaded::InitializeSettings(settings); |
| 356 } |
| 357 |
| 358 void BeginTest() override { proxy()->SetNeedsCommit(); } |
| 359 |
| 360 void DidBeginMainFrame() override { |
| 361 // Check that commit is not blocked on activation after it finishes on the |
| 362 // impl thread. |
| 363 bool commit_blocked_on_activation = |
| 364 !base::AtomicRefCountIsZero(&commit_blocked_on_activation_); |
| 365 EXPECT_FALSE(commit_blocked_on_activation); |
| 366 } |
| 367 |
| 368 void StartCommitOnImpl() override { |
| 369 switch (num_commits_) { |
| 370 case 0: |
| 371 // Block activation until next commit is ready. |
| 372 GetProxyImplForTest()->BlockNotifyReadyToActivateForTesting(true); |
| 373 break; |
| 374 case 1: |
| 375 // After the second commit is ready unblock activation. |
| 376 if (num_commits_ == 1) { |
| 377 ImplThreadTaskRunner()->PostTask( |
| 378 FROM_HERE, |
| 379 base::Bind( |
| 380 &ProxyImplForTest::BlockNotifyReadyToActivateForTesting, |
| 381 base::Unretained(GetProxyImplForTest()), false)); |
| 382 } |
| 383 break; |
| 384 } |
| 385 } |
| 386 |
| 387 void ScheduledActionCommit() override { |
| 388 switch (num_commits_) { |
| 389 case 0: |
| 390 // The next commit is marked as blocked on activation. |
| 391 EXPECT_TRUE(base::AtomicRefCountIsZero(&commit_blocked_on_activation_)); |
| 392 base::AtomicRefCountInc(&commit_blocked_on_activation_); |
| 393 // Set next commit waits for activation and start another commit. |
| 394 PostNextCommitWaitsForActivationToMainThread(); |
| 395 // Fallthrough. |
| 396 case 1: |
| 397 PostSetNeedsCommitToMainThread(); |
| 398 break; |
| 399 } |
| 400 num_commits_++; |
| 401 } |
| 402 |
| 403 void DidActivateSyncTree() override { |
| 404 switch (num_commits_) { |
| 405 case 2: |
| 406 // Mark commit as unblocked since activation is done. |
| 407 EXPECT_TRUE(base::AtomicRefCountIsOne(&commit_blocked_on_activation_)); |
| 408 base::AtomicRefCountDec(&commit_blocked_on_activation_); |
| 409 break; |
| 410 case 3: |
| 411 EndTest(); |
| 412 break; |
| 413 } |
| 414 } |
| 415 |
| 416 void AfterTest() override { |
| 417 // It is safe to read num_commits_ on the main thread now since AfterTest() |
| 418 // runs after the LayerTreeHost is destroyed and the impl thread tear down |
| 419 // is finished. |
| 420 EXPECT_EQ(3, num_commits_); |
| 421 } |
| 422 |
| 423 private: |
| 424 int num_commits_; |
| 425 base::AtomicRefCount commit_blocked_on_activation_; |
| 426 |
| 427 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedCommitWaitsForActivationMFBA); |
| 428 }; |
| 429 |
| 430 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedCommitWaitsForActivationMFBA); |
| 431 |
343 } // namespace cc | 432 } // namespace cc |
OLD | NEW |