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

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: support a more useful set of stride values Created 6 years, 8 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..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'
alexst (slow to review) 2014/05/29 19:37:22 period at the end of line.
+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);
fjhenigman 2014/06/27 18:19:31 would it make sense to pass in the stride as a par
reveman 2014/10/10 12:53:58 Done in latest patch.
+
+ // 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
« 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