Chromium Code Reviews| 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( | |
| 82 scoped_refptr<ui::NativePixmap> pixmap, | |
| 83 GpuMemoryBuffer::Format format) { | |
| 84 DCHECK(pixmap); | |
| 85 DCHECK(!pixmap_); | |
| 86 | |
| 87 bool result = false; | |
|
reveman
2015/07/29 14:16:41
Would this function be easier to read if you set t
dshwang
2015/07/29 15:15:04
current is more succinct, because otherwise we nee
| |
| 88 if (pixmap->GetEGLClientBuffer()) { | |
| 89 EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; | |
| 90 result = GLImageEGL::Initialize(EGL_NATIVE_PIXMAP_KHR, | |
| 91 pixmap->GetEGLClientBuffer(), attrs); | |
| 92 } else if (pixmap->GetDmaBufFd() >= 0) { | |
| 93 base::FileDescriptor handle(pixmap->GetDmaBufFd(), false); | |
|
reveman
2015/07/29 14:16:41
Is this temporary |handle| variable necessary?
dshwang
2015/07/29 15:15:04
no, removed.
| |
| 94 | |
| 95 if (!ValidInternalFormat(internalformat_)) { | |
| 96 LOG(ERROR) << "Invalid internalformat: " << internalformat_; | |
| 97 return false; | |
| 98 } | |
| 99 | |
| 100 if (!ValidFormat(format)) { | |
| 101 LOG(ERROR) << "Invalid format: " << format; | |
| 102 return false; | |
| 103 } | |
| 104 | |
| 105 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT | |
| 106 // target, the EGL will take a reference to the dma_buf. | |
| 107 EGLint attrs[] = {EGL_WIDTH, | |
| 108 size_.width(), | |
| 109 EGL_HEIGHT, | |
| 110 size_.height(), | |
| 111 EGL_LINUX_DRM_FOURCC_EXT, | |
| 112 FourCC(format), | |
| 113 EGL_DMA_BUF_PLANE0_FD_EXT, | |
| 114 handle.fd, | |
| 115 EGL_DMA_BUF_PLANE0_OFFSET_EXT, | |
| 116 0, | |
| 117 EGL_DMA_BUF_PLANE0_PITCH_EXT, | |
| 118 pixmap->GetDmaBufPitch(), | |
| 119 EGL_NONE}; | |
| 120 result = GLImageEGL::Initialize(EGL_LINUX_DMA_BUF_EXT, | |
| 121 static_cast<EGLClientBuffer>(NULL), attrs); | |
|
reveman
2015/07/29 14:16:41
Indent looks wierd here. Please clang format the p
dshwang
2015/07/29 15:15:04
Done.
| |
| 122 } | |
| 123 | |
| 124 if (result) | |
| 125 pixmap_ = pixmap; | |
| 126 return result; | |
| 127 } | |
| 128 | |
| 129 unsigned GLImageOzoneNativePixmap::GetInternalFormat() { | |
| 130 return internalformat_; | |
| 131 } | |
| 132 | |
| 133 void GLImageOzoneNativePixmap::Destroy(bool have_context) { | |
| 134 GLImageEGL::Destroy(have_context); | |
| 135 pixmap_ = nullptr; | |
| 136 } | |
| 137 | |
| 138 bool GLImageOzoneNativePixmap::ScheduleOverlayPlane(AcceleratedWidget widget, | |
| 139 int z_order, | |
| 140 OverlayTransform transform, | |
| 141 const Rect& bounds_rect, | |
| 142 const RectF& crop_rect) { | |
| 143 DCHECK(pixmap_); | |
| 144 return pixmap_->ScheduleOverlayPlane(widget, z_order, transform, bounds_rect, | |
| 145 crop_rect); | |
| 146 } | |
| 147 | |
| 148 } // namespace gfx | |
| OLD | NEW |