OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/gl/gl_image_memory.h" | 5 #include "ui/gl/gl_image_memory.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 bool ValidFormat(gfx::BufferFormat format) { | 40 bool ValidFormat(gfx::BufferFormat format) { |
41 switch (format) { | 41 switch (format) { |
42 case gfx::BufferFormat::ATC: | 42 case gfx::BufferFormat::ATC: |
43 case gfx::BufferFormat::ATCIA: | 43 case gfx::BufferFormat::ATCIA: |
44 case gfx::BufferFormat::DXT1: | 44 case gfx::BufferFormat::DXT1: |
45 case gfx::BufferFormat::DXT5: | 45 case gfx::BufferFormat::DXT5: |
46 case gfx::BufferFormat::ETC1: | 46 case gfx::BufferFormat::ETC1: |
47 case gfx::BufferFormat::R_8: | 47 case gfx::BufferFormat::R_8: |
| 48 case gfx::BufferFormat::R_16: |
48 case gfx::BufferFormat::RG_88: | 49 case gfx::BufferFormat::RG_88: |
49 case gfx::BufferFormat::BGR_565: | 50 case gfx::BufferFormat::BGR_565: |
50 case gfx::BufferFormat::RGBA_4444: | 51 case gfx::BufferFormat::RGBA_4444: |
51 case gfx::BufferFormat::RGBX_8888: | 52 case gfx::BufferFormat::RGBX_8888: |
52 case gfx::BufferFormat::RGBA_8888: | 53 case gfx::BufferFormat::RGBA_8888: |
53 case gfx::BufferFormat::BGRX_8888: | 54 case gfx::BufferFormat::BGRX_8888: |
54 case gfx::BufferFormat::BGRA_8888: | 55 case gfx::BufferFormat::BGRA_8888: |
55 case gfx::BufferFormat::RGBA_F16: | 56 case gfx::BufferFormat::RGBA_F16: |
56 return true; | 57 return true; |
57 case gfx::BufferFormat::YVU_420: | 58 case gfx::BufferFormat::YVU_420: |
58 case gfx::BufferFormat::YUV_420_BIPLANAR: | 59 case gfx::BufferFormat::YUV_420_BIPLANAR: |
59 case gfx::BufferFormat::UYVY_422: | 60 case gfx::BufferFormat::UYVY_422: |
60 return false; | 61 return false; |
61 } | 62 } |
62 | 63 |
63 NOTREACHED(); | 64 NOTREACHED(); |
64 return false; | 65 return false; |
65 } | 66 } |
66 | 67 |
67 bool IsCompressedFormat(gfx::BufferFormat format) { | 68 bool IsCompressedFormat(gfx::BufferFormat format) { |
68 switch (format) { | 69 switch (format) { |
69 case gfx::BufferFormat::ATC: | 70 case gfx::BufferFormat::ATC: |
70 case gfx::BufferFormat::ATCIA: | 71 case gfx::BufferFormat::ATCIA: |
71 case gfx::BufferFormat::DXT1: | 72 case gfx::BufferFormat::DXT1: |
72 case gfx::BufferFormat::DXT5: | 73 case gfx::BufferFormat::DXT5: |
73 case gfx::BufferFormat::ETC1: | 74 case gfx::BufferFormat::ETC1: |
74 return true; | 75 return true; |
75 case gfx::BufferFormat::R_8: | 76 case gfx::BufferFormat::R_8: |
| 77 case gfx::BufferFormat::R_16: |
76 case gfx::BufferFormat::RG_88: | 78 case gfx::BufferFormat::RG_88: |
77 case gfx::BufferFormat::BGR_565: | 79 case gfx::BufferFormat::BGR_565: |
78 case gfx::BufferFormat::RGBA_4444: | 80 case gfx::BufferFormat::RGBA_4444: |
79 case gfx::BufferFormat::RGBX_8888: | 81 case gfx::BufferFormat::RGBX_8888: |
80 case gfx::BufferFormat::RGBA_8888: | 82 case gfx::BufferFormat::RGBA_8888: |
81 case gfx::BufferFormat::BGRX_8888: | 83 case gfx::BufferFormat::BGRX_8888: |
82 case gfx::BufferFormat::BGRA_8888: | 84 case gfx::BufferFormat::BGRA_8888: |
83 case gfx::BufferFormat::RGBA_F16: | 85 case gfx::BufferFormat::RGBA_F16: |
84 return false; | 86 return false; |
85 case gfx::BufferFormat::YVU_420: | 87 case gfx::BufferFormat::YVU_420: |
(...skipping 14 matching lines...) Expand all Loading... |
100 case gfx::BufferFormat::ATCIA: | 102 case gfx::BufferFormat::ATCIA: |
101 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; | 103 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; |
102 case gfx::BufferFormat::DXT1: | 104 case gfx::BufferFormat::DXT1: |
103 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; | 105 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; |
104 case gfx::BufferFormat::DXT5: | 106 case gfx::BufferFormat::DXT5: |
105 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | 107 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; |
106 case gfx::BufferFormat::ETC1: | 108 case gfx::BufferFormat::ETC1: |
107 return GL_ETC1_RGB8_OES; | 109 return GL_ETC1_RGB8_OES; |
108 case gfx::BufferFormat::R_8: | 110 case gfx::BufferFormat::R_8: |
109 return GL_RED; | 111 return GL_RED; |
| 112 case gfx::BufferFormat::R_16: |
| 113 return GL_R16_EXT; |
110 case gfx::BufferFormat::RG_88: | 114 case gfx::BufferFormat::RG_88: |
111 return GL_RG; | 115 return GL_RG; |
112 case gfx::BufferFormat::RGBA_4444: | 116 case gfx::BufferFormat::RGBA_4444: |
113 case gfx::BufferFormat::RGBA_8888: | 117 case gfx::BufferFormat::RGBA_8888: |
114 case gfx::BufferFormat::RGBA_F16: | 118 case gfx::BufferFormat::RGBA_F16: |
115 return GL_RGBA; | 119 return GL_RGBA; |
116 case gfx::BufferFormat::BGRA_8888: | 120 case gfx::BufferFormat::BGRA_8888: |
117 return GL_BGRA_EXT; | 121 return GL_BGRA_EXT; |
118 case gfx::BufferFormat::BGR_565: | 122 case gfx::BufferFormat::BGR_565: |
119 case gfx::BufferFormat::RGBX_8888: | 123 case gfx::BufferFormat::RGBX_8888: |
(...skipping 15 matching lines...) Expand all Loading... |
135 case gfx::BufferFormat::RGBX_8888: | 139 case gfx::BufferFormat::RGBX_8888: |
136 return GL_RGBA; | 140 return GL_RGBA; |
137 case gfx::BufferFormat::BGRX_8888: | 141 case gfx::BufferFormat::BGRX_8888: |
138 return GL_BGRA_EXT; | 142 return GL_BGRA_EXT; |
139 case gfx::BufferFormat::BGR_565: | 143 case gfx::BufferFormat::BGR_565: |
140 case gfx::BufferFormat::RGBA_4444: | 144 case gfx::BufferFormat::RGBA_4444: |
141 case gfx::BufferFormat::RGBA_8888: | 145 case gfx::BufferFormat::RGBA_8888: |
142 case gfx::BufferFormat::BGRA_8888: | 146 case gfx::BufferFormat::BGRA_8888: |
143 case gfx::BufferFormat::RGBA_F16: | 147 case gfx::BufferFormat::RGBA_F16: |
144 case gfx::BufferFormat::R_8: | 148 case gfx::BufferFormat::R_8: |
| 149 case gfx::BufferFormat::R_16: |
145 case gfx::BufferFormat::RG_88: | 150 case gfx::BufferFormat::RG_88: |
146 case gfx::BufferFormat::ATC: | 151 case gfx::BufferFormat::ATC: |
147 case gfx::BufferFormat::ATCIA: | 152 case gfx::BufferFormat::ATCIA: |
148 case gfx::BufferFormat::DXT1: | 153 case gfx::BufferFormat::DXT1: |
149 case gfx::BufferFormat::DXT5: | 154 case gfx::BufferFormat::DXT5: |
150 case gfx::BufferFormat::ETC1: | 155 case gfx::BufferFormat::ETC1: |
151 return TextureFormat(format); | 156 return TextureFormat(format); |
152 case gfx::BufferFormat::YVU_420: | 157 case gfx::BufferFormat::YVU_420: |
153 case gfx::BufferFormat::YUV_420_BIPLANAR: | 158 case gfx::BufferFormat::YUV_420_BIPLANAR: |
154 case gfx::BufferFormat::UYVY_422: | 159 case gfx::BufferFormat::UYVY_422: |
155 NOTREACHED(); | 160 NOTREACHED(); |
156 return 0; | 161 return 0; |
157 } | 162 } |
158 | 163 |
159 NOTREACHED(); | 164 NOTREACHED(); |
160 return 0; | 165 return 0; |
161 } | 166 } |
162 | 167 |
163 GLenum DataType(gfx::BufferFormat format) { | 168 GLenum DataType(gfx::BufferFormat format) { |
164 switch (format) { | 169 switch (format) { |
165 case gfx::BufferFormat::BGR_565: | 170 case gfx::BufferFormat::BGR_565: |
166 return GL_UNSIGNED_SHORT_5_6_5_REV; | 171 return GL_UNSIGNED_SHORT_5_6_5_REV; |
167 case gfx::BufferFormat::RGBA_4444: | 172 case gfx::BufferFormat::RGBA_4444: |
168 return GL_UNSIGNED_SHORT_4_4_4_4; | 173 return GL_UNSIGNED_SHORT_4_4_4_4; |
169 case gfx::BufferFormat::RGBX_8888: | 174 case gfx::BufferFormat::RGBX_8888: |
170 case gfx::BufferFormat::RGBA_8888: | 175 case gfx::BufferFormat::RGBA_8888: |
171 case gfx::BufferFormat::BGRX_8888: | 176 case gfx::BufferFormat::BGRX_8888: |
172 case gfx::BufferFormat::BGRA_8888: | 177 case gfx::BufferFormat::BGRA_8888: |
173 case gfx::BufferFormat::R_8: | 178 case gfx::BufferFormat::R_8: |
| 179 case gfx::BufferFormat::R_16: |
174 case gfx::BufferFormat::RG_88: | 180 case gfx::BufferFormat::RG_88: |
175 return GL_UNSIGNED_BYTE; | 181 return GL_UNSIGNED_BYTE; |
176 case gfx::BufferFormat::RGBA_F16: | 182 case gfx::BufferFormat::RGBA_F16: |
177 return GL_HALF_FLOAT_OES; | 183 return GL_HALF_FLOAT_OES; |
178 case gfx::BufferFormat::ATC: | 184 case gfx::BufferFormat::ATC: |
179 case gfx::BufferFormat::ATCIA: | 185 case gfx::BufferFormat::ATCIA: |
180 case gfx::BufferFormat::DXT1: | 186 case gfx::BufferFormat::DXT1: |
181 case gfx::BufferFormat::DXT5: | 187 case gfx::BufferFormat::DXT5: |
182 case gfx::BufferFormat::ETC1: | 188 case gfx::BufferFormat::ETC1: |
183 case gfx::BufferFormat::YVU_420: | 189 case gfx::BufferFormat::YVU_420: |
(...skipping 15 matching lines...) Expand all Loading... |
199 return base::checked_cast<GLint>(stride) / 2; | 205 return base::checked_cast<GLint>(stride) / 2; |
200 case gfx::BufferFormat::RGBX_8888: | 206 case gfx::BufferFormat::RGBX_8888: |
201 case gfx::BufferFormat::RGBA_8888: | 207 case gfx::BufferFormat::RGBA_8888: |
202 case gfx::BufferFormat::BGRX_8888: | 208 case gfx::BufferFormat::BGRX_8888: |
203 case gfx::BufferFormat::BGRA_8888: | 209 case gfx::BufferFormat::BGRA_8888: |
204 return base::checked_cast<GLint>(stride) / 4; | 210 return base::checked_cast<GLint>(stride) / 4; |
205 case gfx::BufferFormat::RGBA_F16: | 211 case gfx::BufferFormat::RGBA_F16: |
206 return base::checked_cast<GLint>(stride) / 8; | 212 return base::checked_cast<GLint>(stride) / 8; |
207 case gfx::BufferFormat::R_8: | 213 case gfx::BufferFormat::R_8: |
208 return base::checked_cast<GLint>(stride); | 214 return base::checked_cast<GLint>(stride); |
| 215 case gfx::BufferFormat::R_16: |
| 216 return base::checked_cast<GLint>(stride); |
209 case gfx::BufferFormat::ATC: | 217 case gfx::BufferFormat::ATC: |
210 case gfx::BufferFormat::ATCIA: | 218 case gfx::BufferFormat::ATCIA: |
211 case gfx::BufferFormat::DXT1: | 219 case gfx::BufferFormat::DXT1: |
212 case gfx::BufferFormat::DXT5: | 220 case gfx::BufferFormat::DXT5: |
213 case gfx::BufferFormat::ETC1: | 221 case gfx::BufferFormat::ETC1: |
214 case gfx::BufferFormat::YVU_420: | 222 case gfx::BufferFormat::YVU_420: |
215 case gfx::BufferFormat::YUV_420_BIPLANAR: | 223 case gfx::BufferFormat::YUV_420_BIPLANAR: |
216 case gfx::BufferFormat::UYVY_422: | 224 case gfx::BufferFormat::UYVY_422: |
217 NOTREACHED(); | 225 NOTREACHED(); |
218 return 0; | 226 return 0; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 dst[0] = src[2]; | 320 dst[0] = src[2]; |
313 dst[1] = src[1]; | 321 dst[1] = src[1]; |
314 dst[2] = src[0]; | 322 dst[2] = src[0]; |
315 }, | 323 }, |
316 data_format, data_type, data_row_length); | 324 data_format, data_type, data_row_length); |
317 case gfx::BufferFormat::RGBA_4444: | 325 case gfx::BufferFormat::RGBA_4444: |
318 case gfx::BufferFormat::RGBA_8888: | 326 case gfx::BufferFormat::RGBA_8888: |
319 case gfx::BufferFormat::BGRA_8888: | 327 case gfx::BufferFormat::BGRA_8888: |
320 case gfx::BufferFormat::RGBA_F16: | 328 case gfx::BufferFormat::RGBA_F16: |
321 case gfx::BufferFormat::R_8: | 329 case gfx::BufferFormat::R_8: |
| 330 case gfx::BufferFormat::R_16: |
322 case gfx::BufferFormat::RG_88: { | 331 case gfx::BufferFormat::RG_88: { |
323 size_t gles2_data_stride = | 332 size_t gles2_data_stride = |
324 RowSizeForBufferFormat(size.width(), format, 0); | 333 RowSizeForBufferFormat(size.width(), format, 0); |
325 if (stride == gles2_data_stride || | 334 if (stride == gles2_data_stride || |
326 g_current_gl_driver->ext.b_GL_EXT_unpack_subimage) | 335 g_current_gl_driver->ext.b_GL_EXT_unpack_subimage) |
327 return nullptr; // No data conversion needed | 336 return nullptr; // No data conversion needed |
328 | 337 |
329 std::unique_ptr<uint8_t[]> gles2_data( | 338 std::unique_ptr<uint8_t[]> gles2_data( |
330 new uint8_t[gles2_data_stride * size.height()]); | 339 new uint8_t[gles2_data_stride * size.height()]); |
331 for (int y = 0; y < size.height(); ++y) { | 340 for (int y = 0; y < size.height(); ++y) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 return Type::MEMORY; | 519 return Type::MEMORY; |
511 } | 520 } |
512 | 521 |
513 // static | 522 // static |
514 unsigned GLImageMemory::GetInternalFormatForTesting(gfx::BufferFormat format) { | 523 unsigned GLImageMemory::GetInternalFormatForTesting(gfx::BufferFormat format) { |
515 DCHECK(ValidFormat(format)); | 524 DCHECK(ValidFormat(format)); |
516 return TextureFormat(format); | 525 return TextureFormat(format); |
517 } | 526 } |
518 | 527 |
519 } // namespace gl | 528 } // namespace gl |
OLD | NEW |