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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::RG_88: | 48 case gfx::BufferFormat::RG_88: |
49 case gfx::BufferFormat::BGR_565: | 49 case gfx::BufferFormat::BGR_565: |
50 case gfx::BufferFormat::RGBA_4444: | 50 case gfx::BufferFormat::RGBA_4444: |
51 case gfx::BufferFormat::RGBX_8888: | 51 case gfx::BufferFormat::RGBX_8888: |
52 case gfx::BufferFormat::RGBA_8888: | 52 case gfx::BufferFormat::RGBA_8888: |
53 case gfx::BufferFormat::BGRX_8888: | 53 case gfx::BufferFormat::BGRX_8888: |
54 case gfx::BufferFormat::BGRA_8888: | 54 case gfx::BufferFormat::BGRA_8888: |
| 55 case gfx::BufferFormat::RGBA_F16: |
55 return true; | 56 return true; |
56 case gfx::BufferFormat::YVU_420: | 57 case gfx::BufferFormat::YVU_420: |
57 case gfx::BufferFormat::YUV_420_BIPLANAR: | 58 case gfx::BufferFormat::YUV_420_BIPLANAR: |
58 case gfx::BufferFormat::UYVY_422: | 59 case gfx::BufferFormat::UYVY_422: |
59 return false; | 60 return false; |
60 } | 61 } |
61 | 62 |
62 NOTREACHED(); | 63 NOTREACHED(); |
63 return false; | 64 return false; |
64 } | 65 } |
65 | 66 |
66 bool IsCompressedFormat(gfx::BufferFormat format) { | 67 bool IsCompressedFormat(gfx::BufferFormat format) { |
67 switch (format) { | 68 switch (format) { |
68 case gfx::BufferFormat::ATC: | 69 case gfx::BufferFormat::ATC: |
69 case gfx::BufferFormat::ATCIA: | 70 case gfx::BufferFormat::ATCIA: |
70 case gfx::BufferFormat::DXT1: | 71 case gfx::BufferFormat::DXT1: |
71 case gfx::BufferFormat::DXT5: | 72 case gfx::BufferFormat::DXT5: |
72 case gfx::BufferFormat::ETC1: | 73 case gfx::BufferFormat::ETC1: |
73 return true; | 74 return true; |
74 case gfx::BufferFormat::R_8: | 75 case gfx::BufferFormat::R_8: |
75 case gfx::BufferFormat::RG_88: | 76 case gfx::BufferFormat::RG_88: |
76 case gfx::BufferFormat::BGR_565: | 77 case gfx::BufferFormat::BGR_565: |
77 case gfx::BufferFormat::RGBA_4444: | 78 case gfx::BufferFormat::RGBA_4444: |
78 case gfx::BufferFormat::RGBX_8888: | 79 case gfx::BufferFormat::RGBX_8888: |
79 case gfx::BufferFormat::RGBA_8888: | 80 case gfx::BufferFormat::RGBA_8888: |
80 case gfx::BufferFormat::BGRX_8888: | 81 case gfx::BufferFormat::BGRX_8888: |
81 case gfx::BufferFormat::BGRA_8888: | 82 case gfx::BufferFormat::BGRA_8888: |
| 83 case gfx::BufferFormat::RGBA_F16: |
82 return false; | 84 return false; |
83 case gfx::BufferFormat::YVU_420: | 85 case gfx::BufferFormat::YVU_420: |
84 case gfx::BufferFormat::YUV_420_BIPLANAR: | 86 case gfx::BufferFormat::YUV_420_BIPLANAR: |
85 case gfx::BufferFormat::UYVY_422: | 87 case gfx::BufferFormat::UYVY_422: |
86 NOTREACHED(); | 88 NOTREACHED(); |
87 return false; | 89 return false; |
88 } | 90 } |
89 | 91 |
90 NOTREACHED(); | 92 NOTREACHED(); |
91 return false; | 93 return false; |
(...skipping 10 matching lines...) Expand all Loading... |
102 case gfx::BufferFormat::DXT5: | 104 case gfx::BufferFormat::DXT5: |
103 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | 105 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; |
104 case gfx::BufferFormat::ETC1: | 106 case gfx::BufferFormat::ETC1: |
105 return GL_ETC1_RGB8_OES; | 107 return GL_ETC1_RGB8_OES; |
106 case gfx::BufferFormat::R_8: | 108 case gfx::BufferFormat::R_8: |
107 return GL_RED; | 109 return GL_RED; |
108 case gfx::BufferFormat::RG_88: | 110 case gfx::BufferFormat::RG_88: |
109 return GL_RG; | 111 return GL_RG; |
110 case gfx::BufferFormat::RGBA_4444: | 112 case gfx::BufferFormat::RGBA_4444: |
111 case gfx::BufferFormat::RGBA_8888: | 113 case gfx::BufferFormat::RGBA_8888: |
| 114 case gfx::BufferFormat::RGBA_F16: |
112 return GL_RGBA; | 115 return GL_RGBA; |
113 case gfx::BufferFormat::BGRA_8888: | 116 case gfx::BufferFormat::BGRA_8888: |
114 return GL_BGRA_EXT; | 117 return GL_BGRA_EXT; |
115 case gfx::BufferFormat::BGR_565: | 118 case gfx::BufferFormat::BGR_565: |
116 case gfx::BufferFormat::RGBX_8888: | 119 case gfx::BufferFormat::RGBX_8888: |
117 case gfx::BufferFormat::BGRX_8888: | 120 case gfx::BufferFormat::BGRX_8888: |
118 return GL_RGB; | 121 return GL_RGB; |
119 case gfx::BufferFormat::YVU_420: | 122 case gfx::BufferFormat::YVU_420: |
120 case gfx::BufferFormat::YUV_420_BIPLANAR: | 123 case gfx::BufferFormat::YUV_420_BIPLANAR: |
121 case gfx::BufferFormat::UYVY_422: | 124 case gfx::BufferFormat::UYVY_422: |
122 NOTREACHED(); | 125 NOTREACHED(); |
123 return 0; | 126 return 0; |
124 } | 127 } |
125 | 128 |
126 NOTREACHED(); | 129 NOTREACHED(); |
127 return 0; | 130 return 0; |
128 } | 131 } |
129 | 132 |
130 GLenum DataFormat(gfx::BufferFormat format) { | 133 GLenum DataFormat(gfx::BufferFormat format) { |
131 switch (format) { | 134 switch (format) { |
132 case gfx::BufferFormat::RGBX_8888: | 135 case gfx::BufferFormat::RGBX_8888: |
133 return GL_RGBA; | 136 return GL_RGBA; |
134 case gfx::BufferFormat::BGRX_8888: | 137 case gfx::BufferFormat::BGRX_8888: |
135 return GL_BGRA_EXT; | 138 return GL_BGRA_EXT; |
136 case gfx::BufferFormat::BGR_565: | 139 case gfx::BufferFormat::BGR_565: |
137 case gfx::BufferFormat::RGBA_4444: | 140 case gfx::BufferFormat::RGBA_4444: |
138 case gfx::BufferFormat::RGBA_8888: | 141 case gfx::BufferFormat::RGBA_8888: |
139 case gfx::BufferFormat::BGRA_8888: | 142 case gfx::BufferFormat::BGRA_8888: |
| 143 case gfx::BufferFormat::RGBA_F16: |
140 case gfx::BufferFormat::R_8: | 144 case gfx::BufferFormat::R_8: |
141 case gfx::BufferFormat::RG_88: | 145 case gfx::BufferFormat::RG_88: |
142 case gfx::BufferFormat::ATC: | 146 case gfx::BufferFormat::ATC: |
143 case gfx::BufferFormat::ATCIA: | 147 case gfx::BufferFormat::ATCIA: |
144 case gfx::BufferFormat::DXT1: | 148 case gfx::BufferFormat::DXT1: |
145 case gfx::BufferFormat::DXT5: | 149 case gfx::BufferFormat::DXT5: |
146 case gfx::BufferFormat::ETC1: | 150 case gfx::BufferFormat::ETC1: |
147 return TextureFormat(format); | 151 return TextureFormat(format); |
148 case gfx::BufferFormat::YVU_420: | 152 case gfx::BufferFormat::YVU_420: |
149 case gfx::BufferFormat::YUV_420_BIPLANAR: | 153 case gfx::BufferFormat::YUV_420_BIPLANAR: |
(...skipping 12 matching lines...) Expand all Loading... |
162 return GL_UNSIGNED_SHORT_5_6_5_REV; | 166 return GL_UNSIGNED_SHORT_5_6_5_REV; |
163 case gfx::BufferFormat::RGBA_4444: | 167 case gfx::BufferFormat::RGBA_4444: |
164 return GL_UNSIGNED_SHORT_4_4_4_4; | 168 return GL_UNSIGNED_SHORT_4_4_4_4; |
165 case gfx::BufferFormat::RGBX_8888: | 169 case gfx::BufferFormat::RGBX_8888: |
166 case gfx::BufferFormat::RGBA_8888: | 170 case gfx::BufferFormat::RGBA_8888: |
167 case gfx::BufferFormat::BGRX_8888: | 171 case gfx::BufferFormat::BGRX_8888: |
168 case gfx::BufferFormat::BGRA_8888: | 172 case gfx::BufferFormat::BGRA_8888: |
169 case gfx::BufferFormat::R_8: | 173 case gfx::BufferFormat::R_8: |
170 case gfx::BufferFormat::RG_88: | 174 case gfx::BufferFormat::RG_88: |
171 return GL_UNSIGNED_BYTE; | 175 return GL_UNSIGNED_BYTE; |
| 176 case gfx::BufferFormat::RGBA_F16: |
| 177 return GL_HALF_FLOAT_OES; |
172 case gfx::BufferFormat::ATC: | 178 case gfx::BufferFormat::ATC: |
173 case gfx::BufferFormat::ATCIA: | 179 case gfx::BufferFormat::ATCIA: |
174 case gfx::BufferFormat::DXT1: | 180 case gfx::BufferFormat::DXT1: |
175 case gfx::BufferFormat::DXT5: | 181 case gfx::BufferFormat::DXT5: |
176 case gfx::BufferFormat::ETC1: | 182 case gfx::BufferFormat::ETC1: |
177 case gfx::BufferFormat::YVU_420: | 183 case gfx::BufferFormat::YVU_420: |
178 case gfx::BufferFormat::YUV_420_BIPLANAR: | 184 case gfx::BufferFormat::YUV_420_BIPLANAR: |
179 case gfx::BufferFormat::UYVY_422: | 185 case gfx::BufferFormat::UYVY_422: |
180 NOTREACHED(); | 186 NOTREACHED(); |
181 return 0; | 187 return 0; |
182 } | 188 } |
183 | 189 |
184 NOTREACHED(); | 190 NOTREACHED(); |
185 return 0; | 191 return 0; |
186 } | 192 } |
187 | 193 |
188 GLint DataRowLength(size_t stride, gfx::BufferFormat format) { | 194 GLint DataRowLength(size_t stride, gfx::BufferFormat format) { |
189 switch (format) { | 195 switch (format) { |
190 case gfx::BufferFormat::RG_88: | 196 case gfx::BufferFormat::RG_88: |
191 case gfx::BufferFormat::BGR_565: | 197 case gfx::BufferFormat::BGR_565: |
192 case gfx::BufferFormat::RGBA_4444: | 198 case gfx::BufferFormat::RGBA_4444: |
193 return base::checked_cast<GLint>(stride) / 2; | 199 return base::checked_cast<GLint>(stride) / 2; |
194 case gfx::BufferFormat::RGBX_8888: | 200 case gfx::BufferFormat::RGBX_8888: |
195 case gfx::BufferFormat::RGBA_8888: | 201 case gfx::BufferFormat::RGBA_8888: |
196 case gfx::BufferFormat::BGRX_8888: | 202 case gfx::BufferFormat::BGRX_8888: |
197 case gfx::BufferFormat::BGRA_8888: | 203 case gfx::BufferFormat::BGRA_8888: |
198 return base::checked_cast<GLint>(stride) / 4; | 204 return base::checked_cast<GLint>(stride) / 4; |
| 205 case gfx::BufferFormat::RGBA_F16: |
| 206 return base::checked_cast<GLint>(stride) / 8; |
199 case gfx::BufferFormat::R_8: | 207 case gfx::BufferFormat::R_8: |
200 return base::checked_cast<GLint>(stride); | 208 return base::checked_cast<GLint>(stride); |
201 case gfx::BufferFormat::ATC: | 209 case gfx::BufferFormat::ATC: |
202 case gfx::BufferFormat::ATCIA: | 210 case gfx::BufferFormat::ATCIA: |
203 case gfx::BufferFormat::DXT1: | 211 case gfx::BufferFormat::DXT1: |
204 case gfx::BufferFormat::DXT5: | 212 case gfx::BufferFormat::DXT5: |
205 case gfx::BufferFormat::ETC1: | 213 case gfx::BufferFormat::ETC1: |
206 case gfx::BufferFormat::YVU_420: | 214 case gfx::BufferFormat::YVU_420: |
207 case gfx::BufferFormat::YUV_420_BIPLANAR: | 215 case gfx::BufferFormat::YUV_420_BIPLANAR: |
208 case gfx::BufferFormat::UYVY_422: | 216 case gfx::BufferFormat::UYVY_422: |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 return GLES2RGBData(size, stride, data, | 310 return GLES2RGBData(size, stride, data, |
303 [](const uint8_t* src, uint8_t* dst) { | 311 [](const uint8_t* src, uint8_t* dst) { |
304 dst[0] = src[2]; | 312 dst[0] = src[2]; |
305 dst[1] = src[1]; | 313 dst[1] = src[1]; |
306 dst[2] = src[0]; | 314 dst[2] = src[0]; |
307 }, | 315 }, |
308 data_format, data_type, data_row_length); | 316 data_format, data_type, data_row_length); |
309 case gfx::BufferFormat::RGBA_4444: | 317 case gfx::BufferFormat::RGBA_4444: |
310 case gfx::BufferFormat::RGBA_8888: | 318 case gfx::BufferFormat::RGBA_8888: |
311 case gfx::BufferFormat::BGRA_8888: | 319 case gfx::BufferFormat::BGRA_8888: |
| 320 case gfx::BufferFormat::RGBA_F16: |
312 case gfx::BufferFormat::R_8: | 321 case gfx::BufferFormat::R_8: |
313 case gfx::BufferFormat::RG_88: { | 322 case gfx::BufferFormat::RG_88: { |
314 size_t gles2_data_stride = | 323 size_t gles2_data_stride = |
315 RowSizeForBufferFormat(size.width(), format, 0); | 324 RowSizeForBufferFormat(size.width(), format, 0); |
316 if (stride == gles2_data_stride || | 325 if (stride == gles2_data_stride || |
317 g_current_gl_driver->ext.b_GL_EXT_unpack_subimage) | 326 g_current_gl_driver->ext.b_GL_EXT_unpack_subimage) |
318 return nullptr; // No data conversion needed | 327 return nullptr; // No data conversion needed |
319 | 328 |
320 std::unique_ptr<uint8_t[]> gles2_data( | 329 std::unique_ptr<uint8_t[]> gles2_data( |
321 new uint8_t[gles2_data_stride * size.height()]); | 330 new uint8_t[gles2_data_stride * size.height()]); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 return false; | 499 return false; |
491 } | 500 } |
492 | 501 |
493 // static | 502 // static |
494 unsigned GLImageMemory::GetInternalFormatForTesting(gfx::BufferFormat format) { | 503 unsigned GLImageMemory::GetInternalFormatForTesting(gfx::BufferFormat format) { |
495 DCHECK(ValidFormat(format)); | 504 DCHECK(ValidFormat(format)); |
496 return TextureFormat(format); | 505 return TextureFormat(format); |
497 } | 506 } |
498 | 507 |
499 } // namespace gl | 508 } // namespace gl |
OLD | NEW |