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