Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / content / common / gpu / client / gpu_memory_buffer_impl_win.cc
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
9 namespace content {
10
11 // static
12 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::Create(
13     const gfx::Size& size,
14     unsigned internalformat,
15     unsigned usage) {
16   if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
17           size, internalformat, usage)) {
18     scoped_ptr<GpuMemoryBufferImplSharedMemory> buffer(
19         new GpuMemoryBufferImplSharedMemory(size, internalformat));
20     if (!buffer->Initialize())
21       return scoped_ptr<GpuMemoryBufferImpl>();
22
23     return buffer.PassAs<GpuMemoryBufferImpl>();
24   }
25
26   return scoped_ptr<GpuMemoryBufferImpl>();
27 }
28
29 // static
30 void GpuMemoryBufferImpl::AllocateForChildProcess(
31     const gfx::Size& size,
32     unsigned internalformat,
33     unsigned usage,
34     base::ProcessHandle child_process,
35     const AllocationCallback& callback) {
36   if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
37           size, internalformat, usage)) {
38     GpuMemoryBufferImplSharedMemory::AllocateSharedMemoryForChildProcess(
39         size, internalformat, child_process, callback);
40     return;
41   }
42
43   callback.Run(gfx::GpuMemoryBufferHandle());
44 }
45
46 // static
47 void GpuMemoryBufferImpl::DeletedByChildProcess(
48     gfx::GpuMemoryBufferType type,
49     const gfx::GpuMemoryBufferId& id,
50     base::ProcessHandle child_process) {
51 }
52
53 // static
54 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle(
55     const gfx::GpuMemoryBufferHandle& handle,
56     const gfx::Size& size,
57     unsigned internalformat) {
58   switch (handle.type) {
59     case gfx::SHARED_MEMORY_BUFFER: {
60       scoped_ptr<GpuMemoryBufferImplSharedMemory> buffer(
61           new GpuMemoryBufferImplSharedMemory(size, internalformat));
62       if (!buffer->InitializeFromHandle(handle))
63         return scoped_ptr<GpuMemoryBufferImpl>();
64
65       return buffer.PassAs<GpuMemoryBufferImpl>();
66     }
67     default:
68       return scoped_ptr<GpuMemoryBufferImpl>();
69   }
70 }
71
72 }  // namespace content