Commit 0a052383 authored by Florent Pillet's avatar Florent Pillet Committed by Felix Paul Kühne

caopengllayer: improved main thread synchronization and locking

Grouping of 2 sync calls into one, use of CATransaction lock / unlock instead of being / commit and introduction of GCD
Signed-off-by: default avatarFelix Paul Kühne <fkuehne@videolan.org>
parent 4bb97e4a
...@@ -142,28 +142,30 @@ static int Open (vlc_object_t *p_this) ...@@ -142,28 +142,30 @@ static int Open (vlc_object_t *p_this)
/* store for later, released in Close() */ /* store for later, released in Close() */
sys->container = [container retain]; sys->container = [container retain];
[VLCCAOpenGLLayer performSelectorOnMainThread:@selector(getNewView:) withObject:[NSValue valueWithPointer:&sys->cgLayer] waitUntilDone:YES]; dispatch_sync(dispatch_get_main_queue(), ^{
[CATransaction begin];
sys->cgLayer = [[VLCCAOpenGLLayer alloc] init];
[sys->cgLayer setVoutDisplay:vd];
[sys->cgLayer display]; // TODO: Find a better way to wait until we get a context
if ([container respondsToSelector:@selector(addVoutLayer:)]) {
msg_Dbg(vd, "container implements implicit protocol");
[container addVoutLayer:sys->cgLayer];
} else if ([container respondsToSelector:@selector(addSublayer:)] || [container isKindOfClass:[CALayer class]]) {
msg_Dbg(vd, "container doesn't implement implicit protocol, fallback mode used");
[container addSublayer:sys->cgLayer];
} else {
msg_Err(vd, "Provided NSObject container isn't compatible");
[sys->cgLayer release];
sys->cgLayer = nil;
}
[CATransaction commit];
});
if (!sys->cgLayer) if (!sys->cgLayer)
goto bailout; goto bailout;
[sys->cgLayer setVoutDisplay:vd];
// TODO: Find a better way to wait until we get a context
[sys->cgLayer performSelectorOnMainThread:@selector(display)
withObject:nil waitUntilDone:YES];
assert(sys->glContext); assert(sys->glContext);
if ([container respondsToSelector:@selector(addVoutLayer:)]) {
msg_Dbg(vd, "container implements implicit protocol");
[container addVoutLayer:sys->cgLayer];
} else if ([container respondsToSelector:@selector(addSublayer:)] || [container isKindOfClass:[CALayer class]]) {
msg_Dbg(vd, "container doesn't implement implicit protocol, fallback mode used");
[container addSublayer:sys->cgLayer];
} else {
msg_Err(vd, "Provided NSObject container isn't compatible");
goto bailout;
}
/* Initialize common OpenGL video display */ /* Initialize common OpenGL video display */
sys->gl.lock = OpenglLock; sys->gl.lock = OpenglLock;
sys->gl.unlock = OpenglUnlock; sys->gl.unlock = OpenglUnlock;
...@@ -200,7 +202,6 @@ static int Open (vlc_object_t *p_this) ...@@ -200,7 +202,6 @@ static int Open (vlc_object_t *p_this)
vout_display_SendEventFullscreen(vd, false); vout_display_SendEventFullscreen(vd, false);
vout_display_SendEventDisplaySize(vd, (int)outputSize.width, (int)outputSize.height, false); vout_display_SendEventDisplaySize(vd, (int)outputSize.width, (int)outputSize.height, false);
[pool release]; [pool release];
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -269,7 +270,6 @@ static void PictureDisplay (vout_display_t *vd, picture_t *pic, subpicture_t *su ...@@ -269,7 +270,6 @@ static void PictureDisplay (vout_display_t *vd, picture_t *pic, subpicture_t *su
* and makes sure the picture is actually displayed. */ * and makes sure the picture is actually displayed. */
[sys->cgLayer display]; [sys->cgLayer display];
[CATransaction flush]; [CATransaction flush];
sys->b_frame_available = NO;
} }
picture_Release(pic); picture_Release(pic);
...@@ -307,7 +307,9 @@ static int Control (vout_display_t *vd, int query, va_list ap) ...@@ -307,7 +307,9 @@ static int Control (vout_display_t *vd, int query, va_list ap)
/* we always use our current frame here */ /* we always use our current frame here */
vout_display_cfg_t cfg_tmp = *cfg; vout_display_cfg_t cfg_tmp = *cfg;
[CATransaction lock];
CGRect bounds = [sys->cgLayer bounds]; CGRect bounds = [sys->cgLayer bounds];
[CATransaction unlock];
cfg_tmp.display.width = bounds.size.width; cfg_tmp.display.width = bounds.size.width;
cfg_tmp.display.height = bounds.size.height; cfg_tmp.display.height = bounds.size.height;
...@@ -385,20 +387,14 @@ static void *OurGetProcAddress (vlc_gl_t *gl, const char *name) ...@@ -385,20 +387,14 @@ static void *OurGetProcAddress (vlc_gl_t *gl, const char *name)
*****************************************************************************/ *****************************************************************************/
@implementation VLCCAOpenGLLayer @implementation VLCCAOpenGLLayer
+ (void)getNewView:(NSValue *)value
{
id *ret = [value pointerValue];
*ret = [[self alloc] init];
}
- (id)init { - (id)init {
self = [super init]; self = [super init];
if (self) { if (self) {
[CATransaction begin]; [CATransaction lock];
[self setAutoresizingMask: kCALayerWidthSizable | kCALayerHeightSizable]; [self setAutoresizingMask: kCALayerWidthSizable | kCALayerHeightSizable];
[self setAsynchronous: NO]; self.asynchronous = NO;
[CATransaction commit]; [CATransaction unlock];
} }
return self; return self;
...@@ -413,8 +409,9 @@ static void *OurGetProcAddress (vlc_gl_t *gl, const char *name) ...@@ -413,8 +409,9 @@ static void *OurGetProcAddress (vlc_gl_t *gl, const char *name)
{ {
[super resizeWithOldSuperlayerSize: size]; [super resizeWithOldSuperlayerSize: size];
CGRect bounds = self.bounds;
if (_vd) if (_vd)
vout_display_SendEventDisplaySize(_vd, self.bounds.size.width, self.bounds.size.height, _vd->cfg->is_fullscreen); vout_display_SendEventDisplaySize(_vd, bounds.size.width, bounds.size.height, _vd->cfg->is_fullscreen);
} }
- (BOOL)canDrawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp - (BOOL)canDrawInCGLContext:(CGLContextObj)glContext pixelFormat:(CGLPixelFormatObj)pixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp
...@@ -441,6 +438,7 @@ static void *OurGetProcAddress (vlc_gl_t *gl, const char *name) ...@@ -441,6 +438,7 @@ static void *OurGetProcAddress (vlc_gl_t *gl, const char *name)
// flush is also done by this method, no need to call super // flush is also done by this method, no need to call super
vout_display_opengl_Display (sys->vgl, &_vd->source); vout_display_opengl_Display (sys->vgl, &_vd->source);
sys->b_frame_available = NO;
} }
- (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment