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 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2604 resource_provider->SetPixels(id, pixels, rect, rect, offset); | 2605 resource_provider->SetPixels(id, pixels, rect, rect, offset); |
2605 | 2606 |
2606 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 2607 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
2607 resource_provider->DeleteResource(id); | 2608 resource_provider->DeleteResource(id); |
2608 | 2609 |
2609 Mock::VerifyAndClearExpectations(context); | 2610 Mock::VerifyAndClearExpectations(context); |
2610 | 2611 |
2611 // Same for async version. | 2612 // Same for async version. |
2612 id = resource_provider->CreateResource( | 2613 id = resource_provider->CreateResource( |
2613 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2614 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2614 resource_provider->AcquirePixelBuffer(id); | 2615 resource_provider->AcquirePixelRasterBuffer(id); |
2615 | 2616 |
2616 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 2617 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
2617 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 2618 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
2618 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 2619 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
2619 .Times(1); | 2620 .Times(1); |
2620 resource_provider->BeginSetPixels(id); | 2621 resource_provider->BeginSetPixels(id); |
2621 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 2622 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
2622 | 2623 |
2623 resource_provider->ReleasePixelBuffer(id); | 2624 resource_provider->ReleasePixelRasterBuffer(id); |
2624 | 2625 |
2625 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 2626 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
2626 resource_provider->DeleteResource(id); | 2627 resource_provider->DeleteResource(id); |
2627 | 2628 |
2628 Mock::VerifyAndClearExpectations(context); | 2629 Mock::VerifyAndClearExpectations(context); |
2629 } | 2630 } |
2630 | 2631 |
2631 TEST_P(ResourceProviderTest, TextureAllocationStorageUsageAny) { | 2632 TEST_P(ResourceProviderTest, TextureAllocationStorageUsageAny) { |
2632 // Only for GL textures. | 2633 // Only for GL textures. |
2633 if (GetParam() != ResourceProvider::GLTexture) | 2634 if (GetParam() != ResourceProvider::GLTexture) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2720 gfx::Size size(2, 2); | 2721 gfx::Size size(2, 2); |
2721 ResourceFormat format = RGBA_8888; | 2722 ResourceFormat format = RGBA_8888; |
2722 ResourceProvider::ResourceId id = 0; | 2723 ResourceProvider::ResourceId id = 0; |
2723 int texture_id = 123; | 2724 int texture_id = 123; |
2724 | 2725 |
2725 scoped_ptr<ResourceProvider> resource_provider( | 2726 scoped_ptr<ResourceProvider> resource_provider( |
2726 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2727 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2727 | 2728 |
2728 id = resource_provider->CreateResource( | 2729 id = resource_provider->CreateResource( |
2729 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2730 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2730 resource_provider->AcquirePixelBuffer(id); | 2731 resource_provider->AcquirePixelRasterBuffer(id); |
2731 | 2732 |
2732 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 2733 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
2733 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 2734 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
2734 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 2735 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
2735 .Times(1); | 2736 .Times(1); |
2736 resource_provider->BeginSetPixels(id); | 2737 resource_provider->BeginSetPixels(id); |
2737 | 2738 |
2738 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 2739 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
2739 | 2740 |
2740 resource_provider->ReleasePixelBuffer(id); | 2741 resource_provider->ReleasePixelRasterBuffer(id); |
2741 | 2742 |
2742 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 2743 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
2743 resource_provider->DeleteResource(id); | 2744 resource_provider->DeleteResource(id); |
2744 | 2745 |
2745 Mock::VerifyAndClearExpectations(context); | 2746 Mock::VerifyAndClearExpectations(context); |
2746 } | 2747 } |
2747 | 2748 |
2748 TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) { | 2749 TEST_P(ResourceProviderTest, PixelBuffer_Bitmap) { |
2749 if (GetParam() != ResourceProvider::Bitmap) | 2750 if (GetParam() != ResourceProvider::Bitmap) |
2750 return; | 2751 return; |
2751 FakeOutputSurfaceClient output_surface_client; | 2752 FakeOutputSurfaceClient output_surface_client; |
2752 scoped_ptr<OutputSurface> output_surface( | 2753 scoped_ptr<OutputSurface> output_surface( |
2753 FakeOutputSurface::CreateSoftware(make_scoped_ptr( | 2754 FakeOutputSurface::CreateSoftware(make_scoped_ptr( |
2754 new SoftwareOutputDevice))); | 2755 new SoftwareOutputDevice))); |
2755 CHECK(output_surface->BindToClient(&output_surface_client)); | 2756 CHECK(output_surface->BindToClient(&output_surface_client)); |
2756 | 2757 |
2757 gfx::Size size(1, 1); | 2758 gfx::Size size(1, 1); |
2758 ResourceFormat format = RGBA_8888; | 2759 ResourceFormat format = RGBA_8888; |
2759 ResourceProvider::ResourceId id = 0; | 2760 ResourceProvider::ResourceId id = 0; |
2760 const uint32_t kBadBeef = 0xbadbeef; | 2761 const uint32_t kBadBeef = 0xbadbeef; |
2761 | 2762 |
2762 scoped_ptr<ResourceProvider> resource_provider( | 2763 scoped_ptr<ResourceProvider> resource_provider( |
2763 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2764 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2764 | 2765 |
2765 id = resource_provider->CreateResource( | 2766 id = resource_provider->CreateResource( |
2766 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2767 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2767 resource_provider->AcquirePixelBuffer(id); | 2768 resource_provider->AcquirePixelRasterBuffer(id); |
2768 | 2769 |
2769 void* data = resource_provider->MapPixelBuffer(id); | 2770 SkBitmap bitmap; |
2770 ASSERT_TRUE(!!data); | 2771 bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
2771 memcpy(data, &kBadBeef, sizeof(kBadBeef)); | 2772 bitmap.allocPixels(); |
2772 resource_provider->UnmapPixelBuffer(id); | 2773 *(bitmap.getAddr32(0, 0)) = kBadBeef; |
| 2774 SkCanvas* canvas = resource_provider->MapPixelRasterBuffer(id); |
| 2775 canvas->writePixels(bitmap, 0, 0); |
| 2776 resource_provider->UnmapPixelRasterBuffer(id); |
2773 | 2777 |
2774 resource_provider->BeginSetPixels(id); | 2778 resource_provider->BeginSetPixels(id); |
2775 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 2779 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
2776 | 2780 |
2777 resource_provider->ReleasePixelBuffer(id); | 2781 resource_provider->ReleasePixelRasterBuffer(id); |
2778 | 2782 |
2779 { | 2783 { |
2780 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); | 2784 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); |
2781 const SkBitmap* sk_bitmap = lock.sk_bitmap(); | 2785 const SkBitmap* sk_bitmap = lock.sk_bitmap(); |
2782 EXPECT_EQ(sk_bitmap->width(), size.width()); | 2786 EXPECT_EQ(sk_bitmap->width(), size.width()); |
2783 EXPECT_EQ(sk_bitmap->height(), size.height()); | 2787 EXPECT_EQ(sk_bitmap->height(), size.height()); |
2784 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); | 2788 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); |
2785 } | 2789 } |
2786 | 2790 |
2787 resource_provider->DeleteResource(id); | 2791 resource_provider->DeleteResource(id); |
(...skipping 15 matching lines...) Expand all Loading... |
2803 gfx::Size size(2, 2); | 2807 gfx::Size size(2, 2); |
2804 ResourceFormat format = RGBA_8888; | 2808 ResourceFormat format = RGBA_8888; |
2805 ResourceProvider::ResourceId id = 0; | 2809 ResourceProvider::ResourceId id = 0; |
2806 int texture_id = 123; | 2810 int texture_id = 123; |
2807 | 2811 |
2808 scoped_ptr<ResourceProvider> resource_provider( | 2812 scoped_ptr<ResourceProvider> resource_provider( |
2809 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2813 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2810 | 2814 |
2811 id = resource_provider->CreateResource( | 2815 id = resource_provider->CreateResource( |
2812 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2816 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2813 resource_provider->AcquirePixelBuffer(id); | 2817 resource_provider->AcquirePixelRasterBuffer(id); |
2814 | 2818 |
2815 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 2819 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
2816 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 2820 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
2817 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 2821 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
2818 .Times(1); | 2822 .Times(1); |
2819 resource_provider->BeginSetPixels(id); | 2823 resource_provider->BeginSetPixels(id); |
2820 | 2824 |
2821 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); | 2825 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); |
2822 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); | 2826 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); |
2823 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); | 2827 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); |
2824 resource_provider->ForceSetPixelsToComplete(id); | 2828 resource_provider->ForceSetPixelsToComplete(id); |
2825 | 2829 |
2826 resource_provider->ReleasePixelBuffer(id); | 2830 resource_provider->ReleasePixelRasterBuffer(id); |
2827 | 2831 |
2828 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 2832 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
2829 resource_provider->DeleteResource(id); | 2833 resource_provider->DeleteResource(id); |
2830 | 2834 |
2831 Mock::VerifyAndClearExpectations(context); | 2835 Mock::VerifyAndClearExpectations(context); |
2832 } | 2836 } |
2833 | 2837 |
2834 TEST_P(ResourceProviderTest, PixelBufferLostContext) { | 2838 TEST_P(ResourceProviderTest, PixelBufferLostContext) { |
2835 scoped_ptr<AllocationTrackingContext3D> context_owned( | 2839 scoped_ptr<AllocationTrackingContext3D> context_owned( |
2836 new NiceMock<AllocationTrackingContext3D>); | 2840 new NiceMock<AllocationTrackingContext3D>); |
(...skipping 11 matching lines...) Expand all Loading... |
2848 | 2852 |
2849 scoped_ptr<ResourceProvider> resource_provider( | 2853 scoped_ptr<ResourceProvider> resource_provider( |
2850 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2854 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2851 | 2855 |
2852 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id)); | 2856 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id)); |
2853 | 2857 |
2854 id = resource_provider->CreateResource( | 2858 id = resource_provider->CreateResource( |
2855 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2859 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2856 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 2860 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
2857 GL_INNOCENT_CONTEXT_RESET_ARB); | 2861 GL_INNOCENT_CONTEXT_RESET_ARB); |
2858 resource_provider->AcquirePixelBuffer(id); | 2862 |
2859 uint8_t* buffer = resource_provider->MapPixelBuffer(id); | 2863 resource_provider->AcquirePixelRasterBuffer(id); |
2860 EXPECT_TRUE(buffer == NULL); | 2864 SkCanvas* raster_canvas = resource_provider->MapPixelRasterBuffer(id); |
2861 resource_provider->UnmapPixelBuffer(id); | 2865 EXPECT_TRUE(raster_canvas == NULL); |
2862 resource_provider->ReleasePixelBuffer(id); | 2866 resource_provider->UnmapPixelRasterBuffer(id); |
| 2867 resource_provider->ReleasePixelRasterBuffer(id); |
2863 Mock::VerifyAndClearExpectations(context); | 2868 Mock::VerifyAndClearExpectations(context); |
2864 } | 2869 } |
2865 | 2870 |
2866 TEST_P(ResourceProviderTest, Image_GLTexture) { | 2871 TEST_P(ResourceProviderTest, Image_GLTexture) { |
2867 // Only for GL textures. | 2872 // Only for GL textures. |
2868 if (GetParam() != ResourceProvider::GLTexture) | 2873 if (GetParam() != ResourceProvider::GLTexture) |
2869 return; | 2874 return; |
2870 scoped_ptr<AllocationTrackingContext3D> context_owned( | 2875 scoped_ptr<AllocationTrackingContext3D> context_owned( |
2871 new StrictMock<AllocationTrackingContext3D>); | 2876 new StrictMock<AllocationTrackingContext3D>); |
2872 AllocationTrackingContext3D* context = context_owned.get(); | 2877 AllocationTrackingContext3D* context = context_owned.get(); |
2873 | 2878 |
2874 FakeOutputSurfaceClient output_surface_client; | 2879 FakeOutputSurfaceClient output_surface_client; |
2875 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 2880 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
2876 context_owned.PassAs<TestWebGraphicsContext3D>())); | 2881 context_owned.PassAs<TestWebGraphicsContext3D>())); |
2877 CHECK(output_surface->BindToClient(&output_surface_client)); | 2882 CHECK(output_surface->BindToClient(&output_surface_client)); |
2878 | 2883 |
2879 const int kWidth = 2; | 2884 const int kWidth = 2; |
2880 const int kHeight = 2; | 2885 const int kHeight = 2; |
2881 gfx::Size size(kWidth, kHeight); | 2886 gfx::Size size(kWidth, kHeight); |
2882 ResourceFormat format = RGBA_8888; | 2887 ResourceFormat format = RGBA_8888; |
2883 ResourceProvider::ResourceId id = 0; | 2888 ResourceProvider::ResourceId id = 0; |
2884 const unsigned kTextureId = 123u; | 2889 const unsigned kTextureId = 123u; |
2885 const unsigned kImageId = 234u; | 2890 const unsigned kImageId = 234u; |
2886 | 2891 |
2887 scoped_ptr<ResourceProvider> resource_provider( | 2892 scoped_ptr<ResourceProvider> resource_provider( |
2888 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2893 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2889 | 2894 |
2890 id = resource_provider->CreateResource( | 2895 id = resource_provider->CreateResource( |
2891 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2896 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 2897 |
| 2898 const int kStride = 4; |
| 2899 void* dummy_mapped_buffer_address = NULL; |
2892 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) | 2900 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) |
2893 .WillOnce(Return(kImageId)) | 2901 .WillOnce(Return(kImageId)) |
2894 .RetiresOnSaturation(); | 2902 .RetiresOnSaturation(); |
2895 resource_provider->AcquireImage(id); | |
2896 | |
2897 void* dummy_mapped_buffer_address = NULL; | |
2898 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) | |
2899 .WillOnce(Return(dummy_mapped_buffer_address)) | |
2900 .RetiresOnSaturation(); | |
2901 resource_provider->MapImage(id); | |
2902 | |
2903 const int kStride = 4; | |
2904 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId, | 2903 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId, |
2905 GL_IMAGE_ROWBYTES_CHROMIUM, | 2904 GL_IMAGE_ROWBYTES_CHROMIUM, |
2906 _)) | 2905 _)) |
2907 .WillOnce(SetArgPointee<2>(kStride)) | 2906 .WillOnce(SetArgPointee<2>(kStride)) |
2908 .RetiresOnSaturation(); | 2907 .RetiresOnSaturation(); |
2909 int stride = resource_provider->GetImageStride(id); | 2908 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) |
2910 EXPECT_EQ(kStride, stride); | 2909 .WillOnce(Return(dummy_mapped_buffer_address)) |
| 2910 .RetiresOnSaturation(); |
| 2911 resource_provider->MapImageRasterBuffer(id); |
2911 | 2912 |
2912 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) | 2913 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) |
2913 .Times(1) | 2914 .Times(1) |
2914 .RetiresOnSaturation(); | 2915 .RetiresOnSaturation(); |
2915 resource_provider->UnmapImage(id); | 2916 resource_provider->UnmapImageRasterBuffer(id); |
2916 | 2917 |
2917 EXPECT_CALL(*context, NextTextureId()) | 2918 EXPECT_CALL(*context, NextTextureId()) |
2918 .WillOnce(Return(kTextureId)) | 2919 .WillOnce(Return(kTextureId)) |
2919 .RetiresOnSaturation(); | 2920 .RetiresOnSaturation(); |
2920 // Once in CreateTextureId and once in BindForSampling | 2921 // Once in CreateTextureId and once in BindForSampling |
2921 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2) | 2922 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2) |
2922 .RetiresOnSaturation(); | 2923 .RetiresOnSaturation(); |
2923 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | 2924 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
2924 .Times(1) | 2925 .Times(1) |
2925 .RetiresOnSaturation(); | 2926 .RetiresOnSaturation(); |
2926 { | 2927 { |
2927 ResourceProvider::ScopedSamplerGL lock_gl( | 2928 ResourceProvider::ScopedSamplerGL lock_gl( |
2928 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); | 2929 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); |
2929 EXPECT_EQ(kTextureId, lock_gl.texture_id()); | 2930 EXPECT_EQ(kTextureId, lock_gl.texture_id()); |
2930 } | 2931 } |
2931 | 2932 |
| 2933 EXPECT_CALL( |
| 2934 *context, |
| 2935 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) |
| 2936 .WillOnce(SetArgPointee<2>(kStride)) |
| 2937 .RetiresOnSaturation(); |
2932 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) | 2938 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) |
2933 .WillOnce(Return(dummy_mapped_buffer_address)) | 2939 .WillOnce(Return(dummy_mapped_buffer_address)) |
2934 .RetiresOnSaturation(); | 2940 .RetiresOnSaturation(); |
2935 resource_provider->MapImage(id); | 2941 resource_provider->MapImageRasterBuffer(id); |
2936 | 2942 |
2937 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) | 2943 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) |
2938 .Times(1) | 2944 .Times(1) |
2939 .RetiresOnSaturation(); | 2945 .RetiresOnSaturation(); |
2940 resource_provider->UnmapImage(id); | 2946 resource_provider->UnmapImageRasterBuffer(id); |
2941 | 2947 |
2942 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) | 2948 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) |
2943 .RetiresOnSaturation(); | 2949 .RetiresOnSaturation(); |
2944 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | 2950 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
2945 .Times(1) | 2951 .Times(1) |
2946 .RetiresOnSaturation(); | 2952 .RetiresOnSaturation(); |
2947 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | 2953 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
2948 .Times(1) | 2954 .Times(1) |
2949 .RetiresOnSaturation(); | 2955 .RetiresOnSaturation(); |
2950 EXPECT_CALL(*context, RetireTextureId(kTextureId)) | 2956 EXPECT_CALL(*context, RetireTextureId(kTextureId)) |
2951 .Times(1) | 2957 .Times(1) |
2952 .RetiresOnSaturation(); | 2958 .RetiresOnSaturation(); |
2953 { | 2959 { |
2954 ResourceProvider::ScopedSamplerGL lock_gl( | 2960 ResourceProvider::ScopedSamplerGL lock_gl( |
2955 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); | 2961 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); |
2956 EXPECT_EQ(kTextureId, lock_gl.texture_id()); | 2962 EXPECT_EQ(kTextureId, lock_gl.texture_id()); |
2957 } | 2963 } |
2958 | 2964 |
2959 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) | 2965 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) |
2960 .Times(1) | 2966 .Times(1) |
2961 .RetiresOnSaturation(); | 2967 .RetiresOnSaturation(); |
2962 resource_provider->ReleaseImage(id); | |
2963 } | 2968 } |
2964 | 2969 |
2965 TEST_P(ResourceProviderTest, Image_Bitmap) { | 2970 TEST_P(ResourceProviderTest, Image_Bitmap) { |
2966 if (GetParam() != ResourceProvider::Bitmap) | 2971 if (GetParam() != ResourceProvider::Bitmap) |
2967 return; | 2972 return; |
2968 FakeOutputSurfaceClient output_surface_client; | 2973 FakeOutputSurfaceClient output_surface_client; |
2969 scoped_ptr<OutputSurface> output_surface( | 2974 scoped_ptr<OutputSurface> output_surface( |
2970 FakeOutputSurface::CreateSoftware(make_scoped_ptr( | 2975 FakeOutputSurface::CreateSoftware(make_scoped_ptr( |
2971 new SoftwareOutputDevice))); | 2976 new SoftwareOutputDevice))); |
2972 CHECK(output_surface->BindToClient(&output_surface_client)); | 2977 CHECK(output_surface->BindToClient(&output_surface_client)); |
2973 | 2978 |
2974 gfx::Size size(1, 1); | 2979 gfx::Size size(1, 1); |
2975 ResourceFormat format = RGBA_8888; | 2980 ResourceFormat format = RGBA_8888; |
2976 ResourceProvider::ResourceId id = 0; | 2981 ResourceProvider::ResourceId id = 0; |
2977 const uint32_t kBadBeef = 0xbadbeef; | 2982 const uint32_t kBadBeef = 0xbadbeef; |
2978 | 2983 |
2979 scoped_ptr<ResourceProvider> resource_provider( | 2984 scoped_ptr<ResourceProvider> resource_provider( |
2980 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); | 2985 ResourceProvider::Create(output_surface.get(), NULL, 0, false, 1)); |
2981 | 2986 |
2982 id = resource_provider->CreateResource( | 2987 id = resource_provider->CreateResource( |
2983 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); | 2988 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
2984 resource_provider->AcquireImage(id); | |
2985 | 2989 |
2986 const int kStride = 0; | 2990 SkBitmap bitmap; |
2987 int stride = resource_provider->GetImageStride(id); | 2991 bitmap.setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); |
2988 EXPECT_EQ(kStride, stride); | 2992 bitmap.allocPixels(); |
2989 | 2993 *(bitmap.getAddr32(0, 0)) = kBadBeef; |
2990 void* data = resource_provider->MapImage(id); | 2994 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(id); |
2991 ASSERT_TRUE(!!data); | 2995 ASSERT_TRUE(!!canvas); |
2992 memcpy(data, &kBadBeef, sizeof(kBadBeef)); | 2996 canvas->writePixels(bitmap, 0, 0); |
2993 resource_provider->UnmapImage(id); | 2997 resource_provider->UnmapImageRasterBuffer(id); |
2994 | 2998 |
2995 { | 2999 { |
2996 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); | 3000 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); |
2997 const SkBitmap* sk_bitmap = lock.sk_bitmap(); | 3001 const SkBitmap* sk_bitmap = lock.sk_bitmap(); |
2998 EXPECT_EQ(sk_bitmap->width(), size.width()); | 3002 EXPECT_EQ(sk_bitmap->width(), size.width()); |
2999 EXPECT_EQ(sk_bitmap->height(), size.height()); | 3003 EXPECT_EQ(sk_bitmap->height(), size.height()); |
3000 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); | 3004 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); |
3001 } | 3005 } |
3002 | 3006 |
3003 resource_provider->ReleaseImage(id); | |
3004 resource_provider->DeleteResource(id); | 3007 resource_provider->DeleteResource(id); |
3005 } | 3008 } |
3006 | 3009 |
3007 void InitializeGLAndCheck(ContextSharedData* shared_data, | 3010 void InitializeGLAndCheck(ContextSharedData* shared_data, |
3008 ResourceProvider* resource_provider, | 3011 ResourceProvider* resource_provider, |
3009 FakeOutputSurface* output_surface) { | 3012 FakeOutputSurface* output_surface) { |
3010 scoped_ptr<ResourceProviderContext> context_owned = | 3013 scoped_ptr<ResourceProviderContext> context_owned = |
3011 ResourceProviderContext::Create(shared_data); | 3014 ResourceProviderContext::Create(shared_data); |
3012 ResourceProviderContext* context = context_owned.get(); | 3015 ResourceProviderContext* context = context_owned.get(); |
3013 | 3016 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3181 resource_provider->AllocateForTesting(id); | 3184 resource_provider->AllocateForTesting(id); |
3182 Mock::VerifyAndClearExpectations(context); | 3185 Mock::VerifyAndClearExpectations(context); |
3183 | 3186 |
3184 DCHECK_EQ(10u, context->PeekTextureId()); | 3187 DCHECK_EQ(10u, context->PeekTextureId()); |
3185 resource_provider->DeleteResource(id); | 3188 resource_provider->DeleteResource(id); |
3186 } | 3189 } |
3187 } | 3190 } |
3188 | 3191 |
3189 } // namespace | 3192 } // namespace |
3190 } // namespace cc | 3193 } // namespace cc |
OLD | NEW |