Chromium Code Reviews| 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)) |
| 11 | 11 |
| 12 #define DRM_FORMAT_R8 FOURCC('R', '8', ' ', ' ') | 12 #define DRM_FORMAT_R8 FOURCC('R', '8', ' ', ' ') |
| 13 #define DRM_FORMAT_RGB565 FOURCC('R', 'G', '1', '6') | 13 #define DRM_FORMAT_RGB565 FOURCC('R', 'G', '1', '6') |
| 14 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') | 14 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') |
| 15 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4') | 15 #define DRM_FORMAT_ABGR8888 FOURCC('A', 'B', '2', '4') |
| 16 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') | 16 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') |
| 17 #define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4') | 17 #define DRM_FORMAT_XBGR8888 FOURCC('X', 'B', '2', '4') |
| 18 | 18 |
| 19 namespace gl { | 19 namespace gl { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 bool ValidInternalFormat(unsigned internalformat) { | 22 bool ValidInternalFormat(unsigned internalformat, gfx::BufferFormat format) { |
| 23 switch (internalformat) { | 23 switch (internalformat) { |
| 24 case GL_RGB: | 24 case GL_RGB: |
|
reveman
2016/06/03 23:33:01
maybe we should be even more restrictive here and
Daniele Castagna
2016/06/03 23:45:29
Made validation as restrictive as possible.
| |
| 25 case GL_RGBA: | 25 case GL_RGBA: |
| 26 case GL_BGRA_EXT: | 26 case GL_BGRA_EXT: |
| 27 switch (format) { | |
| 28 case gfx::BufferFormat::BGR_565: | |
| 29 case gfx::BufferFormat::RGBA_8888: | |
| 30 case gfx::BufferFormat::RGBX_8888: | |
| 31 case gfx::BufferFormat::BGRA_8888: | |
| 32 case gfx::BufferFormat::BGRX_8888: | |
| 33 return true; | |
| 34 default: | |
| 35 return false; | |
| 36 } | |
| 27 case GL_RED_EXT: | 37 case GL_RED_EXT: |
| 28 return true; | 38 return format == gfx::BufferFormat::R_8; |
| 29 default: | 39 default: |
| 30 return false; | 40 return false; |
| 31 } | 41 } |
| 32 } | 42 } |
| 33 | 43 |
| 34 bool ValidFormat(gfx::BufferFormat format) { | 44 bool ValidFormat(gfx::BufferFormat format) { |
| 35 switch (format) { | 45 switch (format) { |
| 36 case gfx::BufferFormat::R_8: | 46 case gfx::BufferFormat::R_8: |
| 37 case gfx::BufferFormat::BGR_565: | 47 case gfx::BufferFormat::BGR_565: |
| 38 case gfx::BufferFormat::RGBA_8888: | 48 case gfx::BufferFormat::RGBA_8888: |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap, | 109 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap, |
| 100 gfx::BufferFormat format) { | 110 gfx::BufferFormat format) { |
| 101 DCHECK(!pixmap_); | 111 DCHECK(!pixmap_); |
| 102 if (pixmap->GetEGLClientBuffer()) { | 112 if (pixmap->GetEGLClientBuffer()) { |
| 103 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; | 113 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
| 104 if (!GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, | 114 if (!GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, |
| 105 pixmap->GetEGLClientBuffer(), attrs)) { | 115 pixmap->GetEGLClientBuffer(), attrs)) { |
| 106 return false; | 116 return false; |
| 107 } | 117 } |
| 108 } else if (pixmap->AreDmaBufFdsValid()) { | 118 } else if (pixmap->AreDmaBufFdsValid()) { |
| 109 if (!ValidInternalFormat(internalformat_)) { | |
| 110 LOG(ERROR) << "Invalid internalformat: " << internalformat_; | |
| 111 return false; | |
| 112 } | |
| 113 | 119 |
| 114 if (!ValidFormat(format)) { | 120 if (!ValidFormat(format)) { |
| 115 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); | 121 LOG(ERROR) << "Invalid format: " << static_cast<int>(format); |
| 116 return false; | 122 return false; |
| 117 } | 123 } |
| 118 | 124 |
| 125 if (!ValidInternalFormat(internalformat_, format)) { | |
| 126 LOG(ERROR) << "Invalid internalformat: " << internalformat_ | |
| 127 << " for format: " << static_cast<int>(format); | |
| 128 return false; | |
| 129 } | |
| 130 | |
| 119 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT | 131 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT |
| 120 // target, the EGL will take a reference to the dma_buf. | 132 // target, the EGL will take a reference to the dma_buf. |
| 121 std::vector<EGLint> attrs; | 133 std::vector<EGLint> attrs; |
| 122 attrs.push_back(EGL_WIDTH); | 134 attrs.push_back(EGL_WIDTH); |
| 123 attrs.push_back(size_.width()); | 135 attrs.push_back(size_.width()); |
| 124 attrs.push_back(EGL_HEIGHT); | 136 attrs.push_back(EGL_HEIGHT); |
| 125 attrs.push_back(size_.height()); | 137 attrs.push_back(size_.height()); |
| 126 attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT); | 138 attrs.push_back(EGL_LINUX_DRM_FOURCC_EXT); |
| 127 attrs.push_back(FourCC(format)); | 139 attrs.push_back(FourCC(format)); |
| 128 | 140 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 crop_rect); | 193 crop_rect); |
| 182 } | 194 } |
| 183 | 195 |
| 184 void GLImageOzoneNativePixmap::OnMemoryDump( | 196 void GLImageOzoneNativePixmap::OnMemoryDump( |
| 185 base::trace_event::ProcessMemoryDump* pmd, | 197 base::trace_event::ProcessMemoryDump* pmd, |
| 186 uint64_t process_tracing_id, | 198 uint64_t process_tracing_id, |
| 187 const std::string& dump_name) { | 199 const std::string& dump_name) { |
| 188 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 | 200 // TODO(ericrk): Implement GLImage OnMemoryDump. crbug.com/514914 |
| 189 } | 201 } |
| 190 | 202 |
| 203 // static | |
| 204 unsigned GLImageOzoneNativePixmap::GetInternalFormatForTesting( | |
| 205 gfx::BufferFormat format) { | |
| 206 DCHECK(ValidFormat(format)); | |
| 207 switch (format) { | |
| 208 case gfx::BufferFormat::R_8: | |
| 209 return GL_RED_EXT; | |
| 210 case gfx::BufferFormat::BGR_565: | |
| 211 case gfx::BufferFormat::RGBA_8888: | |
| 212 case gfx::BufferFormat::RGBX_8888: | |
| 213 case gfx::BufferFormat::BGRA_8888: | |
| 214 case gfx::BufferFormat::BGRX_8888: | |
| 215 return GL_RGBA; | |
| 216 case gfx::BufferFormat::ATC: | |
| 217 case gfx::BufferFormat::ATCIA: | |
| 218 case gfx::BufferFormat::DXT1: | |
| 219 case gfx::BufferFormat::DXT5: | |
| 220 case gfx::BufferFormat::ETC1: | |
| 221 case gfx::BufferFormat::RGBA_4444: | |
| 222 case gfx::BufferFormat::YUV_420: | |
| 223 case gfx::BufferFormat::YUV_420_BIPLANAR: | |
| 224 case gfx::BufferFormat::UYVY_422: | |
| 225 NOTREACHED(); | |
| 226 return GL_NONE; | |
| 227 } | |
| 228 | |
| 229 NOTREACHED(); | |
| 230 return GL_NONE; | |
| 231 } | |
| 232 | |
| 191 } // namespace gl | 233 } // namespace gl |
| OLD | NEW |