Chromium Code Reviews| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/synchronization/waitable_event.h" | |
| 11 #include "base/threading/thread.h" | |
| 12 #include "base/time/time.h" | |
| 10 #include "cc/debug/test_web_graphics_context_3d.h" | 13 #include "cc/debug/test_web_graphics_context_3d.h" |
| 11 #include "cc/layers/texture_layer_client.h" | 14 #include "cc/layers/texture_layer_client.h" |
| 12 #include "cc/layers/texture_layer_impl.h" | 15 #include "cc/layers/texture_layer_impl.h" |
| 13 #include "cc/resources/returned_resource.h" | 16 #include "cc/resources/returned_resource.h" |
| 14 #include "cc/test/fake_impl_proxy.h" | 17 #include "cc/test/fake_impl_proxy.h" |
| 15 #include "cc/test/fake_layer_tree_host_client.h" | 18 #include "cc/test/fake_layer_tree_host_client.h" |
| 16 #include "cc/test/fake_layer_tree_host_impl.h" | 19 #include "cc/test/fake_layer_tree_host_impl.h" |
| 17 #include "cc/test/fake_output_surface.h" | 20 #include "cc/test/fake_output_surface.h" |
| 18 #include "cc/test/layer_test_common.h" | 21 #include "cc/test/layer_test_common.h" |
| 19 #include "cc/test/layer_tree_test.h" | 22 #include "cc/test/layer_tree_test.h" |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 private: | 556 private: |
| 554 int callback_count_; | 557 int callback_count_; |
| 555 int commit_count_; | 558 int commit_count_; |
| 556 scoped_refptr<Layer> root_; | 559 scoped_refptr<Layer> root_; |
| 557 scoped_refptr<TextureLayer> layer_; | 560 scoped_refptr<TextureLayer> layer_; |
| 558 }; | 561 }; |
| 559 | 562 |
| 560 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 563 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 561 TextureLayerImplWithMailboxThreadedCallback); | 564 TextureLayerImplWithMailboxThreadedCallback); |
| 562 | 565 |
| 566 | |
| 567 class TextureLayerNoMailboxIsActivatedDuringCommit : public LayerTreeTest, | |
| 568 public TextureLayerClient { | |
| 569 protected: | |
| 570 TextureLayerNoMailboxIsActivatedDuringCommit() | |
| 571 : wait_thread_("WAIT"), | |
| 572 wait_event_(false, false) { | |
| 573 wait_thread_.Start(); | |
| 574 } | |
| 575 | |
| 576 virtual void BeginTest() OVERRIDE { | |
| 577 activate_count_ = 0; | |
| 578 | |
| 579 gfx::Size bounds(100, 100); | |
| 580 root_ = Layer::Create(); | |
| 581 root_->SetAnchorPoint(gfx::PointF()); | |
| 582 root_->SetBounds(bounds); | |
| 583 | |
| 584 layer_ = TextureLayer::Create(this); | |
| 585 layer_->SetIsDrawable(true); | |
| 586 layer_->SetAnchorPoint(gfx::PointF()); | |
| 587 layer_->SetBounds(bounds); | |
| 588 | |
| 589 root_->AddChild(layer_); | |
| 590 layer_tree_host()->SetRootLayer(root_); | |
| 591 layer_tree_host()->SetViewportSize(bounds); | |
| 592 | |
| 593 PostSetNeedsCommitToMainThread(); | |
| 594 } | |
| 595 | |
| 596 // TextureLayerClient implementation. | |
| 597 virtual unsigned PrepareTexture() OVERRIDE { | |
| 598 return OffscreenContextProviderForMainThread() | |
| 599 ->Context3d()->createTexture(); | |
| 600 } | |
| 601 virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE { | |
| 602 return OffscreenContextProviderForMainThread()->Context3d(); | |
| 603 } | |
| 604 virtual bool PrepareTextureMailbox(TextureMailbox* mailbox, | |
| 605 bool use_shared_memory) OVERRIDE { | |
| 606 return false; | |
| 607 } | |
| 608 | |
| 609 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
| 610 // Slow down activation so the main thread DidCommit() will run if | |
| 611 // not blocked. | |
| 612 wait_thread_.message_loop()->PostDelayedTask( | |
| 613 FROM_HERE, | |
| 614 base::Bind(&base::WaitableEvent::Signal, | |
| 615 base::Unretained(&wait_event_)), | |
| 616 base::TimeDelta::FromMilliseconds(10)); | |
| 617 wait_event_.Wait(); | |
| 618 } | |
| 619 | |
| 620 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
| 621 { | |
| 622 base::AutoLock lock(activate_lock_); | |
| 623 ++activate_count_; | |
| 624 } | |
| 625 | |
| 626 proxy()->MainThreadTaskRunner()->PostTask( | |
| 627 FROM_HERE, | |
| 628 base::Bind(&TextureLayerNoMailboxIsActivatedDuringCommit::DidActivate, | |
| 629 base::Unretained(this))); | |
| 630 } | |
| 631 | |
| 632 void DidActivate() { | |
| 633 base::AutoLock lock(activate_lock_); | |
| 634 switch (activate_count_) { | |
| 635 case 1: | |
| 636 // The first texture has been activated. Invalidate the layer so it | |
| 637 // grabs a new texture id from the client. | |
| 638 layer_->SetNeedsDisplay(); | |
| 639 // So this commit number should complete after the second activate. | |
| 640 EXPECT_EQ(1, layer_tree_host()->source_frame_number()); | |
| 641 break; | |
| 642 case 2: | |
| 643 // The second mailbox has been activated. Remove the layer from | |
| 644 // the tree to cause another commit/activation. The commit should | |
| 645 // finish *after* the layer is removed from the active tree. | |
| 646 layer_->RemoveFromParent(); | |
| 647 // So this commit number should complete after the third activate. | |
| 648 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); | |
| 649 } | |
| 650 } | |
| 651 | |
| 652 virtual void DidCommit() OVERRIDE { | |
| 653 switch (layer_tree_host()->source_frame_number()) { | |
| 654 case 2: { | |
| 655 // The activate for the 2nd texture should have happened before now. | |
| 656 base::AutoLock lock(activate_lock_); | |
| 657 EXPECT_EQ(2, activate_count_); | |
| 658 break; | |
| 659 } | |
| 660 case 3: { | |
| 661 // The activate to remove the layer should have happened before now. | |
| 662 base::AutoLock lock(activate_lock_); | |
| 663 EXPECT_EQ(3, activate_count_); | |
| 664 | |
| 665 EndTest(); | |
| 666 break; | |
| 667 } | |
| 668 } | |
| 669 } | |
| 670 | |
| 671 | |
| 672 virtual void AfterTest() OVERRIDE {} | |
| 673 | |
| 674 base::Thread wait_thread_; | |
| 675 base::WaitableEvent wait_event_; | |
| 676 base::Lock activate_lock_; | |
| 677 int activate_count_; | |
| 678 int activate_commit_; | |
| 679 scoped_refptr<Layer> root_; | |
| 680 scoped_refptr<TextureLayer> layer_; | |
| 681 }; | |
| 682 | |
| 683 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | |
| 684 TextureLayerNoMailboxIsActivatedDuringCommit); | |
| 685 | |
| 686 class TextureLayerMailboxIsActivatedDuringCommit : public LayerTreeTest { | |
| 687 protected: | |
| 688 TextureLayerMailboxIsActivatedDuringCommit() | |
| 689 : wait_thread_("WAIT"), | |
| 690 wait_event_(false, false) { | |
| 691 wait_thread_.Start(); | |
| 692 } | |
| 693 | |
| 694 static void ReleaseCallback(unsigned sync_point, bool lost_resource) {} | |
| 695 | |
| 696 void SetMailbox(char mailbox_char) { | |
| 697 TextureMailbox mailbox( | |
| 698 std::string(64, mailbox_char), | |
| 699 base::Bind( | |
| 700 &TextureLayerMailboxIsActivatedDuringCommit::ReleaseCallback)); | |
| 701 layer_->SetTextureMailbox(mailbox); | |
| 702 } | |
| 703 | |
| 704 virtual void BeginTest() OVERRIDE { | |
| 705 activate_count_ = 0; | |
| 706 | |
| 707 gfx::Size bounds(100, 100); | |
| 708 root_ = Layer::Create(); | |
| 709 root_->SetAnchorPoint(gfx::PointF()); | |
| 710 root_->SetBounds(bounds); | |
| 711 | |
| 712 layer_ = TextureLayer::CreateForMailbox(NULL); | |
| 713 layer_->SetIsDrawable(true); | |
| 714 layer_->SetAnchorPoint(gfx::PointF()); | |
| 715 layer_->SetBounds(bounds); | |
| 716 | |
| 717 root_->AddChild(layer_); | |
| 718 layer_tree_host()->SetRootLayer(root_); | |
| 719 layer_tree_host()->SetViewportSize(bounds); | |
| 720 SetMailbox('1'); | |
| 721 | |
| 722 PostSetNeedsCommitToMainThread(); | |
| 723 } | |
| 724 | |
| 725 virtual void WillActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
| 726 // Slow down activation so the main thread DidCommit() will run if | |
| 727 // not blocked. | |
| 728 wait_thread_.message_loop()->PostDelayedTask( | |
| 729 FROM_HERE, | |
| 730 base::Bind(&base::WaitableEvent::Signal, | |
| 731 base::Unretained(&wait_event_)), | |
| 732 base::TimeDelta::FromMilliseconds(10)); | |
| 733 wait_event_.Wait(); | |
| 734 } | |
| 735 | |
| 736 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* impl) OVERRIDE { | |
| 737 { | |
| 738 base::AutoLock lock(activate_lock_); | |
| 739 ++activate_count_; | |
| 740 } | |
| 741 | |
| 742 proxy()->MainThreadTaskRunner()->PostTask( | |
| 743 FROM_HERE, | |
| 744 base::Bind(&TextureLayerMailboxIsActivatedDuringCommit::DidActivate, | |
| 745 base::Unretained(this))); | |
| 746 } | |
| 747 | |
| 748 void DidActivate() { | |
| 749 base::AutoLock lock(activate_lock_); | |
| 750 switch (activate_count_) { | |
| 751 case 1: | |
| 752 // The first mailbox has been activated. Set a new mailbox, and | |
| 753 // expect the next commit to finish *after* it is activated. | |
| 754 SetMailbox('2'); | |
|
danakj
2013/08/29 01:59:16
@piman I am actually not sure if using SetTextureM
piman
2013/08/29 04:16:01
I've generally tried to avoid using both ways at t
| |
| 755 // So this commit number should complete after the second activate. | |
| 756 EXPECT_EQ(1, layer_tree_host()->source_frame_number()); | |
| 757 break; | |
| 758 case 2: | |
| 759 // The second mailbox has been activated. Remove the layer from | |
| 760 // the tree to cause another commit/activation. The commit should | |
| 761 // finish *after* the layer is removed from the active tree. | |
| 762 layer_->RemoveFromParent(); | |
| 763 // So this commit number should complete after the third activate. | |
| 764 EXPECT_EQ(2, layer_tree_host()->source_frame_number()); | |
| 765 } | |
| 766 } | |
| 767 | |
| 768 virtual void DidCommit() OVERRIDE { | |
| 769 switch (layer_tree_host()->source_frame_number()) { | |
| 770 case 2: { | |
| 771 // The activate for the 2nd mailbox should have happened before now. | |
| 772 base::AutoLock lock(activate_lock_); | |
| 773 EXPECT_EQ(2, activate_count_); | |
| 774 break; | |
| 775 } | |
| 776 case 3: { | |
| 777 // The activate to remove the layer should have happened before now. | |
| 778 base::AutoLock lock(activate_lock_); | |
| 779 EXPECT_EQ(3, activate_count_); | |
| 780 | |
| 781 EndTest(); | |
| 782 break; | |
| 783 } | |
| 784 } | |
| 785 } | |
| 786 | |
| 787 | |
| 788 virtual void AfterTest() OVERRIDE {} | |
| 789 | |
| 790 base::Thread wait_thread_; | |
| 791 base::WaitableEvent wait_event_; | |
| 792 base::Lock activate_lock_; | |
| 793 int activate_count_; | |
| 794 scoped_refptr<Layer> root_; | |
| 795 scoped_refptr<TextureLayer> layer_; | |
| 796 }; | |
| 797 | |
| 798 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | |
| 799 TextureLayerMailboxIsActivatedDuringCommit); | |
| 800 | |
| 563 class TextureLayerImplWithMailboxTest : public TextureLayerTest { | 801 class TextureLayerImplWithMailboxTest : public TextureLayerTest { |
| 564 protected: | 802 protected: |
| 565 TextureLayerImplWithMailboxTest() | 803 TextureLayerImplWithMailboxTest() |
| 566 : fake_client_( | 804 : fake_client_( |
| 567 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)) {} | 805 FakeLayerTreeHostClient(FakeLayerTreeHostClient::DIRECT_3D)) {} |
| 568 | 806 |
| 569 virtual void SetUp() { | 807 virtual void SetUp() { |
| 570 TextureLayerTest::SetUp(); | 808 TextureLayerTest::SetUp(); |
| 571 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); | 809 layer_tree_host_.reset(new MockLayerTreeHost(&fake_client_)); |
| 572 EXPECT_TRUE(host_impl_.InitializeRenderer(CreateFakeOutputSurface())); | 810 EXPECT_TRUE(host_impl_.InitializeRenderer(CreateFakeOutputSurface())); |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1122 int callback_count_; | 1360 int callback_count_; |
| 1123 scoped_refptr<Layer> root_; | 1361 scoped_refptr<Layer> root_; |
| 1124 scoped_refptr<TextureLayer> layer_; | 1362 scoped_refptr<TextureLayer> layer_; |
| 1125 }; | 1363 }; |
| 1126 | 1364 |
| 1127 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 1365 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 1128 TextureLayerWithMailboxImplThreadDeleted); | 1366 TextureLayerWithMailboxImplThreadDeleted); |
| 1129 | 1367 |
| 1130 } // namespace | 1368 } // namespace |
| 1131 } // namespace cc | 1369 } // namespace cc |
| OLD | NEW |