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 <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 Loading... |
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( | 886 gfx::ColorSpace ResourceProvider::GetResourceColorSpaceForRaster( |
887 const Resource* resource) const { | 887 const Resource* resource) const { |
888 if (!settings_.enable_color_correct_rasterization) | 888 if (!settings_.enable_color_correct_rasterization) |
889 return nullptr; | 889 return gfx::ColorSpace(); |
890 // Returning the nonlinear blended color space matches the expectation of the | 890 return resource->color_space; |
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 } | 891 } |
895 | 892 |
896 void ResourceProvider::CopyToResource(ResourceId id, | 893 void ResourceProvider::CopyToResource(ResourceId id, |
897 const uint8_t* image, | 894 const uint8_t* image, |
898 const gfx::Size& image_size) { | 895 const gfx::Size& image_size) { |
899 Resource* resource = GetResource(id); | 896 Resource* resource = GetResource(id); |
900 DCHECK(!resource->locked_for_write); | 897 DCHECK(!resource->locked_for_write); |
901 DCHECK(!resource->lock_for_read_count); | 898 DCHECK(!resource->lock_for_read_count); |
902 DCHECK(resource->origin == Resource::INTERNAL); | 899 DCHECK(resource->origin == Resource::INTERNAL); |
903 DCHECK_EQ(resource->exported_count, 0); | 900 DCHECK_EQ(resource->exported_count, 0); |
904 DCHECK(ReadLockFenceHasPassed(resource)); | 901 DCHECK(ReadLockFenceHasPassed(resource)); |
905 | 902 |
906 DCHECK_EQ(image_size.width(), resource->size.width()); | 903 DCHECK_EQ(image_size.width(), resource->size.width()); |
907 DCHECK_EQ(image_size.height(), resource->size.height()); | 904 DCHECK_EQ(image_size.height(), resource->size.height()); |
908 | 905 |
909 if (resource->allocated) | 906 if (resource->allocated) |
910 WaitSyncTokenIfNeeded(id); | 907 WaitSyncTokenIfNeeded(id); |
911 | 908 |
912 if (resource->type == RESOURCE_TYPE_BITMAP) { | 909 if (resource->type == RESOURCE_TYPE_BITMAP) { |
913 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); | 910 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); |
914 DCHECK(resource->allocated); | 911 DCHECK(resource->allocated); |
915 DCHECK_EQ(RGBA_8888, resource->format); | 912 DCHECK_EQ(RGBA_8888, resource->format); |
916 SkImageInfo source_info = | 913 SkImageInfo source_info = |
917 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height(), | 914 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); |
918 GetResourceSkColorSpace(resource)); | |
919 size_t image_stride = image_size.width() * 4; | 915 size_t image_stride = image_size.width() * 4; |
920 | 916 |
921 ScopedWriteLockSoftware lock(this, id); | 917 ScopedWriteLockSoftware lock(this, id); |
922 SkCanvas dest(lock.sk_bitmap()); | 918 SkCanvas dest(lock.sk_bitmap()); |
923 dest.writePixels(source_info, image, image_stride, 0, 0); | 919 dest.writePixels(source_info, image, image_stride, 0, 0); |
924 } else { | 920 } else { |
925 ScopedWriteLockGL lock(this, id, false); | 921 ScopedWriteLockGL lock(this, id, false); |
926 unsigned resource_texture_id = lock.texture_id(); | 922 unsigned resource_texture_id = lock.texture_id(); |
927 DCHECK(resource_texture_id); | 923 DCHECK(resource_texture_id); |
928 GLES2Interface* gl = ContextGL(); | 924 GLES2Interface* gl = ContextGL(); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 resource_provider_->BindImageForSampling(resource); | 1184 resource_provider_->BindImageForSampling(resource); |
1189 if (create_mailbox) { | 1185 if (create_mailbox) { |
1190 resource_provider_->CreateMailboxAndBindResource( | 1186 resource_provider_->CreateMailboxAndBindResource( |
1191 resource_provider_->ContextGL(), resource); | 1187 resource_provider_->ContextGL(), resource); |
1192 } | 1188 } |
1193 texture_id_ = resource->gl_id; | 1189 texture_id_ = resource->gl_id; |
1194 target_ = resource->target; | 1190 target_ = resource->target; |
1195 format_ = resource->format; | 1191 format_ = resource->format; |
1196 size_ = resource->size; | 1192 size_ = resource->size; |
1197 mailbox_ = resource->mailbox(); | 1193 mailbox_ = resource->mailbox(); |
1198 sk_color_space_ = resource_provider->GetResourceSkColorSpace(resource); | 1194 color_space_ = resource_provider->GetResourceColorSpaceForRaster(resource); |
1199 } | 1195 } |
1200 | 1196 |
1201 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 1197 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
1202 DCHECK(thread_checker_.CalledOnValidThread()); | 1198 DCHECK(thread_checker_.CalledOnValidThread()); |
1203 Resource* resource = resource_provider_->GetResource(resource_id_); | 1199 Resource* resource = resource_provider_->GetResource(resource_id_); |
1204 DCHECK(resource->locked_for_write); | 1200 DCHECK(resource->locked_for_write); |
1205 // It's not sufficient to check sync_token_.HasData() here because the sync | 1201 // 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 | 1202 // 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. | 1203 // sync token because it's checked in PrepareSendToParent while drawing. |
1208 if (has_sync_token_) | 1204 if (has_sync_token_) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1256 uint32_t flags = | 1252 uint32_t flags = |
1257 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; | 1253 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; |
1258 // Use unknown pixel geometry to disable LCD text. | 1254 // Use unknown pixel geometry to disable LCD text. |
1259 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); | 1255 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
1260 if (can_use_lcd_text) { | 1256 if (can_use_lcd_text) { |
1261 // LegacyFontHost will get LCD text and skia figures out what type to use. | 1257 // LegacyFontHost will get LCD text and skia figures out what type to use. |
1262 surface_props = | 1258 surface_props = |
1263 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); | 1259 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
1264 } | 1260 } |
1265 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( | 1261 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( |
1266 context_provider->GrContext(), desc, resource_lock->sk_color_space(), | 1262 context_provider->GrContext(), desc, nullptr, &surface_props); |
1267 &surface_props); | |
1268 } | 1263 } |
1269 | 1264 |
1270 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { | 1265 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { |
1271 if (sk_surface_.get()) { | 1266 if (sk_surface_.get()) { |
1272 sk_surface_->prepareForExternalIO(); | 1267 sk_surface_->prepareForExternalIO(); |
1273 sk_surface_.reset(); | 1268 sk_surface_.reset(); |
1274 } | 1269 } |
1275 } | 1270 } |
1276 | 1271 |
1277 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 1272 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
1278 const Resource* resource) { | 1273 const Resource* resource) { |
1279 DCHECK_EQ(RGBA_8888, resource->format); | 1274 DCHECK_EQ(RGBA_8888, resource->format); |
1280 SkImageInfo info = SkImageInfo::MakeN32Premul( | 1275 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), |
1281 resource->size.width(), resource->size.height(), | 1276 resource->size.height()); |
1282 GetResourceSkColorSpace(resource)); | |
1283 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); | 1277 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); |
1284 } | 1278 } |
1285 | 1279 |
1286 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 1280 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
1287 ResourceProvider* resource_provider, | 1281 ResourceProvider* resource_provider, |
1288 ResourceId resource_id) | 1282 ResourceId resource_id) |
1289 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1283 : resource_provider_(resource_provider), resource_id_(resource_id) { |
1290 const Resource* resource = resource_provider->LockForRead(resource_id); | 1284 const Resource* resource = resource_provider->LockForRead(resource_id); |
1291 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); | 1285 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); |
1292 } | 1286 } |
(...skipping 12 matching lines...) Expand all Loading... |
1305 texture_info.fID = resource->gl_id; | 1299 texture_info.fID = resource->gl_id; |
1306 texture_info.fTarget = resource->target; | 1300 texture_info.fTarget = resource->target; |
1307 GrBackendTextureDesc desc; | 1301 GrBackendTextureDesc desc; |
1308 desc.fWidth = resource->size.width(); | 1302 desc.fWidth = resource->size.width(); |
1309 desc.fHeight = resource->size.height(); | 1303 desc.fHeight = resource->size.height(); |
1310 desc.fConfig = ToGrPixelConfig(resource->format); | 1304 desc.fConfig = ToGrPixelConfig(resource->format); |
1311 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 1305 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
1312 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); | 1306 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); |
1313 sk_image_ = SkImage::MakeFromTexture( | 1307 sk_image_ = SkImage::MakeFromTexture( |
1314 resource_provider->compositor_context_provider_->GrContext(), desc, | 1308 resource_provider->compositor_context_provider_->GrContext(), desc, |
1315 kPremul_SkAlphaType, | 1309 kPremul_SkAlphaType); |
1316 resource_provider->GetResourceSkColorSpace(resource), nullptr, nullptr); | |
1317 } else if (resource->pixels) { | 1310 } else if (resource->pixels) { |
1318 SkBitmap sk_bitmap; | 1311 SkBitmap sk_bitmap; |
1319 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap, resource); | 1312 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap, resource); |
1320 sk_bitmap.setImmutable(); | 1313 sk_bitmap.setImmutable(); |
1321 sk_image_ = SkImage::MakeFromBitmap(sk_bitmap); | 1314 sk_image_ = SkImage::MakeFromBitmap(sk_bitmap); |
1322 } else { | 1315 } else { |
1323 // During render process shutdown, ~RenderMessageFilter which calls | 1316 // During render process shutdown, ~RenderMessageFilter which calls |
1324 // ~HostSharedBitmapClient (which deletes shared bitmaps from child) | 1317 // ~HostSharedBitmapClient (which deletes shared bitmaps from child) |
1325 // can race with OnBeginFrameDeadline which draws a frame. | 1318 // can race with OnBeginFrameDeadline which draws a frame. |
1326 // In these cases, shared bitmaps (and this read lock) won't be valid. | 1319 // In these cases, shared bitmaps (and this read lock) won't be valid. |
1327 // Renderers need to silently handle locks failing until this race | 1320 // 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. | 1321 // is fixed. DCHECK that this is the only case where there are no pixels. |
1329 DCHECK(!resource->shared_bitmap_id.IsZero()); | 1322 DCHECK(!resource->shared_bitmap_id.IsZero()); |
1330 } | 1323 } |
1331 } | 1324 } |
1332 | 1325 |
1333 ResourceProvider::ScopedReadLockSkImage::~ScopedReadLockSkImage() { | 1326 ResourceProvider::ScopedReadLockSkImage::~ScopedReadLockSkImage() { |
1334 resource_provider_->UnlockForRead(resource_id_); | 1327 resource_provider_->UnlockForRead(resource_id_); |
1335 } | 1328 } |
1336 | 1329 |
1337 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( | 1330 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( |
1338 ResourceProvider* resource_provider, | 1331 ResourceProvider* resource_provider, |
1339 ResourceId resource_id) | 1332 ResourceId resource_id) |
1340 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1333 : resource_provider_(resource_provider), resource_id_(resource_id) { |
1341 Resource* resource = resource_provider->LockForWrite(resource_id); | 1334 Resource* resource = resource_provider->LockForWrite(resource_id); |
1342 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); | 1335 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); |
1343 sk_color_space_ = resource_provider->GetResourceSkColorSpace(resource); | 1336 color_space_ = resource_provider->GetResourceColorSpaceForRaster(resource); |
1344 DCHECK(valid()); | 1337 DCHECK(valid()); |
1345 } | 1338 } |
1346 | 1339 |
1347 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { | 1340 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { |
1348 DCHECK(thread_checker_.CalledOnValidThread()); | 1341 DCHECK(thread_checker_.CalledOnValidThread()); |
1349 Resource* resource = resource_provider_->GetResource(resource_id_); | 1342 Resource* resource = resource_provider_->GetResource(resource_id_); |
1350 DCHECK(resource); | 1343 DCHECK(resource); |
1351 resource->SetSynchronized(); | 1344 resource->SetSynchronized(); |
1352 resource_provider_->UnlockForWrite(resource); | 1345 resource_provider_->UnlockForWrite(resource); |
1353 } | 1346 } |
1354 | 1347 |
1355 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | 1348 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
1356 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, | 1349 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, |
1357 ResourceId resource_id) | 1350 ResourceId resource_id) |
1358 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1351 : resource_provider_(resource_provider), resource_id_(resource_id) { |
1359 Resource* resource = resource_provider->LockForWrite(resource_id); | 1352 Resource* resource = resource_provider->LockForWrite(resource_id); |
1360 DCHECK(IsGpuResourceType(resource->type)); | 1353 DCHECK(IsGpuResourceType(resource->type)); |
1361 format_ = resource->format; | 1354 format_ = resource->format; |
1362 size_ = resource->size; | 1355 size_ = resource->size; |
1363 usage_ = resource->usage; | 1356 usage_ = resource->usage; |
1364 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer); | 1357 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer); |
1365 resource->gpu_memory_buffer = nullptr; | 1358 resource->gpu_memory_buffer = nullptr; |
| 1359 color_space_ = resource_provider->GetResourceColorSpaceForRaster(resource); |
1366 } | 1360 } |
1367 | 1361 |
1368 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | 1362 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
1369 ~ScopedWriteLockGpuMemoryBuffer() { | 1363 ~ScopedWriteLockGpuMemoryBuffer() { |
1370 DCHECK(thread_checker_.CalledOnValidThread()); | 1364 DCHECK(thread_checker_.CalledOnValidThread()); |
1371 Resource* resource = resource_provider_->GetResource(resource_id_); | 1365 Resource* resource = resource_provider_->GetResource(resource_id_); |
1372 DCHECK(resource); | 1366 DCHECK(resource); |
1373 if (gpu_memory_buffer_) { | 1367 if (gpu_memory_buffer_) { |
1374 // Note that this impacts overlay compositing, not rasterization. | 1368 // Note that this impacts overlay compositing, not rasterization. |
1375 if (resource_provider_->settings_.enable_color_correct_rasterization) | 1369 if (resource_provider_->settings_.enable_color_correct_rasterization) |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2187 | 2181 |
2188 const int kImportance = 2; | 2182 const int kImportance = 2; |
2189 pmd->CreateSharedGlobalAllocatorDump(guid); | 2183 pmd->CreateSharedGlobalAllocatorDump(guid); |
2190 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2184 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
2191 } | 2185 } |
2192 | 2186 |
2193 return true; | 2187 return true; |
2194 } | 2188 } |
2195 | 2189 |
2196 } // namespace cc | 2190 } // namespace cc |
OLD | NEW |