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

Side by Side Diff: ui/gl/gl_image_memory.cc

Issue 2920793005: gpu: support R16 GPUMemoryBuffer (Closed)
Patch Set: Add bug number to TODO. Created 3 years, 6 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 | « ui/gl/gl_image_io_surface.mm ('k') | ui/gl/gl_image_native_pixmap.cc » ('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 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
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
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
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:
(...skipping 11 matching lines...) Expand all
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:
174 case gfx::BufferFormat::RG_88: 179 case gfx::BufferFormat::RG_88:
175 return GL_UNSIGNED_BYTE; 180 return GL_UNSIGNED_BYTE;
181 case gfx::BufferFormat::R_16:
182 return GL_UNSIGNED_SHORT;
176 case gfx::BufferFormat::RGBA_F16: 183 case gfx::BufferFormat::RGBA_F16:
177 return GL_HALF_FLOAT_OES; 184 return GL_HALF_FLOAT_OES;
178 case gfx::BufferFormat::ATC: 185 case gfx::BufferFormat::ATC:
179 case gfx::BufferFormat::ATCIA: 186 case gfx::BufferFormat::ATCIA:
180 case gfx::BufferFormat::DXT1: 187 case gfx::BufferFormat::DXT1:
181 case gfx::BufferFormat::DXT5: 188 case gfx::BufferFormat::DXT5:
182 case gfx::BufferFormat::ETC1: 189 case gfx::BufferFormat::ETC1:
183 case gfx::BufferFormat::YVU_420: 190 case gfx::BufferFormat::YVU_420:
184 case gfx::BufferFormat::YUV_420_BIPLANAR: 191 case gfx::BufferFormat::YUV_420_BIPLANAR:
185 case gfx::BufferFormat::UYVY_422: 192 case gfx::BufferFormat::UYVY_422:
186 NOTREACHED(); 193 NOTREACHED();
187 return 0; 194 return 0;
188 } 195 }
189 196
190 NOTREACHED(); 197 NOTREACHED();
191 return 0; 198 return 0;
192 } 199 }
193 200
194 GLint DataRowLength(size_t stride, gfx::BufferFormat format) { 201 GLint DataRowLength(size_t stride, gfx::BufferFormat format) {
195 switch (format) { 202 switch (format) {
196 case gfx::BufferFormat::RG_88: 203 case gfx::BufferFormat::RG_88:
204 case gfx::BufferFormat::R_16:
197 case gfx::BufferFormat::BGR_565: 205 case gfx::BufferFormat::BGR_565:
198 case gfx::BufferFormat::RGBA_4444: 206 case gfx::BufferFormat::RGBA_4444:
199 return base::checked_cast<GLint>(stride) / 2; 207 return base::checked_cast<GLint>(stride) / 2;
200 case gfx::BufferFormat::RGBX_8888: 208 case gfx::BufferFormat::RGBX_8888:
201 case gfx::BufferFormat::RGBA_8888: 209 case gfx::BufferFormat::RGBA_8888:
202 case gfx::BufferFormat::BGRX_8888: 210 case gfx::BufferFormat::BGRX_8888:
203 case gfx::BufferFormat::BGRA_8888: 211 case gfx::BufferFormat::BGRA_8888:
204 return base::checked_cast<GLint>(stride) / 4; 212 return base::checked_cast<GLint>(stride) / 4;
205 case gfx::BufferFormat::RGBA_F16: 213 case gfx::BufferFormat::RGBA_F16:
206 return base::checked_cast<GLint>(stride) / 8; 214 return base::checked_cast<GLint>(stride) / 8;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW
« no previous file with comments | « ui/gl/gl_image_io_surface.mm ('k') | ui/gl/gl_image_native_pixmap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698