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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } | 79 } |
80 | 80 |
81 GLenum TextureToStorageFormat(ResourceFormat format) { | 81 GLenum TextureToStorageFormat(ResourceFormat format) { |
82 GLenum storage_format = GL_RGBA8_OES; | 82 GLenum storage_format = GL_RGBA8_OES; |
83 switch (format) { | 83 switch (format) { |
84 case RGBA_8888: | 84 case RGBA_8888: |
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_F16: | |
90 storage_format = GL_RGBA16F_EXT; | |
91 break; | |
92 case RGBA_4444: | 89 case RGBA_4444: |
93 case ALPHA_8: | 90 case ALPHA_8: |
94 case LUMINANCE_8: | 91 case LUMINANCE_8: |
95 case RGB_565: | 92 case RGB_565: |
96 case ETC1: | 93 case ETC1: |
97 case RED_8: | 94 case RED_8: |
98 case LUMINANCE_F16: | 95 case LUMINANCE_F16: |
99 NOTREACHED(); | 96 NOTREACHED(); |
100 break; | 97 break; |
101 } | 98 } |
102 | 99 |
103 return storage_format; | 100 return storage_format; |
104 } | 101 } |
105 | 102 |
106 bool IsFormatSupportedForStorage(ResourceFormat format, bool use_bgra) { | 103 bool IsFormatSupportedForStorage(ResourceFormat format, bool use_bgra) { |
107 switch (format) { | 104 switch (format) { |
108 case RGBA_8888: | 105 case RGBA_8888: |
109 case RGBA_F16: | |
110 return true; | 106 return true; |
111 case BGRA_8888: | 107 case BGRA_8888: |
112 return use_bgra; | 108 return use_bgra; |
113 case RGBA_4444: | 109 case RGBA_4444: |
114 case ALPHA_8: | 110 case ALPHA_8: |
115 case LUMINANCE_8: | 111 case LUMINANCE_8: |
116 case RGB_565: | 112 case RGB_565: |
117 case ETC1: | 113 case ETC1: |
118 case RED_8: | 114 case RED_8: |
119 case LUMINANCE_F16: | 115 case LUMINANCE_F16: |
120 return false; | 116 return false; |
121 } | 117 } |
122 return false; | 118 return false; |
123 } | 119 } |
124 | 120 |
125 GrPixelConfig ToGrPixelConfig(ResourceFormat format) { | 121 GrPixelConfig ToGrPixelConfig(ResourceFormat format) { |
126 switch (format) { | 122 switch (format) { |
127 case RGBA_8888: | 123 case RGBA_8888: |
128 return kRGBA_8888_GrPixelConfig; | 124 return kRGBA_8888_GrPixelConfig; |
129 case BGRA_8888: | 125 case BGRA_8888: |
130 return kBGRA_8888_GrPixelConfig; | 126 return kBGRA_8888_GrPixelConfig; |
131 case RGBA_4444: | 127 case RGBA_4444: |
132 return kRGBA_4444_GrPixelConfig; | 128 return kRGBA_4444_GrPixelConfig; |
133 case RGBA_F16: | |
134 return kRGBA_half_GrPixelConfig; | |
135 default: | 129 default: |
136 break; | 130 break; |
137 } | 131 } |
138 DCHECK(false) << "Unsupported resource format."; | 132 DCHECK(false) << "Unsupported resource format."; |
139 return kSkia8888_GrPixelConfig; | 133 return kSkia8888_GrPixelConfig; |
140 } | 134 } |
141 | 135 |
142 class ScopedSetActiveTexture { | 136 class ScopedSetActiveTexture { |
143 public: | 137 public: |
144 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) | 138 ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit) |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 case LUMINANCE_8: | 530 case LUMINANCE_8: |
537 return true; | 531 return true; |
538 case BGRA_8888: | 532 case BGRA_8888: |
539 return caps.texture_format_bgra8888; | 533 return caps.texture_format_bgra8888; |
540 case ETC1: | 534 case ETC1: |
541 return caps.texture_format_etc1; | 535 return caps.texture_format_etc1; |
542 case RED_8: | 536 case RED_8: |
543 return caps.texture_rg; | 537 return caps.texture_rg; |
544 case LUMINANCE_F16: | 538 case LUMINANCE_F16: |
545 return caps.texture_half_float_linear; | 539 return caps.texture_half_float_linear; |
546 case RGBA_F16: | |
547 // TODO(ccameron): This will always return false on pixel tests, which | |
548 // makes it un-test-able until we upgrade Mesa. | |
549 // https://crbug.com/687720 | |
550 return caps.texture_half_float_linear && caps.color_buffer_float; | |
551 } | 540 } |
552 | 541 |
553 NOTREACHED(); | 542 NOTREACHED(); |
554 return false; | 543 return false; |
555 } | 544 } |
556 | 545 |
557 bool ResourceProvider::InUseByConsumer(ResourceId id) { | 546 bool ResourceProvider::InUseByConsumer(ResourceId id) { |
558 Resource* resource = GetResource(id); | 547 Resource* resource = GetResource(id); |
559 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || | 548 return resource->lock_for_read_count > 0 || resource->exported_count > 0 || |
560 resource->lost; | 549 resource->lost; |
(...skipping 19 matching lines...) Expand all Loading... |
580 } | 569 } |
581 | 570 |
582 ResourceId ResourceProvider::CreateResource( | 571 ResourceId ResourceProvider::CreateResource( |
583 const gfx::Size& size, | 572 const gfx::Size& size, |
584 TextureHint hint, | 573 TextureHint hint, |
585 ResourceFormat format, | 574 ResourceFormat format, |
586 const gfx::ColorSpace& color_space) { | 575 const gfx::ColorSpace& color_space) { |
587 DCHECK(!size.IsEmpty()); | 576 DCHECK(!size.IsEmpty()); |
588 switch (settings_.default_resource_type) { | 577 switch (settings_.default_resource_type) { |
589 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: | 578 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: |
590 // GPU memory buffers don't support LUMINANCE_F16 or RGBA_F16 yet. | 579 // GPU memory buffers don't support LUMINANCE_F16. |
591 if (format != LUMINANCE_F16 && format != RGBA_F16) { | 580 if (format != LUMINANCE_F16) { |
592 return CreateGLTexture( | 581 return CreateGLTexture( |
593 size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, format, | 582 size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, format, |
594 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, color_space); | 583 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, color_space); |
595 } | 584 } |
596 // Fall through and use a regular texture. | 585 // Fall through and use a regular texture. |
597 case RESOURCE_TYPE_GL_TEXTURE: | 586 case RESOURCE_TYPE_GL_TEXTURE: |
598 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format, | 587 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format, |
599 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | 588 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
600 color_space); | 589 color_space); |
601 | 590 |
(...skipping 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2174 | 2163 |
2175 const int kImportance = 2; | 2164 const int kImportance = 2; |
2176 pmd->CreateSharedGlobalAllocatorDump(guid); | 2165 pmd->CreateSharedGlobalAllocatorDump(guid); |
2177 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2166 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
2178 } | 2167 } |
2179 | 2168 |
2180 return true; | 2169 return true; |
2181 } | 2170 } |
2182 | 2171 |
2183 } // namespace cc | 2172 } // namespace cc |
OLD | NEW |