1 /*****************************************************************************
2 * vout_directx.c: Windows DirectX video output display method
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: vout_directx.c,v 1.26 2002/03/17 17:00:38 sam Exp $
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
27 * This plugin will use YUV overlay if supported, using overlay will result in
28 * the best video quality (hardware interpolation when rescaling the picture)
29 * and the fastest display as it requires less processing.
31 * If YUV overlay is not supported this plugin will use RGB offscreen video
32 * surfaces that will be blitted onto the primary surface (display) to
33 * effectively display the pictures. this fallback method enables us to display
34 * video in window mode.
35 * Another fallback method (which isn't implemented) would be take the
36 * exclusive control of the screen so we could spare the blitting process and
37 * decode directly to video memory. This should theoretically allow for better
38 * performance (although on my system it is actually slower) but this is
39 * restricted to fullscreen video.
41 *****************************************************************************/
42 #include <errno.h> /* ENOMEM */
43 #include <stdlib.h> /* free() */
44 #include <string.h> /* strerror() */
46 #include <videolan/vlc.h>
53 #include "video_output.h"
55 #include "interface.h"
57 #include "vout_directx.h"
59 /*****************************************************************************
61 * Defining them here allows us to get rid of the dxguid library during
63 *****************************************************************************/
65 DEFINE_GUID( IID_IDirectDraw2, 0xB3A6F3E0,0x2B43,0x11CF,0xA2,0xDE,0x00,0xAA,0x00,0xB9,0x33,0x56 );
66 DEFINE_GUID( IID_IDirectDrawSurface3, 0xDA044E00,0x69B2,0x11D0,0xA1,0xD5,0x00,0xAA,0x00,0xB8,0xDF,0xBB );
68 /*****************************************************************************
70 *****************************************************************************/
71 static int vout_Create ( vout_thread_t * );
72 static void vout_Destroy ( vout_thread_t * );
73 static int vout_Init ( vout_thread_t * );
74 static void vout_End ( vout_thread_t * );
75 static int vout_Manage ( vout_thread_t * );
76 static void vout_Render ( vout_thread_t *, picture_t * );
77 static void vout_Display ( vout_thread_t *, picture_t * );
79 static int NewPictureVec ( vout_thread_t *, picture_t *, int );
80 static void FreePictureVec ( vout_thread_t *, picture_t *, int );
81 static int UpdatePictureStruct( vout_thread_t *, picture_t *, int );
83 static int DirectXInitDDraw ( vout_thread_t *p_vout );
84 static void DirectXCloseDDraw ( vout_thread_t *p_vout );
85 static int DirectXCreateDisplay ( vout_thread_t *p_vout );
86 static void DirectXCloseDisplay ( vout_thread_t *p_vout );
87 static int DirectXCreateSurface ( vout_thread_t *p_vout,
88 LPDIRECTDRAWSURFACE3 *, int, int );
89 static void DirectXCloseSurface ( vout_thread_t *p_vout,
90 LPDIRECTDRAWSURFACE3 );
91 static int DirectXCreateClipper ( vout_thread_t *p_vout );
92 static void DirectXGetDDrawCaps ( vout_thread_t *p_vout );
93 static int DirectXGetSurfaceDesc ( picture_t *p_pic );
95 /*****************************************************************************
96 * Functions exported as capabilities. They are declared as static so that
97 * we don't pollute the namespace too much.
98 *****************************************************************************/
99 void _M( vout_getfunctions )( function_list_t * p_function_list )
101 p_function_list->functions.vout.pf_create = vout_Create;
102 p_function_list->functions.vout.pf_init = vout_Init;
103 p_function_list->functions.vout.pf_end = vout_End;
104 p_function_list->functions.vout.pf_destroy = vout_Destroy;
105 p_function_list->functions.vout.pf_manage = vout_Manage;
106 p_function_list->functions.vout.pf_render = vout_Render;
107 p_function_list->functions.vout.pf_display = vout_Display;
110 /*****************************************************************************
111 * vout_Create: allocate DirectX video thread output method
112 *****************************************************************************
113 * This function allocates and initialize the DirectX vout method.
114 *****************************************************************************/
115 static int vout_Create( vout_thread_t *p_vout )
117 /* Allocate structure */
118 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
119 if( p_vout->p_sys == NULL )
121 intf_ErrMsg( "vout error: can't create p_sys (%s)", strerror(ENOMEM) );
125 /* Initialisations */
126 p_vout->p_sys->p_ddobject = NULL;
127 p_vout->p_sys->p_display = NULL;
128 p_vout->p_sys->p_current_surface = NULL;
129 p_vout->p_sys->p_clipper = NULL;
130 p_vout->p_sys->hbrush = NULL;
131 p_vout->p_sys->hwnd = NULL;
132 p_vout->p_sys->i_changes = 0;
133 p_vout->p_sys->b_event_thread_die = 0;
134 p_vout->p_sys->b_caps_overlay_clipping = 0;
135 SetRectEmpty( &p_vout->p_sys->rect_display );
136 p_vout->p_sys->b_using_overlay =
137 !config_GetIntVariable( "nooverlay" );
139 p_vout->p_sys->b_cursor = 1;
141 p_vout->p_sys->b_cursor_autohidden = 0;
142 p_vout->p_sys->i_lastmoved = mdate();
144 /* Set main window's size */
145 if( p_vout->render.i_height * p_vout->render.i_aspect
146 >= p_vout->render.i_width * VOUT_ASPECT_FACTOR )
148 p_vout->p_sys->i_window_width = p_vout->render.i_height
149 * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR;
150 p_vout->p_sys->i_window_height = p_vout->render.i_height;
154 p_vout->p_sys->i_window_width = p_vout->render.i_width;
155 p_vout->p_sys->i_window_height = p_vout->render.i_width
156 * VOUT_ASPECT_FACTOR / p_vout->render.i_aspect;
160 p_vout->p_sys->i_window_width = config_GetIntVariable( "width" );
161 p_vout->p_sys->i_window_height = config_GetIntVariable( "height" );
164 /* Set locks and condition variables */
165 vlc_mutex_init( &p_vout->p_sys->event_thread_lock );
166 vlc_cond_init( &p_vout->p_sys->event_thread_wait );
167 p_vout->p_sys->i_event_thread_status = THREAD_CREATE;
169 /* Create the DirectXEventThread, this thread is created by us to isolate
170 * the Win32 PeekMessage function calls. We want to do this because
171 * Windows can stay blocked inside this call for a long time, and when
172 * this happens it thus blocks vlc's video_output thread.
173 * DirectXEventThread will take care of the creation of the video
174 * window (because PeekMessage has to be called from the same thread which
175 * created the window). */
176 intf_WarnMsg( 3, "vout: vout_Create creating DirectXEventThread" );
177 if( vlc_thread_create( &p_vout->p_sys->event_thread_id,
178 "DirectX Events Thread",
179 (void *) DirectXEventThread, (void *) p_vout) )
181 intf_ErrMsg( "vout error: can't create DirectXEventThread" );
182 intf_ErrMsg("vout error: %s", strerror(ENOMEM));
183 free( p_vout->p_sys );
187 /* We need to wait for the actual creation of the thread and window */
188 if( p_vout->p_sys->i_event_thread_status == THREAD_CREATE )
190 vlc_mutex_lock( &p_vout->p_sys->event_thread_lock );
191 vlc_cond_wait ( &p_vout->p_sys->event_thread_wait,
192 &p_vout->p_sys->event_thread_lock );
193 vlc_mutex_unlock( &p_vout->p_sys->event_thread_lock );
195 if( p_vout->p_sys->i_event_thread_status != THREAD_READY )
197 intf_ErrMsg( "vout error: DirectXEventThread failed" );
198 free( p_vout->p_sys );
202 intf_WarnMsg( 3, "vout: vout_Create DirectXEventThread running" );
205 /* Initialise DirectDraw */
206 if( DirectXInitDDraw( p_vout ) )
208 intf_ErrMsg( "vout error: can't initialise DirectDraw" );
210 /* Kill DirectXEventThread */
211 p_vout->p_sys->b_event_thread_die = 1;
212 /* we need to be sure DirectXEventThread won't stay stuck in
213 * GetMessage, so we send a fake message */
214 PostMessage( p_vout->p_sys->hwnd, WM_CHAR, (WPARAM)'^', 0);
215 vlc_thread_join( p_vout->p_sys->event_thread_id );
220 /* Create the directx display */
221 if( DirectXCreateDisplay( p_vout ) )
223 intf_ErrMsg( "vout error: can't initialise DirectDraw" );
224 DirectXCloseDDraw( p_vout );
226 /* Kill DirectXEventThread */
227 p_vout->p_sys->b_event_thread_die = 1;
228 /* we need to be sure DirectXEventThread won't stay stuck in
229 * GetMessage, so we send a fake message */
230 PostMessage( p_vout->p_sys->hwnd, WM_CHAR, (WPARAM)'^', 0);
231 vlc_thread_join( p_vout->p_sys->event_thread_id );
236 /* Attach the current thread input queue to the events thread qeue.
237 * This allows us to hide or show the cursor in vout_Manage() */
238 ShowCursor( TRUE ); ShowCursor( FALSE ); /* create input queue */
239 AttachThreadInput( GetCurrentThreadId(),
240 GetWindowThreadProcessId( p_vout->p_sys->hwnd, NULL ),
246 /*****************************************************************************
247 * vout_Init: initialize DirectX video thread output method
248 *****************************************************************************
249 * This function create the directx surfaces needed by the output thread.
250 * It is called at the beginning of the thread.
251 *****************************************************************************/
252 static int vout_Init( vout_thread_t *p_vout )
255 /* Initialize the output structure.
256 * Since DirectDraw can do rescaling for us, stick to the default
257 * coordinates and aspect. */
258 p_vout->output.i_width = p_vout->render.i_width;
259 p_vout->output.i_height = p_vout->render.i_height;
260 p_vout->output.i_aspect = p_vout->render.i_aspect;
262 #define MAX_DIRECTBUFFERS 1
264 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
266 /* Change the window title bar text */
267 if( p_vout->p_sys->b_using_overlay )
268 SetWindowText( p_vout->p_sys->hwnd,
269 "VLC DirectX (using hardware overlay)" );
274 /*****************************************************************************
275 * vout_End: terminate Sys video thread output method
276 *****************************************************************************
277 * Terminate an output method created by vout_Create.
278 * It is called at the end of the thread.
279 *****************************************************************************/
280 static void vout_End( vout_thread_t *p_vout )
282 FreePictureVec( p_vout, p_vout->p_picture, I_OUTPUTPICTURES );
286 /*****************************************************************************
287 * vout_Destroy: destroy Sys video thread output method
288 *****************************************************************************
289 * Terminate an output method created by vout_Create
290 *****************************************************************************/
291 static void vout_Destroy( vout_thread_t *p_vout )
293 intf_WarnMsg( 3, "vout: vout_Destroy" );
294 DirectXCloseDisplay( p_vout );
295 DirectXCloseDDraw( p_vout );
297 /* Kill DirectXEventThread */
298 p_vout->p_sys->b_event_thread_die = 1;
299 /* we need to be sure DirectXEventThread won't stay stuck in GetMessage,
300 * so we send a fake message */
301 if( p_vout->p_sys->i_event_thread_status == THREAD_READY &&
302 p_vout->p_sys->hwnd )
304 PostMessage( p_vout->p_sys->hwnd, WM_CHAR, (WPARAM)'q', 0);
305 vlc_thread_join( p_vout->p_sys->event_thread_id );
308 if( p_vout->p_sys != NULL )
310 free( p_vout->p_sys );
311 p_vout->p_sys = NULL;
315 /*****************************************************************************
316 * vout_Manage: handle Sys events
317 *****************************************************************************
318 * This function should be called regularly by the video output thread.
319 * It returns a non null value if an error occured.
320 *****************************************************************************/
321 static int vout_Manage( vout_thread_t *p_vout )
323 WINDOWPLACEMENT window_placement;
325 /* We used to call the Win32 PeekMessage function here to read the window
326 * messages. But since window can stay blocked into this function for a
327 * long time (for example when you move your window on the screen), I
328 * decided to isolate PeekMessage in another thread. */
333 if( p_vout->i_changes & VOUT_SCALE_CHANGE
334 || p_vout->p_sys->i_changes & VOUT_SCALE_CHANGE)
336 intf_WarnMsg( 3, "vout: vout_Manage Scale Change" );
337 if( !p_vout->p_sys->b_using_overlay )
338 InvalidateRect( p_vout->p_sys->hwnd, NULL, TRUE );
340 DirectXUpdateOverlay( p_vout );
341 p_vout->i_changes &= ~VOUT_SCALE_CHANGE;
342 p_vout->p_sys->i_changes &= ~VOUT_SCALE_CHANGE;
348 if( p_vout->i_changes & VOUT_SIZE_CHANGE
349 || p_vout->p_sys->i_changes & VOUT_SIZE_CHANGE )
351 intf_WarnMsg( 3, "vout: vout_Manage Size Change" );
352 if( !p_vout->p_sys->b_using_overlay )
353 InvalidateRect( p_vout->p_sys->hwnd, NULL, TRUE );
355 DirectXUpdateOverlay( p_vout );
356 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
357 p_vout->p_sys->i_changes &= ~VOUT_SIZE_CHANGE;
363 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE
364 || p_vout->p_sys->i_changes & VOUT_FULLSCREEN_CHANGE )
366 p_vout->b_fullscreen = ! p_vout->b_fullscreen;
368 /* We need to switch between Maximized and Normal sized window */
369 window_placement.length = sizeof(WINDOWPLACEMENT);
370 GetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
371 if( p_vout->b_fullscreen )
373 /* Maximized window */
374 window_placement.showCmd = SW_SHOWMAXIMIZED;
375 /* Change window style, no borders and no title bar */
376 SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE, 0 );
382 window_placement.showCmd = SW_SHOWNORMAL;
383 /* Change window style, borders and title bar */
384 SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE,
385 WS_OVERLAPPEDWINDOW | WS_SIZEBOX | WS_VISIBLE );
388 SetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
390 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
391 p_vout->p_sys->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
397 if( ! p_vout->p_sys->b_cursor_autohidden &&
398 ( mdate() - p_vout->p_sys->i_lastmoved > 5000000 ) )
400 /* Hide the mouse automatically */
401 p_vout->p_sys->b_cursor_autohidden = 1;
406 if( p_vout->i_changes & VOUT_CURSOR_CHANGE
407 || p_vout->p_sys->i_changes & VOUT_CURSOR_CHANGE )
409 p_vout->p_sys->b_cursor = ! p_vout->p_sys->b_cursor;
411 ShowCursor( p_vout->p_sys->b_cursor &&
412 ! p_vout->p_sys->b_cursor_autohidden );
414 p_vout->i_changes &= ~VOUT_CURSOR_CHANGE;
415 p_vout->p_sys->i_changes &= ~VOUT_CURSOR_CHANGE;
419 /* Check if the event thread is still running */
420 if( p_vout->p_sys->b_event_thread_die )
426 /*****************************************************************************
427 * vout_Render: render previously calculated output
428 *****************************************************************************/
429 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
434 /*****************************************************************************
435 * vout_Display: displays previously rendered output
436 *****************************************************************************
437 * This function sends the currently rendered image to the display, wait until
438 * it is displayed and switch the two rendering buffers, preparing next frame.
439 *****************************************************************************/
440 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
444 if( (p_vout->p_sys->p_display == NULL) )
446 intf_WarnMsg( 3, "vout error: vout_Display no display!!" );
450 if( !p_vout->p_sys->b_using_overlay )
454 /* We ask for the "NOTEARING" option */
455 memset( &ddbltfx, 0, sizeof(DDBLTFX) );
456 ddbltfx.dwSize = sizeof(DDBLTFX);
457 ddbltfx.dwDDFX = DDBLTFX_NOTEARING | DDBLT_ASYNC;
459 /* Blit video surface to display */
460 dxresult = IDirectDrawSurface3_Blt(p_vout->p_sys->p_display,
461 &p_vout->p_sys->rect_dest_clipped,
462 p_pic->p_sys->p_surface,
463 &p_vout->p_sys->rect_src_clipped,
465 if ( dxresult == DDERR_SURFACELOST )
467 /* Our surface can be lost so be sure
468 * to check this and restore it if needed */
469 IDirectDrawSurface3_Restore( p_vout->p_sys->p_display );
471 /* Now that the surface has been restored try to display again */
472 dxresult = IDirectDrawSurface3_Blt(p_vout->p_sys->p_display,
473 &p_vout->p_sys->rect_dest_clipped,
474 p_pic->p_sys->p_surface,
475 &p_vout->p_sys->rect_src_clipped,
479 if( dxresult != DD_OK )
481 intf_WarnMsg( 3, "vout: could not Blit the surface" );
486 else /* using overlay */
489 /* Flip the overlay buffers */
490 dxresult = IDirectDrawSurface3_Flip( p_pic->p_sys->p_front_surface,
492 if ( dxresult == DDERR_SURFACELOST )
494 /* Our surface can be lost so be sure
495 * to check this and restore it if needed */
496 IDirectDrawSurface3_Restore( p_vout->p_sys->p_display );
497 IDirectDrawSurface3_Restore( p_pic->p_sys->p_front_surface );
499 /* Now that the surface has been restored try to display again */
500 dxresult = IDirectDrawSurface3_Flip( p_pic->p_sys->p_front_surface,
502 DirectXUpdateOverlay( p_vout );
505 if( dxresult != DD_OK )
506 intf_WarnMsg( 8, "vout: couldn't flip overlay surface" );
508 if( !DirectXGetSurfaceDesc( p_pic ) )
511 intf_ErrMsg( "vout error: vout_Display cannot get surface desc" );
515 if( !UpdatePictureStruct( p_vout, p_pic, p_vout->output.i_chroma ) )
518 intf_ErrMsg( "vout error: vout_Display unvalid pic chroma" );
522 /* set currently displayed pic */
523 p_vout->p_sys->p_current_surface = p_pic->p_sys->p_front_surface;
529 /* following functions are local */
531 /*****************************************************************************
532 * DirectXInitDDraw: Takes care of all the DirectDraw initialisations
533 *****************************************************************************
534 * This function initialise and allocate resources for DirectDraw.
535 *****************************************************************************/
536 static int DirectXInitDDraw( vout_thread_t *p_vout )
539 HRESULT (WINAPI *OurDirectDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
540 LPDIRECTDRAW p_ddobject;
542 intf_WarnMsg( 3, "vout: DirectXInitDDraw" );
544 /* load direct draw DLL */
545 p_vout->p_sys->hddraw_dll = LoadLibrary("DDRAW.DLL");
546 if( p_vout->p_sys->hddraw_dll == NULL )
548 intf_WarnMsg( 3, "vout: DirectXInitDDraw failed loading ddraw.dll" );
552 OurDirectDrawCreate =
553 (void *)GetProcAddress(p_vout->p_sys->hddraw_dll, "DirectDrawCreate");
554 if ( OurDirectDrawCreate == NULL )
556 intf_ErrMsg( "vout error: DirectXInitDDraw failed GetProcAddress" );
557 FreeLibrary( p_vout->p_sys->hddraw_dll );
558 p_vout->p_sys->hddraw_dll = NULL;
562 /* Initialize DirectDraw now */
563 dxresult = OurDirectDrawCreate( NULL, &p_ddobject, NULL );
564 if( dxresult != DD_OK )
566 intf_ErrMsg( "vout error: DirectXInitDDraw can't initialize DDraw" );
567 p_vout->p_sys->p_ddobject = NULL;
568 FreeLibrary( p_vout->p_sys->hddraw_dll );
569 p_vout->p_sys->hddraw_dll = NULL;
573 /* Set DirectDraw Cooperative level, ie what control we want over Windows
575 dxresult = IDirectDraw_SetCooperativeLevel( p_ddobject,
576 p_vout->p_sys->hwnd, DDSCL_NORMAL );
577 if( dxresult != DD_OK )
579 intf_ErrMsg( "vout error: can't set direct draw cooperative level." );
580 IDirectDraw_Release( p_ddobject );
581 p_vout->p_sys->p_ddobject = NULL;
582 FreeLibrary( p_vout->p_sys->hddraw_dll );
583 p_vout->p_sys->hddraw_dll = NULL;
587 /* Get the IDirectDraw2 interface */
588 dxresult = IDirectDraw_QueryInterface( p_ddobject, &IID_IDirectDraw2,
589 (LPVOID *)&p_vout->p_sys->p_ddobject );
590 if( dxresult != DD_OK )
592 intf_ErrMsg( "vout error: can't get IDirectDraw2 interface." );
593 IDirectDraw_Release( p_ddobject );
594 p_vout->p_sys->p_ddobject = NULL;
595 FreeLibrary( p_vout->p_sys->hddraw_dll );
596 p_vout->p_sys->hddraw_dll = NULL;
601 /* Release the unused interface */
602 IDirectDraw_Release( p_ddobject );
605 /* Probe the capabilities of the hardware */
606 DirectXGetDDrawCaps( p_vout );
608 intf_WarnMsg( 3, "vout: End DirectXInitDDraw" );
612 /*****************************************************************************
613 * DirectXCreateDisplay: create the DirectDraw display.
614 *****************************************************************************
615 * Create and initialize display according to preferences specified in the vout
617 *****************************************************************************/
618 static int DirectXCreateDisplay( vout_thread_t *p_vout )
622 LPDIRECTDRAWSURFACE p_display;
623 DDPIXELFORMAT pixel_format;
625 intf_WarnMsg( 3, "vout: DirectXCreateDisplay" );
627 /* Now get the primary surface. This surface is what you actually see
629 memset( &ddsd, 0, sizeof( DDSURFACEDESC ));
630 ddsd.dwSize = sizeof(DDSURFACEDESC);
631 ddsd.dwFlags = DDSD_CAPS;
632 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
634 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
637 if( dxresult != DD_OK )
639 intf_ErrMsg( "vout error: can't get direct draw primary surface." );
640 p_vout->p_sys->p_display = NULL;
644 dxresult = IDirectDrawSurface_QueryInterface( p_display,
645 &IID_IDirectDrawSurface3,
646 (LPVOID *)&p_vout->p_sys->p_display );
647 if ( dxresult != DD_OK )
649 intf_ErrMsg( "vout error: can't get IDirectDrawSurface3 interface." );
650 IDirectDrawSurface_Release( p_display );
651 p_vout->p_sys->p_display = NULL;
656 /* Release the old interface */
657 IDirectDrawSurface_Release( p_display );
661 /* The clipper will be used only in non-overlay mode */
662 DirectXCreateClipper( p_vout );
666 /* compute the colorkey pixel value from the RGB value we've got */
667 memset( &pixel_format, 0, sizeof( DDPIXELFORMAT ));
668 pixel_format.dwSize = sizeof( DDPIXELFORMAT );
669 dxresult = IDirectDrawSurface3_GetPixelFormat( p_vout->p_sys->p_display,
671 if( dxresult != DD_OK )
672 intf_WarnMsg( 3, "vout: DirectXUpdateOverlay GetPixelFormat failed" );
673 p_vout->p_sys->i_colorkey = (DWORD)((( p_vout->p_sys->i_rgb_colorkey
674 * pixel_format.dwRBitMask) / 255)
675 & pixel_format.dwRBitMask);
682 /*****************************************************************************
683 * DirectXCreateClipper: Create a clipper that will be used when blitting the
684 * RGB surface to the main display.
685 *****************************************************************************
686 * This clipper prevents us to modify by mistake anything on the screen
687 * which doesn't belong to our window. For example when a part of our video
688 * window is hidden by another window.
689 *****************************************************************************/
690 static int DirectXCreateClipper( vout_thread_t *p_vout )
694 intf_WarnMsg( 3, "vout: DirectXCreateClipper" );
696 /* Create the clipper */
697 dxresult = IDirectDraw2_CreateClipper( p_vout->p_sys->p_ddobject, 0,
698 &p_vout->p_sys->p_clipper, NULL );
699 if( dxresult != DD_OK )
701 intf_WarnMsg( 3, "vout: DirectXCreateClipper can't create clipper." );
702 p_vout->p_sys->p_clipper = NULL;
706 /* associate the clipper to the window */
707 dxresult = IDirectDrawClipper_SetHWnd(p_vout->p_sys->p_clipper, 0,
708 p_vout->p_sys->hwnd);
709 if( dxresult != DD_OK )
712 "vout: DirectXCreateClipper can't attach clipper to window." );
713 IDirectDrawSurface_Release( p_vout->p_sys->p_clipper );
714 p_vout->p_sys->p_clipper = NULL;
718 /* associate the clipper with the surface */
719 dxresult = IDirectDrawSurface_SetClipper(p_vout->p_sys->p_display,
720 p_vout->p_sys->p_clipper);
721 if( dxresult != DD_OK )
724 "vout: DirectXCreateClipper can't attach clipper to surface." );
725 IDirectDrawSurface_Release( p_vout->p_sys->p_clipper );
726 p_vout->p_sys->p_clipper = NULL;
733 /*****************************************************************************
734 * DirectXCreateSurface: create an YUV overlay or RGB surface for the video.
735 *****************************************************************************
736 * The best method of display is with an YUV overlay because the YUV->RGB
737 * conversion is done in hardware.
738 * You can also create a plain RGB surface.
739 * ( Maybe we could also try an RGB overlay surface, which could have hardware
740 * scaling and which would also be faster in window mode because you don't
741 * need to do any blitting to the main display...)
742 *****************************************************************************/
743 static int DirectXCreateSurface( vout_thread_t *p_vout,
744 LPDIRECTDRAWSURFACE3 *pp_surface_final,
745 int i_chroma, int b_overlay )
748 LPDIRECTDRAWSURFACE p_surface;
751 intf_WarnMsg( 3, "vout: DirectXCreateSurface" );
753 /* Create the video surface */
756 /* Now try to create the YUV overlay surface.
757 * This overlay will be displayed on top of the primary surface.
758 * A color key is used to determine whether or not the overlay will be
759 * displayed, ie the overlay will be displayed in place of the primary
760 * surface wherever the primary surface will have this color.
761 * The video window has been created with a background of this color so
762 * the overlay will be only displayed on top of this window */
764 memset( &ddsd, 0, sizeof( DDSURFACEDESC ));
765 ddsd.dwSize = sizeof(DDSURFACEDESC);
766 ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
767 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
768 ddsd.ddpfPixelFormat.dwFourCC = i_chroma;
769 ddsd.dwFlags = DDSD_CAPS |
772 DDSD_BACKBUFFERCOUNT |
774 ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY |
778 ddsd.dwHeight = p_vout->render.i_height;
779 ddsd.dwWidth = p_vout->render.i_width;
780 ddsd.dwBackBufferCount = 1; /* One back buffer */
782 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
785 if( dxresult == DD_OK )
787 intf_WarnMsg( 3,"vout: DirectX YUV overlay created successfully" );
791 intf_ErrMsg( "vout error: can't create YUV overlay surface." );
792 *pp_surface_final = NULL;
799 /* Now try to create a plain RGB surface. */
800 memset( &ddsd, 0, sizeof( DDSURFACEDESC ) );
801 ddsd.dwSize = sizeof(DDSURFACEDESC);
802 ddsd.dwFlags = DDSD_HEIGHT |
805 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN |
806 DDSCAPS_SYSTEMMEMORY;
807 ddsd.dwHeight = p_vout->render.i_height;
808 ddsd.dwWidth = p_vout->render.i_width;
810 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
813 if( dxresult == DD_OK )
815 intf_WarnMsg( 3,"vout: DirectX RGB surface created successfully" );
819 intf_ErrMsg( "vout error: can't create RGB surface." );
820 *pp_surface_final = NULL;
825 /* Now that the surface is created, try to get a newer DirectX interface */
826 dxresult = IDirectDrawSurface_QueryInterface( p_surface,
827 &IID_IDirectDrawSurface3,
828 (LPVOID *)pp_surface_final );
829 IDirectDrawSurface_Release( p_surface ); /* Release the old interface */
830 if ( dxresult != DD_OK )
832 intf_ErrMsg( "vout error: can't get IDirectDrawSurface3 interface." );
833 *pp_surface_final = NULL;
841 /*****************************************************************************
842 * DirectXUpdateOverlay: Move or resize overlay surface on video display.
843 *****************************************************************************
844 * This function is used to move or resize an overlay surface on the screen.
845 * Ususally the overlay is moved by the user and thus, by a move or resize
846 * event (in vout_Manage).
847 *****************************************************************************/
848 void DirectXUpdateOverlay( vout_thread_t *p_vout )
854 if( p_vout->p_sys->p_current_surface == NULL ||
855 !p_vout->p_sys->b_using_overlay )
857 intf_WarnMsg( 5, "vout: DirectXUpdateOverlay no overlay !!" );
861 /* The new window dimensions should already have been computed by the
862 * caller of this function */
864 /* Position and show the overlay */
865 memset(&ddofx, 0, sizeof(DDOVERLAYFX));
866 ddofx.dwSize = sizeof(DDOVERLAYFX);
867 ddofx.dckDestColorkey.dwColorSpaceLowValue = p_vout->p_sys->i_colorkey;
868 ddofx.dckDestColorkey.dwColorSpaceHighValue = p_vout->p_sys->i_colorkey;
870 dwFlags = DDOVER_SHOW;
871 if( !p_vout->p_sys->b_caps_overlay_clipping )
872 dwFlags |= DDOVER_KEYDESTOVERRIDE;
874 dxresult = IDirectDrawSurface3_UpdateOverlay(
875 p_vout->p_sys->p_current_surface,
876 &p_vout->p_sys->rect_src_clipped,
877 p_vout->p_sys->p_display,
878 &p_vout->p_sys->rect_dest_clipped,
881 if(dxresult != DD_OK)
884 "vout: DirectXUpdateOverlay can't move or resize overlay" );
889 /*****************************************************************************
890 * DirectXCloseDDraw: Release the DDraw object allocated by DirectXInitDDraw
891 *****************************************************************************
892 * This function returns all resources allocated by DirectXInitDDraw.
893 *****************************************************************************/
894 static void DirectXCloseDDraw( vout_thread_t *p_vout )
896 intf_WarnMsg(3, "vout: DirectXCloseDDraw" );
897 if( p_vout->p_sys->p_ddobject != NULL )
899 IDirectDraw2_Release(p_vout->p_sys->p_ddobject);
900 p_vout->p_sys->p_ddobject = NULL;
903 if( p_vout->p_sys->hddraw_dll != NULL )
905 FreeLibrary( p_vout->p_sys->hddraw_dll );
906 p_vout->p_sys->hddraw_dll = NULL;
910 /*****************************************************************************
911 * DirectXCloseDisplay: close and reset the DirectX display device
912 *****************************************************************************
913 * This function returns all resources allocated by DirectXCreateDisplay.
914 *****************************************************************************/
915 static void DirectXCloseDisplay( vout_thread_t *p_vout )
917 intf_WarnMsg( 3, "vout: DirectXCloseDisplay" );
919 if( p_vout->p_sys->p_clipper != NULL )
921 intf_WarnMsg( 3, "vout: DirectXCloseDisplay clipper" );
922 IDirectDraw2_Release( p_vout->p_sys->p_clipper );
923 p_vout->p_sys->p_clipper = NULL;
926 if( p_vout->p_sys->p_display != NULL )
928 intf_WarnMsg( 3, "vout: DirectXCloseDisplay display" );
929 IDirectDraw2_Release( p_vout->p_sys->p_display );
930 p_vout->p_sys->p_display = NULL;
934 /*****************************************************************************
935 * DirectXCloseSurface: close the YUV overlay or RGB surface.
936 *****************************************************************************
937 * This function returns all resources allocated for the surface.
938 *****************************************************************************/
939 static void DirectXCloseSurface( vout_thread_t *p_vout,
940 LPDIRECTDRAWSURFACE3 p_surface )
942 intf_WarnMsg( 3, "vout: DirectXCloseSurface" );
943 if( p_surface != NULL )
945 IDirectDraw2_Release( p_surface );
949 /*****************************************************************************
950 * NewPictureVec: allocate a vector of identical pictures
951 *****************************************************************************
952 * Returns 0 on success, -1 otherwise
953 *****************************************************************************/
954 static int NewPictureVec( vout_thread_t *p_vout, picture_t *p_pic,
958 LPDIRECTDRAWSURFACE3 p_surface;
961 /* We couldn't use an YUV overlay so we need to indicate to video_output
962 * which format we are falling back to */
965 case 8: /* FIXME: set the palette */
966 p_vout->output.i_chroma = FOURCC_RGB2; break;
968 p_vout->output.i_chroma = FOURCC_RV15; break;
970 p_vout->output.i_chroma = FOURCC_RV16; break;
972 p_vout->output.i_chroma = FOURCC_RV24; break;
974 p_vout->output.i_chroma = FOURCC_RV32; break;
976 intf_ErrMsg( "vout error: unknown screen depth" );
981 intf_WarnMsg( 3, "vout: NewPictureVec" );
983 I_OUTPUTPICTURES = 0;
985 /* chroma asked for */
986 p_vout->output.i_chroma = p_vout->render.i_chroma;
990 if( p_vout->render.i_chroma == FOURCC_I420 )
991 p_vout->output.i_chroma = FOURCC_YV12;
994 /* First we try to create an overlay surface.
995 * It looks like with most hardware it's not possible to create several
996 * overlay surfaces, and even if it was I bet it would be slower anyway to
997 * use them as direct buffers because they usually reside in video memory
998 * which is quite slow.
999 * So the overlay surface (with a back-buffer) that we create won't be used
1000 * to decode directly into it but instead picture buffers in system memory
1001 * will be blitted to it. */
1002 if( p_vout->p_sys->b_using_overlay )
1004 if( DirectXCreateSurface( p_vout, &p_surface, p_vout->output.i_chroma,
1005 p_vout->p_sys->b_using_overlay ) )
1009 /* Allocate internal structure */
1010 p_pic[0].p_sys = malloc( sizeof( picture_sys_t ) );
1011 if( p_pic[0].p_sys == NULL )
1013 DirectXCloseSurface( p_vout, p_surface );
1017 /* set front buffer */
1018 p_pic[0].p_sys->p_front_surface = p_surface;
1020 /* Get the back buffer */
1021 memset( &dds_caps, 0, sizeof( DDSCAPS ));
1022 dds_caps.dwCaps = DDSCAPS_BACKBUFFER;
1023 if( DD_OK != IDirectDrawSurface3_GetAttachedSurface(
1024 p_surface, &dds_caps,
1025 &p_pic[0].p_sys->p_surface ) )
1027 intf_WarnMsg( 3, "vout: NewPictureVec couldn't get "
1029 /* front buffer is the same as back buffer */
1030 p_pic[0].p_sys->p_surface = p_surface;
1034 p_vout->p_sys->p_current_surface= p_pic[0].p_sys->p_front_surface;
1035 DirectXUpdateOverlay( p_vout );
1036 I_OUTPUTPICTURES = 1;
1038 else p_vout->p_sys->b_using_overlay = 0;
1041 /* As we can't have overlays, will try to create plain RBG surfaces in
1042 * system memory. These surfaces will then be blitted onto the primary
1043 * surface (display) so they can be displayed */
1044 if( !p_vout->p_sys->b_using_overlay )
1047 p_vout->output.i_chroma = FOURCC_RV16;
1048 p_vout->output.i_rmask = 0x001f;
1049 p_vout->output.i_gmask = 0x03e0;
1050 p_vout->output.i_bmask = 0x7c00;
1052 for( i = 0; i < i_num_pics; i++ )
1054 if( DirectXCreateSurface( p_vout, &p_surface,
1055 p_vout->output.i_chroma,
1056 p_vout->p_sys->b_using_overlay ) )
1058 /* Allocate internal structure */
1059 p_pic[i].p_sys = malloc( sizeof( picture_sys_t ) );
1060 if( p_pic[i].p_sys == NULL )
1062 DirectXCloseSurface( p_vout, p_surface );
1063 FreePictureVec( p_vout, p_pic, I_OUTPUTPICTURES );
1064 I_OUTPUTPICTURES = 0;
1067 p_pic[i].p_sys->p_surface = p_surface;
1068 p_pic[i].p_sys->p_front_surface = NULL;
1077 /* Now that we've got all our direct-buffers, we can finish filling in the
1078 * picture_t structures */
1079 for( i = 0; i < I_OUTPUTPICTURES; i++ )
1081 p_pic[i].i_status = DESTROYED_PICTURE;
1082 p_pic[i].i_type = DIRECT_PICTURE;
1083 PP_OUTPUTPICTURE[i] = &p_pic[i];
1085 if( !DirectXGetSurfaceDesc( &p_pic[i] ) )
1088 FreePictureVec( p_vout, p_pic, I_OUTPUTPICTURES );
1089 I_OUTPUTPICTURES = 0;
1093 if( !UpdatePictureStruct(p_vout, &p_pic[i], p_vout->output.i_chroma) )
1096 /* Unknown chroma, tell the guy to get lost */
1097 intf_ErrMsg( "vout error: never heard of chroma 0x%.8x (%4.4s)",
1098 p_vout->output.i_chroma,
1099 (char*)&p_vout->output.i_chroma );
1100 FreePictureVec( p_vout, p_pic, I_OUTPUTPICTURES );
1101 I_OUTPUTPICTURES = 0;
1106 intf_WarnMsg( 3, "vout: End NewPictureVec");
1110 /*****************************************************************************
1111 * FreePicture: destroy a picture vector allocated with NewPictureVec
1112 *****************************************************************************
1114 *****************************************************************************/
1115 static void FreePictureVec( vout_thread_t *p_vout, picture_t *p_pic,
1120 for( i = 0; i < i_num_pics; i++ )
1123 if( p_pic->p_sys->p_front_surface &&
1124 ( p_pic->p_sys->p_surface != p_pic->p_sys->p_front_surface ) )
1125 DirectXCloseSurface( p_vout, p_pic[i].p_sys->p_front_surface );
1128 DirectXCloseSurface( p_vout, p_pic[i].p_sys->p_surface );
1130 for( i = 0; i < i_num_pics; i++ )
1132 free( p_pic[i].p_sys );
1137 /*****************************************************************************
1138 * UpdatePictureStruct: updates the internal data in the picture_t structure
1139 *****************************************************************************
1140 * This will setup stuff for use by the video_output thread
1141 *****************************************************************************/
1142 static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
1146 switch( p_vout->output.i_chroma )
1151 p_pic->Y_PIXELS = p_pic->p_sys->ddsd.lpSurface;
1152 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1153 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->ddsd.lPitch;
1154 p_pic->p[Y_PLANE].i_pixel_bytes = 1;
1155 p_pic->p[Y_PLANE].b_margin = 0;
1157 p_pic->V_PIXELS = p_pic->Y_PIXELS
1158 + p_pic->p[Y_PLANE].i_lines * p_pic->p[Y_PLANE].i_pitch;
1159 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1160 p_pic->p[V_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1161 p_pic->p[V_PLANE].i_pixel_bytes = 1;
1162 p_pic->p[V_PLANE].b_margin = 0;
1164 p_pic->U_PIXELS = p_pic->V_PIXELS
1165 + p_pic->p[V_PLANE].i_lines * p_pic->p[V_PLANE].i_pitch;
1166 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1167 p_pic->p[U_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1168 p_pic->p[U_PLANE].i_pixel_bytes = 1;
1169 p_pic->p[U_PLANE].b_margin = 0;
1171 p_pic->i_planes = 3;
1176 p_pic->p->p_pixels = p_pic->p_sys->ddsd.lpSurface;
1177 p_pic->p->i_lines = p_vout->output.i_height;
1178 p_pic->p->i_pitch = p_pic->p_sys->ddsd.lPitch;
1179 p_pic->p->i_pixel_bytes = 2;
1180 p_pic->p->b_margin = 0;
1182 p_pic->i_planes = 1;
1187 p_pic->p->p_pixels = p_pic->p_sys->ddsd.lpSurface;
1188 p_pic->p->i_lines = p_vout->output.i_height;
1189 p_pic->p->i_pitch = p_pic->p_sys->ddsd.lPitch;
1190 p_pic->p->i_pixel_bytes = 2;
1191 p_pic->p->b_margin = 0;
1193 p_pic->i_planes = 1;
1198 p_pic->Y_PIXELS = p_pic->p_sys->ddsd.lpSurface;
1199 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1200 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->ddsd.lPitch;
1201 p_pic->p[Y_PLANE].i_pixel_bytes = 1;
1202 p_pic->p[Y_PLANE].b_margin = 0;
1204 p_pic->U_PIXELS = p_pic->Y_PIXELS
1205 + p_pic->p[Y_PLANE].i_lines * p_pic->p[Y_PLANE].i_pitch;
1206 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1207 p_pic->p[U_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1208 p_pic->p[U_PLANE].i_pixel_bytes = 1;
1209 p_pic->p[U_PLANE].b_margin = 0;
1211 p_pic->V_PIXELS = p_pic->U_PIXELS
1212 + p_pic->p[U_PLANE].i_lines * p_pic->p[U_PLANE].i_pitch;
1213 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1214 p_pic->p[V_PLANE].i_pitch = p_pic->p[U_PLANE].i_pitch;
1215 p_pic->p[V_PLANE].i_pixel_bytes = 1;
1216 p_pic->p[V_PLANE].b_margin = 0;
1218 p_pic->i_planes = 3;
1224 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1225 + p_pic->p_sys->p_image->offsets[0];
1226 p_pic->p->i_lines = p_vout->output.i_height;
1227 /* XXX: this just looks so plain wrong... check it out ! */
1228 p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0] / 4;
1229 p_pic->p->i_pixel_bytes = 4;
1230 p_pic->p->b_margin = 0;
1232 p_pic->i_planes = 1;
1238 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1239 + p_pic->p_sys->p_image->offsets[0];
1240 p_pic->p->i_lines = p_vout->output.i_height;
1241 p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0];
1242 p_pic->p->i_pixel_bytes = 4;
1243 p_pic->p->b_margin = 0;
1245 p_pic->i_planes = 1;
1258 /*****************************************************************************
1259 * DirectXGetDDrawCaps: Probe the capabilities of the hardware
1260 *****************************************************************************
1261 * It is nice to know which features are supported by the hardware so we can
1262 * find ways to optimize our rendering.
1263 *****************************************************************************/
1264 static void DirectXGetDDrawCaps( vout_thread_t *p_vout )
1269 /* This is just an indication of whether or not we'll support overlay,
1270 * but with this test we don't know if we support YUV overlay */
1271 memset( &ddcaps, 0, sizeof( DDCAPS ));
1272 ddcaps.dwSize = sizeof(DDCAPS);
1273 dxresult = IDirectDraw2_GetCaps( p_vout->p_sys->p_ddobject,
1275 if(dxresult != DD_OK )
1277 intf_WarnMsg( 3,"vout error: can't get caps." );
1281 BOOL bHasOverlay, bHasOverlayFourCC, bCanClipOverlay,
1282 bHasColorKey, bCanStretch;
1284 /* Determine if the hardware supports overlay surfaces */
1285 bHasOverlay = ((ddcaps.dwCaps & DDCAPS_OVERLAY) ==
1286 DDCAPS_OVERLAY) ? TRUE : FALSE;
1287 /* Determine if the hardware supports overlay surfaces */
1288 bHasOverlayFourCC = ((ddcaps.dwCaps & DDCAPS_OVERLAYFOURCC) ==
1289 DDCAPS_OVERLAYFOURCC) ? TRUE : FALSE;
1290 /* Determine if the hardware supports overlay surfaces */
1291 bCanClipOverlay = ((ddcaps.dwCaps & DDCAPS_OVERLAYCANTCLIP) ==
1293 /* Determine if the hardware supports colorkeying */
1294 bHasColorKey = ((ddcaps.dwCaps & DDCAPS_COLORKEY) ==
1295 DDCAPS_COLORKEY) ? TRUE : FALSE;
1296 /* Determine if the hardware supports scaling of the overlay surface */
1297 bCanStretch = ((ddcaps.dwCaps & DDCAPS_OVERLAYSTRETCH) ==
1298 DDCAPS_OVERLAYSTRETCH) ? TRUE : FALSE;
1299 intf_WarnMsg( 3, "vout: DirectDraw Capabilities:" );
1300 intf_WarnMsg( 3, " overlay=%i yuvoverlay=%i can_clip_overlay=%i "
1301 "colorkey=%i stretch=%i",
1302 bHasOverlay, bHasOverlayFourCC, bCanClipOverlay,
1303 bHasColorKey, bCanStretch );
1305 /* Overlay clipping support is interesting for us as it means we can
1306 * get rid of the colorkey alltogether */
1307 p_vout->p_sys->b_caps_overlay_clipping = bCanClipOverlay;
1312 /*****************************************************************************
1313 * DirectXGetSurfaceDesc: Get some more information about the surface
1314 *****************************************************************************
1315 * This function get and stores the surface descriptor which among things
1316 * has the pointer to the picture data.
1317 *****************************************************************************/
1318 static int DirectXGetSurfaceDesc( picture_t *p_pic )
1322 /* Lock the surface to get a valid pointer to the picture buffer */
1323 memset( &p_pic->p_sys->ddsd, 0, sizeof( DDSURFACEDESC ));
1324 p_pic->p_sys->ddsd.dwSize = sizeof(DDSURFACEDESC);
1325 dxresult = IDirectDrawSurface3_Lock( p_pic->p_sys->p_surface,
1326 NULL, &p_pic->p_sys->ddsd,
1327 DDLOCK_NOSYSLOCK | DDLOCK_WAIT,
1329 if ( dxresult == DDERR_SURFACELOST )
1331 /* Your surface can be lost so be sure
1332 * to check this and restore it if needed */
1333 dxresult = IDirectDrawSurface3_Restore( p_pic->p_sys->p_surface );
1334 dxresult = IDirectDrawSurface3_Lock( p_pic->p_sys->p_surface, NULL,
1335 &p_pic->p_sys->ddsd,
1336 DDLOCK_NOSYSLOCK | DDLOCK_WAIT,
1339 if( dxresult != DD_OK )
1341 intf_ErrMsg( "vout: DirectXGetSurfaceDesc can't lock surface" );
1345 /* Unlock the Surface */
1346 dxresult = IDirectDrawSurface3_Unlock( p_pic->p_sys->p_surface, NULL );