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" |
11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
12 #include "ui/gfx/buffer_format_util.h" | 12 #include "ui/gfx/buffer_format_util.h" |
13 #include "ui/gl/gl_bindings.h" | 13 #include "ui/gl/gl_bindings.h" |
14 #include "ui/gl/gl_context.h" | 14 #include "ui/gl/gl_context.h" |
15 #include "ui/gl/gl_version_info.h" | 15 #include "ui/gl/gl_version_info.h" |
16 | 16 |
17 using gfx::BufferFormat; | 17 using gfx::BufferFormat; |
18 | 18 |
19 namespace gl { | 19 namespace gl { |
20 namespace { | 20 namespace { |
21 | 21 |
22 bool ValidInternalFormat(unsigned internalformat) { | 22 bool ValidInternalFormat(unsigned internalformat) { |
23 switch (internalformat) { | 23 switch (internalformat) { |
24 case GL_ATC_RGB_AMD: | 24 case GL_ATC_RGB_AMD: |
25 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: | 25 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: |
26 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: | 26 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
27 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: | 27 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: |
28 case GL_ETC1_RGB8_OES: | 28 case GL_ETC1_RGB8_OES: |
29 case GL_RED: | 29 case GL_RED: |
| 30 case GL_RG: |
30 case GL_RGB: | 31 case GL_RGB: |
31 case GL_RGBA: | 32 case GL_RGBA: |
32 case GL_BGRA_EXT: | 33 case GL_BGRA_EXT: |
33 return true; | 34 return true; |
34 default: | 35 default: |
35 return false; | 36 return false; |
36 } | 37 } |
37 } | 38 } |
38 | 39 |
39 bool ValidFormat(gfx::BufferFormat format) { | 40 bool ValidFormat(gfx::BufferFormat format) { |
40 switch (format) { | 41 switch (format) { |
41 case gfx::BufferFormat::ATC: | 42 case gfx::BufferFormat::ATC: |
42 case gfx::BufferFormat::ATCIA: | 43 case gfx::BufferFormat::ATCIA: |
43 case gfx::BufferFormat::DXT1: | 44 case gfx::BufferFormat::DXT1: |
44 case gfx::BufferFormat::DXT5: | 45 case gfx::BufferFormat::DXT5: |
45 case gfx::BufferFormat::ETC1: | 46 case gfx::BufferFormat::ETC1: |
46 case gfx::BufferFormat::R_8: | 47 case gfx::BufferFormat::R_8: |
| 48 case gfx::BufferFormat::RG_88: |
47 case gfx::BufferFormat::BGR_565: | 49 case gfx::BufferFormat::BGR_565: |
48 case gfx::BufferFormat::RGBA_4444: | 50 case gfx::BufferFormat::RGBA_4444: |
49 case gfx::BufferFormat::RGBX_8888: | 51 case gfx::BufferFormat::RGBX_8888: |
50 case gfx::BufferFormat::RGBA_8888: | 52 case gfx::BufferFormat::RGBA_8888: |
51 case gfx::BufferFormat::BGRX_8888: | 53 case gfx::BufferFormat::BGRX_8888: |
52 case gfx::BufferFormat::BGRA_8888: | 54 case gfx::BufferFormat::BGRA_8888: |
53 return true; | 55 return true; |
54 case gfx::BufferFormat::YVU_420: | 56 case gfx::BufferFormat::YVU_420: |
55 case gfx::BufferFormat::YUV_420_BIPLANAR: | 57 case gfx::BufferFormat::YUV_420_BIPLANAR: |
56 case gfx::BufferFormat::UYVY_422: | 58 case gfx::BufferFormat::UYVY_422: |
57 return false; | 59 return false; |
58 } | 60 } |
59 | 61 |
60 NOTREACHED(); | 62 NOTREACHED(); |
61 return false; | 63 return false; |
62 } | 64 } |
63 | 65 |
64 bool IsCompressedFormat(gfx::BufferFormat format) { | 66 bool IsCompressedFormat(gfx::BufferFormat format) { |
65 switch (format) { | 67 switch (format) { |
66 case gfx::BufferFormat::ATC: | 68 case gfx::BufferFormat::ATC: |
67 case gfx::BufferFormat::ATCIA: | 69 case gfx::BufferFormat::ATCIA: |
68 case gfx::BufferFormat::DXT1: | 70 case gfx::BufferFormat::DXT1: |
69 case gfx::BufferFormat::DXT5: | 71 case gfx::BufferFormat::DXT5: |
70 case gfx::BufferFormat::ETC1: | 72 case gfx::BufferFormat::ETC1: |
71 return true; | 73 return true; |
72 case gfx::BufferFormat::R_8: | 74 case gfx::BufferFormat::R_8: |
| 75 case gfx::BufferFormat::RG_88: |
73 case gfx::BufferFormat::BGR_565: | 76 case gfx::BufferFormat::BGR_565: |
74 case gfx::BufferFormat::RGBA_4444: | 77 case gfx::BufferFormat::RGBA_4444: |
75 case gfx::BufferFormat::RGBX_8888: | 78 case gfx::BufferFormat::RGBX_8888: |
76 case gfx::BufferFormat::RGBA_8888: | 79 case gfx::BufferFormat::RGBA_8888: |
77 case gfx::BufferFormat::BGRX_8888: | 80 case gfx::BufferFormat::BGRX_8888: |
78 case gfx::BufferFormat::BGRA_8888: | 81 case gfx::BufferFormat::BGRA_8888: |
79 return false; | 82 return false; |
80 case gfx::BufferFormat::YVU_420: | 83 case gfx::BufferFormat::YVU_420: |
81 case gfx::BufferFormat::YUV_420_BIPLANAR: | 84 case gfx::BufferFormat::YUV_420_BIPLANAR: |
82 case gfx::BufferFormat::UYVY_422: | 85 case gfx::BufferFormat::UYVY_422: |
(...skipping 12 matching lines...) Expand all Loading... |
95 case gfx::BufferFormat::ATCIA: | 98 case gfx::BufferFormat::ATCIA: |
96 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; | 99 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; |
97 case gfx::BufferFormat::DXT1: | 100 case gfx::BufferFormat::DXT1: |
98 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; | 101 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; |
99 case gfx::BufferFormat::DXT5: | 102 case gfx::BufferFormat::DXT5: |
100 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | 103 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; |
101 case gfx::BufferFormat::ETC1: | 104 case gfx::BufferFormat::ETC1: |
102 return GL_ETC1_RGB8_OES; | 105 return GL_ETC1_RGB8_OES; |
103 case gfx::BufferFormat::R_8: | 106 case gfx::BufferFormat::R_8: |
104 return GL_RED; | 107 return GL_RED; |
| 108 case gfx::BufferFormat::RG_88: |
| 109 return GL_RG; |
105 case gfx::BufferFormat::RGBA_4444: | 110 case gfx::BufferFormat::RGBA_4444: |
106 case gfx::BufferFormat::RGBA_8888: | 111 case gfx::BufferFormat::RGBA_8888: |
107 return GL_RGBA; | 112 return GL_RGBA; |
108 case gfx::BufferFormat::BGRA_8888: | 113 case gfx::BufferFormat::BGRA_8888: |
109 return GL_BGRA_EXT; | 114 return GL_BGRA_EXT; |
110 case gfx::BufferFormat::BGR_565: | 115 case gfx::BufferFormat::BGR_565: |
111 case gfx::BufferFormat::RGBX_8888: | 116 case gfx::BufferFormat::RGBX_8888: |
112 case gfx::BufferFormat::BGRX_8888: | 117 case gfx::BufferFormat::BGRX_8888: |
113 return GL_RGB; | 118 return GL_RGB; |
114 case gfx::BufferFormat::YVU_420: | 119 case gfx::BufferFormat::YVU_420: |
(...skipping 11 matching lines...) Expand all Loading... |
126 switch (format) { | 131 switch (format) { |
127 case gfx::BufferFormat::RGBX_8888: | 132 case gfx::BufferFormat::RGBX_8888: |
128 return GL_RGBA; | 133 return GL_RGBA; |
129 case gfx::BufferFormat::BGRX_8888: | 134 case gfx::BufferFormat::BGRX_8888: |
130 return GL_BGRA_EXT; | 135 return GL_BGRA_EXT; |
131 case gfx::BufferFormat::BGR_565: | 136 case gfx::BufferFormat::BGR_565: |
132 case gfx::BufferFormat::RGBA_4444: | 137 case gfx::BufferFormat::RGBA_4444: |
133 case gfx::BufferFormat::RGBA_8888: | 138 case gfx::BufferFormat::RGBA_8888: |
134 case gfx::BufferFormat::BGRA_8888: | 139 case gfx::BufferFormat::BGRA_8888: |
135 case gfx::BufferFormat::R_8: | 140 case gfx::BufferFormat::R_8: |
| 141 case gfx::BufferFormat::RG_88: |
136 case gfx::BufferFormat::ATC: | 142 case gfx::BufferFormat::ATC: |
137 case gfx::BufferFormat::ATCIA: | 143 case gfx::BufferFormat::ATCIA: |
138 case gfx::BufferFormat::DXT1: | 144 case gfx::BufferFormat::DXT1: |
139 case gfx::BufferFormat::DXT5: | 145 case gfx::BufferFormat::DXT5: |
140 case gfx::BufferFormat::ETC1: | 146 case gfx::BufferFormat::ETC1: |
141 return TextureFormat(format); | 147 return TextureFormat(format); |
142 case gfx::BufferFormat::YVU_420: | 148 case gfx::BufferFormat::YVU_420: |
143 case gfx::BufferFormat::YUV_420_BIPLANAR: | 149 case gfx::BufferFormat::YUV_420_BIPLANAR: |
144 case gfx::BufferFormat::UYVY_422: | 150 case gfx::BufferFormat::UYVY_422: |
145 NOTREACHED(); | 151 NOTREACHED(); |
146 return 0; | 152 return 0; |
147 } | 153 } |
148 | 154 |
149 NOTREACHED(); | 155 NOTREACHED(); |
150 return 0; | 156 return 0; |
151 } | 157 } |
152 | 158 |
153 GLenum DataType(gfx::BufferFormat format) { | 159 GLenum DataType(gfx::BufferFormat format) { |
154 switch (format) { | 160 switch (format) { |
155 case gfx::BufferFormat::BGR_565: | 161 case gfx::BufferFormat::BGR_565: |
156 return GL_UNSIGNED_SHORT_5_6_5_REV; | 162 return GL_UNSIGNED_SHORT_5_6_5_REV; |
157 case gfx::BufferFormat::RGBA_4444: | 163 case gfx::BufferFormat::RGBA_4444: |
158 return GL_UNSIGNED_SHORT_4_4_4_4; | 164 return GL_UNSIGNED_SHORT_4_4_4_4; |
159 case gfx::BufferFormat::RGBX_8888: | 165 case gfx::BufferFormat::RGBX_8888: |
160 case gfx::BufferFormat::RGBA_8888: | 166 case gfx::BufferFormat::RGBA_8888: |
161 case gfx::BufferFormat::BGRX_8888: | 167 case gfx::BufferFormat::BGRX_8888: |
162 case gfx::BufferFormat::BGRA_8888: | 168 case gfx::BufferFormat::BGRA_8888: |
163 case gfx::BufferFormat::R_8: | 169 case gfx::BufferFormat::R_8: |
| 170 case gfx::BufferFormat::RG_88: |
164 return GL_UNSIGNED_BYTE; | 171 return GL_UNSIGNED_BYTE; |
165 case gfx::BufferFormat::ATC: | 172 case gfx::BufferFormat::ATC: |
166 case gfx::BufferFormat::ATCIA: | 173 case gfx::BufferFormat::ATCIA: |
167 case gfx::BufferFormat::DXT1: | 174 case gfx::BufferFormat::DXT1: |
168 case gfx::BufferFormat::DXT5: | 175 case gfx::BufferFormat::DXT5: |
169 case gfx::BufferFormat::ETC1: | 176 case gfx::BufferFormat::ETC1: |
170 case gfx::BufferFormat::YVU_420: | 177 case gfx::BufferFormat::YVU_420: |
171 case gfx::BufferFormat::YUV_420_BIPLANAR: | 178 case gfx::BufferFormat::YUV_420_BIPLANAR: |
172 case gfx::BufferFormat::UYVY_422: | 179 case gfx::BufferFormat::UYVY_422: |
173 NOTREACHED(); | 180 NOTREACHED(); |
174 return 0; | 181 return 0; |
175 } | 182 } |
176 | 183 |
177 NOTREACHED(); | 184 NOTREACHED(); |
178 return 0; | 185 return 0; |
179 } | 186 } |
180 | 187 |
181 GLint DataRowLength(size_t stride, gfx::BufferFormat format) { | 188 GLint DataRowLength(size_t stride, gfx::BufferFormat format) { |
182 switch (format) { | 189 switch (format) { |
| 190 case gfx::BufferFormat::RG_88: |
183 case gfx::BufferFormat::BGR_565: | 191 case gfx::BufferFormat::BGR_565: |
184 case gfx::BufferFormat::RGBA_4444: | 192 case gfx::BufferFormat::RGBA_4444: |
185 return base::checked_cast<GLint>(stride) / 2; | 193 return base::checked_cast<GLint>(stride) / 2; |
186 case gfx::BufferFormat::RGBX_8888: | 194 case gfx::BufferFormat::RGBX_8888: |
187 case gfx::BufferFormat::RGBA_8888: | 195 case gfx::BufferFormat::RGBA_8888: |
188 case gfx::BufferFormat::BGRX_8888: | 196 case gfx::BufferFormat::BGRX_8888: |
189 case gfx::BufferFormat::BGRA_8888: | 197 case gfx::BufferFormat::BGRA_8888: |
190 return base::checked_cast<GLint>(stride) / 4; | 198 return base::checked_cast<GLint>(stride) / 4; |
191 case gfx::BufferFormat::R_8: | 199 case gfx::BufferFormat::R_8: |
192 return base::checked_cast<GLint>(stride); | 200 return base::checked_cast<GLint>(stride); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 return GLES2RGBData(size, stride, data, | 302 return GLES2RGBData(size, stride, data, |
295 [](const uint8_t* src, uint8_t* dst) { | 303 [](const uint8_t* src, uint8_t* dst) { |
296 dst[0] = src[2]; | 304 dst[0] = src[2]; |
297 dst[1] = src[1]; | 305 dst[1] = src[1]; |
298 dst[2] = src[0]; | 306 dst[2] = src[0]; |
299 }, | 307 }, |
300 data_format, data_type, data_row_length); | 308 data_format, data_type, data_row_length); |
301 case gfx::BufferFormat::RGBA_4444: | 309 case gfx::BufferFormat::RGBA_4444: |
302 case gfx::BufferFormat::RGBA_8888: | 310 case gfx::BufferFormat::RGBA_8888: |
303 case gfx::BufferFormat::BGRA_8888: | 311 case gfx::BufferFormat::BGRA_8888: |
304 case gfx::BufferFormat::R_8: { | 312 case gfx::BufferFormat::R_8: |
| 313 case gfx::BufferFormat::RG_88: { |
305 size_t gles2_data_stride = | 314 size_t gles2_data_stride = |
306 RowSizeForBufferFormat(size.width(), format, 0); | 315 RowSizeForBufferFormat(size.width(), format, 0); |
307 if (stride == gles2_data_stride || | 316 if (stride == gles2_data_stride || |
308 g_driver_gl.ext.b_GL_EXT_unpack_subimage) | 317 g_driver_gl.ext.b_GL_EXT_unpack_subimage) |
309 return nullptr; // No data conversion needed | 318 return nullptr; // No data conversion needed |
310 | 319 |
311 std::unique_ptr<uint8_t[]> gles2_data( | 320 std::unique_ptr<uint8_t[]> gles2_data( |
312 new uint8_t[gles2_data_stride * size.height()]); | 321 new uint8_t[gles2_data_stride * size.height()]); |
313 for (int y = 0; y < size.height(); ++y) { | 322 for (int y = 0; y < size.height(); ++y) { |
314 memcpy(&gles2_data[y * gles2_data_stride], &data[y * stride], | 323 memcpy(&gles2_data[y * gles2_data_stride], &data[y * stride], |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 return false; | 496 return false; |
488 } | 497 } |
489 | 498 |
490 // static | 499 // static |
491 unsigned GLImageMemory::GetInternalFormatForTesting(gfx::BufferFormat format) { | 500 unsigned GLImageMemory::GetInternalFormatForTesting(gfx::BufferFormat format) { |
492 DCHECK(ValidFormat(format)); | 501 DCHECK(ValidFormat(format)); |
493 return TextureFormat(format); | 502 return TextureFormat(format); |
494 } | 503 } |
495 | 504 |
496 } // namespace gl | 505 } // namespace gl |
OLD | NEW |