win95 fix fix by Rune Petersen <rune.mail-list at mail.tele.dk>
[mplayer/greg.git] / libvo / vo_directx.c
blobab1b9f6f6ed1a48b42e8cbf666bc2eed86f14f7d
1 /******************************************************************************
2 * vo_directx.c: Directx v2 or later DirectDraw interface for MPlayer
3 * Copyright (c) 2002 - 2004 Sascha Sommer <saschasommer@freenet.de>.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 *****************************************************************************/
21 #include <windows.h>
22 #include <windowsx.h>
23 #include <ddraw.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <errno.h>
27 #include "config.h"
28 #include "video_out.h"
29 #include "video_out_internal.h"
30 #include "fastmemcpy.h"
31 #include "input/input.h"
32 #include "osdep/keycodes.h"
33 #include "input/mouse.h"
34 #include "mp_msg.h"
35 #include "aspect.h"
36 #include "geometry.h"
38 #ifndef WM_XBUTTONDOWN
39 # define WM_XBUTTONDOWN 0x020B
40 # define WM_XBUTTONUP 0x020C
41 # define WM_XBUTTONDBLCLK 0x020D
42 #endif
44 static LPDIRECTDRAWCOLORCONTROL g_cc = NULL; //color control interface
45 static LPDIRECTDRAW7 g_lpdd = NULL; //DirectDraw Object
46 static LPDIRECTDRAWSURFACE7 g_lpddsPrimary = NULL; //Primary Surface: viewport through the Desktop
47 static LPDIRECTDRAWSURFACE7 g_lpddsOverlay = NULL; //Overlay Surface
48 static LPDIRECTDRAWSURFACE7 g_lpddsBack = NULL; //Back surface
49 static LPDIRECTDRAWCLIPPER g_lpddclipper; //clipper object, can only be used without overlay
50 static DDSURFACEDESC2 ddsdsf; //surface descripiton needed for locking
51 static HINSTANCE hddraw_dll; //handle to ddraw.dll
52 static RECT rd; //rect of our stretched image
53 static RECT rs; //rect of our source image
54 static HWND hWnd=NULL; //handle to the window
55 static HWND hWndFS=NULL; //fullscreen window
56 static uint32_t image_width, image_height; //image width and height
57 static uint32_t d_image_width, d_image_height; //image width and height zoomed
58 static uint8_t *image=NULL; //image data
59 static uint32_t image_format=0; //image format
60 static uint32_t primary_image_format;
61 static uint32_t vm_height=0;
62 static uint32_t vm_width=0;
63 static uint32_t vm_bpp=0;
64 static uint32_t dstride; //surface stride
65 static uint32_t nooverlay = 0; //NonOverlay mode
66 static DWORD destcolorkey; //colorkey for our surface
67 static COLORREF windowcolor = RGB(0,0,16); //windowcolor == colorkey
68 static int adapter_count=0;
69 static GUID selected_guid;
70 static GUID *selected_guid_ptr = NULL;
71 static RECT monitor_rect; //monitor coordinates
72 static float window_aspect;
73 static BOOL (WINAPI* myGetMonitorInfo)(HMONITOR, LPMONITORINFO) = NULL;
75 extern void mplayer_put_key(int code); //let mplayer handel the keyevents
76 extern void vo_draw_text(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride));
77 extern int vo_doublebuffering; //tribblebuffering
78 extern int vo_fs;
79 extern int vo_directrendering;
80 extern int vo_ontop;
81 extern int vo_rootwin;
82 extern int vidmode;
83 extern int vo_colorkey;
84 extern int WinID;
86 /*****************************************************************************
87 * DirectDraw GUIDs.
88 * Defining them here allows us to get rid of the dxguid library during
89 * the linking stage.
90 *****************************************************************************/
91 static const GUID IID_IDirectDraw7 =
93 0x15e65ec0,0x3b9c,0x11d2,{0xb9,0x2f,0x00,0x60,0x97,0x97,0xea,0x5b}
96 static const GUID IID_IDirectDrawColorControl =
98 0x4b9f0ee0,0x0d7e,0x11d0,{0x9b,0x06,0x00,0xa0,0xc9,0x03,0xa3,0xb8}
99 };
102 typedef struct directx_fourcc_caps
104 char* img_format_name; //human readable name
105 uint32_t img_format; //as MPlayer image format
106 uint32_t drv_caps; //what hw supports with this format
107 DDPIXELFORMAT g_ddpfOverlay; //as Directx Sourface description
108 } directx_fourcc_caps;
111 static directx_fourcc_caps g_ddpf[] =
113 {"YV12 ",IMGFMT_YV12 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','V','1','2'),0,0,0,0,0}},
114 {"I420 ",IMGFMT_I420 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('I','4','2','0'),0,0,0,0,0}}, //yv12 with swapped uv
115 {"IYUV ",IMGFMT_IYUV ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('I','Y','U','V'),0,0,0,0,0}}, //same as i420
116 {"YVU9 ",IMGFMT_YVU9 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','V','U','9'),0,0,0,0,0}},
117 {"YUY2 ",IMGFMT_YUY2 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','U','Y','2'),0,0,0,0,0}},
118 {"UYVY ",IMGFMT_UYVY ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('U','Y','V','Y'),0,0,0,0,0}},
119 {"RGB15",IMGFMT_RGB15,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000001F, 0x000003E0, 0x00007C00, 0}}, //RGB 5:5:5
120 {"BGR15",IMGFMT_BGR15,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x00007C00, 0x000003E0, 0x0000001F, 0}},
121 {"RGB16",IMGFMT_RGB16,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000001F, 0x000007E0, 0x0000F800, 0}}, //RGB 5:6:5
122 {"BGR16",IMGFMT_BGR16,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000F800, 0x000007E0, 0x0000001F, 0}},
123 {"RGB24",IMGFMT_RGB24,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0}},
124 {"BGR24",IMGFMT_BGR24,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0x00FF0000, 0x0000FF00, 0x000000FF, 0}},
125 {"RGB32",IMGFMT_RGB32,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0}},
126 {"BGR32",IMGFMT_BGR32,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0}}
128 #define NUM_FORMATS (sizeof(g_ddpf) / sizeof(g_ddpf[0]))
130 static vo_info_t info =
132 "Directx DDraw YUV/RGB/BGR renderer",
133 "directx",
134 "Sascha Sommer <saschasommer@freenet.de>",
138 LIBVO_EXTERN(directx)
140 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
141 unsigned char *srca, int stride)
143 switch(image_format) {
144 case IMGFMT_YV12 :
145 case IMGFMT_I420 :
146 case IMGFMT_IYUV :
147 case IMGFMT_YVU9 :
148 vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) image) + dstride*y0 + x0,dstride);
149 break;
150 case IMGFMT_YUY2 :
151 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) image)+ dstride*y0 + 2*x0 ,dstride);
152 break;
153 case IMGFMT_UYVY :
154 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) image) + dstride*y0 + 2*x0 + 1,dstride);
155 break;
156 case IMGFMT_RGB15:
157 case IMGFMT_BGR15:
158 vo_draw_alpha_rgb15(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+2*x0,dstride);
159 break;
160 case IMGFMT_RGB16:
161 case IMGFMT_BGR16:
162 vo_draw_alpha_rgb16(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+2*x0,dstride);
163 break;
164 case IMGFMT_RGB24:
165 case IMGFMT_BGR24:
166 vo_draw_alpha_rgb24(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+4*x0,dstride);
167 break;
168 case IMGFMT_RGB32:
169 case IMGFMT_BGR32:
170 vo_draw_alpha_rgb32(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+4*x0,dstride);
171 break;
175 static void draw_osd(void)
177 vo_draw_text(image_width,image_height,draw_alpha);
180 static uint32_t
181 query_format(uint32_t format)
183 uint32_t i=0;
184 while ( i < NUM_FORMATS )
186 if (g_ddpf[i].img_format == format)
187 return g_ddpf[i].drv_caps;
188 i++;
190 return 0;
193 static uint32_t Directx_CreatePrimarySurface()
195 DDSURFACEDESC2 ddsd;
196 //cleanup
197 if(g_lpddsPrimary)g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
198 g_lpddsPrimary=NULL;
200 if(vidmode)g_lpdd->lpVtbl->SetDisplayMode(g_lpdd,vm_width,vm_height,vm_bpp,vo_refresh_rate,0);
201 ZeroMemory(&ddsd, sizeof(ddsd));
202 ddsd.dwSize = sizeof(ddsd);
203 //set flags and create a primary surface.
204 ddsd.dwFlags = DDSD_CAPS;
205 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
206 if(g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsd, &g_lpddsPrimary, NULL )== DD_OK)
207 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>primary surface created\n");
208 else
210 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>could not create primary surface\n");
211 return 1;
213 return 0;
216 static uint32_t Directx_CreateOverlay(uint32_t imgfmt)
218 HRESULT ddrval;
219 DDSURFACEDESC2 ddsdOverlay;
220 uint32_t i=0;
221 while ( i < NUM_FORMATS +1 && imgfmt != g_ddpf[i].img_format)
223 i++;
225 if (!g_lpdd || !g_lpddsPrimary)
226 return 1;
227 //cleanup
228 if (g_lpddsOverlay)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);
229 if (g_lpddsBack)g_lpddsBack->lpVtbl->Release(g_lpddsBack);
230 g_lpddsOverlay= NULL;
231 g_lpddsBack = NULL;
232 //create our overlay
233 ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay));
234 ddsdOverlay.dwSize = sizeof(ddsdOverlay);
235 ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY;
236 ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_BACKBUFFERCOUNT| DDSD_PIXELFORMAT;
237 ddsdOverlay.dwWidth=image_width;
238 ddsdOverlay.dwHeight=image_height;
239 ddsdOverlay.dwBackBufferCount=2;
240 ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay;
241 if(vo_doublebuffering) //tribblebuffering
243 if (g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL)== DD_OK)
245 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>overlay with format %s created\n",g_ddpf[i].img_format_name);
246 //get the surface directly attached to the primary (the back buffer)
247 ddsdOverlay.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
248 if(g_lpddsOverlay->lpVtbl->GetAttachedSurface(g_lpddsOverlay,&ddsdOverlay.ddsCaps, &g_lpddsBack) != DD_OK)
250 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't get attached surface\n");
251 return 1;
253 return 0;
255 vo_doublebuffering=0; //disable tribblebuffering
256 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><WARN>cannot create tribblebuffer overlay with format %s\n",g_ddpf[i].img_format_name);
258 //single buffer
259 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>using singlebuffer overlay\n");
260 ddsdOverlay.dwBackBufferCount=0;
261 ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;
262 ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT;
263 ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay;
264 // try to create the overlay surface
265 ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL);
266 if(ddrval != DD_OK)
268 if(ddrval == DDERR_INVALIDPIXELFORMAT)mp_msg(MSGT_VO,MSGL_V,"<vo_directx><ERROR> invalid pixelformat: %s\n",g_ddpf[i].img_format_name);
269 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>");
270 switch(ddrval)
272 case DDERR_INCOMPATIBLEPRIMARY:
273 {mp_msg(MSGT_VO, MSGL_ERR,"incompatible primary surface\n");break;}
274 case DDERR_INVALIDCAPS:
275 {mp_msg(MSGT_VO, MSGL_ERR,"invalid caps\n");break;}
276 case DDERR_INVALIDOBJECT:
277 {mp_msg(MSGT_VO, MSGL_ERR,"invalid object\n");break;}
278 case DDERR_INVALIDPARAMS:
279 {mp_msg(MSGT_VO, MSGL_ERR,"invalid parameters\n");break;}
280 case DDERR_NODIRECTDRAWHW:
281 {mp_msg(MSGT_VO, MSGL_ERR,"no directdraw hardware\n");break;}
282 case DDERR_NOEMULATION:
283 {mp_msg(MSGT_VO, MSGL_ERR,"can't emulate\n");break;}
284 case DDERR_NOFLIPHW:
285 {mp_msg(MSGT_VO, MSGL_ERR,"hardware can't do flip\n");break;}
286 case DDERR_NOOVERLAYHW:
287 {mp_msg(MSGT_VO, MSGL_ERR,"hardware can't do overlay\n");break;}
288 case DDERR_OUTOFMEMORY:
289 {mp_msg(MSGT_VO, MSGL_ERR,"not enough system memory\n");break;}
290 case DDERR_UNSUPPORTEDMODE:
291 {mp_msg(MSGT_VO, MSGL_ERR,"unsupported mode\n");break;}
292 case DDERR_OUTOFVIDEOMEMORY:
293 {mp_msg(MSGT_VO, MSGL_ERR,"not enough video memory\n");break;}
294 default:
295 mp_msg(MSGT_VO, MSGL_ERR,"create surface failed with 0x%x\n",ddrval);
297 return 1;
299 g_lpddsBack = g_lpddsOverlay;
300 return 0;
303 static uint32_t Directx_CreateBackpuffer()
305 DDSURFACEDESC2 ddsd;
306 //cleanup
307 if (g_lpddsBack)g_lpddsBack->lpVtbl->Release(g_lpddsBack);
308 g_lpddsBack=NULL;
309 ZeroMemory(&ddsd, sizeof(ddsd));
310 ddsd.dwSize = sizeof(ddsd);
311 ddsd.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
312 ddsd.dwFlags= DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
313 ddsd.dwWidth=image_width;
314 ddsd.dwHeight=image_height;
315 if(g_lpdd->lpVtbl->CreateSurface( g_lpdd, &ddsd, &g_lpddsBack, 0 ) != DD_OK )
317 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't create backpuffer\n");
318 return 1;
320 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>backbuffer created\n");
321 return 0;
324 static void uninit(void)
326 if (g_cc != NULL)
328 g_cc->lpVtbl->Release(g_cc);
330 g_cc=NULL;
331 if (g_lpddclipper != NULL) g_lpddclipper->lpVtbl->Release(g_lpddclipper);
332 g_lpddclipper = NULL;
333 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>clipper released\n");
334 if (g_lpddsBack != NULL) g_lpddsBack->lpVtbl->Release(g_lpddsBack);
335 g_lpddsBack = NULL;
336 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>back surface released\n");
337 if(vo_doublebuffering && !nooverlay)
339 if (g_lpddsOverlay != NULL)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);
340 g_lpddsOverlay = NULL;
341 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>overlay surface released\n");
343 if (g_lpddsPrimary != NULL) g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
344 g_lpddsPrimary = NULL;
345 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>primary released\n");
346 if(hWndFS)DestroyWindow(hWndFS);
347 if(hWnd != NULL)DestroyWindow(hWnd);
348 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>window destroyed\n");
349 if (g_lpdd != NULL){
350 if(vidmode)g_lpdd->lpVtbl->RestoreDisplayMode(g_lpdd);
351 g_lpdd->lpVtbl->Release(g_lpdd);
353 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>directdrawobject released\n");
354 FreeLibrary( hddraw_dll);
355 hddraw_dll= NULL;
356 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>ddraw.dll freed\n");
357 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>uninited\n");
360 static BOOL WINAPI EnumCallbackEx(GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm)
362 mp_msg(MSGT_VO, MSGL_INFO ,"<vo_directx> adapter %d: ", adapter_count);
364 if (!lpGUID)
366 mp_msg(MSGT_VO, MSGL_INFO ,"%s", "Primary Display Adapter");
368 else
370 mp_msg(MSGT_VO, MSGL_INFO ,"%s", lpDriverDescription);
373 if(adapter_count == vo_adapter_num){
374 MONITORINFO mi;
375 if (!lpGUID)
376 selected_guid_ptr = NULL;
377 else
379 selected_guid = *lpGUID;
380 selected_guid_ptr = &selected_guid;
382 mi.cbSize = sizeof(mi);
384 if (myGetMonitorInfo(hm, &mi)) {
385 monitor_rect = mi.rcMonitor;
387 mp_msg(MSGT_VO, MSGL_INFO ,"\t\t<--");
389 mp_msg(MSGT_VO, MSGL_INFO ,"\n");
391 adapter_count++;
393 return 1; // list all adapters
396 static uint32_t Directx_InitDirectDraw()
398 HRESULT (WINAPI *OurDirectDrawCreateEx)(GUID *,LPVOID *, REFIID,IUnknown FAR *);
399 LPDIRECTDRAW lpDDraw;
400 DDSURFACEDESC2 ddsd;
401 LPDIRECTDRAWENUMERATEEX OurDirectDrawEnumerateEx;
402 HINSTANCE user32dll=LoadLibrary("user32.dll");
404 if(user32dll){
405 myGetMonitorInfo=GetProcAddress(user32dll,"GetMonitorInfoA");
406 if(!myGetMonitorInfo && vo_adapter_num){
407 mp_msg(MSGT_VO, MSGL_ERR, "<vo_directx> -adapter is not supported on Win95\n");
408 vo_adapter_num = 0;
412 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>Initing DirectDraw\n" );
414 //load direct draw DLL: based on videolans code
415 hddraw_dll = LoadLibrary("DDRAW.DLL");
416 if( hddraw_dll == NULL )
418 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed loading ddraw.dll\n" );
419 return 1;
422 if(vo_adapter_num){ //display other than default
423 OurDirectDrawEnumerateEx = (LPDIRECTDRAWENUMERATEEX) GetProcAddress(hddraw_dll,"DirectDrawEnumerateExA");
424 if (!OurDirectDrawEnumerateEx){
425 FreeLibrary( hddraw_dll );
426 hddraw_dll = NULL;
427 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed geting proc address: DirectDrawEnumerateEx\n");
428 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>no directx 7 or higher installed\n");
429 return 1;
432 // enumerate all display devices attached to the desktop
433 OurDirectDrawEnumerateEx(EnumCallbackEx, NULL, DDENUM_ATTACHEDSECONDARYDEVICES );
435 if(vo_adapter_num >= adapter_count)
436 mp_msg(MSGT_VO, MSGL_ERR,"Selected adapter (%d) doesn't exist: Default Display Adapter selected\n",vo_adapter_num);
438 FreeLibrary(user32dll);
440 OurDirectDrawCreateEx = (void *)GetProcAddress(hddraw_dll, "DirectDrawCreateEx");
441 if ( OurDirectDrawCreateEx == NULL )
443 FreeLibrary( hddraw_dll );
444 hddraw_dll = NULL;
445 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed geting proc address: DirectDrawCreateEx\n");
446 return 1;
449 // initialize DirectDraw and create directx v7 object
450 if (OurDirectDrawCreateEx(selected_guid_ptr, (VOID**)&g_lpdd, &IID_IDirectDraw7, NULL ) != DD_OK )
452 FreeLibrary( hddraw_dll );
453 hddraw_dll = NULL;
454 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't initialize ddraw\n");
455 return 1;
458 //get current screen siz for selected monitor ...
459 ddsd.dwSize=sizeof(ddsd);
460 ddsd.dwFlags=DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
461 g_lpdd->lpVtbl->GetDisplayMode(g_lpdd, &ddsd);
462 if(vo_screenwidth && vo_screenheight)
464 vm_height=vo_screenheight;
465 vm_width=vo_screenwidth;
467 else
469 vm_height=ddsd.dwHeight;
470 vm_width=ddsd.dwWidth;
474 if(vo_dbpp)vm_bpp=vo_dbpp;
475 else vm_bpp=ddsd.ddpfPixelFormat.dwRGBBitCount;
477 if(vidmode){
478 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, hWnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN) != DD_OK)
480 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set cooperativelevel for exclusive mode\n");
481 return 1;
483 /*SetDisplayMode(ddobject,width,height,bpp,refreshrate,aditionalflags)*/
484 if(g_lpdd->lpVtbl->SetDisplayMode(g_lpdd,vm_width, vm_height, vm_bpp,0,0) != DD_OK)
486 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set displaymode\n");
487 return 1;
489 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>Inited adapter %i for %i x %i @ %i \n",vo_adapter_num,vm_width,vm_height,vm_bpp);
490 return 0;
492 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, hWnd, DDSCL_NORMAL) != DD_OK) // or DDSCL_SETFOCUSWINDOW
494 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>could not set cooperativelevel for hardwarecheck\n");
495 return 1;
497 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>DirectDraw Inited\n");
498 return 0;
501 static void check_events(void)
503 MSG msg;
504 while (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
506 TranslateMessage(&msg);
507 DispatchMessage(&msg);
511 static uint32_t Directx_ManageDisplay()
513 HRESULT ddrval;
514 DDCAPS capsDrv;
515 DDOVERLAYFX ovfx;
516 DWORD dwUpdateFlags=0;
517 int width,height;
519 if(vo_fs || vidmode){
520 aspect(&width,&height,A_ZOOM);
521 rd.left=(vo_screenwidth-width)/2;
522 rd.top=(vo_screenheight-height)/2;
523 if(ShowCursor(FALSE)>=0)while(ShowCursor(FALSE)>=0){}
525 else if (WinID != -1 && vo_geometry) {
526 POINT pt;
527 pt.x = vo_dx;
528 pt.y = vo_dy;
529 ClientToScreen(hWnd,&pt);
530 width=d_image_width;
531 height=d_image_height;
532 rd.left = pt.x;
533 rd.top = pt.y;
534 while(ShowCursor(TRUE)<=0){}
536 else {
537 POINT pt;
538 pt.x = 0; //overlayposition relative to the window
539 pt.y = 0;
540 ClientToScreen(hWnd,&pt);
541 GetClientRect(hWnd, &rd);
542 width=rd.right - rd.left;
543 height=rd.bottom - rd.top;
544 pt.x -= monitor_rect.left; /* move coordinates from global to local monitor space */
545 pt.y -= monitor_rect.top;
546 rd.right -= monitor_rect.left;
547 rd.bottom -= monitor_rect.top;
548 rd.left = pt.x;
549 rd.top = pt.y;
550 if(!nooverlay && (!width || !height)){
551 /*window is minimized*/
552 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL);
553 return 0;
555 if(vo_keepaspect){
556 int tmpheight=((float)width/window_aspect);
557 tmpheight+=tmpheight%2;
558 if(tmpheight > height){
559 width=((float)height*window_aspect);
560 width+=width%2;
562 else height=tmpheight;
564 while(ShowCursor(TRUE)<=0){}
566 rd.right=rd.left+width;
567 rd.bottom=rd.top+height;
569 /*ok, let's workaround some overlay limitations*/
570 if(!nooverlay)
572 uint32_t uStretchFactor1000; //minimum stretch
573 uint32_t xstretch1000,ystretch1000;
574 /*get driver capabilities*/
575 ZeroMemory(&capsDrv, sizeof(capsDrv));
576 capsDrv.dwSize = sizeof(capsDrv);
577 if(g_lpdd->lpVtbl->GetCaps(g_lpdd,&capsDrv, NULL) != DD_OK)return 1;
578 /*get minimum stretch, depends on display adaptor and mode (refresh rate!) */
579 uStretchFactor1000 = capsDrv.dwMinOverlayStretch>1000 ? capsDrv.dwMinOverlayStretch : 1000;
580 rd.right = ((width+rd.left)*uStretchFactor1000+999)/1000;
581 rd.bottom = (height+rd.top)*uStretchFactor1000/1000;
582 /*calculate xstretch1000 and ystretch1000*/
583 xstretch1000 = ((rd.right - rd.left)* 1000)/image_width ;
584 ystretch1000 = ((rd.bottom - rd.top)* 1000)/image_height;
585 rs.left=0;
586 rs.right=image_width;
587 rs.top=0;
588 rs.bottom=image_height;
589 if(rd.left < 0)rs.left=(-rd.left*1000)/xstretch1000;
590 if(rd.top < 0)rs.top=(-rd.top*1000)/ystretch1000;
591 if(rd.right > vo_screenwidth)rs.right=((vo_screenwidth-rd.left)*1000)/xstretch1000;
592 if(rd.bottom > vo_screenheight)rs.bottom=((vo_screenheight-rd.top)*1000)/ystretch1000;
593 /*do not allow to zoom or shrink if hardware isn't able to do so*/
594 if((width < image_width)&& !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKX))
596 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKXN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only shrinkN\n");
597 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't shrink x\n");
598 rd.right=rd.left+image_width;
600 else if((width > image_width)&& !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHX))
602 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHXN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only stretchN\n");
603 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't stretch x\n");
604 rd.right = rd.left+image_width;
606 if((height < image_height) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKY))
608 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKYN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only shrinkN\n");
609 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't shrink y\n");
610 rd.bottom = rd.top + image_height;
612 else if((height > image_height ) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHY))
614 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHYN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only stretchN\n");
615 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't stretch y\n");
616 rd.bottom = rd.top + image_height;
618 /*the last thing to check are alignment restrictions
619 these expressions (x & -y) just do alignment by dropping low order bits...
620 so to round up, we add first, then truncate*/
621 if((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYSRC) && capsDrv.dwAlignBoundarySrc)
622 rs.left = (rs.left + capsDrv.dwAlignBoundarySrc / 2) & -(signed)(capsDrv.dwAlignBoundarySrc);
623 if((capsDrv.dwCaps & DDCAPS_ALIGNSIZESRC) && capsDrv.dwAlignSizeSrc)
624 rs.right = rs.left + ((rs.right - rs.left + capsDrv.dwAlignSizeSrc / 2) & -(signed) (capsDrv.dwAlignSizeSrc));
625 if((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYDEST) && capsDrv.dwAlignBoundaryDest)
626 rd.left = (rd.left + capsDrv.dwAlignBoundaryDest / 2) & -(signed)(capsDrv.dwAlignBoundaryDest);
627 if((capsDrv.dwCaps & DDCAPS_ALIGNSIZEDEST) && capsDrv.dwAlignSizeDest)
628 rd.right = rd.left + ((rd.right - rd.left) & -(signed) (capsDrv.dwAlignSizeDest));
629 /*create an overlay FX structure to specify a destination color key*/
630 ZeroMemory(&ovfx, sizeof(ovfx));
631 ovfx.dwSize = sizeof(ovfx);
632 if(vo_fs||vidmode)
634 ovfx.dckDestColorkey.dwColorSpaceLowValue = 0;
635 ovfx.dckDestColorkey.dwColorSpaceHighValue = 0;
637 else
639 ovfx.dckDestColorkey.dwColorSpaceLowValue = destcolorkey;
640 ovfx.dckDestColorkey.dwColorSpaceHighValue = destcolorkey;
642 // set the flags we'll send to UpdateOverlay //DDOVER_AUTOFLIP|DDOVERFX_MIRRORLEFTRIGHT|DDOVERFX_MIRRORUPDOWN could be usefull?;
643 dwUpdateFlags = DDOVER_SHOW | DDOVER_DDFX;
644 /*if hardware can't do colorkeying set the window on top*/
645 if(capsDrv.dwCKeyCaps & DDCKEYCAPS_DESTOVERLAY) dwUpdateFlags |= DDOVER_KEYDESTOVERRIDE;
646 else vo_ontop = 1;
648 else
650 g_lpddclipper->lpVtbl->SetHWnd(g_lpddclipper, 0,(vo_fs && !vidmode)?hWndFS: hWnd);
653 if(!vidmode && !vo_fs){
654 if(WinID == -1) {
655 RECT rdw=rd;
656 AdjustWindowRect(&rdw,WS_OVERLAPPEDWINDOW|WS_SIZEBOX,FALSE);
657 // printf("window: %i %i %ix%i\n",rdw.left,rdw.top,rdw.right - rdw.left,rdw.bottom - rdw.top);
658 rdw.left += monitor_rect.left; /* move to global coordinate space */
659 rdw.top += monitor_rect.top;
660 rdw.right += monitor_rect.left;
661 rdw.bottom += monitor_rect.top;
662 SetWindowPos(hWnd,(vo_ontop)?HWND_TOPMOST:(vo_rootwin?HWND_BOTTOM:HWND_NOTOPMOST),rdw.left,rdw.top,rdw.right-rdw.left,rdw.bottom-rdw.top,SWP_NOOWNERZORDER);
665 else SetWindowPos(vidmode?hWnd:hWndFS,vo_rootwin?HWND_BOTTOM:HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOOWNERZORDER);
667 /*make sure the overlay is inside the screen*/
668 if(rd.left<0)rd.left=0;
669 if(rd.right>vo_screenwidth)rd.right=vo_screenwidth;
670 if(rd.top<0)rd.top=0;
671 if(rd.bottom>vo_screenheight)rd.bottom=vo_screenheight;
673 /*for nonoverlay mode we are finished, for overlay mode we have to display the overlay first*/
674 if(nooverlay)return 0;
676 // printf("overlay: %i %i %ix%i\n",rd.left,rd.top,rd.right - rd.left,rd.bottom - rd.top);
677 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,&rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx);
678 if(FAILED(ddrval))
680 // one cause might be the driver lied about minimum stretch
681 // we should try upping the destination size a bit, or
682 // perhaps shrinking the source size
683 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>UpdateOverlay failed\n" );
684 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>Overlay:x1:%i,y1:%i,x2:%i,y2:%i,w:%i,h:%i\n",rd.left,rd.top,rd.right,rd.bottom,rd.right - rd.left,rd.bottom - rd.top );
685 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>");
686 switch (ddrval)
688 case DDERR_NOSTRETCHHW:
689 {mp_msg(MSGT_VO, MSGL_ERR ,"hardware can't stretch: try to size the window back\n");break;}
690 case DDERR_INVALIDRECT:
691 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid rectangle\n");break;}
692 case DDERR_INVALIDPARAMS:
693 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid parameters\n");break;}
694 case DDERR_HEIGHTALIGN:
695 {mp_msg(MSGT_VO, MSGL_ERR ,"height align\n");break;}
696 case DDERR_XALIGN:
697 {mp_msg(MSGT_VO, MSGL_ERR ,"x align\n");break;}
698 case DDERR_UNSUPPORTED:
699 {mp_msg(MSGT_VO, MSGL_ERR ,"unsupported\n");break;}
700 case DDERR_INVALIDSURFACETYPE:
701 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid surfacetype\n");break;}
702 case DDERR_INVALIDOBJECT:
703 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid object\n");break;}
704 case DDERR_SURFACELOST:
706 mp_msg(MSGT_VO, MSGL_ERR ,"surfaces lost\n");
707 g_lpddsOverlay->lpVtbl->Restore( g_lpddsOverlay ); //restore and try again
708 g_lpddsPrimary->lpVtbl->Restore( g_lpddsPrimary );
709 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,&rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx);
710 if(ddrval !=DD_OK)mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>UpdateOverlay failed again\n" );
711 break;
713 default:
714 mp_msg(MSGT_VO, MSGL_ERR ," 0x%x\n",ddrval);
716 /*ok we can't do anything about it -> hide overlay*/
717 if(ddrval != DD_OK)
719 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL);
720 return 1;
723 return 0;
726 //find out supported overlay pixelformats
727 static uint32_t Directx_CheckOverlayPixelformats()
729 DDCAPS capsDrv;
730 HRESULT ddrval;
731 DDSURFACEDESC2 ddsdOverlay;
732 uint32_t i;
733 uint32_t formatcount = 0;
734 //get driver caps to determine overlay support
735 ZeroMemory(&capsDrv, sizeof(capsDrv));
736 capsDrv.dwSize = sizeof(capsDrv);
737 ddrval = g_lpdd->lpVtbl->GetCaps(g_lpdd,&capsDrv, NULL);
738 if (FAILED(ddrval))
740 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>failed getting ddrawcaps\n");
741 return 1;
743 if (!(capsDrv.dwCaps & DDCAPS_OVERLAY))
745 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>Your card doesn't support overlay\n");
746 return 1;
748 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>testing supported overlay pixelformats\n");
749 //it is not possible to query for pixel formats supported by the
750 //overlay hardware: try out various formats till one works
751 ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay));
752 ddsdOverlay.dwSize = sizeof(ddsdOverlay);
753 ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;
754 ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH| DDSD_PIXELFORMAT;
755 ddsdOverlay.dwWidth=300;
756 ddsdOverlay.dwHeight=280;
757 ddsdOverlay.dwBackBufferCount=0;
758 //try to create an overlay surface using one of the pixel formats in our global list
759 i=0;
762 ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay;
763 ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL);
764 if (ddrval == DD_OK)
766 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT OVERLAY>%i %s supported\n",i,g_ddpf[i].img_format_name);
767 g_ddpf[i].drv_caps = VFCAP_CSP_SUPPORTED |VFCAP_OSD |VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP;
768 formatcount++;}
769 else mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT OVERLAY>%i %s not supported\n",i,g_ddpf[i].img_format_name);
770 if (g_lpddsOverlay != NULL) {g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);g_lpddsOverlay = NULL;}
771 } while( ++i < NUM_FORMATS );
772 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>Your card supports %i of %i overlayformats\n",formatcount, NUM_FORMATS);
773 if (formatcount == 0)
775 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><WARN>Your card supports overlay, but we couldn't create one\n");
776 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>This can have the following reasons:\n");
777 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- you are already using an overlay with another app\n");
778 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- you don't have enough videomemory\n");
779 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- vo_directx doesn't support the cards overlay pixelformat\n");
780 return 1;
782 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYMIRRORLEFTRIGHT)mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>can mirror left right\n"); //I don't have hardware which
783 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYMIRRORUPDOWN )mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>can mirror up down\n"); //supports those send me one and I'll implement ;)
784 return 0;
787 //find out the Pixelformat of the Primary Surface
788 static uint32_t Directx_CheckPrimaryPixelformat()
790 uint32_t i=0;
791 uint32_t formatcount = 0;
792 DDPIXELFORMAT ddpf;
793 DDSURFACEDESC2 ddsd;
794 HDC hdc;
795 HRESULT hres;
796 COLORREF rgbT=RGB(0,0,0);
797 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>checking primary surface\n");
798 memset( &ddpf, 0, sizeof( DDPIXELFORMAT ));
799 ddpf.dwSize = sizeof( DDPIXELFORMAT );
800 //we have to create a primary surface first
801 if(Directx_CreatePrimarySurface()!=0)return 1;
802 if(g_lpddsPrimary->lpVtbl->GetPixelFormat( g_lpddsPrimary, &ddpf ) != DD_OK )
804 mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>can't get pixelformat\n");
805 return 1;
807 while ( i < NUM_FORMATS )
809 if (g_ddpf[i].g_ddpfOverlay.dwRGBBitCount == ddpf.dwRGBBitCount)
811 if (g_ddpf[i].g_ddpfOverlay.dwRBitMask == ddpf.dwRBitMask)
813 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT PRIMARY>%i %s supported\n",i,g_ddpf[i].img_format_name);
814 g_ddpf[i].drv_caps = VFCAP_CSP_SUPPORTED |VFCAP_OSD;
815 formatcount++;
816 primary_image_format=g_ddpf[i].img_format;
819 i++;
821 //get the colorkey for overlay mode
822 destcolorkey = CLR_INVALID;
823 if (windowcolor != CLR_INVALID && g_lpddsPrimary->lpVtbl->GetDC(g_lpddsPrimary,&hdc) == DD_OK)
825 rgbT = GetPixel(hdc, 0, 0);
826 SetPixel(hdc, 0, 0, windowcolor);
827 g_lpddsPrimary->lpVtbl->ReleaseDC(g_lpddsPrimary,hdc);
829 // read back the converted color
830 ddsd.dwSize = sizeof(ddsd);
831 while ((hres = g_lpddsPrimary->lpVtbl->Lock(g_lpddsPrimary,NULL, &ddsd, 0, NULL)) == DDERR_WASSTILLDRAWING)
833 if (hres == DD_OK)
835 destcolorkey = *(DWORD *) ddsd.lpSurface;
836 if (ddsd.ddpfPixelFormat.dwRGBBitCount < 32)
837 destcolorkey &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1;
838 g_lpddsPrimary->lpVtbl->Unlock(g_lpddsPrimary,NULL);
840 if (windowcolor != CLR_INVALID && g_lpddsPrimary->lpVtbl->GetDC(g_lpddsPrimary,&hdc) == DD_OK)
842 SetPixel(hdc, 0, 0, rgbT);
843 g_lpddsPrimary->lpVtbl->ReleaseDC(g_lpddsPrimary,hdc);
845 //release primary
846 g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
847 g_lpddsPrimary = NULL;
848 if(formatcount==0)
850 mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>Unknown Pixelformat\n");
851 return 1;
853 return 0;
856 //function handles input
857 static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
859 switch (message)
861 case WM_MOUSEACTIVATE:
862 return MA_ACTIVATEANDEAT;
863 case WM_NCACTIVATE:
865 if(vidmode && adapter_count > 2) //only disable if more than one adapter.
866 return 0;
867 break;
869 case WM_DESTROY:
871 PostQuitMessage(0);
872 return 0;
874 case WM_CLOSE:
876 mp_input_queue_cmd(mp_input_parse_cmd("quit"));
877 return 0;
879 case WM_WINDOWPOSCHANGED:
881 //printf("Windowposchange\n");
882 if(g_lpddsBack != NULL) //or it will crash with -vm
884 Directx_ManageDisplay();
886 break;
888 case WM_SYSCOMMAND:
890 switch (wParam)
891 { //kill screensaver etc.
892 //note: works only when the window is active
893 //you can workaround this by disabling the allow screensaver option in
894 //the link to the app
895 case SC_SCREENSAVE:
896 case SC_MONITORPOWER:
897 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>killing screensaver\n" );
898 return 0;
901 case WM_KEYDOWN:
903 switch (wParam)
905 case VK_LEFT:
906 {mplayer_put_key(KEY_LEFT);break;}
907 case VK_UP:
908 {mplayer_put_key(KEY_UP);break;}
909 case VK_RIGHT:
910 {mplayer_put_key(KEY_RIGHT);break;}
911 case VK_DOWN:
912 {mplayer_put_key(KEY_DOWN);break;}
913 case VK_TAB:
914 {mplayer_put_key(KEY_TAB);break;}
915 case VK_BACK:
916 {mplayer_put_key(KEY_BS);break;}
917 case VK_DELETE:
918 {mplayer_put_key(KEY_DELETE);break;}
919 case VK_INSERT:
920 {mplayer_put_key(KEY_INSERT);break;}
921 case VK_HOME:
922 {mplayer_put_key(KEY_HOME);break;}
923 case VK_END:
924 {mplayer_put_key(KEY_END);break;}
925 case VK_PRIOR:
926 {mplayer_put_key(KEY_PAGE_UP);break;}
927 case VK_NEXT:
928 {mplayer_put_key(KEY_PAGE_DOWN);break;}
929 case VK_ESCAPE:
930 {mplayer_put_key(KEY_ESC);break;}
932 break;
934 case WM_CHAR:
936 mplayer_put_key(wParam);
937 break;
939 case WM_LBUTTONDOWN:
941 if (!vo_nomouse_input)
942 mplayer_put_key(MOUSE_BTN0);
943 break;
945 case WM_MBUTTONDOWN:
947 if (!vo_nomouse_input)
948 mplayer_put_key(MOUSE_BTN1);
949 break;
951 case WM_RBUTTONDOWN:
953 if (!vo_nomouse_input)
954 mplayer_put_key(MOUSE_BTN2);
955 break;
957 case WM_MOUSEWHEEL:
959 if (vo_nomouse_input)
960 break;
961 int x = GET_WHEEL_DELTA_WPARAM(wParam);
962 if (x > 0)
963 mplayer_put_key(MOUSE_BTN3);
964 else
965 mplayer_put_key(MOUSE_BTN4);
966 break;
968 case WM_XBUTTONDOWN:
970 if (vo_nomouse_input)
971 break;
972 if (HIWORD(wParam) == 1)
973 mplayer_put_key(MOUSE_BTN5);
974 else
975 mplayer_put_key(MOUSE_BTN6);
976 break;
980 return DefWindowProc(hWnd, message, wParam, lParam);
984 static uint32_t preinit(const char *arg)
986 HINSTANCE hInstance = GetModuleHandle(NULL);
987 HICON mplayericon=NULL;
988 char exedir[MAX_PATH];
989 WNDCLASS wc;
990 if(arg)
992 if(strstr(arg,"noaccel"))
994 mp_msg(MSGT_VO,MSGL_V,"<vo_directx><INFO>disabled overlay\n");
995 nooverlay = 1;
998 /*load icon from the main app*/
999 if(GetModuleFileName(NULL,exedir,MAX_PATH))
1001 mplayericon = ExtractIcon( hInstance, exedir, 0 );
1003 if(!mplayericon)mplayericon=LoadIcon(NULL,IDI_APPLICATION);
1004 monitor_rect.right=GetSystemMetrics(SM_CXSCREEN);
1005 monitor_rect.bottom=GetSystemMetrics(SM_CYSCREEN);
1007 windowcolor = vo_colorkey;
1008 wc.style = CS_HREDRAW | CS_VREDRAW;
1009 wc.lpfnWndProc = WndProc;
1010 wc.cbClsExtra = 0;
1011 wc.cbWndExtra = 0;
1012 wc.hInstance = hInstance;
1013 wc.hCursor = LoadCursor(NULL,IDC_ARROW);
1014 wc.hIcon = mplayericon;
1015 wc.hbrBackground = CreateSolidBrush(vidmode?RGB(0,0,0):windowcolor);
1016 wc.lpszClassName = "MPlayer - The Movie Player";
1017 wc.lpszMenuName = NULL;
1018 RegisterClass(&wc);
1019 if (WinID != -1) hWnd = WinID;
1020 else
1021 hWnd = CreateWindowEx(vidmode?WS_EX_TOPMOST:0,
1022 "MPlayer - The Movie Player","",(vidmode)?WS_POPUP:WS_OVERLAPPEDWINDOW| WS_SIZEBOX,
1023 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,NULL,NULL,hInstance,NULL);
1024 wc.hbrBackground = CreateSolidBrush(RGB(0,0,0));
1025 wc.lpszClassName = "MPlayer - Fullscreen";
1026 RegisterClass(&wc);
1028 if (Directx_InitDirectDraw()!= 0)return 1; //init DirectDraw
1030 if(!vidmode)hWndFS = CreateWindow("MPlayer - Fullscreen","MPlayer Fullscreen",WS_POPUP,monitor_rect.left,monitor_rect.top,monitor_rect.right-monitor_rect.left,monitor_rect.bottom-monitor_rect.top,hWnd,NULL,hInstance,NULL);
1031 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>initial mplayer windows created\n");
1033 if (Directx_CheckPrimaryPixelformat()!=0)return 1;
1034 if (!nooverlay && Directx_CheckOverlayPixelformats() == 0) //check for supported hardware
1036 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>hardware supports overlay\n");
1037 nooverlay = 0;
1039 else //if we can't have overlay we create a backpuffer with the same imageformat as the primary surface
1041 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>using backpuffer\n");
1042 nooverlay = 1;
1044 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>preinit succesfully finished\n");
1045 return 0;
1048 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y )
1050 uint8_t *s;
1051 uint8_t *d;
1052 uint32_t i=0, uvstride=dstride/2;
1053 // copy Y
1054 d=image+dstride*y+x;
1055 s=src[0];
1056 for(i=0;i<h;i++){
1057 memcpy(d,s,w);
1058 s+=stride[0];
1059 d+=dstride;
1062 w/=2;h/=2;x/=2;y/=2;
1064 // copy U
1065 d=image+dstride*image_height + uvstride*y+x;
1066 if(image_format == IMGFMT_YV12)s=src[2];
1067 else s=src[1];
1068 for(i=0;i<h;i++){
1069 memcpy(d,s,w);
1070 s+=stride[1];
1071 d+=uvstride;
1074 // copy V
1075 d=image+dstride*image_height +uvstride*(image_height/2) + uvstride*y+x;
1076 if(image_format == IMGFMT_YV12)s=src[1];
1077 else s=src[2];
1078 for(i=0;i<h;i++){
1079 memcpy(d,s,w);
1080 s+=stride[2];
1081 d+=uvstride;
1083 return 0;
1086 static void flip_page(void)
1088 HRESULT dxresult;
1089 g_lpddsBack->lpVtbl->Unlock (g_lpddsBack,NULL);
1090 if (vo_doublebuffering)
1092 // flip to the next image in the sequence
1093 dxresult = g_lpddsOverlay->lpVtbl->Flip( g_lpddsOverlay,NULL, DDFLIP_WAIT);
1094 if(dxresult == DDERR_SURFACELOST)
1096 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR><vo_directx><INFO>Restoring Surface\n");
1097 g_lpddsBack->lpVtbl->Restore( g_lpddsBack );
1098 dxresult = g_lpddsOverlay->lpVtbl->Flip( g_lpddsOverlay,NULL, DDFLIP_WAIT);
1100 if(dxresult != DD_OK)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't flip page\n");
1102 if(nooverlay)
1104 DDBLTFX ddbltfx;
1105 // ask for the "NOTEARING" option
1106 memset( &ddbltfx, 0, sizeof(DDBLTFX) );
1107 ddbltfx.dwSize = sizeof(DDBLTFX);
1108 ddbltfx.dwDDFX = DDBLTFX_NOTEARING;
1109 g_lpddsPrimary->lpVtbl->Blt(g_lpddsPrimary, &rd, g_lpddsBack, NULL, DDBLT_WAIT, &ddbltfx);
1111 g_lpddsBack->lpVtbl->Lock(g_lpddsBack,NULL,&ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT , NULL);
1112 if(vo_directrendering && (dstride != ddsdsf.lPitch)){
1113 mp_msg(MSGT_VO,MSGL_WARN,"<vo_directx><WARN>stride changed !!!! disabling direct rendering\n");
1114 vo_directrendering=0;
1116 dstride = ddsdsf.lPitch;
1117 image = ddsdsf.lpSurface;
1120 static uint32_t draw_frame(uint8_t *src[])
1122 memcpy( image, *src, dstride * image_height );
1123 return 0;
1126 static uint32_t get_image(mp_image_t *mpi)
1128 if(mpi->flags&MP_IMGFLAG_READABLE) {mp_msg(MSGT_VO, MSGL_V,"<vo_directx><ERROR>slow video ram\n");return VO_FALSE;}
1129 if(mpi->type==MP_IMGTYPE_STATIC) {mp_msg(MSGT_VO, MSGL_V,"<vo_directx><ERROR>not static\n");return VO_FALSE;}
1130 if((mpi->width==dstride) || (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH)))
1132 if(mpi->flags&MP_IMGFLAG_PLANAR)
1134 if(image_format == IMGFMT_YV12)
1136 mpi->planes[2]= image + dstride*image_height;
1137 mpi->planes[1]= image + dstride*image_height+ dstride*image_height/4;
1138 mpi->stride[1]=mpi->stride[2]=dstride/2;
1140 else if(image_format == IMGFMT_IYUV || image_format == IMGFMT_I420)
1142 mpi->planes[1]= image + dstride*image_height;
1143 mpi->planes[2]= image + dstride*image_height+ dstride*image_height/4;
1144 mpi->stride[1]=mpi->stride[2]=dstride/2;
1146 else if(image_format == IMGFMT_YVU9)
1148 mpi->planes[2] = image + dstride*image_height;
1149 mpi->planes[1] = image + dstride*image_height+ dstride*image_height/16;
1150 mpi->stride[1]=mpi->stride[2]=dstride/4;
1153 mpi->planes[0]=image;
1154 mpi->stride[0]=dstride;
1155 mpi->width=image_width;
1156 mpi->height=image_height;
1157 mpi->flags|=MP_IMGFLAG_DIRECT;
1158 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>Direct Rendering ENABLED\n");
1159 return VO_TRUE;
1161 return VO_FALSE;
1164 static uint32_t put_image(mp_image_t *mpi){
1166 uint32_t i = 0;
1167 uint8_t *d;
1168 uint8_t *s;
1169 uint32_t x = mpi->x;
1170 uint32_t y = mpi->y;
1171 uint32_t w = mpi->w;
1172 uint32_t h = mpi->h;
1174 if (WinID != -1) Directx_ManageDisplay();
1176 if((mpi->flags&MP_IMGFLAG_DIRECT)||(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK))
1178 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>put_image: nothing to do: drawslices\n");
1179 return VO_TRUE;
1182 if (mpi->flags&MP_IMGFLAG_PLANAR)
1185 if(image_format!=IMGFMT_YVU9)draw_slice(mpi->planes,mpi->stride,mpi->w,mpi->h,0,0);
1186 else
1188 // copy Y
1189 d=image+dstride*y+x;
1190 s=mpi->planes[0];
1191 for(i=0;i<h;i++){
1192 memcpy(d,s,w);
1193 s+=mpi->stride[0];
1194 d+=dstride;
1196 w/=4;h/=4;x/=4;y/=4;
1197 // copy V
1198 d=image+dstride*image_height + dstride*y/4+x;
1199 s=mpi->planes[2];
1200 for(i=0;i<h;i++){
1201 memcpy(d,s,w);
1202 s+=mpi->stride[1];
1203 d+=dstride/4;
1205 // copy U
1206 d=image+dstride*image_height + dstride*image_height/16 + dstride/4*y+x;
1207 s=mpi->planes[1];
1208 for(i=0;i<h;i++){
1209 memcpy(d,s,w);
1210 s+=mpi->stride[2];
1211 d+=dstride/4;
1215 else //packed
1217 memcpy( image, mpi->planes[0], image_height * dstride);
1219 return VO_TRUE;
1222 static uint32_t
1223 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t options, char *title, uint32_t format)
1225 RECT rd;
1226 vo_screenwidth = monitor_rect.right - monitor_rect.left;
1227 vo_screenheight = monitor_rect.bottom - monitor_rect.top;
1228 vo_fs = options & 0x01;
1229 image_format = format;
1230 image_width = width;
1231 image_height = height;
1232 d_image_width = d_width;
1233 d_image_height = d_height;
1234 if(format != primary_image_format)nooverlay = 0;
1235 aspect_save_orig(image_width,image_height);
1236 aspect_save_prescale(d_image_width,d_image_height);
1237 if(vidmode){
1238 vo_screenwidth=vm_width;
1239 vo_screenheight=vm_height;
1241 aspect_save_screenres(vo_screenwidth,vo_screenheight);
1242 aspect(&d_image_width, &d_image_height, A_NOZOOM);
1243 window_aspect= (float)d_image_width / (float)d_image_height;
1244 vo_dx = 0;
1245 vo_dy = 0;
1246 if(!vidmode){
1247 if(vo_geometry){
1248 vo_dx= ( vo_screenwidth - d_image_width ) / 2; vo_dy=( vo_screenheight - d_image_height ) / 2;
1249 geometry(&vo_dx, &vo_dy, &d_image_width, &d_image_height, vo_screenwidth, vo_screenheight);
1251 else {
1252 GetWindowRect(hWnd,&rd);
1253 vo_dx=rd.left;
1254 vo_dy=rd.top;
1256 vo_dx += monitor_rect.left; /* move position to global window space */
1257 vo_dy += monitor_rect.top;
1258 rd.left = vo_dx;
1259 rd.top = vo_dy;
1260 rd.right = rd.left + d_image_width;
1261 rd.bottom = rd.top + d_image_height;
1262 if (WinID == -1) {
1263 AdjustWindowRect(&rd,WS_OVERLAPPEDWINDOW|WS_SIZEBOX,FALSE);
1264 SetWindowPos(hWnd,NULL, vo_dx, vo_dy,rd.right-rd.left,rd.bottom-rd.top,SWP_SHOWWINDOW|SWP_NOOWNERZORDER);
1267 else ShowWindow(hWnd,SW_SHOW);
1269 if(vo_fs && !vidmode)ShowWindow(hWndFS,SW_SHOW);
1270 if (WinID == -1)
1271 SetWindowText(hWnd,title);
1274 if(vidmode)vo_fs=0;
1275 /*release all surfaces*/
1276 if (g_lpddsBack != NULL) g_lpddsBack->lpVtbl->Release(g_lpddsBack);
1277 g_lpddsBack = NULL;
1278 if(vo_doublebuffering)
1280 if (g_lpddsOverlay != NULL)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);
1282 g_lpddsOverlay = NULL;
1283 if (g_lpddsPrimary != NULL) g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
1284 g_lpddsPrimary = NULL;
1285 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>overlay surfaces released\n");
1288 /*create the surfaces*/
1289 if(Directx_CreatePrimarySurface())return 1;
1290 if (!nooverlay && Directx_CreateOverlay(image_format))
1292 if(format == primary_image_format)nooverlay=1; /*overlay creation failed*/
1293 else {
1294 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't use overlay mode: please use -vo directx:noaccel\n");
1295 return 1;
1298 if(nooverlay)
1300 if(Directx_CreateBackpuffer())
1302 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't get the driver to work on your system :(\n");
1303 return 1;
1305 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>back surface created\n");
1306 vo_doublebuffering = 0;
1307 /*create clipper for nonoverlay mode*/
1308 if(g_lpddclipper)g_lpddclipper->lpVtbl->Release(g_lpddclipper);
1309 g_lpddclipper=NULL;
1310 if(g_lpdd->lpVtbl->CreateClipper(g_lpdd, 0, &g_lpddclipper,NULL)!= DD_OK){mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't create clipper\n");return 1;}
1311 if(g_lpddclipper->lpVtbl->SetHWnd (g_lpddclipper, 0, hWnd)!= DD_OK){mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't associate clipper with window\n");return 1;}
1312 if(g_lpddsPrimary->lpVtbl->SetClipper (g_lpddsPrimary,g_lpddclipper)!=DD_OK){mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't associate primary surface with clipper\n");return 1;}
1313 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>clipper succesfully created\n");
1314 }else{
1315 if(DD_OK != g_lpddsOverlay->lpVtbl->QueryInterface(g_lpddsOverlay,&IID_IDirectDrawColorControl,(void**)&g_cc))
1316 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><WARN>unable to get DirectDraw ColorControl interface\n");
1318 Directx_ManageDisplay();
1319 memset(&ddsdsf, 0,sizeof(DDSURFACEDESC2));
1320 ddsdsf.dwSize = sizeof (DDSURFACEDESC2);
1321 g_lpddsBack->lpVtbl->Lock(g_lpddsBack,NULL,&ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL);
1322 dstride = ddsdsf.lPitch;
1323 image = ddsdsf.lpSurface;
1324 return 0;
1327 //function to set color controls
1328 // brightness [0, 10000]
1329 // contrast [0, 20000]
1330 // hue [-180, 180]
1331 // saturation [0, 20000]
1332 static uint32_t color_ctrl_set(char *what, int value)
1334 uint32_t r = VO_NOTIMPL;
1335 DDCOLORCONTROL dcc;
1336 //printf("\n*** %s = %d\n", what, value);
1337 if (!g_cc) {
1338 //printf("\n *** could not get color control interface!!!\n");
1339 return VO_NOTIMPL;
1341 ZeroMemory(&dcc, sizeof(dcc));
1342 dcc.dwSize = sizeof(dcc);
1344 if (!strcmp(what, "brightness")) {
1345 dcc.dwFlags = DDCOLOR_BRIGHTNESS;
1346 dcc.lBrightness = (value + 100) * 10000 / 200;
1347 r = VO_TRUE;
1348 } else if (!strcmp(what, "contrast")) {
1349 dcc.dwFlags = DDCOLOR_CONTRAST;
1350 dcc.lContrast = (value + 100) * 20000 / 200;
1351 r = VO_TRUE;
1352 } else if (!strcmp(what, "hue")) {
1353 dcc.dwFlags = DDCOLOR_HUE;
1354 dcc.lHue = value * 180 / 100;
1355 r = VO_TRUE;
1356 } else if (!strcmp(what, "saturation")) {
1357 dcc.dwFlags = DDCOLOR_SATURATION;
1358 dcc.lSaturation = (value + 100) * 20000 / 200;
1359 r = VO_TRUE;
1362 if (r == VO_TRUE) {
1363 g_cc->lpVtbl->SetColorControls(g_cc, &dcc);
1365 return r;
1368 //analoguous to color_ctrl_set
1369 static uint32_t color_ctrl_get(char *what, int *value)
1371 uint32_t r = VO_NOTIMPL;
1372 DDCOLORCONTROL dcc;
1373 if (!g_cc) {
1374 //printf("\n *** could not get color control interface!!!\n");
1375 return VO_NOTIMPL;
1377 ZeroMemory(&dcc, sizeof(dcc));
1378 dcc.dwSize = sizeof(dcc);
1380 if (g_cc->lpVtbl->GetColorControls(g_cc, &dcc) != DD_OK) {
1381 return r;
1384 if (!strcmp(what, "brightness") && (dcc.dwFlags & DDCOLOR_BRIGHTNESS)) {
1385 *value = dcc.lBrightness * 200 / 10000 - 100;
1386 r = VO_TRUE;
1387 } else if (!strcmp(what, "contrast") && (dcc.dwFlags & DDCOLOR_CONTRAST)) {
1388 *value = dcc.lContrast * 200 / 20000 - 100;
1389 r = VO_TRUE;
1390 } else if (!strcmp(what, "hue") && (dcc.dwFlags & DDCOLOR_HUE)) {
1391 *value = dcc.lHue * 100 / 180;
1392 r = VO_TRUE;
1393 } else if (!strcmp(what, "saturation") && (dcc.dwFlags & DDCOLOR_SATURATION)) {
1394 *value = dcc.lSaturation * 200 / 20000 - 100;
1395 r = VO_TRUE;
1397 // printf("\n*** %s = %d\n", what, *value);
1399 return r;
1402 static uint32_t control(uint32_t request, void *data, ...)
1404 switch (request) {
1406 case VOCTRL_GET_IMAGE:
1407 return get_image(data);
1408 case VOCTRL_QUERY_FORMAT:
1409 return query_format(*((uint32_t*)data));
1410 case VOCTRL_DRAW_IMAGE:
1411 return put_image(data);
1412 case VOCTRL_ONTOP:
1413 if(WinID != -1) return VO_TRUE;
1414 if(vidmode)
1416 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>ontop has no meaning in exclusive mode\n");
1418 else
1420 if(vo_ontop) vo_ontop = 0;
1421 else vo_ontop = 1;
1422 Directx_ManageDisplay();
1424 return VO_TRUE;
1425 case VOCTRL_ROOTWIN:
1426 if(WinID != -1) return VO_TRUE;
1427 if(vidmode)
1429 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>rootwin has no meaning in exclusive mode\n");
1431 else
1433 if(vo_rootwin) vo_rootwin = 0;
1434 else vo_rootwin = 1;
1435 Directx_ManageDisplay();
1437 return VO_TRUE;
1438 case VOCTRL_FULLSCREEN:
1440 if(vidmode)
1442 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>currently we do not allow to switch from exclusive to windowed mode\n");
1444 else
1446 if(!vo_fs)
1448 vo_fs=1;
1449 ShowWindow(hWndFS,SW_SHOW);
1450 ShowWindow(hWnd,SW_HIDE);
1452 else
1454 vo_fs=0;
1455 ShowWindow(hWndFS,SW_HIDE);
1456 ShowWindow(hWnd,SW_SHOW);
1458 Directx_ManageDisplay();
1459 break;
1461 return VO_TRUE;
1463 case VOCTRL_SET_EQUALIZER: {
1464 va_list ap;
1465 int value;
1467 va_start(ap, data);
1468 value = va_arg(ap, int);
1469 va_end(ap);
1470 return color_ctrl_set(data, value);
1472 case VOCTRL_GET_EQUALIZER: {
1473 va_list ap;
1474 int *value;
1476 va_start(ap, data);
1477 value = va_arg(ap, int*);
1478 va_end(ap);
1479 return color_ctrl_get(data, value);
1482 return VO_NOTIMPL;