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 <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "content/common/mac/io_surface_manager.h" | |
10 #include "ui/gl/gl_image_io_surface.h" | 11 #include "ui/gl/gl_image_io_surface.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 namespace { | 14 namespace { |
14 | 15 |
15 void AddBooleanValue(CFMutableDictionaryRef dictionary, | |
16 const CFStringRef key, | |
17 bool value) { | |
18 CFDictionaryAddValue( | |
19 dictionary, key, value ? kCFBooleanTrue : kCFBooleanFalse); | |
20 } | |
21 | |
22 void AddIntegerValue(CFMutableDictionaryRef dictionary, | 16 void AddIntegerValue(CFMutableDictionaryRef dictionary, |
23 const CFStringRef key, | 17 const CFStringRef key, |
24 int32 value) { | 18 int32 value) { |
25 base::ScopedCFTypeRef<CFNumberRef> number( | 19 base::ScopedCFTypeRef<CFNumberRef> number( |
26 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | 20 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
27 CFDictionaryAddValue(dictionary, key, number.get()); | 21 CFDictionaryAddValue(dictionary, key, number.get()); |
28 } | 22 } |
29 | 23 |
30 int32 BytesPerPixel(gfx::GpuMemoryBuffer::Format format) { | 24 int32 BytesPerPixel(gfx::GpuMemoryBuffer::Format format) { |
31 switch (format) { | 25 switch (format) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 gfx::PluginWindowHandle surface_handle) { | 104 gfx::PluginWindowHandle surface_handle) { |
111 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 105 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; |
112 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 106 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, |
113 0, | 107 0, |
114 &kCFTypeDictionaryKeyCallBacks, | 108 &kCFTypeDictionaryKeyCallBacks, |
115 &kCFTypeDictionaryValueCallBacks)); | 109 &kCFTypeDictionaryValueCallBacks)); |
116 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | 110 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
117 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | 111 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
118 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); | 112 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); |
119 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); | 113 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); |
120 // TODO(reveman): Remove this when using a mach_port_t to transfer | |
121 // IOSurface to browser and renderer process. crbug.com/323304 | |
122 AddBooleanValue(properties, kIOSurfaceIsGlobal, true); | |
123 | 114 |
124 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | 115 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); |
125 if (!io_surface) | 116 if (!io_surface) |
126 return gfx::GpuMemoryBufferHandle(); | 117 return gfx::GpuMemoryBufferHandle(); |
127 | 118 |
119 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, | |
120 io_surface)) { | |
121 return gfx::GpuMemoryBufferHandle(); | |
122 } | |
123 | |
128 { | 124 { |
129 base::AutoLock lock(io_surfaces_lock_); | 125 base::AutoLock lock(io_surfaces_lock_); |
130 | 126 |
131 IOSurfaceMapKey key(id, client_id); | 127 IOSurfaceMapKey key(id, client_id); |
132 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); | 128 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); |
133 io_surfaces_[key] = io_surface; | 129 io_surfaces_[key] = io_surface; |
134 } | 130 } |
135 | 131 |
136 gfx::GpuMemoryBufferHandle handle; | 132 gfx::GpuMemoryBufferHandle handle; |
137 handle.type = gfx::IO_SURFACE_BUFFER; | 133 handle.type = gfx::IO_SURFACE_BUFFER; |
138 handle.id = id; | 134 handle.id = id; |
139 handle.io_surface_id = IOSurfaceGetID(io_surface); | |
140 return handle; | 135 return handle; |
141 } | 136 } |
142 | 137 |
143 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( | 138 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( |
144 gfx::GpuMemoryBufferId id, | 139 gfx::GpuMemoryBufferId id, |
145 int client_id) { | 140 int client_id) { |
146 base::AutoLock lock(io_surfaces_lock_); | 141 { |
142 base::AutoLock lock(io_surfaces_lock_); | |
147 | 143 |
148 IOSurfaceMapKey key(id, client_id); | 144 IOSurfaceMapKey key(id, client_id); |
149 IOSurfaceMap::iterator it = io_surfaces_.find(key); | 145 IOSurfaceMap::iterator it = io_surfaces_.find(key); |
Daniele Castagna
2015/05/08 18:58:30
io_surfaces_.erase(IOSurfaceMapKey(id, client_id))
reveman
2015/05/09 15:54:54
https://codereview.chromium.org/1131463004
| |
150 if (it != io_surfaces_.end()) | 146 if (it != io_surfaces_.end()) |
151 io_surfaces_.erase(it); | 147 io_surfaces_.erase(it); |
148 } | |
149 | |
150 IOSurfaceManager::GetInstance()->UnregisterIOSurface(id, client_id); | |
152 } | 151 } |
153 | 152 |
154 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { | 153 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { |
155 return this; | 154 return this; |
156 } | 155 } |
157 | 156 |
158 scoped_refptr<gfx::GLImage> | 157 scoped_refptr<gfx::GLImage> |
159 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( | 158 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( |
160 const gfx::GpuMemoryBufferHandle& handle, | 159 const gfx::GpuMemoryBufferHandle& handle, |
161 const gfx::Size& size, | 160 const gfx::Size& size, |
162 gfx::GpuMemoryBuffer::Format format, | 161 gfx::GpuMemoryBuffer::Format format, |
163 unsigned internalformat, | 162 unsigned internalformat, |
164 int client_id) { | 163 int client_id) { |
165 base::AutoLock lock(io_surfaces_lock_); | 164 base::AutoLock lock(io_surfaces_lock_); |
166 | 165 |
167 DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER); | 166 DCHECK_EQ(handle.type, gfx::IO_SURFACE_BUFFER); |
168 IOSurfaceMapKey key(handle.id, client_id); | 167 IOSurfaceMapKey key(handle.id, client_id); |
169 IOSurfaceMap::iterator it = io_surfaces_.find(key); | 168 IOSurfaceMap::iterator it = io_surfaces_.find(key); |
170 if (it == io_surfaces_.end()) | 169 if (it == io_surfaces_.end()) |
171 return scoped_refptr<gfx::GLImage>(); | 170 return scoped_refptr<gfx::GLImage>(); |
172 | 171 |
173 scoped_refptr<gfx::GLImageIOSurface> image(new gfx::GLImageIOSurface(size)); | 172 scoped_refptr<gfx::GLImageIOSurface> image(new gfx::GLImageIOSurface(size)); |
174 if (!image->Initialize(it->second.get())) | 173 if (!image->Initialize(it->second.get())) |
175 return scoped_refptr<gfx::GLImage>(); | 174 return scoped_refptr<gfx::GLImage>(); |
176 | 175 |
177 return image; | 176 return image; |
178 } | 177 } |
179 | 178 |
180 } // namespace content | 179 } // namespace content |
OLD | NEW |