]> git.sesse.net Git - vlc/commitdiff
ios_vout2: fix crash when trying to draw OpenGL changes while the app is in the backg...
authorFelix Paul Kühne <fkuehne@videolan.org>
Thu, 28 Mar 2013 11:34:46 +0000 (12:34 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Sun, 19 May 2013 10:12:38 +0000 (12:12 +0200)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/video_output/ios2.m

index a18f8f2003f273050341a43299461171725e9a09..0774550b7e5a743d43e9f83d2259dc284ebf0907 100644 (file)
@@ -89,9 +89,11 @@ vlc_module_end ()
     GLuint _frameBuffer;
 
     BOOL _bufferNeedReset;
+    BOOL _appActive;
 }
 @property (readwrite) vout_display_t* voutDisplay;
 @property (readonly) EAGLContext* eaglContext;
+@property (readonly) BOOL isAppActive;
 
 - (void)createBuffers;
 - (void)destroyBuffers;
@@ -189,6 +191,8 @@ static int Open(vlc_object_t *this)
     vd->control = Control;
 
     /* */
+    [[NSNotificationCenter defaultCenter] addObserver:sys->glESView selector:@selector(applicationStateChanged:) name:UIApplicationWillResignActiveNotification object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:sys->glESView selector:@selector(applicationStateChanged:) name:UIApplicationDidBecomeActiveNotification object:nil];
     [sys->glESView performSelectorOnMainThread:@selector(reshape) withObject:nil waitUntilDone:YES];
 
     [autoreleasePool release];
@@ -311,7 +315,8 @@ static void PictureDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *sub
 {
     vout_display_sys_t *sys = vd->sys;
     sys->has_first_frame = true;
-    vout_display_opengl_Display(sys->vgl, &vd->source);
+    if ([sys->glESView isAppActive])
+        vout_display_opengl_Display(sys->vgl, &vd->source);
 
     picture_Release(pic);
 
@@ -324,7 +329,8 @@ static void PictureRender(vout_display_t *vd, picture_t *pic, subpicture_t *subp
 
     vout_display_sys_t *sys = vd->sys;
 
-    vout_display_opengl_Prepare(sys->vgl, pic, subpicture);
+    if ([sys->glESView isAppActive])
+        vout_display_opengl_Prepare(sys->vgl, pic, subpicture);
 }
 
 static picture_pool_t *PicturePool(vout_display_t *vd, unsigned requested_count)
@@ -350,14 +356,15 @@ static int OpenglESClean(vlc_gl_t *gl)
 static void OpenglESSwap(vlc_gl_t *gl)
 {
     vout_display_sys_t *sys = (vout_display_sys_t *)gl->sys;
-    [[sys->glESView eaglContext] presentRenderbuffer:GL_RENDERBUFFER];
+    if ([sys->glESView isAppActive])
+        [[sys->glESView eaglContext] presentRenderbuffer:GL_RENDERBUFFER];
 }
 
 /*****************************************************************************
  * Our UIView object
  *****************************************************************************/
 @implementation VLCOpenGLES2VideoView
-@synthesize voutDisplay = _voutDisplay, eaglContext = _eaglContext;
+@synthesize voutDisplay = _voutDisplay, eaglContext = _eaglContext, isAppActive = _appActive;
 
 + (Class)layerClass
 {
@@ -384,6 +391,8 @@ static void OpenglESSwap(vlc_gl_t *gl)
     [self performSelectorOnMainThread:@selector(reshape) withObject:nil waitUntilDone:NO];
     [self setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
 
+    _appActive = ([UIApplication sharedApplication].applicationState == UIApplicationStateActive);
+
     return self;
 }
 
@@ -484,6 +493,14 @@ static void OpenglESSwap(vlc_gl_t *gl)
     glViewport(place.x, place.y, place.width, place.height);
 }
 
+- (void)applicationStateChanged:(NSNotification *)notification
+{
+    if ([[notification name] isEqualToString: UIApplicationWillResignActiveNotification])
+        _appActive = NO;
+    else
+        _appActive = YES;
+}
+
 - (void)updateConstraints
 {
     [self reshape];