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