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