| 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 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 // Software resources are immutable; they cannot change format or be | 837 // Software resources are immutable; they cannot change format or be |
| 838 // resized. | 838 // resized. |
| 839 return true; | 839 return true; |
| 840 } | 840 } |
| 841 } | 841 } |
| 842 | 842 |
| 843 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) { | 843 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) { |
| 844 return GetResource(id)->hint; | 844 return GetResource(id)->hint; |
| 845 } | 845 } |
| 846 | 846 |
| 847 sk_sp<SkColorSpace> ResourceProvider::GetResourceSkColorSpace( | 847 gfx::ColorSpace ResourceProvider::GetResourceColorSpaceForRaster( |
| 848 const Resource* resource) const { | 848 const Resource* resource) const { |
| 849 if (!settings_.enable_color_correct_rasterization) | 849 if (!settings_.enable_color_correct_rasterization) |
| 850 return nullptr; | 850 return gfx::ColorSpace(); |
| 851 // Returning the nonlinear blended color space matches the expectation of the | 851 return resource->color_space; |
| 852 // web that colors are blended in the output color space, not in a | |
| 853 // physically-based linear space. | |
| 854 return resource->color_space.ToNonlinearBlendedSkColorSpace(); | |
| 855 } | 852 } |
| 856 | 853 |
| 857 void ResourceProvider::CopyToResource(ResourceId id, | 854 void ResourceProvider::CopyToResource(ResourceId id, |
| 858 const uint8_t* image, | 855 const uint8_t* image, |
| 859 const gfx::Size& image_size) { | 856 const gfx::Size& image_size) { |
| 860 Resource* resource = GetResource(id); | 857 Resource* resource = GetResource(id); |
| 861 DCHECK(!resource->locked_for_write); | 858 DCHECK(!resource->locked_for_write); |
| 862 DCHECK(!resource->lock_for_read_count); | 859 DCHECK(!resource->lock_for_read_count); |
| 863 DCHECK(resource->origin == Resource::INTERNAL); | 860 DCHECK(resource->origin == Resource::INTERNAL); |
| 864 DCHECK_EQ(resource->exported_count, 0); | 861 DCHECK_EQ(resource->exported_count, 0); |
| 865 DCHECK(ReadLockFenceHasPassed(resource)); | 862 DCHECK(ReadLockFenceHasPassed(resource)); |
| 866 | 863 |
| 867 DCHECK_EQ(image_size.width(), resource->size.width()); | 864 DCHECK_EQ(image_size.width(), resource->size.width()); |
| 868 DCHECK_EQ(image_size.height(), resource->size.height()); | 865 DCHECK_EQ(image_size.height(), resource->size.height()); |
| 869 | 866 |
| 870 if (resource->allocated) | 867 if (resource->allocated) |
| 871 WaitSyncTokenIfNeeded(id); | 868 WaitSyncTokenIfNeeded(id); |
| 872 | 869 |
| 873 if (resource->type == RESOURCE_TYPE_BITMAP) { | 870 if (resource->type == RESOURCE_TYPE_BITMAP) { |
| 874 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); | 871 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); |
| 875 DCHECK(resource->allocated); | 872 DCHECK(resource->allocated); |
| 876 DCHECK_EQ(RGBA_8888, resource->format); | 873 DCHECK_EQ(RGBA_8888, resource->format); |
| 877 SkImageInfo source_info = | 874 SkImageInfo source_info = |
| 878 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height(), | 875 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); |
| 879 GetResourceSkColorSpace(resource)); | |
| 880 size_t image_stride = image_size.width() * 4; | 876 size_t image_stride = image_size.width() * 4; |
| 881 | 877 |
| 882 ScopedWriteLockSoftware lock(this, id); | 878 ScopedWriteLockSoftware lock(this, id); |
| 883 SkCanvas dest(lock.sk_bitmap()); | 879 SkCanvas dest(lock.sk_bitmap()); |
| 884 dest.writePixels(source_info, image, image_stride, 0, 0); | 880 dest.writePixels(source_info, image, image_stride, 0, 0); |
| 885 } else { | 881 } else { |
| 886 ScopedWriteLockGL lock(this, id, false); | 882 ScopedWriteLockGL lock(this, id, false); |
| 887 unsigned resource_texture_id = lock.texture_id(); | 883 unsigned resource_texture_id = lock.texture_id(); |
| 888 DCHECK(resource_texture_id); | 884 DCHECK(resource_texture_id); |
| 889 GLES2Interface* gl = ContextGL(); | 885 GLES2Interface* gl = ContextGL(); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 resource_provider_->BindImageForSampling(resource); | 1145 resource_provider_->BindImageForSampling(resource); |
| 1150 if (create_mailbox) { | 1146 if (create_mailbox) { |
| 1151 resource_provider_->CreateMailboxAndBindResource( | 1147 resource_provider_->CreateMailboxAndBindResource( |
| 1152 resource_provider_->ContextGL(), resource); | 1148 resource_provider_->ContextGL(), resource); |
| 1153 } | 1149 } |
| 1154 texture_id_ = resource->gl_id; | 1150 texture_id_ = resource->gl_id; |
| 1155 target_ = resource->target; | 1151 target_ = resource->target; |
| 1156 format_ = resource->format; | 1152 format_ = resource->format; |
| 1157 size_ = resource->size; | 1153 size_ = resource->size; |
| 1158 mailbox_ = resource->mailbox(); | 1154 mailbox_ = resource->mailbox(); |
| 1159 sk_color_space_ = resource_provider->GetResourceSkColorSpace(resource); | 1155 color_space_ = resource_provider->GetResourceColorSpaceForRaster(resource); |
| 1160 } | 1156 } |
| 1161 | 1157 |
| 1162 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 1158 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
| 1163 DCHECK(thread_checker_.CalledOnValidThread()); | 1159 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1164 Resource* resource = resource_provider_->GetResource(resource_id_); | 1160 Resource* resource = resource_provider_->GetResource(resource_id_); |
| 1165 DCHECK(resource->locked_for_write); | 1161 DCHECK(resource->locked_for_write); |
| 1166 // It's not sufficient to check sync_token_.HasData() here because the sync | 1162 // It's not sufficient to check sync_token_.HasData() here because the sync |
| 1167 // might be null because of context loss. Even in that case we want to set the | 1163 // might be null because of context loss. Even in that case we want to set the |
| 1168 // sync token because it's checked in PrepareSendToParent while drawing. | 1164 // sync token because it's checked in PrepareSendToParent while drawing. |
| 1169 if (has_sync_token_) | 1165 if (has_sync_token_) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1217 uint32_t flags = | 1213 uint32_t flags = |
| 1218 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; | 1214 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; |
| 1219 // Use unknown pixel geometry to disable LCD text. | 1215 // Use unknown pixel geometry to disable LCD text. |
| 1220 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); | 1216 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
| 1221 if (can_use_lcd_text) { | 1217 if (can_use_lcd_text) { |
| 1222 // LegacyFontHost will get LCD text and skia figures out what type to use. | 1218 // LegacyFontHost will get LCD text and skia figures out what type to use. |
| 1223 surface_props = | 1219 surface_props = |
| 1224 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); | 1220 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 1225 } | 1221 } |
| 1226 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( | 1222 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( |
| 1227 context_provider->GrContext(), desc, resource_lock->sk_color_space(), | 1223 context_provider->GrContext(), desc, nullptr, &surface_props); |
| 1228 &surface_props); | |
| 1229 } | 1224 } |
| 1230 | 1225 |
| 1231 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { | 1226 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { |
| 1232 if (sk_surface_.get()) { | 1227 if (sk_surface_.get()) { |
| 1233 sk_surface_->prepareForExternalIO(); | 1228 sk_surface_->prepareForExternalIO(); |
| 1234 sk_surface_.reset(); | 1229 sk_surface_.reset(); |
| 1235 } | 1230 } |
| 1236 } | 1231 } |
| 1237 | 1232 |
| 1238 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 1233 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
| 1239 const Resource* resource) { | 1234 const Resource* resource) { |
| 1240 DCHECK_EQ(RGBA_8888, resource->format); | 1235 DCHECK_EQ(RGBA_8888, resource->format); |
| 1241 SkImageInfo info = SkImageInfo::MakeN32Premul( | 1236 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), |
| 1242 resource->size.width(), resource->size.height(), | 1237 resource->size.height()); |
| 1243 GetResourceSkColorSpace(resource)); | |
| 1244 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); | 1238 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); |
| 1245 } | 1239 } |
| 1246 | 1240 |
| 1247 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 1241 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
| 1248 ResourceProvider* resource_provider, | 1242 ResourceProvider* resource_provider, |
| 1249 ResourceId resource_id) | 1243 ResourceId resource_id) |
| 1250 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1244 : resource_provider_(resource_provider), resource_id_(resource_id) { |
| 1251 const Resource* resource = resource_provider->LockForRead(resource_id); | 1245 const Resource* resource = resource_provider->LockForRead(resource_id); |
| 1252 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); | 1246 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); |
| 1253 } | 1247 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1266 texture_info.fID = resource->gl_id; | 1260 texture_info.fID = resource->gl_id; |
| 1267 texture_info.fTarget = resource->target; | 1261 texture_info.fTarget = resource->target; |
| 1268 GrBackendTextureDesc desc; | 1262 GrBackendTextureDesc desc; |
| 1269 desc.fWidth = resource->size.width(); | 1263 desc.fWidth = resource->size.width(); |
| 1270 desc.fHeight = resource->size.height(); | 1264 desc.fHeight = resource->size.height(); |
| 1271 desc.fConfig = ToGrPixelConfig(resource->format); | 1265 desc.fConfig = ToGrPixelConfig(resource->format); |
| 1272 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 1266 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 1273 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); | 1267 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); |
| 1274 sk_image_ = SkImage::MakeFromTexture( | 1268 sk_image_ = SkImage::MakeFromTexture( |
| 1275 resource_provider->compositor_context_provider_->GrContext(), desc, | 1269 resource_provider->compositor_context_provider_->GrContext(), desc, |
| 1276 kPremul_SkAlphaType, | 1270 kPremul_SkAlphaType); |
| 1277 resource_provider->GetResourceSkColorSpace(resource), nullptr, nullptr); | |
| 1278 } else if (resource->pixels) { | 1271 } else if (resource->pixels) { |
| 1279 SkBitmap sk_bitmap; | 1272 SkBitmap sk_bitmap; |
| 1280 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap, resource); | 1273 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap, resource); |
| 1281 sk_bitmap.setImmutable(); | 1274 sk_bitmap.setImmutable(); |
| 1282 sk_image_ = SkImage::MakeFromBitmap(sk_bitmap); | 1275 sk_image_ = SkImage::MakeFromBitmap(sk_bitmap); |
| 1283 } else { | 1276 } else { |
| 1284 // During render process shutdown, ~RenderMessageFilter which calls | 1277 // During render process shutdown, ~RenderMessageFilter which calls |
| 1285 // ~HostSharedBitmapClient (which deletes shared bitmaps from child) | 1278 // ~HostSharedBitmapClient (which deletes shared bitmaps from child) |
| 1286 // can race with OnBeginFrameDeadline which draws a frame. | 1279 // can race with OnBeginFrameDeadline which draws a frame. |
| 1287 // In these cases, shared bitmaps (and this read lock) won't be valid. | 1280 // In these cases, shared bitmaps (and this read lock) won't be valid. |
| 1288 // Renderers need to silently handle locks failing until this race | 1281 // Renderers need to silently handle locks failing until this race |
| 1289 // is fixed. DCHECK that this is the only case where there are no pixels. | 1282 // is fixed. DCHECK that this is the only case where there are no pixels. |
| 1290 DCHECK(!resource->shared_bitmap_id.IsZero()); | 1283 DCHECK(!resource->shared_bitmap_id.IsZero()); |
| 1291 } | 1284 } |
| 1292 } | 1285 } |
| 1293 | 1286 |
| 1294 ResourceProvider::ScopedReadLockSkImage::~ScopedReadLockSkImage() { | 1287 ResourceProvider::ScopedReadLockSkImage::~ScopedReadLockSkImage() { |
| 1295 resource_provider_->UnlockForRead(resource_id_); | 1288 resource_provider_->UnlockForRead(resource_id_); |
| 1296 } | 1289 } |
| 1297 | 1290 |
| 1298 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( | 1291 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( |
| 1299 ResourceProvider* resource_provider, | 1292 ResourceProvider* resource_provider, |
| 1300 ResourceId resource_id) | 1293 ResourceId resource_id) |
| 1301 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1294 : resource_provider_(resource_provider), resource_id_(resource_id) { |
| 1302 Resource* resource = resource_provider->LockForWrite(resource_id); | 1295 Resource* resource = resource_provider->LockForWrite(resource_id); |
| 1303 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); | 1296 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); |
| 1304 sk_color_space_ = resource_provider->GetResourceSkColorSpace(resource); | 1297 color_space_ = resource_provider->GetResourceColorSpaceForRaster(resource); |
| 1305 DCHECK(valid()); | 1298 DCHECK(valid()); |
| 1306 } | 1299 } |
| 1307 | 1300 |
| 1308 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { | 1301 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { |
| 1309 DCHECK(thread_checker_.CalledOnValidThread()); | 1302 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1310 Resource* resource = resource_provider_->GetResource(resource_id_); | 1303 Resource* resource = resource_provider_->GetResource(resource_id_); |
| 1311 DCHECK(resource); | 1304 DCHECK(resource); |
| 1312 resource->SetSynchronized(); | 1305 resource->SetSynchronized(); |
| 1313 resource_provider_->UnlockForWrite(resource); | 1306 resource_provider_->UnlockForWrite(resource); |
| 1314 } | 1307 } |
| 1315 | 1308 |
| 1316 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | 1309 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
| 1317 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, | 1310 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, |
| 1318 ResourceId resource_id) | 1311 ResourceId resource_id) |
| 1319 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1312 : resource_provider_(resource_provider), resource_id_(resource_id) { |
| 1320 Resource* resource = resource_provider->LockForWrite(resource_id); | 1313 Resource* resource = resource_provider->LockForWrite(resource_id); |
| 1321 DCHECK(IsGpuResourceType(resource->type)); | 1314 DCHECK(IsGpuResourceType(resource->type)); |
| 1322 format_ = resource->format; | 1315 format_ = resource->format; |
| 1323 size_ = resource->size; | 1316 size_ = resource->size; |
| 1324 usage_ = resource->usage; | 1317 usage_ = resource->usage; |
| 1325 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer); | 1318 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer); |
| 1326 resource->gpu_memory_buffer = nullptr; | 1319 resource->gpu_memory_buffer = nullptr; |
| 1320 color_space_ = resource_provider->GetResourceColorSpaceForRaster(resource); |
| 1327 } | 1321 } |
| 1328 | 1322 |
| 1329 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | 1323 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
| 1330 ~ScopedWriteLockGpuMemoryBuffer() { | 1324 ~ScopedWriteLockGpuMemoryBuffer() { |
| 1331 DCHECK(thread_checker_.CalledOnValidThread()); | 1325 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1332 Resource* resource = resource_provider_->GetResource(resource_id_); | 1326 Resource* resource = resource_provider_->GetResource(resource_id_); |
| 1333 DCHECK(resource); | 1327 DCHECK(resource); |
| 1334 if (gpu_memory_buffer_) { | 1328 if (gpu_memory_buffer_) { |
| 1335 // Note that this impacts overlay compositing, not rasterization. | 1329 // Note that this impacts overlay compositing, not rasterization. |
| 1336 if (resource_provider_->settings_.enable_color_correct_rasterization) | 1330 if (resource_provider_->settings_.enable_color_correct_rasterization) |
| (...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2148 | 2142 |
| 2149 const int kImportance = 2; | 2143 const int kImportance = 2; |
| 2150 pmd->CreateSharedGlobalAllocatorDump(guid); | 2144 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 2151 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2145 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 2152 } | 2146 } |
| 2153 | 2147 |
| 2154 return true; | 2148 return true; |
| 2155 } | 2149 } |
| 2156 | 2150 |
| 2157 } // namespace cc | 2151 } // namespace cc |
| OLD | NEW |