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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 gfx::PluginWindowHandle surface_handle) { | 106 gfx::PluginWindowHandle surface_handle) { |
113 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; | 107 base::ScopedCFTypeRef<CFMutableDictionaryRef> properties; |
114 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, | 108 properties.reset(CFDictionaryCreateMutable(kCFAllocatorDefault, |
115 0, | 109 0, |
116 &kCFTypeDictionaryKeyCallBacks, | 110 &kCFTypeDictionaryKeyCallBacks, |
117 &kCFTypeDictionaryValueCallBacks)); | 111 &kCFTypeDictionaryValueCallBacks)); |
118 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); | 112 AddIntegerValue(properties, kIOSurfaceWidth, size.width()); |
119 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); | 113 AddIntegerValue(properties, kIOSurfaceHeight, size.height()); |
120 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); | 114 AddIntegerValue(properties, kIOSurfaceBytesPerElement, BytesPerPixel(format)); |
121 AddIntegerValue(properties, kIOSurfacePixelFormat, PixelFormat(format)); | 115 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 | 116 |
126 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); | 117 base::ScopedCFTypeRef<IOSurfaceRef> io_surface(IOSurfaceCreate(properties)); |
127 if (!io_surface) | 118 if (!io_surface) |
128 return gfx::GpuMemoryBufferHandle(); | 119 return gfx::GpuMemoryBufferHandle(); |
129 | 120 |
| 121 if (!IOSurfaceManager::GetInstance()->RegisterIOSurface(id, client_id, |
| 122 io_surface)) { |
| 123 return gfx::GpuMemoryBufferHandle(); |
| 124 } |
| 125 |
130 { | 126 { |
131 base::AutoLock lock(io_surfaces_lock_); | 127 base::AutoLock lock(io_surfaces_lock_); |
132 | 128 |
133 IOSurfaceMapKey key(id, client_id); | 129 IOSurfaceMapKey key(id, client_id); |
134 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); | 130 DCHECK(io_surfaces_.find(key) == io_surfaces_.end()); |
135 io_surfaces_[key] = io_surface; | 131 io_surfaces_[key] = io_surface; |
136 } | 132 } |
137 | 133 |
138 gfx::GpuMemoryBufferHandle handle; | 134 gfx::GpuMemoryBufferHandle handle; |
139 handle.type = gfx::IO_SURFACE_BUFFER; | 135 handle.type = gfx::IO_SURFACE_BUFFER; |
140 handle.id = id; | 136 handle.id = id; |
141 handle.io_surface_id = IOSurfaceGetID(io_surface); | |
142 return handle; | 137 return handle; |
143 } | 138 } |
144 | 139 |
145 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( | 140 void GpuMemoryBufferFactoryIOSurface::DestroyGpuMemoryBuffer( |
146 gfx::GpuMemoryBufferId id, | 141 gfx::GpuMemoryBufferId id, |
147 int client_id) { | 142 int client_id) { |
148 base::AutoLock lock(io_surfaces_lock_); | 143 { |
| 144 base::AutoLock lock(io_surfaces_lock_); |
149 | 145 |
150 IOSurfaceMapKey key(id, client_id); | 146 IOSurfaceMapKey key(id, client_id); |
151 DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); | 147 DCHECK(io_surfaces_.find(key) != io_surfaces_.end()); |
152 io_surfaces_.erase(key); | 148 io_surfaces_.erase(key); |
| 149 } |
| 150 |
| 151 IOSurfaceManager::GetInstance()->UnregisterIOSurface(id, client_id); |
153 } | 152 } |
154 | 153 |
155 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { | 154 gpu::ImageFactory* GpuMemoryBufferFactoryIOSurface::AsImageFactory() { |
156 return this; | 155 return this; |
157 } | 156 } |
158 | 157 |
159 scoped_refptr<gfx::GLImage> | 158 scoped_refptr<gfx::GLImage> |
160 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( | 159 GpuMemoryBufferFactoryIOSurface::CreateImageForGpuMemoryBuffer( |
161 const gfx::GpuMemoryBufferHandle& handle, | 160 const gfx::GpuMemoryBufferHandle& handle, |
162 const gfx::Size& size, | 161 const gfx::Size& size, |
(...skipping 10 matching lines...) Expand all Loading... |
173 | 172 |
174 scoped_refptr<gfx::GLImageIOSurface> image( | 173 scoped_refptr<gfx::GLImageIOSurface> image( |
175 new gfx::GLImageIOSurface(size, internalformat)); | 174 new gfx::GLImageIOSurface(size, internalformat)); |
176 if (!image->Initialize(it->second.get(), format)) | 175 if (!image->Initialize(it->second.get(), format)) |
177 return scoped_refptr<gfx::GLImage>(); | 176 return scoped_refptr<gfx::GLImage>(); |
178 | 177 |
179 return image; | 178 return image; |
180 } | 179 } |
181 | 180 |
182 } // namespace content | 181 } // namespace content |
OLD | NEW |