Mercurial > mplayer.hg
annotate libvo/vo_tdfxfb.c @ 4995:d26babb53d8d
DivX5linux support working (only tested with divx3 and divx4 upto now, will try getting divx5 damples now)
author | atmos4 |
---|---|
date | Sat, 09 Mar 2002 00:12:49 +0000 |
parents | 32e1f5042f65 |
children | 80d8fed6e683 |
rev | line source |
---|---|
2350 | 1 // uncomment this if you pached mplayer.c with mplayer_our_out_buffer_hack.diff |
2 //#define VO_TDFXFB_METHOD 2 | |
3 #define VO_TDFXFB_METHOD 1 | |
4 // method: Host-to-Screen bitBLT-ing. | |
5 #define HWACCEL_OSD_M2 | |
6 //#define YV12_CONV_METH | |
7 #define DONT_USE_FAST_MEMCPY | |
1979 | 8 |
9 /* | |
10 * video_out_tdfxfb.c | |
11 * | |
12 * Copyright (C) Zeljko Stevanovic 2001, <zsteva@ptt.yu> | |
13 * | |
14 * Most code rewrited, move from /dev/3dfx to /dev/fb0 (kernel 2.4.?) | |
15 * add support for YUY2 and BGR16 format, remove all X11 DGA code. | |
2350 | 16 * - add support for hardware accelerated OSD (buggy for now). |
17 * work on BGR16 and YUY2 (VO_3DFX_METHOD == 2 only) | |
18 * [oct2001] | |
19 * - added hardware acceleration for OSD (does not look nice, but is faster) | |
20 * (for YV12 don't fork.) | |
21 * - fixed YV12 support for ffdivx, but on my cpu this is sllower of yuv2rgb() | |
22 * try to uncommenting '#define YV12_CONV_METH' | |
23 * - fast_memcpy() is sllower of memcpy() (why, i don't know) | |
24 * | |
1979 | 25 * |
26 * Copyright (C) Colin Cross Apr 2000 | |
27 * | |
28 * This file heavily based off of video_out_mga.c of Aaron Holtzman's | |
29 * mpeg2dec | |
30 * | |
31 * mpeg2dec is free software; you can redistribute it and/or modify | |
32 * it under the terms of the GNU General Public License as published by | |
33 * the Free Software Foundation; either version 2, or (at your option) | |
34 * any later version. | |
35 * | |
36 * mpeg2dec is distributed in the hope that it will be useful, | |
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
39 * GNU General Public License for more details. | |
40 * | |
41 * You should have received a copy of the GNU General Public License | |
42 * along with GNU Make; see the file COPYING. If not, write to | |
43 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
44 * | |
45 */ | |
46 | |
47 #include <stdio.h> | |
48 #include <stdlib.h> | |
49 #include <string.h> | |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
50 #include <errno.h> |
1979 | 51 |
52 #include "config.h" | |
53 #include "video_out.h" | |
54 #include "video_out_internal.h" | |
55 | |
56 LIBVO_EXTERN(tdfxfb) | |
57 | |
58 #include <sys/ioctl.h> | |
59 #include <unistd.h> | |
60 #include <fcntl.h> | |
61 #include <sys/mman.h> | |
62 #include <errno.h> | |
63 #include <wchar.h> | |
64 #include <signal.h> | |
65 | |
66 #include <linux/fb.h> | |
67 | |
68 extern int verbose; | |
69 | |
70 //#define LOG(x) syslog(LOG_USER | LOG_DEBUG,x) | |
71 #define LOG(x) | |
72 | |
73 #include "drivers/3dfx.h" | |
74 | |
2350 | 75 // fast_memcpy() is slower of memcpy(), why? i dont know... |
76 #ifndef DONT_USE_FAST_MEMCPY | |
1979 | 77 #include "fastmemcpy.h" |
2350 | 78 #endif |
79 | |
80 #ifdef YV12_CONV_METH | |
2732 | 81 #include "../postproc/rgb2rgb.h" |
2350 | 82 #endif |
1979 | 83 |
84 static vo_info_t vo_info = | |
85 { | |
86 "tdfxfb (/dev/fb?)", | |
87 "tdfxfb", | |
2350 | 88 "Zeljko Stevanovic <zsteva@ptt.yu>", |
1979 | 89 "" |
90 }; | |
91 | |
92 static char *fb_devname = NULL; | |
93 static int fb_fd = -1; | |
94 static struct fb_fix_screeninfo fb_finfo; | |
95 static struct fb_var_screeninfo fb_vinfo; | |
96 | |
97 static uint32_t in_width; | |
98 static uint32_t in_height; | |
99 static uint32_t in_format; | |
100 static uint32_t in_bytepp; | |
101 | |
102 static uint32_t in_banshee_format, | |
103 in_banshee_size; | |
104 | |
105 static uint32_t screenwidth; | |
106 static uint32_t screenheight; | |
107 static uint32_t screendepth; | |
108 static uint32_t vidwidth, vidheight; // resize on screen to ... for ration expect... | |
109 static uint32_t vidx=0, vidy=0; // for centring on screen. | |
110 | |
111 static uint32_t vid_banshee_xy, | |
112 vid_banshee_format, | |
113 vid_banshee_size; | |
114 | |
115 static void (*draw_alpha_p)(int w, int h, unsigned char *src, | |
116 unsigned char *srca, int stride, unsigned char *dst, | |
117 int dstride); | |
118 | |
119 static uint32_t *vidpage0; | |
120 static uint32_t *vidpage1; | |
121 static uint32_t *in_page0; | |
122 | |
123 static uint32_t vidpage0offset; | |
124 static uint32_t vidpage1offset; | |
125 static uint32_t in_page0_offset; | |
126 | |
127 // Current pointer into framebuffer where display is located | |
128 static uint32_t targetoffset; | |
129 | |
130 static uint32_t page_space; | |
131 | |
132 static uint32_t *tdfx_iobase; | |
133 | |
134 static voodoo_io_reg *reg_IO; | |
135 static voodoo_2d_reg *reg_2d; | |
136 static voodoo_yuv_reg *reg_YUV; | |
137 static voodoo_yuv_fb *fb_YUV; | |
138 | |
139 static uint32_t *memBase0, *memBase1; | |
140 //static uint32_t baseAddr0, baseAddr1; | |
141 | |
142 //#define BANSHEE_SCREEN_MEMORY (8*1024*1024) | |
2350 | 143 static uint32_t tdfx_free_offset = 0; |
1979 | 144 |
145 /*- ----------------------------------------------------------------- -*/ | |
146 | |
147 /* code get from linux kernel tdfxfb.c by Hannu Mallat */ | |
148 | |
149 typedef uint32_t u32; | |
150 | |
151 static inline u32 tdfx_inl(unsigned int reg) { | |
152 return *((volatile uint32_t *)(tdfx_iobase + reg)); | |
153 } | |
154 | |
155 static inline void tdfx_outl(unsigned int reg, u32 val) { | |
156 *((volatile uint32_t *)(tdfx_iobase + reg)) = val; | |
157 } | |
158 | |
159 static inline void banshee_make_room(int size) { | |
160 while((tdfx_inl(STATUS) & 0x1f) < size); | |
161 } | |
162 | |
163 static inline void banshee_wait_idle(void) | |
164 { | |
165 int i = 0; | |
166 | |
167 banshee_make_room(1); | |
168 tdfx_outl(COMMAND_3D, COMMAND_3D_NOP); | |
169 | |
170 while(1) { | |
171 i = (tdfx_inl(STATUS) & STATUS_BUSY) ? 0 : i + 1; | |
172 if(i == 3) break; | |
173 } | |
174 } | |
175 | |
176 | |
177 /*- ----------------------------------------------------------------- -*/ | |
178 | |
179 static void | |
180 restore_regs(voodoo_2d_reg *regs) | |
181 { | |
182 reg_2d->commandExtra = regs->commandExtra; | |
183 reg_2d->clip0Min = regs->clip0Min; | |
184 reg_2d->clip0Max = regs->clip0Max; | |
185 | |
186 reg_2d->srcBaseAddr = regs->srcBaseAddr; | |
187 reg_2d->srcXY = regs->srcXY; | |
188 reg_2d->srcFormat = regs->srcFormat; | |
189 reg_2d->srcSize = regs->srcSize; | |
190 | |
191 reg_2d->dstBaseAddr = regs->dstBaseAddr; | |
192 reg_2d->dstXY = regs->dstXY; | |
193 reg_2d->dstFormat = regs->dstFormat; | |
2350 | 194 reg_2d->dstSize = regs->dstSize; |
1979 | 195 |
196 reg_2d->command = 0; | |
197 } | |
198 | |
199 | |
200 static void | |
201 restore(void) | |
202 { | |
2350 | 203 reg_IO->vidDesktopStartAddr = vidpage0offset; |
1979 | 204 //XF86DGADirectVideo(display,0,0); |
205 } | |
206 | |
207 static void | |
208 sighup(int foo) | |
209 { | |
2350 | 210 reg_IO->vidDesktopStartAddr = vidpage0offset; |
1979 | 211 //XF86DGADirectVideo(display,0,0); |
212 exit(0); | |
213 } | |
214 | |
2350 | 215 #if 0 |
1979 | 216 static void |
217 dump_yuv_planar(void *y, void *u, void *v, | |
218 uint32_t to, uint32_t px, uint32_t py, uint32_t width, uint32_t height) | |
219 { | |
220 uint32_t j; | |
2350 | 221 uint32_t *YUV_U, *YUV_V, *YUV_Y; |
222 uint32_t width2 = width >> 1; | |
223 uint32_t height2 = height >> 1; | |
1979 | 224 |
225 reg_YUV->yuvBaseAddr = to + in_width * 2 * py; | |
2350 | 226 reg_YUV->yuvStride = width << 1; |
1979 | 227 |
2350 | 228 YUV_U = &fb_YUV->U[0]; |
229 YUV_V = &fb_YUV->V[0]; | |
230 YUV_Y = &fb_YUV->Y[0]; | |
231 for (j = 0; j < height2; j++) | |
1979 | 232 { |
2350 | 233 memcpy(YUV_U, u, width2); |
234 memcpy(YUV_V, v, width2); | |
235 memcpy(YUV_Y, y, width); YUV_Y += VOODOO_YUV_STRIDE; y += width; | |
236 memcpy(YUV_Y, y, width); YUV_Y += VOODOO_YUV_STRIDE; y += width; | |
237 YUV_U += VOODOO_YUV_STRIDE; u += width2; | |
238 YUV_V += VOODOO_YUV_STRIDE; v += width2; | |
1979 | 239 } |
240 } | |
241 #endif | |
242 | |
2350 | 243 #define S2S_BLT(cmd, to, dXY, dFmt, dSize, from, sXY, sFmt, sSize, extCmd) \ |
1979 | 244 do { \ |
245 voodoo_2d_reg saved_regs = *reg_2d; \ | |
246 \ | |
2350 | 247 reg_2d->commandExtra = (extCmd); \ |
1979 | 248 reg_2d->clip0Min = 0; \ |
249 reg_2d->clip0Max = 0xffffffff; \ | |
250 \ | |
251 reg_2d->srcBaseAddr = (from); \ | |
252 reg_2d->srcXY = (sXY); \ | |
253 reg_2d->srcFormat = (sFmt); \ | |
254 reg_2d->srcSize = (sSize); \ | |
255 \ | |
256 reg_2d->dstBaseAddr = (to); \ | |
257 reg_2d->dstXY = (dXY); \ | |
258 reg_2d->dstFormat = (dFmt); \ | |
259 reg_2d->dstSize = (dSize); \ | |
260 \ | |
261 reg_2d->command = (cmd); \ | |
262 \ | |
2350 | 263 banshee_wait_idle(); \ |
1979 | 264 restore_regs(&saved_regs); \ |
265 } while (0) | |
266 | |
267 | |
268 /*- ----------------------------------------------------------------- -*/ | |
269 | |
270 static uint32_t draw_slice_YV12(uint8_t *image[], int stride[], int w,int h,int x,int y); | |
271 static uint32_t draw_frame_YV12(uint8_t *src[]); | |
272 static void flip_page_YV12(void); | |
273 static void draw_osd_YV12(void); | |
274 | |
275 static uint32_t draw_slice_YUY2_BGR16(uint8_t *image[], int stride[], int w,int h,int x,int y); | |
276 static uint32_t draw_frame_YUY2_BGR16(uint8_t *src[]); | |
2350 | 277 static void flip_page_vidpage10(void); |
278 static void draw_osd(void); | |
1979 | 279 |
280 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, | |
281 unsigned char *srca, int stride); | |
2350 | 282 #ifdef HWACCEL_OSD_M2 |
283 static void my_draw_alpha_accel(int x0, int y0, int w, int h, unsigned char *src, | |
284 unsigned char *srca, int stride); | |
285 #endif | |
1979 | 286 |
287 static void | |
288 update_target(void) | |
289 { | |
290 } | |
291 | |
2350 | 292 #ifndef VO_TDFXFB_METHOD |
293 #define VO_TDFXFB_METHOD 1 | |
1979 | 294 #endif |
295 | |
296 | |
2350 | 297 #if VO_TDFXFB_METHOD == 2 |
1979 | 298 extern void **our_out_buffer; |
299 #endif | |
300 | |
301 static uint32_t | |
4433 | 302 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, |
303 uint32_t fullscreen, char *title, uint32_t format,const vo_tune_info_t *info) | |
1979 | 304 { |
305 | |
2350 | 306 if (verbose) { |
1979 | 307 printf("vo_3dfx->init( width = %d, height = %d, " |
308 "d_width = %d, d_height = %d, format = %d)\n", | |
309 width, height, d_width, d_height, format); | |
310 printf("vo_3dfx->init( format => %s )\n", vo_format_name(format)); | |
311 printf("vo_3dfx: vo_depthonscreen => %d, vo_screenwidth => %d, " | |
312 "vo_screenhight => %d\n", vo_depthonscreen, vo_screenwidth, vo_screenheight); | |
313 printf("vo_3dfx->init() vo_dwidth => %d, vo_dheight => %d, vo_dbpp => %d\n", | |
314 vo_dwidth, vo_dheight, vo_dbpp); | |
315 } | |
316 | |
317 if (!fb_devname && !(fb_devname = getenv("FRAMEBUFFER"))) | |
318 fb_devname = "/dev/fb0"; | |
319 | |
2350 | 320 if (verbose) |
1979 | 321 printf("vo_3dfx->init(): fbdev ==> %s\n", fb_devname); |
322 | |
323 if ((fb_fd = open(fb_devname, O_RDWR)) == -1) { | |
324 printf("vo_3dfx->init(): can't open %s, %s\n", fb_devname, strerror(errno)); | |
325 return -1; | |
326 } | |
327 | |
328 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fb_finfo)) { | |
329 printf("vo_3dfx->init(): problem with ioctl(fb_fd, FBITGET_FSCREENINFO.., %s\n", | |
330 strerror(errno)); | |
331 return -1; | |
332 } | |
333 | |
334 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &fb_vinfo)) { | |
335 printf("vo_3dfx->init(): problem with ioctl(fb_fd, FBITGET_VSCREENINFO.., %s\n", | |
336 strerror(errno)); | |
337 return -1; | |
338 } | |
339 | |
340 if (verbose) { | |
341 printf("fb_finfo:\n"); | |
342 printf(" id: %s\n", fb_finfo.id); | |
343 printf(" frame bufer at %x len %x (%d)\n", fb_finfo.smem_start, fb_finfo.smem_len, | |
344 fb_finfo.smem_len); | |
345 printf(" mem io at %x len %x\n", fb_finfo.mmio_start, fb_finfo.mmio_len); | |
346 | |
347 printf("fb_vinfo:\n"); | |
348 printf(" resolution: %dx%d\n", fb_vinfo.xres, fb_vinfo.yres); | |
349 printf(" virtual res: %dx%d\n", fb_vinfo.xres_virtual, fb_vinfo.yres_virtual); | |
350 printf(" virt offset: %dx%d\n", fb_vinfo.xoffset, fb_vinfo.yoffset); | |
351 } | |
352 | |
353 if (fb_finfo.accel != FB_ACCEL_3DFX_BANSHEE) { | |
354 printf("vo_3dfx->init(): this driver made only for 3dfx banshee... sorry...\n"); | |
355 return -1; | |
356 } | |
357 if (fb_vinfo.bits_per_pixel != 16) { | |
358 printf("vo_3dfx->init(): for now fork only in 16 bits mode. use fbset -depth 16 <mode>\n"); | |
359 return -1; | |
360 } | |
361 //return -1; | |
362 | |
363 | |
364 screenwidth = fb_vinfo.xres; | |
365 screenheight = fb_vinfo.yres; | |
366 screendepth = 2; | |
367 // Store sizes for later | |
368 in_width = width; | |
369 in_height = height; | |
370 in_format = format; | |
371 | |
2350 | 372 if (fullscreen) { |
1979 | 373 double exrat; |
2350 | 374 |
375 if (verbose) | |
376 printf("vo_tdfxfb->init(): fullscreen mode...\n"); | |
377 | |
378 vidwidth = screenwidth; | |
379 vidheight = screenheight; | |
1979 | 380 |
381 exrat = (double)in_width / in_height; | |
382 if (verbose) | |
383 printf("vo_3dfx->init(): in_width / in_height => %f\n", exrat); | |
384 if (screenwidth / exrat <= screenheight) | |
385 vidheight = (double)screenwidth / exrat; | |
386 else | |
387 vidwidth = (double)screenheight * exrat; | |
388 | |
389 vidx = (screenwidth - vidwidth) / 2; | |
390 vidy = (screenheight - vidheight) / 2; | |
391 | |
392 if (verbose) { | |
393 printf("vo_3dfx->init(): vidwidth => %d\n", vidwidth); | |
394 printf("vo_3dfx->init(): vidheight => %d\n", vidheight); | |
395 printf("vo_3dfx->init(): vidx => %d\n", vidx); | |
396 printf("vo_3dfx->init(): vidy => %d\n", vidy); | |
397 } | |
2350 | 398 } else { |
399 if (in_width > screenwidth || in_height > screenheight) { | |
400 printf("vo_tdfxfb->init(): your resolution is small for play move...\n"); | |
401 return -1; | |
402 } else { | |
403 vidwidth = in_width; | |
404 vidheight = in_height; | |
405 vidx = (screenwidth - in_width) / 2; | |
406 vidy = (screenheight - in_height) / 2; | |
407 } | |
1979 | 408 } |
409 | |
410 signal(SIGALRM,sighup); | |
411 //alarm(120); | |
412 | |
413 | |
414 // access to 3dfx hardware.... | |
415 memBase1 = mmap(0, fb_finfo.smem_len, PROT_READ | PROT_WRITE, | |
416 MAP_SHARED, fb_fd, 0); | |
417 memBase0 = mmap(0, fb_finfo.mmio_len, PROT_READ | PROT_WRITE, | |
418 MAP_SHARED, fb_fd, fb_finfo.smem_len); | |
419 | |
420 if (memBase0 == (uint32_t *)0xFFFFFFFF || | |
421 memBase1 == (uint32_t *)0xFFFFFFFF) | |
422 { | |
423 printf("Couldn't map 3dfx memory areas: %p, %p, %d\n", | |
424 memBase0, memBase1, errno); | |
425 } | |
426 | |
427 | |
428 tdfx_iobase = (void *)memBase0 + VOODOO_IO_REG_OFFSET; | |
429 | |
430 // Set up global pointers | |
431 reg_IO = (void *)memBase0 + VOODOO_IO_REG_OFFSET; | |
432 reg_2d = (void *)memBase0 + VOODOO_2D_REG_OFFSET; | |
433 reg_YUV = (void *)memBase0 + VOODOO_YUV_REG_OFFSET; | |
434 fb_YUV = (void *)memBase0 + VOODOO_YUV_PLANE_OFFSET; | |
435 | |
436 vidpage0offset = 0; | |
437 vidpage1offset = screenwidth * screenheight * screendepth; | |
438 in_page0_offset = vidpage1offset + screenwidth * screenheight * screendepth; | |
439 | |
440 vidpage0 = (void *)memBase1 + (unsigned long int)vidpage0offset; | |
441 vidpage1 = (void *)memBase1 + (unsigned long int)vidpage1offset; | |
442 in_page0 = (void *)memBase1 + (unsigned long int)in_page0_offset; | |
443 | |
444 vid_banshee_xy = XYREG(vidx, vidy); | |
445 vid_banshee_format = screenwidth*2 | VOODOO_BLT_FORMAT_16; | |
446 vid_banshee_size = XYREG(vidwidth, vidheight); | |
447 | |
448 in_banshee_size = XYREG(in_width, in_height); | |
449 | |
2350 | 450 //video_out_3dfx.flip_page = flip_page_all; |
451 draw_alpha_p = vo_draw_alpha_rgb16; | |
1979 | 452 |
453 switch (in_format) { | |
454 case IMGFMT_YV12: | |
455 video_out_tdfxfb.draw_slice = draw_slice_YV12; | |
456 video_out_tdfxfb.draw_frame = draw_frame_YV12; | |
457 video_out_tdfxfb.flip_page = flip_page_YV12; | |
458 video_out_tdfxfb.draw_osd = draw_osd_YV12; | |
2350 | 459 draw_alpha_p = vo_draw_alpha_yuy2; |
1979 | 460 in_banshee_format = in_width * 2 | VOODOO_BLT_FORMAT_YUYV; |
2350 | 461 #ifdef YV12_CONV_METH |
462 yuv2rgb_init(16, MODE_RGB); | |
463 in_banshee_format = in_width * 2 | VOODOO_BLT_FORMAT_16; | |
464 draw_alpha_p = vo_draw_alpha_rgb16; | |
465 #endif | |
1979 | 466 break; |
467 case IMGFMT_YUY2: | |
468 video_out_tdfxfb.draw_slice = draw_slice_YUY2_BGR16; | |
469 video_out_tdfxfb.draw_frame = draw_frame_YUY2_BGR16; | |
2350 | 470 video_out_tdfxfb.flip_page = flip_page_vidpage10; |
1979 | 471 |
472 in_banshee_format = in_width * 2 | VOODOO_BLT_FORMAT_YUYV; | |
473 in_bytepp = 2; | |
2350 | 474 #if VO_TDFXFB_METHOD == 2 |
475 *our_out_buffer = in_page0; | |
476 #endif | |
477 | |
1979 | 478 break; |
479 case IMGFMT_BGR|16: | |
480 video_out_tdfxfb.draw_slice = draw_slice_YUY2_BGR16; | |
481 video_out_tdfxfb.draw_frame = draw_frame_YUY2_BGR16; | |
2350 | 482 video_out_tdfxfb.flip_page = flip_page_vidpage10; |
483 | |
1979 | 484 in_banshee_format = in_width * 2 | VOODOO_BLT_FORMAT_16; |
485 in_bytepp = 2; | |
2350 | 486 #if VO_TDFXFB_METHOD == 2 |
487 *our_out_buffer = in_page0; | |
488 #endif | |
1979 | 489 break; |
490 } | |
491 | |
492 | |
493 // Clear pages 1,2,3 | |
494 // leave page 0, that belongs to X. | |
495 // So does part of 1. Oops. | |
496 memset(vidpage0, 0x00, screenwidth * screenheight * screendepth); | |
497 memset(vidpage1, 0x00, screenwidth * screenheight * screendepth); | |
498 memset(in_page0, 0x00, in_width * in_height * in_bytepp); | |
499 | |
500 // Show page 0 (unblanked) | |
501 reg_IO->vidDesktopStartAddr = vidpage0offset; | |
502 //banshee_make_room(1); | |
503 //tdfx_outl(VIDDESKSTART, vidpage1offset); | |
504 | |
505 /* fd is deliberately not closed - if it were, mmaps might be released??? */ | |
506 | |
507 atexit(restore); | |
508 | |
2350 | 509 printf("(display) tdfxfb initialized %p/%p\n",memBase0,memBase1); |
1979 | 510 return 0; |
511 } | |
512 | |
513 static const vo_info_t* | |
514 get_info(void) | |
515 { | |
516 return &vo_info; | |
517 } | |
518 | |
519 // ------------------------------------------------------------------- | |
520 // YV12 fork fine. but only on vcd, with ffmpeg codec for DivX don't given corect picture. | |
521 | |
522 static uint32_t | |
523 draw_frame_YV12(uint8_t *src[]) | |
524 { | |
525 return 0; | |
526 } | |
527 | |
2350 | 528 #ifndef YV12_CONV_METH |
529 | |
1979 | 530 static uint32_t |
531 draw_slice_YV12(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
532 { | |
2350 | 533 void *img_y = image[0]; |
534 void *img_u = image[1]; | |
535 void *img_v = image[2]; | |
536 uint32_t j; | |
537 uint32_t *YUV_U = &fb_YUV->U[0], | |
538 *YUV_V = &fb_YUV->V[0], | |
539 *YUV_Y = &fb_YUV->Y[0]; | |
540 uint32_t height2 = h >> 1; | |
541 | |
542 #if 0 | |
543 printf("stride[0] => %d\n", stride[0]); | |
544 printf("stride[1] => %d\n", stride[1]); | |
545 printf("stride[2] => %d\n", stride[2]); | |
546 printf("w => %d, h => %d, x => %d, y => %d\n", w, h, x, y); | |
547 #endif | |
548 #if 0 | |
1979 | 549 dump_yuv_planar((uint32_t *)image[0], (uint32_t *)image[1], |
550 (uint32_t *)image[2], in_page0_offset, x, y, w, h); | |
2350 | 551 #endif |
552 | |
553 //reg_YUV->yuvBaseAddr = to + mystride * 2 * py; | |
554 reg_YUV->yuvBaseAddr = in_page0_offset + w * 2 * y; | |
555 reg_YUV->yuvStride = w << 1; | |
556 | |
557 for (j = 0; j < height2; j++) | |
558 { | |
559 memcpy(YUV_U, img_u, stride[1]); | |
560 memcpy(YUV_V, img_v, stride[2]); | |
561 memcpy(YUV_Y, img_y, stride[0]); YUV_Y += VOODOO_YUV_STRIDE; img_y += stride[0]; | |
562 memcpy(YUV_Y, img_y, stride[0]); YUV_Y += VOODOO_YUV_STRIDE; img_y += stride[0]; | |
563 YUV_U += VOODOO_YUV_STRIDE; img_u += stride[1]; | |
564 YUV_V += VOODOO_YUV_STRIDE; img_v += stride[2]; | |
565 } | |
566 | |
1979 | 567 return 0; |
568 } | |
569 | |
2350 | 570 #else /* !YV12_CONV_METH */ |
571 // ------------------------------------------------------------------- | |
572 // YV12 with converting support | |
573 | |
574 static uint32_t | |
575 draw_slice_YV12(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
576 { | |
577 uint8_t *dest = (uint8_t *)(in_page0) + (in_width * y + x) * 2; | |
578 //dump_yuv_planar((uint32_t *)image[0], (uint32_t *)image[1], | |
579 // (uint32_t *)image[2], in_page0_offset, x, y, w, h); | |
580 yuv2rgb(dest, image[0], image[1], image[2], w, h, in_width * 2, | |
581 stride[0], stride[1]); | |
582 return 0; | |
583 } | |
584 | |
585 #endif /* else ! YV12_CONV_METH */ | |
586 | |
1979 | 587 static void |
588 flip_page_YV12(void) | |
589 { | |
590 S2S_BLT(2 | 1 << 8 | 0xcc << 24, // 2 | 1<<8 | 0xcc<<24, | |
591 vidpage0offset, vid_banshee_xy, | |
592 vid_banshee_format, vid_banshee_size, | |
593 in_page0_offset, 0, | |
2350 | 594 in_banshee_format, in_banshee_size, 0); |
595 | |
1979 | 596 } |
597 | |
598 static void draw_alpha_YV12(int x0, int y0, int w, int h, unsigned char *src, | |
599 unsigned char *srca, int stride) | |
600 { | |
2350 | 601 unsigned char *dst = (void *)in_page0 + (in_width * (0+y0) + 0+x0) * 2; // 2 <= bpp |
1979 | 602 uint32_t dstride = in_width * 2; // 2 <= bpp |
2350 | 603 //printf("draw_alpha: x0,y0 = %d,%d; w,h = %d,%d; stride=%d;\n", x0, y0, w, h, stride); |
604 (*draw_alpha_p)(w, h, src, srca, stride, dst, dstride); | |
1979 | 605 } |
606 | |
607 | |
608 static void draw_osd_YV12(void) | |
609 { | |
2350 | 610 #ifndef HWACCEL_OSD_M2 |
611 //vo_draw_text(vidwidth, vidheight, draw_alpha); | |
612 #else | |
613 //vo_draw_text(vidwidth, vidheight, my_draw_alpha_accel); | |
614 #endif /* else ! HWACCEL_OSD_M2 */ | |
1979 | 615 vo_draw_text(in_width, in_height, draw_alpha_YV12); |
616 } | |
617 | |
618 | |
2350 | 619 |
1979 | 620 // ------------------------------------------------------------------- |
621 // YUYV & BGR16 support | |
622 | |
623 static uint32_t | |
624 draw_frame_YUY2_BGR16(uint8_t *src[]) | |
625 { | |
2350 | 626 #if VO_TDFXFB_METHOD == 1 |
1979 | 627 memcpy(in_page0, src[0], in_width * in_height * in_bytepp); |
628 #endif | |
629 // blt to offscreen page. | |
630 S2S_BLT(2 | 1 << 8 | 0xcc << 24, // 2 | 1<<8 | 0xcc<<24, | |
631 vidpage1offset, vid_banshee_xy, | |
632 vid_banshee_format, vid_banshee_size, | |
633 in_page0_offset, 0, | |
2350 | 634 in_banshee_format, in_banshee_size, 0); |
1979 | 635 banshee_wait_idle(); |
636 return 0; | |
637 } | |
638 | |
639 static uint32_t | |
2350 | 640 draw_frame_YUY2_BGR16_h2s_bitblt(uint8_t *src[]) |
641 { | |
642 uint32_t i, len; | |
643 uint32_t *launch = (uint32_t *)®_2d->launchArea[0]; | |
644 uint32_t *src32 = (uint32_t *)src[0]; | |
645 voodoo_2d_reg saved_regs = *reg_2d; | |
646 | |
647 reg_2d->commandExtra = 0; | |
648 reg_2d->clip0Min = 0; | |
649 reg_2d->clip0Max = 0xffffffff; | |
650 | |
651 reg_2d->colorFore = 0; | |
652 reg_2d->colorBack = 0; | |
653 | |
654 reg_2d->srcXY = 0; | |
655 //reg_2d->srcBaseAddr = (from); | |
656 | |
657 // reg_2d->srcFormat = 0x00400000 | BIT(20); // byte allignment + byte swizzle... | |
658 // YUYV + dword packet | |
659 reg_2d->srcFormat = in_width*2 | VOODOO_BLT_FORMAT_YUYV; // | (2 << 22); | |
660 reg_2d->dstXY = vid_banshee_xy; | |
661 reg_2d->dstSize = vid_banshee_size; | |
662 reg_2d->dstBaseAddr = vidpage1offset; | |
663 reg_2d->dstFormat = vid_banshee_format; | |
664 | |
665 // host-to-screen blting + tranpasparent | |
666 //reg_2d->command = 3 | (1 << 16)| (ROP_COPY << 24); | |
667 reg_2d->command = 3 | (ROP_COPY << 24); | |
668 | |
669 i = 0; | |
670 len = in_width * in_height * 2; /* 2 => 16 bit */ | |
671 len >>= 2; /* / 4 */ | |
672 for (;;) { | |
673 if (i == len) break; launch[0] = src32[i]; i++; | |
674 if (i == len) break; launch[1] = src32[i]; i++; | |
675 if (i == len) break; launch[2] = src32[i]; i++; | |
676 if (i == len) break; launch[3] = src32[i]; i++; | |
677 } | |
678 banshee_wait_idle(); | |
679 restore_regs(&saved_regs); | |
680 return; | |
681 } | |
682 | |
683 static uint32_t | |
1979 | 684 draw_slice_YUY2_BGR16(uint8_t *image[], int stride[], int w,int h,int x,int y) |
685 { | |
686 return 0; | |
687 } | |
688 | |
689 static void | |
2350 | 690 flip_page_vidpage10(void) |
1979 | 691 { |
692 uint32_t o; | |
693 void *p; | |
694 | |
695 // flip screen pages. | |
696 o = vidpage0offset; vidpage0offset = vidpage1offset; vidpage1offset = o; | |
697 p = vidpage0; vidpage0 = vidpage1; vidpage1 = p; | |
698 | |
699 reg_IO->vidDesktopStartAddr = vidpage0offset; | |
700 } | |
701 | |
2350 | 702 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, |
1979 | 703 unsigned char *srca, int stride) |
704 { | |
705 unsigned char *dst = (void *)vidpage1 + (screenwidth * (vidy+y0) + vidx+x0) * 2; // 2 <= bpp | |
706 uint32_t dstride = screenwidth * 2; // 2 <= bpp | |
2350 | 707 //printf("draw_alpha: x0,y0 = %d,%d; w,h = %d,%d; stride=%d;\n", x0, y0, w, h, stride); |
1979 | 708 (*draw_alpha_p)(w, h, src, srca, stride, dst, dstride); |
709 } | |
710 | |
2350 | 711 static void draw_osd(void) |
1979 | 712 { |
2350 | 713 #ifndef HWACCEL_OSD_M2 |
714 vo_draw_text(vidwidth, vidheight, draw_alpha); | |
715 #else | |
716 vo_draw_text(vidwidth, vidheight, my_draw_alpha_accel); | |
717 #endif /* else ! HWACCEL_OSD_M2 */ | |
1979 | 718 } |
719 | |
720 // ------------------------------------------------------------------- | |
721 | |
722 static uint32_t | |
723 draw_frame(uint8_t *src[]) | |
724 { | |
725 /* dummy */ | |
726 return 0; | |
727 } | |
728 | |
729 static uint32_t | |
730 draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
731 { | |
732 /* dummy */ | |
733 return 0; | |
734 } | |
735 | |
736 static void | |
737 flip_page(void) | |
738 { | |
739 /* dummy */ | |
740 } | |
741 | |
2350 | 742 /*- ----------------------------------------------------------------- -*/ |
1979 | 743 |
744 static uint32_t | |
745 query_format(uint32_t format) | |
746 { | |
747 switch(format){ | |
748 case IMGFMT_YV12: | |
749 return 4|2; // 4|2; | |
750 case IMGFMT_YUY2: | |
751 if (verbose) printf("query_format: IMGFMT_YUY2\n"); | |
2350 | 752 return 4|2; //4|2; |
1979 | 753 case IMGFMT_BGR|16: |
2350 | 754 if (verbose) printf("query_format: IMGFMT_BGR|16\n"); |
755 return 4|2; // 4|2; /* osd + ????? */ | |
1979 | 756 } |
757 return 0; | |
758 } | |
759 | |
760 static void | |
761 uninit(void) | |
762 { | |
2350 | 763 reg_IO->vidDesktopStartAddr = vidpage0offset; |
1979 | 764 } |
765 | |
766 | |
767 static void check_events(void) | |
768 { | |
769 } | |
770 | |
2350 | 771 #ifdef HWACCEL_OSD_M2 |
772 | |
773 static void my_draw_alpha_accel(int x0, int y0, int w, int h, unsigned char *src, | |
1979 | 774 unsigned char *srca, int stride) |
775 { | |
2350 | 776 int y, x; |
777 uint32_t pbuf, pcnt; | |
778 uint32_t *launch = (uint32_t *)®_2d->launchArea[0]; | |
779 voodoo_2d_reg saved_regs = *reg_2d; | |
780 | |
781 reg_2d->commandExtra = 0; | |
782 reg_2d->clip0Min = 0; | |
783 reg_2d->clip0Max = 0xffffffff; | |
1979 | 784 |
2350 | 785 reg_2d->colorFore = 0xffff; |
786 reg_2d->colorBack = 0; | |
787 | |
788 reg_2d->srcXY = 0; | |
789 //reg_2d->srcBaseAddr = (from); | |
790 | |
791 reg_2d->srcFormat = 0x00400000 | BIT(20); // byte allignment + byte swizzle... | |
792 //reg_2d->srcSize = XYREG(w, h); | |
793 reg_2d->dstSize = XYREG(w, h); | |
794 | |
795 reg_2d->dstBaseAddr = vidpage1offset; | |
796 reg_2d->dstXY = XYREG(vidx+x0, vidy+y0); | |
797 reg_2d->dstFormat = vid_banshee_format; | |
1979 | 798 |
2350 | 799 // host-to-screen blting + tranpasparent |
800 reg_2d->command = 3 | (1 << 16)| (ROP_COPY << 24); | |
801 | |
802 pcnt = 0; | |
803 pbuf = 0; | |
804 for (y = 0; y < h; y++) { | |
805 for (x = 0; x < w; x++) { | |
806 pbuf = (pbuf << 1) | (((src[x] > 150) ? 1 : 0)); | |
807 if (++pcnt == 32) { launch[0] = pbuf; pcnt = 0; pbuf = 0; } | |
808 } | |
809 | |
810 if ((pcnt % 8) != 0) { | |
811 pbuf <<= 8 - (pcnt % 8); | |
812 pcnt += 8 - (pcnt % 8); | |
813 if (pcnt == 32) { launch[0] = pbuf; pcnt = 0; pbuf = 0; } | |
814 } | |
815 | |
816 src += stride; | |
817 srca += stride; | |
818 } | |
819 if (pcnt != 0) launch[0] = pbuf; | |
820 | |
1979 | 821 banshee_wait_idle(); |
2350 | 822 restore_regs(&saved_regs); |
823 return; | |
1979 | 824 } |
2350 | 825 #endif /* ! HWACCEL_OSD_M2 */ |
1979 | 826 |
4352 | 827 static uint32_t preinit(const char *arg) |
828 { | |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
829 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
|
830 { |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
831 printf("vo_tdfxfb: 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
|
832 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
|
833 } |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
834 return 0; |
4352 | 835 } |
1979 | 836 |
4596 | 837 static uint32_t control(uint32_t request, void *data, ...) |
4352 | 838 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
839 switch (request) { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
840 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
841 return query_format(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
842 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
843 return VO_NOTIMPL; |
4352 | 844 } |