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_shared_memory.h"
8 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h"
13 void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferId id
,
14 const gfx::Size
& size
,
18 const CreationCallback
& callback
) {
19 if (GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(format
,
21 GpuMemoryBufferImplSurfaceTexture::Create(
22 id
, size
, format
, client_id
, callback
);
26 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
27 size
, format
, usage
)) {
28 GpuMemoryBufferImplSharedMemory::Create(id
, size
, format
, callback
);
32 callback
.Run(scoped_ptr
<GpuMemoryBufferImpl
>());
36 void GpuMemoryBufferImpl::AllocateForChildProcess(
37 gfx::GpuMemoryBufferId id
,
38 const gfx::Size
& size
,
41 base::ProcessHandle child_process
,
43 const AllocationCallback
& callback
) {
44 if (GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(format
,
46 GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess(
47 id
, size
, format
, child_client_id
, callback
);
51 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
52 size
, format
, usage
)) {
53 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
54 id
, size
, format
, child_process
, callback
);
58 callback
.Run(gfx::GpuMemoryBufferHandle());
62 void GpuMemoryBufferImpl::DeletedByChildProcess(
63 gfx::GpuMemoryBufferType type
,
64 gfx::GpuMemoryBufferId id
,
65 base::ProcessHandle child_process
,
69 case gfx::SHARED_MEMORY_BUFFER
:
71 case gfx::SURFACE_TEXTURE_BUFFER
:
72 GpuMemoryBufferImplSurfaceTexture::DeletedByChildProcess(
73 id
, child_client_id
, sync_point
);
82 scoped_ptr
<GpuMemoryBufferImpl
> GpuMemoryBufferImpl::CreateFromHandle(
83 const gfx::GpuMemoryBufferHandle
& handle
,
84 const gfx::Size
& size
,
86 const DestructionCallback
& callback
) {
87 switch (handle
.type
) {
88 case gfx::SHARED_MEMORY_BUFFER
:
89 return GpuMemoryBufferImplSharedMemory::CreateFromHandle(
90 handle
, size
, format
, callback
);
91 case gfx::SURFACE_TEXTURE_BUFFER
:
92 return GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
93 handle
, size
, format
, callback
);
95 return scoped_ptr
<GpuMemoryBufferImpl
>();
99 } // namespace content