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