OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/common/gpu/client/gpu_memory_buffer_impl.h" | 5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
6 | 6 |
7 #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h
" | 7 #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_buffer.h
" |
8 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" | 8 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" |
9 | 9 |
10 namespace content { | 10 namespace content { |
11 | 11 |
12 // static | 12 // static |
13 void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferId id, | 13 void GpuMemoryBufferImpl::GetSupportedTypes( |
| 14 std::vector<gfx::GpuMemoryBufferType>* types) { |
| 15 const gfx::GpuMemoryBufferType supported_types[] = { |
| 16 gfx::OZONE_NATIVE_BUFFER, |
| 17 gfx::SHARED_MEMORY_BUFFER |
| 18 }; |
| 19 types->assign(supported_types, supported_types + arraysize(supported_types)); |
| 20 } |
| 21 |
| 22 // static |
| 23 bool GpuMemoryBufferImpl::IsConfigurationSupported( |
| 24 gfx::GpuMemoryBufferType type, |
| 25 Format format, |
| 26 Usage usage) { |
| 27 switch (type) { |
| 28 case gfx::SHARED_MEMORY_BUFFER: |
| 29 return GpuMemoryBufferImplSharedMemory::IsFormatSupported(format) && |
| 30 GpuMemoryBufferImplSharedMemory::IsUsageSupported(usage); |
| 31 case gfx::OZONE_NATIVE_BUFFER: |
| 32 return GpuMemoryBufferImplOzoneNativeBuffer::IsFormatSupported(format) && |
| 33 GpuMemoryBufferImplOzoneNativeBuffer::IsUsageSupported(usage); |
| 34 default: |
| 35 NOTREACHED(); |
| 36 return false; |
| 37 } |
| 38 } |
| 39 |
| 40 // static |
| 41 void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferType type, |
| 42 gfx::GpuMemoryBufferId id, |
14 const gfx::Size& size, | 43 const gfx::Size& size, |
15 Format format, | 44 Format format, |
16 Usage usage, | 45 Usage usage, |
17 int client_id, | 46 int client_id, |
18 const CreationCallback& callback) { | 47 const CreationCallback& callback) { |
19 if (GpuMemoryBufferImplOzoneNativeBuffer::IsConfigurationSupported(format, | 48 switch (type) { |
20 usage)) { | 49 case gfx::SHARED_MEMORY_BUFFER: |
21 GpuMemoryBufferImplOzoneNativeBuffer::Create( | 50 GpuMemoryBufferImplSharedMemory::Create(id, size, format, callback); |
22 id, size, format, client_id, callback); | 51 break; |
23 return; | 52 case gfx::OZONE_NATIVE_BUFFER: |
| 53 GpuMemoryBufferImplOzoneNativeBuffer::Create( |
| 54 id, size, format, client_id, callback); |
| 55 break; |
| 56 default: |
| 57 NOTREACHED(); |
| 58 break; |
24 } | 59 } |
25 | |
26 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( | |
27 size, format, usage)) { | |
28 GpuMemoryBufferImplSharedMemory::Create(id, size, format, callback); | |
29 return; | |
30 } | |
31 | |
32 callback.Run(scoped_ptr<GpuMemoryBufferImpl>()); | |
33 } | 60 } |
34 | 61 |
35 // static | 62 // static |
36 void GpuMemoryBufferImpl::AllocateForChildProcess( | 63 void GpuMemoryBufferImpl::AllocateForChildProcess( |
| 64 gfx::GpuMemoryBufferType type, |
37 gfx::GpuMemoryBufferId id, | 65 gfx::GpuMemoryBufferId id, |
38 const gfx::Size& size, | 66 const gfx::Size& size, |
39 Format format, | 67 Format format, |
40 Usage usage, | 68 Usage usage, |
41 base::ProcessHandle child_process, | 69 base::ProcessHandle child_process, |
42 int child_client_id, | 70 int child_client_id, |
43 const AllocationCallback& callback) { | 71 const AllocationCallback& callback) { |
44 if (GpuMemoryBufferImplOzoneNativeBuffer::IsConfigurationSupported(format, | 72 switch (type) { |
45 usage)) { | 73 case gfx::SHARED_MEMORY_BUFFER: |
46 GpuMemoryBufferImplOzoneNativeBuffer::AllocateForChildProcess( | 74 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( |
47 id, size, format, child_client_id, callback); | 75 id, size, format, child_process, callback); |
48 return; | 76 break; |
| 77 case gfx::OZONE_NATIVE_BUFFER: |
| 78 GpuMemoryBufferImplOzoneNativeBuffer::AllocateForChildProcess( |
| 79 id, size, format, child_client_id, callback); |
| 80 break; |
| 81 default: |
| 82 NOTREACHED(); |
| 83 break; |
49 } | 84 } |
50 | |
51 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported( | |
52 size, format, usage)) { | |
53 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess( | |
54 id, size, format, child_process, callback); | |
55 return; | |
56 } | |
57 | |
58 callback.Run(gfx::GpuMemoryBufferHandle()); | |
59 } | 85 } |
60 | 86 |
61 // static | 87 // static |
62 void GpuMemoryBufferImpl::DeletedByChildProcess( | 88 void GpuMemoryBufferImpl::DeletedByChildProcess( |
63 gfx::GpuMemoryBufferType type, | 89 gfx::GpuMemoryBufferType type, |
64 gfx::GpuMemoryBufferId id, | 90 gfx::GpuMemoryBufferId id, |
65 base::ProcessHandle child_process, | 91 base::ProcessHandle child_process, |
66 int child_client_id, | 92 int child_client_id, |
67 uint32_t sync_point) { | 93 uint32_t sync_point) { |
68 switch (type) { | 94 switch (type) { |
(...skipping 16 matching lines...) Expand all Loading... |
85 Format format, | 111 Format format, |
86 const DestructionCallback& callback) { | 112 const DestructionCallback& callback) { |
87 switch (handle.type) { | 113 switch (handle.type) { |
88 case gfx::SHARED_MEMORY_BUFFER: | 114 case gfx::SHARED_MEMORY_BUFFER: |
89 return GpuMemoryBufferImplSharedMemory::CreateFromHandle( | 115 return GpuMemoryBufferImplSharedMemory::CreateFromHandle( |
90 handle, size, format, callback); | 116 handle, size, format, callback); |
91 case gfx::OZONE_NATIVE_BUFFER: | 117 case gfx::OZONE_NATIVE_BUFFER: |
92 return GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle( | 118 return GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle( |
93 handle, size, format, callback); | 119 handle, size, format, callback); |
94 default: | 120 default: |
| 121 NOTREACHED(); |
95 return scoped_ptr<GpuMemoryBufferImpl>(); | 122 return scoped_ptr<GpuMemoryBufferImpl>(); |
96 } | 123 } |
97 } | 124 } |
98 | 125 |
99 } // namespace content | 126 } // namespace content |
OLD | NEW |