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