OLD | NEW |
| (Empty) |
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/gpu_memory_buffer_factory_io_surface.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "base/logging.h" | |
10 #include "ui/gfx/buffer_format_util.h" | |
11 #include "ui/gfx/mac/io_surface.h" | |
12 #include "ui/gl/gl_image_io_surface.h" | |
13 | |
14 namespace content { | |
15 | |
16 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { | |
17 } | |
18 | |
19 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { | |
20 } | |
21 | |
22 gfx::GpuMemoryBufferHandle | |
23 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( | |
24 gfx::GpuMemoryBufferId id, | |
25 const gfx::Size& size, | |
26 gfx::BufferFormat format, | |
27 gfx::BufferUsage usage, | |
28 int client_id, | |
29 gpu::SurfaceHandle surface_handle) { | |
30 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( | |
31 gfx::CreateIOSurface(size, format)); | |
32 if (!io_surface) | |
33 return gfx::GpuMemoryBufferHandle(); | |
34 | |
35 { | |
36 base::AutoLock lock(io_surfaces_lock_); | |
37 | |
38 IOSurfaceMapKey key(id, client_id); | |
39 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); | |
40 io_surfaces_[key] = io_surface; | |
41 } | |
42 | |
43 gfx::GpuMemoryBufferHandle handle; | |
44 handle.type = gfx::IO_SURFACE_BUFFER; | |
45 handle.id = id; | |
46 handle.mach_port.reset(IOSurfaceCreateMachPort(io_surface)); | |
47 return handle; | |
48 } | |
49 | |
50 gfx::GpuMemoryBufferHandle | |
51 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBufferFromHandle( | |
52 const gfx::GpuMemoryBufferHandle& handle, | |
53 gfx::GpuMemoryBufferId id, | |
54 const gfx::Size& size, | |
55 gfx::BufferFormat format, | |
56 int client_id) { | |
57 NOTIMPLEMENTED(); | |
58 return gfx::GpuMemoryBufferHandle(); | |
59 } | |
60 | |
61 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( | |
62 gfx::GpuMemoryBufferId id, | |
63 int client_id) { | |
64 { | |
65 base::AutoLock lock(io_surfaces_lock_); | |
66 | |
67 IOSurfaceMapKey key(id, client_id); | |
68 DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); | |
69 io_surfaces_.erase(key); | |
70 } | |
71 } | |
72 | |
73 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { | |
74 return this; | |
75 } | |
76 | |
77 scoped_refptr<gl::GLImage> | |
78 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( | |
79 const gfx::GpuMemoryBufferHandle& handle, | |
80 const gfx::Size& size, | |
81 gfx::BufferFormat format, | |
82 unsigned internalformat, | |
83 int client_id) { | |
84 base::AutoLock lock(io_surfaces_lock_); | |
85 | |
86 DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER); | |
87 IOSurfaceMapKey key(handle.id, client_id); | |
88 IOSurfaceMap::iterator it = io_surfaces_.find(key); | |
89 if (it == io_surfaces_.end()) | |
90 return scoped_refptr<gl::GLImage>(); | |
91 | |
92 scoped_refptr<gl::GLImageIOSurface> image( | |
93 new gl::GLImageIOSurface(size, internalformat)); | |
94 if (!image->Initialize(it->second.get(), handle.id, format)) | |
95 return scoped_refptr<gl::GLImage>(); | |
96 | |
97 return image; | |
98 } | |
99 | |
100 } // namespace content | |
OLD | NEW |