| 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 23 matching lines...) Expand all Loading... |
| 34 #include "skia/ext/texture_handle.h" | 34 #include "skia/ext/texture_handle.h" |
| 35 #include "third_party/khronos/GLES2/gl2.h" | 35 #include "third_party/khronos/GLES2/gl2.h" |
| 36 #include "third_party/khronos/GLES2/gl2ext.h" | 36 #include "third_party/khronos/GLES2/gl2ext.h" |
| 37 #include "third_party/skia/include/core/SkCanvas.h" | 37 #include "third_party/skia/include/core/SkCanvas.h" |
| 38 #include "third_party/skia/include/core/SkSurface.h" | 38 #include "third_party/skia/include/core/SkSurface.h" |
| 39 #include "third_party/skia/include/gpu/GrContext.h" | 39 #include "third_party/skia/include/gpu/GrContext.h" |
| 40 #include "third_party/skia/include/gpu/GrTextureProvider.h" | 40 #include "third_party/skia/include/gpu/GrTextureProvider.h" |
| 41 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" | 41 #include "third_party/skia/include/gpu/gl/GrGLTypes.h" |
| 42 #include "ui/gfx/geometry/rect.h" | 42 #include "ui/gfx/geometry/rect.h" |
| 43 #include "ui/gfx/geometry/vector2d.h" | 43 #include "ui/gfx/geometry/vector2d.h" |
| 44 #include "ui/gfx/icc_profile.h" |
| 44 #include "ui/gl/trace_util.h" | 45 #include "ui/gl/trace_util.h" |
| 45 | 46 |
| 46 using gpu::gles2::GLES2Interface; | 47 using gpu::gles2::GLES2Interface; |
| 47 | 48 |
| 48 namespace cc { | 49 namespace cc { |
| 49 | 50 |
| 50 class IdAllocator { | 51 class IdAllocator { |
| 51 public: | 52 public: |
| 52 virtual ~IdAllocator() {} | 53 virtual ~IdAllocator() {} |
| 53 | 54 |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 | 385 |
| 385 ResourceProvider::ResourceProvider( | 386 ResourceProvider::ResourceProvider( |
| 386 ContextProvider* compositor_context_provider, | 387 ContextProvider* compositor_context_provider, |
| 387 SharedBitmapManager* shared_bitmap_manager, | 388 SharedBitmapManager* shared_bitmap_manager, |
| 388 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 389 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 389 BlockingTaskRunner* blocking_main_thread_task_runner, | 390 BlockingTaskRunner* blocking_main_thread_task_runner, |
| 390 int highp_threshold_min, | 391 int highp_threshold_min, |
| 391 size_t id_allocation_chunk_size, | 392 size_t id_allocation_chunk_size, |
| 392 bool delegated_sync_points_required, | 393 bool delegated_sync_points_required, |
| 393 bool use_gpu_memory_buffer_resources, | 394 bool use_gpu_memory_buffer_resources, |
| 395 bool enable_color_correct_rendering, |
| 394 const BufferToTextureTargetMap& buffer_to_texture_target_map) | 396 const BufferToTextureTargetMap& buffer_to_texture_target_map) |
| 395 : compositor_context_provider_(compositor_context_provider), | 397 : compositor_context_provider_(compositor_context_provider), |
| 396 shared_bitmap_manager_(shared_bitmap_manager), | 398 shared_bitmap_manager_(shared_bitmap_manager), |
| 397 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | 399 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
| 398 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), | 400 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), |
| 399 lost_output_surface_(false), | 401 lost_output_surface_(false), |
| 400 highp_threshold_min_(highp_threshold_min), | 402 highp_threshold_min_(highp_threshold_min), |
| 401 next_id_(1), | 403 next_id_(1), |
| 402 next_child_(1), | 404 next_child_(1), |
| 403 delegated_sync_points_required_(delegated_sync_points_required), | 405 delegated_sync_points_required_(delegated_sync_points_required), |
| 404 default_resource_type_(use_gpu_memory_buffer_resources | 406 default_resource_type_(use_gpu_memory_buffer_resources |
| 405 ? RESOURCE_TYPE_GPU_MEMORY_BUFFER | 407 ? RESOURCE_TYPE_GPU_MEMORY_BUFFER |
| 406 : RESOURCE_TYPE_GL_TEXTURE), | 408 : RESOURCE_TYPE_GL_TEXTURE), |
| 407 use_texture_storage_ext_(false), | 409 use_texture_storage_ext_(false), |
| 408 use_texture_format_bgra_(false), | 410 use_texture_format_bgra_(false), |
| 409 use_texture_usage_hint_(false), | 411 use_texture_usage_hint_(false), |
| 410 use_compressed_texture_etc1_(false), | 412 use_compressed_texture_etc1_(false), |
| 411 yuv_resource_format_(LUMINANCE_8), | 413 yuv_resource_format_(LUMINANCE_8), |
| 412 max_texture_size_(0), | 414 max_texture_size_(0), |
| 413 best_texture_format_(RGBA_8888), | 415 best_texture_format_(RGBA_8888), |
| 414 best_render_buffer_format_(RGBA_8888), | 416 best_render_buffer_format_(RGBA_8888), |
| 417 enable_color_correct_rendering_(enable_color_correct_rendering), |
| 415 id_allocation_chunk_size_(id_allocation_chunk_size), | 418 id_allocation_chunk_size_(id_allocation_chunk_size), |
| 416 use_sync_query_(false), | 419 use_sync_query_(false), |
| 417 buffer_to_texture_target_map_(buffer_to_texture_target_map), | 420 buffer_to_texture_target_map_(buffer_to_texture_target_map), |
| 418 tracing_id_(g_next_resource_provider_tracing_id.GetNext()) { | 421 tracing_id_(g_next_resource_provider_tracing_id.GetNext()) { |
| 419 DCHECK(id_allocation_chunk_size_); | 422 DCHECK(id_allocation_chunk_size_); |
| 420 DCHECK(thread_checker_.CalledOnValidThread()); | 423 DCHECK(thread_checker_.CalledOnValidThread()); |
| 421 | 424 |
| 422 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). | 425 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
| 423 // Don't register a dump provider in these cases. | 426 // Don't register a dump provider in these cases. |
| 424 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 | 427 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 } | 816 } |
| 814 | 817 |
| 815 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) { | 818 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) { |
| 816 return GetResource(id)->target; | 819 return GetResource(id)->target; |
| 817 } | 820 } |
| 818 | 821 |
| 819 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) { | 822 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) { |
| 820 return GetResource(id)->hint; | 823 return GetResource(id)->hint; |
| 821 } | 824 } |
| 822 | 825 |
| 823 static sk_sp<SkColorSpace> ColorSpaceToSkColorSpace( | 826 sk_sp<SkColorSpace> ResourceProvider::GetResourceSkColorSpace( |
| 824 const gfx::ColorSpace& color_space) { | 827 const Resource* resource) const { |
| 825 // TODO(crbug.com/634102): Implement conversion for skia-based compositing to | 828 // TODO(crbug.com/634102): Implement conversion for skia-based compositing to |
| 826 // be color-managed | 829 // be color-managed |
| 827 return nullptr; | 830 return nullptr; |
| 828 } | 831 } |
| 829 | 832 |
| 830 void ResourceProvider::CopyToResource(ResourceId id, | 833 void ResourceProvider::CopyToResource(ResourceId id, |
| 831 const uint8_t* image, | 834 const uint8_t* image, |
| 832 const gfx::Size& image_size) { | 835 const gfx::Size& image_size) { |
| 833 Resource* resource = GetResource(id); | 836 Resource* resource = GetResource(id); |
| 834 DCHECK(!resource->locked_for_write); | 837 DCHECK(!resource->locked_for_write); |
| 835 DCHECK(!resource->lock_for_read_count); | 838 DCHECK(!resource->lock_for_read_count); |
| 836 DCHECK(resource->origin == Resource::INTERNAL); | 839 DCHECK(resource->origin == Resource::INTERNAL); |
| 837 DCHECK_EQ(resource->exported_count, 0); | 840 DCHECK_EQ(resource->exported_count, 0); |
| 838 DCHECK(ReadLockFenceHasPassed(resource)); | 841 DCHECK(ReadLockFenceHasPassed(resource)); |
| 839 | 842 |
| 840 DCHECK_EQ(image_size.width(), resource->size.width()); | 843 DCHECK_EQ(image_size.width(), resource->size.width()); |
| 841 DCHECK_EQ(image_size.height(), resource->size.height()); | 844 DCHECK_EQ(image_size.height(), resource->size.height()); |
| 842 | 845 |
| 843 if (resource->allocated) | 846 if (resource->allocated) |
| 844 WaitSyncTokenIfNeeded(id); | 847 WaitSyncTokenIfNeeded(id); |
| 845 | 848 |
| 846 if (resource->type == RESOURCE_TYPE_BITMAP) { | 849 if (resource->type == RESOURCE_TYPE_BITMAP) { |
| 847 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); | 850 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); |
| 848 DCHECK(resource->allocated); | 851 DCHECK(resource->allocated); |
| 849 DCHECK_EQ(RGBA_8888, resource->format); | 852 DCHECK_EQ(RGBA_8888, resource->format); |
| 850 SkImageInfo source_info = SkImageInfo::MakeN32Premul( | 853 SkImageInfo source_info = |
| 851 image_size.width(), image_size.height(), | 854 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height(), |
| 852 ColorSpaceToSkColorSpace(resource->color_space)); | 855 GetResourceSkColorSpace(resource)); |
| 853 size_t image_stride = image_size.width() * 4; | 856 size_t image_stride = image_size.width() * 4; |
| 854 | 857 |
| 855 ScopedWriteLockSoftware lock(this, id); | 858 ScopedWriteLockSoftware lock(this, id); |
| 856 SkCanvas dest(lock.sk_bitmap()); | 859 SkCanvas dest(lock.sk_bitmap()); |
| 857 dest.writePixels(source_info, image, image_stride, 0, 0); | 860 dest.writePixels(source_info, image, image_stride, 0, 0); |
| 858 } else { | 861 } else { |
| 859 ScopedWriteLockGL lock(this, id, false); | 862 ScopedWriteLockGL lock(this, id, false); |
| 860 unsigned resource_texture_id = lock.texture_id(); | 863 unsigned resource_texture_id = lock.texture_id(); |
| 861 DCHECK(resource_texture_id); | 864 DCHECK(resource_texture_id); |
| 862 GLES2Interface* gl = ContextGL(); | 865 GLES2Interface* gl = ContextGL(); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 resource_provider_->BindImageForSampling(resource); | 1093 resource_provider_->BindImageForSampling(resource); |
| 1091 if (create_mailbox) { | 1094 if (create_mailbox) { |
| 1092 resource_provider_->CreateMailboxAndBindResource( | 1095 resource_provider_->CreateMailboxAndBindResource( |
| 1093 resource_provider_->ContextGL(), resource); | 1096 resource_provider_->ContextGL(), resource); |
| 1094 } | 1097 } |
| 1095 texture_id_ = resource->gl_id; | 1098 texture_id_ = resource->gl_id; |
| 1096 target_ = resource->target; | 1099 target_ = resource->target; |
| 1097 format_ = resource->format; | 1100 format_ = resource->format; |
| 1098 size_ = resource->size; | 1101 size_ = resource->size; |
| 1099 mailbox_ = resource->mailbox(); | 1102 mailbox_ = resource->mailbox(); |
| 1103 sk_color_space_ = resource_provider->GetResourceSkColorSpace(resource); |
| 1100 } | 1104 } |
| 1101 | 1105 |
| 1102 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 1106 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
| 1103 DCHECK(thread_checker_.CalledOnValidThread()); | 1107 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1104 Resource* resource = resource_provider_->GetResource(resource_id_); | 1108 Resource* resource = resource_provider_->GetResource(resource_id_); |
| 1105 DCHECK(resource->locked_for_write); | 1109 DCHECK(resource->locked_for_write); |
| 1106 if (sync_token_.HasData()) | 1110 if (sync_token_.HasData()) |
| 1107 resource->UpdateSyncToken(sync_token_); | 1111 resource->UpdateSyncToken(sync_token_); |
| 1108 if (synchronized_) | 1112 if (synchronized_) |
| 1109 resource->SetSynchronized(); | 1113 resource->SetSynchronized(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 uint32_t flags = | 1158 uint32_t flags = |
| 1155 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; | 1159 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; |
| 1156 // Use unknown pixel geometry to disable LCD text. | 1160 // Use unknown pixel geometry to disable LCD text. |
| 1157 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); | 1161 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
| 1158 if (can_use_lcd_text) { | 1162 if (can_use_lcd_text) { |
| 1159 // LegacyFontHost will get LCD text and skia figures out what type to use. | 1163 // LegacyFontHost will get LCD text and skia figures out what type to use. |
| 1160 surface_props = | 1164 surface_props = |
| 1161 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); | 1165 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 1162 } | 1166 } |
| 1163 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( | 1167 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( |
| 1164 context_provider->GrContext(), desc, &surface_props); | 1168 context_provider->GrContext(), desc, resource_lock->sk_color_space(), |
| 1169 &surface_props); |
| 1165 } | 1170 } |
| 1166 | 1171 |
| 1167 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { | 1172 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { |
| 1168 if (sk_surface_.get()) { | 1173 if (sk_surface_.get()) { |
| 1169 sk_surface_->prepareForExternalIO(); | 1174 sk_surface_->prepareForExternalIO(); |
| 1170 sk_surface_.reset(); | 1175 sk_surface_.reset(); |
| 1171 } | 1176 } |
| 1172 } | 1177 } |
| 1173 | 1178 |
| 1174 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 1179 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
| 1175 const Resource* resource) { | 1180 const Resource* resource) { |
| 1176 DCHECK_EQ(RGBA_8888, resource->format); | 1181 DCHECK_EQ(RGBA_8888, resource->format); |
| 1177 SkImageInfo info = SkImageInfo::MakeN32Premul( | 1182 SkImageInfo info = SkImageInfo::MakeN32Premul( |
| 1178 resource->size.width(), resource->size.height(), | 1183 resource->size.width(), resource->size.height(), |
| 1179 ColorSpaceToSkColorSpace(resource->color_space)); | 1184 GetResourceSkColorSpace(resource)); |
| 1180 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); | 1185 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); |
| 1181 } | 1186 } |
| 1182 | 1187 |
| 1183 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 1188 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
| 1184 ResourceProvider* resource_provider, | 1189 ResourceProvider* resource_provider, |
| 1185 ResourceId resource_id) | 1190 ResourceId resource_id) |
| 1186 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1191 : resource_provider_(resource_provider), resource_id_(resource_id) { |
| 1187 const Resource* resource = resource_provider->LockForRead(resource_id); | 1192 const Resource* resource = resource_provider->LockForRead(resource_id); |
| 1188 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); | 1193 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); |
| 1189 } | 1194 } |
| 1190 | 1195 |
| 1191 ResourceProvider::ScopedReadLockSoftware::~ScopedReadLockSoftware() { | 1196 ResourceProvider::ScopedReadLockSoftware::~ScopedReadLockSoftware() { |
| 1192 resource_provider_->UnlockForRead(resource_id_); | 1197 resource_provider_->UnlockForRead(resource_id_); |
| 1193 } | 1198 } |
| 1194 | 1199 |
| 1195 ResourceProvider::ScopedReadLockSkImage::ScopedReadLockSkImage( | 1200 ResourceProvider::ScopedReadLockSkImage::ScopedReadLockSkImage( |
| 1196 ResourceProvider* resource_provider, | 1201 ResourceProvider* resource_provider, |
| 1197 ResourceId resource_id) | 1202 ResourceId resource_id) |
| 1198 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1203 : resource_provider_(resource_provider), resource_id_(resource_id) { |
| 1199 const Resource* resource = resource_provider->LockForRead(resource_id); | 1204 const Resource* resource = resource_provider->LockForRead(resource_id); |
| 1200 if (resource->gl_id) { | 1205 if (resource->gl_id) { |
| 1201 GrGLTextureInfo texture_info; | 1206 GrGLTextureInfo texture_info; |
| 1202 texture_info.fID = resource->gl_id; | 1207 texture_info.fID = resource->gl_id; |
| 1203 texture_info.fTarget = resource->target; | 1208 texture_info.fTarget = resource->target; |
| 1204 GrBackendTextureDesc desc; | 1209 GrBackendTextureDesc desc; |
| 1205 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 1210 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 1206 desc.fWidth = resource->size.width(); | 1211 desc.fWidth = resource->size.width(); |
| 1207 desc.fHeight = resource->size.height(); | 1212 desc.fHeight = resource->size.height(); |
| 1208 desc.fConfig = ToGrPixelConfig(resource->format); | 1213 desc.fConfig = ToGrPixelConfig(resource->format); |
| 1209 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 1214 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 1210 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); | 1215 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); |
| 1211 sk_image_ = SkImage::MakeFromTexture( | 1216 sk_image_ = SkImage::MakeFromTexture( |
| 1212 resource_provider->compositor_context_provider_->GrContext(), desc, | 1217 resource_provider->compositor_context_provider_->GrContext(), desc, |
| 1213 kPremul_SkAlphaType, ColorSpaceToSkColorSpace(resource->color_space), | 1218 kPremul_SkAlphaType, |
| 1214 nullptr, nullptr); | 1219 resource_provider->GetResourceSkColorSpace(resource), nullptr, nullptr); |
| 1215 } else if (resource->pixels) { | 1220 } else if (resource->pixels) { |
| 1216 SkBitmap sk_bitmap; | 1221 SkBitmap sk_bitmap; |
| 1217 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap, resource); | 1222 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap, resource); |
| 1218 sk_bitmap.setImmutable(); | 1223 sk_bitmap.setImmutable(); |
| 1219 sk_image_ = SkImage::MakeFromBitmap(sk_bitmap); | 1224 sk_image_ = SkImage::MakeFromBitmap(sk_bitmap); |
| 1220 } else { | 1225 } else { |
| 1221 // During render process shutdown, ~RenderMessageFilter which calls | 1226 // During render process shutdown, ~RenderMessageFilter which calls |
| 1222 // ~HostSharedBitmapClient (which deletes shared bitmaps from child) | 1227 // ~HostSharedBitmapClient (which deletes shared bitmaps from child) |
| 1223 // can race with OnBeginFrameDeadline which draws a frame. | 1228 // can race with OnBeginFrameDeadline which draws a frame. |
| 1224 // In these cases, shared bitmaps (and this read lock) won't be valid. | 1229 // In these cases, shared bitmaps (and this read lock) won't be valid. |
| 1225 // Renderers need to silently handle locks failing until this race | 1230 // Renderers need to silently handle locks failing until this race |
| 1226 // is fixed. DCHECK that this is the only case where there are no pixels. | 1231 // is fixed. DCHECK that this is the only case where there are no pixels. |
| 1227 DCHECK(!resource->shared_bitmap_id.IsZero()); | 1232 DCHECK(!resource->shared_bitmap_id.IsZero()); |
| 1228 } | 1233 } |
| 1229 } | 1234 } |
| 1230 | 1235 |
| 1231 ResourceProvider::ScopedReadLockSkImage::~ScopedReadLockSkImage() { | 1236 ResourceProvider::ScopedReadLockSkImage::~ScopedReadLockSkImage() { |
| 1232 resource_provider_->UnlockForRead(resource_id_); | 1237 resource_provider_->UnlockForRead(resource_id_); |
| 1233 } | 1238 } |
| 1234 | 1239 |
| 1235 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( | 1240 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( |
| 1236 ResourceProvider* resource_provider, | 1241 ResourceProvider* resource_provider, |
| 1237 ResourceId resource_id) | 1242 ResourceId resource_id) |
| 1238 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1243 : resource_provider_(resource_provider), resource_id_(resource_id) { |
| 1239 ResourceProvider::PopulateSkBitmapWithResource( | 1244 resource_provider->PopulateSkBitmapWithResource( |
| 1240 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); | 1245 &sk_bitmap_, resource_provider->LockForWrite(resource_id)); |
| 1241 DCHECK(valid()); | 1246 DCHECK(valid()); |
| 1242 } | 1247 } |
| 1243 | 1248 |
| 1244 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { | 1249 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { |
| 1245 DCHECK(thread_checker_.CalledOnValidThread()); | 1250 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1246 Resource* resource = resource_provider_->GetResource(resource_id_); | 1251 Resource* resource = resource_provider_->GetResource(resource_id_); |
| 1247 DCHECK(resource); | 1252 DCHECK(resource); |
| 1248 resource->SetSynchronized(); | 1253 resource->SetSynchronized(); |
| 1249 resource_provider_->UnlockForWrite(resource); | 1254 resource_provider_->UnlockForWrite(resource); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1261 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer); | 1266 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer); |
| 1262 resource->gpu_memory_buffer = nullptr; | 1267 resource->gpu_memory_buffer = nullptr; |
| 1263 } | 1268 } |
| 1264 | 1269 |
| 1265 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | 1270 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
| 1266 ~ScopedWriteLockGpuMemoryBuffer() { | 1271 ~ScopedWriteLockGpuMemoryBuffer() { |
| 1267 DCHECK(thread_checker_.CalledOnValidThread()); | 1272 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1268 Resource* resource = resource_provider_->GetResource(resource_id_); | 1273 Resource* resource = resource_provider_->GetResource(resource_id_); |
| 1269 DCHECK(resource); | 1274 DCHECK(resource); |
| 1270 if (gpu_memory_buffer_) { | 1275 if (gpu_memory_buffer_) { |
| 1276 if (resource_provider_->enable_color_correct_rendering_) |
| 1277 gpu_memory_buffer_->SetColorSpaceForScanout(resource->color_space); |
| 1271 DCHECK(!resource->gpu_memory_buffer); | 1278 DCHECK(!resource->gpu_memory_buffer); |
| 1272 resource_provider_->LazyCreate(resource); | 1279 resource_provider_->LazyCreate(resource); |
| 1273 resource->gpu_memory_buffer = std::move(gpu_memory_buffer_); | 1280 resource->gpu_memory_buffer = std::move(gpu_memory_buffer_); |
| 1274 resource->allocated = true; | 1281 resource->allocated = true; |
| 1275 resource_provider_->LazyCreateImage(resource); | 1282 resource_provider_->LazyCreateImage(resource); |
| 1276 resource->dirty_image = true; | 1283 resource->dirty_image = true; |
| 1277 resource->is_overlay_candidate = true; | 1284 resource->is_overlay_candidate = true; |
| 1278 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | 1285 // GpuMemoryBuffer provides direct access to the memory used by the GPU. |
| 1279 // Read lock fences are required to ensure that we're not trying to map a | 1286 // Read lock fences are required to ensure that we're not trying to map a |
| 1280 // buffer that is currently in-use by the GPU. | 1287 // buffer that is currently in-use by the GPU. |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 resource->allocated = true; | 1849 resource->allocated = true; |
| 1843 GLES2Interface* gl = ContextGL(); | 1850 GLES2Interface* gl = ContextGL(); |
| 1844 gfx::Size& size = resource->size; | 1851 gfx::Size& size = resource->size; |
| 1845 ResourceFormat format = resource->format; | 1852 ResourceFormat format = resource->format; |
| 1846 gl->BindTexture(resource->target, resource->gl_id); | 1853 gl->BindTexture(resource->target, resource->gl_id); |
| 1847 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { | 1854 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { |
| 1848 resource->gpu_memory_buffer = | 1855 resource->gpu_memory_buffer = |
| 1849 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 1856 gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
| 1850 size, BufferFormat(format), resource->usage, | 1857 size, BufferFormat(format), resource->usage, |
| 1851 gpu::kNullSurfaceHandle); | 1858 gpu::kNullSurfaceHandle); |
| 1859 if (resource->gpu_memory_buffer && enable_color_correct_rendering_) { |
| 1860 resource->gpu_memory_buffer->SetColorSpaceForScanout( |
| 1861 resource->color_space); |
| 1862 } |
| 1863 |
| 1852 LazyCreateImage(resource); | 1864 LazyCreateImage(resource); |
| 1853 resource->dirty_image = true; | 1865 resource->dirty_image = true; |
| 1854 resource->is_overlay_candidate = true; | 1866 resource->is_overlay_candidate = true; |
| 1855 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | 1867 // GpuMemoryBuffer provides direct access to the memory used by the GPU. |
| 1856 // Read lock fences are required to ensure that we're not trying to map a | 1868 // Read lock fences are required to ensure that we're not trying to map a |
| 1857 // buffer that is currently in-use by the GPU. | 1869 // buffer that is currently in-use by the GPU. |
| 1858 resource->read_lock_fences_enabled = true; | 1870 resource->read_lock_fences_enabled = true; |
| 1859 } else if (use_texture_storage_ext_ && | 1871 } else if (use_texture_storage_ext_ && |
| 1860 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && | 1872 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && |
| 1861 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { | 1873 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2027 | 2039 |
| 2028 const int kImportance = 2; | 2040 const int kImportance = 2; |
| 2029 pmd->CreateSharedGlobalAllocatorDump(guid); | 2041 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 2030 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2042 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 2031 } | 2043 } |
| 2032 | 2044 |
| 2033 return true; | 2045 return true; |
| 2034 } | 2046 } |
| 2035 | 2047 |
| 2036 } // namespace cc | 2048 } // namespace cc |
| OLD | NEW |