| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/gfx/buffer_format_util.h" | 5 #include "ui/gfx/buffer_format_util.h" |
| 6 #include "ui/gl/gl_image_ozone_native_pixmap.h" | 6 #include "ui/gl/gl_image_ozone_native_pixmap.h" |
| 7 | 7 |
| 8 #define FOURCC(a, b, c, d) \ | 8 #define FOURCC(a, b, c, d) \ |
| 9 ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \ | 9 ((static_cast<uint32_t>(a)) | (static_cast<uint32_t>(b) << 8) | \ |
| 10 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24)) | 10 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24)) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 case gfx::BufferFormat::YUV_420_BIPLANAR: | 89 case gfx::BufferFormat::YUV_420_BIPLANAR: |
| 90 case gfx::BufferFormat::UYVY_422: | 90 case gfx::BufferFormat::UYVY_422: |
| 91 NOTREACHED(); | 91 NOTREACHED(); |
| 92 return 0; | 92 return 0; |
| 93 } | 93 } |
| 94 | 94 |
| 95 NOTREACHED(); | 95 NOTREACHED(); |
| 96 return 0; | 96 return 0; |
| 97 } | 97 } |
| 98 | 98 |
| 99 #if !defined(ARCH_CPU_X86_FAMILY) | |
| 100 bool IsFormatCrCb(gfx::BufferFormat format) { | |
| 101 switch (format) { | |
| 102 case gfx::BufferFormat::YVU_420: | |
| 103 return true; | |
| 104 case gfx::BufferFormat::R_8: | |
| 105 case gfx::BufferFormat::BGR_565: | |
| 106 case gfx::BufferFormat::RGBA_8888: | |
| 107 case gfx::BufferFormat::RGBX_8888: | |
| 108 case gfx::BufferFormat::BGRA_8888: | |
| 109 case gfx::BufferFormat::BGRX_8888: | |
| 110 case gfx::BufferFormat::ATC: | |
| 111 case gfx::BufferFormat::ATCIA: | |
| 112 case gfx::BufferFormat::DXT1: | |
| 113 case gfx::BufferFormat::DXT5: | |
| 114 case gfx::BufferFormat::ETC1: | |
| 115 case gfx::BufferFormat::RGBA_4444: | |
| 116 case gfx::BufferFormat::YUV_420_BIPLANAR: | |
| 117 case gfx::BufferFormat::UYVY_422: | |
| 118 return false; | |
| 119 } | |
| 120 NOTREACHED(); | |
| 121 return false; | |
| 122 } | |
| 123 #endif | |
| 124 | |
| 125 } // namespace | 99 } // namespace |
| 126 | 100 |
| 127 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const gfx::Size& size, | 101 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const gfx::Size& size, |
| 128 unsigned internalformat) | 102 unsigned internalformat) |
| 129 : GLImageEGL(size), internalformat_(internalformat) {} | 103 : GLImageEGL(size), internalformat_(internalformat) {} |
| 130 | 104 |
| 131 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() { | 105 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() { |
| 132 } | 106 } |
| 133 | 107 |
| 134 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap, | 108 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 156 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT | 130 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT |
| 157 // target, the EGL will take a reference to the dma_buf. | 131 // target, the EGL will take a reference to the dma_buf. |
| 158 std::vector<EGLint> attrs; | 132 std::vector<EGLint> attrs; |
| 159 attrs.push_back(EGL_WIDTH); | 133 attrs.push_back(EGL_WIDTH); |
| 160 attrs.push_back(size_.width()); | 134 attrs.push_back(size_.width()); |
| 161 attrs.push_back(EGL_HEIGHT); | 135 attrs.push_back(EGL_HEIGHT); |
| 162 attrs.push_back(size_.height()); | 136 attrs.push_back(size_.height()); |
| 163 attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT); | 137 attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT); |
| 164 attrs.push_back(FourCC(format)); | 138 attrs.push_back(FourCC(format)); |
| 165 | 139 |
| 166 for (size_t attrs_plane = 0; | 140 for (size_t plane = 0; |
| 167 attrs_plane < | 141 plane < gfx::NumberOfPlanesForBufferFormat(pixmap->GetBufferFormat()); |
| 168 gfx::NumberOfPlanesForBufferFormat(pixmap->GetBufferFormat()); | 142 ++plane) { |
| 169 ++attrs_plane) { | 143 attrs.push_back(EGL_DMA_BUF_PLANE0_FD_EXT + plane * 3); |
| 170 size_t pixmap_plane = attrs_plane; | 144 attrs.push_back( |
| 171 | 145 pixmap->GetDmaBufFd(plane < pixmap->GetDmaBufFdCount() ? plane : 0)); |
| 172 // TODO(dcastagna): Intel mesa flips V and U when the fourcc format is a | 146 attrs.push_back(EGL_DMA_BUF_PLANE0_OFFSET_EXT + plane * 3); |
| 173 // CrCb format therefore we don't need to. | 147 attrs.push_back(pixmap->GetDmaBufOffset(plane)); |
| 174 // Once crbug.com/646137 is addressed this ifdef (but not its content) can be | 148 attrs.push_back(EGL_DMA_BUF_PLANE0_PITCH_EXT + plane * 3); |
| 175 // removed. | 149 attrs.push_back(pixmap->GetDmaBufPitch(plane)); |
| 176 #if !defined(ARCH_CPU_X86_FAMILY) | |
| 177 // EGL_EXT_image_dma_buf_import always expects U and V as plane 1 and 2 in | |
| 178 // case of a YUV/YVU format. We swap U and V plane indexes for CrCb | |
| 179 // multi-planar formats. | |
| 180 if (IsFormatCrCb(format) && | |
| 181 gfx::NumberOfPlanesForBufferFormat(pixmap->GetBufferFormat()) == 3 && | |
| 182 attrs_plane) { | |
| 183 pixmap_plane = 3 - attrs_plane; | |
| 184 } | |
| 185 #endif | |
| 186 attrs.push_back(pixmap->GetDmaBufFd( | |
| 187 pixmap_plane < pixmap->GetDmaBufFdCount() ? pixmap_plane : 0)); | |
| 188 attrs.push_back(EGL_DMA_BUF_PLANE0_OFFSET_EXT + attrs_plane * 3); | |
| 189 attrs.push_back(pixmap->GetDmaBufOffset(pixmap_plane)); | |
| 190 attrs.push_back(EGL_DMA_BUF_PLANE0_PITCH_EXT + attrs_plane * 3); | |
| 191 attrs.push_back(pixmap->GetDmaBufPitch(pixmap_plane)); | |
| 192 } | 150 } |
| 193 attrs.push_back(EGL_NONE); | 151 attrs.push_back(EGL_NONE); |
| 194 | 152 |
| 195 if (!GLImageEGL::Initialize(EGL_LINUX_DMA_BUF_EXT, | 153 if (!GLImageEGL::Initialize(EGL_LINUX_DMA_BUF_EXT, |
| 196 static_cast<EGLClientBuffer>(nullptr), | 154 static_cast<EGLClientBuffer>(nullptr), |
| 197 &attrs[0])) { | 155 &attrs[0])) { |
| 198 return false; | 156 return false; |
| 199 } | 157 } |
| 200 } | 158 } |
| 201 | 159 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 case gfx::BufferFormat::UYVY_422: | 226 case gfx::BufferFormat::UYVY_422: |
| 269 NOTREACHED(); | 227 NOTREACHED(); |
| 270 return GL_NONE; | 228 return GL_NONE; |
| 271 } | 229 } |
| 272 | 230 |
| 273 NOTREACHED(); | 231 NOTREACHED(); |
| 274 return GL_NONE; | 232 return GL_NONE; |
| 275 } | 233 } |
| 276 | 234 |
| 277 } // namespace gl | 235 } // namespace gl |
| OLD | NEW |