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

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

Issue 454843002: cc: Do bitmap conversion for RasterBuffer in the worker thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 gfx::Rect rect(size); 603 gfx::Rect rect(size);
604 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d()); 604 child_resource_provider_->SetPixels(id1, data1, rect, rect, gfx::Vector2d());
605 605
606 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( 606 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource(
607 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 607 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
608 uint8_t data2[4] = { 5, 5, 5, 5 }; 608 uint8_t data2[4] = { 5, 5, 5, 5 };
609 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); 609 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
610 610
611 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( 611 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource(
612 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 612 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
613 child_resource_provider_->MapImageRasterBuffer(id3); 613 child_resource_provider_->AcquireImageRasterBuffer(id3);
614 child_resource_provider_->UnmapImageRasterBuffer(id3); 614 child_resource_provider_->ReleaseImageRasterBuffer(id3);
615 615
616 GLuint external_texture_id = child_context_->createExternalTexture(); 616 GLuint external_texture_id = child_context_->createExternalTexture();
617 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id); 617 child_context_->bindTexture(GL_TEXTURE_EXTERNAL_OES, external_texture_id);
618 618
619 gpu::Mailbox external_mailbox; 619 gpu::Mailbox external_mailbox;
620 child_context_->genMailboxCHROMIUM(external_mailbox.name); 620 child_context_->genMailboxCHROMIUM(external_mailbox.name);
621 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES, 621 child_context_->produceTextureCHROMIUM(GL_TEXTURE_EXTERNAL_OES,
622 external_mailbox.name); 622 external_mailbox.name);
623 const GLuint external_sync_point = child_context_->insertSyncPoint(); 623 const GLuint external_sync_point = child_context_->insertSyncPoint();
624 ResourceProvider::ResourceId id4 = 624 ResourceProvider::ResourceId id4 =
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 952
953 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource( 953 ResourceProvider::ResourceId id2 = child_resource_provider_->CreateResource(
954 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 954 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
955 uint8_t data2[4] = { 5, 5, 5, 5 }; 955 uint8_t data2[4] = { 5, 5, 5, 5 };
956 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d()); 956 child_resource_provider_->SetPixels(id2, data2, rect, rect, gfx::Vector2d());
957 957
958 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource( 958 ResourceProvider::ResourceId id3 = child_resource_provider_->CreateResource(
959 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 959 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
960 uint8_t data3[4] = { 6, 7, 8, 9 }; 960 uint8_t data3[4] = { 6, 7, 8, 9 };
961 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); 961 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height());
962 SkCanvas* raster_canvas = child_resource_provider_->MapImageRasterBuffer(id3); 962 RasterBuffer* raster_buffer =
963 raster_canvas->writePixels(info, data3, info.minRowBytes(), 0, 0); 963 child_resource_provider_->AcquireImageRasterBuffer(id3);
964 child_resource_provider_->UnmapImageRasterBuffer(id3); 964 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas();
965 canvas->writePixels(info, data3, info.minRowBytes(), 0, 0);
966 raster_buffer->ReleaseSkCanvas(canvas);
967 canvas.clear();
968 child_resource_provider_->ReleaseImageRasterBuffer(id3);
965 969
966 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); 970 scoped_ptr<base::SharedMemory> shared_memory(new base::SharedMemory());
967 shared_memory->CreateAndMapAnonymous(1); 971 shared_memory->CreateAndMapAnonymous(1);
968 base::SharedMemory* shared_memory_ptr = shared_memory.get(); 972 base::SharedMemory* shared_memory_ptr = shared_memory.get();
969 ResourceProvider::ResourceId id4 = 973 ResourceProvider::ResourceId id4 =
970 child_resource_provider_->CreateResourceFromTextureMailbox( 974 child_resource_provider_->CreateResourceFromTextureMailbox(
971 TextureMailbox(shared_memory_ptr, gfx::Size(1, 1)), 975 TextureMailbox(shared_memory_ptr, gfx::Size(1, 1)),
972 SingleReleaseCallback::Create(base::Bind( 976 SingleReleaseCallback::Create(base::Bind(
973 &SharedMemoryReleaseCallback, base::Passed(&shared_memory)))); 977 &SharedMemoryReleaseCallback, base::Passed(&shared_memory))));
974 978
(...skipping 1942 matching lines...) Expand 10 before | Expand all | Expand 10 after
2917 resource_provider->SetPixels(id, pixels, rect, rect, offset); 2921 resource_provider->SetPixels(id, pixels, rect, rect, offset);
2918 2922
2919 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1); 2923 EXPECT_CALL(*context, RetireTextureId(texture_id)).Times(1);
2920 resource_provider->DeleteResource(id); 2924 resource_provider->DeleteResource(id);
2921 2925
2922 Mock::VerifyAndClearExpectations(context); 2926 Mock::VerifyAndClearExpectations(context);
2923 2927
2924 // Same for async version. 2928 // Same for async version.
2925 id = resource_provider->CreateResource( 2929 id = resource_provider->CreateResource(
2926 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 2930 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
2927 resource_provider->AcquirePixelRasterBuffer(id); 2931 RasterBuffer* raster_buffer = resource_provider->AcquirePixelRasterBuffer(id);
2932 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas();
2933 raster_buffer->ReleaseSkCanvas(canvas);
2934 canvas.clear();
2928 2935
2929 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 2936 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
2930 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 2937 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
2931 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 2938 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
2932 .Times(1); 2939 .Times(1);
2933 resource_provider->BeginSetPixels(id); 2940 resource_provider->BeginSetPixels(id);
2934 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id)); 2941 ASSERT_TRUE(resource_provider->DidSetPixelsComplete(id));
2935 2942
2936 resource_provider->ReleasePixelRasterBuffer(id); 2943 resource_provider->ReleasePixelRasterBuffer(id);
2937 2944
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
3005 gfx::Size size(2, 2); 3012 gfx::Size size(2, 2);
3006 ResourceFormat format = RGBA_8888; 3013 ResourceFormat format = RGBA_8888;
3007 ResourceProvider::ResourceId id = 0; 3014 ResourceProvider::ResourceId id = 0;
3008 int texture_id = 123; 3015 int texture_id = 123;
3009 3016
3010 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3017 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3011 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3018 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3012 3019
3013 id = resource_provider->CreateResource( 3020 id = resource_provider->CreateResource(
3014 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 3021 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3015 resource_provider->AcquirePixelRasterBuffer(id); 3022 RasterBuffer* raster_buffer = resource_provider->AcquirePixelRasterBuffer(id);
3023 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas();
3024 raster_buffer->ReleaseSkCanvas(canvas);
3025 canvas.clear();
3016 3026
3017 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3027 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3018 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3028 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3019 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 3029 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
3020 .Times(1); 3030 .Times(1);
3021 resource_provider->BeginSetPixels(id); 3031 resource_provider->BeginSetPixels(id);
3022 3032
3023 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id)); 3033 EXPECT_TRUE(resource_provider->DidSetPixelsComplete(id));
3024 3034
3025 resource_provider->ReleasePixelRasterBuffer(id); 3035 resource_provider->ReleasePixelRasterBuffer(id);
(...skipping 20 matching lines...) Expand all
3046 gfx::Size size(2, 2); 3056 gfx::Size size(2, 2);
3047 ResourceFormat format = RGBA_8888; 3057 ResourceFormat format = RGBA_8888;
3048 ResourceProvider::ResourceId id = 0; 3058 ResourceProvider::ResourceId id = 0;
3049 int texture_id = 123; 3059 int texture_id = 123;
3050 3060
3051 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3061 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3052 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3062 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3053 3063
3054 id = resource_provider->CreateResource( 3064 id = resource_provider->CreateResource(
3055 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 3065 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3056 resource_provider->AcquirePixelRasterBuffer(id); 3066 RasterBuffer* raster_buffer = resource_provider->AcquirePixelRasterBuffer(id);
3067 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas();
3068 raster_buffer->ReleaseSkCanvas(canvas);
3069 canvas.clear();
3057 3070
3058 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id)); 3071 EXPECT_CALL(*context, NextTextureId()).WillOnce(Return(texture_id));
3059 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2); 3072 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(2);
3060 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _)) 3073 EXPECT_CALL(*context, asyncTexImage2DCHROMIUM(_, _, _, 2, 2, _, _, _, _))
3061 .Times(1); 3074 .Times(1);
3062 resource_provider->BeginSetPixels(id); 3075 resource_provider->BeginSetPixels(id);
3063 3076
3064 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1); 3077 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, texture_id)).Times(1);
3065 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1); 3078 EXPECT_CALL(*context, waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)).Times(1);
3066 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1); 3079 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, 0)).Times(1);
(...skipping 25 matching lines...) Expand all
3092 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3105 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3093 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3106 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3094 3107
3095 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id)); 3108 EXPECT_CALL(*context, NextTextureId()).WillRepeatedly(Return(texture_id));
3096 3109
3097 id = resource_provider->CreateResource( 3110 id = resource_provider->CreateResource(
3098 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 3111 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3099 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, 3112 context->loseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
3100 GL_INNOCENT_CONTEXT_RESET_ARB); 3113 GL_INNOCENT_CONTEXT_RESET_ARB);
3101 3114
3102 resource_provider->AcquirePixelRasterBuffer(id); 3115 RasterBuffer* raster_buffer = resource_provider->AcquirePixelRasterBuffer(id);
3103 SkCanvas* raster_canvas = resource_provider->MapPixelRasterBuffer(id); 3116 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas();
3104 EXPECT_TRUE(raster_canvas == NULL); 3117 EXPECT_TRUE(canvas.get() == NULL);
3105 resource_provider->UnmapPixelRasterBuffer(id); 3118 raster_buffer->ReleaseSkCanvas(canvas);
3119 canvas.clear();
3106 resource_provider->ReleasePixelRasterBuffer(id); 3120 resource_provider->ReleasePixelRasterBuffer(id);
3107 Mock::VerifyAndClearExpectations(context); 3121 Mock::VerifyAndClearExpectations(context);
3108 } 3122 }
3109 3123
3110 TEST_P(ResourceProviderTest, Image_GLTexture) { 3124 TEST_P(ResourceProviderTest, Image_GLTexture) {
3111 // Only for GL textures. 3125 // Only for GL textures.
3112 if (GetParam() != ResourceProvider::GLTexture) 3126 if (GetParam() != ResourceProvider::GLTexture)
3113 return; 3127 return;
3114 scoped_ptr<AllocationTrackingContext3D> context_owned( 3128 scoped_ptr<AllocationTrackingContext3D> context_owned(
3115 new StrictMock<AllocationTrackingContext3D>); 3129 new StrictMock<AllocationTrackingContext3D>);
(...skipping 26 matching lines...) Expand all
3142 .WillOnce(Return(kImageId)) 3156 .WillOnce(Return(kImageId))
3143 .RetiresOnSaturation(); 3157 .RetiresOnSaturation();
3144 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId, 3158 EXPECT_CALL(*context, getImageParameterivCHROMIUM(kImageId,
3145 GL_IMAGE_ROWBYTES_CHROMIUM, 3159 GL_IMAGE_ROWBYTES_CHROMIUM,
3146 _)) 3160 _))
3147 .WillOnce(SetArgPointee<2>(kStride)) 3161 .WillOnce(SetArgPointee<2>(kStride))
3148 .RetiresOnSaturation(); 3162 .RetiresOnSaturation();
3149 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) 3163 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId))
3150 .WillOnce(Return(dummy_mapped_buffer_address)) 3164 .WillOnce(Return(dummy_mapped_buffer_address))
3151 .RetiresOnSaturation(); 3165 .RetiresOnSaturation();
3152 resource_provider->MapImageRasterBuffer(id); 3166 resource_provider->AcquireImageRasterBuffer(id);
3153 3167 resource_provider->ReleaseImageRasterBuffer(id);
3154 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId))
3155 .Times(1)
3156 .RetiresOnSaturation();
3157 resource_provider->UnmapImageRasterBuffer(id);
3158 3168
3159 EXPECT_CALL(*context, NextTextureId()) 3169 EXPECT_CALL(*context, NextTextureId())
3160 .WillOnce(Return(kTextureId)) 3170 .WillOnce(Return(kTextureId))
3161 .RetiresOnSaturation(); 3171 .RetiresOnSaturation();
3162 // Once in CreateTextureId and once in BindForSampling 3172 // Once in CreateTextureId and once in BindForSampling
3163 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2) 3173 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(2)
3164 .RetiresOnSaturation(); 3174 .RetiresOnSaturation();
3165 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) 3175 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId))
3166 .Times(1) 3176 .Times(1)
3167 .RetiresOnSaturation(); 3177 .RetiresOnSaturation();
3168 { 3178 {
3169 ResourceProvider::ScopedSamplerGL lock_gl( 3179 ResourceProvider::ScopedSamplerGL lock_gl(
3170 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR); 3180 resource_provider.get(), id, GL_TEXTURE_2D, GL_LINEAR);
3171 EXPECT_EQ(kTextureId, lock_gl.texture_id()); 3181 EXPECT_EQ(kTextureId, lock_gl.texture_id());
3172 } 3182 }
3173 3183
3174 EXPECT_CALL( 3184 EXPECT_CALL(
3175 *context, 3185 *context,
3176 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) 3186 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _))
3177 .WillOnce(SetArgPointee<2>(kStride)) 3187 .WillOnce(SetArgPointee<2>(kStride))
3178 .RetiresOnSaturation(); 3188 .RetiresOnSaturation();
3179 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) 3189 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId))
3180 .WillOnce(Return(dummy_mapped_buffer_address)) 3190 .WillOnce(Return(dummy_mapped_buffer_address))
3181 .RetiresOnSaturation(); 3191 .RetiresOnSaturation();
3182 resource_provider->MapImageRasterBuffer(id); 3192 resource_provider->AcquireImageRasterBuffer(id);
3183 3193 resource_provider->ReleaseImageRasterBuffer(id);
3184 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId))
3185 .Times(1)
3186 .RetiresOnSaturation();
3187 resource_provider->UnmapImageRasterBuffer(id);
3188 3194
3189 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1) 3195 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kTextureId)).Times(1)
3190 .RetiresOnSaturation(); 3196 .RetiresOnSaturation();
3191 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) 3197 EXPECT_CALL(*context, releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId))
3192 .Times(1) 3198 .Times(1)
3193 .RetiresOnSaturation(); 3199 .RetiresOnSaturation();
3194 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId)) 3200 EXPECT_CALL(*context, bindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId))
3195 .Times(1) 3201 .Times(1)
3196 .RetiresOnSaturation(); 3202 .RetiresOnSaturation();
3197 EXPECT_CALL(*context, RetireTextureId(kTextureId)) 3203 EXPECT_CALL(*context, RetireTextureId(kTextureId))
(...skipping 26 matching lines...) Expand all
3224 3230
3225 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3231 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3226 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3232 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3227 3233
3228 id = resource_provider->CreateResource( 3234 id = resource_provider->CreateResource(
3229 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 3235 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3230 3236
3231 SkBitmap bitmap; 3237 SkBitmap bitmap;
3232 bitmap.allocN32Pixels(size.width(), size.height()); 3238 bitmap.allocN32Pixels(size.width(), size.height());
3233 *(bitmap.getAddr32(0, 0)) = kBadBeef; 3239 *(bitmap.getAddr32(0, 0)) = kBadBeef;
3234 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(id); 3240 RasterBuffer* raster_buffer = resource_provider->AcquireImageRasterBuffer(id);
3241 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas();
3235 ASSERT_TRUE(!!canvas); 3242 ASSERT_TRUE(!!canvas);
3236 canvas->writePixels(bitmap, 0, 0); 3243 canvas->writePixels(bitmap, 0, 0);
3237 resource_provider->UnmapImageRasterBuffer(id); 3244 raster_buffer->ReleaseSkCanvas(canvas);
3245 canvas.clear();
3246 resource_provider->ReleaseImageRasterBuffer(id);
3238 3247
3239 { 3248 {
3240 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id); 3249 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), id);
3241 const SkBitmap* sk_bitmap = lock.sk_bitmap(); 3250 const SkBitmap* sk_bitmap = lock.sk_bitmap();
3242 EXPECT_EQ(sk_bitmap->width(), size.width()); 3251 EXPECT_EQ(sk_bitmap->width(), size.width());
3243 EXPECT_EQ(sk_bitmap->height(), size.height()); 3252 EXPECT_EQ(sk_bitmap->height(), size.height());
3244 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef); 3253 EXPECT_EQ(*sk_bitmap->getAddr32(0, 0), kBadBeef);
3245 } 3254 }
3246 3255
3247 resource_provider->DeleteResource(id); 3256 resource_provider->DeleteResource(id);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3284 .WillOnce(Return(kImageId)) 3293 .WillOnce(Return(kImageId))
3285 .RetiresOnSaturation(); 3294 .RetiresOnSaturation();
3286 EXPECT_CALL( 3295 EXPECT_CALL(
3287 *context, 3296 *context,
3288 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _)) 3297 getImageParameterivCHROMIUM(kImageId, GL_IMAGE_ROWBYTES_CHROMIUM, _))
3289 .WillOnce(SetArgPointee<2>(kStride)) 3298 .WillOnce(SetArgPointee<2>(kStride))
3290 .RetiresOnSaturation(); 3299 .RetiresOnSaturation();
3291 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId)) 3300 EXPECT_CALL(*context, mapImageCHROMIUM(kImageId))
3292 .WillOnce(Return(dummy_mapped_buffer_address)) 3301 .WillOnce(Return(dummy_mapped_buffer_address))
3293 .RetiresOnSaturation(); 3302 .RetiresOnSaturation();
3294 resource_provider->MapImageRasterBuffer(source_id); 3303 resource_provider->AcquireImageRasterBuffer(source_id);
3295 Mock::VerifyAndClearExpectations(context); 3304 resource_provider->ReleaseImageRasterBuffer(source_id);
3296
3297 EXPECT_CALL(*context, unmapImageCHROMIUM(kImageId))
3298 .Times(1)
3299 .RetiresOnSaturation();
3300 resource_provider->UnmapImageRasterBuffer(source_id);
3301 Mock::VerifyAndClearExpectations(context); 3305 Mock::VerifyAndClearExpectations(context);
3302 3306
3303 dest_id = resource_provider->CreateResource( 3307 dest_id = resource_provider->CreateResource(
3304 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 3308 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3305 3309
3306 EXPECT_CALL(*context, NextTextureId()) 3310 EXPECT_CALL(*context, NextTextureId())
3307 .WillOnce(Return(kDestTextureId)) 3311 .WillOnce(Return(kDestTextureId))
3308 .RetiresOnSaturation(); 3312 .RetiresOnSaturation();
3309 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId)) 3313 EXPECT_CALL(*context, bindTexture(GL_TEXTURE_2D, kDestTextureId))
3310 .Times(1) 3314 .Times(1)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3350 3354
3351 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create( 3355 scoped_ptr<ResourceProvider> resource_provider(ResourceProvider::Create(
3352 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false)); 3356 output_surface.get(), shared_bitmap_manager_.get(), 0, false, 1, false));
3353 3357
3354 source_id = resource_provider->CreateResource( 3358 source_id = resource_provider->CreateResource(
3355 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 3359 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3356 3360
3357 SkBitmap bitmap; 3361 SkBitmap bitmap;
3358 bitmap.allocN32Pixels(size.width(), size.height()); 3362 bitmap.allocN32Pixels(size.width(), size.height());
3359 *(bitmap.getAddr32(0, 0)) = kBadBeef; 3363 *(bitmap.getAddr32(0, 0)) = kBadBeef;
3360 SkCanvas* canvas = resource_provider->MapImageRasterBuffer(source_id); 3364 RasterBuffer* raster_buffer =
3365 resource_provider->AcquireImageRasterBuffer(source_id);
3366 skia::RefPtr<SkCanvas> canvas = raster_buffer->AcquireSkCanvas();
3361 ASSERT_TRUE(!!canvas); 3367 ASSERT_TRUE(!!canvas);
3362 canvas->writePixels(bitmap, 0, 0); 3368 canvas->writePixels(bitmap, 0, 0);
3363 resource_provider->UnmapImageRasterBuffer(source_id); 3369 raster_buffer->ReleaseSkCanvas(canvas);
3370 canvas.clear();
3371 resource_provider->ReleaseImageRasterBuffer(source_id);
3364 3372
3365 dest_id = resource_provider->CreateResource( 3373 dest_id = resource_provider->CreateResource(
3366 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format); 3374 size, GL_CLAMP_TO_EDGE, ResourceProvider::TextureHintImmutable, format);
3367 3375
3368 resource_provider->CopyResource(source_id, dest_id); 3376 resource_provider->CopyResource(source_id, dest_id);
3369 3377
3370 { 3378 {
3371 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(), 3379 ResourceProvider::ScopedReadLockSoftware lock(resource_provider.get(),
3372 dest_id); 3380 dest_id);
3373 const SkBitmap* sk_bitmap = lock.sk_bitmap(); 3381 const SkBitmap* sk_bitmap = lock.sk_bitmap();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
3567 resource_provider->AllocateForTesting(id); 3575 resource_provider->AllocateForTesting(id);
3568 Mock::VerifyAndClearExpectations(context); 3576 Mock::VerifyAndClearExpectations(context);
3569 3577
3570 DCHECK_EQ(10u, context->PeekTextureId()); 3578 DCHECK_EQ(10u, context->PeekTextureId());
3571 resource_provider->DeleteResource(id); 3579 resource_provider->DeleteResource(id);
3572 } 3580 }
3573 } 3581 }
3574 3582
3575 } // namespace 3583 } // namespace
3576 } // namespace cc 3584 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698