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
3 // found in the LICENSE file.
5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
7 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h"
8 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h"
13 scoped_ptr
<GpuMemoryBufferImpl
> GpuMemoryBufferImpl::Create(
14 const gfx::Size
& size
,
15 unsigned internalformat
,
17 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
18 size
, internalformat
, usage
)) {
19 scoped_ptr
<GpuMemoryBufferImplSharedMemory
> buffer(
20 new GpuMemoryBufferImplSharedMemory(size
, internalformat
));
21 if (!buffer
->Initialize())
22 return scoped_ptr
<GpuMemoryBufferImpl
>();
24 return buffer
.PassAs
<GpuMemoryBufferImpl
>();
27 return scoped_ptr
<GpuMemoryBufferImpl
>();
31 void GpuMemoryBufferImpl::AllocateForChildProcess(
32 const gfx::Size
& size
,
33 unsigned internalformat
,
35 base::ProcessHandle child_process
,
37 const AllocationCallback
& callback
) {
38 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
39 size
, internalformat
, usage
)) {
40 GpuMemoryBufferImplSharedMemory::AllocateSharedMemoryForChildProcess(
41 size
, internalformat
, child_process
, callback
);
45 callback
.Run(gfx::GpuMemoryBufferHandle());
49 void GpuMemoryBufferImpl::DeletedByChildProcess(
50 gfx::GpuMemoryBufferType type
,
51 const gfx::GpuMemoryBufferId
& id
,
52 base::ProcessHandle child_process
) {
56 scoped_ptr
<GpuMemoryBufferImpl
> GpuMemoryBufferImpl::CreateFromHandle(
57 const gfx::GpuMemoryBufferHandle
& handle
,
58 const gfx::Size
& size
,
59 unsigned internalformat
) {
60 switch (handle
.type
) {
61 case gfx::SHARED_MEMORY_BUFFER
: {
62 scoped_ptr
<GpuMemoryBufferImplSharedMemory
> buffer(
63 new GpuMemoryBufferImplSharedMemory(size
, internalformat
));
64 if (!buffer
->InitializeFromHandle(handle
))
65 return scoped_ptr
<GpuMemoryBufferImpl
>();
67 return buffer
.PassAs
<GpuMemoryBufferImpl
>();
69 case gfx::IO_SURFACE_BUFFER
: {
70 scoped_ptr
<GpuMemoryBufferImplIOSurface
> buffer(
71 new GpuMemoryBufferImplIOSurface(size
, internalformat
));
72 if (!buffer
->InitializeFromHandle(handle
))
73 return scoped_ptr
<GpuMemoryBufferImpl
>();
75 return buffer
.PassAs
<GpuMemoryBufferImpl
>();
78 return scoped_ptr
<GpuMemoryBufferImpl
>();
82 } // namespace content