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> |
11 #include <limits> | 11 #include <limits> |
12 #include <unordered_map> | 12 #include <unordered_map> |
13 | 13 |
14 #include "base/atomic_sequence_num.h" | 14 #include "base/atomic_sequence_num.h" |
| 15 #include "base/command_line.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
17 #include "base/numerics/safe_math.h" | 18 #include "base/numerics/safe_math.h" |
18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
19 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
22 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
23 #include "base/trace_event/memory_dump_manager.h" | 24 #include "base/trace_event/memory_dump_manager.h" |
24 #include "base/trace_event/trace_event.h" | 25 #include "base/trace_event/trace_event.h" |
| 26 #include "cc/base/switches.h" |
25 #include "cc/resources/platform_color.h" | 27 #include "cc/resources/platform_color.h" |
26 #include "cc/resources/resource_util.h" | 28 #include "cc/resources/resource_util.h" |
27 #include "cc/resources/returned_resource.h" | 29 #include "cc/resources/returned_resource.h" |
28 #include "cc/resources/shared_bitmap_manager.h" | 30 #include "cc/resources/shared_bitmap_manager.h" |
29 #include "cc/resources/transferable_resource.h" | 31 #include "cc/resources/transferable_resource.h" |
30 #include "gpu/GLES2/gl2extchromium.h" | 32 #include "gpu/GLES2/gl2extchromium.h" |
31 #include "gpu/command_buffer/client/context_support.h" | 33 #include "gpu/command_buffer/client/context_support.h" |
32 #include "gpu/command_buffer/client/gles2_interface.h" | 34 #include "gpu/command_buffer/client/gles2_interface.h" |
33 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 35 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
34 #include "skia/ext/texture_handle.h" | 36 #include "skia/ext/texture_handle.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 break; | 87 break; |
86 case BGRA_8888: | 88 case BGRA_8888: |
87 storage_format = GL_BGRA8_EXT; | 89 storage_format = GL_BGRA8_EXT; |
88 break; | 90 break; |
89 case RGBA_4444: | 91 case RGBA_4444: |
90 case ALPHA_8: | 92 case ALPHA_8: |
91 case LUMINANCE_8: | 93 case LUMINANCE_8: |
92 case RGB_565: | 94 case RGB_565: |
93 case ETC1: | 95 case ETC1: |
94 case RED_8: | 96 case RED_8: |
| 97 case RG_88: |
95 case LUMINANCE_F16: | 98 case LUMINANCE_F16: |
96 NOTREACHED(); | 99 NOTREACHED(); |
97 break; | 100 break; |
98 } | 101 } |
99 | 102 |
100 return storage_format; | 103 return storage_format; |
101 } | 104 } |
102 | 105 |
103 bool IsFormatSupportedForStorage(ResourceFormat format, bool use_bgra) { | 106 bool IsFormatSupportedForStorage(ResourceFormat format, bool use_bgra) { |
104 switch (format) { | 107 switch (format) { |
105 case RGBA_8888: | 108 case RGBA_8888: |
106 return true; | 109 return true; |
107 case BGRA_8888: | 110 case BGRA_8888: |
108 return use_bgra; | 111 return use_bgra; |
109 case RGBA_4444: | 112 case RGBA_4444: |
110 case ALPHA_8: | 113 case ALPHA_8: |
111 case LUMINANCE_8: | 114 case LUMINANCE_8: |
112 case RGB_565: | 115 case RGB_565: |
113 case ETC1: | 116 case ETC1: |
114 case RED_8: | 117 case RED_8: |
| 118 case RG_88: |
115 case LUMINANCE_F16: | 119 case LUMINANCE_F16: |
116 return false; | 120 return false; |
117 } | 121 } |
118 return false; | 122 return false; |
119 } | 123 } |
120 | 124 |
121 GrPixelConfig ToGrPixelConfig(ResourceFormat format) { | 125 GrPixelConfig ToGrPixelConfig(ResourceFormat format) { |
122 switch (format) { | 126 switch (format) { |
123 case RGBA_8888: | 127 case RGBA_8888: |
124 return kRGBA_8888_GrPixelConfig; | 128 return kRGBA_8888_GrPixelConfig; |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 use_texture_format_bgra_ = caps.texture_format_bgra8888; | 453 use_texture_format_bgra_ = caps.texture_format_bgra8888; |
450 use_texture_usage_hint_ = caps.texture_usage; | 454 use_texture_usage_hint_ = caps.texture_usage; |
451 use_compressed_texture_etc1_ = caps.texture_format_etc1; | 455 use_compressed_texture_etc1_ = caps.texture_format_etc1; |
452 | 456 |
453 if (caps.disable_one_component_textures) { | 457 if (caps.disable_one_component_textures) { |
454 yuv_resource_format_ = yuv_highbit_resource_format_ = RGBA_8888; | 458 yuv_resource_format_ = yuv_highbit_resource_format_ = RGBA_8888; |
455 } else { | 459 } else { |
456 yuv_resource_format_ = caps.texture_rg ? RED_8 : LUMINANCE_8; | 460 yuv_resource_format_ = caps.texture_rg ? RED_8 : LUMINANCE_8; |
457 yuv_highbit_resource_format_ = | 461 yuv_highbit_resource_format_ = |
458 caps.texture_half_float_linear ? LUMINANCE_F16 : yuv_resource_format_; | 462 caps.texture_half_float_linear ? LUMINANCE_F16 : yuv_resource_format_; |
| 463 const base::CommandLine* command_line = |
| 464 base::CommandLine::ForCurrentProcess(); |
| 465 if (command_line->HasSwitch(switches::kDisableHalfFloatConversionTexture) || |
| 466 !caps.texture_half_float_linear) { |
| 467 yuv_highbit_resource_format_ = |
| 468 caps.texture_rg ? RG_88 : yuv_highbit_resource_format_; |
| 469 } |
459 } | 470 } |
460 | 471 |
461 use_sync_query_ = caps.sync_query; | 472 use_sync_query_ = caps.sync_query; |
462 | 473 |
463 GLES2Interface* gl = ContextGL(); | 474 GLES2Interface* gl = ContextGL(); |
464 | 475 |
465 max_texture_size_ = 0; // Context expects cleared value. | 476 max_texture_size_ = 0; // Context expects cleared value. |
466 gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_); | 477 gl->GetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size_); |
467 best_texture_format_ = | 478 best_texture_format_ = |
468 PlatformColor::BestSupportedTextureFormat(use_texture_format_bgra_); | 479 PlatformColor::BestSupportedTextureFormat(use_texture_format_bgra_); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 case RGBA_4444: | 527 case RGBA_4444: |
517 case RGBA_8888: | 528 case RGBA_8888: |
518 case RGB_565: | 529 case RGB_565: |
519 case LUMINANCE_8: | 530 case LUMINANCE_8: |
520 return true; | 531 return true; |
521 case BGRA_8888: | 532 case BGRA_8888: |
522 return caps.texture_format_bgra8888; | 533 return caps.texture_format_bgra8888; |
523 case ETC1: | 534 case ETC1: |
524 return caps.texture_format_etc1; | 535 return caps.texture_format_etc1; |
525 case RED_8: | 536 case RED_8: |
| 537 case RG_88: |
526 return caps.texture_rg; | 538 return caps.texture_rg; |
527 case LUMINANCE_F16: | 539 case LUMINANCE_F16: |
528 return caps.texture_half_float_linear; | 540 return caps.texture_half_float_linear; |
529 } | 541 } |
530 | 542 |
531 NOTREACHED(); | 543 NOTREACHED(); |
532 return false; | 544 return false; |
533 } | 545 } |
534 | 546 |
535 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 547 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 669 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
658 const TextureMailbox& mailbox, | 670 const TextureMailbox& mailbox, |
659 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl, | 671 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl, |
660 bool read_lock_fences_enabled) { | 672 bool read_lock_fences_enabled) { |
661 DCHECK(thread_checker_.CalledOnValidThread()); | 673 DCHECK(thread_checker_.CalledOnValidThread()); |
662 // Just store the information. Mailbox will be consumed in LockForRead(). | 674 // Just store the information. Mailbox will be consumed in LockForRead(). |
663 ResourceId id = next_id_++; | 675 ResourceId id = next_id_++; |
664 DCHECK(mailbox.IsValid()); | 676 DCHECK(mailbox.IsValid()); |
665 Resource* resource = nullptr; | 677 Resource* resource = nullptr; |
666 if (mailbox.IsTexture()) { | 678 if (mailbox.IsTexture()) { |
| 679 // TODO(dshwang): the resource can be R_8 or RG_88. crbug.com/624436 |
667 resource = InsertResource( | 680 resource = InsertResource( |
668 id, | 681 id, |
669 Resource(0, mailbox.size_in_pixels(), Resource::EXTERNAL, | 682 Resource(0, mailbox.size_in_pixels(), Resource::EXTERNAL, |
670 mailbox.target(), | 683 mailbox.target(), |
671 mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR, | 684 mailbox.nearest_neighbor() ? GL_NEAREST : GL_LINEAR, |
672 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE, RGBA_8888)); | 685 TEXTURE_HINT_IMMUTABLE, RESOURCE_TYPE_GL_TEXTURE, RGBA_8888)); |
673 } else { | 686 } else { |
674 DCHECK(mailbox.IsSharedMemory()); | 687 DCHECK(mailbox.IsSharedMemory()); |
675 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); | 688 SharedBitmap* shared_bitmap = mailbox.shared_bitmap(); |
676 uint8_t* pixels = shared_bitmap->pixels(); | 689 uint8_t* pixels = shared_bitmap->pixels(); |
(...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2055 | 2068 |
2056 const int kImportance = 2; | 2069 const int kImportance = 2; |
2057 pmd->CreateSharedGlobalAllocatorDump(guid); | 2070 pmd->CreateSharedGlobalAllocatorDump(guid); |
2058 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2071 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
2059 } | 2072 } |
2060 | 2073 |
2061 return true; | 2074 return true; |
2062 } | 2075 } |
2063 | 2076 |
2064 } // namespace cc | 2077 } // namespace cc |
OLD | NEW |