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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: gpu/ipc/common/gpu_memory_buffer_support.cc
diff --git a/gpu/ipc/common/gpu_memory_buffer_support.cc b/gpu/ipc/common/gpu_memory_buffer_support.cc
index 64412459f3b269c0587f8218267da4628fee6e85..fd1c6871394136f848f6bac5a59375575ca7ac1a 100644
--- a/gpu/ipc/common/gpu_memory_buffer_support.cc
+++ b/gpu/ipc/common/gpu_memory_buffer_support.cc
@@ -4,8 +4,12 @@
#include "gpu/ipc/common/gpu_memory_buffer_support.h"
+#include "base/command_line.h"
#include "base/logging.h"
#include "build/build_config.h"
+#include "gpu/ipc/common/gpu_switches.h"
+#include "ui/gl/gl_bindings.h"
+#include "ui/gl/gl_switches.h"
#if defined(USE_OZONE)
#include "ui/ozone/public/client_native_pixmap_factory.h"
@@ -13,6 +17,22 @@
namespace gpu {
+bool AreNativeGpuMemoryBuffersEnabled() {
+ // 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
+ if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kUseGL) == gl::kGLImplementationOSMesaName) {
+ return false;
+ }
+
+#if defined(OS_MACOSX)
+ return !base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableNativeGpuMemoryBuffers);
+#else
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableNativeGpuMemoryBuffers);
+#endif
+}
+
gfx::GpuMemoryBufferType GetNativeGpuMemoryBufferType() {
#if defined(OS_MACOSX)
return gfx::IO_SURFACE_BUFFER;
@@ -25,6 +45,11 @@ gfx::GpuMemoryBufferType GetNativeGpuMemoryBufferType() {
bool IsNativeGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format,
gfx::BufferUsage usage) {
+ bool never_cpu_read =
+ 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
+ if (!(AreNativeGpuMemoryBuffersEnabled() || never_cpu_read))
+ return false;
+
DCHECK_NE(gfx::SHARED_MEMORY_BUFFER, GetNativeGpuMemoryBufferType());
DCHECK_NE(gfx::EMPTY_BUFFER, GetNativeGpuMemoryBufferType());
#if defined(OS_MACOSX)
@@ -58,4 +83,80 @@ bool IsNativeGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format,
return false;
}
+GpuMemoryBufferConfigurationSet GetNativeGpuMemoryBufferConfigurations() {
+ GpuMemoryBufferConfigurationSet configurations;
+
+#if defined(USE_OZONE) || defined(OS_MACOSX)
+ if (AreNativeGpuMemoryBuffersEnabled()) {
+ const gfx::BufferFormat kNativeFormats[] = {
+ gfx::BufferFormat::R_8, gfx::BufferFormat::RG_88,
+ gfx::BufferFormat::BGR_565, gfx::BufferFormat::RGBA_4444,
+ gfx::BufferFormat::RGBA_8888, gfx::BufferFormat::BGRA_8888,
+ gfx::BufferFormat::UYVY_422, gfx::BufferFormat::YUYV_422,
+ gfx::BufferFormat::YVU_420, gfx::BufferFormat::YUV_420_BIPLANAR};
+ const gfx::BufferUsage kNativeUsages[] = {
+ gfx::BufferUsage::GPU_READ, gfx::BufferUsage::SCANOUT,
+ gfx::BufferUsage::GPU_READ_CPU_READ_WRITE,
+ gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT};
+ for (auto format : kNativeFormats) {
+ for (auto usage : kNativeUsages) {
+ if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage))
+ configurations.insert(std::make_pair(format, usage));
+ }
+ }
+ }
+
+ // 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.
+ bool force_native_gpu_read_write_formats =
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kUseGL) != gl::kGLImplementationOSMesaName;
+ if (force_native_gpu_read_write_formats) {
+ const gfx::BufferFormat kGPUReadWriteFormats[] = {
+ gfx::BufferFormat::BGR_565, gfx::BufferFormat::RGBA_8888,
+ gfx::BufferFormat::RGBX_8888, gfx::BufferFormat::BGRA_8888,
+ gfx::BufferFormat::BGRX_8888, gfx::BufferFormat::UYVY_422,
+ 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
+ const gfx::BufferUsage kGPUReadWriteUsages[] = {gfx::BufferUsage::GPU_READ,
+ gfx::BufferUsage::SCANOUT};
+ for (auto format : kGPUReadWriteFormats) {
+ for (auto usage : kGPUReadWriteUsages) {
+ if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage))
+ configurations.insert(std::make_pair(format, usage));
+ }
+ }
+ }
+#endif // defined(USE_OZONE) || defined(OS_MACOSX)
+
+ return configurations;
+}
+
+uint32_t GetImageTextureTarget(gfx::BufferFormat format,
+ gfx::BufferUsage usage) {
+#if defined(USE_OZONE) || defined(OS_MACOSX)
+ GpuMemoryBufferConfigurationSet native_configurations =
+ GetNativeGpuMemoryBufferConfigurations();
+ if (native_configurations.find(std::make_pair(format, usage)) ==
+ native_configurations.end()) {
+ return GL_TEXTURE_2D;
+ }
+
+ switch (GetNativeGpuMemoryBufferType()) {
+ case gfx::OZONE_NATIVE_PIXMAP:
+ // GPU memory buffers that are shared with the GL using EGLImages
+ // require TEXTURE_EXTERNAL_OES.
+ return GL_TEXTURE_EXTERNAL_OES;
+ case gfx::IO_SURFACE_BUFFER:
+ // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB.
+ return GL_TEXTURE_RECTANGLE_ARB;
+ case gfx::SHARED_MEMORY_BUFFER:
+ case gfx::EMPTY_BUFFER:
+ break;
+ }
+ NOTREACHED();
+ return GL_TEXTURE_2D;
+#else // defined(USE_OZONE) || defined(OS_MACOSX)
+ return GL_TEXTURE_2D;
+#endif
+}
+
} // namespace gpu

Powered by Google App Engine
This is Rietveld 408576698