OLD | NEW |
| (Empty) |
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 "base/logging.h" | |
8 #include "build/build_config.h" | |
9 #include "content/common/gpu/client/gpu_memory_buffer_impl_shared_memory.h" | |
10 | |
11 #if defined(OS_MACOSX) | |
12 #include "content/common/gpu/client/gpu_memory_buffer_impl_io_surface.h" | |
13 #endif | |
14 | |
15 #if defined(OS_ANDROID) | |
16 #include "content/common/gpu/client/gpu_memory_buffer_impl_surface_texture.h" | |
17 #endif | |
18 | |
19 #if defined(USE_OZONE) | |
20 #include "content/common/gpu/client/gpu_memory_buffer_impl_ozone_native_pixmap.h
" | |
21 #endif | |
22 | |
23 namespace content { | |
24 | |
25 GpuMemoryBufferImpl::GpuMemoryBufferImpl(gfx::GpuMemoryBufferId id, | |
26 const gfx::Size& size, | |
27 gfx::BufferFormat format, | |
28 const DestructionCallback& callback) | |
29 : id_(id), | |
30 size_(size), | |
31 format_(format), | |
32 callback_(callback), | |
33 mapped_(false) {} | |
34 | |
35 GpuMemoryBufferImpl::~GpuMemoryBufferImpl() { | |
36 DCHECK(!mapped_); | |
37 callback_.Run(destruction_sync_token_); | |
38 } | |
39 | |
40 // static | |
41 scoped_ptr<GpuMemoryBufferImpl> GpuMemoryBufferImpl::CreateFromHandle( | |
42 const gfx::GpuMemoryBufferHandle& handle, | |
43 const gfx::Size& size, | |
44 gfx::BufferFormat format, | |
45 gfx::BufferUsage usage, | |
46 const DestructionCallback& callback) { | |
47 switch (handle.type) { | |
48 case gfx::SHARED_MEMORY_BUFFER: | |
49 return GpuMemoryBufferImplSharedMemory::CreateFromHandle( | |
50 handle, size, format, usage, callback); | |
51 #if defined(OS_MACOSX) | |
52 case gfx::IO_SURFACE_BUFFER: | |
53 return GpuMemoryBufferImplIOSurface::CreateFromHandle( | |
54 handle, size, format, usage, callback); | |
55 #endif | |
56 #if defined(OS_ANDROID) | |
57 case gfx::SURFACE_TEXTURE_BUFFER: | |
58 return GpuMemoryBufferImplSurfaceTexture::CreateFromHandle( | |
59 handle, size, format, usage, callback); | |
60 #endif | |
61 #if defined(USE_OZONE) | |
62 case gfx::OZONE_NATIVE_PIXMAP: | |
63 return GpuMemoryBufferImplOzoneNativePixmap::CreateFromHandle( | |
64 handle, size, format, usage, callback); | |
65 #endif | |
66 default: | |
67 NOTREACHED(); | |
68 return nullptr; | |
69 } | |
70 } | |
71 | |
72 // static | |
73 GpuMemoryBufferImpl* GpuMemoryBufferImpl::FromClientBuffer( | |
74 ClientBuffer buffer) { | |
75 return reinterpret_cast<GpuMemoryBufferImpl*>(buffer); | |
76 } | |
77 | |
78 gfx::Size GpuMemoryBufferImpl::GetSize() const { | |
79 return size_; | |
80 } | |
81 | |
82 gfx::BufferFormat GpuMemoryBufferImpl::GetFormat() const { | |
83 return format_; | |
84 } | |
85 | |
86 gfx::GpuMemoryBufferId GpuMemoryBufferImpl::GetId() const { | |
87 return id_; | |
88 } | |
89 | |
90 ClientBuffer GpuMemoryBufferImpl::AsClientBuffer() { | |
91 return reinterpret_cast<ClientBuffer>(this); | |
92 } | |
93 | |
94 } // namespace content | |
OLD | NEW |