OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "gpu/ipc/host/gpu_memory_buffer_support.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" |
| 9 #include "build/build_config.h" |
| 10 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
| 11 #include "gpu/ipc/host/gpu_switches.h" |
| 12 #include "ui/gl/gl_switches.h" |
| 13 |
| 14 namespace gpu { |
| 15 |
| 16 bool AreNativeGpuMemoryBuffersEnabled() { |
| 17 // Disable native buffers when using Mesa. |
| 18 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 19 switches::kUseGL) == gl::kGLImplementationOSMesaName) { |
| 20 return false; |
| 21 } |
| 22 |
| 23 #if defined(OS_MACOSX) |
| 24 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 25 switches::kDisableNativeGpuMemoryBuffers); |
| 26 #else |
| 27 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 28 switches::kEnableNativeGpuMemoryBuffers); |
| 29 #endif |
| 30 } |
| 31 |
| 32 GpuMemoryBufferConfigurationSet GetNativeGpuMemoryBufferConfigurations() { |
| 33 GpuMemoryBufferConfigurationSet configurations; |
| 34 |
| 35 if (AreNativeGpuMemoryBuffersEnabled()) { |
| 36 const gfx::BufferFormat kNativeFormats[] = { |
| 37 gfx::BufferFormat::R_8, |
| 38 gfx::BufferFormat::RG_88, |
| 39 gfx::BufferFormat::BGR_565, |
| 40 gfx::BufferFormat::RGBA_4444, |
| 41 gfx::BufferFormat::RGBA_8888, |
| 42 gfx::BufferFormat::BGRA_8888, |
| 43 gfx::BufferFormat::UYVY_422, |
| 44 gfx::BufferFormat::YVU_420, |
| 45 gfx::BufferFormat::YUV_420_BIPLANAR}; |
| 46 const gfx::BufferUsage kNativeUsages[] = { |
| 47 gfx::BufferUsage::GPU_READ, gfx::BufferUsage::SCANOUT, |
| 48 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
| 49 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT}; |
| 50 for (auto& format : kNativeFormats) { |
| 51 for (auto& usage : kNativeUsages) { |
| 52 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) |
| 53 configurations.insert(std::make_pair(format, usage)); |
| 54 } |
| 55 } |
| 56 } |
| 57 |
| 58 #if defined(USE_OZONE) || defined(OS_MACOSX) |
| 59 // Disable native buffers only when using Mesa. |
| 60 bool force_native_gpu_read_write_formats = |
| 61 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 62 switches::kUseGL) != gl::kGLImplementationOSMesaName; |
| 63 #else |
| 64 bool force_native_gpu_read_write_formats = false; |
| 65 #endif |
| 66 if (force_native_gpu_read_write_formats) { |
| 67 const gfx::BufferFormat kGPUReadWriteFormats[] = { |
| 68 gfx::BufferFormat::BGR_565, gfx::BufferFormat::RGBA_8888, |
| 69 gfx::BufferFormat::RGBX_8888, gfx::BufferFormat::BGRA_8888, |
| 70 gfx::BufferFormat::BGRX_8888, gfx::BufferFormat::UYVY_422, |
| 71 gfx::BufferFormat::YVU_420, gfx::BufferFormat::YUV_420_BIPLANAR}; |
| 72 const gfx::BufferUsage kGPUReadWriteUsages[] = {gfx::BufferUsage::GPU_READ, |
| 73 gfx::BufferUsage::SCANOUT}; |
| 74 for (auto& format : kGPUReadWriteFormats) { |
| 75 for (auto& usage : kGPUReadWriteUsages) { |
| 76 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) |
| 77 configurations.insert(std::make_pair(format, usage)); |
| 78 } |
| 79 } |
| 80 } |
| 81 |
| 82 return configurations; |
| 83 } |
| 84 |
| 85 } // namespace gpu |
OLD | NEW |