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