Mercurial > mplayer.hg
annotate libvo/vo_3dfx.c @ 16740:e168c0704cfc
change to switch/case for dumpsub
author | ods15 |
---|---|
date | Wed, 12 Oct 2005 14:37:03 +0000 |
parents | fd51fd1ff231 |
children | ecdffaf7118c |
rev | line source |
---|---|
1 | 1 /* |
2 * video_out_3dfx.c | |
3 * | |
4 * Copyright (C) Colin Cross Apr 2000 | |
5 * | |
6 * This file heavily based off of video_out_mga.c of Aaron Holtzman's | |
7 * mpeg2dec | |
8 * | |
9 * mpeg2dec is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2, or (at your option) | |
12 * any later version. | |
13 * | |
14 * mpeg2dec is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with GNU Make; see the file COPYING. If not, write to | |
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 * | |
23 */ | |
24 | |
25 #include <stdio.h> | |
26 #include <stdlib.h> | |
27 #include <string.h> | |
28 | |
29 #include "config.h" | |
30 #include "video_out.h" | |
31 #include "video_out_internal.h" | |
32 | |
33 #include <sys/ioctl.h> | |
34 #include <unistd.h> | |
35 #include <fcntl.h> | |
36 #include <sys/mman.h> | |
37 #include <errno.h> | |
38 #include <wchar.h> | |
39 #include <signal.h> | |
40 | |
41 #include <X11/Xlib.h> | |
42 #include <X11/extensions/xf86dga.h> | |
43 #include <X11/Xutil.h> | |
44 | |
45 //#define LOG(x) syslog(LOG_USER | LOG_DEBUG,x) | |
46 #define LOG(x) | |
47 | |
48 #include "drivers/3dfx.h" | |
49 | |
354 | 50 #include "fastmemcpy.h" |
350 | 51 |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7124
diff
changeset
|
52 static vo_info_t info = |
1 | 53 { |
54 "3dfx (/dev/3dfx)", | |
55 "3dfx", | |
56 "Colin Cross <colin@MIT.EDU>", | |
57 "" | |
58 }; | |
59 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7124
diff
changeset
|
60 LIBVO_EXTERN(3dfx) |
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7124
diff
changeset
|
61 |
1 | 62 static uint32_t is_fullscreen = 1; |
63 | |
64 static uint32_t vidwidth; | |
65 static uint32_t vidheight; | |
66 | |
67 static uint32_t screenwidth; | |
68 static uint32_t screenheight; | |
69 static uint32_t screendepth = 2; //Only 16bpp supported right now | |
70 | |
71 static uint32_t dispwidth = 1280; // You can change these to whatever you want | |
72 static uint32_t dispheight = 720; // 16:9 screen ratio?? | |
73 static uint32_t dispx; | |
74 static uint32_t dispy; | |
75 | |
76 static uint32_t *vidpage0; | |
77 static uint32_t *vidpage1; | |
78 static uint32_t *vidpage2; | |
79 | |
80 static uint32_t vidpage0offset; | |
81 static uint32_t vidpage1offset; | |
82 static uint32_t vidpage2offset; | |
83 | |
84 // Current pointer into framebuffer where display is located | |
85 static uint32_t targetoffset; | |
86 | |
87 static uint32_t page_space; | |
88 | |
89 static voodoo_io_reg *reg_IO; | |
90 static voodoo_2d_reg *reg_2d; | |
91 static voodoo_yuv_reg *reg_YUV; | |
92 static voodoo_yuv_fb *fb_YUV; | |
93 | |
94 static uint32_t *memBase0, *memBase1; | |
95 static uint32_t baseAddr0, baseAddr1; | |
96 | |
97 | |
98 /* X11 related variables */ | |
99 static Display *display; | |
100 static Window mywindow; | |
101 static int bpp; | |
102 static XWindowAttributes attribs; | |
103 | |
104 | |
105 static void | |
106 restore(void) | |
107 { | |
108 //reg_IO->vidDesktopStartAddr = vidpage0offset; | |
109 XF86DGADirectVideo(display,0,0); | |
110 } | |
111 | |
112 static void | |
113 sighup(int foo) | |
114 { | |
115 //reg_IO->vidDesktopStartAddr = vidpage0offset; | |
116 XF86DGADirectVideo(display,0,0); | |
117 exit(0); | |
118 } | |
119 | |
120 static void | |
121 restore_regs(voodoo_2d_reg *regs) | |
122 { | |
123 reg_2d->commandExtra = regs->commandExtra; | |
124 reg_2d->clip0Min = regs->clip0Min; | |
125 reg_2d->clip0Max = regs->clip0Max; | |
126 | |
127 reg_2d->srcBaseAddr = regs->srcBaseAddr; | |
128 reg_2d->srcXY = regs->srcXY; | |
129 reg_2d->srcFormat = regs->srcFormat; | |
130 reg_2d->srcSize = regs->srcSize; | |
131 | |
132 reg_2d->dstBaseAddr = regs->dstBaseAddr; | |
133 reg_2d->dstXY = regs->dstXY; | |
134 reg_2d->dstFormat = regs->dstFormat; | |
135 | |
136 reg_2d->dstSize = regs->dstSize; | |
137 reg_2d->command = 0; | |
138 } | |
139 | |
140 static uint32_t | |
10994 | 141 create_window(Display *display, char *title) |
1 | 142 { |
143 int screen; | |
144 unsigned int fg, bg; | |
145 XSizeHints hint; | |
146 XVisualInfo vinfo; | |
147 XEvent xev; | |
148 | |
149 Colormap theCmap; | |
150 XSetWindowAttributes xswa; | |
151 unsigned long xswamask; | |
152 | |
153 screen = DefaultScreen(display); | |
154 | |
155 hint.x = 0; | |
156 hint.y = 10; | |
157 hint.width = dispwidth; | |
158 hint.height = dispheight; | |
159 hint.flags = PPosition | PSize; | |
160 | |
161 bg = WhitePixel(display, screen); | |
162 fg = BlackPixel(display, screen); | |
163 | |
164 XGetWindowAttributes(display, DefaultRootWindow(display), &attribs); | |
165 bpp = attribs.depth; | |
166 if (bpp != 16) | |
167 { | |
614 | 168 printf("Only 16bpp supported!"); |
1 | 169 exit(-1); |
170 } | |
171 | |
172 XMatchVisualInfo(display,screen,bpp,TrueColor,&vinfo); | |
173 printf("visual id is %lx\n",vinfo.visualid); | |
174 | |
175 theCmap = XCreateColormap(display, RootWindow(display,screen), | |
176 vinfo.visual, AllocNone); | |
177 | |
178 xswa.background_pixel = 0; | |
179 xswa.border_pixel = 1; | |
180 xswa.colormap = theCmap; | |
181 xswamask = CWBackPixel | CWBorderPixel |CWColormap; | |
182 | |
183 | |
184 mywindow = XCreateWindow(display, RootWindow(display,screen), | |
185 hint.x, hint.y, hint.width, hint.height, 4, bpp,CopyFromParent,vinfo.visual,xswamask,&xswa); | |
1137
4c7b219e126c
patch: some X11 compliance fixed: set ClassHint and better fullscreen mode
arpi_esp
parents:
614
diff
changeset
|
186 vo_x11_classhint( display,mywindow,"3dfx" ); |
1 | 187 |
188 XSelectInput(display, mywindow, StructureNotifyMask); | |
189 | |
190 /* Tell other applications about this window */ | |
191 | |
10994 | 192 XSetStandardProperties(display, mywindow, title, title, None, NULL, 0, &hint); |
1 | 193 |
194 /* Map window. */ | |
195 | |
196 XMapWindow(display, mywindow); | |
197 | |
198 /* Wait for map. */ | |
199 do | |
200 { | |
201 XNextEvent(display, &xev); | |
202 } | |
203 while (xev.type != MapNotify || xev.xmap.event != mywindow); | |
204 | |
205 XSelectInput(display, mywindow, NoEventMask); | |
206 | |
207 XSync(display, False); | |
208 | |
209 return 0; | |
210 } | |
211 | |
212 static void | |
213 dump_yuv_planar(uint32_t *y, uint32_t *u, uint32_t *v, uint32_t to, uint32_t width, uint32_t height) | |
214 { | |
215 // YUV conversion works like this: | |
216 // | |
217 // We write the Y, U, and V planes separately into 3dfx YUV Planar memory | |
218 // region. The nice chip then takes these and packs them into the YUYV | |
219 // format in the regular frame buffer, starting at yuvBaseAddr, page 2 here. | |
220 // Then we tell the 3dfx to do a Screen to Screen Stretch BLT to copy all | |
221 // of the data on page 2 onto page 1, converting it to 16 bpp RGB as it goes. | |
222 // The result is a nice image on page 1 ready for display. | |
223 | |
224 uint32_t j; | |
225 uint32_t y_imax, uv_imax, jmax; | |
226 | |
227 reg_YUV->yuvBaseAddr = to; | |
228 reg_YUV->yuvStride = screenwidth*2; | |
229 | |
230 LOG("video_out_3dfx: starting planar dump\n"); | |
231 jmax = height>>1; // vidheight/2, height of U and V planes | |
232 y_imax = width; // Y plane is twice as wide as U and V planes | |
233 uv_imax = width>>1; // vidwidth/2/4, width of U and V planes in 32-bit words | |
234 | |
235 for (j=0;j<jmax;j++) | |
236 { | |
237 //XXX this should be hand-rolled 32 bit memcpy for safeness. | |
238 memcpy(fb_YUV->U + (uint32_t) VOODOO_YUV_STRIDE* j ,((uint8_t*) u) + uv_imax* j , uv_imax); | |
239 memcpy(fb_YUV->V + (uint32_t) VOODOO_YUV_STRIDE* j ,((uint8_t*) v) + uv_imax* j , uv_imax); | |
240 memcpy(fb_YUV->Y + (uint32_t) VOODOO_YUV_STRIDE* (j<<1) ,((uint8_t*) y) + y_imax * (j<<1) , y_imax); | |
241 memcpy(fb_YUV->Y + (uint32_t) VOODOO_YUV_STRIDE*((j<<1)+1),((uint8_t*) y) + y_imax *((j<<1)+1), y_imax); | |
242 } | |
243 LOG("video_out_3dfx: done planar dump\n"); | |
244 } | |
245 | |
246 static void | |
247 screen_to_screen_stretch_blt(uint32_t to, uint32_t from, uint32_t width, uint32_t height) | |
248 { | |
249 //FIXME - this function should be called by a show_frame function that | |
250 // uses a series of blts to show only those areas not covered | |
251 // by another window | |
252 voodoo_2d_reg saved_regs; | |
253 | |
254 LOG("video_out_3dfx: saving registers\n"); | |
255 // Save VGA regs (so X kinda works when we're done) | |
256 saved_regs = *reg_2d; | |
257 | |
258 /* The following lines set up the screen to screen stretch blt from page2 to | |
259 page 1 | |
260 */ | |
261 | |
262 LOG("video_out_3dfx: setting blt registers\n"); | |
263 reg_2d->commandExtra = 4; //disable colorkeying, enable wait for v-refresh (0100b) | |
264 reg_2d->clip0Min = 0; | |
265 reg_2d->clip0Max = 0xFFFFFFFF; //no clipping | |
266 | |
267 reg_2d->srcBaseAddr = from; | |
268 reg_2d->srcXY = 0; | |
269 reg_2d->srcFormat = screenwidth*2 | VOODOO_BLT_FORMAT_YUYV; // | 1<<21; | |
270 reg_2d->srcSize = vidwidth | (vidheight << 16); | |
271 | |
272 reg_2d->dstBaseAddr = to; | |
273 reg_2d->dstXY = 0; | |
274 reg_2d->dstFormat = screenwidth*2 | VOODOO_BLT_FORMAT_16; | |
275 | |
276 reg_2d->dstSize = width | (height << 16); | |
277 | |
278 LOG("video_out_3dfx: starting blt\n"); | |
279 // Executes screen to screen stretch blt | |
280 reg_2d->command = 2 | 1<<8 | 0xCC<<24; | |
281 | |
282 LOG("video_out_3dfx: restoring regs\n"); | |
283 restore_regs(&saved_regs); | |
284 | |
285 LOG("video_out_3dfx: done blt\n"); | |
286 } | |
287 | |
288 static void | |
289 update_target(void) | |
290 { | |
291 uint32_t xp, yp, w, h, b, d; | |
292 Window root; | |
293 | |
294 XGetGeometry(display,mywindow,&root,&xp,&yp,&w,&h,&b,&d); | |
295 XTranslateCoordinates(display,mywindow,root,0,0,&xp,&yp,&root); | |
296 dispx = (uint32_t) xp; | |
297 dispy = (uint32_t) yp; | |
298 dispwidth = (uint32_t) w; | |
299 dispheight = (uint32_t) h; | |
300 | |
301 if (is_fullscreen) | |
302 targetoffset = vidpage0offset + (screenheight - dispheight)/2*screenwidth*screendepth + (screenwidth-dispwidth)/2*screendepth; | |
303 else | |
304 targetoffset = vidpage0offset + (dispy*screenwidth + dispx)*screendepth; | |
305 } | |
306 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
13056
diff
changeset
|
307 static int |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
6207
diff
changeset
|
308 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) |
1 | 309 { |
310 int fd; | |
311 char *name = ":0.0"; | |
312 pioData data; | |
313 uint32_t retval; | |
314 | |
315 if(getenv("DISPLAY")) | |
316 name = getenv("DISPLAY"); | |
317 display = XOpenDisplay(name); | |
318 | |
319 screenwidth = XDisplayWidth(display,0); | |
320 screenheight = XDisplayHeight(display,0); | |
321 | |
322 page_space = screenwidth*screenheight*screendepth; | |
323 vidpage0offset = 0; | |
324 vidpage1offset = page_space; // Use third and fourth pages | |
325 vidpage2offset = page_space*2; | |
326 | |
327 signal(SIGALRM,sighup); | |
328 //alarm(120); | |
329 | |
330 // Open driver device | |
331 if ( (fd = open("/dev/3dfx",O_RDWR) ) == -1) | |
332 { | |
614 | 333 printf("Couldn't open /dev/3dfx\n"); |
1 | 334 exit(1); |
335 } | |
336 | |
337 // Store sizes for later | |
338 vidwidth = width; | |
339 vidheight = height; | |
340 | |
341 is_fullscreen = fullscreen = 0; | |
342 if (!is_fullscreen) | |
10994 | 343 create_window(display, title); |
1 | 344 |
345 // Ask 3dfx driver for base memory address 0 | |
346 data.port = 0x10; // PCI_BASE_ADDRESS_0_LINUX; | |
347 data.size = 4; | |
348 data.value = &baseAddr0; | |
349 data.device = 0; | |
350 if ((retval = ioctl(fd,_IOC(_IOC_READ,'3',3,0),&data)) < 0) | |
351 { | |
352 printf("Error: %d\n",retval); | |
353 //return -1; | |
354 } | |
355 | |
356 // Ask 3dfx driver for base memory address 1 | |
357 data.port = 0x14; // PCI_BASE_ADDRESS_1_LINUX; | |
358 data.size = 4; | |
359 data.value = &baseAddr1; | |
360 data.device = 0; | |
361 if ((retval = ioctl(fd,_IOC(_IOC_READ,'3',3,0),&data)) < 0) | |
362 { | |
363 printf("Error: %d\n",retval); | |
364 //return -1; | |
365 } | |
366 | |
367 // Map all 3dfx memory areas | |
368 memBase0 = mmap(0,0x1000000,PROT_READ | PROT_WRITE,MAP_SHARED,fd,baseAddr0); | |
369 memBase1 = mmap(0,3*page_space,PROT_READ | PROT_WRITE,MAP_SHARED,fd,baseAddr1); | |
370 if (memBase0 == (uint32_t *) 0xFFFFFFFF || memBase1 == (uint32_t *) 0xFFFFFFFF) | |
371 { | |
372 printf("Couldn't map 3dfx memory areas: %p,%p,%d\n", | |
373 memBase0,memBase1,errno); | |
374 } | |
375 | |
376 // Set up global pointers | |
377 reg_IO = (void *)memBase0 + VOODOO_IO_REG_OFFSET; | |
378 reg_2d = (void *)memBase0 + VOODOO_2D_REG_OFFSET; | |
379 reg_YUV = (void *)memBase0 + VOODOO_YUV_REG_OFFSET; | |
380 fb_YUV = (void *)memBase0 + VOODOO_YUV_PLANE_OFFSET; | |
381 | |
382 vidpage0 = (void *)memBase1 + (unsigned long int)vidpage0offset; | |
383 vidpage1 = (void *)memBase1 + (unsigned long int)vidpage1offset; | |
384 vidpage2 = (void *)memBase1 + (unsigned long int)vidpage2offset; | |
385 | |
386 // Clear pages 1,2,3 | |
387 // leave page 0, that belongs to X. | |
388 // So does part of 1. Oops. | |
389 memset(vidpage1,0x00,page_space); | |
390 memset(vidpage2,0x00,page_space); | |
391 | |
392 if (is_fullscreen) | |
393 memset(vidpage0,0x00,page_space); | |
394 | |
395 | |
396 #ifndef VOODOO_DEBUG | |
397 // Show page 0 (unblanked) | |
398 reg_IO->vidDesktopStartAddr = vidpage0offset; | |
399 | |
400 /* Stop X from messing with my video registers! | |
401 Find a better way to do this? | |
402 Currently I use DGA to tell XF86 to not screw with registers, but I can't really use it | |
403 to do FB stuff because I need to know the absolute FB position and offset FB position | |
404 to feed to BLT command | |
405 */ | |
406 //XF86DGADirectVideo(display,0,XF86DGADirectGraphics); //| XF86DGADirectMouse | XF86DGADirectKeyb); | |
407 #endif | |
408 | |
409 /* fd is deliberately not closed - if it were, mmaps might be released??? */ | |
410 | |
411 atexit(restore); | |
412 | |
413 printf("(display) 3dfx initialized %p\n",memBase1); | |
414 return 0; | |
415 } | |
416 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
13056
diff
changeset
|
417 static int |
1 | 418 draw_frame(uint8_t *src[]) |
419 { | |
420 LOG("video_out_3dfx: starting display_frame\n"); | |
421 | |
422 // Put packed data onto page 2 | |
423 dump_yuv_planar((uint32_t *)src[0],(uint32_t *)src[1],(uint32_t *)src[2], | |
424 vidpage2offset,vidwidth,vidheight); | |
425 | |
426 LOG("video_out_3dfx: done display_frame\n"); | |
427 return 0; | |
428 } | |
429 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
13056
diff
changeset
|
430 static int |
1978 | 431 //draw_slice(uint8_t *src[], uint32_t slice_num) |
432 draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
1 | 433 { |
434 uint32_t target; | |
435 | |
1978 | 436 target = vidpage2offset + (screenwidth*2 * y); |
437 dump_yuv_planar((uint32_t *)src[0],(uint32_t *)src[1],(uint32_t *)src[2],target,vidwidth,h); | |
1 | 438 return 0; |
439 } | |
440 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1137
diff
changeset
|
441 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1137
diff
changeset
|
442 { |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1137
diff
changeset
|
443 } |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1137
diff
changeset
|
444 |
1 | 445 static void |
446 flip_page(void) | |
447 { | |
448 //FIXME - update_target() should be called by event handler when window | |
449 // is resized or moved | |
450 update_target(); | |
451 LOG("video_out_3dfx: calling blt function\n"); | |
452 screen_to_screen_stretch_blt(targetoffset, vidpage2offset, dispwidth, dispheight); | |
453 } | |
454 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
13056
diff
changeset
|
455 static int |
1 | 456 query_format(uint32_t format) |
457 { | |
6207 | 458 /* does this supports scaling? up & down? */ |
1 | 459 switch(format){ |
460 case IMGFMT_YV12: | |
461 // case IMGFMT_YUY2: | |
462 // case IMGFMT_RGB|24: | |
463 // case IMGFMT_BGR|24: | |
6207 | 464 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW; |
1 | 465 } |
466 return 0; | |
467 } | |
468 | |
469 static void | |
470 uninit(void) | |
471 { | |
472 } | |
473 | |
474 | |
31 | 475 static void check_events(void) |
476 { | |
477 } | |
478 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
13056
diff
changeset
|
479 static int preinit(const char *arg) |
4352 | 480 { |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
481 if(arg) |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
482 { |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
483 printf("vo_3dfx: Unknown subdevice: %s\n",arg); |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
484 return ENOSYS; |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
485 } |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
486 return 0; |
4352 | 487 } |
31 | 488 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
13056
diff
changeset
|
489 static int control(uint32_t request, void *data, ...) |
4352 | 490 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
491 switch (request) { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
492 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
493 return query_format(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
494 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
495 return VO_NOTIMPL; |
4352 | 496 } |