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