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_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. | |
| 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; | |
| 50 if (!(AreNativeGpuMemoryBuffersEnabled() || never_cpu_read)) | |
|
dshwang
2017/03/07 21:50:03
reveman@, besides video GMB support, I think this
| |
| 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 Loading... | |
| 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, | |
| 93 gfx::BufferFormat::RG_88, | |
| 94 gfx::BufferFormat::BGR_565, | |
| 95 gfx::BufferFormat::RGBA_4444, | |
| 96 gfx::BufferFormat::RGBA_8888, | |
| 97 gfx::BufferFormat::BGRA_8888, | |
| 98 gfx::BufferFormat::UYVY_422, | |
| 99 gfx::BufferFormat::YVU_420, | |
| 100 gfx::BufferFormat::YUV_420_BIPLANAR}; | |
| 101 const gfx::BufferUsage kNativeUsages[] = { | |
| 102 gfx::BufferUsage::GPU_READ, gfx::BufferUsage::SCANOUT, | |
| 103 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | |
| 104 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT}; | |
| 105 for (auto format : kNativeFormats) { | |
| 106 for (auto usage : kNativeUsages) { | |
| 107 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) | |
| 108 configurations.insert(std::make_pair(format, usage)); | |
| 109 } | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 // Disable native buffers only when using Mesa. | |
| 114 bool force_native_gpu_read_write_formats = | |
| 115 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 116 switches::kUseGL) != gl::kGLImplementationOSMesaName; | |
| 117 if (force_native_gpu_read_write_formats) { | |
| 118 const gfx::BufferFormat kGPUReadWriteFormats[] = { | |
| 119 gfx::BufferFormat::BGR_565, gfx::BufferFormat::RGBA_8888, | |
| 120 gfx::BufferFormat::RGBX_8888, gfx::BufferFormat::BGRA_8888, | |
| 121 gfx::BufferFormat::BGRX_8888, gfx::BufferFormat::UYVY_422, | |
| 122 gfx::BufferFormat::YVU_420, gfx::BufferFormat::YUV_420_BIPLANAR}; | |
| 123 const gfx::BufferUsage kGPUReadWriteUsages[] = {gfx::BufferUsage::GPU_READ, | |
| 124 gfx::BufferUsage::SCANOUT}; | |
| 125 for (auto format : kGPUReadWriteFormats) { | |
| 126 for (auto usage : kGPUReadWriteUsages) { | |
| 127 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) | |
| 128 configurations.insert(std::make_pair(format, usage)); | |
| 129 } | |
| 130 } | |
| 131 } | |
| 132 #endif // defined(USE_OZONE) || defined(OS_MACOSX) | |
| 133 | |
| 134 return configurations; | |
| 135 } | |
| 136 | |
| 137 uint32_t GetImageTextureTarget(gfx::BufferFormat format, | |
| 138 gfx::BufferUsage usage) { | |
| 139 #if defined(USE_OZONE) || defined(OS_MACOSX) | |
| 140 GpuMemoryBufferConfigurationSet native_configurations = | |
| 141 GetNativeGpuMemoryBufferConfigurations(); | |
| 142 if (native_configurations.find(std::make_pair(format, usage)) == | |
| 143 native_configurations.end()) { | |
| 144 return GL_TEXTURE_2D; | |
| 145 } | |
| 146 | |
| 147 switch (GetNativeGpuMemoryBufferType()) { | |
| 148 case gfx::OZONE_NATIVE_PIXMAP: | |
| 149 // GPU memory buffers that are shared with the GL using EGLImages | |
| 150 // require TEXTURE_EXTERNAL_OES. | |
| 151 return GL_TEXTURE_EXTERNAL_OES; | |
| 152 case gfx::IO_SURFACE_BUFFER: | |
| 153 // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB. | |
| 154 return GL_TEXTURE_RECTANGLE_ARB; | |
| 155 case gfx::SHARED_MEMORY_BUFFER: | |
| 156 case gfx::EMPTY_BUFFER: | |
| 157 break; | |
| 158 } | |
| 159 NOTREACHED(); | |
| 160 return GL_TEXTURE_2D; | |
| 161 #else // defined(USE_OZONE) || defined(OS_MACOSX) | |
| 162 return GL_TEXTURE_2D; | |
| 163 #endif | |
| 164 } | |
| 165 | |
| 61 } // namespace gpu | 166 } // namespace gpu |
| OLD | NEW |