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

Side by Side Diff: components/viz/common/resources/resource_format_utils.cc

Issue 2969223002: [media]: Replace LUMINANCE_F16 by R16 for 9/10-bit h264 videos.
Patch Set: Fix in resource_format_utils Created 3 years, 3 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 | « components/viz/common/resources/resource_format.h ('k') | media/base/media_switches.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/viz/common/resources/resource_format_utils.h" 5 #include "components/viz/common/resources/resource_format_utils.h"
6 6
7 #include "third_party/khronos/GLES2/gl2.h" 7 #include "third_party/khronos/GLES2/gl2.h"
8 #include "third_party/khronos/GLES2/gl2ext.h" 8 #include "third_party/khronos/GLES2/gl2ext.h"
9 #include "ui/gfx/gpu_memory_buffer.h" 9 #include "ui/gfx/gpu_memory_buffer.h"
10 10
11 namespace viz { 11 namespace viz {
12 12
13 SkColorType ResourceFormatToClosestSkColorType(ResourceFormat format) { 13 SkColorType ResourceFormatToClosestSkColorType(ResourceFormat format) {
14 // Use kN32_SkColorType if there is no corresponding SkColorType. 14 // Use kN32_SkColorType if there is no corresponding SkColorType.
15 switch (format) { 15 switch (format) {
16 case RGBA_4444: 16 case RGBA_4444:
17 return kARGB_4444_SkColorType; 17 return kARGB_4444_SkColorType;
18 case RGBA_8888: 18 case RGBA_8888:
19 case BGRA_8888: 19 case BGRA_8888:
20 return kN32_SkColorType; 20 return kN32_SkColorType;
21 case ALPHA_8: 21 case ALPHA_8:
22 return kAlpha_8_SkColorType; 22 return kAlpha_8_SkColorType;
23 case RGB_565: 23 case RGB_565:
24 return kRGB_565_SkColorType; 24 return kRGB_565_SkColorType;
25 case LUMINANCE_8: 25 case LUMINANCE_8:
26 return kGray_8_SkColorType; 26 return kGray_8_SkColorType;
27 case ETC1: 27 case ETC1:
28 case RED_8: 28 case RED_8:
29 case LUMINANCE_F16: 29 case LUMINANCE_F16:
30 case R16_EXT:
30 return kN32_SkColorType; 31 return kN32_SkColorType;
31 case RGBA_F16: 32 case RGBA_F16:
32 return kRGBA_F16_SkColorType; 33 return kRGBA_F16_SkColorType;
33 } 34 }
34 NOTREACHED(); 35 NOTREACHED();
35 return kN32_SkColorType; 36 return kN32_SkColorType;
36 } 37 }
37 38
38 int BitsPerPixel(ResourceFormat format) { 39 int BitsPerPixel(ResourceFormat format) {
39 switch (format) { 40 switch (format) {
40 case RGBA_F16: 41 case RGBA_F16:
41 return 64; 42 return 64;
42 case BGRA_8888: 43 case BGRA_8888:
43 case RGBA_8888: 44 case RGBA_8888:
44 return 32; 45 return 32;
45 case RGBA_4444: 46 case RGBA_4444:
46 case RGB_565: 47 case RGB_565:
47 case LUMINANCE_F16: 48 case LUMINANCE_F16:
49 case R16_EXT:
48 return 16; 50 return 16;
49 case ALPHA_8: 51 case ALPHA_8:
50 case LUMINANCE_8: 52 case LUMINANCE_8:
51 case RED_8: 53 case RED_8:
52 return 8; 54 return 8;
53 case ETC1: 55 case ETC1:
54 return 4; 56 return 4;
55 } 57 }
56 NOTREACHED(); 58 NOTREACHED();
57 return 0; 59 return 0;
58 } 60 }
59 61
60 GLenum GLDataType(ResourceFormat format) { 62 GLenum GLDataType(ResourceFormat format) {
61 DCHECK_LE(format, RESOURCE_FORMAT_MAX); 63 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
62 static const GLenum format_gl_data_type[] = { 64 static const GLenum format_gl_data_type[] = {
63 GL_UNSIGNED_BYTE, // RGBA_8888 65 GL_UNSIGNED_BYTE, // RGBA_8888
64 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444 66 GL_UNSIGNED_SHORT_4_4_4_4, // RGBA_4444
65 GL_UNSIGNED_BYTE, // BGRA_8888 67 GL_UNSIGNED_BYTE, // BGRA_8888
66 GL_UNSIGNED_BYTE, // ALPHA_8 68 GL_UNSIGNED_BYTE, // ALPHA_8
67 GL_UNSIGNED_BYTE, // LUMINANCE_8 69 GL_UNSIGNED_BYTE, // LUMINANCE_8
68 GL_UNSIGNED_SHORT_5_6_5, // RGB_565, 70 GL_UNSIGNED_SHORT_5_6_5, // RGB_565,
69 GL_UNSIGNED_BYTE, // ETC1 71 GL_UNSIGNED_BYTE, // ETC1
70 GL_UNSIGNED_BYTE, // RED_8 72 GL_UNSIGNED_BYTE, // RED_8
71 GL_HALF_FLOAT_OES, // LUMINANCE_F16 73 GL_HALF_FLOAT_OES, // LUMINANCE_F16
72 GL_HALF_FLOAT_OES, // RGBA_F16 74 GL_HALF_FLOAT_OES, // RGBA_F16
75 GL_UNSIGNED_SHORT, // R16_EXT
73 }; 76 };
74 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1), 77 static_assert(arraysize(format_gl_data_type) == (RESOURCE_FORMAT_MAX + 1),
75 "format_gl_data_type does not handle all cases."); 78 "format_gl_data_type does not handle all cases.");
76 79
77 return format_gl_data_type[format]; 80 return format_gl_data_type[format];
78 } 81 }
79 82
80 GLenum GLDataFormat(ResourceFormat format) { 83 GLenum GLDataFormat(ResourceFormat format) {
81 DCHECK_LE(format, RESOURCE_FORMAT_MAX); 84 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
82 static const GLenum format_gl_data_format[] = { 85 static const GLenum format_gl_data_format[] = {
83 GL_RGBA, // RGBA_8888 86 GL_RGBA, // RGBA_8888
84 GL_RGBA, // RGBA_4444 87 GL_RGBA, // RGBA_4444
85 GL_BGRA_EXT, // BGRA_8888 88 GL_BGRA_EXT, // BGRA_8888
86 GL_ALPHA, // ALPHA_8 89 GL_ALPHA, // ALPHA_8
87 GL_LUMINANCE, // LUMINANCE_8 90 GL_LUMINANCE, // LUMINANCE_8
88 GL_RGB, // RGB_565 91 GL_RGB, // RGB_565
89 GL_ETC1_RGB8_OES, // ETC1 92 GL_ETC1_RGB8_OES, // ETC1
90 GL_RED_EXT, // RED_8 93 GL_RED_EXT, // RED_8
91 GL_LUMINANCE, // LUMINANCE_F16 94 GL_LUMINANCE, // LUMINANCE_F16
92 GL_RGBA, // RGBA_F16 95 GL_RGBA, // RGBA_F16
96 GL_R16_EXT, // R16_EXT
93 }; 97 };
94 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), 98 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1),
95 "format_gl_data_format does not handle all cases."); 99 "format_gl_data_format does not handle all cases.");
96 return format_gl_data_format[format]; 100 return format_gl_data_format[format];
97 } 101 }
98 102
99 GLenum GLInternalFormat(ResourceFormat format) { 103 GLenum GLInternalFormat(ResourceFormat format) {
100 // In GLES2, the internal format must match the texture format. (It no longer 104 // In GLES2, the internal format must match the texture format. (It no longer
101 // is true in GLES3, however it still holds for the BGRA extension.) 105 // is true in GLES3, however it still holds for the BGRA extension.)
102 return GLDataFormat(format); 106 return GLDataFormat(format);
(...skipping 11 matching lines...) Expand all
114 GL_RGBA, // RGBA_8888 118 GL_RGBA, // RGBA_8888
115 GL_RGBA, // RGBA_4444 119 GL_RGBA, // RGBA_4444
116 GL_RGBA, // BGRA_8888 120 GL_RGBA, // BGRA_8888
117 GL_ALPHA, // ALPHA_8 121 GL_ALPHA, // ALPHA_8
118 GL_LUMINANCE, // LUMINANCE_8 122 GL_LUMINANCE, // LUMINANCE_8
119 GL_RGB, // RGB_565 123 GL_RGB, // RGB_565
120 GL_RGB, // ETC1 124 GL_RGB, // ETC1
121 GL_LUMINANCE, // RED_8 125 GL_LUMINANCE, // RED_8
122 GL_LUMINANCE, // LUMINANCE_F16 126 GL_LUMINANCE, // LUMINANCE_F16
123 GL_RGBA, // RGBA_F16 127 GL_RGBA, // RGBA_F16
128 GL_LUMINANCE, // R16_EXT
124 }; 129 };
125 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1), 130 static_assert(arraysize(format_gl_data_format) == (RESOURCE_FORMAT_MAX + 1),
126 "format_gl_data_format does not handle all cases."); 131 "format_gl_data_format does not handle all cases.");
127 return format_gl_data_format[format]; 132 return format_gl_data_format[format];
128 } 133 }
129 134
130 gfx::BufferFormat BufferFormat(ResourceFormat format) { 135 gfx::BufferFormat BufferFormat(ResourceFormat format) {
131 switch (format) { 136 switch (format) {
132 case BGRA_8888: 137 case BGRA_8888:
133 return gfx::BufferFormat::BGRA_8888; 138 return gfx::BufferFormat::BGRA_8888;
134 case RED_8: 139 case RED_8:
135 return gfx::BufferFormat::R_8; 140 return gfx::BufferFormat::R_8;
141 case R16_EXT:
142 return gfx::BufferFormat::R_16;
136 case RGBA_4444: 143 case RGBA_4444:
137 return gfx::BufferFormat::RGBA_4444; 144 return gfx::BufferFormat::RGBA_4444;
138 case RGBA_8888: 145 case RGBA_8888:
139 return gfx::BufferFormat::RGBA_8888; 146 return gfx::BufferFormat::RGBA_8888;
140 case ETC1: 147 case ETC1:
141 return gfx::BufferFormat::ETC1; 148 return gfx::BufferFormat::ETC1;
142 case RGBA_F16: 149 case RGBA_F16:
143 return gfx::BufferFormat::RGBA_F16; 150 return gfx::BufferFormat::RGBA_F16;
144 case ALPHA_8: 151 case ALPHA_8:
145 case LUMINANCE_8: 152 case LUMINANCE_8:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 case RGBA_8888: 185 case RGBA_8888:
179 case BGRA_8888: 186 case BGRA_8888:
180 case ALPHA_8: 187 case ALPHA_8:
181 case RGBA_F16: 188 case RGBA_F16:
182 return true; 189 return true;
183 case LUMINANCE_8: 190 case LUMINANCE_8:
184 case RGB_565: 191 case RGB_565:
185 case ETC1: 192 case ETC1:
186 case RED_8: 193 case RED_8:
187 case LUMINANCE_F16: 194 case LUMINANCE_F16:
195 case R16_EXT:
188 return false; 196 return false;
189 } 197 }
190 NOTREACHED(); 198 NOTREACHED();
191 return false; 199 return false;
192 } 200 }
193 201
194 } // namespace viz 202 } // namespace viz
OLDNEW
« no previous file with comments | « components/viz/common/resources/resource_format.h ('k') | media/base/media_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698