| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/layers/texture_layer.h" | 5 #include "cc/layers/texture_layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 class MockMailboxCallback { | 95 class MockMailboxCallback { |
| 96 public: | 96 public: |
| 97 MOCK_METHOD3(Release, | 97 MOCK_METHOD3(Release, |
| 98 void(const gpu::Mailbox& mailbox, | 98 void(const gpu::Mailbox& mailbox, |
| 99 uint32 sync_point, | 99 uint32 sync_point, |
| 100 bool lost_resource)); | 100 bool lost_resource)); |
| 101 MOCK_METHOD3(Release2, | 101 MOCK_METHOD3(Release2, |
| 102 void(base::SharedMemory* shared_memory, | 102 void(base::SharedMemory* shared_memory, |
| 103 uint32 sync_point, | 103 uint32 sync_point, |
| 104 bool lost_resource)); | 104 bool lost_resource)); |
| 105 MOCK_METHOD4(ReleaseImpl, |
| 106 void(const gpu::Mailbox& mailbox, |
| 107 uint32 sync_point, |
| 108 bool lost_resource, |
| 109 BlockingTaskRunner* main_thread_task_runner)); |
| 110 MOCK_METHOD4(ReleaseImpl2, |
| 111 void(base::SharedMemory* shared_memory, |
| 112 uint32 sync_point, |
| 113 bool lost_resource, |
| 114 BlockingTaskRunner* main_thread_task_runner)); |
| 105 }; | 115 }; |
| 106 | 116 |
| 107 struct CommonMailboxObjects { | 117 struct CommonMailboxObjects { |
| 108 CommonMailboxObjects() | 118 CommonMailboxObjects() |
| 109 : mailbox_name1_(MailboxFromChar('1')), | 119 : mailbox_name1_(MailboxFromChar('1')), |
| 110 mailbox_name2_(MailboxFromChar('2')), | 120 mailbox_name2_(MailboxFromChar('2')), |
| 111 sync_point1_(1), | 121 sync_point1_(1), |
| 112 sync_point2_(2), | 122 sync_point2_(2), |
| 113 shared_memory_(new base::SharedMemory) { | 123 shared_memory_(new base::SharedMemory) { |
| 114 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, | 124 release_mailbox1_ = base::Bind(&MockMailboxCallback::Release, |
| 115 base::Unretained(&mock_callback_), | 125 base::Unretained(&mock_callback_), |
| 116 mailbox_name1_); | 126 mailbox_name1_); |
| 117 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, | 127 release_mailbox2_ = base::Bind(&MockMailboxCallback::Release, |
| 118 base::Unretained(&mock_callback_), | 128 base::Unretained(&mock_callback_), |
| 119 mailbox_name2_); | 129 mailbox_name2_); |
| 130 release_mailbox1_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl, |
| 131 base::Unretained(&mock_callback_), |
| 132 mailbox_name1_); |
| 133 release_mailbox2_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl, |
| 134 base::Unretained(&mock_callback_), |
| 135 mailbox_name2_); |
| 120 const uint32 arbitrary_target1 = GL_TEXTURE_2D; | 136 const uint32 arbitrary_target1 = GL_TEXTURE_2D; |
| 121 const uint32 arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES; | 137 const uint32 arbitrary_target2 = GL_TEXTURE_EXTERNAL_OES; |
| 122 mailbox1_ = TextureMailbox(mailbox_name1_, arbitrary_target1, sync_point1_); | 138 mailbox1_ = TextureMailbox(mailbox_name1_, arbitrary_target1, sync_point1_); |
| 123 mailbox2_ = TextureMailbox(mailbox_name2_, arbitrary_target2, sync_point2_); | 139 mailbox2_ = TextureMailbox(mailbox_name2_, arbitrary_target2, sync_point2_); |
| 124 gfx::Size size(128, 128); | 140 gfx::Size size(128, 128); |
| 125 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); | 141 EXPECT_TRUE(shared_memory_->CreateAndMapAnonymous(4 * size.GetArea())); |
| 126 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, | 142 release_mailbox3_ = base::Bind(&MockMailboxCallback::Release2, |
| 127 base::Unretained(&mock_callback_), | 143 base::Unretained(&mock_callback_), |
| 128 shared_memory_.get()); | 144 shared_memory_.get()); |
| 145 release_mailbox3_impl_ = base::Bind(&MockMailboxCallback::ReleaseImpl2, |
| 146 base::Unretained(&mock_callback_), |
| 147 shared_memory_.get()); |
| 129 mailbox3_ = TextureMailbox(shared_memory_.get(), size); | 148 mailbox3_ = TextureMailbox(shared_memory_.get(), size); |
| 130 } | 149 } |
| 131 | 150 |
| 132 gpu::Mailbox mailbox_name1_; | 151 gpu::Mailbox mailbox_name1_; |
| 133 gpu::Mailbox mailbox_name2_; | 152 gpu::Mailbox mailbox_name2_; |
| 134 MockMailboxCallback mock_callback_; | 153 MockMailboxCallback mock_callback_; |
| 135 ReleaseCallback release_mailbox1_; | 154 ReleaseCallback release_mailbox1_; |
| 136 ReleaseCallback release_mailbox2_; | 155 ReleaseCallback release_mailbox2_; |
| 137 ReleaseCallback release_mailbox3_; | 156 ReleaseCallback release_mailbox3_; |
| 157 ReleaseCallbackImpl release_mailbox1_impl_; |
| 158 ReleaseCallbackImpl release_mailbox2_impl_; |
| 159 ReleaseCallbackImpl release_mailbox3_impl_; |
| 138 TextureMailbox mailbox1_; | 160 TextureMailbox mailbox1_; |
| 139 TextureMailbox mailbox2_; | 161 TextureMailbox mailbox2_; |
| 140 TextureMailbox mailbox3_; | 162 TextureMailbox mailbox3_; |
| 141 uint32 sync_point1_; | 163 uint32 sync_point1_; |
| 142 uint32 sync_point2_; | 164 uint32 sync_point2_; |
| 143 scoped_ptr<base::SharedMemory> shared_memory_; | 165 scoped_ptr<base::SharedMemory> shared_memory_; |
| 144 }; | 166 }; |
| 145 | 167 |
| 146 class TextureLayerTest : public testing::Test { | 168 class TextureLayerTest : public testing::Test { |
| 147 public: | 169 public: |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); | 392 EXPECT_CALL(*layer_tree_host_, SetNeedsCommit()).Times(AtLeast(1)); |
| 371 test_layer->SetTextureMailboxWithoutReleaseCallback(mailbox2); | 393 test_layer->SetTextureMailboxWithoutReleaseCallback(mailbox2); |
| 372 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 394 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 373 } | 395 } |
| 374 | 396 |
| 375 class TextureLayerMailboxHolderTest : public TextureLayerTest { | 397 class TextureLayerMailboxHolderTest : public TextureLayerTest { |
| 376 public: | 398 public: |
| 377 TextureLayerMailboxHolderTest() | 399 TextureLayerMailboxHolderTest() |
| 378 : main_thread_("MAIN") { | 400 : main_thread_("MAIN") { |
| 379 main_thread_.Start(); | 401 main_thread_.Start(); |
| 402 main_thread_task_runner_ = |
| 403 BlockingTaskRunner::Create(main_thread_.message_loop_proxy()); |
| 380 } | 404 } |
| 381 | 405 |
| 382 void Wait(const base::Thread& thread) { | 406 void Wait(const base::Thread& thread) { |
| 383 bool manual_reset = false; | 407 bool manual_reset = false; |
| 384 bool initially_signaled = false; | 408 bool initially_signaled = false; |
| 385 base::WaitableEvent event(manual_reset, initially_signaled); | 409 base::WaitableEvent event(manual_reset, initially_signaled); |
| 386 thread.message_loop()->PostTask( | 410 thread.message_loop()->PostTask( |
| 387 FROM_HERE, | 411 FROM_HERE, |
| 388 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); | 412 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event))); |
| 389 event.Wait(); | 413 event.Wait(); |
| 390 } | 414 } |
| 391 | 415 |
| 392 void CreateMainRef() { | 416 void CreateMainRef() { |
| 393 main_ref_ = TestMailboxHolder::Create( | 417 main_ref_ = TestMailboxHolder::Create( |
| 394 test_data_.mailbox1_, | 418 test_data_.mailbox1_, |
| 395 SingleReleaseCallback::Create(test_data_.release_mailbox1_)).Pass(); | 419 SingleReleaseCallback::Create(test_data_.release_mailbox1_)).Pass(); |
| 396 } | 420 } |
| 397 | 421 |
| 398 void ReleaseMainRef() { | 422 void ReleaseMainRef() { |
| 399 main_ref_.reset(); | 423 main_ref_.reset(); |
| 400 } | 424 } |
| 401 | 425 |
| 402 void CreateImplRef(scoped_ptr<SingleReleaseCallback>* impl_ref) { | 426 void CreateImplRef(scoped_ptr<SingleReleaseCallbackImpl>* impl_ref) { |
| 403 *impl_ref = main_ref_->holder()->GetCallbackForImplThread(); | 427 *impl_ref = main_ref_->holder()->GetCallbackForImplThread(); |
| 404 } | 428 } |
| 405 | 429 |
| 406 void CapturePostTasksAndWait(base::WaitableEvent* begin_capture, | 430 void CapturePostTasksAndWait(base::WaitableEvent* begin_capture, |
| 407 base::WaitableEvent* wait_for_capture, | 431 base::WaitableEvent* wait_for_capture, |
| 408 base::WaitableEvent* stop_capture) { | 432 base::WaitableEvent* stop_capture) { |
| 409 begin_capture->Wait(); | 433 begin_capture->Wait(); |
| 410 BlockingTaskRunner::CapturePostTasks capture; | 434 BlockingTaskRunner::CapturePostTasks capture( |
| 435 main_thread_task_runner_.get()); |
| 411 wait_for_capture->Signal(); | 436 wait_for_capture->Signal(); |
| 412 stop_capture->Wait(); | 437 stop_capture->Wait(); |
| 413 } | 438 } |
| 414 | 439 |
| 415 protected: | 440 protected: |
| 416 scoped_ptr<TestMailboxHolder::MainThreadReference> | 441 scoped_ptr<TestMailboxHolder::MainThreadReference> |
| 417 main_ref_; | 442 main_ref_; |
| 418 base::Thread main_thread_; | 443 base::Thread main_thread_; |
| 444 scoped_ptr<BlockingTaskRunner> main_thread_task_runner_; |
| 419 CommonMailboxObjects test_data_; | 445 CommonMailboxObjects test_data_; |
| 420 }; | 446 }; |
| 421 | 447 |
| 422 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) { | 448 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_BothReleaseThenMain) { |
| 423 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 449 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
| 424 ASSERT_TRUE(test_layer.get()); | 450 ASSERT_TRUE(test_layer.get()); |
| 425 | 451 |
| 426 main_thread_.message_loop()->PostTask( | 452 main_thread_.message_loop()->PostTask( |
| 427 FROM_HERE, | 453 FROM_HERE, |
| 428 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 454 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 429 base::Unretained(this))); | 455 base::Unretained(this))); |
| 430 | 456 |
| 431 Wait(main_thread_); | 457 Wait(main_thread_); |
| 432 | 458 |
| 433 // The texture layer is attached to compositor1, and passes a reference to its | 459 // The texture layer is attached to compositor1, and passes a reference to its |
| 434 // impl tree. | 460 // impl tree. |
| 435 scoped_ptr<SingleReleaseCallback> compositor1; | 461 scoped_ptr<SingleReleaseCallbackImpl> compositor1; |
| 436 main_thread_.message_loop()->PostTask( | 462 main_thread_.message_loop()->PostTask( |
| 437 FROM_HERE, | 463 FROM_HERE, |
| 438 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 464 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 439 base::Unretained(this), | 465 base::Unretained(this), |
| 440 &compositor1)); | 466 &compositor1)); |
| 441 | 467 |
| 442 // Then the texture layer is removed and attached to compositor2, and passes a | 468 // Then the texture layer is removed and attached to compositor2, and passes a |
| 443 // reference to its impl tree. | 469 // reference to its impl tree. |
| 444 scoped_ptr<SingleReleaseCallback> compositor2; | 470 scoped_ptr<SingleReleaseCallbackImpl> compositor2; |
| 445 main_thread_.message_loop()->PostTask( | 471 main_thread_.message_loop()->PostTask( |
| 446 FROM_HERE, | 472 FROM_HERE, |
| 447 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 473 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 448 base::Unretained(this), | 474 base::Unretained(this), |
| 449 &compositor2)); | 475 &compositor2)); |
| 450 | 476 |
| 451 Wait(main_thread_); | 477 Wait(main_thread_); |
| 452 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 478 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 453 | 479 |
| 454 // The compositors both destroy their impl trees before the main thread layer | 480 // The compositors both destroy their impl trees before the main thread layer |
| 455 // is destroyed. | 481 // is destroyed. |
| 456 compositor1->Run(100, false); | 482 compositor1->Run(100, false, main_thread_task_runner_.get()); |
| 457 compositor2->Run(200, false); | 483 compositor2->Run(200, false, main_thread_task_runner_.get()); |
| 458 | 484 |
| 459 Wait(main_thread_); | 485 Wait(main_thread_); |
| 460 | 486 |
| 461 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); | 487 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
| 462 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 488 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 463 | 489 |
| 464 // The main thread ref is the last one, so the mailbox is released back to the | 490 // The main thread ref is the last one, so the mailbox is released back to the |
| 465 // embedder, with the last sync point provided by the impl trees. | 491 // embedder, with the last sync point provided by the impl trees. |
| 466 EXPECT_CALL(test_data_.mock_callback_, | 492 EXPECT_CALL(test_data_.mock_callback_, |
| 467 Release(test_data_.mailbox_name1_, 200, false)).Times(1); | 493 Release(test_data_.mailbox_name1_, 200, false)).Times(1); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 480 | 506 |
| 481 main_thread_.message_loop()->PostTask( | 507 main_thread_.message_loop()->PostTask( |
| 482 FROM_HERE, | 508 FROM_HERE, |
| 483 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 509 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 484 base::Unretained(this))); | 510 base::Unretained(this))); |
| 485 | 511 |
| 486 Wait(main_thread_); | 512 Wait(main_thread_); |
| 487 | 513 |
| 488 // The texture layer is attached to compositor1, and passes a reference to its | 514 // The texture layer is attached to compositor1, and passes a reference to its |
| 489 // impl tree. | 515 // impl tree. |
| 490 scoped_ptr<SingleReleaseCallback> compositor1; | 516 scoped_ptr<SingleReleaseCallbackImpl> compositor1; |
| 491 main_thread_.message_loop()->PostTask( | 517 main_thread_.message_loop()->PostTask( |
| 492 FROM_HERE, | 518 FROM_HERE, |
| 493 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 519 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 494 base::Unretained(this), | 520 base::Unretained(this), |
| 495 &compositor1)); | 521 &compositor1)); |
| 496 | 522 |
| 497 // Then the texture layer is removed and attached to compositor2, and passes a | 523 // Then the texture layer is removed and attached to compositor2, and passes a |
| 498 // reference to its impl tree. | 524 // reference to its impl tree. |
| 499 scoped_ptr<SingleReleaseCallback> compositor2; | 525 scoped_ptr<SingleReleaseCallbackImpl> compositor2; |
| 500 main_thread_.message_loop()->PostTask( | 526 main_thread_.message_loop()->PostTask( |
| 501 FROM_HERE, | 527 FROM_HERE, |
| 502 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 528 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 503 base::Unretained(this), | 529 base::Unretained(this), |
| 504 &compositor2)); | 530 &compositor2)); |
| 505 | 531 |
| 506 Wait(main_thread_); | 532 Wait(main_thread_); |
| 507 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 533 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 508 | 534 |
| 509 // One compositor destroys their impl tree. | 535 // One compositor destroys their impl tree. |
| 510 compositor1->Run(100, false); | 536 compositor1->Run(100, false, main_thread_task_runner_.get()); |
| 511 | 537 |
| 512 // Then the main thread reference is destroyed. | 538 // Then the main thread reference is destroyed. |
| 513 main_thread_.message_loop()->PostTask( | 539 main_thread_.message_loop()->PostTask( |
| 514 FROM_HERE, | 540 FROM_HERE, |
| 515 base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, | 541 base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
| 516 base::Unretained(this))); | 542 base::Unretained(this))); |
| 517 | 543 |
| 518 Wait(main_thread_); | 544 Wait(main_thread_); |
| 519 | 545 |
| 520 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); | 546 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
| 521 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 547 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 522 | 548 |
| 523 // The second impl reference is destroyed last, causing the mailbox to be | 549 // The second impl reference is destroyed last, causing the mailbox to be |
| 524 // released back to the embedder with the last sync point from the impl tree. | 550 // released back to the embedder with the last sync point from the impl tree. |
| 525 EXPECT_CALL(test_data_.mock_callback_, | 551 EXPECT_CALL(test_data_.mock_callback_, |
| 526 Release(test_data_.mailbox_name1_, 200, true)).Times(1); | 552 Release(test_data_.mailbox_name1_, 200, true)).Times(1); |
| 527 | 553 |
| 528 compositor2->Run(200, true); | 554 compositor2->Run(200, true, main_thread_task_runner_.get()); |
| 529 Wait(main_thread_); | 555 Wait(main_thread_); |
| 530 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 556 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 531 } | 557 } |
| 532 | 558 |
| 533 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) { | 559 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_MainReleasedFirst) { |
| 534 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 560 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
| 535 ASSERT_TRUE(test_layer.get()); | 561 ASSERT_TRUE(test_layer.get()); |
| 536 | 562 |
| 537 main_thread_.message_loop()->PostTask( | 563 main_thread_.message_loop()->PostTask( |
| 538 FROM_HERE, | 564 FROM_HERE, |
| 539 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 565 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 540 base::Unretained(this))); | 566 base::Unretained(this))); |
| 541 | 567 |
| 542 Wait(main_thread_); | 568 Wait(main_thread_); |
| 543 | 569 |
| 544 // The texture layer is attached to compositor1, and passes a reference to its | 570 // The texture layer is attached to compositor1, and passes a reference to its |
| 545 // impl tree. | 571 // impl tree. |
| 546 scoped_ptr<SingleReleaseCallback> compositor1; | 572 scoped_ptr<SingleReleaseCallbackImpl> compositor1; |
| 547 main_thread_.message_loop()->PostTask( | 573 main_thread_.message_loop()->PostTask( |
| 548 FROM_HERE, | 574 FROM_HERE, |
| 549 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 575 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 550 base::Unretained(this), | 576 base::Unretained(this), |
| 551 &compositor1)); | 577 &compositor1)); |
| 552 | 578 |
| 553 // Then the texture layer is removed and attached to compositor2, and passes a | 579 // Then the texture layer is removed and attached to compositor2, and passes a |
| 554 // reference to its impl tree. | 580 // reference to its impl tree. |
| 555 scoped_ptr<SingleReleaseCallback> compositor2; | 581 scoped_ptr<SingleReleaseCallbackImpl> compositor2; |
| 556 main_thread_.message_loop()->PostTask( | 582 main_thread_.message_loop()->PostTask( |
| 557 FROM_HERE, | 583 FROM_HERE, |
| 558 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 584 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 559 base::Unretained(this), | 585 base::Unretained(this), |
| 560 &compositor2)); | 586 &compositor2)); |
| 561 | 587 |
| 562 Wait(main_thread_); | 588 Wait(main_thread_); |
| 563 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 589 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 564 | 590 |
| 565 // The main thread reference is destroyed first. | 591 // The main thread reference is destroyed first. |
| 566 main_thread_.message_loop()->PostTask( | 592 main_thread_.message_loop()->PostTask( |
| 567 FROM_HERE, | 593 FROM_HERE, |
| 568 base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, | 594 base::Bind(&TextureLayerMailboxHolderTest::ReleaseMainRef, |
| 569 base::Unretained(this))); | 595 base::Unretained(this))); |
| 570 | 596 |
| 571 // One compositor destroys their impl tree. | 597 // One compositor destroys their impl tree. |
| 572 compositor2->Run(200, false); | 598 compositor2->Run(200, false, main_thread_task_runner_.get()); |
| 573 | 599 |
| 574 Wait(main_thread_); | 600 Wait(main_thread_); |
| 575 | 601 |
| 576 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); | 602 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); |
| 577 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 603 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 578 | 604 |
| 579 // The second impl reference is destroyed last, causing the mailbox to be | 605 // The second impl reference is destroyed last, causing the mailbox to be |
| 580 // released back to the embedder with the last sync point from the impl tree. | 606 // released back to the embedder with the last sync point from the impl tree. |
| 581 EXPECT_CALL(test_data_.mock_callback_, | 607 EXPECT_CALL(test_data_.mock_callback_, |
| 582 Release(test_data_.mailbox_name1_, 100, true)).Times(1); | 608 Release(test_data_.mailbox_name1_, 100, true)).Times(1); |
| 583 | 609 |
| 584 compositor1->Run(100, true); | 610 compositor1->Run(100, true, main_thread_task_runner_.get()); |
| 585 Wait(main_thread_); | 611 Wait(main_thread_); |
| 586 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 612 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 587 } | 613 } |
| 588 | 614 |
| 589 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) { | 615 TEST_F(TextureLayerMailboxHolderTest, TwoCompositors_SecondImplRefShortcut) { |
| 590 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); | 616 scoped_refptr<TextureLayer> test_layer = TextureLayer::CreateForMailbox(NULL); |
| 591 ASSERT_TRUE(test_layer.get()); | 617 ASSERT_TRUE(test_layer.get()); |
| 592 | 618 |
| 593 main_thread_.message_loop()->PostTask( | 619 main_thread_.message_loop()->PostTask( |
| 594 FROM_HERE, | 620 FROM_HERE, |
| 595 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, | 621 base::Bind(&TextureLayerMailboxHolderTest::CreateMainRef, |
| 596 base::Unretained(this))); | 622 base::Unretained(this))); |
| 597 | 623 |
| 598 Wait(main_thread_); | 624 Wait(main_thread_); |
| 599 | 625 |
| 600 // The texture layer is attached to compositor1, and passes a reference to its | 626 // The texture layer is attached to compositor1, and passes a reference to its |
| 601 // impl tree. | 627 // impl tree. |
| 602 scoped_ptr<SingleReleaseCallback> compositor1; | 628 scoped_ptr<SingleReleaseCallbackImpl> compositor1; |
| 603 main_thread_.message_loop()->PostTask( | 629 main_thread_.message_loop()->PostTask( |
| 604 FROM_HERE, | 630 FROM_HERE, |
| 605 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 631 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 606 base::Unretained(this), | 632 base::Unretained(this), |
| 607 &compositor1)); | 633 &compositor1)); |
| 608 | 634 |
| 609 // Then the texture layer is removed and attached to compositor2, and passes a | 635 // Then the texture layer is removed and attached to compositor2, and passes a |
| 610 // reference to its impl tree. | 636 // reference to its impl tree. |
| 611 scoped_ptr<SingleReleaseCallback> compositor2; | 637 scoped_ptr<SingleReleaseCallbackImpl> compositor2; |
| 612 main_thread_.message_loop()->PostTask( | 638 main_thread_.message_loop()->PostTask( |
| 613 FROM_HERE, | 639 FROM_HERE, |
| 614 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, | 640 base::Bind(&TextureLayerMailboxHolderTest::CreateImplRef, |
| 615 base::Unretained(this), | 641 base::Unretained(this), |
| 616 &compositor2)); | 642 &compositor2)); |
| 617 | 643 |
| 618 Wait(main_thread_); | 644 Wait(main_thread_); |
| 619 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 645 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 620 | 646 |
| 621 // The main thread reference is destroyed first. | 647 // The main thread reference is destroyed first. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 639 FROM_HERE, | 665 FROM_HERE, |
| 640 base::Bind(&TextureLayerMailboxHolderTest::CapturePostTasksAndWait, | 666 base::Bind(&TextureLayerMailboxHolderTest::CapturePostTasksAndWait, |
| 641 base::Unretained(this), | 667 base::Unretained(this), |
| 642 &begin_capture, | 668 &begin_capture, |
| 643 &wait_for_capture, | 669 &wait_for_capture, |
| 644 &stop_capture)); | 670 &stop_capture)); |
| 645 | 671 |
| 646 // Before the main thread capturing starts, one compositor destroys their | 672 // Before the main thread capturing starts, one compositor destroys their |
| 647 // impl reference. Since capturing did not start, this gets post-tasked to | 673 // impl reference. Since capturing did not start, this gets post-tasked to |
| 648 // the main thread. | 674 // the main thread. |
| 649 compositor1->Run(100, false); | 675 compositor1->Run(100, false, main_thread_task_runner_.get()); |
| 650 | 676 |
| 651 // Start capturing on the main thread. | 677 // Start capturing on the main thread. |
| 652 begin_capture.Signal(); | 678 begin_capture.Signal(); |
| 653 wait_for_capture.Wait(); | 679 wait_for_capture.Wait(); |
| 654 | 680 |
| 655 // Meanwhile, the second compositor released its impl reference, but this task | 681 // Meanwhile, the second compositor released its impl reference, but this task |
| 656 // gets shortcutted directly to the main thread. This means the reference is | 682 // gets shortcutted directly to the main thread. This means the reference is |
| 657 // released before compositor1, whose reference will be released later when | 683 // released before compositor1, whose reference will be released later when |
| 658 // the post-task is serviced. But since it was destroyed _on the impl thread_ | 684 // the post-task is serviced. But since it was destroyed _on the impl thread_ |
| 659 // last, its sync point values should be used. | 685 // last, its sync point values should be used. |
| 660 compositor2->Run(200, true); | 686 compositor2->Run(200, true, main_thread_task_runner_.get()); |
| 661 | 687 |
| 662 stop_capture.Signal(); | 688 stop_capture.Signal(); |
| 663 Wait(main_thread_); | 689 Wait(main_thread_); |
| 664 | 690 |
| 665 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 691 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 666 } | 692 } |
| 667 | 693 |
| 668 class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { | 694 class TextureLayerImplWithMailboxThreadedCallback : public LayerTreeTest { |
| 669 public: | 695 public: |
| 670 TextureLayerImplWithMailboxThreadedCallback() | 696 TextureLayerImplWithMailboxThreadedCallback() |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 return will_draw; | 936 return will_draw; |
| 911 } | 937 } |
| 912 | 938 |
| 913 CommonMailboxObjects test_data_; | 939 CommonMailboxObjects test_data_; |
| 914 FakeLayerTreeHostClient fake_client_; | 940 FakeLayerTreeHostClient fake_client_; |
| 915 }; | 941 }; |
| 916 | 942 |
| 917 // Test conditions for results of TextureLayerImpl::WillDraw under | 943 // Test conditions for results of TextureLayerImpl::WillDraw under |
| 918 // different configurations of different mailbox, texture_id, and draw_mode. | 944 // different configurations of different mailbox, texture_id, and draw_mode. |
| 919 TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) { | 945 TEST_F(TextureLayerImplWithMailboxTest, TestWillDraw) { |
| 920 EXPECT_CALL(test_data_.mock_callback_, | 946 EXPECT_CALL( |
| 921 Release(test_data_.mailbox_name1_, | 947 test_data_.mock_callback_, |
| 922 test_data_.sync_point1_, | 948 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_point1_, false, _)) |
| 923 false)) | |
| 924 .Times(AnyNumber()); | 949 .Times(AnyNumber()); |
| 925 EXPECT_CALL(test_data_.mock_callback_, | 950 EXPECT_CALL(test_data_.mock_callback_, |
| 926 Release2(test_data_.shared_memory_.get(), 0, false)) | 951 ReleaseImpl2(test_data_.shared_memory_.get(), 0, false, _)) |
| 927 .Times(AnyNumber()); | 952 .Times(AnyNumber()); |
| 928 // Hardware mode. | 953 // Hardware mode. |
| 929 { | 954 { |
| 930 scoped_ptr<TextureLayerImpl> impl_layer = | 955 scoped_ptr<TextureLayerImpl> impl_layer = |
| 931 TextureLayerImpl::Create(host_impl_.active_tree(), 1); | 956 TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
| 932 impl_layer->SetTextureMailbox( | 957 impl_layer->SetTextureMailbox( |
| 933 test_data_.mailbox1_, | 958 test_data_.mailbox1_, |
| 934 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); | 959 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
| 935 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); | 960 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
| 936 } | 961 } |
| 937 | 962 |
| 938 { | 963 { |
| 939 scoped_ptr<TextureLayerImpl> impl_layer = | 964 scoped_ptr<TextureLayerImpl> impl_layer = |
| 940 TextureLayerImpl::Create(host_impl_.active_tree(), 1); | 965 TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
| 941 impl_layer->SetTextureMailbox(TextureMailbox(), | 966 impl_layer->SetTextureMailbox(TextureMailbox(), |
| 942 scoped_ptr<SingleReleaseCallback>()); | 967 scoped_ptr<SingleReleaseCallbackImpl>()); |
| 943 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); | 968 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
| 944 } | 969 } |
| 945 | 970 |
| 946 { | 971 { |
| 947 // Software resource. | 972 // Software resource. |
| 948 scoped_ptr<TextureLayerImpl> impl_layer = | 973 scoped_ptr<TextureLayerImpl> impl_layer = |
| 949 TextureLayerImpl::Create(host_impl_.active_tree(), 1); | 974 TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
| 950 impl_layer->SetTextureMailbox( | 975 impl_layer->SetTextureMailbox( |
| 951 test_data_.mailbox3_, | 976 test_data_.mailbox3_, |
| 952 SingleReleaseCallback::Create(test_data_.release_mailbox3_)); | 977 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_)); |
| 953 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); | 978 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_HARDWARE)); |
| 954 } | 979 } |
| 955 | 980 |
| 956 // Software mode. | 981 // Software mode. |
| 957 { | 982 { |
| 958 scoped_ptr<TextureLayerImpl> impl_layer = | 983 scoped_ptr<TextureLayerImpl> impl_layer = |
| 959 TextureLayerImpl::Create(host_impl_.active_tree(), 1); | 984 TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
| 960 impl_layer->SetTextureMailbox( | 985 impl_layer->SetTextureMailbox( |
| 961 test_data_.mailbox1_, | 986 test_data_.mailbox1_, |
| 962 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); | 987 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
| 963 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); | 988 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
| 964 } | 989 } |
| 965 | 990 |
| 966 { | 991 { |
| 967 scoped_ptr<TextureLayerImpl> impl_layer = | 992 scoped_ptr<TextureLayerImpl> impl_layer = |
| 968 TextureLayerImpl::Create(host_impl_.active_tree(), 1); | 993 TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
| 969 impl_layer->SetTextureMailbox(TextureMailbox(), | 994 impl_layer->SetTextureMailbox(TextureMailbox(), |
| 970 scoped_ptr<SingleReleaseCallback>()); | 995 scoped_ptr<SingleReleaseCallbackImpl>()); |
| 971 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); | 996 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
| 972 } | 997 } |
| 973 | 998 |
| 974 { | 999 { |
| 975 // Software resource. | 1000 // Software resource. |
| 976 scoped_ptr<TextureLayerImpl> impl_layer = | 1001 scoped_ptr<TextureLayerImpl> impl_layer = |
| 977 TextureLayerImpl::Create(host_impl_.active_tree(), 1); | 1002 TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
| 978 impl_layer->SetTextureMailbox( | 1003 impl_layer->SetTextureMailbox( |
| 979 test_data_.mailbox3_, | 1004 test_data_.mailbox3_, |
| 980 SingleReleaseCallback::Create(test_data_.release_mailbox3_)); | 1005 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox3_impl_)); |
| 981 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); | 1006 EXPECT_TRUE(WillDraw(impl_layer.get(), DRAW_MODE_SOFTWARE)); |
| 982 } | 1007 } |
| 983 | 1008 |
| 984 // Resourceless software mode. | 1009 // Resourceless software mode. |
| 985 { | 1010 { |
| 986 scoped_ptr<TextureLayerImpl> impl_layer = | 1011 scoped_ptr<TextureLayerImpl> impl_layer = |
| 987 TextureLayerImpl::Create(host_impl_.active_tree(), 1); | 1012 TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
| 988 impl_layer->SetTextureMailbox( | 1013 impl_layer->SetTextureMailbox( |
| 989 test_data_.mailbox1_, | 1014 test_data_.mailbox1_, |
| 990 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); | 1015 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
| 991 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE)); | 1016 EXPECT_FALSE(WillDraw(impl_layer.get(), DRAW_MODE_RESOURCELESS_SOFTWARE)); |
| 992 } | 1017 } |
| 993 } | 1018 } |
| 994 | 1019 |
| 995 TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) { | 1020 TEST_F(TextureLayerImplWithMailboxTest, TestImplLayerCallbacks) { |
| 996 host_impl_.CreatePendingTree(); | 1021 host_impl_.CreatePendingTree(); |
| 997 scoped_ptr<TextureLayerImpl> pending_layer; | 1022 scoped_ptr<TextureLayerImpl> pending_layer; |
| 998 pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1); | 1023 pending_layer = TextureLayerImpl::Create(host_impl_.pending_tree(), 1); |
| 999 ASSERT_TRUE(pending_layer); | 1024 ASSERT_TRUE(pending_layer); |
| 1000 | 1025 |
| 1001 scoped_ptr<LayerImpl> active_layer( | 1026 scoped_ptr<LayerImpl> active_layer( |
| 1002 pending_layer->CreateLayerImpl(host_impl_.active_tree())); | 1027 pending_layer->CreateLayerImpl(host_impl_.active_tree())); |
| 1003 ASSERT_TRUE(active_layer); | 1028 ASSERT_TRUE(active_layer); |
| 1004 | 1029 |
| 1005 pending_layer->SetTextureMailbox( | 1030 pending_layer->SetTextureMailbox( |
| 1006 test_data_.mailbox1_, | 1031 test_data_.mailbox1_, |
| 1007 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); | 1032 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
| 1008 | 1033 |
| 1009 // Test multiple commits without an activation. | 1034 // Test multiple commits without an activation. |
| 1010 EXPECT_CALL(test_data_.mock_callback_, | 1035 EXPECT_CALL( |
| 1011 Release(test_data_.mailbox_name1_, | 1036 test_data_.mock_callback_, |
| 1012 test_data_.sync_point1_, | 1037 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_point1_, false, _)) |
| 1013 false)) | |
| 1014 .Times(1); | 1038 .Times(1); |
| 1015 pending_layer->SetTextureMailbox( | 1039 pending_layer->SetTextureMailbox( |
| 1016 test_data_.mailbox2_, | 1040 test_data_.mailbox2_, |
| 1017 SingleReleaseCallback::Create(test_data_.release_mailbox2_)); | 1041 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox2_impl_)); |
| 1018 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 1042 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 1019 | 1043 |
| 1020 // Test callback after activation. | 1044 // Test callback after activation. |
| 1021 pending_layer->PushPropertiesTo(active_layer.get()); | 1045 pending_layer->PushPropertiesTo(active_layer.get()); |
| 1022 active_layer->DidBecomeActive(); | 1046 active_layer->DidBecomeActive(); |
| 1023 | 1047 |
| 1024 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); | 1048 EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0); |
| 1025 pending_layer->SetTextureMailbox( | 1049 pending_layer->SetTextureMailbox( |
| 1026 test_data_.mailbox1_, | 1050 test_data_.mailbox1_, |
| 1027 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); | 1051 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
| 1028 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 1052 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 1029 | 1053 |
| 1030 EXPECT_CALL(test_data_.mock_callback_, | 1054 EXPECT_CALL(test_data_.mock_callback_, |
| 1031 Release(test_data_.mailbox_name2_, _, false)) | 1055 ReleaseImpl(test_data_.mailbox_name2_, _, false, _)).Times(1); |
| 1032 .Times(1); | |
| 1033 pending_layer->PushPropertiesTo(active_layer.get()); | 1056 pending_layer->PushPropertiesTo(active_layer.get()); |
| 1034 active_layer->DidBecomeActive(); | 1057 active_layer->DidBecomeActive(); |
| 1035 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 1058 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 1036 | 1059 |
| 1037 // Test resetting the mailbox. | 1060 // Test resetting the mailbox. |
| 1038 EXPECT_CALL(test_data_.mock_callback_, | 1061 EXPECT_CALL(test_data_.mock_callback_, |
| 1039 Release(test_data_.mailbox_name1_, _, false)) | 1062 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1); |
| 1040 .Times(1); | |
| 1041 pending_layer->SetTextureMailbox(TextureMailbox(), | 1063 pending_layer->SetTextureMailbox(TextureMailbox(), |
| 1042 scoped_ptr<SingleReleaseCallback>()); | 1064 scoped_ptr<SingleReleaseCallbackImpl>()); |
| 1043 pending_layer->PushPropertiesTo(active_layer.get()); | 1065 pending_layer->PushPropertiesTo(active_layer.get()); |
| 1044 active_layer->DidBecomeActive(); | 1066 active_layer->DidBecomeActive(); |
| 1045 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 1067 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 1046 | 1068 |
| 1047 // Test destructor. | 1069 // Test destructor. |
| 1048 EXPECT_CALL(test_data_.mock_callback_, | 1070 EXPECT_CALL( |
| 1049 Release(test_data_.mailbox_name1_, | 1071 test_data_.mock_callback_, |
| 1050 test_data_.sync_point1_, | 1072 ReleaseImpl(test_data_.mailbox_name1_, test_data_.sync_point1_, false, _)) |
| 1051 false)) | |
| 1052 .Times(1); | 1073 .Times(1); |
| 1053 pending_layer->SetTextureMailbox( | 1074 pending_layer->SetTextureMailbox( |
| 1054 test_data_.mailbox1_, | 1075 test_data_.mailbox1_, |
| 1055 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); | 1076 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
| 1056 } | 1077 } |
| 1057 | 1078 |
| 1058 TEST_F(TextureLayerImplWithMailboxTest, | 1079 TEST_F(TextureLayerImplWithMailboxTest, |
| 1059 TestDestructorCallbackOnCreatedResource) { | 1080 TestDestructorCallbackOnCreatedResource) { |
| 1060 scoped_ptr<TextureLayerImpl> impl_layer; | 1081 scoped_ptr<TextureLayerImpl> impl_layer; |
| 1061 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1); | 1082 impl_layer = TextureLayerImpl::Create(host_impl_.active_tree(), 1); |
| 1062 ASSERT_TRUE(impl_layer); | 1083 ASSERT_TRUE(impl_layer); |
| 1063 | 1084 |
| 1064 EXPECT_CALL(test_data_.mock_callback_, | 1085 EXPECT_CALL(test_data_.mock_callback_, |
| 1065 Release(test_data_.mailbox_name1_, _, false)) | 1086 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1); |
| 1066 .Times(1); | |
| 1067 impl_layer->SetTextureMailbox( | 1087 impl_layer->SetTextureMailbox( |
| 1068 test_data_.mailbox1_, | 1088 test_data_.mailbox1_, |
| 1069 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); | 1089 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
| 1070 impl_layer->DidBecomeActive(); | 1090 impl_layer->DidBecomeActive(); |
| 1071 EXPECT_TRUE(impl_layer->WillDraw( | 1091 EXPECT_TRUE(impl_layer->WillDraw( |
| 1072 DRAW_MODE_HARDWARE, host_impl_.active_tree()->resource_provider())); | 1092 DRAW_MODE_HARDWARE, host_impl_.active_tree()->resource_provider())); |
| 1073 impl_layer->DidDraw(host_impl_.active_tree()->resource_provider()); | 1093 impl_layer->DidDraw(host_impl_.active_tree()->resource_provider()); |
| 1074 impl_layer->SetTextureMailbox(TextureMailbox(), | 1094 impl_layer->SetTextureMailbox(TextureMailbox(), |
| 1075 scoped_ptr<SingleReleaseCallback>()); | 1095 scoped_ptr<SingleReleaseCallbackImpl>()); |
| 1076 } | 1096 } |
| 1077 | 1097 |
| 1078 TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) { | 1098 TEST_F(TextureLayerImplWithMailboxTest, TestCallbackOnInUseResource) { |
| 1079 ResourceProvider* provider = host_impl_.active_tree()->resource_provider(); | 1099 ResourceProvider* provider = host_impl_.active_tree()->resource_provider(); |
| 1080 ResourceProvider::ResourceId id = | 1100 ResourceProvider::ResourceId id = provider->CreateResourceFromTextureMailbox( |
| 1081 provider->CreateResourceFromTextureMailbox( | 1101 test_data_.mailbox1_, |
| 1082 test_data_.mailbox1_, | 1102 SingleReleaseCallbackImpl::Create(test_data_.release_mailbox1_impl_)); |
| 1083 SingleReleaseCallback::Create(test_data_.release_mailbox1_)); | |
| 1084 provider->AllocateForTesting(id); | 1103 provider->AllocateForTesting(id); |
| 1085 | 1104 |
| 1086 // Transfer some resources to the parent. | 1105 // Transfer some resources to the parent. |
| 1087 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 1106 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
| 1088 resource_ids_to_transfer.push_back(id); | 1107 resource_ids_to_transfer.push_back(id); |
| 1089 TransferableResourceArray list; | 1108 TransferableResourceArray list; |
| 1090 provider->PrepareSendToParent(resource_ids_to_transfer, &list); | 1109 provider->PrepareSendToParent(resource_ids_to_transfer, &list); |
| 1091 EXPECT_TRUE(provider->InUseByConsumer(id)); | 1110 EXPECT_TRUE(provider->InUseByConsumer(id)); |
| 1092 EXPECT_CALL(test_data_.mock_callback_, Release(_, _, _)).Times(0); | 1111 EXPECT_CALL(test_data_.mock_callback_, ReleaseImpl(_, _, _, _)).Times(0); |
| 1093 provider->DeleteResource(id); | 1112 provider->DeleteResource(id); |
| 1094 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); | 1113 Mock::VerifyAndClearExpectations(&test_data_.mock_callback_); |
| 1095 EXPECT_CALL(test_data_.mock_callback_, | 1114 EXPECT_CALL(test_data_.mock_callback_, |
| 1096 Release(test_data_.mailbox_name1_, _, false)) | 1115 ReleaseImpl(test_data_.mailbox_name1_, _, false, _)).Times(1); |
| 1097 .Times(1); | |
| 1098 ReturnedResourceArray returned; | 1116 ReturnedResourceArray returned; |
| 1099 TransferableResource::ReturnResources(list, &returned); | 1117 TransferableResource::ReturnResources(list, &returned); |
| 1100 provider->ReceiveReturnsFromParent(returned); | 1118 provider->ReceiveReturnsFromParent(returned); |
| 1101 } | 1119 } |
| 1102 | 1120 |
| 1103 // Checks that TextureLayer::Update does not cause an extra commit when setting | 1121 // Checks that TextureLayer::Update does not cause an extra commit when setting |
| 1104 // the texture mailbox. | 1122 // the texture mailbox. |
| 1105 class TextureLayerNoExtraCommitForMailboxTest | 1123 class TextureLayerNoExtraCommitForMailboxTest |
| 1106 : public LayerTreeTest, | 1124 : public LayerTreeTest, |
| 1107 public TextureLayerClient { | 1125 public TextureLayerClient { |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1552 int callback_count_; | 1570 int callback_count_; |
| 1553 scoped_refptr<Layer> root_; | 1571 scoped_refptr<Layer> root_; |
| 1554 scoped_refptr<TextureLayer> layer_; | 1572 scoped_refptr<TextureLayer> layer_; |
| 1555 }; | 1573 }; |
| 1556 | 1574 |
| 1557 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1575 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1558 TextureLayerWithMailboxImplThreadDeleted); | 1576 TextureLayerWithMailboxImplThreadDeleted); |
| 1559 | 1577 |
| 1560 } // namespace | 1578 } // namespace |
| 1561 } // namespace cc | 1579 } // namespace cc |
| OLD | NEW |