Partially cleanup the vout_window API
authorRémi Denis-Courmont <rdenis@simphalempin.com>
Tue, 20 Jan 2009 17:20:07 +0000 (19:20 +0200)
committerRémi Denis-Courmont <rdenis@simphalempin.com>
Tue, 20 Jan 2009 17:21:02 +0000 (19:21 +0200)
include/vlc_vout.h
include/vlc_window.h
modules/control/hotkeys.c
modules/video_output/msw/events.c
modules/video_output/msw/vout.h
modules/video_output/omapfb.c
modules/video_output/x11/xcommon.c
modules/video_output/x11/xcommon.h
src/video_output/video_output.c
src/video_output/vout_intf.c

index 6cbf932..2cd78ab 100644 (file)
@@ -512,7 +512,6 @@ struct vout_thread_t
     unsigned int        i_window_height;            /**< video window height */
     unsigned int        i_alignment;          /**< video alignment in window */
 
-    struct vout_window_t *p_window;   /**< window for embedded vout (if any) */
     /**@}*/
 
     /** \name Plugin used and shortcuts to access its capabilities */
@@ -670,9 +669,6 @@ VLC_EXPORT( void,            vout_UnlinkPicture,  ( vout_thread_t *, picture_t *
 VLC_EXPORT( void,            vout_PlacePicture,   ( vout_thread_t *, unsigned int, unsigned int, unsigned int *, unsigned int *, unsigned int *, unsigned int * ) );
 
 VLC_EXPORT( int, vout_vaControlDefault, ( vout_thread_t *, int, va_list ) );
-VLC_EXPORT( void *, vout_RequestWindow, ( vout_thread_t *, int *, int *, unsigned int *, unsigned int * ) );
-VLC_EXPORT( void,   vout_ReleaseWindow, ( vout_thread_t *, void * ) );
-VLC_EXPORT( int, vout_ControlWindow, ( vout_thread_t *, void *, int, va_list ) );
 void vout_IntfInit( vout_thread_t * );
 VLC_EXPORT( int, vout_Snapshot, ( vout_thread_t *p_vout, picture_t *p_pic ) );
 VLC_EXPORT( void, vout_EnableFilter, ( vout_thread_t *, char *,bool , bool  ) );
index 9e95a6b..41d58cb 100644 (file)
@@ -46,4 +46,8 @@ struct vout_window_t
     int (*control) (struct vout_window_t *, int, va_list);
 };
 
+VLC_EXPORT( vout_window_t *, vout_RequestWindow, ( vout_thread_t *, int *, int *, unsigned int *, unsigned int * ) );
+VLC_EXPORT( void,   vout_ReleaseWindow, ( vout_window_t * ) );
+VLC_EXPORT( int, vout_ControlWindow, ( vout_window_t *, int, va_list ) );
+
 #endif /* !LIBVLCCORE_WINDOW_H */
index 3e93d61..c8927b7 100644 (file)
@@ -1021,7 +1021,7 @@ static void DisplayPosition( intf_thread_t *p_intf, vout_thread_t *p_vout,
         vout_OSDMessage( p_input, POSITION_TEXT_CHAN, psz_time );
     }
 
-    if( !p_vout->p_window || p_vout->b_fullscreen )
+    if( p_vout->b_fullscreen )
     {
         var_Get( p_input, "position", &pos );
         vout_OSDSlider( VLC_OBJECT( p_input ), POSITION_WIDGET_CHAN,
@@ -1038,7 +1038,7 @@ static void DisplayVolume( intf_thread_t *p_intf, vout_thread_t *p_vout,
     }
     ClearChannels( p_intf, p_vout );
 
-    if( !p_vout->p_window || p_vout->b_fullscreen )
+    if( p_vout->b_fullscreen )
     {
         vout_OSDSlider( VLC_OBJECT( p_vout ), VOLUME_WIDGET_CHAN,
             i_vol*100/AOUT_VOLUME_MAX, OSD_VERT_SLIDER );
index 35c74f3..0d60399 100644 (file)
@@ -41,6 +41,7 @@
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
 #include <vlc_vout.h>
+#include <vlc_window.h>
 
 #include <windows.h>
 #include <windowsx.h>
@@ -64,7 +65,7 @@
     //WINSHELLAPI BOOL WINAPI SHFullScreen(HWND hwndRequester, DWORD dwState);
 #endif
 
-/*#if defined(UNDER_CE) && !defined(__PLUGIN__) /*FIXME*/
+/*#if defined(UNDER_CE) && !defined(__PLUGIN__) --FIXME*/
 /*#   define SHFS_SHOWSIPBUTTON 0x0004
 #   define SHFS_HIDESIPBUTTON 0x0008
 #   define MENU_HEIGHT 26
@@ -80,6 +81,7 @@ static void DirectXCloseWindow ( vout_thread_t *p_vout );
 static long FAR PASCAL DirectXEventProc( HWND, UINT, WPARAM, LPARAM );
 
 static int Control( vout_thread_t *p_vout, int i_query, va_list args );
+static int vaControlParentWindow( vout_thread_t *, int, va_list );
 
 static void DirectXPopupMenu( event_thread_t *p_event, bool b_open )
 {
@@ -416,11 +418,12 @@ static int DirectXCreateWindow( vout_thread_t *p_vout )
     hInstance = GetModuleHandle(NULL);
 
     /* If an external window was specified, we'll draw in it. */
-    p_vout->p_sys->hparent =
+    p_vout->p_sys->parent_window =
         vout_RequestWindow( p_vout, &p_vout->p_sys->i_window_x,
                             &p_vout->p_sys->i_window_y,
                             &p_vout->p_sys->i_window_width,
                             &p_vout->p_sys->i_window_height );
+    p_vout->p_sys->hparent = p_vout->p_sys->parent_window->handle;
 
     /* We create the window ourself, there is no previous window proc. */
     p_vout->p_sys->pf_wndproc = NULL;
@@ -598,9 +601,7 @@ static void DirectXCloseWindow( vout_thread_t *p_vout )
     DestroyWindow( p_vout->p_sys->hwnd );
     if( p_vout->p_sys->hfswnd ) DestroyWindow( p_vout->p_sys->hfswnd );
 
-    if( p_vout->p_sys->hparent )
-        vout_ReleaseWindow( p_vout, (void *)p_vout->p_sys->hparent );
-
+    vout_ReleaseWindow( p_vout->p_sys->parent_window );
     p_vout->p_sys->hwnd = NULL;
 
     /* We don't unregister the Window Class because it could lead to race
@@ -1044,9 +1045,8 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args )
     switch( i_query )
     {
     case VOUT_GET_SIZE:
-        if( p_vout->p_sys->hparent )
-            return vout_ControlWindow( p_vout,
-                    (void *)p_vout->p_sys->hparent, i_query, args );
+        if( p_vout->p_sys->parent_window )
+            return vaControlParentWindow( p_vout, i_query, args );
 
         pi_width  = va_arg( args, unsigned int * );
         pi_height = va_arg( args, unsigned int * );
@@ -1058,9 +1058,8 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args )
         return VLC_SUCCESS;
 
     case VOUT_SET_SIZE:
-        if( p_vout->p_sys->hparent )
-            return vout_ControlWindow( p_vout,
-                    (void *)p_vout->p_sys->hparent, i_query, args );
+        if( p_vout->p_sys->parent_window )
+            return vaControlParentWindow( p_vout, i_query, args );
 
         /* Update dimensions */
         rect_window.top = rect_window.left = 0;
@@ -1121,12 +1120,12 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args )
                           SWP_FRAMECHANGED );
         }
 
-        return vout_vaControlDefault( p_vout, i_query, args );
+        vout_ReleaseWindow( p_vout->p_sys->parent_window );
+        return VLC_SUCCESS;
 
     case VOUT_SET_STAY_ON_TOP:
         if( p_vout->p_sys->hparent && !var_GetBool( p_vout, "fullscreen" ) )
-            return vout_ControlWindow( p_vout,
-                    (void *)p_vout->p_sys->hparent, i_query, args );
+            return vaControlParentWindow( p_vout, i_query, args );
 
         p_vout->p_sys->b_on_top_change = true;
         return VLC_SUCCESS;
@@ -1165,13 +1164,21 @@ static void SetWindowState(HWND hwnd, int nShowCmd,WINDOWPLACEMENT window_placem
 }
 
 /* Internal wrapper to call vout_ControlWindow for hparent */
-static void ControlParentWindow( vout_thread_t *p_vout, int i_query, ... )
+static int vaControlParentWindow( vout_thread_t *p_vout, int i_query,
+                                   va_list args )
+{
+    return vout_ControlWindow( p_vout->p_sys->parent_window, i_query, args );
+}
+
+static int ControlParentWindow( vout_thread_t *p_vout, int i_query, ... )
 {
     va_list args;
+    int ret;
+
     va_start( args, i_query );
-    vout_ControlWindow( p_vout,
-        (void *)p_vout->p_sys->hparent, i_query, args );
+    ret = vaControlParentWindow( p_vout, i_query, args );
     va_end( args );
+    return ret;
 }
 
 void Win32ToggleFullscreen( vout_thread_t *p_vout )
index d1753f1..945899b 100644 (file)
@@ -68,6 +68,8 @@ typedef struct event_thread_t
 
 #endif
 
+struct vout_window_t;
+
 /*****************************************************************************
  * vout_sys_t: video output method descriptor
  *****************************************************************************
@@ -78,6 +80,7 @@ struct vout_sys_t
 {
     HWND                 hwnd;                  /* Handle of the main window */
     HWND                 hvideownd;        /* Handle of the video sub-window */
+    struct vout_window_t *parent_window;         /* Parent window VLC object */
     HWND                 hparent;             /* Handle of the parent window */
     HWND                 hfswnd;          /* Handle of the fullscreen window */
     WNDPROC              pf_wndproc;             /* Window handling callback */
index 5732d04..dc62567 100644 (file)
@@ -50,6 +50,7 @@
 #include <vlc_plugin.h>
 #include <vlc_keys.h>
 #include <vlc_vout.h>
+#include <vlc_window.h>
 #include <vlc_playlist.h>
 
 /*****************************************************************************
@@ -160,7 +161,7 @@ struct vout_sys_t
 
     /* X11 */
     Display   *p_display;
-    Window     owner_window;
+    vout_window_t *owner_window;
     Window     window;
     mtime_t    i_time_button_last_pressed;         /* To detect double click */
 
@@ -243,7 +244,7 @@ static void Destroy( vlc_object_t *p_this )
 
     if( p_vout->p_sys->b_embed )
     {
-        vout_ReleaseWindow( p_vout, (void *)p_vout->p_sys->owner_window );
+        vout_ReleaseWindow( p_vout->p_sys->owner_window );
         if( p_vout->b_fullscreen )
             XDestroyWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
         XCloseDisplay( p_vout->p_sys->p_display );
@@ -374,6 +375,10 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args )
 {
     switch( i_query )
     {
+       case VOUT_REPARENT:
+       case VOUT_CLOSE:
+            vout_ReleaseWindow( p_vout->p_sys->owner_window );
+            return VLC_SUCCESS;
        default:
             return vout_vaControlDefault( p_vout, i_query, args );
     }
@@ -696,7 +701,7 @@ static void CreateWindow( vout_sys_t *p_sys )
         BlackPixel( p_sys->p_display, DefaultScreen(p_sys->p_display) );
     xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask;
     p_sys->window = XCreateWindow( p_sys->p_display,
-                                   p_sys->owner_window,
+                                   p_sys->owner_window->handle,
                                    0, 0,
                                    p_sys->main_window.i_width,
                                    p_sys->main_window.i_height,
@@ -709,7 +714,7 @@ static void CreateWindow( vout_sys_t *p_sys )
     XSelectInput( p_sys->p_display, p_sys->window,
                   KeyPressMask | ButtonPressMask | StructureNotifyMask |
                   VisibilityChangeMask | FocusChangeMask );
-    XSelectInput( p_sys->p_display, p_sys->owner_window,
+    XSelectInput( p_sys->p_display, p_sys->owner_window->handle,
                   StructureNotifyMask );
     XSetInputFocus( p_sys->p_display, p_sys->window, RevertToParent, CurrentTime );
 }
index 4286464..1d0771d 100644 (file)
@@ -35,6 +35,7 @@
 #include <vlc_interface.h>
 #include <vlc_playlist.h>
 #include <vlc_vout.h>
+#include <vlc_window.h>
 #include <vlc_keys.h>
 
 #include <errno.h>                                                 /* ENOMEM */
@@ -1160,7 +1161,7 @@ static int ManageVideo( vout_thread_t *p_vout )
     if( p_vout->p_sys->p_win->owner_window )
     {
         while( XCheckWindowEvent( p_vout->p_sys->p_display,
-                                  p_vout->p_sys->p_win->owner_window,
+                                  p_vout->p_sys->p_win->owner_window->handle,
                                   StructureNotifyMask, &xevent ) == True )
         {
             /* ConfigureNotify event: prepare  */
@@ -1621,9 +1622,8 @@ static int CreateWindow( vout_thread_t *p_vout, x11_window_t *p_win )
 
     if( !p_vout->b_fullscreen )
     {
-        void *ptr = vout_RequestWindow( p_vout, &p_win->i_x, &p_win->i_y,
-                                        &p_win->i_width, &p_win->i_height );
-        p_win->owner_window = (uintptr_t)ptr;
+        p_win->owner_window = vout_RequestWindow( p_vout, &p_win->i_x,
+                              &p_win->i_y, &p_win->i_width, &p_win->i_height );
         xsize_hints.base_width  = xsize_hints.width = p_win->i_width;
         xsize_hints.base_height = xsize_hints.height = p_win->i_height;
         xsize_hints.flags       = PSize | PMinSize;
@@ -1638,7 +1638,7 @@ static int CreateWindow( vout_thread_t *p_vout, x11_window_t *p_win )
     else
     {
         /* Fullscreen window size and position */
-        p_win->owner_window = 0;
+        p_win->owner_window = NULL;
         p_win->i_x = p_win->i_y = 0;
         p_win->i_width =
             DisplayWidth( p_vout->p_sys->p_display, p_vout->p_sys->i_screen );
@@ -1719,11 +1719,11 @@ static int CreateWindow( vout_thread_t *p_vout, x11_window_t *p_win )
         unsigned int dummy4, dummy5;
 
         /* Select events we are interested in. */
-        XSelectInput( p_vout->p_sys->p_display, p_win->owner_window,
+        XSelectInput( p_vout->p_sys->p_display, p_win->owner_window->handle,
                       StructureNotifyMask );
 
         /* Get the parent window's geometry information */
-        XGetGeometry( p_vout->p_sys->p_display, p_win->owner_window,
+        XGetGeometry( p_vout->p_sys->p_display, p_win->owner_window->handle,
                       &dummy1, &dummy2, &dummy3,
                       &p_win->i_width,
                       &p_win->i_height,
@@ -1736,7 +1736,7 @@ static int CreateWindow( vout_thread_t *p_vout, x11_window_t *p_win )
          * ButtonPress event, so we need to open a new window anyway. */
         p_win->base_window =
             XCreateWindow( p_vout->p_sys->p_display,
-                           p_win->owner_window,
+                           p_win->owner_window->handle,
                            0, 0,
                            p_win->i_width, p_win->i_height,
                            0,
@@ -1883,8 +1883,7 @@ static void DestroyWindow( vout_thread_t *p_vout, x11_window_t *p_win )
     XUnmapWindow( p_vout->p_sys->p_display, p_win->base_window );
     XDestroyWindow( p_vout->p_sys->p_display, p_win->base_window );
 
-    if( p_win->owner_window )
-        vout_ReleaseWindow( p_vout, (void *)p_win->owner_window );
+    vout_ReleaseWindow( p_win->owner_window );
 }
 
 /*****************************************************************************
@@ -3131,8 +3130,8 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args )
     {
         case VOUT_GET_SIZE:
             if( p_vout->p_sys->p_win->owner_window )
-                return vout_ControlWindow( p_vout,
-                    (void *)p_vout->p_sys->p_win->owner_window, i_query, args);
+                return vout_ControlWindow( p_vout->p_sys->p_win->owner_window,
+                                           i_query, args);
 
             pi_width  = va_arg( args, unsigned int * );
             pi_height = va_arg( args, unsigned int * );
@@ -3145,8 +3144,8 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args )
 
         case VOUT_SET_SIZE:
             if( p_vout->p_sys->p_win->owner_window )
-                return vout_ControlWindow( p_vout,
-                    (void *)p_vout->p_sys->p_win->owner_window, i_query, args);
+                return vout_ControlWindow( p_vout->p_sys->p_win->owner_window,
+                                           i_query, args);
 
             vlc_mutex_lock( &p_vout->p_sys->lock );
 
@@ -3193,17 +3192,18 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args )
                              p_vout->p_sys->original_window.base_window,
                              d, 0, 0);
             XSync( p_vout->p_sys->p_display, False );
-            p_vout->p_sys->original_window.owner_window = 0;
 #ifdef MODULE_NAME_IS_xvmc
             xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
 #endif
             vlc_mutex_unlock( &p_vout->p_sys->lock );
-            return vout_vaControlDefault( p_vout, i_query, args );
+            vout_ReleaseWindow( p_vout->p_sys->p_win->owner_window );
+            p_vout->p_sys->original_window.owner_window = NULL;
+            return VLC_SUCCESS;
 
         case VOUT_SET_STAY_ON_TOP:
             if( p_vout->p_sys->p_win->owner_window )
-                return vout_ControlWindow( p_vout,
-                    (void *)p_vout->p_sys->p_win->owner_window, i_query, args);
+                return vout_ControlWindow( p_vout->p_sys->p_win->owner_window,
+                                           i_query, args);
 
             b_arg = (bool) va_arg( args, int );
             vlc_mutex_lock( &p_vout->p_sys->lock );
index aaf8242..e82a56a 100644 (file)
@@ -55,6 +55,7 @@
 #include <libosso.h>
 #endif
 
+struct vout_window_t;
 
 /*****************************************************************************
  * x11_window_t: X11 window descriptor
@@ -63,7 +64,7 @@
  *****************************************************************************/
 typedef struct x11_window_t
 {
-    Window              owner_window;               /* owner window (if any) */
+    struct vout_window_t*owner_window;               /* owner window (if any) */
     Window              base_window;                          /* base window */
     Window              video_window;     /* sub-window for displaying video */
     GC                  gc;              /* graphic context instance handler */
index 8ec40d9..6ffe6ae 100644 (file)
@@ -385,7 +385,6 @@ vout_thread_t * __vout_Create( vlc_object_t *p_parent, video_format_t *p_fmt )
     p_vout->p->b_paused = false;
     p_vout->p->i_pause_date = 0;
     p_vout->pf_control = NULL;
-    p_vout->p_window = NULL;
     p_vout->p->i_par_num =
     p_vout->p->i_par_den = 1;
     p_vout->p->p_picture_displayed = NULL;
index dcfb063..e4dd70c 100644 (file)
@@ -81,30 +81,25 @@ static int TitlePositionCallback( vlc_object_t *, char const *,
 
 /**
  * Creates a video output window.
- * On Unix systems, this returns an X11 drawable handle.
- * On Windows, this returns a Win32 window handle.
+ * On Unix systems, this is an X11 drawable (handle).
+ * On Windows, this is a Win32 window (handle).
  * Video output plugins are supposed to called this function and display the
  * video within the resulting window, while in windowed mode.
  *
- * Note that a given video output thread must not allocate more than one
- * such window at a time.
- *
  * @param p_vout video output thread to create a window for
  * @param pi_x_hint pointer to store the recommended horizontal position [OUT]
  * @param pi_y_hint pointer to store the recommended vertical position [OUT]
  * @param pi_width_hint pointer to store the recommended width [OUT]
  * @param pi_height_hint pointer to store the recommended height [OUT]
  *
- * @return a platform-specific window handle, or NULL in case of failure.
- * In case of success, the handle is released with vout_ReleaseWindow().
+ * @return a vout_window_t object, or NULL in case of failure.
+ * The window is released with vout_ReleaseWindow().
  */
-void *vout_RequestWindow( vout_thread_t *p_vout,
+vout_window_t *vout_RequestWindow( vout_thread_t *p_vout,
                           int *pi_x_hint, int *pi_y_hint,
                           unsigned int *pi_width_hint,
                           unsigned int *pi_height_hint )
 {
-    assert (p_vout->p_window == NULL);
-
     /* Get requested coordinates */
     *pi_x_hint = var_GetInteger( p_vout, "video-x" );
     *pi_y_hint = var_GetInteger( p_vout, "video-y" );
@@ -135,40 +130,31 @@ void *vout_RequestWindow( vout_thread_t *p_vout,
         vlc_object_release (wnd);
         return NULL;
     }
-    p_vout->p_window = wnd;
     *pi_width_hint = wnd->width;
     *pi_height_hint = wnd->height;
     *pi_x_hint = wnd->pos_x;
     *pi_y_hint = wnd->pos_y;
-    return wnd->handle;
+    return wnd;
 }
 
 /**
  * Releases a window handle obtained with vout_RequestWindow().
  * @param p_vout video output thread that allocated the window
- * @param dummy unused legacy paramater
+ *               (if this is NULL; this fnction is a no-op).
  */
-void vout_ReleaseWindow( vout_thread_t *p_vout, void *dummy )
+void vout_ReleaseWindow( vout_window_t *wnd )
 {
-    vout_window_t *wnd = p_vout->p_window;
-
     if (wnd == NULL)
         return;
-    p_vout->p_window = NULL;
 
     assert (wnd->module);
     module_unneed (wnd, wnd->module);
 
     vlc_object_release (wnd);
-    (void)dummy;
 }
 
-int vout_ControlWindow( vout_thread_t *p_vout, void *dummy,
-                        int i_query, va_list args )
+int vout_ControlWindow( vout_window_t *wnd, int i_query, va_list args )
 {
-    (void)dummy;
-    vout_window_t *wnd = p_vout->p_window;
-
     if (wnd == NULL)
         return VLC_EGENERIC;
 
@@ -922,11 +908,6 @@ int vout_vaControlDefault( vout_thread_t *p_vout, int i_query, va_list args )
     (void)args;
     switch( i_query )
     {
-    case VOUT_REPARENT:
-    case VOUT_CLOSE:
-        vout_ReleaseWindow( p_vout, NULL );
-        return VLC_SUCCESS;
-
     case VOUT_SNAPSHOT:
         p_vout->p->b_snapshot = true;
         return VLC_SUCCESS;