1 /*****************************************************************************
2 * vout_directx.c: Windows DirectX video output display method
3 *****************************************************************************
4 * Copyright (C) 2001 VideoLAN
5 * $Id: vout_directx.c,v 1.36 2002/05/30 08:17:04 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() */
41 #include <videolan/vlc.h>
48 #include "video_output.h"
50 #include "interface.h"
52 #include "vout_directx.h"
54 /*****************************************************************************
56 * Defining them here allows us to get rid of the dxguid library during
58 *****************************************************************************/
60 DEFINE_GUID( IID_IDirectDraw2, 0xB3A6F3E0,0x2B43,0x11CF,0xA2,0xDE,0x00,0xAA,0x00,0xB9,0x33,0x56 );
61 DEFINE_GUID( IID_IDirectDrawSurface3, 0xDA044E00,0x69B2,0x11D0,0xA1,0xD5,0x00,0xAA,0x00,0xB8,0xDF,0xBB );
63 /*****************************************************************************
65 *****************************************************************************/
66 static int vout_Create ( vout_thread_t * );
67 static void vout_Destroy ( vout_thread_t * );
68 static int vout_Init ( vout_thread_t * );
69 static void vout_End ( vout_thread_t * );
70 static int vout_Manage ( vout_thread_t * );
71 static void vout_Render ( vout_thread_t *, picture_t * );
72 static void vout_Display ( vout_thread_t *, picture_t * );
74 static int NewPictureVec ( vout_thread_t *, picture_t *, int );
75 static void FreePictureVec ( vout_thread_t *, picture_t *, int );
76 static int UpdatePictureStruct( vout_thread_t *, picture_t *, int );
78 static int DirectXInitDDraw ( vout_thread_t *p_vout );
79 static void DirectXCloseDDraw ( vout_thread_t *p_vout );
80 static int DirectXCreateDisplay ( vout_thread_t *p_vout );
81 static void DirectXCloseDisplay ( vout_thread_t *p_vout );
82 static int DirectXCreateSurface ( vout_thread_t *p_vout,
83 LPDIRECTDRAWSURFACE3 *, int, int, int );
84 static void DirectXCloseSurface ( vout_thread_t *p_vout,
85 LPDIRECTDRAWSURFACE3 );
86 static int DirectXCreateClipper ( vout_thread_t *p_vout );
87 static void DirectXGetDDrawCaps ( vout_thread_t *p_vout );
88 static int DirectXGetSurfaceDesc ( picture_t *p_pic );
90 /*****************************************************************************
91 * Functions exported as capabilities. They are declared as static so that
92 * we don't pollute the namespace too much.
93 *****************************************************************************/
94 void _M( vout_getfunctions )( function_list_t * p_function_list )
96 p_function_list->functions.vout.pf_create = vout_Create;
97 p_function_list->functions.vout.pf_init = vout_Init;
98 p_function_list->functions.vout.pf_end = vout_End;
99 p_function_list->functions.vout.pf_destroy = vout_Destroy;
100 p_function_list->functions.vout.pf_manage = vout_Manage;
101 p_function_list->functions.vout.pf_render = vout_Render;
102 p_function_list->functions.vout.pf_display = vout_Display;
105 /*****************************************************************************
106 * vout_Create: allocate DirectX video thread output method
107 *****************************************************************************
108 * This function allocates and initialize the DirectX vout method.
109 *****************************************************************************/
110 static int vout_Create( vout_thread_t *p_vout )
112 /* Allocate structure */
113 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
114 if( p_vout->p_sys == NULL )
116 intf_ErrMsg( "vout error: can't create p_sys (%s)", strerror(ENOMEM) );
120 /* Initialisations */
121 p_vout->p_sys->p_ddobject = NULL;
122 p_vout->p_sys->p_display = NULL;
123 p_vout->p_sys->p_current_surface = NULL;
124 p_vout->p_sys->p_clipper = NULL;
125 p_vout->p_sys->hbrush = NULL;
126 p_vout->p_sys->hwnd = NULL;
127 p_vout->p_sys->i_changes = 0;
128 p_vout->p_sys->b_event_thread_die = 0;
129 p_vout->p_sys->b_caps_overlay_clipping = 0;
130 SetRectEmpty( &p_vout->p_sys->rect_display );
131 p_vout->p_sys->b_using_overlay = config_GetIntVariable( "overlay" );
132 p_vout->p_sys->b_use_sysmem = config_GetIntVariable( "directx-use-sysmem");
133 p_vout->p_sys->b_hw_yuv = config_GetIntVariable( "directx-hw-yuv" );
135 p_vout->p_sys->b_cursor_hidden = 0;
136 p_vout->p_sys->i_lastmoved = mdate();
138 /* Set main window's size */
139 p_vout->p_sys->i_window_width = p_vout->i_window_width;
140 p_vout->p_sys->i_window_height = p_vout->i_window_height;
142 /* Set locks and condition variables */
143 vlc_mutex_init( &p_vout->p_sys->event_thread_lock );
144 vlc_cond_init( &p_vout->p_sys->event_thread_wait );
145 p_vout->p_sys->i_event_thread_status = THREAD_CREATE;
147 /* Create the DirectXEventThread, this thread is created by us to isolate
148 * the Win32 PeekMessage function calls. We want to do this because
149 * Windows can stay blocked inside this call for a long time, and when
150 * this happens it thus blocks vlc's video_output thread.
151 * DirectXEventThread will take care of the creation of the video
152 * window (because PeekMessage has to be called from the same thread which
153 * created the window). */
154 intf_WarnMsg( 3, "vout: vout_Create creating DirectXEventThread" );
155 if( vlc_thread_create( &p_vout->p_sys->event_thread_id,
156 "DirectX Events Thread",
157 (void *) DirectXEventThread, (void *) p_vout) )
159 intf_ErrMsg( "vout error: can't create DirectXEventThread" );
160 intf_ErrMsg("vout error: %s", strerror(ENOMEM));
161 free( p_vout->p_sys );
165 /* We need to wait for the actual creation of the thread and window */
166 vlc_mutex_lock( &p_vout->p_sys->event_thread_lock );
167 if( p_vout->p_sys->i_event_thread_status == THREAD_CREATE )
169 vlc_cond_wait ( &p_vout->p_sys->event_thread_wait,
170 &p_vout->p_sys->event_thread_lock );
172 vlc_mutex_unlock( &p_vout->p_sys->event_thread_lock );
173 if( p_vout->p_sys->i_event_thread_status != THREAD_READY )
175 intf_ErrMsg( "vout error: DirectXEventThread failed" );
176 free( p_vout->p_sys );
180 intf_WarnMsg( 3, "vout: vout_Create DirectXEventThread running" );
182 /* Initialise DirectDraw */
183 if( DirectXInitDDraw( p_vout ) )
185 intf_ErrMsg( "vout error: can't initialise DirectDraw" );
186 vout_Destroy( p_vout );
190 /* Create the directx display */
191 if( DirectXCreateDisplay( p_vout ) )
193 intf_ErrMsg( "vout error: can't initialise DirectDraw" );
194 DirectXCloseDDraw( p_vout );
195 vout_Destroy( p_vout );
202 /*****************************************************************************
203 * vout_Init: initialize DirectX video thread output method
204 *****************************************************************************
205 * This function create the directx surfaces needed by the output thread.
206 * It is called at the beginning of the thread.
207 *****************************************************************************/
208 static int vout_Init( vout_thread_t *p_vout )
211 /* Initialize the output structure.
212 * Since DirectDraw can do rescaling for us, stick to the default
213 * coordinates and aspect. */
214 p_vout->output.i_width = p_vout->render.i_width;
215 p_vout->output.i_height = p_vout->render.i_height;
216 p_vout->output.i_aspect = p_vout->render.i_aspect;
218 #define MAX_DIRECTBUFFERS 1
219 /* Right now we use only 1 directbuffer because we don't want the
220 * video decoder to decode directly into direct buffers as they are
221 * created into video memory and video memory is _really_ slow */
223 NewPictureVec( p_vout, p_vout->p_picture, MAX_DIRECTBUFFERS );
225 /* Change the window title bar text */
226 if( p_vout->p_sys->b_using_overlay )
227 SetWindowText( p_vout->p_sys->hwnd,
228 "VLC DirectX (using hardware overlay)" );
229 else if( p_vout->p_sys->b_hw_yuv )
230 SetWindowText( p_vout->p_sys->hwnd,
231 "VLC DirectX (using hardware YUV->RGB conversion)" );
236 /*****************************************************************************
237 * vout_End: terminate Sys video thread output method
238 *****************************************************************************
239 * Terminate an output method created by vout_Create.
240 * It is called at the end of the thread.
241 *****************************************************************************/
242 static void vout_End( vout_thread_t *p_vout )
244 FreePictureVec( p_vout, p_vout->p_picture, I_OUTPUTPICTURES );
248 /*****************************************************************************
249 * vout_Destroy: destroy Sys video thread output method
250 *****************************************************************************
251 * Terminate an output method created by vout_Create
252 *****************************************************************************/
253 static void vout_Destroy( vout_thread_t *p_vout )
255 intf_WarnMsg( 3, "vout: vout_Destroy" );
256 DirectXCloseDisplay( p_vout );
257 DirectXCloseDDraw( p_vout );
259 /* Kill DirectXEventThread */
260 vlc_mutex_lock( &p_vout->p_sys->event_thread_lock );
261 p_vout->p_sys->b_event_thread_die = 1;
263 /* we need to be sure DirectXEventThread won't stay stuck in GetMessage,
264 * so we send a fake message */
265 if( p_vout->p_sys->hwnd )
266 PostMessage( p_vout->p_sys->hwnd, WM_NULL, 0, 0);
268 vlc_mutex_unlock( &p_vout->p_sys->event_thread_lock );
269 vlc_thread_join( p_vout->p_sys->event_thread_id );
271 if( p_vout->p_sys != NULL )
273 free( p_vout->p_sys );
274 p_vout->p_sys = NULL;
278 /*****************************************************************************
279 * vout_Manage: handle Sys events
280 *****************************************************************************
281 * This function should be called regularly by the video output thread.
282 * It returns a non null value if an error occured.
283 *****************************************************************************/
284 static int vout_Manage( vout_thread_t *p_vout )
286 WINDOWPLACEMENT window_placement;
288 /* We used to call the Win32 PeekMessage function here to read the window
289 * messages. But since window can stay blocked into this function for a
290 * long time (for example when you move your window on the screen), I
291 * decided to isolate PeekMessage in another thread. */
296 if( p_vout->i_changes & VOUT_SCALE_CHANGE
297 || p_vout->p_sys->i_changes & VOUT_SCALE_CHANGE)
299 intf_WarnMsg( 3, "vout: vout_Manage Scale Change" );
300 if( !p_vout->p_sys->b_using_overlay )
301 InvalidateRect( p_vout->p_sys->hwnd, NULL, TRUE );
303 DirectXUpdateOverlay( p_vout );
304 p_vout->i_changes &= ~VOUT_SCALE_CHANGE;
305 p_vout->p_sys->i_changes &= ~VOUT_SCALE_CHANGE;
311 if( p_vout->i_changes & VOUT_SIZE_CHANGE
312 || p_vout->p_sys->i_changes & VOUT_SIZE_CHANGE )
314 intf_WarnMsg( 3, "vout: vout_Manage Size Change" );
315 if( !p_vout->p_sys->b_using_overlay )
316 InvalidateRect( p_vout->p_sys->hwnd, NULL, TRUE );
318 DirectXUpdateOverlay( p_vout );
319 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
320 p_vout->p_sys->i_changes &= ~VOUT_SIZE_CHANGE;
326 if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE
327 || p_vout->p_sys->i_changes & VOUT_FULLSCREEN_CHANGE )
329 p_vout->b_fullscreen = ! p_vout->b_fullscreen;
331 /* We need to switch between Maximized and Normal sized window */
332 window_placement.length = sizeof(WINDOWPLACEMENT);
333 GetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
334 if( p_vout->b_fullscreen )
336 /* Maximized window */
337 window_placement.showCmd = SW_SHOWMAXIMIZED;
338 /* Change window style, no borders and no title bar */
339 SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE, 0 );
345 window_placement.showCmd = SW_SHOWNORMAL;
346 /* Change window style, borders and title bar */
347 SetWindowLong( p_vout->p_sys->hwnd, GWL_STYLE,
348 WS_OVERLAPPEDWINDOW | WS_SIZEBOX | WS_VISIBLE );
351 SetWindowPlacement( p_vout->p_sys->hwnd, &window_placement );
353 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
354 p_vout->p_sys->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
360 if( (!p_vout->p_sys->b_cursor_hidden) &&
361 ( (mdate() - p_vout->p_sys->i_lastmoved) > 5000000 ) )
363 /* Hide the mouse automatically */
364 p_vout->p_sys->b_cursor_hidden = 1;
365 PostMessage( p_vout->p_sys->hwnd, WM_VLC_HIDE_MOUSE, 0, 0 );
368 /* Check if the event thread is still running */
369 if( p_vout->p_sys->b_event_thread_die )
375 /*****************************************************************************
376 * vout_Render: render previously calculated output
377 *****************************************************************************/
378 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
383 /*****************************************************************************
384 * vout_Display: displays previously rendered output
385 *****************************************************************************
386 * This function sends the currently rendered image to the display, wait until
387 * it is displayed and switch the two rendering buffers, preparing next frame.
388 *****************************************************************************/
389 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
393 if( (p_vout->p_sys->p_display == NULL) )
395 intf_WarnMsg( 3, "vout error: vout_Display no display!!" );
399 if( !p_vout->p_sys->b_using_overlay )
403 /* We ask for the "NOTEARING" option */
404 memset( &ddbltfx, 0, sizeof(DDBLTFX) );
405 ddbltfx.dwSize = sizeof(DDBLTFX);
406 ddbltfx.dwDDFX = DDBLTFX_NOTEARING;
408 /* Blit video surface to display */
409 dxresult = IDirectDrawSurface3_Blt(p_vout->p_sys->p_display,
410 &p_vout->p_sys->rect_dest_clipped,
411 p_pic->p_sys->p_surface,
412 &p_vout->p_sys->rect_src_clipped,
413 DDBLT_ASYNC, &ddbltfx );
414 if ( dxresult == DDERR_SURFACELOST )
416 /* Our surface can be lost so be sure
417 * to check this and restore it if needed */
418 IDirectDrawSurface3_Restore( p_vout->p_sys->p_display );
420 /* Now that the surface has been restored try to display again */
421 dxresult = IDirectDrawSurface3_Blt(p_vout->p_sys->p_display,
422 &p_vout->p_sys->rect_dest_clipped,
423 p_pic->p_sys->p_surface,
424 &p_vout->p_sys->rect_src_clipped,
425 DDBLT_ASYNC, &ddbltfx );
428 if( dxresult != DD_OK )
430 intf_WarnMsg( 3, "vout: could not Blit the surface" );
435 else /* using overlay */
438 /* Flip the overlay buffers if we are using back buffers */
439 if( p_pic->p_sys->p_front_surface == p_pic->p_sys->p_surface )
442 dxresult = IDirectDrawSurface3_Flip( p_pic->p_sys->p_front_surface,
444 if ( dxresult == DDERR_SURFACELOST )
446 /* Our surface can be lost so be sure
447 * to check this and restore it if needed */
448 IDirectDrawSurface3_Restore( p_vout->p_sys->p_display );
449 IDirectDrawSurface3_Restore( p_pic->p_sys->p_front_surface );
451 /* Now that the surface has been restored try to display again */
452 dxresult = IDirectDrawSurface3_Flip( p_pic->p_sys->p_front_surface,
454 DirectXUpdateOverlay( p_vout );
457 if( dxresult != DD_OK )
458 intf_WarnMsg( 8, "vout: couldn't flip overlay surface" );
461 if( !DirectXGetSurfaceDesc( p_pic ) )
464 intf_ErrMsg( "vout error: vout_Display cannot get surface desc" );
468 if( !UpdatePictureStruct( p_vout, p_pic, p_vout->output.i_chroma ) )
471 intf_ErrMsg( "vout error: vout_Display unvalid pic chroma" );
475 /* set currently displayed pic */
476 p_vout->p_sys->p_current_surface = p_pic->p_sys->p_front_surface;
482 /* following functions are local */
484 /*****************************************************************************
485 * DirectXInitDDraw: Takes care of all the DirectDraw initialisations
486 *****************************************************************************
487 * This function initialise and allocate resources for DirectDraw.
488 *****************************************************************************/
489 static int DirectXInitDDraw( vout_thread_t *p_vout )
492 HRESULT (WINAPI *OurDirectDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
493 LPDIRECTDRAW p_ddobject;
495 intf_WarnMsg( 3, "vout: DirectXInitDDraw" );
497 /* load direct draw DLL */
498 p_vout->p_sys->hddraw_dll = LoadLibrary("DDRAW.DLL");
499 if( p_vout->p_sys->hddraw_dll == NULL )
501 intf_WarnMsg( 3, "vout: DirectXInitDDraw failed loading ddraw.dll" );
505 OurDirectDrawCreate =
506 (void *)GetProcAddress(p_vout->p_sys->hddraw_dll, "DirectDrawCreate");
507 if ( OurDirectDrawCreate == NULL )
509 intf_ErrMsg( "vout error: DirectXInitDDraw failed GetProcAddress" );
510 FreeLibrary( p_vout->p_sys->hddraw_dll );
511 p_vout->p_sys->hddraw_dll = NULL;
515 /* Initialize DirectDraw now */
516 dxresult = OurDirectDrawCreate( NULL, &p_ddobject, NULL );
517 if( dxresult != DD_OK )
519 intf_ErrMsg( "vout error: DirectXInitDDraw can't initialize DDraw" );
520 p_vout->p_sys->p_ddobject = NULL;
521 FreeLibrary( p_vout->p_sys->hddraw_dll );
522 p_vout->p_sys->hddraw_dll = NULL;
526 /* Set DirectDraw Cooperative level, ie what control we want over Windows
528 dxresult = IDirectDraw_SetCooperativeLevel( p_ddobject,
529 p_vout->p_sys->hwnd, DDSCL_NORMAL );
530 if( dxresult != DD_OK )
532 intf_ErrMsg( "vout error: can't set direct draw cooperative level." );
533 IDirectDraw_Release( p_ddobject );
534 p_vout->p_sys->p_ddobject = NULL;
535 FreeLibrary( p_vout->p_sys->hddraw_dll );
536 p_vout->p_sys->hddraw_dll = NULL;
540 /* Get the IDirectDraw2 interface */
541 dxresult = IDirectDraw_QueryInterface( p_ddobject, &IID_IDirectDraw2,
542 (LPVOID *)&p_vout->p_sys->p_ddobject );
543 if( dxresult != DD_OK )
545 intf_ErrMsg( "vout error: can't get IDirectDraw2 interface." );
546 IDirectDraw_Release( p_ddobject );
547 p_vout->p_sys->p_ddobject = NULL;
548 FreeLibrary( p_vout->p_sys->hddraw_dll );
549 p_vout->p_sys->hddraw_dll = NULL;
554 /* Release the unused interface */
555 IDirectDraw_Release( p_ddobject );
558 /* Probe the capabilities of the hardware */
559 DirectXGetDDrawCaps( p_vout );
561 intf_WarnMsg( 3, "vout: End DirectXInitDDraw" );
565 /*****************************************************************************
566 * DirectXCreateDisplay: create the DirectDraw display.
567 *****************************************************************************
568 * Create and initialize display according to preferences specified in the vout
570 *****************************************************************************/
571 static int DirectXCreateDisplay( vout_thread_t *p_vout )
575 LPDIRECTDRAWSURFACE p_display;
576 DDPIXELFORMAT pixel_format;
578 intf_WarnMsg( 3, "vout: DirectXCreateDisplay" );
580 /* Now get the primary surface. This surface is what you actually see
582 memset( &ddsd, 0, sizeof( DDSURFACEDESC ));
583 ddsd.dwSize = sizeof(DDSURFACEDESC);
584 ddsd.dwFlags = DDSD_CAPS;
585 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
587 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
590 if( dxresult != DD_OK )
592 intf_ErrMsg( "vout error: can't get direct draw primary surface." );
593 p_vout->p_sys->p_display = NULL;
597 dxresult = IDirectDrawSurface_QueryInterface( p_display,
598 &IID_IDirectDrawSurface3,
599 (LPVOID *)&p_vout->p_sys->p_display );
600 if ( dxresult != DD_OK )
602 intf_ErrMsg( "vout error: can't get IDirectDrawSurface3 interface." );
603 IDirectDrawSurface_Release( p_display );
604 p_vout->p_sys->p_display = NULL;
609 /* Release the old interface */
610 IDirectDrawSurface_Release( p_display );
614 /* The clipper will be used only in non-overlay mode */
615 DirectXCreateClipper( p_vout );
619 /* compute the colorkey pixel value from the RGB value we've got */
620 memset( &pixel_format, 0, sizeof( DDPIXELFORMAT ));
621 pixel_format.dwSize = sizeof( DDPIXELFORMAT );
622 dxresult = IDirectDrawSurface3_GetPixelFormat( p_vout->p_sys->p_display,
624 if( dxresult != DD_OK )
625 intf_WarnMsg( 3, "vout: DirectXUpdateOverlay GetPixelFormat failed" );
626 p_vout->p_sys->i_colorkey = (DWORD)((( p_vout->p_sys->i_rgb_colorkey
627 * pixel_format.dwRBitMask) / 255)
628 & pixel_format.dwRBitMask);
635 /*****************************************************************************
636 * DirectXCreateClipper: Create a clipper that will be used when blitting the
637 * RGB surface to the main display.
638 *****************************************************************************
639 * This clipper prevents us to modify by mistake anything on the screen
640 * which doesn't belong to our window. For example when a part of our video
641 * window is hidden by another window.
642 *****************************************************************************/
643 static int DirectXCreateClipper( vout_thread_t *p_vout )
647 intf_WarnMsg( 3, "vout: DirectXCreateClipper" );
649 /* Create the clipper */
650 dxresult = IDirectDraw2_CreateClipper( p_vout->p_sys->p_ddobject, 0,
651 &p_vout->p_sys->p_clipper, NULL );
652 if( dxresult != DD_OK )
654 intf_WarnMsg( 3, "vout: DirectXCreateClipper can't create clipper." );
655 p_vout->p_sys->p_clipper = NULL;
659 /* associate the clipper to the window */
660 dxresult = IDirectDrawClipper_SetHWnd(p_vout->p_sys->p_clipper, 0,
661 p_vout->p_sys->hwnd);
662 if( dxresult != DD_OK )
665 "vout: DirectXCreateClipper can't attach clipper to window." );
666 IDirectDrawSurface_Release( p_vout->p_sys->p_clipper );
667 p_vout->p_sys->p_clipper = NULL;
671 /* associate the clipper with the surface */
672 dxresult = IDirectDrawSurface_SetClipper(p_vout->p_sys->p_display,
673 p_vout->p_sys->p_clipper);
674 if( dxresult != DD_OK )
677 "vout: DirectXCreateClipper can't attach clipper to surface." );
678 IDirectDrawSurface_Release( p_vout->p_sys->p_clipper );
679 p_vout->p_sys->p_clipper = NULL;
686 /*****************************************************************************
687 * DirectXCreateSurface: create an YUV overlay or RGB surface for the video.
688 *****************************************************************************
689 * The best method of display is with an YUV overlay because the YUV->RGB
690 * conversion is done in hardware.
691 * You can also create a plain RGB surface.
692 * ( Maybe we could also try an RGB overlay surface, which could have hardware
693 * scaling and which would also be faster in window mode because you don't
694 * need to do any blitting to the main display...)
695 *****************************************************************************/
696 static int DirectXCreateSurface( vout_thread_t *p_vout,
697 LPDIRECTDRAWSURFACE3 *pp_surface_final,
698 int i_chroma, int b_overlay,
702 LPDIRECTDRAWSURFACE p_surface;
705 /* Create the video surface */
708 /* Now try to create the YUV overlay surface.
709 * This overlay will be displayed on top of the primary surface.
710 * A color key is used to determine whether or not the overlay will be
711 * displayed, ie the overlay will be displayed in place of the primary
712 * surface wherever the primary surface will have this color.
713 * The video window has been created with a background of this color so
714 * the overlay will be only displayed on top of this window */
716 memset( &ddsd, 0, sizeof( DDSURFACEDESC ));
717 ddsd.dwSize = sizeof(DDSURFACEDESC);
718 ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
719 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
720 ddsd.ddpfPixelFormat.dwFourCC = i_chroma;
721 ddsd.dwFlags = DDSD_CAPS |
725 ddsd.dwFlags |= (i_backbuffers ? DDSD_BACKBUFFERCOUNT : 0);
726 ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY |
728 ddsd.ddsCaps.dwCaps |= (i_backbuffers ? DDSCAPS_COMPLEX | DDSCAPS_FLIP
730 ddsd.dwHeight = p_vout->render.i_height;
731 ddsd.dwWidth = p_vout->render.i_width;
732 ddsd.dwBackBufferCount = i_backbuffers;
734 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
737 if( dxresult != DD_OK )
739 *pp_surface_final = NULL;
746 boolean_t b_rgb_surface = ( i_chroma == FOURCC_RGB2 ) ||
747 ( i_chroma == FOURCC_RV15 ) || ( i_chroma == FOURCC_RV16 ) ||
748 ( i_chroma == FOURCC_RV24 ) || ( i_chroma == FOURCC_RV32 );
750 memset( &ddsd, 0, sizeof( DDSURFACEDESC ) );
751 ddsd.dwSize = sizeof(DDSURFACEDESC);
752 ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
753 ddsd.dwFlags = DDSD_HEIGHT |
756 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
757 ddsd.dwHeight = p_vout->render.i_height;
758 ddsd.dwWidth = p_vout->render.i_width;
760 if( p_vout->p_sys->b_use_sysmem )
761 ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
763 ddsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
767 ddsd.dwFlags |= DDSD_PIXELFORMAT;
768 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
769 ddsd.ddpfPixelFormat.dwFourCC = i_chroma;
772 dxresult = IDirectDraw2_CreateSurface( p_vout->p_sys->p_ddobject,
775 if( dxresult != DD_OK )
777 *pp_surface_final = NULL;
782 /* Now that the surface is created, try to get a newer DirectX interface */
783 dxresult = IDirectDrawSurface_QueryInterface( p_surface,
784 &IID_IDirectDrawSurface3,
785 (LPVOID *)pp_surface_final );
786 IDirectDrawSurface_Release( p_surface ); /* Release the old interface */
787 if ( dxresult != DD_OK )
789 intf_ErrMsg( "vout error: can't get IDirectDrawSurface3 interface." );
790 *pp_surface_final = NULL;
797 /*****************************************************************************
798 * DirectXUpdateOverlay: Move or resize overlay surface on video display.
799 *****************************************************************************
800 * This function is used to move or resize an overlay surface on the screen.
801 * Ususally the overlay is moved by the user and thus, by a move or resize
802 * event (in vout_Manage).
803 *****************************************************************************/
804 void DirectXUpdateOverlay( vout_thread_t *p_vout )
810 if( p_vout->p_sys->p_current_surface == NULL ||
811 !p_vout->p_sys->b_using_overlay )
814 /* The new window dimensions should already have been computed by the
815 * caller of this function */
817 /* Position and show the overlay */
818 memset(&ddofx, 0, sizeof(DDOVERLAYFX));
819 ddofx.dwSize = sizeof(DDOVERLAYFX);
820 ddofx.dckDestColorkey.dwColorSpaceLowValue = p_vout->p_sys->i_colorkey;
821 ddofx.dckDestColorkey.dwColorSpaceHighValue = p_vout->p_sys->i_colorkey;
823 dwFlags = DDOVER_SHOW;
824 if( !p_vout->p_sys->b_caps_overlay_clipping )
825 dwFlags |= DDOVER_KEYDESTOVERRIDE;
827 dxresult = IDirectDrawSurface3_UpdateOverlay(
828 p_vout->p_sys->p_current_surface,
829 &p_vout->p_sys->rect_src_clipped,
830 p_vout->p_sys->p_display,
831 &p_vout->p_sys->rect_dest_clipped,
834 if(dxresult != DD_OK)
837 "vout: DirectXUpdateOverlay can't move or resize overlay" );
842 /*****************************************************************************
843 * DirectXCloseDDraw: Release the DDraw object allocated by DirectXInitDDraw
844 *****************************************************************************
845 * This function returns all resources allocated by DirectXInitDDraw.
846 *****************************************************************************/
847 static void DirectXCloseDDraw( vout_thread_t *p_vout )
849 intf_WarnMsg(3, "vout: DirectXCloseDDraw" );
850 if( p_vout->p_sys->p_ddobject != NULL )
852 IDirectDraw2_Release(p_vout->p_sys->p_ddobject);
853 p_vout->p_sys->p_ddobject = NULL;
856 if( p_vout->p_sys->hddraw_dll != NULL )
858 FreeLibrary( p_vout->p_sys->hddraw_dll );
859 p_vout->p_sys->hddraw_dll = NULL;
863 /*****************************************************************************
864 * DirectXCloseDisplay: close and reset the DirectX display device
865 *****************************************************************************
866 * This function returns all resources allocated by DirectXCreateDisplay.
867 *****************************************************************************/
868 static void DirectXCloseDisplay( vout_thread_t *p_vout )
870 intf_WarnMsg( 3, "vout: DirectXCloseDisplay" );
872 if( p_vout->p_sys->p_clipper != NULL )
874 intf_WarnMsg( 3, "vout: DirectXCloseDisplay clipper" );
875 IDirectDraw2_Release( p_vout->p_sys->p_clipper );
876 p_vout->p_sys->p_clipper = NULL;
879 if( p_vout->p_sys->p_display != NULL )
881 intf_WarnMsg( 3, "vout: DirectXCloseDisplay display" );
882 IDirectDraw2_Release( p_vout->p_sys->p_display );
883 p_vout->p_sys->p_display = NULL;
887 /*****************************************************************************
888 * DirectXCloseSurface: close the YUV overlay or RGB surface.
889 *****************************************************************************
890 * This function returns all resources allocated for the surface.
891 *****************************************************************************/
892 static void DirectXCloseSurface( vout_thread_t *p_vout,
893 LPDIRECTDRAWSURFACE3 p_surface )
895 intf_WarnMsg( 3, "vout: DirectXCloseSurface" );
896 if( p_surface != NULL )
898 IDirectDraw2_Release( p_surface );
902 /*****************************************************************************
903 * NewPictureVec: allocate a vector of identical pictures
904 *****************************************************************************
905 * Returns 0 on success, -1 otherwise
906 *****************************************************************************/
907 static int NewPictureVec( vout_thread_t *p_vout, picture_t *p_pic,
911 boolean_t b_result_ok;
912 LPDIRECTDRAWSURFACE3 p_surface;
914 intf_WarnMsg( 3, "vout: NewPictureVec" );
916 I_OUTPUTPICTURES = 0;
918 /* Choose the chroma we will try first. */
919 switch( p_vout->render.i_chroma )
923 p_vout->output.i_chroma = FOURCC_YUY2;
928 p_vout->output.i_chroma = FOURCC_UYVY;
931 p_vout->output.i_chroma = FOURCC_YVYU;
934 p_vout->output.i_chroma = FOURCC_YV12;
938 /* First we try to use an YUV overlay surface.
939 * The overlay surface that we create won't be used to decode directly
940 * into it because accessing video memory directly is way to slow (remember
941 * that pictures are decoded macroblock per macroblock). Instead the video
942 * will be decoded in picture buffers in system memory which will then be
943 * memcpy() to the overlay surface. */
944 if( p_vout->p_sys->b_using_overlay )
946 /* Triple buffering rocks! it doesn't have any processing overhead
947 * (you don't have to wait for the vsync) and provides for a very nice
948 * video quality (no tearing). */
950 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
951 p_vout->output.i_chroma,
952 p_vout->p_sys->b_using_overlay,
953 2 /* number of backbuffers */ );
956 /* Try to reduce the number of backbuffers */
957 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
958 p_vout->output.i_chroma,
959 p_vout->p_sys->b_using_overlay,
960 0 /* number of backbuffers */);
966 picture_sys_t front_pic_sys;
967 front_pic.p_sys = &front_pic_sys;
969 /* Allocate internal structure */
970 p_pic[0].p_sys = malloc( sizeof( picture_sys_t ) );
971 if( p_pic[0].p_sys == NULL )
973 DirectXCloseSurface( p_vout, p_surface );
977 /* set front buffer */
978 p_pic[0].p_sys->p_front_surface = p_surface;
980 /* Get the back buffer */
981 memset( &dds_caps, 0, sizeof( DDSCAPS ) );
982 dds_caps.dwCaps = DDSCAPS_BACKBUFFER;
983 if( DD_OK != IDirectDrawSurface3_GetAttachedSurface(
984 p_surface, &dds_caps,
985 &p_pic[0].p_sys->p_surface ) )
987 intf_WarnMsg( 3, "vout: NewPictureVec couldn't get "
989 /* front buffer is the same as back buffer */
990 p_pic[0].p_sys->p_surface = p_surface;
994 p_vout->p_sys->p_current_surface = front_pic.p_sys->p_surface =
995 p_pic[0].p_sys->p_front_surface;
997 /* reset the front buffer memory */
998 if( DirectXGetSurfaceDesc( &front_pic ) &&
999 UpdatePictureStruct( p_vout, &front_pic,
1000 p_vout->output.i_chroma ) )
1003 for( j = 0; j < front_pic.i_planes; j++ )
1004 memset( front_pic.p[j].p_pixels, 127,
1005 front_pic.p[j].i_lines * front_pic.p[j].i_pitch
1006 * front_pic.p[j].i_pixel_bytes );
1009 DirectXUpdateOverlay( p_vout );
1010 I_OUTPUTPICTURES = 1;
1011 intf_WarnMsg( 3,"vout: DirectX YUV overlay created successfully" );
1015 intf_WarnMsg( 3, "vout: can't create an YUV overlay surface." );
1016 p_vout->p_sys->b_using_overlay = 0;
1020 /* As we can't have an overlay, we'll try to create a plain offscreen
1021 * surface. This surface will reside in video memory because there's a
1022 * better chance then that we'll be able to use some kind of hardware
1023 * acceleration like rescaling, blitting or YUV->RGB conversions.
1024 * We then only need to blit this surface onto the main display when we
1025 * want to display it */
1026 if( !p_vout->p_sys->b_using_overlay )
1029 if( p_vout->p_sys->b_hw_yuv )
1030 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
1031 p_vout->output.i_chroma,
1032 p_vout->p_sys->b_using_overlay,
1033 0 /* no back buffers */ );
1035 if( !p_vout->p_sys->b_hw_yuv || !b_result_ok )
1037 /* Our last choice is to use a plain RGB surface */
1038 DDPIXELFORMAT ddpfPixelFormat;
1040 ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
1041 IDirectDrawSurface3_GetPixelFormat( p_vout->p_sys->p_display,
1044 if( ddpfPixelFormat.dwFlags & DDPF_RGB )
1046 switch( ddpfPixelFormat.dwRGBBitCount )
1048 case 8: /* FIXME: set the palette */
1049 p_vout->output.i_chroma = FOURCC_RGB2; break;
1051 p_vout->output.i_chroma = FOURCC_RV15; break;
1053 p_vout->output.i_chroma = FOURCC_RV16; break;
1055 p_vout->output.i_chroma = FOURCC_RV24; break;
1057 p_vout->output.i_chroma = FOURCC_RV32; break;
1059 intf_ErrMsg( "vout error: unknown screen depth" );
1062 p_vout->output.i_rmask = ddpfPixelFormat.dwRBitMask;
1063 p_vout->output.i_gmask = ddpfPixelFormat.dwGBitMask;
1064 p_vout->output.i_bmask = ddpfPixelFormat.dwBBitMask;
1067 p_vout->p_sys->b_hw_yuv = 0;
1069 b_result_ok = DirectXCreateSurface( p_vout, &p_surface,
1070 p_vout->output.i_chroma,
1071 p_vout->p_sys->b_using_overlay,
1072 0 /* no back buffers */ );
1077 /* Allocate internal structure */
1078 p_pic[0].p_sys = malloc( sizeof( picture_sys_t ) );
1079 if( p_pic[0].p_sys == NULL )
1081 DirectXCloseSurface( p_vout, p_surface );
1084 p_pic[0].p_sys->p_surface = p_pic[0].p_sys->p_front_surface
1087 I_OUTPUTPICTURES = 1;
1089 intf_WarnMsg( 3, "vout: DirectX plain surface created "
1093 intf_ErrMsg( "vout error: DirectX can't create plain surface." );
1097 /* Now that we've got all our direct-buffers, we can finish filling in the
1098 * picture_t structures */
1099 for( i = 0; i < I_OUTPUTPICTURES; i++ )
1101 p_pic[i].i_status = DESTROYED_PICTURE;
1102 p_pic[i].i_type = DIRECT_PICTURE;
1103 PP_OUTPUTPICTURE[i] = &p_pic[i];
1105 if( !DirectXGetSurfaceDesc( &p_pic[i] ) )
1108 FreePictureVec( p_vout, p_pic, I_OUTPUTPICTURES );
1109 I_OUTPUTPICTURES = 0;
1113 if( !UpdatePictureStruct(p_vout, &p_pic[i], p_vout->output.i_chroma) )
1116 /* Unknown chroma, tell the guy to get lost */
1117 intf_ErrMsg( "vout error: never heard of chroma 0x%.8x (%4.4s)",
1118 p_vout->output.i_chroma,
1119 (char*)&p_vout->output.i_chroma );
1120 FreePictureVec( p_vout, p_pic, I_OUTPUTPICTURES );
1121 I_OUTPUTPICTURES = 0;
1126 intf_WarnMsg( 3, "vout: End NewPictureVec");
1130 /*****************************************************************************
1131 * FreePicture: destroy a picture vector allocated with NewPictureVec
1132 *****************************************************************************
1134 *****************************************************************************/
1135 static void FreePictureVec( vout_thread_t *p_vout, picture_t *p_pic,
1140 for( i = 0; i < i_num_pics; i++ )
1142 DirectXCloseSurface( p_vout, p_pic[i].p_sys->p_front_surface );
1144 for( i = 0; i < i_num_pics; i++ )
1146 free( p_pic[i].p_sys );
1151 /*****************************************************************************
1152 * UpdatePictureStruct: updates the internal data in the picture_t structure
1153 *****************************************************************************
1154 * This will setup stuff for use by the video_output thread
1155 *****************************************************************************/
1156 static int UpdatePictureStruct( vout_thread_t *p_vout, picture_t *p_pic,
1160 switch( p_vout->output.i_chroma )
1168 p_pic->p->p_pixels = p_pic->p_sys->ddsd.lpSurface;
1169 p_pic->p->i_lines = p_vout->output.i_height;
1170 p_pic->p->i_pitch = p_pic->p_sys->ddsd.lPitch;
1171 p_pic->p->b_margin = 0;
1172 p_pic->i_planes = 1;
1173 switch( p_vout->output.i_chroma )
1176 p_pic->p->i_pixel_bytes = 1;
1180 p_pic->p->i_pixel_bytes = 2;
1184 p_pic->p->i_pixel_bytes = 4;
1193 p_pic->Y_PIXELS = p_pic->p_sys->ddsd.lpSurface;
1194 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1195 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->ddsd.lPitch;
1196 p_pic->p[Y_PLANE].i_pixel_bytes = 1;
1197 p_pic->p[Y_PLANE].b_margin = 0;
1199 p_pic->V_PIXELS = p_pic->Y_PIXELS
1200 + p_pic->p[Y_PLANE].i_lines * p_pic->p[Y_PLANE].i_pitch;
1201 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1202 p_pic->p[V_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1203 p_pic->p[V_PLANE].i_pixel_bytes = 1;
1204 p_pic->p[V_PLANE].b_margin = 0;
1206 p_pic->U_PIXELS = p_pic->V_PIXELS
1207 + p_pic->p[V_PLANE].i_lines * p_pic->p[V_PLANE].i_pitch;
1208 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1209 p_pic->p[U_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1210 p_pic->p[U_PLANE].i_pixel_bytes = 1;
1211 p_pic->p[U_PLANE].b_margin = 0;
1213 p_pic->i_planes = 3;
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_bytes = 1;
1222 p_pic->p[Y_PLANE].b_margin = 0;
1224 p_pic->U_PIXELS = p_pic->Y_PIXELS
1225 + p_pic->p[Y_PLANE].i_lines * p_pic->p[Y_PLANE].i_pitch;
1226 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1227 p_pic->p[U_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1228 p_pic->p[U_PLANE].i_pixel_bytes = 1;
1229 p_pic->p[U_PLANE].b_margin = 0;
1231 p_pic->V_PIXELS = p_pic->U_PIXELS
1232 + p_pic->p[U_PLANE].i_lines * p_pic->p[U_PLANE].i_pitch;
1233 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1234 p_pic->p[V_PLANE].i_pitch = p_pic->p[Y_PLANE].i_pitch / 2;
1235 p_pic->p[V_PLANE].i_pixel_bytes = 1;
1236 p_pic->p[V_PLANE].b_margin = 0;
1238 p_pic->i_planes = 3;
1250 /*****************************************************************************
1251 * DirectXGetDDrawCaps: Probe the capabilities of the hardware
1252 *****************************************************************************
1253 * It is nice to know which features are supported by the hardware so we can
1254 * find ways to optimize our rendering.
1255 *****************************************************************************/
1256 static void DirectXGetDDrawCaps( vout_thread_t *p_vout )
1261 /* This is just an indication of whether or not we'll support overlay,
1262 * but with this test we don't know if we support YUV overlay */
1263 memset( &ddcaps, 0, sizeof( DDCAPS ));
1264 ddcaps.dwSize = sizeof(DDCAPS);
1265 dxresult = IDirectDraw2_GetCaps( p_vout->p_sys->p_ddobject,
1267 if(dxresult != DD_OK )
1269 intf_WarnMsg( 3,"vout error: can't get caps." );
1273 BOOL bHasOverlay, bHasOverlayFourCC, bCanClipOverlay,
1274 bHasColorKey, bCanStretch;
1276 /* Determine if the hardware supports overlay surfaces */
1277 bHasOverlay = ((ddcaps.dwCaps & DDCAPS_OVERLAY) ==
1278 DDCAPS_OVERLAY) ? TRUE : FALSE;
1279 /* Determine if the hardware supports overlay surfaces */
1280 bHasOverlayFourCC = ((ddcaps.dwCaps & DDCAPS_OVERLAYFOURCC) ==
1281 DDCAPS_OVERLAYFOURCC) ? TRUE : FALSE;
1282 /* Determine if the hardware supports overlay surfaces */
1283 bCanClipOverlay = ((ddcaps.dwCaps & DDCAPS_OVERLAYCANTCLIP) ==
1285 /* Determine if the hardware supports colorkeying */
1286 bHasColorKey = ((ddcaps.dwCaps & DDCAPS_COLORKEY) ==
1287 DDCAPS_COLORKEY) ? TRUE : FALSE;
1288 /* Determine if the hardware supports scaling of the overlay surface */
1289 bCanStretch = ((ddcaps.dwCaps & DDCAPS_OVERLAYSTRETCH) ==
1290 DDCAPS_OVERLAYSTRETCH) ? TRUE : FALSE;
1291 intf_WarnMsg( 3, "vout: DirectDraw Capabilities:" );
1292 intf_WarnMsg( 3, " overlay=%i yuvoverlay=%i can_clip_overlay=%i "
1293 "colorkey=%i stretch=%i",
1294 bHasOverlay, bHasOverlayFourCC, bCanClipOverlay,
1295 bHasColorKey, bCanStretch );
1297 /* Overlay clipping support is interesting for us as it means we can
1298 * get rid of the colorkey alltogether */
1299 p_vout->p_sys->b_caps_overlay_clipping = bCanClipOverlay;
1304 /*****************************************************************************
1305 * DirectXGetSurfaceDesc: Get some more information about the surface
1306 *****************************************************************************
1307 * This function get and stores the surface descriptor which among things
1308 * has the pointer to the picture data.
1309 *****************************************************************************/
1310 static int DirectXGetSurfaceDesc( picture_t *p_pic )
1314 /* Lock the surface to get a valid pointer to the picture buffer */
1315 memset( &p_pic->p_sys->ddsd, 0, sizeof( DDSURFACEDESC ));
1316 p_pic->p_sys->ddsd.dwSize = sizeof(DDSURFACEDESC);
1317 dxresult = IDirectDrawSurface3_Lock( p_pic->p_sys->p_surface,
1318 NULL, &p_pic->p_sys->ddsd,
1319 DDLOCK_NOSYSLOCK | DDLOCK_WAIT,
1321 if ( dxresult == DDERR_SURFACELOST )
1323 /* Your surface can be lost so be sure
1324 * to check this and restore it if needed */
1325 dxresult = IDirectDrawSurface3_Restore( p_pic->p_sys->p_surface );
1326 dxresult = IDirectDrawSurface3_Lock( p_pic->p_sys->p_surface, NULL,
1327 &p_pic->p_sys->ddsd,
1328 DDLOCK_NOSYSLOCK | DDLOCK_WAIT,
1331 if( dxresult != DD_OK )
1333 intf_ErrMsg( "vout: DirectXGetSurfaceDesc can't lock surface" );
1337 /* Unlock the Surface */
1338 dxresult = IDirectDrawSurface3_Unlock( p_pic->p_sys->p_surface, NULL );