Mercurial > mplayer.hg
annotate libvo/vo_directx.c @ 7763:cdb43addad4c
-fixed-vo support
author | pontscho |
---|---|
date | Wed, 16 Oct 2002 21:32:03 +0000 |
parents | 32878695ca8b |
children | f804db78f704 |
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 | |
7682 | 60 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
|
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: | |
7713 | 252 {mp_msg(MSGT_VO, MSGL_ERR,"invalid pixelformat: %s\n",g_ddpf[i].img_format_name);break;} |
7537 | 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); | |
7682 | 327 g_lpddsPrimary = NULL; |
328 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
|
329 if(hWnd != NULL)DestroyWindow(hWnd); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
330 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>window destroyed\n"); |
7537 | 331 if (g_lpdd != NULL) g_lpdd->lpVtbl->Release(g_lpdd); |
332 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>directdrawobject released\n"); | |
333 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>uninited\n"); | |
334 } | |
335 | |
336 static uint32_t Directx_InitDirectDraw() | |
337 { | |
338 HINSTANCE hddraw_dll; | |
339 HRESULT (WINAPI *OurDirectDrawCreate)(GUID *,LPDIRECTDRAW *,IUnknown *); | |
340 LPDIRECTDRAW lpDDraw; | |
341 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>Initing DirectDraw\n" ); | |
342 | |
343 //load direct draw DLL: based on videolans code | |
344 hddraw_dll = LoadLibrary("DDRAW.DLL"); | |
345 if( hddraw_dll == NULL ) | |
346 { | |
347 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed loading ddraw.dll\n" ); | |
348 return 1; | |
349 } | |
350 OurDirectDrawCreate = (void *)GetProcAddress(hddraw_dll, "DirectDrawCreate"); | |
351 if ( OurDirectDrawCreate == NULL ) | |
352 { | |
353 FreeLibrary( hddraw_dll ); | |
354 hddraw_dll = NULL; | |
355 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>failed geting proc address\n"); | |
356 return 1; | |
357 } | |
358 // initialize DirectDraw and create directx v1 object | |
359 if (OurDirectDrawCreate( NULL, &lpDDraw, NULL ) != DD_OK ) | |
360 { | |
361 lpDDraw = NULL; | |
362 FreeLibrary( hddraw_dll ); | |
363 hddraw_dll = NULL; | |
364 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't initialize ddraw\n"); | |
365 return 1; | |
366 } | |
367 // ask IDirectDraw for IDirectDraw2 | |
368 if (lpDDraw->lpVtbl->QueryInterface(lpDDraw, &IID_IDirectDraw2, (void **)&g_lpdd) != DD_OK) | |
369 { | |
370 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>no directx 2 installed\n"); | |
371 return 1; | |
372 } | |
373 //release our old interface and free ddraw.dll | |
374 lpDDraw->lpVtbl->Release(lpDDraw); | |
375 FreeLibrary( hddraw_dll); | |
376 hddraw_dll= NULL; | |
377 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>lpDDraw released & hddraw freed\n" ); | |
378 //set cooperativelevel: for our tests, no handle to a window is needed | |
379 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, NULL, DDSCL_NORMAL) != DD_OK) | |
380 { | |
381 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>could not set cooperativelevel for hardwarecheck\n"); | |
382 return 1; | |
383 } | |
384 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>DirectDraw Inited\n"); | |
385 return 0; | |
386 } | |
387 | |
388 static void check_events(void) | |
389 { | |
390 MSG msg; | |
391 while (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE)) | |
392 { | |
393 TranslateMessage(&msg); | |
394 DispatchMessage(&msg); | |
395 } | |
396 } | |
397 | |
398 //fullscreen code: centers and zooms image, returns window rect | |
399 static RECT Directx_Fullscreencalc() | |
400 { | |
401 uint32_t xscreen = GetSystemMetrics(SM_CXSCREEN); | |
402 uint32_t yscreen = GetSystemMetrics(SM_CYSCREEN); | |
403 uint32_t xstretch1000,ystretch1000; | |
404 RECT rd_window; | |
405 rd.top = 0; | |
406 rd.left=0; | |
407 rd.right = xscreen; | |
408 rd.bottom = yscreen; | |
409 rd_window=rd; | |
410 xstretch1000 = (xscreen*1000)/d_image_width; | |
411 ystretch1000 = (yscreen*1000)/d_image_height; | |
412 if(xstretch1000 > ystretch1000) | |
413 { | |
414 rd.bottom=yscreen; | |
415 rd.right=(d_image_width*ystretch1000)/1000; | |
416 } | |
417 else | |
418 { | |
419 rd.right=xscreen; | |
420 rd.bottom=(d_image_height*xstretch1000)/1000; | |
421 } | |
422 //printf("%i,%i,%i,%i,%i,%i\n",xstretch1000,ystretch1000,d_image_height,d_image_width,rd.bottom,rd.right); | |
423 rd.left = (xscreen-rd.right)/2; | |
424 rd.right= rd.right+rd.left; | |
425 rd.top = (yscreen-rd.bottom)/2; | |
426 rd.bottom = rd.bottom + rd.top; | |
427 return rd_window; | |
428 } | |
429 | |
430 //this function hopefully takes into account most of those alignments, minimum stretch, move outside of screen | |
431 //no stretch hw, etc... and displays the overlay | |
432 //I seperated non overlay mode because it is already to much stuff in here | |
433 static uint32_t Directx_DisplayOverlay() | |
434 { | |
435 WINDOWPLACEMENT window_placement; | |
436 RECT rd_window; //Rect of the window | |
437 HRESULT ddrval; | |
438 DDCAPS capsDrv; | |
439 DDOVERLAYFX ovfx; | |
440 DWORD dwUpdateFlags; | |
441 HWND hWndafter; | |
442 uint32_t uStretchFactor1000; //minimum stretch | |
443 uint32_t xstretch1000,ystretch1000; | |
444 uint32_t xscreen = GetSystemMetrics(SM_CXSCREEN); | |
445 uint32_t yscreen = GetSystemMetrics(SM_CYSCREEN); | |
446 POINT point_window; | |
447 //get driver capabilities | |
448 ZeroMemory(&capsDrv, sizeof(capsDrv)); | |
449 capsDrv.dwSize = sizeof(capsDrv); | |
450 if(g_lpdd->lpVtbl->GetCaps(g_lpdd,&capsDrv, NULL) != DD_OK)return 1; | |
451 //check minimum stretch, depends on display adaptor and mode (refresh rate!) | |
452 uStretchFactor1000 = capsDrv.dwMinOverlayStretch>1000 ? capsDrv.dwMinOverlayStretch : 1000; | |
453 window_placement.length = sizeof(WINDOWPLACEMENT); | |
454 GetWindowPlacement(hWnd, &window_placement ); | |
455 if(!fs) //windowed | |
456 { | |
457 if (window_placement.showCmd == SW_SHOWMAXIMIZED) //is our window maximized? | |
458 { | |
459 CloseWindow(hWnd); //we do this to prevent the screen being filled with garbage | |
460 window_placement.showCmd = SW_SHOWNORMAL; //restore | |
461 SetWindowLong( hWnd,GWL_STYLE , WS_OVERLAPPEDWINDOW| WS_SIZEBOX ); //change Style | |
462 SetWindowPlacement( hWnd, &window_placement ); | |
463 } | |
464 } | |
465 else //fullscreen | |
466 { | |
467 if (window_placement.showCmd == SW_SHOWNORMAL) //is our window normal? | |
468 { | |
469 window_placement.showCmd = SW_SHOWMAXIMIZED; //maximize | |
470 SetWindowLong( hWnd, GWL_STYLE, 0 ); //change style | |
471 SetWindowPlacement( hWnd, &window_placement ); | |
472 } | |
473 } | |
474 | |
475 if(!fs) | |
476 { | |
477 GetClientRect (hWnd, &rd_window); | |
478 if(rd_window.top == rd_window.bottom) //window is minimized | |
479 { | |
480 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL); //hide the overlay | |
481 return 0; | |
482 } | |
483 if (GetWindowTextLength(hWnd)==0) | |
484 { | |
485 SetWindowText(hWnd,"MPlayer - DirectX Overlay"); //for the first call: change only title, not the overlay size | |
486 } | |
487 else | |
488 { | |
489 d_image_width = rd_window.right - rd_window.left; //calculate new overlay from the window size | |
490 d_image_height = rd_window.bottom - rd_window.top; | |
491 } | |
492 } | |
493 else | |
494 { | |
495 rd.top = 0;rd.left=0; | |
496 rd.bottom = yscreen; rd.right = xscreen; | |
497 rs.top = 0;rs.left=0; | |
498 rs.bottom = image_height; rs.right = image_width; | |
499 } | |
500 //check if hardware can stretch or shrink, if needed | |
501 //do some cards support only nshrinking or is this a special shrink,stretch feature? | |
502 if((d_image_width < image_width)&& !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKX)) | |
503 { | |
504 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKXN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only shrinkN\n"); | |
505 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't shrink x\n"); | |
506 d_image_width=image_width; | |
507 } | |
508 else if((d_image_width > image_width)&& !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHX)) | |
509 { | |
510 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHXN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only stretchN\n"); | |
511 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't stretch x\n"); | |
512 d_image_width = image_width; | |
513 } | |
514 if((d_image_height < image_height) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKY)) | |
515 { | |
516 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSHRINKYN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only shrinkN\n"); | |
517 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't shrink y\n"); | |
518 d_image_height = image_height; | |
519 } | |
520 else if((d_image_height > image_height ) && !(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHY)) | |
521 { | |
522 if(capsDrv.dwFXCaps & DDFXCAPS_OVERLAYSTRETCHYN)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can only stretchN\n"); | |
523 else mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't stretch y\n"); | |
524 d_image_height = image_height; | |
525 } | |
526 | |
527 if(!fs) //windowed | |
528 { | |
529 point_window.x = 0; //overlayposition relative to the window | |
530 point_window.y = 0; | |
531 ClientToScreen(hWnd,&point_window); | |
532 rd.left = point_window.x; //fill the wanted x1&y1 of the Overlay | |
533 rd.top = point_window.y; | |
534 //fix minimum stretch | |
535 rd.right = ((d_image_width+rd.left)*uStretchFactor1000+999)/1000; | |
536 rd.bottom = (d_image_height+rd.top)*uStretchFactor1000/1000; | |
537 //calculate xstretch1000 and ystretch1000 | |
538 xstretch1000 = ((rd.right - rd.left)* 1000)/image_width ; | |
539 ystretch1000 = ((rd.bottom - rd.top)* 1000)/image_height; | |
540 //handle move outside of window with cropping | |
541 rd_window = rd; //don't crop the window !!! | |
542 if(rd.left < 0) //move out left | |
543 { | |
544 rs.left=(-rd.left*1000)/xstretch1000; | |
545 rd.left = 0; | |
546 } | |
547 else rs.left=0; | |
548 if(rd.top < 0) //move out up | |
549 { | |
550 rs.top=(-rd.top*1000)/ystretch1000; | |
551 rd.top = 0; | |
552 } | |
553 else rs.top = 0; | |
554 if(rd.right > xscreen) //move out right | |
555 { | |
556 rs.right=((xscreen-rd.left)*1000)/xstretch1000; | |
557 rd.right= xscreen; | |
558 } | |
559 else rs.right = image_width; | |
560 if(rd.bottom > yscreen) //move out down | |
561 { | |
562 rs.bottom=((yscreen-rd.top)*1000)/ystretch1000; | |
563 rd.bottom= yscreen; | |
564 } | |
565 else rs.bottom= image_height; | |
566 } | |
567 else | |
568 { | |
569 rd_window = Directx_Fullscreencalc(); | |
570 } | |
571 // check alignment restrictions | |
572 // these expressions (x & -y) just do alignment by dropping low order bits... | |
573 // so to round up, we add first, then truncate. | |
574 if ((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYSRC) && capsDrv.dwAlignBoundarySrc) | |
575 rs.left = (rs.left + capsDrv.dwAlignBoundarySrc / 2) & -(signed)(capsDrv.dwAlignBoundarySrc); | |
576 if ((capsDrv.dwCaps & DDCAPS_ALIGNSIZESRC) && capsDrv.dwAlignSizeSrc) | |
577 rs.right = rs.left + (rs.right - rs.left + capsDrv.dwAlignSizeSrc / 2) & -(signed) (capsDrv.dwAlignSizeSrc); | |
578 if ((capsDrv.dwCaps & DDCAPS_ALIGNBOUNDARYDEST) && capsDrv.dwAlignBoundaryDest) | |
579 { | |
580 rd.left = (rd.left + capsDrv.dwAlignBoundaryDest / 2) & -(signed)(capsDrv.dwAlignBoundaryDest); | |
581 if(!fs)rd_window.left = (rd_window.left + capsDrv.dwAlignBoundaryDest / 2) & -(signed)(capsDrv.dwAlignBoundaryDest); //don't forget the window | |
582 } | |
583 if ((capsDrv.dwCaps & DDCAPS_ALIGNSIZEDEST) && capsDrv.dwAlignSizeDest) | |
584 { | |
585 rd.right = rd.left + (rd.right - rd.left) & -(signed) (capsDrv.dwAlignSizeDest); | |
586 if(!fs)rd_window.right = rd_window.left + (rd_window.right - rd_window.left) & -(signed) (capsDrv.dwAlignSizeDest); //don't forget the window | |
587 } | |
588 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
|
589 |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
590 //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
|
591 //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
|
592 //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
|
593 //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
|
594 |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
595 // 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
|
596 ZeroMemory(&ovfx, sizeof(ovfx)); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
597 ovfx.dwSize = sizeof(ovfx); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
598 ovfx.dckDestColorkey.dwColorSpaceLowValue = destcolorkey; |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
599 ovfx.dckDestColorkey.dwColorSpaceHighValue = destcolorkey; |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
600 // 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
|
601 dwUpdateFlags = DDOVER_SHOW | DDOVER_DDFX; |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
602 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
|
603 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
|
604 //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
|
605 if((fs) || (!fs && ontop))hWndafter=HWND_TOPMOST; |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
606 else hWndafter=HWND_NOTOPMOST; |
7537 | 607 SetWindowPos(hWnd, |
608 hWndafter, | |
609 rd_window.left, | |
610 rd_window.top, | |
611 rd_window.right - rd_window.left, | |
612 rd_window.bottom - rd_window.top, | |
613 SWP_SHOWWINDOW|SWP_NOOWNERZORDER/*|SWP_NOREDRAW*/); | |
614 | |
7624
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
615 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,&rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx); |
7537 | 616 if(FAILED(ddrval)) |
617 { | |
618 // on cause might be the driver lied about minimum stretch | |
619 // we should try upping the destination size a bit, or | |
620 // perhaps shrinking the source size | |
621 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>UpdateOverlay failed\n" ); | |
622 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 ); | |
623 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>"); | |
624 switch (ddrval) | |
625 { | |
626 case DDERR_NOSTRETCHHW: | |
627 {mp_msg(MSGT_VO, MSGL_ERR ,"hardware can't stretch: try to size the window back\n");break;} | |
628 case DDERR_INVALIDRECT: | |
629 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid rectangle\n");break;} | |
630 case DDERR_INVALIDPARAMS: | |
631 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid parameters\n");break;} | |
632 case DDERR_HEIGHTALIGN: | |
633 {mp_msg(MSGT_VO, MSGL_ERR ,"height align\n");break;} | |
634 case DDERR_XALIGN: | |
635 {mp_msg(MSGT_VO, MSGL_ERR ,"x align\n");break;} | |
636 case DDERR_UNSUPPORTED: | |
637 {mp_msg(MSGT_VO, MSGL_ERR ,"unsupported\n");break;} | |
638 case DDERR_INVALIDSURFACETYPE: | |
639 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid surfacetype\n");break;} | |
640 case DDERR_INVALIDOBJECT: | |
641 {mp_msg(MSGT_VO, MSGL_ERR ,"invalid object\n");break;} | |
642 case DDERR_SURFACELOST: | |
643 { | |
644 mp_msg(MSGT_VO, MSGL_ERR ,"surfaces lost\n"); | |
645 g_lpddsOverlay->lpVtbl->Restore( g_lpddsOverlay ); //restore and try again | |
646 g_lpddsPrimary->lpVtbl->Restore( g_lpddsPrimary ); | |
647 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,&rs, g_lpddsPrimary, &rd, dwUpdateFlags, &ovfx); | |
648 if(ddrval !=DD_OK)mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>UpdateOverlay failed again\n" ); | |
649 break; | |
650 } | |
651 } | |
652 //hide overlay | |
653 if(ddrval != DD_OK) | |
654 { | |
655 ddrval = g_lpddsOverlay->lpVtbl->UpdateOverlay(g_lpddsOverlay,NULL, g_lpddsPrimary, NULL, DDOVER_HIDE, NULL); | |
656 return 1; | |
657 } | |
658 } | |
659 return 0; | |
660 } | |
661 | |
662 static uint32_t Directx_DisplayNonOverlay() | |
663 { | |
664 WINDOWPLACEMENT window_placement; | |
665 RECT rd_window; //rect of the window | |
666 HWND hWndafter; | |
667 POINT point_window; | |
668 window_placement.length = sizeof(WINDOWPLACEMENT); | |
669 GetWindowPlacement(hWnd, &window_placement ); | |
670 | |
671 if(!fs) //windowed | |
672 { | |
673 if (window_placement.showCmd == SW_SHOWMAXIMIZED) //is our window maximized? | |
674 { | |
675 CloseWindow(hWnd); //we do this to prevent the screen from being filled with garbage | |
676 window_placement.showCmd = SW_SHOWNORMAL; //restore | |
677 SetWindowLong(hWnd,GWL_STYLE , WS_OVERLAPPEDWINDOW| WS_SIZEBOX ); //change style | |
678 SetWindowPlacement( hWnd, &window_placement ); | |
679 } | |
680 } | |
681 else //fullscreen | |
682 { | |
683 if (window_placement.showCmd == SW_SHOWNORMAL) //is our window normal? | |
684 { | |
685 window_placement.showCmd = SW_SHOWMAXIMIZED; //maximize | |
686 SetWindowLong( hWnd, GWL_STYLE, 0 ); //change Style | |
687 SetWindowPlacement( hWnd, &window_placement ); | |
688 } | |
689 } | |
690 | |
691 if(!fs) //windowed | |
692 { | |
693 GetClientRect (hWnd, &rd_window); | |
694 if(rd_window.top == rd_window.bottom)return 0; //window is minimized | |
695 if (GetWindowTextLength(hWnd)==0) | |
696 { | |
697 SetWindowText(hWnd,"MPlayer - DirectX NoN-Overlay"); //for the first call: change only title, not d_image stuff | |
698 } | |
699 else | |
700 { | |
701 d_image_width = rd_window.right - rd_window.left; //Calculate new Imagedimensions | |
702 d_image_height = rd_window.bottom - rd_window.top; | |
703 } | |
704 point_window.x = 0; //imageposition relative to the window | |
705 point_window.y = 0; | |
706 ClientToScreen(hWnd,&point_window); | |
707 rd.left = point_window.x; //fill the wanted x1&y1 of the image | |
708 rd.top = point_window.y; | |
709 rd.right = d_image_width+rd.left; | |
710 rd.bottom =d_image_height+rd.top; | |
711 rd_window = rd; | |
712 AdjustWindowRect(&rd_window,WS_OVERLAPPEDWINDOW|WS_SIZEBOX,0); | |
713 } | |
714 else //fullscreen | |
715 { | |
716 rd_window=Directx_Fullscreencalc(); | |
717 } | |
718 if((fs) || (!fs && ontop))hWndafter=HWND_TOPMOST; | |
719 else hWndafter=HWND_NOTOPMOST; | |
720 SetWindowPos(hWnd, | |
721 hWndafter, | |
722 rd_window.left, | |
723 rd_window.top, | |
724 rd_window.right - rd_window.left, | |
725 rd_window.bottom - rd_window.top, | |
726 SWP_SHOWWINDOW|SWP_NOOWNERZORDER); | |
727 return 0; | |
728 } | |
729 | |
730 //find out supported overlay pixelformats | |
731 static uint32_t Directx_CheckOverlayPixelformats() | |
732 { | |
733 DDCAPS capsDrv; | |
734 HRESULT ddrval; | |
735 DDSURFACEDESC ddsdOverlay; | |
736 uint32_t i; | |
737 uint32_t formatcount = 0; | |
738 //get driver caps to determine overlay support | |
739 ZeroMemory(&capsDrv, sizeof(capsDrv)); | |
740 capsDrv.dwSize = sizeof(capsDrv); | |
741 ddrval = g_lpdd->lpVtbl->GetCaps(g_lpdd,&capsDrv, NULL); | |
742 if (FAILED(ddrval)) | |
743 { | |
744 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>failed getting ddrawcaps\n"); | |
745 return 1; | |
746 } | |
747 if (!(capsDrv.dwCaps & DDCAPS_OVERLAY)) | |
748 { | |
749 mp_msg(MSGT_VO, MSGL_ERR ,"<vo_directx><ERROR>Your card doesn't support overlay\n"); | |
750 return 1; | |
751 } | |
752 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>testing supported overlay pixelformats\n"); | |
753 //it is not possible to query for pixel formats supported by the | |
754 //overlay hardware: try out various formats till one works | |
755 ZeroMemory(&ddsdOverlay, sizeof(ddsdOverlay)); | |
756 ddsdOverlay.dwSize = sizeof(ddsdOverlay); | |
757 ddsdOverlay.ddsCaps.dwCaps=DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY; | |
758 ddsdOverlay.dwFlags= DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH| DDSD_PIXELFORMAT; | |
759 ddsdOverlay.dwWidth=300; | |
760 ddsdOverlay.dwHeight=280; | |
761 ddsdOverlay.dwBackBufferCount=0; | |
762 //try to create an overlay surface using one of the pixel formats in our global list | |
763 i=0; | |
764 do | |
765 { | |
766 ddsdOverlay.ddpfPixelFormat=g_ddpf[i].g_ddpfOverlay; | |
767 ddrval = g_lpdd->lpVtbl->CreateSurface(g_lpdd,&ddsdOverlay, &g_lpddsOverlay, NULL); | |
768 if (ddrval == DD_OK) | |
769 { | |
770 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT OVERLAY>%i %s supported\n",i,g_ddpf[i].img_format_name); | |
771 g_ddpf[i].drv_caps = VFCAP_CSP_SUPPORTED |VFCAP_OSD |VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_HWSCALE_UP; | |
772 formatcount++;} | |
773 else mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT OVERLAY>%i %s not supported\n",i,g_ddpf[i].img_format_name); | |
774 if (g_lpddsOverlay != NULL) {g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay);g_lpddsOverlay = NULL;} | |
775 } while( ++i < NUM_FORMATS ); | |
776 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>Your card supports %i of %i overlayformats\n",formatcount, NUM_FORMATS); | |
777 if (formatcount == 0) | |
778 { | |
779 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><WARN>Your card supports overlay, but we couldn't create one\n"); | |
780 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>This can have the following reasons:\n"); | |
781 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- you are already using an overlay with another app\n"); | |
782 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- you don't have enough videomemory\n"); | |
783 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>- vo_directx doesn't support the cards overlay pixelformat\n"); | |
784 return 1; | |
785 } | |
786 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 | |
787 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 ;) | |
788 return 0; | |
789 } | |
790 | |
791 //find out the Pixelformat of the Primary Surface | |
792 static uint32_t Directx_CheckPrimaryPixelformat() | |
793 { | |
794 uint32_t i=0; | |
795 uint32_t formatcount = 0; | |
796 DDPIXELFORMAT ddpf; | |
7624
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
797 DDSURFACEDESC ddsd; |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
798 HDC hdc; |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
799 HRESULT hres; |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
800 COLORREF rgbT; |
7537 | 801 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>checking primary surface\n"); |
802 memset( &ddpf, 0, sizeof( DDPIXELFORMAT )); | |
803 ddpf.dwSize = sizeof( DDPIXELFORMAT ); | |
804 //we have to create a primary surface first | |
805 if(Directx_CreatePrimarySurface()!=0)return 1; | |
806 if(g_lpddsPrimary->lpVtbl->GetPixelFormat( g_lpddsPrimary, &ddpf ) != DD_OK ) | |
807 { | |
808 mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>can't get pixelformat\n"); | |
809 return 1; | |
810 } | |
811 while ( i < NUM_FORMATS ) | |
812 { | |
813 if (g_ddpf[i].g_ddpfOverlay.dwRGBBitCount == ddpf.dwRGBBitCount) | |
814 { | |
815 if (g_ddpf[i].g_ddpfOverlay.dwRBitMask == ddpf.dwRBitMask) | |
816 { | |
817 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><FORMAT PRIMARY>%i %s supported\n",i,g_ddpf[i].img_format_name); | |
7713 | 818 g_ddpf[i].drv_caps = VFCAP_CSP_SUPPORTED |VFCAP_OSD; |
7537 | 819 formatcount++; |
820 } | |
821 } | |
822 i++; | |
823 } | |
7624
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
824 //get the colorkey for overlay mode |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
825 destcolorkey = CLR_INVALID; |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
826 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
|
827 { |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
828 rgbT = GetPixel(hdc, 0, 0); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
829 SetPixel(hdc, 0, 0, windowcolor); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
830 g_lpddsPrimary->lpVtbl->ReleaseDC(g_lpddsPrimary,hdc); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
831 } |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
832 // read back the converted color |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
833 ddsd.dwSize = sizeof(ddsd); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
834 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
|
835 ; |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
836 if (hres == 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 destcolorkey = *(DWORD *) ddsd.lpSurface; |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
839 if (ddsd.ddpfPixelFormat.dwRGBBitCount < 32) |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
840 destcolorkey &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1; |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
841 g_lpddsPrimary->lpVtbl->Unlock(g_lpddsPrimary,NULL); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
842 } |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
843 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
|
844 { |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
845 SetPixel(hdc, 0, 0, rgbT); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
846 g_lpddsPrimary->lpVtbl->ReleaseDC(g_lpddsPrimary,hdc); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
847 } |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
848 //release primary |
7537 | 849 g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary); |
850 g_lpddsPrimary = NULL; | |
851 if(formatcount==0) | |
852 { | |
853 mp_msg(MSGT_VO, MSGL_FATAL ,"<vo_directx><FATAL ERROR>Unknown Pixelformat\n"); | |
854 return 1; | |
855 } | |
856 return 0; | |
857 } | |
858 | |
859 //function handles input | |
860 static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) | |
861 { | |
862 switch (message) | |
863 { | |
864 case WM_DESTROY: | |
865 { | |
7624
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
866 PostQuitMessage(0); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
867 return 0; |
7537 | 868 } |
869 case WM_CLOSE: | |
870 { | |
871 mplayer_put_key('q'); | |
872 return 0; | |
873 } | |
874 case WM_WINDOWPOSCHANGED: | |
875 { | |
876 //printf("Windowposchange\n"); | |
7624
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
877 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
|
878 { |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
879 if(nooverlay)Directx_DisplayNonOverlay(); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
880 else Directx_DisplayOverlay(); |
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
881 } |
7537 | 882 break; |
883 } | |
884 case WM_SYSCOMMAND: | |
885 { | |
886 switch (wParam) | |
887 { //kill screensaver etc. | |
888 //note: works only when the window is active | |
889 //you can workaround this by disabling the allow screensaver option in | |
890 //the link to the app | |
891 case SC_SCREENSAVE: | |
892 case SC_MONITORPOWER: | |
893 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>killing screensaver\n" ); | |
894 return 0; | |
895 } | |
896 } | |
897 case WM_KEYDOWN: | |
898 { | |
899 switch (wParam) | |
900 { | |
901 case VK_LEFT: | |
902 {mplayer_put_key(KEY_LEFT);break;} | |
903 case VK_UP: | |
904 {mplayer_put_key(KEY_UP);break;} | |
905 case VK_RIGHT: | |
906 {mplayer_put_key(KEY_RIGHT);break;} | |
907 case VK_DOWN: | |
908 {mplayer_put_key(KEY_DOWN);break;} | |
909 case VK_TAB: | |
910 {mplayer_put_key(KEY_TAB);break;} | |
911 case VK_CONTROL: | |
912 {mplayer_put_key(KEY_CTRL);break;} | |
913 case VK_DELETE: | |
914 {mplayer_put_key(KEY_DELETE);break;} | |
915 case VK_INSERT: | |
916 {mplayer_put_key(KEY_INSERT);break;} | |
917 case VK_HOME: | |
918 {mplayer_put_key(KEY_HOME);break;} | |
919 case VK_END: | |
920 {mplayer_put_key(VK_END);break;} | |
921 case VK_PRIOR: | |
922 {mplayer_put_key(KEY_PAGE_UP);break;} | |
923 case VK_NEXT: | |
924 {mplayer_put_key(KEY_PAGE_DOWN);break;} | |
925 case VK_ESCAPE: | |
926 {mplayer_put_key(KEY_ESC);break;} | |
927 } | |
928 break; | |
929 } | |
930 case WM_CHAR: | |
931 { | |
932 mplayer_put_key(wParam); | |
933 break; | |
934 } | |
935 | |
936 } | |
937 return DefWindowProc(hWnd, message, wParam, lParam); | |
938 } | |
939 | |
940 static uint32_t Directx_CreateWindow() | |
941 { | |
942 HINSTANCE hInstance = GetModuleHandle(NULL); | |
943 WNDCLASS wc; | |
944 wc.style = CS_HREDRAW | CS_VREDRAW; | |
945 wc.lpfnWndProc = WndProc; | |
946 wc.cbClsExtra = 0; | |
947 wc.cbWndExtra = 0; | |
948 wc.hInstance = hInstance; | |
949 wc.hCursor = LoadCursor(NULL,IDC_ARROW); | |
950 wc.hIcon = LoadIcon(NULL,IDI_APPLICATION); | |
7624
b1a3b979c630
This patch hopefully fixes colorkeying and a segfault in exclusive mode
arpi
parents:
7537
diff
changeset
|
951 wc.hbrBackground = CreateSolidBrush(windowcolor); |
7537 | 952 wc.lpszClassName = "Mplayer - Movieplayer for Linux"; |
953 wc.lpszMenuName = NULL; | |
954 RegisterClass(&wc); | |
955 hWnd = CreateWindow("MPlayer - Movieplayer for Linux", | |
956 "", | |
957 WS_OVERLAPPEDWINDOW| WS_SIZEBOX, | |
958 CW_USEDEFAULT, //position x | |
959 CW_USEDEFAULT, //position y | |
960 100, //width | |
961 100, //height | |
962 NULL, | |
963 NULL, | |
964 hInstance, | |
965 NULL); | |
966 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>initial mplayer window created\n"); | |
967 return 0; | |
968 } | |
969 | |
970 static uint32_t preinit(const char *arg) | |
971 { | |
7682 | 972 if(arg) |
973 { | |
974 if(!strcmp(arg,"noaccel")) | |
975 { | |
976 mp_msg(MSGT_VO,MSGL_V,"<vo_directx><INFO>disabled overlay\n"); | |
977 nooverlay = 1; | |
978 } | |
979 else | |
980 { | |
981 mp_msg(MSGT_VO,MSGL_ERR,"<vo_directx><ERROR>unknown subdevice: %s\n",arg); | |
982 return ENOSYS; | |
983 } | |
984 } | |
7537 | 985 if (Directx_InitDirectDraw()!= 0)return 1; //init DirectDraw |
986 if (Directx_CheckPrimaryPixelformat()!=0)return 1; | |
7682 | 987 if (!nooverlay && Directx_CheckOverlayPixelformats() == 0) //check for supported hardware |
7537 | 988 { |
989 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>hardware supports overlay\n"); | |
990 nooverlay = 0; | |
991 } | |
992 else //if we can't have overlay we create a backpuffer with the same imageformat as the primary surface | |
993 { | |
994 mp_msg(MSGT_VO, MSGL_V ,"<vo_directx><INFO>using backpuffer\n"); | |
995 nooverlay = 1; | |
996 } | |
997 Directx_CreateWindow(); //create initial window | |
998 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>preinit succesfully finished\n"); | |
999 return 0; | |
1000 } | |
1001 | |
1002 static uint32_t draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y ) | |
1003 { | |
1004 uint8_t *s; | |
1005 uint8_t *d; | |
1006 uint32_t i=0; | |
1007 | |
1008 // copy Y | |
1009 d=image+dstride*y+x; | |
1010 s=src[0]; | |
1011 for(i=0;i<h;i++){ | |
1012 memcpy(d,s,w); | |
1013 s+=stride[0]; | |
1014 d+=stride[0]; | |
1015 } | |
1016 | |
1017 w/=2;h/=2;x/=2;y/=2; | |
1018 | |
1019 // copy U | |
1020 d=image+image_width*image_height + dstride*y/2+x; | |
1021 if(swap)s=src[2]; | |
1022 else s=src[1]; | |
1023 for(i=0;i<h;i++){ | |
1024 memcpy(d,s,w); | |
1025 s+=stride[1]; | |
1026 d+=stride[1]; | |
1027 } | |
1028 | |
1029 // copy V | |
1030 d=image+image_width*image_height +image_width*image_height/4 + dstride*y/2+x; | |
1031 if(swap)s=src[1]; | |
1032 else s=src[2]; | |
1033 for(i=0;i<h;i++){ | |
1034 memcpy(d,s,w); | |
1035 s+=stride[2]; | |
1036 d+=stride[2]; | |
1037 } | |
1038 return 0; | |
1039 } | |
1040 | |
1041 static void flip_page(void) | |
1042 { | |
1043 HRESULT dxresult; | |
1044 //bufferflipping is slow on my system? | |
1045 if (vo_doublebuffering) | |
1046 { | |
1047 // flip to the next image in the sequence | |
1048 dxresult = g_lpddsOverlay->lpVtbl->Flip( g_lpddsOverlay,NULL, DDFLIP_WAIT); | |
1049 if(dxresult == DDERR_SURFACELOST) | |
1050 { | |
1051 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR><vo_directx><INFO>Restoring Surface\n"); | |
1052 g_lpddsBack->lpVtbl->Restore( g_lpddsBack ); | |
1053 dxresult = g_lpddsOverlay->lpVtbl->Flip( g_lpddsOverlay,NULL, DDFLIP_WAIT); | |
1054 } | |
1055 if(dxresult != DD_OK)mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't flip page\n"); | |
1056 } | |
1057 g_lpddsBack->lpVtbl->Lock(g_lpddsBack,NULL,&ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT , NULL); | |
1058 g_lpddsBack->lpVtbl->Unlock (g_lpddsBack,NULL); | |
1059 dstride = ddsdsf.lPitch; | |
1060 image = ddsdsf.lpSurface; | |
1061 if(nooverlay == 1) | |
1062 { | |
1063 DDBLTFX ddbltfx; | |
1064 // ask for the "NOTEARING" option | |
1065 memset( &ddbltfx, 0, sizeof(DDBLTFX) ); | |
1066 ddbltfx.dwSize = sizeof(DDBLTFX); | |
1067 ddbltfx.dwDDFX = DDBLTFX_NOTEARING; | |
1068 g_lpddsPrimary->lpVtbl->Blt(g_lpddsPrimary, &rd, g_lpddsBack, NULL, DDBLT_WAIT, &ddbltfx); | |
1069 } | |
1070 } | |
1071 | |
1072 static uint32_t draw_frame(uint8_t *src[]) | |
1073 { | |
1074 memcpy( image, *src, dstride * image_height ); | |
1075 return 0; | |
1076 } | |
1077 | |
1078 static uint32_t get_image(mp_image_t *mpi) | |
1079 { | |
1080 //dr is untested for planar formats | |
1081 //we should make a surface in mem and use busmastering! | |
1082 if(mpi->flags&MP_IMGFLAG_READABLE) {mp_msg(MSGT_VO, MSGL_V,"<vo_directx><ERROR>slow video ram\n");return VO_FALSE;} | |
1083 if(mpi->type==MP_IMGTYPE_STATIC) {mp_msg(MSGT_VO, MSGL_V,"<vo_directx><ERROR>not static\n");return VO_FALSE;} | |
1084 if((mpi->width==dstride) || (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))) | |
1085 { | |
1086 if(mpi->flags&MP_IMGFLAG_PLANAR && image_format==IMGFMT_YV12) | |
1087 { | |
1088 mpi->planes[0]=image; | |
1089 if(swap) | |
1090 { | |
1091 mpi->planes[2]= image + dstride*image_height; | |
1092 mpi->planes[1]= image + dstride*image_height+ dstride*image_height/4; | |
1093 } | |
1094 else | |
1095 { | |
1096 mpi->planes[1]= image + dstride*image_height; | |
1097 mpi->planes[2]= image + dstride*image_height+ dstride*image_height/4; | |
1098 } | |
1099 mpi->width=mpi->stride[0]=dstride; | |
1100 mpi->stride[1]=mpi->stride[2]=dstride/2; | |
1101 } | |
1102 else //packed | |
1103 { | |
1104 mpi->planes[0]=image; | |
1105 mpi->width=image_width; | |
1106 mpi->stride[0]=dstride; | |
1107 } | |
1108 mpi->flags|=MP_IMGFLAG_DIRECT; | |
1109 mp_msg(MSGT_VO, MSGL_DBG3, "<vo_directx><INFO>Direct Rendering ENABLED\n"); | |
1110 return VO_TRUE; | |
1111 } | |
1112 return VO_FALSE; | |
1113 } | |
1114 | |
1115 static uint32_t put_image(mp_image_t *mpi){ | |
1116 | |
1117 uint32_t i = 0; | |
1118 uint8_t *d; | |
1119 uint8_t *s; | |
1120 uint32_t x = mpi->x; | |
1121 uint32_t y = mpi->y; | |
1122 uint32_t w = mpi->w; | |
1123 uint32_t h = mpi->h; | |
1124 | |
1125 if((mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))) | |
1126 { | |
1127 mp_msg(MSGT_VO, MSGL_DBG3 ,"<vo_directx><INFO>put_image: nothing to do: drawslices\n"); | |
1128 return VO_TRUE; | |
1129 } | |
1130 | |
1131 if (mpi->flags&MP_IMGFLAG_PLANAR) | |
1132 { | |
1133 if (image_format == IMGFMT_YV12|| image_format == IMGFMT_I420 || image_format == IMGFMT_IYUV) | |
1134 { | |
1135 draw_slice(mpi->planes, mpi->stride, mpi->w,mpi->h,mpi->x,mpi->y ); | |
1136 } | |
1137 else if(image_format==IMGFMT_YVU9) | |
1138 { | |
1139 // copy Y | |
1140 d=image+dstride*y+x; | |
1141 s=mpi->planes[0]; | |
1142 for(i=0;i<h;i++){ | |
1143 memcpy(d,s,w); | |
1144 s+=mpi->stride[0]; | |
1145 d+=dstride; | |
1146 } | |
1147 w/=4;h/=4;x/=4;y/=4; dstride/=4; | |
1148 // copy V | |
1149 d=image+image_width*image_height + dstride*y+x; | |
1150 if(swap)s=mpi->planes[2]; | |
1151 else s=mpi->planes[1]; | |
1152 for(i=0;i<h;i++){ | |
1153 memcpy(d,s,w); | |
1154 s+=mpi->stride[1]; | |
1155 d+=dstride; | |
1156 } | |
1157 // copy U | |
1158 d=image+image_width*image_height +image_width*image_height/16 + dstride*y+x; | |
1159 if(swap)s=mpi->planes[1]; | |
1160 else s=mpi->planes[2]; | |
1161 for(i=0;i<h;i++){ | |
1162 memcpy(d,s,w); | |
1163 s+=mpi->stride[2]; | |
1164 d+=dstride; | |
1165 } | |
1166 } | |
1167 } | |
1168 else //packed | |
1169 { | |
1170 memcpy( image, mpi->planes[0], image_height * dstride); | |
1171 } | |
1172 return VO_TRUE; | |
1173 } | |
1174 | |
1175 static uint32_t | |
1176 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t options, char *title, uint32_t format) | |
1177 { | |
1178 //int zoom = options & 0x04; | |
1179 //int flip = options & 0x08; | |
1180 fs = options & 0x01; | |
1181 vm = options & 0x02; | |
1182 if(vm)fs=1; | |
1183 image_format = format; | |
1184 d_image_width = d_width; | |
1185 d_image_height = d_height; | |
1186 image_width = width; | |
1187 image_height = height; | |
1188 //printf("<vo_directx><INFO>config entered\n"); | |
1189 //printf("width:%i\nheight:%i\nd_width:%i\nd_height%i\n",width,height,d_width,d_height); | |
7682 | 1190 SetWindowText(hWnd,""); |
1191 if (g_lpddsBack != NULL) g_lpddsBack->lpVtbl->Release(g_lpddsBack); | |
1192 g_lpddsBack = NULL; | |
1193 if(vo_doublebuffering) | |
1194 { | |
1195 if (g_lpddsOverlay != NULL)g_lpddsOverlay->lpVtbl->Release(g_lpddsOverlay); | |
1196 } | |
1197 g_lpddsOverlay = NULL; | |
1198 if (g_lpddsPrimary != NULL) g_lpddsPrimary->lpVtbl->Release(g_lpddsPrimary); | |
1199 g_lpddsPrimary = NULL; | |
1200 mp_msg(MSGT_VO, MSGL_DBG3,"<vo_directx><INFO>overlay surfaces released\n"); | |
1201 if(vm) | |
7537 | 1202 { //exclusive mode |
1203 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, hWnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN) != DD_OK) | |
1204 { | |
1205 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set cooperativelevel for exclusive mode"); | |
1206 return 1; | |
1207 } //ddobject,width,height,bpp,refreshrate,aditionalflags | |
1208 SetWindowLong( hWnd, GWL_STYLE, 0 ); //changeWindowStyle | |
1209 if(g_lpdd->lpVtbl->SetDisplayMode(g_lpdd,640, 480, 16,0,0) != DD_OK) | |
1210 { | |
1211 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set displaymode\n"); | |
1212 return 1; | |
1213 } | |
1214 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>cooperativelevel for exclusive mode set\n"); | |
1215 } | |
1216 else | |
1217 { | |
1218 if (g_lpdd->lpVtbl->SetCooperativeLevel(g_lpdd, hWnd, DDSCL_NORMAL) != DD_OK) | |
1219 { | |
1220 mp_msg(MSGT_VO, MSGL_FATAL,"<vo_directx><FATAL ERROR>can't set cooperativelevel for windowed mode"); | |
1221 return 1; | |
1222 } | |
1223 SetWindowLong( hWnd,WS_OVERLAPPEDWINDOW| WS_SIZEBOX , 0 ); | |
1224 mp_msg(MSGT_VO, MSGL_V,"<vo_directx><INFO>cooperativelevel for windowed mode set\n"); | |
1225 } | |
1226 if(Directx_CreatePrimarySurface()!=0)return 1; | |
1227 if (nooverlay==0) | |
1228 { | |
1229 if(Directx_CreateOverlay(image_format)==0) | |
1230 { | |
1231 Directx_DisplayOverlay(); | |
1232 if(!vo_doublebuffering) g_lpddsBack = g_lpddsOverlay; | |
1233 } | |
1234 else | |
1235 { | |
1236 nooverlay=1; //if failed try with nooverlay | |
1237 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>can't use overlay mode\n"); | |
1238 | |
1239 } | |
1240 } | |
1241 if (nooverlay==1) | |
1242 { | |
1243 if(Directx_CreateBackpuffer()!=0)return 1; | |
1244 Directx_DisplayNonOverlay(); | |
1245 } | |
1246 | |
1247 if(Directx_CreateClipper() != 0)return 1; | |
1248 memset(&ddsdsf, 0,sizeof(DDSURFACEDESC)); | |
1249 ddsdsf.dwSize = sizeof (DDSURFACEDESC); | |
1250 g_lpddsBack->lpVtbl->Lock(g_lpddsBack,NULL,&ddsdsf, DDLOCK_NOSYSLOCK | DDLOCK_WAIT, NULL); | |
1251 g_lpddsBack->lpVtbl->Unlock (g_lpddsBack,NULL); | |
1252 dstride = ddsdsf.lPitch; | |
1253 image = ddsdsf.lpSurface; | |
1254 if(image_format==IMGFMT_I420||image_format==IMGFMT_IYUV) | |
1255 { | |
1256 if(swap)swap=0; //swap uv | |
1257 else swap=1; | |
1258 } | |
1259 return 0; | |
1260 } | |
1261 | |
1262 static uint32_t control(uint32_t request, void *data, ...) | |
1263 { | |
1264 switch (request) { | |
1265 | |
1266 case VOCTRL_GET_IMAGE: | |
1267 return get_image(data); | |
1268 case VOCTRL_QUERY_FORMAT: | |
1269 return query_format(*((uint32_t*)data)); | |
1270 case VOCTRL_DRAW_IMAGE: | |
1271 return put_image(data); | |
1272 case VOCTRL_FULLSCREEN: | |
1273 { | |
1274 //printf("Display mode switch\n"); | |
1275 if(vm) | |
1276 { | |
1277 mp_msg(MSGT_VO, MSGL_ERR,"<vo_directx><ERROR>currently we do not allow to switch from exclusive to windowed mode\n"); | |
1278 } | |
1279 else | |
1280 { | |
1281 if(fs)fs=0; //set to fullscreen or windowed | |
1282 else fs = 1; | |
1283 if(nooverlay == 0)Directx_DisplayOverlay(); //update window | |
1284 else Directx_DisplayNonOverlay(); | |
1285 } | |
1286 return VO_TRUE; | |
1287 } | |
1288 }; | |
1289 return VO_NOTIMPL; | |
1290 } |