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

Side by Side Diff: gpu/ipc/common/gpu_memory_buffer_support.cc

Issue 2648633005: cros: Support YUYV format for GPU memory buffer video frames
Patch Set: Created 3 years, 11 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/ipc/common/gpu_memory_buffer_support.h" 5 #include "gpu/ipc/common/gpu_memory_buffer_support.h"
6 6
7 #include "base/command_line.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "gpu/ipc/common/gpu_switches.h"
11 #include "ui/gl/gl_bindings.h"
12 #include "ui/gl/gl_switches.h"
9 13
10 #if defined(USE_OZONE) 14 #if defined(USE_OZONE)
11 #include "ui/ozone/public/client_native_pixmap_factory.h" 15 #include "ui/ozone/public/client_native_pixmap_factory.h"
12 #endif 16 #endif
13 17
14 namespace gpu { 18 namespace gpu {
15 19
20 bool AreNativeGpuMemoryBuffersEnabled() {
21 // Disable native buffers when using Mesa.
marcheu1 2017/01/21 00:25:18 this comment is misleading, this is osmesa not mes
dshwang 2017/01/23 23:13:42 Thx for noting. Done. This part is from existing g
22 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
23 switches::kUseGL) == gl::kGLImplementationOSMesaName) {
24 return false;
25 }
26
27 #if defined(OS_MACOSX)
28 return !base::CommandLine::ForCurrentProcess()->HasSwitch(
29 switches::kDisableNativeGpuMemoryBuffers);
30 #else
31 return base::CommandLine::ForCurrentProcess()->HasSwitch(
32 switches::kEnableNativeGpuMemoryBuffers);
33 #endif
34 }
35
16 gfx::GpuMemoryBufferType GetNativeGpuMemoryBufferType() { 36 gfx::GpuMemoryBufferType GetNativeGpuMemoryBufferType() {
17 #if defined(OS_MACOSX) 37 #if defined(OS_MACOSX)
18 return gfx::IO_SURFACE_BUFFER; 38 return gfx::IO_SURFACE_BUFFER;
19 #endif 39 #endif
20 #if defined(USE_OZONE) 40 #if defined(USE_OZONE)
21 return gfx::OZONE_NATIVE_PIXMAP; 41 return gfx::OZONE_NATIVE_PIXMAP;
22 #endif 42 #endif
23 return gfx::EMPTY_BUFFER; 43 return gfx::EMPTY_BUFFER;
24 } 44 }
25 45
26 bool IsNativeGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format, 46 bool IsNativeGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format,
27 gfx::BufferUsage usage) { 47 gfx::BufferUsage usage) {
48 bool never_cpu_read =
49 usage == gfx::BufferUsage::SCANOUT || usage == gfx::BufferUsage::GPU_READ;
marcheu1 2017/01/21 00:25:18 what does scanout have to do with cpu read? Don't
dshwang 2017/01/23 23:13:42 must use gfx::BufferUsage::GPU_READ_CPU_READ_WRITE
50 if (!(AreNativeGpuMemoryBuffersEnabled() || never_cpu_read))
51 return false;
52
28 DCHECK_NE(gfx::SHARED_MEMORY_BUFFER, GetNativeGpuMemoryBufferType()); 53 DCHECK_NE(gfx::SHARED_MEMORY_BUFFER, GetNativeGpuMemoryBufferType());
29 DCHECK_NE(gfx::EMPTY_BUFFER, GetNativeGpuMemoryBufferType()); 54 DCHECK_NE(gfx::EMPTY_BUFFER, GetNativeGpuMemoryBufferType());
30 #if defined(OS_MACOSX) 55 #if defined(OS_MACOSX)
31 switch (usage) { 56 switch (usage) {
32 case gfx::BufferUsage::GPU_READ: 57 case gfx::BufferUsage::GPU_READ:
33 case gfx::BufferUsage::SCANOUT: 58 case gfx::BufferUsage::SCANOUT:
34 return format == gfx::BufferFormat::BGRA_8888 || 59 return format == gfx::BufferFormat::BGRA_8888 ||
35 format == gfx::BufferFormat::RGBA_8888 || 60 format == gfx::BufferFormat::RGBA_8888 ||
36 format == gfx::BufferFormat::BGRX_8888; 61 format == gfx::BufferFormat::BGRX_8888;
37 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: 62 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE:
(...skipping 13 matching lines...) Expand all
51 return false; 76 return false;
52 } 77 }
53 return ui::ClientNativePixmapFactory::GetInstance()->IsConfigurationSupported( 78 return ui::ClientNativePixmapFactory::GetInstance()->IsConfigurationSupported(
54 format, usage); 79 format, usage);
55 #endif 80 #endif
56 81
57 NOTREACHED(); 82 NOTREACHED();
58 return false; 83 return false;
59 } 84 }
60 85
86 GpuMemoryBufferConfigurationSet GetNativeGpuMemoryBufferConfigurations() {
87 GpuMemoryBufferConfigurationSet configurations;
88
89 #if defined(USE_OZONE) || defined(OS_MACOSX)
90 if (AreNativeGpuMemoryBuffersEnabled()) {
91 const gfx::BufferFormat kNativeFormats[] = {
92 gfx::BufferFormat::R_8, gfx::BufferFormat::RG_88,
93 gfx::BufferFormat::BGR_565, gfx::BufferFormat::RGBA_4444,
94 gfx::BufferFormat::RGBA_8888, gfx::BufferFormat::BGRA_8888,
95 gfx::BufferFormat::UYVY_422, gfx::BufferFormat::YUYV_422,
96 gfx::BufferFormat::YVU_420, gfx::BufferFormat::YUV_420_BIPLANAR};
97 const gfx::BufferUsage kNativeUsages[] = {
98 gfx::BufferUsage::GPU_READ, gfx::BufferUsage::SCANOUT,
99 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
100 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT};
101 for (auto format : kNativeFormats) {
102 for (auto usage : kNativeUsages) {
103 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage))
104 configurations.insert(std::make_pair(format, usage));
105 }
106 }
107 }
108
109 // Disable native buffers only when using Mesa.
marcheu1 2017/01/21 00:25:18 again this is osmesa
dshwang 2017/01/23 23:13:42 Done.
110 bool force_native_gpu_read_write_formats =
111 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
112 switches::kUseGL) != gl::kGLImplementationOSMesaName;
113 if (force_native_gpu_read_write_formats) {
114 const gfx::BufferFormat kGPUReadWriteFormats[] = {
115 gfx::BufferFormat::BGR_565, gfx::BufferFormat::RGBA_8888,
116 gfx::BufferFormat::RGBX_8888, gfx::BufferFormat::BGRA_8888,
117 gfx::BufferFormat::BGRX_8888, gfx::BufferFormat::UYVY_422,
118 gfx::BufferFormat::YVU_420, gfx::BufferFormat::YUV_420_BIPLANAR};
marcheu1 2017/01/21 00:25:18 why are you hardcoding this table here?
dshwang 2017/01/23 23:13:42 I just merge existing gpu/ipc/host/gpu_memory_buff
119 const gfx::BufferUsage kGPUReadWriteUsages[] = {gfx::BufferUsage::GPU_READ,
120 gfx::BufferUsage::SCANOUT};
121 for (auto format : kGPUReadWriteFormats) {
122 for (auto usage : kGPUReadWriteUsages) {
123 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage))
124 configurations.insert(std::make_pair(format, usage));
125 }
126 }
127 }
128 #endif // defined(USE_OZONE) || defined(OS_MACOSX)
129
130 return configurations;
131 }
132
133 uint32_t GetImageTextureTarget(gfx::BufferFormat format,
134 gfx::BufferUsage usage) {
135 #if defined(USE_OZONE) || defined(OS_MACOSX)
136 GpuMemoryBufferConfigurationSet native_configurations =
137 GetNativeGpuMemoryBufferConfigurations();
138 if (native_configurations.find(std::make_pair(format, usage)) ==
139 native_configurations.end()) {
140 return GL_TEXTURE_2D;
141 }
142
143 switch (GetNativeGpuMemoryBufferType()) {
144 case gfx::OZONE_NATIVE_PIXMAP:
145 // GPU memory buffers that are shared with the GL using EGLImages
146 // require TEXTURE_EXTERNAL_OES.
147 return GL_TEXTURE_EXTERNAL_OES;
148 case gfx::IO_SURFACE_BUFFER:
149 // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB.
150 return GL_TEXTURE_RECTANGLE_ARB;
151 case gfx::SHARED_MEMORY_BUFFER:
152 case gfx::EMPTY_BUFFER:
153 break;
154 }
155 NOTREACHED();
156 return GL_TEXTURE_2D;
157 #else // defined(USE_OZONE) || defined(OS_MACOSX)
158 return GL_TEXTURE_2D;
159 #endif
160 }
161
61 } // namespace gpu 162 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698