11/*
22 msosxdisplay.m
33 Copyright (C) 2011 Belledonne Communications, Grenoble, France
4-
4+
55 This program is free software; you can redistribute it and/or
66 modify it under the terms of the GNU General Public License
77 as published by the Free Software Foundation; either version 2
88 of the License, or (at your option) any later version.
9-
9+
1010 This program is distributed in the hope that it will be useful,
1111 but WITHOUT ANY WARRANTY; without even the implied warranty of
1212 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313 GNU General Public License for more details.
14-
14+
1515 You should have received a copy of the GNU General Public License
1616 along with this program; if not, write to the Free Software
1717 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -55,12 +55,12 @@ - (id)init {
5555self->prevBounds = CGRectMake (0 , 0 , 0 , 0 );
5656self->lock = [[NSRecursiveLock alloc ] init ];
5757self->display_helper = ogl_display_new ();
58-
58+
5959[self setOpaque: YES ];
6060[self setAsynchronous: NO ];
6161[self setAutoresizingMask: kCALayerWidthSizable | kCALayerHeightSizable ];
6262[self setNeedsDisplayOnBoundsChange: YES ];
63-
63+
6464// FBO Support
6565GLint numPixelFormats = 0 ;
6666CGLPixelFormatAttribute attributes[] =
@@ -70,19 +70,19 @@ - (id)init {
7070kCGLPFADoubleBuffer ,
71710
7272};
73-
73+
7474CGLChoosePixelFormat (attributes, &cglPixelFormat, &numPixelFormats);
7575assert (cglPixelFormat);
76-
76+
7777cglContext = [super copyCGLContextForPixelFormat: cglPixelFormat];
7878assert (cglContext);
79-
79+
8080CGLContextObj savedContext = CGLGetCurrentContext ();
8181CGLSetCurrentContext (cglContext);
8282CGLLockContext (cglContext);
83-
83+
8484ogl_display_init (display_helper, prevBounds.size .width , prevBounds.size .height );
85-
85+
8686CGLUnlockContext (cglContext);
8787CGLSetCurrentContext (savedContext);
8888}
@@ -93,17 +93,17 @@ - (void)dealloc {
9393CGLContextObj savedContext = CGLGetCurrentContext ();
9494CGLSetCurrentContext (cglContext);
9595CGLLockContext (cglContext);
96-
96+
9797ogl_display_uninit (display_helper, TRUE );
9898ogl_display_free (display_helper);
99-
99+
100100CGLUnlockContext (cglContext);
101101CGLSetCurrentContext (savedContext);
102-
102+
103103[self releaseCGLContext: cglContext];
104104[self releaseCGLPixelFormat: cglPixelFormat];
105105[lock release ];
106-
106+
107107[super dealloc ];
108108}
109109
@@ -125,31 +125,31 @@ - (void)releaseCGLContext:(CGLContextObj)glContext {
125125CGLReleaseContext (cglContext);
126126}
127127
128- - (void )drawInCGLContext : (CGLContextObj)glContext
129- pixelFormat : (CGLPixelFormatObj)pixelFormat
130- forLayerTime : (CFTimeInterval)timeInterval
131- displayTime : (const CVTimeStamp *)timeStamp {
128+ - (void )drawInCGLContext : (CGLContextObj)glContext
129+ pixelFormat : (CGLPixelFormatObj)pixelFormat
130+ forLayerTime : (CFTimeInterval)timeInterval
131+ displayTime : (const CVTimeStamp *)timeStamp {
132132if ([lock tryLock ]) {
133133CGLContextObj savedContext = CGLGetCurrentContext ();
134134CGLSetCurrentContext (cglContext);
135135CGLLockContext (cglContext);
136-
136+
137137if (!CGRectEqualToRect (prevBounds, [self bounds ])) {
138138prevBounds = [self bounds ];
139139ogl_display_set_size (display_helper, prevBounds.size .width , prevBounds.size .height );
140140}
141-
141+
142142glClearColor (0 , 0 , 0 , 0 );
143143glClear (GL_COLOR_BUFFER_BIT);
144144ogl_display_render (display_helper, 0 );
145-
145+
146146CGLUnlockContext (cglContext);
147147CGLSetCurrentContext (savedContext);
148148CGLFlushDrawable (cglContext);
149-
150- [super drawInCGLContext: glContext
151- pixelFormat: pixelFormat
152- forLayerTime: timeInterval
149+
150+ [super drawInCGLContext: glContext
151+ pixelFormat: pixelFormat
152+ forLayerTime: timeInterval
153153displayTime: timeStamp];
154154[lock unlock ];
155155}
@@ -219,7 +219,7 @@ - (id)init {
219219
220220- (void )resetContainers {
221221[glLayer removeFromSuperlayer ];
222-
222+
223223if (window != nil ) {
224224if (closeWindow) {
225225[window close ];
@@ -241,14 +241,14 @@ - (void)setWindow:(NSWindow*)awindow {
241241if (window == awindow) {
242242return ;
243243}
244-
244+
245245[self resetContainers ];
246-
246+
247247if (awindow != nil ) {
248248window = [awindow retain ];
249249[glLayer setFrame: [[window.contentView layer ] bounds ]];
250250[[window.contentView layer ] addSublayer: glLayer];
251-
251+
252252glLayer.sourceSize = CGSizeMake (0 , 0 ); // Force window resize
253253}
254254}
@@ -257,9 +257,9 @@ - (void)setView:(NSView*)aview {
257257if (view == aview) {
258258return ;
259259}
260-
260+
261261[self resetContainers ];
262-
262+
263263if (aview != nil ) {
264264view = [aview retain ];
265265[view setWantsLayer: YES ];
@@ -272,9 +272,9 @@ - (void)setLayer:(CALayer*)alayer {
272272if (layer == alayer) {
273273return ;
274274}
275-
275+
276276[self resetContainers ];
277-
277+
278278if (alayer != nil ) {
279279layer = [alayer retain ];
280280[glLayer setFrame: [layer bounds ]];
@@ -294,24 +294,25 @@ - (void)createWindowIfNeeded {
294294CGFloat xPos = NSWidth ([[awindow screen ] frame ])/2 - NSWidth ([awindow frame ])/2 ;
295295CGFloat yPos = NSHeight ([[awindow screen ] frame ])/2 - NSHeight ([awindow frame ])/2 ;
296296[awindow setFrame: NSMakeRect (xPos, yPos, NSWidth ([awindow frame ]), NSHeight ([awindow frame ])) display: YES ];
297-
297+
298298// Init view
299299NSView *innerView = [[NSView alloc ] initWithFrame: [window frame ]];
300300[innerView setWantsLayer: YES ];
301301[innerView.layer setAutoresizingMask: kCALayerWidthSizable | kCALayerHeightSizable ];
302302[innerView.layer setNeedsDisplayOnBoundsChange: YES ];
303303[awindow setContentView: innerView];
304304[innerView release ];
305-
305+
306306self.window = awindow;
307307self.closeWindow = TRUE ;
308308}
309309}
310310
311311- (void )dealloc {
312312[self resetContainers ];
313+ [self .glLayer release ];
313314self.glLayer = nil ;
314-
315+
315316[super dealloc ];
316317}
317318
@@ -336,7 +337,7 @@ static void osx_gl_process(MSFilter* f) {
336337OSXDisplay* thiz = (OSXDisplay*) f->data ;
337338mblk_t * m = 0 ;
338339MSPicture pic;
339-
340+
340341NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc ] init ];
341342
342343if ((m=ms_queue_peek_last (f->inputs [0 ])) != NULL ) {
@@ -345,14 +346,14 @@ static void osx_gl_process(MSFilter* f) {
345346// Source size change?
346347if (pic.w != thiz.glLayer .sourceSize .width || pic.h != thiz.glLayer .sourceSize .height ) {
347348thiz.glLayer .sourceSize = CGSizeMake (pic.w , pic.h );
348-
349+
349350// Force window resize
350351if (thiz.window != nil ) {
351352[thiz.glLayer performSelectorOnMainThread: @selector (resizeToWindow: ) withObject: thiz.window waitUntilDone: FALSE ];
352353}
353354}
354355ogl_display_set_yuv_to_display (thiz.glLayer ->display_helper , m);
355-
356+
356357// Force redraw
357358[thiz.glLayer performSelectorOnMainThread: @selector (setNeedsDisplay ) withObject: nil waitUntilDone: FALSE ];
358359}
@@ -367,7 +368,7 @@ static void osx_gl_process(MSFilter* f) {
367368if (thiz != nil ) {
368369if (!mblk_get_precious_flag (m)) ms_yuv_buf_mirror (&pic);
369370ogl_display_set_preview_yuv_to_display (thiz.glLayer ->display_helper , m);
370-
371+
371372// Force redraw
372373[thiz.glLayer performSelectorOnMainThread: @selector (setNeedsDisplay ) withObject: nil waitUntilDone: FALSE ];
373374}
@@ -396,7 +397,7 @@ static int osx_gl_set_vsize(MSFilter* f, void* arg) {
396397static int osx_gl_get_native_window_id (MSFilter* f, void * arg) {
397398OSXDisplay* thiz = (OSXDisplay*) f->data ;
398399unsigned long *winId = (unsigned long *)arg;
399- int ret = -1 ;
400+ int ret = -1 ;
400401if (thiz != nil ) {
401402if (thiz.window != nil ) {
402403*winId = (unsigned long )thiz.window ;
@@ -407,7 +408,7 @@ static int osx_gl_get_native_window_id(MSFilter* f, void* arg) {
407408} else if (thiz.layer != nil ) {
408409*winId = (unsigned long )thiz.layer ;
409410ret = 0 ;
410- } else if (thiz.autoWindow ) {
411+ } else if (thiz.autoWindow ) {
411412*winId = MS_FILTER_VIDEO_AUTO;
412413ret = 0 ;
413414} else {
@@ -422,7 +423,7 @@ static int osx_gl_set_native_window_id(MSFilter* f, void* arg) {
422423OSXDisplay* thiz = (OSXDisplay*) f->data ;
423424unsigned long winId = *((unsigned long *)arg);
424425NSObject *obj = *((NSObject **)arg);
425- int ret = -1 ;
426+ int ret = -1 ;
426427if (thiz != nil ) {
427428NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc ] init ];
428429if (winId != MS_FILTER_VIDEO_AUTO && winId != MS_FILTER_VIDEO_NONE) {
@@ -441,7 +442,7 @@ static int osx_gl_set_native_window_id(MSFilter* f, void* arg) {
441442thiz.autoWindow = FALSE ;
442443} else {
443444thiz.autoWindow = TRUE ;
444- }
445+ }
445446[thiz performSelectorOnMainThread: @selector (resetContainers ) withObject: nil waitUntilDone: NO ];
446447ret = 0 ;
447448}
0 commit comments