7537
|
1 /******************************************************************************
|
|
2 * vo_directx.c: Directx v2 or later DirectDraw interface for MPlayer
|
|
3 * Copyright (c) 2002 Sascha Sommer <saschasommer@freenet.de>.
|
|
4 *
|
|
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.
|
|
9 *
|
|
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.
|
|
14 *
|
|
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.
|
|
18 *
|
|
19 *****************************************************************************/
|
|
20 /******************************************************************************
|
|
21 * TODO:
|
|
22 * -fix dr + implement DMA
|
|
23 * -implement mousehiding
|
|
24 * -fix undefined symbols when using CreateSolidBrush
|
|
25 * necessary for:
|
|
26 * -correct colorkeying
|
|
27 * -black window background
|
|
28 * -better exclusive mode
|
|
29 *
|
|
30 *****************************************************************************/
|
|
31
|
|
32 #include <windows.h>
|
|
33 #include <windowsx.h>
|
|
34 #include <ddraw.h>
|
|
35 #include <initguid.h>
|
|
36 #include <stdlib.h>
|
|
37 #include <errno.h>
|
|
38 #include "config.h"
|
|
39 #include "video_out.h"
|
|
40 #include "video_out_internal.h"
|
|
41 #include "fastmemcpy.h"
|
|
42 #include "../input/input.h"
|
|
43 #include "../linux/keycodes.h"
|
|
44 #include "../mp_msg.h"
|
|
45
|
|
46 static LPDIRECTDRAW2 g_lpdd = NULL; //DirectDraw Object
|
|
47 static LPDIRECTDRAWSURFACE g_lpddsPrimary = NULL; //Primary Surface: viewport through the Desktop
|
|
48 static LPDIRECTDRAWSURFACE g_lpddsOverlay = NULL; //Overlay Surface
|
|
49 static LPDIRECTDRAWSURFACE g_lpddsBack = NULL; //Back surface
|
|
50 static LPDIRECTDRAWCLIPPER g_lpddclipper; //clipper object, can only be without overlay
|
|
51 static DDSURFACEDESC ddsdsf; //surface descripiton needed for locking
|
|
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 uint32_t ontop=0; //always in foreground
|
|
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; //image format
|
|
60 static uint32_t vm = 0; //exclusive mode, allows resolution switching (not implemented yet)
|
|
61 static uint32_t fs = 0; //display in window or fullscreen
|
|
62 static uint32_t dstride; //surface stride
|
|
63 static uint32_t swap = 1; //swap u<->v planes set to 1 if you experience bluish faces
|
|
64 static uint32_t nooverlay = 1; //NonOverlay mode
|
|
65
|
|
66 extern void mplayer_put_key(int code); //let mplayer handel the keyevents
|
|
67 extern int vo_doublebuffering; //tribblebuffering
|
|
68
|
|
69 int i_colorkey; //fix this!!
|
|
70
|
|
71 /*****************************************************************************
|
|
72 * DirectDraw GUIDs.
|
|
73 * Defining them here allows us to get rid of the dxguid library during
|
|
74 * the linking stage.
|
|
75 *****************************************************************************/
|
|
76 DEFINE_GUID( IID_IDirectDraw2, 0xB3A6F3E0,0x2B43,0x11CF,0xA2,0xDE,0x00,0xAA,0x00,0xB9,0x33,0x56 );
|
|
77
|
|
78 typedef struct directx_fourcc_caps
|
|
79 {
|
|
80 char* img_format_name; //human readable name
|
|
81 uint32_t img_format; //as MPlayer image format
|
|
82 uint32_t drv_caps; //what hw supports with this format
|
|
83 DDPIXELFORMAT g_ddpfOverlay; //as Directx Sourface description
|
|
84 } directx_fourcc_caps;
|
|
85
|
|
86
|
|
87 static directx_fourcc_caps g_ddpf[] =
|
|
88 {
|
|
89 {"YV12 ",IMGFMT_YV12 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','V','1','2'),0,0,0,0,0}},
|
|
90 {"I420 ",IMGFMT_I420 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('I','4','2','0'),0,0,0,0,0}}, //yv12 with swapped uv
|
|
91 {"IYUV ",IMGFMT_IYUV ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('I','Y','U','V'),0,0,0,0,0}}, //same as i420
|
|
92 {"YVU9 ",IMGFMT_YVU9 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','V','U','9'),0,0,0,0,0}},
|
|
93 {"YUY2 ",IMGFMT_YUY2 ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('Y','U','Y','2'),0,0,0,0,0}},
|
|
94 // {"UYVY ",IMGFMT_UYVY ,0,{sizeof(DDPIXELFORMAT), DDPF_FOURCC,MAKEFOURCC('U','Y','V','Y'),0,0,0,0,0}},
|
|
95 {"RGB15",IMGFMT_RGB15,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000001F, 0x000003E0, 0x00007C00, 0}}, //RGB 5:5:5
|
|
96 {"BGR15",IMGFMT_BGR15,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x00007C00, 0x000003E0, 0x0000001F, 0}},
|
|
97 {"RGB16",IMGFMT_RGB16,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000F800, 0x000007E0, 0x0000001F, 0}}, //RGB 5:6:5
|
|
98 {"BGR16",IMGFMT_BGR16,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 16, 0x0000001F, 0x000007E0, 0x0000F800, 0}},
|
|
99 {"RGB24",IMGFMT_RGB24,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0}},
|
|
100 {"BGR24",IMGFMT_BGR24,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 24, 0x00FF0000, 0x0000FF00, 0x000000FF, 0}},
|
|
101 {"RGB32",IMGFMT_RGB32,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0}},
|
|
102 {"BGR32",IMGFMT_BGR32,0,{sizeof(DDPIXELFORMAT), DDPF_RGB, 0, 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0}}
|
|
103 };
|
|
104 #define NUM_FORMATS (sizeof(g_ddpf) / sizeof(g_ddpf[0]))
|
|
105
|
|
106
|
|
107 LIBVO_EXTERN(directx)
|
|
108
|
|
109 static vo_info_t vo_info =
|
|
110 {
|
|
111 "Directx DDraw YUV/RGB/BGR renderer",
|
|
112 "directx",
|
|
113 "Sascha Sommer <saschasommer@freenet.de>",
|
|
114 ""
|
|
115 };
|
|
116
|
|
117
|
|
118 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
|
|
119 unsigned char *srca, int stride)
|
|
120 {
|
|
121 switch(image_format) {
|
|
122 case IMGFMT_YV12 :
|
|
123 case IMGFMT_I420 :
|
|
124 case IMGFMT_IYUV :
|
|
125 case IMGFMT_YVU9 :
|
|
126 vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) image) + image_width*y0 + x0,image_width);
|
|
127 break;
|
|
128 case IMGFMT_YUY2 :
|
|
129 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) image)+ 2*image_width*y0 + 2*x0 ,2*image_width);
|
|
130 break;
|
|
131 case IMGFMT_UYVY :
|
|
132 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) image) + 2*image_width*y0 + 2*x0 + 1,dstride);
|
|
133 break;
|
|
134 case IMGFMT_RGB15:
|
|
135 case IMGFMT_BGR15:
|
|
136 vo_draw_alpha_rgb15(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+2*x0,dstride);
|
|
137 break;
|
|
138 case IMGFMT_RGB16:
|
|
139 case IMGFMT_BGR16:
|
|
140 vo_draw_alpha_rgb16(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+2*x0,dstride);
|
|
141 break;
|
|
142 case IMGFMT_RGB24:
|
|
143 case IMGFMT_BGR24:
|
|
144 vo_draw_alpha_rgb24(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+4*x0,dstride);
|
|
145 break;
|
|
146 case IMGFMT_RGB32:
|
|
147 case IMGFMT_BGR32:
|
|
148 vo_draw_alpha_rgb32(w,h,src,srca,stride,((uint8_t *) image)+dstride*y0+4*x0,dstride);
|
|
149 break;
|
|
150 }
|
|
151 }
|
|
152
|
|
153 static void draw_osd(void)
|
|
154 {
|
|
155 vo_draw_text(image_width,image_height,draw_alpha);
|
|
156 }
|
|
157
|
|
158 static uint32_t
|
|
159 query_format(uint32_t format)
|
|
160 {
|
|
161 uint32_t i=0;
|
|
162 while ( i < NUM_FORMATS )
|
|
163 {
|
|
164 if (g_ddpf[i].img_format == format)
|
|
165 return g_ddpf[i].drv_caps;
|
|
166 i++;
|
|
167 }
|
|
168 return 0;
|
|
169 }
|
|
170
|
|
171 static uint32_t Directx_CreatePrimarySurface()
|
|
172 {
|
|
173 DDSURFACEDESC ddsd;
|
|
174 //cleanup
|
|
175 if(g_lpddsPrimary)g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
|
|
176 g_lpddsPrimary=NULL;
|
|
177 ZeroMemory(&ddsd, sizeof(ddsd));
|
|
178 ddsd.dwSize = sizeof(ddsd);
|
|
179 //set flags and create a primary surface.
|
|
180 ddsd.dwFlags = DDSD_CAPS;
|
|
181 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
|
|
182 if(g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsd, &g_lpddsPrimary, NULL )== DD_OK)
|
|
183 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>primary surface created\n");
|
|
184 else
|
|
185 {
|
|
186 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>could not create primary surface\n");
|
|
187 return 1;
|
|
188 }
|
|
189 return 0;
|
|
190 }
|
|
191
|
|
192 static uint32_t Directx_CreateOverlay(uint32_t imgfmt)
|
|
193 {
|
|
194 HRESULT ddrval;
|
|
195 DDSURFACEDESC ddsdOverlay;
|
|
196 uint32_t i=0;
|
|
197 while ( i < NUM_FORMATS +1 && imgfmt != g_ddpf[i].img_format)
|
|
198 {
|
|
199 i++;
|
|
200 }
|
|
201 if (!g_lpdd || !g_lpddsPrimary)
|
|
202 return 1;
|
|
203 //cleanup
|
|
204 if (g_lpddsOverlay)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);
|
|
205 if (g_lpddsBack)g_lpddsBack->lpVtbl->Release(g_lpddsBack);
|
|
206 g_lpddsOverlay= NULL;
|
|
207 g_lpddsBack = NULL;
|
|
208 //create our overlay
|
|
209 ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay));
|
|
210 ddsdOverlay.dwSize = sizeof(ddsdOverlay);
|
|
211 ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_VIDEOMEMORY;
|
|
212 ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_BACKBUFFERCOUNT| DDSD_PIXELFORMAT;
|
|
213 ddsdOverlay.dwWidth=image_width;
|
|
214 ddsdOverlay.dwHeight=image_height;
|
|
215 ddsdOverlay.dwBackBufferCount=2;
|
|
216 ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay;
|
|
217 if(vo_doublebuffering) //tribblebuffering
|
|
218 {
|
|
219 if (g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL)== DD_OK)
|
|
220 {
|
|
221 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>overlay with format %s created\n",g_ddpf[i].img_format_name);
|
|
222 //get the surface directly attached to the primary (the back buffer)
|
|
223 ddsdOverlay.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
|
|
224 if(g_lpddsOverlay->lpVtbl->GetAttachedSurface(g_lpddsOverlay,&ddsdOverlay.ddsCaps, &g_lpddsBack) != DD_OK)
|
|
225 {
|
|
226 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't get attached surface\n");
|
|
227 return 1;
|
|
228 }
|
|
229 return 0;
|
|
230 }
|
|
231 vo_doublebuffering=0; //disable tribblebuffering
|
|
232 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><WARN>cannot create tribblebuffer overlay with format %s\n",g_ddpf[i].img_format_name);
|
|
233 }
|
|
234 //single buffer
|
|
235 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>using singlebuffer overlay\n");
|
|
236 ddsdOverlay.dwBackBufferCount=0;
|
|
237 ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;
|
|
238 ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT;
|
|
239 ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay;
|
|
240 // try to create the overlay surface
|
|
241 ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL);
|
|
242 if(ddrval != DD_OK)
|
|
243 {
|
|
244 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>");
|
|
245 switch(ddrval)
|
|
246 {
|
|
247 case DDERR_INCOMPATIBLEPRIMARY:
|
|
248 {mp_msg(MSGT_VO, MSGL_ERR,"incompatible primary surface\n");break;}
|
|
249 case DDERR_INVALIDCAPS:
|
|
250 {mp_msg(MSGT_VO, MSGL_ERR,"invalid caps\n");break;}
|
|
251 case DDERR_INVALIDOBJECT:
|
|
252 {mp_msg(MSGT_VO, MSGL_ERR,"invalid object\n");break;}
|
|
253 case DDERR_INVALIDPARAMS:
|
|
254 {mp_msg(MSGT_VO, MSGL_ERR,"invalid parameters\n");break;}
|
|
255 case DDERR_INVALIDPIXELFORMAT:
|
|
256 {mp_msg(MSGT_VO, MSGL_ERR,"invalid pixelformat\n");break;}
|
|
257 case DDERR_NODIRECTDRAWHW:
|
|
258 {mp_msg(MSGT_VO, MSGL_ERR,"no directdraw hardware\n");break;}
|
|
259 case DDERR_NOEMULATION:
|
|
260 {mp_msg(MSGT_VO, MSGL_ERR,"cant emulate\n");break;}
|
|
261 case DDERR_NOFLIPHW:
|
|
262 {mp_msg(MSGT_VO, MSGL_ERR,"hardware can't do flip\n");break;}
|
|
263 case DDERR_NOOVERLAYHW:
|
|
264 {mp_msg(MSGT_VO, MSGL_ERR,"hardware can't do overlay\n");break;}
|
|
265 case DDERR_OUTOFMEMORY:
|
|
266 {mp_msg(MSGT_VO, MSGL_ERR,"not enough system memory\n");break;}
|
|
267 case DDERR_UNSUPPORTEDMODE:
|
|
268 {mp_msg(MSGT_VO, MSGL_ERR,"unsupported mode\n");break;}
|
|
269 case DDERR_OUTOFVIDEOMEMORY:
|
|
270 {mp_msg(MSGT_VO, MSGL_ERR,"not enough video memory\n");break;}
|
|
271 }
|
|
272 return 1;
|
|
273 }
|
|
274 g_lpddsBack = g_lpddsOverlay;
|
|
275 //FIX THIS STUFF !!
|
|
276 i_colorkey = (DWORD)((( ((int)((HBRUSH)(COLOR_BACKGROUND + 1))) * g_ddpf[i].g_ddpfOverlay.dwRBitMask) / 255)
|
|
277 & g_ddpf[i].g_ddpfOverlay.dwRBitMask);
|
|
278 return 0;
|
|
279 }
|
|
280
|
|
281 static uint32_t Directx_CreateBackpuffer()
|
|
282 {
|
|
283 DDSURFACEDESC ddsd;
|
|
284 //cleanup
|
|
285 if (g_lpddsBack)g_lpddsBack->lpVtbl->Release(g_lpddsBack);
|
|
286 g_lpddsBack=NULL;
|
|
287 ZeroMemory(&ddsd, sizeof(ddsd));
|
|
288 ddsd.dwSize = sizeof(ddsd);
|
|
289 ddsd.ddsCaps.dwCaps= DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
|
|
290 ddsd.dwFlags= DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
|
|
291 ddsd.dwWidth=image_width;
|
|
292 ddsd.dwHeight=image_height;
|
|
293 if(g_lpdd->lpVtbl->CreateSurface( g_lpdd, &ddsd, &g_lpddsBack, 0 ) != DD_OK )
|
|
294 {
|
|
295 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't create backpuffer\n");
|
|
296 return 1;
|
|
297 }
|
|
298 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>backbuffer created\n");
|
|
299 return 0;
|
|
300 }
|
|
301
|
|
302 //create clipper for nonoverlay mode
|
|
303 static uint32_t Directx_CreateClipper()
|
|
304 {
|
|
305 if(g_lpddclipper)g_lpddclipper->lpVtbl->Release(g_lpddclipper);
|
|
306 g_lpddclipper=NULL;
|
|
307 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;}
|
|
308 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;}
|
|
309 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;}
|
|
310 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>clipper succesfully created\n");
|
|
311 return 0;
|
|
312 }
|
|
313
|
|
314 static const vo_info_t*
|
|
315 get_info(void)
|
|
316 {
|
|
317 return &vo_info;
|
|
318 }
|
|
319
|
|
320 static void uninit(void)
|
|
321 {
|
|
322 if (g_lpddclipper != NULL) g_lpddclipper->lpVtbl->Release(g_lpddclipper);
|
|
323 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>clipper released\n");
|
|
324 CloseWindow(hWnd);
|
|
325 if(hWnd != NULL)DestroyWindow(hWnd);
|
|
326 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>window destroyed\n");
|
|
327 if (g_lpddsBack != NULL) g_lpddsBack->lpVtbl->Release(g_lpddsBack);
|
|
328 g_lpddsBack = NULL;
|
|
329 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>back surface released\n");
|
|
330 if(vo_doublebuffering)
|
|
331 {
|
|
332 if (g_lpddsOverlay != NULL)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);
|
|
333 g_lpddsOverlay = NULL;
|
|
334 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>overlay surface released\n");
|
|
335 }
|
|
336 if (g_lpddsPrimary != NULL) g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
|
|
337 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>primary released\n");
|
|
338 if (g_lpdd != NULL) g_lpdd->lpVtbl->Release(g_lpdd);
|
|
339 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>directdrawobject released\n");
|
|
340 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>uninited\n");
|
|
341 }
|
|
342
|
|
343 static uint32_t Directx_InitDirectDraw()
|
|
344 {
|
|
345 HINSTANCE hddraw_dll;
|
|
346 HRESULT (WINAPI *OurDirectDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *);
|
|
347 LPDIRECTDRAW lpDDraw;
|
|
348 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>Initing DirectDraw\n" );
|
|
349
|
|
350 //load direct draw DLL: based on videolans code
|
|
351 hddraw_dll = LoadLibrary("DDRAW.DLL");
|
|
352 if( hddraw_dll == NULL )
|
|
353 {
|
|
354 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed loading ddraw.dll\n" );
|
|
355 return 1;
|
|
356 }
|
|
357 OurDirectDrawCreate = (void *)GetProcAddress(hddraw_dll, "DirectDrawCreate");
|
|
358 if ( OurDirectDrawCreate == NULL )
|
|
359 {
|
|
360 FreeLibrary( hddraw_dll );
|
|
361 hddraw_dll = NULL;
|
|
362 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed geting proc address\n");
|
|
363 return 1;
|
|
364 }
|
|
365 // initialize DirectDraw and create directx v1 object
|
|
366 if (OurDirectDrawCreate( NULL, &lpDDraw, NULL ) != DD_OK )
|
|
367 {
|
|
368 lpDDraw = NULL;
|
|
369 FreeLibrary( hddraw_dll );
|
|
370 hddraw_dll = NULL;
|
|
371 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't initialize ddraw\n");
|
|
372 return 1;
|
|
373 }
|
|
374 // ask IDirectDraw for IDirectDraw2
|
|
375 if (lpDDraw->lpVtbl->QueryInterface(lpDDraw, &IID_IDirectDraw2, (void **)&g_lpdd) != DD_OK)
|
|
376 {
|
|
377 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>no directx 2 installed\n");
|
|
378 return 1;
|
|
379 }
|
|
380 //release our old interface and free ddraw.dll
|
|
381 lpDDraw->lpVtbl->Release(lpDDraw);
|
|
382 FreeLibrary( hddraw_dll);
|
|
383 hddraw_dll= NULL;
|
|
384 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>lpDDraw released & hddraw freed\n" );
|
|
385 //set cooperativelevel: for our tests, no handle to a window is needed
|
|
386 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, NULL, DDSCL_NORMAL) != DD_OK)
|
|
387 {
|
|
388 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>could not set cooperativelevel for hardwarecheck\n");
|
|
389 return 1;
|
|
390 }
|
|
391 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>DirectDraw Inited\n");
|
|
392 return 0;
|
|
393 }
|
|
394
|
|
395 static void check_events(void)
|
|
396 {
|
|
397 MSG msg;
|
|
398 while (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
|
|
399 {
|
|
400 TranslateMessage(&msg);
|
|
401 DispatchMessage(&msg);
|
|
402 }
|
|
403 }
|
|
404
|
|
405 //fullscreen code: centers and zooms image, returns window rect
|
|
406 static RECT Directx_Fullscreencalc()
|
|
407 {
|
|
408 uint32_t xscreen = GetSystemMetrics(SM_CXSCREEN);
|
|
409 uint32_t yscreen = GetSystemMetrics(SM_CYSCREEN);
|
|
410 uint32_t xstretch1000,ystretch1000;
|
|
411 RECT rd_window;
|
|
412 rd.top = 0;
|
|
413 rd.left=0;
|
|
414 rd.right = xscreen;
|
|
415 rd.bottom = yscreen;
|
|
416 rd_window=rd;
|
|
417 xstretch1000 = (xscreen*1000)/d_image_width;
|
|
418 ystretch1000 = (yscreen*1000)/d_image_height;
|
|
419 if(xstretch1000 > ystretch1000)
|
|
420 {
|
|
421 rd.bottom=yscreen;
|
|
422 rd.right=(d_image_width*ystretch1000)/1000;
|
|
423 }
|
|
424 else
|
|
425 {
|
|
426 rd.right=xscreen;
|
|
427 rd.bottom=(d_image_height*xstretch1000)/1000;
|
|
428 }
|
|
429 //printf("%i,%i,%i,%i,%i,%i\n",xstretch1000,ystretch1000,d_image_height,d_image_width,rd.bottom,rd.right);
|
|
430 rd.left = (xscreen-rd.right)/2;
|
|
431 rd.right= rd.right+rd.left;
|
|
432 rd.top = (yscreen-rd.bottom)/2;
|
|
433 rd.bottom = rd.bottom + rd.top;
|
|
434 return rd_window;
|
|
435 }
|
|
436
|
|
437 //this function hopefully takes into account most of those alignments, minimum stretch, move outside of screen
|
|
438 //no stretch hw, etc... and displays the overlay
|
|
439 //I seperated non overlay mode because it is already to much stuff in here
|
|
440 static uint32_t Directx_DisplayOverlay()
|
|
441 {
|
|
442 WINDOWPLACEMENT window_placement;
|
|
443 RECT rd_window; //Rect of the window
|
|
444 HRESULT ddrval;
|
|
445 DDCAPS capsDrv;
|
|
446 DDOVERLAYFX ovfx;
|
|
447 DWORD dwUpdateFlags;
|
|
448 HWND hWndafter;
|
|
449 uint32_t uStretchFactor1000; //minimum stretch
|
|
450 uint32_t xstretch1000,ystretch1000;
|
|
451 uint32_t xscreen = GetSystemMetrics(SM_CXSCREEN);
|
|
452 uint32_t yscreen = GetSystemMetrics(SM_CYSCREEN);
|
|
453 POINT point_window;
|
|
454 //get driver capabilities
|
|
455 ZeroMemory(&capsDrv, sizeof(capsDrv));
|
|
456 capsDrv.dwSize = sizeof(capsDrv);
|
|
457 if(g_lpdd->lpVtbl->GetCaps(g_lpdd,&capsDrv, NULL) != DD_OK)return 1;
|
|
458 //check minimum stretch, depends on display adaptor and mode (refresh rate!)
|
|
459 uStretchFactor1000 = capsDrv.dwMinOverlayStretch>1000 ? capsDrv.dwMinOverlayStretch : 1000;
|
|
460 window_placement.length = sizeof(WINDOWPLACEMENT);
|
|
461 GetWindowPlacement(hWnd, &window_placement );
|
|
462 if(!fs) //windowed
|
|
463 {
|
|
464 if (window_placement.showCmd == SW_SHOWMAXIMIZED) //is our window maximized?
|
|
465 {
|
|
466 CloseWindow(hWnd); //we do this to prevent the screen being filled with garbage
|
|
467 window_placement.showCmd = SW_SHOWNORMAL; //restore
|
|
468 SetWindowLong( hWnd,GWL_STYLE , WS_OVERLAPPEDWINDOW| WS_SIZEBOX ); //change Style
|
|
469 SetWindowPlacement( hWnd, &window_placement );
|
|
470 }
|
|
471 }
|
|
472 else //fullscreen
|
|
473 {
|
|
474 if (window_placement.showCmd == SW_SHOWNORMAL) //is our window normal?
|
|
475 {
|
|
476 window_placement.showCmd = SW_SHOWMAXIMIZED; //maximize
|
|
477 SetWindowLong( hWnd, GWL_STYLE, 0 ); //change style
|
|
478 SetWindowPlacement( hWnd, &window_placement );
|
|
479 }
|
|
480 }
|
|
481
|
|
482 if(!fs)
|
|
483 {
|
|
484 GetClientRect (hWnd, &rd_window);
|
|
485 if(rd_window.top == rd_window.bottom) //window is minimized
|
|
486 {
|
|
487 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL); //hide the overlay
|
|
488 return 0;
|
|
489 }
|
|
490 if (GetWindowTextLength(hWnd)==0)
|
|
491 {
|
|
492 SetWindowText(hWnd,"MPlayer - DirectX Overlay"); //for the first call: change only title, not the overlay size
|
|
493 }
|
|
494 else
|
|
495 {
|
|
496 d_image_width = rd_window.right - rd_window.left; //calculate new overlay from the window size
|
|
497 d_image_height = rd_window.bottom - rd_window.top;
|
|
498 }
|
|
499 }
|
|
500 else
|
|
501 {
|
|
502 rd.top = 0;rd.left=0;
|
|
503 rd.bottom = yscreen; rd.right = xscreen;
|
|
504 rs.top = 0;rs.left=0;
|
|
505 rs.bottom = image_height; rs.right = image_width;
|
|
506 }
|
|
507 //check if hardware can stretch or shrink, if needed
|
|
508 //do some cards support only nshrinking or is this a special shrink,stretch feature?
|
|
509 if((d_image_width < image_width)&& !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKX))
|
|
510 {
|
|
511 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKXN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only shrinkN\n");
|
|
512 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't shrink x\n");
|
|
513 d_image_width=image_width;
|
|
514 }
|
|
515 else if((d_image_width > image_width)&& !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHX))
|
|
516 {
|
|
517 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHXN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only stretchN\n");
|
|
518 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't stretch x\n");
|
|
519 d_image_width = image_width;
|
|
520 }
|
|
521 if((d_image_height < image_height) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKY))
|
|
522 {
|
|
523 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKYN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only shrinkN\n");
|
|
524 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't shrink y\n");
|
|
525 d_image_height = image_height;
|
|
526 }
|
|
527 else if((d_image_height > image_height ) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHY))
|
|
528 {
|
|
529 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHYN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only stretchN\n");
|
|
530 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't stretch y\n");
|
|
531 d_image_height = image_height;
|
|
532 }
|
|
533
|
|
534 if(!fs) //windowed
|
|
535 {
|
|
536 point_window.x = 0; //overlayposition relative to the window
|
|
537 point_window.y = 0;
|
|
538 ClientToScreen(hWnd,&point_window);
|
|
539 rd.left = point_window.x; //fill the wanted x1&y1 of the Overlay
|
|
540 rd.top = point_window.y;
|
|
541 //fix minimum stretch
|
|
542 rd.right = ((d_image_width+rd.left)*uStretchFactor1000+999)/1000;
|
|
543 rd.bottom = (d_image_height+rd.top)*uStretchFactor1000/1000;
|
|
544 //calculate xstretch1000 and ystretch1000
|
|
545 xstretch1000 = ((rd.right - rd.left)* 1000)/image_width ;
|
|
546 ystretch1000 = ((rd.bottom - rd.top)* 1000)/image_height;
|
|
547 //handle move outside of window with cropping
|
|
548 rd_window = rd; //don't crop the window !!!
|
|
549 if(rd.left < 0) //move out left
|
|
550 {
|
|
551 rs.left=(-rd.left*1000)/xstretch1000;
|
|
552 rd.left = 0;
|
|
553 }
|
|
554 else rs.left=0;
|
|
555 if(rd.top < 0) //move out up
|
|
556 {
|
|
557 rs.top=(-rd.top*1000)/ystretch1000;
|
|
558 rd.top = 0;
|
|
559 }
|
|
560 else rs.top = 0;
|
|
561 if(rd.right > xscreen) //move out right
|
|
562 {
|
|
563 rs.right=((xscreen-rd.left)*1000)/xstretch1000;
|
|
564 rd.right= xscreen;
|
|
565 }
|
|
566 else rs.right = image_width;
|
|
567 if(rd.bottom > yscreen) //move out down
|
|
568 {
|
|
569 rs.bottom=((yscreen-rd.top)*1000)/ystretch1000;
|
|
570 rd.bottom= yscreen;
|
|
571 }
|
|
572 else rs.bottom= image_height;
|
|
573 }
|
|
574 else
|
|
575 {
|
|
576 rd_window = Directx_Fullscreencalc();
|
|
577 }
|
|
578 // check alignment restrictions
|
|
579 // these expressions (x & -y) just do alignment by dropping low order bits...
|
|
580 // so to round up, we add first, then truncate.
|
|
581 if ((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYSRC) && capsDrv.dwAlignBoundarySrc)
|
|
582 rs.left = (rs.left + capsDrv.dwAlignBoundarySrc / 2) & -(signed)(capsDrv.dwAlignBoundarySrc);
|
|
583 if ((capsDrv.dwCaps & DDCAPS_ALIGNSIZESRC) && capsDrv.dwAlignSizeSrc)
|
|
584 rs.right = rs.left + (rs.right - rs.left + capsDrv.dwAlignSizeSrc / 2) & -(signed) (capsDrv.dwAlignSizeSrc);
|
|
585 if ((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYDEST) && capsDrv.dwAlignBoundaryDest)
|
|
586 {
|
|
587 rd.left = (rd.left + capsDrv.dwAlignBoundaryDest / 2) & -(signed)(capsDrv.dwAlignBoundaryDest);
|
|
588 if(!fs)rd_window.left = (rd_window.left + capsDrv.dwAlignBoundaryDest / 2) & -(signed)(capsDrv.dwAlignBoundaryDest); //don't forget the window
|
|
589 }
|
|
590 if ((capsDrv.dwCaps & DDCAPS_ALIGNSIZEDEST) && capsDrv.dwAlignSizeDest)
|
|
591 {
|
|
592 rd.right = rd.left + (rd.right - rd.left) & -(signed) (capsDrv.dwAlignSizeDest);
|
|
593 if(!fs)rd_window.right = rd_window.left + (rd_window.right - rd_window.left) & -(signed) (capsDrv.dwAlignSizeDest); //don't forget the window
|
|
594 }
|
|
595 if(!fs)AdjustWindowRect(&rd_window,WS_OVERLAPPEDWINDOW|WS_SIZEBOX,0); //calculate window rect
|
|
596 /*if((fs) || (!fs && ontop))hWndafter=HWND_TOPMOST;
|
|
597 else hWndafter=HWND_NOTOPMOST;*/
|
|
598 hWndafter = HWND_TOPMOST;
|
|
599 SetWindowPos(hWnd,
|
|
600 hWndafter,
|
|
601 rd_window.left,
|
|
602 rd_window.top,
|
|
603 rd_window.right - rd_window.left,
|
|
604 rd_window.bottom - rd_window.top,
|
|
605 SWP_SHOWWINDOW|SWP_NOOWNERZORDER/*|SWP_NOREDRAW*/);
|
|
606
|
|
607 //printf("Window:x:%i,y:%i,w:%i,h:%i\n",rd_window.left,rd_window.top,rd_window.right - rd_window.left,rd_window.bottom - rd_window.top);
|
|
608 //printf("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);
|
|
609 //printf("Source:x1:%i,x2:%i,y1:%i,y2:%i\n",rs.left,rs.right,rs.top,rs.bottom);
|
|
610 //printf("Image:x:%i->%i,y:%i->%i\n",image_width,d_image_width,image_height,d_image_height);
|
|
611
|
|
612 // Create an overlay FX structure so we can specify a source color key.
|
|
613 // This information is ignored if the DDOVER_SRCKEYOVERRIDE flag isn't set.
|
|
614 ZeroMemory(&ovfx, sizeof(ovfx));
|
|
615 ovfx.dwSize = sizeof(ovfx);
|
|
616 ovfx.dckSrcColorkey.dwColorSpaceLowValue= i_colorkey;//(int)(HBRUSH)(COLOR_BACKGROUND + 1);
|
|
617 ovfx.dckSrcColorkey.dwColorSpaceHighValue=i_colorkey;///*(HBRUSH) */(COLOR_BACKGROUND + 1);
|
|
618 // set the flags we'll send to UpdateOverlay //DDOVER_AUTOFLIP|DDOVERFX_MIRRORLEFTRIGHT|DDOVERFX_MIRRORUPDOWN could be usefull?;
|
|
619 dwUpdateFlags = DDOVER_SHOW | DDOVER_DDFX;
|
|
620 if (capsDrv.dwCKeyCaps & DDCKEYCAPS_SRCOVERLAY) dwUpdateFlags |= DDOVER_KEYSRCOVERRIDE;
|
|
621 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,&rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx);
|
|
622 if(FAILED(ddrval))
|
|
623 {
|
|
624 // on cause might be the driver lied about minimum stretch
|
|
625 // we should try upping the destination size a bit, or
|
|
626 // perhaps shrinking the source size
|
|
627 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>UpdateOverlay failed\n" );
|
|
628 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 );
|
|
629 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>");
|
|
630 switch (ddrval)
|
|
631 {
|
|
632 case DDERR_NOSTRETCHHW:
|
|
633 {mp_msg(MSGT_VO, MSGL_ERR ,"hardware can't stretch: try to size the window back\n");break;}
|
|
634 case DDERR_INVALIDRECT:
|
|
635 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid rectangle\n");break;}
|
|
636 case DDERR_INVALIDPARAMS:
|
|
637 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid parameters\n");break;}
|
|
638 case DDERR_HEIGHTALIGN:
|
|
639 {mp_msg(MSGT_VO, MSGL_ERR ,"height align\n");break;}
|
|
640 case DDERR_XALIGN:
|
|
641 {mp_msg(MSGT_VO, MSGL_ERR ,"x align\n");break;}
|
|
642 case DDERR_UNSUPPORTED:
|
|
643 {mp_msg(MSGT_VO, MSGL_ERR ,"unsupported\n");break;}
|
|
644 case DDERR_INVALIDSURFACETYPE:
|
|
645 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid surfacetype\n");break;}
|
|
646 case DDERR_INVALIDOBJECT:
|
|
647 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid object\n");break;}
|
|
648 case DDERR_SURFACELOST:
|
|
649 {
|
|
650 mp_msg(MSGT_VO, MSGL_ERR ,"surfaces lost\n");
|
|
651 g_lpddsOverlay->lpVtbl->Restore( g_lpddsOverlay ); //restore and try again
|
|
652 g_lpddsPrimary->lpVtbl->Restore( g_lpddsPrimary );
|
|
653 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,&rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx);
|
|
654 if(ddrval !=DD_OK)mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>UpdateOverlay failed again\n" );
|
|
655 break;
|
|
656 }
|
|
657 }
|
|
658 //hide overlay
|
|
659 if(ddrval != DD_OK)
|
|
660 {
|
|
661 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL);
|
|
662 return 1;
|
|
663 }
|
|
664 }
|
|
665 return 0;
|
|
666 }
|
|
667
|
|
668 static uint32_t Directx_DisplayNonOverlay()
|
|
669 {
|
|
670 WINDOWPLACEMENT window_placement;
|
|
671 RECT rd_window; //rect of the window
|
|
672 HWND hWndafter;
|
|
673 uint32_t xscreen = GetSystemMetrics(SM_CXSCREEN);
|
|
674 uint32_t yscreen = GetSystemMetrics(SM_CYSCREEN);
|
|
675 uint32_t xstretch1000,ystretch1000;//zoom factors
|
|
676 POINT point_window;
|
|
677 window_placement.length = sizeof(WINDOWPLACEMENT);
|
|
678 GetWindowPlacement(hWnd, &window_placement );
|
|
679
|
|
680 if(!fs) //windowed
|
|
681 {
|
|
682 if (window_placement.showCmd == SW_SHOWMAXIMIZED) //is our window maximized?
|
|
683 {
|
|
684 CloseWindow(hWnd); //we do this to prevent the screen from being filled with garbage
|
|
685 window_placement.showCmd = SW_SHOWNORMAL; //restore
|
|
686 SetWindowLong(hWnd,GWL_STYLE , WS_OVERLAPPEDWINDOW| WS_SIZEBOX ); //change style
|
|
687 SetWindowPlacement( hWnd, &window_placement );
|
|
688 }
|
|
689 }
|
|
690 else //fullscreen
|
|
691 {
|
|
692 if (window_placement.showCmd == SW_SHOWNORMAL) //is our window normal?
|
|
693 {
|
|
694 window_placement.showCmd = SW_SHOWMAXIMIZED; //maximize
|
|
695 SetWindowLong( hWnd, GWL_STYLE, 0 ); //change Style
|
|
696 SetWindowPlacement( hWnd, &window_placement );
|
|
697 }
|
|
698 }
|
|
699
|
|
700 if(!fs) //windowed
|
|
701 {
|
|
702 GetClientRect (hWnd, &rd_window);
|
|
703 if(rd_window.top == rd_window.bottom)return 0; //window is minimized
|
|
704 if (GetWindowTextLength(hWnd)==0)
|
|
705 {
|
|
706 SetWindowText(hWnd,"MPlayer - DirectX NoN-Overlay"); //for the first call: change only title, not d_image stuff
|
|
707 }
|
|
708 else
|
|
709 {
|
|
710 d_image_width = rd_window.right - rd_window.left; //Calculate new Imagedimensions
|
|
711 d_image_height = rd_window.bottom - rd_window.top;
|
|
712 }
|
|
713 point_window.x = 0; //imageposition relative to the window
|
|
714 point_window.y = 0;
|
|
715 ClientToScreen(hWnd,&point_window);
|
|
716 rd.left = point_window.x; //fill the wanted x1&y1 of the image
|
|
717 rd.top = point_window.y;
|
|
718 rd.right = d_image_width+rd.left;
|
|
719 rd.bottom =d_image_height+rd.top;
|
|
720 rd_window = rd;
|
|
721 AdjustWindowRect(&rd_window,WS_OVERLAPPEDWINDOW|WS_SIZEBOX,0);
|
|
722 }
|
|
723 else //fullscreen
|
|
724 {
|
|
725 rd_window=Directx_Fullscreencalc();
|
|
726 }
|
|
727 if((fs) || (!fs && ontop))hWndafter=HWND_TOPMOST;
|
|
728 else hWndafter=HWND_NOTOPMOST;
|
|
729 SetWindowPos(hWnd,
|
|
730 hWndafter,
|
|
731 rd_window.left,
|
|
732 rd_window.top,
|
|
733 rd_window.right - rd_window.left,
|
|
734 rd_window.bottom - rd_window.top,
|
|
735 SWP_SHOWWINDOW|SWP_NOOWNERZORDER);
|
|
736 return 0;
|
|
737 }
|
|
738
|
|
739 //find out supported overlay pixelformats
|
|
740 static uint32_t Directx_CheckOverlayPixelformats()
|
|
741 {
|
|
742 DDCAPS capsDrv;
|
|
743 HRESULT ddrval;
|
|
744 DDSURFACEDESC ddsdOverlay;
|
|
745 uint32_t i;
|
|
746 uint32_t formatcount = 0;
|
|
747 //get driver caps to determine overlay support
|
|
748 ZeroMemory(&capsDrv, sizeof(capsDrv));
|
|
749 capsDrv.dwSize = sizeof(capsDrv);
|
|
750 ddrval = g_lpdd->lpVtbl->GetCaps(g_lpdd,&capsDrv, NULL);
|
|
751 if (FAILED(ddrval))
|
|
752 {
|
|
753 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>failed getting ddrawcaps\n");
|
|
754 return 1;
|
|
755 }
|
|
756 if (!(capsDrv.dwCaps & DDCAPS_OVERLAY))
|
|
757 {
|
|
758 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>Your card doesn't support overlay\n");
|
|
759 return 1;
|
|
760 }
|
|
761 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>testing supported overlay pixelformats\n");
|
|
762 //it is not possible to query for pixel formats supported by the
|
|
763 //overlay hardware: try out various formats till one works
|
|
764 ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay));
|
|
765 ddsdOverlay.dwSize = sizeof(ddsdOverlay);
|
|
766 ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;
|
|
767 ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH| DDSD_PIXELFORMAT;
|
|
768 ddsdOverlay.dwWidth=300;
|
|
769 ddsdOverlay.dwHeight=280;
|
|
770 ddsdOverlay.dwBackBufferCount=0;
|
|
771 //try to create an overlay surface using one of the pixel formats in our global list
|
|
772 i=0;
|
|
773 do
|
|
774 {
|
|
775 ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay;
|
|
776 ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL);
|
|
777 if (ddrval == DD_OK)
|
|
778 {
|
|
779 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT OVERLAY>%i %s supported\n",i,g_ddpf[i].img_format_name);
|
|
780 g_ddpf[i].drv_caps = VFCAP_CSP_SUPPORTED |VFCAP_OSD |VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP;
|
|
781 formatcount++;}
|
|
782 else mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT OVERLAY>%i %s not supported\n",i,g_ddpf[i].img_format_name);
|
|
783 if (g_lpddsOverlay != NULL) {g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);g_lpddsOverlay = NULL;}
|
|
784 } while( ++i < NUM_FORMATS );
|
|
785 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>Your card supports %i of %i overlayformats\n",formatcount, NUM_FORMATS);
|
|
786 if (formatcount == 0)
|
|
787 {
|
|
788 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><WARN>Your card supports overlay, but we couldn't create one\n");
|
|
789 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>This can have the following reasons:\n");
|
|
790 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- you are already using an overlay with another app\n");
|
|
791 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- you don't have enough videomemory\n");
|
|
792 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- vo_directx doesn't support the cards overlay pixelformat\n");
|
|
793 return 1;
|
|
794 }
|
|
795 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
|
|
796 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 ;)
|
|
797 return 0;
|
|
798 }
|
|
799
|
|
800 //find out the Pixelformat of the Primary Surface
|
|
801 static uint32_t Directx_CheckPrimaryPixelformat()
|
|
802 {
|
|
803 uint32_t i=0;
|
|
804 uint32_t formatcount = 0;
|
|
805 DDPIXELFORMAT ddpf;
|
|
806 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>checking primary surface\n");
|
|
807 memset( &ddpf, 0, sizeof( DDPIXELFORMAT ));
|
|
808 ddpf.dwSize = sizeof( DDPIXELFORMAT );
|
|
809 //we have to create a primary surface first
|
|
810 if(Directx_CreatePrimarySurface()!=0)return 1;
|
|
811 if(g_lpddsPrimary->lpVtbl->GetPixelFormat( g_lpddsPrimary, &ddpf ) != DD_OK )
|
|
812 {
|
|
813 mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>can't get pixelformat\n");
|
|
814 return 1;
|
|
815 }
|
|
816 while ( i < NUM_FORMATS )
|
|
817 {
|
|
818 if (g_ddpf[i].g_ddpfOverlay.dwRGBBitCount == ddpf.dwRGBBitCount)
|
|
819 {
|
|
820 if (g_ddpf[i].g_ddpfOverlay.dwRBitMask == ddpf.dwRBitMask)
|
|
821 {
|
|
822 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT PRIMARY>%i %s supported\n",i,g_ddpf[i].img_format_name);
|
|
823 g_ddpf[i].drv_caps = VFCAP_CSP_SUPPORTED |VFCAP_OSD |VFCAP_CSP_SUPPORTED_BY_HW;
|
|
824 formatcount++;
|
|
825 }
|
|
826 }
|
|
827 i++;
|
|
828 }
|
|
829 g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary);
|
|
830 g_lpddsPrimary = NULL;
|
|
831 if(formatcount==0)
|
|
832 {
|
|
833 mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>Unknown Pixelformat\n");
|
|
834 return 1;
|
|
835 }
|
|
836 return 0;
|
|
837 }
|
|
838
|
|
839 //function handles input
|
|
840 static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
841 {
|
|
842 switch (message)
|
|
843 {
|
|
844 case WM_DESTROY:
|
|
845 {
|
|
846 mplayer_put_key('q');
|
|
847 return 0;
|
|
848 }
|
|
849 case WM_CLOSE:
|
|
850 {
|
|
851 mplayer_put_key('q');
|
|
852 return 0;
|
|
853 }
|
|
854 case WM_WINDOWPOSCHANGED:
|
|
855 {
|
|
856 //printf("Windowposchange\n");
|
|
857 if(nooverlay)Directx_DisplayNonOverlay();
|
|
858 else Directx_DisplayOverlay();
|
|
859 break;
|
|
860 }
|
|
861 case WM_SYSCOMMAND:
|
|
862 {
|
|
863 switch (wParam)
|
|
864 { //kill screensaver etc.
|
|
865 //note: works only when the window is active
|
|
866 //you can workaround this by disabling the allow screensaver option in
|
|
867 //the link to the app
|
|
868 case SC_SCREENSAVE:
|
|
869 case SC_MONITORPOWER:
|
|
870 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>killing screensaver\n" );
|
|
871 return 0;
|
|
872 }
|
|
873 }
|
|
874 case WM_KEYDOWN:
|
|
875 {
|
|
876 switch (wParam)
|
|
877 {
|
|
878 case VK_LEFT:
|
|
879 {mplayer_put_key(KEY_LEFT);break;}
|
|
880 case VK_UP:
|
|
881 {mplayer_put_key(KEY_UP);break;}
|
|
882 case VK_RIGHT:
|
|
883 {mplayer_put_key(KEY_RIGHT);break;}
|
|
884 case VK_DOWN:
|
|
885 {mplayer_put_key(KEY_DOWN);break;}
|
|
886 case VK_TAB:
|
|
887 {mplayer_put_key(KEY_TAB);break;}
|
|
888 case VK_CONTROL:
|
|
889 {mplayer_put_key(KEY_CTRL);break;}
|
|
890 case VK_DELETE:
|
|
891 {mplayer_put_key(KEY_DELETE);break;}
|
|
892 case VK_INSERT:
|
|
893 {mplayer_put_key(KEY_INSERT);break;}
|
|
894 case VK_HOME:
|
|
895 {mplayer_put_key(KEY_HOME);break;}
|
|
896 case VK_END:
|
|
897 {mplayer_put_key(VK_END);break;}
|
|
898 case VK_PRIOR:
|
|
899 {mplayer_put_key(KEY_PAGE_UP);break;}
|
|
900 case VK_NEXT:
|
|
901 {mplayer_put_key(KEY_PAGE_DOWN);break;}
|
|
902 case VK_ESCAPE:
|
|
903 {mplayer_put_key(KEY_ESC);break;}
|
|
904 }
|
|
905 break;
|
|
906 }
|
|
907 case WM_CHAR:
|
|
908 {
|
|
909 mplayer_put_key(wParam);
|
|
910 break;
|
|
911 }
|
|
912
|
|
913 }
|
|
914 return DefWindowProc(hWnd, message, wParam, lParam);
|
|
915 }
|
|
916
|
|
917 static uint32_t Directx_CreateWindow()
|
|
918 {
|
|
919 HINSTANCE hInstance = GetModuleHandle(NULL);
|
|
920 WNDCLASS wc;
|
|
921 wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
922 wc.lpfnWndProc = WndProc;
|
|
923 wc.cbClsExtra = 0;
|
|
924 wc.cbWndExtra = 0;
|
|
925 wc.hInstance = hInstance;
|
|
926 wc.hCursor = LoadCursor(NULL,IDC_ARROW);
|
|
927 wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
|
|
928 wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);
|
|
929 wc.lpszClassName = "Mplayer - Movieplayer for Linux";
|
|
930 wc.lpszMenuName = NULL;
|
|
931 RegisterClass(&wc);
|
|
932 hWnd = CreateWindow("MPlayer - Movieplayer for Linux",
|
|
933 "",
|
|
934 WS_OVERLAPPEDWINDOW| WS_SIZEBOX,
|
|
935 CW_USEDEFAULT, //position x
|
|
936 CW_USEDEFAULT, //position y
|
|
937 100, //width
|
|
938 100, //height
|
|
939 NULL,
|
|
940 NULL,
|
|
941 hInstance,
|
|
942 NULL);
|
|
943 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>initial mplayer window created\n");
|
|
944 return 0;
|
|
945 }
|
|
946
|
|
947 static uint32_t preinit(const char *arg)
|
|
948 {
|
|
949 if (Directx_InitDirectDraw()!= 0)return 1; //init DirectDraw
|
|
950 if (Directx_CheckPrimaryPixelformat()!=0)return 1;
|
|
951 if (Directx_CheckOverlayPixelformats() == 0) //check for supported hardware
|
|
952 {
|
|
953 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>hardware supports overlay\n");
|
|
954 nooverlay = 0;
|
|
955 }
|
|
956 else //if we can't have overlay we create a backpuffer with the same imageformat as the primary surface
|
|
957 {
|
|
958 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>using backpuffer\n");
|
|
959 nooverlay = 1;
|
|
960 }
|
|
961 Directx_CreateWindow(); //create initial window
|
|
962 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>preinit succesfully finished\n");
|
|
963 return 0;
|
|
964 }
|
|
965
|
|
966 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y )
|
|
967 {
|
|
968 uint8_t *s;
|
|
969 uint8_t *d;
|
|
970 uint32_t i=0;
|
|
971
|
|
972 // copy Y
|
|
973 d=image+dstride*y+x;
|
|
974 s=src[0];
|
|
975 for(i=0;i<h;i++){
|
|
976 memcpy(d,s,w);
|
|
977 s+=stride[0];
|
|
978 d+=stride[0];
|
|
979 }
|
|
980
|
|
981 w/=2;h/=2;x/=2;y/=2;
|
|
982
|
|
983 // copy U
|
|
984 d=image+image_width*image_height + dstride*y/2+x;
|
|
985 if(swap)s=src[2];
|
|
986 else s=src[1];
|
|
987 for(i=0;i<h;i++){
|
|
988 memcpy(d,s,w);
|
|
989 s+=stride[1];
|
|
990 d+=stride[1];
|
|
991 }
|
|
992
|
|
993 // copy V
|
|
994 d=image+image_width*image_height +image_width*image_height/4 + dstride*y/2+x;
|
|
995 if(swap)s=src[1];
|
|
996 else s=src[2];
|
|
997 for(i=0;i<h;i++){
|
|
998 memcpy(d,s,w);
|
|
999 s+=stride[2];
|
|
1000 d+=stride[2];
|
|
1001 }
|
|
1002 return 0;
|
|
1003 }
|
|
1004
|
|
1005 static void flip_page(void)
|
|
1006 {
|
|
1007 HRESULT dxresult;
|
|
1008 //bufferflipping is slow on my system?
|
|
1009 if (vo_doublebuffering)
|
|
1010 {
|
|
1011 // flip to the next image in the sequence
|
|
1012 dxresult = g_lpddsOverlay->lpVtbl->Flip( g_lpddsOverlay,NULL, DDFLIP_WAIT);
|
|
1013 if(dxresult == DDERR_SURFACELOST)
|
|
1014 {
|
|
1015 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR><vo_directx><INFO>Restoring Surface\n");
|
|
1016 g_lpddsBack->lpVtbl->Restore( g_lpddsBack );
|
|
1017 dxresult = g_lpddsOverlay->lpVtbl->Flip( g_lpddsOverlay,NULL, DDFLIP_WAIT);
|
|
1018 }
|
|
1019 if(dxresult != DD_OK)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't flip page\n");
|
|
1020 }
|
|
1021 g_lpddsBack->lpVtbl->Lock(g_lpddsBack,NULL,&ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT , NULL);
|
|
1022 g_lpddsBack->lpVtbl->Unlock (g_lpddsBack,NULL);
|
|
1023 dstride = ddsdsf.lPitch;
|
|
1024 image = ddsdsf.lpSurface;
|
|
1025 if(nooverlay == 1)
|
|
1026 {
|
|
1027 DDBLTFX ddbltfx;
|
|
1028 // ask for the "NOTEARING" option
|
|
1029 memset( &ddbltfx, 0, sizeof(DDBLTFX) );
|
|
1030 ddbltfx.dwSize = sizeof(DDBLTFX);
|
|
1031 ddbltfx.dwDDFX = DDBLTFX_NOTEARING;
|
|
1032 g_lpddsPrimary->lpVtbl->Blt(g_lpddsPrimary, &rd, g_lpddsBack, NULL, DDBLT_WAIT, &ddbltfx);
|
|
1033 }
|
|
1034 }
|
|
1035
|
|
1036 static uint32_t draw_frame(uint8_t *src[])
|
|
1037 {
|
|
1038 memcpy( image, *src, dstride * image_height );
|
|
1039 return 0;
|
|
1040 }
|
|
1041
|
|
1042 static uint32_t get_image(mp_image_t *mpi)
|
|
1043 {
|
|
1044 //dr is untested for planar formats
|
|
1045 //we should make a surface in mem and use busmastering!
|
|
1046 if(mpi->flags&MP_IMGFLAG_READABLE) {mp_msg(MSGT_VO, MSGL_V,"<vo_directx><ERROR>slow video ram\n");return VO_FALSE;}
|
|
1047 if(mpi->type==MP_IMGTYPE_STATIC) {mp_msg(MSGT_VO, MSGL_V,"<vo_directx><ERROR>not static\n");return VO_FALSE;}
|
|
1048 if((mpi->width==dstride) || (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH)))
|
|
1049 {
|
|
1050 if(mpi->flags&MP_IMGFLAG_PLANAR && image_format==IMGFMT_YV12)
|
|
1051 {
|
|
1052 mpi->planes[0]=image;
|
|
1053 if(swap)
|
|
1054 {
|
|
1055 mpi->planes[2]= image + dstride*image_height;
|
|
1056 mpi->planes[1]= image + dstride*image_height+ dstride*image_height/4;
|
|
1057 }
|
|
1058 else
|
|
1059 {
|
|
1060 mpi->planes[1]= image + dstride*image_height;
|
|
1061 mpi->planes[2]= image + dstride*image_height+ dstride*image_height/4;
|
|
1062 }
|
|
1063 mpi->width=mpi->stride[0]=dstride;
|
|
1064 mpi->stride[1]=mpi->stride[2]=dstride/2;
|
|
1065 }
|
|
1066 else //packed
|
|
1067 {
|
|
1068 mpi->planes[0]=image;
|
|
1069 mpi->width=image_width;
|
|
1070 mpi->stride[0]=dstride;
|
|
1071 }
|
|
1072 mpi->flags|=MP_IMGFLAG_DIRECT;
|
|
1073 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>Direct Rendering ENABLED\n");
|
|
1074 return VO_TRUE;
|
|
1075 }
|
|
1076 return VO_FALSE;
|
|
1077 }
|
|
1078
|
|
1079 static uint32_t put_image(mp_image_t *mpi){
|
|
1080
|
|
1081 uint32_t i = 0;
|
|
1082 uint8_t *d;
|
|
1083 uint8_t *s;
|
|
1084 uint32_t x = mpi->x;
|
|
1085 uint32_t y = mpi->y;
|
|
1086 uint32_t w = mpi->w;
|
|
1087 uint32_t h = mpi->h;
|
|
1088
|
|
1089 if((mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)))
|
|
1090 {
|
|
1091 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>put_image: nothing to do: drawslices\n");
|
|
1092 return VO_TRUE;
|
|
1093 }
|
|
1094
|
|
1095 if (mpi->flags&MP_IMGFLAG_PLANAR)
|
|
1096 {
|
|
1097 if (image_format == IMGFMT_YV12|| image_format == IMGFMT_I420 || image_format == IMGFMT_IYUV)
|
|
1098 {
|
|
1099 draw_slice(mpi->planes, mpi->stride, mpi->w,mpi->h,mpi->x,mpi->y );
|
|
1100 }
|
|
1101 else if(image_format==IMGFMT_YVU9)
|
|
1102 {
|
|
1103 // copy Y
|
|
1104 d=image+dstride*y+x;
|
|
1105 s=mpi->planes[0];
|
|
1106 for(i=0;i<h;i++){
|
|
1107 memcpy(d,s,w);
|
|
1108 s+=mpi->stride[0];
|
|
1109 d+=dstride;
|
|
1110 }
|
|
1111 w/=4;h/=4;x/=4;y/=4; dstride/=4;
|
|
1112 // copy V
|
|
1113 d=image+image_width*image_height + dstride*y+x;
|
|
1114 if(swap)s=mpi->planes[2];
|
|
1115 else s=mpi->planes[1];
|
|
1116 for(i=0;i<h;i++){
|
|
1117 memcpy(d,s,w);
|
|
1118 s+=mpi->stride[1];
|
|
1119 d+=dstride;
|
|
1120 }
|
|
1121 // copy U
|
|
1122 d=image+image_width*image_height +image_width*image_height/16 + dstride*y+x;
|
|
1123 if(swap)s=mpi->planes[1];
|
|
1124 else s=mpi->planes[2];
|
|
1125 for(i=0;i<h;i++){
|
|
1126 memcpy(d,s,w);
|
|
1127 s+=mpi->stride[2];
|
|
1128 d+=dstride;
|
|
1129 }
|
|
1130 }
|
|
1131 }
|
|
1132 else //packed
|
|
1133 {
|
|
1134 memcpy( image, mpi->planes[0], image_height * dstride);
|
|
1135 }
|
|
1136 return VO_TRUE;
|
|
1137 }
|
|
1138
|
|
1139 static uint32_t
|
|
1140 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t options, char *title, uint32_t format)
|
|
1141 {
|
|
1142 DDSURFACEDESC ddsd;
|
|
1143 //int zoom = options & 0x04;
|
|
1144 //int flip = options & 0x08;
|
|
1145 fs = options & 0x01;
|
|
1146 vm = options & 0x02;
|
|
1147 if(vm)fs=1;
|
|
1148 image_format = format;
|
|
1149 d_image_width = d_width;
|
|
1150 d_image_height = d_height;
|
|
1151 image_width = width;
|
|
1152 image_height = height;
|
|
1153 //printf("<vo_directx><INFO>config entered\n");
|
|
1154 //printf("width:%i\nheight:%i\nd_width:%i\nd_height%i\n",width,height,d_width,d_height);
|
|
1155 if(vm)
|
|
1156 { //exclusive mode
|
|
1157 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, hWnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN) != DD_OK)
|
|
1158 {
|
|
1159 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set cooperativelevel for exclusive mode");
|
|
1160 return 1;
|
|
1161 } //ddobject,width,height,bpp,refreshrate,aditionalflags
|
|
1162 SetWindowLong( hWnd, GWL_STYLE, 0 ); //changeWindowStyle
|
|
1163 if(g_lpdd->lpVtbl->SetDisplayMode(g_lpdd,640, 480, 16,0,0) != DD_OK)
|
|
1164 {
|
|
1165 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set displaymode\n");
|
|
1166 return 1;
|
|
1167 }
|
|
1168 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>cooperativelevel for exclusive mode set\n");
|
|
1169 }
|
|
1170 else
|
|
1171 {
|
|
1172 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, hWnd, DDSCL_NORMAL) != DD_OK)
|
|
1173 {
|
|
1174 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set cooperativelevel for windowed mode");
|
|
1175 return 1;
|
|
1176 }
|
|
1177 SetWindowLong( hWnd,WS_OVERLAPPEDWINDOW| WS_SIZEBOX , 0 );
|
|
1178 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>cooperativelevel for windowed mode set\n");
|
|
1179 }
|
|
1180 if(Directx_CreatePrimarySurface()!=0)return 1;
|
|
1181 if (nooverlay==0)
|
|
1182 {
|
|
1183 if(Directx_CreateOverlay(image_format)==0)
|
|
1184 {
|
|
1185 Directx_DisplayOverlay();
|
|
1186 if(!vo_doublebuffering) g_lpddsBack = g_lpddsOverlay;
|
|
1187 }
|
|
1188 else
|
|
1189 {
|
|
1190 nooverlay=1; //if failed try with nooverlay
|
|
1191 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't use overlay mode\n");
|
|
1192
|
|
1193 }
|
|
1194 }
|
|
1195 if (nooverlay==1)
|
|
1196 {
|
|
1197 if(Directx_CreateBackpuffer()!=0)return 1;
|
|
1198 Directx_DisplayNonOverlay();
|
|
1199 }
|
|
1200
|
|
1201 if(Directx_CreateClipper() != 0)return 1;
|
|
1202 memset(&ddsdsf, 0,sizeof(DDSURFACEDESC));
|
|
1203 ddsdsf.dwSize = sizeof (DDSURFACEDESC);
|
|
1204 g_lpddsBack->lpVtbl->Lock(g_lpddsBack,NULL,&ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL);
|
|
1205 g_lpddsBack->lpVtbl->Unlock (g_lpddsBack,NULL);
|
|
1206 dstride = ddsdsf.lPitch;
|
|
1207 image = ddsdsf.lpSurface;
|
|
1208 if(image_format==IMGFMT_I420||image_format==IMGFMT_IYUV)
|
|
1209 {
|
|
1210 if(swap)swap=0; //swap uv
|
|
1211 else swap=1;
|
|
1212 }
|
|
1213 return 0;
|
|
1214 }
|
|
1215
|
|
1216 static uint32_t control(uint32_t request, void *data, ...)
|
|
1217 {
|
|
1218 switch (request) {
|
|
1219
|
|
1220 case VOCTRL_GET_IMAGE:
|
|
1221 return get_image(data);
|
|
1222 case VOCTRL_QUERY_FORMAT:
|
|
1223 return query_format(*((uint32_t*)data));
|
|
1224 case VOCTRL_DRAW_IMAGE:
|
|
1225 return put_image(data);
|
|
1226 case VOCTRL_FULLSCREEN:
|
|
1227 {
|
|
1228 //printf("Display mode switch\n");
|
|
1229 if(vm)
|
|
1230 {
|
|
1231 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>currently we do not allow to switch from exclusive to windowed mode\n");
|
|
1232 }
|
|
1233 else
|
|
1234 {
|
|
1235 if(fs)fs=0; //set to fullscreen or windowed
|
|
1236 else fs = 1;
|
|
1237 if(nooverlay == 0)Directx_DisplayOverlay(); //update window
|
|
1238 else Directx_DisplayNonOverlay();
|
|
1239 }
|
|
1240 return VO_TRUE;
|
|
1241 }
|
|
1242 };
|
|
1243 return VO_NOTIMPL;
|
|
1244 }
|