[vlc-devel] [PATCH v3 02/20] opengl: flip the vertical placement when using the placed picture area

Steve Lhomme robux4 at ycbcr.xyz
Wed Aug 26 13:55:29 CEST 2020


In OpenGL is Y axis is flipped compared to the core so we need to flip the
place->y value to match the OpenGL coordinates.
---
 modules/video_output/caopengllayer.m  |  7 +------
 modules/video_output/macosx.m         | 18 ++++++------------
 modules/video_output/opengl/display.c | 26 +++++++-------------------
 modules/video_output/win32/glwin32.c  | 10 ++--------
 4 files changed, 16 insertions(+), 45 deletions(-)

diff --git a/modules/video_output/caopengllayer.m b/modules/video_output/caopengllayer.m
index 0dafcec000a..b5821465651 100644
--- a/modules/video_output/caopengllayer.m
+++ b/modules/video_output/caopengllayer.m
@@ -319,14 +319,9 @@ static int Control (vout_display_t *vd, int query, va_list ap)
             cfg_tmp.display.width = bounds.size.width;
             cfg_tmp.display.height = bounds.size.height;
 
-            /* Reverse vertical alignment as the GL tex are Y inverted */
-            if (cfg_tmp.align.vertical == VLC_VIDEO_ALIGN_TOP)
-                cfg_tmp.align.vertical = VLC_VIDEO_ALIGN_BOTTOM;
-            else if (cfg_tmp.align.vertical == VLC_VIDEO_ALIGN_BOTTOM)
-                cfg_tmp.align.vertical = VLC_VIDEO_ALIGN_TOP;
-
             vout_display_place_t place;
             vout_display_PlacePicture(&place, &vd->source, &cfg_tmp);
+            vout_display_PlaceFlipVertical(&cfg_tmp, &place);
             if (unlikely(OpenglLock(sys->gl)))
                 // don't return an error or we need to handle VOUT_DISPLAY_RESET_PICTURES
                 return VLC_SUCCESS;
diff --git a/modules/video_output/macosx.m b/modules/video_output/macosx.m
index 15d0c305772..18c21534454 100644
--- a/modules/video_output/macosx.m
+++ b/modules/video_output/macosx.m
@@ -322,8 +322,8 @@ static void PictureDisplay (vout_display_t *vd, picture_t *pic)
         if (@available(macOS 10.14, *)) {
             vout_display_place_t place;
             vout_display_PlacePicture(&place, &vd->source, &sys->cfg);
-            vout_display_opengl_Viewport(vd->sys->vgl, place.x,
-                                         sys->cfg.display.height - (place.y + place.height),
+            vout_display_PlaceFlipVertical(&sys->cfg, &place);
+            vout_display_opengl_Viewport(vd->sys->vgl, place.x, place.y,
                                          place.width, place.height);
         }
 
@@ -355,16 +355,9 @@ static int Control (vout_display_t *vd, int query, va_list ap)
 
                 /* we always use our current frame here, because we have some size constraints
                  in the ui vout provider */
-                vout_display_cfg_t cfg_tmp = *cfg;
-
-                /* Reverse vertical alignment as the GL tex are Y inverted */
-                if (cfg_tmp.align.vertical == VLC_VIDEO_ALIGN_TOP)
-                    cfg_tmp.align.vertical = VLC_VIDEO_ALIGN_BOTTOM;
-                else if (cfg_tmp.align.vertical == VLC_VIDEO_ALIGN_BOTTOM)
-                    cfg_tmp.align.vertical = VLC_VIDEO_ALIGN_TOP;
-
                 vout_display_place_t place;
-                vout_display_PlacePicture(&place, &vd->source, &cfg_tmp);
+                vout_display_PlacePicture(&place, &vd->source, cfg);
+                vout_display_PlaceFlipVertical(cfg, &place);
                 @synchronized (sys->glView) {
                     sys->cfg = *cfg;
                 }
@@ -378,7 +371,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
                 if (query != VOUT_DISPLAY_CHANGE_DISPLAY_SIZE)
                     // x / y are top left corner, but we need the lower left one
                     vout_display_opengl_Viewport(sys->vgl, place.x,
-                                                 cfg_tmp.display.height - (place.y + place.height),
+                                                 cfg->display.height - (place.y + place.height),
                                                  place.width, place.height);
                 vlc_gl_ReleaseCurrent (sys->gl);
 
@@ -628,6 +621,7 @@ static void OpenglSwap (vlc_gl_t *gl)
             sys->cfg.display.height = bounds.size.height;
 
             vout_display_PlacePicture(&place, &vd->source, &sys->cfg);
+            vout_display_PlaceFlipVertical(&sys->cfg, &place);
             // FIXME: this call leads to a fatal mutex locking error in vout_ChangeDisplaySize()
             // vout_window_ReportSize(sys->embed, bounds.size.width, bounds.size.height);
         }
diff --git a/modules/video_output/opengl/display.c b/modules/video_output/opengl/display.c
index 2db08ccc03b..fa08c08be01 100644
--- a/modules/video_output/opengl/display.c
+++ b/modules/video_output/opengl/display.c
@@ -206,16 +206,6 @@ static void PictureDisplay (vout_display_t *vd, picture_t *pic)
     }
 }
 
-static void
-FlipVerticalAlign(vout_display_cfg_t *cfg)
-{
-    /* Reverse vertical alignment as the GL tex are Y inverted */
-    if (cfg->align.vertical == VLC_VIDEO_ALIGN_TOP)
-        cfg->align.vertical = VLC_VIDEO_ALIGN_BOTTOM;
-    else if (cfg->align.vertical == VLC_VIDEO_ALIGN_BOTTOM)
-        cfg->align.vertical = VLC_VIDEO_ALIGN_TOP;
-}
-
 static int Control (vout_display_t *vd, int query, va_list ap)
 {
     vout_display_sys_t *sys = vd->sys;
@@ -231,25 +221,23 @@ static int Control (vout_display_t *vd, int query, va_list ap)
       case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
       case VOUT_DISPLAY_CHANGE_ZOOM:
       {
-        vout_display_cfg_t cfg = *va_arg(ap, const vout_display_cfg_t *);
+        const vout_display_cfg_t *cfg = va_arg(ap, const vout_display_cfg_t *);
         const video_format_t *src = &vd->source;
 
-        FlipVerticalAlign(&cfg);
-
-        vout_display_PlacePicture(&sys->place, src, &cfg);
+        vout_display_PlacePicture(&sys->place, src, cfg);
+        vout_display_PlaceFlipVertical(cfg, &sys->place);
         sys->place_changed = true;
-        vlc_gl_Resize (sys->gl, cfg.display.width, cfg.display.height);
+        vlc_gl_Resize (sys->gl, cfg->display.width, cfg->display.height);
         return VLC_SUCCESS;
       }
 
       case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
       case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
       {
-        vout_display_cfg_t cfg = *va_arg(ap, const vout_display_cfg_t *);
-
-        FlipVerticalAlign(&cfg);
+        const vout_display_cfg_t *cfg = va_arg(ap, const vout_display_cfg_t *);
 
-        vout_display_PlacePicture(&sys->place, &vd->source, &cfg);
+        vout_display_PlacePicture(&sys->place, &vd->source, cfg);
+        vout_display_PlaceFlipVertical(cfg, &sys->place);
         sys->place_changed = true;
         return VLC_SUCCESS;
       }
diff --git a/modules/video_output/win32/glwin32.c b/modules/video_output/win32/glwin32.c
index 434801ea0dc..272b8e90478 100644
--- a/modules/video_output/win32/glwin32.c
+++ b/modules/video_output/win32/glwin32.c
@@ -211,16 +211,10 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
         return;
     if (sys->area.place_changed)
     {
-        vout_display_cfg_t place_cfg = sys->area.vdcfg;
-        vout_display_place_t place;
+        vout_display_place_t place = sys->area.place;
 
         /* Reverse vertical alignment as the GL tex are Y inverted */
-        if (place_cfg.align.vertical == VLC_VIDEO_ALIGN_TOP)
-            place_cfg.align.vertical = VLC_VIDEO_ALIGN_BOTTOM;
-        else if (place_cfg.align.vertical == VLC_VIDEO_ALIGN_BOTTOM)
-            place_cfg.align.vertical = VLC_VIDEO_ALIGN_TOP;
-
-        vout_display_PlacePicture(&place, &vd->source, &place_cfg);
+        vout_display_PlaceFlipVertical(&sys->area.vdcfg, &place);
 
         const int width  = place.width;
         const int height = place.height;
-- 
2.26.2



More information about the vlc-devel mailing list