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

Side by Side Diff: ui/gl/gl_image_linux_dma_buffer.cc

Issue 211133005: [WIP] Not for review. Zero copy. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 6 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 unified diff | Download patch
« no previous file with comments | « ui/gl/gl_image_linux_dma_buffer.h ('k') | ui/gl/gl_image_x11.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 bool IsHandleValid(const base::FileDescriptor& handle) {
48 return handle.fd >= 0;
49 }
50
51 // Aligns 'value' by rounding it up to the next multiple of 'alignment'
52 int AlignValue(int value, int alignment) {
53 return value + (alignment - (value % alignment)) % alignment;
54 }
55
56 } // namespace
57
58 GLImageLinuxDMABuffer::GLImageLinuxDMABuffer(gfx::Size size,
59 unsigned internalformat)
60 : GLImageEGL(size), internalformat_(internalformat) {}
61
62 GLImageLinuxDMABuffer::~GLImageLinuxDMABuffer() { Destroy(); }
63
64 bool GLImageLinuxDMABuffer::Initialize(gfx::GpuMemoryBufferHandle buffer) {
65 if (!ValidFormat(internalformat_)) {
66 LOG(ERROR) << "Invalid format: " << internalformat_;
67 return false;
68 }
69
70 if (!IsHandleValid(buffer.handle)) {
71 LOG(ERROR) << "Invalid file descriptor: " << buffer.handle.fd;
72 return false;
73 }
74
75 // Align stride to a multiple of 64.
76 int stride = AlignValue(size_.width() * BytesPerPixel(internalformat_), 64);
77
78 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT
79 // target, the EGL will take a reference to the dma_buf.
80 EGLint attrs[] = {EGL_WIDTH, size_.width(),
81 EGL_HEIGHT, size_.height(),
82 EGL_LINUX_DRM_FOURCC_EXT, FourCC(internalformat_),
83 EGL_DMA_BUF_PLANE0_FD_EXT, buffer.handle.fd,
84 EGL_DMA_BUF_PLANE0_OFFSET_EXT, 0,
85 EGL_DMA_BUF_PLANE0_PITCH_EXT, stride,
86 EGL_NONE};
87 return GLImageEGL::Initialize(
88 EGL_LINUX_DMA_BUF_EXT, static_cast<EGLClientBuffer>(NULL), attrs);
89 }
90
91 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_image_linux_dma_buffer.h ('k') | ui/gl/gl_image_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698