[vlc-commits] window: add separate callback for resizing

Rémi Denis-Courmont git at videolan.org
Sun Dec 2 19:03:30 CET 2018


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Dec  2 11:59:51 2018 +0200| [330b336644add1acad0f0f88c6ba75d19fdeea1b] | committer: Rémi Denis-Courmont

window: add separate callback for resizing

Also remove the return value. It is universally ignored, as the request
is asynchronous (so success means really nothing). Plus the Skin engine
did not even return the correct value.

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

 include/vlc_vout_window.h                   | 21 +++++++++++---
 modules/gui/macosx/VLCVideoOutputProvider.m | 29 +++++++++++--------
 modules/gui/minimal_macosx/intf.m           | 30 +++++++++++---------
 modules/gui/qt/main_interface.cpp           | 17 +++++------
 modules/gui/qt/main_interface.hpp           |  1 +
 modules/gui/skins2/src/skin_main.cpp        | 33 +++++++++++-----------
 modules/video_output/drawable.c             |  1 -
 modules/video_output/wayland/xdg-shell.c    | 44 +++++++++++++----------------
 modules/video_output/wdummy.c               | 10 +------
 modules/video_output/xcb/window.c           | 28 +++++++++---------
 10 files changed, 111 insertions(+), 103 deletions(-)

diff --git a/include/vlc_vout_window.h b/include/vlc_vout_window.h
index 883bd9a94b..7137631dbd 100644
--- a/include/vlc_vout_window.h
+++ b/include/vlc_vout_window.h
@@ -59,7 +59,6 @@ enum vout_window_type {
  */
 enum vout_window_control {
     VOUT_WINDOW_SET_STATE, /* unsigned state */
-    VOUT_WINDOW_SET_SIZE,   /* unsigned i_width, unsigned i_height */
 };
 
 /**
@@ -142,6 +141,8 @@ struct vout_window_callbacks {
 };
 
 struct vout_window_operations {
+    void (*resize)(vout_window_t *, unsigned width, unsigned height);
+
     /**
      * Control callback (mandatory)
      *
@@ -291,12 +292,24 @@ static inline int vout_window_SetState(vout_window_t *window, unsigned state)
 }
 
 /**
- * Configures the window display (i.e. inner/useful) size.
+ * Requests a new window size.
+ *
+ * This requests a change of the window size.
+ *
+ * \warning  The windowing system may or may not actually resize the window
+ * to the requested size. Track the resized event to determine the actual size.
+ *
+ * \note The size is expressed in terms of the "useful" area,
+ * i.e. it excludes any side decoration added by the windowing system.
+ *
+ * \param width pixel width
+ * \param height height width
  */
-static inline int vout_window_SetSize(vout_window_t *window,
+static inline void vout_window_SetSize(vout_window_t *window,
                                       unsigned width, unsigned height)
 {
-    return vout_window_Control(window, VOUT_WINDOW_SET_SIZE, width, height);
+    if (window->ops->resize != NULL)
+        window->ops->resize(window, width, height);
 }
 
 /**
diff --git a/modules/gui/macosx/VLCVideoOutputProvider.m b/modules/gui/macosx/VLCVideoOutputProvider.m
index ab0dffeb7b..8253c0b035 100644
--- a/modules/gui/macosx/VLCVideoOutputProvider.m
+++ b/modules/gui/macosx/VLCVideoOutputProvider.m
@@ -39,6 +39,22 @@
 #import "VLCPlaylist.h"
 #import "NSScreen+VLCAdditions.h"
 
+static void WindowResize(vout_window_t *p_wnd,
+                         unsigned i_width, unsigned i_height)
+{
+    @autoreleasepool {
+        VLCVideoOutputProvider *voutProvider = [[VLCMain sharedInstance] voutProvider];
+        if (!voutProvider) {
+            return;
+        }
+
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [voutProvider setNativeVideoSize:NSMakeSize(i_width, i_height)
+                          forWindow:p_wnd];
+        });
+    }
+}
+
 static const char windowed;
 
 static void WindowSetFullscreen(vout_window_t *p_wnd, const char *psz_id)
@@ -76,6 +92,7 @@ static int WindowControl(vout_window_t *, int i_query, va_list);
 static void WindowClose(vout_window_t *);
 
 static const struct vout_window_operations ops = {
+    WindowResize,
     WindowControl,
     WindowClose,
     WindowUnsetFullscreen,
@@ -149,18 +166,6 @@ static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args)
 
                 break;
             }
-            case VOUT_WINDOW_SET_SIZE:
-            {
-                unsigned int i_width  = va_arg(args, unsigned int);
-                unsigned int i_height = va_arg(args, unsigned int);
-
-                dispatch_async(dispatch_get_main_queue(), ^{
-                    [voutProvider setNativeVideoSize:NSMakeSize(i_width, i_height)
-                                             forWindow:p_wnd];
-                });
-
-                break;
-            }
             default:
             {
                 msg_Warn(p_wnd, "unsupported control query: %i", i_query );
diff --git a/modules/gui/minimal_macosx/intf.m b/modules/gui/minimal_macosx/intf.m
index cb163d860f..7dce791264 100644
--- a/modules/gui/minimal_macosx/intf.m
+++ b/modules/gui/minimal_macosx/intf.m
@@ -101,6 +101,21 @@ static void Run(intf_thread_t *p_intf)
  * Vout window management
  *****************************************************************************/
 
+static void WindowResize(vout_window_t *p_wnd,
+                         unsigned i_width, unsigned i_height)
+{
+    NSWindow* o_window = [(__bridge id)p_wnd->handle.nsobject window];
+
+    @autoreleasepool {
+        dispatch_sync(dispatch_get_main_queue(), ^{
+            NSRect theFrame = [o_window frame];
+            theFrame.size.width = i_width;
+            theFrame.size.height = i_height;
+            [o_window setFrame:theFrame display:YES animate:YES];
+        });
+    }
+}
+
 static void WindowUnsetFullscreen(vout_window_t *p_wnd)
 {
     NSWindow* o_window = [(__bridge id)p_wnd->handle.nsobject window];
@@ -127,6 +142,7 @@ static int WindowControl(vout_window_t *, int i_query, va_list);
 static void WindowClose(vout_window_t *);
 
 static const struct vout_window_operations ops = {
+    WindowResize,
     WindowControl,
     WindowClose,
     WindowUnsetFullscreen,
@@ -178,20 +194,6 @@ static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args)
 
             return VLC_SUCCESS;
         }
-        case VOUT_WINDOW_SET_SIZE:
-        {
-            unsigned int i_width  = va_arg(args, unsigned int);
-            unsigned int i_height = va_arg(args, unsigned int);
-            @autoreleasepool {
-                dispatch_sync(dispatch_get_main_queue(), ^{
-                    NSRect theFrame = [o_window frame];
-                    theFrame.size.width = i_width;
-                    theFrame.size.height = i_height;
-                    [o_window setFrame:theFrame display:YES animate:YES];
-                });
-            }
-            return VLC_SUCCESS;
-        }
         default:
             msg_Warn(p_wnd, "unsupported control query");
             return VLC_EGENERIC;
diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index 351c8d2775..7365d7d3cb 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -730,6 +730,7 @@ bool MainInterface::getVideo( struct vout_window_t *p_wnd,
                               bool fullscreen )
 {
     static const struct vout_window_operations ops = {
+        MainInterface::resizeVideo,
         MainInterface::controlVideo,
         MainInterface::releaseVideo,
         MainInterface::requestVideoWindowed,
@@ -983,6 +984,14 @@ void MainInterface::setInterfaceAlwaysOnTop( bool on_top )
 }
 
 /* Asynchronous calls for video window contrlos */
+void MainInterface::resizeVideo( vout_window_t *p_wnd,
+                                 unsigned i_width, unsigned i_height )
+{
+    MainInterface *p_mi = (MainInterface *)p_wnd->sys;
+
+    emit p_mi->askVideoToResize( i_width, i_height );
+}
+
 void MainInterface::requestVideoWindowed( struct vout_window_t *wnd )
 {
    MainInterface *p_mi = (MainInterface *)wnd->sys;
@@ -1004,14 +1013,6 @@ int MainInterface::controlVideo( vout_window_t *p_wnd, int i_query,
 
     switch( i_query )
     {
-    case VOUT_WINDOW_SET_SIZE:
-    {
-        unsigned int i_width  = va_arg( args, unsigned int );
-        unsigned int i_height = va_arg( args, unsigned int );
-
-        emit p_mi->askVideoToResize( i_width, i_height );
-        return VLC_SUCCESS;
-    }
     case VOUT_WINDOW_SET_STATE:
     {
         unsigned i_arg = va_arg( args, unsigned );
diff --git a/modules/gui/qt/main_interface.hpp b/modules/gui/qt/main_interface.hpp
index 2f769409d2..855133c724 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -74,6 +74,7 @@ public:
                    unsigned int i_width, unsigned int i_height, bool );
 private:
     static void releaseVideo( struct vout_window_t * );
+    static void resizeVideo( struct vout_window_t *, unsigned, unsigned );
     static int controlVideo( struct vout_window_t *, int, va_list );
     static void requestVideoWindowed( struct vout_window_t * );
     static void requestVideoFullScreen( struct vout_window_t *, const char * );
diff --git a/modules/gui/skins2/src/skin_main.cpp b/modules/gui/skins2/src/skin_main.cpp
index 21cad54099..777af9e3cc 100644
--- a/modules/gui/skins2/src/skin_main.cpp
+++ b/modules/gui/skins2/src/skin_main.cpp
@@ -344,6 +344,22 @@ static void WindowCloseLocal( intf_thread_t* pIntf, vlc_object_t *pObj )
     VoutManager::instance( pIntf )->releaseWnd( pWnd );
 }
 
+static void WindowResize( vout_window_t *pWnd,
+                          unsigned i_width, unsigned i_height )
+{
+    vout_window_skins_t* sys = (vout_window_skins_t *)pWnd->sys;
+    intf_thread_t *pIntf = sys->pIntf;
+
+    if( i_width == 0 || i_height == 0 )
+        return;
+
+    // Post a vout resize command
+    AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
+    CmdResizeVout *pCmd = new CmdResizeVout( pIntf, pWnd,
+                                             (int)i_width, (int)i_height );
+    pQueue->push( CmdGenericPtr( pCmd ) );
+}
+
 static void WindowUnsetFullscreen( vout_window_t *pWnd )
 {
     vout_window_skins_t* sys = (vout_window_skins_t *)pWnd->sys;
@@ -366,6 +382,7 @@ static void WindowSetFullscreen( vout_window_t *pWnd, const char * )
 }
 
 static const struct vout_window_operations window_ops = {
+    WindowResize,
     WindowControl,
     WindowClose,
     WindowUnsetFullscreen,
@@ -439,22 +456,6 @@ static int WindowControl( vout_window_t *pWnd, int query, va_list args )
 
     switch( query )
     {
-        case VOUT_WINDOW_SET_SIZE:
-        {
-            unsigned int i_width  = va_arg( args, unsigned int );
-            unsigned int i_height = va_arg( args, unsigned int );
-
-            if( i_width && i_height )
-            {
-                // Post a vout resize command
-                CmdResizeVout *pCmd =
-                    new CmdResizeVout( pIntf, pWnd,
-                                       (int)i_width, (int)i_height );
-                pQueue->push( CmdGenericPtr( pCmd ) );
-            }
-            return VLC_EGENERIC;
-        }
-
         case VOUT_WINDOW_SET_STATE:
         {
             unsigned i_arg = va_arg( args, unsigned );
diff --git a/modules/video_output/drawable.c b/modules/video_output/drawable.c
index 37f26c4a69..303e44b592 100644
--- a/modules/video_output/drawable.c
+++ b/modules/video_output/drawable.c
@@ -146,7 +146,6 @@ static int Control (vout_window_t *wnd, int query, va_list ap)
 
     switch (query)
     {
-        case VOUT_WINDOW_SET_SIZE:   /* not allowed */
         case VOUT_WINDOW_SET_STATE: /* not allowed either, would be ugly */
             return VLC_EGENERIC;
         default:
diff --git a/modules/video_output/wayland/xdg-shell.c b/modules/video_output/wayland/xdg-shell.c
index 9904cd4029..89d1eed700 100644
--- a/modules/video_output/wayland/xdg-shell.c
+++ b/modules/video_output/wayland/xdg-shell.c
@@ -166,43 +166,38 @@ static void ReportSize(vout_window_t *wnd)
     xdg_surface_set_window_geometry(sys->surface, 0, 0, width, height);
 }
 
-static int Control(vout_window_t *wnd, int cmd, va_list ap)
+static void Resize(vout_window_t *wnd, unsigned width, unsigned height)
 {
     vout_window_sys_t *sys = wnd->sys;
-    struct wl_display *display = wnd->display.wl;
 
+#ifdef XDG_SHELL
+    /* The minimum size must be smaller or equal to the maximum size
+     * at _all_ times. This gets a bit cumbersome. */
+    xdg_toplevel_set_min_size(sys->toplevel, 0, 0);
+    xdg_toplevel_set_max_size(sys->toplevel, width, height);
+    xdg_toplevel_set_min_size(sys->toplevel, width, height);
+#endif
+
+    vlc_mutex_lock(&sys->lock);
+    sys->set.width = width;
+    sys->set.height = height;
+    ReportSize(wnd);
+    vlc_mutex_unlock(&sys->lock);
+    wl_display_flush(wnd->display.wl);
+}
+
+static int Control(vout_window_t *wnd, int cmd, va_list ap)
+{
     switch (cmd)
     {
         case VOUT_WINDOW_SET_STATE:
             return VLC_EGENERIC;
 
-        case VOUT_WINDOW_SET_SIZE:
-        {
-            unsigned width = va_arg(ap, unsigned);
-            unsigned height = va_arg(ap, unsigned);
-
-#ifdef XDG_SHELL
-            /* The minimum size must be smaller or equal to the maximum size
-             * at _all_ times. This gets a bit cumbersome. */
-            xdg_toplevel_set_min_size(sys->toplevel, 0, 0);
-            xdg_toplevel_set_max_size(sys->toplevel, width, height);
-            xdg_toplevel_set_min_size(sys->toplevel, width, height);
-#endif
-
-            vlc_mutex_lock(&sys->lock);
-            sys->set.width = width;
-            sys->set.height = height;
-            ReportSize(wnd);
-            vlc_mutex_unlock(&sys->lock);
-            break;
-        }
-
         default:
             msg_Err(wnd, "request %d not implemented", cmd);
             return VLC_EGENERIC;
     }
 
-    wl_display_flush(display);
     return VLC_SUCCESS;
 }
 
@@ -244,6 +239,7 @@ static void SetFullscreen(vout_window_t *wnd, const char *idstr)
 }
 
 static const struct vout_window_operations ops = {
+    .resize = Resize,
     .control = Control,
     .destroy = Close,
     .unset_fullscreen = UnsetFullscreen,
diff --git a/modules/video_output/wdummy.c b/modules/video_output/wdummy.c
index 1e55953a76..5979504790 100644
--- a/modules/video_output/wdummy.c
+++ b/modules/video_output/wdummy.c
@@ -34,15 +34,6 @@ static int Control(vout_window_t *wnd, int query, va_list ap)
 {
     switch (query)
     {
-        case VOUT_WINDOW_SET_SIZE:
-        {
-            unsigned width = va_arg(ap, unsigned);
-            unsigned height = va_arg(ap, unsigned);
-
-            vout_window_ReportSize(wnd, width, height);
-            return VLC_SUCCESS;
-        }
-
         case VOUT_WINDOW_SET_STATE:
             /* These controls deserve a proper window provider. Move along. */
             return VLC_EGENERIC;
@@ -54,6 +45,7 @@ static int Control(vout_window_t *wnd, int query, va_list ap)
 }
 
 static const struct vout_window_operations ops = {
+    .resize = vout_window_ReportSize,
     .control = Control,
 };
 
diff --git a/modules/video_output/xcb/window.c b/modules/video_output/xcb/window.c
index 5d981ab624..a4d19ae9e1 100644
--- a/modules/video_output/xcb/window.c
+++ b/modules/video_output/xcb/window.c
@@ -413,6 +413,18 @@ static void change_wm_state (vout_window_t *wnd, bool on, xcb_atom_t state)
                     (const char *)&ev);
 }
 
+static void Resize(vout_window_t *wnd, unsigned width, unsigned height)
+{
+    vout_window_sys_t *sys = wnd->sys;
+    xcb_connection_t *conn = sys->conn;
+    const uint32_t values[] = { width, height, };
+
+    xcb_configure_window(conn, wnd->handle.xid,
+                         XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
+                         values);
+    xcb_flush(conn);
+}
+
 static int Control (vout_window_t *wnd, int cmd, va_list ap)
 {
     vout_window_sys_t *p_sys = wnd->sys;
@@ -420,21 +432,6 @@ static int Control (vout_window_t *wnd, int cmd, va_list ap)
 
     switch (cmd)
     {
-        case VOUT_WINDOW_SET_SIZE:
-        {
-            if (p_sys->embedded)
-                return VLC_EGENERIC;
-
-            unsigned width = va_arg (ap, unsigned);
-            unsigned height = va_arg (ap, unsigned);
-            const uint32_t values[] = { width, height, };
-
-            xcb_configure_window (conn, wnd->handle.xid,
-                                  XCB_CONFIG_WINDOW_WIDTH |
-                                  XCB_CONFIG_WINDOW_HEIGHT, values);
-            break;
-        }
-
         case VOUT_WINDOW_SET_STATE:
         {
             unsigned state = va_arg (ap, unsigned);
@@ -575,6 +572,7 @@ static void set_wm_deco(xcb_connection_t *conn, xcb_window_t window, bool on)
 static void Close(vout_window_t *);
 
 static const struct vout_window_operations ops = {
+    .resize = Resize,
     .set_fullscreen = SetFullscreen,
     .unset_fullscreen = UnsetFullscreen,
     .control = Control,



More information about the vlc-commits mailing list