Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / common / gpu / client / gpu_memory_buffer_impl_ozone.cc
blob784f75c6c900c124178e4723b99f84733424bea3
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.
5 #include "content/common/gpu/client/gpu_memory_buffer_impl.h"
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"
10 namespace content {
12 // static
13 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::Create(
14 const gfx::Size& size,
15 unsigned internalformat,
16 unsigned usage) {
17 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
18 size, internalformat, usage)) {
19 scoped_ptr<GpuMemoryBufferImplSharedMemory> buffer(
20 new GpuMemoryBufferImplSharedMemory(size, internalformat));
21 if (!buffer->Initialize())
22 return scoped_ptr<GpuMemoryBufferImpl>();
24 return buffer.PassAs<GpuMemoryBufferImpl>();
27 return scoped_ptr<GpuMemoryBufferImpl>();
30 // static
31 void GpuMemoryBufferImpl::AllocateForChildProcess(
32 const gfx::Size& size,
33 unsigned internalformat,
34 unsigned usage,
35 base::ProcessHandle child_process,
36 int child_id,
37 const AllocationCallback& callback) {
38 if (GpuMemoryBufferImplOzoneNativeBuffer::IsConfigurationSupported(
39 internalformat, usage)) {
40 GpuMemoryBufferImplOzoneNativeBuffer::AllocateOzoneNativeBufferForChildId(
41 size, internalformat, usage, child_id, callback);
42 return;
44 if (GpuMemoryBufferImplSharedMemory::IsConfigurationSupported(
45 size, internalformat, usage)) {
46 GpuMemoryBufferImplSharedMemory::AllocateSharedMemoryForChildProcess(
47 size, internalformat, child_process, callback);
48 return;
51 callback.Run(gfx::GpuMemoryBufferHandle());
54 // static
55 void GpuMemoryBufferImpl::DeletedByChildProcess(
56 gfx::GpuMemoryBufferType type,
57 const gfx::GpuMemoryBufferId& id,
58 base::ProcessHandle child_process) {
61 // static
62 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle(
63 const gfx::GpuMemoryBufferHandle& handle,
64 const gfx::Size& size,
65 unsigned internalformat) {
66 switch (handle.type) {
67 case gfx::SHARED_MEMORY_BUFFER: {
68 scoped_ptr<GpuMemoryBufferImplSharedMemory> buffer(
69 new GpuMemoryBufferImplSharedMemory(size, internalformat));
70 if (!buffer->InitializeFromHandle(handle))
71 return scoped_ptr<GpuMemoryBufferImpl>();
73 return buffer.PassAs<GpuMemoryBufferImpl>();
75 case gfx::OZONE_NATIVE_BUFFER: {
76 scoped_ptr<GpuMemoryBufferImplOzoneNativeBuffer> buffer(
77 new GpuMemoryBufferImplOzoneNativeBuffer(size, internalformat));
78 if (!buffer->InitializeFromHandle(handle))
79 return scoped_ptr<GpuMemoryBufferImpl>();
81 return buffer.PassAs<GpuMemoryBufferImpl>();
83 default:
84 return scoped_ptr<GpuMemoryBufferImpl>();
88 } // namespace content