Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / common / gpu / client / gpu_memory_buffer_impl_ozone.cc
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.
4
5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
6
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"
9
10 namespace content {
11
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 (GpuMemoryBufferImplOzoneNativeBuffer::IsConfigurationSupported(format,
20                                                                      usage)) {
21     GpuMemoryBufferImplOzoneNativeBuffer::Create(
22         id, size, format, client_id, callback);
23     return;
24   }
25
26   if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
27           size, format, usage)) {
28     GpuMemoryBufferImplSharedMemory::Create(id, size, format, callback);
29     return;
30   }
31
32   callback.Run(scoped_ptr<GpuMemoryBufferImpl>());
33 }
34
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 (GpuMemoryBufferImplOzoneNativeBuffer::IsConfigurationSupported(format,
45                                                                      usage)) {
46     GpuMemoryBufferImplOzoneNativeBuffer::AllocateForChildProcess(
47         id, size, format, child_client_id, callback);
48     return;
49   }
50
51   if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
52           size, format, usage)) {
53     GpuMemoryBufferImplSharedMemory::AllocateForChildProcess(
54         id, size, format, child_process, callback);
55     return;
56   }
57
58   callback.Run(gfx::GpuMemoryBufferHandle());
59 }
60
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_t sync_point) {
68   switch (type) {
69     case gfx::SHARED_MEMORY_BUFFER:
70       break;
71     case gfx::OZONE_NATIVE_BUFFER:
72       GpuMemoryBufferImplOzoneNativeBuffer::DeletedByChildProcess(
73           id, child_client_id, sync_point);
74       break;
75     default:
76       NOTREACHED();
77       break;
78   }
79 }
80
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::OZONE_NATIVE_BUFFER:
92       return GpuMemoryBufferImplOzoneNativeBuffer::CreateFromHandle(
93           handle, size, format, callback);
94     default:
95       return scoped_ptr<GpuMemoryBufferImpl>();
96   }
97 }
98
99 }  // namespace content