| Index: ui/gl/gl_image_linux_dma_buffer.cc
|
| diff --git a/ui/gl/gl_image_linux_dma_buffer.cc b/ui/gl/gl_image_linux_dma_buffer.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8767ca65ad036edb3a8fb2f8319599a7be701ceb
|
| --- /dev/null
|
| +++ b/ui/gl/gl_image_linux_dma_buffer.cc
|
| @@ -0,0 +1,91 @@
|
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ui/gl/gl_image_linux_dma_buffer.h"
|
| +
|
| +#include <unistd.h>
|
| +
|
| +#define FOURCC(a, b, c, d) \
|
| + ((static_cast<uint32>(a)) | (static_cast<uint32>(b) << 8) | \
|
| + (static_cast<uint32>(c) << 16) | (static_cast<uint32>(d) << 24))
|
| +
|
| +#define DRM_FORMAT_ARGB8888 FOURCC('A', 'R', '2', '4')
|
| +
|
| +namespace gfx {
|
| +namespace {
|
| +
|
| +bool ValidFormat(unsigned internalformat) {
|
| + switch (internalformat) {
|
| + case GL_BGRA8_EXT:
|
| + return true;
|
| + default:
|
| + return false;
|
| + }
|
| +}
|
| +
|
| +EGLint FourCC(unsigned internalformat) {
|
| + switch (internalformat) {
|
| + case GL_BGRA8_EXT:
|
| + return DRM_FORMAT_ARGB8888;
|
| + default:
|
| + NOTREACHED();
|
| + return 0;
|
| + }
|
| +}
|
| +
|
| +int BytesPerPixel(unsigned internalformat) {
|
| + switch (internalformat) {
|
| + case GL_BGRA8_EXT:
|
| + return 4;
|
| + default:
|
| + NOTREACHED();
|
| + return 0;
|
| + }
|
| +}
|
| +
|
| +bool IsHandleValid(const base::FileDescriptor& handle) {
|
| + return handle.fd >= 0;
|
| +}
|
| +
|
| +// Aligns 'value' by rounding it up to the next multiple of 'alignment'
|
| +int AlignValue(int value, int alignment) {
|
| + return value + (alignment - (value % alignment)) % alignment;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +GLImageLinuxDMABuffer::GLImageLinuxDMABuffer(gfx::Size size,
|
| + unsigned internalformat)
|
| + : GLImageEGL(size), internalformat_(internalformat) {}
|
| +
|
| +GLImageLinuxDMABuffer::~GLImageLinuxDMABuffer() { Destroy(); }
|
| +
|
| +bool GLImageLinuxDMABuffer::Initialize(gfx::GpuMemoryBufferHandle buffer) {
|
| + if (!ValidFormat(internalformat_)) {
|
| + LOG(ERROR) << "Invalid format: " << internalformat_;
|
| + return false;
|
| + }
|
| +
|
| + if (!IsHandleValid(buffer.handle)) {
|
| + LOG(ERROR) << "Invalid file descriptor: " << buffer.handle.fd;
|
| + return false;
|
| + }
|
| +
|
| + // Align stride to a multiple of 64.
|
| + int stride = AlignValue(size_.width() * BytesPerPixel(internalformat_), 64);
|
| +
|
| + // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT
|
| + // target, the EGL will take a reference to the dma_buf.
|
| + EGLint attrs[] = {EGL_WIDTH, size_.width(),
|
| + EGL_HEIGHT, size_.height(),
|
| + EGL_LINUX_DRM_FOURCC_EXT, FourCC(internalformat_),
|
| + EGL_DMA_BUF_PLANE0_FD_EXT, buffer.handle.fd,
|
| + EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
|
| + EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
|
| + EGL_NONE};
|
| + return GLImageEGL::Initialize(
|
| + EGL_LINUX_DMA_BUF_EXT, static_cast<EGLClientBuffer>(NULL), attrs);
|
| +}
|
| +
|
| +} // namespace gfx
|
|
|