[vlc-commits] mac plugin: correctly build the layer hierarchy when playback starts in fullscreen instead of within the browser window

Felix Paul Kühne git at videolan.org
Fri Nov 7 00:19:39 CET 2014


npapi-vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Fri Nov  7 00:19:15 2014 +0100| [40c43293b31b30118593fef7658f5f40db31e368] | committer: Felix Paul Kühne

mac plugin: correctly build the layer hierarchy when playback starts in fullscreen instead of within the browser window

This also solves an issue where the video was displayed with incorrect dimensions in windowed mode

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

 npapi/vlcplugin_mac.mm |   51 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 36 insertions(+), 15 deletions(-)

diff --git a/npapi/vlcplugin_mac.mm b/npapi/vlcplugin_mac.mm
index c242f20..8886c2c 100644
--- a/npapi/vlcplugin_mac.mm
+++ b/npapi/vlcplugin_mac.mm
@@ -200,24 +200,27 @@ void VlcPluginMac::toggle_fullscreen()
     this->update_controls();
 
     if (get_fullscreen() != 0) {
-        if (!fullscreenWindow) {
-            /* this window is kind of useless. however, we need to support 10.5, since enterFullScreenMode depends on the
-             * existance of a parent window. This is solved in 10.6 and we should remove the window once we require it. */
-            fullscreenWindow = [[VLCFullscreenWindow alloc] initWithContentRect: NSMakeRect(0., 0., npwindow.width, npwindow.height)];
-            [fullscreenWindow setLevel: CGShieldingWindowLevel()];
-            fullscreenView = [fullscreenWindow customContentView];
-
-            /* CAVE: the order of these methods is important, since we want a layer-hosting view instead of
-             * a layer-backed view, which you'd get if you do it the other way around */
-            [fullscreenView setLayer: [CALayer layer]];
-            [fullscreenView setWantsLayer:YES];
-            [fullscreenView setCppPlugin: this];
-        }
+        /* this window is kind of useless. however, we need to support 10.5, since enterFullScreenMode depends on the
+         * existance of a parent window. This is solved in 10.6 and we should remove the window once we require it. */
+        fullscreenWindow = [[VLCFullscreenWindow alloc] initWithContentRect: NSMakeRect(0., 0., npwindow.width, npwindow.height)];
+        [fullscreenWindow setLevel: CGShieldingWindowLevel()];
+        fullscreenView = [fullscreenWindow customContentView];
+
+        /* CAVE: the order of these methods is important, since we want a layer-hosting view instead of
+         * a layer-backed view, which you'd get if you do it the other way around */
+        [fullscreenView setLayer: [CALayer layer]];
+        [fullscreenView setWantsLayer:YES];
+        [fullscreenView setCppPlugin: this];
 
         [noMediaLayer removeFromSuperlayer];
         [playbackLayer removeFromSuperlayer];
         [controllerLayer removeFromSuperlayer];
 
+        if (!fullscreenView)
+            return;
+        if (![fullscreenView layer])
+            return;
+
         [[fullscreenView layer] addSublayer: noMediaLayer];
         [[fullscreenView layer] addSublayer: playbackLayer];
         [[fullscreenView layer] addSublayer: controllerLayer];
@@ -239,6 +242,7 @@ void VlcPluginMac::toggle_fullscreen()
         [browserRootLayer addSublayer: playbackLayer];
         [browserRootLayer addSublayer: controllerLayer];
         [fullscreenWindow orderOut: nil];
+        [fullscreenWindow release];
     }
 }
 
@@ -488,8 +492,25 @@ bool VlcPluginMac::handle_event(void *event)
     playbackLayer = (VLCPlaybackLayer *)[aLayer retain];
     playbackLayer.opaque = 1.;
     playbackLayer.hidden = NO;
-    playbackLayer.bounds = noMediaLayer.bounds;
-    [self insertSublayer:playbackLayer below:controllerLayer];
+
+    if (libvlc_get_fullscreen(_cppPlugin->getMD()) != 0) {
+        /* work-around a 32bit runtime limitation where we can't cast
+         * NSRect to CGRect */
+        NSRect fullscreenViewFrame = fullscreenView.frame;
+        playbackLayer.bounds = CGRectMake(fullscreenViewFrame.origin.x,
+                                          fullscreenViewFrame.origin.y,
+                                          fullscreenViewFrame.size.width,
+                                          fullscreenViewFrame.size.height);
+        playbackLayer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;
+
+        [controllerLayer removeFromSuperlayer];
+        [[fullscreenView layer] addSublayer: playbackLayer];
+        [[fullscreenView layer] addSublayer: controllerLayer];
+        [[fullscreenView layer] setNeedsDisplay];
+    } else {
+        playbackLayer.bounds = noMediaLayer.bounds;
+        [self insertSublayer:playbackLayer below:controllerLayer];
+    }
     [self setNeedsDisplay];
     [playbackLayer setNeedsDisplay];
     CGRect frame = playbackLayer.bounds;



More information about the vlc-commits mailing list