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