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 2585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2596 EXPECT_EQ(sk_bitmap->height(), size.height()); | 2596 EXPECT_EQ(sk_bitmap->height(), size.height()); |
2597 EXPECT_EQ(*sk_bitmap->getAddr32(16, 16), kBadBeef); | 2597 EXPECT_EQ(*sk_bitmap->getAddr32(16, 16), kBadBeef); |
2598 } | 2598 } |
2599 | 2599 |
2600 resource_provider->DeleteResource(id); | 2600 resource_provider->DeleteResource(id); |
2601 EXPECT_EQ(0u, release_sync_point); | 2601 EXPECT_EQ(0u, release_sync_point); |
2602 EXPECT_FALSE(lost_resource); | 2602 EXPECT_FALSE(lost_resource); |
2603 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); | 2603 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); |
2604 } | 2604 } |
2605 | 2605 |
2606 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D) { | 2606 class ResourceProviderTestTextureMailboxGLFilters |
| 2607 : public ResourceProviderTest { |
| 2608 public: |
| 2609 static void RunTest(TestSharedBitmapManager* shared_bitmap_manager, |
| 2610 TestGpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 2611 BlockingTaskRunner* main_thread_task_runner, |
| 2612 bool mailbox_nearest_neighbor, |
| 2613 GLenum sampler_filter) { |
| 2614 scoped_ptr<TextureStateTrackingContext> context_owned( |
| 2615 new TextureStateTrackingContext); |
| 2616 TextureStateTrackingContext* context = context_owned.get(); |
| 2617 |
| 2618 FakeOutputSurfaceClient output_surface_client; |
| 2619 scoped_ptr<OutputSurface> output_surface( |
| 2620 FakeOutputSurface::Create3d(context_owned.Pass())); |
| 2621 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 2622 |
| 2623 scoped_ptr<ResourceProvider> resource_provider( |
| 2624 ResourceProvider::Create(output_surface.get(), |
| 2625 shared_bitmap_manager, |
| 2626 gpu_memory_buffer_manager, |
| 2627 main_thread_task_runner, |
| 2628 0, |
| 2629 false, |
| 2630 1)); |
| 2631 |
| 2632 unsigned texture_id = 1; |
| 2633 uint32 sync_point = 30; |
| 2634 unsigned target = GL_TEXTURE_2D; |
| 2635 |
| 2636 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2637 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2638 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2639 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
| 2640 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
| 2641 |
| 2642 gpu::Mailbox gpu_mailbox; |
| 2643 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); |
| 2644 uint32 release_sync_point = 0; |
| 2645 bool lost_resource = false; |
| 2646 BlockingTaskRunner* mailbox_task_runner = NULL; |
| 2647 scoped_ptr<SingleReleaseCallbackImpl> callback = |
| 2648 SingleReleaseCallbackImpl::Create(base::Bind(&ReleaseCallback, |
| 2649 &release_sync_point, |
| 2650 &lost_resource, |
| 2651 &mailbox_task_runner)); |
| 2652 |
| 2653 TextureMailbox mailbox(gpu_mailbox, target, sync_point); |
| 2654 mailbox.set_nearest_neighbor(mailbox_nearest_neighbor); |
| 2655 |
| 2656 ResourceProvider::ResourceId id = |
| 2657 resource_provider->CreateResourceFromTextureMailbox(mailbox, |
| 2658 callback.Pass()); |
| 2659 EXPECT_NE(0u, id); |
| 2660 |
| 2661 Mock::VerifyAndClearExpectations(context); |
| 2662 |
| 2663 { |
| 2664 // Mailbox sync point WaitSyncPoint before using the texture. |
| 2665 EXPECT_CALL(*context, waitSyncPoint(sync_point)); |
| 2666 resource_provider->WaitSyncPointIfNeeded(id); |
| 2667 Mock::VerifyAndClearExpectations(context); |
| 2668 |
| 2669 // Using the texture does a consume of the mailbox. |
| 2670 EXPECT_CALL(*context, bindTexture(target, texture_id)).Times(2); |
| 2671 EXPECT_CALL(*context, consumeTextureCHROMIUM(target, _)); |
| 2672 |
| 2673 EXPECT_CALL(*context, insertSyncPoint()).Times(0); |
| 2674 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
| 2675 |
| 2676 // The sampler will reset these if |mailbox_nearest_neighbor| does not |
| 2677 // match |sampler_filter|. |
| 2678 if (mailbox_nearest_neighbor != (sampler_filter == GL_NEAREST)) { |
| 2679 EXPECT_CALL(*context, texParameteri( |
| 2680 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, sampler_filter)); |
| 2681 EXPECT_CALL(*context, texParameteri( |
| 2682 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, sampler_filter)); |
| 2683 } |
| 2684 |
| 2685 ResourceProvider::ScopedSamplerGL lock( |
| 2686 resource_provider.get(), id, sampler_filter); |
| 2687 Mock::VerifyAndClearExpectations(context); |
| 2688 |
| 2689 // When done with it, a sync point should be inserted, but no produce is |
| 2690 // necessary. |
| 2691 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); |
| 2692 EXPECT_CALL(*context, insertSyncPoint()); |
| 2693 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); |
| 2694 |
| 2695 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); |
| 2696 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); |
| 2697 } |
| 2698 |
| 2699 resource_provider->DeleteResource(id); |
| 2700 EXPECT_EQ(0u, release_sync_point); |
| 2701 EXPECT_FALSE(lost_resource); |
| 2702 EXPECT_EQ(main_thread_task_runner, mailbox_task_runner); |
| 2703 } |
| 2704 }; |
| 2705 |
| 2706 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToLinear) { |
2607 // Mailboxing is only supported for GL textures. | 2707 // Mailboxing is only supported for GL textures. |
2608 if (GetParam() != ResourceProvider::GLTexture) | 2708 if (GetParam() != ResourceProvider::GLTexture) |
2609 return; | 2709 return; |
2610 | 2710 |
2611 scoped_ptr<TextureStateTrackingContext> context_owned( | 2711 ResourceProviderTestTextureMailboxGLFilters::RunTest( |
2612 new TextureStateTrackingContext); | 2712 shared_bitmap_manager_.get(), |
2613 TextureStateTrackingContext* context = context_owned.get(); | 2713 gpu_memory_buffer_manager_.get(), |
| 2714 main_thread_task_runner_.get(), |
| 2715 false, |
| 2716 GL_LINEAR); |
| 2717 } |
2614 | 2718 |
2615 FakeOutputSurfaceClient output_surface_client; | 2719 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_NearestToNearest) { |
2616 scoped_ptr<OutputSurface> output_surface( | 2720 // Mailboxing is only supported for GL textures. |
2617 FakeOutputSurface::Create3d(context_owned.Pass())); | 2721 if (GetParam() != ResourceProvider::GLTexture) |
2618 CHECK(output_surface->BindToClient(&output_surface_client)); | 2722 return; |
2619 | 2723 |
2620 scoped_ptr<ResourceProvider> resource_provider( | 2724 ResourceProviderTestTextureMailboxGLFilters::RunTest( |
2621 ResourceProvider::Create(output_surface.get(), | 2725 shared_bitmap_manager_.get(), |
2622 shared_bitmap_manager_.get(), | 2726 gpu_memory_buffer_manager_.get(), |
2623 gpu_memory_buffer_manager_.get(), | 2727 main_thread_task_runner_.get(), |
2624 main_thread_task_runner_.get(), | 2728 true, |
2625 0, | 2729 GL_NEAREST); |
2626 false, | 2730 } |
2627 1)); | |
2628 | 2731 |
2629 unsigned texture_id = 1; | 2732 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_NearestToLinear) { |
2630 uint32 sync_point = 30; | 2733 // Mailboxing is only supported for GL textures. |
2631 unsigned target = GL_TEXTURE_2D; | 2734 if (GetParam() != ResourceProvider::GLTexture) |
| 2735 return; |
2632 | 2736 |
2633 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | 2737 ResourceProviderTestTextureMailboxGLFilters::RunTest( |
2634 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | 2738 shared_bitmap_manager_.get(), |
2635 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | 2739 gpu_memory_buffer_manager_.get(), |
2636 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | 2740 main_thread_task_runner_.get(), |
2637 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | 2741 true, |
| 2742 GL_LINEAR); |
| 2743 } |
2638 | 2744 |
2639 gpu::Mailbox gpu_mailbox; | 2745 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToNearest) { |
2640 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1); | 2746 // Mailboxing is only supported for GL textures. |
2641 uint32 release_sync_point = 0; | 2747 if (GetParam() != ResourceProvider::GLTexture) |
2642 bool lost_resource = false; | 2748 return; |
2643 BlockingTaskRunner* main_thread_task_runner = NULL; | |
2644 scoped_ptr<SingleReleaseCallbackImpl> callback = | |
2645 SingleReleaseCallbackImpl::Create(base::Bind(&ReleaseCallback, | |
2646 &release_sync_point, | |
2647 &lost_resource, | |
2648 &main_thread_task_runner)); | |
2649 | 2749 |
2650 TextureMailbox mailbox(gpu_mailbox, target, sync_point); | 2750 ResourceProviderTestTextureMailboxGLFilters::RunTest( |
2651 | 2751 shared_bitmap_manager_.get(), |
2652 ResourceProvider::ResourceId id = | 2752 gpu_memory_buffer_manager_.get(), |
2653 resource_provider->CreateResourceFromTextureMailbox( | 2753 main_thread_task_runner_.get(), |
2654 mailbox, callback.Pass()); | 2754 false, |
2655 EXPECT_NE(0u, id); | 2755 GL_NEAREST); |
2656 | |
2657 Mock::VerifyAndClearExpectations(context); | |
2658 | |
2659 { | |
2660 // Mailbox sync point WaitSyncPoint before using the texture. | |
2661 EXPECT_CALL(*context, waitSyncPoint(sync_point)); | |
2662 resource_provider->WaitSyncPointIfNeeded(id); | |
2663 Mock::VerifyAndClearExpectations(context); | |
2664 | |
2665 // Using the texture does a consume of the mailbox. | |
2666 EXPECT_CALL(*context, bindTexture(target, texture_id)); | |
2667 EXPECT_CALL(*context, consumeTextureCHROMIUM(target, _)); | |
2668 | |
2669 EXPECT_CALL(*context, insertSyncPoint()).Times(0); | |
2670 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | |
2671 | |
2672 ResourceProvider::ScopedReadLockGL lock(resource_provider.get(), id); | |
2673 Mock::VerifyAndClearExpectations(context); | |
2674 | |
2675 // When done with it, a sync point should be inserted, but no produce is | |
2676 // necessary. | |
2677 EXPECT_CALL(*context, bindTexture(_, _)).Times(0); | |
2678 EXPECT_CALL(*context, insertSyncPoint()); | |
2679 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0); | |
2680 | |
2681 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0); | |
2682 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0); | |
2683 } | |
2684 | |
2685 resource_provider->DeleteResource(id); | |
2686 EXPECT_EQ(0u, release_sync_point); | |
2687 EXPECT_FALSE(lost_resource); | |
2688 EXPECT_EQ(main_thread_task_runner_.get(), main_thread_task_runner); | |
2689 } | 2756 } |
2690 | 2757 |
2691 TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { | 2758 TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { |
2692 // Mailboxing is only supported for GL textures. | 2759 // Mailboxing is only supported for GL textures. |
2693 if (GetParam() != ResourceProvider::GLTexture) | 2760 if (GetParam() != ResourceProvider::GLTexture) |
2694 return; | 2761 return; |
2695 | 2762 |
2696 scoped_ptr<TextureStateTrackingContext> context_owned( | 2763 scoped_ptr<TextureStateTrackingContext> context_owned( |
2697 new TextureStateTrackingContext); | 2764 new TextureStateTrackingContext); |
2698 TextureStateTrackingContext* context = context_owned.get(); | 2765 TextureStateTrackingContext* context = context_owned.get(); |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3643 resource_provider->AllocateForTesting(id); | 3710 resource_provider->AllocateForTesting(id); |
3644 Mock::VerifyAndClearExpectations(context); | 3711 Mock::VerifyAndClearExpectations(context); |
3645 | 3712 |
3646 DCHECK_EQ(10u, context->PeekTextureId()); | 3713 DCHECK_EQ(10u, context->PeekTextureId()); |
3647 resource_provider->DeleteResource(id); | 3714 resource_provider->DeleteResource(id); |
3648 } | 3715 } |
3649 } | 3716 } |
3650 | 3717 |
3651 } // namespace | 3718 } // namespace |
3652 } // namespace cc | 3719 } // namespace cc |
OLD | NEW |