| 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_GR88 FOURCC('G', 'R', '8', '8') | 17 #define DRM_FORMAT_GR88 FOURCC('G', 'R', '8', '8') |
| 18 #define DRM_FORMAT_RGB565 FOURCC('R', 'G', '1', '6') | 18 #define DRM_FORMAT_RGB565 FOURCC('R', 'G', '1', '6') |
| 19 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') | 19 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') |
| 20 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4') | 20 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4') |
| 21 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') | 21 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') |
| 22 #define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4') | 22 #define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4') |
| 23 #define DRM_FORMAT_YVU420 FOURCC('Y', 'V', '1', '2') | 23 #define DRM_FORMAT_YVU420 FOURCC('Y', 'V', '1', '2') |
| 24 #define DRM_FORMAT_NV12 FOURCC('N', 'V', '1', '2') | 24 #define DRM_FORMAT_NV12 FOURCC('N', 'V', '1', '2') |
| 25 #define DRM_FORMAT_UYVY FOURCC('U', 'Y', 'V', 'Y') |
| 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; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 case gfx::BufferFormat::RGBA_F16: | 106 case gfx::BufferFormat::RGBA_F16: |
| 106 case gfx::BufferFormat::UYVY_422: | 107 case gfx::BufferFormat::UYVY_422: |
| 107 NOTREACHED(); | 108 NOTREACHED(); |
| 108 return 0; | 109 return 0; |
| 109 } | 110 } |
| 110 | 111 |
| 111 NOTREACHED(); | 112 NOTREACHED(); |
| 112 return 0; | 113 return 0; |
| 113 } | 114 } |
| 114 | 115 |
| 116 gfx::BufferFormat GetBufferFormatFromFourCCFormat(int format) { |
| 117 switch (format) { |
| 118 case DRM_FORMAT_R8: |
| 119 return gfx::BufferFormat::R_8; |
| 120 case DRM_FORMAT_GR88: |
| 121 return gfx::BufferFormat::RG_88; |
| 122 case DRM_FORMAT_ABGR8888: |
| 123 return gfx::BufferFormat::RGBA_8888; |
| 124 case DRM_FORMAT_XBGR8888: |
| 125 return gfx::BufferFormat::RGBX_8888; |
| 126 case DRM_FORMAT_ARGB8888: |
| 127 return gfx::BufferFormat::BGRA_8888; |
| 128 case DRM_FORMAT_XRGB8888: |
| 129 return gfx::BufferFormat::BGRX_8888; |
| 130 case DRM_FORMAT_RGB565: |
| 131 return gfx::BufferFormat::BGR_565; |
| 132 case DRM_FORMAT_UYVY: |
| 133 return gfx::BufferFormat::UYVY_422; |
| 134 case DRM_FORMAT_NV12: |
| 135 return gfx::BufferFormat::YUV_420_BIPLANAR; |
| 136 case DRM_FORMAT_YVU420: |
| 137 return gfx::BufferFormat::YVU_420; |
| 138 default: |
| 139 return gfx::BufferFormat::BGRA_8888; |
| 140 } |
| 141 } |
| 142 |
| 115 } // namespace | 143 } // namespace |
| 116 | 144 |
| 117 GLImageNativePixmap::GLImageNativePixmap(const gfx::Size& size, | 145 GLImageNativePixmap::GLImageNativePixmap(const gfx::Size& size, |
| 118 unsigned internalformat) | 146 unsigned internalformat) |
| 119 : GLImageEGL(size), | 147 : GLImageEGL(size), |
| 120 internalformat_(internalformat), | 148 internalformat_(internalformat), |
| 121 has_image_flush_external_( | 149 has_image_flush_external_( |
| 122 gl::GLSurfaceEGL::HasEGLExtension("EGL_EXT_image_flush_external")) {} | 150 gl::GLSurfaceEGL::HasEGLExtension("EGL_EXT_image_flush_external")) {} |
| 123 | 151 |
| 124 GLImageNativePixmap::~GLImageNativePixmap() {} | 152 GLImageNativePixmap::~GLImageNativePixmap() {} |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 static_cast<EGLClientBuffer>(nullptr), | 217 static_cast<EGLClientBuffer>(nullptr), |
| 190 &attrs[0])) { | 218 &attrs[0])) { |
| 191 return false; | 219 return false; |
| 192 } | 220 } |
| 193 } | 221 } |
| 194 | 222 |
| 195 pixmap_ = pixmap; | 223 pixmap_ = pixmap; |
| 196 return true; | 224 return true; |
| 197 } | 225 } |
| 198 | 226 |
| 227 gfx::GpuMemoryBufferAttribVector |
| 228 GLImageNativePixmap::QueryDmaBufFormatsAndModifiers() { |
| 229 bool has_dma_buf_import_modifier = gl::GLSurfaceEGL::HasEGLExtension( |
| 230 "EGL_EXT_image_dma_buf_import_modifiers"); |
| 231 std::vector<std::pair<EGLint, EGLuint64KHR>> drm_supported_gmb_attribs; |
| 232 gfx::GpuMemoryBufferAttribVector supported_gmb_attribs; |
| 233 |
| 234 if (!has_dma_buf_import_modifier) |
| 235 return supported_gmb_attribs; |
| 236 |
| 237 drm_supported_gmb_attribs = GLImageEGL::GetDmaBufFormatsWithModifiers(); |
| 238 |
| 239 for (auto& elem : drm_supported_gmb_attribs) |
| 240 supported_gmb_attribs.push_back(gfx::GpuMemoryBufferAttrib( |
| 241 GetBufferFormatFromFourCCFormat(elem.first), elem.second)); |
| 242 return supported_gmb_attribs; |
| 243 } |
| 244 |
| 199 unsigned GLImageNativePixmap::GetInternalFormat() { | 245 unsigned GLImageNativePixmap::GetInternalFormat() { |
| 200 return internalformat_; | 246 return internalformat_; |
| 201 } | 247 } |
| 202 | 248 |
| 203 bool GLImageNativePixmap::CopyTexImage(unsigned target) { | 249 bool GLImageNativePixmap::CopyTexImage(unsigned target) { |
| 204 if (egl_image_ == EGL_NO_IMAGE_KHR) { | 250 if (egl_image_ == EGL_NO_IMAGE_KHR) { |
| 205 // Pass-through image type fails to bind and copy; make sure we | 251 // Pass-through image type fails to bind and copy; make sure we |
| 206 // don't draw with uninitialized texture. | 252 // don't draw with uninitialized texture. |
| 207 std::vector<unsigned char> data(size_.width() * size_.height() * 4); | 253 std::vector<unsigned char> data(size_.width() * size_.height() * 4); |
| 208 glTexImage2D(target, 0, GL_RGBA, size_.width(), size_.height(), 0, GL_RGBA, | 254 glTexImage2D(target, 0, GL_RGBA, size_.width(), size_.height(), 0, GL_RGBA, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 case gfx::BufferFormat::UYVY_422: | 320 case gfx::BufferFormat::UYVY_422: |
| 275 NOTREACHED(); | 321 NOTREACHED(); |
| 276 return GL_NONE; | 322 return GL_NONE; |
| 277 } | 323 } |
| 278 | 324 |
| 279 NOTREACHED(); | 325 NOTREACHED(); |
| 280 return GL_NONE; | 326 return GL_NONE; |
| 281 } | 327 } |
| 282 | 328 |
| 283 } // namespace gl | 329 } // namespace gl |
| OLD | NEW |