Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_switches.h" | |
| 9 | 12 |
| 10 #if defined(USE_OZONE) | 13 #if defined(USE_OZONE) |
| 11 #include "ui/ozone/public/client_native_pixmap_factory.h" | 14 #include "ui/ozone/public/client_native_pixmap_factory.h" |
| 12 #endif | 15 #endif |
| 13 | 16 |
| 14 namespace gpu { | 17 namespace gpu { |
| 15 | 18 |
| 19 bool AreNativeGpuMemoryBuffersEnabled() { | |
| 20 // Disable native buffers when using Mesa. | |
| 21 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 22 switches::kUseGL) == gl::kGLImplementationOSMesaName) { | |
| 23 return false; | |
| 24 } | |
| 25 | |
| 26 #if defined(OS_MACOSX) | |
| 27 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 28 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
| |
| 29 #else | |
| 30 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 31 switches::kEnableNativeGpuMemoryBuffers); | |
| 32 #endif | |
| 33 } | |
| 34 | |
| 16 gfx::GpuMemoryBufferType GetNativeGpuMemoryBufferType() { | 35 gfx::GpuMemoryBufferType GetNativeGpuMemoryBufferType() { |
| 17 #if defined(OS_MACOSX) | 36 #if defined(OS_MACOSX) |
| 18 return gfx::IO_SURFACE_BUFFER; | 37 return gfx::IO_SURFACE_BUFFER; |
| 19 #endif | 38 #endif |
| 20 #if defined(USE_OZONE) | 39 #if defined(USE_OZONE) |
| 21 return gfx::OZONE_NATIVE_PIXMAP; | 40 return gfx::OZONE_NATIVE_PIXMAP; |
| 22 #endif | 41 #endif |
| 23 return gfx::EMPTY_BUFFER; | 42 return gfx::EMPTY_BUFFER; |
| 24 } | 43 } |
| 25 | 44 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 51 return false; | 70 return false; |
| 52 } | 71 } |
| 53 return ui::ClientNativePixmapFactory::GetInstance()->IsConfigurationSupported( | 72 return ui::ClientNativePixmapFactory::GetInstance()->IsConfigurationSupported( |
| 54 format, usage); | 73 format, usage); |
| 55 #endif | 74 #endif |
| 56 | 75 |
| 57 NOTREACHED(); | 76 NOTREACHED(); |
| 58 return false; | 77 return false; |
| 59 } | 78 } |
| 60 | 79 |
| 80 GpuMemoryBufferConfigurationSet GetNativeGpuMemoryBufferConfigurations() { | |
| 81 GpuMemoryBufferConfigurationSet configurations; | |
| 82 | |
| 83 if (AreNativeGpuMemoryBuffersEnabled()) { | |
| 84 const gfx::BufferFormat kNativeFormats[] = { | |
| 85 gfx::BufferFormat::R_8, | |
| 86 gfx::BufferFormat::RG_88, | |
| 87 gfx::BufferFormat::BGR_565, | |
| 88 gfx::BufferFormat::RGBA_4444, | |
| 89 gfx::BufferFormat::RGBA_8888, | |
| 90 gfx::BufferFormat::BGRA_8888, | |
| 91 gfx::BufferFormat::UYVY_422, | |
| 92 gfx::BufferFormat::YVU_420, | |
| 93 gfx::BufferFormat::YUV_420_BIPLANAR}; | |
| 94 const gfx::BufferUsage kNativeUsages[] = { | |
| 95 gfx::BufferUsage::GPU_READ, gfx::BufferUsage::SCANOUT, | |
| 96 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | |
| 97 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT}; | |
| 98 for (auto& format : kNativeFormats) { | |
| 99 for (auto& usage : kNativeUsages) { | |
| 100 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) | |
| 101 configurations.insert(std::make_pair(format, usage)); | |
| 102 } | |
| 103 } | |
| 104 } | |
| 105 | |
| 106 #if defined(USE_OZONE) || defined(OS_MACOSX) | |
| 107 // Disable native buffers only when using Mesa. | |
| 108 bool force_native_gpu_read_write_formats = | |
| 109 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 110 switches::kUseGL) != gl::kGLImplementationOSMesaName; | |
| 111 #else | |
| 112 bool force_native_gpu_read_write_formats = false; | |
| 113 #endif | |
| 114 if (force_native_gpu_read_write_formats) { | |
| 115 const gfx::BufferFormat kGPUReadWriteFormats[] = { | |
| 116 gfx::BufferFormat::BGR_565, gfx::BufferFormat::RGBA_8888, | |
| 117 gfx::BufferFormat::RGBX_8888, gfx::BufferFormat::BGRA_8888, | |
| 118 gfx::BufferFormat::BGRX_8888, gfx::BufferFormat::UYVY_422, | |
| 119 gfx::BufferFormat::YVU_420, gfx::BufferFormat::YUV_420_BIPLANAR}; | |
| 120 const gfx::BufferUsage kGPUReadWriteUsages[] = {gfx::BufferUsage::GPU_READ, | |
| 121 gfx::BufferUsage::SCANOUT}; | |
| 122 for (auto& format : kGPUReadWriteFormats) { | |
| 123 for (auto& usage : kGPUReadWriteUsages) { | |
| 124 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) | |
| 125 configurations.insert(std::make_pair(format, usage)); | |
| 126 } | |
| 127 } | |
| 128 } | |
| 129 | |
| 130 return configurations; | |
| 131 } | |
| 132 | |
| 61 } // namespace gpu | 133 } // namespace gpu |
| OLD | NEW |