Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: ui/gl/io_surface_support_mac.cc

Issue 100053005: Allow AllocateGpuMemoryBuffer to be called from multiple threads. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gl/io_surface_support_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <dlfcn.h> 5 #include <dlfcn.h>
6 6
7 #include "base/memory/singleton.h" 7 #include "base/memory/singleton.h"
8 #include "ui/gl/io_surface_support_mac.h" 8 #include "ui/gl/io_surface_support_mac.h"
9 9
10 typedef CFTypeRef (*IOSurfaceCreateProcPtr)(CFDictionaryRef properties); 10 typedef CFTypeRef (*IOSurfaceCreateProcPtr)(CFDictionaryRef properties);
11 typedef uint32 (*IOSurfaceGetIDProcPtr)(CFTypeRef io_surface); 11 typedef uint32 (*IOSurfaceGetIDProcPtr)(CFTypeRef io_surface);
12 typedef CFTypeRef (*IOSurfaceLookupProcPtr)(uint32 io_surface_id); 12 typedef CFTypeRef (*IOSurfaceLookupProcPtr)(uint32 io_surface_id);
13 typedef mach_port_t (*IOSurfaceCreateMachPortProcPtr)(CFTypeRef io_surface); 13 typedef mach_port_t (*IOSurfaceCreateMachPortProcPtr)(CFTypeRef io_surface);
14 typedef CFTypeRef (*IOSurfaceLookupFromMachPortProcPtr)(mach_port_t port); 14 typedef CFTypeRef (*IOSurfaceLookupFromMachPortProcPtr)(mach_port_t port);
15 typedef size_t (*IOSurfaceGetWidthPtr)(CFTypeRef io_surface); 15 typedef size_t (*IOSurfaceGetWidthPtr)(CFTypeRef io_surface);
16 typedef size_t (*IOSurfaceGetHeightPtr)(CFTypeRef io_surface); 16 typedef size_t (*IOSurfaceGetHeightPtr)(CFTypeRef io_surface);
17 typedef size_t (*IOSurfaceGetBytesPerRowPtr)(CFTypeRef io_surface); 17 typedef size_t (*IOSurfaceGetBytesPerRowPtr)(CFTypeRef io_surface);
18 typedef void* (*IOSurfaceGetBaseAddressPtr)(CFTypeRef io_surface); 18 typedef void* (*IOSurfaceGetBaseAddressPtr)(CFTypeRef io_surface);
19 typedef IOReturn (*IOSurfaceLockPtr)(CFTypeRef io_surface, 19 typedef IOReturn (*IOSurfaceLockPtr)(CFTypeRef io_surface,
20 uint32 options, 20 uint32 options,
21 uint32* seed); 21 uint32* seed);
22 typedef IOReturn (*IOSurfaceUnlockPtr)(CFTypeRef io_surface, 22 typedef IOReturn (*IOSurfaceUnlockPtr)(CFTypeRef io_surface,
23 uint32 options, 23 uint32 options,
24 uint32* seed); 24 uint32* seed);
25 typedef void (*IOSurfaceDecrementUseCountPtr)(CFTypeRef io_surface);
26 typedef void (*IOSurfaceIncrementUseCountPtr)(CFTypeRef io_surface);
27 typedef Boolean (*IOSurfaceIsInUsePtr)(CFTypeRef io_surface);
25 28
26 typedef CGLError (*CGLTexImageIOSurface2DProcPtr)(CGLContextObj ctx, 29 typedef CGLError (*CGLTexImageIOSurface2DProcPtr)(CGLContextObj ctx,
27 GLenum target, 30 GLenum target,
28 GLenum internal_format, 31 GLenum internal_format,
29 GLsizei width, 32 GLsizei width,
30 GLsizei height, 33 GLsizei height,
31 GLenum format, 34 GLenum format,
32 GLenum type, 35 GLenum type,
33 CFTypeRef io_surface, 36 CFTypeRef io_surface,
34 GLuint plane); 37 GLuint plane);
(...skipping 25 matching lines...) Expand all
60 virtual size_t IOSurfaceGetBytesPerRow(CFTypeRef io_surface) OVERRIDE; 63 virtual size_t IOSurfaceGetBytesPerRow(CFTypeRef io_surface) OVERRIDE;
61 virtual void* IOSurfaceGetBaseAddress(CFTypeRef io_surface) OVERRIDE; 64 virtual void* IOSurfaceGetBaseAddress(CFTypeRef io_surface) OVERRIDE;
62 65
63 virtual IOReturn IOSurfaceLock(CFTypeRef io_surface, 66 virtual IOReturn IOSurfaceLock(CFTypeRef io_surface,
64 uint32 options, 67 uint32 options,
65 uint32* seed) OVERRIDE; 68 uint32* seed) OVERRIDE;
66 virtual IOReturn IOSurfaceUnlock(CFTypeRef io_surface, 69 virtual IOReturn IOSurfaceUnlock(CFTypeRef io_surface,
67 uint32 options, 70 uint32 options,
68 uint32* seed) OVERRIDE; 71 uint32* seed) OVERRIDE;
69 72
73 virtual void IOSurfaceDecrementUseCount(CFTypeRef io_surface) OVERRIDE;
74 virtual void IOSurfaceIncrementUseCount(CFTypeRef io_surface) OVERRIDE;
75 virtual Boolean IOSurfaceIsInUse(CFTypeRef io_surface) OVERRIDE;
76
70 virtual CGLError CGLTexImageIOSurface2D(CGLContextObj ctx, 77 virtual CGLError CGLTexImageIOSurface2D(CGLContextObj ctx,
71 GLenum target, 78 GLenum target,
72 GLenum internal_format, 79 GLenum internal_format,
73 GLsizei width, 80 GLsizei width,
74 GLsizei height, 81 GLsizei height,
75 GLenum format, 82 GLenum format,
76 GLenum type, 83 GLenum type,
77 CFTypeRef io_surface, 84 CFTypeRef io_surface,
78 GLuint plane) OVERRIDE; 85 GLuint plane) OVERRIDE;
79 86
(...skipping 18 matching lines...) Expand all
98 IOSurfaceGetIDProcPtr io_surface_get_id_; 105 IOSurfaceGetIDProcPtr io_surface_get_id_;
99 IOSurfaceLookupProcPtr io_surface_lookup_; 106 IOSurfaceLookupProcPtr io_surface_lookup_;
100 IOSurfaceCreateMachPortProcPtr io_surface_create_mach_port_; 107 IOSurfaceCreateMachPortProcPtr io_surface_create_mach_port_;
101 IOSurfaceLookupFromMachPortProcPtr io_surface_lookup_from_mach_port_; 108 IOSurfaceLookupFromMachPortProcPtr io_surface_lookup_from_mach_port_;
102 IOSurfaceGetWidthPtr io_surface_get_width_; 109 IOSurfaceGetWidthPtr io_surface_get_width_;
103 IOSurfaceGetHeightPtr io_surface_get_height_; 110 IOSurfaceGetHeightPtr io_surface_get_height_;
104 IOSurfaceGetBytesPerRowPtr io_surface_get_bytes_per_row_; 111 IOSurfaceGetBytesPerRowPtr io_surface_get_bytes_per_row_;
105 IOSurfaceGetBaseAddressPtr io_surface_get_base_address_; 112 IOSurfaceGetBaseAddressPtr io_surface_get_base_address_;
106 IOSurfaceLockPtr io_surface_lock_; 113 IOSurfaceLockPtr io_surface_lock_;
107 IOSurfaceUnlockPtr io_surface_unlock_; 114 IOSurfaceUnlockPtr io_surface_unlock_;
115 IOSurfaceDecrementUseCountPtr io_surface_decrement_use_count_;
116 IOSurfaceIncrementUseCountPtr io_surface_increment_use_count_;
117 IOSurfaceIsInUsePtr io_surface_is_in_use_;
118
108 CGLTexImageIOSurface2DProcPtr cgl_tex_image_io_surface_2d_; 119 CGLTexImageIOSurface2DProcPtr cgl_tex_image_io_surface_2d_;
109 CVPixelBufferGetIOSurfaceProcPtr cv_pixel_buffer_get_io_surface_; 120 CVPixelBufferGetIOSurfaceProcPtr cv_pixel_buffer_get_io_surface_;
110 bool initialized_successfully_; 121 bool initialized_successfully_;
111 122
112 friend struct DefaultSingletonTraits<IOSurfaceSupportImpl>; 123 friend struct DefaultSingletonTraits<IOSurfaceSupportImpl>;
113 DISALLOW_COPY_AND_ASSIGN(IOSurfaceSupportImpl); 124 DISALLOW_COPY_AND_ASSIGN(IOSurfaceSupportImpl);
114 }; 125 };
115 126
116 IOSurfaceSupportImpl* IOSurfaceSupportImpl::GetInstance() { 127 IOSurfaceSupportImpl* IOSurfaceSupportImpl::GetInstance() {
117 IOSurfaceSupportImpl* impl = Singleton<IOSurfaceSupportImpl>::get(); 128 IOSurfaceSupportImpl* impl = Singleton<IOSurfaceSupportImpl>::get();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 uint32* seed) { 194 uint32* seed) {
184 return io_surface_lock_(io_surface, options, seed); 195 return io_surface_lock_(io_surface, options, seed);
185 } 196 }
186 197
187 IOReturn IOSurfaceSupportImpl::IOSurfaceUnlock(CFTypeRef io_surface, 198 IOReturn IOSurfaceSupportImpl::IOSurfaceUnlock(CFTypeRef io_surface,
188 uint32 options, 199 uint32 options,
189 uint32* seed) { 200 uint32* seed) {
190 return io_surface_unlock_(io_surface, options, seed); 201 return io_surface_unlock_(io_surface, options, seed);
191 } 202 }
192 203
204 void IOSurfaceSupportImpl::IOSurfaceDecrementUseCount(CFTypeRef io_surface) {
205 io_surface_decrement_use_count_(io_surface);
206 }
207
208 void IOSurfaceSupportImpl::IOSurfaceIncrementUseCount(CFTypeRef io_surface) {
209 io_surface_increment_use_count_(io_surface);
210 }
211
212 Boolean IOSurfaceSupportImpl::IOSurfaceIsInUse(CFTypeRef io_surface) {
213 return io_surface_is_in_use_(io_surface);
214 }
215
216
193 CGLError IOSurfaceSupportImpl::CGLTexImageIOSurface2D(CGLContextObj ctx, 217 CGLError IOSurfaceSupportImpl::CGLTexImageIOSurface2D(CGLContextObj ctx,
194 GLenum target, 218 GLenum target,
195 GLenum internal_format, 219 GLenum internal_format,
196 GLsizei width, 220 GLsizei width,
197 GLsizei height, 221 GLsizei height,
198 GLenum format, 222 GLenum format,
199 GLenum type, 223 GLenum type,
200 CFTypeRef io_surface, 224 CFTypeRef io_surface,
201 GLuint plane) { 225 GLuint plane) {
202 return cgl_tex_image_io_surface_2d_(ctx, 226 return cgl_tex_image_io_surface_2d_(ctx,
(...skipping 25 matching lines...) Expand all
228 io_surface_get_id_(NULL), 252 io_surface_get_id_(NULL),
229 io_surface_lookup_(NULL), 253 io_surface_lookup_(NULL),
230 io_surface_create_mach_port_(NULL), 254 io_surface_create_mach_port_(NULL),
231 io_surface_lookup_from_mach_port_(NULL), 255 io_surface_lookup_from_mach_port_(NULL),
232 io_surface_get_width_(NULL), 256 io_surface_get_width_(NULL),
233 io_surface_get_height_(NULL), 257 io_surface_get_height_(NULL),
234 io_surface_get_bytes_per_row_(NULL), 258 io_surface_get_bytes_per_row_(NULL),
235 io_surface_get_base_address_(NULL), 259 io_surface_get_base_address_(NULL),
236 io_surface_lock_(NULL), 260 io_surface_lock_(NULL),
237 io_surface_unlock_(NULL), 261 io_surface_unlock_(NULL),
262 io_surface_decrement_use_count_(NULL),
263 io_surface_increment_use_count_(NULL),
264 io_surface_is_in_use_(NULL),
238 cgl_tex_image_io_surface_2d_(NULL), 265 cgl_tex_image_io_surface_2d_(NULL),
239 cv_pixel_buffer_get_io_surface_(NULL), 266 cv_pixel_buffer_get_io_surface_(NULL),
240 initialized_successfully_(false) { 267 initialized_successfully_(false) {
241 iosurface_handle_ = dlopen( 268 iosurface_handle_ = dlopen(
242 "/System/Library/Frameworks/IOSurface.framework/IOSurface", 269 "/System/Library/Frameworks/IOSurface.framework/IOSurface",
243 RTLD_LAZY | RTLD_LOCAL); 270 RTLD_LAZY | RTLD_LOCAL);
244 opengl_handle_ = dlopen( 271 opengl_handle_ = dlopen(
245 "/System/Library/Frameworks/OpenGL.framework/OpenGL", 272 "/System/Library/Frameworks/OpenGL.framework/OpenGL",
246 RTLD_LAZY | RTLD_LOCAL); 273 RTLD_LAZY | RTLD_LOCAL);
247 core_video_handle_ = dlopen( 274 core_video_handle_ = dlopen(
(...skipping 24 matching lines...) Expand all
272 void* io_surface_get_width_ptr = 299 void* io_surface_get_width_ptr =
273 dlsym(iosurface_handle_, "IOSurfaceGetWidth"); 300 dlsym(iosurface_handle_, "IOSurfaceGetWidth");
274 void* io_surface_get_height_ptr = 301 void* io_surface_get_height_ptr =
275 dlsym(iosurface_handle_, "IOSurfaceGetHeight"); 302 dlsym(iosurface_handle_, "IOSurfaceGetHeight");
276 void* io_surface_get_bytes_per_row_ptr = 303 void* io_surface_get_bytes_per_row_ptr =
277 dlsym(iosurface_handle_, "IOSurfaceGetBytesPerRow"); 304 dlsym(iosurface_handle_, "IOSurfaceGetBytesPerRow");
278 void* io_surface_get_base_address_ptr = 305 void* io_surface_get_base_address_ptr =
279 dlsym(iosurface_handle_, "IOSurfaceGetBaseAddress"); 306 dlsym(iosurface_handle_, "IOSurfaceGetBaseAddress");
280 void* io_surface_lock_ptr = dlsym(iosurface_handle_, "IOSurfaceLock"); 307 void* io_surface_lock_ptr = dlsym(iosurface_handle_, "IOSurfaceLock");
281 void* io_surface_unlock_ptr = dlsym(iosurface_handle_, "IOSurfaceUnlock"); 308 void* io_surface_unlock_ptr = dlsym(iosurface_handle_, "IOSurfaceUnlock");
309 void* io_surface_decrement_use_count_ptr =
310 dlsym(iosurface_handle_, "IOSurfaceDecrementUseCount");
311 void* io_surface_increment_use_count_ptr =
312 dlsym(iosurface_handle_, "IOSurfaceIncrementUseCount");
313 void* io_surface_is_in_use_ptr =
314 dlsym(iosurface_handle_, "IOSurfaceIsInUse");
315
282 void* tex_image_io_surface_2d_ptr = 316 void* tex_image_io_surface_2d_ptr =
283 dlsym(opengl_handle_, "CGLTexImageIOSurface2D"); 317 dlsym(opengl_handle_, "CGLTexImageIOSurface2D");
284 void* cv_pixel_buffer_get_io_surface = 318 void* cv_pixel_buffer_get_io_surface =
285 dlsym(core_video_handle_, "CVPixelBufferGetIOSurface"); 319 dlsym(core_video_handle_, "CVPixelBufferGetIOSurface");
286 if (!surface_width_ptr || 320 if (!surface_width_ptr ||
287 !surface_height_ptr || 321 !surface_height_ptr ||
288 !surface_bytes_per_element_ptr || 322 !surface_bytes_per_element_ptr ||
289 !surface_pixel_format_ptr || 323 !surface_pixel_format_ptr ||
290 !surface_is_global_ptr || 324 !surface_is_global_ptr ||
291 !surface_create_ptr || 325 !surface_create_ptr ||
292 !surface_get_id_ptr || 326 !surface_get_id_ptr ||
293 !surface_lookup_ptr || 327 !surface_lookup_ptr ||
294 !surface_create_mach_port_ptr || 328 !surface_create_mach_port_ptr ||
295 !surface_lookup_from_mach_port_ptr || 329 !surface_lookup_from_mach_port_ptr ||
296 !io_surface_get_width_ptr || 330 !io_surface_get_width_ptr ||
297 !io_surface_get_height_ptr || 331 !io_surface_get_height_ptr ||
298 !io_surface_get_bytes_per_row_ptr || 332 !io_surface_get_bytes_per_row_ptr ||
299 !io_surface_get_base_address_ptr || 333 !io_surface_get_base_address_ptr ||
300 !io_surface_lock_ptr || 334 !io_surface_lock_ptr ||
301 !io_surface_unlock_ptr || 335 !io_surface_unlock_ptr ||
336 !io_surface_decrement_use_count_ptr ||
337 !io_surface_increment_use_count_ptr ||
338 !io_surface_is_in_use_ptr ||
302 !tex_image_io_surface_2d_ptr || 339 !tex_image_io_surface_2d_ptr ||
303 !cv_pixel_buffer_get_io_surface) { 340 !cv_pixel_buffer_get_io_surface) {
304 CloseLibraryHandles(); 341 CloseLibraryHandles();
305 return; 342 return;
306 } 343 }
307 344
308 k_io_surface_width_ = *static_cast<CFStringRef*>(surface_width_ptr); 345 k_io_surface_width_ = *static_cast<CFStringRef*>(surface_width_ptr);
309 k_io_surface_height_ = *static_cast<CFStringRef*>(surface_height_ptr); 346 k_io_surface_height_ = *static_cast<CFStringRef*>(surface_height_ptr);
310 k_io_surface_bytes_per_element_ = 347 k_io_surface_bytes_per_element_ =
311 *static_cast<CFStringRef*>(surface_bytes_per_element_ptr); 348 *static_cast<CFStringRef*>(surface_bytes_per_element_ptr);
(...skipping 20 matching lines...) Expand all
332 io_surface_get_height_ptr); 369 io_surface_get_height_ptr);
333 io_surface_get_bytes_per_row_ = 370 io_surface_get_bytes_per_row_ =
334 reinterpret_cast<IOSurfaceGetBytesPerRowPtr>( 371 reinterpret_cast<IOSurfaceGetBytesPerRowPtr>(
335 io_surface_get_bytes_per_row_ptr); 372 io_surface_get_bytes_per_row_ptr);
336 io_surface_get_base_address_ = 373 io_surface_get_base_address_ =
337 reinterpret_cast<IOSurfaceGetBaseAddressPtr>( 374 reinterpret_cast<IOSurfaceGetBaseAddressPtr>(
338 io_surface_get_base_address_ptr); 375 io_surface_get_base_address_ptr);
339 io_surface_lock_ = reinterpret_cast<IOSurfaceLockPtr>(io_surface_lock_ptr); 376 io_surface_lock_ = reinterpret_cast<IOSurfaceLockPtr>(io_surface_lock_ptr);
340 io_surface_unlock_ = reinterpret_cast<IOSurfaceUnlockPtr>( 377 io_surface_unlock_ = reinterpret_cast<IOSurfaceUnlockPtr>(
341 io_surface_unlock_ptr); 378 io_surface_unlock_ptr);
379 io_surface_decrement_use_count_ =
380 reinterpret_cast<IOSurfaceDecrementUseCountPtr>(
381 io_surface_decrement_use_count_ptr);
382 io_surface_increment_use_count_ =
383 reinterpret_cast<IOSurfaceIncrementUseCountPtr>(
384 io_surface_increment_use_count_ptr);
385 io_surface_is_in_use_ =
386 reinterpret_cast<IOSurfaceIsInUsePtr>(io_surface_is_in_use_ptr);
342 cgl_tex_image_io_surface_2d_ = 387 cgl_tex_image_io_surface_2d_ =
343 reinterpret_cast<CGLTexImageIOSurface2DProcPtr>( 388 reinterpret_cast<CGLTexImageIOSurface2DProcPtr>(
344 tex_image_io_surface_2d_ptr); 389 tex_image_io_surface_2d_ptr);
345 cv_pixel_buffer_get_io_surface_ = 390 cv_pixel_buffer_get_io_surface_ =
346 reinterpret_cast<CVPixelBufferGetIOSurfaceProcPtr>( 391 reinterpret_cast<CVPixelBufferGetIOSurfaceProcPtr>(
347 cv_pixel_buffer_get_io_surface); 392 cv_pixel_buffer_get_io_surface);
348 initialized_successfully_ = true; 393 initialized_successfully_ = true;
349 } 394 }
350 395
351 IOSurfaceSupportImpl::~IOSurfaceSupportImpl() { 396 IOSurfaceSupportImpl::~IOSurfaceSupportImpl() {
(...skipping 18 matching lines...) Expand all
370 IOSurfaceSupport* IOSurfaceSupport::Initialize() { 415 IOSurfaceSupport* IOSurfaceSupport::Initialize() {
371 return IOSurfaceSupportImpl::GetInstance(); 416 return IOSurfaceSupportImpl::GetInstance();
372 } 417 }
373 418
374 IOSurfaceSupport::IOSurfaceSupport() { 419 IOSurfaceSupport::IOSurfaceSupport() {
375 } 420 }
376 421
377 IOSurfaceSupport::~IOSurfaceSupport() { 422 IOSurfaceSupport::~IOSurfaceSupport() {
378 } 423 }
379 424
OLDNEW
« no previous file with comments | « ui/gl/io_surface_support_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698