1 /*****************************************************************************
2 * vout_directx.c: Windows DirectX video output display method
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: vout_directx.c,v 1.42 2002/07/31 20:56:51 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() */
49 #include "vout_directx.h"
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 static int Init ( vout_thread_t * );
64 static void End ( vout_thread_t * );
65 static int Manage ( vout_thread_t * );
66 static void Display ( vout_thread_t *, picture_t * );
68 static int NewPictureVec ( vout_thread_t *, picture_t *, int );
69 static void FreePictureVec ( vout_thread_t *, picture_t *, int );
70 static int UpdatePictureStruct( vout_thread_t *, picture_t *, int );
72 static int DirectXInitDDraw ( vout_thread_t *p_vout );
73 static void DirectXCloseDDraw ( vout_thread_t *p_vout );
74 static int DirectXCreateDisplay ( vout_thread_t *p_vout );
75 static void DirectXCloseDisplay ( vout_thread_t *p_vout );
76 static int DirectXCreateSurface ( vout_thread_t *p_vout,
77 LPDIRECTDRAWSURFACE2 *, int, int, int );
78 static void DirectXCloseSurface ( vout_thread_t *p_vout,
79 LPDIRECTDRAWSURFACE2 );
80 static int DirectXCreateClipper ( vout_thread_t *p_vout );
81 static void DirectXGetDDrawCaps ( vout_thread_t *p_vout );
82 static int DirectXGetSurfaceDesc ( picture_t *p_pic );
84 /*****************************************************************************
85 * OpenVideo: allocate DirectX video thread output method
86 *****************************************************************************
87 * This function allocates and initialize the DirectX vout method.
88 *****************************************************************************/
89 int E_(OpenVideo) ( vlc_object_t *p_this )
91 vout_thread_t * p_vout = (vout_thread_t *)p_this;
93 /* Allocate structure */
94 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
95 if( p_vout->p_sys == NULL )
97 msg_Err( p_vout, "out of memory" );
101 /* Initialisations */
102 p_vout->pf_init = Init;
103 p_vout->pf_end = End;
104 p_vout->pf_manage = Manage;
105 p_vout->pf_render = NULL;
106 p_vout->pf_display = Display;
108 p_vout->p_sys->p_ddobject = NULL;
109 p_vout->p_sys->p_display = NULL;
110 p_vout->p_sys->p_current_surface = NULL;
111 p_vout->p_sys->p_clipper = NULL;
112 p_vout->p_sys->hbrush = NULL;
113 p_vout->p_sys->hwnd = NULL;
114 p_vout->p_sys->i_changes = 0;
115 p_vout->p_sys->b_caps_overlay_clipping = 0;
116 SetRectEmpty( &p_vout->p_sys->rect_display );
117 p_vout->p_sys->b_using_overlay = config_GetInt( p_vout, "overlay" );
118 p_vout->p_sys->b_use_sysmem = config_GetInt( p_vout, "directx-use-sysmem");
119 p_vout->p_sys->b_hw_yuv = config_GetInt( p_vout, "directx-hw-yuv" );
121 p_vout->p_sys->b_cursor_hidden = 0;
122 p_vout->p_sys->i_lastmoved = mdate();
124 /* Set main window's size */
125 p_vout->p_sys->i_window_width = p_vout->i_window_width;
126 p_vout->p_sys->i_window_height = p_vout->i_window_height;
128 /* Create the DirectXEventThread, this thread is created by us to isolate
129 * the Win32 PeekMessage function calls. We want to do this because
130 * Windows can stay blocked inside this call for a long time, and when
131 * this happens it thus blocks vlc's video_output thread.
132 * DirectXEventThread will take care of the creation of the video
133 * window (because PeekMessage has to be called from the same thread which
134 * created the window). */
135 msg_Dbg( p_vout, "creating DirectXEventThread" );
136 p_vout->p_sys->p_event =
137 vlc_object_create( p_vout, sizeof(event_thread_t) );
138 p_vout->p_sys->p_event->p_vout = p_vout;
139 if( vlc_thread_create( p_vout->p_sys->p_event,
140 "DirectX Events Thread", DirectXEventThread, 1 ) )
142 msg_Err( p_vout, "cannot create DirectXEventThread" );
143 vlc_object_destroy( p_vout->p_sys->p_event );
144 p_vout->p_sys->p_event = NULL;
148 if( p_vout->p_sys->p_event->b_error )
150 msg_Err( p_vout, "DirectXEventThread failed" );
154 vlc_object_attach( p_vout->p_sys->p_event, p_vout );
156 msg_Dbg( p_vout, "DirectXEventThread running" );
158 /* Initialise DirectDraw */
159 if( DirectXInitDDraw( p_vout ) )
161 msg_Err( p_vout, "cannot initialize DirectDraw" );
165 /* Create the directx display */
166 if( DirectXCreateDisplay( p_vout ) )
168 msg_Err( p_vout, "cannot initialize DirectDraw" );
180 /*****************************************************************************
181 * Init: initialize DirectX video thread output method
182 *****************************************************************************
183 * This function create the directx surfaces needed by the output thread.
184 * It is called at the beginning of the thread.
185 *****************************************************************************/
186 static int Init( vout_thread_t *p_vout )
190 /* Initialize the output structure.
191 * Since DirectDraw can do rescaling for us, stick to the default
192 * coordinates and aspect. */
193 p_vout->output.i_width = p_vout->render.i_width;
194 p_vout->output.i_height = p_vout->render.i_height;
195 p_vout->output.i_aspect = p_vout->render.i_aspect;
197 #define MAX_DIRECTBUFFERS 1
198 /* Right now we use only 1 directbuffer because we don't want the
199 * video decoder to decode directly into direct buffers as they are
200 * created into video memory and video memory is _really_ slow */
202 /* Choose the chroma we will try first. */
203 switch( p_vout->render.i_chroma )
205 case VLC_FOURCC('Y','U','Y','2'):
206 case VLC_FOURCC('Y','U','N','V'):
207 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
209 case VLC_FOURCC('U','Y','V','Y'):
210 case VLC_FOURCC('U','Y','N','V'):
211 case VLC_FOURCC('Y','4','2','2'):
212 p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y');
214 case VLC_FOURCC('Y','V','Y','U'):
215 p_vout->output.i_chroma = VLC_FOURCC('Y','V','Y','U');
218 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
222 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
224 i_chroma_backup = p_vout->output.i_chroma;
226 if( !I_OUTPUTPICTURES )
228 /* hmmm, it didn't work! Let's try commonly supported chromas */
229 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
230 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
231 if( !I_OUTPUTPICTURES )
233 /* hmmm, it didn't work! Let's try commonly supported chromas */
234 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
235 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
239 if( !I_OUTPUTPICTURES )
241 /* If it still didn't work then don't try to use an overlay */
242 p_vout->output.i_chroma = i_chroma_backup;
243 p_vout->p_sys->b_using_overlay = 0;
244 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
247 /* Change the window title bar text */
248 if( p_vout->p_sys->b_using_overlay )
249 SetWindowText( p_vout->p_sys->hwnd,
250 VOUT_TITLE " (hardware YUV overlay DirectX output)" );
251 else if( p_vout->p_sys->b_hw_yuv )
252 SetWindowText( p_vout->p_sys->hwnd,
253 VOUT_TITLE " (hardware YUV DirectX output)" );
254 else SetWindowText( p_vout->p_sys->hwnd,
255 VOUT_TITLE " (software RGB DirectX output)" );
260 /*****************************************************************************
261 * End: terminate Sys video thread output method
262 *****************************************************************************
263 * Terminate an output method created by Create.
264 * It is called at the end of the thread.
265 *****************************************************************************/
266 static void End( vout_thread_t *p_vout )
268 FreePictureVec( p_vout, p_vout->p_picture, I_OUTPUTPICTURES );
272 /*****************************************************************************
273 * CloseVideo: destroy Sys video thread output method
274 *****************************************************************************
275 * Terminate an output method created by Create
276 *****************************************************************************/
277 void E_(CloseVideo) ( vlc_object_t *p_this )
279 vout_thread_t * p_vout = (vout_thread_t *)p_this;
281 msg_Dbg( p_vout, "CloseVideo" );
283 DirectXCloseDisplay( p_vout );
284 DirectXCloseDDraw( p_vout );
286 if( p_vout->p_sys->p_event )
288 vlc_object_detach_all( p_vout->p_sys->p_event );
290 /* Kill DirectXEventThread */
291 p_vout->p_sys->p_event->b_die = 1;
293 /* we need to be sure DirectXEventThread won't stay stuck in
294 * GetMessage, so we send a fake message */
295 if( p_vout->p_sys->hwnd )
296 PostMessage( p_vout->p_sys->hwnd, WM_NULL, 0, 0);
298 vlc_thread_join( p_vout->p_sys->p_event );
299 vlc_object_destroy( p_vout->p_sys->p_event );
304 free( p_vout->p_sys );
305 p_vout->p_sys = NULL;
309 /*****************************************************************************
310 * Manage: handle Sys events
311 *****************************************************************************
312 * This function should be called regularly by the video output thread.
313 * It returns a non null value if an error occured.
314 *****************************************************************************/
315 static int Manage( vout_thread_t *p_vout )
317 WINDOWPLACEMENT window_placement;
319 /* We used to call the Win32 PeekMessage function here to read the window
320 * messages. But since window can stay blocked into this function for a
321 * long time (for example when you move your window on the screen), I
322 * decided to isolate PeekMessage in another thread. */
327 if( p_vout->i_changes & VOUT_SCALE_CHANGE
328 || p_vout->p_sys->i_changes & VOUT_SCALE_CHANGE)
330 msg_Dbg( p_vout, "Scale Change" );
331 if( !p_vout->p_sys->b_using_overlay )
332 InvalidateRect( p_vout->p_sys->hwnd, NULL, TRUE );
334 DirectXUpdateOverlay( p_vout );
335 p_vout->i_changes &= ~VOUT_SCALE_CHANGE;
336 p_vout->p_sys->i_changes &= ~VOUT_SCALE_CHANGE;
342 if( p_vout->i_changes & VOUT_SIZE_CHANGE
343 || p_vout->p_sys->i_changes & VOUT_SIZE_CHANGE )
345 msg_Dbg( p_vout, "Size Change" );
346 if( !p_vout->p_sys->b_using_overlay )
347 InvalidateRect( p_vout->p_sys->hwnd, NULL, TRUE );
349 DirectXUpdateOverlay( p_vout );
350 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
351 p_vout->p_sys->i_changes &= ~VOUT_SIZE_CHANGE;
357 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE
358 || p_vout->p_sys->i_changes & VOUT_FULLSCREEN_CHANGE )
360 p_vout->b_fullscreen = ! p_vout->b_fullscreen;
362 /* We need to switch between Maximized and Normal sized window */
363 window_placement.length = sizeof(WINDOWPLACEMENT);
364 GetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
365 if( p_vout->b_fullscreen )
367 /* Maximized window */
368 window_placement.showCmd = SW_SHOWMAXIMIZED;
369 /* Change window style, no borders and no title bar */
370 SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE, 0 );
376 window_placement.showCmd = SW_SHOWNORMAL;
377 /* Change window style, borders and title bar */
378 SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE,
379 WS_OVERLAPPEDWINDOW | WS_SIZEBOX | WS_VISIBLE );
382 SetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
384 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
385 p_vout->p_sys->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
391 if( (!p_vout->p_sys->b_cursor_hidden) &&
392 ( (mdate() - p_vout->p_sys->i_lastmoved) > 5000000 ) )
394 /* Hide the mouse automatically */
395 p_vout->p_sys->b_cursor_hidden = 1;
396 PostMessage( p_vout->p_sys->hwnd, WM_VLC_HIDE_MOUSE, 0, 0 );
399 /* Check if the event thread is still running */
400 if( p_vout->p_sys->p_event->b_die )
406 /*****************************************************************************
407 * Display: displays previously rendered output
408 *****************************************************************************
409 * This function sends the currently rendered image to the display, wait until
410 * it is displayed and switch the two rendering buffers, preparing next frame.
411 *****************************************************************************/
412 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
416 if( (p_vout->p_sys->p_display == NULL) )
418 msg_Warn( p_vout, "no display!!" );
422 if( !p_vout->p_sys->b_using_overlay )
426 /* We ask for the "NOTEARING" option */
427 memset( &ddbltfx, 0, sizeof(DDBLTFX) );
428 ddbltfx.dwSize = sizeof(DDBLTFX);
429 ddbltfx.dwDDFX = DDBLTFX_NOTEARING;
431 /* Blit video surface to display */
432 dxresult = IDirectDrawSurface2_Blt(p_vout->p_sys->p_display,
433 &p_vout->p_sys->rect_dest_clipped,
434 p_pic->p_sys->p_surface,
435 &p_vout->p_sys->rect_src_clipped,
436 DDBLT_ASYNC, &ddbltfx );
437 if ( dxresult == DDERR_SURFACELOST )
439 /* Our surface can be lost so be sure
440 * to check this and restore it if needed */
441 IDirectDrawSurface2_Restore( p_vout->p_sys->p_display );
443 /* Now that the surface has been restored try to display again */
444 dxresult = IDirectDrawSurface2_Blt(p_vout->p_sys->p_display,
445 &p_vout->p_sys->rect_dest_clipped,
446 p_pic->p_sys->p_surface,
447 &p_vout->p_sys->rect_src_clipped,
448 DDBLT_ASYNC, &ddbltfx );
451 if( dxresult != DD_OK )
453 msg_Warn( p_vout, "could not Blit the surface" );
458 else /* using overlay */
461 /* Flip the overlay buffers if we are using back buffers */
462 if( p_pic->p_sys->p_front_surface == p_pic->p_sys->p_surface )
465 dxresult = IDirectDrawSurface2_Flip( p_pic->p_sys->p_front_surface,
467 if ( dxresult == DDERR_SURFACELOST )
469 /* Our surface can be lost so be sure
470 * to check this and restore it if needed */
471 IDirectDrawSurface2_Restore( p_vout->p_sys->p_display );
472 IDirectDrawSurface2_Restore( p_pic->p_sys->p_front_surface );
474 /* Now that the surface has been restored try to display again */
475 dxresult = IDirectDrawSurface2_Flip( p_pic->p_sys->p_front_surface,
477 DirectXUpdateOverlay( p_vout );
480 if( dxresult != DD_OK )
481 msg_Warn( p_vout, "could not flip overlay surface" );
483 if( !DirectXGetSurfaceDesc( p_pic ) )
486 msg_Err( p_vout, "cannot get surface desc" );
490 if( !UpdatePictureStruct( p_vout, p_pic, p_vout->output.i_chroma ) )
493 msg_Err( p_vout, "invalid pic chroma" );
497 /* set currently displayed pic */
498 p_vout->p_sys->p_current_surface = p_pic->p_sys->p_front_surface;
504 /* following functions are local */
506 /*****************************************************************************
507 * DirectXInitDDraw: Takes care of all the DirectDraw initialisations
508 *****************************************************************************
509 * This function initialise and allocate resources for DirectDraw.
510 *****************************************************************************/
511 static int DirectXInitDDraw( vout_thread_t *p_vout )
514 HRESULT (WINAPI *OurDirectDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
515 LPDIRECTDRAW p_ddobject;
517 msg_Dbg( p_vout, "DirectXInitDDraw" );
519 /* load direct draw DLL */
520 p_vout->p_sys->hddraw_dll = LoadLibrary("DDRAW.DLL");
521 if( p_vout->p_sys->hddraw_dll == NULL )
523 msg_Warn( p_vout, "DirectXInitDDraw failed loading ddraw.dll" );
527 OurDirectDrawCreate =
528 (void *)GetProcAddress(p_vout->p_sys->hddraw_dll, "DirectDrawCreate");
529 if ( OurDirectDrawCreate == NULL )
531 msg_Err( p_vout, "DirectXInitDDraw failed GetProcAddress" );
535 /* Initialize DirectDraw now */
536 dxresult = OurDirectDrawCreate( NULL, &p_ddobject, NULL );
537 if( dxresult != DD_OK )
539 msg_Err( p_vout, "DirectXInitDDraw cannot initialize DDraw" );
543 /* Get the IDirectDraw2 interface */
544 dxresult = IDirectDraw_QueryInterface( p_ddobject, &IID_IDirectDraw2,
545 (LPVOID *)&p_vout->p_sys->p_ddobject );
546 /* Release the unused interface */
547 IDirectDraw_Release( p_ddobject );
548 if( dxresult != DD_OK )
550 msg_Err( p_vout, "cannot get IDirectDraw2 interface" );
554 /* Set DirectDraw Cooperative level, ie what control we want over Windows
556 dxresult = IDirectDraw2_SetCooperativeLevel( p_vout->p_sys->p_ddobject,
557 p_vout->p_sys->hwnd, DDSCL_NORMAL );
558 if( dxresult != DD_OK )
560 msg_Err( p_vout, "cannot set direct draw cooperative level" );
564 /* Probe the capabilities of the hardware */
565 DirectXGetDDrawCaps( p_vout );
567 msg_Dbg( p_vout, "End DirectXInitDDraw" );
571 if( p_vout->p_sys->p_ddobject )
572 IDirectDraw2_Release( p_vout->p_sys->p_ddobject );
573 if( p_vout->p_sys->hddraw_dll )
574 FreeLibrary( p_vout->p_sys->hddraw_dll );
575 p_vout->p_sys->hddraw_dll = NULL;
576 p_vout->p_sys->p_ddobject = NULL;
580 /*****************************************************************************
581 * DirectXCreateDisplay: create the DirectDraw display.
582 *****************************************************************************
583 * Create and initialize display according to preferences specified in the vout
585 *****************************************************************************/
586 static int DirectXCreateDisplay( vout_thread_t *p_vout )
590 LPDIRECTDRAWSURFACE p_display;
591 DDPIXELFORMAT pixel_format;
593 msg_Dbg( p_vout, "DirectXCreateDisplay" );
595 /* Now get the primary surface. This surface is what you actually see
597 memset( &ddsd, 0, sizeof( DDSURFACEDESC ));
598 ddsd.dwSize = sizeof(DDSURFACEDESC);
599 ddsd.dwFlags = DDSD_CAPS;
600 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
602 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
605 if( dxresult != DD_OK )
607 msg_Err( p_vout, "cannot get direct draw primary surface" );
611 dxresult = IDirectDrawSurface_QueryInterface( p_display,
612 &IID_IDirectDrawSurface2,
613 (LPVOID *)&p_vout->p_sys->p_display );
614 /* Release the old interface */
615 IDirectDrawSurface_Release( p_display );
616 if ( dxresult != DD_OK )
618 msg_Err( p_vout, "cannot get IDirectDrawSurface2 interface" );
622 /* The clipper will be used only in non-overlay mode */
623 DirectXCreateClipper( p_vout );
627 /* compute the colorkey pixel value from the RGB value we've got */
628 memset( &pixel_format, 0, sizeof( DDPIXELFORMAT ));
629 pixel_format.dwSize = sizeof( DDPIXELFORMAT );
630 dxresult = IDirectDrawSurface2_GetPixelFormat( p_vout->p_sys->p_display,
632 if( dxresult != DD_OK )
633 msg_Warn( p_vout, "DirectXUpdateOverlay GetPixelFormat failed" );
634 p_vout->p_sys->i_colorkey = (DWORD)((( p_vout->p_sys->i_rgb_colorkey
635 * pixel_format.dwRBitMask) / 255)
636 & pixel_format.dwRBitMask);
643 /*****************************************************************************
644 * DirectXCreateClipper: Create a clipper that will be used when blitting the
645 * RGB surface to the main display.
646 *****************************************************************************
647 * This clipper prevents us to modify by mistake anything on the screen
648 * which doesn't belong to our window. For example when a part of our video
649 * window is hidden by another window.
650 *****************************************************************************/
651 static int DirectXCreateClipper( vout_thread_t *p_vout )
655 msg_Dbg( p_vout, "DirectXCreateClipper" );
657 /* Create the clipper */
658 dxresult = IDirectDraw2_CreateClipper( p_vout->p_sys->p_ddobject, 0,
659 &p_vout->p_sys->p_clipper, NULL );
660 if( dxresult != DD_OK )
662 msg_Warn( p_vout, "DirectXCreateClipper cannot create clipper" );
666 /* associate the clipper to the window */
667 dxresult = IDirectDrawClipper_SetHWnd(p_vout->p_sys->p_clipper, 0,
668 p_vout->p_sys->hwnd);
669 if( dxresult != DD_OK )
672 "DirectXCreateClipper cannot attach clipper to window" );
676 /* associate the clipper with the surface */
677 dxresult = IDirectDrawSurface_SetClipper(p_vout->p_sys->p_display,
678 p_vout->p_sys->p_clipper);
679 if( dxresult != DD_OK )
682 "DirectXCreateClipper cannot attach clipper to surface" );
689 if( p_vout->p_sys->p_clipper )
690 IDirectDrawClipper_Release( p_vout->p_sys->p_clipper );
691 p_vout->p_sys->p_clipper = NULL;
696 /*****************************************************************************
697 * DirectXCreateSurface: create an YUV overlay or RGB surface for the video.
698 *****************************************************************************
699 * The best method of display is with an YUV overlay because the YUV->RGB
700 * conversion is done in hardware.
701 * You can also create a plain RGB surface.
702 * ( Maybe we could also try an RGB overlay surface, which could have hardware
703 * scaling and which would also be faster in window mode because you don't
704 * need to do any blitting to the main display...)
705 *****************************************************************************/
706 static int DirectXCreateSurface( vout_thread_t *p_vout,
707 LPDIRECTDRAWSURFACE2 *pp_surface_final,
708 int i_chroma, int b_overlay,
712 LPDIRECTDRAWSURFACE p_surface;
715 /* Create the video surface */
718 /* Now try to create the YUV overlay surface.
719 * This overlay will be displayed on top of the primary surface.
720 * A color key is used to determine whether or not the overlay will be
721 * displayed, ie the overlay will be displayed in place of the primary
722 * surface wherever the primary surface will have this color.
723 * The video window has been created with a background of this color so
724 * the overlay will be only displayed on top of this window */
726 memset( &ddsd, 0, sizeof( DDSURFACEDESC ));
727 ddsd.dwSize = sizeof(DDSURFACEDESC);
728 ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
729 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
730 ddsd.ddpfPixelFormat.dwFourCC = i_chroma;
731 ddsd.dwFlags = DDSD_CAPS |
735 ddsd.dwFlags |= (i_backbuffers ? DDSD_BACKBUFFERCOUNT : 0);
736 ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY |
738 ddsd.ddsCaps.dwCaps |= (i_backbuffers ? DDSCAPS_COMPLEX | DDSCAPS_FLIP
740 ddsd.dwHeight = p_vout->render.i_height;
741 ddsd.dwWidth = p_vout->render.i_width;
742 ddsd.dwBackBufferCount = i_backbuffers;
744 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
747 if( dxresult != DD_OK )
749 *pp_surface_final = NULL;
756 vlc_bool_t b_rgb_surface =
757 ( i_chroma == VLC_FOURCC('R','G','B','2') )
758 || ( i_chroma == VLC_FOURCC('R','V','1','5') )
759 || ( i_chroma == VLC_FOURCC('R','V','1','6') )
760 || ( i_chroma == VLC_FOURCC('R','V','2','4') )
761 || ( i_chroma == VLC_FOURCC('R','V','3','2') );
763 memset( &ddsd, 0, sizeof( DDSURFACEDESC ) );
764 ddsd.dwSize = sizeof(DDSURFACEDESC);
765 ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
766 ddsd.dwFlags = DDSD_HEIGHT |
769 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
770 ddsd.dwHeight = p_vout->render.i_height;
771 ddsd.dwWidth = p_vout->render.i_width;
773 if( p_vout->p_sys->b_use_sysmem )
774 ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
776 ddsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
780 ddsd.dwFlags |= DDSD_PIXELFORMAT;
781 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
782 ddsd.ddpfPixelFormat.dwFourCC = i_chroma;
785 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
788 if( dxresult != DD_OK )
790 *pp_surface_final = NULL;
795 /* Now that the surface is created, try to get a newer DirectX interface */
796 dxresult = IDirectDrawSurface_QueryInterface( p_surface,
797 &IID_IDirectDrawSurface2,
798 (LPVOID *)pp_surface_final );
799 IDirectDrawSurface_Release( p_surface ); /* Release the old interface */
800 if ( dxresult != DD_OK )
802 msg_Err( p_vout, "cannot get IDirectDrawSurface2 interface" );
803 *pp_surface_final = NULL;
810 /*****************************************************************************
811 * DirectXUpdateOverlay: Move or resize overlay surface on video display.
812 *****************************************************************************
813 * This function is used to move or resize an overlay surface on the screen.
814 * Ususally the overlay is moved by the user and thus, by a move or resize
816 *****************************************************************************/
817 void DirectXUpdateOverlay( vout_thread_t *p_vout )
823 if( p_vout->p_sys->p_current_surface == NULL ||
824 !p_vout->p_sys->b_using_overlay )
827 /* The new window dimensions should already have been computed by the
828 * caller of this function */
830 /* Position and show the overlay */
831 memset(&ddofx, 0, sizeof(DDOVERLAYFX));
832 ddofx.dwSize = sizeof(DDOVERLAYFX);
833 ddofx.dckDestColorkey.dwColorSpaceLowValue = p_vout->p_sys->i_colorkey;
834 ddofx.dckDestColorkey.dwColorSpaceHighValue = p_vout->p_sys->i_colorkey;
836 dwFlags = DDOVER_SHOW;
837 if( !p_vout->p_sys->b_caps_overlay_clipping )
838 dwFlags |= DDOVER_KEYDESTOVERRIDE;
840 dxresult = IDirectDrawSurface2_UpdateOverlay(
841 p_vout->p_sys->p_current_surface,
842 &p_vout->p_sys->rect_src_clipped,
843 p_vout->p_sys->p_display,
844 &p_vout->p_sys->rect_dest_clipped,
847 if(dxresult != DD_OK)
850 "DirectXUpdateOverlay cannot move or resize overlay" );
855 /*****************************************************************************
856 * DirectXCloseDDraw: Release the DDraw object allocated by DirectXInitDDraw
857 *****************************************************************************
858 * This function returns all resources allocated by DirectXInitDDraw.
859 *****************************************************************************/
860 static void DirectXCloseDDraw( vout_thread_t *p_vout )
862 msg_Dbg( p_vout, "DirectXCloseDDraw" );
863 if( p_vout->p_sys->p_ddobject != NULL )
865 IDirectDraw2_Release(p_vout->p_sys->p_ddobject);
866 p_vout->p_sys->p_ddobject = NULL;
869 if( p_vout->p_sys->hddraw_dll != NULL )
871 FreeLibrary( p_vout->p_sys->hddraw_dll );
872 p_vout->p_sys->hddraw_dll = NULL;
876 /*****************************************************************************
877 * DirectXCloseDisplay: close and reset the DirectX display device
878 *****************************************************************************
879 * This function returns all resources allocated by DirectXCreateDisplay.
880 *****************************************************************************/
881 static void DirectXCloseDisplay( vout_thread_t *p_vout )
883 msg_Dbg( p_vout, "DirectXCloseDisplay" );
885 if( p_vout->p_sys->p_clipper != NULL )
887 msg_Dbg( p_vout, "DirectXCloseDisplay clipper" );
888 IDirectDrawClipper_Release( p_vout->p_sys->p_clipper );
889 p_vout->p_sys->p_clipper = NULL;
892 if( p_vout->p_sys->p_display != NULL )
894 msg_Dbg( p_vout, "DirectXCloseDisplay display" );
895 IDirectDrawSurface2_Release( p_vout->p_sys->p_display );
896 p_vout->p_sys->p_display = NULL;
900 /*****************************************************************************
901 * DirectXCloseSurface: close the YUV overlay or RGB surface.
902 *****************************************************************************
903 * This function returns all resources allocated for the surface.
904 *****************************************************************************/
905 static void DirectXCloseSurface( vout_thread_t *p_vout,
906 LPDIRECTDRAWSURFACE2 p_surface )
908 msg_Dbg( p_vout, "DirectXCloseSurface" );
909 if( p_surface != NULL )
911 IDirectDrawSurface2_Release( p_surface );
915 /*****************************************************************************
916 * NewPictureVec: allocate a vector of identical pictures
917 *****************************************************************************
918 * Returns 0 on success, -1 otherwise
919 *****************************************************************************/
920 static int NewPictureVec( vout_thread_t *p_vout, picture_t *p_pic,
924 vlc_bool_t b_result_ok;
925 LPDIRECTDRAWSURFACE2 p_surface;
927 msg_Dbg( p_vout, "NewPictureVec" );
929 I_OUTPUTPICTURES = 0;
931 /* First we try to use an YUV overlay surface.
932 * The overlay surface that we create won't be used to decode directly
933 * into it because accessing video memory directly is way to slow (remember
934 * that pictures are decoded macroblock per macroblock). Instead the video
935 * will be decoded in picture buffers in system memory which will then be
936 * memcpy() to the overlay surface. */
937 if( p_vout->p_sys->b_using_overlay )
939 /* Triple buffering rocks! it doesn't have any processing overhead
940 * (you don't have to wait for the vsync) and provides for a very nice
941 * video quality (no tearing). */
943 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
944 p_vout->output.i_chroma,
945 p_vout->p_sys->b_using_overlay,
946 2 /* number of backbuffers */ );
949 /* Try to reduce the number of backbuffers */
950 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
951 p_vout->output.i_chroma,
952 p_vout->p_sys->b_using_overlay,
953 0 /* number of backbuffers */);
959 picture_sys_t front_pic_sys;
960 front_pic.p_sys = &front_pic_sys;
962 /* Allocate internal structure */
963 p_pic[0].p_sys = malloc( sizeof( picture_sys_t ) );
964 if( p_pic[0].p_sys == NULL )
966 DirectXCloseSurface( p_vout, p_surface );
970 /* set front buffer */
971 p_pic[0].p_sys->p_front_surface = p_surface;
973 /* Get the back buffer */
974 memset( &dds_caps, 0, sizeof( DDSCAPS ) );
975 dds_caps.dwCaps = DDSCAPS_BACKBUFFER;
976 if( DD_OK != IDirectDrawSurface2_GetAttachedSurface(
977 p_surface, &dds_caps,
978 &p_pic[0].p_sys->p_surface ) )
980 msg_Warn( p_vout, "NewPictureVec could not get back buffer" );
981 /* front buffer is the same as back buffer */
982 p_pic[0].p_sys->p_surface = p_surface;
986 p_vout->p_sys->p_current_surface = front_pic.p_sys->p_surface =
987 p_pic[0].p_sys->p_front_surface;
989 /* reset the front buffer memory */
990 if( DirectXGetSurfaceDesc( &front_pic ) &&
991 UpdatePictureStruct( p_vout, &front_pic,
992 p_vout->output.i_chroma ) )
995 for( i = 0; i < front_pic.i_planes; i++ )
996 for( j = 0; j < front_pic.p[i].i_lines; j++)
997 memset( front_pic.p[i].p_pixels + j *
998 front_pic.p[i].i_pitch, 127,
999 front_pic.p[i].i_visible_pitch );
1002 DirectXUpdateOverlay( p_vout );
1003 I_OUTPUTPICTURES = 1;
1004 msg_Dbg( p_vout, "DirectX YUV overlay created successfully" );
1008 /* As we can't have an overlay, we'll try to create a plain offscreen
1009 * surface. This surface will reside in video memory because there's a
1010 * better chance then that we'll be able to use some kind of hardware
1011 * acceleration like rescaling, blitting or YUV->RGB conversions.
1012 * We then only need to blit this surface onto the main display when we
1013 * want to display it */
1014 if( !p_vout->p_sys->b_using_overlay )
1017 if( p_vout->p_sys->b_hw_yuv )
1018 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
1019 p_vout->output.i_chroma,
1020 p_vout->p_sys->b_using_overlay,
1021 0 /* no back buffers */ );
1023 if( !p_vout->p_sys->b_hw_yuv || !b_result_ok )
1025 /* Our last choice is to use a plain RGB surface */
1026 DDPIXELFORMAT ddpfPixelFormat;
1028 ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
1029 IDirectDrawSurface2_GetPixelFormat( p_vout->p_sys->p_display,
1032 if( ddpfPixelFormat.dwFlags & DDPF_RGB )
1034 switch( ddpfPixelFormat.dwRGBBitCount )
1036 case 8: /* FIXME: set the palette */
1037 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
1040 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
1043 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
1046 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
1049 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
1052 msg_Err( p_vout, "unknown screen depth" );
1055 p_vout->output.i_rmask = ddpfPixelFormat.dwRBitMask;
1056 p_vout->output.i_gmask = ddpfPixelFormat.dwGBitMask;
1057 p_vout->output.i_bmask = ddpfPixelFormat.dwBBitMask;
1060 p_vout->p_sys->b_hw_yuv = 0;
1062 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
1063 p_vout->output.i_chroma,
1064 p_vout->p_sys->b_using_overlay,
1065 0 /* no back buffers */ );
1070 /* Allocate internal structure */
1071 p_pic[0].p_sys = malloc( sizeof( picture_sys_t ) );
1072 if( p_pic[0].p_sys == NULL )
1074 DirectXCloseSurface( p_vout, p_surface );
1077 p_pic[0].p_sys->p_surface = p_pic[0].p_sys->p_front_surface
1080 I_OUTPUTPICTURES = 1;
1082 msg_Dbg( p_vout, "DirectX plain surface created successfully" );
1087 /* Now that we've got all our direct-buffers, we can finish filling in the
1088 * picture_t structures */
1089 for( i = 0; i < I_OUTPUTPICTURES; i++ )
1091 p_pic[i].i_status = DESTROYED_PICTURE;
1092 p_pic[i].i_type = DIRECT_PICTURE;
1093 PP_OUTPUTPICTURE[i] = &p_pic[i];
1095 if( !DirectXGetSurfaceDesc( &p_pic[i] ) )
1098 FreePictureVec( p_vout, p_pic, I_OUTPUTPICTURES );
1099 I_OUTPUTPICTURES = 0;
1103 if( !UpdatePictureStruct(p_vout, &p_pic[i], p_vout->output.i_chroma) )
1106 /* Unknown chroma, tell the guy to get lost */
1107 msg_Err( p_vout, "never heard of chroma 0x%.8x (%4.4s)",
1108 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma );
1109 FreePictureVec( p_vout, p_pic, I_OUTPUTPICTURES );
1110 I_OUTPUTPICTURES = 0;
1115 msg_Dbg( p_vout, "End NewPictureVec");
1119 /*****************************************************************************
1120 * FreePicture: destroy a picture vector allocated with NewPictureVec
1121 *****************************************************************************
1123 *****************************************************************************/
1124 static void FreePictureVec( vout_thread_t *p_vout, picture_t *p_pic,
1129 for( i = 0; i < i_num_pics; i++ )
1131 DirectXCloseSurface( p_vout, p_pic[i].p_sys->p_front_surface );
1133 for( i = 0; i < i_num_pics; i++ )
1135 free( p_pic[i].p_sys );
1140 /*****************************************************************************
1141 * UpdatePictureStruct: updates the internal data in the picture_t structure
1142 *****************************************************************************
1143 * This will setup stuff for use by the video_output thread
1144 *****************************************************************************/
1145 static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
1149 switch( p_vout->output.i_chroma )
1151 case VLC_FOURCC('R','G','B','2'):
1152 case VLC_FOURCC('R','V','1','5'):
1153 case VLC_FOURCC('R','V','1','6'):
1154 case VLC_FOURCC('R','V','2','4'):
1155 case VLC_FOURCC('R','V','3','2'):
1156 p_pic->p->p_pixels = p_pic->p_sys->ddsd.lpSurface;
1157 p_pic->p->i_lines = p_vout->output.i_height;
1158 p_pic->p->i_pitch = p_pic->p_sys->ddsd.lPitch;
1159 switch( p_vout->output.i_chroma )
1161 case VLC_FOURCC('R','G','B','2'):
1162 p_pic->p->i_pixel_pitch = 1;
1164 case VLC_FOURCC('R','V','1','5'):
1165 case VLC_FOURCC('R','V','1','6'):
1166 p_pic->p->i_pixel_pitch = 2;
1168 case VLC_FOURCC('R','V','2','4'):
1169 case VLC_FOURCC('R','V','3','2'):
1170 p_pic->p->i_pixel_pitch = 4;
1175 p_pic->p->i_visible_pitch = p_vout->output.i_width *
1176 p_pic->p->i_pixel_pitch;
1177 p_pic->i_planes = 1;
1180 case VLC_FOURCC('Y','V','1','2'):
1182 p_pic->Y_PIXELS = p_pic->p_sys->ddsd.lpSurface;
1183 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1184 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->ddsd.lPitch;
1185 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
1186 p_pic->p[Y_PLANE].i_visible_pitch = p_vout->output.i_width *
1187 p_pic->p[Y_PLANE].i_pixel_pitch;
1189 p_pic->V_PIXELS = p_pic->Y_PIXELS
1190 + p_pic->p[Y_PLANE].i_lines * p_pic->p[Y_PLANE].i_pitch;
1191 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1192 p_pic->p[V_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1193 p_pic->p[V_PLANE].i_pixel_pitch = 1;
1194 p_pic->p[V_PLANE].i_visible_pitch = p_vout->output.i_width *
1195 p_pic->p[V_PLANE].i_pixel_pitch;
1197 p_pic->U_PIXELS = p_pic->V_PIXELS
1198 + p_pic->p[V_PLANE].i_lines * p_pic->p[V_PLANE].i_pitch;
1199 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1200 p_pic->p[U_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1201 p_pic->p[U_PLANE].i_pixel_pitch = 1;
1202 p_pic->p[U_PLANE].i_visible_pitch = p_vout->output.i_width *
1203 p_pic->p[U_PLANE].i_pixel_pitch;
1205 p_pic->i_planes = 3;
1208 case VLC_FOURCC('I','Y','U','V'):
1210 p_pic->Y_PIXELS = p_pic->p_sys->ddsd.lpSurface;
1211 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1212 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->ddsd.lPitch;
1213 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
1214 p_pic->p[Y_PLANE].i_visible_pitch = p_vout->output.i_width *
1215 p_pic->p[Y_PLANE].i_pixel_pitch;
1217 p_pic->U_PIXELS = p_pic->Y_PIXELS
1218 + p_pic->p[Y_PLANE].i_lines * p_pic->p[Y_PLANE].i_pitch;
1219 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1220 p_pic->p[U_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1221 p_pic->p[U_PLANE].i_pixel_pitch = 1;
1222 p_pic->p[U_PLANE].i_visible_pitch = p_vout->output.i_width *
1223 p_pic->p[U_PLANE].i_pixel_pitch;
1225 p_pic->V_PIXELS = p_pic->U_PIXELS
1226 + p_pic->p[U_PLANE].i_lines * p_pic->p[U_PLANE].i_pitch;
1227 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1228 p_pic->p[V_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1229 p_pic->p[V_PLANE].i_pixel_pitch = 1;
1230 p_pic->p[V_PLANE].i_visible_pitch = p_vout->output.i_width *
1231 p_pic->p[V_PLANE].i_pixel_pitch;
1233 p_pic->i_planes = 3;
1236 case VLC_FOURCC('Y','U','Y','2'):
1238 p_pic->p->p_pixels = p_pic->p_sys->ddsd.lpSurface;
1239 p_pic->p->i_lines = p_vout->output.i_height;
1240 p_pic->p->i_pitch = p_pic->p_sys->ddsd.lPitch;
1241 p_pic->p->i_pixel_pitch = 2;
1242 p_pic->p->i_visible_pitch = p_vout->output.i_width *
1243 p_pic->p->i_pixel_pitch;
1245 p_pic->i_planes = 1;
1257 /*****************************************************************************
1258 * DirectXGetDDrawCaps: Probe the capabilities of the hardware
1259 *****************************************************************************
1260 * It is nice to know which features are supported by the hardware so we can
1261 * find ways to optimize our rendering.
1262 *****************************************************************************/
1263 static void DirectXGetDDrawCaps( vout_thread_t *p_vout )
1268 /* This is just an indication of whether or not we'll support overlay,
1269 * but with this test we don't know if we support YUV overlay */
1270 memset( &ddcaps, 0, sizeof( DDCAPS ));
1271 ddcaps.dwSize = sizeof(DDCAPS);
1272 dxresult = IDirectDraw2_GetCaps( p_vout->p_sys->p_ddobject,
1274 if(dxresult != DD_OK )
1276 msg_Warn( p_vout, "cannot get caps" );
1280 BOOL bHasOverlay, bHasOverlayFourCC, bCanClipOverlay,
1281 bHasColorKey, bCanStretch;
1283 /* Determine if the hardware supports overlay surfaces */
1284 bHasOverlay = ((ddcaps.dwCaps & DDCAPS_OVERLAY) ==
1285 DDCAPS_OVERLAY) ? TRUE : FALSE;
1286 /* Determine if the hardware supports overlay surfaces */
1287 bHasOverlayFourCC = ((ddcaps.dwCaps & DDCAPS_OVERLAYFOURCC) ==
1288 DDCAPS_OVERLAYFOURCC) ? TRUE : FALSE;
1289 /* Determine if the hardware supports overlay surfaces */
1290 bCanClipOverlay = ((ddcaps.dwCaps & DDCAPS_OVERLAYCANTCLIP) ==
1292 /* Determine if the hardware supports colorkeying */
1293 bHasColorKey = ((ddcaps.dwCaps & DDCAPS_COLORKEY) ==
1294 DDCAPS_COLORKEY) ? TRUE : FALSE;
1295 /* Determine if the hardware supports scaling of the overlay surface */
1296 bCanStretch = ((ddcaps.dwCaps & DDCAPS_OVERLAYSTRETCH) ==
1297 DDCAPS_OVERLAYSTRETCH) ? TRUE : FALSE;
1298 msg_Dbg( p_vout, "DirectDraw Capabilities: overlay=%i yuvoverlay=%i "
1299 "can_clip_overlay=%i colorkey=%i stretch=%i",
1300 bHasOverlay, bHasOverlayFourCC, bCanClipOverlay,
1301 bHasColorKey, bCanStretch );
1303 /* Overlay clipping support is interesting for us as it means we can
1304 * get rid of the colorkey alltogether */
1305 p_vout->p_sys->b_caps_overlay_clipping = bCanClipOverlay;
1310 /*****************************************************************************
1311 * DirectXGetSurfaceDesc: Get some more information about the surface
1312 *****************************************************************************
1313 * This function get and stores the surface descriptor which among things
1314 * has the pointer to the picture data.
1315 *****************************************************************************/
1316 static int DirectXGetSurfaceDesc( picture_t *p_pic )
1320 /* Lock the surface to get a valid pointer to the picture buffer */
1321 memset( &p_pic->p_sys->ddsd, 0, sizeof( DDSURFACEDESC ));
1322 p_pic->p_sys->ddsd.dwSize = sizeof(DDSURFACEDESC);
1323 dxresult = IDirectDrawSurface2_Lock( p_pic->p_sys->p_surface,
1324 NULL, &p_pic->p_sys->ddsd,
1325 DDLOCK_NOSYSLOCK | DDLOCK_WAIT,
1327 if ( dxresult == DDERR_SURFACELOST )
1329 /* Your surface can be lost so be sure
1330 * to check this and restore it if needed */
1331 dxresult = IDirectDrawSurface2_Restore( p_pic->p_sys->p_surface );
1332 dxresult = IDirectDrawSurface2_Lock( p_pic->p_sys->p_surface, NULL,
1333 &p_pic->p_sys->ddsd,
1334 DDLOCK_NOSYSLOCK | DDLOCK_WAIT,
1337 if( dxresult != DD_OK )
1339 //X msg_Err( p_vout, "DirectXGetSurfaceDesc cannot lock surface" );
1343 /* Unlock the Surface */
1344 dxresult = IDirectDrawSurface2_Unlock( p_pic->p_sys->p_surface, NULL );