OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/gl/gl_image_ozone_native_pixmap.h" |
| 6 |
| 7 #define FOURCC(a, b, c, d) \ |
| 8 ((static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \ |
| 9 (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24)) |
| 10 |
| 11 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') |
| 12 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4') |
| 13 |
| 14 namespace gfx { |
| 15 namespace { |
| 16 |
| 17 bool ValidInternalFormat(unsigned internalformat) { |
| 18 switch (internalformat) { |
| 19 case GL_RGB: |
| 20 case GL_BGRA_EXT: |
| 21 return true; |
| 22 default: |
| 23 return false; |
| 24 } |
| 25 } |
| 26 |
| 27 bool ValidFormat(gfx::GpuMemoryBuffer::Format format) { |
| 28 switch (format) { |
| 29 case GpuMemoryBuffer::BGRA_8888: |
| 30 case GpuMemoryBuffer::RGBX_8888: |
| 31 return true; |
| 32 case GpuMemoryBuffer::ATC: |
| 33 case GpuMemoryBuffer::ATCIA: |
| 34 case GpuMemoryBuffer::DXT1: |
| 35 case GpuMemoryBuffer::DXT5: |
| 36 case GpuMemoryBuffer::ETC1: |
| 37 case GpuMemoryBuffer::R_8: |
| 38 case GpuMemoryBuffer::RGBA_4444: |
| 39 case GpuMemoryBuffer::RGBA_8888: |
| 40 case GpuMemoryBuffer::YUV_420: |
| 41 return false; |
| 42 } |
| 43 |
| 44 NOTREACHED(); |
| 45 return false; |
| 46 } |
| 47 |
| 48 EGLint FourCC(gfx::GpuMemoryBuffer::Format format) { |
| 49 switch (format) { |
| 50 case GpuMemoryBuffer::BGRA_8888: |
| 51 return DRM_FORMAT_ARGB8888; |
| 52 case GpuMemoryBuffer::RGBX_8888: |
| 53 return DRM_FORMAT_XRGB8888; |
| 54 case GpuMemoryBuffer::ATC: |
| 55 case GpuMemoryBuffer::ATCIA: |
| 56 case GpuMemoryBuffer::DXT1: |
| 57 case GpuMemoryBuffer::DXT5: |
| 58 case GpuMemoryBuffer::ETC1: |
| 59 case GpuMemoryBuffer::R_8: |
| 60 case GpuMemoryBuffer::RGBA_4444: |
| 61 case GpuMemoryBuffer::RGBA_8888: |
| 62 case GpuMemoryBuffer::YUV_420: |
| 63 NOTREACHED(); |
| 64 return 0; |
| 65 } |
| 66 |
| 67 NOTREACHED(); |
| 68 return 0; |
| 69 } |
| 70 |
| 71 } // namespace |
| 72 |
| 73 GLImageOzoneNativePixmap::GLImageOzoneNativePixmap(const Size& size, |
| 74 unsigned internalformat) |
| 75 : GLImageEGL(size), internalformat_(internalformat) {} |
| 76 |
| 77 GLImageOzoneNativePixmap::~GLImageOzoneNativePixmap() { |
| 78 DCHECK(!pixmap_); |
| 79 } |
| 80 |
| 81 bool GLImageOzoneNativePixmap::Initialize(ui::NativePixmap* pixmap, |
| 82 GpuMemoryBuffer::Format format) { |
| 83 DCHECK(!pixmap_); |
| 84 |
| 85 bool result = true; |
| 86 if (pixmap->GetEGLClientBuffer()) { |
| 87 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; |
| 88 result = GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, |
| 89 pixmap->GetEGLClientBuffer(), attrs); |
| 90 } else if (pixmap->GetDmaBufFd() >= 0) { |
| 91 if (!ValidInternalFormat(internalformat_)) { |
| 92 LOG(ERROR) << "Invalid internalformat: " << internalformat_; |
| 93 return false; |
| 94 } |
| 95 |
| 96 if (!ValidFormat(format)) { |
| 97 LOG(ERROR) << "Invalid format: " << format; |
| 98 return false; |
| 99 } |
| 100 |
| 101 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT |
| 102 // target, the EGL will take a reference to the dma_buf. |
| 103 EGLint attrs[] = {EGL_WIDTH, |
| 104 size_.width(), |
| 105 EGL_HEIGHT, |
| 106 size_.height(), |
| 107 EGL_LINUX_DRM_FOURCC_EXT, |
| 108 FourCC(format), |
| 109 EGL_DMA_BUF_PLANE0_FD_EXT, |
| 110 pixmap->GetDmaBufFd(), |
| 111 EGL_DMA_BUF_PLANE0_OFFSET_EXT, |
| 112 0, |
| 113 EGL_DMA_BUF_PLANE0_PITCH_EXT, |
| 114 pixmap->GetDmaBufPitch(), |
| 115 EGL_NONE}; |
| 116 result = GLImageEGL::Initialize( |
| 117 EGL_LINUX_DMA_BUF_EXT, static_cast<EGLClientBuffer>(nullptr), attrs); |
| 118 } |
| 119 |
| 120 if (result) |
| 121 pixmap_ = pixmap; |
| 122 return result; |
| 123 } |
| 124 |
| 125 unsigned GLImageOzoneNativePixmap::GetInternalFormat() { |
| 126 return internalformat_; |
| 127 } |
| 128 |
| 129 void GLImageOzoneNativePixmap::Destroy(bool have_context) { |
| 130 GLImageEGL::Destroy(have_context); |
| 131 pixmap_ = nullptr; |
| 132 } |
| 133 |
| 134 bool GLImageOzoneNativePixmap::ScheduleOverlayPlane(AcceleratedWidget widget, |
| 135 int z_order, |
| 136 OverlayTransform transform, |
| 137 const Rect& bounds_rect, |
| 138 const RectF& crop_rect) { |
| 139 DCHECK(pixmap_); |
| 140 return pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect, |
| 141 crop_rect); |
| 142 } |
| 143 |
| 144 } // namespace gfx |
OLD | NEW |