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..13897e944184bb8a88642e4ea1a60b3bfa6009b7 100644 |
--- a/gpu/ipc/common/gpu_memory_buffer_support.cc |
+++ b/gpu/ipc/common/gpu_memory_buffer_support.cc |
@@ -4,8 +4,11 @@ |
#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_switches.h" |
#if defined(USE_OZONE) |
#include "ui/ozone/public/client_native_pixmap_factory.h" |
@@ -13,6 +16,22 @@ |
namespace gpu { |
+bool AreNativeGpuMemoryBuffersEnabled() { |
+ // Disable native buffers when using Mesa. |
+ if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
+ switches::kUseGL) == gl::kGLImplementationOSMesaName) { |
+ return false; |
+ } |
+ |
+#if defined(OS_MACOSX) |
+ return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kDisableNativeGpuMemoryBuffers); |
piman
2016/12/07 19:41:44
These switches are not forwarded to child processe
sadrul
2016/12/07 23:02:56
I have made this change. '//gpu/ipc/host' target i
|
+#else |
+ return base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableNativeGpuMemoryBuffers); |
+#endif |
+} |
+ |
gfx::GpuMemoryBufferType GetNativeGpuMemoryBufferType() { |
#if defined(OS_MACOSX) |
return gfx::IO_SURFACE_BUFFER; |
@@ -58,4 +77,57 @@ bool IsNativeGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format, |
return false; |
} |
+GpuMemoryBufferConfigurationSet GetNativeGpuMemoryBufferConfigurations() { |
+ GpuMemoryBufferConfigurationSet configurations; |
+ |
+ 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::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)); |
+ } |
+ } |
+ } |
+ |
+#if defined(USE_OZONE) || defined(OS_MACOSX) |
+ // Disable native buffers only when using Mesa. |
+ bool force_native_gpu_read_write_formats = |
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
+ switches::kUseGL) != gl::kGLImplementationOSMesaName; |
+#else |
+ bool force_native_gpu_read_write_formats = false; |
+#endif |
+ 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}; |
+ 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)); |
+ } |
+ } |
+ } |
+ |
+ return configurations; |
+} |
+ |
} // namespace gpu |