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 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 gfx::Rect rect(size); | 626 gfx::Rect rect(size); |
627 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); | 627 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); |
628 | 628 |
629 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( | 629 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( |
630 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 630 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
631 uint8_t data2[4] = { 5, 5, 5, 5 }; | 631 uint8_t data2[4] = { 5, 5, 5, 5 }; |
632 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); | 632 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); |
633 | 633 |
634 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( | 634 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( |
635 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 635 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
636 child_resource_provider_->AcquireImageRasterBuffer(id3); | 636 child_resource_provider_->AcquireImage(id3); |
637 child_resource_provider_->ReleaseImageRasterBuffer(id3); | 637 int stride; |
| 638 child_resource_provider_->MapImage(id3, &stride); |
| 639 child_resource_provider_->UnmapImage(id3); |
638 | 640 |
639 GLuint external_texture_id = child_context_->createExternalTexture(); | 641 GLuint external_texture_id = child_context_->createExternalTexture(); |
640 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id); | 642 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id); |
641 | 643 |
642 gpu::Mailbox external_mailbox; | 644 gpu::Mailbox external_mailbox; |
643 child_context_->genMailboxCHROMIUM(external_mailbox.name); | 645 child_context_->genMailboxCHROMIUM(external_mailbox.name); |
644 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, | 646 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, |
645 external_mailbox.name); | 647 external_mailbox.name); |
646 const GLuint external_sync_point = child_context_->insertSyncPoint(); | 648 const GLuint external_sync_point = child_context_->insertSyncPoint(); |
647 ResourceProvider::ResourceId id4 = | 649 ResourceProvider::ResourceId id4 = |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 gfx::Rect rect(size); | 975 gfx::Rect rect(size); |
974 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); | 976 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); |
975 | 977 |
976 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( | 978 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( |
977 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 979 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
978 uint8_t data2[4] = { 5, 5, 5, 5 }; | 980 uint8_t data2[4] = { 5, 5, 5, 5 }; |
979 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); | 981 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); |
980 | 982 |
981 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( | 983 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( |
982 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 984 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
| 985 child_resource_provider_->AcquireImage(id3); |
983 uint8_t data3[4] = { 6, 7, 8, 9 }; | 986 uint8_t data3[4] = { 6, 7, 8, 9 }; |
984 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); | 987 int stride; |
985 RasterBuffer* raster_buffer = | 988 void* data = child_resource_provider_->MapImage(id3, &stride); |
986 child_resource_provider_->AcquireImageRasterBuffer(id3); | 989 memcpy(data, data3, sizeof(data3)); |
987 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas(); | 990 child_resource_provider_->UnmapImage(id3); |
988 canvas->writePixels(info, data3, info.minRowBytes(), 0, 0); | |
989 raster_buffer->ReleaseSkCanvas(canvas); | |
990 canvas.clear(); | |
991 child_resource_provider_->ReleaseImageRasterBuffer(id3); | |
992 | 991 |
993 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 992 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
994 shared_memory->CreateAndMapAnonymous(1); | 993 shared_memory->CreateAndMapAnonymous(1); |
995 base::SharedMemory* shared_memory_ptr = shared_memory.get(); | 994 base::SharedMemory* shared_memory_ptr = shared_memory.get(); |
996 ResourceProvider::ResourceId id4 = | 995 ResourceProvider::ResourceId id4 = |
997 child_resource_provider_->CreateResourceFromTextureMailbox( | 996 child_resource_provider_->CreateResourceFromTextureMailbox( |
998 TextureMailbox(shared_memory_ptr, gfx::Size(1, 1)), | 997 TextureMailbox(shared_memory_ptr, gfx::Size(1, 1)), |
999 SingleReleaseCallbackImpl::Create(base::Bind( | 998 SingleReleaseCallbackImpl::Create(base::Bind( |
1000 &SharedMemoryReleaseCallback, base::Passed(&shared_memory)))); | 999 &SharedMemoryReleaseCallback, base::Passed(&shared_memory)))); |
1001 | 1000 |
(...skipping 2042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3044 resource_provider->SetPixels(id, pixels, rect, rect, offset); | 3043 resource_provider->SetPixels(id, pixels, rect, rect, offset); |
3045 | 3044 |
3046 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 3045 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
3047 resource_provider->DeleteResource(id); | 3046 resource_provider->DeleteResource(id); |
3048 | 3047 |
3049 Mock::VerifyAndClearExpectations(context); | 3048 Mock::VerifyAndClearExpectations(context); |
3050 | 3049 |
3051 // Same for async version. | 3050 // Same for async version. |
3052 id = resource_provider->CreateResource( | 3051 id = resource_provider->CreateResource( |
3053 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 3052 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
3054 RasterBuffer* raster_buffer = resource_provider->AcquirePixelRasterBuffer(id); | 3053 resource_provider->AcquirePixelBuffer(id); |
3055 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas(); | |
3056 raster_buffer->ReleaseSkCanvas(canvas); | |
3057 canvas.clear(); | |
3058 | 3054 |
3059 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 3055 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
3060 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 3056 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
3061 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 3057 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
3062 .Times(1); | 3058 .Times(1); |
3063 resource_provider->BeginSetPixels(id); | 3059 resource_provider->BeginSetPixels(id); |
3064 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 3060 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
3065 | 3061 |
3066 resource_provider->ReleasePixelRasterBuffer(id); | 3062 resource_provider->ReleasePixelBuffer(id); |
3067 | 3063 |
3068 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 3064 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
3069 resource_provider->DeleteResource(id); | 3065 resource_provider->DeleteResource(id); |
3070 | 3066 |
3071 Mock::VerifyAndClearExpectations(context); | 3067 Mock::VerifyAndClearExpectations(context); |
3072 } | 3068 } |
3073 | 3069 |
3074 TEST_P(ResourceProviderTest, TextureAllocationHint) { | 3070 TEST_P(ResourceProviderTest, TextureAllocationHint) { |
3075 // Only for GL textures. | 3071 // Only for GL textures. |
3076 if (GetParam() != ResourceProvider::GLTexture) | 3072 if (GetParam() != ResourceProvider::GLTexture) |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3209 ResourceProvider::Create(output_surface.get(), | 3205 ResourceProvider::Create(output_surface.get(), |
3210 shared_bitmap_manager_.get(), | 3206 shared_bitmap_manager_.get(), |
3211 NULL, | 3207 NULL, |
3212 0, | 3208 0, |
3213 false, | 3209 false, |
3214 1, | 3210 1, |
3215 false)); | 3211 false)); |
3216 | 3212 |
3217 id = resource_provider->CreateResource( | 3213 id = resource_provider->CreateResource( |
3218 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 3214 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
3219 RasterBuffer* raster_buffer = resource_provider->AcquirePixelRasterBuffer(id); | 3215 resource_provider->AcquirePixelBuffer(id); |
3220 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas(); | |
3221 raster_buffer->ReleaseSkCanvas(canvas); | |
3222 canvas.clear(); | |
3223 | 3216 |
3224 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 3217 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
3225 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 3218 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
3226 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 3219 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
3227 .Times(1); | 3220 .Times(1); |
3228 resource_provider->BeginSetPixels(id); | 3221 resource_provider->BeginSetPixels(id); |
3229 | 3222 |
3230 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); | 3223 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); |
3231 | 3224 |
3232 resource_provider->ReleasePixelRasterBuffer(id); | 3225 resource_provider->ReleasePixelBuffer(id); |
3233 | 3226 |
3234 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 3227 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
3235 resource_provider->DeleteResource(id); | 3228 resource_provider->DeleteResource(id); |
3236 | 3229 |
3237 Mock::VerifyAndClearExpectations(context); | 3230 Mock::VerifyAndClearExpectations(context); |
3238 } | 3231 } |
3239 | 3232 |
3240 TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) { | 3233 TEST_P(ResourceProviderTest, ForcingAsyncUploadToComplete) { |
3241 // Only for GL textures. | 3234 // Only for GL textures. |
3242 if (GetParam() != ResourceProvider::GLTexture) | 3235 if (GetParam() != ResourceProvider::GLTexture) |
(...skipping 16 matching lines...) Expand all Loading... |
3259 ResourceProvider::Create(output_surface.get(), | 3252 ResourceProvider::Create(output_surface.get(), |
3260 shared_bitmap_manager_.get(), | 3253 shared_bitmap_manager_.get(), |
3261 NULL, | 3254 NULL, |
3262 0, | 3255 0, |
3263 false, | 3256 false, |
3264 1, | 3257 1, |
3265 false)); | 3258 false)); |
3266 | 3259 |
3267 id = resource_provider->CreateResource( | 3260 id = resource_provider->CreateResource( |
3268 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 3261 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
3269 RasterBuffer* raster_buffer = resource_provider->AcquirePixelRasterBuffer(id); | 3262 resource_provider->AcquirePixelBuffer(id); |
3270 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas(); | |
3271 raster_buffer->ReleaseSkCanvas(canvas); | |
3272 canvas.clear(); | |
3273 | 3263 |
3274 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); | 3264 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); |
3275 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); | 3265 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); |
3276 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) | 3266 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) |
3277 .Times(1); | 3267 .Times(1); |
3278 resource_provider->BeginSetPixels(id); | 3268 resource_provider->BeginSetPixels(id); |
3279 | 3269 |
3280 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); | 3270 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); |
3281 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); | 3271 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); |
3282 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); | 3272 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); |
3283 resource_provider->ForceSetPixelsToComplete(id); | 3273 resource_provider->ForceSetPixelsToComplete(id); |
3284 | 3274 |
3285 resource_provider->ReleasePixelRasterBuffer(id); | 3275 resource_provider->ReleasePixelBuffer(id); |
3286 | 3276 |
3287 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); | 3277 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); |
3288 resource_provider->DeleteResource(id); | 3278 resource_provider->DeleteResource(id); |
3289 | 3279 |
3290 Mock::VerifyAndClearExpectations(context); | 3280 Mock::VerifyAndClearExpectations(context); |
3291 } | 3281 } |
3292 | 3282 |
3293 TEST_P(ResourceProviderTest, PixelBufferLostContext) { | 3283 TEST_P(ResourceProviderTest, PixelBufferLostContext) { |
3294 scoped_ptr<AllocationTrackingContext3D> context_owned( | 3284 scoped_ptr<AllocationTrackingContext3D> context_owned( |
3295 new NiceMock<AllocationTrackingContext3D>); | 3285 new NiceMock<AllocationTrackingContext3D>); |
(...skipping 18 matching lines...) Expand all Loading... |
3314 1, | 3304 1, |
3315 false)); | 3305 false)); |
3316 | 3306 |
3317 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id)); | 3307 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id)); |
3318 | 3308 |
3319 id = resource_provider->CreateResource( | 3309 id = resource_provider->CreateResource( |
3320 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 3310 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
3321 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, | 3311 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, |
3322 GL_INNOCENT_CONTEXT_RESET_ARB); | 3312 GL_INNOCENT_CONTEXT_RESET_ARB); |
3323 | 3313 |
3324 RasterBuffer* raster_buffer = resource_provider->AcquirePixelRasterBuffer(id); | 3314 resource_provider->AcquirePixelBuffer(id); |
3325 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas(); | 3315 int stride; |
3326 EXPECT_TRUE(canvas); | 3316 void* buffer = resource_provider->MapPixelBuffer(id, &stride); |
3327 raster_buffer->ReleaseSkCanvas(canvas); | 3317 EXPECT_FALSE(buffer); |
3328 resource_provider->ReleasePixelRasterBuffer(id); | 3318 resource_provider->UnmapPixelBuffer(id); |
3329 Mock::VerifyAndClearExpectations(context); | 3319 Mock::VerifyAndClearExpectations(context); |
3330 } | 3320 } |
3331 | 3321 |
3332 TEST_P(ResourceProviderTest, Image_GLTexture) { | 3322 TEST_P(ResourceProviderTest, Image_GLTexture) { |
3333 // Only for GL textures. | 3323 // Only for GL textures. |
3334 if (GetParam() != ResourceProvider::GLTexture) | 3324 if (GetParam() != ResourceProvider::GLTexture) |
3335 return; | 3325 return; |
3336 scoped_ptr<AllocationTrackingContext3D> context_owned( | 3326 scoped_ptr<AllocationTrackingContext3D> context_owned( |
3337 new StrictMock<AllocationTrackingContext3D>); | 3327 new StrictMock<AllocationTrackingContext3D>); |
3338 AllocationTrackingContext3D* context = context_owned.get(); | 3328 AllocationTrackingContext3D* context = context_owned.get(); |
(...skipping 23 matching lines...) Expand all Loading... |
3362 id = resource_provider->CreateResource( | 3352 id = resource_provider->CreateResource( |
3363 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 3353 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
3364 | 3354 |
3365 const int kStride = 4; | 3355 const int kStride = 4; |
3366 void* dummy_mapped_buffer_address = NULL; | 3356 void* dummy_mapped_buffer_address = NULL; |
3367 EXPECT_CALL( | 3357 EXPECT_CALL( |
3368 *context, | 3358 *context, |
3369 createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM)) | 3359 createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM)) |
3370 .WillOnce(Return(kImageId)) | 3360 .WillOnce(Return(kImageId)) |
3371 .RetiresOnSaturation(); | 3361 .RetiresOnSaturation(); |
| 3362 resource_provider->AcquireImage(id); |
| 3363 |
3372 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId, | 3364 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId, |
3373 GL_IMAGE_ROWBYTES_CHROMIUM, | 3365 GL_IMAGE_ROWBYTES_CHROMIUM, |
3374 _)) | 3366 _)) |
3375 .WillOnce(SetArgPointee<2>(kStride)) | 3367 .WillOnce(SetArgPointee<2>(kStride)) |
3376 .RetiresOnSaturation(); | 3368 .RetiresOnSaturation(); |
3377 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) | 3369 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) |
3378 .WillOnce(Return(dummy_mapped_buffer_address)) | 3370 .WillOnce(Return(dummy_mapped_buffer_address)) |
3379 .RetiresOnSaturation(); | 3371 .RetiresOnSaturation(); |
3380 resource_provider->AcquireImageRasterBuffer(id); | 3372 int stride; |
3381 resource_provider->ReleaseImageRasterBuffer(id); | 3373 resource_provider->MapImage(id, &stride); |
| 3374 |
| 3375 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) |
| 3376 .Times(1) |
| 3377 .RetiresOnSaturation(); |
| 3378 resource_provider->UnmapImage(id); |
3382 | 3379 |
3383 EXPECT_CALL(*context, NextTextureId()) | 3380 EXPECT_CALL(*context, NextTextureId()) |
3384 .WillOnce(Return(kTextureId)) | 3381 .WillOnce(Return(kTextureId)) |
3385 .RetiresOnSaturation(); | 3382 .RetiresOnSaturation(); |
3386 // Once in CreateTextureId and once in BindForSampling | 3383 // Once in CreateTextureId and once in BindForSampling |
3387 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2) | 3384 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2) |
3388 .RetiresOnSaturation(); | 3385 .RetiresOnSaturation(); |
3389 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | 3386 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
3390 .Times(1) | 3387 .Times(1) |
3391 .RetiresOnSaturation(); | 3388 .RetiresOnSaturation(); |
3392 { | 3389 { |
3393 ResourceProvider::ScopedSamplerGL lock_gl( | 3390 ResourceProvider::ScopedSamplerGL lock_gl( |
3394 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); | 3391 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); |
3395 EXPECT_EQ(kTextureId, lock_gl.texture_id()); | 3392 EXPECT_EQ(kTextureId, lock_gl.texture_id()); |
3396 } | 3393 } |
3397 | 3394 |
3398 EXPECT_CALL( | 3395 EXPECT_CALL( |
3399 *context, | 3396 *context, |
3400 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) | 3397 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) |
3401 .WillOnce(SetArgPointee<2>(kStride)) | 3398 .WillOnce(SetArgPointee<2>(kStride)) |
3402 .RetiresOnSaturation(); | 3399 .RetiresOnSaturation(); |
3403 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) | 3400 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) |
3404 .WillOnce(Return(dummy_mapped_buffer_address)) | 3401 .WillOnce(Return(dummy_mapped_buffer_address)) |
3405 .RetiresOnSaturation(); | 3402 .RetiresOnSaturation(); |
3406 resource_provider->AcquireImageRasterBuffer(id); | 3403 resource_provider->MapImage(id, &stride); |
3407 resource_provider->ReleaseImageRasterBuffer(id); | 3404 |
| 3405 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) |
| 3406 .Times(1) |
| 3407 .RetiresOnSaturation(); |
| 3408 resource_provider->UnmapImage(id); |
3408 | 3409 |
3409 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) | 3410 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) |
3410 .RetiresOnSaturation(); | 3411 .RetiresOnSaturation(); |
3411 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | 3412 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
3412 .Times(1) | 3413 .Times(1) |
3413 .RetiresOnSaturation(); | 3414 .RetiresOnSaturation(); |
3414 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) | 3415 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) |
3415 .Times(1) | 3416 .Times(1) |
3416 .RetiresOnSaturation(); | 3417 .RetiresOnSaturation(); |
3417 EXPECT_CALL(*context, RetireTextureId(kTextureId)) | 3418 EXPECT_CALL(*context, RetireTextureId(kTextureId)) |
(...skipping 28 matching lines...) Expand all Loading... |
3446 ResourceProvider::Create(output_surface.get(), | 3447 ResourceProvider::Create(output_surface.get(), |
3447 shared_bitmap_manager_.get(), | 3448 shared_bitmap_manager_.get(), |
3448 NULL, | 3449 NULL, |
3449 0, | 3450 0, |
3450 false, | 3451 false, |
3451 1, | 3452 1, |
3452 false)); | 3453 false)); |
3453 | 3454 |
3454 id = resource_provider->CreateResource( | 3455 id = resource_provider->CreateResource( |
3455 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 3456 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
| 3457 resource_provider->AcquireImage(id); |
3456 | 3458 |
3457 SkBitmap bitmap; | 3459 int stride; |
3458 bitmap.allocN32Pixels(size.width(), size.height()); | 3460 void* data = resource_provider->MapImage(id, &stride); |
3459 *(bitmap.getAddr32(0, 0)) = kBadBeef; | 3461 ASSERT_TRUE(!!data); |
3460 RasterBuffer* raster_buffer = resource_provider->AcquireImageRasterBuffer(id); | 3462 memcpy(data, &kBadBeef, sizeof(kBadBeef)); |
3461 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas(); | 3463 resource_provider->UnmapImage(id); |
3462 ASSERT_TRUE(!!canvas); | |
3463 canvas->writePixels(bitmap, 0, 0); | |
3464 raster_buffer->ReleaseSkCanvas(canvas); | |
3465 canvas.clear(); | |
3466 resource_provider->ReleaseImageRasterBuffer(id); | |
3467 | 3464 |
3468 { | 3465 { |
3469 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); | 3466 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); |
3470 const SkBitmap* sk_bitmap = lock.sk_bitmap(); | 3467 const SkBitmap* sk_bitmap = lock.sk_bitmap(); |
3471 EXPECT_EQ(sk_bitmap->width(), size.width()); | 3468 EXPECT_EQ(sk_bitmap->width(), size.width()); |
3472 EXPECT_EQ(sk_bitmap->height(), size.height()); | 3469 EXPECT_EQ(sk_bitmap->height(), size.height()); |
3473 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); | 3470 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); |
3474 } | 3471 } |
3475 | 3472 |
| 3473 resource_provider->ReleaseImage(id); |
3476 resource_provider->DeleteResource(id); | 3474 resource_provider->DeleteResource(id); |
3477 } | 3475 } |
3478 | 3476 |
3479 TEST_P(ResourceProviderTest, CopyResource_GLTexture) { | 3477 TEST_P(ResourceProviderTest, CopyResource_GLTexture) { |
3480 if (GetParam() != ResourceProvider::GLTexture) | 3478 if (GetParam() != ResourceProvider::GLTexture) |
3481 return; | 3479 return; |
3482 scoped_ptr<AllocationTrackingContext3D> context_owned( | 3480 scoped_ptr<AllocationTrackingContext3D> context_owned( |
3483 new StrictMock<AllocationTrackingContext3D>); | 3481 new StrictMock<AllocationTrackingContext3D>); |
3484 AllocationTrackingContext3D* context = context_owned.get(); | 3482 AllocationTrackingContext3D* context = context_owned.get(); |
3485 context_owned->set_support_sync_query(true); | 3483 context_owned->set_support_sync_query(true); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3519 .WillOnce(Return(kImageId)) | 3517 .WillOnce(Return(kImageId)) |
3520 .RetiresOnSaturation(); | 3518 .RetiresOnSaturation(); |
3521 EXPECT_CALL( | 3519 EXPECT_CALL( |
3522 *context, | 3520 *context, |
3523 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) | 3521 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) |
3524 .WillOnce(SetArgPointee<2>(kStride)) | 3522 .WillOnce(SetArgPointee<2>(kStride)) |
3525 .RetiresOnSaturation(); | 3523 .RetiresOnSaturation(); |
3526 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) | 3524 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) |
3527 .WillOnce(Return(dummy_mapped_buffer_address)) | 3525 .WillOnce(Return(dummy_mapped_buffer_address)) |
3528 .RetiresOnSaturation(); | 3526 .RetiresOnSaturation(); |
3529 resource_provider->AcquireImageRasterBuffer(source_id); | 3527 resource_provider->AcquireImage(source_id); |
3530 resource_provider->ReleaseImageRasterBuffer(source_id); | 3528 int stride; |
| 3529 resource_provider->MapImage(source_id, &stride); |
| 3530 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId)) |
| 3531 .Times(1) |
| 3532 .RetiresOnSaturation(); |
| 3533 resource_provider->UnmapImage(source_id); |
3531 Mock::VerifyAndClearExpectations(context); | 3534 Mock::VerifyAndClearExpectations(context); |
3532 | 3535 |
3533 dest_id = resource_provider->CreateResource( | 3536 dest_id = resource_provider->CreateResource( |
3534 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 3537 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
3535 | 3538 |
3536 EXPECT_CALL(*context, NextTextureId()) | 3539 EXPECT_CALL(*context, NextTextureId()) |
3537 .WillOnce(Return(kDestTextureId)) | 3540 .WillOnce(Return(kDestTextureId)) |
3538 .RetiresOnSaturation(); | 3541 .RetiresOnSaturation(); |
3539 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId)) | 3542 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId)) |
3540 .Times(1) | 3543 .Times(1) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3582 ResourceProvider::Create(output_surface.get(), | 3585 ResourceProvider::Create(output_surface.get(), |
3583 shared_bitmap_manager_.get(), | 3586 shared_bitmap_manager_.get(), |
3584 NULL, | 3587 NULL, |
3585 0, | 3588 0, |
3586 false, | 3589 false, |
3587 1, | 3590 1, |
3588 false)); | 3591 false)); |
3589 | 3592 |
3590 source_id = resource_provider->CreateResource( | 3593 source_id = resource_provider->CreateResource( |
3591 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 3594 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
| 3595 resource_provider->AcquireImage(source_id); |
3592 | 3596 |
3593 SkBitmap bitmap; | 3597 int stride; |
3594 bitmap.allocN32Pixels(size.width(), size.height()); | 3598 void* data = resource_provider->MapImage(source_id, &stride); |
3595 *(bitmap.getAddr32(0, 0)) = kBadBeef; | 3599 ASSERT_TRUE(!!data); |
3596 RasterBuffer* raster_buffer = | 3600 memcpy(data, &kBadBeef, sizeof(kBadBeef)); |
3597 resource_provider->AcquireImageRasterBuffer(source_id); | 3601 resource_provider->UnmapImage(source_id); |
3598 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas(); | |
3599 ASSERT_TRUE(!!canvas); | |
3600 canvas->writePixels(bitmap, 0, 0); | |
3601 raster_buffer->ReleaseSkCanvas(canvas); | |
3602 canvas.clear(); | |
3603 resource_provider->ReleaseImageRasterBuffer(source_id); | |
3604 | 3602 |
3605 dest_id = resource_provider->CreateResource( | 3603 dest_id = resource_provider->CreateResource( |
3606 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); | 3604 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); |
3607 | 3605 |
3608 resource_provider->CopyResource(source_id, dest_id); | 3606 resource_provider->CopyResource(source_id, dest_id); |
3609 | 3607 |
3610 { | 3608 { |
3611 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), | 3609 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), |
3612 dest_id); | 3610 dest_id); |
3613 const SkBitmap* sk_bitmap = lock.sk_bitmap(); | 3611 const SkBitmap* sk_bitmap = lock.sk_bitmap(); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3817 resource_provider->AllocateForTesting(id); | 3815 resource_provider->AllocateForTesting(id); |
3818 Mock::VerifyAndClearExpectations(context); | 3816 Mock::VerifyAndClearExpectations(context); |
3819 | 3817 |
3820 DCHECK_EQ(10u, context->PeekTextureId()); | 3818 DCHECK_EQ(10u, context->PeekTextureId()); |
3821 resource_provider->DeleteResource(id); | 3819 resource_provider->DeleteResource(id); |
3822 } | 3820 } |
3823 } | 3821 } |
3824 | 3822 |
3825 } // namespace | 3823 } // namespace |
3826 } // namespace cc | 3824 } // namespace cc |
OLD | NEW |