| 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/host/gpu_memory_buffer_support.h" | 5 #include "gpu/ipc/host/gpu_memory_buffer_support.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "gpu/ipc/common/gpu_memory_buffer_support.h" | 10 #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 switches::kDisableNativeGpuMemoryBuffers); | 26 switches::kDisableNativeGpuMemoryBuffers); |
| 27 #else | 27 #else |
| 28 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 28 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 29 switches::kEnableNativeGpuMemoryBuffers); | 29 switches::kEnableNativeGpuMemoryBuffers); |
| 30 #endif | 30 #endif |
| 31 } | 31 } |
| 32 | 32 |
| 33 GpuMemoryBufferConfigurationSet GetNativeGpuMemoryBufferConfigurations() { | 33 GpuMemoryBufferConfigurationSet GetNativeGpuMemoryBufferConfigurations() { |
| 34 GpuMemoryBufferConfigurationSet configurations; | 34 GpuMemoryBufferConfigurationSet configurations; |
| 35 | 35 |
| 36 #if defined(USE_OZONE) || defined(OS_MACOSX) |
| 36 if (AreNativeGpuMemoryBuffersEnabled()) { | 37 if (AreNativeGpuMemoryBuffersEnabled()) { |
| 37 const gfx::BufferFormat kNativeFormats[] = { | 38 const gfx::BufferFormat kNativeFormats[] = { |
| 38 gfx::BufferFormat::R_8, | 39 gfx::BufferFormat::R_8, |
| 39 gfx::BufferFormat::RG_88, | 40 gfx::BufferFormat::RG_88, |
| 40 gfx::BufferFormat::BGR_565, | 41 gfx::BufferFormat::BGR_565, |
| 41 gfx::BufferFormat::RGBA_4444, | 42 gfx::BufferFormat::RGBA_4444, |
| 42 gfx::BufferFormat::RGBA_8888, | 43 gfx::BufferFormat::RGBA_8888, |
| 43 gfx::BufferFormat::BGRA_8888, | 44 gfx::BufferFormat::BGRA_8888, |
| 44 gfx::BufferFormat::UYVY_422, | 45 gfx::BufferFormat::UYVY_422, |
| 45 gfx::BufferFormat::YVU_420, | 46 gfx::BufferFormat::YVU_420, |
| 46 gfx::BufferFormat::YUV_420_BIPLANAR}; | 47 gfx::BufferFormat::YUV_420_BIPLANAR}; |
| 47 const gfx::BufferUsage kNativeUsages[] = { | 48 const gfx::BufferUsage kNativeUsages[] = { |
| 48 gfx::BufferUsage::GPU_READ, gfx::BufferUsage::SCANOUT, | 49 gfx::BufferUsage::GPU_READ, gfx::BufferUsage::SCANOUT, |
| 49 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, | 50 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
| 50 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT}; | 51 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT}; |
| 51 for (auto& format : kNativeFormats) { | 52 for (auto format : kNativeFormats) { |
| 52 for (auto& usage : kNativeUsages) { | 53 for (auto usage : kNativeUsages) { |
| 53 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) | 54 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) |
| 54 configurations.insert(std::make_pair(format, usage)); | 55 configurations.insert(std::make_pair(format, usage)); |
| 55 } | 56 } |
| 56 } | 57 } |
| 57 } | 58 } |
| 58 | 59 |
| 59 #if defined(USE_OZONE) || defined(OS_MACOSX) | |
| 60 // Disable native buffers only when using Mesa. | 60 // Disable native buffers only when using Mesa. |
| 61 bool force_native_gpu_read_write_formats = | 61 bool force_native_gpu_read_write_formats = |
| 62 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 62 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 63 switches::kUseGL) != gl::kGLImplementationOSMesaName; | 63 switches::kUseGL) != gl::kGLImplementationOSMesaName; |
| 64 #else | |
| 65 bool force_native_gpu_read_write_formats = false; | |
| 66 #endif | |
| 67 if (force_native_gpu_read_write_formats) { | 64 if (force_native_gpu_read_write_formats) { |
| 68 const gfx::BufferFormat kGPUReadWriteFormats[] = { | 65 const gfx::BufferFormat kGPUReadWriteFormats[] = { |
| 69 gfx::BufferFormat::BGR_565, gfx::BufferFormat::RGBA_8888, | 66 gfx::BufferFormat::BGR_565, gfx::BufferFormat::RGBA_8888, |
| 70 gfx::BufferFormat::RGBX_8888, gfx::BufferFormat::BGRA_8888, | 67 gfx::BufferFormat::RGBX_8888, gfx::BufferFormat::BGRA_8888, |
| 71 gfx::BufferFormat::BGRX_8888, gfx::BufferFormat::UYVY_422, | 68 gfx::BufferFormat::BGRX_8888, gfx::BufferFormat::UYVY_422, |
| 72 gfx::BufferFormat::YVU_420, gfx::BufferFormat::YUV_420_BIPLANAR}; | 69 gfx::BufferFormat::YVU_420, gfx::BufferFormat::YUV_420_BIPLANAR}; |
| 73 const gfx::BufferUsage kGPUReadWriteUsages[] = {gfx::BufferUsage::GPU_READ, | 70 const gfx::BufferUsage kGPUReadWriteUsages[] = {gfx::BufferUsage::GPU_READ, |
| 74 gfx::BufferUsage::SCANOUT}; | 71 gfx::BufferUsage::SCANOUT}; |
| 75 for (auto& format : kGPUReadWriteFormats) { | 72 for (auto format : kGPUReadWriteFormats) { |
| 76 for (auto& usage : kGPUReadWriteUsages) { | 73 for (auto usage : kGPUReadWriteUsages) { |
| 77 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) | 74 if (IsNativeGpuMemoryBufferConfigurationSupported(format, usage)) |
| 78 configurations.insert(std::make_pair(format, usage)); | 75 configurations.insert(std::make_pair(format, usage)); |
| 79 } | 76 } |
| 80 } | 77 } |
| 81 } | 78 } |
| 79 #endif // defined(USE_OZONE) || defined(OS_MACOSX) |
| 82 | 80 |
| 83 return configurations; | 81 return configurations; |
| 84 } | 82 } |
| 85 | 83 |
| 86 uint32_t GetImageTextureTarget(gfx::BufferFormat format, | 84 uint32_t GetImageTextureTarget(gfx::BufferFormat format, |
| 87 gfx::BufferUsage usage) { | 85 gfx::BufferUsage usage) { |
| 86 #if defined(USE_OZONE) || defined(OS_MACOSX) |
| 88 GpuMemoryBufferConfigurationSet native_configurations = | 87 GpuMemoryBufferConfigurationSet native_configurations = |
| 89 GetNativeGpuMemoryBufferConfigurations(); | 88 GetNativeGpuMemoryBufferConfigurations(); |
| 90 if (native_configurations.find(std::make_pair(format, usage)) == | 89 if (native_configurations.find(std::make_pair(format, usage)) == |
| 91 native_configurations.end()) { | 90 native_configurations.end()) { |
| 92 return GL_TEXTURE_2D; | 91 return GL_TEXTURE_2D; |
| 93 } | 92 } |
| 94 | 93 |
| 95 switch (GetNativeGpuMemoryBufferType()) { | 94 switch (GetNativeGpuMemoryBufferType()) { |
| 96 case gfx::OZONE_NATIVE_PIXMAP: | 95 case gfx::OZONE_NATIVE_PIXMAP: |
| 97 // GPU memory buffers that are shared with the GL using EGLImages | 96 // GPU memory buffers that are shared with the GL using EGLImages |
| 98 // require TEXTURE_EXTERNAL_OES. | 97 // require TEXTURE_EXTERNAL_OES. |
| 99 return GL_TEXTURE_EXTERNAL_OES; | 98 return GL_TEXTURE_EXTERNAL_OES; |
| 100 case gfx::IO_SURFACE_BUFFER: | 99 case gfx::IO_SURFACE_BUFFER: |
| 101 // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB. | 100 // IOSurface backed images require GL_TEXTURE_RECTANGLE_ARB. |
| 102 return GL_TEXTURE_RECTANGLE_ARB; | 101 return GL_TEXTURE_RECTANGLE_ARB; |
| 103 case gfx::SHARED_MEMORY_BUFFER: | 102 case gfx::SHARED_MEMORY_BUFFER: |
| 104 return GL_TEXTURE_2D; | |
| 105 case gfx::EMPTY_BUFFER: | 103 case gfx::EMPTY_BUFFER: |
| 106 NOTREACHED(); | 104 break; |
| 107 return GL_TEXTURE_2D; | |
| 108 } | 105 } |
| 109 | |
| 110 NOTREACHED(); | 106 NOTREACHED(); |
| 111 return GL_TEXTURE_2D; | 107 return GL_TEXTURE_2D; |
| 108 #else // defined(USE_OZONE) || defined(OS_MACOSX) |
| 109 return GL_TEXTURE_2D; |
| 110 #endif |
| 112 } | 111 } |
| 113 | 112 |
| 114 } // namespace gpu | 113 } // namespace gpu |
| OLD | NEW |