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

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

Issue 2662303004: Move const ResourceProvider members into Settings struct (Closed)
Patch Set: fix build 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
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 : default_resource_type(use_gpu_memory_buffer_resources
407 ? RESOURCE_TYPE_GPU_MEMORY_BUFFER
408 : RESOURCE_TYPE_GL_TEXTURE),
409 enable_color_correct_rendering(enable_color_correct_rendering),
410 delegated_sync_points_required(delegated_sync_points_required) {
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_) { 478 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; 479 return;
454 }
455 480
456 DCHECK(!texture_id_allocator_); 481 DCHECK(!texture_id_allocator_);
457 DCHECK(!buffer_id_allocator_); 482 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(); 483 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( 484 texture_id_allocator_.reset(
488 new TextureIdAllocator(gl, id_allocation_chunk_size_)); 485 new TextureIdAllocator(gl, id_allocation_chunk_size));
489 buffer_id_allocator_.reset( 486 buffer_id_allocator_.reset(
490 new BufferIdAllocator(gl, id_allocation_chunk_size_)); 487 new BufferIdAllocator(gl, id_allocation_chunk_size));
491 } 488 }
492 489
493 ResourceProvider::~ResourceProvider() { 490 ResourceProvider::~ResourceProvider() {
494 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( 491 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
495 this); 492 this);
496 493
497 while (!children_.empty()) 494 while (!children_.empty())
498 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN); 495 DestroyChildInternal(children_.begin(), FOR_SHUTDOWN);
499 while (!resources_.empty()) 496 while (!resources_.empty())
500 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN); 497 DeleteResourceInternal(resources_.begin(), FOR_SHUTDOWN);
501 498
502 GLES2Interface* gl = ContextGL(); 499 GLES2Interface* gl = ContextGL();
503 if (!IsGpuResourceType(default_resource_type_)) { 500 if (!IsGpuResourceType(settings_.default_resource_type)) {
504 // We are not in GL mode, but double check before returning. 501 // We are not in GL mode, but double check before returning.
505 DCHECK(!gl); 502 DCHECK(!gl);
506 return; 503 return;
507 } 504 }
508 505
509 DCHECK(gl); 506 DCHECK(gl);
510 #if DCHECK_IS_ON() 507 #if DCHECK_IS_ON()
511 // Check that all GL resources has been deleted. 508 // Check that all GL resources has been deleted.
512 for (ResourceMap::const_iterator itr = resources_.begin(); 509 for (ResourceMap::const_iterator itr = resources_.begin();
513 itr != resources_.end(); ++itr) { 510 itr != resources_.end(); ++itr) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 } 555 }
559 556
560 void ResourceProvider::LoseResourceForTesting(ResourceId id) { 557 void ResourceProvider::LoseResourceForTesting(ResourceId id) {
561 Resource* resource = GetResource(id); 558 Resource* resource = GetResource(id);
562 DCHECK(resource); 559 DCHECK(resource);
563 resource->lost = true; 560 resource->lost = true;
564 } 561 }
565 562
566 ResourceFormat ResourceProvider::YuvResourceFormat(int bits) const { 563 ResourceFormat ResourceProvider::YuvResourceFormat(int bits) const {
567 if (bits > 8) { 564 if (bits > 8) {
568 return yuv_highbit_resource_format_; 565 return settings_.yuv_highbit_resource_format;
569 } else { 566 } else {
570 return yuv_resource_format_; 567 return settings_.yuv_resource_format;
571 } 568 }
572 } 569 }
573 570
574 ResourceId ResourceProvider::CreateResource( 571 ResourceId ResourceProvider::CreateResource(
575 const gfx::Size& size, 572 const gfx::Size& size,
576 TextureHint hint, 573 TextureHint hint,
577 ResourceFormat format, 574 ResourceFormat format,
578 const gfx::ColorSpace& color_space) { 575 const gfx::ColorSpace& color_space) {
579 DCHECK(!size.IsEmpty()); 576 DCHECK(!size.IsEmpty());
580 switch (default_resource_type_) { 577 switch (settings_.default_resource_type) {
581 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: 578 case RESOURCE_TYPE_GPU_MEMORY_BUFFER:
582 // GPU memory buffers don't support LUMINANCE_F16. 579 // GPU memory buffers don't support LUMINANCE_F16.
583 if (format != LUMINANCE_F16) { 580 if (format != LUMINANCE_F16) {
584 return CreateGLTexture( 581 return CreateGLTexture(
585 size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, format, 582 size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, format,
586 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, color_space); 583 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, color_space);
587 } 584 }
588 // Fall through and use a regular texture. 585 // Fall through and use a regular texture.
589 case RESOURCE_TYPE_GL_TEXTURE: 586 case RESOURCE_TYPE_GL_TEXTURE:
590 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format, 587 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format,
591 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, 588 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
592 color_space); 589 color_space);
593 590
594 case RESOURCE_TYPE_BITMAP: 591 case RESOURCE_TYPE_BITMAP:
595 DCHECK_EQ(RGBA_8888, format); 592 DCHECK_EQ(RGBA_8888, format);
596 return CreateBitmap(size, color_space); 593 return CreateBitmap(size, color_space);
597 } 594 }
598 595
599 LOG(FATAL) << "Invalid default resource type."; 596 LOG(FATAL) << "Invalid default resource type.";
600 return 0; 597 return 0;
601 } 598 }
602 599
603 ResourceId ResourceProvider::CreateGpuMemoryBufferResource( 600 ResourceId ResourceProvider::CreateGpuMemoryBufferResource(
604 const gfx::Size& size, 601 const gfx::Size& size,
605 TextureHint hint, 602 TextureHint hint,
606 ResourceFormat format, 603 ResourceFormat format,
607 gfx::BufferUsage usage, 604 gfx::BufferUsage usage,
608 const gfx::ColorSpace& color_space) { 605 const gfx::ColorSpace& color_space) {
609 DCHECK(!size.IsEmpty()); 606 DCHECK(!size.IsEmpty());
610 switch (default_resource_type_) { 607 switch (settings_.default_resource_type) {
611 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: 608 case RESOURCE_TYPE_GPU_MEMORY_BUFFER:
612 case RESOURCE_TYPE_GL_TEXTURE: { 609 case RESOURCE_TYPE_GL_TEXTURE: {
613 return CreateGLTexture(size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, 610 return CreateGLTexture(size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER,
614 format, usage, color_space); 611 format, usage, color_space);
615 } 612 }
616 case RESOURCE_TYPE_BITMAP: 613 case RESOURCE_TYPE_BITMAP:
617 DCHECK_EQ(RGBA_8888, format); 614 DCHECK_EQ(RGBA_8888, format);
618 return CreateBitmap(size, color_space); 615 return CreateBitmap(size, color_space);
619 } 616 }
620 617
621 LOG(FATAL) << "Invalid default resource type."; 618 LOG(FATAL) << "Invalid default resource type.";
622 return 0; 619 return 0;
623 } 620 }
624 621
625 ResourceId ResourceProvider::CreateGLTexture( 622 ResourceId ResourceProvider::CreateGLTexture(
626 const gfx::Size& size, 623 const gfx::Size& size,
627 TextureHint hint, 624 TextureHint hint,
628 ResourceType type, 625 ResourceType type,
629 ResourceFormat format, 626 ResourceFormat format,
630 gfx::BufferUsage usage, 627 gfx::BufferUsage usage,
631 const gfx::ColorSpace& color_space) { 628 const gfx::ColorSpace& color_space) {
632 DCHECK_LE(size.width(), max_texture_size_); 629 DCHECK_LE(size.width(), settings_.max_texture_size);
633 DCHECK_LE(size.height(), max_texture_size_); 630 DCHECK_LE(size.height(), settings_.max_texture_size);
634 DCHECK(thread_checker_.CalledOnValidThread()); 631 DCHECK(thread_checker_.CalledOnValidThread());
635 632
636 // TODO(crbug.com/590317): We should not assume that all resources created by 633 // 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 634 // ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this
638 // based on the current RasterBufferProvider's needs. 635 // based on the current RasterBufferProvider's needs.
639 GLenum target = type == RESOURCE_TYPE_GPU_MEMORY_BUFFER 636 GLenum target = type == RESOURCE_TYPE_GPU_MEMORY_BUFFER
640 ? GetImageTextureTarget(usage, format) 637 ? GetImageTextureTarget(usage, format)
641 : GL_TEXTURE_2D; 638 : GL_TEXTURE_2D;
642 639
643 ResourceId id = next_id_++; 640 ResourceId id = next_id_++;
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 ResourceProvider::ResourceType ResourceProvider::GetResourceType( 849 ResourceProvider::ResourceType ResourceProvider::GetResourceType(
853 ResourceId id) { 850 ResourceId id) {
854 return GetResource(id)->type; 851 return GetResource(id)->type;
855 } 852 }
856 853
857 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) { 854 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) {
858 return GetResource(id)->target; 855 return GetResource(id)->target;
859 } 856 }
860 857
861 bool ResourceProvider::IsImmutable(ResourceId id) { 858 bool ResourceProvider::IsImmutable(ResourceId id) {
862 if (IsGpuResourceType(default_resource_type_)) { 859 if (IsGpuResourceType(settings_.default_resource_type)) {
863 return GetTextureHint(id) == TEXTURE_HINT_IMMUTABLE; 860 return GetTextureHint(id) == TEXTURE_HINT_IMMUTABLE;
864 } else { 861 } else {
865 // Software resources are immutable; they cannot change format or be 862 // Software resources are immutable; they cannot change format or be
866 // resized. 863 // resized.
867 return true; 864 return true;
868 } 865 }
869 } 866 }
870 867
871 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) { 868 ResourceProvider::TextureHint ResourceProvider::GetTextureHint(ResourceId id) {
872 return GetResource(id)->hint; 869 return GetResource(id)->hint;
873 } 870 }
874 871
875 sk_sp<SkColorSpace> ResourceProvider::GetResourceSkColorSpace( 872 sk_sp<SkColorSpace> ResourceProvider::GetResourceSkColorSpace(
876 const Resource* resource) const { 873 const Resource* resource) const {
877 if (!enable_color_correct_rendering_) 874 if (!settings_.enable_color_correct_rendering)
878 return nullptr; 875 return nullptr;
879 return resource->color_space.ToSkColorSpace(); 876 return resource->color_space.ToSkColorSpace();
880 } 877 }
881 878
882 void ResourceProvider::CopyToResource(ResourceId id, 879 void ResourceProvider::CopyToResource(ResourceId id,
883 const uint8_t* image, 880 const uint8_t* image,
884 const gfx::Size& image_size) { 881 const gfx::Size& image_size) {
885 Resource* resource = GetResource(id); 882 Resource* resource = GetResource(id);
886 DCHECK(!resource->locked_for_write); 883 DCHECK(!resource->locked_for_write);
887 DCHECK(!resource->lock_for_read_count); 884 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); 1344 gpu_memory_buffer_ = std::move(resource->gpu_memory_buffer);
1348 resource->gpu_memory_buffer = nullptr; 1345 resource->gpu_memory_buffer = nullptr;
1349 } 1346 }
1350 1347
1351 ResourceProvider::ScopedWriteLockGpuMemoryBuffer:: 1348 ResourceProvider::ScopedWriteLockGpuMemoryBuffer::
1352 ~ScopedWriteLockGpuMemoryBuffer() { 1349 ~ScopedWriteLockGpuMemoryBuffer() {
1353 DCHECK(thread_checker_.CalledOnValidThread()); 1350 DCHECK(thread_checker_.CalledOnValidThread());
1354 Resource* resource = resource_provider_->GetResource(resource_id_); 1351 Resource* resource = resource_provider_->GetResource(resource_id_);
1355 DCHECK(resource); 1352 DCHECK(resource);
1356 if (gpu_memory_buffer_) { 1353 if (gpu_memory_buffer_) {
1357 if (resource_provider_->enable_color_correct_rendering_) 1354 if (resource_provider_->settings_.enable_color_correct_rendering)
1358 gpu_memory_buffer_->SetColorSpaceForScanout(resource->color_space); 1355 gpu_memory_buffer_->SetColorSpaceForScanout(resource->color_space);
1359 DCHECK(!resource->gpu_memory_buffer); 1356 DCHECK(!resource->gpu_memory_buffer);
1360 resource_provider_->LazyCreate(resource); 1357 resource_provider_->LazyCreate(resource);
1361 resource->gpu_memory_buffer = std::move(gpu_memory_buffer_); 1358 resource->gpu_memory_buffer = std::move(gpu_memory_buffer_);
1362 resource->allocated = true; 1359 resource->allocated = true;
1363 resource_provider_->LazyCreateImage(resource); 1360 resource_provider_->LazyCreateImage(resource);
1364 resource->dirty_image = true; 1361 resource->dirty_image = true;
1365 resource->is_overlay_candidate = true; 1362 resource->is_overlay_candidate = true;
1366 // GpuMemoryBuffer provides direct access to the memory used by the GPU. 1363 // 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 1364 // 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 1466 // 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. 1467 // as pointers so we don't have to look up the resource id multiple times.
1471 std::vector<Resource*> resources; 1468 std::vector<Resource*> resources;
1472 resources.reserve(resource_ids.size()); 1469 resources.reserve(resource_ids.size());
1473 for (const ResourceId id : resource_ids) { 1470 for (const ResourceId id : resource_ids) {
1474 Resource* resource = GetResource(id); 1471 Resource* resource = GetResource(id);
1475 // Check the synchronization and sync token state when delegated sync points 1472 // 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 1473 // 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 1474 // 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. 1475 // lazily and generate a sync token at that point.
1479 DCHECK(!delegated_sync_points_required_ || resource->dirty_image || 1476 DCHECK(!settings_.delegated_sync_points_required || resource->dirty_image ||
1480 !resource->needs_sync_token()); 1477 !resource->needs_sync_token());
1481 1478
1482 // If we are validating the resource to be sent, the resource cannot be 1479 // 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. 1480 // in a LOCALLY_USED state. It must have been properly synchronized.
1484 DCHECK(!delegated_sync_points_required_ || 1481 DCHECK(!settings_.delegated_sync_points_required ||
1485 Resource::LOCALLY_USED != resource->synchronization_state()); 1482 Resource::LOCALLY_USED != resource->synchronization_state());
1486 1483
1487 resources.push_back(resource); 1484 resources.push_back(resource);
1488 } 1485 }
1489 1486
1490 // Lazily create any mailboxes and verify all unverified sync tokens. 1487 // Lazily create any mailboxes and verify all unverified sync tokens.
1491 std::vector<GLbyte*> unverified_sync_tokens; 1488 std::vector<GLbyte*> unverified_sync_tokens;
1492 std::vector<Resource*> need_synchronization_resources; 1489 std::vector<Resource*> need_synchronization_resources;
1493 for (Resource* resource : resources) { 1490 for (Resource* resource : resources) {
1494 if (!IsGpuResourceType(resource->type)) 1491 if (!IsGpuResourceType(resource->type))
1495 continue; 1492 continue;
1496 1493
1497 CreateMailboxAndBindResource(gl, resource); 1494 CreateMailboxAndBindResource(gl, resource);
1498 1495
1499 if (delegated_sync_points_required_) { 1496 if (settings_.delegated_sync_points_required) {
1500 if (resource->needs_sync_token()) { 1497 if (resource->needs_sync_token()) {
1501 need_synchronization_resources.push_back(resource); 1498 need_synchronization_resources.push_back(resource);
1502 } else if (resource->mailbox().HasSyncToken() && 1499 } else if (resource->mailbox().HasSyncToken() &&
1503 !resource->mailbox().sync_token().verified_flush()) { 1500 !resource->mailbox().sync_token().verified_flush()) {
1504 unverified_sync_tokens.push_back(resource->GetSyncTokenData()); 1501 unverified_sync_tokens.push_back(resource->GetSyncTokenData());
1505 } 1502 }
1506 } 1503 }
1507 } 1504 }
1508 1505
1509 // Insert sync point to synchronize the mailbox creation or bound textures. 1506 // Insert sync point to synchronize the mailbox creation or bound textures.
1510 gpu::SyncToken new_sync_token; 1507 gpu::SyncToken new_sync_token;
1511 if (!need_synchronization_resources.empty()) { 1508 if (!need_synchronization_resources.empty()) {
1512 DCHECK(delegated_sync_points_required_); 1509 DCHECK(settings_.delegated_sync_points_required);
1513 DCHECK(gl); 1510 DCHECK(gl);
1514 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM(); 1511 const uint64_t fence_sync = gl->InsertFenceSyncCHROMIUM();
1515 gl->OrderingBarrierCHROMIUM(); 1512 gl->OrderingBarrierCHROMIUM();
1516 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData()); 1513 gl->GenUnverifiedSyncTokenCHROMIUM(fence_sync, new_sync_token.GetData());
1517 unverified_sync_tokens.push_back(new_sync_token.GetData()); 1514 unverified_sync_tokens.push_back(new_sync_token.GetData());
1518 } 1515 }
1519 1516
1520 if (!unverified_sync_tokens.empty()) { 1517 if (!unverified_sync_tokens.empty()) {
1521 DCHECK(delegated_sync_points_required_); 1518 DCHECK(settings_.delegated_sync_points_required);
1522 DCHECK(gl); 1519 DCHECK(gl);
1523 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(), 1520 gl->VerifySyncTokensCHROMIUM(unverified_sync_tokens.data(),
1524 unverified_sync_tokens.size()); 1521 unverified_sync_tokens.size());
1525 } 1522 }
1526 1523
1527 // Set sync token after verification. 1524 // Set sync token after verification.
1528 for (Resource* resource : need_synchronization_resources) { 1525 for (Resource* resource : need_synchronization_resources) {
1529 DCHECK(IsGpuResourceType(resource->type)); 1526 DCHECK(IsGpuResourceType(resource->type));
1530 resource->UpdateSyncToken(new_sync_token); 1527 resource->UpdateSyncToken(new_sync_token);
1531 resource->SetSynchronized(); 1528 resource->SetSynchronized();
1532 } 1529 }
1533 1530
1534 // Transfer Resources 1531 // Transfer Resources
1535 DCHECK_EQ(resources.size(), resource_ids.size()); 1532 DCHECK_EQ(resources.size(), resource_ids.size());
1536 for (size_t i = 0; i < resources.size(); ++i) { 1533 for (size_t i = 0; i < resources.size(); ++i) {
1537 Resource* source = resources[i]; 1534 Resource* source = resources[i];
1538 const ResourceId id = resource_ids[i]; 1535 const ResourceId id = resource_ids[i];
1539 1536
1540 DCHECK(!delegated_sync_points_required_ || !source->needs_sync_token()); 1537 DCHECK(!settings_.delegated_sync_points_required ||
1541 DCHECK(!delegated_sync_points_required_ || 1538 !source->needs_sync_token());
1539 DCHECK(!settings_.delegated_sync_points_required ||
1542 Resource::LOCALLY_USED != source->synchronization_state()); 1540 Resource::LOCALLY_USED != source->synchronization_state());
1543 1541
1544 TransferableResource resource; 1542 TransferableResource resource;
1545 TransferResource(source, id, &resource); 1543 TransferResource(source, id, &resource);
1546 1544
1547 source->exported_count++; 1545 source->exported_count++;
1548 list->push_back(resource); 1546 list->push_back(resource);
1549 } 1547 }
1550 } 1548 }
1551 1549
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 DCHECK(gl); 1943 DCHECK(gl);
1946 1944
1947 // Create and set texture properties. Allocation is delayed until needed. 1945 // Create and set texture properties. Allocation is delayed until needed.
1948 gl->BindTexture(resource->target, resource->gl_id); 1946 gl->BindTexture(resource->target, resource->gl_id);
1949 gl->TexParameteri(resource->target, GL_TEXTURE_MIN_FILTER, 1947 gl->TexParameteri(resource->target, GL_TEXTURE_MIN_FILTER,
1950 resource->original_filter); 1948 resource->original_filter);
1951 gl->TexParameteri(resource->target, GL_TEXTURE_MAG_FILTER, 1949 gl->TexParameteri(resource->target, GL_TEXTURE_MAG_FILTER,
1952 resource->original_filter); 1950 resource->original_filter);
1953 gl->TexParameteri(resource->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1951 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); 1952 gl->TexParameteri(resource->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1955 if (use_texture_usage_hint_ && (resource->hint & TEXTURE_HINT_FRAMEBUFFER)) { 1953 if (settings_.use_texture_usage_hint &&
1954 (resource->hint & TEXTURE_HINT_FRAMEBUFFER)) {
1956 gl->TexParameteri(resource->target, GL_TEXTURE_USAGE_ANGLE, 1955 gl->TexParameteri(resource->target, GL_TEXTURE_USAGE_ANGLE,
1957 GL_FRAMEBUFFER_ATTACHMENT_ANGLE); 1956 GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
1958 } 1957 }
1959 } 1958 }
1960 1959
1961 void ResourceProvider::AllocateForTesting(ResourceId id) { 1960 void ResourceProvider::AllocateForTesting(ResourceId id) {
1962 LazyAllocate(GetResource(id)); 1961 LazyAllocate(GetResource(id));
1963 } 1962 }
1964 1963
1965 void ResourceProvider::LazyAllocate(Resource* resource) { 1964 void ResourceProvider::LazyAllocate(Resource* resource) {
1966 DCHECK(resource); 1965 DCHECK(resource);
1967 if (resource->allocated) 1966 if (resource->allocated)
1968 return; 1967 return;
1969 LazyCreate(resource); 1968 LazyCreate(resource);
1970 if (!resource->gl_id) 1969 if (!resource->gl_id)
1971 return; 1970 return;
1972 resource->allocated = true; 1971 resource->allocated = true;
1973 GLES2Interface* gl = ContextGL(); 1972 GLES2Interface* gl = ContextGL();
1974 gfx::Size& size = resource->size; 1973 gfx::Size& size = resource->size;
1975 ResourceFormat format = resource->format; 1974 ResourceFormat format = resource->format;
1976 gl->BindTexture(resource->target, resource->gl_id); 1975 gl->BindTexture(resource->target, resource->gl_id);
1977 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) { 1976 if (resource->type == RESOURCE_TYPE_GPU_MEMORY_BUFFER) {
1978 resource->gpu_memory_buffer = 1977 resource->gpu_memory_buffer =
1979 gpu_memory_buffer_manager_->CreateGpuMemoryBuffer( 1978 gpu_memory_buffer_manager_->CreateGpuMemoryBuffer(
1980 size, BufferFormat(format), resource->usage, 1979 size, BufferFormat(format), resource->usage,
1981 gpu::kNullSurfaceHandle); 1980 gpu::kNullSurfaceHandle);
1982 if (resource->gpu_memory_buffer && enable_color_correct_rendering_) { 1981 if (resource->gpu_memory_buffer &&
1982 settings_.enable_color_correct_rendering) {
1983 resource->gpu_memory_buffer->SetColorSpaceForScanout( 1983 resource->gpu_memory_buffer->SetColorSpaceForScanout(
1984 resource->color_space); 1984 resource->color_space);
1985 } 1985 }
1986 1986
1987 LazyCreateImage(resource); 1987 LazyCreateImage(resource);
1988 resource->dirty_image = true; 1988 resource->dirty_image = true;
1989 resource->is_overlay_candidate = true; 1989 resource->is_overlay_candidate = true;
1990 // GpuMemoryBuffer provides direct access to the memory used by the GPU. 1990 // 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 1991 // 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. 1992 // buffer that is currently in-use by the GPU.
1993 resource->read_lock_fences_enabled = true; 1993 resource->read_lock_fences_enabled = true;
1994 } else if (use_texture_storage_ext_ && 1994 } else if (settings_.use_texture_storage_ext &&
1995 IsFormatSupportedForStorage(format, use_texture_format_bgra_) && 1995 IsFormatSupportedForStorage(format,
1996 settings_.use_texture_format_bgra) &&
1996 (resource->hint & TEXTURE_HINT_IMMUTABLE)) { 1997 (resource->hint & TEXTURE_HINT_IMMUTABLE)) {
1997 GLenum storage_format = TextureToStorageFormat(format); 1998 GLenum storage_format = TextureToStorageFormat(format);
1998 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(), 1999 gl->TexStorage2DEXT(resource->target, 1, storage_format, size.width(),
1999 size.height()); 2000 size.height());
2000 } else { 2001 } else {
2001 // ETC1 does not support preallocation. 2002 // ETC1 does not support preallocation.
2002 if (format != ETC1) { 2003 if (format != ETC1) {
2003 gl->TexImage2D(resource->target, 0, GLInternalFormat(format), 2004 gl->TexImage2D(resource->target, 0, GLInternalFormat(format),
2004 size.width(), size.height(), 0, GLDataFormat(format), 2005 size.width(), size.height(), 0, GLDataFormat(format),
2005 GLDataType(format), nullptr); 2006 GLDataType(format), nullptr);
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2162 2163
2163 const int kImportance = 2; 2164 const int kImportance = 2;
2164 pmd->CreateSharedGlobalAllocatorDump(guid); 2165 pmd->CreateSharedGlobalAllocatorDump(guid);
2165 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); 2166 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance);
2166 } 2167 }
2167 2168
2168 return true; 2169 return true;
2169 } 2170 }
2170 2171
2171 } // namespace cc 2172 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698