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

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

Issue 562833004: cc: Move RasterBuffer implementations from ResourceProvider to RasterWorkerPool implementations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fix Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/resources/resource_provider.h" 5 #include "cc/resources/resource_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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
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
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 resource_provider->ReleasePixelBuffer(id);
3326 EXPECT_TRUE(canvas.get() == NULL);
3327 raster_buffer->ReleaseSkCanvas(canvas);
3328 canvas.clear();
3329 resource_provider->ReleasePixelRasterBuffer(id);
3330 Mock::VerifyAndClearExpectations(context); 3316 Mock::VerifyAndClearExpectations(context);
3331 } 3317 }
3332 3318
3333 TEST_P(ResourceProviderTest, Image_GLTexture) { 3319 TEST_P(ResourceProviderTest, Image_GLTexture) {
3334 // Only for GL textures. 3320 // Only for GL textures.
3335 if (GetParam() != ResourceProvider::GLTexture) 3321 if (GetParam() != ResourceProvider::GLTexture)
3336 return; 3322 return;
3337 scoped_ptr<AllocationTrackingContext3D> context_owned( 3323 scoped_ptr<AllocationTrackingContext3D> context_owned(
3338 new StrictMock<AllocationTrackingContext3D>); 3324 new StrictMock<AllocationTrackingContext3D>);
3339 AllocationTrackingContext3D* context = context_owned.get(); 3325 AllocationTrackingContext3D* context = context_owned.get();
(...skipping 23 matching lines...) Expand all
3363 id = resource_provider->CreateResource( 3349 id = resource_provider->CreateResource(
3364 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 3350 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3365 3351
3366 const int kStride = 4; 3352 const int kStride = 4;
3367 void* dummy_mapped_buffer_address = NULL; 3353 void* dummy_mapped_buffer_address = NULL;
3368 EXPECT_CALL( 3354 EXPECT_CALL(
3369 *context, 3355 *context,
3370 createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM)) 3356 createImageCHROMIUM(kWidth, kHeight, GL_RGBA8_OES, GL_IMAGE_MAP_CHROMIUM))
3371 .WillOnce(Return(kImageId)) 3357 .WillOnce(Return(kImageId))
3372 .RetiresOnSaturation(); 3358 .RetiresOnSaturation();
3359 resource_provider->AcquireImage(id);
3360
3373 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId, 3361 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId,
3374 GL_IMAGE_ROWBYTES_CHROMIUM, 3362 GL_IMAGE_ROWBYTES_CHROMIUM,
3375 _)) 3363 _))
3376 .WillOnce(SetArgPointee<2>(kStride)) 3364 .WillOnce(SetArgPointee<2>(kStride))
3377 .RetiresOnSaturation(); 3365 .RetiresOnSaturation();
3378 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) 3366 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId))
3379 .WillOnce(Return(dummy_mapped_buffer_address)) 3367 .WillOnce(Return(dummy_mapped_buffer_address))
3380 .RetiresOnSaturation(); 3368 .RetiresOnSaturation();
3381 resource_provider->AcquireImageRasterBuffer(id); 3369 int stride;
3382 resource_provider->ReleaseImageRasterBuffer(id); 3370 resource_provider->MapImage(id, &stride);
3371
3372 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId))
3373 .Times(1)
3374 .RetiresOnSaturation();
3375 resource_provider->UnmapImage(id);
3383 3376
3384 EXPECT_CALL(*context, NextTextureId()) 3377 EXPECT_CALL(*context, NextTextureId())
3385 .WillOnce(Return(kTextureId)) 3378 .WillOnce(Return(kTextureId))
3386 .RetiresOnSaturation(); 3379 .RetiresOnSaturation();
3387 // Once in CreateTextureId and once in BindForSampling 3380 // Once in CreateTextureId and once in BindForSampling
3388 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2) 3381 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2)
3389 .RetiresOnSaturation(); 3382 .RetiresOnSaturation();
3390 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) 3383 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId))
3391 .Times(1) 3384 .Times(1)
3392 .RetiresOnSaturation(); 3385 .RetiresOnSaturation();
3393 { 3386 {
3394 ResourceProvider::ScopedSamplerGL lock_gl( 3387 ResourceProvider::ScopedSamplerGL lock_gl(
3395 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); 3388 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR);
3396 EXPECT_EQ(kTextureId, lock_gl.texture_id()); 3389 EXPECT_EQ(kTextureId, lock_gl.texture_id());
3397 } 3390 }
3398 3391
3399 EXPECT_CALL( 3392 EXPECT_CALL(
3400 *context, 3393 *context,
3401 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) 3394 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _))
3402 .WillOnce(SetArgPointee<2>(kStride)) 3395 .WillOnce(SetArgPointee<2>(kStride))
3403 .RetiresOnSaturation(); 3396 .RetiresOnSaturation();
3404 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) 3397 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId))
3405 .WillOnce(Return(dummy_mapped_buffer_address)) 3398 .WillOnce(Return(dummy_mapped_buffer_address))
3406 .RetiresOnSaturation(); 3399 .RetiresOnSaturation();
3407 resource_provider->AcquireImageRasterBuffer(id); 3400 resource_provider->MapImage(id, &stride);
3408 resource_provider->ReleaseImageRasterBuffer(id); 3401
3402 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId))
3403 .Times(1)
3404 .RetiresOnSaturation();
3405 resource_provider->UnmapImage(id);
3409 3406
3410 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) 3407 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1)
3411 .RetiresOnSaturation(); 3408 .RetiresOnSaturation();
3412 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) 3409 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId))
3413 .Times(1) 3410 .Times(1)
3414 .RetiresOnSaturation(); 3411 .RetiresOnSaturation();
3415 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) 3412 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId))
3416 .Times(1) 3413 .Times(1)
3417 .RetiresOnSaturation(); 3414 .RetiresOnSaturation();
3418 EXPECT_CALL(*context, RetireTextureId(kTextureId)) 3415 EXPECT_CALL(*context, RetireTextureId(kTextureId))
(...skipping 28 matching lines...) Expand all
3447 ResourceProvider::Create(output_surface.get(), 3444 ResourceProvider::Create(output_surface.get(),
3448 shared_bitmap_manager_.get(), 3445 shared_bitmap_manager_.get(),
3449 NULL, 3446 NULL,
3450 0, 3447 0,
3451 false, 3448 false,
3452 1, 3449 1,
3453 false)); 3450 false));
3454 3451
3455 id = resource_provider->CreateResource( 3452 id = resource_provider->CreateResource(
3456 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 3453 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3454 resource_provider->AcquireImage(id);
3457 3455
3458 SkBitmap bitmap; 3456 int stride;
3459 bitmap.allocN32Pixels(size.width(), size.height()); 3457 void* data = resource_provider->MapImage(id, &stride);
3460 *(bitmap.getAddr32(0, 0)) = kBadBeef; 3458 ASSERT_TRUE(!!data);
3461 RasterBuffer* raster_buffer = resource_provider->AcquireImageRasterBuffer(id); 3459 memcpy(data, &kBadBeef, sizeof(kBadBeef));
3462 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas(); 3460 resource_provider->UnmapImage(id);
3463 ASSERT_TRUE(!!canvas);
3464 canvas->writePixels(bitmap, 0, 0);
3465 raster_buffer->ReleaseSkCanvas(canvas);
3466 canvas.clear();
3467 resource_provider->ReleaseImageRasterBuffer(id);
3468 3461
3469 { 3462 {
3470 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); 3463 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id);
3471 const SkBitmap* sk_bitmap = lock.sk_bitmap(); 3464 const SkBitmap* sk_bitmap = lock.sk_bitmap();
3472 EXPECT_EQ(sk_bitmap->width(), size.width()); 3465 EXPECT_EQ(sk_bitmap->width(), size.width());
3473 EXPECT_EQ(sk_bitmap->height(), size.height()); 3466 EXPECT_EQ(sk_bitmap->height(), size.height());
3474 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); 3467 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef);
3475 } 3468 }
3476 3469
3470 resource_provider->ReleaseImage(id);
3477 resource_provider->DeleteResource(id); 3471 resource_provider->DeleteResource(id);
3478 } 3472 }
3479 3473
3480 TEST_P(ResourceProviderTest, CopyResource_GLTexture) { 3474 TEST_P(ResourceProviderTest, CopyResource_GLTexture) {
3481 if (GetParam() != ResourceProvider::GLTexture) 3475 if (GetParam() != ResourceProvider::GLTexture)
3482 return; 3476 return;
3483 scoped_ptr<AllocationTrackingContext3D> context_owned( 3477 scoped_ptr<AllocationTrackingContext3D> context_owned(
3484 new StrictMock<AllocationTrackingContext3D>); 3478 new StrictMock<AllocationTrackingContext3D>);
3485 AllocationTrackingContext3D* context = context_owned.get(); 3479 AllocationTrackingContext3D* context = context_owned.get();
3486 context_owned->set_support_sync_query(true); 3480 context_owned->set_support_sync_query(true);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3520 .WillOnce(Return(kImageId)) 3514 .WillOnce(Return(kImageId))
3521 .RetiresOnSaturation(); 3515 .RetiresOnSaturation();
3522 EXPECT_CALL( 3516 EXPECT_CALL(
3523 *context, 3517 *context,
3524 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) 3518 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _))
3525 .WillOnce(SetArgPointee<2>(kStride)) 3519 .WillOnce(SetArgPointee<2>(kStride))
3526 .RetiresOnSaturation(); 3520 .RetiresOnSaturation();
3527 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) 3521 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId))
3528 .WillOnce(Return(dummy_mapped_buffer_address)) 3522 .WillOnce(Return(dummy_mapped_buffer_address))
3529 .RetiresOnSaturation(); 3523 .RetiresOnSaturation();
3530 resource_provider->AcquireImageRasterBuffer(source_id); 3524 resource_provider->AcquireImage(source_id);
3531 resource_provider->ReleaseImageRasterBuffer(source_id); 3525 int stride;
3526 resource_provider->MapImage(source_id, &stride);
3527 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId))
3528 .Times(1)
3529 .RetiresOnSaturation();
3530 resource_provider->UnmapImage(source_id);
3532 Mock::VerifyAndClearExpectations(context); 3531 Mock::VerifyAndClearExpectations(context);
3533 3532
3534 dest_id = resource_provider->CreateResource( 3533 dest_id = resource_provider->CreateResource(
3535 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 3534 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3536 3535
3537 EXPECT_CALL(*context, NextTextureId()) 3536 EXPECT_CALL(*context, NextTextureId())
3538 .WillOnce(Return(kDestTextureId)) 3537 .WillOnce(Return(kDestTextureId))
3539 .RetiresOnSaturation(); 3538 .RetiresOnSaturation();
3540 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId)) 3539 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId))
3541 .Times(1) 3540 .Times(1)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3583 ResourceProvider::Create(output_surface.get(), 3582 ResourceProvider::Create(output_surface.get(),
3584 shared_bitmap_manager_.get(), 3583 shared_bitmap_manager_.get(),
3585 NULL, 3584 NULL,
3586 0, 3585 0,
3587 false, 3586 false,
3588 1, 3587 1,
3589 false)); 3588 false));
3590 3589
3591 source_id = resource_provider->CreateResource( 3590 source_id = resource_provider->CreateResource(
3592 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 3591 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3592 resource_provider->AcquireImage(source_id);
3593 3593
3594 SkBitmap bitmap; 3594 int stride;
3595 bitmap.allocN32Pixels(size.width(), size.height()); 3595 void* data = resource_provider->MapImage(source_id, &stride);
3596 *(bitmap.getAddr32(0, 0)) = kBadBeef; 3596 ASSERT_TRUE(!!data);
3597 RasterBuffer* raster_buffer = 3597 memcpy(data, &kBadBeef, sizeof(kBadBeef));
3598 resource_provider->AcquireImageRasterBuffer(source_id); 3598 resource_provider->UnmapImage(source_id);
3599 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas();
3600 ASSERT_TRUE(!!canvas);
3601 canvas->writePixels(bitmap, 0, 0);
3602 raster_buffer->ReleaseSkCanvas(canvas);
3603 canvas.clear();
3604 resource_provider->ReleaseImageRasterBuffer(source_id);
3605 3599
3606 dest_id = resource_provider->CreateResource( 3600 dest_id = resource_provider->CreateResource(
3607 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 3601 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3608 3602
3609 resource_provider->CopyResource(source_id, dest_id); 3603 resource_provider->CopyResource(source_id, dest_id);
3610 3604
3611 { 3605 {
3612 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), 3606 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(),
3613 dest_id); 3607 dest_id);
3614 const SkBitmap* sk_bitmap = lock.sk_bitmap(); 3608 const SkBitmap* sk_bitmap = lock.sk_bitmap();
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
3818 resource_provider->AllocateForTesting(id); 3812 resource_provider->AllocateForTesting(id);
3819 Mock::VerifyAndClearExpectations(context); 3813 Mock::VerifyAndClearExpectations(context);
3820 3814
3821 DCHECK_EQ(10u, context->PeekTextureId()); 3815 DCHECK_EQ(10u, context->PeekTextureId());
3822 resource_provider->DeleteResource(id); 3816 resource_provider->DeleteResource(id);
3823 } 3817 }
3824 } 3818 }
3825 3819
3826 } // namespace 3820 } // namespace
3827 } // namespace cc 3821 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698