| 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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 | 376 |
| 377 ResourceProvider::Child::Child() | 377 ResourceProvider::Child::Child() |
| 378 : gpu_memory_buffer_client_id(-1), | 378 : gpu_memory_buffer_client_id(-1), |
| 379 marked_for_deletion(false), | 379 marked_for_deletion(false), |
| 380 needs_sync_tokens(true) {} | 380 needs_sync_tokens(true) {} |
| 381 | 381 |
| 382 ResourceProvider::Child::Child(const Child& other) = default; | 382 ResourceProvider::Child::Child(const Child& other) = default; |
| 383 | 383 |
| 384 ResourceProvider::Child::~Child() {} | 384 ResourceProvider::Child::~Child() {} |
| 385 | 385 |
| 386 std::unique_ptr<ResourceProvider> ResourceProvider::Create( | 386 ResourceProvider::ResourceProvider( |
| 387 OutputSurface* output_surface, | 387 ContextProvider* compositor_context_provider, |
| 388 SharedBitmapManager* shared_bitmap_manager, | 388 SharedBitmapManager* shared_bitmap_manager, |
| 389 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 389 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 390 BlockingTaskRunner* blocking_main_thread_task_runner, | 390 BlockingTaskRunner* blocking_main_thread_task_runner, |
| 391 int highp_threshold_min, | 391 int highp_threshold_min, |
| 392 size_t id_allocation_chunk_size, | 392 size_t id_allocation_chunk_size, |
| 393 bool delegated_sync_points_required, |
| 393 bool use_gpu_memory_buffer_resources, | 394 bool use_gpu_memory_buffer_resources, |
| 394 const std::vector<unsigned>& use_image_texture_targets) { | 395 const std::vector<unsigned>& use_image_texture_targets) |
| 395 std::unique_ptr<ResourceProvider> resource_provider(new ResourceProvider( | 396 : compositor_context_provider_(compositor_context_provider), |
| 396 output_surface, shared_bitmap_manager, gpu_memory_buffer_manager, | 397 shared_bitmap_manager_(shared_bitmap_manager), |
| 397 blocking_main_thread_task_runner, highp_threshold_min, | 398 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), |
| 398 id_allocation_chunk_size, use_gpu_memory_buffer_resources, | 399 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), |
| 399 use_image_texture_targets)); | 400 lost_output_surface_(false), |
| 400 resource_provider->Initialize(); | 401 highp_threshold_min_(highp_threshold_min), |
| 401 return resource_provider; | 402 next_id_(1), |
| 403 next_child_(1), |
| 404 delegated_sync_points_required_(delegated_sync_points_required), |
| 405 default_resource_type_(use_gpu_memory_buffer_resources |
| 406 ? RESOURCE_TYPE_GPU_MEMORY_BUFFER |
| 407 : RESOURCE_TYPE_GL_TEXTURE), |
| 408 use_texture_storage_ext_(false), |
| 409 use_texture_format_bgra_(false), |
| 410 use_texture_usage_hint_(false), |
| 411 use_compressed_texture_etc1_(false), |
| 412 yuv_resource_format_(LUMINANCE_8), |
| 413 max_texture_size_(0), |
| 414 best_texture_format_(RGBA_8888), |
| 415 best_render_buffer_format_(RGBA_8888), |
| 416 id_allocation_chunk_size_(id_allocation_chunk_size), |
| 417 use_sync_query_(false), |
| 418 use_image_texture_targets_(use_image_texture_targets), |
| 419 tracing_id_(g_next_resource_provider_tracing_id.GetNext()) { |
| 420 DCHECK(id_allocation_chunk_size_); |
| 421 DCHECK(thread_checker_.CalledOnValidThread()); |
| 422 |
| 423 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). |
| 424 // Don't register a dump provider in these cases. |
| 425 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 |
| 426 if (base::ThreadTaskRunnerHandle::IsSet()) { |
| 427 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| 428 this, "cc::ResourceProvider", base::ThreadTaskRunnerHandle::Get()); |
| 429 } |
| 430 |
| 431 if (!compositor_context_provider_) { |
| 432 default_resource_type_ = RESOURCE_TYPE_BITMAP; |
| 433 // Pick an arbitrary limit here similar to what hardware might. |
| 434 max_texture_size_ = 16 * 1024; |
| 435 best_texture_format_ = RGBA_8888; |
| 436 return; |
| 437 } |
| 438 |
| 439 DCHECK(!texture_id_allocator_); |
| 440 DCHECK(!buffer_id_allocator_); |
| 441 |
| 442 const auto& caps = compositor_context_provider_->ContextCapabilities(); |
| 443 |
| 444 DCHECK(IsGpuResourceType(default_resource_type_)); |
| 445 use_texture_storage_ext_ = caps.texture_storage; |
| 446 use_texture_format_bgra_ = caps.texture_format_bgra8888; |
| 447 use_texture_usage_hint_ = caps.texture_usage; |
| 448 use_compressed_texture_etc1_ = caps.texture_format_etc1; |
| 449 yuv_resource_format_ = caps.texture_rg ? RED_8 : LUMINANCE_8; |
| 450 yuv_highbit_resource_format_ = yuv_resource_format_; |
| 451 if (caps.texture_half_float_linear) |
| 452 yuv_highbit_resource_format_ = LUMINANCE_F16; |
| 453 use_sync_query_ = caps.sync_query; |
| 454 |
| 455 GLES2Interface* gl = ContextGL(); |
| 456 |
| 457 max_texture_size_ = 0; // Context expects cleared value. |
| 458 gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_); |
| 459 best_texture_format_ = |
| 460 PlatformColor::BestSupportedTextureFormat(use_texture_format_bgra_); |
| 461 |
| 462 best_render_buffer_format_ = PlatformColor::BestSupportedTextureFormat( |
| 463 caps.render_buffer_format_bgra8888); |
| 464 |
| 465 texture_id_allocator_.reset( |
| 466 new TextureIdAllocator(gl, id_allocation_chunk_size_)); |
| 467 buffer_id_allocator_.reset( |
| 468 new BufferIdAllocator(gl, id_allocation_chunk_size_)); |
| 402 } | 469 } |
| 403 | 470 |
| 404 ResourceProvider::~ResourceProvider() { | 471 ResourceProvider::~ResourceProvider() { |
| 405 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 472 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| 406 this); | 473 this); |
| 407 | 474 |
| 408 while (!children_.empty()) | 475 while (!children_.empty()) |
| 409 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN); | 476 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN); |
| 410 while (!resources_.empty()) | 477 while (!resources_.empty()) |
| 411 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN); | 478 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 426 } | 493 } |
| 427 #endif // DCHECK_IS_ON() | 494 #endif // DCHECK_IS_ON() |
| 428 | 495 |
| 429 texture_id_allocator_ = nullptr; | 496 texture_id_allocator_ = nullptr; |
| 430 buffer_id_allocator_ = nullptr; | 497 buffer_id_allocator_ = nullptr; |
| 431 gl->Finish(); | 498 gl->Finish(); |
| 432 } | 499 } |
| 433 | 500 |
| 434 bool ResourceProvider::IsResourceFormatSupported(ResourceFormat format) const { | 501 bool ResourceProvider::IsResourceFormatSupported(ResourceFormat format) const { |
| 435 gpu::Capabilities caps; | 502 gpu::Capabilities caps; |
| 436 if (output_surface_->context_provider()) | 503 if (compositor_context_provider_) |
| 437 caps = output_surface_->context_provider()->ContextCapabilities(); | 504 caps = compositor_context_provider_->ContextCapabilities(); |
| 438 | 505 |
| 439 switch (format) { | 506 switch (format) { |
| 440 case ALPHA_8: | 507 case ALPHA_8: |
| 441 case RGBA_4444: | 508 case RGBA_4444: |
| 442 case RGBA_8888: | 509 case RGBA_8888: |
| 443 case RGB_565: | 510 case RGB_565: |
| 444 case LUMINANCE_8: | 511 case LUMINANCE_8: |
| 445 return true; | 512 return true; |
| 446 case BGRA_8888: | 513 case BGRA_8888: |
| 447 return caps.texture_format_bgra8888; | 514 return caps.texture_format_bgra8888; |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { | 1218 ResourceProvider::ScopedWriteLockGr::~ScopedWriteLockGr() { |
| 1152 DCHECK(thread_checker_.CalledOnValidThread()); | 1219 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1153 DCHECK(resource_->locked_for_write); | 1220 DCHECK(resource_->locked_for_write); |
| 1154 if (set_sync_token_) | 1221 if (set_sync_token_) |
| 1155 resource_->UpdateSyncToken(sync_token_); | 1222 resource_->UpdateSyncToken(sync_token_); |
| 1156 | 1223 |
| 1157 resource_provider_->UnlockForWrite(resource_); | 1224 resource_provider_->UnlockForWrite(resource_); |
| 1158 } | 1225 } |
| 1159 | 1226 |
| 1160 void ResourceProvider::ScopedWriteLockGr::InitSkSurface( | 1227 void ResourceProvider::ScopedWriteLockGr::InitSkSurface( |
| 1228 GrContext* gr_context, |
| 1161 bool use_distance_field_text, | 1229 bool use_distance_field_text, |
| 1162 bool can_use_lcd_text, | 1230 bool can_use_lcd_text, |
| 1163 int msaa_sample_count) { | 1231 int msaa_sample_count) { |
| 1164 DCHECK(resource_->locked_for_write); | 1232 DCHECK(resource_->locked_for_write); |
| 1165 | 1233 |
| 1166 GrGLTextureInfo texture_info; | 1234 GrGLTextureInfo texture_info; |
| 1167 texture_info.fID = resource_->gl_id; | 1235 texture_info.fID = resource_->gl_id; |
| 1168 texture_info.fTarget = resource_->target; | 1236 texture_info.fTarget = resource_->target; |
| 1169 GrBackendTextureDesc desc; | 1237 GrBackendTextureDesc desc; |
| 1170 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | 1238 desc.fFlags = kRenderTarget_GrBackendTextureFlag; |
| 1171 desc.fWidth = resource_->size.width(); | 1239 desc.fWidth = resource_->size.width(); |
| 1172 desc.fHeight = resource_->size.height(); | 1240 desc.fHeight = resource_->size.height(); |
| 1173 desc.fConfig = ToGrPixelConfig(resource_->format); | 1241 desc.fConfig = ToGrPixelConfig(resource_->format); |
| 1174 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | 1242 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 1175 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); | 1243 desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(texture_info); |
| 1176 desc.fSampleCnt = msaa_sample_count; | 1244 desc.fSampleCnt = msaa_sample_count; |
| 1177 | 1245 |
| 1178 bool use_worker_context = true; | |
| 1179 class GrContext* gr_context = | |
| 1180 resource_provider_->GrContext(use_worker_context); | |
| 1181 uint32_t flags = | 1246 uint32_t flags = |
| 1182 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; | 1247 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; |
| 1183 // Use unknown pixel geometry to disable LCD text. | 1248 // Use unknown pixel geometry to disable LCD text. |
| 1184 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); | 1249 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
| 1185 if (can_use_lcd_text) { | 1250 if (can_use_lcd_text) { |
| 1186 // LegacyFontHost will get LCD text and skia figures out what type to use. | 1251 // LegacyFontHost will get LCD text and skia figures out what type to use. |
| 1187 surface_props = | 1252 surface_props = |
| 1188 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); | 1253 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 1189 } | 1254 } |
| 1190 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( | 1255 sk_surface_ = SkSurface::MakeFromBackendTextureAsRenderTarget( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1219 | 1284 |
| 1220 void ResourceProvider::SynchronousFence::Wait() { | 1285 void ResourceProvider::SynchronousFence::Wait() { |
| 1221 HasPassed(); | 1286 HasPassed(); |
| 1222 } | 1287 } |
| 1223 | 1288 |
| 1224 void ResourceProvider::SynchronousFence::Synchronize() { | 1289 void ResourceProvider::SynchronousFence::Synchronize() { |
| 1225 TRACE_EVENT0("cc", "ResourceProvider::SynchronousFence::Synchronize"); | 1290 TRACE_EVENT0("cc", "ResourceProvider::SynchronousFence::Synchronize"); |
| 1226 gl_->Finish(); | 1291 gl_->Finish(); |
| 1227 } | 1292 } |
| 1228 | 1293 |
| 1229 ResourceProvider::ResourceProvider( | |
| 1230 OutputSurface* output_surface, | |
| 1231 SharedBitmapManager* shared_bitmap_manager, | |
| 1232 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | |
| 1233 BlockingTaskRunner* blocking_main_thread_task_runner, | |
| 1234 int highp_threshold_min, | |
| 1235 size_t id_allocation_chunk_size, | |
| 1236 bool use_gpu_memory_buffer_resources, | |
| 1237 const std::vector<unsigned>& use_image_texture_targets) | |
| 1238 : output_surface_(output_surface), | |
| 1239 shared_bitmap_manager_(shared_bitmap_manager), | |
| 1240 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), | |
| 1241 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), | |
| 1242 lost_output_surface_(false), | |
| 1243 highp_threshold_min_(highp_threshold_min), | |
| 1244 next_id_(1), | |
| 1245 next_child_(1), | |
| 1246 default_resource_type_(use_gpu_memory_buffer_resources | |
| 1247 ? RESOURCE_TYPE_GPU_MEMORY_BUFFER | |
| 1248 : RESOURCE_TYPE_GL_TEXTURE), | |
| 1249 use_texture_storage_ext_(false), | |
| 1250 use_texture_format_bgra_(false), | |
| 1251 use_texture_usage_hint_(false), | |
| 1252 use_compressed_texture_etc1_(false), | |
| 1253 yuv_resource_format_(LUMINANCE_8), | |
| 1254 max_texture_size_(0), | |
| 1255 best_texture_format_(RGBA_8888), | |
| 1256 best_render_buffer_format_(RGBA_8888), | |
| 1257 id_allocation_chunk_size_(id_allocation_chunk_size), | |
| 1258 use_sync_query_(false), | |
| 1259 use_image_texture_targets_(use_image_texture_targets), | |
| 1260 tracing_id_(g_next_resource_provider_tracing_id.GetNext()) { | |
| 1261 DCHECK(output_surface_->HasClient()); | |
| 1262 DCHECK(id_allocation_chunk_size_); | |
| 1263 } | |
| 1264 | |
| 1265 void ResourceProvider::Initialize() { | |
| 1266 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1267 | |
| 1268 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). | |
| 1269 // Don't register a dump provider in these cases. | |
| 1270 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 | |
| 1271 if (base::ThreadTaskRunnerHandle::IsSet()) { | |
| 1272 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
| 1273 this, "cc::ResourceProvider", base::ThreadTaskRunnerHandle::Get()); | |
| 1274 } | |
| 1275 | |
| 1276 GLES2Interface* gl = ContextGL(); | |
| 1277 if (!gl) { | |
| 1278 default_resource_type_ = RESOURCE_TYPE_BITMAP; | |
| 1279 // Pick an arbitrary limit here similar to what hardware might. | |
| 1280 max_texture_size_ = 16 * 1024; | |
| 1281 best_texture_format_ = RGBA_8888; | |
| 1282 return; | |
| 1283 } | |
| 1284 | |
| 1285 DCHECK(!texture_id_allocator_); | |
| 1286 DCHECK(!buffer_id_allocator_); | |
| 1287 | |
| 1288 const gpu::Capabilities& caps = | |
| 1289 output_surface_->context_provider()->ContextCapabilities(); | |
| 1290 | |
| 1291 DCHECK(IsGpuResourceType(default_resource_type_)); | |
| 1292 use_texture_storage_ext_ = caps.texture_storage; | |
| 1293 use_texture_format_bgra_ = caps.texture_format_bgra8888; | |
| 1294 use_texture_usage_hint_ = caps.texture_usage; | |
| 1295 use_compressed_texture_etc1_ = caps.texture_format_etc1; | |
| 1296 yuv_resource_format_ = caps.texture_rg ? RED_8 : LUMINANCE_8; | |
| 1297 yuv_highbit_resource_format_ = yuv_resource_format_; | |
| 1298 if (caps.texture_half_float_linear) | |
| 1299 yuv_highbit_resource_format_ = LUMINANCE_F16; | |
| 1300 use_sync_query_ = caps.sync_query; | |
| 1301 | |
| 1302 max_texture_size_ = 0; // Context expects cleared value. | |
| 1303 gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_); | |
| 1304 best_texture_format_ = | |
| 1305 PlatformColor::BestSupportedTextureFormat(use_texture_format_bgra_); | |
| 1306 | |
| 1307 best_render_buffer_format_ = PlatformColor::BestSupportedTextureFormat( | |
| 1308 caps.render_buffer_format_bgra8888); | |
| 1309 | |
| 1310 texture_id_allocator_.reset( | |
| 1311 new TextureIdAllocator(gl, id_allocation_chunk_size_)); | |
| 1312 buffer_id_allocator_.reset( | |
| 1313 new BufferIdAllocator(gl, id_allocation_chunk_size_)); | |
| 1314 } | |
| 1315 | |
| 1316 int ResourceProvider::CreateChild(const ReturnCallback& return_callback, | 1294 int ResourceProvider::CreateChild(const ReturnCallback& return_callback, |
| 1317 int gpu_memory_buffer_client_id) { | 1295 int gpu_memory_buffer_client_id) { |
| 1318 DCHECK(thread_checker_.CalledOnValidThread()); | 1296 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1319 | 1297 |
| 1320 Child child_info; | 1298 Child child_info; |
| 1321 child_info.return_callback = return_callback; | 1299 child_info.return_callback = return_callback; |
| 1322 child_info.gpu_memory_buffer_client_id = gpu_memory_buffer_client_id; | 1300 child_info.gpu_memory_buffer_client_id = gpu_memory_buffer_client_id; |
| 1323 | 1301 |
| 1324 int child = next_child_++; | 1302 int child = next_child_++; |
| 1325 children_[child] = child_info; | 1303 children_[child] = child_info; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 // This function goes through the array multiple times, store the resources | 1354 // This function goes through the array multiple times, store the resources |
| 1377 // as pointers so we don't have to look up the resource id multiple times. | 1355 // as pointers so we don't have to look up the resource id multiple times. |
| 1378 std::vector<Resource*> resources; | 1356 std::vector<Resource*> resources; |
| 1379 resources.reserve(resource_ids.size()); | 1357 resources.reserve(resource_ids.size()); |
| 1380 for (const ResourceId id : resource_ids) { | 1358 for (const ResourceId id : resource_ids) { |
| 1381 Resource* resource = GetResource(id); | 1359 Resource* resource = GetResource(id); |
| 1382 // Check the synchronization and sync token state when delegated sync points | 1360 // Check the synchronization and sync token state when delegated sync points |
| 1383 // are required. The only case where we allow a sync token to not be set is | 1361 // are required. The only case where we allow a sync token to not be set is |
| 1384 // the case where the image is dirty. In that case we will bind the image | 1362 // the case where the image is dirty. In that case we will bind the image |
| 1385 // lazily and generate a sync token at that point. | 1363 // lazily and generate a sync token at that point. |
| 1386 DCHECK(!output_surface_->capabilities().delegated_sync_points_required || | 1364 DCHECK(!delegated_sync_points_required_ || resource->dirty_image || |
| 1387 resource->dirty_image || !resource->needs_sync_token()); | 1365 !resource->needs_sync_token()); |
| 1388 | 1366 |
| 1389 // If we are validating the resource to be sent, the resource cannot be | 1367 // If we are validating the resource to be sent, the resource cannot be |
| 1390 // in a LOCALLY_USED state. It must have been properly synchronized. | 1368 // in a LOCALLY_USED state. It must have been properly synchronized. |
| 1391 DCHECK(!output_surface_->capabilities().delegated_sync_points_required || | 1369 DCHECK(!delegated_sync_points_required_ || |
| 1392 Resource::LOCALLY_USED != resource->synchronization_state()); | 1370 Resource::LOCALLY_USED != resource->synchronization_state()); |
| 1393 | 1371 |
| 1394 resources.push_back(resource); | 1372 resources.push_back(resource); |
| 1395 } | 1373 } |
| 1396 | 1374 |
| 1397 // Lazily create any mailboxes and verify all unverified sync tokens. | 1375 // Lazily create any mailboxes and verify all unverified sync tokens. |
| 1398 std::vector<GLbyte*> unverified_sync_tokens; | 1376 std::vector<GLbyte*> unverified_sync_tokens; |
| 1399 std::vector<Resource*> need_synchronization_resources; | 1377 std::vector<Resource*> need_synchronization_resources; |
| 1400 for (Resource* resource : resources) { | 1378 for (Resource* resource : resources) { |
| 1401 CreateMailboxAndBindResource(gl, resource); | 1379 CreateMailboxAndBindResource(gl, resource); |
| 1402 | 1380 |
| 1403 if (output_surface_->capabilities().delegated_sync_points_required && | 1381 if (delegated_sync_points_required_ && resource->needs_sync_token()) { |
| 1404 resource->needs_sync_token()) { | |
| 1405 need_synchronization_resources.push_back(resource); | 1382 need_synchronization_resources.push_back(resource); |
| 1406 } else if (resource->mailbox().HasSyncToken() && | 1383 } else if (resource->mailbox().HasSyncToken() && |
| 1407 !resource->mailbox().sync_token().verified_flush()) { | 1384 !resource->mailbox().sync_token().verified_flush()) { |
| 1408 unverified_sync_tokens.push_back(resource->GetSyncTokenData()); | 1385 unverified_sync_tokens.push_back(resource->GetSyncTokenData()); |
| 1409 } | 1386 } |
| 1410 } | 1387 } |
| 1411 | 1388 |
| 1412 // Insert sync point to synchronize the mailbox creation or bound textures. | 1389 // Insert sync point to synchronize the mailbox creation or bound textures. |
| 1413 gpu::SyncToken new_sync_token; | 1390 gpu::SyncToken new_sync_token; |
| 1414 if (gl) { | 1391 if (gl) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1428 resource->UpdateSyncToken(new_sync_token); | 1405 resource->UpdateSyncToken(new_sync_token); |
| 1429 resource->SetSynchronized(); | 1406 resource->SetSynchronized(); |
| 1430 } | 1407 } |
| 1431 | 1408 |
| 1432 // Transfer Resources | 1409 // Transfer Resources |
| 1433 DCHECK_EQ(resources.size(), resource_ids.size()); | 1410 DCHECK_EQ(resources.size(), resource_ids.size()); |
| 1434 for (size_t i = 0; i < resources.size(); ++i) { | 1411 for (size_t i = 0; i < resources.size(); ++i) { |
| 1435 Resource* source = resources[i]; | 1412 Resource* source = resources[i]; |
| 1436 const ResourceId id = resource_ids[i]; | 1413 const ResourceId id = resource_ids[i]; |
| 1437 | 1414 |
| 1438 DCHECK(!output_surface_->capabilities().delegated_sync_points_required || | 1415 DCHECK(!delegated_sync_points_required_ || !source->needs_sync_token()); |
| 1439 !source->needs_sync_token()); | 1416 DCHECK(!delegated_sync_points_required_ || |
| 1440 DCHECK(!output_surface_->capabilities().delegated_sync_points_required || | |
| 1441 Resource::LOCALLY_USED != source->synchronization_state()); | 1417 Resource::LOCALLY_USED != source->synchronization_state()); |
| 1442 | 1418 |
| 1443 TransferableResource resource; | 1419 TransferableResource resource; |
| 1444 TransferResource(source, id, &resource); | 1420 TransferResource(source, id, &resource); |
| 1445 | 1421 |
| 1446 source->exported_count++; | 1422 source->exported_count++; |
| 1447 list->push_back(resource); | 1423 list->push_back(resource); |
| 1448 } | 1424 } |
| 1449 } | 1425 } |
| 1450 | 1426 |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1927 return use_image_texture_targets_[static_cast<size_t>(buffer_format)]; | 1903 return use_image_texture_targets_[static_cast<size_t>(buffer_format)]; |
| 1928 } | 1904 } |
| 1929 | 1905 |
| 1930 void ResourceProvider::ValidateResource(ResourceId id) const { | 1906 void ResourceProvider::ValidateResource(ResourceId id) const { |
| 1931 DCHECK(thread_checker_.CalledOnValidThread()); | 1907 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1932 DCHECK(id); | 1908 DCHECK(id); |
| 1933 DCHECK(resources_.find(id) != resources_.end()); | 1909 DCHECK(resources_.find(id) != resources_.end()); |
| 1934 } | 1910 } |
| 1935 | 1911 |
| 1936 GLES2Interface* ResourceProvider::ContextGL() const { | 1912 GLES2Interface* ResourceProvider::ContextGL() const { |
| 1937 ContextProvider* context_provider = output_surface_->context_provider(); | 1913 ContextProvider* context_provider = compositor_context_provider_; |
| 1938 return context_provider ? context_provider->ContextGL() : nullptr; | 1914 return context_provider ? context_provider->ContextGL() : nullptr; |
| 1939 } | 1915 } |
| 1940 | 1916 |
| 1941 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | |
| 1942 ContextProvider* context_provider = | |
| 1943 worker_context ? output_surface_->worker_context_provider() | |
| 1944 : output_surface_->context_provider(); | |
| 1945 return context_provider ? context_provider->GrContext() : nullptr; | |
| 1946 } | |
| 1947 | |
| 1948 bool ResourceProvider::IsGLContextLost() const { | 1917 bool ResourceProvider::IsGLContextLost() const { |
| 1949 return ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR; | 1918 return ContextGL()->GetGraphicsResetStatusKHR() != GL_NO_ERROR; |
| 1950 } | 1919 } |
| 1951 | 1920 |
| 1952 bool ResourceProvider::OnMemoryDump( | 1921 bool ResourceProvider::OnMemoryDump( |
| 1953 const base::trace_event::MemoryDumpArgs& args, | 1922 const base::trace_event::MemoryDumpArgs& args, |
| 1954 base::trace_event::ProcessMemoryDump* pmd) { | 1923 base::trace_event::ProcessMemoryDump* pmd) { |
| 1955 DCHECK(thread_checker_.CalledOnValidThread()); | 1924 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1956 | 1925 |
| 1957 const uint64_t tracing_process_id = | 1926 const uint64_t tracing_process_id = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1997 // prevent double counting the memory. | 1966 // prevent double counting the memory. |
| 1998 base::trace_event::MemoryAllocatorDumpGuid guid; | 1967 base::trace_event::MemoryAllocatorDumpGuid guid; |
| 1999 switch (resource.type) { | 1968 switch (resource.type) { |
| 2000 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: | 1969 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: |
| 2001 guid = gfx::GetGpuMemoryBufferGUIDForTracing( | 1970 guid = gfx::GetGpuMemoryBufferGUIDForTracing( |
| 2002 tracing_process_id, resource.gpu_memory_buffer->GetHandle().id); | 1971 tracing_process_id, resource.gpu_memory_buffer->GetHandle().id); |
| 2003 break; | 1972 break; |
| 2004 case RESOURCE_TYPE_GL_TEXTURE: | 1973 case RESOURCE_TYPE_GL_TEXTURE: |
| 2005 DCHECK(resource.gl_id); | 1974 DCHECK(resource.gl_id); |
| 2006 guid = gfx::GetGLTextureClientGUIDForTracing( | 1975 guid = gfx::GetGLTextureClientGUIDForTracing( |
| 2007 output_surface_->context_provider() | 1976 compositor_context_provider_->ContextSupport() |
| 2008 ->ContextSupport() | |
| 2009 ->ShareGroupTracingGUID(), | 1977 ->ShareGroupTracingGUID(), |
| 2010 resource.gl_id); | 1978 resource.gl_id); |
| 2011 break; | 1979 break; |
| 2012 case RESOURCE_TYPE_BITMAP: | 1980 case RESOURCE_TYPE_BITMAP: |
| 2013 DCHECK(resource.has_shared_bitmap_id); | 1981 DCHECK(resource.has_shared_bitmap_id); |
| 2014 guid = GetSharedBitmapGUIDForTracing(resource.shared_bitmap_id); | 1982 guid = GetSharedBitmapGUIDForTracing(resource.shared_bitmap_id); |
| 2015 break; | 1983 break; |
| 2016 } | 1984 } |
| 2017 | 1985 |
| 2018 DCHECK(!guid.empty()); | 1986 DCHECK(!guid.empty()); |
| 2019 | 1987 |
| 2020 const int kImportance = 2; | 1988 const int kImportance = 2; |
| 2021 pmd->CreateSharedGlobalAllocatorDump(guid); | 1989 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 2022 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 1990 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 2023 } | 1991 } |
| 2024 | 1992 |
| 2025 return true; | 1993 return true; |
| 2026 } | 1994 } |
| 2027 | 1995 |
| 2028 } // namespace cc | 1996 } // namespace cc |
| OLD | NEW |