Mercurial > mplayer.hg
annotate libvo/vo_3dfx.c @ 11994:a7751694c177
spp softthresholding in mmx
author | michael |
---|---|
date | Tue, 24 Feb 2004 13:28:42 +0000 |
parents | fb0b7fe53645 |
children | 1c2f6de431bf |
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 XFlush(display); | |
208 XSync(display, False); | |
209 | |
210 return 0; | |
211 } | |
212 | |
213 static void | |
214 dump_yuv_planar(uint32_t *y, uint32_t *u, uint32_t *v, uint32_t to, uint32_t width, uint32_t height) | |
215 { | |
216 // YUV conversion works like this: | |
217 // | |
218 // We write the Y, U, and V planes separately into 3dfx YUV Planar memory | |
219 // region. The nice chip then takes these and packs them into the YUYV | |
220 // format in the regular frame buffer, starting at yuvBaseAddr, page 2 here. | |
221 // Then we tell the 3dfx to do a Screen to Screen Stretch BLT to copy all | |
222 // of the data on page 2 onto page 1, converting it to 16 bpp RGB as it goes. | |
223 // The result is a nice image on page 1 ready for display. | |
224 | |
225 uint32_t j; | |
226 uint32_t y_imax, uv_imax, jmax; | |
227 | |
228 reg_YUV->yuvBaseAddr = to; | |
229 reg_YUV->yuvStride = screenwidth*2; | |
230 | |
231 LOG("video_out_3dfx: starting planar dump\n"); | |
232 jmax = height>>1; // vidheight/2, height of U and V planes | |
233 y_imax = width; // Y plane is twice as wide as U and V planes | |
234 uv_imax = width>>1; // vidwidth/2/4, width of U and V planes in 32-bit words | |
235 | |
236 for (j=0;j<jmax;j++) | |
237 { | |
238 //XXX this should be hand-rolled 32 bit memcpy for safeness. | |
239 memcpy(fb_YUV->U + (uint32_t) VOODOO_YUV_STRIDE* j ,((uint8_t*) u) + uv_imax* j , uv_imax); | |
240 memcpy(fb_YUV->V + (uint32_t) VOODOO_YUV_STRIDE* j ,((uint8_t*) v) + uv_imax* j , uv_imax); | |
241 memcpy(fb_YUV->Y + (uint32_t) VOODOO_YUV_STRIDE* (j<<1) ,((uint8_t*) y) + y_imax * (j<<1) , y_imax); | |
242 memcpy(fb_YUV->Y + (uint32_t) VOODOO_YUV_STRIDE*((j<<1)+1),((uint8_t*) y) + y_imax *((j<<1)+1), y_imax); | |
243 } | |
244 LOG("video_out_3dfx: done planar dump\n"); | |
245 } | |
246 | |
247 static void | |
248 screen_to_screen_stretch_blt(uint32_t to, uint32_t from, uint32_t width, uint32_t height) | |
249 { | |
250 //FIXME - this function should be called by a show_frame function that | |
251 // uses a series of blts to show only those areas not covered | |
252 // by another window | |
253 voodoo_2d_reg saved_regs; | |
254 | |
255 LOG("video_out_3dfx: saving registers\n"); | |
256 // Save VGA regs (so X kinda works when we're done) | |
257 saved_regs = *reg_2d; | |
258 | |
259 /* The following lines set up the screen to screen stretch blt from page2 to | |
260 page 1 | |
261 */ | |
262 | |
263 LOG("video_out_3dfx: setting blt registers\n"); | |
264 reg_2d->commandExtra = 4; //disable colorkeying, enable wait for v-refresh (0100b) | |
265 reg_2d->clip0Min = 0; | |
266 reg_2d->clip0Max = 0xFFFFFFFF; //no clipping | |
267 | |
268 reg_2d->srcBaseAddr = from; | |
269 reg_2d->srcXY = 0; | |
270 reg_2d->srcFormat = screenwidth*2 | VOODOO_BLT_FORMAT_YUYV; // | 1<<21; | |
271 reg_2d->srcSize = vidwidth | (vidheight << 16); | |
272 | |
273 reg_2d->dstBaseAddr = to; | |
274 reg_2d->dstXY = 0; | |
275 reg_2d->dstFormat = screenwidth*2 | VOODOO_BLT_FORMAT_16; | |
276 | |
277 reg_2d->dstSize = width | (height << 16); | |
278 | |
279 LOG("video_out_3dfx: starting blt\n"); | |
280 // Executes screen to screen stretch blt | |
281 reg_2d->command = 2 | 1<<8 | 0xCC<<24; | |
282 | |
283 LOG("video_out_3dfx: restoring regs\n"); | |
284 restore_regs(&saved_regs); | |
285 | |
286 LOG("video_out_3dfx: done blt\n"); | |
287 } | |
288 | |
289 static void | |
290 update_target(void) | |
291 { | |
292 uint32_t xp, yp, w, h, b, d; | |
293 Window root; | |
294 | |
295 XGetGeometry(display,mywindow,&root,&xp,&yp,&w,&h,&b,&d); | |
296 XTranslateCoordinates(display,mywindow,root,0,0,&xp,&yp,&root); | |
297 dispx = (uint32_t) xp; | |
298 dispy = (uint32_t) yp; | |
299 dispwidth = (uint32_t) w; | |
300 dispheight = (uint32_t) h; | |
301 | |
302 if (is_fullscreen) | |
303 targetoffset = vidpage0offset + (screenheight - dispheight)/2*screenwidth*screendepth + (screenwidth-dispwidth)/2*screendepth; | |
304 else | |
305 targetoffset = vidpage0offset + (dispy*screenwidth + dispx)*screendepth; | |
306 } | |
307 | |
308 static uint32_t | |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
6207
diff
changeset
|
309 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) |
1 | 310 { |
311 int fd; | |
312 char *name = ":0.0"; | |
313 pioData data; | |
314 uint32_t retval; | |
315 | |
316 if(getenv("DISPLAY")) | |
317 name = getenv("DISPLAY"); | |
318 display = XOpenDisplay(name); | |
319 | |
320 screenwidth = XDisplayWidth(display,0); | |
321 screenheight = XDisplayHeight(display,0); | |
322 | |
323 page_space = screenwidth*screenheight*screendepth; | |
324 vidpage0offset = 0; | |
325 vidpage1offset = page_space; // Use third and fourth pages | |
326 vidpage2offset = page_space*2; | |
327 | |
328 signal(SIGALRM,sighup); | |
329 //alarm(120); | |
330 | |
331 // Open driver device | |
332 if ( (fd = open("/dev/3dfx",O_RDWR) ) == -1) | |
333 { | |
614 | 334 printf("Couldn't open /dev/3dfx\n"); |
1 | 335 exit(1); |
336 } | |
337 | |
338 // Store sizes for later | |
339 vidwidth = width; | |
340 vidheight = height; | |
341 | |
342 is_fullscreen = fullscreen = 0; | |
343 if (!is_fullscreen) | |
10994 | 344 create_window(display, title); |
1 | 345 |
346 // Ask 3dfx driver for base memory address 0 | |
347 data.port = 0x10; // PCI_BASE_ADDRESS_0_LINUX; | |
348 data.size = 4; | |
349 data.value = &baseAddr0; | |
350 data.device = 0; | |
351 if ((retval = ioctl(fd,_IOC(_IOC_READ,'3',3,0),&data)) < 0) | |
352 { | |
353 printf("Error: %d\n",retval); | |
354 //return -1; | |
355 } | |
356 | |
357 // Ask 3dfx driver for base memory address 1 | |
358 data.port = 0x14; // PCI_BASE_ADDRESS_1_LINUX; | |
359 data.size = 4; | |
360 data.value = &baseAddr1; | |
361 data.device = 0; | |
362 if ((retval = ioctl(fd,_IOC(_IOC_READ,'3',3,0),&data)) < 0) | |
363 { | |
364 printf("Error: %d\n",retval); | |
365 //return -1; | |
366 } | |
367 | |
368 // Map all 3dfx memory areas | |
369 memBase0 = mmap(0,0x1000000,PROT_READ | PROT_WRITE,MAP_SHARED,fd,baseAddr0); | |
370 memBase1 = mmap(0,3*page_space,PROT_READ | PROT_WRITE,MAP_SHARED,fd,baseAddr1); | |
371 if (memBase0 == (uint32_t *) 0xFFFFFFFF || memBase1 == (uint32_t *) 0xFFFFFFFF) | |
372 { | |
373 printf("Couldn't map 3dfx memory areas: %p,%p,%d\n", | |
374 memBase0,memBase1,errno); | |
375 } | |
376 | |
377 // Set up global pointers | |
378 reg_IO = (void *)memBase0 + VOODOO_IO_REG_OFFSET; | |
379 reg_2d = (void *)memBase0 + VOODOO_2D_REG_OFFSET; | |
380 reg_YUV = (void *)memBase0 + VOODOO_YUV_REG_OFFSET; | |
381 fb_YUV = (void *)memBase0 + VOODOO_YUV_PLANE_OFFSET; | |
382 | |
383 vidpage0 = (void *)memBase1 + (unsigned long int)vidpage0offset; | |
384 vidpage1 = (void *)memBase1 + (unsigned long int)vidpage1offset; | |
385 vidpage2 = (void *)memBase1 + (unsigned long int)vidpage2offset; | |
386 | |
387 // Clear pages 1,2,3 | |
388 // leave page 0, that belongs to X. | |
389 // So does part of 1. Oops. | |
390 memset(vidpage1,0x00,page_space); | |
391 memset(vidpage2,0x00,page_space); | |
392 | |
393 if (is_fullscreen) | |
394 memset(vidpage0,0x00,page_space); | |
395 | |
396 | |
397 #ifndef VOODOO_DEBUG | |
398 // Show page 0 (unblanked) | |
399 reg_IO->vidDesktopStartAddr = vidpage0offset; | |
400 | |
401 /* Stop X from messing with my video registers! | |
402 Find a better way to do this? | |
403 Currently I use DGA to tell XF86 to not screw with registers, but I can't really use it | |
404 to do FB stuff because I need to know the absolute FB position and offset FB position | |
405 to feed to BLT command | |
406 */ | |
407 //XF86DGADirectVideo(display,0,XF86DGADirectGraphics); //| XF86DGADirectMouse | XF86DGADirectKeyb); | |
408 #endif | |
409 | |
410 /* fd is deliberately not closed - if it were, mmaps might be released??? */ | |
411 | |
412 atexit(restore); | |
413 | |
414 printf("(display) 3dfx initialized %p\n",memBase1); | |
415 return 0; | |
416 } | |
417 | |
418 static uint32_t | |
419 draw_frame(uint8_t *src[]) | |
420 { | |
421 LOG("video_out_3dfx: starting display_frame\n"); | |
422 | |
423 // Put packed data onto page 2 | |
424 dump_yuv_planar((uint32_t *)src[0],(uint32_t *)src[1],(uint32_t *)src[2], | |
425 vidpage2offset,vidwidth,vidheight); | |
426 | |
427 LOG("video_out_3dfx: done display_frame\n"); | |
428 return 0; | |
429 } | |
430 | |
431 static uint32_t | |
1978 | 432 //draw_slice(uint8_t *src[], uint32_t slice_num) |
433 draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
1 | 434 { |
435 uint32_t target; | |
436 | |
1978 | 437 target = vidpage2offset + (screenwidth*2 * y); |
438 dump_yuv_planar((uint32_t *)src[0],(uint32_t *)src[1],(uint32_t *)src[2],target,vidwidth,h); | |
1 | 439 return 0; |
440 } | |
441 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1137
diff
changeset
|
442 static void draw_osd(void) |
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 } |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1137
diff
changeset
|
445 |
1 | 446 static void |
447 flip_page(void) | |
448 { | |
449 //FIXME - update_target() should be called by event handler when window | |
450 // is resized or moved | |
451 update_target(); | |
452 LOG("video_out_3dfx: calling blt function\n"); | |
453 screen_to_screen_stretch_blt(targetoffset, vidpage2offset, dispwidth, dispheight); | |
454 } | |
455 | |
456 static uint32_t | |
457 query_format(uint32_t format) | |
458 { | |
6207 | 459 /* does this supports scaling? up & down? */ |
1 | 460 switch(format){ |
461 case IMGFMT_YV12: | |
462 // case IMGFMT_YUY2: | |
463 // case IMGFMT_RGB|24: | |
464 // case IMGFMT_BGR|24: | |
6207 | 465 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW; |
1 | 466 } |
467 return 0; | |
468 } | |
469 | |
470 static void | |
471 uninit(void) | |
472 { | |
473 } | |
474 | |
475 | |
31 | 476 static void check_events(void) |
477 { | |
478 } | |
479 | |
4352 | 480 static uint32_t preinit(const char *arg) |
481 { | |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
482 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
|
483 { |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
484 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
|
485 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
|
486 } |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
487 return 0; |
4352 | 488 } |
31 | 489 |
4596 | 490 static uint32_t control(uint32_t request, void *data, ...) |
4352 | 491 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
492 switch (request) { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
493 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
494 return query_format(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
495 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
496 return VO_NOTIMPL; |
4352 | 497 } |