| 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_implementation.h" |
| 13 #include "ui/gl/gl_switches.h" |
| 9 | 14 |
| 10 #if defined(USE_OZONE) | 15 #if defined(USE_OZONE) |
| 11 #include "ui/ozone/public/client_native_pixmap_factory_ozone.h" | 16 #include "ui/ozone/public/client_native_pixmap_factory_ozone.h" |
| 12 #endif | 17 #endif |
| 13 | 18 |
| 14 namespace gpu { | 19 namespace gpu { |
| 15 | 20 |
| 21 bool AreNativeGpuMemoryBuffersEnabled() { |
| 22 // Disable native buffers when using software GL. |
| 23 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 24 switches::kUseGL) == |
| 25 gl::GetGLImplementationName(gl::GetSoftwareGLImplementation())) { |
| 26 return false; |
| 27 } |
| 28 |
| 29 #if defined(OS_MACOSX) |
| 30 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 31 switches::kDisableNativeGpuMemoryBuffers); |
| 32 #else |
| 33 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 34 switches::kEnableNativeGpuMemoryBuffers); |
| 35 #endif |
| 36 } |
| 37 |
| 16 gfx::GpuMemoryBufferType GetNativeGpuMemoryBufferType() { | 38 gfx::GpuMemoryBufferType GetNativeGpuMemoryBufferType() { |
| 17 #if defined(OS_MACOSX) | 39 #if defined(OS_MACOSX) |
| 18 return gfx::IO_SURFACE_BUFFER; | 40 return gfx::IO_SURFACE_BUFFER; |
| 19 #endif | 41 #endif |
| 20 #if defined(USE_OZONE) | 42 #if defined(USE_OZONE) |
| 21 return gfx::NATIVE_PIXMAP; | 43 return gfx::NATIVE_PIXMAP; |
| 22 #endif | 44 #endif |
| 23 return gfx::EMPTY_BUFFER; | 45 return gfx::EMPTY_BUFFER; |
| 24 } | 46 } |
| 25 | 47 |
| 26 bool IsNativeGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format, | 48 bool IsNativeGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format, |
| 27 gfx::BufferUsage usage) { | 49 gfx::BufferUsage usage) { |
| 50 bool never_cpu_read = |
| 51 usage == gfx::BufferUsage::SCANOUT || usage == gfx::BufferUsage::GPU_READ; |
| 52 if (!(AreNativeGpuMemoryBuffersEnabled() || never_cpu_read)) |
| 53 return false; |
| 54 |
| 28 DCHECK_NE(gfx::SHARED_MEMORY_BUFFER, GetNativeGpuMemoryBufferType()); | 55 DCHECK_NE(gfx::SHARED_MEMORY_BUFFER, GetNativeGpuMemoryBufferType()); |
| 29 DCHECK_NE(gfx::EMPTY_BUFFER, GetNativeGpuMemoryBufferType()); | 56 DCHECK_NE(gfx::EMPTY_BUFFER, GetNativeGpuMemoryBufferType()); |
| 30 #if defined(OS_MACOSX) | 57 #if defined(OS_MACOSX) |
| 31 switch (usage) { | 58 switch (usage) { |
| 32 case gfx::BufferUsage::GPU_READ: | 59 case gfx::BufferUsage::GPU_READ: |
| 33 case gfx::BufferUsage::SCANOUT: | 60 case gfx::BufferUsage::SCANOUT: |
| 34 case gfx::BufferUsage::SCANOUT_CPU_READ_WRITE: | 61 case gfx::BufferUsage::SCANOUT_CPU_READ_WRITE: |
| 35 return format == gfx::BufferFormat::BGRA_8888 || | 62 return format == gfx::BufferFormat::BGRA_8888 || |
| 36 format == gfx::BufferFormat::RGBA_8888 || | 63 format == gfx::BufferFormat::RGBA_8888 || |
| 37 format == gfx::BufferFormat::BGRX_8888; | 64 format == gfx::BufferFormat::BGRX_8888; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 52 return false; | 79 return false; |
| 53 } | 80 } |
| 54 return gfx::ClientNativePixmapFactory::GetInstance() | 81 return gfx::ClientNativePixmapFactory::GetInstance() |
| 55 ->IsConfigurationSupported(format, usage); | 82 ->IsConfigurationSupported(format, usage); |
| 56 #endif | 83 #endif |
| 57 | 84 |
| 58 NOTREACHED(); | 85 NOTREACHED(); |
| 59 return false; | 86 return false; |
| 60 } | 87 } |
| 61 | 88 |
| 89 GpuMemoryBufferConfigurationSet GetNativeGpuMemoryBufferConfigurations() { |
| 90 GpuMemoryBufferConfigurationSet configurations; |
| 91 |
| 92 #if defined(USE_OZONE) || defined(OS_MACOSX) |
| 93 if (AreNativeGpuMemoryBuffersEnabled()) { |
| 94 const gfx::BufferFormat kNativeFormats[] = { |
| 95 gfx::BufferFormat::R_8, gfx::BufferFormat::RG_88, |
| 96 gfx::BufferFormat::BGR_565, gfx::BufferFormat::RGBA_4444, |
| 97 gfx::BufferFormat::RGBA_8888, gfx::BufferFormat::BGRA_8888, |
| 98 gfx::BufferFormat::UYVY_422, gfx::BufferFormat::YUYV_422, |
| 99 gfx::BufferFormat::YVU_420, gfx::BufferFormat::YUV_420_BIPLANAR}; |
| 100 const gfx::BufferUsage kNativeUsages[] = { |
| 101 gfx::BufferUsage::GPU_READ, gfx::BufferUsage::SCANOUT, |
| 102 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
| 103 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT}; |
| 104 for (auto format : kNativeFormats) { |
| 105 for (auto usage : kNativeUsages) { |
| 106 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) |
| 107 configurations.insert(std::make_pair(format, usage)); |
| 108 } |
| 109 } |
| 110 } |
| 111 |
| 112 // Disable native buffers only when using software GL. |
| 113 bool force_native_gpu_read_write_formats = |
| 114 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 115 switches::kUseGL) != |
| 116 gl::GetGLImplementationName(gl::GetSoftwareGLImplementation()); |
| 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::YUYV_422, gfx::BufferFormat::YVU_420, |
| 123 gfx::BufferFormat::YUV_420_BIPLANAR}; |
| 124 const gfx::BufferUsage kGPUReadWriteUsages[] = { |
| 125 gfx::BufferUsage::GPU_READ, gfx::BufferUsage::SCANOUT, |
| 126 gfx::BufferUsage::SCANOUT_CPU_READ_WRITE}; |
| 127 for (auto format : kGPUReadWriteFormats) { |
| 128 for (auto usage : kGPUReadWriteUsages) { |
| 129 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) |
| 130 configurations.insert(std::make_pair(format, usage)); |
| 131 } |
| 132 } |
| 133 } |
| 134 #endif // defined(USE_OZONE) || defined(OS_MACOSX) |
| 135 |
| 136 return configurations; |
| 137 } |
| 138 |
| 139 uint32_t GetImageTextureTarget(gfx::BufferFormat format, |
| 140 gfx::BufferUsage usage) { |
| 141 #if defined(USE_OZONE) || defined(OS_MACOSX) |
| 142 GpuMemoryBufferConfigurationSet native_configurations = |
| 143 GetNativeGpuMemoryBufferConfigurations(); |
| 144 if (native_configurations.find(std::make_pair(format, usage)) == |
| 145 native_configurations.end()) { |
| 146 return GL_TEXTURE_2D; |
| 147 } |
| 148 |
| 149 switch (GetNativeGpuMemoryBufferType()) { |
| 150 case gfx::NATIVE_PIXMAP: |
| 151 // GPU memory buffers that are shared with the GL using EGLImages |
| 152 // require TEXTURE_EXTERNAL_OES. |
| 153 return GL_TEXTURE_EXTERNAL_OES; |
| 154 case gfx::IO_SURFACE_BUFFER: |
| 155 // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB. |
| 156 return GL_TEXTURE_RECTANGLE_ARB; |
| 157 case gfx::SHARED_MEMORY_BUFFER: |
| 158 case gfx::EMPTY_BUFFER: |
| 159 break; |
| 160 } |
| 161 NOTREACHED(); |
| 162 return GL_TEXTURE_2D; |
| 163 #else // defined(USE_OZONE) || defined(OS_MACOSX) |
| 164 return GL_TEXTURE_2D; |
| 165 #endif |
| 166 } |
| 167 |
| 62 } // namespace gpu | 168 } // namespace gpu |
| OLD | NEW |