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