1 // Copyright 2014 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_ozone_native_buffer.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 (GpuMemoryBufferImplOzoneNativeBuffer::IsConfigurationSupported(
39 internalformat
, usage
)) {
40 GpuMemoryBufferImplOzoneNativeBuffer::AllocateOzoneNativeBufferForChildId(
41 size
, internalformat
, usage
, child_id
, callback
);
44 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
45 size
, internalformat
, usage
)) {
46 GpuMemoryBufferImplSharedMemory::AllocateSharedMemoryForChildProcess(
47 size
, internalformat
, child_process
, callback
);
51 callback
.Run(gfx::GpuMemoryBufferHandle());
55 void GpuMemoryBufferImpl::DeletedByChildProcess(
56 gfx::GpuMemoryBufferType type
,
57 const gfx::GpuMemoryBufferId
& id
,
58 base::ProcessHandle child_process
) {
62 scoped_ptr
<GpuMemoryBufferImpl
> GpuMemoryBufferImpl::CreateFromHandle(
63 const gfx::GpuMemoryBufferHandle
& handle
,
64 const gfx::Size
& size
,
65 unsigned internalformat
) {
66 switch (handle
.type
) {
67 case gfx::SHARED_MEMORY_BUFFER
: {
68 scoped_ptr
<GpuMemoryBufferImplSharedMemory
> buffer(
69 new GpuMemoryBufferImplSharedMemory(size
, internalformat
));
70 if (!buffer
->InitializeFromHandle(handle
))
71 return scoped_ptr
<GpuMemoryBufferImpl
>();
73 return buffer
.PassAs
<GpuMemoryBufferImpl
>();
75 case gfx::OZONE_NATIVE_BUFFER
: {
76 scoped_ptr
<GpuMemoryBufferImplOzoneNativeBuffer
> buffer(
77 new GpuMemoryBufferImplOzoneNativeBuffer(size
, internalformat
));
78 if (!buffer
->InitializeFromHandle(handle
))
79 return scoped_ptr
<GpuMemoryBufferImpl
>();
81 return buffer
.PassAs
<GpuMemoryBufferImpl
>();
84 return scoped_ptr
<GpuMemoryBufferImpl
>();
88 } // namespace content