1 /*****************************************************************************
2 * vout.c: Windows DirectX video output display method
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: vout.c,v 1.2 2002/08/12 09:34:15 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 also enables us to
34 * display video in window mode.
36 *****************************************************************************/
37 #include <errno.h> /* ENOMEM */
38 #include <stdlib.h> /* free() */
39 #include <string.h> /* strerror() */
51 /*****************************************************************************
53 * Defining them here allows us to get rid of the dxguid library during
55 *****************************************************************************/
57 DEFINE_GUID( IID_IDirectDraw2, 0xB3A6F3E0,0x2B43,0x11CF,0xA2,0xDE,0x00,0xAA,0x00,0xB9,0x33,0x56 );
58 DEFINE_GUID( IID_IDirectDrawSurface2, 0x57805885,0x6eec,0x11cf,0x94,0x41,0xa8,0x23,0x03,0xc1,0x0e,0x27 );
60 /*****************************************************************************
62 *****************************************************************************/
63 int E_(OpenVideo) ( vlc_object_t * );
64 void E_(CloseVideo) ( vlc_object_t * );
66 static int Init ( vout_thread_t * );
67 static void End ( vout_thread_t * );
68 static int Manage ( vout_thread_t * );
69 static void Display ( vout_thread_t *, picture_t * );
71 static int NewPictureVec ( vout_thread_t *, picture_t *, int );
72 static void FreePictureVec ( vout_thread_t *, picture_t *, int );
73 static int UpdatePictureStruct( vout_thread_t *, picture_t *, int );
75 static int DirectXInitDDraw ( vout_thread_t *p_vout );
76 static void DirectXCloseDDraw ( vout_thread_t *p_vout );
77 static int DirectXCreateDisplay ( vout_thread_t *p_vout );
78 static void DirectXCloseDisplay ( vout_thread_t *p_vout );
79 static int DirectXCreateSurface ( vout_thread_t *p_vout,
80 LPDIRECTDRAWSURFACE2 *, int, int, int );
81 static void DirectXCloseSurface ( vout_thread_t *p_vout,
82 LPDIRECTDRAWSURFACE2 );
83 static int DirectXCreateClipper ( vout_thread_t *p_vout );
84 static void DirectXGetDDrawCaps ( vout_thread_t *p_vout );
85 static int DirectXGetSurfaceDesc ( picture_t *p_pic );
87 /*****************************************************************************
88 * OpenVideo: allocate DirectX video thread output method
89 *****************************************************************************
90 * This function allocates and initialize the DirectX vout method.
91 *****************************************************************************/
92 int E_(OpenVideo) ( vlc_object_t *p_this )
94 vout_thread_t * p_vout = (vout_thread_t *)p_this;
96 /* Allocate structure */
97 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
98 if( p_vout->p_sys == NULL )
100 msg_Err( p_vout, "out of memory" );
104 /* Initialisations */
105 p_vout->pf_init = Init;
106 p_vout->pf_end = End;
107 p_vout->pf_manage = Manage;
108 p_vout->pf_render = NULL;
109 p_vout->pf_display = Display;
111 p_vout->p_sys->p_ddobject = NULL;
112 p_vout->p_sys->p_display = NULL;
113 p_vout->p_sys->p_current_surface = NULL;
114 p_vout->p_sys->p_clipper = NULL;
115 p_vout->p_sys->hbrush = NULL;
116 p_vout->p_sys->hwnd = NULL;
117 p_vout->p_sys->i_changes = 0;
118 p_vout->p_sys->b_caps_overlay_clipping = 0;
119 SetRectEmpty( &p_vout->p_sys->rect_display );
120 p_vout->p_sys->b_using_overlay = config_GetInt( p_vout, "overlay" );
121 p_vout->p_sys->b_use_sysmem = config_GetInt( p_vout, "directx-use-sysmem");
122 p_vout->p_sys->b_hw_yuv = config_GetInt( p_vout, "directx-hw-yuv" );
124 p_vout->p_sys->b_cursor_hidden = 0;
125 p_vout->p_sys->i_lastmoved = mdate();
127 /* Set main window's size */
128 p_vout->p_sys->i_window_width = p_vout->i_window_width;
129 p_vout->p_sys->i_window_height = p_vout->i_window_height;
131 /* Create the DirectXEventThread, this thread is created by us to isolate
132 * the Win32 PeekMessage function calls. We want to do this because
133 * Windows can stay blocked inside this call for a long time, and when
134 * this happens it thus blocks vlc's video_output thread.
135 * DirectXEventThread will take care of the creation of the video
136 * window (because PeekMessage has to be called from the same thread which
137 * created the window). */
138 msg_Dbg( p_vout, "creating DirectXEventThread" );
139 p_vout->p_sys->p_event =
140 vlc_object_create( p_vout, sizeof(event_thread_t) );
141 p_vout->p_sys->p_event->p_vout = p_vout;
142 if( vlc_thread_create( p_vout->p_sys->p_event,
143 "DirectX Events Thread", DirectXEventThread, 1 ) )
145 msg_Err( p_vout, "cannot create DirectXEventThread" );
146 vlc_object_destroy( p_vout->p_sys->p_event );
147 p_vout->p_sys->p_event = NULL;
151 if( p_vout->p_sys->p_event->b_error )
153 msg_Err( p_vout, "DirectXEventThread failed" );
157 vlc_object_attach( p_vout->p_sys->p_event, p_vout );
159 msg_Dbg( p_vout, "DirectXEventThread running" );
161 /* Initialise DirectDraw */
162 if( DirectXInitDDraw( p_vout ) )
164 msg_Err( p_vout, "cannot initialize DirectDraw" );
168 /* Create the directx display */
169 if( DirectXCreateDisplay( p_vout ) )
171 msg_Err( p_vout, "cannot initialize DirectDraw" );
178 E_(CloseVideo)( VLC_OBJECT(p_vout) );
183 /*****************************************************************************
184 * Init: initialize DirectX video thread output method
185 *****************************************************************************
186 * This function create the directx surfaces needed by the output thread.
187 * It is called at the beginning of the thread.
188 *****************************************************************************/
189 static int Init( vout_thread_t *p_vout )
193 /* Initialize the output structure.
194 * Since DirectDraw can do rescaling for us, stick to the default
195 * coordinates and aspect. */
196 p_vout->output.i_width = p_vout->render.i_width;
197 p_vout->output.i_height = p_vout->render.i_height;
198 p_vout->output.i_aspect = p_vout->render.i_aspect;
200 #define MAX_DIRECTBUFFERS 1
201 /* Right now we use only 1 directbuffer because we don't want the
202 * video decoder to decode directly into direct buffers as they are
203 * created into video memory and video memory is _really_ slow */
205 /* Choose the chroma we will try first. */
206 switch( p_vout->render.i_chroma )
208 case VLC_FOURCC('Y','U','Y','2'):
209 case VLC_FOURCC('Y','U','N','V'):
210 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
212 case VLC_FOURCC('U','Y','V','Y'):
213 case VLC_FOURCC('U','Y','N','V'):
214 case VLC_FOURCC('Y','4','2','2'):
215 p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y');
217 case VLC_FOURCC('Y','V','Y','U'):
218 p_vout->output.i_chroma = VLC_FOURCC('Y','V','Y','U');
221 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
225 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
227 i_chroma_backup = p_vout->output.i_chroma;
229 if( !I_OUTPUTPICTURES )
231 /* hmmm, it didn't work! Let's try commonly supported chromas */
232 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
233 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
234 if( !I_OUTPUTPICTURES )
236 /* hmmm, it didn't work! Let's try commonly supported chromas */
237 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
238 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
242 if( !I_OUTPUTPICTURES )
244 /* If it still didn't work then don't try to use an overlay */
245 p_vout->output.i_chroma = i_chroma_backup;
246 p_vout->p_sys->b_using_overlay = 0;
247 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
250 /* Change the window title bar text */
251 if( p_vout->p_sys->b_using_overlay )
252 SetWindowText( p_vout->p_sys->hwnd,
253 VOUT_TITLE " (hardware YUV overlay DirectX output)" );
254 else if( p_vout->p_sys->b_hw_yuv )
255 SetWindowText( p_vout->p_sys->hwnd,
256 VOUT_TITLE " (hardware YUV DirectX output)" );
257 else SetWindowText( p_vout->p_sys->hwnd,
258 VOUT_TITLE " (software RGB DirectX output)" );
263 /*****************************************************************************
264 * End: terminate Sys video thread output method
265 *****************************************************************************
266 * Terminate an output method created by Create.
267 * It is called at the end of the thread.
268 *****************************************************************************/
269 static void End( vout_thread_t *p_vout )
271 FreePictureVec( p_vout, p_vout->p_picture, I_OUTPUTPICTURES );
275 /*****************************************************************************
276 * CloseVideo: destroy Sys video thread output method
277 *****************************************************************************
278 * Terminate an output method created by Create
279 *****************************************************************************/
280 void E_(CloseVideo) ( vlc_object_t *p_this )
282 vout_thread_t * p_vout = (vout_thread_t *)p_this;
284 msg_Dbg( p_vout, "CloseVideo" );
286 DirectXCloseDisplay( p_vout );
287 DirectXCloseDDraw( p_vout );
289 if( p_vout->p_sys->p_event )
291 vlc_object_detach( p_vout->p_sys->p_event );
293 /* Kill DirectXEventThread */
294 p_vout->p_sys->p_event->b_die = 1;
296 /* we need to be sure DirectXEventThread won't stay stuck in
297 * GetMessage, so we send a fake message */
298 if( p_vout->p_sys->hwnd )
299 PostMessage( p_vout->p_sys->hwnd, WM_NULL, 0, 0);
301 vlc_thread_join( p_vout->p_sys->p_event );
302 vlc_object_destroy( p_vout->p_sys->p_event );
307 free( p_vout->p_sys );
308 p_vout->p_sys = NULL;
312 /*****************************************************************************
313 * Manage: handle Sys events
314 *****************************************************************************
315 * This function should be called regularly by the video output thread.
316 * It returns a non null value if an error occured.
317 *****************************************************************************/
318 static int Manage( vout_thread_t *p_vout )
320 WINDOWPLACEMENT window_placement;
322 /* We used to call the Win32 PeekMessage function here to read the window
323 * messages. But since window can stay blocked into this function for a
324 * long time (for example when you move your window on the screen), I
325 * decided to isolate PeekMessage in another thread. */
330 if( p_vout->i_changes & VOUT_SCALE_CHANGE
331 || p_vout->p_sys->i_changes & VOUT_SCALE_CHANGE)
333 msg_Dbg( p_vout, "Scale Change" );
334 if( !p_vout->p_sys->b_using_overlay )
335 InvalidateRect( p_vout->p_sys->hwnd, NULL, TRUE );
337 DirectXUpdateOverlay( p_vout );
338 p_vout->i_changes &= ~VOUT_SCALE_CHANGE;
339 p_vout->p_sys->i_changes &= ~VOUT_SCALE_CHANGE;
345 if( p_vout->i_changes & VOUT_SIZE_CHANGE
346 || p_vout->p_sys->i_changes & VOUT_SIZE_CHANGE )
348 msg_Dbg( p_vout, "Size Change" );
349 if( !p_vout->p_sys->b_using_overlay )
350 InvalidateRect( p_vout->p_sys->hwnd, NULL, TRUE );
352 DirectXUpdateOverlay( p_vout );
353 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
354 p_vout->p_sys->i_changes &= ~VOUT_SIZE_CHANGE;
360 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE
361 || p_vout->p_sys->i_changes & VOUT_FULLSCREEN_CHANGE )
363 p_vout->b_fullscreen = ! p_vout->b_fullscreen;
365 /* We need to switch between Maximized and Normal sized window */
366 window_placement.length = sizeof(WINDOWPLACEMENT);
367 GetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
368 if( p_vout->b_fullscreen )
370 /* Maximized window */
371 window_placement.showCmd = SW_SHOWMAXIMIZED;
372 /* Change window style, no borders and no title bar */
373 SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE, 0 );
379 window_placement.showCmd = SW_SHOWNORMAL;
380 /* Change window style, borders and title bar */
381 SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE,
382 WS_OVERLAPPEDWINDOW | WS_SIZEBOX | WS_VISIBLE );
385 SetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
387 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
388 p_vout->p_sys->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
394 if( (!p_vout->p_sys->b_cursor_hidden) &&
395 ( (mdate() - p_vout->p_sys->i_lastmoved) > 5000000 ) )
397 /* Hide the mouse automatically */
398 p_vout->p_sys->b_cursor_hidden = 1;
399 PostMessage( p_vout->p_sys->hwnd, WM_VLC_HIDE_MOUSE, 0, 0 );
402 /* Check if the event thread is still running */
403 if( p_vout->p_sys->p_event->b_die )
409 /*****************************************************************************
410 * Display: displays previously rendered output
411 *****************************************************************************
412 * This function sends the currently rendered image to the display, wait until
413 * it is displayed and switch the two rendering buffers, preparing next frame.
414 *****************************************************************************/
415 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
419 if( (p_vout->p_sys->p_display == NULL) )
421 msg_Warn( p_vout, "no display!!" );
425 if( !p_vout->p_sys->b_using_overlay )
429 /* We ask for the "NOTEARING" option */
430 memset( &ddbltfx, 0, sizeof(DDBLTFX) );
431 ddbltfx.dwSize = sizeof(DDBLTFX);
432 ddbltfx.dwDDFX = DDBLTFX_NOTEARING;
434 /* Blit video surface to display */
435 dxresult = IDirectDrawSurface2_Blt(p_vout->p_sys->p_display,
436 &p_vout->p_sys->rect_dest_clipped,
437 p_pic->p_sys->p_surface,
438 &p_vout->p_sys->rect_src_clipped,
439 DDBLT_ASYNC, &ddbltfx );
440 if ( dxresult == DDERR_SURFACELOST )
442 /* Our surface can be lost so be sure
443 * to check this and restore it if needed */
444 IDirectDrawSurface2_Restore( p_vout->p_sys->p_display );
446 /* Now that the surface has been restored try to display again */
447 dxresult = IDirectDrawSurface2_Blt(p_vout->p_sys->p_display,
448 &p_vout->p_sys->rect_dest_clipped,
449 p_pic->p_sys->p_surface,
450 &p_vout->p_sys->rect_src_clipped,
451 DDBLT_ASYNC, &ddbltfx );
454 if( dxresult != DD_OK )
456 msg_Warn( p_vout, "could not Blit the surface" );
461 else /* using overlay */
464 /* Flip the overlay buffers if we are using back buffers */
465 if( p_pic->p_sys->p_front_surface == p_pic->p_sys->p_surface )
468 dxresult = IDirectDrawSurface2_Flip( p_pic->p_sys->p_front_surface,
470 if ( dxresult == DDERR_SURFACELOST )
472 /* Our surface can be lost so be sure
473 * to check this and restore it if needed */
474 IDirectDrawSurface2_Restore( p_vout->p_sys->p_display );
475 IDirectDrawSurface2_Restore( p_pic->p_sys->p_front_surface );
477 /* Now that the surface has been restored try to display again */
478 dxresult = IDirectDrawSurface2_Flip( p_pic->p_sys->p_front_surface,
480 DirectXUpdateOverlay( p_vout );
483 if( dxresult != DD_OK )
484 msg_Warn( p_vout, "could not flip overlay surface" );
486 if( !DirectXGetSurfaceDesc( p_pic ) )
489 msg_Err( p_vout, "cannot get surface desc" );
493 if( !UpdatePictureStruct( p_vout, p_pic, p_vout->output.i_chroma ) )
496 msg_Err( p_vout, "invalid pic chroma" );
500 /* set currently displayed pic */
501 p_vout->p_sys->p_current_surface = p_pic->p_sys->p_front_surface;
507 /* following functions are local */
509 /*****************************************************************************
510 * DirectXInitDDraw: Takes care of all the DirectDraw initialisations
511 *****************************************************************************
512 * This function initialise and allocate resources for DirectDraw.
513 *****************************************************************************/
514 static int DirectXInitDDraw( vout_thread_t *p_vout )
517 HRESULT (WINAPI *OurDirectDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
518 LPDIRECTDRAW p_ddobject;
520 msg_Dbg( p_vout, "DirectXInitDDraw" );
522 /* load direct draw DLL */
523 p_vout->p_sys->hddraw_dll = LoadLibrary("DDRAW.DLL");
524 if( p_vout->p_sys->hddraw_dll == NULL )
526 msg_Warn( p_vout, "DirectXInitDDraw failed loading ddraw.dll" );
530 OurDirectDrawCreate =
531 (void *)GetProcAddress(p_vout->p_sys->hddraw_dll, "DirectDrawCreate");
532 if ( OurDirectDrawCreate == NULL )
534 msg_Err( p_vout, "DirectXInitDDraw failed GetProcAddress" );
538 /* Initialize DirectDraw now */
539 dxresult = OurDirectDrawCreate( NULL, &p_ddobject, NULL );
540 if( dxresult != DD_OK )
542 msg_Err( p_vout, "DirectXInitDDraw cannot initialize DDraw" );
546 /* Get the IDirectDraw2 interface */
547 dxresult = IDirectDraw_QueryInterface( p_ddobject, &IID_IDirectDraw2,
548 (LPVOID *)&p_vout->p_sys->p_ddobject );
549 /* Release the unused interface */
550 IDirectDraw_Release( p_ddobject );
551 if( dxresult != DD_OK )
553 msg_Err( p_vout, "cannot get IDirectDraw2 interface" );
557 /* Set DirectDraw Cooperative level, ie what control we want over Windows
559 dxresult = IDirectDraw2_SetCooperativeLevel( p_vout->p_sys->p_ddobject,
560 p_vout->p_sys->hwnd, DDSCL_NORMAL );
561 if( dxresult != DD_OK )
563 msg_Err( p_vout, "cannot set direct draw cooperative level" );
567 /* Probe the capabilities of the hardware */
568 DirectXGetDDrawCaps( p_vout );
570 msg_Dbg( p_vout, "End DirectXInitDDraw" );
574 if( p_vout->p_sys->p_ddobject )
575 IDirectDraw2_Release( p_vout->p_sys->p_ddobject );
576 if( p_vout->p_sys->hddraw_dll )
577 FreeLibrary( p_vout->p_sys->hddraw_dll );
578 p_vout->p_sys->hddraw_dll = NULL;
579 p_vout->p_sys->p_ddobject = NULL;
583 /*****************************************************************************
584 * DirectXCreateDisplay: create the DirectDraw display.
585 *****************************************************************************
586 * Create and initialize display according to preferences specified in the vout
588 *****************************************************************************/
589 static int DirectXCreateDisplay( vout_thread_t *p_vout )
593 LPDIRECTDRAWSURFACE p_display;
594 DDPIXELFORMAT pixel_format;
596 msg_Dbg( p_vout, "DirectXCreateDisplay" );
598 /* Now get the primary surface. This surface is what you actually see
600 memset( &ddsd, 0, sizeof( DDSURFACEDESC ));
601 ddsd.dwSize = sizeof(DDSURFACEDESC);
602 ddsd.dwFlags = DDSD_CAPS;
603 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
605 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
608 if( dxresult != DD_OK )
610 msg_Err( p_vout, "cannot get direct draw primary surface" );
614 dxresult = IDirectDrawSurface_QueryInterface( p_display,
615 &IID_IDirectDrawSurface2,
616 (LPVOID *)&p_vout->p_sys->p_display );
617 /* Release the old interface */
618 IDirectDrawSurface_Release( p_display );
619 if ( dxresult != DD_OK )
621 msg_Err( p_vout, "cannot get IDirectDrawSurface2 interface" );
625 /* The clipper will be used only in non-overlay mode */
626 DirectXCreateClipper( p_vout );
630 /* compute the colorkey pixel value from the RGB value we've got */
631 memset( &pixel_format, 0, sizeof( DDPIXELFORMAT ));
632 pixel_format.dwSize = sizeof( DDPIXELFORMAT );
633 dxresult = IDirectDrawSurface2_GetPixelFormat( p_vout->p_sys->p_display,
635 if( dxresult != DD_OK )
636 msg_Warn( p_vout, "DirectXUpdateOverlay GetPixelFormat failed" );
637 p_vout->p_sys->i_colorkey = (DWORD)((( p_vout->p_sys->i_rgb_colorkey
638 * pixel_format.dwRBitMask) / 255)
639 & pixel_format.dwRBitMask);
646 /*****************************************************************************
647 * DirectXCreateClipper: Create a clipper that will be used when blitting the
648 * RGB surface to the main display.
649 *****************************************************************************
650 * This clipper prevents us to modify by mistake anything on the screen
651 * which doesn't belong to our window. For example when a part of our video
652 * window is hidden by another window.
653 *****************************************************************************/
654 static int DirectXCreateClipper( vout_thread_t *p_vout )
658 msg_Dbg( p_vout, "DirectXCreateClipper" );
660 /* Create the clipper */
661 dxresult = IDirectDraw2_CreateClipper( p_vout->p_sys->p_ddobject, 0,
662 &p_vout->p_sys->p_clipper, NULL );
663 if( dxresult != DD_OK )
665 msg_Warn( p_vout, "DirectXCreateClipper cannot create clipper" );
669 /* associate the clipper to the window */
670 dxresult = IDirectDrawClipper_SetHWnd(p_vout->p_sys->p_clipper, 0,
671 p_vout->p_sys->hwnd);
672 if( dxresult != DD_OK )
675 "DirectXCreateClipper cannot attach clipper to window" );
679 /* associate the clipper with the surface */
680 dxresult = IDirectDrawSurface_SetClipper(p_vout->p_sys->p_display,
681 p_vout->p_sys->p_clipper);
682 if( dxresult != DD_OK )
685 "DirectXCreateClipper cannot attach clipper to surface" );
692 if( p_vout->p_sys->p_clipper )
693 IDirectDrawClipper_Release( p_vout->p_sys->p_clipper );
694 p_vout->p_sys->p_clipper = NULL;
699 /*****************************************************************************
700 * DirectXCreateSurface: create an YUV overlay or RGB surface for the video.
701 *****************************************************************************
702 * The best method of display is with an YUV overlay because the YUV->RGB
703 * conversion is done in hardware.
704 * You can also create a plain RGB surface.
705 * ( Maybe we could also try an RGB overlay surface, which could have hardware
706 * scaling and which would also be faster in window mode because you don't
707 * need to do any blitting to the main display...)
708 *****************************************************************************/
709 static int DirectXCreateSurface( vout_thread_t *p_vout,
710 LPDIRECTDRAWSURFACE2 *pp_surface_final,
711 int i_chroma, int b_overlay,
715 LPDIRECTDRAWSURFACE p_surface;
718 /* Create the video surface */
721 /* Now try to create the YUV overlay surface.
722 * This overlay will be displayed on top of the primary surface.
723 * A color key is used to determine whether or not the overlay will be
724 * displayed, ie the overlay will be displayed in place of the primary
725 * surface wherever the primary surface will have this color.
726 * The video window has been created with a background of this color so
727 * the overlay will be only displayed on top of this window */
729 memset( &ddsd, 0, sizeof( DDSURFACEDESC ));
730 ddsd.dwSize = sizeof(DDSURFACEDESC);
731 ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
732 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
733 ddsd.ddpfPixelFormat.dwFourCC = i_chroma;
734 ddsd.dwFlags = DDSD_CAPS |
738 ddsd.dwFlags |= (i_backbuffers ? DDSD_BACKBUFFERCOUNT : 0);
739 ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY |
741 ddsd.ddsCaps.dwCaps |= (i_backbuffers ? DDSCAPS_COMPLEX | DDSCAPS_FLIP
743 ddsd.dwHeight = p_vout->render.i_height;
744 ddsd.dwWidth = p_vout->render.i_width;
745 ddsd.dwBackBufferCount = i_backbuffers;
747 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
750 if( dxresult != DD_OK )
752 *pp_surface_final = NULL;
759 vlc_bool_t b_rgb_surface =
760 ( i_chroma == VLC_FOURCC('R','G','B','2') )
761 || ( i_chroma == VLC_FOURCC('R','V','1','5') )
762 || ( i_chroma == VLC_FOURCC('R','V','1','6') )
763 || ( i_chroma == VLC_FOURCC('R','V','2','4') )
764 || ( i_chroma == VLC_FOURCC('R','V','3','2') );
766 memset( &ddsd, 0, sizeof( DDSURFACEDESC ) );
767 ddsd.dwSize = sizeof(DDSURFACEDESC);
768 ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
769 ddsd.dwFlags = DDSD_HEIGHT |
772 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
773 ddsd.dwHeight = p_vout->render.i_height;
774 ddsd.dwWidth = p_vout->render.i_width;
776 if( p_vout->p_sys->b_use_sysmem )
777 ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
779 ddsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
783 ddsd.dwFlags |= DDSD_PIXELFORMAT;
784 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
785 ddsd.ddpfPixelFormat.dwFourCC = i_chroma;
788 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
791 if( dxresult != DD_OK )
793 *pp_surface_final = NULL;
798 /* Now that the surface is created, try to get a newer DirectX interface */
799 dxresult = IDirectDrawSurface_QueryInterface( p_surface,
800 &IID_IDirectDrawSurface2,
801 (LPVOID *)pp_surface_final );
802 IDirectDrawSurface_Release( p_surface ); /* Release the old interface */
803 if ( dxresult != DD_OK )
805 msg_Err( p_vout, "cannot get IDirectDrawSurface2 interface" );
806 *pp_surface_final = NULL;
813 /*****************************************************************************
814 * DirectXUpdateOverlay: Move or resize overlay surface on video display.
815 *****************************************************************************
816 * This function is used to move or resize an overlay surface on the screen.
817 * Ususally the overlay is moved by the user and thus, by a move or resize
819 *****************************************************************************/
820 void DirectXUpdateOverlay( vout_thread_t *p_vout )
826 if( p_vout->p_sys->p_current_surface == NULL ||
827 !p_vout->p_sys->b_using_overlay )
830 /* The new window dimensions should already have been computed by the
831 * caller of this function */
833 /* Position and show the overlay */
834 memset(&ddofx, 0, sizeof(DDOVERLAYFX));
835 ddofx.dwSize = sizeof(DDOVERLAYFX);
836 ddofx.dckDestColorkey.dwColorSpaceLowValue = p_vout->p_sys->i_colorkey;
837 ddofx.dckDestColorkey.dwColorSpaceHighValue = p_vout->p_sys->i_colorkey;
839 dwFlags = DDOVER_SHOW;
840 if( !p_vout->p_sys->b_caps_overlay_clipping )
841 dwFlags |= DDOVER_KEYDESTOVERRIDE;
843 dxresult = IDirectDrawSurface2_UpdateOverlay(
844 p_vout->p_sys->p_current_surface,
845 &p_vout->p_sys->rect_src_clipped,
846 p_vout->p_sys->p_display,
847 &p_vout->p_sys->rect_dest_clipped,
850 if(dxresult != DD_OK)
853 "DirectXUpdateOverlay cannot move or resize overlay" );
858 /*****************************************************************************
859 * DirectXCloseDDraw: Release the DDraw object allocated by DirectXInitDDraw
860 *****************************************************************************
861 * This function returns all resources allocated by DirectXInitDDraw.
862 *****************************************************************************/
863 static void DirectXCloseDDraw( vout_thread_t *p_vout )
865 msg_Dbg( p_vout, "DirectXCloseDDraw" );
866 if( p_vout->p_sys->p_ddobject != NULL )
868 IDirectDraw2_Release(p_vout->p_sys->p_ddobject);
869 p_vout->p_sys->p_ddobject = NULL;
872 if( p_vout->p_sys->hddraw_dll != NULL )
874 FreeLibrary( p_vout->p_sys->hddraw_dll );
875 p_vout->p_sys->hddraw_dll = NULL;
879 /*****************************************************************************
880 * DirectXCloseDisplay: close and reset the DirectX display device
881 *****************************************************************************
882 * This function returns all resources allocated by DirectXCreateDisplay.
883 *****************************************************************************/
884 static void DirectXCloseDisplay( vout_thread_t *p_vout )
886 msg_Dbg( p_vout, "DirectXCloseDisplay" );
888 if( p_vout->p_sys->p_clipper != NULL )
890 msg_Dbg( p_vout, "DirectXCloseDisplay clipper" );
891 IDirectDrawClipper_Release( p_vout->p_sys->p_clipper );
892 p_vout->p_sys->p_clipper = NULL;
895 if( p_vout->p_sys->p_display != NULL )
897 msg_Dbg( p_vout, "DirectXCloseDisplay display" );
898 IDirectDrawSurface2_Release( p_vout->p_sys->p_display );
899 p_vout->p_sys->p_display = NULL;
903 /*****************************************************************************
904 * DirectXCloseSurface: close the YUV overlay or RGB surface.
905 *****************************************************************************
906 * This function returns all resources allocated for the surface.
907 *****************************************************************************/
908 static void DirectXCloseSurface( vout_thread_t *p_vout,
909 LPDIRECTDRAWSURFACE2 p_surface )
911 msg_Dbg( p_vout, "DirectXCloseSurface" );
912 if( p_surface != NULL )
914 IDirectDrawSurface2_Release( p_surface );
918 /*****************************************************************************
919 * NewPictureVec: allocate a vector of identical pictures
920 *****************************************************************************
921 * Returns 0 on success, -1 otherwise
922 *****************************************************************************/
923 static int NewPictureVec( vout_thread_t *p_vout, picture_t *p_pic,
927 vlc_bool_t b_result_ok;
928 LPDIRECTDRAWSURFACE2 p_surface;
930 msg_Dbg( p_vout, "NewPictureVec" );
932 I_OUTPUTPICTURES = 0;
934 /* First we try to use an YUV overlay surface.
935 * The overlay surface that we create won't be used to decode directly
936 * into it because accessing video memory directly is way to slow (remember
937 * that pictures are decoded macroblock per macroblock). Instead the video
938 * will be decoded in picture buffers in system memory which will then be
939 * memcpy() to the overlay surface. */
940 if( p_vout->p_sys->b_using_overlay )
942 /* Triple buffering rocks! it doesn't have any processing overhead
943 * (you don't have to wait for the vsync) and provides for a very nice
944 * video quality (no tearing). */
946 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
947 p_vout->output.i_chroma,
948 p_vout->p_sys->b_using_overlay,
949 2 /* number of backbuffers */ );
952 /* Try to reduce the number of backbuffers */
953 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
954 p_vout->output.i_chroma,
955 p_vout->p_sys->b_using_overlay,
956 0 /* number of backbuffers */);
962 picture_sys_t front_pic_sys;
963 front_pic.p_sys = &front_pic_sys;
965 /* Allocate internal structure */
966 p_pic[0].p_sys = malloc( sizeof( picture_sys_t ) );
967 if( p_pic[0].p_sys == NULL )
969 DirectXCloseSurface( p_vout, p_surface );
973 /* set front buffer */
974 p_pic[0].p_sys->p_front_surface = p_surface;
976 /* Get the back buffer */
977 memset( &dds_caps, 0, sizeof( DDSCAPS ) );
978 dds_caps.dwCaps = DDSCAPS_BACKBUFFER;
979 if( DD_OK != IDirectDrawSurface2_GetAttachedSurface(
980 p_surface, &dds_caps,
981 &p_pic[0].p_sys->p_surface ) )
983 msg_Warn( p_vout, "NewPictureVec could not get back buffer" );
984 /* front buffer is the same as back buffer */
985 p_pic[0].p_sys->p_surface = p_surface;
989 p_vout->p_sys->p_current_surface = front_pic.p_sys->p_surface =
990 p_pic[0].p_sys->p_front_surface;
992 /* reset the front buffer memory */
993 if( DirectXGetSurfaceDesc( &front_pic ) &&
994 UpdatePictureStruct( p_vout, &front_pic,
995 p_vout->output.i_chroma ) )
998 for( i = 0; i < front_pic.i_planes; i++ )
999 for( j = 0; j < front_pic.p[i].i_lines; j++)
1000 memset( front_pic.p[i].p_pixels + j *
1001 front_pic.p[i].i_pitch, 127,
1002 front_pic.p[i].i_visible_pitch );
1005 DirectXUpdateOverlay( p_vout );
1006 I_OUTPUTPICTURES = 1;
1007 msg_Dbg( p_vout, "DirectX YUV overlay created successfully" );
1011 /* As we can't have an overlay, we'll try to create a plain offscreen
1012 * surface. This surface will reside in video memory because there's a
1013 * better chance then that we'll be able to use some kind of hardware
1014 * acceleration like rescaling, blitting or YUV->RGB conversions.
1015 * We then only need to blit this surface onto the main display when we
1016 * want to display it */
1017 if( !p_vout->p_sys->b_using_overlay )
1020 if( p_vout->p_sys->b_hw_yuv )
1021 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
1022 p_vout->output.i_chroma,
1023 p_vout->p_sys->b_using_overlay,
1024 0 /* no back buffers */ );
1026 if( !p_vout->p_sys->b_hw_yuv || !b_result_ok )
1028 /* Our last choice is to use a plain RGB surface */
1029 DDPIXELFORMAT ddpfPixelFormat;
1031 ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
1032 IDirectDrawSurface2_GetPixelFormat( p_vout->p_sys->p_display,
1035 if( ddpfPixelFormat.dwFlags & DDPF_RGB )
1037 switch( ddpfPixelFormat.dwRGBBitCount )
1039 case 8: /* FIXME: set the palette */
1040 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
1043 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
1046 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
1049 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
1052 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
1055 msg_Err( p_vout, "unknown screen depth" );
1058 p_vout->output.i_rmask = ddpfPixelFormat.dwRBitMask;
1059 p_vout->output.i_gmask = ddpfPixelFormat.dwGBitMask;
1060 p_vout->output.i_bmask = ddpfPixelFormat.dwBBitMask;
1063 p_vout->p_sys->b_hw_yuv = 0;
1065 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
1066 p_vout->output.i_chroma,
1067 p_vout->p_sys->b_using_overlay,
1068 0 /* no back buffers */ );
1073 /* Allocate internal structure */
1074 p_pic[0].p_sys = malloc( sizeof( picture_sys_t ) );
1075 if( p_pic[0].p_sys == NULL )
1077 DirectXCloseSurface( p_vout, p_surface );
1080 p_pic[0].p_sys->p_surface = p_pic[0].p_sys->p_front_surface
1083 I_OUTPUTPICTURES = 1;
1085 msg_Dbg( p_vout, "DirectX plain surface created successfully" );
1090 /* Now that we've got all our direct-buffers, we can finish filling in the
1091 * picture_t structures */
1092 for( i = 0; i < I_OUTPUTPICTURES; i++ )
1094 p_pic[i].i_status = DESTROYED_PICTURE;
1095 p_pic[i].i_type = DIRECT_PICTURE;
1096 PP_OUTPUTPICTURE[i] = &p_pic[i];
1098 if( !DirectXGetSurfaceDesc( &p_pic[i] ) )
1101 FreePictureVec( p_vout, p_pic, I_OUTPUTPICTURES );
1102 I_OUTPUTPICTURES = 0;
1106 if( !UpdatePictureStruct(p_vout, &p_pic[i], p_vout->output.i_chroma) )
1109 /* Unknown chroma, tell the guy to get lost */
1110 msg_Err( p_vout, "never heard of chroma 0x%.8x (%4.4s)",
1111 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma );
1112 FreePictureVec( p_vout, p_pic, I_OUTPUTPICTURES );
1113 I_OUTPUTPICTURES = 0;
1118 msg_Dbg( p_vout, "End NewPictureVec");
1122 /*****************************************************************************
1123 * FreePicture: destroy a picture vector allocated with NewPictureVec
1124 *****************************************************************************
1126 *****************************************************************************/
1127 static void FreePictureVec( vout_thread_t *p_vout, picture_t *p_pic,
1132 for( i = 0; i < i_num_pics; i++ )
1134 DirectXCloseSurface( p_vout, p_pic[i].p_sys->p_front_surface );
1136 for( i = 0; i < i_num_pics; i++ )
1138 free( p_pic[i].p_sys );
1143 /*****************************************************************************
1144 * UpdatePictureStruct: updates the internal data in the picture_t structure
1145 *****************************************************************************
1146 * This will setup stuff for use by the video_output thread
1147 *****************************************************************************/
1148 static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
1152 switch( p_vout->output.i_chroma )
1154 case VLC_FOURCC('R','G','B','2'):
1155 case VLC_FOURCC('R','V','1','5'):
1156 case VLC_FOURCC('R','V','1','6'):
1157 case VLC_FOURCC('R','V','2','4'):
1158 case VLC_FOURCC('R','V','3','2'):
1159 p_pic->p->p_pixels = p_pic->p_sys->ddsd.lpSurface;
1160 p_pic->p->i_lines = p_vout->output.i_height;
1161 p_pic->p->i_pitch = p_pic->p_sys->ddsd.lPitch;
1162 switch( p_vout->output.i_chroma )
1164 case VLC_FOURCC('R','G','B','2'):
1165 p_pic->p->i_pixel_pitch = 1;
1167 case VLC_FOURCC('R','V','1','5'):
1168 case VLC_FOURCC('R','V','1','6'):
1169 p_pic->p->i_pixel_pitch = 2;
1171 case VLC_FOURCC('R','V','2','4'):
1172 case VLC_FOURCC('R','V','3','2'):
1173 p_pic->p->i_pixel_pitch = 4;
1178 p_pic->p->i_visible_pitch = p_vout->output.i_width *
1179 p_pic->p->i_pixel_pitch;
1180 p_pic->i_planes = 1;
1183 case VLC_FOURCC('Y','V','1','2'):
1185 p_pic->Y_PIXELS = p_pic->p_sys->ddsd.lpSurface;
1186 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1187 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->ddsd.lPitch;
1188 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
1189 p_pic->p[Y_PLANE].i_visible_pitch = p_vout->output.i_width *
1190 p_pic->p[Y_PLANE].i_pixel_pitch;
1192 p_pic->V_PIXELS = p_pic->Y_PIXELS
1193 + p_pic->p[Y_PLANE].i_lines * p_pic->p[Y_PLANE].i_pitch;
1194 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1195 p_pic->p[V_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1196 p_pic->p[V_PLANE].i_pixel_pitch = 1;
1197 p_pic->p[V_PLANE].i_visible_pitch = p_vout->output.i_width *
1198 p_pic->p[V_PLANE].i_pixel_pitch;
1200 p_pic->U_PIXELS = p_pic->V_PIXELS
1201 + p_pic->p[V_PLANE].i_lines * p_pic->p[V_PLANE].i_pitch;
1202 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1203 p_pic->p[U_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1204 p_pic->p[U_PLANE].i_pixel_pitch = 1;
1205 p_pic->p[U_PLANE].i_visible_pitch = p_vout->output.i_width *
1206 p_pic->p[U_PLANE].i_pixel_pitch;
1208 p_pic->i_planes = 3;
1211 case VLC_FOURCC('I','Y','U','V'):
1213 p_pic->Y_PIXELS = p_pic->p_sys->ddsd.lpSurface;
1214 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1215 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->ddsd.lPitch;
1216 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
1217 p_pic->p[Y_PLANE].i_visible_pitch = p_vout->output.i_width *
1218 p_pic->p[Y_PLANE].i_pixel_pitch;
1220 p_pic->U_PIXELS = p_pic->Y_PIXELS
1221 + p_pic->p[Y_PLANE].i_lines * p_pic->p[Y_PLANE].i_pitch;
1222 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1223 p_pic->p[U_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1224 p_pic->p[U_PLANE].i_pixel_pitch = 1;
1225 p_pic->p[U_PLANE].i_visible_pitch = p_vout->output.i_width *
1226 p_pic->p[U_PLANE].i_pixel_pitch;
1228 p_pic->V_PIXELS = p_pic->U_PIXELS
1229 + p_pic->p[U_PLANE].i_lines * p_pic->p[U_PLANE].i_pitch;
1230 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1231 p_pic->p[V_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1232 p_pic->p[V_PLANE].i_pixel_pitch = 1;
1233 p_pic->p[V_PLANE].i_visible_pitch = p_vout->output.i_width *
1234 p_pic->p[V_PLANE].i_pixel_pitch;
1236 p_pic->i_planes = 3;
1239 case VLC_FOURCC('Y','U','Y','2'):
1241 p_pic->p->p_pixels = p_pic->p_sys->ddsd.lpSurface;
1242 p_pic->p->i_lines = p_vout->output.i_height;
1243 p_pic->p->i_pitch = p_pic->p_sys->ddsd.lPitch;
1244 p_pic->p->i_pixel_pitch = 2;
1245 p_pic->p->i_visible_pitch = p_vout->output.i_width *
1246 p_pic->p->i_pixel_pitch;
1248 p_pic->i_planes = 1;
1260 /*****************************************************************************
1261 * DirectXGetDDrawCaps: Probe the capabilities of the hardware
1262 *****************************************************************************
1263 * It is nice to know which features are supported by the hardware so we can
1264 * find ways to optimize our rendering.
1265 *****************************************************************************/
1266 static void DirectXGetDDrawCaps( vout_thread_t *p_vout )
1271 /* This is just an indication of whether or not we'll support overlay,
1272 * but with this test we don't know if we support YUV overlay */
1273 memset( &ddcaps, 0, sizeof( DDCAPS ));
1274 ddcaps.dwSize = sizeof(DDCAPS);
1275 dxresult = IDirectDraw2_GetCaps( p_vout->p_sys->p_ddobject,
1277 if(dxresult != DD_OK )
1279 msg_Warn( p_vout, "cannot get caps" );
1283 BOOL bHasOverlay, bHasOverlayFourCC, bCanClipOverlay,
1284 bHasColorKey, bCanStretch;
1286 /* Determine if the hardware supports overlay surfaces */
1287 bHasOverlay = ((ddcaps.dwCaps & DDCAPS_OVERLAY) ==
1288 DDCAPS_OVERLAY) ? TRUE : FALSE;
1289 /* Determine if the hardware supports overlay surfaces */
1290 bHasOverlayFourCC = ((ddcaps.dwCaps & DDCAPS_OVERLAYFOURCC) ==
1291 DDCAPS_OVERLAYFOURCC) ? TRUE : FALSE;
1292 /* Determine if the hardware supports overlay surfaces */
1293 bCanClipOverlay = ((ddcaps.dwCaps & DDCAPS_OVERLAYCANTCLIP) ==
1295 /* Determine if the hardware supports colorkeying */
1296 bHasColorKey = ((ddcaps.dwCaps & DDCAPS_COLORKEY) ==
1297 DDCAPS_COLORKEY) ? TRUE : FALSE;
1298 /* Determine if the hardware supports scaling of the overlay surface */
1299 bCanStretch = ((ddcaps.dwCaps & DDCAPS_OVERLAYSTRETCH) ==
1300 DDCAPS_OVERLAYSTRETCH) ? TRUE : FALSE;
1301 msg_Dbg( p_vout, "DirectDraw Capabilities: overlay=%i yuvoverlay=%i "
1302 "can_clip_overlay=%i colorkey=%i stretch=%i",
1303 bHasOverlay, bHasOverlayFourCC, bCanClipOverlay,
1304 bHasColorKey, bCanStretch );
1306 /* Overlay clipping support is interesting for us as it means we can
1307 * get rid of the colorkey alltogether */
1308 p_vout->p_sys->b_caps_overlay_clipping = bCanClipOverlay;
1313 /*****************************************************************************
1314 * DirectXGetSurfaceDesc: Get some more information about the surface
1315 *****************************************************************************
1316 * This function get and stores the surface descriptor which among things
1317 * has the pointer to the picture data.
1318 *****************************************************************************/
1319 static int DirectXGetSurfaceDesc( picture_t *p_pic )
1323 /* Lock the surface to get a valid pointer to the picture buffer */
1324 memset( &p_pic->p_sys->ddsd, 0, sizeof( DDSURFACEDESC ));
1325 p_pic->p_sys->ddsd.dwSize = sizeof(DDSURFACEDESC);
1326 dxresult = IDirectDrawSurface2_Lock( p_pic->p_sys->p_surface,
1327 NULL, &p_pic->p_sys->ddsd,
1328 DDLOCK_NOSYSLOCK | DDLOCK_WAIT,
1330 if ( dxresult == DDERR_SURFACELOST )
1332 /* Your surface can be lost so be sure
1333 * to check this and restore it if needed */
1334 dxresult = IDirectDrawSurface2_Restore( p_pic->p_sys->p_surface );
1335 dxresult = IDirectDrawSurface2_Lock( p_pic->p_sys->p_surface, NULL,
1336 &p_pic->p_sys->ddsd,
1337 DDLOCK_NOSYSLOCK | DDLOCK_WAIT,
1340 if( dxresult != DD_OK )
1342 //X msg_Err( p_vout, "DirectXGetSurfaceDesc cannot lock surface" );
1346 /* Unlock the Surface */
1347 dxresult = IDirectDrawSurface2_Unlock( p_pic->p_sys->p_surface, NULL );