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