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