[vlc-devel] [PATCH 5/6] VLCVideoUIView: handle application backgrounding

Alexandre Janniaux ajanni at videolabs.io
Fri Feb 5 09:01:56 UTC 2021


When the application is moved to the background, iOS require that no
OpenGL drawing commands are sent to the GPU. Previous ios.m
implementation and current VLCOpenGLES2VideoView have code to handle
this case, flushing the commandlist and disabling the OpenGL commands,
but it is unfit with the design of vlc_gl_t since vlc_gl_MakeCurrent
would only fail and drawing would still happen.

In addition, making vlc_gl_MakeCurrent fail because of this reason would
prevent using it when closing the display, which should never happen
since there are no other moments when we can release the resources.

Instead, signal the core that we should not draw anymore with the
callbacks.
---
 modules/video_output/apple/VLCVideoUIView.m | 28 +++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/modules/video_output/apple/VLCVideoUIView.m b/modules/video_output/apple/VLCVideoUIView.m
index 3a4c749816..b2828da8c4 100644
--- a/modules/video_output/apple/VLCVideoUIView.m
+++ b/modules/video_output/apple/VLCVideoUIView.m
@@ -90,6 +90,7 @@
 - (void)tapRecognized:(UITapGestureRecognizer *)tapRecognizer;
 - (void)enable;
 - (void)disable;
+- (void)applicationStateChanged:(NSNotification*)notification;
 @end
 
 /*****************************************************************************
@@ -120,6 +121,15 @@
     _tapRecognizer = [[UITapGestureRecognizer alloc]
         initWithTarget:self action:@selector(tapRecognized:)];
 
+    [[NSNotificationCenter defaultCenter] addObserver:self
+                                             selector:@selector(applicationStateChanged:)
+                                                 name:UIApplicationWillEnterForegroundNotification
+                                               object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self
+                                             selector:@selector(applicationStateChanged:)
+                                                 name:UIApplicationWillResignActiveNotification
+                                               object:nil];
+
     return self;
 }
 
@@ -295,6 +305,24 @@ end:
     [self reshape];
 }
 
+- (void)applicationStateChanged:(NSNotification *)notification
+{
+    vlc_mutex_lock(&_mutex);
+
+    if (_wnd == NULL)
+    {
+        vlc_mutex_unlock(&_mutex);
+        return;
+    }
+
+    if ([[notification name] isEqualToString:UIApplicationWillEnterForegroundNotification])
+        vout_window_ReportRenderingResumed(_wnd);
+    else if ([[notification name] isEqualToString:UIApplicationWillResignActiveNotification])
+        vout_window_ReportRenderingSuspended(_wnd);
+
+    vlc_mutex_unlock(&_mutex);
+}
+
 /* Subview are expected to fill the whole frame so tell the compositor
  * that it doesn't have to bother with what's behind the window. */
 - (BOOL)isOpaque
-- 
2.28.0



More information about the vlc-devel mailing list