[vlc-devel] [PATCH] [3.x] vout/caopengllayer: fix scaling when changing displays

Marvin Scholz epirat07 at gmail.com
Mon Feb 24 19:17:58 CET 2020


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.
---
 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 @@ - (instancetype)initWithVoutDisplay:(vout_display_t *)vd;
 - (void)placePictureWithConfig:(const vout_display_cfg_t *)cfg;
 - (void)displayFromVout;
 - (void)reportCurrentLayerSize;
+- (void)reportCurrentLayerSizeWithScale:(CGFloat)scale;
 - (void)vlcClose;
 @end
 
@@ -581,6 +582,17 @@ - (BOOL)layer:(CALayer *)layer
 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 @@ - (void)resizeWithOldSuperlayerSize:(CGSize)size
     [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 @@ - (void)reportCurrentLayerSize
     }
 }
 
+- (void)reportCurrentLayerSize
+{
+    CGFloat scale = self.contentsScale;
+    [self reportCurrentLayerSizeWithScale:scale];
+}
+
 - (void)display
 {
     [_displayLock lock];
-- 
2.21.1 (Apple Git-122.3)



More information about the vlc-devel mailing list