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 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 gfx::Rect rect(size); | 647 gfx::Rect rect(size); |
648 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); | 648 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); |
649 | 649 |
650 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( | 650 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( |
651 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 651 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
652 uint8_t data2[4] = { 5, 5, 5, 5 }; | 652 uint8_t data2[4] = { 5, 5, 5, 5 }; |
653 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); | 653 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); |
654 | 654 |
655 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( | 655 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( |
656 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 656 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
657 child_resource_provider_->AcquireImage(id3); | 657 child_resource_provider_->MapImageRasterBuffer(id3); |
658 child_resource_provider_->MapImage(id3); | 658 child_resource_provider_->UnmapImageRasterBuffer(id3); |
659 child_resource_provider_->UnmapImage(id3); | |
660 | 659 |
661 GLuint external_texture_id = child_context_->createExternalTexture(); | 660 GLuint external_texture_id = child_context_->createExternalTexture(); |
662 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id); | 661 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id); |
663 | 662 |
664 gpu::Mailbox external_mailbox; | 663 gpu::Mailbox external_mailbox; |
665 child_context_->genMailboxCHROMIUM(external_mailbox.name); | 664 child_context_->genMailboxCHROMIUM(external_mailbox.name); |
666 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, | 665 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, |
667 external_mailbox.name); | 666 external_mailbox.name); |
668 const GLuint external_sync_point = child_context_->insertSyncPoint(); | 667 const GLuint external_sync_point = child_context_->insertSyncPoint(); |
669 ResourceProvider::ResourceId id4 = | 668 ResourceProvider::ResourceId id4 = |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 gfx::Rect rect(size); | 887 gfx::Rect rect(size); |
889 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); | 888 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); |
890 | 889 |
891 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( | 890 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( |
892 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 891 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
893 uint8_t data2[4] = { 5, 5, 5, 5 }; | 892 uint8_t data2[4] = { 5, 5, 5, 5 }; |
894 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); | 893 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); |
895 | 894 |
896 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( | 895 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( |
897 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 896 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
898 child_resource_provider_->AcquireImage(id3); | |
899 void* data = child_resource_provider_->MapImage(id3); | |
900 uint8_t data3[4] = { 6, 7, 8, 9 }; | 897 uint8_t data3[4] = { 6, 7, 8, 9 }; |
901 memcpy(data, data3, sizeof(data3)); | 898 SkBitmap bitmap3; |
902 child_resource_provider_->UnmapImage(id3); | 899 bitmap3.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
| 900 bitmap3.setPixels(data3); |
| 901 SkCanvas* raster_canvas = child_resource_provider_->MapImageRasterBuffer(id3); |
| 902 raster_canvas->writePixels(bitmap3, 0, 0); |
| 903 child_resource_provider_->UnmapImageRasterBuffer(id3); |
903 | 904 |
904 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 905 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
905 shared_memory->CreateAndMapAnonymous(1); | 906 shared_memory->CreateAndMapAnonymous(1); |
906 base::SharedMemory* shared_memory_ptr = shared_memory.get(); | 907 base::SharedMemory* shared_memory_ptr = shared_memory.get(); |
907 ResourceProvider::ResourceId id4 = | 908 ResourceProvider::ResourceId id4 = |
908 child_resource_provider_->CreateResourceFromTextureMailbox( | 909 child_resource_provider_->CreateResourceFromTextureMailbox( |
909 TextureMailbox(shared_memory_ptr, gfx::Size(1, 1)), | 910 TextureMailbox(shared_memory_ptr, gfx::Size(1, 1)), |
910 SingleReleaseCallback::Create(base::Bind( | 911 SingleReleaseCallback::Create(base::Bind( |
911 &SharedMemoryReleaseCallback, base::Passed(&shared_memory)))); | 912 &SharedMemoryReleaseCallback, base::Passed(&shared_memory)))); |
912 | 913 |
(...skipping 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2609 resource_provider->SetPixels(id, pixels, rect, rect, offset); | 2610 resource_provider->SetPixels(id, pixels, rect, rect, offset); |
2610 | 2611 |
2611 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 2612 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
2612 resource_provider->DeleteResource(id); | 2613 resource_provider->DeleteResource(id); |
2613 | 2614 |
2614 Mock::VerifyAndClearExpectations(context); | 2615 Mock::VerifyAndClearExpectations(context); |
2615 | 2616 |
2616 // Same for async version. | 2617 // Same for async version. |
2617 id = resource_provider->CreateResource( | 2618 id = resource_provider->CreateResource( |
2618 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2619 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2619 resource_provider->AcquirePixelBuffer(id); | 2620 resource_provider->AcquirePixelRasterBuffer(id); |
2620 | 2621 |
2621 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 2622 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
2622 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 2623 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
2623 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 2624 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
2624 .Times(1); | 2625 .Times(1); |
2625 resource_provider->BeginSetPixels(id); | 2626 resource_provider->BeginSetPixels(id); |
2626 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 2627 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
2627 | 2628 |
2628 resource_provider->ReleasePixelBuffer(id); | 2629 resource_provider->ReleasePixelRasterBuffer(id); |
2629 | 2630 |
2630 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 2631 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
2631 resource_provider->DeleteResource(id); | 2632 resource_provider->DeleteResource(id); |
2632 | 2633 |
2633 Mock::VerifyAndClearExpectations(context); | 2634 Mock::VerifyAndClearExpectations(context); |
2634 } | 2635 } |
2635 | 2636 |
2636 TEST_P(ResourceProviderTest, TextureAllocationStorageUsageAny) { | 2637 TEST_P(ResourceProviderTest, TextureAllocationStorageUsageAny) { |
2637 // Only for GL textures. | 2638 // Only for GL textures. |
2638 if (GetParam() != ResourceProvider::GLTexture) | 2639 if (GetParam() != ResourceProvider::GLTexture) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2725 gfx::Size size(2, 2); | 2726 gfx::Size size(2, 2); |
2726 ResourceFormat format = RGBA_8888; | 2727 ResourceFormat format = RGBA_8888; |
2727 ResourceProvider::ResourceId id = 0; | 2728 ResourceProvider::ResourceId id = 0; |
2728 int texture_id = 123; | 2729 int texture_id = 123; |
2729 | 2730 |
2730 scoped_ptr<ResourceProvider> resource_provider( | 2731 scoped_ptr<ResourceProvider> resource_provider( |
2731 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2732 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2732 | 2733 |
2733 id = resource_provider->CreateResource( | 2734 id = resource_provider->CreateResource( |
2734 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2735 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2735 resource_provider->AcquirePixelBuffer(id); | 2736 resource_provider->AcquirePixelRasterBuffer(id); |
2736 | 2737 |
2737 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 2738 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
2738 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 2739 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
2739 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 2740 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
2740 .Times(1); | 2741 .Times(1); |
2741 resource_provider->BeginSetPixels(id); | 2742 resource_provider->BeginSetPixels(id); |
2742 | 2743 |
2743 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 2744 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
2744 | 2745 |
2745 resource_provider->ReleasePixelBuffer(id); | 2746 resource_provider->ReleasePixelRasterBuffer(id); |
2746 | 2747 |
2747 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 2748 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
2748 resource_provider->DeleteResource(id); | 2749 resource_provider->DeleteResource(id); |
2749 | 2750 |
2750 Mock::VerifyAndClearExpectations(context); | 2751 Mock::VerifyAndClearExpectations(context); |
2751 } | 2752 } |
2752 | 2753 |
2753 TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) { | 2754 TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) { |
2754 if (GetParam() != ResourceProvider::Bitmap) | 2755 if (GetParam() != ResourceProvider::Bitmap) |
2755 return; | 2756 return; |
2756 FakeOutputSurfaceClient output_surface_client; | 2757 FakeOutputSurfaceClient output_surface_client; |
2757 scoped_ptr<OutputSurface> output_surface( | 2758 scoped_ptr<OutputSurface> output_surface( |
2758 FakeOutputSurface::CreateSoftware(make_scoped_ptr( | 2759 FakeOutputSurface::CreateSoftware(make_scoped_ptr( |
2759 new SoftwareOutputDevice))); | 2760 new SoftwareOutputDevice))); |
2760 CHECK(output_surface->BindToClient(&output_surface_client)); | 2761 CHECK(output_surface->BindToClient(&output_surface_client)); |
2761 | 2762 |
2762 gfx::Size size(1, 1); | 2763 gfx::Size size(1, 1); |
2763 ResourceFormat format = RGBA_8888; | 2764 ResourceFormat format = RGBA_8888; |
2764 ResourceProvider::ResourceId id = 0; | 2765 ResourceProvider::ResourceId id = 0; |
2765 const uint32_t kBadBeef = 0xbadbeef; | 2766 const uint32_t kBadBeef = 0xbadbeef; |
2766 | 2767 |
2767 scoped_ptr<ResourceProvider> resource_provider( | 2768 scoped_ptr<ResourceProvider> resource_provider( |
2768 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2769 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2769 | 2770 |
2770 id = resource_provider->CreateResource( | 2771 id = resource_provider->CreateResource( |
2771 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2772 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2772 resource_provider->AcquirePixelBuffer(id); | 2773 resource_provider->AcquirePixelRasterBuffer(id); |
2773 | 2774 |
2774 void* data = resource_provider->MapPixelBuffer(id); | 2775 SkBitmap bitmap; |
2775 ASSERT_TRUE(!!data); | 2776 bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
2776 memcpy(data, &kBadBeef, sizeof(kBadBeef)); | 2777 bitmap.allocPixels(); |
2777 resource_provider->UnmapPixelBuffer(id); | 2778 *(bitmap.getAddr32(0, 0)) = kBadBeef; |
| 2779 SkCanvas* canvas = resource_provider->MapPixelRasterBuffer(id); |
| 2780 canvas->writePixels(bitmap, 0, 0); |
| 2781 resource_provider->UnmapPixelRasterBuffer(id); |
2778 | 2782 |
2779 resource_provider->BeginSetPixels(id); | 2783 resource_provider->BeginSetPixels(id); |
2780 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 2784 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
2781 | 2785 |
2782 resource_provider->ReleasePixelBuffer(id); | 2786 resource_provider->ReleasePixelRasterBuffer(id); |
2783 | 2787 |
2784 { | 2788 { |
2785 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); | 2789 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); |
2786 const SkBitmap* sk_bitmap = lock.sk_bitmap(); | 2790 const SkBitmap* sk_bitmap = lock.sk_bitmap(); |
2787 EXPECT_EQ(sk_bitmap->width(), size.width()); | 2791 EXPECT_EQ(sk_bitmap->width(), size.width()); |
2788 EXPECT_EQ(sk_bitmap->height(), size.height()); | 2792 EXPECT_EQ(sk_bitmap->height(), size.height()); |
2789 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); | 2793 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); |
2790 } | 2794 } |
2791 | 2795 |
2792 resource_provider->DeleteResource(id); | 2796 resource_provider->DeleteResource(id); |
(...skipping 15 matching lines...) Expand all Loading... |
2808 gfx::Size size(2, 2); | 2812 gfx::Size size(2, 2); |
2809 ResourceFormat format = RGBA_8888; | 2813 ResourceFormat format = RGBA_8888; |
2810 ResourceProvider::ResourceId id = 0; | 2814 ResourceProvider::ResourceId id = 0; |
2811 int texture_id = 123; | 2815 int texture_id = 123; |
2812 | 2816 |
2813 scoped_ptr<ResourceProvider> resource_provider( | 2817 scoped_ptr<ResourceProvider> resource_provider( |
2814 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2818 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2815 | 2819 |
2816 id = resource_provider->CreateResource( | 2820 id = resource_provider->CreateResource( |
2817 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2821 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2818 resource_provider->AcquirePixelBuffer(id); | 2822 resource_provider->AcquirePixelRasterBuffer(id); |
2819 | 2823 |
2820 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 2824 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
2821 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 2825 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
2822 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 2826 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
2823 .Times(1); | 2827 .Times(1); |
2824 resource_provider->BeginSetPixels(id); | 2828 resource_provider->BeginSetPixels(id); |
2825 | 2829 |
2826 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); | 2830 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); |
2827 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); | 2831 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); |
2828 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); | 2832 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); |
2829 resource_provider->ForceSetPixelsToComplete(id); | 2833 resource_provider->ForceSetPixelsToComplete(id); |
2830 | 2834 |
2831 resource_provider->ReleasePixelBuffer(id); | 2835 resource_provider->ReleasePixelRasterBuffer(id); |
2832 | 2836 |
2833 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 2837 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
2834 resource_provider->DeleteResource(id); | 2838 resource_provider->DeleteResource(id); |
2835 | 2839 |
2836 Mock::VerifyAndClearExpectations(context); | 2840 Mock::VerifyAndClearExpectations(context); |
2837 } | 2841 } |
2838 | 2842 |
2839 TEST_P(ResourceProviderTest, PixelBufferLostContext) { | 2843 TEST_P(ResourceProviderTest, PixelBufferLostContext) { |
2840 scoped_ptr<AllocationTrackingContext3D> context_owned( | 2844 scoped_ptr<AllocationTrackingContext3D> context_owned( |
2841 new NiceMock<AllocationTrackingContext3D>); | 2845 new NiceMock<AllocationTrackingContext3D>); |
(...skipping 11 matching lines...) Expand all Loading... |
2853 | 2857 |
2854 scoped_ptr<ResourceProvider> resource_provider( | 2858 scoped_ptr<ResourceProvider> resource_provider( |
2855 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2859 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2856 | 2860 |
2857 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id)); | 2861 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id)); |
2858 | 2862 |
2859 id = resource_provider->CreateResource( | 2863 id = resource_provider->CreateResource( |
2860 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2864 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2861 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 2865 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
2862 GL_INNOCENT_CONTEXT_RESET_ARB); | 2866 GL_INNOCENT_CONTEXT_RESET_ARB); |
2863 resource_provider->AcquirePixelBuffer(id); | 2867 |
2864 uint8_t* buffer = resource_provider->MapPixelBuffer(id); | 2868 resource_provider->AcquirePixelRasterBuffer(id); |
2865 EXPECT_TRUE(buffer == NULL); | 2869 SkCanvas* raster_canvas = resource_provider->MapPixelRasterBuffer(id); |
2866 resource_provider->UnmapPixelBuffer(id); | 2870 EXPECT_TRUE(raster_canvas == NULL); |
2867 resource_provider->ReleasePixelBuffer(id); | 2871 resource_provider->UnmapPixelRasterBuffer(id); |
| 2872 resource_provider->ReleasePixelRasterBuffer(id); |
2868 Mock::VerifyAndClearExpectations(context); | 2873 Mock::VerifyAndClearExpectations(context); |
2869 } | 2874 } |
2870 | 2875 |
2871 TEST_P(ResourceProviderTest, Image_GLTexture) { | 2876 TEST_P(ResourceProviderTest, Image_GLTexture) { |
2872 // Only for GL textures. | 2877 // Only for GL textures. |
2873 if (GetParam() != ResourceProvider::GLTexture) | 2878 if (GetParam() != ResourceProvider::GLTexture) |
2874 return; | 2879 return; |
2875 scoped_ptr<AllocationTrackingContext3D> context_owned( | 2880 scoped_ptr<AllocationTrackingContext3D> context_owned( |
2876 new StrictMock<AllocationTrackingContext3D>); | 2881 new StrictMock<AllocationTrackingContext3D>); |
2877 AllocationTrackingContext3D* context = context_owned.get(); | 2882 AllocationTrackingContext3D* context = context_owned.get(); |
2878 | 2883 |
2879 FakeOutputSurfaceClient output_surface_client; | 2884 FakeOutputSurfaceClient output_surface_client; |
2880 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2885 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
2881 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2886 context_owned.PassAs<TestWebGraphicsContext3D>())); |
2882 CHECK(output_surface->BindToClient(&output_surface_client)); | 2887 CHECK(output_surface->BindToClient(&output_surface_client)); |
2883 | 2888 |
2884 const int kWidth = 2; | 2889 const int kWidth = 2; |
2885 const int kHeight = 2; | 2890 const int kHeight = 2; |
2886 gfx::Size size(kWidth, kHeight); | 2891 gfx::Size size(kWidth, kHeight); |
2887 ResourceFormat format = RGBA_8888; | 2892 ResourceFormat format = RGBA_8888; |
2888 ResourceProvider::ResourceId id = 0; | 2893 ResourceProvider::ResourceId id = 0; |
2889 const unsigned kTextureId = 123u; | 2894 const unsigned kTextureId = 123u; |
2890 const unsigned kImageId = 234u; | 2895 const unsigned kImageId = 234u; |
2891 | 2896 |
2892 scoped_ptr<ResourceProvider> resource_provider( | 2897 scoped_ptr<ResourceProvider> resource_provider( |
2893 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2898 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2894 | 2899 |
2895 id = resource_provider->CreateResource( | 2900 id = resource_provider->CreateResource( |
2896 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2901 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2902 |
| 2903 const int kStride = 4; |
| 2904 void* dummy_mapped_buffer_address = NULL; |
2897 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) | 2905 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) |
2898 .WillOnce(Return(kImageId)) | 2906 .WillOnce(Return(kImageId)) |
2899 .RetiresOnSaturation(); | 2907 .RetiresOnSaturation(); |
2900 resource_provider->AcquireImage(id); | |
2901 | |
2902 void* dummy_mapped_buffer_address = NULL; | |
2903 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) | |
2904 .WillOnce(Return(dummy_mapped_buffer_address)) | |
2905 .RetiresOnSaturation(); | |
2906 resource_provider->MapImage(id); | |
2907 | |
2908 const int kStride = 4; | |
2909 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId, | 2908 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId, |
2910 GL_IMAGE_ROWBYTES_CHROMIUM, | 2909 GL_IMAGE_ROWBYTES_CHROMIUM, |
2911 _)) | 2910 _)) |
2912 .WillOnce(SetArgPointee<2>(kStride)) | 2911 .WillOnce(SetArgPointee<2>(kStride)) |
2913 .RetiresOnSaturation(); | 2912 .RetiresOnSaturation(); |
2914 int stride = resource_provider->GetImageStride(id); | 2913 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) |
2915 EXPECT_EQ(kStride, stride); | 2914 .WillOnce(Return(dummy_mapped_buffer_address)) |
| 2915 .RetiresOnSaturation(); |
| 2916 resource_provider->MapImageRasterBuffer(id); |
2916 | 2917 |
2917 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) | 2918 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) |
2918 .Times(1) | 2919 .Times(1) |
2919 .RetiresOnSaturation(); | 2920 .RetiresOnSaturation(); |
2920 resource_provider->UnmapImage(id); | 2921 resource_provider->UnmapImageRasterBuffer(id); |
2921 | 2922 |
2922 EXPECT_CALL(*context, NextTextureId()) | 2923 EXPECT_CALL(*context, NextTextureId()) |
2923 .WillOnce(Return(kTextureId)) | 2924 .WillOnce(Return(kTextureId)) |
2924 .RetiresOnSaturation(); | 2925 .RetiresOnSaturation(); |
2925 // Once in CreateTextureId and once in BindForSampling | 2926 // Once in CreateTextureId and once in BindForSampling |
2926 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2) | 2927 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2) |
2927 .RetiresOnSaturation(); | 2928 .RetiresOnSaturation(); |
2928 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | 2929 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
2929 .Times(1) | 2930 .Times(1) |
2930 .RetiresOnSaturation(); | 2931 .RetiresOnSaturation(); |
2931 { | 2932 { |
2932 ResourceProvider::ScopedSamplerGL lock_gl( | 2933 ResourceProvider::ScopedSamplerGL lock_gl( |
2933 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); | 2934 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); |
2934 EXPECT_EQ(kTextureId, lock_gl.texture_id()); | 2935 EXPECT_EQ(kTextureId, lock_gl.texture_id()); |
2935 } | 2936 } |
2936 | 2937 |
| 2938 EXPECT_CALL( |
| 2939 *context, |
| 2940 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) |
| 2941 .WillOnce(SetArgPointee<2>(kStride)) |
| 2942 .RetiresOnSaturation(); |
2937 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) | 2943 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) |
2938 .WillOnce(Return(dummy_mapped_buffer_address)) | 2944 .WillOnce(Return(dummy_mapped_buffer_address)) |
2939 .RetiresOnSaturation(); | 2945 .RetiresOnSaturation(); |
2940 resource_provider->MapImage(id); | 2946 resource_provider->MapImageRasterBuffer(id); |
2941 | 2947 |
2942 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) | 2948 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) |
2943 .Times(1) | 2949 .Times(1) |
2944 .RetiresOnSaturation(); | 2950 .RetiresOnSaturation(); |
2945 resource_provider->UnmapImage(id); | 2951 resource_provider->UnmapImageRasterBuffer(id); |
2946 | 2952 |
2947 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) | 2953 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) |
2948 .RetiresOnSaturation(); | 2954 .RetiresOnSaturation(); |
2949 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | 2955 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
2950 .Times(1) | 2956 .Times(1) |
2951 .RetiresOnSaturation(); | 2957 .RetiresOnSaturation(); |
2952 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | 2958 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
2953 .Times(1) | 2959 .Times(1) |
2954 .RetiresOnSaturation(); | 2960 .RetiresOnSaturation(); |
2955 EXPECT_CALL(*context, RetireTextureId(kTextureId)) | 2961 EXPECT_CALL(*context, RetireTextureId(kTextureId)) |
2956 .Times(1) | 2962 .Times(1) |
2957 .RetiresOnSaturation(); | 2963 .RetiresOnSaturation(); |
2958 { | 2964 { |
2959 ResourceProvider::ScopedSamplerGL lock_gl( | 2965 ResourceProvider::ScopedSamplerGL lock_gl( |
2960 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); | 2966 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); |
2961 EXPECT_EQ(kTextureId, lock_gl.texture_id()); | 2967 EXPECT_EQ(kTextureId, lock_gl.texture_id()); |
2962 } | 2968 } |
2963 | 2969 |
2964 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) | 2970 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) |
2965 .Times(1) | 2971 .Times(1) |
2966 .RetiresOnSaturation(); | 2972 .RetiresOnSaturation(); |
2967 resource_provider->ReleaseImage(id); | |
2968 } | 2973 } |
2969 | 2974 |
2970 TEST_P(ResourceProviderTest, Image_Bitmap) { | 2975 TEST_P(ResourceProviderTest, Image_Bitmap) { |
2971 if (GetParam() != ResourceProvider::Bitmap) | 2976 if (GetParam() != ResourceProvider::Bitmap) |
2972 return; | 2977 return; |
2973 FakeOutputSurfaceClient output_surface_client; | 2978 FakeOutputSurfaceClient output_surface_client; |
2974 scoped_ptr<OutputSurface> output_surface( | 2979 scoped_ptr<OutputSurface> output_surface( |
2975 FakeOutputSurface::CreateSoftware(make_scoped_ptr( | 2980 FakeOutputSurface::CreateSoftware(make_scoped_ptr( |
2976 new SoftwareOutputDevice))); | 2981 new SoftwareOutputDevice))); |
2977 CHECK(output_surface->BindToClient(&output_surface_client)); | 2982 CHECK(output_surface->BindToClient(&output_surface_client)); |
2978 | 2983 |
2979 gfx::Size size(1, 1); | 2984 gfx::Size size(1, 1); |
2980 ResourceFormat format = RGBA_8888; | 2985 ResourceFormat format = RGBA_8888; |
2981 ResourceProvider::ResourceId id = 0; | 2986 ResourceProvider::ResourceId id = 0; |
2982 const uint32_t kBadBeef = 0xbadbeef; | 2987 const uint32_t kBadBeef = 0xbadbeef; |
2983 | 2988 |
2984 scoped_ptr<ResourceProvider> resource_provider( | 2989 scoped_ptr<ResourceProvider> resource_provider( |
2985 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2990 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2986 | 2991 |
2987 id = resource_provider->CreateResource( | 2992 id = resource_provider->CreateResource( |
2988 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2993 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2989 resource_provider->AcquireImage(id); | |
2990 | 2994 |
2991 const int kStride = 0; | 2995 SkBitmap bitmap; |
2992 int stride = resource_provider->GetImageStride(id); | 2996 bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
2993 EXPECT_EQ(kStride, stride); | 2997 bitmap.allocPixels(); |
2994 | 2998 *(bitmap.getAddr32(0, 0)) = kBadBeef; |
2995 void* data = resource_provider->MapImage(id); | 2999 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(id); |
2996 ASSERT_TRUE(!!data); | 3000 ASSERT_TRUE(!!canvas); |
2997 memcpy(data, &kBadBeef, sizeof(kBadBeef)); | 3001 canvas->writePixels(bitmap, 0, 0); |
2998 resource_provider->UnmapImage(id); | 3002 resource_provider->UnmapImageRasterBuffer(id); |
2999 | 3003 |
3000 { | 3004 { |
3001 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); | 3005 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); |
3002 const SkBitmap* sk_bitmap = lock.sk_bitmap(); | 3006 const SkBitmap* sk_bitmap = lock.sk_bitmap(); |
3003 EXPECT_EQ(sk_bitmap->width(), size.width()); | 3007 EXPECT_EQ(sk_bitmap->width(), size.width()); |
3004 EXPECT_EQ(sk_bitmap->height(), size.height()); | 3008 EXPECT_EQ(sk_bitmap->height(), size.height()); |
3005 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); | 3009 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); |
3006 } | 3010 } |
3007 | 3011 |
3008 resource_provider->ReleaseImage(id); | |
3009 resource_provider->DeleteResource(id); | 3012 resource_provider->DeleteResource(id); |
3010 } | 3013 } |
3011 | 3014 |
3012 void InitializeGLAndCheck(ContextSharedData* shared_data, | 3015 void InitializeGLAndCheck(ContextSharedData* shared_data, |
3013 ResourceProvider* resource_provider, | 3016 ResourceProvider* resource_provider, |
3014 FakeOutputSurface* output_surface) { | 3017 FakeOutputSurface* output_surface) { |
3015 scoped_ptr<ResourceProviderContext> context_owned = | 3018 scoped_ptr<ResourceProviderContext> context_owned = |
3016 ResourceProviderContext::Create(shared_data); | 3019 ResourceProviderContext::Create(shared_data); |
3017 ResourceProviderContext* context = context_owned.get(); | 3020 ResourceProviderContext* context = context_owned.get(); |
3018 | 3021 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3186 resource_provider->AllocateForTesting(id); | 3189 resource_provider->AllocateForTesting(id); |
3187 Mock::VerifyAndClearExpectations(context); | 3190 Mock::VerifyAndClearExpectations(context); |
3188 | 3191 |
3189 DCHECK_EQ(10u, context->PeekTextureId()); | 3192 DCHECK_EQ(10u, context->PeekTextureId()); |
3190 resource_provider->DeleteResource(id); | 3193 resource_provider->DeleteResource(id); |
3191 } | 3194 } |
3192 } | 3195 } |
3193 | 3196 |
3194 } // namespace | 3197 } // namespace |
3195 } // namespace cc | 3198 } // namespace cc |
OLD | NEW |