| 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 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 DCHECK(mailbox.IsSharedMemory()); | 665 DCHECK(mailbox.IsSharedMemory()); |
| 666 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); | 666 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); |
| 667 uint8_t* pixels = shared_bitmap->pixels(); | 667 uint8_t* pixels = shared_bitmap->pixels(); |
| 668 DCHECK(pixels); | 668 DCHECK(pixels); |
| 669 resource = InsertResource( | 669 resource = InsertResource( |
| 670 id, Resource(pixels, shared_bitmap, mailbox.size_in_pixels(), | 670 id, Resource(pixels, shared_bitmap, mailbox.size_in_pixels(), |
| 671 Resource::EXTERNAL, GL_LINEAR)); | 671 Resource::EXTERNAL, GL_LINEAR)); |
| 672 } | 672 } |
| 673 resource->allocated = true; | 673 resource->allocated = true; |
| 674 resource->set_mailbox(mailbox); | 674 resource->set_mailbox(mailbox); |
| 675 resource->color_space = mailbox.color_space(); |
| 675 resource->release_callback_impl = | 676 resource->release_callback_impl = |
| 676 base::Bind(&SingleReleaseCallbackImpl::Run, | 677 base::Bind(&SingleReleaseCallbackImpl::Run, |
| 677 base::Owned(release_callback_impl.release())); | 678 base::Owned(release_callback_impl.release())); |
| 678 resource->read_lock_fences_enabled = read_lock_fences_enabled; | 679 resource->read_lock_fences_enabled = read_lock_fences_enabled; |
| 679 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); | 680 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); |
| 680 resource->color_space = mailbox.color_space(); | 681 resource->color_space = mailbox.color_space(); |
| 681 | 682 |
| 682 return id; | 683 return id; |
| 683 } | 684 } |
| 684 | 685 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 } | 813 } |
| 813 | 814 |
| 814 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) { | 815 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) { |
| 815 return GetResource(id)->target; | 816 return GetResource(id)->target; |
| 816 } | 817 } |
| 817 | 818 |
| 818 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) { | 819 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) { |
| 819 return GetResource(id)->hint; | 820 return GetResource(id)->hint; |
| 820 } | 821 } |
| 821 | 822 |
| 823 static sk_sp<SkColorSpace> ColorSpaceToSkColorSpace( |
| 824 const gfx::ColorSpace& color_space) { |
| 825 // TODO(crbug.com/634102): Implement conversion for skia-based compositing to |
| 826 // be color-managed |
| 827 return nullptr; |
| 828 } |
| 829 |
| 822 void ResourceProvider::CopyToResource(ResourceId id, | 830 void ResourceProvider::CopyToResource(ResourceId id, |
| 823 const uint8_t* image, | 831 const uint8_t* image, |
| 824 const gfx::Size& image_size) { | 832 const gfx::Size& image_size) { |
| 825 Resource* resource = GetResource(id); | 833 Resource* resource = GetResource(id); |
| 826 DCHECK(!resource->locked_for_write); | 834 DCHECK(!resource->locked_for_write); |
| 827 DCHECK(!resource->lock_for_read_count); | 835 DCHECK(!resource->lock_for_read_count); |
| 828 DCHECK(resource->origin == Resource::INTERNAL); | 836 DCHECK(resource->origin == Resource::INTERNAL); |
| 829 DCHECK_EQ(resource->exported_count, 0); | 837 DCHECK_EQ(resource->exported_count, 0); |
| 830 DCHECK(ReadLockFenceHasPassed(resource)); | 838 DCHECK(ReadLockFenceHasPassed(resource)); |
| 831 | 839 |
| 832 DCHECK_EQ(image_size.width(), resource->size.width()); | 840 DCHECK_EQ(image_size.width(), resource->size.width()); |
| 833 DCHECK_EQ(image_size.height(), resource->size.height()); | 841 DCHECK_EQ(image_size.height(), resource->size.height()); |
| 834 | 842 |
| 835 if (resource->allocated) | 843 if (resource->allocated) |
| 836 WaitSyncTokenIfNeeded(id); | 844 WaitSyncTokenIfNeeded(id); |
| 837 | 845 |
| 838 if (resource->type == RESOURCE_TYPE_BITMAP) { | 846 if (resource->type == RESOURCE_TYPE_BITMAP) { |
| 839 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); | 847 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); |
| 840 DCHECK(resource->allocated); | 848 DCHECK(resource->allocated); |
| 841 DCHECK_EQ(RGBA_8888, resource->format); | 849 DCHECK_EQ(RGBA_8888, resource->format); |
| 842 SkImageInfo source_info = | 850 SkImageInfo source_info = SkImageInfo::MakeN32Premul( |
| 843 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); | 851 image_size.width(), image_size.height(), |
| 852 ColorSpaceToSkColorSpace(resource->color_space)); |
| 844 size_t image_stride = image_size.width() * 4; | 853 size_t image_stride = image_size.width() * 4; |
| 845 | 854 |
| 846 ScopedWriteLockSoftware lock(this, id); | 855 ScopedWriteLockSoftware lock(this, id); |
| 847 SkCanvas dest(lock.sk_bitmap()); | 856 SkCanvas dest(lock.sk_bitmap()); |
| 848 dest.writePixels(source_info, image, image_stride, 0, 0); | 857 dest.writePixels(source_info, image, image_stride, 0, 0); |
| 849 } else { | 858 } else { |
| 850 ScopedWriteLockGL lock(this, id, false); | 859 ScopedWriteLockGL lock(this, id, false); |
| 851 unsigned resource_texture_id = lock.texture_id(); | 860 unsigned resource_texture_id = lock.texture_id(); |
| 852 DCHECK(resource_texture_id); | 861 DCHECK(resource_texture_id); |
| 853 GLES2Interface* gl = ContextGL(); | 862 GLES2Interface* gl = ContextGL(); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1158 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { | 1167 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { |
| 1159 if (sk_surface_.get()) { | 1168 if (sk_surface_.get()) { |
| 1160 sk_surface_->prepareForExternalIO(); | 1169 sk_surface_->prepareForExternalIO(); |
| 1161 sk_surface_.reset(); | 1170 sk_surface_.reset(); |
| 1162 } | 1171 } |
| 1163 } | 1172 } |
| 1164 | 1173 |
| 1165 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 1174 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
| 1166 const Resource* resource) { | 1175 const Resource* resource) { |
| 1167 DCHECK_EQ(RGBA_8888, resource->format); | 1176 DCHECK_EQ(RGBA_8888, resource->format); |
| 1168 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), | 1177 SkImageInfo info = SkImageInfo::MakeN32Premul( |
| 1169 resource->size.height()); | 1178 resource->size.width(), resource->size.height(), |
| 1179 ColorSpaceToSkColorSpace(resource->color_space)); |
| 1170 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); | 1180 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); |
| 1171 } | 1181 } |
| 1172 | 1182 |
| 1173 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 1183 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
| 1174 ResourceProvider* resource_provider, | 1184 ResourceProvider* resource_provider, |
| 1175 ResourceId resource_id) | 1185 ResourceId resource_id) |
| 1176 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1186 : resource_provider_(resource_provider), resource_id_(resource_id) { |
| 1177 const Resource* resource = resource_provider->LockForRead(resource_id); | 1187 const Resource* resource = resource_provider->LockForRead(resource_id); |
| 1178 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); | 1188 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); |
| 1179 } | 1189 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1192 texture_info.fID = resource->gl_id; | 1202 texture_info.fID = resource->gl_id; |
| 1193 texture_info.fTarget = resource->target; | 1203 texture_info.fTarget = resource->target; |
| 1194 GrBackendTextureDesc desc; | 1204 GrBackendTextureDesc desc; |
| 1195 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 1205 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 1196 desc.fWidth = resource->size.width(); | 1206 desc.fWidth = resource->size.width(); |
| 1197 desc.fHeight = resource->size.height(); | 1207 desc.fHeight = resource->size.height(); |
| 1198 desc.fConfig = ToGrPixelConfig(resource->format); | 1208 desc.fConfig = ToGrPixelConfig(resource->format); |
| 1199 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 1209 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 1200 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); | 1210 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); |
| 1201 sk_image_ = SkImage::MakeFromTexture( | 1211 sk_image_ = SkImage::MakeFromTexture( |
| 1202 resource_provider->compositor_context_provider_->GrContext(), desc); | 1212 resource_provider->compositor_context_provider_->GrContext(), desc, |
| 1213 kPremul_SkAlphaType, ColorSpaceToSkColorSpace(resource->color_space), |
| 1214 nullptr, nullptr); |
| 1203 } else if (resource->pixels) { | 1215 } else if (resource->pixels) { |
| 1204 SkBitmap sk_bitmap; | 1216 SkBitmap sk_bitmap; |
| 1205 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap, resource); | 1217 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap, resource); |
| 1206 sk_bitmap.setImmutable(); | 1218 sk_bitmap.setImmutable(); |
| 1207 sk_image_ = SkImage::MakeFromBitmap(sk_bitmap); | 1219 sk_image_ = SkImage::MakeFromBitmap(sk_bitmap); |
| 1208 } else { | 1220 } else { |
| 1209 // During render process shutdown, ~RenderMessageFilter which calls | 1221 // During render process shutdown, ~RenderMessageFilter which calls |
| 1210 // ~HostSharedBitmapClient (which deletes shared bitmaps from child) | 1222 // ~HostSharedBitmapClient (which deletes shared bitmaps from child) |
| 1211 // can race with OnBeginFrameDeadline which draws a frame. | 1223 // can race with OnBeginFrameDeadline which draws a frame. |
| 1212 // In these cases, shared bitmaps (and this read lock) won't be valid. | 1224 // In these cases, shared bitmaps (and this read lock) won't be valid. |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2015 | 2027 |
| 2016 const int kImportance = 2; | 2028 const int kImportance = 2; |
| 2017 pmd->CreateSharedGlobalAllocatorDump(guid); | 2029 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 2018 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2030 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 2019 } | 2031 } |
| 2020 | 2032 |
| 2021 return true; | 2033 return true; |
| 2022 } | 2034 } |
| 2023 | 2035 |
| 2024 } // namespace cc | 2036 } // namespace cc |
| OLD | NEW |