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 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
756 DCHECK(resource->allocated); | 756 DCHECK(resource->allocated); |
757 DCHECK_EQ(RGBA_8888, resource->format); | 757 DCHECK_EQ(RGBA_8888, resource->format); |
758 SkImageInfo source_info = | 758 SkImageInfo source_info = |
759 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); | 759 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); |
760 size_t image_stride = image_size.width() * 4; | 760 size_t image_stride = image_size.width() * 4; |
761 | 761 |
762 ScopedWriteLockSoftware lock(this, id); | 762 ScopedWriteLockSoftware lock(this, id); |
763 SkCanvas dest(lock.sk_bitmap()); | 763 SkCanvas dest(lock.sk_bitmap()); |
764 dest.writePixels(source_info, image, image_stride, 0, 0); | 764 dest.writePixels(source_info, image, image_stride, 0, 0); |
765 } else { | 765 } else { |
766 ScopedWriteLockGL lock(this, id); | 766 ScopedWriteLockGL lock(this, id, false); |
767 DCHECK(lock.texture_id()); | 767 unsigned resource_texture_id = lock.ProduceTextureId(); |
768 DCHECK(resource_texture_id); | |
768 GLES2Interface* gl = ContextGL(); | 769 GLES2Interface* gl = ContextGL(); |
769 DCHECK(gl); | 770 DCHECK(gl); |
770 gl->BindTexture(resource->target, lock.texture_id()); | 771 gl->BindTexture(resource->target, resource_texture_id); |
771 if (resource->format == ETC1) { | 772 if (resource->format == ETC1) { |
772 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 773 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
773 int image_bytes = ResourceUtil::CheckedSizeInBytes<int>(image_size, ETC1); | 774 int image_bytes = ResourceUtil::CheckedSizeInBytes<int>(image_size, ETC1); |
774 gl->CompressedTexImage2D(resource->target, 0, GLInternalFormat(ETC1), | 775 gl->CompressedTexImage2D(resource->target, 0, GLInternalFormat(ETC1), |
775 image_size.width(), image_size.height(), 0, | 776 image_size.width(), image_size.height(), 0, |
776 image_bytes, image); | 777 image_bytes, image); |
777 } else { | 778 } else { |
778 gl->TexSubImage2D(resource->target, 0, 0, 0, image_size.width(), | 779 gl->TexSubImage2D(resource->target, 0, 0, 0, image_size.width(), |
779 image_size.height(), GLDataFormat(resource->format), | 780 image_size.height(), GLDataFormat(resource->format), |
780 GLDataType(resource->format), image); | 781 GLDataType(resource->format), image); |
781 } | 782 } |
783 lock.ReleaseTextureId(); | |
782 } | 784 } |
783 } | 785 } |
784 | 786 |
785 void ResourceProvider::GenerateSyncTokenForResource(ResourceId resource_id) { | 787 void ResourceProvider::GenerateSyncTokenForResource(ResourceId resource_id) { |
786 Resource* resource = GetResource(resource_id); | 788 Resource* resource = GetResource(resource_id); |
787 if (!resource->needs_sync_token()) | 789 if (!resource->needs_sync_token()) |
788 return; | 790 return; |
789 | 791 |
790 gpu::SyncToken sync_token; | 792 gpu::SyncToken sync_token; |
791 GLES2Interface* gl = ContextGL(); | 793 GLES2Interface* gl = ContextGL(); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
981 : ScopedReadLockGL(resource_provider, resource_id), | 983 : ScopedReadLockGL(resource_provider, resource_id), |
982 unit_(unit), | 984 unit_(unit), |
983 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) { | 985 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) { |
984 } | 986 } |
985 | 987 |
986 ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() { | 988 ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() { |
987 } | 989 } |
988 | 990 |
989 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL( | 991 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL( |
990 ResourceProvider* resource_provider, | 992 ResourceProvider* resource_provider, |
991 ResourceId resource_id) | 993 ResourceId resource_id, |
994 bool use_mailbox) | |
992 : resource_provider_(resource_provider), | 995 : resource_provider_(resource_provider), |
993 resource_(resource_provider->LockForWrite(resource_id)), | 996 resource_(resource_provider->LockForWrite(resource_id)), |
997 use_mailbox_(use_mailbox), | |
994 texture_id_(0), | 998 texture_id_(0), |
995 set_sync_token_(false) { | 999 set_sync_token_(false) { |
996 resource_provider_->LazyAllocate(resource_); | 1000 resource_provider_->LazyAllocate(resource_); |
997 texture_id_ = resource_->gl_id; | |
998 DCHECK(texture_id_); | |
999 if (resource_->image_id && resource_->dirty_image) | 1001 if (resource_->image_id && resource_->dirty_image) |
1000 resource_provider_->BindImageForSampling(resource_); | 1002 resource_provider_->BindImageForSampling(resource_); |
1003 if (use_mailbox_) { | |
1004 resource_provider_->CreateMailboxAndBindResource( | |
1005 resource_provider_->ContextGL(), resource_); | |
1006 } | |
1001 } | 1007 } |
1002 | 1008 |
1003 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 1009 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
1010 DCHECK_EQ(texture_id_, 0u); | |
1004 if (set_sync_token_) | 1011 if (set_sync_token_) |
1005 resource_->UpdateSyncToken(sync_token_); | 1012 resource_->UpdateSyncToken(sync_token_); |
1006 resource_provider_->UnlockForWrite(resource_); | 1013 resource_provider_->UnlockForWrite(resource_); |
1007 } | 1014 } |
1008 | 1015 |
1016 unsigned ResourceProvider::ScopedWriteLockGL::ProduceTextureId() { | |
1017 if (use_mailbox_) { | |
1018 if (!texture_id_) { | |
1019 gpu::gles2::GLES2Interface* gl = resource_provider_->output_surface() | |
1020 ->worker_context_provider() | |
1021 ->ContextGL(); | |
piman
2016/05/06 01:55:30
This path is taken in ResourceProvider::CopyToReso
sunnyps
2016/05/25 02:18:43
Done.
| |
1022 texture_id_ = gl->CreateAndConsumeTextureCHROMIUM( | |
1023 resource_->target, resource_->mailbox().name()); | |
piman
2016/05/06 01:55:30
When called on the worker thread, it's not safe to
sunnyps
2016/05/25 02:18:43
Done.
| |
1024 DCHECK(texture_id_); | |
1025 } | |
1026 return texture_id_; | |
1027 } | |
1028 return resource_->gl_id; | |
piman
2016/05/06 01:55:30
(ditto)
sunnyps
2016/05/25 02:18:43
Done.
| |
1029 } | |
1030 | |
1031 void ResourceProvider::ScopedWriteLockGL::ReleaseTextureId() { | |
1032 if (use_mailbox_) { | |
1033 gpu::gles2::GLES2Interface* gl = resource_provider_->output_surface() | |
1034 ->worker_context_provider() | |
1035 ->ContextGL(); | |
piman
2016/05/06 01:55:30
And ditto wrt which context.
sunnyps
2016/05/25 02:18:43
Done.
| |
1036 gl->DeleteTextures(1, &texture_id_); | |
1037 texture_id_ = 0; | |
1038 } | |
1039 } | |
1040 | |
1009 void ResourceProvider::PopulateSkBitmapWithResource( | 1041 void ResourceProvider::PopulateSkBitmapWithResource( |
1010 SkBitmap* sk_bitmap, const Resource* resource) { | 1042 SkBitmap* sk_bitmap, const Resource* resource) { |
1011 DCHECK_EQ(RGBA_8888, resource->format); | 1043 DCHECK_EQ(RGBA_8888, resource->format); |
1012 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), | 1044 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), |
1013 resource->size.height()); | 1045 resource->size.height()); |
1014 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); | 1046 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); |
1015 } | 1047 } |
1016 | 1048 |
1017 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( | 1049 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware( |
1018 ResourceProvider* resource_provider, | 1050 ResourceProvider* resource_provider, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1078 gpu_memory_buffer_ = | 1110 gpu_memory_buffer_ = |
1079 resource_provider_->gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( | 1111 resource_provider_->gpu_memory_buffer_manager_->AllocateGpuMemoryBuffer( |
1080 resource_->size, BufferFormat(resource_->format), | 1112 resource_->size, BufferFormat(resource_->format), |
1081 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle); | 1113 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, gpu::kNullSurfaceHandle); |
1082 } | 1114 } |
1083 return gpu_memory_buffer_.get(); | 1115 return gpu_memory_buffer_.get(); |
1084 } | 1116 } |
1085 | 1117 |
1086 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( | 1118 ResourceProvider::ScopedWriteLockGr::ScopedWriteLockGr( |
1087 ResourceProvider* resource_provider, | 1119 ResourceProvider* resource_provider, |
1088 ResourceId resource_id) | 1120 ResourceId resource_id, |
1121 bool use_mailbox) | |
1089 : resource_provider_(resource_provider), | 1122 : resource_provider_(resource_provider), |
1090 resource_(resource_provider->LockForWrite(resource_id)), | 1123 resource_(resource_provider->LockForWrite(resource_id)), |
1124 use_mailbox_(use_mailbox), | |
1125 texture_id_(0), | |
1091 set_sync_token_(false) { | 1126 set_sync_token_(false) { |
1092 DCHECK(thread_checker_.CalledOnValidThread()); | 1127 DCHECK(thread_checker_.CalledOnValidThread()); |
1093 resource_provider_->LazyAllocate(resource_); | 1128 resource_provider_->LazyAllocate(resource_); |
1094 if (resource_->image_id && resource_->dirty_image) | 1129 if (resource_->image_id && resource_->dirty_image) |
1095 resource_provider_->BindImageForSampling(resource_); | 1130 resource_provider_->BindImageForSampling(resource_); |
1131 if (use_mailbox_) { | |
1132 resource_provider_->CreateMailboxAndBindResource( | |
1133 resource_provider_->ContextGL(), resource_); | |
1134 } | |
1096 } | 1135 } |
1097 | 1136 |
1098 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { | 1137 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { |
1099 DCHECK(thread_checker_.CalledOnValidThread()); | 1138 DCHECK(thread_checker_.CalledOnValidThread()); |
1100 DCHECK(resource_->locked_for_write); | 1139 DCHECK(resource_->locked_for_write); |
1140 DCHECK_EQ(texture_id_, 0u); | |
1101 if (set_sync_token_) | 1141 if (set_sync_token_) |
1102 resource_->UpdateSyncToken(sync_token_); | 1142 resource_->UpdateSyncToken(sync_token_); |
1103 | 1143 |
1104 resource_provider_->UnlockForWrite(resource_); | 1144 resource_provider_->UnlockForWrite(resource_); |
1105 } | 1145 } |
1106 | 1146 |
1107 void ResourceProvider::ScopedWriteLockGr::InitSkSurface( | 1147 void ResourceProvider::ScopedWriteLockGr::InitSkSurface( |
1108 bool use_distance_field_text, | 1148 bool use_distance_field_text, |
1109 bool can_use_lcd_text, | 1149 bool can_use_lcd_text, |
1110 int msaa_sample_count) { | 1150 int msaa_sample_count) { |
1111 DCHECK(resource_->locked_for_write); | 1151 DCHECK(resource_->locked_for_write); |
1112 | 1152 |
1153 if (use_mailbox_) { | |
1154 gpu::gles2::GLES2Interface* gl = resource_provider_->output_surface() | |
1155 ->worker_context_provider() | |
1156 ->ContextGL(); | |
1157 texture_id_ = gl->CreateAndConsumeTextureCHROMIUM( | |
1158 resource_->target, resource_->mailbox().name()); | |
piman
2016/05/06 01:55:30
Same as above, unsafe to access resource_
sunnyps
2016/05/25 02:18:43
Done.
| |
1159 } | |
1160 | |
1113 GrGLTextureInfo texture_info; | 1161 GrGLTextureInfo texture_info; |
1114 texture_info.fID = resource_->gl_id; | 1162 texture_info.fID = use_mailbox_ ? texture_id_ : resource_->gl_id; |
1115 texture_info.fTarget = resource_->target; | 1163 texture_info.fTarget = resource_->target; |
1116 GrBackendTextureDesc desc; | 1164 GrBackendTextureDesc desc; |
1117 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 1165 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
1118 desc.fWidth = resource_->size.width(); | 1166 desc.fWidth = resource_->size.width(); |
1119 desc.fHeight = resource_->size.height(); | 1167 desc.fHeight = resource_->size.height(); |
1120 desc.fConfig = ToGrPixelConfig(resource_->format); | 1168 desc.fConfig = ToGrPixelConfig(resource_->format); |
1121 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 1169 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
1122 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); | 1170 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); |
1123 desc.fSampleCnt = msaa_sample_count; | 1171 desc.fSampleCnt = msaa_sample_count; |
1124 | 1172 |
1125 bool use_worker_context = true; | 1173 bool use_worker_context = true; |
1126 class GrContext* gr_context = | 1174 class GrContext* gr_context = |
1127 resource_provider_->GrContext(use_worker_context); | 1175 resource_provider_->GrContext(use_worker_context); |
1128 uint32_t flags = | 1176 uint32_t flags = |
1129 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; | 1177 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; |
1130 // Use unknown pixel geometry to disable LCD text. | 1178 // Use unknown pixel geometry to disable LCD text. |
1131 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); | 1179 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
1132 if (can_use_lcd_text) { | 1180 if (can_use_lcd_text) { |
1133 // LegacyFontHost will get LCD text and skia figures out what type to use. | 1181 // LegacyFontHost will get LCD text and skia figures out what type to use. |
1134 surface_props = | 1182 surface_props = |
1135 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); | 1183 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
1136 } | 1184 } |
1137 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( | 1185 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( |
1138 gr_context, desc, &surface_props); | 1186 gr_context, desc, &surface_props); |
1187 if (!sk_surface_ && use_mailbox_) { | |
1188 gpu::gles2::GLES2Interface* gl = resource_provider_->output_surface() | |
1189 ->worker_context_provider() | |
1190 ->ContextGL(); | |
1191 gl->DeleteTextures(1, &texture_id_); | |
1192 texture_id_ = 0; | |
1193 } | |
1139 } | 1194 } |
1140 | 1195 |
1141 void ResourceProvider::ScopedWriteLockGr::ReleaseSkSurface() { | 1196 void ResourceProvider::ScopedWriteLockGr::ReleaseSkSurface() { |
1142 DCHECK(sk_surface_); | 1197 DCHECK(sk_surface_); |
1143 sk_surface_->prepareForExternalIO(); | 1198 sk_surface_->prepareForExternalIO(); |
1144 sk_surface_.reset(); | 1199 sk_surface_.reset(); |
1200 if (use_mailbox_) { | |
1201 gpu::gles2::GLES2Interface* gl = resource_provider_->output_surface() | |
1202 ->worker_context_provider() | |
1203 ->ContextGL(); | |
1204 gl->DeleteTextures(1, &texture_id_); | |
1205 texture_id_ = 0; | |
1206 } | |
1145 } | 1207 } |
1146 | 1208 |
1147 ResourceProvider::SynchronousFence::SynchronousFence( | 1209 ResourceProvider::SynchronousFence::SynchronousFence( |
1148 gpu::gles2::GLES2Interface* gl) | 1210 gpu::gles2::GLES2Interface* gl) |
1149 : gl_(gl), has_synchronized_(true) { | 1211 : gl_(gl), has_synchronized_(true) { |
1150 } | 1212 } |
1151 | 1213 |
1152 ResourceProvider::SynchronousFence::~SynchronousFence() { | 1214 ResourceProvider::SynchronousFence::~SynchronousFence() { |
1153 } | 1215 } |
1154 | 1216 |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1960 | 2022 |
1961 const int kImportance = 2; | 2023 const int kImportance = 2; |
1962 pmd->CreateSharedGlobalAllocatorDump(guid); | 2024 pmd->CreateSharedGlobalAllocatorDump(guid); |
1963 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2025 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
1964 } | 2026 } |
1965 | 2027 |
1966 return true; | 2028 return true; |
1967 } | 2029 } |
1968 | 2030 |
1969 } // namespace cc | 2031 } // namespace cc |
OLD | NEW |