OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" | 5 #include "content/common/gpu/gpu_memory_buffer_factory_io_surface.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | 10 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
11 #include "ui/gfx/buffer_format_util.h" | 11 #include "ui/gfx/buffer_format_util.h" |
12 #include "ui/gfx/mac/io_surface_manager.h" | 12 #include "ui/gfx/mac/io_surface.h" |
13 #include "ui/gl/gl_image_io_surface.h" | 13 #include "ui/gl/gl_image_io_surface.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { | 17 GpuMemoryBufferFactoryIOSurface::GpuMemoryBufferFactoryIOSurface() { |
18 } | 18 } |
19 | 19 |
20 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { | 20 GpuMemoryBufferFactoryIOSurface::~GpuMemoryBufferFactoryIOSurface() { |
21 } | 21 } |
22 | 22 |
(...skipping 19 matching lines...) Expand all Loading... |
42 | 42 |
43 gfx::GpuMemoryBufferHandle | 43 gfx::GpuMemoryBufferHandle |
44 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( | 44 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBuffer( |
45 gfx::GpuMemoryBufferId id, | 45 gfx::GpuMemoryBufferId id, |
46 const gfx::Size& size, | 46 const gfx::Size& size, |
47 gfx::BufferFormat format, | 47 gfx::BufferFormat format, |
48 gfx::BufferUsage usage, | 48 gfx::BufferUsage usage, |
49 int client_id, | 49 int client_id, |
50 gfx::PluginWindowHandle surface_handle) { | 50 gfx::PluginWindowHandle surface_handle) { |
51 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( | 51 base::ScopedCFTypeRef<IOSurfaceRef> io_surface( |
52 gfx::IOSurfaceManager::CreateIOSurface(size, format)); | 52 gfx::CreateIOSurface(size, format)); |
53 if (!io_surface) | 53 if (!io_surface) |
54 return gfx::GpuMemoryBufferHandle(); | 54 return gfx::GpuMemoryBufferHandle(); |
55 | 55 |
56 if (!gfx::IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, | |
57 io_surface)) { | |
58 return gfx::GpuMemoryBufferHandle(); | |
59 } | |
60 | |
61 { | 56 { |
62 base::AutoLock lock(io_surfaces_lock_); | 57 base::AutoLock lock(io_surfaces_lock_); |
63 | 58 |
64 IOSurfaceMapKey key(id, client_id); | 59 IOSurfaceMapKey key(id, client_id); |
65 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); | 60 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); |
66 io_surfaces_[key] = io_surface; | 61 io_surfaces_[key] = io_surface; |
67 } | 62 } |
68 | 63 |
69 gfx::GpuMemoryBufferHandle handle; | 64 gfx::GpuMemoryBufferHandle handle; |
70 handle.type = gfx::IO_SURFACE_BUFFER; | 65 handle.type = gfx::IO_SURFACE_BUFFER; |
71 handle.id = id; | 66 handle.id = id; |
| 67 handle.mach_port.reset(IOSurfaceCreateMachPort(io_surface)); |
72 return handle; | 68 return handle; |
73 } | 69 } |
74 | 70 |
75 gfx::GpuMemoryBufferHandle | 71 gfx::GpuMemoryBufferHandle |
76 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBufferFromHandle( | 72 GpuMemoryBufferFactoryIOSurface::CreateGpuMemoryBufferFromHandle( |
77 const gfx::GpuMemoryBufferHandle& handle, | 73 const gfx::GpuMemoryBufferHandle& handle, |
78 gfx::GpuMemoryBufferId id, | 74 gfx::GpuMemoryBufferId id, |
79 const gfx::Size& size, | 75 const gfx::Size& size, |
80 gfx::BufferFormat format, | 76 gfx::BufferFormat format, |
81 int client_id) { | 77 int client_id) { |
82 NOTIMPLEMENTED(); | 78 NOTIMPLEMENTED(); |
83 return gfx::GpuMemoryBufferHandle(); | 79 return gfx::GpuMemoryBufferHandle(); |
84 } | 80 } |
85 | 81 |
86 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( | 82 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( |
87 gfx::GpuMemoryBufferId id, | 83 gfx::GpuMemoryBufferId id, |
88 int client_id) { | 84 int client_id) { |
89 { | 85 { |
90 base::AutoLock lock(io_surfaces_lock_); | 86 base::AutoLock lock(io_surfaces_lock_); |
91 | 87 |
92 IOSurfaceMapKey key(id, client_id); | 88 IOSurfaceMapKey key(id, client_id); |
93 DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); | 89 DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); |
94 io_surfaces_.erase(key); | 90 io_surfaces_.erase(key); |
95 } | 91 } |
96 | |
97 gfx::IOSurfaceManager::GetInstance()->UnregisterIOSurface(id, client_id); | |
98 } | 92 } |
99 | 93 |
100 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { | 94 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { |
101 return this; | 95 return this; |
102 } | 96 } |
103 | 97 |
104 scoped_refptr<gl::GLImage> | 98 scoped_refptr<gl::GLImage> |
105 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( | 99 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( |
106 const gfx::GpuMemoryBufferHandle& handle, | 100 const gfx::GpuMemoryBufferHandle& handle, |
107 const gfx::Size& size, | 101 const gfx::Size& size, |
(...skipping 10 matching lines...) Expand all Loading... |
118 | 112 |
119 scoped_refptr<gl::GLImageIOSurface> image( | 113 scoped_refptr<gl::GLImageIOSurface> image( |
120 new gl::GLImageIOSurface(size, internalformat)); | 114 new gl::GLImageIOSurface(size, internalformat)); |
121 if (!image->Initialize(it->second.get(), handle.id, format)) | 115 if (!image->Initialize(it->second.get(), handle.id, format)) |
122 return scoped_refptr<gl::GLImage>(); | 116 return scoped_refptr<gl::GLImage>(); |
123 | 117 |
124 return image; | 118 return image; |
125 } | 119 } |
126 | 120 |
127 } // namespace content | 121 } // namespace content |
OLD | NEW |