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/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), | 657 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES), |
658 list[3].mailbox_holder.texture_target); | 658 list[3].mailbox_holder.texture_target); |
659 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); | 659 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id1)); |
660 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); | 660 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id2)); |
661 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); | 661 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id3)); |
662 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id4)); | 662 EXPECT_TRUE(child_resource_provider_->InUseByConsumer(id4)); |
663 resource_provider_->ReceiveFromChild(child_id, list); | 663 resource_provider_->ReceiveFromChild(child_id, list); |
664 EXPECT_NE(list[0].mailbox_holder.sync_point, | 664 EXPECT_NE(list[0].mailbox_holder.sync_point, |
665 context3d_->last_waited_sync_point()); | 665 context3d_->last_waited_sync_point()); |
666 { | 666 { |
| 667 resource_provider_->WaitSyncPointIfNeeded(list[0].id); |
667 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), | 668 ResourceProvider::ScopedReadLockGL lock(resource_provider_.get(), |
668 list[0].id); | 669 list[0].id); |
669 } | 670 } |
670 EXPECT_EQ(list[0].mailbox_holder.sync_point, | 671 EXPECT_EQ(list[0].mailbox_holder.sync_point, |
671 context3d_->last_waited_sync_point()); | 672 context3d_->last_waited_sync_point()); |
672 resource_provider_->DeclareUsedResourcesFromChild(child_id, | 673 resource_provider_->DeclareUsedResourcesFromChild(child_id, |
673 resource_ids_to_transfer); | 674 resource_ids_to_transfer); |
674 } | 675 } |
675 | 676 |
676 EXPECT_EQ(4u, resource_provider_->num_resources()); | 677 EXPECT_EQ(4u, resource_provider_->num_resources()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 EXPECT_FALSE(returned_to_child[3].lost); | 747 EXPECT_FALSE(returned_to_child[3].lost); |
747 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); | 748 child_resource_provider_->ReceiveReturnsFromParent(returned_to_child); |
748 returned_to_child.clear(); | 749 returned_to_child.clear(); |
749 } | 750 } |
750 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id1)); | 751 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id1)); |
751 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id2)); | 752 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id2)); |
752 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id3)); | 753 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id3)); |
753 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id4)); | 754 EXPECT_FALSE(child_resource_provider_->InUseByConsumer(id4)); |
754 | 755 |
755 { | 756 { |
| 757 child_resource_provider_->WaitSyncPointIfNeeded(id1); |
756 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), | 758 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), |
757 id1); | 759 id1); |
758 ASSERT_NE(0U, lock.texture_id()); | 760 ASSERT_NE(0U, lock.texture_id()); |
759 child_context_->bindTexture(GL_TEXTURE_2D, lock.texture_id()); | 761 child_context_->bindTexture(GL_TEXTURE_2D, lock.texture_id()); |
760 child_context_->GetPixels(size, format, result); | 762 child_context_->GetPixels(size, format, result); |
761 EXPECT_EQ(0, memcmp(data1, result, pixel_size)); | 763 EXPECT_EQ(0, memcmp(data1, result, pixel_size)); |
762 } | 764 } |
763 { | 765 { |
| 766 child_resource_provider_->WaitSyncPointIfNeeded(id2); |
764 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), | 767 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), |
765 id2); | 768 id2); |
766 ASSERT_NE(0U, lock.texture_id()); | 769 ASSERT_NE(0U, lock.texture_id()); |
767 child_context_->bindTexture(GL_TEXTURE_2D, lock.texture_id()); | 770 child_context_->bindTexture(GL_TEXTURE_2D, lock.texture_id()); |
768 child_context_->GetPixels(size, format, result); | 771 child_context_->GetPixels(size, format, result); |
769 EXPECT_EQ(0, memcmp(data2, result, pixel_size)); | 772 EXPECT_EQ(0, memcmp(data2, result, pixel_size)); |
770 } | 773 } |
771 { | 774 { |
| 775 child_resource_provider_->WaitSyncPointIfNeeded(id3); |
772 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), | 776 ResourceProvider::ScopedReadLockGL lock(child_resource_provider_.get(), |
773 id3); | 777 id3); |
774 ASSERT_NE(0U, lock.texture_id()); | 778 ASSERT_NE(0U, lock.texture_id()); |
775 child_context_->bindTexture(GL_TEXTURE_2D, lock.texture_id()); | 779 child_context_->bindTexture(GL_TEXTURE_2D, lock.texture_id()); |
776 } | 780 } |
777 { | 781 { |
778 // Transfer resources to the parent again. | 782 // Transfer resources to the parent again. |
779 ResourceProvider::ResourceIdArray resource_ids_to_transfer; | 783 ResourceProvider::ResourceIdArray resource_ids_to_transfer; |
780 resource_ids_to_transfer.push_back(id1); | 784 resource_ids_to_transfer.push_back(id1); |
781 resource_ids_to_transfer.push_back(id2); | 785 resource_ids_to_transfer.push_back(id2); |
(...skipping 1729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2511 TextureMailbox mailbox(gpu_mailbox, target, sync_point); | 2515 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
2512 | 2516 |
2513 ResourceProvider::ResourceId id = | 2517 ResourceProvider::ResourceId id = |
2514 resource_provider->CreateResourceFromTextureMailbox( | 2518 resource_provider->CreateResourceFromTextureMailbox( |
2515 mailbox, callback.Pass()); | 2519 mailbox, callback.Pass()); |
2516 EXPECT_NE(0u, id); | 2520 EXPECT_NE(0u, id); |
2517 | 2521 |
2518 Mock::VerifyAndClearExpectations(context); | 2522 Mock::VerifyAndClearExpectations(context); |
2519 | 2523 |
2520 { | 2524 { |
| 2525 // Mailbox sync point WaitSyncPoint before using the texture. |
| 2526 EXPECT_CALL(*context, waitSyncPoint(sync_point)); |
| 2527 resource_provider->WaitSyncPointIfNeeded(id); |
| 2528 Mock::VerifyAndClearExpectations(context); |
| 2529 |
2521 // Using the texture does a consume of the mailbox. | 2530 // Using the texture does a consume of the mailbox. |
2522 EXPECT_CALL(*context, bindTexture(target, texture_id)); | 2531 EXPECT_CALL(*context, bindTexture(target, texture_id)); |
2523 EXPECT_CALL(*context, waitSyncPoint(sync_point)); | |
2524 EXPECT_CALL(*context, consumeTextureCHROMIUM(target, _)); | 2532 EXPECT_CALL(*context, consumeTextureCHROMIUM(target, _)); |
2525 | 2533 |
2526 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2534 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
2527 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2535 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
2528 | 2536 |
2529 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); | 2537 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); |
2530 Mock::VerifyAndClearExpectations(context); | 2538 Mock::VerifyAndClearExpectations(context); |
2531 | 2539 |
2532 // When done with it, a sync point should be inserted, but no produce is | 2540 // When done with it, a sync point should be inserted, but no produce is |
2533 // necessary. | 2541 // necessary. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2575 TextureMailbox mailbox(gpu_mailbox, target, sync_point); | 2583 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
2576 | 2584 |
2577 ResourceProvider::ResourceId id = | 2585 ResourceProvider::ResourceId id = |
2578 resource_provider->CreateResourceFromTextureMailbox( | 2586 resource_provider->CreateResourceFromTextureMailbox( |
2579 mailbox, callback.Pass()); | 2587 mailbox, callback.Pass()); |
2580 EXPECT_NE(0u, id); | 2588 EXPECT_NE(0u, id); |
2581 | 2589 |
2582 Mock::VerifyAndClearExpectations(context); | 2590 Mock::VerifyAndClearExpectations(context); |
2583 | 2591 |
2584 { | 2592 { |
| 2593 // Mailbox sync point WaitSyncPoint before using the texture. |
| 2594 EXPECT_CALL(*context, waitSyncPoint(sync_point)); |
| 2595 resource_provider->WaitSyncPointIfNeeded(id); |
| 2596 Mock::VerifyAndClearExpectations(context); |
| 2597 |
2585 // Using the texture does a consume of the mailbox. | 2598 // Using the texture does a consume of the mailbox. |
2586 EXPECT_CALL(*context, bindTexture(target, texture_id)); | 2599 EXPECT_CALL(*context, bindTexture(target, texture_id)); |
2587 EXPECT_CALL(*context, waitSyncPoint(sync_point)); | |
2588 EXPECT_CALL(*context, consumeTextureCHROMIUM(target, _)); | 2600 EXPECT_CALL(*context, consumeTextureCHROMIUM(target, _)); |
2589 | 2601 |
2590 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2602 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
2591 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2603 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
2592 | 2604 |
2593 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); | 2605 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); |
2594 Mock::VerifyAndClearExpectations(context); | 2606 Mock::VerifyAndClearExpectations(context); |
2595 | 2607 |
2596 // When done with it, a sync point should be inserted, but no produce is | 2608 // When done with it, a sync point should be inserted, but no produce is |
2597 // necessary. | 2609 // necessary. |
2598 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2610 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
2599 EXPECT_CALL(*context, insertSyncPoint()); | 2611 EXPECT_CALL(*context, insertSyncPoint()); |
2600 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2612 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
2601 | 2613 |
2602 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2614 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
2603 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2615 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
2604 } | 2616 } |
2605 } | 2617 } |
2606 | 2618 |
| 2619 TEST_P(ResourceProviderTest, |
| 2620 TextureMailbox_WaitSyncPointIfNeeded_WithSyncPoint) { |
| 2621 // Mailboxing is only supported for GL textures. |
| 2622 if (GetParam() != ResourceProvider::GLTexture) |
| 2623 return; |
| 2624 |
| 2625 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 2626 new TextureStateTrackingContext); |
| 2627 TextureStateTrackingContext* context = context_owned.get(); |
| 2628 |
| 2629 FakeOutputSurfaceClient output_surface_client; |
| 2630 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2631 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2632 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2633 |
| 2634 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 2635 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); |
| 2636 |
| 2637 uint32 sync_point = 30; |
| 2638 unsigned target = GL_TEXTURE_2D; |
| 2639 |
| 2640 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2641 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2642 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2643 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
| 2644 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
| 2645 |
| 2646 gpu::Mailbox gpu_mailbox; |
| 2647 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| 2648 scoped_ptr<SingleReleaseCallback> callback = |
| 2649 SingleReleaseCallback::Create(base::Bind(&EmptyReleaseCallback)); |
| 2650 |
| 2651 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
| 2652 |
| 2653 ResourceProvider::ResourceId id = |
| 2654 resource_provider->CreateResourceFromTextureMailbox(mailbox, |
| 2655 callback.Pass()); |
| 2656 EXPECT_NE(0u, id); |
| 2657 |
| 2658 Mock::VerifyAndClearExpectations(context); |
| 2659 |
| 2660 { |
| 2661 // First call to WaitSyncPointIfNeeded should call waitSyncPoint. |
| 2662 EXPECT_CALL(*context, waitSyncPoint(sync_point)); |
| 2663 resource_provider->WaitSyncPointIfNeeded(id); |
| 2664 Mock::VerifyAndClearExpectations(context); |
| 2665 |
| 2666 // Subsequent calls to WaitSyncPointIfNeeded shouldn't call waitSyncPoint. |
| 2667 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2668 resource_provider->WaitSyncPointIfNeeded(id); |
| 2669 Mock::VerifyAndClearExpectations(context); |
| 2670 } |
| 2671 } |
| 2672 |
| 2673 TEST_P(ResourceProviderTest, TextureMailbox_WaitSyncPointIfNeeded_NoSyncPoint) { |
| 2674 // Mailboxing is only supported for GL textures. |
| 2675 if (GetParam() != ResourceProvider::GLTexture) |
| 2676 return; |
| 2677 |
| 2678 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 2679 new TextureStateTrackingContext); |
| 2680 TextureStateTrackingContext* context = context_owned.get(); |
| 2681 |
| 2682 FakeOutputSurfaceClient output_surface_client; |
| 2683 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 2684 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 2685 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2686 |
| 2687 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 2688 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); |
| 2689 |
| 2690 uint32 sync_point = 0; |
| 2691 unsigned target = GL_TEXTURE_2D; |
| 2692 |
| 2693 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2694 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2695 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2696 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
| 2697 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
| 2698 |
| 2699 gpu::Mailbox gpu_mailbox; |
| 2700 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| 2701 scoped_ptr<SingleReleaseCallback> callback = |
| 2702 SingleReleaseCallback::Create(base::Bind(&EmptyReleaseCallback)); |
| 2703 |
| 2704 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
| 2705 |
| 2706 ResourceProvider::ResourceId id = |
| 2707 resource_provider->CreateResourceFromTextureMailbox(mailbox, |
| 2708 callback.Pass()); |
| 2709 EXPECT_NE(0u, id); |
| 2710 |
| 2711 Mock::VerifyAndClearExpectations(context); |
| 2712 |
| 2713 { |
| 2714 // WaitSyncPointIfNeeded with sync_point == 0 shouldn't call waitSyncPoint. |
| 2715 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2716 resource_provider->WaitSyncPointIfNeeded(id); |
| 2717 Mock::VerifyAndClearExpectations(context); |
| 2718 } |
| 2719 } |
| 2720 |
2607 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { | 2721 class AllocationTrackingContext3D : public TestWebGraphicsContext3D { |
2608 public: | 2722 public: |
2609 MOCK_METHOD0(NextTextureId, GLuint()); | 2723 MOCK_METHOD0(NextTextureId, GLuint()); |
2610 MOCK_METHOD1(RetireTextureId, void(GLuint id)); | 2724 MOCK_METHOD1(RetireTextureId, void(GLuint id)); |
2611 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); | 2725 MOCK_METHOD2(bindTexture, void(GLenum target, GLuint texture)); |
2612 MOCK_METHOD5(texStorage2DEXT, | 2726 MOCK_METHOD5(texStorage2DEXT, |
2613 void(GLenum target, | 2727 void(GLenum target, |
2614 GLint levels, | 2728 GLint levels, |
2615 GLuint internalformat, | 2729 GLuint internalformat, |
2616 GLint width, | 2730 GLint width, |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3405 resource_provider->AllocateForTesting(id); | 3519 resource_provider->AllocateForTesting(id); |
3406 Mock::VerifyAndClearExpectations(context); | 3520 Mock::VerifyAndClearExpectations(context); |
3407 | 3521 |
3408 DCHECK_EQ(10u, context->PeekTextureId()); | 3522 DCHECK_EQ(10u, context->PeekTextureId()); |
3409 resource_provider->DeleteResource(id); | 3523 resource_provider->DeleteResource(id); |
3410 } | 3524 } |
3411 } | 3525 } |
3412 | 3526 |
3413 } // namespace | 3527 } // namespace |
3414 } // namespace cc | 3528 } // namespace cc |
OLD | NEW |