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

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

Issue 1258713002: ozone: unify GpuMemoryBufferFactoryOzoneNativePixmap in content/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix linux_chromium_gn_dgb build Created 5 years, 4 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_ozone_native_pixmap.h » ('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 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 #define DRM_FORMAT_XRGB8888 FOURCC('X', 'R', '2', '4')
15
16 namespace gfx {
17 namespace {
18
19 bool ValidInternalFormat(unsigned internalformat) {
20 switch (internalformat) {
21 case GL_RGB:
22 case GL_BGRA_EXT:
23 return true;
24 default:
25 return false;
26 }
27 }
28
29 bool ValidFormat(gfx::GpuMemoryBuffer::Format format) {
30 switch (format) {
31 case GpuMemoryBuffer::BGRA_8888:
32 case GpuMemoryBuffer::RGBX_8888:
33 return true;
34 case GpuMemoryBuffer::ATC:
35 case GpuMemoryBuffer::ATCIA:
36 case GpuMemoryBuffer::DXT1:
37 case GpuMemoryBuffer::DXT5:
38 case GpuMemoryBuffer::ETC1:
39 case GpuMemoryBuffer::R_8:
40 case GpuMemoryBuffer::RGBA_4444:
41 case GpuMemoryBuffer::RGBA_8888:
42 case GpuMemoryBuffer::YUV_420:
43 return false;
44 }
45
46 NOTREACHED();
47 return false;
48 }
49
50 EGLint FourCC(gfx::GpuMemoryBuffer::Format format) {
51 switch (format) {
52 case GpuMemoryBuffer::BGRA_8888:
53 return DRM_FORMAT_ARGB8888;
54 case GpuMemoryBuffer::RGBX_8888:
55 return DRM_FORMAT_XRGB8888;
56 case GpuMemoryBuffer::ATC:
57 case GpuMemoryBuffer::ATCIA:
58 case GpuMemoryBuffer::DXT1:
59 case GpuMemoryBuffer::DXT5:
60 case GpuMemoryBuffer::ETC1:
61 case GpuMemoryBuffer::R_8:
62 case GpuMemoryBuffer::RGBA_4444:
63 case GpuMemoryBuffer::RGBA_8888:
64 case GpuMemoryBuffer::YUV_420:
65 NOTREACHED();
66 return 0;
67 }
68
69 NOTREACHED();
70 return 0;
71 }
72
73 bool IsHandleValid(const base::FileDescriptor& handle) {
74 return handle.fd >= 0;
75 }
76
77 } // namespace
78
79 GLImageLinuxDMABuffer::GLImageLinuxDMABuffer(const Size& size,
80 unsigned internalformat)
81 : GLImageEGL(size), internalformat_(internalformat) {
82 }
83
84 GLImageLinuxDMABuffer::~GLImageLinuxDMABuffer() {
85 }
86
87 bool GLImageLinuxDMABuffer::Initialize(const base::FileDescriptor& handle,
88 GpuMemoryBuffer::Format format,
89 int pitch) {
90 if (!ValidInternalFormat(internalformat_)) {
91 LOG(ERROR) << "Invalid internalformat: " << internalformat_;
92 return false;
93 }
94
95 if (!ValidFormat(format)) {
96 LOG(ERROR) << "Invalid format: " << format;
97 return false;
98 }
99
100 if (!IsHandleValid(handle)) {
101 LOG(ERROR) << "Invalid file descriptor: " << handle.fd;
102 return false;
103 }
104
105 // Note: If eglCreateImageKHR is successful for a EGL_LINUX_DMA_BUF_EXT
106 // target, the EGL will take a reference to the dma_buf.
107 EGLint attrs[] = {EGL_WIDTH,
108 size_.width(),
109 EGL_HEIGHT,
110 size_.height(),
111 EGL_LINUX_DRM_FOURCC_EXT,
112 FourCC(format),
113 EGL_DMA_BUF_PLANE0_FD_EXT,
114 handle.fd,
115 EGL_DMA_BUF_PLANE0_OFFSET_EXT,
116 0,
117 EGL_DMA_BUF_PLANE0_PITCH_EXT,
118 pitch,
119 EGL_NONE};
120 return GLImageEGL::Initialize(
121 EGL_LINUX_DMA_BUF_EXT, static_cast<EGLClientBuffer>(NULL), attrs);
122 }
123
124 unsigned GLImageLinuxDMABuffer::GetInternalFormat() { return internalformat_; }
125
126 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_image_linux_dma_buffer.h ('k') | ui/gl/gl_image_ozone_native_pixmap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698