Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 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_linux_dma_buffer.h" | |
| 6 | |
| 7 #include <unistd.h> | |
| 8 | |
| 9 #define FOURCC(a, b, c, d) \ | |
| 10 ((static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \ | |
| 11 (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24)) | |
| 12 | |
| 13 #define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4') | |
| 14 | |
| 15 namespace gfx { | |
| 16 namespace { | |
| 17 | |
| 18 bool ValidFormat(unsigned internalformat) { | |
| 19 switch (internalformat) { | |
| 20 case GL_BGRA8_EXT: | |
| 21 return true; | |
| 22 default: | |
| 23 return false; | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 EGLint FourCC(unsigned internalformat) { | |
| 28 switch (internalformat) { | |
| 29 case GL_BGRA8_EXT: | |
| 30 return DRM_FORMAT_ARGB8888; | |
| 31 default: | |
| 32 NOTREACHED(); | |
| 33 return 0; | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 int BytesPerPixel(unsigned internalformat) { | |
| 38 switch (internalformat) { | |
| 39 case GL_BGRA8_EXT: | |
| 40 return 4; | |
| 41 default: | |
| 42 NOTREACHED(); | |
| 43 return 0; | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 } // namespace | |
| 48 | |
| 49 GLImageLinuxDMABuffer::GLImageLinuxDMABuffer(gfx::Size size, | |
| 50 unsigned internalformat) | |
| 51 : GLImageEGL(size), internalformat_(internalformat), fd_(-1) {} | |
| 52 | |
| 53 GLImageLinuxDMABuffer::~GLImageLinuxDMABuffer() { Destroy(); } | |
| 54 | |
| 55 bool GLImageLinuxDMABuffer::Initialize(gfx::GpuMemoryBufferHandle buffer) { | |
| 56 if (!ValidFormat(internalformat_)) { | |
| 57 LOG(ERROR) << "Invalid format: " << internalformat_; | |
| 58 return false; | |
| 59 } | |
| 60 | |
| 61 if (buffer.handle.fd < 0) { | |
| 62 LOG(ERROR) << "Invalid file descriptor: " << buffer.handle.fd; | |
| 63 return false; | |
| 64 } | |
| 65 | |
| 66 fd_ = dup(buffer.handle.fd); | |
| 67 if (fd_ < 0) { | |
| 68 LOG(ERROR) << "Failed to duplicate file descriptor."; | |
| 69 return false; | |
| 70 } | |
| 71 | |
| 72 EGLint attrs[] = {EGL_WIDTH, | |
| 73 size_.width(), | |
| 74 EGL_HEIGHT, | |
| 75 size_.height(), | |
| 76 EGL_LINUX_DRM_FOURCC_EXT, | |
| 77 FourCC(internalformat_), | |
| 78 EGL_DMA_BUF_PLANE0_FD_EXT, | |
| 79 fd_, | |
| 80 EGL_DMA_BUF_PLANE0_OFFSET_EXT, | |
| 81 0, | |
| 82 EGL_DMA_BUF_PLANE0_PITCH_EXT, | |
| 83 size_.width() * BytesPerPixel(internalformat_), | |
| 84 EGL_NONE}; | |
| 85 return GLImageEGL::Initialize( | |
| 86 EGL_LINUX_DMA_BUF_EXT, static_cast<EGLClientBuffer>(NULL), attrs); | |
| 87 } | |
| 88 | |
| 89 void GLImageLinuxDMABuffer::Destroy() { | |
| 90 GLImageEGL::Destroy(); | |
| 91 if (fd_ >= 0) | |
| 92 close(fd_); | |
|
fjhenigman
2014/03/27 23:35:49
The spec [1] and a mesa-dev thread [2] and the cur
reveman
2014/03/27 23:57:14
Ok, cool. Removed dup from latest patch.
| |
| 93 } | |
| 94 | |
| 95 } // namespace gfx | |
| OLD | NEW |