Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / common / gpu / client / gpu_memory_buffer_impl_win.cc
blob5c04cd8d9b18f94824c27e0eff5e3d2246866439
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"
9 namespace content {
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>();
23 return buffer.PassAs<GpuMemoryBufferImpl>();
26 return scoped_ptr<GpuMemoryBufferImpl>();
29 // static
30 void GpuMemoryBufferImpl::AllocateForChildProcess(
31 const gfx::Size& size,
32 unsigned internalformat,
33 unsigned usage,
34 base::ProcessHandle child_process,
35 int child_id,
36 const AllocationCallback& callback) {
37 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
38 size, internalformat, usage)) {
39 GpuMemoryBufferImplSharedMemory::AllocateSharedMemoryForChildProcess(
40 size, internalformat, child_process, callback);
41 return;
44 callback.Run(gfx::GpuMemoryBufferHandle());
47 // static
48 void GpuMemoryBufferImpl::DeletedByChildProcess(
49 gfx::GpuMemoryBufferType type,
50 const gfx::GpuMemoryBufferId& id,
51 base::ProcessHandle child_process) {
54 // static
55 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle(
56 const gfx::GpuMemoryBufferHandle& handle,
57 const gfx::Size& size,
58 unsigned internalformat) {
59 switch (handle.type) {
60 case gfx::SHARED_MEMORY_BUFFER: {
61 scoped_ptr<GpuMemoryBufferImplSharedMemory> buffer(
62 new GpuMemoryBufferImplSharedMemory(size, internalformat));
63 if (!buffer->InitializeFromHandle(handle))
64 return scoped_ptr<GpuMemoryBufferImpl>();
66 return buffer.PassAs<GpuMemoryBufferImpl>();
68 default:
69 return scoped_ptr<GpuMemoryBufferImpl>();
73 } // namespace content