| 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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 DCHECK(mailbox.IsSharedMemory()); | 656 DCHECK(mailbox.IsSharedMemory()); |
| 657 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); | 657 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); |
| 658 uint8_t* pixels = shared_bitmap->pixels(); | 658 uint8_t* pixels = shared_bitmap->pixels(); |
| 659 DCHECK(pixels); | 659 DCHECK(pixels); |
| 660 resource = InsertResource( | 660 resource = InsertResource( |
| 661 id, Resource(pixels, shared_bitmap, mailbox.size_in_pixels(), | 661 id, Resource(pixels, shared_bitmap, mailbox.size_in_pixels(), |
| 662 Resource::EXTERNAL, GL_LINEAR)); | 662 Resource::EXTERNAL, GL_LINEAR)); |
| 663 } | 663 } |
| 664 resource->allocated = true; | 664 resource->allocated = true; |
| 665 resource->set_mailbox(mailbox); | 665 resource->set_mailbox(mailbox); |
| 666 resource->color_space = mailbox.color_space(); |
| 666 resource->release_callback_impl = | 667 resource->release_callback_impl = |
| 667 base::Bind(&SingleReleaseCallbackImpl::Run, | 668 base::Bind(&SingleReleaseCallbackImpl::Run, |
| 668 base::Owned(release_callback_impl.release())); | 669 base::Owned(release_callback_impl.release())); |
| 669 resource->read_lock_fences_enabled = read_lock_fences_enabled; | 670 resource->read_lock_fences_enabled = read_lock_fences_enabled; |
| 670 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); | 671 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); |
| 671 | 672 |
| 672 return id; | 673 return id; |
| 673 } | 674 } |
| 674 | 675 |
| 675 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 676 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 } | 803 } |
| 803 | 804 |
| 804 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) { | 805 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) { |
| 805 return GetResource(id)->target; | 806 return GetResource(id)->target; |
| 806 } | 807 } |
| 807 | 808 |
| 808 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) { | 809 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) { |
| 809 return GetResource(id)->hint; | 810 return GetResource(id)->hint; |
| 810 } | 811 } |
| 811 | 812 |
| 813 static sk_sp<SkColorSpace> toSkColorSpace(const gfx::ColorSpace& color_space) { |
| 814 // TODO(crbug.com/634102): Implement conversion for skia-based compositing to |
| 815 // be color-managed |
| 816 return nullptr; |
| 817 } |
| 818 |
| 812 void ResourceProvider::CopyToResource(ResourceId id, | 819 void ResourceProvider::CopyToResource(ResourceId id, |
| 813 const uint8_t* image, | 820 const uint8_t* image, |
| 814 const gfx::Size& image_size) { | 821 const gfx::Size& image_size) { |
| 815 Resource* resource = GetResource(id); | 822 Resource* resource = GetResource(id); |
| 816 DCHECK(!resource->locked_for_write); | 823 DCHECK(!resource->locked_for_write); |
| 817 DCHECK(!resource->lock_for_read_count); | 824 DCHECK(!resource->lock_for_read_count); |
| 818 DCHECK(resource->origin == Resource::INTERNAL); | 825 DCHECK(resource->origin == Resource::INTERNAL); |
| 819 DCHECK_EQ(resource->exported_count, 0); | 826 DCHECK_EQ(resource->exported_count, 0); |
| 820 DCHECK(ReadLockFenceHasPassed(resource)); | 827 DCHECK(ReadLockFenceHasPassed(resource)); |
| 821 | 828 |
| 822 DCHECK_EQ(image_size.width(), resource->size.width()); | 829 DCHECK_EQ(image_size.width(), resource->size.width()); |
| 823 DCHECK_EQ(image_size.height(), resource->size.height()); | 830 DCHECK_EQ(image_size.height(), resource->size.height()); |
| 824 | 831 |
| 825 if (resource->allocated) | 832 if (resource->allocated) |
| 826 WaitSyncTokenIfNeeded(id); | 833 WaitSyncTokenIfNeeded(id); |
| 827 | 834 |
| 828 if (resource->type == RESOURCE_TYPE_BITMAP) { | 835 if (resource->type == RESOURCE_TYPE_BITMAP) { |
| 829 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); | 836 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); |
| 830 DCHECK(resource->allocated); | 837 DCHECK(resource->allocated); |
| 831 DCHECK_EQ(RGBA_8888, resource->format); | 838 DCHECK_EQ(RGBA_8888, resource->format); |
| 832 SkImageInfo source_info = | 839 SkImageInfo source_info = |
| 833 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); | 840 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height(), |
| 841 toSkColorSpace(resource->color_space)); |
| 834 size_t image_stride = image_size.width() * 4; | 842 size_t image_stride = image_size.width() * 4; |
| 835 | 843 |
| 836 ScopedWriteLockSoftware lock(this, id); | 844 ScopedWriteLockSoftware lock(this, id); |
| 837 SkCanvas dest(lock.sk_bitmap()); | 845 SkCanvas dest(lock.sk_bitmap()); |
| 838 dest.writePixels(source_info, image, image_stride, 0, 0); | 846 dest.writePixels(source_info, image, image_stride, 0, 0); |
| 839 } else { | 847 } else { |
| 840 ScopedWriteLockGL lock(this, id, false); | 848 ScopedWriteLockGL lock(this, id, false); |
| 841 unsigned resource_texture_id = lock.texture_id(); | 849 unsigned resource_texture_id = lock.texture_id(); |
| 842 DCHECK(resource_texture_id); | 850 DCHECK(resource_texture_id); |
| 843 GLES2Interface* gl = ContextGL(); | 851 GLES2Interface* gl = ContextGL(); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1147 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { | 1155 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { |
| 1148 if (sk_surface_.get()) { | 1156 if (sk_surface_.get()) { |
| 1149 sk_surface_->prepareForExternalIO(); | 1157 sk_surface_->prepareForExternalIO(); |
| 1150 sk_surface_.reset(); | 1158 sk_surface_.reset(); |
| 1151 } | 1159 } |
| 1152 } | 1160 } |
| 1153 | 1161 |
| 1154 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 1162 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
| 1155 const Resource* resource) { | 1163 const Resource* resource) { |
| 1156 DCHECK_EQ(RGBA_8888, resource->format); | 1164 DCHECK_EQ(RGBA_8888, resource->format); |
| 1157 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), | 1165 SkImageInfo info = SkImageInfo::MakeN32Premul( |
| 1158 resource->size.height()); | 1166 resource->size.width(), resource->size.height(), |
| 1167 toSkColorSpace(resource->color_space)); |
| 1159 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); | 1168 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); |
| 1160 } | 1169 } |
| 1161 | 1170 |
| 1162 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 1171 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
| 1163 ResourceProvider* resource_provider, | 1172 ResourceProvider* resource_provider, |
| 1164 ResourceId resource_id) | 1173 ResourceId resource_id) |
| 1165 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1174 : resource_provider_(resource_provider), resource_id_(resource_id) { |
| 1166 const Resource* resource = resource_provider->LockForRead(resource_id); | 1175 const Resource* resource = resource_provider->LockForRead(resource_id); |
| 1167 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); | 1176 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap_, resource); |
| 1168 } | 1177 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1181 texture_info.fID = resource->gl_id; | 1190 texture_info.fID = resource->gl_id; |
| 1182 texture_info.fTarget = resource->target; | 1191 texture_info.fTarget = resource->target; |
| 1183 GrBackendTextureDesc desc; | 1192 GrBackendTextureDesc desc; |
| 1184 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 1193 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 1185 desc.fWidth = resource->size.width(); | 1194 desc.fWidth = resource->size.width(); |
| 1186 desc.fHeight = resource->size.height(); | 1195 desc.fHeight = resource->size.height(); |
| 1187 desc.fConfig = ToGrPixelConfig(resource->format); | 1196 desc.fConfig = ToGrPixelConfig(resource->format); |
| 1188 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 1197 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 1189 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); | 1198 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); |
| 1190 sk_image_ = SkImage::MakeFromTexture( | 1199 sk_image_ = SkImage::MakeFromTexture( |
| 1191 resource_provider->compositor_context_provider_->GrContext(), desc); | 1200 resource_provider->compositor_context_provider_->GrContext(), desc, |
| 1201 kPremul_SkAlphaType, toSkColorSpace(resource->color_space), nullptr, |
| 1202 nullptr); |
| 1192 } else if (resource->pixels) { | 1203 } else if (resource->pixels) { |
| 1193 SkBitmap sk_bitmap; | 1204 SkBitmap sk_bitmap; |
| 1194 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap, resource); | 1205 ResourceProvider::PopulateSkBitmapWithResource(&sk_bitmap, resource); |
| 1195 sk_bitmap.setImmutable(); | 1206 sk_bitmap.setImmutable(); |
| 1196 sk_image_ = SkImage::MakeFromBitmap(sk_bitmap); | 1207 sk_image_ = SkImage::MakeFromBitmap(sk_bitmap); |
| 1197 } else { | 1208 } else { |
| 1198 // During render process shutdown, ~RenderMessageFilter which calls | 1209 // During render process shutdown, ~RenderMessageFilter which calls |
| 1199 // ~HostSharedBitmapClient (which deletes shared bitmaps from child) | 1210 // ~HostSharedBitmapClient (which deletes shared bitmaps from child) |
| 1200 // can race with OnBeginFrameDeadline which draws a frame. | 1211 // can race with OnBeginFrameDeadline which draws a frame. |
| 1201 // In these cases, shared bitmaps (and this read lock) won't be valid. | 1212 // In these cases, shared bitmaps (and this read lock) won't be valid. |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 it->mailbox_holder.texture_target, it->filter, | 1489 it->mailbox_holder.texture_target, it->filter, |
| 1479 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE, | 1490 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE, |
| 1480 it->format)); | 1491 it->format)); |
| 1481 resource->set_mailbox(TextureMailbox(it->mailbox_holder.mailbox, | 1492 resource->set_mailbox(TextureMailbox(it->mailbox_holder.mailbox, |
| 1482 it->mailbox_holder.sync_token, | 1493 it->mailbox_holder.sync_token, |
| 1483 it->mailbox_holder.texture_target)); | 1494 it->mailbox_holder.texture_target)); |
| 1484 resource->read_lock_fences_enabled = it->read_lock_fences_enabled; | 1495 resource->read_lock_fences_enabled = it->read_lock_fences_enabled; |
| 1485 resource->is_overlay_candidate = it->is_overlay_candidate; | 1496 resource->is_overlay_candidate = it->is_overlay_candidate; |
| 1486 resource->color_space = it->color_space; | 1497 resource->color_space = it->color_space; |
| 1487 } | 1498 } |
| 1499 |
| 1488 resource->child_id = child; | 1500 resource->child_id = child; |
| 1489 // Don't allocate a texture for a child. | 1501 // Don't allocate a texture for a child. |
| 1490 resource->allocated = true; | 1502 resource->allocated = true; |
| 1491 resource->imported_count = 1; | 1503 resource->imported_count = 1; |
| 1492 child_info.parent_to_child_map[local_id] = it->id; | 1504 child_info.parent_to_child_map[local_id] = it->id; |
| 1493 child_info.child_to_parent_map[it->id] = local_id; | 1505 child_info.child_to_parent_map[it->id] = local_id; |
| 1494 } | 1506 } |
| 1495 } | 1507 } |
| 1496 | 1508 |
| 1497 void ResourceProvider::DeclareUsedResourcesFromChild( | 1509 void ResourceProvider::DeclareUsedResourcesFromChild( |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2004 | 2016 |
| 2005 const int kImportance = 2; | 2017 const int kImportance = 2; |
| 2006 pmd->CreateSharedGlobalAllocatorDump(guid); | 2018 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 2007 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2019 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 2008 } | 2020 } |
| 2009 | 2021 |
| 2010 return true; | 2022 return true; |
| 2011 } | 2023 } |
| 2012 | 2024 |
| 2013 } // namespace cc | 2025 } // namespace cc |
| OLD | NEW |