Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: cc/resources/resource_provider_unittest.cc

Issue 558083002: [cc] Add nearest neighbor filtering for TextureLayer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 because |nearest_neighbor| was set on the
danakj 2014/11/18 16:17:05 These expectations will differ depending on neares
jackhou1 2014/11/19 03:33:17 Updated the comment. At the moment the tests are
danakj 2014/11/19 16:01:56 Ah right I missed the sampler part, thanks for the
2677 // mailbox.
2678 EXPECT_CALL(
2679 *context,
2680 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, sampler_filter));
2681 EXPECT_CALL(
2682 *context,
2683 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, sampler_filter));
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_NearestToLinear) {
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 true,
2716 GL_LINEAR);
2717 }
2614 2718
2615 FakeOutputSurfaceClient output_surface_client; 2719 TEST_P(ResourceProviderTest, TextureMailbox_GLTexture2D_LinearToNearest) {
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 false,
2625 0, 2729 GL_NEAREST);
2626 false,
2627 1));
2628
2629 unsigned texture_id = 1;
2630 uint32 sync_point = 30;
2631 unsigned target = GL_TEXTURE_2D;
2632
2633 EXPECT_CALL(*context, bindTexture(_, _)).Times(0);
2634 EXPECT_CALL(*context, waitSyncPoint(_)).Times(0);
2635 EXPECT_CALL(*context, insertSyncPoint()).Times(0);
2636 EXPECT_CALL(*context, produceTextureCHROMIUM(_, _)).Times(0);
2637 EXPECT_CALL(*context, consumeTextureCHROMIUM(_, _)).Times(0);
2638
2639 gpu::Mailbox gpu_mailbox;
2640 memcpy(gpu_mailbox.name, "Hello world", strlen("Hello world") + 1);
2641 uint32 release_sync_point = 0;
2642 bool lost_resource = false;
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
2650 TextureMailbox mailbox(gpu_mailbox, target, sync_point);
2651
2652 ResourceProvider::ResourceId id =
2653 resource_provider->CreateResourceFromTextureMailbox(
2654 mailbox, callback.Pass());
2655 EXPECT_NE(0u, id);
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 } 2730 }
2690 2731
2691 TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) { 2732 TEST_P(ResourceProviderTest, TextureMailbox_GLTextureExternalOES) {
2692 // Mailboxing is only supported for GL textures. 2733 // Mailboxing is only supported for GL textures.
2693 if (GetParam() != ResourceProvider::GLTexture) 2734 if (GetParam() != ResourceProvider::GLTexture)
2694 return; 2735 return;
2695 2736
2696 scoped_ptr<TextureStateTrackingContext> context_owned( 2737 scoped_ptr<TextureStateTrackingContext> context_owned(
2697 new TextureStateTrackingContext); 2738 new TextureStateTrackingContext);
2698 TextureStateTrackingContext* context = context_owned.get(); 2739 TextureStateTrackingContext* context = context_owned.get();
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
3639 resource_provider->AllocateForTesting(id); 3680 resource_provider->AllocateForTesting(id);
3640 Mock::VerifyAndClearExpectations(context); 3681 Mock::VerifyAndClearExpectations(context);
3641 3682
3642 DCHECK_EQ(10u, context->PeekTextureId()); 3683 DCHECK_EQ(10u, context->PeekTextureId());
3643 resource_provider->DeleteResource(id); 3684 resource_provider->DeleteResource(id);
3644 } 3685 }
3645 } 3686 }
3646 3687
3647 } // namespace 3688 } // namespace
3648 } // namespace cc 3689 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698