[vlc-commits] window: use dedicated state callback

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


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Dec  2 12:13:56 2018 +0200| [240ab225dbeef6505447dc33293e0cc99d2ed2e2] | committer: Rémi Denis-Courmont

window: use dedicated state callback

This removes the vararg control callback.

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

 include/vlc_vout_window.h                   | 48 +++--------------------------
 modules/gui/macosx/VLCVideoOutputProvider.m | 28 +++++++++++++++--
 modules/gui/minimal_macosx/intf.m           | 33 +++++---------------
 modules/gui/qt/main_interface.cpp           | 21 +++----------
 modules/gui/qt/main_interface.hpp           |  2 +-
 modules/gui/skins2/src/skin_main.cpp        | 41 ++++++++----------------
 modules/video_output/drawable.c             | 18 -----------
 modules/video_output/wayland/xdg-shell.c    | 16 ----------
 modules/video_output/wdummy.c               | 15 ---------
 modules/video_output/win32/glwin32.c        |  7 -----
 modules/video_output/xcb/window.c           | 32 +++++--------------
 11 files changed, 64 insertions(+), 197 deletions(-)

diff --git a/include/vlc_vout_window.h b/include/vlc_vout_window.h
index 7137631dbd..a3857c80fa 100644
--- a/include/vlc_vout_window.h
+++ b/include/vlc_vout_window.h
@@ -55,13 +55,6 @@ enum vout_window_type {
 };
 
 /**
- * Control query for vout_window_t
- */
-enum vout_window_control {
-    VOUT_WINDOW_SET_STATE, /* unsigned state */
-};
-
-/**
  * Window management state.
  */
 enum vout_window_state {
@@ -144,23 +137,13 @@ struct vout_window_operations {
     void (*resize)(vout_window_t *, unsigned width, unsigned height);
 
     /**
-     * Control callback (mandatory)
-     *
-     * This callback handles some control request regarding the window.
-     * See \ref vout_window_control.
-     *
-     * This field should not be used directly when manipulating a window.
-     * vout_window_Control() should be used instead.
-     */
-    int (*control)(vout_window_t *, int, va_list);
-
-    /**
      * Destroy the window.
      *
      * Destroys the window and releases all associated resources.
      */
     void (*destroy)(vout_window_t *);
 
+    void (*set_state)(vout_window_t *, unsigned state);
     void (*unset_fullscreen)(vout_window_t *);
     void (*set_fullscreen)(vout_window_t *, const char *id);
 };
@@ -259,36 +242,13 @@ VLC_API void vout_window_Delete(vout_window_t *);
 
 void vout_window_SetInhibition(vout_window_t *window, bool enabled);
 
-static inline int vout_window_vaControl(vout_window_t *window, int query,
-                                        va_list ap)
-{
-    return window->ops->control(window, query, ap);
-}
-
-/**
- * Reconfigures a window.
- *
- * @note The vout_window_* wrappers should be used instead of this function.
- *
- * @warning The caller must own the window, as vout_window_t is not thread safe.
- */
-static inline int vout_window_Control(vout_window_t *window, int query, ...)
-{
-    va_list ap;
-    int ret;
-
-    va_start(ap, query);
-    ret = vout_window_vaControl(window, query, ap);
-    va_end(ap);
-    return ret;
-}
-
 /**
  * Configures the window manager state for this window.
  */
-static inline int vout_window_SetState(vout_window_t *window, unsigned state)
+static inline void vout_window_SetState(vout_window_t *window, unsigned state)
 {
-    return vout_window_Control(window, VOUT_WINDOW_SET_STATE, state);
+    if (window->ops->set_state != NULL)
+        window->ops->set_state(window, state);
 }
 
 /**
diff --git a/modules/gui/macosx/VLCVideoOutputProvider.m b/modules/gui/macosx/VLCVideoOutputProvider.m
index 8253c0b035..2f68ffe31c 100644
--- a/modules/gui/macosx/VLCVideoOutputProvider.m
+++ b/modules/gui/macosx/VLCVideoOutputProvider.m
@@ -55,6 +55,31 @@ static void WindowResize(vout_window_t *p_wnd,
     }
 }
 
+static void WindowSetState(vout_window_t *p_wnd, unsigned i_state)
+{
+    if (i_state & VOUT_WINDOW_STATE_BELOW)
+    {
+        msg_Dbg(p_wnd, "Ignore change to VOUT_WINDOW_STATE_BELOW");
+        return;
+    }
+
+    @autoreleasepool {
+        VLCVideoOutputProvider *voutProvider = [[VLCMain sharedInstance] voutProvider];
+        if (!voutProvider) {
+            return;
+        }
+
+        NSInteger i_cooca_level = NSNormalWindowLevel;
+
+        if (i_state & VOUT_WINDOW_STATE_ABOVE)
+            i_cooca_level = NSStatusWindowLevel;
+
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [voutProvider setWindowLevel:i_cooca_level forWindow:p_wnd];
+        });
+    }
+}
+
 static const char windowed;
 
 static void WindowSetFullscreen(vout_window_t *p_wnd, const char *psz_id)
@@ -88,13 +113,12 @@ static void WindowUnsetFullscreen(vout_window_t *wnd)
 
 static atomic_bool b_intf_starting = ATOMIC_VAR_INIT(false);
 
-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,
+    WindowSetState,
     WindowUnsetFullscreen,
     WindowSetFullscreen,
 };
diff --git a/modules/gui/minimal_macosx/intf.m b/modules/gui/minimal_macosx/intf.m
index 7dce791264..3778313f56 100644
--- a/modules/gui/minimal_macosx/intf.m
+++ b/modules/gui/minimal_macosx/intf.m
@@ -116,6 +116,13 @@ static void WindowResize(vout_window_t *p_wnd,
     }
 }
 
+static void WindowSetState(vout_window_t *p_wnd, unsigned state)
+{
+    NSWindow* o_window = [(__bridge id)p_wnd->handle.nsobject window];
+
+    [o_window setLevel:i_state];
+}
+
 static void WindowUnsetFullscreen(vout_window_t *p_wnd)
 {
     NSWindow* o_window = [(__bridge id)p_wnd->handle.nsobject window];
@@ -138,13 +145,12 @@ static void WindowSetFullscreen(vout_window_t *p_wnd, const char *psz_id)
     }
 }
 
-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,
+    WindowSetState,
     WindowUnsetFullscreen,
     WindowSetFullscreen,
 };
@@ -177,29 +183,6 @@ int WindowOpen(vout_window_t *p_wnd, const vout_window_cfg_t *cfg)
     return VLC_SUCCESS;
 }
 
-static int WindowControl(vout_window_t *p_wnd, int i_query, va_list args)
-{
-    NSWindow* o_window = [(__bridge id)p_wnd->handle.nsobject window];
-    if (!o_window) {
-        msg_Err(p_wnd, "failed to recover cocoa window");
-        return VLC_EGENERIC;
-    }
-
-    switch (i_query) {
-        case VOUT_WINDOW_SET_STATE:
-        {
-            unsigned i_state = va_arg(args, unsigned);
-
-            [o_window setLevel:i_state];
-
-            return VLC_SUCCESS;
-        }
-        default:
-            msg_Warn(p_wnd, "unsupported control query");
-            return VLC_EGENERIC;
-    }
-}
-
 static void WindowClose(vout_window_t *p_wnd)
 {
     @autoreleasepool {
diff --git a/modules/gui/qt/main_interface.cpp b/modules/gui/qt/main_interface.cpp
index 7365d7d3cb..0b737622d4 100644
--- a/modules/gui/qt/main_interface.cpp
+++ b/modules/gui/qt/main_interface.cpp
@@ -731,8 +731,8 @@ bool MainInterface::getVideo( struct vout_window_t *p_wnd,
 {
     static const struct vout_window_operations ops = {
         MainInterface::resizeVideo,
-        MainInterface::controlVideo,
         MainInterface::releaseVideo,
+        MainInterface::requestVideoState,
         MainInterface::requestVideoWindowed,
         MainInterface::requestVideoFullScreen,
     };
@@ -1006,25 +1006,12 @@ void MainInterface::requestVideoFullScreen( vout_window_t *wnd, const char * )
     emit p_mi->askVideoSetFullScreen( true );
 }
 
-int MainInterface::controlVideo( vout_window_t *p_wnd, int i_query,
-                                 va_list args )
+void MainInterface::requestVideoState( vout_window_t *p_wnd, unsigned i_arg )
 {
     MainInterface *p_mi = (MainInterface *)p_wnd->sys;
+    bool on_top = (i_arg & VOUT_WINDOW_STATE_ABOVE) != 0;
 
-    switch( i_query )
-    {
-    case VOUT_WINDOW_SET_STATE:
-    {
-        unsigned i_arg = va_arg( args, unsigned );
-        unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
-
-        emit p_mi->askVideoOnTop( on_top != 0 );
-        return VLC_SUCCESS;
-    }
-    default:
-        msg_Warn( p_wnd, "unsupported control query" );
-        return VLC_EGENERIC;
-    }
+    emit p_mi->askVideoOnTop( on_top );
 }
 
 void MainInterface::releaseVideo( vout_window_t *p_wnd )
diff --git a/modules/gui/qt/main_interface.hpp b/modules/gui/qt/main_interface.hpp
index 855133c724..0c64d192a3 100644
--- a/modules/gui/qt/main_interface.hpp
+++ b/modules/gui/qt/main_interface.hpp
@@ -75,7 +75,7 @@ public:
 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 requestVideoState( struct vout_window_t *, unsigned );
     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 777af9e3cc..8af14b4471 100644
--- a/modules/gui/skins2/src/skin_main.cpp
+++ b/modules/gui/skins2/src/skin_main.cpp
@@ -320,7 +320,6 @@ end:
 
 static int  WindowOpen( vout_window_t *, const vout_window_cfg_t * );
 static void WindowClose( vout_window_t * );
-static int  WindowControl( vout_window_t *, int, va_list );
 
 typedef struct
 {
@@ -360,6 +359,18 @@ static void WindowResize( vout_window_t *pWnd,
     pQueue->push( CmdGenericPtr( pCmd ) );
 }
 
+static void WindowSetState( vout_window_t *pWnd, unsigned i_arg )
+{
+    vout_window_skins_t* sys = (vout_window_skins_t *)pWnd->sys;
+    intf_thread_t *pIntf = sys->pIntf;
+    AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
+    bool on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
+
+    // Post a SetOnTop command
+    CmdSetOnTop* pCmd = new CmdSetOnTop( pIntf, on_top );
+    pQueue->push( CmdGenericPtr( pCmd ) );
+}
+
 static void WindowUnsetFullscreen( vout_window_t *pWnd )
 {
     vout_window_skins_t* sys = (vout_window_skins_t *)pWnd->sys;
@@ -383,8 +394,8 @@ static void WindowSetFullscreen( vout_window_t *pWnd, const char * )
 
 static const struct vout_window_operations window_ops = {
     WindowResize,
-    WindowControl,
     WindowClose,
+    WindowSetState,
     WindowUnsetFullscreen,
     WindowSetFullscreen,
 };
@@ -448,32 +459,6 @@ static void WindowClose( vout_window_t *pWnd )
     delete sys;
 }
 
-static int WindowControl( vout_window_t *pWnd, int query, va_list args )
-{
-    vout_window_skins_t* sys = (vout_window_skins_t *)pWnd->sys;
-    intf_thread_t *pIntf = sys->pIntf;
-    AsyncQueue *pQueue = AsyncQueue::instance( pIntf );
-
-    switch( query )
-    {
-        case VOUT_WINDOW_SET_STATE:
-        {
-            unsigned i_arg = va_arg( args, unsigned );
-            unsigned on_top = i_arg & VOUT_WINDOW_STATE_ABOVE;
-
-            // Post a SetOnTop command
-            CmdSetOnTop* pCmd =
-                new CmdSetOnTop( pIntf, on_top );
-            pQueue->push( CmdGenericPtr( pCmd ) );
-            return VLC_SUCCESS;
-        }
-
-        default:
-            msg_Dbg( pIntf, "control query not supported" );
-            return VLC_EGENERIC;
-    }
-}
-
 //---------------------------------------------------------------------------
 // Module descriptor
 //---------------------------------------------------------------------------
diff --git a/modules/video_output/drawable.c b/modules/video_output/drawable.c
index 303e44b592..b5ca715f50 100644
--- a/modules/video_output/drawable.c
+++ b/modules/video_output/drawable.c
@@ -55,15 +55,12 @@ vlc_module_begin ()
         change_volatile ()
 vlc_module_end ()
 
-static int Control (vout_window_t *, int, va_list);
-
 /* Keep a list of busy drawables, so we don't overlap videos if there are
  * more than one video track in the stream. */
 static vlc_mutex_t serializer = VLC_STATIC_MUTEX;
 static uintptr_t *used = NULL;
 
 static const struct vout_window_operations ops = {
-    .control = Control,
     .destroy = Close,
 };
 
@@ -138,18 +135,3 @@ static void Close (vout_window_t *wnd)
     }
     vlc_mutex_unlock (&serializer);
 }
-
-
-static int Control (vout_window_t *wnd, int query, va_list ap)
-{
-    VLC_UNUSED( ap );
-
-    switch (query)
-    {
-        case VOUT_WINDOW_SET_STATE: /* not allowed either, would be ugly */
-            return VLC_EGENERIC;
-        default:
-            msg_Warn (wnd, "unsupported control query %d", query);
-            return VLC_EGENERIC;
-    }
-}
diff --git a/modules/video_output/wayland/xdg-shell.c b/modules/video_output/wayland/xdg-shell.c
index 89d1eed700..dd4e7305f0 100644
--- a/modules/video_output/wayland/xdg-shell.c
+++ b/modules/video_output/wayland/xdg-shell.c
@@ -186,21 +186,6 @@ static void Resize(vout_window_t *wnd, unsigned width, unsigned height)
     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;
-
-        default:
-            msg_Err(wnd, "request %d not implemented", cmd);
-            return VLC_EGENERIC;
-    }
-
-    return VLC_SUCCESS;
-}
-
 static void Close(vout_window_t *);
 
 static void UnsetFullscreen(vout_window_t *wnd)
@@ -240,7 +225,6 @@ 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,
     .set_fullscreen = SetFullscreen,
diff --git a/modules/video_output/wdummy.c b/modules/video_output/wdummy.c
index 5979504790..104d70b991 100644
--- a/modules/video_output/wdummy.c
+++ b/modules/video_output/wdummy.c
@@ -30,23 +30,8 @@
 #include <vlc_plugin.h>
 #include <vlc_vout_window.h>
 
-static int Control(vout_window_t *wnd, int query, va_list ap)
-{
-    switch (query)
-    {
-        case VOUT_WINDOW_SET_STATE:
-            /* These controls deserve a proper window provider. Move along. */
-            return VLC_EGENERIC;
-
-        default:
-            msg_Warn(wnd, "unsupported control query %d", query);
-            return VLC_EGENERIC;
-    }
-}
-
 static const struct vout_window_operations ops = {
     .resize = vout_window_ReportSize,
-    .control = Control,
 };
 
 static int Open(vout_window_t *wnd, const vout_window_cfg_t *cfg)
diff --git a/modules/video_output/win32/glwin32.c b/modules/video_output/win32/glwin32.c
index e1fc112cf2..c3b82a410b 100644
--- a/modules/video_output/win32/glwin32.c
+++ b/modules/video_output/win32/glwin32.c
@@ -84,15 +84,8 @@ static int Control(vout_display_t *vd, int query, va_list args)
     return CommonControl(vd, query, args);
 }
 
-static int EmbedVideoWindow_Control(vout_window_t *wnd, int query, va_list ap)
-{
-    VLC_UNUSED( ap ); VLC_UNUSED( query );
-    return VLC_EGENERIC;
-}
-
 static const struct vout_window_operations embedVideoWindow_Ops =
 {
-    .control = EmbedVideoWindow_Control,
 };
 
 static vout_window_t *EmbedVideoWindow_Create(vout_display_t *vd)
diff --git a/modules/video_output/xcb/window.c b/modules/video_output/xcb/window.c
index f808926eea..791d1fbc09 100644
--- a/modules/video_output/xcb/window.c
+++ b/modules/video_output/xcb/window.c
@@ -423,30 +423,15 @@ static void Resize(vout_window_t *wnd, unsigned width, unsigned height)
     xcb_flush(conn);
 }
 
-static int Control (vout_window_t *wnd, int cmd, va_list ap)
+static void SetState(vout_window_t *wnd, unsigned state)
 {
-    vout_window_sys_t *p_sys = wnd->sys;
-    xcb_connection_t *conn = p_sys->conn;
-
-    switch (cmd)
-    {
-        case VOUT_WINDOW_SET_STATE:
-        {
-            unsigned state = va_arg (ap, unsigned);
-            bool above = (state & VOUT_WINDOW_STATE_ABOVE) != 0;
-            bool below = (state & VOUT_WINDOW_STATE_BELOW) != 0;
-
-            change_wm_state (wnd, above, p_sys->wm_state_above);
-            change_wm_state (wnd, below, p_sys->wm_state_below);
-            break;
-        }
+    vout_window_sys_t *sys = wnd->sys;
+    bool above = (state & VOUT_WINDOW_STATE_ABOVE) != 0;
+    bool below = (state & VOUT_WINDOW_STATE_BELOW) != 0;
 
-        default:
-            msg_Err (wnd, "request %d not implemented", cmd);
-            return VLC_EGENERIC;
-    }
-    xcb_flush (p_sys->conn);
-    return VLC_SUCCESS;
+    change_wm_state(wnd, above, sys->wm_state_above);
+    change_wm_state(wnd, below, sys->wm_state_below);
+    xcb_flush(sys->conn);
 }
 
 static void UnsetFullscreen(vout_window_t *wnd)
@@ -573,8 +558,8 @@ static const struct vout_window_operations ops = {
     .resize = Resize,
     .set_fullscreen = SetFullscreen,
     .unset_fullscreen = UnsetFullscreen,
-    .control = Control,
     .destroy = Close,
+    .set_state = SetState,
 };
 
 /**
@@ -835,7 +820,6 @@ static void ReleaseDrawable (vlc_object_t *obj, xcb_window_t window)
 static void EmClose(vout_window_t *);
 
 static const struct vout_window_operations em_ops = {
-    .control = Control,
     .destroy = EmClose,
 };
 



More information about the vlc-commits mailing list