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 void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferId id,
14 const gfx::Size& size,
18 const CreationCallback& callback) {
19 if (GpuMemoryBufferImplOzoneNativeBuffer::IsConfigurationSupported(format,
21 GpuMemoryBufferImplOzoneNativeBuffer::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 (GpuMemoryBufferImplOzoneNativeBuffer::IsConfigurationSupported(format,
46 GpuMemoryBufferImplOzoneNativeBuffer::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,
67 uint32_t sync_point) {
69 case gfx::SHARED_MEMORY_BUFFER:
71 case gfx::OZONE_NATIVE_BUFFER:
72 GpuMemoryBufferImplOzoneNativeBuffer::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::OZONE_NATIVE_BUFFER:
92 return GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle(
93 handle, size, format, callback);
95 return scoped_ptr<GpuMemoryBufferImpl>();
99 } // namespace content