gpu: Associate all GpuMemoryBuffers with unique IDs.
[chromium-blink-merge.git] / content / common / gpu / client / gpu_memory_buffer_impl_android.cc
blob9c0fdb368c67b02d9bb7ac985828663d7b6ccf16
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"
10 namespace content {
12 // static
13 void GpuMemoryBufferImpl::Create(gfx::GpuMemoryBufferId id,
14 const gfx::Size& size,
15 Format format,
16 Usage usage,
17 int client_id,
18 const CreationCallback& callback) {
19 if (GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(format,
20 usage)) {
21 GpuMemoryBufferImplSurfaceTexture::Create(
22 id, size, format, client_id, callback);
23 return;
26 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
27 size, format, usage)) {
28 GpuMemoryBufferImplSharedMemory::Create(id, size, format, callback);
29 return;
32 callback.Run(scoped_ptr<GpuMemoryBufferImpl>());
35 // static
36 void GpuMemoryBufferImpl::AllocateForChildProcess(
37 gfx::GpuMemoryBufferId id,
38 const gfx::Size& size,
39 Format format,
40 Usage usage,
41 base::ProcessHandle child_process,
42 int child_client_id,
43 const AllocationCallback& callback) {
44 if (GpuMemoryBufferImplSurfaceTexture::IsConfigurationSupported(format,
45 usage)) {
46 GpuMemoryBufferImplSurfaceTexture::AllocateForChildProcess(
47 id, size, format, child_client_id, callback);
48 return;
51 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
52 size, format, usage)) {
53 GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
54 id, size, format, child_process, callback);
55 return;
58 callback.Run(gfx::GpuMemoryBufferHandle());
61 // static
62 void GpuMemoryBufferImpl::DeletedByChildProcess(
63 gfx::GpuMemoryBufferType type,
64 gfx::GpuMemoryBufferId id,
65 base::ProcessHandle child_process,
66 int child_client_id,
67 uint32 sync_point) {
68 switch (type) {
69 case gfx::SHARED_MEMORY_BUFFER:
70 break;
71 case gfx::SURFACE_TEXTURE_BUFFER:
72 GpuMemoryBufferImplSurfaceTexture::DeletedByChildProcess(
73 id, child_client_id, sync_point);
74 break;
75 default:
76 NOTREACHED();
77 break;
81 // static
82 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle(
83 const gfx::GpuMemoryBufferHandle& handle,
84 const gfx::Size& size,
85 Format format,
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);
94 default:
95 return scoped_ptr<GpuMemoryBufferImpl>();
99 } // namespace content