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/logging.h" | 7 #include "base/logging.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(USE_OZONE) | 10 #if defined(USE_OZONE) |
11 #include "ui/ozone/public/client_native_pixmap_factory.h" | 11 #include "ui/ozone/public/client_native_pixmap_factory.h" |
12 #endif | 12 #endif |
13 | 13 |
14 namespace gpu { | 14 namespace gpu { |
15 | 15 |
16 gfx::GpuMemoryBufferType GetNativeGpuMemoryBufferType() { | 16 gfx::GpuMemoryBufferType GetNativeGpuMemoryBufferType() { |
17 #if defined(OS_MACOSX) | 17 #if defined(OS_MACOSX) |
18 return gfx::IO_SURFACE_BUFFER; | 18 return gfx::IO_SURFACE_BUFFER; |
19 #endif | 19 #endif |
20 #if defined(OS_ANDROID) | |
21 return gfx::SURFACE_TEXTURE_BUFFER; | |
22 #endif | |
23 #if defined(USE_OZONE) | 20 #if defined(USE_OZONE) |
24 return gfx::OZONE_NATIVE_PIXMAP; | 21 return gfx::OZONE_NATIVE_PIXMAP; |
25 #endif | 22 #endif |
26 return gfx::EMPTY_BUFFER; | 23 return gfx::EMPTY_BUFFER; |
27 } | 24 } |
28 | 25 |
29 bool IsNativeGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format, | 26 bool IsNativeGpuMemoryBufferConfigurationSupported(gfx::BufferFormat format, |
30 gfx::BufferUsage usage) { | 27 gfx::BufferUsage usage) { |
31 DCHECK_NE(gfx::SHARED_MEMORY_BUFFER, GetNativeGpuMemoryBufferType()); | 28 DCHECK_NE(gfx::SHARED_MEMORY_BUFFER, GetNativeGpuMemoryBufferType()); |
32 DCHECK_NE(gfx::EMPTY_BUFFER, GetNativeGpuMemoryBufferType()); | 29 DCHECK_NE(gfx::EMPTY_BUFFER, GetNativeGpuMemoryBufferType()); |
33 #if defined(OS_MACOSX) | 30 #if defined(OS_MACOSX) |
34 switch (usage) { | 31 switch (usage) { |
35 case gfx::BufferUsage::GPU_READ: | 32 case gfx::BufferUsage::GPU_READ: |
36 case gfx::BufferUsage::SCANOUT: | 33 case gfx::BufferUsage::SCANOUT: |
37 return format == gfx::BufferFormat::BGRA_8888 || | 34 return format == gfx::BufferFormat::BGRA_8888 || |
38 format == gfx::BufferFormat::RGBA_8888 || | 35 format == gfx::BufferFormat::RGBA_8888 || |
39 format == gfx::BufferFormat::BGRX_8888; | 36 format == gfx::BufferFormat::BGRX_8888; |
40 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: | 37 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: |
41 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: | 38 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: |
42 return format == gfx::BufferFormat::R_8 || | 39 return format == gfx::BufferFormat::R_8 || |
43 format == gfx::BufferFormat::BGRA_8888 || | 40 format == gfx::BufferFormat::BGRA_8888 || |
44 format == gfx::BufferFormat::UYVY_422 || | 41 format == gfx::BufferFormat::UYVY_422 || |
45 format == gfx::BufferFormat::YUV_420_BIPLANAR; | 42 format == gfx::BufferFormat::YUV_420_BIPLANAR; |
46 } | 43 } |
47 NOTREACHED(); | 44 NOTREACHED(); |
48 return false; | 45 return false; |
49 #endif | 46 #endif |
50 | 47 |
51 #if defined(OS_ANDROID) | |
52 switch (usage) { | |
53 case gfx::BufferUsage::GPU_READ: | |
54 case gfx::BufferUsage::SCANOUT: | |
55 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE_PERSISTENT: | |
56 return false; | |
57 case gfx::BufferUsage::GPU_READ_CPU_READ_WRITE: | |
58 return format == gfx::BufferFormat::RGBA_8888; | |
59 } | |
60 NOTREACHED(); | |
61 return false; | |
62 #endif | |
63 | |
64 #if defined(USE_OZONE) | 48 #if defined(USE_OZONE) |
65 if (!ui::ClientNativePixmapFactory::GetInstance()) { | 49 if (!ui::ClientNativePixmapFactory::GetInstance()) { |
66 // unittests don't have to set ClientNativePixmapFactory. | 50 // unittests don't have to set ClientNativePixmapFactory. |
67 return false; | 51 return false; |
68 } | 52 } |
69 return ui::ClientNativePixmapFactory::GetInstance()->IsConfigurationSupported( | 53 return ui::ClientNativePixmapFactory::GetInstance()->IsConfigurationSupported( |
70 format, usage); | 54 format, usage); |
71 #endif | 55 #endif |
72 | 56 |
73 NOTREACHED(); | 57 NOTREACHED(); |
74 return false; | 58 return false; |
75 } | 59 } |
76 | 60 |
77 } // namespace gpu | 61 } // namespace gpu |
OLD | NEW |