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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 case BufferFormat::UYVY_422: | 193 case BufferFormat::UYVY_422: |
194 NOTREACHED(); | 194 NOTREACHED(); |
195 return 0; | 195 return 0; |
196 } | 196 } |
197 | 197 |
198 NOTREACHED(); | 198 NOTREACHED(); |
199 return 0; | 199 return 0; |
200 } | 200 } |
201 | 201 |
202 template <typename F> | 202 template <typename F> |
203 scoped_ptr<uint8_t[]> GLES2RGBData(const gfx::Size& size, | 203 std::unique_ptr<uint8_t[]> GLES2RGBData(const gfx::Size& size, |
204 BufferFormat format, | 204 BufferFormat format, |
205 size_t stride, | 205 size_t stride, |
206 const uint8_t* data, | 206 const uint8_t* data, |
207 F const& data_to_rgb, | 207 F const& data_to_rgb, |
208 GLenum* data_format, | 208 GLenum* data_format, |
209 GLenum* data_type, | 209 GLenum* data_type, |
210 GLint* data_row_length) { | 210 GLint* data_row_length) { |
211 TRACE_EVENT2("gpu", "GLES2RGBData", "width", size.width(), "height", | 211 TRACE_EVENT2("gpu", "GLES2RGBData", "width", size.width(), "height", |
212 size.height()); | 212 size.height()); |
213 | 213 |
214 // Four-byte row alignment as specified by glPixelStorei with argument | 214 // Four-byte row alignment as specified by glPixelStorei with argument |
215 // GL_UNPACK_ALIGNMENT set to 4. | 215 // GL_UNPACK_ALIGNMENT set to 4. |
216 size_t gles2_rgb_data_stride = (size.width() * 3 + 3) & ~3; | 216 size_t gles2_rgb_data_stride = (size.width() * 3 + 3) & ~3; |
217 scoped_ptr<uint8_t[]> gles2_rgb_data( | 217 std::unique_ptr<uint8_t[]> gles2_rgb_data( |
218 new uint8_t[gles2_rgb_data_stride * size.height()]); | 218 new uint8_t[gles2_rgb_data_stride * size.height()]); |
219 | 219 |
220 for (int y = 0; y < size.height(); ++y) { | 220 for (int y = 0; y < size.height(); ++y) { |
221 for (int x = 0; x < size.width(); ++x) { | 221 for (int x = 0; x < size.width(); ++x) { |
222 data_to_rgb(&data[y * stride + x * 4], | 222 data_to_rgb(&data[y * stride + x * 4], |
223 &gles2_rgb_data[y * gles2_rgb_data_stride + x * 3]); | 223 &gles2_rgb_data[y * gles2_rgb_data_stride + x * 3]); |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 *data_format = GL_RGB; | 227 *data_format = GL_RGB; |
228 *data_type = GL_UNSIGNED_BYTE; | 228 *data_type = GL_UNSIGNED_BYTE; |
229 *data_row_length = size.width(); | 229 *data_row_length = size.width(); |
230 return gles2_rgb_data; | 230 return gles2_rgb_data; |
231 } | 231 } |
232 | 232 |
233 scoped_ptr<uint8_t[]> GLES2Data(const gfx::Size& size, | 233 std::unique_ptr<uint8_t[]> GLES2Data(const gfx::Size& size, |
234 BufferFormat format, | 234 BufferFormat format, |
235 size_t stride, | 235 size_t stride, |
236 const uint8_t* data, | 236 const uint8_t* data, |
237 GLenum* data_format, | 237 GLenum* data_format, |
238 GLenum* data_type, | 238 GLenum* data_type, |
239 GLint* data_row_length) { | 239 GLint* data_row_length) { |
240 TRACE_EVENT2("gpu", "GLES2Data", "width", size.width(), "height", | 240 TRACE_EVENT2("gpu", "GLES2Data", "width", size.width(), "height", |
241 size.height()); | 241 size.height()); |
242 | 242 |
243 switch (format) { | 243 switch (format) { |
244 case BufferFormat::RGBX_8888: | 244 case BufferFormat::RGBX_8888: |
245 return GLES2RGBData(size, format, stride, | 245 return GLES2RGBData(size, format, stride, |
246 data, [](const uint8_t* src, uint8_t* dst) { | 246 data, [](const uint8_t* src, uint8_t* dst) { |
247 dst[0] = src[0]; | 247 dst[0] = src[0]; |
248 dst[1] = src[1]; | 248 dst[1] = src[1]; |
249 dst[2] = src[2]; | 249 dst[2] = src[2]; |
250 }, data_format, data_type, data_row_length); | 250 }, data_format, data_type, data_row_length); |
251 case BufferFormat::BGRX_8888: | 251 case BufferFormat::BGRX_8888: |
252 return GLES2RGBData(size, format, stride, | 252 return GLES2RGBData(size, format, stride, |
253 data, [](const uint8_t* src, uint8_t* dst) { | 253 data, [](const uint8_t* src, uint8_t* dst) { |
254 dst[0] = src[2]; | 254 dst[0] = src[2]; |
255 dst[1] = src[1]; | 255 dst[1] = src[1]; |
256 dst[2] = src[0]; | 256 dst[2] = src[0]; |
257 }, data_format, data_type, data_row_length); | 257 }, data_format, data_type, data_row_length); |
258 case BufferFormat::RGBA_4444: | 258 case BufferFormat::RGBA_4444: |
259 case BufferFormat::RGBA_8888: | 259 case BufferFormat::RGBA_8888: |
260 case BufferFormat::BGRA_8888: | 260 case BufferFormat::BGRA_8888: |
261 case BufferFormat::R_8: { | 261 case BufferFormat::R_8: { |
262 size_t gles2_data_stride = | 262 size_t gles2_data_stride = |
263 RowSizeForBufferFormat(size.width(), format, 0); | 263 RowSizeForBufferFormat(size.width(), format, 0); |
264 if (stride == gles2_data_stride || | 264 if (stride == gles2_data_stride || |
265 gfx::g_driver_gl.ext.b_GL_EXT_unpack_subimage) | 265 gfx::g_driver_gl.ext.b_GL_EXT_unpack_subimage) |
266 return nullptr; // No data conversion needed | 266 return nullptr; // No data conversion needed |
267 | 267 |
268 scoped_ptr<uint8_t[]> gles2_data( | 268 std::unique_ptr<uint8_t[]> gles2_data( |
269 new uint8_t[gles2_data_stride * size.height()]); | 269 new uint8_t[gles2_data_stride * size.height()]); |
270 for (int y = 0; y < size.height(); ++y) { | 270 for (int y = 0; y < size.height(); ++y) { |
271 memcpy(&gles2_data[y * gles2_data_stride], &data[y * stride], | 271 memcpy(&gles2_data[y * gles2_data_stride], &data[y * stride], |
272 gles2_data_stride); | 272 gles2_data_stride); |
273 } | 273 } |
274 *data_row_length = size.width(); | 274 *data_row_length = size.width(); |
275 return gles2_data; | 275 return gles2_data; |
276 } | 276 } |
277 case BufferFormat::ATC: | 277 case BufferFormat::ATC: |
278 case BufferFormat::ATCIA: | 278 case BufferFormat::ATCIA: |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 358 |
359 if (IsCompressedFormat(format_)) { | 359 if (IsCompressedFormat(format_)) { |
360 glCompressedTexImage2D( | 360 glCompressedTexImage2D( |
361 target, 0, TextureFormat(format_), size_.width(), size_.height(), 0, | 361 target, 0, TextureFormat(format_), size_.width(), size_.height(), 0, |
362 static_cast<GLsizei>(BufferSizeForBufferFormat(size_, format_)), | 362 static_cast<GLsizei>(BufferSizeForBufferFormat(size_, format_)), |
363 memory_); | 363 memory_); |
364 } else { | 364 } else { |
365 GLenum data_format = DataFormat(format_); | 365 GLenum data_format = DataFormat(format_); |
366 GLenum data_type = DataType(format_); | 366 GLenum data_type = DataType(format_); |
367 GLint data_row_length = DataRowLength(stride_, format_); | 367 GLint data_row_length = DataRowLength(stride_, format_); |
368 scoped_ptr<uint8_t[]> gles2_data; | 368 std::unique_ptr<uint8_t[]> gles2_data; |
369 | 369 |
370 if (gfx::GLContext::GetCurrent()->GetVersionInfo()->is_es) { | 370 if (gfx::GLContext::GetCurrent()->GetVersionInfo()->is_es) { |
371 gles2_data = GLES2Data(size_, format_, stride_, memory_, &data_format, | 371 gles2_data = GLES2Data(size_, format_, stride_, memory_, &data_format, |
372 &data_type, &data_row_length); | 372 &data_type, &data_row_length); |
373 } | 373 } |
374 | 374 |
375 if (data_row_length != size_.width()) | 375 if (data_row_length != size_.width()) |
376 glPixelStorei(GL_UNPACK_ROW_LENGTH, data_row_length); | 376 glPixelStorei(GL_UNPACK_ROW_LENGTH, data_row_length); |
377 | 377 |
378 glTexImage2D(target, 0, TextureFormat(format_), size_.width(), | 378 glTexImage2D(target, 0, TextureFormat(format_), size_.width(), |
(...skipping 29 matching lines...) Expand all Loading... |
408 | 408 |
409 glCompressedTexSubImage2D( | 409 glCompressedTexSubImage2D( |
410 target, 0, offset.x(), offset.y(), rect.width(), rect.height(), | 410 target, 0, offset.x(), offset.y(), rect.width(), rect.height(), |
411 DataFormat(format_), | 411 DataFormat(format_), |
412 static_cast<GLsizei>(BufferSizeForBufferFormat(rect.size(), format_)), | 412 static_cast<GLsizei>(BufferSizeForBufferFormat(rect.size(), format_)), |
413 data); | 413 data); |
414 } else { | 414 } else { |
415 GLenum data_format = DataFormat(format_); | 415 GLenum data_format = DataFormat(format_); |
416 GLenum data_type = DataType(format_); | 416 GLenum data_type = DataType(format_); |
417 GLint data_row_length = DataRowLength(stride_, format_); | 417 GLint data_row_length = DataRowLength(stride_, format_); |
418 scoped_ptr<uint8_t[]> gles2_data; | 418 std::unique_ptr<uint8_t[]> gles2_data; |
419 | 419 |
420 if (gfx::GLContext::GetCurrent()->GetVersionInfo()->is_es) { | 420 if (gfx::GLContext::GetCurrent()->GetVersionInfo()->is_es) { |
421 gles2_data = GLES2Data(rect.size(), format_, stride_, data, &data_format, | 421 gles2_data = GLES2Data(rect.size(), format_, stride_, data, &data_format, |
422 &data_type, &data_row_length); | 422 &data_type, &data_row_length); |
423 } | 423 } |
424 | 424 |
425 if (data_row_length != rect.width()) | 425 if (data_row_length != rect.width()) |
426 glPixelStorei(GL_UNPACK_ROW_LENGTH, data_row_length); | 426 glPixelStorei(GL_UNPACK_ROW_LENGTH, data_row_length); |
427 | 427 |
428 glTexSubImage2D(target, 0, offset.x(), offset.y(), rect.width(), | 428 glTexSubImage2D(target, 0, offset.x(), offset.y(), rect.width(), |
(...skipping 15 matching lines...) Expand all Loading... |
444 return false; | 444 return false; |
445 } | 445 } |
446 | 446 |
447 // static | 447 // static |
448 unsigned GLImageMemory::GetInternalFormatForTesting(BufferFormat format) { | 448 unsigned GLImageMemory::GetInternalFormatForTesting(BufferFormat format) { |
449 DCHECK(ValidFormat(format)); | 449 DCHECK(ValidFormat(format)); |
450 return TextureFormat(format); | 450 return TextureFormat(format); |
451 } | 451 } |
452 | 452 |
453 } // namespace gl | 453 } // namespace gl |
OLD | NEW |