[vlc-commits] vout ios: correctly handle scenarios with multiple OpenGL contexts in a sharegroup

Felix Paul Kühne git at videolan.org
Wed Sep 30 11:58:55 CEST 2015


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Wed Sep 30 11:58:02 2015 +0200| [c052d250802f9dc54b17d6935e6c3604ef7413a0] | committer: Felix Paul Kühne

vout ios: correctly handle scenarios with multiple OpenGL contexts in a sharegroup

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c052d250802f9dc54b17d6935e6c3604ef7413a0
---

 modules/video_output/ios2.m |   35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/modules/video_output/ios2.m b/modules/video_output/ios2.m
index 178b057..b33f5cd 100644
--- a/modules/video_output/ios2.m
+++ b/modules/video_output/ios2.m
@@ -367,6 +367,7 @@ void Close (vlc_object_t *this)
 
         [sys->glESView release];
 
+        /* when using the traditional pipeline, the cross-platform code will free the the pool */
         if (sys->zero_copy) {
             if (sys->picturePool)
                 picture_pool_Release(sys->picturePool);
@@ -615,13 +616,11 @@ static void ZeroCopyDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *su
     /* a client app may have already created a rendering context,
      * so re-use it if it is valid */
     EAGLContext *existingContext = [EAGLContext currentContext];
-    if (existingContext) {
-        if ([existingContext API] == kEAGLRenderingAPIOpenGLES2)
-             _eaglContext = [EAGLContext currentContext];
-    }
-
-    if (!_eaglContext)
+    if (existingContext != nil)
+        _eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup: existingContext.sharegroup];
+    else
         _eaglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
+
     if (unlikely(!_eaglContext))
         return nil;
     if (unlikely(![EAGLContext setCurrentContext:_eaglContext]))
@@ -691,6 +690,7 @@ static void ZeroCopyDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *su
 - (void)destroyBuffers
 {
     /* re-set current context */
+    EAGLContext *previousContext = [EAGLContext currentContext];
     [EAGLContext setCurrentContext:_eaglContext];
 
     /* clear frame buffer */
@@ -700,15 +700,21 @@ static void ZeroCopyDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *su
     /* clear render buffer */
     glDeleteRenderbuffers(1, &_renderBuffer);
     _renderBuffer = 0;
+    [EAGLContext setCurrentContext:previousContext];
 }
 
 - (void)resetBuffers
 {
+    EAGLContext *previousContext = [EAGLContext currentContext];
+    [EAGLContext setCurrentContext:_eaglContext];
+
     if (_bufferNeedReset) {
         [self destroyBuffers];
         [self createBuffers];
         _bufferNeedReset = NO;
     }
+
+    [EAGLContext setCurrentContext:previousContext];
 }
 
 - (void)layoutSubviews
@@ -729,6 +735,7 @@ static void ZeroCopyDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *su
 {
     assert([[NSThread currentThread] isMainThread]);
 
+    EAGLContext *previousContext = [EAGLContext currentContext];
     [EAGLContext setCurrentContext:_eaglContext];
 
     CGSize viewSize = [self bounds].size;
@@ -752,6 +759,7 @@ static void ZeroCopyDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *su
 
     // x / y are top left corner, but we need the lower left one
     glViewport(place.x, place.y, place.width, place.height);
+    [EAGLContext setCurrentContext:previousContext];
 }
 
 - (void)tapRecognized:(UITapGestureRecognizer *)tapRecognizer
@@ -797,6 +805,10 @@ static void ZeroCopyDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *su
 
 - (void)displayPixelBuffer:(CVPixelBufferRef)pixelBuffer
 {
+    /* the currently current context may not be ours, so cache it and restore it later */
+    EAGLContext *previousContext = [EAGLContext currentContext];
+    [EAGLContext setCurrentContext:_eaglContext];
+
     CVReturn err;
     if (pixelBuffer != NULL) {
         int frameWidth = (int)CVPixelBufferGetWidth(pixelBuffer);
@@ -805,7 +817,7 @@ static void ZeroCopyDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *su
         if (!_videoTextureCache) {
             if (_voutDisplay)
                 msg_Err(_voutDisplay, "No video texture cache");
-            return;
+            goto done;
         }
 
         [self cleanUpTextures];
@@ -934,10 +946,17 @@ static void ZeroCopyDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *su
 
     glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffer);
     [_eaglContext presentRenderbuffer:GL_RENDERBUFFER];
+
+    glFlush();
+
+done:
+    /* restore previous eagl context which we cached on entry */
+    [EAGLContext setCurrentContext:previousContext];
 }
 
 - (void)setupZeroCopyGL
 {
+    EAGLContext *previousContext = [EAGLContext currentContext];
     [EAGLContext setCurrentContext:_eaglContext];
     [self createBuffers];
     [self loadShaders];
@@ -959,9 +978,9 @@ static void ZeroCopyDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *su
         if (err != noErr) {
             if (_voutDisplay)
                 msg_Err(_voutDisplay, "Error at CVOpenGLESTextureCacheCreate %d", err);
-            return;
         }
     }
+    [EAGLContext setCurrentContext:previousContext];
 }
 
 - (void)cleanUpTextures



More information about the vlc-commits mailing list