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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 break; | 85 break; |
86 case BGRA_8888: | 86 case BGRA_8888: |
87 storage_format = GL_BGRA8_EXT; | 87 storage_format = GL_BGRA8_EXT; |
88 break; | 88 break; |
89 case RGBA_4444: | 89 case RGBA_4444: |
90 case ALPHA_8: | 90 case ALPHA_8: |
91 case LUMINANCE_8: | 91 case LUMINANCE_8: |
92 case RGB_565: | 92 case RGB_565: |
93 case ETC1: | 93 case ETC1: |
94 case RED_8: | 94 case RED_8: |
| 95 case RG_88: |
95 case LUMINANCE_F16: | 96 case LUMINANCE_F16: |
96 NOTREACHED(); | 97 NOTREACHED(); |
97 break; | 98 break; |
98 } | 99 } |
99 | 100 |
100 return storage_format; | 101 return storage_format; |
101 } | 102 } |
102 | 103 |
103 bool IsFormatSupportedForStorage(ResourceFormat format, bool use_bgra) { | 104 bool IsFormatSupportedForStorage(ResourceFormat format, bool use_bgra) { |
104 switch (format) { | 105 switch (format) { |
105 case RGBA_8888: | 106 case RGBA_8888: |
106 return true; | 107 return true; |
107 case BGRA_8888: | 108 case BGRA_8888: |
108 return use_bgra; | 109 return use_bgra; |
109 case RGBA_4444: | 110 case RGBA_4444: |
110 case ALPHA_8: | 111 case ALPHA_8: |
111 case LUMINANCE_8: | 112 case LUMINANCE_8: |
112 case RGB_565: | 113 case RGB_565: |
113 case ETC1: | 114 case ETC1: |
114 case RED_8: | 115 case RED_8: |
| 116 case RG_88: |
115 case LUMINANCE_F16: | 117 case LUMINANCE_F16: |
116 return false; | 118 return false; |
117 } | 119 } |
118 return false; | 120 return false; |
119 } | 121 } |
120 | 122 |
121 GrPixelConfig ToGrPixelConfig(ResourceFormat format) { | 123 GrPixelConfig ToGrPixelConfig(ResourceFormat format) { |
122 switch (format) { | 124 switch (format) { |
123 case RGBA_8888: | 125 case RGBA_8888: |
124 return kRGBA_8888_GrPixelConfig; | 126 return kRGBA_8888_GrPixelConfig; |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 next_id_(1), | 406 next_id_(1), |
405 next_child_(1), | 407 next_child_(1), |
406 delegated_sync_points_required_(delegated_sync_points_required), | 408 delegated_sync_points_required_(delegated_sync_points_required), |
407 default_resource_type_(use_gpu_memory_buffer_resources | 409 default_resource_type_(use_gpu_memory_buffer_resources |
408 ? RESOURCE_TYPE_GPU_MEMORY_BUFFER | 410 ? RESOURCE_TYPE_GPU_MEMORY_BUFFER |
409 : RESOURCE_TYPE_GL_TEXTURE), | 411 : RESOURCE_TYPE_GL_TEXTURE), |
410 use_texture_storage_ext_(false), | 412 use_texture_storage_ext_(false), |
411 use_texture_format_bgra_(false), | 413 use_texture_format_bgra_(false), |
412 use_texture_usage_hint_(false), | 414 use_texture_usage_hint_(false), |
413 use_compressed_texture_etc1_(false), | 415 use_compressed_texture_etc1_(false), |
414 yuv_resource_format_(LUMINANCE_8), | |
415 max_texture_size_(0), | 416 max_texture_size_(0), |
416 best_texture_format_(RGBA_8888), | 417 best_texture_format_(RGBA_8888), |
417 best_render_buffer_format_(RGBA_8888), | 418 best_render_buffer_format_(RGBA_8888), |
418 enable_color_correct_rendering_(enable_color_correct_rendering), | 419 enable_color_correct_rendering_(enable_color_correct_rendering), |
419 id_allocation_chunk_size_(id_allocation_chunk_size), | 420 id_allocation_chunk_size_(id_allocation_chunk_size), |
420 use_sync_query_(false), | 421 use_sync_query_(false), |
421 buffer_to_texture_target_map_(buffer_to_texture_target_map), | 422 buffer_to_texture_target_map_(buffer_to_texture_target_map), |
422 tracing_id_(g_next_resource_provider_tracing_id.GetNext()) { | 423 tracing_id_(g_next_resource_provider_tracing_id.GetNext()) { |
423 DCHECK(id_allocation_chunk_size_); | 424 DCHECK(id_allocation_chunk_size_); |
424 DCHECK(thread_checker_.CalledOnValidThread()); | 425 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 17 matching lines...) Expand all Loading... |
442 DCHECK(!texture_id_allocator_); | 443 DCHECK(!texture_id_allocator_); |
443 DCHECK(!buffer_id_allocator_); | 444 DCHECK(!buffer_id_allocator_); |
444 | 445 |
445 const auto& caps = compositor_context_provider_->ContextCapabilities(); | 446 const auto& caps = compositor_context_provider_->ContextCapabilities(); |
446 | 447 |
447 DCHECK(IsGpuResourceType(default_resource_type_)); | 448 DCHECK(IsGpuResourceType(default_resource_type_)); |
448 use_texture_storage_ext_ = caps.texture_storage; | 449 use_texture_storage_ext_ = caps.texture_storage; |
449 use_texture_format_bgra_ = caps.texture_format_bgra8888; | 450 use_texture_format_bgra_ = caps.texture_format_bgra8888; |
450 use_texture_usage_hint_ = caps.texture_usage; | 451 use_texture_usage_hint_ = caps.texture_usage; |
451 use_compressed_texture_etc1_ = caps.texture_format_etc1; | 452 use_compressed_texture_etc1_ = caps.texture_format_etc1; |
452 | |
453 if (caps.disable_one_component_textures) { | |
454 yuv_resource_format_ = yuv_highbit_resource_format_ = RGBA_8888; | |
455 } else { | |
456 yuv_resource_format_ = caps.texture_rg ? RED_8 : LUMINANCE_8; | |
457 yuv_highbit_resource_format_ = | |
458 caps.texture_half_float_linear ? LUMINANCE_F16 : yuv_resource_format_; | |
459 } | |
460 | |
461 use_sync_query_ = caps.sync_query; | 453 use_sync_query_ = caps.sync_query; |
462 | 454 |
463 GLES2Interface* gl = ContextGL(); | 455 GLES2Interface* gl = ContextGL(); |
464 | 456 |
465 max_texture_size_ = 0; // Context expects cleared value. | 457 max_texture_size_ = 0; // Context expects cleared value. |
466 gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_); | 458 gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_); |
467 best_texture_format_ = | 459 best_texture_format_ = |
468 PlatformColor::BestSupportedTextureFormat(use_texture_format_bgra_); | 460 PlatformColor::BestSupportedTextureFormat(use_texture_format_bgra_); |
469 | 461 |
470 best_render_buffer_format_ = PlatformColor::BestSupportedTextureFormat( | 462 best_render_buffer_format_ = PlatformColor::BestSupportedTextureFormat( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 case RGBA_4444: | 508 case RGBA_4444: |
517 case RGBA_8888: | 509 case RGBA_8888: |
518 case RGB_565: | 510 case RGB_565: |
519 case LUMINANCE_8: | 511 case LUMINANCE_8: |
520 return true; | 512 return true; |
521 case BGRA_8888: | 513 case BGRA_8888: |
522 return caps.texture_format_bgra8888; | 514 return caps.texture_format_bgra8888; |
523 case ETC1: | 515 case ETC1: |
524 return caps.texture_format_etc1; | 516 return caps.texture_format_etc1; |
525 case RED_8: | 517 case RED_8: |
| 518 case RG_88: |
526 return caps.texture_rg; | 519 return caps.texture_rg; |
527 case LUMINANCE_F16: | 520 case LUMINANCE_F16: |
528 return caps.texture_half_float_linear; | 521 return caps.texture_half_float_linear; |
529 } | 522 } |
530 | 523 |
531 NOTREACHED(); | 524 NOTREACHED(); |
532 return false; | 525 return false; |
533 } | 526 } |
534 | 527 |
535 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 528 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
536 Resource* resource = GetResource(id); | 529 Resource* resource = GetResource(id); |
537 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || | 530 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || |
538 resource->lost; | 531 resource->lost; |
539 } | 532 } |
540 | 533 |
541 bool ResourceProvider::IsLost(ResourceId id) { | 534 bool ResourceProvider::IsLost(ResourceId id) { |
542 Resource* resource = GetResource(id); | 535 Resource* resource = GetResource(id); |
543 return resource->lost; | 536 return resource->lost; |
544 } | 537 } |
545 | 538 |
546 void ResourceProvider::LoseResourceForTesting(ResourceId id) { | 539 void ResourceProvider::LoseResourceForTesting(ResourceId id) { |
547 Resource* resource = GetResource(id); | 540 Resource* resource = GetResource(id); |
548 DCHECK(resource); | 541 DCHECK(resource); |
549 resource->lost = true; | 542 resource->lost = true; |
550 } | 543 } |
551 | 544 |
552 ResourceFormat ResourceProvider::YuvResourceFormat(int bits) const { | |
553 if (bits > 8) { | |
554 return yuv_highbit_resource_format_; | |
555 } else { | |
556 return yuv_resource_format_; | |
557 } | |
558 } | |
559 | |
560 ResourceId ResourceProvider::CreateResource( | 545 ResourceId ResourceProvider::CreateResource( |
561 const gfx::Size& size, | 546 const gfx::Size& size, |
562 TextureHint hint, | 547 TextureHint hint, |
563 ResourceFormat format, | 548 ResourceFormat format, |
564 const gfx::ColorSpace& color_space) { | 549 const gfx::ColorSpace& color_space) { |
565 DCHECK(!size.IsEmpty()); | 550 DCHECK(!size.IsEmpty()); |
566 switch (default_resource_type_) { | 551 switch (default_resource_type_) { |
567 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: | 552 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: |
568 // GPU memory buffers don't support LUMINANCE_F16. | 553 // GPU memory buffers don't support LUMINANCE_F16. |
569 if (format != LUMINANCE_F16) { | 554 if (format != LUMINANCE_F16) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 Resource* resource = InsertResource( | 634 Resource* resource = InsertResource( |
650 id, | 635 id, |
651 Resource(pixels, bitmap.release(), size, Resource::INTERNAL, GL_LINEAR)); | 636 Resource(pixels, bitmap.release(), size, Resource::INTERNAL, GL_LINEAR)); |
652 resource->allocated = true; | 637 resource->allocated = true; |
653 resource->color_space = color_space; | 638 resource->color_space = color_space; |
654 return id; | 639 return id; |
655 } | 640 } |
656 | 641 |
657 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 642 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
658 const TextureMailbox& mailbox, | 643 const TextureMailbox& mailbox, |
| 644 ResourceFormat format, |
659 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl, | 645 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl, |
660 bool read_lock_fences_enabled) { | 646 bool read_lock_fences_enabled) { |
661 DCHECK(thread_checker_.CalledOnValidThread()); | 647 DCHECK(thread_checker_.CalledOnValidThread()); |
662 // Just store the information. Mailbox will be consumed in LockForRead(). | 648 // Just store the information. Mailbox will be consumed in LockForRead(). |
663 ResourceId id = next_id_++; | 649 ResourceId id = next_id_++; |
664 DCHECK(mailbox.IsValid()); | 650 DCHECK(mailbox.IsValid()); |
665 Resource* resource = nullptr; | 651 Resource* resource = nullptr; |
666 if (mailbox.IsTexture()) { | 652 if (mailbox.IsTexture()) { |
667 resource = InsertResource( | 653 resource = InsertResource( |
668 id, | 654 id, Resource(0, mailbox.size_in_pixels(), Resource::EXTERNAL, |
669 Resource(0, mailbox.size_in_pixels(), Resource::EXTERNAL, | 655 mailbox.target(), |
670 mailbox.target(), | 656 mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR, |
671 mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR, | 657 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE, format)); |
672 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE, RGBA_8888)); | |
673 } else { | 658 } else { |
674 DCHECK(mailbox.IsSharedMemory()); | 659 DCHECK(mailbox.IsSharedMemory()); |
675 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); | 660 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); |
676 uint8_t* pixels = shared_bitmap->pixels(); | 661 uint8_t* pixels = shared_bitmap->pixels(); |
677 DCHECK(pixels); | 662 DCHECK(pixels); |
678 resource = InsertResource( | 663 resource = InsertResource( |
679 id, Resource(pixels, shared_bitmap, mailbox.size_in_pixels(), | 664 id, Resource(pixels, shared_bitmap, mailbox.size_in_pixels(), |
680 Resource::EXTERNAL, GL_LINEAR)); | 665 Resource::EXTERNAL, GL_LINEAR)); |
| 666 resource->format = format; |
681 } | 667 } |
682 resource->allocated = true; | 668 resource->allocated = true; |
683 resource->set_mailbox(mailbox); | 669 resource->set_mailbox(mailbox); |
684 resource->color_space = mailbox.color_space(); | 670 resource->color_space = mailbox.color_space(); |
685 resource->release_callback_impl = | 671 resource->release_callback_impl = |
686 base::Bind(&SingleReleaseCallbackImpl::Run, | 672 base::Bind(&SingleReleaseCallbackImpl::Run, |
687 base::Owned(release_callback_impl.release())); | 673 base::Owned(release_callback_impl.release())); |
688 resource->read_lock_fences_enabled = read_lock_fences_enabled; | 674 resource->read_lock_fences_enabled = read_lock_fences_enabled; |
689 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); | 675 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); |
690 resource->color_space = mailbox.color_space(); | 676 resource->color_space = mailbox.color_space(); |
691 | 677 |
692 return id; | 678 return id; |
693 } | 679 } |
694 | 680 |
| 681 // TODO(dswang): remove this method. crbug.com/624436 |
| 682 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 683 const TextureMailbox& mailbox, |
| 684 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl, |
| 685 bool read_lock_fences_enabled) { |
| 686 return CreateResourceFromTextureMailbox( |
| 687 mailbox, RGBA_8888, std::move(release_callback_impl), false); |
| 688 } |
| 689 |
695 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 690 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
696 const TextureMailbox& mailbox, | 691 const TextureMailbox& mailbox, |
697 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl) { | 692 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl) { |
698 return CreateResourceFromTextureMailbox( | 693 return CreateResourceFromTextureMailbox( |
699 mailbox, std::move(release_callback_impl), false); | 694 mailbox, std::move(release_callback_impl), false); |
700 } | 695 } |
701 | 696 |
702 void ResourceProvider::DeleteResource(ResourceId id) { | 697 void ResourceProvider::DeleteResource(ResourceId id) { |
703 DCHECK(thread_checker_.CalledOnValidThread()); | 698 DCHECK(thread_checker_.CalledOnValidThread()); |
704 ResourceMap::iterator it = resources_.find(id); | 699 ResourceMap::iterator it = resources_.find(id); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 | 813 |
819 ResourceProvider::ResourceType ResourceProvider::GetResourceType( | 814 ResourceProvider::ResourceType ResourceProvider::GetResourceType( |
820 ResourceId id) { | 815 ResourceId id) { |
821 return GetResource(id)->type; | 816 return GetResource(id)->type; |
822 } | 817 } |
823 | 818 |
824 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) { | 819 GLenum ResourceProvider::GetResourceTextureTarget(ResourceId id) { |
825 return GetResource(id)->target; | 820 return GetResource(id)->target; |
826 } | 821 } |
827 | 822 |
| 823 ResourceFormat ResourceProvider::GetResourceFormat(ResourceId id) { |
| 824 return GetResource(id)->format; |
| 825 } |
| 826 |
828 bool ResourceProvider::IsImmutable(ResourceId id) { | 827 bool ResourceProvider::IsImmutable(ResourceId id) { |
829 if (IsGpuResourceType(default_resource_type_)) { | 828 if (IsGpuResourceType(default_resource_type_)) { |
830 return GetTextureHint(id) == TEXTURE_HINT_IMMUTABLE; | 829 return GetTextureHint(id) == TEXTURE_HINT_IMMUTABLE; |
831 } else { | 830 } else { |
832 // Software resources are immutable; they cannot change format or be | 831 // Software resources are immutable; they cannot change format or be |
833 // resized. | 832 // resized. |
834 return true; | 833 return true; |
835 } | 834 } |
836 } | 835 } |
837 | 836 |
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2059 | 2058 |
2060 const int kImportance = 2; | 2059 const int kImportance = 2; |
2061 pmd->CreateSharedGlobalAllocatorDump(guid); | 2060 pmd->CreateSharedGlobalAllocatorDump(guid); |
2062 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2061 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
2063 } | 2062 } |
2064 | 2063 |
2065 return true; | 2064 return true; |
2066 } | 2065 } |
2067 | 2066 |
2068 } // namespace cc | 2067 } // namespace cc |
OLD | NEW |