| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/numerics/safe_conversions.h" | 8 #include "base/numerics/safe_conversions.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "ui/gfx/buffer_format_util.h" | 10 #include "ui/gfx/buffer_format_util.h" |
| 11 #include "ui/gl/gl_bindings.h" | 11 #include "ui/gl/gl_bindings.h" |
| 12 #include "ui/gl/gl_context.h" | 12 #include "ui/gl/gl_context.h" |
| 13 #include "ui/gl/gl_utils.h" |
| 13 #include "ui/gl/gl_version_info.h" | 14 #include "ui/gl/gl_version_info.h" |
| 14 | 15 |
| 15 using gfx::BufferFormat; | 16 using gfx::BufferFormat; |
| 16 | 17 |
| 17 namespace gl { | 18 namespace gl { |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 bool ValidInternalFormat(unsigned internalformat) { | 21 bool ValidInternalFormat(unsigned internalformat) { |
| 21 switch (internalformat) { | 22 switch (internalformat) { |
| 22 case GL_ATC_RGB_AMD: | 23 case GL_ATC_RGB_AMD: |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 case BufferFormat::YUV_420_BIPLANAR: | 78 case BufferFormat::YUV_420_BIPLANAR: |
| 78 case BufferFormat::UYVY_422: | 79 case BufferFormat::UYVY_422: |
| 79 NOTREACHED(); | 80 NOTREACHED(); |
| 80 return false; | 81 return false; |
| 81 } | 82 } |
| 82 | 83 |
| 83 NOTREACHED(); | 84 NOTREACHED(); |
| 84 return false; | 85 return false; |
| 85 } | 86 } |
| 86 | 87 |
| 87 GLenum TextureFormat(BufferFormat format) { | |
| 88 switch (format) { | |
| 89 case BufferFormat::ATC: | |
| 90 return GL_ATC_RGB_AMD; | |
| 91 case BufferFormat::ATCIA: | |
| 92 return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD; | |
| 93 case BufferFormat::DXT1: | |
| 94 return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; | |
| 95 case BufferFormat::DXT5: | |
| 96 return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; | |
| 97 case BufferFormat::ETC1: | |
| 98 return GL_ETC1_RGB8_OES; | |
| 99 case BufferFormat::R_8: | |
| 100 return GL_RED; | |
| 101 case BufferFormat::RGBA_4444: | |
| 102 case BufferFormat::RGBA_8888: | |
| 103 return GL_RGBA; | |
| 104 case BufferFormat::BGRA_8888: | |
| 105 return GL_BGRA_EXT; | |
| 106 case BufferFormat::RGBX_8888: | |
| 107 case BufferFormat::BGRX_8888: | |
| 108 return GL_RGB; | |
| 109 case BufferFormat::YUV_420: | |
| 110 case BufferFormat::YUV_420_BIPLANAR: | |
| 111 case BufferFormat::UYVY_422: | |
| 112 NOTREACHED(); | |
| 113 return 0; | |
| 114 } | |
| 115 | |
| 116 NOTREACHED(); | |
| 117 return 0; | |
| 118 } | |
| 119 | |
| 120 GLenum DataFormat(BufferFormat format) { | 88 GLenum DataFormat(BufferFormat format) { |
| 121 switch (format) { | 89 switch (format) { |
| 122 case BufferFormat::RGBX_8888: | 90 case BufferFormat::RGBX_8888: |
| 123 return GL_RGBA; | 91 return GL_RGBA; |
| 124 case BufferFormat::BGRX_8888: | 92 case BufferFormat::BGRX_8888: |
| 125 return GL_BGRA_EXT; | 93 return GL_BGRA_EXT; |
| 126 case BufferFormat::RGBA_4444: | 94 case BufferFormat::RGBA_4444: |
| 127 case BufferFormat::RGBA_8888: | 95 case BufferFormat::RGBA_8888: |
| 128 case BufferFormat::BGRA_8888: | 96 case BufferFormat::BGRA_8888: |
| 129 case BufferFormat::R_8: | 97 case BufferFormat::R_8: |
| 130 case BufferFormat::ATC: | 98 case BufferFormat::ATC: |
| 131 case BufferFormat::ATCIA: | 99 case BufferFormat::ATCIA: |
| 132 case BufferFormat::DXT1: | 100 case BufferFormat::DXT1: |
| 133 case BufferFormat::DXT5: | 101 case BufferFormat::DXT5: |
| 134 case BufferFormat::ETC1: | 102 case BufferFormat::ETC1: |
| 135 return TextureFormat(format); | 103 return GetTextureFormatFrom(format); |
| 136 case BufferFormat::YUV_420: | 104 case BufferFormat::YUV_420: |
| 137 case BufferFormat::YUV_420_BIPLANAR: | 105 case BufferFormat::YUV_420_BIPLANAR: |
| 138 case BufferFormat::UYVY_422: | 106 case BufferFormat::UYVY_422: |
| 139 NOTREACHED(); | 107 NOTREACHED(); |
| 140 return 0; | 108 return 0; |
| 141 } | 109 } |
| 142 | 110 |
| 143 NOTREACHED(); | 111 NOTREACHED(); |
| 144 return 0; | 112 return 0; |
| 145 } | 113 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 bool GLImageMemory::CopyTexImage(unsigned target) { | 316 bool GLImageMemory::CopyTexImage(unsigned target) { |
| 349 TRACE_EVENT2("gpu", "GLImageMemory::CopyTexImage", "width", size_.width(), | 317 TRACE_EVENT2("gpu", "GLImageMemory::CopyTexImage", "width", size_.width(), |
| 350 "height", size_.height()); | 318 "height", size_.height()); |
| 351 | 319 |
| 352 // GL_TEXTURE_EXTERNAL_OES is not a supported target. | 320 // GL_TEXTURE_EXTERNAL_OES is not a supported target. |
| 353 if (target == GL_TEXTURE_EXTERNAL_OES) | 321 if (target == GL_TEXTURE_EXTERNAL_OES) |
| 354 return false; | 322 return false; |
| 355 | 323 |
| 356 if (IsCompressedFormat(format_)) { | 324 if (IsCompressedFormat(format_)) { |
| 357 glCompressedTexImage2D( | 325 glCompressedTexImage2D( |
| 358 target, 0, TextureFormat(format_), size_.width(), size_.height(), 0, | 326 target, 0, GetTextureFormatFrom(format_), size_.width(), size_.height(), |
| 359 static_cast<GLsizei>(BufferSizeForBufferFormat(size_, format_)), | 327 0, static_cast<GLsizei>(BufferSizeForBufferFormat(size_, format_)), |
| 360 memory_); | 328 memory_); |
| 361 } else { | 329 } else { |
| 362 GLenum data_format = DataFormat(format_); | 330 GLenum data_format = DataFormat(format_); |
| 363 GLenum data_type = DataType(format_); | 331 GLenum data_type = DataType(format_); |
| 364 GLint data_row_length = DataRowLength(stride_, format_); | 332 GLint data_row_length = DataRowLength(stride_, format_); |
| 365 scoped_ptr<uint8_t[]> gles2_data; | 333 scoped_ptr<uint8_t[]> gles2_data; |
| 366 | 334 |
| 367 if (gfx::GLContext::GetCurrent()->GetVersionInfo()->is_es) { | 335 if (gfx::GLContext::GetCurrent()->GetVersionInfo()->is_es) { |
| 368 gles2_data = GLES2Data(size_, format_, stride_, memory_, &data_format, | 336 gles2_data = GLES2Data(size_, format_, stride_, memory_, &data_format, |
| 369 &data_type, &data_row_length); | 337 &data_type, &data_row_length); |
| 370 } | 338 } |
| 371 | 339 |
| 372 if (data_row_length != size_.width()) | 340 if (data_row_length != size_.width()) |
| 373 glPixelStorei(GL_UNPACK_ROW_LENGTH, data_row_length); | 341 glPixelStorei(GL_UNPACK_ROW_LENGTH, data_row_length); |
| 374 | 342 |
| 375 glTexImage2D(target, 0, TextureFormat(format_), size_.width(), | 343 glTexImage2D(target, 0, GetTextureFormatFrom(format_), size_.width(), |
| 376 size_.height(), 0, data_format, data_type, | 344 size_.height(), 0, data_format, data_type, |
| 377 gles2_data ? gles2_data.get() : memory_); | 345 gles2_data ? gles2_data.get() : memory_); |
| 378 | 346 |
| 379 if (data_row_length != size_.width()) | 347 if (data_row_length != size_.width()) |
| 380 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); | 348 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); |
| 381 } | 349 } |
| 382 | 350 |
| 383 return true; | 351 return true; |
| 384 } | 352 } |
| 385 | 353 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 402 } |
| 435 | 403 |
| 436 bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 404 bool GLImageMemory::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
| 437 int z_order, | 405 int z_order, |
| 438 gfx::OverlayTransform transform, | 406 gfx::OverlayTransform transform, |
| 439 const gfx::Rect& bounds_rect, | 407 const gfx::Rect& bounds_rect, |
| 440 const gfx::RectF& crop_rect) { | 408 const gfx::RectF& crop_rect) { |
| 441 return false; | 409 return false; |
| 442 } | 410 } |
| 443 | 411 |
| 444 // static | |
| 445 unsigned GLImageMemory::GetInternalFormatForTesting(BufferFormat format) { | |
| 446 DCHECK(ValidFormat(format)); | |
| 447 return TextureFormat(format); | |
| 448 } | |
| 449 | |
| 450 } // namespace gl | 412 } // namespace gl |
| OLD | NEW |