Mercurial > mplayer.hg
annotate libvo/vo_directx.c @ 9833:9cdbcd86c176
temporary disable mf support for systems without glob
author | faust3 |
---|---|
date | Fri, 04 Apr 2003 20:32:21 +0000 |
parents | df23774c0468 |
children | 3933e0ef000c |
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: | |
789 {mplayer_put_key(VK_END);break;} | |
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); | |
812 WNDCLASS wc; | |
7682 | 813 if(arg) |
814 { | |
9488
abe81caa8cc1
fix fullscreenswitching patch by Joey Parrish <joey at nicewarrior.org>
faust3
parents:
9380
diff
changeset
|
815 if(strstr(arg,"noaccel")) |
7682 | 816 { |
817 mp_msg(MSGT_VO,MSGL_V,"<vo_directx><INFO>disabled overlay\n"); | |
818 nooverlay = 1; | |
819 } | |
9488
abe81caa8cc1
fix fullscreenswitching patch by Joey Parrish <joey at nicewarrior.org>
faust3
parents:
9380
diff
changeset
|
820 if(strstr(arg,"ontop")) |
7682 | 821 { |
9488
abe81caa8cc1
fix fullscreenswitching patch by Joey Parrish <joey at nicewarrior.org>
faust3
parents:
9380
diff
changeset
|
822 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
|
823 ontop = 1; |
7682 | 824 } |
825 } | |
7537 | 826 if (Directx_InitDirectDraw()!= 0)return 1; //init DirectDraw |
827 if (Directx_CheckPrimaryPixelformat()!=0)return 1; | |
7682 | 828 if (!nooverlay && Directx_CheckOverlayPixelformats() == 0) //check for supported hardware |
7537 | 829 { |
830 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>hardware supports overlay\n"); | |
831 nooverlay = 0; | |
832 } | |
833 else //if we can't have overlay we create a backpuffer with the same imageformat as the primary surface | |
834 { | |
835 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>using backpuffer\n"); | |
836 nooverlay = 1; | |
837 } | |
8667 | 838 wc.style = CS_HREDRAW | CS_VREDRAW; |
839 wc.lpfnWndProc = WndProc; | |
840 wc.cbClsExtra = 0; | |
841 wc.cbWndExtra = 0; | |
842 wc.hInstance = hInstance; | |
843 wc.hCursor = LoadCursor(NULL,IDC_ARROW); | |
844 wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); | |
845 wc.hbrBackground = CreateSolidBrush(windowcolor); | |
846 wc.lpszClassName = "Mplayer - Movieplayer for Linux"; | |
847 wc.lpszMenuName = NULL; | |
848 RegisterClass(&wc); | |
849 hWnd = CreateWindow("MPlayer - Movieplayer for Linux", | |
850 "", | |
851 WS_OVERLAPPEDWINDOW| WS_SIZEBOX, | |
852 CW_USEDEFAULT, //position x | |
853 CW_USEDEFAULT, //position y | |
854 100, //width | |
855 100, //height | |
856 NULL, | |
857 NULL, | |
858 hInstance, | |
859 NULL); | |
860 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>initial mplayer window created\n"); | |
7537 | 861 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>preinit succesfully finished\n"); |
862 return 0; | |
863 } | |
864 | |
865 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y ) | |
866 { | |
867 uint8_t *s; | |
868 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
|
869 uint32_t i=0, uvstride=dstride/2; |
7537 | 870 // copy Y |
871 d=image+dstride*y+x; | |
872 s=src[0]; | |
873 for(i=0;i<h;i++){ | |
874 memcpy(d,s,w); | |
875 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
|
876 d+=dstride; |
7537 | 877 } |
878 | |
879 w/=2;h/=2;x/=2;y/=2; | |
880 | |
881 // copy U | |
8490
ac40496c7d9e
1000l! I have no idea how this code worked at all before. I guess no
rfelker
parents:
8148
diff
changeset
|
882 d=image+dstride*image_height + uvstride*y+x; |
8667 | 883 if(image_format == IMGFMT_YV12)s=src[2]; |
7537 | 884 else s=src[1]; |
885 for(i=0;i<h;i++){ | |
886 memcpy(d,s,w); | |
887 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
|
888 d+=uvstride; |
7537 | 889 } |
890 | |
891 // copy V | |
8490
ac40496c7d9e
1000l! I have no idea how this code worked at all before. I guess no
rfelker
parents:
8148
diff
changeset
|
892 d=image+dstride*image_height +uvstride*(image_height/2) + uvstride*y+x; |
8667 | 893 if(image_format == IMGFMT_YV12)s=src[1]; |
7537 | 894 else s=src[2]; |
895 for(i=0;i<h;i++){ | |
896 memcpy(d,s,w); | |
897 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
|
898 d+=uvstride; |
7537 | 899 } |
900 return 0; | |
901 } | |
902 | |
903 static void flip_page(void) | |
904 { | |
905 HRESULT dxresult; | |
8519 | 906 g_lpddsBack->lpVtbl->Unlock (g_lpddsBack,NULL); |
7537 | 907 if (vo_doublebuffering) |
908 { | |
909 // flip to the next image in the sequence | |
910 dxresult = g_lpddsOverlay->lpVtbl->Flip( g_lpddsOverlay,NULL, DDFLIP_WAIT); | |
911 if(dxresult == DDERR_SURFACELOST) | |
912 { | |
913 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR><vo_directx><INFO>Restoring Surface\n"); | |
914 g_lpddsBack->lpVtbl->Restore( g_lpddsBack ); | |
915 dxresult = g_lpddsOverlay->lpVtbl->Flip( g_lpddsOverlay,NULL, DDFLIP_WAIT); | |
916 } | |
917 if(dxresult != DD_OK)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't flip page\n"); | |
918 } | |
8495 | 919 if(nooverlay) |
7537 | 920 { |
921 DDBLTFX ddbltfx; | |
922 // ask for the "NOTEARING" option | |
923 memset( &ddbltfx, 0, sizeof(DDBLTFX) ); | |
924 ddbltfx.dwSize = sizeof(DDBLTFX); | |
925 ddbltfx.dwDDFX = DDBLTFX_NOTEARING; | |
926 g_lpddsPrimary->lpVtbl->Blt(g_lpddsPrimary, &rd, g_lpddsBack, NULL, DDBLT_WAIT, &ddbltfx); | |
927 } | |
8495 | 928 g_lpddsBack->lpVtbl->Lock(g_lpddsBack,NULL,&ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT , NULL); |
929 dstride = ddsdsf.lPitch; | |
930 image = ddsdsf.lpSurface; | |
7537 | 931 } |
932 | |
933 static uint32_t draw_frame(uint8_t *src[]) | |
934 { | |
935 memcpy( image, *src, dstride * image_height ); | |
936 return 0; | |
937 } | |
938 | |
939 static uint32_t get_image(mp_image_t *mpi) | |
940 { | |
941 if(mpi->flags&MP_IMGFLAG_READABLE) {mp_msg(MSGT_VO, MSGL_V,"<vo_directx><ERROR>slow video ram\n");return VO_FALSE;} | |
942 if(mpi->type==MP_IMGTYPE_STATIC) {mp_msg(MSGT_VO, MSGL_V,"<vo_directx><ERROR>not static\n");return VO_FALSE;} | |
943 if((mpi->width==dstride) || (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))) | |
944 { | |
8667 | 945 if(mpi->flags&MP_IMGFLAG_PLANAR) |
7537 | 946 { |
8667 | 947 if(image_format == IMGFMT_YV12) |
7537 | 948 { |
949 mpi->planes[2]= image + dstride*image_height; | |
950 mpi->planes[1]= image + dstride*image_height+ dstride*image_height/4; | |
8667 | 951 mpi->stride[1]=mpi->stride[2]=dstride/2; |
7537 | 952 } |
8667 | 953 else if(image_format == IMGFMT_IYUV || image_format == IMGFMT_I420) |
7537 | 954 { |
955 mpi->planes[1]= image + dstride*image_height; | |
956 mpi->planes[2]= image + dstride*image_height+ dstride*image_height/4; | |
8667 | 957 mpi->stride[1]=mpi->stride[2]=dstride/2; |
7537 | 958 } |
8667 | 959 else if(image_format == IMGFMT_YVU9) |
960 { | |
961 mpi->planes[2] = image + dstride*image_height; | |
962 mpi->planes[1] = image + dstride*image_height+ dstride*image_height/16; | |
963 mpi->stride[1]=mpi->stride[2]=dstride/4; | |
964 } | |
7537 | 965 } |
8667 | 966 mpi->planes[0]=image; |
967 mpi->stride[0]=dstride; | |
968 mpi->width=image_width; | |
969 mpi->height=image_height; | |
7537 | 970 mpi->flags|=MP_IMGFLAG_DIRECT; |
971 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>Direct Rendering ENABLED\n"); | |
972 return VO_TRUE; | |
973 } | |
974 return VO_FALSE; | |
975 } | |
976 | |
977 static uint32_t put_image(mp_image_t *mpi){ | |
978 | |
979 uint32_t i = 0; | |
980 uint8_t *d; | |
981 uint8_t *s; | |
982 uint32_t x = mpi->x; | |
983 uint32_t y = mpi->y; | |
984 uint32_t w = mpi->w; | |
985 uint32_t h = mpi->h; | |
986 | |
8667 | 987 if((mpi->flags&MP_IMGFLAG_DIRECT)||(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)) |
7537 | 988 { |
989 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>put_image: nothing to do: drawslices\n"); | |
990 return VO_TRUE; | |
991 } | |
992 | |
993 if (mpi->flags&MP_IMGFLAG_PLANAR) | |
994 { | |
8667 | 995 |
996 if(image_format!=IMGFMT_YVU9)draw_slice(mpi->planes,mpi->stride,mpi->w,mpi->h,0,0); | |
997 else | |
7537 | 998 { |
999 // copy Y | |
1000 d=image+dstride*y+x; | |
1001 s=mpi->planes[0]; | |
1002 for(i=0;i<h;i++){ | |
1003 memcpy(d,s,w); | |
1004 s+=mpi->stride[0]; | |
1005 d+=dstride; | |
1006 } | |
8519 | 1007 w/=4;h/=4;x/=4;y/=4; |
7537 | 1008 // copy V |
8519 | 1009 d=image+dstride*image_height + dstride*y/4+x; |
8667 | 1010 s=mpi->planes[2]; |
7537 | 1011 for(i=0;i<h;i++){ |
1012 memcpy(d,s,w); | |
1013 s+=mpi->stride[1]; | |
8519 | 1014 d+=dstride/4; |
7537 | 1015 } |
1016 // copy U | |
8519 | 1017 d=image+dstride*image_height + dstride*image_height/16 + dstride/4*y+x; |
8667 | 1018 s=mpi->planes[1]; |
7537 | 1019 for(i=0;i<h;i++){ |
1020 memcpy(d,s,w); | |
1021 s+=mpi->stride[2]; | |
8519 | 1022 d+=dstride/4; |
7537 | 1023 } |
1024 } | |
1025 } | |
1026 else //packed | |
1027 { | |
1028 memcpy( image, mpi->planes[0], image_height * dstride); | |
1029 } | |
1030 return VO_TRUE; | |
1031 } | |
1032 | |
1033 static uint32_t | |
1034 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t options, char *title, uint32_t format) | |
1035 { | |
1036 fs = options & 0x01; | |
1037 vm = options & 0x02; | |
1038 image_format = format; | |
1039 image_width = width; | |
1040 image_height = height; | |
8519 | 1041 d_image_width = d_width; |
1042 d_image_height = d_height; | |
1043 aspect_save_orig(image_width,image_height); | |
1044 aspect_save_prescale(d_image_width,d_image_height); | |
1045 aspect_save_screenres(GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN)); | |
1046 aspect(&d_image_width,&d_image_height,A_NOZOOM); | |
8667 | 1047 SetWindowText(hWnd,title); |
1048 /*release all surfaces*/ | |
7682 | 1049 if (g_lpddsBack != NULL) g_lpddsBack->lpVtbl->Release(g_lpddsBack); |
1050 g_lpddsBack = NULL; | |
1051 if(vo_doublebuffering) | |
1052 { | |
1053 if (g_lpddsOverlay != NULL)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay); | |
1054 } | |
1055 g_lpddsOverlay = NULL; | |
1056 if (g_lpddsPrimary != NULL) g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary); | |
1057 g_lpddsPrimary = NULL; | |
1058 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>overlay surfaces released\n"); | |
8667 | 1059 /*set cooperativelevel*/ |
1060 if(vm) /*exclusive mode*/ | |
1061 { | |
1062 fs=1; | |
1063 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, hWnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN) != DD_OK) | |
1064 { | |
1065 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set cooperativelevel for exclusive mode"); | |
1066 return 1; | |
1067 } | |
1068 SetWindowLong( hWnd, GWL_STYLE, 0 ); | |
1069 /*SetDisplayMode(ddobject,width,height,bpp,refreshrate,aditionalflags)*/ | |
1070 if(g_lpdd->lpVtbl->SetDisplayMode(g_lpdd,640, 480, 16,0,0) != DD_OK) | |
1071 { | |
1072 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set displaymode\n"); | |
1073 return 1; | |
1074 } | |
1075 aspect_save_screenres(GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN)); | |
1076 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>using exclusive mode\n"); | |
7537 | 1077 } |
1078 else | |
1079 { | |
8667 | 1080 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, hWnd, DDSCL_NORMAL) != DD_OK) |
7537 | 1081 { |
8667 | 1082 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set cooperativelevel for windowed mode"); |
1083 return 1; | |
7537 | 1084 } |
8667 | 1085 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>using normal cooperativelevel\n"); |
7537 | 1086 } |
8667 | 1087 if(fs) |
1088 { | |
1089 /*remove the borders*/ | |
1090 SetWindowLong( hWnd, GWL_STYLE, 0 ); | |
1091 /*change backgroundcolor*/ | |
1092 SetClassLongA(hWnd,GCL_HBRBACKGROUND,(int)CreateSolidBrush(RGB(0,0,0))); | |
1093 /*repaint*/ | |
1094 RedrawWindow(hWnd,NULL,NULL,RDW_INVALIDATE|RDW_ERASE|RDW_INTERNALPAINT); | |
1095 /*hide mouse*/ | |
1096 ShowCursor(FALSE); | |
1097 } | |
1098 /*create the surfaces*/ | |
1099 if(Directx_CreatePrimarySurface())return 1; | |
1100 if (!nooverlay && Directx_CreateOverlay(image_format)) | |
7537 | 1101 { |
8667 | 1102 nooverlay=1; /*overlay creation failed*/ |
9728 | 1103 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't use overlay mode: please use -vo directx:noaccel\n"); |
1104 return 1; | |
7537 | 1105 } |
8667 | 1106 if(nooverlay) |
1107 { | |
1108 if(Directx_CreateBackpuffer()) | |
1109 { | |
1110 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't get the driver to work on your system :(\n"); | |
1111 return 1; | |
1112 } | |
1113 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>back surface created\n"); | |
1114 vo_doublebuffering = 0; | |
1115 /*create clipper for nonoverlay mode*/ | |
1116 if(g_lpddclipper)g_lpddclipper->lpVtbl->Release(g_lpddclipper); | |
1117 g_lpddclipper=NULL; | |
1118 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;} | |
1119 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;} | |
1120 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;} | |
1121 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>clipper succesfully created\n"); | |
1122 } | |
1123 Directx_ManageDisplay(d_image_width,d_image_height); | |
7537 | 1124 memset(&ddsdsf, 0,sizeof(DDSURFACEDESC)); |
1125 ddsdsf.dwSize = sizeof (DDSURFACEDESC); | |
1126 g_lpddsBack->lpVtbl->Lock(g_lpddsBack,NULL,&ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL); | |
1127 dstride = ddsdsf.lPitch; | |
1128 image = ddsdsf.lpSurface; | |
1129 return 0; | |
1130 } | |
1131 | |
1132 static uint32_t control(uint32_t request, void *data, ...) | |
1133 { | |
1134 switch (request) { | |
1135 | |
1136 case VOCTRL_GET_IMAGE: | |
1137 return get_image(data); | |
1138 case VOCTRL_QUERY_FORMAT: | |
1139 return query_format(*((uint32_t*)data)); | |
1140 case VOCTRL_DRAW_IMAGE: | |
1141 return put_image(data); | |
1142 case VOCTRL_FULLSCREEN: | |
1143 { | |
1144 if(vm) | |
1145 { | |
1146 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>currently we do not allow to switch from exclusive to windowed mode\n"); | |
1147 } | |
1148 else | |
1149 { | |
8667 | 1150 WINDOWPLACEMENT window_placement; |
1151 uint32_t width = 0; /*default: restore to the size it had before maximizing*/ | |
1152 uint32_t height = 0; | |
1153 window_placement.length = sizeof(WINDOWPLACEMENT); | |
1154 GetWindowPlacement(hWnd, &window_placement); | |
1155 if(fs) /*go to windowed*/ | |
1156 { | |
1157 fs = 0; | |
1158 /*prevent the screen being filled with garbage*/ | |
1159 window_placement.showCmd = SW_SHOWMINIMIZED; | |
1160 SetWindowPlacement(hWnd,&window_placement); | |
1161 /*change style and restore the window*/ | |
1162 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
|
1163 window_placement.showCmd = SW_RESTORE; |
8667 | 1164 SetWindowPlacement(hWnd,&window_placement ); |
1165 /*restore backgroundcolor*/ | |
1166 SetClassLongA(hWnd,GCL_HBRBACKGROUND,(int)CreateSolidBrush(windowcolor)); | |
1167 /*never ever make a big window*/ | |
1168 if(((window_placement.rcNormalPosition.bottom - window_placement.rcNormalPosition.top)==GetSystemMetrics(SM_CYSCREEN)) | |
1169 &&((window_placement.rcNormalPosition.right - window_placement.rcNormalPosition.left)==GetSystemMetrics(SM_CXSCREEN))) | |
1170 { | |
1171 width = d_image_width; | |
1172 height = d_image_height; | |
1173 } | |
1174 /*show cursor again*/ | |
1175 ShowCursor(TRUE); | |
1176 } | |
1177 else /*go to fullscreen*/ | |
1178 { | |
1179 fs = 1; | |
1180 /*remove decoration and maximize*/ | |
1181 SetWindowLong(hWnd,GWL_STYLE,0); | |
1182 window_placement.showCmd = SW_SHOWMAXIMIZED; | |
1183 SetWindowPlacement(hWnd,&window_placement); | |
1184 /*make the window really black*/ | |
1185 SetClassLongA(hWnd,GCL_HBRBACKGROUND,(int)CreateSolidBrush(RGB(0,0,0))); | |
1186 /*hide mouse cursor in fullscreen mode*/ | |
1187 if(ShowCursor(FALSE)<0); | |
1188 else while(ShowCursor(FALSE)>=0)mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx>ShowCursor(FALSE)>=0\n"); | |
1189 } | |
1190 RedrawWindow(hWnd,NULL,NULL,RDW_INVALIDATE|RDW_ERASE|RDW_INTERNALPAINT); | |
1191 Directx_ManageDisplay(width,height); | |
7537 | 1192 } |
1193 return VO_TRUE; | |
1194 } | |
1195 }; | |
1196 return VO_NOTIMPL; | |
1197 } |