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.
4
5#include "content/common/gpu/client/gpu_memory_buffer_impl.h"
6
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"
9
10namespace content {
11
12// static
13void GpuMemoryBufferImpl::Create(const gfx::Size& size,
14                                 unsigned internalformat,
15                                 unsigned usage,
16                                 int client_id,
17                                 const CreationCallback& callback) {
18  if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
19          size, internalformat, usage)) {
20    GpuMemoryBufferImplSharedMemory::Create(
21        size, internalformat, usage, callback);
22    return;
23  }
24
25  callback.Run(scoped_ptr<GpuMemoryBufferImpl>());
26}
27
28// static
29void GpuMemoryBufferImpl::AllocateForChildProcess(
30    const gfx::Size& size,
31    unsigned internalformat,
32    unsigned usage,
33    base::ProcessHandle child_process,
34    int child_client_id,
35    const AllocationCallback& callback) {
36  if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
37          size, internalformat, usage)) {
38    GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
39        size, internalformat, child_process, callback);
40    return;
41  }
42
43  callback.Run(gfx::GpuMemoryBufferHandle());
44}
45
46// static
47void GpuMemoryBufferImpl::DeletedByChildProcess(
48    gfx::GpuMemoryBufferType type,
49    const gfx::GpuMemoryBufferId& id,
50    base::ProcessHandle child_process) {
51}
52
53// static
54scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle(
55    const gfx::GpuMemoryBufferHandle& handle,
56    const gfx::Size& size,
57    unsigned internalformat,
58    const DestructionCallback& callback) {
59  switch (handle.type) {
60    case gfx::SHARED_MEMORY_BUFFER:
61      return GpuMemoryBufferImplSharedMemory::CreateFromHandle(
62          handle, size, internalformat, callback);
63    case gfx::SURFACE_TEXTURE_BUFFER:
64      return GpuMemoryBufferImplSurfaceTexture::CreateFromHandle(
65          handle, size, internalformat, callback);
66    default:
67      return scoped_ptr<GpuMemoryBufferImpl>();
68  }
69}
70
71}  // namespace content
72