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