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 3009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3020 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); | 3020 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); |
3021 const SkBitmap* sk_bitmap = lock.sk_bitmap(); | 3021 const SkBitmap* sk_bitmap = lock.sk_bitmap(); |
3022 EXPECT_EQ(sk_bitmap->width(), size.width()); | 3022 EXPECT_EQ(sk_bitmap->width(), size.width()); |
3023 EXPECT_EQ(sk_bitmap->height(), size.height()); | 3023 EXPECT_EQ(sk_bitmap->height(), size.height()); |
3024 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); | 3024 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); |
3025 } | 3025 } |
3026 | 3026 |
3027 resource_provider->DeleteResource(id); | 3027 resource_provider->DeleteResource(id); |
3028 } | 3028 } |
3029 | 3029 |
| 3030 TEST_P(ResourceProviderTest, CopyResource_GLTexture) { |
| 3031 if (GetParam() != ResourceProvider::GLTexture) |
| 3032 return; |
| 3033 scoped_ptr<AllocationTrackingContext3D> context_owned( |
| 3034 new StrictMock<AllocationTrackingContext3D>); |
| 3035 AllocationTrackingContext3D* context = context_owned.get(); |
| 3036 |
| 3037 FakeOutputSurfaceClient output_surface_client; |
| 3038 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
| 3039 context_owned.PassAs<TestWebGraphicsContext3D>())); |
| 3040 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 3041 |
| 3042 const int kWidth = 2; |
| 3043 const int kHeight = 2; |
| 3044 gfx::Size size(kWidth, kHeight); |
| 3045 ResourceFormat format = RGBA_8888; |
| 3046 ResourceProvider::ResourceId source_id = 0; |
| 3047 ResourceProvider::ResourceId dest_id = 0; |
| 3048 const unsigned kSourceTextureId = 123u; |
| 3049 const unsigned kDestTextureId = 321u; |
| 3050 const unsigned kImageId = 234u; |
| 3051 |
| 3052 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 3053 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1)); |
| 3054 |
| 3055 source_id = resource_provider->CreateResource( |
| 3056 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 3057 |
| 3058 const int kStride = 4; |
| 3059 void* dummy_mapped_buffer_address = NULL; |
| 3060 EXPECT_CALL(*context, createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES)) |
| 3061 .WillOnce(Return(kImageId)) |
| 3062 .RetiresOnSaturation(); |
| 3063 EXPECT_CALL( |
| 3064 *context, |
| 3065 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) |
| 3066 .WillOnce(SetArgPointee<2>(kStride)) |
| 3067 .RetiresOnSaturation(); |
| 3068 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId, GL_READ_WRITE)) |
| 3069 .WillOnce(Return(dummy_mapped_buffer_address)) |
| 3070 .RetiresOnSaturation(); |
| 3071 resource_provider->MapImageRasterBuffer(source_id); |
| 3072 |
| 3073 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) |
| 3074 .Times(1) |
| 3075 .RetiresOnSaturation(); |
| 3076 resource_provider->UnmapImageRasterBuffer(source_id); |
| 3077 |
| 3078 dest_id = resource_provider->CreateResource( |
| 3079 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 3080 |
| 3081 EXPECT_CALL(*context, NextTextureId()) |
| 3082 .WillOnce(Return(kDestTextureId)) |
| 3083 .RetiresOnSaturation(); |
| 3084 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId)) |
| 3085 .Times(1) |
| 3086 .RetiresOnSaturation(); |
| 3087 EXPECT_CALL(*context, NextTextureId()) |
| 3088 .WillOnce(Return(kSourceTextureId)) |
| 3089 .RetiresOnSaturation(); |
| 3090 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kSourceTextureId)) |
| 3091 .Times(2) |
| 3092 .RetiresOnSaturation(); |
| 3093 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
| 3094 .Times(1) |
| 3095 .RetiresOnSaturation(); |
| 3096 resource_provider->CopyResource(source_id, dest_id); |
| 3097 |
| 3098 EXPECT_CALL(*context, destroyImageCHROMIUM(kImageId)) |
| 3099 .Times(1) |
| 3100 .RetiresOnSaturation(); |
| 3101 EXPECT_CALL(*context, RetireTextureId(kSourceTextureId)) |
| 3102 .Times(1) |
| 3103 .RetiresOnSaturation(); |
| 3104 EXPECT_CALL(*context, RetireTextureId(kDestTextureId)) |
| 3105 .Times(1) |
| 3106 .RetiresOnSaturation(); |
| 3107 resource_provider->DeleteResource(source_id); |
| 3108 resource_provider->DeleteResource(dest_id); |
| 3109 } |
| 3110 |
| 3111 TEST_P(ResourceProviderTest, CopyResource_Bitmap) { |
| 3112 if (GetParam() != ResourceProvider::Bitmap) |
| 3113 return; |
| 3114 FakeOutputSurfaceClient output_surface_client; |
| 3115 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::CreateSoftware( |
| 3116 make_scoped_ptr(new SoftwareOutputDevice))); |
| 3117 CHECK(output_surface->BindToClient(&output_surface_client)); |
| 3118 |
| 3119 gfx::Size size(1, 1); |
| 3120 ResourceFormat format = RGBA_8888; |
| 3121 ResourceProvider::ResourceId source_id = 0; |
| 3122 ResourceProvider::ResourceId dest_id = 0; |
| 3123 const uint32_t kBadBeef = 0xbadbeef; |
| 3124 |
| 3125 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( |
| 3126 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1)); |
| 3127 |
| 3128 source_id = resource_provider->CreateResource( |
| 3129 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 3130 |
| 3131 SkBitmap bitmap; |
| 3132 bitmap.allocN32Pixels(size.width(), size.height()); |
| 3133 *(bitmap.getAddr32(0, 0)) = kBadBeef; |
| 3134 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(source_id); |
| 3135 ASSERT_TRUE(!!canvas); |
| 3136 canvas->writePixels(bitmap, 0, 0); |
| 3137 resource_provider->UnmapImageRasterBuffer(source_id); |
| 3138 |
| 3139 dest_id = resource_provider->CreateResource( |
| 3140 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureUsageAny, format); |
| 3141 |
| 3142 resource_provider->CopyResource(source_id, dest_id); |
| 3143 |
| 3144 { |
| 3145 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), |
| 3146 dest_id); |
| 3147 const SkBitmap* sk_bitmap = lock.sk_bitmap(); |
| 3148 EXPECT_EQ(sk_bitmap->width(), size.width()); |
| 3149 EXPECT_EQ(sk_bitmap->height(), size.height()); |
| 3150 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); |
| 3151 } |
| 3152 |
| 3153 resource_provider->DeleteResource(source_id); |
| 3154 resource_provider->DeleteResource(dest_id); |
| 3155 } |
| 3156 |
3030 void InitializeGLAndCheck(ContextSharedData* shared_data, | 3157 void InitializeGLAndCheck(ContextSharedData* shared_data, |
3031 ResourceProvider* resource_provider, | 3158 ResourceProvider* resource_provider, |
3032 FakeOutputSurface* output_surface) { | 3159 FakeOutputSurface* output_surface) { |
3033 scoped_ptr<ResourceProviderContext> context_owned = | 3160 scoped_ptr<ResourceProviderContext> context_owned = |
3034 ResourceProviderContext::Create(shared_data); | 3161 ResourceProviderContext::Create(shared_data); |
3035 ResourceProviderContext* context = context_owned.get(); | 3162 ResourceProviderContext* context = context_owned.get(); |
3036 | 3163 |
3037 scoped_refptr<TestContextProvider> context_provider = | 3164 scoped_refptr<TestContextProvider> context_provider = |
3038 TestContextProvider::Create( | 3165 TestContextProvider::Create( |
3039 context_owned.PassAs<TestWebGraphicsContext3D>()); | 3166 context_owned.PassAs<TestWebGraphicsContext3D>()); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3208 resource_provider->AllocateForTesting(id); | 3335 resource_provider->AllocateForTesting(id); |
3209 Mock::VerifyAndClearExpectations(context); | 3336 Mock::VerifyAndClearExpectations(context); |
3210 | 3337 |
3211 DCHECK_EQ(10u, context->PeekTextureId()); | 3338 DCHECK_EQ(10u, context->PeekTextureId()); |
3212 resource_provider->DeleteResource(id); | 3339 resource_provider->DeleteResource(id); |
3213 } | 3340 } |
3214 } | 3341 } |
3215 | 3342 |
3216 } // namespace | 3343 } // namespace |
3217 } // namespace cc | 3344 } // namespace cc |
OLD | NEW |