[vlc-commits] vout/caopengllayer: fix scaling when changing displays

Marvin Scholz git at videolan.org
Thu Feb 27 21:51:54 CET 2020


vlc/vlc-3.0 | branch: master | Marvin Scholz <epirat07 at gmail.com> | Mon Feb 24 19:17:37 2020 +0100| [57401f907ca98bfd37e73577014642fd16c123bb] | committer: Marvin Scholz

vout/caopengllayer: fix scaling when changing displays

Changing from a retina screen to a non-retina screen changes the
scale of the layer, so from point of view of the OpenGL code, the
size of the surface changes. Therefore we need to signal this change
so that the size is adapted correctly.

This is not a perfect solution as the size event will arrive too late
so for a few frames the wrong size can still be seen before it switches
to the new size. Ideally this would be handled like the live resize
but so far I have not found a good solution for how to do that.

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

 modules/video_output/caopengllayer.m | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/modules/video_output/caopengllayer.m b/modules/video_output/caopengllayer.m
index 7a4c1ee819..629124150b 100644
--- a/modules/video_output/caopengllayer.m
+++ b/modules/video_output/caopengllayer.m
@@ -80,6 +80,7 @@ static int Control          (vout_display_t *vd, int query, va_list ap);
 - (void)placePictureWithConfig:(const vout_display_cfg_t *)cfg;
 - (void)displayFromVout;
 - (void)reportCurrentLayerSize;
+- (void)reportCurrentLayerSizeWithScale:(CGFloat)scale;
 - (void)vlcClose;
 @end
 
@@ -581,6 +582,17 @@ static int Control(vout_display_t *vd, int query, va_list ap)
 shouldInheritContentsScale:(CGFloat)newScale
    fromWindow:(NSWindow *)window
 {
+    // If the scale changes, from the OpenGL point of view
+    // the size changes, so we need to indicate a resize
+    if (layer == self.layer) {
+        [(VLCCAOpenGLLayer *)self.layer
+            reportCurrentLayerSizeWithScale:newScale];
+        // FIXME
+        // For a brief moment the old image with a wrong scale
+        // is still visible, thats because the resize event is not
+        // processed immediately. Ideally this would be handled similar
+        // to how the live resize is done, to avoid this.
+    }
     return YES;
 }
 
@@ -785,10 +797,9 @@ shouldInheritContentsScale:(CGFloat)newScale
     [self reportCurrentLayerSize];
 }
 
-- (void)reportCurrentLayerSize
+- (void)reportCurrentLayerSizeWithScale:(CGFloat)scale
 {
     CGSize newSize = self.visibleRect.size;
-    CGFloat scale = self.contentsScale;
 
     // Calculate pixel values
     newSize.width *= scale;
@@ -803,6 +814,12 @@ shouldInheritContentsScale:(CGFloat)newScale
     }
 }
 
+- (void)reportCurrentLayerSize
+{
+    CGFloat scale = self.contentsScale;
+    [self reportCurrentLayerSizeWithScale:scale];
+}
+
 - (void)display
 {
     [_displayLock lock];



More information about the vlc-commits mailing list