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