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

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

Issue 2752523006: cc: Use SkCreateColorSpaceXformCanvas for color transforms (Closed)
Patch Set: Allow to link Created 3 years, 9 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 // Software resources are immutable; they cannot change format or be 876 // Software resources are immutable; they cannot change format or be
877 // resized. 877 // resized.
878 return true; 878 return true;
879 } 879 }
880 } 880 }
881 881
882 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) { 882 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) {
883 return GetResource(id)->hint; 883 return GetResource(id)->hint;
884 } 884 }
885 885
886 sk_sp<SkColorSpace> ResourceProvider::GetResourceSkColorSpace(
887 const Resource* resource) const {
888 if (!settings_.enable_color_correct_rasterization)
889 return nullptr;
890 // Returning the nonlinear blended color space matches the expectation of the
891 // web that colors are blended in the output color space, not in a
892 // physically-based linear space.
893 return resource->color_space.ToNonlinearBlendedSkColorSpace();
894 }
895
896 void ResourceProvider::CopyToResource(ResourceId id, 886 void ResourceProvider::CopyToResource(ResourceId id,
897 const uint8_t* image, 887 const uint8_t* image,
898 const gfx::Size& image_size) { 888 const gfx::Size& image_size) {
899 Resource* resource = GetResource(id); 889 Resource* resource = GetResource(id);
900 DCHECK(!resource->locked_for_write); 890 DCHECK(!resource->locked_for_write);
901 DCHECK(!resource->lock_for_read_count); 891 DCHECK(!resource->lock_for_read_count);
902 DCHECK(resource->origin == Resource::INTERNAL); 892 DCHECK(resource->origin == Resource::INTERNAL);
903 DCHECK_EQ(resource->exported_count, 0); 893 DCHECK_EQ(resource->exported_count, 0);
904 DCHECK(ReadLockFenceHasPassed(resource)); 894 DCHECK(ReadLockFenceHasPassed(resource));
905 895
906 DCHECK_EQ(image_size.width(), resource->size.width()); 896 DCHECK_EQ(image_size.width(), resource->size.width());
907 DCHECK_EQ(image_size.height(), resource->size.height()); 897 DCHECK_EQ(image_size.height(), resource->size.height());
908 898
909 if (resource->allocated) 899 if (resource->allocated)
910 WaitSyncTokenIfNeeded(id); 900 WaitSyncTokenIfNeeded(id);
911 901
912 if (resource->type == RESOURCE_TYPE_BITMAP) { 902 if (resource->type == RESOURCE_TYPE_BITMAP) {
913 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); 903 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type);
914 DCHECK(resource->allocated); 904 DCHECK(resource->allocated);
915 DCHECK_EQ(RGBA_8888, resource->format); 905 DCHECK_EQ(RGBA_8888, resource->format);
916 SkImageInfo source_info = 906 SkImageInfo source_info =
917 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height(), 907 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height());
918 GetResourceSkColorSpace(resource));
919 size_t image_stride = image_size.width() * 4; 908 size_t image_stride = image_size.width() * 4;
920 909
921 ScopedWriteLockSoftware lock(this, id); 910 ScopedWriteLockSoftware lock(this, id);
922 SkCanvas dest(lock.sk_bitmap()); 911 SkCanvas dest(lock.sk_bitmap());
923 dest.writePixels(source_info, image, image_stride, 0, 0); 912 dest.writePixels(source_info, image, image_stride, 0, 0);
924 } else { 913 } else {
925 ScopedWriteLockGL lock(this, id, false); 914 ScopedWriteLockGL lock(this, id, false);
926 unsigned resource_texture_id = lock.texture_id(); 915 unsigned resource_texture_id = lock.texture_id();
927 DCHECK(resource_texture_id); 916 DCHECK(resource_texture_id);
928 GLES2Interface* gl = ContextGL(); 917 GLES2Interface* gl = ContextGL();
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 resource_provider_->BindImageForSampling(resource); 1177 resource_provider_->BindImageForSampling(resource);
1189 if (create_mailbox) { 1178 if (create_mailbox) {
1190 resource_provider_->CreateMailboxAndBindResource( 1179 resource_provider_->CreateMailboxAndBindResource(
1191 resource_provider_->ContextGL(), resource); 1180 resource_provider_->ContextGL(), resource);
1192 } 1181 }
1193 texture_id_ = resource->gl_id; 1182 texture_id_ = resource->gl_id;
1194 target_ = resource->target; 1183 target_ = resource->target;
1195 format_ = resource->format; 1184 format_ = resource->format;
1196 size_ = resource->size; 1185 size_ = resource->size;
1197 mailbox_ = resource->mailbox(); 1186 mailbox_ = resource->mailbox();
1198 sk_color_space_ = resource_provider->GetResourceSkColorSpace(resource);
1199 } 1187 }
1200 1188
1201 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { 1189 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() {
1202 DCHECK(thread_checker_.CalledOnValidThread()); 1190 DCHECK(thread_checker_.CalledOnValidThread());
1203 Resource* resource = resource_provider_->GetResource(resource_id_); 1191 Resource* resource = resource_provider_->GetResource(resource_id_);
1204 DCHECK(resource->locked_for_write); 1192 DCHECK(resource->locked_for_write);
1205 // It's not sufficient to check sync_token_.HasData() here because the sync 1193 // It's not sufficient to check sync_token_.HasData() here because the sync
1206 // might be null because of context loss. Even in that case we want to set the 1194 // might be null because of context loss. Even in that case we want to set the
1207 // sync token because it's checked in PrepareSendToParent while drawing. 1195 // sync token because it's checked in PrepareSendToParent while drawing.
1208 if (has_sync_token_) 1196 if (has_sync_token_)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 uint32_t flags = 1244 uint32_t flags =
1257 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; 1245 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;
1258 // Use unknown pixel geometry to disable LCD text. 1246 // Use unknown pixel geometry to disable LCD text.
1259 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); 1247 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry);
1260 if (can_use_lcd_text) { 1248 if (can_use_lcd_text) {
1261 // LegacyFontHost will get LCD text and skia figures out what type to use. 1249 // LegacyFontHost will get LCD text and skia figures out what type to use.
1262 surface_props = 1250 surface_props =
1263 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); 1251 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType);
1264 } 1252 }
1265 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( 1253 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget(
1266 context_provider->GrContext(), desc, resource_lock->sk_color_space(), 1254 context_provider->GrContext(), desc, nullptr, &surface_props);
1267 &surface_props);
1268 } 1255 }
1269 1256
1270 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { 1257 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() {
1271 if (sk_surface_.get()) { 1258 if (sk_surface_.get()) {
1272 sk_surface_->prepareForExternalIO(); 1259 sk_surface_->prepareForExternalIO();
1273 sk_surface_.reset(); 1260 sk_surface_.reset();
1274 } 1261 }
1275 } 1262 }
1276 1263
1277 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, 1264 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap,
1278 const Resource* resource) { 1265 const Resource* resource) {
1279 DCHECK_EQ(RGBA_8888, resource->format); 1266 DCHECK_EQ(RGBA_8888, resource->format);
1280 SkImageInfo info = SkImageInfo::MakeN32Premul( 1267 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(),
1281 resource->size.width(), resource->size.height(), 1268 resource->size.height());
1282 GetResourceSkColorSpace(resource));
1283 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); 1269 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes());
1284 } 1270 }
1285 1271
1286 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( 1272 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(
1287 ResourceProvider* resource_provider, 1273 ResourceProvider* resource_provider,
1288 ResourceId resource_id) 1274 ResourceId resource_id)
1289 : resource_provider_(resource_provider), resource_id_(resource_id) { 1275 : resource_provider_(resource_provider), resource_id_(resource_id) {
1290 const Resource* resource = resource_provider->LockForRead(resource_id); 1276 const Resource* resource = resource_provider->LockForRead(resource_id);
1291 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); 1277 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource);
1292 } 1278 }
(...skipping 12 matching lines...) Expand all
1305 texture_info.fID = resource->gl_id; 1291 texture_info.fID = resource->gl_id;
1306 texture_info.fTarget = resource->target; 1292 texture_info.fTarget = resource->target;
1307 GrBackendTextureDesc desc; 1293 GrBackendTextureDesc desc;
1308 desc.fWidth = resource->size.width(); 1294 desc.fWidth = resource->size.width();
1309 desc.fHeight = resource->size.height(); 1295 desc.fHeight = resource->size.height();
1310 desc.fConfig = ToGrPixelConfig(resource->format); 1296 desc.fConfig = ToGrPixelConfig(resource->format);
1311 desc.fOrigin = kTopLeft_GrSurfaceOrigin; 1297 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
1312 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); 1298 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info);
1313 sk_image_ = SkImage::MakeFromTexture( 1299 sk_image_ = SkImage::MakeFromTexture(
1314 resource_provider->compositor_context_provider_->GrContext(), desc, 1300 resource_provider->compositor_context_provider_->GrContext(), desc,
1315 kPremul_SkAlphaType, 1301 kPremul_SkAlphaType);
1316 resource_provider->GetResourceSkColorSpace(resource), nullptr, nullptr);
1317 } else if (resource->pixels) { 1302 } else if (resource->pixels) {
1318 SkBitmap sk_bitmap; 1303 SkBitmap sk_bitmap;
1319 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap, resource); 1304 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap, resource);
1320 sk_bitmap.setImmutable(); 1305 sk_bitmap.setImmutable();
1321 sk_image_ = SkImage::MakeFromBitmap(sk_bitmap); 1306 sk_image_ = SkImage::MakeFromBitmap(sk_bitmap);
1322 } else { 1307 } else {
1323 // During render process shutdown, ~RenderMessageFilter which calls 1308 // During render process shutdown, ~RenderMessageFilter which calls
1324 // ~HostSharedBitmapClient (which deletes shared bitmaps from child) 1309 // ~HostSharedBitmapClient (which deletes shared bitmaps from child)
1325 // can race with OnBeginFrameDeadline which draws a frame. 1310 // can race with OnBeginFrameDeadline which draws a frame.
1326 // In these cases, shared bitmaps (and this read lock) won't be valid. 1311 // In these cases, shared bitmaps (and this read lock) won't be valid.
1327 // Renderers need to silently handle locks failing until this race 1312 // Renderers need to silently handle locks failing until this race
1328 // is fixed. DCHECK that this is the only case where there are no pixels. 1313 // is fixed. DCHECK that this is the only case where there are no pixels.
1329 DCHECK(!resource->shared_bitmap_id.IsZero()); 1314 DCHECK(!resource->shared_bitmap_id.IsZero());
1330 } 1315 }
1331 } 1316 }
1332 1317
1333 ResourceProvider::ScopedReadLockSkImage::~ScopedReadLockSkImage() { 1318 ResourceProvider::ScopedReadLockSkImage::~ScopedReadLockSkImage() {
1334 resource_provider_->UnlockForRead(resource_id_); 1319 resource_provider_->UnlockForRead(resource_id_);
1335 } 1320 }
1336 1321
1337 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( 1322 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware(
1338 ResourceProvider* resource_provider, 1323 ResourceProvider* resource_provider,
1339 ResourceId resource_id) 1324 ResourceId resource_id)
1340 : resource_provider_(resource_provider), resource_id_(resource_id) { 1325 : resource_provider_(resource_provider), resource_id_(resource_id) {
1341 Resource* resource = resource_provider->LockForWrite(resource_id); 1326 Resource* resource = resource_provider->LockForWrite(resource_id);
1342 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); 1327 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource);
1343 sk_color_space_ = resource_provider->GetResourceSkColorSpace(resource);
1344 DCHECK(valid()); 1328 DCHECK(valid());
1345 } 1329 }
1346 1330
1347 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { 1331 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() {
1348 DCHECK(thread_checker_.CalledOnValidThread()); 1332 DCHECK(thread_checker_.CalledOnValidThread());
1349 Resource* resource = resource_provider_->GetResource(resource_id_); 1333 Resource* resource = resource_provider_->GetResource(resource_id_);
1350 DCHECK(resource); 1334 DCHECK(resource);
1351 resource->SetSynchronized(); 1335 resource->SetSynchronized();
1352 resource_provider_->UnlockForWrite(resource); 1336 resource_provider_->UnlockForWrite(resource);
1353 } 1337 }
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 2171
2188 const int kImportance = 2; 2172 const int kImportance = 2;
2189 pmd->CreateSharedGlobalAllocatorDump(guid); 2173 pmd->CreateSharedGlobalAllocatorDump(guid);
2190 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 2174 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
2191 } 2175 }
2192 2176
2193 return true; 2177 return true;
2194 } 2178 }
2195 2179
2196 } // namespace cc 2180 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698