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