Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: cc/resources/resource_provider.cc

Issue 2662303004: Move const ResourceProvider members into Settings struct (Closed)
Patch Set: comment update Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 SetSynchronized(); 391 SetSynchronized();
392 } 392 }
393 393
394 ResourceProvider::Child::Child() 394 ResourceProvider::Child::Child()
395 : marked_for_deletion(false), needs_sync_tokens(true) {} 395 : marked_for_deletion(false), needs_sync_tokens(true) {}
396 396
397 ResourceProvider::Child::Child(const Child& other) = default; 397 ResourceProvider::Child::Child(const Child& other) = default;
398 398
399 ResourceProvider::Child::~Child() {} 399 ResourceProvider::Child::~Child() {}
400 400
401 ResourceProvider::Settings::Settings(
402 ContextProvider* compositor_context_provider,
403 bool delegated_sync_points_required,
404 bool use_gpu_memory_buffer_resources,
405 bool enable_color_correct_rendering)
406 : delegated_sync_points_required(delegated_sync_points_required),
407 default_resource_type(use_gpu_memory_buffer_resources
408 ? RESOURCE_TYPE_GPU_MEMORY_BUFFER
409 : RESOURCE_TYPE_GL_TEXTURE),
410 enable_color_correct_rendering(enable_color_correct_rendering) {
411 if (!compositor_context_provider) {
412 default_resource_type = RESOURCE_TYPE_BITMAP;
413 // Pick an arbitrary limit here similar to what hardware might.
414 max_texture_size = 16 * 1024;
415 best_texture_format = RGBA_8888;
416 return;
417 }
418
419 DCHECK(IsGpuResourceType(default_resource_type));
420
421 const auto& caps = compositor_context_provider->ContextCapabilities();
422 use_texture_storage_ext = caps.texture_storage;
423 use_texture_format_bgra = caps.texture_format_bgra8888;
424 use_texture_usage_hint = caps.texture_usage;
425 use_sync_query = caps.sync_query;
426
427 if (caps.disable_one_component_textures) {
428 yuv_resource_format = yuv_highbit_resource_format = RGBA_8888;
429 } else {
430 yuv_resource_format = caps.texture_rg ? RED_8 : LUMINANCE_8;
431 yuv_highbit_resource_format =
432 caps.texture_half_float_linear ? LUMINANCE_F16 : yuv_resource_format;
433 }
434
435 GLES2Interface* gl = compositor_context_provider->ContextGL();
436 gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
437
438 best_texture_format =
439 PlatformColor::BestSupportedTextureFormat(use_texture_format_bgra);
440 best_render_buffer_format = PlatformColor::BestSupportedTextureFormat(
441 caps.render_buffer_format_bgra8888);
442 }
443
401 ResourceProvider::ResourceProvider( 444 ResourceProvider::ResourceProvider(
402 ContextProvider* compositor_context_provider, 445 ContextProvider* compositor_context_provider,
403 SharedBitmapManager* shared_bitmap_manager, 446 SharedBitmapManager* shared_bitmap_manager,
404 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, 447 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
405 BlockingTaskRunner* blocking_main_thread_task_runner, 448 BlockingTaskRunner* blocking_main_thread_task_runner,
406 int highp_threshold_min,
407 size_t id_allocation_chunk_size, 449 size_t id_allocation_chunk_size,
408 bool delegated_sync_points_required, 450 bool delegated_sync_points_required,
409 bool use_gpu_memory_buffer_resources, 451 bool use_gpu_memory_buffer_resources,
410 bool enable_color_correct_rendering, 452 bool enable_color_correct_rendering,
411 const BufferToTextureTargetMap& buffer_to_texture_target_map) 453 const BufferToTextureTargetMap& buffer_to_texture_target_map)
412 : compositor_context_provider_(compositor_context_provider), 454 : settings_(compositor_context_provider,
455 delegated_sync_points_required,
456 use_gpu_memory_buffer_resources,
457 enable_color_correct_rendering),
458 compositor_context_provider_(compositor_context_provider),
413 shared_bitmap_manager_(shared_bitmap_manager), 459 shared_bitmap_manager_(shared_bitmap_manager),
414 gpu_memory_buffer_manager_(gpu_memory_buffer_manager), 460 gpu_memory_buffer_manager_(gpu_memory_buffer_manager),
415 blocking_main_thread_task_runner_(blocking_main_thread_task_runner), 461 blocking_main_thread_task_runner_(blocking_main_thread_task_runner),
416 lost_context_provider_(false), 462 lost_context_provider_(false),
417 highp_threshold_min_(highp_threshold_min),
418 next_id_(1), 463 next_id_(1),
419 next_child_(1), 464 next_child_(1),
420 delegated_sync_points_required_(delegated_sync_points_required),
421 default_resource_type_(use_gpu_memory_buffer_resources
422 ? RESOURCE_TYPE_GPU_MEMORY_BUFFER
423 : RESOURCE_TYPE_GL_TEXTURE),
424 use_texture_storage_ext_(false),
425 use_texture_format_bgra_(false),
426 use_texture_usage_hint_(false),
427 use_compressed_texture_etc1_(false),
428 yuv_resource_format_(LUMINANCE_8),
429 max_texture_size_(0),
430 best_texture_format_(RGBA_8888),
431 best_render_buffer_format_(RGBA_8888),
432 enable_color_correct_rendering_(enable_color_correct_rendering),
433 id_allocation_chunk_size_(id_allocation_chunk_size),
434 use_sync_query_(false),
435 buffer_to_texture_target_map_(buffer_to_texture_target_map), 465 buffer_to_texture_target_map_(buffer_to_texture_target_map),
436 tracing_id_(g_next_resource_provider_tracing_id.GetNext()) { 466 tracing_id_(g_next_resource_provider_tracing_id.GetNext()) {
437 DCHECK(id_allocation_chunk_size_); 467 DCHECK(id_allocation_chunk_size);
438 DCHECK(thread_checker_.CalledOnValidThread()); 468 DCHECK(thread_checker_.CalledOnValidThread());
439 469
440 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview). 470 // In certain cases, ThreadTaskRunnerHandle isn't set (Android Webview).
441 // Don't register a dump provider in these cases. 471 // Don't register a dump provider in these cases.
442 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156 472 // TODO(ericrk): Get this working in Android Webview. crbug.com/517156
443 if (base::ThreadTaskRunnerHandle::IsSet()) { 473 if (base::ThreadTaskRunnerHandle::IsSet()) {
444 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( 474 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
445 this, "cc::ResourceProvider", base::ThreadTaskRunnerHandle::Get()); 475 this, "cc::ResourceProvider", base::ThreadTaskRunnerHandle::Get());
446 } 476 }
447 477
448 if (!compositor_context_provider_) {
449 default_resource_type_ = RESOURCE_TYPE_BITMAP;
450 // Pick an arbitrary limit here similar to what hardware might.
451 max_texture_size_ = 16 * 1024;
452 best_texture_format_ = RGBA_8888;
453 return;
454 }
455
456 DCHECK(!texture_id_allocator_); 478 DCHECK(!texture_id_allocator_);
457 DCHECK(!buffer_id_allocator_); 479 DCHECK(!buffer_id_allocator_);
458
459 const auto& caps = compositor_context_provider_->ContextCapabilities();
460
461 DCHECK(IsGpuResourceType(default_resource_type_));
462 use_texture_storage_ext_ = caps.texture_storage;
463 use_texture_format_bgra_ = caps.texture_format_bgra8888;
464 use_texture_usage_hint_ = caps.texture_usage;
465 use_compressed_texture_etc1_ = caps.texture_format_etc1;
466
467 if (caps.disable_one_component_textures) {
468 yuv_resource_format_ = yuv_highbit_resource_format_ = RGBA_8888;
469 } else {
470 yuv_resource_format_ = caps.texture_rg ? RED_8 : LUMINANCE_8;
471 yuv_highbit_resource_format_ =
472 caps.texture_half_float_linear ? LUMINANCE_F16 : yuv_resource_format_;
473 }
474
475 use_sync_query_ = caps.sync_query;
476
477 GLES2Interface* gl = ContextGL(); 480 GLES2Interface* gl = ContextGL();
478
479 max_texture_size_ = 0; // Context expects cleared value.
480 gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_);
481 best_texture_format_ =
482 PlatformColor::BestSupportedTextureFormat(use_texture_format_bgra_);
483
484 best_render_buffer_format_ = PlatformColor::BestSupportedTextureFormat(
485 caps.render_buffer_format_bgra8888);
486
487 texture_id_allocator_.reset( 481 texture_id_allocator_.reset(
488 new TextureIdAllocator(gl, id_allocation_chunk_size_)); 482 new TextureIdAllocator(gl, id_allocation_chunk_size));
489 buffer_id_allocator_.reset( 483 buffer_id_allocator_.reset(
490 new BufferIdAllocator(gl, id_allocation_chunk_size_)); 484 new BufferIdAllocator(gl, id_allocation_chunk_size));
491 } 485 }
492 486
493 ResourceProvider::~ResourceProvider() { 487 ResourceProvider::~ResourceProvider() {
494 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 488 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
495 this); 489 this);
496 490
497 while (!children_.empty()) 491 while (!children_.empty())
498 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN); 492 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN);
499 while (!resources_.empty()) 493 while (!resources_.empty())
500 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN); 494 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN);
501 495
502 GLES2Interface* gl = ContextGL(); 496 GLES2Interface* gl = ContextGL();
503 if (!IsGpuResourceType(default_resource_type_)) { 497 if (!IsGpuResourceType(settings_.default_resource_type)) {
504 // We are not in GL mode, but double check before returning. 498 // We are not in GL mode, but double check before returning.
505 DCHECK(!gl); 499 DCHECK(!gl);
506 return; 500 return;
507 } 501 }
508 502
509 DCHECK(gl); 503 DCHECK(gl);
510 #if DCHECK_IS_ON() 504 #if DCHECK_IS_ON()
511 // Check that all GL resources has been deleted. 505 // Check that all GL resources has been deleted.
512 for (ResourceMap::const_iterator itr = resources_.begin(); 506 for (ResourceMap::const_iterator itr = resources_.begin();
513 itr != resources_.end(); ++itr) { 507 itr != resources_.end(); ++itr) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 } 552 }
559 553
560 void ResourceProvider::LoseResourceForTesting(ResourceId id) { 554 void ResourceProvider::LoseResourceForTesting(ResourceId id) {
561 Resource* resource = GetResource(id); 555 Resource* resource = GetResource(id);
562 DCHECK(resource); 556 DCHECK(resource);
563 resource->lost = true; 557 resource->lost = true;
564 } 558 }
565 559
566 ResourceFormat ResourceProvider::YuvResourceFormat(int bits) const { 560 ResourceFormat ResourceProvider::YuvResourceFormat(int bits) const {
567 if (bits > 8) { 561 if (bits > 8) {
568 return yuv_highbit_resource_format_; 562 return settings_.yuv_highbit_resource_format;
569 } else { 563 } else {
570 return yuv_resource_format_; 564 return settings_.yuv_resource_format;
571 } 565 }
572 } 566 }
573 567
574 ResourceId ResourceProvider::CreateResource( 568 ResourceId ResourceProvider::CreateResource(
575 const gfx::Size& size, 569 const gfx::Size& size,
576 TextureHint hint, 570 TextureHint hint,
577 ResourceFormat format, 571 ResourceFormat format,
578 const gfx::ColorSpace& color_space) { 572 const gfx::ColorSpace& color_space) {
579 DCHECK(!size.IsEmpty()); 573 DCHECK(!size.IsEmpty());
580 switch (default_resource_type_) { 574 switch (settings_.default_resource_type) {
581 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: 575 case RESOURCE_TYPE_GPU_MEMORY_BUFFER:
582 // GPU memory buffers don't support LUMINANCE_F16. 576 // GPU memory buffers don't support LUMINANCE_F16.
583 if (format != LUMINANCE_F16) { 577 if (format != LUMINANCE_F16) {
584 return CreateGLTexture( 578 return CreateGLTexture(
585 size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, format, 579 size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, format,
586 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, color_space); 580 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, color_space);
587 } 581 }
588 // Fall through and use a regular texture. 582 // Fall through and use a regular texture.
589 case RESOURCE_TYPE_GL_TEXTURE: 583 case RESOURCE_TYPE_GL_TEXTURE:
590 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format, 584 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format,
591 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, 585 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
592 color_space); 586 color_space);
593 587
594 case RESOURCE_TYPE_BITMAP: 588 case RESOURCE_TYPE_BITMAP:
595 DCHECK_EQ(RGBA_8888, format); 589 DCHECK_EQ(RGBA_8888, format);
596 return CreateBitmap(size, color_space); 590 return CreateBitmap(size, color_space);
597 } 591 }
598 592
599 LOG(FATAL) << "Invalid default resource type."; 593 LOG(FATAL) << "Invalid default resource type.";
600 return 0; 594 return 0;
601 } 595 }
602 596
603 ResourceId ResourceProvider::CreateGpuMemoryBufferResource( 597 ResourceId ResourceProvider::CreateGpuMemoryBufferResource(
604 const gfx::Size& size, 598 const gfx::Size& size,
605 TextureHint hint, 599 TextureHint hint,
606 ResourceFormat format, 600 ResourceFormat format,
607 gfx::BufferUsage usage, 601 gfx::BufferUsage usage,
608 const gfx::ColorSpace& color_space) { 602 const gfx::ColorSpace& color_space) {
609 DCHECK(!size.IsEmpty()); 603 DCHECK(!size.IsEmpty());
610 switch (default_resource_type_) { 604 switch (settings_.default_resource_type) {
611 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: 605 case RESOURCE_TYPE_GPU_MEMORY_BUFFER:
612 case RESOURCE_TYPE_GL_TEXTURE: { 606 case RESOURCE_TYPE_GL_TEXTURE: {
613 return CreateGLTexture(size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, 607 return CreateGLTexture(size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER,
614 format, usage, color_space); 608 format, usage, color_space);
615 } 609 }
616 case RESOURCE_TYPE_BITMAP: 610 case RESOURCE_TYPE_BITMAP:
617 DCHECK_EQ(RGBA_8888, format); 611 DCHECK_EQ(RGBA_8888, format);
618 return CreateBitmap(size, color_space); 612 return CreateBitmap(size, color_space);
619 } 613 }
620 614
621 LOG(FATAL) << "Invalid default resource type."; 615 LOG(FATAL) << "Invalid default resource type.";
622 return 0; 616 return 0;
623 } 617 }
624 618
625 ResourceId ResourceProvider::CreateGLTexture( 619 ResourceId ResourceProvider::CreateGLTexture(
626 const gfx::Size& size, 620 const gfx::Size& size,
627 TextureHint hint, 621 TextureHint hint,
628 ResourceType type, 622 ResourceType type,
629 ResourceFormat format, 623 ResourceFormat format,
630 gfx::BufferUsage usage, 624 gfx::BufferUsage usage,
631 const gfx::ColorSpace& color_space) { 625 const gfx::ColorSpace& color_space) {
632 DCHECK_LE(size.width(), max_texture_size_); 626 DCHECK_LE(size.width(), settings_.max_texture_size);
633 DCHECK_LE(size.height(), max_texture_size_); 627 DCHECK_LE(size.height(), settings_.max_texture_size);
634 DCHECK(thread_checker_.CalledOnValidThread()); 628 DCHECK(thread_checker_.CalledOnValidThread());
635 629
636 // TODO(crbug.com/590317): We should not assume that all resources created by 630 // TODO(crbug.com/590317): We should not assume that all resources created by
637 // ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this 631 // ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this
638 // based on the current RasterBufferProvider's needs. 632 // based on the current RasterBufferProvider's needs.
639 GLenum target = type == RESOURCE_TYPE_GPU_MEMORY_BUFFER 633 GLenum target = type == RESOURCE_TYPE_GPU_MEMORY_BUFFER
640 ? GetImageTextureTarget(usage, format) 634 ? GetImageTextureTarget(usage, format)
641 : GL_TEXTURE_2D; 635 : GL_TEXTURE_2D;
642 636
643 ResourceId id = next_id_++; 637 ResourceId id = next_id_++;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 ResourceProvider::ResourceType ResourceProvider::GetResourceType( 846 ResourceProvider::ResourceType ResourceProvider::GetResourceType(
853 ResourceId id) { 847 ResourceId id) {
854 return GetResource(id)->type; 848 return GetResource(id)->type;
855 } 849 }
856 850
857 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) { 851 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) {
858 return GetResource(id)->target; 852 return GetResource(id)->target;
859 } 853 }
860 854
861 bool ResourceProvider::IsImmutable(ResourceId id) { 855 bool ResourceProvider::IsImmutable(ResourceId id) {
862 if (IsGpuResourceType(default_resource_type_)) { 856 if (IsGpuResourceType(settings_.default_resource_type)) {
863 return GetTextureHint(id) == TEXTURE_HINT_IMMUTABLE; 857 return GetTextureHint(id) == TEXTURE_HINT_IMMUTABLE;
864 } else { 858 } else {
865 // Software resources are immutable; they cannot change format or be 859 // Software resources are immutable; they cannot change format or be
866 // resized. 860 // resized.
867 return true; 861 return true;
868 } 862 }
869 } 863 }
870 864
871 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) { 865 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) {
872 return GetResource(id)->hint; 866 return GetResource(id)->hint;
873 } 867 }
874 868
875 sk_sp<SkColorSpace> ResourceProvider::GetResourceSkColorSpace( 869 sk_sp<SkColorSpace> ResourceProvider::GetResourceSkColorSpace(
876 const Resource* resource) const { 870 const Resource* resource) const {
877 if (!enable_color_correct_rendering_) 871 if (!settings_.enable_color_correct_rendering)
878 return nullptr; 872 return nullptr;
879 return resource->color_space.ToSkColorSpace(); 873 return resource->color_space.ToSkColorSpace();
880 } 874 }
881 875
882 void ResourceProvider::CopyToResource(ResourceId id, 876 void ResourceProvider::CopyToResource(ResourceId id,
883 const uint8_t* image, 877 const uint8_t* image,
884 const gfx::Size& image_size) { 878 const gfx::Size& image_size) {
885 Resource* resource = GetResource(id); 879 Resource* resource = GetResource(id);
886 DCHECK(!resource->locked_for_write); 880 DCHECK(!resource->locked_for_write);
887 DCHECK(!resource->lock_for_read_count); 881 DCHECK(!resource->lock_for_read_count);
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer); 1341 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer);
1348 resource->gpu_memory_buffer = nullptr; 1342 resource->gpu_memory_buffer = nullptr;
1349 } 1343 }
1350 1344
1351 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: 1345 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::
1352 ~ScopedWriteLockGpuMemoryBuffer() { 1346 ~ScopedWriteLockGpuMemoryBuffer() {
1353 DCHECK(thread_checker_.CalledOnValidThread()); 1347 DCHECK(thread_checker_.CalledOnValidThread());
1354 Resource* resource = resource_provider_->GetResource(resource_id_); 1348 Resource* resource = resource_provider_->GetResource(resource_id_);
1355 DCHECK(resource); 1349 DCHECK(resource);
1356 if (gpu_memory_buffer_) { 1350 if (gpu_memory_buffer_) {
1357 if (resource_provider_->enable_color_correct_rendering_) 1351 if (resource_provider_->settings_.enable_color_correct_rendering)
1358 gpu_memory_buffer_->SetColorSpaceForScanout(resource->color_space); 1352 gpu_memory_buffer_->SetColorSpaceForScanout(resource->color_space);
1359 DCHECK(!resource->gpu_memory_buffer); 1353 DCHECK(!resource->gpu_memory_buffer);
1360 resource_provider_->LazyCreate(resource); 1354 resource_provider_->LazyCreate(resource);
1361 resource->gpu_memory_buffer = std::move(gpu_memory_buffer_); 1355 resource->gpu_memory_buffer = std::move(gpu_memory_buffer_);
1362 resource->allocated = true; 1356 resource->allocated = true;
1363 resource_provider_->LazyCreateImage(resource); 1357 resource_provider_->LazyCreateImage(resource);
1364 resource->dirty_image = true; 1358 resource->dirty_image = true;
1365 resource->is_overlay_candidate = true; 1359 resource->is_overlay_candidate = true;
1366 // GpuMemoryBuffer provides direct access to the memory used by the GPU. 1360 // GpuMemoryBuffer provides direct access to the memory used by the GPU.
1367 // Read lock fences are required to ensure that we're not trying to map a 1361 // Read lock fences are required to ensure that we're not trying to map a
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 // This function goes through the array multiple times, store the resources 1463 // This function goes through the array multiple times, store the resources
1470 // as pointers so we don't have to look up the resource id multiple times. 1464 // as pointers so we don't have to look up the resource id multiple times.
1471 std::vector<Resource*> resources; 1465 std::vector<Resource*> resources;
1472 resources.reserve(resource_ids.size()); 1466 resources.reserve(resource_ids.size());
1473 for (const ResourceId id : resource_ids) { 1467 for (const ResourceId id : resource_ids) {
1474 Resource* resource = GetResource(id); 1468 Resource* resource = GetResource(id);
1475 // Check the synchronization and sync token state when delegated sync points 1469 // Check the synchronization and sync token state when delegated sync points
1476 // are required. The only case where we allow a sync token to not be set is 1470 // are required. The only case where we allow a sync token to not be set is
1477 // the case where the image is dirty. In that case we will bind the image 1471 // the case where the image is dirty. In that case we will bind the image
1478 // lazily and generate a sync token at that point. 1472 // lazily and generate a sync token at that point.
1479 DCHECK(!delegated_sync_points_required_ || resource->dirty_image || 1473 DCHECK(!settings_.delegated_sync_points_required || resource->dirty_image ||
1480 !resource->needs_sync_token()); 1474 !resource->needs_sync_token());
1481 1475
1482 // If we are validating the resource to be sent, the resource cannot be 1476 // If we are validating the resource to be sent, the resource cannot be
1483 // in a LOCALLY_USED state. It must have been properly synchronized. 1477 // in a LOCALLY_USED state. It must have been properly synchronized.
1484 DCHECK(!delegated_sync_points_required_ || 1478 DCHECK(!settings_.delegated_sync_points_required ||
1485 Resource::LOCALLY_USED != resource->synchronization_state()); 1479 Resource::LOCALLY_USED != resource->synchronization_state());
1486 1480
1487 resources.push_back(resource); 1481 resources.push_back(resource);
1488 } 1482 }
1489 1483
1490 // Lazily create any mailboxes and verify all unverified sync tokens. 1484 // Lazily create any mailboxes and verify all unverified sync tokens.
1491 std::vector<GLbyte*> unverified_sync_tokens; 1485 std::vector<GLbyte*> unverified_sync_tokens;
1492 std::vector<Resource*> need_synchronization_resources; 1486 std::vector<Resource*> need_synchronization_resources;
1493 for (Resource* resource : resources) { 1487 for (Resource* resource : resources) {
1494 if (!IsGpuResourceType(resource->type)) 1488 if (!IsGpuResourceType(resource->type))
1495 continue; 1489 continue;
1496 1490
1497 CreateMailboxAndBindResource(gl, resource); 1491 CreateMailboxAndBindResource(gl, resource);
1498 1492
1499 if (delegated_sync_points_required_) { 1493 if (settings_.delegated_sync_points_required) {
1500 if (resource->needs_sync_token()) { 1494 if (resource->needs_sync_token()) {
1501 need_synchronization_resources.push_back(resource); 1495 need_synchronization_resources.push_back(resource);
1502 } else if (resource->mailbox().HasSyncToken() && 1496 } else if (resource->mailbox().HasSyncToken() &&
1503 !resource->mailbox().sync_token().verified_flush()) { 1497 !resource->mailbox().sync_token().verified_flush()) {
1504 unverified_sync_tokens.push_back(resource->GetSyncTokenData()); 1498 unverified_sync_tokens.push_back(resource->GetSyncTokenData());
1505 } 1499 }
1506 } 1500 }
1507 } 1501 }
1508 1502
1509 // Insert sync point to synchronize the mailbox creation or bound textures. 1503 // Insert sync point to synchronize the mailbox creation or bound textures.
1510 gpu::SyncToken new_sync_token; 1504 gpu::SyncToken new_sync_token;
1511 if (!need_synchronization_resources.empty()) { 1505 if (!need_synchronization_resources.empty()) {
1512 DCHECK(delegated_sync_points_required_); 1506 DCHECK(settings_.delegated_sync_points_required);
1513 DCHECK(gl); 1507 DCHECK(gl);
1514 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); 1508 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
1515 gl->OrderingBarrierCHROMIUM(); 1509 gl->OrderingBarrierCHROMIUM();
1516 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData()); 1510 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData());
1517 unverified_sync_tokens.push_back(new_sync_token.GetData()); 1511 unverified_sync_tokens.push_back(new_sync_token.GetData());
1518 } 1512 }
1519 1513
1520 if (!unverified_sync_tokens.empty()) { 1514 if (!unverified_sync_tokens.empty()) {
1521 DCHECK(delegated_sync_points_required_); 1515 DCHECK(settings_.delegated_sync_points_required);
1522 DCHECK(gl); 1516 DCHECK(gl);
1523 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(), 1517 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(),
1524 unverified_sync_tokens.size()); 1518 unverified_sync_tokens.size());
1525 } 1519 }
1526 1520
1527 // Set sync token after verification. 1521 // Set sync token after verification.
1528 for (Resource* resource : need_synchronization_resources) { 1522 for (Resource* resource : need_synchronization_resources) {
1529 DCHECK(IsGpuResourceType(resource->type)); 1523 DCHECK(IsGpuResourceType(resource->type));
1530 resource->UpdateSyncToken(new_sync_token); 1524 resource->UpdateSyncToken(new_sync_token);
1531 resource->SetSynchronized(); 1525 resource->SetSynchronized();
1532 } 1526 }
1533 1527
1534 // Transfer Resources 1528 // Transfer Resources
1535 DCHECK_EQ(resources.size(), resource_ids.size()); 1529 DCHECK_EQ(resources.size(), resource_ids.size());
1536 for (size_t i = 0; i < resources.size(); ++i) { 1530 for (size_t i = 0; i < resources.size(); ++i) {
1537 Resource* source = resources[i]; 1531 Resource* source = resources[i];
1538 const ResourceId id = resource_ids[i]; 1532 const ResourceId id = resource_ids[i];
1539 1533
1540 DCHECK(!delegated_sync_points_required_ || !source->needs_sync_token()); 1534 DCHECK(!settings_.delegated_sync_points_required ||
1541 DCHECK(!delegated_sync_points_required_ || 1535 !source->needs_sync_token());
1536 DCHECK(!settings_.delegated_sync_points_required ||
1542 Resource::LOCALLY_USED != source->synchronization_state()); 1537 Resource::LOCALLY_USED != source->synchronization_state());
1543 1538
1544 TransferableResource resource; 1539 TransferableResource resource;
1545 TransferResource(source, id, &resource); 1540 TransferResource(source, id, &resource);
1546 1541
1547 source->exported_count++; 1542 source->exported_count++;
1548 list->push_back(resource); 1543 list->push_back(resource);
1549 } 1544 }
1550 } 1545 }
1551 1546
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 DCHECK(gl); 1940 DCHECK(gl);
1946 1941
1947 // Create and set texture properties. Allocation is delayed until needed. 1942 // Create and set texture properties. Allocation is delayed until needed.
1948 gl->BindTexture(resource->target, resource->gl_id); 1943 gl->BindTexture(resource->target, resource->gl_id);
1949 gl->TexParameteri(resource->target, GL_TEXTURE_MIN_FILTER, 1944 gl->TexParameteri(resource->target, GL_TEXTURE_MIN_FILTER,
1950 resource->original_filter); 1945 resource->original_filter);
1951 gl->TexParameteri(resource->target, GL_TEXTURE_MAG_FILTER, 1946 gl->TexParameteri(resource->target, GL_TEXTURE_MAG_FILTER,
1952 resource->original_filter); 1947 resource->original_filter);
1953 gl->TexParameteri(resource->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1948 gl->TexParameteri(resource->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1954 gl->TexParameteri(resource->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 1949 gl->TexParameteri(resource->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1955 if (use_texture_usage_hint_ && (resource->hint & TEXTURE_HINT_FRAMEBUFFER)) { 1950 if (settings_.use_texture_usage_hint &&
1951 (resource->hint & TEXTURE_HINT_FRAMEBUFFER)) {
1956 gl->TexParameteri(resource->target, GL_TEXTURE_USAGE_ANGLE, 1952 gl->TexParameteri(resource->target, GL_TEXTURE_USAGE_ANGLE,
1957 GL_FRAMEBUFFER_ATTACHMENT_ANGLE); 1953 GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
1958 } 1954 }
1959 } 1955 }
1960 1956
1961 void ResourceProvider::AllocateForTesting(ResourceId id) { 1957 void ResourceProvider::AllocateForTesting(ResourceId id) {
1962 LazyAllocate(GetResource(id)); 1958 LazyAllocate(GetResource(id));
1963 } 1959 }
1964 1960
1965 void ResourceProvider::LazyAllocate(Resource* resource) { 1961 void ResourceProvider::LazyAllocate(Resource* resource) {
1966 DCHECK(resource); 1962 DCHECK(resource);
1967 if (resource->allocated) 1963 if (resource->allocated)
1968 return; 1964 return;
1969 LazyCreate(resource); 1965 LazyCreate(resource);
1970 if (!resource->gl_id) 1966 if (!resource->gl_id)
1971 return; 1967 return;
1972 resource->allocated = true; 1968 resource->allocated = true;
1973 GLES2Interface* gl = ContextGL(); 1969 GLES2Interface* gl = ContextGL();
1974 gfx::Size& size = resource->size; 1970 gfx::Size& size = resource->size;
1975 ResourceFormat format = resource->format; 1971 ResourceFormat format = resource->format;
1976 gl->BindTexture(resource->target, resource->gl_id); 1972 gl->BindTexture(resource->target, resource->gl_id);
1977 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { 1973 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) {
1978 resource->gpu_memory_buffer = 1974 resource->gpu_memory_buffer =
1979 gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( 1975 gpu_memory_buffer_manager_->CreateGpuMemoryBuffer(
1980 size, BufferFormat(format), resource->usage, 1976 size, BufferFormat(format), resource->usage,
1981 gpu::kNullSurfaceHandle); 1977 gpu::kNullSurfaceHandle);
1982 if (resource->gpu_memory_buffer && enable_color_correct_rendering_) { 1978 if (resource->gpu_memory_buffer &&
1979 settings_.enable_color_correct_rendering) {
1983 resource->gpu_memory_buffer->SetColorSpaceForScanout( 1980 resource->gpu_memory_buffer->SetColorSpaceForScanout(
1984 resource->color_space); 1981 resource->color_space);
1985 } 1982 }
1986 1983
1987 LazyCreateImage(resource); 1984 LazyCreateImage(resource);
1988 resource->dirty_image = true; 1985 resource->dirty_image = true;
1989 resource->is_overlay_candidate = true; 1986 resource->is_overlay_candidate = true;
1990 // GpuMemoryBuffer provides direct access to the memory used by the GPU. 1987 // GpuMemoryBuffer provides direct access to the memory used by the GPU.
1991 // Read lock fences are required to ensure that we're not trying to map a 1988 // Read lock fences are required to ensure that we're not trying to map a
1992 // buffer that is currently in-use by the GPU. 1989 // buffer that is currently in-use by the GPU.
1993 resource->read_lock_fences_enabled = true; 1990 resource->read_lock_fences_enabled = true;
1994 } else if (use_texture_storage_ext_ && 1991 } else if (settings_.use_texture_storage_ext &&
1995 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && 1992 IsFormatSupportedForStorage(format,
1993 settings_.use_texture_format_bgra) &&
1996 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { 1994 (resource->hint & TEXTURE_HINT_IMMUTABLE)) {
1997 GLenum storage_format = TextureToStorageFormat(format); 1995 GLenum storage_format = TextureToStorageFormat(format);
1998 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), 1996 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(),
1999 size.height()); 1997 size.height());
2000 } else { 1998 } else {
2001 // ETC1 does not support preallocation. 1999 // ETC1 does not support preallocation.
2002 if (format != ETC1) { 2000 if (format != ETC1) {
2003 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), 2001 gl->TexImage2D(resource->target, 0, GLInternalFormat(format),
2004 size.width(), size.height(), 0, GLDataFormat(format), 2002 size.width(), size.height(), 0, GLDataFormat(format),
2005 GLDataType(format), nullptr); 2003 GLDataType(format), nullptr);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2162 2160
2163 const int kImportance = 2; 2161 const int kImportance = 2;
2164 pmd->CreateSharedGlobalAllocatorDump(guid); 2162 pmd->CreateSharedGlobalAllocatorDump(guid);
2165 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 2163 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
2166 } 2164 }
2167 2165
2168 return true; 2166 return true;
2169 } 2167 }
2170 2168
2171 } // namespace cc 2169 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698