Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Unified Diff: ui/gl/gl_image_linux_dma_buffer.cc

Issue 215143002: ui: Add Linux dma-buf implementation of GLImage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gl/gl_image_linux_dma_buffer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..581edbe8c63546bdb386577b45d36cd619a5b857
--- /dev/null
+++ b/ui/gl/gl_image_linux_dma_buffer.cc
@@ -0,0 +1,95 @@
+// 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;
+ }
+}
+
+} // namespace
+
+GLImageLinuxDMABuffer::GLImageLinuxDMABuffer(gfx::Size size,
+ unsigned internalformat)
+ : GLImageEGL(size), internalformat_(internalformat), fd_(-1) {}
+
+GLImageLinuxDMABuffer::~GLImageLinuxDMABuffer() { Destroy(); }
+
+bool GLImageLinuxDMABuffer::Initialize(gfx::GpuMemoryBufferHandle buffer) {
+ if (!ValidFormat(internalformat_)) {
+ LOG(ERROR) << "Invalid format: " << internalformat_;
+ return false;
+ }
+
+ if (buffer.handle.fd < 0) {
+ LOG(ERROR) << "Invalid file descriptor: " << buffer.handle.fd;
+ return false;
+ }
+
+ fd_ = dup(buffer.handle.fd);
+ if (fd_ < 0) {
+ LOG(ERROR) << "Failed to duplicate file descriptor.";
+ return false;
+ }
+
+ EGLint attrs[] = {EGL_WIDTH,
+ size_.width(),
+ EGL_HEIGHT,
+ size_.height(),
+ EGL_LINUX_DRM_FOURCC_EXT,
+ FourCC(internalformat_),
+ EGL_DMA_BUF_PLANE0_FD_EXT,
+ fd_,
+ EGL_DMA_BUF_PLANE0_OFFSET_EXT,
+ 0,
+ EGL_DMA_BUF_PLANE0_PITCH_EXT,
+ size_.width() * BytesPerPixel(internalformat_),
+ EGL_NONE};
+ return GLImageEGL::Initialize(
+ EGL_LINUX_DMA_BUF_EXT, static_cast<EGLClientBuffer>(NULL), attrs);
+}
+
+void GLImageLinuxDMABuffer::Destroy() {
+ GLImageEGL::Destroy();
+ if (fd_ >= 0)
+ 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.
+}
+
+} // namespace gfx
« no previous file with comments | « ui/gl/gl_image_linux_dma_buffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698