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 "content/common/gpu/client/gpu_memory_buffer_impl_shm.h" | 7 #include "content/common/gpu/client/gpu_memory_buffer_impl_shm.h" |
8 | 8 |
9 namespace content { | 9 namespace content { |
10 | 10 |
| 11 // static |
11 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::Create( | 12 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::Create( |
| 13 const gfx::Size& size, |
| 14 unsigned internalformat, |
| 15 unsigned usage) { |
| 16 if (GpuMemoryBufferImplShm::IsConfigurationSupported( |
| 17 size, internalformat, usage)) { |
| 18 scoped_ptr<GpuMemoryBufferImplShm> buffer( |
| 19 new GpuMemoryBufferImplShm(size, internalformat)); |
| 20 if (!buffer->Initialize()) |
| 21 return scoped_ptr<GpuMemoryBufferImpl>(); |
| 22 |
| 23 return buffer.PassAs<GpuMemoryBufferImpl>(); |
| 24 } |
| 25 |
| 26 return scoped_ptr<GpuMemoryBufferImpl>(); |
| 27 } |
| 28 |
| 29 // static |
| 30 void GpuMemoryBufferImpl::AllocateForChildProcess( |
| 31 const gfx::Size& size, |
| 32 unsigned internalformat, |
| 33 unsigned usage, |
| 34 base::ProcessHandle child_process, |
| 35 gfx::GpuMemoryBufferHandle* handle) { |
| 36 if (GpuMemoryBufferImplShm::IsConfigurationSupported( |
| 37 size, internalformat, usage)) { |
| 38 GpuMemoryBufferImplShm::AllocateSharedMemoryForChildProcess( |
| 39 size, internalformat, child_process, handle); |
| 40 return; |
| 41 } |
| 42 |
| 43 handle->type = gfx::EMPTY_BUFFER; |
| 44 } |
| 45 |
| 46 // static |
| 47 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( |
12 gfx::GpuMemoryBufferHandle handle, | 48 gfx::GpuMemoryBufferHandle handle, |
13 gfx::Size size, | 49 const gfx::Size& size, |
14 unsigned internalformat) { | 50 unsigned internalformat) { |
15 switch (handle.type) { | 51 switch (handle.type) { |
16 case gfx::SHARED_MEMORY_BUFFER: { | 52 case gfx::SHARED_MEMORY_BUFFER: { |
17 scoped_ptr<GpuMemoryBufferImplShm> buffer( | 53 scoped_ptr<GpuMemoryBufferImplShm> buffer( |
18 new GpuMemoryBufferImplShm(size, internalformat)); | 54 new GpuMemoryBufferImplShm(size, internalformat)); |
19 if (!buffer->Initialize(handle)) | 55 if (!buffer->InitializeFromHandle(handle)) |
20 return scoped_ptr<GpuMemoryBufferImpl>(); | 56 return scoped_ptr<GpuMemoryBufferImpl>(); |
21 | 57 |
22 return buffer.PassAs<GpuMemoryBufferImpl>(); | 58 return buffer.PassAs<GpuMemoryBufferImpl>(); |
23 } | 59 } |
24 default: | 60 default: |
25 return scoped_ptr<GpuMemoryBufferImpl>(); | 61 return scoped_ptr<GpuMemoryBufferImpl>(); |
26 } | 62 } |
27 } | 63 } |
28 | 64 |
29 } // namespace content | 65 } // namespace content |
OLD | NEW |