]> git.sesse.net Git - vlc/blobdiff - modules/video_output/directx/directx.c
* ALL: use i_visible_lines in plane_t.
[vlc] / modules / video_output / directx / directx.c
index 2ba1032012982e076713c408cbdda41b94e93aa2..eab877d0febf6505009178b2b59223c939797868 100644 (file)
@@ -44,6 +44,7 @@
 
 #include <windows.h>
 #include <ddraw.h>
+#include <commctrl.h>
 
 #include <multimon.h>
 #undef GetSystemMetrics
@@ -93,11 +94,13 @@ static int  DirectXUnlockSurface  ( vout_thread_t *p_vout, picture_t *p_pic );
 
 static DWORD DirectXFindColorkey( vout_thread_t *p_vout, uint32_t i_color );
 
+void SwitchWallpaperMode( vout_thread_t *, vlc_bool_t );
+
 /* Object variables callbacks */
-static int OnTopCallback( vlc_object_t *, char const *,
-                          vlc_value_t, vlc_value_t, void * );
 static int FindDevicesCallback( vlc_object_t *, char const *,
                                 vlc_value_t, vlc_value_t, void * );
+static int WallpaperCallback( vlc_object_t *, char const *,
+                              vlc_value_t, vlc_value_t, void * );
 
 /*****************************************************************************
  * Module descriptor
@@ -116,13 +119,20 @@ static int FindDevicesCallback( vlc_object_t *, char const *,
 
 #define TRIPLEBUF_TEXT N_("Use triple buffering for overlays")
 #define TRIPLEBUF_LONGTEXT N_( \
-    "Try to use triple bufferring when using YUV overlays. That results in " \
+    "Try to use triple buffering when using YUV overlays. That results in " \
     "much better video quality (no flickering)." )
 
 #define DEVICE_TEXT N_("Name of desired display device")
-#define DEVICE_LONGTEXT N_("In a multimonitor configuration, you can specify "\
-    "the Windows device name of the display that you want the video window " \
-    "to open on. For example, \"\\\\.\\DISPLAY1\" or \"\\\\.\\DISPLAY2\"." )
+#define DEVICE_LONGTEXT N_("In a multiple monitor configuration, you can " \
+    "specify the Windows device name of the display that you want the video " \
+    "window to open on. For example, \"\\\\.\\DISPLAY1\" or " \
+    "\"\\\\.\\DISPLAY2\"." )
+
+#define WALLPAPER_TEXT N_("Enable wallpaper mode ")
+#define WALLPAPER_LONGTEXT N_( \
+    "The wallpaper mode allows you to display the video as the desktop " \
+    "background. Note that this feature only works in overlay mode and " \
+    "the desktop must not already have a wallpaper." )
 
 static char *ppsz_dev[] = { "" };
 static char *ppsz_dev_text[] = { N_("Default") };
@@ -140,6 +150,9 @@ vlc_module_begin();
         change_string_list( ppsz_dev, ppsz_dev_text, FindDevicesCallback );
         change_action_add( FindDevicesCallback, N_("Refresh list") );
 
+    add_bool( "directx-wallpaper", 0, NULL, WALLPAPER_TEXT, WALLPAPER_LONGTEXT,
+              VLC_TRUE );
+
     set_description( _("DirectX video output") );
     set_capability( "video output", 100 );
     add_shortcut( "directx" );
@@ -162,7 +175,7 @@ vlc_module_end();
 static int OpenVideo( vlc_object_t *p_this )
 {
     vout_thread_t * p_vout = (vout_thread_t *)p_this;
-    vlc_value_t val, text;
+    vlc_value_t val;
     HMODULE huser32;
 
     /* Allocate structure */
@@ -188,7 +201,10 @@ static int OpenVideo( vlc_object_t *p_this )
     p_vout->p_sys->hwnd = p_vout->p_sys->hvideownd = NULL;
     p_vout->p_sys->hparent = NULL;
     p_vout->p_sys->i_changes = 0;
-    SetRectEmpty( &p_vout->p_sys->rect_display  );
+    p_vout->p_sys->b_wallpaper = 0;
+    vlc_mutex_init( p_vout, &p_vout->p_sys->lock );
+    SetRectEmpty( &p_vout->p_sys->rect_display );
+    SetRectEmpty( &p_vout->p_sys->rect_parent );
 
     /* Multimonitor stuff */
     p_vout->p_sys->hmonitor = NULL;
@@ -208,6 +224,7 @@ static int OpenVideo( vlc_object_t *p_this )
     var_Create( p_vout, "directx-hw-yuv", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
     var_Create( p_vout, "directx-3buffering", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
     var_Create( p_vout, "directx-device", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+    var_Create( p_vout, "video-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
 
     p_vout->p_sys->b_cursor_hidden = 0;
     p_vout->p_sys->i_lastmoved = mdate();
@@ -260,13 +277,19 @@ static int OpenVideo( vlc_object_t *p_this )
         goto error;
     }
 
-    /* Add a variable to indicate if the window should be on top of others */
-    var_Create( p_vout, "video-on-top", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
-    text.psz_string = _("Always on top");
-    var_Change( p_vout, "video-on-top", VLC_VAR_SETTEXT, &text, NULL );
+    /* Variable to indicate if the window should be on top of others */
+    /* Trigger a callback right now */
     var_Get( p_vout, "video-on-top", &val );
-    p_vout->p_sys->b_on_top_change = val.b_bool;
-    var_AddCallback( p_vout, "video-on-top", OnTopCallback, NULL );
+    var_Set( p_vout, "video-on-top", val );
+
+    /* Variable to indicate if the window should be on top of others */
+    /* Trigger a callback right now */
+    var_Create( p_vout, "directx-wallpaper", VLC_VAR_BOOL|VLC_VAR_DOINHERIT );
+    val.psz_string = _("Wallpaper");
+    var_Change( p_vout, "directx-wallpaper", VLC_VAR_SETTEXT, &val, NULL );
+    var_AddCallback( p_vout, "directx-wallpaper", WallpaperCallback, NULL );
+    var_Get( p_vout, "directx-wallpaper", &val );
+    var_Set( p_vout, "directx-wallpaper", val );
 
     return VLC_SUCCESS;
 
@@ -375,8 +398,7 @@ static int Init( vout_thread_t *p_vout )
     }
 
     /* Change the window title bar text */
-    if( p_vout->p_sys->hparent ) ; /* Do nothing */
-    else PostMessage( p_vout->p_sys->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 );
+    PostMessage( p_vout->p_sys->hwnd, WM_VLC_CHANGE_TEXT, 0, 0 );
 
     return VLC_SUCCESS;
 }
@@ -408,8 +430,6 @@ static void CloseVideo( vlc_object_t *p_this )
 
     msg_Dbg( p_vout, "CloseVideo" );
 
-    var_Destroy( p_vout, "video-on-top" );
-
     if( p_vout->p_sys->p_event )
     {
         vlc_object_detach( p_vout->p_sys->p_event );
@@ -428,6 +448,11 @@ static void CloseVideo( vlc_object_t *p_this )
         vlc_object_destroy( p_vout->p_sys->p_event );
     }
 
+    vlc_mutex_destroy( &p_vout->p_sys->lock );
+
+    /* Make sure the wallpaper is restored */
+    SwitchWallpaperMode( p_vout, VLC_FALSE );
+
     if( p_vout->p_sys )
     {
         free( p_vout->p_sys );
@@ -439,7 +464,7 @@ static void CloseVideo( vlc_object_t *p_this )
  * Manage: handle Sys events
  *****************************************************************************
  * This function should be called regularly by the video output thread.
- * It returns a non null value if an error occured.
+ * It returns a non null value if an error occurred.
  *****************************************************************************/
 static int Manage( vout_thread_t *p_vout )
 {
@@ -447,9 +472,37 @@ static int Manage( vout_thread_t *p_vout )
 
     /* If we do not control our window, we check for geometry changes
      * ourselves because the parent might not send us its events. */
-    if( p_vout->p_sys->hparent )
+    vlc_mutex_lock( &p_vout->p_sys->lock );
+    if( p_vout->p_sys->hparent && !p_vout->b_fullscreen )
+    {
+        RECT rect_parent;
+        POINT point;
+
+        vlc_mutex_unlock( &p_vout->p_sys->lock );
+
+        GetClientRect( p_vout->p_sys->hparent, &rect_parent );
+        point.x = point.y = 0;
+        ClientToScreen( p_vout->p_sys->hparent, &point );
+        OffsetRect( &rect_parent, point.x, point.y );
+
+        if( !EqualRect( &rect_parent, &p_vout->p_sys->rect_parent ) )
+        {
+            p_vout->p_sys->rect_parent = rect_parent;
+
+            /* This one is to force the update even if only
+             * the position has changed */
+            SetWindowPos( p_vout->p_sys->hwnd, 0, 1, 1,
+                          rect_parent.right - rect_parent.left,
+                          rect_parent.bottom - rect_parent.top, 0 );
+
+            SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0,
+                          rect_parent.right - rect_parent.left,
+                          rect_parent.bottom - rect_parent.top, 0 );
+        }
+    }
+    else
     {
-        DirectXUpdateRects( p_vout, VLC_FALSE );
+        vlc_mutex_unlock( &p_vout->p_sys->lock );
     }
 
     /*
@@ -457,8 +510,7 @@ static int Manage( vout_thread_t *p_vout )
      */
     if( p_vout->p_sys->i_changes & DX_POSITION_CHANGE )
     {
-        if( p_vout->p_sys->b_using_overlay )
-            DirectXUpdateOverlay( p_vout );
+        p_vout->p_sys->i_changes &= ~DX_POSITION_CHANGE;
 
         /* Check if we are still on the same monitor */
         if( p_vout->p_sys->MonitorFromWindow &&
@@ -469,8 +521,6 @@ static int Manage( vout_thread_t *p_vout )
             /* This will force the vout core to recreate the picture buffers */
             p_vout->i_changes |= VOUT_PICTURE_BUFFERS_CHANGE;
         }
-
-        p_vout->p_sys->i_changes &= ~DX_POSITION_CHANGE;
     }
 
     /* We used to call the Win32 PeekMessage function here to read the window
@@ -478,37 +528,76 @@ static int Manage( vout_thread_t *p_vout )
      * long time (for example when you move your window on the screen), I
      * decided to isolate PeekMessage in another thread. */
 
+    if( p_vout->p_sys->i_changes & DX_WALLPAPER_CHANGE )
+    {
+        SwitchWallpaperMode( p_vout, !p_vout->p_sys->b_wallpaper );
+        p_vout->p_sys->i_changes &= ~DX_WALLPAPER_CHANGE;
+        DirectXUpdateOverlay( p_vout );
+    }
+
     /*
      * Fullscreen change
      */
     if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE
         || p_vout->p_sys->i_changes & VOUT_FULLSCREEN_CHANGE )
     {
+        int i_style = 0;
         vlc_value_t val;
 
         p_vout->b_fullscreen = ! p_vout->b_fullscreen;
 
         /* We need to switch between Maximized and Normal sized window */
         window_placement.length = sizeof(WINDOWPLACEMENT);
-        GetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
         if( p_vout->b_fullscreen )
         {
+            if( p_vout->p_sys->hparent )
+            {
+                POINT point;
+
+                /* Retrieve the window position */
+                point.x = point.y = 0;
+                ClientToScreen( p_vout->p_sys->hwnd, &point );
+                SetParent( p_vout->p_sys->hwnd, GetDesktopWindow() );
+                SetWindowPos( p_vout->p_sys->hwnd, 0, point.x, point.y, 0, 0,
+                              SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED );
+                SetForegroundWindow( p_vout->p_sys->hwnd );
+            }
+
             /* Maximized window */
+            GetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
             window_placement.showCmd = SW_SHOWMAXIMIZED;
             /* Change window style, no borders and no title bar */
-            SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE, WS_CLIPCHILDREN );
-
+            i_style = WS_CLIPCHILDREN | WS_VISIBLE | WS_POPUP;
         }
         else
         {
+            if( p_vout->p_sys->hparent )
+            {
+                SetParent( p_vout->p_sys->hwnd, p_vout->p_sys->hparent );
+                SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0, 0, 0,
+                              SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED );
+                i_style = WS_CLIPCHILDREN | WS_VISIBLE | WS_CHILD;
+                SetForegroundWindow( p_vout->p_sys->hparent );
+            }
+            else
+            {
+                i_style = WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW |
+                          WS_SIZEBOX | WS_VISIBLE;
+            }
+
             /* Normal window */
+            GetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
             window_placement.showCmd = SW_SHOWNORMAL;
-            /* Change window style, borders and title bar */
-            SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE, WS_CLIPCHILDREN |
-                           WS_OVERLAPPEDWINDOW | WS_SIZEBOX | WS_VISIBLE );
+
+            /* Make sure the mouse cursor is displayed */
+            PostMessage( p_vout->p_sys->hwnd, WM_VLC_SHOW_MOUSE, 0, 0 );
         }
 
+        /* Change window style, borders and title bar */
+        SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE, i_style );
         SetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
+        SetWindowPos( p_vout->p_sys->hwnd, 0, 0, 0, 0, 0,
+                      SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED );
 
         /* Update the object variable and trigger callback */
         val.b_bool = p_vout->b_fullscreen;
@@ -521,15 +610,23 @@ static int Manage( vout_thread_t *p_vout )
     /*
      * Pointer change
      */
-    if( (!p_vout->p_sys->b_cursor_hidden) &&
-        ( (mdate() - p_vout->p_sys->i_lastmoved) > 5000000 ) )
+    if( p_vout->b_fullscreen && !p_vout->p_sys->b_cursor_hidden &&
+        (mdate() - p_vout->p_sys->i_lastmoved) > 5000000 )
     {
-        /* Hide the mouse automatically */
-        if( p_vout->p_sys->hwnd != p_vout->p_sys->hparent )
+        POINT point;
+        HWND hwnd;
+
+        /* Hide the cursor only if it is inside our window */
+        GetCursorPos( &point );
+        hwnd = WindowFromPoint(point);
+        if( hwnd == p_vout->p_sys->hwnd || hwnd == p_vout->p_sys->hvideownd )
         {
-            p_vout->p_sys->b_cursor_hidden = VLC_TRUE;
             PostMessage( p_vout->p_sys->hwnd, WM_VLC_HIDE_MOUSE, 0, 0 );
         }
+        else
+        {
+            p_vout->p_sys->i_lastmoved = mdate();
+        }
     }
 
     /*
@@ -1087,10 +1184,35 @@ int DirectXUpdateOverlay( vout_thread_t *p_vout )
     DDOVERLAYFX     ddofx;
     DWORD           dwFlags;
     HRESULT         dxresult;
+    RECT            rect_src = p_vout->p_sys->rect_src_clipped;
+    RECT            rect_dest = p_vout->p_sys->rect_dest_clipped;
+
+    if( !p_vout->p_sys->b_using_overlay ) return VLC_EGENERIC;
+
+    if( p_vout->p_sys->b_wallpaper )
+    {
+        int i_x, i_y, i_width, i_height;
 
-    if( p_vout->p_sys->p_current_surface == NULL ||
-        !p_vout->p_sys->b_using_overlay )
+        rect_src.left = rect_src.top = 0;
+        rect_src.right = p_vout->render.i_width;
+        rect_src.bottom = p_vout->render.i_height;
+
+        rect_dest = p_vout->p_sys->rect_display;
+        vout_PlacePicture( p_vout, rect_dest.right, rect_dest.bottom,
+                           &i_x, &i_y, &i_width, &i_height );
+
+        rect_dest.left += i_x;
+        rect_dest.right = rect_dest.left + i_width;
+        rect_dest.top += i_y;
+        rect_dest.bottom = rect_dest.top + i_height;
+    }
+
+    vlc_mutex_lock( &p_vout->p_sys->lock );
+    if( p_vout->p_sys->p_current_surface == NULL )
+    {
+        vlc_mutex_unlock( &p_vout->p_sys->lock );
         return VLC_EGENERIC;
+    }
 
     /* The new window dimensions should already have been computed by the
      * caller of this function */
@@ -1104,15 +1226,15 @@ int DirectXUpdateOverlay( vout_thread_t *p_vout )
     dwFlags = DDOVER_SHOW | DDOVER_KEYDESTOVERRIDE;
 
     dxresult = IDirectDrawSurface2_UpdateOverlay(
-                                         p_vout->p_sys->p_current_surface,
-                                         &p_vout->p_sys->rect_src_clipped,
-                                         p_vout->p_sys->p_display,
-                                         &p_vout->p_sys->rect_dest_clipped,
-                                         dwFlags, &ddofx );
+                   p_vout->p_sys->p_current_surface,
+                   &rect_src, p_vout->p_sys->p_display, &rect_dest,
+                   dwFlags, &ddofx );
+
+    vlc_mutex_unlock( &p_vout->p_sys->lock );
+
     if(dxresult != DD_OK)
     {
-        msg_Warn( p_vout,
-                  "DirectXUpdateOverlay cannot move or resize overlay" );
+        msg_Warn( p_vout, "DirectXUpdateOverlay cannot move/resize overlay" );
         return VLC_EGENERIC;
     }
 
@@ -1270,7 +1392,7 @@ static int NewPictureVec( vout_thread_t *p_vout, picture_t *p_pic,
             {
                 int i,j;
                 for( i = 0; i < front_pic.i_planes; i++ )
-                    for( j = 0; j < front_pic.p[i].i_lines; j++)
+                    for( j = 0; j < front_pic.p[i].i_visible_lines; j++)
                         memset( front_pic.p[i].p_pixels + j *
                                 front_pic.p[i].i_pitch, 127,
                                 front_pic.p[i].i_visible_pitch );
@@ -1411,6 +1533,7 @@ static int NewPictureVec( vout_thread_t *p_vout, picture_t *p_pic,
     {
         p_pic[i].i_status = DESTROYED_PICTURE;
         p_pic[i].i_type   = DIRECT_PICTURE;
+        p_pic[i].b_slow   = VLC_TRUE;
         p_pic[i].pf_lock  = DirectXLockSurface;
         p_pic[i].pf_unlock = DirectXUnlockSurface;
         PP_OUTPUTPICTURE[i] = &p_pic[i];
@@ -1442,6 +1565,10 @@ static void FreePictureVec( vout_thread_t *p_vout, picture_t *p_pic,
 {
     int i;
 
+    vlc_mutex_lock( &p_vout->p_sys->lock );
+    p_vout->p_sys->p_current_surface = 0;
+    vlc_mutex_unlock( &p_vout->p_sys->lock );
+
     for( i = 0; i < i_num_pics; i++ )
     {
         DirectXCloseSurface( p_vout, p_pic[i].p_sys->p_front_surface );
@@ -1451,8 +1578,6 @@ static void FreePictureVec( vout_thread_t *p_vout, picture_t *p_pic,
             free( p_pic[i].p_sys );
         }
     }
-
-    p_vout->p_sys->p_current_surface = 0;
 }
 
 /*****************************************************************************
@@ -1472,6 +1597,7 @@ static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
         case VLC_FOURCC('R','V','3','2'):
             p_pic->p->p_pixels = p_pic->p_sys->ddsd.lpSurface;
             p_pic->p->i_lines = p_vout->output.i_height;
+            p_pic->p->i_visible_lines = p_vout->output.i_height;
             p_pic->p->i_pitch = p_pic->p_sys->ddsd.lPitch;
             switch( p_vout->output.i_chroma )
             {
@@ -1500,6 +1626,7 @@ static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
 
             p_pic->Y_PIXELS = p_pic->p_sys->ddsd.lpSurface;
             p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
+            p_pic->p[Y_PLANE].i_visible_lines = p_vout->output.i_height;
             p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->ddsd.lPitch;
             p_pic->p[Y_PLANE].i_pixel_pitch = 1;
             p_pic->p[Y_PLANE].i_visible_pitch = p_vout->output.i_width *
@@ -1508,6 +1635,7 @@ static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
             p_pic->V_PIXELS =  p_pic->Y_PIXELS
               + p_pic->p[Y_PLANE].i_lines * p_pic->p[Y_PLANE].i_pitch;
             p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
+            p_pic->p[V_PLANE].i_visible_lines = p_vout->output.i_height / 2;
             p_pic->p[V_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
             p_pic->p[V_PLANE].i_pixel_pitch = 1;
             p_pic->p[V_PLANE].i_visible_pitch = p_vout->output.i_width / 2 *
@@ -1516,6 +1644,7 @@ static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
             p_pic->U_PIXELS = p_pic->V_PIXELS
               + p_pic->p[V_PLANE].i_lines * p_pic->p[V_PLANE].i_pitch;
             p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
+            p_pic->p[U_PLANE].i_visible_lines = p_vout->output.i_height / 2;
             p_pic->p[U_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
             p_pic->p[U_PLANE].i_pixel_pitch = 1;
             p_pic->p[U_PLANE].i_visible_pitch = p_vout->output.i_width / 2 *
@@ -1528,6 +1657,7 @@ static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
 
             p_pic->Y_PIXELS = p_pic->p_sys->ddsd.lpSurface;
             p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
+            p_pic->p[Y_PLANE].i_visible_lines = p_vout->output.i_height;
             p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->ddsd.lPitch;
             p_pic->p[Y_PLANE].i_pixel_pitch = 1;
             p_pic->p[Y_PLANE].i_visible_pitch = p_vout->output.i_width *
@@ -1536,6 +1666,7 @@ static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
             p_pic->U_PIXELS = p_pic->Y_PIXELS
               + p_pic->p[Y_PLANE].i_lines * p_pic->p[Y_PLANE].i_pitch;
             p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
+            p_pic->p[U_PLANE].i_visible_lines = p_vout->output.i_height / 2;
             p_pic->p[U_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
             p_pic->p[U_PLANE].i_pixel_pitch = 1;
             p_pic->p[U_PLANE].i_visible_pitch = p_vout->output.i_width / 2 *
@@ -1544,6 +1675,7 @@ static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
             p_pic->V_PIXELS =  p_pic->U_PIXELS
               + p_pic->p[U_PLANE].i_lines * p_pic->p[U_PLANE].i_pitch;
             p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
+            p_pic->p[V_PLANE].i_visible_lines = p_vout->output.i_height / 2;
             p_pic->p[V_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
             p_pic->p[V_PLANE].i_pixel_pitch = 1;
             p_pic->p[V_PLANE].i_visible_pitch = p_vout->output.i_width / 2 *
@@ -1552,10 +1684,12 @@ static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
             p_pic->i_planes = 3;
             break;
 
+        case VLC_FOURCC('U','Y','V','Y'):
         case VLC_FOURCC('Y','U','Y','2'):
 
             p_pic->p->p_pixels = p_pic->p_sys->ddsd.lpSurface;
             p_pic->p->i_lines = p_vout->output.i_height;
+            p_pic->p->i_visible_lines = p_vout->output.i_height;
             p_pic->p->i_pitch = p_pic->p_sys->ddsd.lPitch;
             p_pic->p->i_pixel_pitch = 2;
             p_pic->p->i_visible_pitch = p_vout->output.i_width *
@@ -1786,15 +1920,45 @@ static DWORD DirectXFindColorkey( vout_thread_t *p_vout, uint32_t i_color )
 }
 
 /*****************************************************************************
- * object variables callbacks: a bunch of object variables are used by the
- * interfaces to interact with the vout.
+ * A few toolbox functions
  *****************************************************************************/
-static int OnTopCallback( vlc_object_t *p_this, char const *psz_cmd,
-                        vlc_value_t oldval, vlc_value_t newval, void *p_data )
+void SwitchWallpaperMode( vout_thread_t *p_vout, vlc_bool_t b_on )
 {
-    vout_thread_t *p_vout = (vout_thread_t *)p_this;
-    p_vout->p_sys->b_on_top_change = VLC_TRUE;
-    return VLC_SUCCESS;
+    HWND hwnd;
+
+    if( p_vout->p_sys->b_wallpaper == b_on ) return; /* Nothing to do */
+
+    hwnd = FindWindow( "Progman", NULL );
+    if( hwnd ) hwnd = FindWindowEx( hwnd, NULL, "SHELLDLL_DefView", NULL );
+    if( hwnd ) hwnd = FindWindowEx( hwnd, NULL, "SysListView32", NULL );
+    if( !hwnd )
+    {
+        msg_Warn( p_vout, "couldn't find \"SysListView32\" window, "
+                  "wallpaper mode not supported" );
+        return;
+    }
+
+    p_vout->p_sys->b_wallpaper = b_on;
+
+    msg_Dbg( p_vout, "wallpaper mode %s", b_on ? "enabled" : "disabled" );
+
+    if( p_vout->p_sys->b_wallpaper )
+    {
+        p_vout->p_sys->color_bkg = ListView_GetBkColor( hwnd );
+        p_vout->p_sys->color_bkgtxt = ListView_GetTextBkColor( hwnd );
+
+        ListView_SetBkColor( hwnd, p_vout->p_sys->i_rgb_colorkey );
+        ListView_SetTextBkColor( hwnd, p_vout->p_sys->i_rgb_colorkey );
+    }
+    else if( hwnd )
+    {
+        ListView_SetBkColor( hwnd, p_vout->p_sys->color_bkg );
+        ListView_SetTextBkColor( hwnd, p_vout->p_sys->color_bkgtxt );
+    }
+
+    /* Update desktop */
+    InvalidateRect( hwnd, NULL, TRUE );            
+    UpdateWindow( hwnd );
 }
 
 /*****************************************************************************
@@ -1866,5 +2030,38 @@ static int FindDevicesCallback( vlc_object_t *p_this, char const *psz_name,
 
     FreeLibrary( hddraw_dll );
 
+    /* Signal change to the interface */
+    p_item->b_dirty = VLC_TRUE;
+
+    return VLC_SUCCESS;
+}
+
+static int WallpaperCallback( vlc_object_t *p_this, char const *psz_cmd,
+                              vlc_value_t oldval, vlc_value_t newval,
+                              void *p_data )
+{
+    vout_thread_t *p_vout = (vout_thread_t *)p_this;
+
+    if( (newval.b_bool && !p_vout->p_sys->b_wallpaper) ||
+        (!newval.b_bool && p_vout->p_sys->b_wallpaper) )
+    {
+        playlist_t *p_playlist;
+
+        p_playlist =
+            (playlist_t *)vlc_object_find( p_this, VLC_OBJECT_PLAYLIST,
+                                           FIND_PARENT );
+        if( p_playlist )
+        {
+            /* Modify playlist as well because the vout might have to be
+             * restarted */
+            var_Create( p_playlist, "directx-wallpaper", VLC_VAR_BOOL );
+            var_Set( p_playlist, "directx-wallpaper", newval );
+
+            vlc_object_release( p_playlist );
+        }
+
+        p_vout->p_sys->i_changes |= DX_WALLPAPER_CHANGE;
+    }
+
     return VLC_SUCCESS;
 }