1 /*****************************************************************************
2 * vout.c: Windows DirectX video output display method
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: directx.c,v 1.3 2002/10/06 19:28:28 gbazin 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() */
52 /*****************************************************************************
54 * Defining them here allows us to get rid of the dxguid library during
56 *****************************************************************************/
58 DEFINE_GUID( IID_IDirectDraw2, 0xB3A6F3E0,0x2B43,0x11CF,0xA2,0xDE,0x00,0xAA,0x00,0xB9,0x33,0x56 );
59 DEFINE_GUID( IID_IDirectDrawSurface2, 0x57805885,0x6eec,0x11cf,0x94,0x41,0xa8,0x23,0x03,0xc1,0x0e,0x27 );
61 /*****************************************************************************
63 *****************************************************************************/
64 static int OpenVideo ( vlc_object_t * );
65 static void CloseVideo ( vlc_object_t * );
67 static int Init ( vout_thread_t * );
68 static void End ( vout_thread_t * );
69 static int Manage ( vout_thread_t * );
70 static void Display ( vout_thread_t *, picture_t * );
72 static int NewPictureVec ( vout_thread_t *, picture_t *, int );
73 static void FreePictureVec ( vout_thread_t *, picture_t *, int );
74 static int UpdatePictureStruct( vout_thread_t *, picture_t *, int );
76 static int DirectXInitDDraw ( vout_thread_t *p_vout );
77 static void DirectXCloseDDraw ( vout_thread_t *p_vout );
78 static int DirectXCreateDisplay ( vout_thread_t *p_vout );
79 static void DirectXCloseDisplay ( vout_thread_t *p_vout );
80 static int DirectXCreateSurface ( vout_thread_t *p_vout,
81 LPDIRECTDRAWSURFACE2 *, int, int, int );
82 static void DirectXCloseSurface ( vout_thread_t *p_vout,
83 LPDIRECTDRAWSURFACE2 );
84 static int DirectXCreateClipper ( vout_thread_t *p_vout );
85 static void DirectXGetDDrawCaps ( vout_thread_t *p_vout );
86 static int DirectXGetSurfaceDesc ( picture_t *p_pic );
88 /*****************************************************************************
90 *****************************************************************************/
91 #define HW_YUV_TEXT N_("use hardware YUV->RGB conversions")
92 #define HW_YUV_LONGTEXT N_( \
93 "Try to use hardware acceleration for YUV->RGB conversions. " \
94 "This option doesn't have any effect when using overlays." )
95 #define SYSMEM_TEXT N_("use video buffers in system memory")
96 #define SYSMEM_LONGTEXT N_( \
97 "Create video buffers in system memory instead of video memory. This " \
98 "isn't recommended as usually using video memory allows to benefit from " \
99 "more hardware acceleration (like rescaling or YUV->RGB conversions). " \
100 "This option doesn't have any effect when using overlays." )
103 add_category_hint( N_("Video"), NULL );
104 add_bool( "directx-hw-yuv", 1, NULL, HW_YUV_TEXT, HW_YUV_LONGTEXT );
105 add_bool( "directx-use-sysmem", 0, NULL, SYSMEM_TEXT, SYSMEM_LONGTEXT );
106 set_description( _("DirectX video module") );
107 set_capability( "video output", 100 );
108 set_callbacks( OpenVideo, CloseVideo );
112 /* check if we registered a window class because we need to
115 if( GetClassInfo( GetModuleHandle(NULL), "VLC DirectX", &wndclass ) )
116 UnregisterClass( "VLC DirectX", GetModuleHandle(NULL) );
119 /*****************************************************************************
120 * OpenVideo: allocate DirectX video thread output method
121 *****************************************************************************
122 * This function allocates and initialize the DirectX vout method.
123 *****************************************************************************/
124 static int OpenVideo( vlc_object_t *p_this )
126 vout_thread_t * p_vout = (vout_thread_t *)p_this;
128 /* Allocate structure */
129 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
130 if( p_vout->p_sys == NULL )
132 msg_Err( p_vout, "out of memory" );
136 /* Initialisations */
137 p_vout->pf_init = Init;
138 p_vout->pf_end = End;
139 p_vout->pf_manage = Manage;
140 p_vout->pf_render = NULL;
141 p_vout->pf_display = Display;
143 p_vout->p_sys->p_ddobject = NULL;
144 p_vout->p_sys->p_display = NULL;
145 p_vout->p_sys->p_current_surface = NULL;
146 p_vout->p_sys->p_clipper = NULL;
147 p_vout->p_sys->hbrush = NULL;
148 p_vout->p_sys->hwnd = NULL;
149 p_vout->p_sys->i_changes = 0;
150 p_vout->p_sys->b_caps_overlay_clipping = 0;
151 SetRectEmpty( &p_vout->p_sys->rect_display );
152 p_vout->p_sys->b_using_overlay = config_GetInt( p_vout, "overlay" );
153 p_vout->p_sys->b_use_sysmem = config_GetInt( p_vout, "directx-use-sysmem");
154 p_vout->p_sys->b_hw_yuv = config_GetInt( p_vout, "directx-hw-yuv" );
156 p_vout->p_sys->b_cursor_hidden = 0;
157 p_vout->p_sys->i_lastmoved = mdate();
159 /* Set main window's size */
160 p_vout->p_sys->i_window_width = p_vout->i_window_width;
161 p_vout->p_sys->i_window_height = p_vout->i_window_height;
163 /* Create the DirectXEventThread, this thread is created by us to isolate
164 * the Win32 PeekMessage function calls. We want to do this because
165 * Windows can stay blocked inside this call for a long time, and when
166 * this happens it thus blocks vlc's video_output thread.
167 * DirectXEventThread will take care of the creation of the video
168 * window (because PeekMessage has to be called from the same thread which
169 * created the window). */
170 msg_Dbg( p_vout, "creating DirectXEventThread" );
171 p_vout->p_sys->p_event =
172 vlc_object_create( p_vout, sizeof(event_thread_t) );
173 p_vout->p_sys->p_event->p_vout = p_vout;
174 if( vlc_thread_create( p_vout->p_sys->p_event,
175 "DirectX Events Thread", DirectXEventThread,
176 VLC_THREAD_PRIORITY_LOW, 1 ) )
178 msg_Err( p_vout, "cannot create DirectXEventThread" );
179 vlc_object_destroy( p_vout->p_sys->p_event );
180 p_vout->p_sys->p_event = NULL;
184 if( p_vout->p_sys->p_event->b_error )
186 msg_Err( p_vout, "DirectXEventThread failed" );
190 vlc_object_attach( p_vout->p_sys->p_event, p_vout );
192 msg_Dbg( p_vout, "DirectXEventThread running" );
194 /* Initialise DirectDraw */
195 if( DirectXInitDDraw( p_vout ) )
197 msg_Err( p_vout, "cannot initialize DirectDraw" );
201 /* Create the directx display */
202 if( DirectXCreateDisplay( p_vout ) )
204 msg_Err( p_vout, "cannot initialize DirectDraw" );
211 CloseVideo( VLC_OBJECT(p_vout) );
216 /*****************************************************************************
217 * Init: initialize DirectX video thread output method
218 *****************************************************************************
219 * This function create the directx surfaces needed by the output thread.
220 * It is called at the beginning of the thread.
221 *****************************************************************************/
222 static int Init( vout_thread_t *p_vout )
226 /* Initialize the output structure.
227 * Since DirectDraw can do rescaling for us, stick to the default
228 * coordinates and aspect. */
229 p_vout->output.i_width = p_vout->render.i_width;
230 p_vout->output.i_height = p_vout->render.i_height;
231 p_vout->output.i_aspect = p_vout->render.i_aspect;
233 #define MAX_DIRECTBUFFERS 1
234 /* Right now we use only 1 directbuffer because we don't want the
235 * video decoder to decode directly into direct buffers as they are
236 * created into video memory and video memory is _really_ slow */
238 /* Choose the chroma we will try first. */
239 switch( p_vout->render.i_chroma )
241 case VLC_FOURCC('Y','U','Y','2'):
242 case VLC_FOURCC('Y','U','N','V'):
243 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
245 case VLC_FOURCC('U','Y','V','Y'):
246 case VLC_FOURCC('U','Y','N','V'):
247 case VLC_FOURCC('Y','4','2','2'):
248 p_vout->output.i_chroma = VLC_FOURCC('U','Y','V','Y');
250 case VLC_FOURCC('Y','V','Y','U'):
251 p_vout->output.i_chroma = VLC_FOURCC('Y','V','Y','U');
254 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
258 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
260 i_chroma_backup = p_vout->output.i_chroma;
262 if( !I_OUTPUTPICTURES )
264 /* hmmm, it didn't work! Let's try commonly supported chromas */
265 p_vout->output.i_chroma = VLC_FOURCC('Y','V','1','2');
266 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
267 if( !I_OUTPUTPICTURES )
269 /* hmmm, it didn't work! Let's try commonly supported chromas */
270 p_vout->output.i_chroma = VLC_FOURCC('Y','U','Y','2');
271 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
275 if( !I_OUTPUTPICTURES )
277 /* If it still didn't work then don't try to use an overlay */
278 p_vout->output.i_chroma = i_chroma_backup;
279 p_vout->p_sys->b_using_overlay = 0;
280 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
283 /* Change the window title bar text */
284 if( p_vout->p_sys->b_using_overlay )
285 SetWindowText( p_vout->p_sys->hwnd,
286 VOUT_TITLE " (hardware YUV overlay DirectX output)" );
287 else if( p_vout->p_sys->b_hw_yuv )
288 SetWindowText( p_vout->p_sys->hwnd,
289 VOUT_TITLE " (hardware YUV DirectX output)" );
290 else SetWindowText( p_vout->p_sys->hwnd,
291 VOUT_TITLE " (software RGB DirectX output)" );
296 /*****************************************************************************
297 * End: terminate Sys video thread output method
298 *****************************************************************************
299 * Terminate an output method created by Create.
300 * It is called at the end of the thread.
301 *****************************************************************************/
302 static void End( vout_thread_t *p_vout )
304 FreePictureVec( p_vout, p_vout->p_picture, I_OUTPUTPICTURES );
308 /*****************************************************************************
309 * CloseVideo: destroy Sys video thread output method
310 *****************************************************************************
311 * Terminate an output method created by Create
312 *****************************************************************************/
313 static void CloseVideo( vlc_object_t *p_this )
315 vout_thread_t * p_vout = (vout_thread_t *)p_this;
317 msg_Dbg( p_vout, "CloseVideo" );
319 DirectXCloseDisplay( p_vout );
320 DirectXCloseDDraw( p_vout );
322 if( p_vout->p_sys->p_event )
324 vlc_object_detach( p_vout->p_sys->p_event );
326 /* Kill DirectXEventThread */
327 p_vout->p_sys->p_event->b_die = 1;
329 /* we need to be sure DirectXEventThread won't stay stuck in
330 * GetMessage, so we send a fake message */
331 if( p_vout->p_sys->hwnd )
332 PostMessage( p_vout->p_sys->hwnd, WM_NULL, 0, 0);
334 vlc_thread_join( p_vout->p_sys->p_event );
335 vlc_object_destroy( p_vout->p_sys->p_event );
340 free( p_vout->p_sys );
341 p_vout->p_sys = NULL;
345 /*****************************************************************************
346 * Manage: handle Sys events
347 *****************************************************************************
348 * This function should be called regularly by the video output thread.
349 * It returns a non null value if an error occured.
350 *****************************************************************************/
351 static int Manage( vout_thread_t *p_vout )
353 WINDOWPLACEMENT window_placement;
355 /* We used to call the Win32 PeekMessage function here to read the window
356 * messages. But since window can stay blocked into this function for a
357 * long time (for example when you move your window on the screen), I
358 * decided to isolate PeekMessage in another thread. */
363 if( p_vout->i_changes & VOUT_SCALE_CHANGE
364 || p_vout->p_sys->i_changes & VOUT_SCALE_CHANGE)
366 msg_Dbg( p_vout, "Scale Change" );
367 if( !p_vout->p_sys->b_using_overlay )
368 InvalidateRect( p_vout->p_sys->hwnd, NULL, TRUE );
370 DirectXUpdateOverlay( p_vout );
371 p_vout->i_changes &= ~VOUT_SCALE_CHANGE;
372 p_vout->p_sys->i_changes &= ~VOUT_SCALE_CHANGE;
378 if( p_vout->i_changes & VOUT_SIZE_CHANGE
379 || p_vout->p_sys->i_changes & VOUT_SIZE_CHANGE )
381 msg_Dbg( p_vout, "Size Change" );
382 if( !p_vout->p_sys->b_using_overlay )
383 InvalidateRect( p_vout->p_sys->hwnd, NULL, TRUE );
385 DirectXUpdateOverlay( p_vout );
386 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
387 p_vout->p_sys->i_changes &= ~VOUT_SIZE_CHANGE;
393 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE
394 || p_vout->p_sys->i_changes & VOUT_FULLSCREEN_CHANGE )
396 p_vout->b_fullscreen = ! p_vout->b_fullscreen;
398 /* We need to switch between Maximized and Normal sized window */
399 window_placement.length = sizeof(WINDOWPLACEMENT);
400 GetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
401 if( p_vout->b_fullscreen )
403 /* Maximized window */
404 window_placement.showCmd = SW_SHOWMAXIMIZED;
405 /* Change window style, no borders and no title bar */
406 SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE, 0 );
412 window_placement.showCmd = SW_SHOWNORMAL;
413 /* Change window style, borders and title bar */
414 SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE,
415 WS_OVERLAPPEDWINDOW | WS_SIZEBOX | WS_VISIBLE );
418 SetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
420 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
421 p_vout->p_sys->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
427 if( (!p_vout->p_sys->b_cursor_hidden) &&
428 ( (mdate() - p_vout->p_sys->i_lastmoved) > 5000000 ) )
430 /* Hide the mouse automatically */
431 p_vout->p_sys->b_cursor_hidden = 1;
432 PostMessage( p_vout->p_sys->hwnd, WM_VLC_HIDE_MOUSE, 0, 0 );
435 /* Check if the event thread is still running */
436 if( p_vout->p_sys->p_event->b_die )
442 /*****************************************************************************
443 * Display: displays previously rendered output
444 *****************************************************************************
445 * This function sends the currently rendered image to the display, wait until
446 * it is displayed and switch the two rendering buffers, preparing next frame.
447 *****************************************************************************/
448 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
452 if( (p_vout->p_sys->p_display == NULL) )
454 msg_Warn( p_vout, "no display!!" );
458 if( !p_vout->p_sys->b_using_overlay )
462 /* We ask for the "NOTEARING" option */
463 memset( &ddbltfx, 0, sizeof(DDBLTFX) );
464 ddbltfx.dwSize = sizeof(DDBLTFX);
465 ddbltfx.dwDDFX = DDBLTFX_NOTEARING;
467 /* Blit video surface to display */
468 dxresult = IDirectDrawSurface2_Blt(p_vout->p_sys->p_display,
469 &p_vout->p_sys->rect_dest_clipped,
470 p_pic->p_sys->p_surface,
471 &p_vout->p_sys->rect_src_clipped,
472 DDBLT_ASYNC, &ddbltfx );
473 if ( dxresult == DDERR_SURFACELOST )
475 /* Our surface can be lost so be sure
476 * to check this and restore it if needed */
477 IDirectDrawSurface2_Restore( p_vout->p_sys->p_display );
479 /* Now that the surface has been restored try to display again */
480 dxresult = IDirectDrawSurface2_Blt(p_vout->p_sys->p_display,
481 &p_vout->p_sys->rect_dest_clipped,
482 p_pic->p_sys->p_surface,
483 &p_vout->p_sys->rect_src_clipped,
484 DDBLT_ASYNC, &ddbltfx );
487 if( dxresult != DD_OK )
489 msg_Warn( p_vout, "could not Blit the surface" );
494 else /* using overlay */
497 /* Flip the overlay buffers if we are using back buffers */
498 if( p_pic->p_sys->p_front_surface == p_pic->p_sys->p_surface )
501 dxresult = IDirectDrawSurface2_Flip( p_pic->p_sys->p_front_surface,
503 if ( dxresult == DDERR_SURFACELOST )
505 /* Our surface can be lost so be sure
506 * to check this and restore it if needed */
507 IDirectDrawSurface2_Restore( p_vout->p_sys->p_display );
508 IDirectDrawSurface2_Restore( p_pic->p_sys->p_front_surface );
510 /* Now that the surface has been restored try to display again */
511 dxresult = IDirectDrawSurface2_Flip( p_pic->p_sys->p_front_surface,
513 DirectXUpdateOverlay( p_vout );
516 if( dxresult != DD_OK )
517 msg_Warn( p_vout, "could not flip overlay surface" );
519 if( !DirectXGetSurfaceDesc( p_pic ) )
522 msg_Err( p_vout, "cannot get surface desc" );
526 if( !UpdatePictureStruct( p_vout, p_pic, p_vout->output.i_chroma ) )
529 msg_Err( p_vout, "invalid pic chroma" );
533 /* set currently displayed pic */
534 p_vout->p_sys->p_current_surface = p_pic->p_sys->p_front_surface;
540 /* following functions are local */
542 /*****************************************************************************
543 * DirectXInitDDraw: Takes care of all the DirectDraw initialisations
544 *****************************************************************************
545 * This function initialise and allocate resources for DirectDraw.
546 *****************************************************************************/
547 static int DirectXInitDDraw( vout_thread_t *p_vout )
550 HRESULT (WINAPI *OurDirectDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
551 LPDIRECTDRAW p_ddobject;
553 msg_Dbg( p_vout, "DirectXInitDDraw" );
555 /* load direct draw DLL */
556 p_vout->p_sys->hddraw_dll = LoadLibrary("DDRAW.DLL");
557 if( p_vout->p_sys->hddraw_dll == NULL )
559 msg_Warn( p_vout, "DirectXInitDDraw failed loading ddraw.dll" );
563 OurDirectDrawCreate =
564 (void *)GetProcAddress(p_vout->p_sys->hddraw_dll, "DirectDrawCreate");
565 if ( OurDirectDrawCreate == NULL )
567 msg_Err( p_vout, "DirectXInitDDraw failed GetProcAddress" );
571 /* Initialize DirectDraw now */
572 dxresult = OurDirectDrawCreate( NULL, &p_ddobject, NULL );
573 if( dxresult != DD_OK )
575 msg_Err( p_vout, "DirectXInitDDraw cannot initialize DDraw" );
579 /* Get the IDirectDraw2 interface */
580 dxresult = IDirectDraw_QueryInterface( p_ddobject, &IID_IDirectDraw2,
581 (LPVOID *)&p_vout->p_sys->p_ddobject );
582 /* Release the unused interface */
583 IDirectDraw_Release( p_ddobject );
584 if( dxresult != DD_OK )
586 msg_Err( p_vout, "cannot get IDirectDraw2 interface" );
590 /* Set DirectDraw Cooperative level, ie what control we want over Windows
592 dxresult = IDirectDraw2_SetCooperativeLevel( p_vout->p_sys->p_ddobject,
593 p_vout->p_sys->hwnd, DDSCL_NORMAL );
594 if( dxresult != DD_OK )
596 msg_Err( p_vout, "cannot set direct draw cooperative level" );
600 /* Probe the capabilities of the hardware */
601 DirectXGetDDrawCaps( p_vout );
603 msg_Dbg( p_vout, "End DirectXInitDDraw" );
607 if( p_vout->p_sys->p_ddobject )
608 IDirectDraw2_Release( p_vout->p_sys->p_ddobject );
609 if( p_vout->p_sys->hddraw_dll )
610 FreeLibrary( p_vout->p_sys->hddraw_dll );
611 p_vout->p_sys->hddraw_dll = NULL;
612 p_vout->p_sys->p_ddobject = NULL;
616 /*****************************************************************************
617 * DirectXCreateDisplay: create the DirectDraw display.
618 *****************************************************************************
619 * Create and initialize display according to preferences specified in the vout
621 *****************************************************************************/
622 static int DirectXCreateDisplay( vout_thread_t *p_vout )
626 LPDIRECTDRAWSURFACE p_display;
627 DDPIXELFORMAT pixel_format;
629 msg_Dbg( p_vout, "DirectXCreateDisplay" );
631 /* Now get the primary surface. This surface is what you actually see
633 memset( &ddsd, 0, sizeof( DDSURFACEDESC ));
634 ddsd.dwSize = sizeof(DDSURFACEDESC);
635 ddsd.dwFlags = DDSD_CAPS;
636 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
638 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
641 if( dxresult != DD_OK )
643 msg_Err( p_vout, "cannot get direct draw primary surface" );
647 dxresult = IDirectDrawSurface_QueryInterface( p_display,
648 &IID_IDirectDrawSurface2,
649 (LPVOID *)&p_vout->p_sys->p_display );
650 /* Release the old interface */
651 IDirectDrawSurface_Release( p_display );
652 if ( dxresult != DD_OK )
654 msg_Err( p_vout, "cannot get IDirectDrawSurface2 interface" );
658 /* The clipper will be used only in non-overlay mode */
659 DirectXCreateClipper( p_vout );
663 /* compute the colorkey pixel value from the RGB value we've got */
664 memset( &pixel_format, 0, sizeof( DDPIXELFORMAT ));
665 pixel_format.dwSize = sizeof( DDPIXELFORMAT );
666 dxresult = IDirectDrawSurface2_GetPixelFormat( p_vout->p_sys->p_display,
668 if( dxresult != DD_OK )
669 msg_Warn( p_vout, "DirectXUpdateOverlay GetPixelFormat failed" );
670 p_vout->p_sys->i_colorkey = (DWORD)((( p_vout->p_sys->i_rgb_colorkey
671 * pixel_format.dwRBitMask) / 255)
672 & pixel_format.dwRBitMask);
679 /*****************************************************************************
680 * DirectXCreateClipper: Create a clipper that will be used when blitting the
681 * RGB surface to the main display.
682 *****************************************************************************
683 * This clipper prevents us to modify by mistake anything on the screen
684 * which doesn't belong to our window. For example when a part of our video
685 * window is hidden by another window.
686 *****************************************************************************/
687 static int DirectXCreateClipper( vout_thread_t *p_vout )
691 msg_Dbg( p_vout, "DirectXCreateClipper" );
693 /* Create the clipper */
694 dxresult = IDirectDraw2_CreateClipper( p_vout->p_sys->p_ddobject, 0,
695 &p_vout->p_sys->p_clipper, NULL );
696 if( dxresult != DD_OK )
698 msg_Warn( p_vout, "DirectXCreateClipper cannot create clipper" );
702 /* associate the clipper to the window */
703 dxresult = IDirectDrawClipper_SetHWnd(p_vout->p_sys->p_clipper, 0,
704 p_vout->p_sys->hwnd);
705 if( dxresult != DD_OK )
708 "DirectXCreateClipper cannot attach clipper to window" );
712 /* associate the clipper with the surface */
713 dxresult = IDirectDrawSurface_SetClipper(p_vout->p_sys->p_display,
714 p_vout->p_sys->p_clipper);
715 if( dxresult != DD_OK )
718 "DirectXCreateClipper cannot attach clipper to surface" );
725 if( p_vout->p_sys->p_clipper )
726 IDirectDrawClipper_Release( p_vout->p_sys->p_clipper );
727 p_vout->p_sys->p_clipper = NULL;
732 /*****************************************************************************
733 * DirectXCreateSurface: create an YUV overlay or RGB surface for the video.
734 *****************************************************************************
735 * The best method of display is with an YUV overlay because the YUV->RGB
736 * conversion is done in hardware.
737 * You can also create a plain RGB surface.
738 * ( Maybe we could also try an RGB overlay surface, which could have hardware
739 * scaling and which would also be faster in window mode because you don't
740 * need to do any blitting to the main display...)
741 *****************************************************************************/
742 static int DirectXCreateSurface( vout_thread_t *p_vout,
743 LPDIRECTDRAWSURFACE2 *pp_surface_final,
744 int i_chroma, int b_overlay,
748 LPDIRECTDRAWSURFACE p_surface;
751 /* Create the video surface */
754 /* Now try to create the YUV overlay surface.
755 * This overlay will be displayed on top of the primary surface.
756 * A color key is used to determine whether or not the overlay will be
757 * displayed, ie the overlay will be displayed in place of the primary
758 * surface wherever the primary surface will have this color.
759 * The video window has been created with a background of this color so
760 * the overlay will be only displayed on top of this window */
762 memset( &ddsd, 0, sizeof( DDSURFACEDESC ));
763 ddsd.dwSize = sizeof(DDSURFACEDESC);
764 ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
765 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
766 ddsd.ddpfPixelFormat.dwFourCC = i_chroma;
767 ddsd.dwFlags = DDSD_CAPS |
771 ddsd.dwFlags |= (i_backbuffers ? DDSD_BACKBUFFERCOUNT : 0);
772 ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY |
774 ddsd.ddsCaps.dwCaps |= (i_backbuffers ? DDSCAPS_COMPLEX | DDSCAPS_FLIP
776 ddsd.dwHeight = p_vout->render.i_height;
777 ddsd.dwWidth = p_vout->render.i_width;
778 ddsd.dwBackBufferCount = i_backbuffers;
780 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
783 if( dxresult != DD_OK )
785 *pp_surface_final = NULL;
792 vlc_bool_t b_rgb_surface =
793 ( i_chroma == VLC_FOURCC('R','G','B','2') )
794 || ( i_chroma == VLC_FOURCC('R','V','1','5') )
795 || ( i_chroma == VLC_FOURCC('R','V','1','6') )
796 || ( i_chroma == VLC_FOURCC('R','V','2','4') )
797 || ( i_chroma == VLC_FOURCC('R','V','3','2') );
799 memset( &ddsd, 0, sizeof( DDSURFACEDESC ) );
800 ddsd.dwSize = sizeof(DDSURFACEDESC);
801 ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
802 ddsd.dwFlags = DDSD_HEIGHT |
805 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
806 ddsd.dwHeight = p_vout->render.i_height;
807 ddsd.dwWidth = p_vout->render.i_width;
809 if( p_vout->p_sys->b_use_sysmem )
810 ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
812 ddsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
816 ddsd.dwFlags |= DDSD_PIXELFORMAT;
817 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
818 ddsd.ddpfPixelFormat.dwFourCC = i_chroma;
821 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
824 if( dxresult != DD_OK )
826 *pp_surface_final = NULL;
831 /* Now that the surface is created, try to get a newer DirectX interface */
832 dxresult = IDirectDrawSurface_QueryInterface( p_surface,
833 &IID_IDirectDrawSurface2,
834 (LPVOID *)pp_surface_final );
835 IDirectDrawSurface_Release( p_surface ); /* Release the old interface */
836 if ( dxresult != DD_OK )
838 msg_Err( p_vout, "cannot get IDirectDrawSurface2 interface" );
839 *pp_surface_final = NULL;
846 /*****************************************************************************
847 * DirectXUpdateOverlay: Move or resize overlay surface on video display.
848 *****************************************************************************
849 * This function is used to move or resize an overlay surface on the screen.
850 * Ususally the overlay is moved by the user and thus, by a move or resize
852 *****************************************************************************/
853 void DirectXUpdateOverlay( vout_thread_t *p_vout )
859 if( p_vout->p_sys->p_current_surface == NULL ||
860 !p_vout->p_sys->b_using_overlay )
863 /* The new window dimensions should already have been computed by the
864 * caller of this function */
866 /* Position and show the overlay */
867 memset(&ddofx, 0, sizeof(DDOVERLAYFX));
868 ddofx.dwSize = sizeof(DDOVERLAYFX);
869 ddofx.dckDestColorkey.dwColorSpaceLowValue = p_vout->p_sys->i_colorkey;
870 ddofx.dckDestColorkey.dwColorSpaceHighValue = p_vout->p_sys->i_colorkey;
872 dwFlags = DDOVER_SHOW;
873 if( !p_vout->p_sys->b_caps_overlay_clipping )
874 dwFlags |= DDOVER_KEYDESTOVERRIDE;
876 dxresult = IDirectDrawSurface2_UpdateOverlay(
877 p_vout->p_sys->p_current_surface,
878 &p_vout->p_sys->rect_src_clipped,
879 p_vout->p_sys->p_display,
880 &p_vout->p_sys->rect_dest_clipped,
883 if(dxresult != DD_OK)
886 "DirectXUpdateOverlay cannot move or resize overlay" );
891 /*****************************************************************************
892 * DirectXCloseDDraw: Release the DDraw object allocated by DirectXInitDDraw
893 *****************************************************************************
894 * This function returns all resources allocated by DirectXInitDDraw.
895 *****************************************************************************/
896 static void DirectXCloseDDraw( vout_thread_t *p_vout )
898 msg_Dbg( p_vout, "DirectXCloseDDraw" );
899 if( p_vout->p_sys->p_ddobject != NULL )
901 IDirectDraw2_Release(p_vout->p_sys->p_ddobject);
902 p_vout->p_sys->p_ddobject = NULL;
905 if( p_vout->p_sys->hddraw_dll != NULL )
907 FreeLibrary( p_vout->p_sys->hddraw_dll );
908 p_vout->p_sys->hddraw_dll = NULL;
912 /*****************************************************************************
913 * DirectXCloseDisplay: close and reset the DirectX display device
914 *****************************************************************************
915 * This function returns all resources allocated by DirectXCreateDisplay.
916 *****************************************************************************/
917 static void DirectXCloseDisplay( vout_thread_t *p_vout )
919 msg_Dbg( p_vout, "DirectXCloseDisplay" );
921 if( p_vout->p_sys->p_clipper != NULL )
923 msg_Dbg( p_vout, "DirectXCloseDisplay clipper" );
924 IDirectDrawClipper_Release( p_vout->p_sys->p_clipper );
925 p_vout->p_sys->p_clipper = NULL;
928 if( p_vout->p_sys->p_display != NULL )
930 msg_Dbg( p_vout, "DirectXCloseDisplay display" );
931 IDirectDrawSurface2_Release( p_vout->p_sys->p_display );
932 p_vout->p_sys->p_display = NULL;
936 /*****************************************************************************
937 * DirectXCloseSurface: close the YUV overlay or RGB surface.
938 *****************************************************************************
939 * This function returns all resources allocated for the surface.
940 *****************************************************************************/
941 static void DirectXCloseSurface( vout_thread_t *p_vout,
942 LPDIRECTDRAWSURFACE2 p_surface )
944 msg_Dbg( p_vout, "DirectXCloseSurface" );
945 if( p_surface != NULL )
947 IDirectDrawSurface2_Release( p_surface );
951 /*****************************************************************************
952 * NewPictureVec: allocate a vector of identical pictures
953 *****************************************************************************
954 * Returns 0 on success, -1 otherwise
955 *****************************************************************************/
956 static int NewPictureVec( vout_thread_t *p_vout, picture_t *p_pic,
960 vlc_bool_t b_result_ok;
961 LPDIRECTDRAWSURFACE2 p_surface;
963 msg_Dbg( p_vout, "NewPictureVec" );
965 I_OUTPUTPICTURES = 0;
967 /* First we try to use an YUV overlay surface.
968 * The overlay surface that we create won't be used to decode directly
969 * into it because accessing video memory directly is way to slow (remember
970 * that pictures are decoded macroblock per macroblock). Instead the video
971 * will be decoded in picture buffers in system memory which will then be
972 * memcpy() to the overlay surface. */
973 if( p_vout->p_sys->b_using_overlay )
975 /* Triple buffering rocks! it doesn't have any processing overhead
976 * (you don't have to wait for the vsync) and provides for a very nice
977 * video quality (no tearing). */
979 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
980 p_vout->output.i_chroma,
981 p_vout->p_sys->b_using_overlay,
982 2 /* number of backbuffers */ );
985 /* Try to reduce the number of backbuffers */
986 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
987 p_vout->output.i_chroma,
988 p_vout->p_sys->b_using_overlay,
989 0 /* number of backbuffers */);
995 picture_sys_t front_pic_sys;
996 front_pic.p_sys = &front_pic_sys;
998 /* Allocate internal structure */
999 p_pic[0].p_sys = malloc( sizeof( picture_sys_t ) );
1000 if( p_pic[0].p_sys == NULL )
1002 DirectXCloseSurface( p_vout, p_surface );
1006 /* set front buffer */
1007 p_pic[0].p_sys->p_front_surface = p_surface;
1009 /* Get the back buffer */
1010 memset( &dds_caps, 0, sizeof( DDSCAPS ) );
1011 dds_caps.dwCaps = DDSCAPS_BACKBUFFER;
1012 if( DD_OK != IDirectDrawSurface2_GetAttachedSurface(
1013 p_surface, &dds_caps,
1014 &p_pic[0].p_sys->p_surface ) )
1016 msg_Warn( p_vout, "NewPictureVec could not get back buffer" );
1017 /* front buffer is the same as back buffer */
1018 p_pic[0].p_sys->p_surface = p_surface;
1022 p_vout->p_sys->p_current_surface = front_pic.p_sys->p_surface =
1023 p_pic[0].p_sys->p_front_surface;
1025 /* reset the front buffer memory */
1026 if( DirectXGetSurfaceDesc( &front_pic ) &&
1027 UpdatePictureStruct( p_vout, &front_pic,
1028 p_vout->output.i_chroma ) )
1031 for( i = 0; i < front_pic.i_planes; i++ )
1032 for( j = 0; j < front_pic.p[i].i_lines; j++)
1033 memset( front_pic.p[i].p_pixels + j *
1034 front_pic.p[i].i_pitch, 127,
1035 front_pic.p[i].i_visible_pitch );
1038 DirectXUpdateOverlay( p_vout );
1039 I_OUTPUTPICTURES = 1;
1040 msg_Dbg( p_vout, "DirectX YUV overlay created successfully" );
1044 /* As we can't have an overlay, we'll try to create a plain offscreen
1045 * surface. This surface will reside in video memory because there's a
1046 * better chance then that we'll be able to use some kind of hardware
1047 * acceleration like rescaling, blitting or YUV->RGB conversions.
1048 * We then only need to blit this surface onto the main display when we
1049 * want to display it */
1050 if( !p_vout->p_sys->b_using_overlay )
1053 if( p_vout->p_sys->b_hw_yuv )
1054 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
1055 p_vout->output.i_chroma,
1056 p_vout->p_sys->b_using_overlay,
1057 0 /* no back buffers */ );
1059 if( !p_vout->p_sys->b_hw_yuv || !b_result_ok )
1061 /* Our last choice is to use a plain RGB surface */
1062 DDPIXELFORMAT ddpfPixelFormat;
1064 ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
1065 IDirectDrawSurface2_GetPixelFormat( p_vout->p_sys->p_display,
1068 if( ddpfPixelFormat.dwFlags & DDPF_RGB )
1070 switch( ddpfPixelFormat.dwRGBBitCount )
1072 case 8: /* FIXME: set the palette */
1073 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
1076 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5');
1079 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6');
1082 p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4');
1085 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2');
1088 msg_Err( p_vout, "unknown screen depth" );
1091 p_vout->output.i_rmask = ddpfPixelFormat.dwRBitMask;
1092 p_vout->output.i_gmask = ddpfPixelFormat.dwGBitMask;
1093 p_vout->output.i_bmask = ddpfPixelFormat.dwBBitMask;
1096 p_vout->p_sys->b_hw_yuv = 0;
1098 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
1099 p_vout->output.i_chroma,
1100 p_vout->p_sys->b_using_overlay,
1101 0 /* no back buffers */ );
1106 /* Allocate internal structure */
1107 p_pic[0].p_sys = malloc( sizeof( picture_sys_t ) );
1108 if( p_pic[0].p_sys == NULL )
1110 DirectXCloseSurface( p_vout, p_surface );
1113 p_pic[0].p_sys->p_surface = p_pic[0].p_sys->p_front_surface
1116 I_OUTPUTPICTURES = 1;
1118 msg_Dbg( p_vout, "DirectX plain surface created successfully" );
1123 /* Now that we've got all our direct-buffers, we can finish filling in the
1124 * picture_t structures */
1125 for( i = 0; i < I_OUTPUTPICTURES; i++ )
1127 p_pic[i].i_status = DESTROYED_PICTURE;
1128 p_pic[i].i_type = DIRECT_PICTURE;
1129 PP_OUTPUTPICTURE[i] = &p_pic[i];
1131 if( !DirectXGetSurfaceDesc( &p_pic[i] ) )
1134 FreePictureVec( p_vout, p_pic, I_OUTPUTPICTURES );
1135 I_OUTPUTPICTURES = 0;
1139 if( !UpdatePictureStruct(p_vout, &p_pic[i], p_vout->output.i_chroma) )
1142 /* Unknown chroma, tell the guy to get lost */
1143 msg_Err( p_vout, "never heard of chroma 0x%.8x (%4.4s)",
1144 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma );
1145 FreePictureVec( p_vout, p_pic, I_OUTPUTPICTURES );
1146 I_OUTPUTPICTURES = 0;
1151 msg_Dbg( p_vout, "End NewPictureVec");
1155 /*****************************************************************************
1156 * FreePicture: destroy a picture vector allocated with NewPictureVec
1157 *****************************************************************************
1159 *****************************************************************************/
1160 static void FreePictureVec( vout_thread_t *p_vout, picture_t *p_pic,
1165 for( i = 0; i < i_num_pics; i++ )
1167 DirectXCloseSurface( p_vout, p_pic[i].p_sys->p_front_surface );
1169 for( i = 0; i < i_num_pics; i++ )
1171 free( p_pic[i].p_sys );
1176 /*****************************************************************************
1177 * UpdatePictureStruct: updates the internal data in the picture_t structure
1178 *****************************************************************************
1179 * This will setup stuff for use by the video_output thread
1180 *****************************************************************************/
1181 static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
1185 switch( p_vout->output.i_chroma )
1187 case VLC_FOURCC('R','G','B','2'):
1188 case VLC_FOURCC('R','V','1','5'):
1189 case VLC_FOURCC('R','V','1','6'):
1190 case VLC_FOURCC('R','V','2','4'):
1191 case VLC_FOURCC('R','V','3','2'):
1192 p_pic->p->p_pixels = p_pic->p_sys->ddsd.lpSurface;
1193 p_pic->p->i_lines = p_vout->output.i_height;
1194 p_pic->p->i_pitch = p_pic->p_sys->ddsd.lPitch;
1195 switch( p_vout->output.i_chroma )
1197 case VLC_FOURCC('R','G','B','2'):
1198 p_pic->p->i_pixel_pitch = 1;
1200 case VLC_FOURCC('R','V','1','5'):
1201 case VLC_FOURCC('R','V','1','6'):
1202 p_pic->p->i_pixel_pitch = 2;
1204 case VLC_FOURCC('R','V','2','4'):
1205 case VLC_FOURCC('R','V','3','2'):
1206 p_pic->p->i_pixel_pitch = 4;
1211 p_pic->p->i_visible_pitch = p_vout->output.i_width *
1212 p_pic->p->i_pixel_pitch;
1213 p_pic->i_planes = 1;
1216 case VLC_FOURCC('Y','V','1','2'):
1218 p_pic->Y_PIXELS = p_pic->p_sys->ddsd.lpSurface;
1219 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1220 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->ddsd.lPitch;
1221 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
1222 p_pic->p[Y_PLANE].i_visible_pitch = p_vout->output.i_width *
1223 p_pic->p[Y_PLANE].i_pixel_pitch;
1225 p_pic->V_PIXELS = p_pic->Y_PIXELS
1226 + p_pic->p[Y_PLANE].i_lines * p_pic->p[Y_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->U_PIXELS = p_pic->V_PIXELS
1234 + p_pic->p[V_PLANE].i_lines * p_pic->p[V_PLANE].i_pitch;
1235 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1236 p_pic->p[U_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1237 p_pic->p[U_PLANE].i_pixel_pitch = 1;
1238 p_pic->p[U_PLANE].i_visible_pitch = p_vout->output.i_width *
1239 p_pic->p[U_PLANE].i_pixel_pitch;
1241 p_pic->i_planes = 3;
1244 case VLC_FOURCC('I','Y','U','V'):
1246 p_pic->Y_PIXELS = p_pic->p_sys->ddsd.lpSurface;
1247 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1248 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->ddsd.lPitch;
1249 p_pic->p[Y_PLANE].i_pixel_pitch = 1;
1250 p_pic->p[Y_PLANE].i_visible_pitch = p_vout->output.i_width *
1251 p_pic->p[Y_PLANE].i_pixel_pitch;
1253 p_pic->U_PIXELS = p_pic->Y_PIXELS
1254 + p_pic->p[Y_PLANE].i_lines * p_pic->p[Y_PLANE].i_pitch;
1255 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1256 p_pic->p[U_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1257 p_pic->p[U_PLANE].i_pixel_pitch = 1;
1258 p_pic->p[U_PLANE].i_visible_pitch = p_vout->output.i_width *
1259 p_pic->p[U_PLANE].i_pixel_pitch;
1261 p_pic->V_PIXELS = p_pic->U_PIXELS
1262 + p_pic->p[U_PLANE].i_lines * p_pic->p[U_PLANE].i_pitch;
1263 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1264 p_pic->p[V_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1265 p_pic->p[V_PLANE].i_pixel_pitch = 1;
1266 p_pic->p[V_PLANE].i_visible_pitch = p_vout->output.i_width *
1267 p_pic->p[V_PLANE].i_pixel_pitch;
1269 p_pic->i_planes = 3;
1272 case VLC_FOURCC('Y','U','Y','2'):
1274 p_pic->p->p_pixels = p_pic->p_sys->ddsd.lpSurface;
1275 p_pic->p->i_lines = p_vout->output.i_height;
1276 p_pic->p->i_pitch = p_pic->p_sys->ddsd.lPitch;
1277 p_pic->p->i_pixel_pitch = 2;
1278 p_pic->p->i_visible_pitch = p_vout->output.i_width *
1279 p_pic->p->i_pixel_pitch;
1281 p_pic->i_planes = 1;
1293 /*****************************************************************************
1294 * DirectXGetDDrawCaps: Probe the capabilities of the hardware
1295 *****************************************************************************
1296 * It is nice to know which features are supported by the hardware so we can
1297 * find ways to optimize our rendering.
1298 *****************************************************************************/
1299 static void DirectXGetDDrawCaps( vout_thread_t *p_vout )
1304 /* This is just an indication of whether or not we'll support overlay,
1305 * but with this test we don't know if we support YUV overlay */
1306 memset( &ddcaps, 0, sizeof( DDCAPS ));
1307 ddcaps.dwSize = sizeof(DDCAPS);
1308 dxresult = IDirectDraw2_GetCaps( p_vout->p_sys->p_ddobject,
1310 if(dxresult != DD_OK )
1312 msg_Warn( p_vout, "cannot get caps" );
1316 BOOL bHasOverlay, bHasOverlayFourCC, bCanClipOverlay,
1317 bHasColorKey, bCanStretch;
1319 /* Determine if the hardware supports overlay surfaces */
1320 bHasOverlay = ((ddcaps.dwCaps & DDCAPS_OVERLAY) ==
1321 DDCAPS_OVERLAY) ? TRUE : FALSE;
1322 /* Determine if the hardware supports overlay surfaces */
1323 bHasOverlayFourCC = ((ddcaps.dwCaps & DDCAPS_OVERLAYFOURCC) ==
1324 DDCAPS_OVERLAYFOURCC) ? TRUE : FALSE;
1325 /* Determine if the hardware supports overlay surfaces */
1326 bCanClipOverlay = ((ddcaps.dwCaps & DDCAPS_OVERLAYCANTCLIP) ==
1328 /* Determine if the hardware supports colorkeying */
1329 bHasColorKey = ((ddcaps.dwCaps & DDCAPS_COLORKEY) ==
1330 DDCAPS_COLORKEY) ? TRUE : FALSE;
1331 /* Determine if the hardware supports scaling of the overlay surface */
1332 bCanStretch = ((ddcaps.dwCaps & DDCAPS_OVERLAYSTRETCH) ==
1333 DDCAPS_OVERLAYSTRETCH) ? TRUE : FALSE;
1334 msg_Dbg( p_vout, "DirectDraw Capabilities: overlay=%i yuvoverlay=%i "
1335 "can_clip_overlay=%i colorkey=%i stretch=%i",
1336 bHasOverlay, bHasOverlayFourCC, bCanClipOverlay,
1337 bHasColorKey, bCanStretch );
1339 /* Overlay clipping support is interesting for us as it means we can
1340 * get rid of the colorkey alltogether */
1341 p_vout->p_sys->b_caps_overlay_clipping = bCanClipOverlay;
1346 /*****************************************************************************
1347 * DirectXGetSurfaceDesc: Get some more information about the surface
1348 *****************************************************************************
1349 * This function get and stores the surface descriptor which among things
1350 * has the pointer to the picture data.
1351 *****************************************************************************/
1352 static int DirectXGetSurfaceDesc( picture_t *p_pic )
1356 /* Lock the surface to get a valid pointer to the picture buffer */
1357 memset( &p_pic->p_sys->ddsd, 0, sizeof( DDSURFACEDESC ));
1358 p_pic->p_sys->ddsd.dwSize = sizeof(DDSURFACEDESC);
1359 dxresult = IDirectDrawSurface2_Lock( p_pic->p_sys->p_surface,
1360 NULL, &p_pic->p_sys->ddsd,
1361 DDLOCK_NOSYSLOCK | DDLOCK_WAIT,
1363 if ( dxresult == DDERR_SURFACELOST )
1365 /* Your surface can be lost so be sure
1366 * to check this and restore it if needed */
1367 dxresult = IDirectDrawSurface2_Restore( p_pic->p_sys->p_surface );
1368 dxresult = IDirectDrawSurface2_Lock( p_pic->p_sys->p_surface, NULL,
1369 &p_pic->p_sys->ddsd,
1370 DDLOCK_NOSYSLOCK | DDLOCK_WAIT,
1373 if( dxresult != DD_OK )
1375 //X msg_Err( p_vout, "DirectXGetSurfaceDesc cannot lock surface" );
1379 /* Unlock the Surface */
1380 dxresult = IDirectDrawSurface2_Unlock( p_pic->p_sys->p_surface, NULL );