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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 case LUMINANCE_8: | 128 case LUMINANCE_8: |
| 129 case RGB_565: | 129 case RGB_565: |
| 130 case ETC1: | 130 case ETC1: |
| 131 case RED_8: | 131 case RED_8: |
| 132 case LUMINANCE_F16: | 132 case LUMINANCE_F16: |
| 133 return false; | 133 return false; |
| 134 } | 134 } |
| 135 return false; | 135 return false; |
| 136 } | 136 } |
| 137 | 137 |
| 138 GrPixelConfig ToGrPixelConfig(ResourceFormat format) { | |
| 139 switch (format) { | |
| 140 case RGBA_8888: | |
| 141 return kRGBA_8888_GrPixelConfig; | |
| 142 case BGRA_8888: | |
| 143 return kBGRA_8888_GrPixelConfig; | |
| 144 case RGBA_4444: | |
| 145 return kRGBA_4444_GrPixelConfig; | |
| 146 case RGBA_F16: | |
| 147 return kRGBA_half_GrPixelConfig; | |
| 148 default: | |
| 149 break; | |
| 150 } | |
| 151 DCHECK(false) << "Unsupported resource format."; | |
| 152 return kSkia8888_GrPixelConfig; | |
| 153 } | |
| 154 | |
| 155 class ScopedSetActiveTexture { | 138 class ScopedSetActiveTexture { |
| 156 public: | 139 public: |
| 157 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) | 140 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) |
| 158 : gl_(gl), unit_(unit) { | 141 : gl_(gl), unit_(unit) { |
| 159 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); | 142 DCHECK_EQ(GL_TEXTURE0, ResourceProvider::GetActiveTextureUnit(gl_)); |
| 160 | 143 |
| 161 if (unit_ != GL_TEXTURE0) | 144 if (unit_ != GL_TEXTURE0) |
| 162 gl_->ActiveTexture(unit_); | 145 gl_->ActiveTexture(unit_); |
| 163 } | 146 } |
| 164 | 147 |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 922 } else { | 905 } else { |
| 923 gl->TexSubImage2D(resource->target, 0, 0, 0, image_size.width(), | 906 gl->TexSubImage2D(resource->target, 0, 0, 0, image_size.width(), |
| 924 image_size.height(), GLDataFormat(resource->format), | 907 image_size.height(), GLDataFormat(resource->format), |
| 925 GLDataType(resource->format), image); | 908 GLDataType(resource->format), image); |
| 926 } | 909 } |
| 927 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); | 910 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); |
| 928 gl->OrderingBarrierCHROMIUM(); | 911 gl->OrderingBarrierCHROMIUM(); |
| 929 gpu::SyncToken sync_token; | 912 gpu::SyncToken sync_token; |
| 930 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 913 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
| 931 lock.set_sync_token(sync_token); | 914 lock.set_sync_token(sync_token); |
| 932 lock.set_synchronized(true); | |
| 933 } | 915 } |
| 934 } | 916 } |
| 935 | 917 |
| 936 void ResourceProvider::GenerateSyncTokenForResource(ResourceId resource_id) { | 918 void ResourceProvider::GenerateSyncTokenForResource(ResourceId resource_id) { |
| 937 Resource* resource = GetResource(resource_id); | 919 Resource* resource = GetResource(resource_id); |
| 938 if (!resource->needs_sync_token()) | 920 if (!resource->needs_sync_token()) |
| 939 return; | 921 return; |
| 940 | 922 |
| 941 gpu::SyncToken sync_token; | 923 gpu::SyncToken sync_token; |
| 942 GLES2Interface* gl = ContextGL(); | 924 GLES2Interface* gl = ContextGL(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 ResourceProvider::Resource* ResourceProvider::GetResource(ResourceId id) { | 978 ResourceProvider::Resource* ResourceProvider::GetResource(ResourceId id) { |
| 997 DCHECK(thread_checker_.CalledOnValidThread()); | 979 DCHECK(thread_checker_.CalledOnValidThread()); |
| 998 DCHECK(id); | 980 DCHECK(id); |
| 999 ResourceMap::iterator it = resources_.find(id); | 981 ResourceMap::iterator it = resources_.find(id); |
| 1000 DCHECK(it != resources_.end()); | 982 DCHECK(it != resources_.end()); |
| 1001 return &it->second; | 983 return &it->second; |
| 1002 } | 984 } |
| 1003 | 985 |
| 1004 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { | 986 const ResourceProvider::Resource* ResourceProvider::LockForRead(ResourceId id) { |
| 1005 Resource* resource = GetResource(id); | 987 Resource* resource = GetResource(id); |
| 1006 DCHECK(!resource->locked_for_write) << "locked for write: " | 988 DCHECK(!resource->locked_for_write) |
| 1007 << resource->locked_for_write; | 989 << "locked for write: " << resource->locked_for_write; |
| 1008 DCHECK_EQ(resource->exported_count, 0); | 990 DCHECK_EQ(resource->exported_count, 0); |
| 1009 // Uninitialized! Call SetPixels or LockForWrite first. | 991 // Uninitialized! Call SetPixels or LockForWrite first. |
| 1010 DCHECK(resource->allocated); | 992 DCHECK(resource->allocated); |
| 1011 | 993 |
| 1012 // Mailbox sync_tokens must be processed by a call to | 994 // Mailbox sync_tokens must be processed by a call to |
| 1013 // WaitSyncTokenIfNeeded() prior to calling LockForRead(). | 995 // WaitSyncTokenIfNeeded() prior to calling LockForRead(). |
| 1014 DCHECK_NE(Resource::NEEDS_WAIT, resource->synchronization_state()); | 996 DCHECK_NE(Resource::NEEDS_WAIT, resource->synchronization_state()); |
| 1015 | 997 |
| 1016 LazyCreate(resource); | 998 LazyCreate(resource); |
| 1017 | 999 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1158 GLenum filter) | 1140 GLenum filter) |
| 1159 : resource_lock_(resource_provider, resource_id), | 1141 : resource_lock_(resource_provider, resource_id), |
| 1160 unit_(unit), | 1142 unit_(unit), |
| 1161 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) {} | 1143 target_(resource_provider->BindForSampling(resource_id, unit_, filter)) {} |
| 1162 | 1144 |
| 1163 ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() {} | 1145 ResourceProvider::ScopedSamplerGL::~ScopedSamplerGL() {} |
| 1164 | 1146 |
| 1165 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL( | 1147 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL( |
| 1166 ResourceProvider* resource_provider, | 1148 ResourceProvider* resource_provider, |
| 1167 ResourceId resource_id, | 1149 ResourceId resource_id, |
| 1168 bool create_mailbox) | 1150 bool async_worker_context_enabled) |
|
piman
2017/06/09 22:14:20
nit: I'm not sure the parameter name is just right
| |
| 1169 : resource_provider_(resource_provider), | 1151 : resource_provider_(resource_provider), |
| 1170 resource_id_(resource_id), | 1152 resource_id_(resource_id), |
| 1171 has_sync_token_(false), | 1153 async_worker_context_enabled_(async_worker_context_enabled) { |
| 1172 synchronized_(false) { | |
| 1173 DCHECK(thread_checker_.CalledOnValidThread()); | 1154 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1155 | |
| 1174 Resource* resource = resource_provider->LockForWrite(resource_id); | 1156 Resource* resource = resource_provider->LockForWrite(resource_id); |
| 1175 resource_provider_->LazyAllocate(resource); | 1157 DCHECK(IsGpuResourceType(resource->type)); |
| 1176 if (resource->image_id && resource->dirty_image) | 1158 |
| 1177 resource_provider_->BindImageForSampling(resource); | 1159 if (async_worker_context_enabled) { |
| 1178 if (create_mailbox) { | 1160 resource_provider->LazyCreateMailbox(resource); |
| 1179 resource_provider_->CreateMailboxAndBindResource( | 1161 } else { |
| 1180 resource_provider_->ContextGL(), resource); | 1162 resource_provider->LazyAllocate(resource); |
| 1163 if (resource->image_id && resource->dirty_image) | |
| 1164 resource_provider_->BindImageForSampling(resource); | |
| 1181 } | 1165 } |
| 1166 | |
| 1167 type_ = resource->type; | |
| 1182 texture_id_ = resource->gl_id; | 1168 texture_id_ = resource->gl_id; |
| 1169 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer); | |
| 1170 usage_ = resource->usage; | |
| 1171 image_id_ = resource->image_id; | |
| 1172 bound_image_id_ = resource->bound_image_id; | |
| 1173 dirty_image_ = resource->dirty_image; | |
| 1183 target_ = resource->target; | 1174 target_ = resource->target; |
| 1184 format_ = resource->format; | 1175 format_ = resource->format; |
| 1185 size_ = resource->size; | 1176 size_ = resource->size; |
| 1186 mailbox_ = resource->mailbox(); | 1177 color_space_ = resource->color_space; |
| 1187 color_space_ = resource_provider->GetResourceColorSpaceForRaster(resource); | 1178 color_space_for_raster_ = |
| 1179 resource_provider->GetResourceColorSpaceForRaster(resource); | |
| 1180 hint_ = resource->hint; | |
| 1181 allocated_ = resource->allocated; | |
| 1182 mailbox_ = resource->mailbox().mailbox(); | |
| 1183 set_sync_token_ = false; | |
| 1188 } | 1184 } |
| 1189 | 1185 |
| 1190 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { | 1186 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() { |
| 1191 DCHECK(thread_checker_.CalledOnValidThread()); | 1187 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1192 Resource* resource = resource_provider_->GetResource(resource_id_); | 1188 Resource* resource = resource_provider_->GetResource(resource_id_); |
| 1193 DCHECK(resource->locked_for_write); | 1189 DCHECK(resource->locked_for_write); |
| 1194 // It's not sufficient to check sync_token_.HasData() here because the sync | 1190 |
| 1195 // might be null because of context loss. Even in that case we want to set the | 1191 resource->allocated = allocated_; |
| 1196 // sync token because it's checked in PrepareSendToParent while drawing. | 1192 |
| 1197 if (has_sync_token_) | 1193 if (gpu_memory_buffer_) { |
| 1194 resource_provider_->SetGpuMemoryBuffer(resource, | |
| 1195 std::move(gpu_memory_buffer_)); | |
| 1196 } | |
| 1197 resource->image_id = image_id_; | |
| 1198 resource->bound_image_id = bound_image_id_; | |
| 1199 resource->dirty_image = dirty_image_; | |
| 1200 | |
| 1201 if (set_sync_token_) | |
| 1198 resource->UpdateSyncToken(sync_token_); | 1202 resource->UpdateSyncToken(sync_token_); |
| 1199 if (synchronized_) | 1203 if (!async_worker_context_enabled_) |
| 1200 resource->SetSynchronized(); | 1204 resource->SetSynchronized(); |
| 1205 | |
| 1201 resource_provider_->UnlockForWrite(resource); | 1206 resource_provider_->UnlockForWrite(resource); |
| 1202 } | 1207 } |
| 1203 | 1208 |
| 1204 ResourceProvider::ScopedTextureProvider::ScopedTextureProvider( | 1209 unsigned ResourceProvider::ScopedWriteLockGL::ConsumeTexture( |
| 1205 gpu::gles2::GLES2Interface* gl, | 1210 gpu::gles2::GLES2Interface* gl) { |
| 1206 ScopedWriteLockGL* resource_lock, | 1211 DCHECK(async_worker_context_enabled_); |
| 1207 bool use_mailbox) | 1212 DCHECK(!mailbox_.IsZero()); |
| 1208 : gl_(gl), use_mailbox_(use_mailbox) { | 1213 |
| 1209 if (use_mailbox_) { | 1214 unsigned gl_id = gl->CreateAndConsumeTextureCHROMIUM(target_, mailbox_.name); |
| 1210 texture_id_ = gl_->CreateAndConsumeTextureCHROMIUM( | 1215 DCHECK(gl_id); |
| 1211 resource_lock->target(), resource_lock->mailbox().name()); | 1216 |
| 1212 } else { | 1217 if (!allocated_) { |
| 1213 texture_id_ = resource_lock->texture_id(); | 1218 allocated_ = true; |
| 1219 if (type_ == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { | |
| 1220 DCHECK(!gpu_memory_buffer_); | |
| 1221 DCHECK(!image_id_); | |
| 1222 gpu_memory_buffer_ = resource_provider_->AllocateGpuMemoryBuffer( | |
| 1223 size_, format_, usage_, color_space_); | |
| 1224 image_id_ = resource_provider_->CreateImage(gl, gpu_memory_buffer_.get(), | |
| 1225 size_, format_); | |
| 1226 dirty_image_ = true; | |
| 1227 } else { | |
| 1228 resource_provider_->AllocateGLTexture(gl, gl_id, target_, size_, format_, | |
| 1229 hint_); | |
| 1230 } | |
| 1214 } | 1231 } |
| 1215 DCHECK(texture_id_); | |
| 1216 } | |
| 1217 | 1232 |
| 1218 ResourceProvider::ScopedTextureProvider::~ScopedTextureProvider() { | 1233 if (image_id_ && dirty_image_) { |
| 1219 if (use_mailbox_) | 1234 gl->BindTexture(target_, gl_id); |
| 1220 gl_->DeleteTextures(1, &texture_id_); | 1235 if (bound_image_id_) |
| 1221 } | 1236 gl->ReleaseTexImage2DCHROMIUM(target_, bound_image_id_); |
| 1237 gl->BindTexImage2DCHROMIUM(target_, image_id_); | |
| 1238 bound_image_id_ = image_id_; | |
| 1239 dirty_image_ = false; | |
| 1240 } | |
| 1222 | 1241 |
| 1223 ResourceProvider::ScopedSkSurfaceProvider::ScopedSkSurfaceProvider( | 1242 return gl_id; |
| 1224 ContextProvider* context_provider, | |
| 1225 ScopedWriteLockGL* resource_lock, | |
| 1226 bool use_mailbox, | |
| 1227 bool use_distance_field_text, | |
| 1228 bool can_use_lcd_text, | |
| 1229 int msaa_sample_count) | |
| 1230 : texture_provider_(context_provider->ContextGL(), | |
| 1231 resource_lock, | |
| 1232 use_mailbox) { | |
| 1233 GrGLTextureInfo texture_info; | |
| 1234 texture_info.fID = texture_provider_.texture_id(); | |
| 1235 texture_info.fTarget = resource_lock->target(); | |
| 1236 GrBackendTextureDesc desc; | |
| 1237 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | |
| 1238 desc.fWidth = resource_lock->size().width(); | |
| 1239 desc.fHeight = resource_lock->size().height(); | |
| 1240 desc.fConfig = ToGrPixelConfig(resource_lock->format()); | |
| 1241 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
| 1242 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); | |
| 1243 desc.fSampleCnt = msaa_sample_count; | |
| 1244 | |
| 1245 uint32_t flags = | |
| 1246 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; | |
| 1247 // Use unknown pixel geometry to disable LCD text. | |
| 1248 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); | |
| 1249 if (can_use_lcd_text) { | |
| 1250 // LegacyFontHost will get LCD text and skia figures out what type to use. | |
| 1251 surface_props = | |
| 1252 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); | |
| 1253 } | |
| 1254 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( | |
| 1255 context_provider->GrContext(), desc, nullptr, &surface_props); | |
| 1256 } | |
| 1257 | |
| 1258 ResourceProvider::ScopedSkSurfaceProvider::~ScopedSkSurfaceProvider() { | |
| 1259 if (sk_surface_.get()) { | |
| 1260 sk_surface_->prepareForExternalIO(); | |
| 1261 sk_surface_.reset(); | |
| 1262 } | |
| 1263 } | 1243 } |
| 1264 | 1244 |
| 1265 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 1245 void ResourceProvider::PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
| 1266 const Resource* resource) { | 1246 const Resource* resource) { |
| 1267 DCHECK_EQ(RGBA_8888, resource->format); | 1247 DCHECK_EQ(RGBA_8888, resource->format); |
| 1268 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), | 1248 SkImageInfo info = SkImageInfo::MakeN32Premul(resource->size.width(), |
| 1269 resource->size.height()); | 1249 resource->size.height()); |
| 1270 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); | 1250 sk_bitmap->installPixels(info, resource->pixels, info.minRowBytes()); |
| 1271 } | 1251 } |
| 1272 | 1252 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1318 | 1298 |
| 1319 ResourceProvider::ScopedReadLockSkImage::~ScopedReadLockSkImage() { | 1299 ResourceProvider::ScopedReadLockSkImage::~ScopedReadLockSkImage() { |
| 1320 resource_provider_->UnlockForRead(resource_id_); | 1300 resource_provider_->UnlockForRead(resource_id_); |
| 1321 } | 1301 } |
| 1322 | 1302 |
| 1323 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( | 1303 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware( |
| 1324 ResourceProvider* resource_provider, | 1304 ResourceProvider* resource_provider, |
| 1325 ResourceId resource_id) | 1305 ResourceId resource_id) |
| 1326 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1306 : resource_provider_(resource_provider), resource_id_(resource_id) { |
| 1327 Resource* resource = resource_provider->LockForWrite(resource_id); | 1307 Resource* resource = resource_provider->LockForWrite(resource_id); |
| 1308 color_space_ = resource_provider->GetResourceColorSpaceForRaster(resource); | |
| 1328 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); | 1309 resource_provider->PopulateSkBitmapWithResource(&sk_bitmap_, resource); |
| 1329 color_space_ = resource_provider->GetResourceColorSpaceForRaster(resource); | |
| 1330 DCHECK(valid()); | 1310 DCHECK(valid()); |
| 1331 } | 1311 } |
| 1332 | 1312 |
| 1333 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { | 1313 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() { |
| 1334 DCHECK(thread_checker_.CalledOnValidThread()); | 1314 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1335 Resource* resource = resource_provider_->GetResource(resource_id_); | 1315 Resource* resource = resource_provider_->GetResource(resource_id_); |
| 1336 DCHECK(resource); | |
| 1337 resource->SetSynchronized(); | 1316 resource->SetSynchronized(); |
| 1338 resource_provider_->UnlockForWrite(resource); | 1317 resource_provider_->UnlockForWrite(resource); |
| 1339 } | 1318 } |
| 1340 | 1319 |
| 1341 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | 1320 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
| 1342 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, | 1321 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, |
| 1343 ResourceId resource_id) | 1322 ResourceId resource_id) |
| 1344 : resource_provider_(resource_provider), resource_id_(resource_id) { | 1323 : resource_provider_(resource_provider), resource_id_(resource_id) { |
| 1345 Resource* resource = resource_provider->LockForWrite(resource_id); | 1324 Resource* resource = resource_provider->LockForWrite(resource_id); |
| 1346 DCHECK(IsGpuResourceType(resource->type)); | 1325 DCHECK_EQ(resource->type, ResourceProvider::RESOURCE_TYPE_GPU_MEMORY_BUFFER); |
| 1326 size_ = resource->size; | |
| 1347 format_ = resource->format; | 1327 format_ = resource->format; |
| 1348 size_ = resource->size; | |
| 1349 usage_ = resource->usage; | 1328 usage_ = resource->usage; |
| 1329 color_space_ = resource_provider->GetResourceColorSpaceForRaster(resource); | |
| 1350 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer); | 1330 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer); |
| 1351 resource->gpu_memory_buffer = nullptr; | |
| 1352 color_space_ = resource_provider->GetResourceColorSpaceForRaster(resource); | |
| 1353 } | 1331 } |
| 1354 | 1332 |
| 1355 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: | 1333 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: |
| 1356 ~ScopedWriteLockGpuMemoryBuffer() { | 1334 ~ScopedWriteLockGpuMemoryBuffer() { |
| 1357 DCHECK(thread_checker_.CalledOnValidThread()); | 1335 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1358 Resource* resource = resource_provider_->GetResource(resource_id_); | 1336 Resource* resource = resource_provider_->GetResource(resource_id_); |
| 1359 DCHECK(resource); | |
| 1360 if (gpu_memory_buffer_) { | 1337 if (gpu_memory_buffer_) { |
| 1361 // Note that this impacts overlay compositing, not rasterization. | 1338 resource_provider_->SetGpuMemoryBuffer(resource, |
| 1362 if (resource_provider_->settings_.enable_color_correct_rasterization) | 1339 std::move(gpu_memory_buffer_)); |
| 1363 gpu_memory_buffer_->SetColorSpaceForScanout(resource->color_space); | |
| 1364 DCHECK(!resource->gpu_memory_buffer); | |
| 1365 resource_provider_->LazyCreate(resource); | |
| 1366 resource->gpu_memory_buffer = std::move(gpu_memory_buffer_); | |
| 1367 resource->allocated = true; | |
| 1368 resource_provider_->LazyCreateImage(resource); | 1340 resource_provider_->LazyCreateImage(resource); |
| 1369 resource->dirty_image = true; | 1341 resource->dirty_image = true; |
| 1370 resource->is_overlay_candidate = true; | |
| 1371 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | |
| 1372 // Read lock fences are required to ensure that we're not trying to map a | |
| 1373 // buffer that is currently in-use by the GPU. | |
| 1374 resource->read_lock_fences_enabled = true; | |
| 1375 } | 1342 } |
| 1376 resource->SetSynchronized(); | 1343 resource->SetSynchronized(); |
| 1377 resource_provider_->UnlockForWrite(resource); | 1344 resource_provider_->UnlockForWrite(resource); |
| 1378 } | 1345 } |
| 1379 | 1346 |
| 1380 gfx::GpuMemoryBuffer* | 1347 gfx::GpuMemoryBuffer* |
| 1381 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::GetGpuMemoryBuffer() { | 1348 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::GetGpuMemoryBuffer() { |
| 1382 if (!gpu_memory_buffer_) { | 1349 if (!gpu_memory_buffer_) { |
| 1383 gpu_memory_buffer_ = | 1350 gpu_memory_buffer_ = resource_provider_->AllocateGpuMemoryBuffer( |
| 1384 resource_provider_->gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( | 1351 size_, format_, usage_, color_space_); |
| 1385 size_, BufferFormat(format_), usage_, gpu::kNullSurfaceHandle); | |
| 1386 } | 1352 } |
| 1387 return gpu_memory_buffer_.get(); | 1353 return gpu_memory_buffer_.get(); |
| 1388 } | 1354 } |
| 1389 | 1355 |
| 1390 ResourceProvider::ScopedBatchReturnResources::ScopedBatchReturnResources( | 1356 ResourceProvider::ScopedBatchReturnResources::ScopedBatchReturnResources( |
| 1391 ResourceProvider* resource_provider) | 1357 ResourceProvider* resource_provider) |
| 1392 : resource_provider_(resource_provider) { | 1358 : resource_provider_(resource_provider) { |
| 1393 resource_provider_->SetBatchReturnResources(true); | 1359 resource_provider_->SetBatchReturnResources(true); |
| 1394 } | 1360 } |
| 1395 | 1361 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1495 !resource->needs_sync_token()); | 1461 !resource->needs_sync_token()); |
| 1496 | 1462 |
| 1497 // If we are validating the resource to be sent, the resource cannot be | 1463 // If we are validating the resource to be sent, the resource cannot be |
| 1498 // in a LOCALLY_USED state. It must have been properly synchronized. | 1464 // in a LOCALLY_USED state. It must have been properly synchronized. |
| 1499 DCHECK(!settings_.delegated_sync_points_required || | 1465 DCHECK(!settings_.delegated_sync_points_required || |
| 1500 Resource::LOCALLY_USED != resource->synchronization_state()); | 1466 Resource::LOCALLY_USED != resource->synchronization_state()); |
| 1501 | 1467 |
| 1502 resources.push_back(resource); | 1468 resources.push_back(resource); |
| 1503 } | 1469 } |
| 1504 | 1470 |
| 1505 // Lazily create any mailboxes and verify all unverified sync tokens. | 1471 // Lazily create any mailboxes and verify all unverified sync tokens. Also |
| 1472 // upload GMB resources to GPU if necessary. | |
| 1506 std::vector<GLbyte*> unverified_sync_tokens; | 1473 std::vector<GLbyte*> unverified_sync_tokens; |
| 1507 std::vector<Resource*> need_synchronization_resources; | 1474 std::vector<Resource*> need_synchronization_resources; |
| 1508 for (Resource* resource : resources) { | 1475 for (Resource* resource : resources) { |
| 1509 if (!IsGpuResourceType(resource->type)) | 1476 if (!IsGpuResourceType(resource->type)) |
| 1510 continue; | 1477 continue; |
| 1511 | 1478 |
| 1512 CreateMailboxAndBindResource(gl, resource); | 1479 LazyCreateMailbox(resource); |
| 1480 | |
| 1481 if (resource->image_id && resource->dirty_image) | |
| 1482 BindImageForSampling(resource); | |
| 1513 | 1483 |
| 1514 if (settings_.delegated_sync_points_required) { | 1484 if (settings_.delegated_sync_points_required) { |
| 1515 if (resource->needs_sync_token()) { | 1485 if (resource->needs_sync_token()) { |
| 1516 need_synchronization_resources.push_back(resource); | 1486 need_synchronization_resources.push_back(resource); |
| 1517 } else if (resource->mailbox().HasSyncToken() && | 1487 } else if (resource->mailbox().HasSyncToken() && |
| 1518 !resource->mailbox().sync_token().verified_flush()) { | 1488 !resource->mailbox().sync_token().verified_flush()) { |
| 1519 unverified_sync_tokens.push_back(resource->GetSyncTokenData()); | 1489 unverified_sync_tokens.push_back(resource->GetSyncTokenData()); |
| 1520 } | 1490 } |
| 1521 } | 1491 } |
| 1522 } | 1492 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1669 CHECK_GE(resource->exported_count, returned.count); | 1639 CHECK_GE(resource->exported_count, returned.count); |
| 1670 resource->exported_count -= returned.count; | 1640 resource->exported_count -= returned.count; |
| 1671 resource->lost |= returned.lost; | 1641 resource->lost |= returned.lost; |
| 1672 if (resource->exported_count) | 1642 if (resource->exported_count) |
| 1673 continue; | 1643 continue; |
| 1674 | 1644 |
| 1675 if (returned.sync_token.HasData()) { | 1645 if (returned.sync_token.HasData()) { |
| 1676 DCHECK(!resource->has_shared_bitmap_id); | 1646 DCHECK(!resource->has_shared_bitmap_id); |
| 1677 if (resource->origin == Resource::INTERNAL) { | 1647 if (resource->origin == Resource::INTERNAL) { |
| 1678 DCHECK(resource->gl_id); | 1648 DCHECK(resource->gl_id); |
| 1679 DCHECK(returned.sync_token.HasData()); | |
| 1680 gl->WaitSyncTokenCHROMIUM(returned.sync_token.GetConstData()); | 1649 gl->WaitSyncTokenCHROMIUM(returned.sync_token.GetConstData()); |
| 1681 resource->SetSynchronized(); | |
|
piman
2017/06/09 22:14:20
Why are we removing this one? Won't this cause ext
| |
| 1682 } else { | 1650 } else { |
| 1683 DCHECK(!resource->gl_id); | 1651 DCHECK(!resource->gl_id); |
| 1684 resource->UpdateSyncToken(returned.sync_token); | 1652 resource->UpdateSyncToken(returned.sync_token); |
| 1685 } | 1653 } |
| 1686 } | 1654 } |
| 1687 | 1655 |
| 1688 if (!resource->marked_for_deletion) | 1656 if (!resource->marked_for_deletion) |
| 1689 continue; | 1657 continue; |
| 1690 | 1658 |
| 1691 if (!resource->child_id) { | 1659 if (!resource->child_id) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1743 bool promotable = iter != promotion_hints.end(); | 1711 bool promotable = iter != promotion_hints.end(); |
| 1744 gl->OverlayPromotionHintCHROMIUM(resource->gl_id, promotable, | 1712 gl->OverlayPromotionHintCHROMIUM(resource->gl_id, promotable, |
| 1745 promotable ? iter->second.x() : 0, | 1713 promotable ? iter->second.x() : 0, |
| 1746 promotable ? iter->second.y() : 0); | 1714 promotable ? iter->second.y() : 0); |
| 1747 } | 1715 } |
| 1748 UnlockForRead(id); | 1716 UnlockForRead(id); |
| 1749 } | 1717 } |
| 1750 } | 1718 } |
| 1751 #endif | 1719 #endif |
| 1752 | 1720 |
| 1753 void ResourceProvider::CreateMailboxAndBindResource( | |
| 1754 gpu::gles2::GLES2Interface* gl, | |
| 1755 Resource* resource) { | |
| 1756 DCHECK(IsGpuResourceType(resource->type)); | |
| 1757 DCHECK(gl); | |
| 1758 | |
| 1759 if (!resource->mailbox().IsValid()) { | |
| 1760 LazyCreate(resource); | |
| 1761 | |
| 1762 gpu::MailboxHolder mailbox_holder; | |
| 1763 mailbox_holder.texture_target = resource->target; | |
| 1764 gl->GenMailboxCHROMIUM(mailbox_holder.mailbox.name); | |
| 1765 gl->ProduceTextureDirectCHROMIUM(resource->gl_id, | |
| 1766 mailbox_holder.texture_target, | |
| 1767 mailbox_holder.mailbox.name); | |
| 1768 resource->set_mailbox(TextureMailbox(mailbox_holder)); | |
| 1769 } | |
| 1770 | |
| 1771 if (resource->image_id && resource->dirty_image) { | |
| 1772 DCHECK(resource->gl_id); | |
| 1773 DCHECK(resource->origin == Resource::INTERNAL); | |
| 1774 BindImageForSampling(resource); | |
| 1775 } | |
| 1776 } | |
| 1777 | |
| 1778 void ResourceProvider::TransferResource(Resource* source, | 1721 void ResourceProvider::TransferResource(Resource* source, |
| 1779 ResourceId id, | 1722 ResourceId id, |
| 1780 TransferableResource* resource) { | 1723 TransferableResource* resource) { |
| 1781 DCHECK(!source->locked_for_write); | 1724 DCHECK(!source->locked_for_write); |
| 1782 DCHECK(!source->lock_for_read_count); | 1725 DCHECK(!source->lock_for_read_count); |
| 1783 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox().IsValid()); | 1726 DCHECK(source->origin != Resource::EXTERNAL || source->mailbox().IsValid()); |
| 1784 DCHECK(source->allocated); | 1727 DCHECK(source->allocated); |
| 1785 resource->id = id; | 1728 resource->id = id; |
| 1786 resource->format = source->format; | 1729 resource->format = source->format; |
| 1787 resource->buffer_format = source->buffer_format; | 1730 resource->buffer_format = source->buffer_format; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1961 if (!IsGpuResourceType(resource->type) || | 1904 if (!IsGpuResourceType(resource->type) || |
| 1962 resource->origin != Resource::INTERNAL) | 1905 resource->origin != Resource::INTERNAL) |
| 1963 return; | 1906 return; |
| 1964 | 1907 |
| 1965 if (resource->gl_id) | 1908 if (resource->gl_id) |
| 1966 return; | 1909 return; |
| 1967 | 1910 |
| 1968 DCHECK(resource->origin == Resource::INTERNAL); | 1911 DCHECK(resource->origin == Resource::INTERNAL); |
| 1969 DCHECK(!resource->mailbox().IsValid()); | 1912 DCHECK(!resource->mailbox().IsValid()); |
| 1970 resource->gl_id = texture_id_allocator_->NextId(); | 1913 resource->gl_id = texture_id_allocator_->NextId(); |
| 1914 DCHECK(resource->gl_id); | |
| 1971 | 1915 |
| 1972 GLES2Interface* gl = ContextGL(); | 1916 GLES2Interface* gl = ContextGL(); |
| 1973 DCHECK(gl); | 1917 DCHECK(gl); |
| 1974 | 1918 |
| 1975 // Create and set texture properties. Allocation is delayed until needed. | 1919 // Create and set texture properties. Allocation is delayed until needed. |
| 1976 gl->BindTexture(resource->target, resource->gl_id); | 1920 gl->BindTexture(resource->target, resource->gl_id); |
| 1977 gl->TexParameteri(resource->target, GL_TEXTURE_MIN_FILTER, | 1921 gl->TexParameteri(resource->target, GL_TEXTURE_MIN_FILTER, |
| 1978 resource->original_filter); | 1922 resource->original_filter); |
| 1979 gl->TexParameteri(resource->target, GL_TEXTURE_MAG_FILTER, | 1923 gl->TexParameteri(resource->target, GL_TEXTURE_MAG_FILTER, |
| 1980 resource->original_filter); | 1924 resource->original_filter); |
| 1981 gl->TexParameteri(resource->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 1925 gl->TexParameteri(resource->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1982 gl->TexParameteri(resource->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 1926 gl->TexParameteri(resource->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
| 1983 if (settings_.use_texture_usage_hint && | 1927 if (settings_.use_texture_usage_hint && |
| 1984 (resource->hint & TEXTURE_HINT_FRAMEBUFFER)) { | 1928 (resource->hint & TEXTURE_HINT_FRAMEBUFFER)) { |
| 1985 gl->TexParameteri(resource->target, GL_TEXTURE_USAGE_ANGLE, | 1929 gl->TexParameteri(resource->target, GL_TEXTURE_USAGE_ANGLE, |
| 1986 GL_FRAMEBUFFER_ATTACHMENT_ANGLE); | 1930 GL_FRAMEBUFFER_ATTACHMENT_ANGLE); |
| 1987 } | 1931 } |
| 1988 } | 1932 } |
| 1989 | 1933 |
| 1934 void ResourceProvider::LazyCreateMailbox(Resource* resource) { | |
| 1935 DCHECK(resource); | |
| 1936 if (resource->mailbox().IsValid()) | |
| 1937 return; | |
| 1938 | |
| 1939 LazyCreate(resource); | |
| 1940 DCHECK(resource->gl_id); | |
| 1941 | |
| 1942 gpu::gles2::GLES2Interface* gl = ContextGL(); | |
| 1943 DCHECK(gl); | |
| 1944 | |
| 1945 gpu::MailboxHolder mailbox_holder; | |
| 1946 mailbox_holder.texture_target = resource->target; | |
| 1947 gl->GenMailboxCHROMIUM(mailbox_holder.mailbox.name); | |
| 1948 gl->ProduceTextureDirectCHROMIUM(resource->gl_id, | |
| 1949 mailbox_holder.texture_target, | |
| 1950 mailbox_holder.mailbox.name); | |
| 1951 resource->set_mailbox(TextureMailbox(mailbox_holder)); | |
| 1952 } | |
| 1953 | |
| 1990 void ResourceProvider::AllocateForTesting(ResourceId id) { | 1954 void ResourceProvider::AllocateForTesting(ResourceId id) { |
| 1991 LazyAllocate(GetResource(id)); | 1955 LazyAllocate(GetResource(id)); |
| 1992 } | 1956 } |
| 1993 | 1957 |
| 1994 void ResourceProvider::LazyAllocate(Resource* resource) { | 1958 void ResourceProvider::LazyAllocate(Resource* resource) { |
| 1995 DCHECK(resource); | 1959 DCHECK(resource); |
| 1996 if (resource->allocated) | 1960 if (resource->allocated) |
| 1997 return; | 1961 return; |
| 1998 LazyCreate(resource); | 1962 // Bitmap resources are always allocated on initialization. |
| 1999 if (!resource->gl_id) | 1963 DCHECK(IsGpuResourceType(resource->type)); |
| 2000 return; | |
| 2001 resource->allocated = true; | 1964 resource->allocated = true; |
| 2002 GLES2Interface* gl = ContextGL(); | 1965 |
| 2003 gfx::Size& size = resource->size; | |
| 2004 ResourceFormat format = resource->format; | |
| 2005 gl->BindTexture(resource->target, resource->gl_id); | |
| 2006 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { | 1966 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { |
| 2007 resource->gpu_memory_buffer = | 1967 SetGpuMemoryBuffer(resource, AllocateGpuMemoryBuffer( |
| 2008 gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( | 1968 resource->size, resource->format, |
| 2009 size, BufferFormat(format), resource->usage, | 1969 resource->usage, resource->color_space)); |
| 2010 gpu::kNullSurfaceHandle); | |
| 2011 // Note that this impacts overlay compositing, not rasterization. | |
| 2012 if (resource->gpu_memory_buffer && | |
| 2013 settings_.enable_color_correct_rasterization) { | |
| 2014 resource->gpu_memory_buffer->SetColorSpaceForScanout( | |
| 2015 resource->color_space); | |
| 2016 } | |
| 2017 | |
| 2018 LazyCreateImage(resource); | 1970 LazyCreateImage(resource); |
| 2019 resource->dirty_image = true; | |
| 2020 resource->is_overlay_candidate = true; | |
| 2021 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | |
| 2022 // Read lock fences are required to ensure that we're not trying to map a | |
| 2023 // buffer that is currently in-use by the GPU. | |
| 2024 resource->read_lock_fences_enabled = true; | |
| 2025 } else if (settings_.use_texture_storage_ext && | |
| 2026 IsFormatSupportedForStorage(format, | |
| 2027 settings_.use_texture_format_bgra) && | |
| 2028 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { | |
| 2029 GLenum storage_format = TextureToStorageFormat(format); | |
| 2030 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), | |
| 2031 size.height()); | |
| 2032 } else { | 1971 } else { |
| 2033 // ETC1 does not support preallocation. | 1972 LazyCreate(resource); |
| 2034 if (format != ETC1) { | 1973 AllocateGLTexture(ContextGL(), resource->gl_id, resource->target, |
| 2035 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), | 1974 resource->size, resource->format, resource->hint); |
| 2036 size.width(), size.height(), 0, GLDataFormat(format), | |
| 2037 GLDataType(format), nullptr); | |
| 2038 } | |
| 2039 } | 1975 } |
| 2040 } | 1976 } |
| 2041 | 1977 |
| 2042 void ResourceProvider::LazyCreateImage(Resource* resource) { | 1978 void ResourceProvider::AllocateGLTexture(gpu::gles2::GLES2Interface* gl, |
| 2043 DCHECK(resource->gpu_memory_buffer); | 1979 unsigned gl_id, |
| 2044 DCHECK(resource->gl_id); | 1980 GLenum target, |
| 2045 DCHECK(resource->allocated); | 1981 const gfx::Size& size, |
| 2046 // Avoid crashing in release builds if GpuMemoryBuffer allocation fails. | 1982 ResourceFormat format, |
| 2047 // http://crbug.com/554541 | 1983 TextureHint hint) { |
| 2048 if (!resource->gpu_memory_buffer) | 1984 if (settings_.use_texture_storage_ext && |
| 2049 return; | 1985 IsFormatSupportedForStorage(format, settings_.use_texture_format_bgra) && |
| 2050 if (!resource->image_id) { | 1986 (hint & TEXTURE_HINT_IMMUTABLE)) { |
| 2051 GLES2Interface* gl = ContextGL(); | 1987 GLenum storage_format = TextureToStorageFormat(format); |
| 2052 DCHECK(gl); | 1988 gl->BindTexture(target, gl_id); |
| 2053 | 1989 gl->TexStorage2DEXT(target, 1, storage_format, size.width(), size.height()); |
| 2054 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | 1990 } else if (format != ETC1) { |
| 2055 // TODO(reveman): This avoids a performance problem on ARM ChromeOS | 1991 // ETC1 does not support preallocation. |
| 2056 // devices. This only works with shared memory backed buffers. | 1992 gl->BindTexture(target, gl_id); |
| 2057 // crbug.com/580166 | 1993 gl->TexImage2D(target, 0, GLInternalFormat(format), size.width(), |
| 2058 DCHECK_EQ(resource->gpu_memory_buffer->GetHandle().type, | 1994 size.height(), 0, GLDataFormat(format), GLDataType(format), |
| 2059 gfx::SHARED_MEMORY_BUFFER); | 1995 nullptr); |
| 2060 #endif | |
| 2061 resource->image_id = gl->CreateImageCHROMIUM( | |
| 2062 resource->gpu_memory_buffer->AsClientBuffer(), resource->size.width(), | |
| 2063 resource->size.height(), GLInternalFormat(resource->format)); | |
| 2064 DCHECK(resource->image_id || IsGLContextLost()); | |
| 2065 | |
| 2066 resource->SetLocallyUsed(); | |
| 2067 } | 1996 } |
| 2068 } | 1997 } |
| 2069 | 1998 |
| 1999 std::unique_ptr<gfx::GpuMemoryBuffer> ResourceProvider::AllocateGpuMemoryBuffer( | |
| 2000 const gfx::Size& size, | |
| 2001 ResourceFormat format, | |
| 2002 gfx::BufferUsage usage, | |
| 2003 gfx::ColorSpace color_space) { | |
| 2004 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer = | |
| 2005 gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( | |
| 2006 size, BufferFormat(format), usage, gpu::kNullSurfaceHandle); | |
| 2007 // Note that this impacts overlay compositing, not rasterization. | |
| 2008 if (settings_.enable_color_correct_rasterization) | |
| 2009 gpu_memory_buffer->SetColorSpaceForScanout(color_space); | |
| 2010 return gpu_memory_buffer; | |
| 2011 } | |
| 2012 | |
| 2013 void ResourceProvider::SetGpuMemoryBuffer( | |
| 2014 Resource* resource, | |
| 2015 std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer) { | |
| 2016 DCHECK(gpu_memory_buffer); | |
| 2017 DCHECK(resource->locked_for_write); | |
| 2018 DCHECK(!resource->gpu_memory_buffer); | |
| 2019 resource->gpu_memory_buffer = std::move(gpu_memory_buffer); | |
| 2020 resource->allocated = true; | |
| 2021 resource->is_overlay_candidate = true; | |
| 2022 // GpuMemoryBuffer provides direct access to the memory used by the GPU. | |
| 2023 // Read lock fences are required to ensure that we're not trying to map a | |
| 2024 // buffer that is currently in-use by the GPU. | |
| 2025 resource->read_lock_fences_enabled = true; | |
| 2026 } | |
| 2027 | |
| 2028 unsigned ResourceProvider::CreateImage(gpu::gles2::GLES2Interface* gl, | |
| 2029 gfx::GpuMemoryBuffer* gpu_memory_buffer, | |
| 2030 const gfx::Size& size, | |
| 2031 ResourceFormat format) { | |
| 2032 DCHECK(gl); | |
| 2033 DCHECK(gpu_memory_buffer); | |
| 2034 // Avoid crashing in release builds if GpuMemoryBuffer allocation fails. | |
| 2035 // http://crbug.com/554541 | |
| 2036 if (!gpu_memory_buffer) | |
| 2037 return 0; | |
| 2038 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY) | |
| 2039 // TODO(reveman): This avoids a performance problem on ARM ChromeOS | |
| 2040 // devices. This only works with shared memory backed buffers. | |
| 2041 // crbug.com/580166 | |
| 2042 DCHECK_EQ(gpu_memory_buffer->GetHandle().type, gfx::SHARED_MEMORY_BUFFER); | |
| 2043 #endif | |
| 2044 unsigned image_id = | |
| 2045 gl->CreateImageCHROMIUM(gpu_memory_buffer->AsClientBuffer(), size.width(), | |
| 2046 size.height(), GLInternalFormat(format)); | |
| 2047 DCHECK(image_id || gl->GetGraphicsResetStatusKHR() != GL_NO_ERROR); | |
| 2048 return image_id; | |
| 2049 } | |
| 2050 | |
| 2051 void ResourceProvider::LazyCreateImage(Resource* resource) { | |
| 2052 DCHECK(resource); | |
| 2053 if (resource->image_id) | |
| 2054 return; | |
| 2055 | |
| 2056 LazyCreate(resource); | |
| 2057 DCHECK(resource->gl_id); | |
| 2058 | |
| 2059 resource->image_id = | |
| 2060 CreateImage(ContextGL(), resource->gpu_memory_buffer.get(), | |
| 2061 resource->size, resource->format); | |
| 2062 resource->dirty_image = true; | |
| 2063 } | |
| 2064 | |
| 2070 void ResourceProvider::BindImageForSampling(Resource* resource) { | 2065 void ResourceProvider::BindImageForSampling(Resource* resource) { |
| 2071 GLES2Interface* gl = ContextGL(); | |
| 2072 DCHECK(resource->gl_id); | 2066 DCHECK(resource->gl_id); |
| 2073 DCHECK(resource->image_id); | 2067 DCHECK(resource->image_id); |
| 2074 | 2068 |
| 2069 gpu::gles2::GLES2Interface* gl = ContextGL(); | |
| 2070 DCHECK(gl); | |
| 2071 | |
| 2075 // Release image currently bound to texture. | 2072 // Release image currently bound to texture. |
| 2076 gl->BindTexture(resource->target, resource->gl_id); | 2073 gl->BindTexture(resource->target, resource->gl_id); |
| 2077 if (resource->bound_image_id) | 2074 if (resource->bound_image_id) |
| 2078 gl->ReleaseTexImage2DCHROMIUM(resource->target, resource->bound_image_id); | 2075 gl->ReleaseTexImage2DCHROMIUM(resource->target, resource->bound_image_id); |
| 2079 gl->BindTexImage2DCHROMIUM(resource->target, resource->image_id); | 2076 gl->BindTexImage2DCHROMIUM(resource->target, resource->image_id); |
| 2080 resource->bound_image_id = resource->image_id; | 2077 resource->bound_image_id = resource->image_id; |
| 2081 resource->dirty_image = false; | 2078 resource->dirty_image = false; |
| 2082 resource->SetLocallyUsed(); | 2079 resource->SetLocallyUsed(); |
| 2083 } | 2080 } |
| 2084 | 2081 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2194 | 2191 |
| 2195 const int kImportance = 2; | 2192 const int kImportance = 2; |
| 2196 pmd->CreateSharedGlobalAllocatorDump(guid); | 2193 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 2197 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2194 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 2198 } | 2195 } |
| 2199 | 2196 |
| 2200 return true; | 2197 return true; |
| 2201 } | 2198 } |
| 2202 | 2199 |
| 2203 } // namespace cc | 2200 } // namespace cc |
| OLD | NEW |