| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_native_pixmap.h" | 5 #include "ui/gl/gl_image_native_pixmap.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ui/gfx/buffer_format_util.h" | 9 #include "ui/gfx/buffer_format_util.h" |
| 10 #include "ui/gl/gl_surface_egl.h" | 10 #include "ui/gl/gl_surface_egl.h" |
| 11 | 11 |
| 12 #define FOURCC(a, b, c, d) \ | 12 #define FOURCC(a, b, c, d) \ |
| 13 ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \ | 13 ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \ |
| 14 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24)) | 14 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24)) |
| 15 | 15 |
| 16 #define DRM_FORMAT_R8 FOURCC('R', '8', ' ', ' ') | 16 #define DRM_FORMAT_R8 FOURCC('R', '8', ' ', ' ') |
| 17 #define DRM_FORMAT_R16 FOURCC('R', '1', '6', ' ') |
| 17 #define DRM_FORMAT_GR88 FOURCC('G', 'R', '8', '8') | 18 #define DRM_FORMAT_GR88 FOURCC('G', 'R', '8', '8') |
| 18 #define DRM_FORMAT_RGB565 FOURCC('R', 'G', '1', '6') | 19 #define DRM_FORMAT_RGB565 FOURCC('R', 'G', '1', '6') |
| 19 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') | 20 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') |
| 20 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4') | 21 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4') |
| 21 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') | 22 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') |
| 22 #define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4') | 23 #define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4') |
| 23 #define DRM_FORMAT_YVU420 FOURCC('Y', 'V', '1', '2') | 24 #define DRM_FORMAT_YVU420 FOURCC('Y', 'V', '1', '2') |
| 24 #define DRM_FORMAT_NV12 FOURCC('N', 'V', '1', '2') | 25 #define DRM_FORMAT_NV12 FOURCC('N', 'V', '1', '2') |
| 25 | 26 |
| 26 namespace gl { | 27 namespace gl { |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 bool ValidInternalFormat(unsigned internalformat, gfx::BufferFormat format) { | 30 bool ValidInternalFormat(unsigned internalformat, gfx::BufferFormat format) { |
| 30 switch (internalformat) { | 31 switch (internalformat) { |
| 31 case GL_RGB: | 32 case GL_RGB: |
| 32 return format == gfx::BufferFormat::BGR_565 || | 33 return format == gfx::BufferFormat::BGR_565 || |
| 33 format == gfx::BufferFormat::RGBX_8888 || | 34 format == gfx::BufferFormat::RGBX_8888 || |
| 34 format == gfx::BufferFormat::BGRX_8888; | 35 format == gfx::BufferFormat::BGRX_8888; |
| 35 case GL_RGB_YCRCB_420_CHROMIUM: | 36 case GL_RGB_YCRCB_420_CHROMIUM: |
| 36 return format == gfx::BufferFormat::YVU_420; | 37 return format == gfx::BufferFormat::YVU_420; |
| 37 case GL_RGB_YCBCR_420V_CHROMIUM: | 38 case GL_RGB_YCBCR_420V_CHROMIUM: |
| 38 return format == gfx::BufferFormat::YUV_420_BIPLANAR; | 39 return format == gfx::BufferFormat::YUV_420_BIPLANAR; |
| 39 case GL_RGBA: | 40 case GL_RGBA: |
| 40 return format == gfx::BufferFormat::RGBA_8888; | 41 return format == gfx::BufferFormat::RGBA_8888; |
| 41 case GL_BGRA_EXT: | 42 case GL_BGRA_EXT: |
| 42 return format == gfx::BufferFormat::BGRA_8888; | 43 return format == gfx::BufferFormat::BGRA_8888; |
| 43 case GL_RED_EXT: | 44 case GL_RED_EXT: |
| 44 return format == gfx::BufferFormat::R_8; | 45 return format == gfx::BufferFormat::R_8; |
| 46 case GL_R16_EXT: |
| 47 return format == gfx::BufferFormat::R_16; |
| 45 case GL_RG_EXT: | 48 case GL_RG_EXT: |
| 46 return format == gfx::BufferFormat::RG_88; | 49 return format == gfx::BufferFormat::RG_88; |
| 47 default: | 50 default: |
| 48 return false; | 51 return false; |
| 49 } | 52 } |
| 50 } | 53 } |
| 51 | 54 |
| 52 bool ValidFormat(gfx::BufferFormat format) { | 55 bool ValidFormat(gfx::BufferFormat format) { |
| 53 switch (format) { | 56 switch (format) { |
| 54 case gfx::BufferFormat::R_8: | 57 case gfx::BufferFormat::R_8: |
| 58 case gfx::BufferFormat::R_16: |
| 55 case gfx::BufferFormat::RG_88: | 59 case gfx::BufferFormat::RG_88: |
| 56 case gfx::BufferFormat::BGR_565: | 60 case gfx::BufferFormat::BGR_565: |
| 57 case gfx::BufferFormat::RGBA_8888: | 61 case gfx::BufferFormat::RGBA_8888: |
| 58 case gfx::BufferFormat::RGBX_8888: | 62 case gfx::BufferFormat::RGBX_8888: |
| 59 case gfx::BufferFormat::BGRA_8888: | 63 case gfx::BufferFormat::BGRA_8888: |
| 60 case gfx::BufferFormat::BGRX_8888: | 64 case gfx::BufferFormat::BGRX_8888: |
| 61 case gfx::BufferFormat::YVU_420: | 65 case gfx::BufferFormat::YVU_420: |
| 62 case gfx::BufferFormat::YUV_420_BIPLANAR: | 66 case gfx::BufferFormat::YUV_420_BIPLANAR: |
| 63 return true; | 67 return true; |
| 64 case gfx::BufferFormat::ATC: | 68 case gfx::BufferFormat::ATC: |
| 65 case gfx::BufferFormat::ATCIA: | 69 case gfx::BufferFormat::ATCIA: |
| 66 case gfx::BufferFormat::DXT1: | 70 case gfx::BufferFormat::DXT1: |
| 67 case gfx::BufferFormat::DXT5: | 71 case gfx::BufferFormat::DXT5: |
| 68 case gfx::BufferFormat::ETC1: | 72 case gfx::BufferFormat::ETC1: |
| 69 case gfx::BufferFormat::RGBA_4444: | 73 case gfx::BufferFormat::RGBA_4444: |
| 70 case gfx::BufferFormat::RGBA_F16: | 74 case gfx::BufferFormat::RGBA_F16: |
| 71 case gfx::BufferFormat::UYVY_422: | 75 case gfx::BufferFormat::UYVY_422: |
| 72 return false; | 76 return false; |
| 73 } | 77 } |
| 74 | 78 |
| 75 NOTREACHED(); | 79 NOTREACHED(); |
| 76 return false; | 80 return false; |
| 77 } | 81 } |
| 78 | 82 |
| 79 EGLint FourCC(gfx::BufferFormat format) { | 83 EGLint FourCC(gfx::BufferFormat format) { |
| 80 switch (format) { | 84 switch (format) { |
| 81 case gfx::BufferFormat::R_8: | 85 case gfx::BufferFormat::R_8: |
| 82 return DRM_FORMAT_R8; | 86 return DRM_FORMAT_R8; |
| 87 case gfx::BufferFormat::R_16: |
| 88 return DRM_FORMAT_R16; |
| 83 case gfx::BufferFormat::RG_88: | 89 case gfx::BufferFormat::RG_88: |
| 84 return DRM_FORMAT_GR88; | 90 return DRM_FORMAT_GR88; |
| 85 case gfx::BufferFormat::BGR_565: | 91 case gfx::BufferFormat::BGR_565: |
| 86 return DRM_FORMAT_RGB565; | 92 return DRM_FORMAT_RGB565; |
| 87 case gfx::BufferFormat::RGBA_8888: | 93 case gfx::BufferFormat::RGBA_8888: |
| 88 return DRM_FORMAT_ABGR8888; | 94 return DRM_FORMAT_ABGR8888; |
| 89 case gfx::BufferFormat::RGBX_8888: | 95 case gfx::BufferFormat::RGBX_8888: |
| 90 return DRM_FORMAT_XBGR8888; | 96 return DRM_FORMAT_XBGR8888; |
| 91 case gfx::BufferFormat::BGRA_8888: | 97 case gfx::BufferFormat::BGRA_8888: |
| 92 return DRM_FORMAT_ARGB8888; | 98 return DRM_FORMAT_ARGB8888; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 | 249 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 |
| 244 } | 250 } |
| 245 | 251 |
| 246 // static | 252 // static |
| 247 unsigned GLImageNativePixmap::GetInternalFormatForTesting( | 253 unsigned GLImageNativePixmap::GetInternalFormatForTesting( |
| 248 gfx::BufferFormat format) { | 254 gfx::BufferFormat format) { |
| 249 DCHECK(ValidFormat(format)); | 255 DCHECK(ValidFormat(format)); |
| 250 switch (format) { | 256 switch (format) { |
| 251 case gfx::BufferFormat::R_8: | 257 case gfx::BufferFormat::R_8: |
| 252 return GL_RED_EXT; | 258 return GL_RED_EXT; |
| 259 case gfx::BufferFormat::R_16: |
| 260 return GL_R16_EXT; |
| 253 case gfx::BufferFormat::RG_88: | 261 case gfx::BufferFormat::RG_88: |
| 254 return GL_RG_EXT; | 262 return GL_RG_EXT; |
| 255 case gfx::BufferFormat::BGR_565: | 263 case gfx::BufferFormat::BGR_565: |
| 256 case gfx::BufferFormat::RGBX_8888: | 264 case gfx::BufferFormat::RGBX_8888: |
| 257 case gfx::BufferFormat::BGRX_8888: | 265 case gfx::BufferFormat::BGRX_8888: |
| 258 return GL_RGB; | 266 return GL_RGB; |
| 259 case gfx::BufferFormat::RGBA_8888: | 267 case gfx::BufferFormat::RGBA_8888: |
| 260 return GL_RGBA; | 268 return GL_RGBA; |
| 261 case gfx::BufferFormat::BGRA_8888: | 269 case gfx::BufferFormat::BGRA_8888: |
| 262 return GL_BGRA_EXT; | 270 return GL_BGRA_EXT; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 274 case gfx::BufferFormat::UYVY_422: | 282 case gfx::BufferFormat::UYVY_422: |
| 275 NOTREACHED(); | 283 NOTREACHED(); |
| 276 return GL_NONE; | 284 return GL_NONE; |
| 277 } | 285 } |
| 278 | 286 |
| 279 NOTREACHED(); | 287 NOTREACHED(); |
| 280 return GL_NONE; | 288 return GL_NONE; |
| 281 } | 289 } |
| 282 | 290 |
| 283 } // namespace gl | 291 } // namespace gl |
| OLD | NEW |