comparison libvo/vo_tdfxfb.c @ 1979:6278f566cd91

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