2 * Video driver for Framebuffer device
3 * by Szabolcs Berecz <szabi@inf.elte.hu>
6 * Some idea and code borrowed from Chris Lawrence's ppmtofb-0.27
7 * Some fixes and small improvements by Joey Parrish <joey@nicewarrior.org>
19 #include <sys/ioctl.h>
24 #include "video_out.h"
25 #include "video_out_internal.h"
26 #include "fastmemcpy.h"
30 #include "vosub_vidix.h"
35 static const vo_info_t info
= {
38 "Szabolcs Berecz <szabi@inf.elte.hu>",
45 /* Name of VIDIX driver */
46 static const char *vidix_name
= NULL
;
47 static vidix_grkey_t gr_key
;
49 static signed int pre_init_err
= -2;
50 /******************************
52 ******************************/
54 static range_t
*monitor_hfreq
= NULL
;
55 static range_t
*monitor_vfreq
= NULL
;
56 static range_t
*monitor_dotclock
= NULL
;
60 uint32_t xres
, yres
, vxres
, vyres
, depth
;
61 uint32_t pixclock
, left
, right
, upper
, lower
, hslen
, vslen
;
66 #define MAX_NR_TOKEN 16
68 #define MAX_LINE_LEN 1000
73 static int validate_mode(fb_mode_t
*m
)
76 mp_msg(MSGT_VO
, MSGL_V
, "needs geometry ");
80 mp_msg(MSGT_VO
, MSGL_V
, "needs timings ");
87 static int line_num
= 0;
89 static char *token
[MAX_NR_TOKEN
];
91 static int get_token(int num
)
93 static int read_nextline
= 1;
98 if (num
>= MAX_NR_TOKEN
) {
99 mp_msg(MSGT_VO
, MSGL_V
, "get_token(): max >= MAX_NR_TOKEN!\n");
104 if (!fgets(line
, MAX_LINE_LEN
, fp
))
110 for (i
= 0; i
< num
; i
++) {
111 while (isspace(line
[line_pos
]))
113 if (line
[line_pos
] == '\0' || line
[line_pos
] == '#') {
117 token
[i
] = line
+ line_pos
;
119 if (c
== '"' || c
== '\'') {
121 while (line
[++line_pos
] != c
&& line
[line_pos
])
125 line
[line_pos
] = ' ';
127 for (/* NOTHING */; !isspace(line
[line_pos
]) &&
128 line
[line_pos
]; line_pos
++)
131 if (!line
[line_pos
]) {
137 line
[line_pos
++] = '\0';
147 static fb_mode_t
*fb_modes
= NULL
;
148 static int nr_modes
= 0;
150 static int parse_fbmode_cfg(char *cfgfile
)
152 #define CHECK_IN_MODE_DEF\
154 mp_msg(MSGT_VO, MSGL_V, "'needs 'mode' first");\
155 goto err_out_print_linenum;\
157 fb_mode_t
*mode
= NULL
;
158 char *endptr
; // strtoul()...
162 /* If called more than once, reuse parsed data */
166 mp_msg(MSGT_VO
, MSGL_V
, "Reading %s: ", cfgfile
);
168 if ((fp
= fopen(cfgfile
, "r")) == NULL
) {
169 mp_msg(MSGT_VO
, MSGL_V
, "can't open '%s': %s\n", cfgfile
, strerror(errno
));
173 if ((line
= (char *) malloc(MAX_LINE_LEN
+ 1)) == NULL
) {
174 mp_msg(MSGT_VO
, MSGL_V
, "can't get memory for 'line': %s\n", strerror(errno
));
179 * check if the cfgfile starts with 'mode'
181 while ((tmp
= get_token(1)) == RET_EOL
)
185 if (!strcmp(token
[0], "mode"))
187 goto err_out_parse_error
;
189 while ((tmp
= get_token(1)) != RET_EOF
) {
192 if (!strcmp(token
[0], "mode")) {
194 mp_msg(MSGT_VO
, MSGL_V
, "'endmode' required");
195 goto err_out_print_linenum
;
197 if (!validate_mode(mode
))
198 goto err_out_not_valid
;
200 if (!(fb_modes
= (fb_mode_t
*)
201 realloc(fb_modes
, sizeof(fb_mode_t
) * (nr_modes
+ 1)))) {
202 mp_msg(MSGT_VO
, MSGL_V
, "can't realloc 'fb_modes' (nr_modes = %d):"
203 " %s\n", nr_modes
, strerror(errno
));
206 mode
= fb_modes
+ nr_modes
;
208 memset(mode
, 0, sizeof(fb_mode_t
));
210 if (get_token(1) < 0)
211 goto err_out_parse_error
;
212 for (i
= 0; i
< nr_modes
- 1; i
++) {
213 if (!strcmp(token
[0], fb_modes
[i
].name
)) {
214 mp_msg(MSGT_VO
, MSGL_V
, "mode name '%s' isn't unique", token
[0]);
215 goto err_out_print_linenum
;
218 if (!(mode
->name
= strdup(token
[0]))) {
219 mp_msg(MSGT_VO
, MSGL_V
, "can't strdup -> 'name': %s\n", strerror(errno
));
223 } else if (!strcmp(token
[0], "geometry")) {
225 if (get_token(5) < 0)
226 goto err_out_parse_error
;
227 mode
->xres
= strtoul(token
[0], &endptr
, 0);
229 goto err_out_parse_error
;
230 mode
->yres
= strtoul(token
[1], &endptr
, 0);
232 goto err_out_parse_error
;
233 mode
->vxres
= strtoul(token
[2], &endptr
, 0);
235 goto err_out_parse_error
;
236 mode
->vyres
= strtoul(token
[3], &endptr
, 0);
238 goto err_out_parse_error
;
239 mode
->depth
= strtoul(token
[4], &endptr
, 0);
241 goto err_out_parse_error
;
242 } else if (!strcmp(token
[0], "timings")) {
244 if (get_token(7) < 0)
245 goto err_out_parse_error
;
246 mode
->pixclock
= strtoul(token
[0], &endptr
, 0);
248 goto err_out_parse_error
;
249 mode
->left
= strtoul(token
[1], &endptr
, 0);
251 goto err_out_parse_error
;
252 mode
->right
= strtoul(token
[2], &endptr
, 0);
254 goto err_out_parse_error
;
255 mode
->upper
= strtoul(token
[3], &endptr
, 0);
257 goto err_out_parse_error
;
258 mode
->lower
= strtoul(token
[4], &endptr
, 0);
260 goto err_out_parse_error
;
261 mode
->hslen
= strtoul(token
[5], &endptr
, 0);
263 goto err_out_parse_error
;
264 mode
->vslen
= strtoul(token
[6], &endptr
, 0);
266 goto err_out_parse_error
;
267 } else if (!strcmp(token
[0], "endmode")) {
270 } else if (!strcmp(token
[0], "accel")) {
272 if (get_token(1) < 0)
273 goto err_out_parse_error
;
275 * it's only used for text acceleration
276 * so we just ignore it.
278 } else if (!strcmp(token
[0], "hsync")) {
280 if (get_token(1) < 0)
281 goto err_out_parse_error
;
282 if (!strcmp(token
[0], "low"))
283 mode
->sync
&= ~FB_SYNC_HOR_HIGH_ACT
;
284 else if (!strcmp(token
[0], "high"))
285 mode
->sync
|= FB_SYNC_HOR_HIGH_ACT
;
287 goto err_out_parse_error
;
288 } else if (!strcmp(token
[0], "vsync")) {
290 if (get_token(1) < 0)
291 goto err_out_parse_error
;
292 if (!strcmp(token
[0], "low"))
293 mode
->sync
&= ~FB_SYNC_VERT_HIGH_ACT
;
294 else if (!strcmp(token
[0], "high"))
295 mode
->sync
|= FB_SYNC_VERT_HIGH_ACT
;
297 goto err_out_parse_error
;
298 } else if (!strcmp(token
[0], "csync")) {
300 if (get_token(1) < 0)
301 goto err_out_parse_error
;
302 if (!strcmp(token
[0], "low"))
303 mode
->sync
&= ~FB_SYNC_COMP_HIGH_ACT
;
304 else if (!strcmp(token
[0], "high"))
305 mode
->sync
|= FB_SYNC_COMP_HIGH_ACT
;
307 goto err_out_parse_error
;
308 } else if (!strcmp(token
[0], "extsync")) {
310 if (get_token(1) < 0)
311 goto err_out_parse_error
;
312 if (!strcmp(token
[0], "false"))
313 mode
->sync
&= ~FB_SYNC_EXT
;
314 else if (!strcmp(token
[0], "true"))
315 mode
->sync
|= FB_SYNC_EXT
;
317 goto err_out_parse_error
;
318 } else if (!strcmp(token
[0], "laced")) {
320 if (get_token(1) < 0)
321 goto err_out_parse_error
;
322 if (!strcmp(token
[0], "false"))
323 mode
->vmode
= FB_VMODE_NONINTERLACED
;
324 else if (!strcmp(token
[0], "true"))
325 mode
->vmode
= FB_VMODE_INTERLACED
;
327 goto err_out_parse_error
;
328 } else if (!strcmp(token
[0], "double")) {
330 if (get_token(1) < 0)
331 goto err_out_parse_error
;
332 if (!strcmp(token
[0], "false"))
334 else if (!strcmp(token
[0], "true"))
335 mode
->vmode
= FB_VMODE_DOUBLE
;
337 goto err_out_parse_error
;
339 goto err_out_parse_error
;
341 if (!validate_mode(mode
))
342 goto err_out_not_valid
;
344 mp_msg(MSGT_VO
, MSGL_V
, "%d modes\n", nr_modes
);
349 mp_msg(MSGT_VO
, MSGL_V
, "parse error");
350 err_out_print_linenum
:
351 mp_msg(MSGT_VO
, MSGL_V
, " at line %d\n", line_num
);
362 mp_msg(MSGT_VO
, MSGL_V
, "previous mode is not correct");
363 goto err_out_print_linenum
;
366 static fb_mode_t
*find_mode_by_name(char *name
)
370 for (i
= 0; i
< nr_modes
; i
++)
371 if (!strcmp(name
, fb_modes
[i
].name
))
376 static float dcf(fb_mode_t
*m
) //driving clock frequency
378 return 1e12f
/ m
->pixclock
;
381 static float hsf(fb_mode_t
*m
) //horizontal scan frequency
383 int htotal
= m
->left
+ m
->xres
+ m
->right
+ m
->hslen
;
384 return dcf(m
) / htotal
;
387 static float vsf(fb_mode_t
*m
) //vertical scan frequency
389 int vtotal
= m
->upper
+ m
->yres
+ m
->lower
+ m
->vslen
;
390 return hsf(m
) / vtotal
;
394 static int mode_works(fb_mode_t
*m
, range_t
*hfreq
, range_t
*vfreq
,
402 mp_msg(MSGT_VO
, MSGL_DBG2
, "mode %dx%d:", m
->xres
, m
->yres
);
403 if (!in_range(hfreq
, h
)) {
405 mp_msg(MSGT_VO
, MSGL_DBG2
, " hsync out of range.");
407 if (!in_range(vfreq
, v
)) {
409 mp_msg(MSGT_VO
, MSGL_DBG2
, " vsync out of range.");
411 if (!in_range(dotclock
, d
)) {
413 mp_msg(MSGT_VO
, MSGL_DBG2
, " dotclock out of range.");
416 mp_msg(MSGT_VO
, MSGL_DBG2
, " hsync, vsync, dotclock ok.\n");
418 mp_msg(MSGT_VO
, MSGL_DBG2
, "\n");
423 static fb_mode_t
*find_best_mode(int xres
, int yres
, range_t
*hfreq
,
424 range_t
*vfreq
, range_t
*dotclock
)
427 fb_mode_t
*best
= fb_modes
;
430 mp_msg(MSGT_VO
, MSGL_DBG2
, "Searching for first working mode\n");
432 for (i
= 0; i
< nr_modes
; i
++, best
++)
433 if (mode_works(best
, hfreq
, vfreq
, dotclock
))
438 if (i
== nr_modes
- 1)
441 mp_msg(MSGT_VO
, MSGL_DBG2
, "First working mode: %dx%d\n", best
->xres
, best
->yres
);
442 mp_msg(MSGT_VO
, MSGL_DBG2
, "Searching for better modes\n");
444 for (curr
= best
+ 1; i
< nr_modes
- 1; i
++, curr
++) {
445 if (!mode_works(curr
, hfreq
, vfreq
, dotclock
))
448 if (best
->xres
< xres
|| best
->yres
< yres
) {
449 if (curr
->xres
> best
->xres
|| curr
->yres
> best
->yres
) {
450 mp_msg(MSGT_VO
, MSGL_DBG2
, "better than %dx%d, which is too small.\n",
451 best
->xres
, best
->yres
);
454 mp_msg(MSGT_VO
, MSGL_DBG2
, "too small.\n");
455 } else if (curr
->xres
== best
->xres
&& curr
->yres
== best
->yres
&&
456 vsf(curr
) > vsf(best
)) {
457 mp_msg(MSGT_VO
, MSGL_DBG2
, "faster screen refresh.\n");
459 } else if ((curr
->xres
<= best
->xres
&& curr
->yres
<= best
->yres
) &&
460 (curr
->xres
>= xres
&& curr
->yres
>= yres
)) {
461 mp_msg(MSGT_VO
, MSGL_DBG2
, "better than %dx%d, which is too large.\n",
462 best
->xres
, best
->yres
);
465 if (curr
->xres
< xres
|| curr
->yres
< yres
)
466 mp_msg(MSGT_VO
, MSGL_DBG2
, "too small.\n");
467 else if (curr
->xres
> best
->xres
|| curr
->yres
> best
->yres
)
468 mp_msg(MSGT_VO
, MSGL_DBG2
, "too large.\n");
470 mp_msg(MSGT_VO
, MSGL_DBG2
, "it's worse, don't know why.\n");
477 static void set_bpp(struct fb_var_screeninfo
*p
, int bpp
)
479 p
->bits_per_pixel
= (bpp
+ 1) & ~1;
480 p
->red
.msb_right
= p
->green
.msb_right
= p
->blue
.msb_right
= p
->transp
.msb_right
= 0;
481 p
->transp
.offset
= p
->transp
.length
= 0;
485 p
->transp
.offset
= 24;
486 p
->transp
.length
= 8;
511 static void fb_mode2fb_vinfo(fb_mode_t
*m
, struct fb_var_screeninfo
*v
)
515 v
->xres_virtual
= m
->vxres
;
516 v
->yres_virtual
= m
->vyres
;
517 set_bpp(v
, m
->depth
);
518 v
->pixclock
= m
->pixclock
;
519 v
->left_margin
= m
->left
;
520 v
->right_margin
= m
->right
;
521 v
->upper_margin
= m
->upper
;
522 v
->lower_margin
= m
->lower
;
523 v
->hsync_len
= m
->hslen
;
524 v
->vsync_len
= m
->vslen
;
530 /******************************
532 ******************************/
534 /* command line/config file options */
535 static char *fb_dev_name
= NULL
;
536 char *fb_mode_cfgfile
= NULL
;
537 char *fb_mode_name
= NULL
;
539 static fb_mode_t
*fb_mode
= NULL
;
541 /* vt related variables */
542 static FILE *vt_fp
= NULL
;
543 static int vt_doit
= 1;
545 /* vo_fbdev related variables */
546 static int fb_dev_fd
;
547 static int fb_tty_fd
= -1;
548 static size_t fb_size
;
549 static uint8_t *frame_buffer
;
550 static uint8_t *center
;
551 static struct fb_fix_screeninfo fb_finfo
;
552 static struct fb_var_screeninfo fb_orig_vinfo
;
553 static struct fb_var_screeninfo fb_vinfo
;
554 static unsigned short fb_ored
[256], fb_ogreen
[256], fb_oblue
[256];
555 static struct fb_cmap fb_oldcmap
= { 0, 256, fb_ored
, fb_ogreen
, fb_oblue
};
556 static int fb_cmap_changed
= 0;
557 static int fb_pixel_size
; // 32: 4 24: 3 16: 2 15: 2
558 static int fb_bpp
; // 32: 32 24: 24 16: 16 15: 15
559 static int fb_bpp_we_want
; // 32: 32 24: 24 16: 16 15: 15
560 static int fb_line_len
;
563 static void (*draw_alpha_p
)(int w
, int h
, unsigned char *src
,
564 unsigned char *srca
, int stride
,
565 unsigned char *dst
, int dstride
);
568 static int in_height
;
569 static int out_width
;
570 static int out_height
;
571 static int first_row
;
573 static uint32_t pixel_format
;
577 * Note: this function is completely cut'n'pasted from
578 * Chris Lawrence's code.
579 * (modified a bit to fit in my code...)
581 static struct fb_cmap
*make_directcolor_cmap(struct fb_var_screeninfo
*var
)
583 /* Hopefully any DIRECTCOLOR device will have a big enough palette
584 * to handle mapping the full color depth.
585 * e.g. 8 bpp -> 256 entry palette
587 * We could handle some sort of gamma here
589 int i
, cols
, rcols
, gcols
, bcols
;
590 uint16_t *red
, *green
, *blue
;
591 struct fb_cmap
*cmap
;
593 rcols
= 1 << var
->red
.length
;
594 gcols
= 1 << var
->green
.length
;
595 bcols
= 1 << var
->blue
.length
;
597 /* Make our palette the length of the deepest color */
598 cols
= (rcols
> gcols
? rcols
: gcols
);
599 cols
= (cols
> bcols
? cols
: bcols
);
601 red
= malloc(cols
* sizeof(red
[0]));
603 mp_msg(MSGT_VO
, MSGL_V
, "Can't allocate red palette with %d entries.\n", cols
);
606 for (i
= 0; i
< rcols
; i
++)
607 red
[i
] = (65535 / (rcols
- 1)) * i
;
609 green
= malloc(cols
* sizeof(green
[0]));
611 mp_msg(MSGT_VO
, MSGL_V
, "Can't allocate green palette with %d entries.\n", cols
);
615 for (i
= 0; i
< gcols
; i
++)
616 green
[i
] = (65535 / (gcols
- 1)) * i
;
618 blue
= malloc(cols
* sizeof(blue
[0]));
620 mp_msg(MSGT_VO
, MSGL_V
, "Can't allocate blue palette with %d entries.\n", cols
);
625 for (i
= 0; i
< bcols
; i
++)
626 blue
[i
] = (65535 / (bcols
- 1)) * i
;
628 cmap
= malloc(sizeof(struct fb_cmap
));
630 mp_msg(MSGT_VO
, MSGL_V
, "Can't allocate color map\n");
648 static int fb_preinit(int reset
)
650 static int fb_preinit_done
= 0;
651 static int fb_works
= 0;
661 if (!fb_dev_name
&& !(fb_dev_name
= getenv("FRAMEBUFFER")))
662 fb_dev_name
= strdup("/dev/fb0");
663 mp_msg(MSGT_VO
, MSGL_V
, "using %s\n", fb_dev_name
);
665 if ((fb_dev_fd
= open(fb_dev_name
, O_RDWR
)) == -1) {
666 mp_msg(MSGT_VO
, MSGL_ERR
, "Can't open %s: %s\n", fb_dev_name
, strerror(errno
));
669 if (ioctl(fb_dev_fd
, FBIOGET_VSCREENINFO
, &fb_vinfo
)) {
670 mp_msg(MSGT_VO
, MSGL_ERR
, "Can't get VSCREENINFO: %s\n", strerror(errno
));
673 fb_orig_vinfo
= fb_vinfo
;
675 if ((fb_tty_fd
= open("/dev/tty", O_RDWR
)) < 0) {
676 mp_msg(MSGT_VO
, MSGL_ERR
, "notice: Can't open /dev/tty: %s\n", strerror(errno
));
679 fb_bpp
= fb_vinfo
.red
.length
+ fb_vinfo
.green
.length
+
680 fb_vinfo
.blue
.length
+ fb_vinfo
.transp
.length
;
682 if (fb_bpp
== 8 && !vo_dbpp
) {
683 mp_msg(MSGT_VO
, MSGL_ERR
, "8 bpp output is not supported.\n");
688 if (vo_dbpp
!= 15 && vo_dbpp
!= 16 && vo_dbpp
!= 24 && vo_dbpp
!= 32) {
689 mp_msg(MSGT_VO
, MSGL_ERR
, "can't switch to %d bpp\n", vo_dbpp
);
695 if (!fb_mode_cfgfile
)
696 fb_mode_cfgfile
= strdup("/etc/fb.modes");
713 static void vt_set_textarea(int u
, int l
)
715 /* how can I determine the font height?
716 * just use 16 for now
718 int urow
= ((u
+ 15) / 16) + 1;
721 mp_msg(MSGT_VO
, MSGL_DBG2
, "vt_set_textarea(%d,%d): %d,%d\n", u
, l
, urow
, lrow
);
723 fprintf(vt_fp
, "\33[%d;%dr\33[%d;%dH", urow
, lrow
, lrow
, 0);
728 static int config(uint32_t width
, uint32_t height
, uint32_t d_width
,
729 uint32_t d_height
, uint32_t flags
, char *title
,
732 struct fb_cmap
*cmap
;
733 int vm
= flags
& VOFLAG_MODESWITCHING
;
734 int zoom
= flags
& VOFLAG_SWSCALE
;
737 fs
= flags
& VOFLAG_FULLSCREEN
;
739 if (pre_init_err
== -2) {
740 mp_msg(MSGT_VO
, MSGL_ERR
, "Internal fatal error: config() was called before preinit()\n");
747 if (fb_mode_name
&& !vm
) {
748 mp_msg(MSGT_VO
, MSGL_ERR
, "-fbmode can only be used with -vm\n");
751 if (vm
&& (parse_fbmode_cfg(fb_mode_cfgfile
) < 0))
753 if (d_width
&& (fs
|| vm
)) {
755 out_height
= d_height
;
762 pixel_format
= format
;
765 if (!(fb_mode
= find_mode_by_name(fb_mode_name
))) {
766 mp_msg(MSGT_VO
, MSGL_ERR
, "can't find requested video mode\n");
769 fb_mode2fb_vinfo(fb_mode
, &fb_vinfo
);
771 monitor_hfreq
= str2range(monitor_hfreq_str
);
772 monitor_vfreq
= str2range(monitor_vfreq_str
);
773 monitor_dotclock
= str2range(monitor_dotclock_str
);
774 if (!monitor_hfreq
|| !monitor_vfreq
|| !monitor_dotclock
) {
775 mp_msg(MSGT_VO
, MSGL_ERR
, "you have to specify the capabilities of"
779 if (!(fb_mode
= find_best_mode(out_width
, out_height
, monitor_hfreq
,
780 monitor_vfreq
, monitor_dotclock
))) {
781 mp_msg(MSGT_VO
, MSGL_ERR
, "can't find best video mode\n");
784 mp_msg(MSGT_VO
, MSGL_V
, "using mode %dx%d @ %.1fHz\n", fb_mode
->xres
,
785 fb_mode
->yres
, vsf(fb_mode
));
786 fb_mode2fb_vinfo(fb_mode
, &fb_vinfo
);
788 fb_bpp_we_want
= fb_bpp
;
789 set_bpp(&fb_vinfo
, fb_bpp
);
790 fb_vinfo
.xres_virtual
= fb_vinfo
.xres
;
791 fb_vinfo
.yres_virtual
= fb_vinfo
.yres
;
793 if (fb_tty_fd
>= 0 && ioctl(fb_tty_fd
, KDSETMODE
, KD_GRAPHICS
) < 0) {
794 mp_msg(MSGT_VO
, MSGL_V
, "Can't set graphics mode: %s\n", strerror(errno
));
799 if (ioctl(fb_dev_fd
, FBIOPUT_VSCREENINFO
, &fb_vinfo
)) {
800 mp_msg(MSGT_VO
, MSGL_ERR
, "Can't put VSCREENINFO: %s\n", strerror(errno
));
801 if (fb_tty_fd
>= 0 && ioctl(fb_tty_fd
, KDSETMODE
, KD_TEXT
) < 0) {
802 mp_msg(MSGT_VO
, MSGL_ERR
, "Can't restore text mode: %s\n", strerror(errno
));
807 fb_pixel_size
= fb_vinfo
.bits_per_pixel
/ 8;
808 fb_bpp
= fb_vinfo
.red
.length
+ fb_vinfo
.green
.length
+
809 fb_vinfo
.blue
.length
+ fb_vinfo
.transp
.length
;
810 if (fb_bpp_we_want
!= fb_bpp
)
811 mp_msg(MSGT_VO
, MSGL_WARN
, "requested %d bpp, got %d bpp!!!\n",
812 fb_bpp_we_want
, fb_bpp
);
816 draw_alpha_p
= vo_draw_alpha_rgb32
;
819 draw_alpha_p
= vo_draw_alpha_rgb24
;
822 draw_alpha_p
= vo_draw_alpha_rgb16
;
825 draw_alpha_p
= vo_draw_alpha_rgb15
;
831 fb_xres
= fb_vinfo
.xres
;
832 fb_yres
= fb_vinfo
.yres
;
836 out_height
= fb_yres
;
838 if (out_width
< in_width
|| out_height
< in_height
) {
839 mp_msg(MSGT_VO
, MSGL_ERR
, "screensize is smaller than video size\n");
843 first_row
= (out_height
- in_height
) / 2;
844 last_row
= (out_height
+ in_height
) / 2;
846 if (ioctl(fb_dev_fd
, FBIOGET_FSCREENINFO
, &fb_finfo
)) {
847 mp_msg(MSGT_VO
, MSGL_ERR
, "Can't get FSCREENINFO: %s\n", strerror(errno
));
851 if (fb_finfo
.type
!= FB_TYPE_PACKED_PIXELS
) {
852 mp_msg(MSGT_VO
, MSGL_ERR
, "type %d not supported\n", fb_finfo
.type
);
856 switch (fb_finfo
.visual
) {
857 case FB_VISUAL_TRUECOLOR
:
859 case FB_VISUAL_DIRECTCOLOR
:
860 mp_msg(MSGT_VO
, MSGL_V
, "creating cmap for directcolor\n");
861 if (ioctl(fb_dev_fd
, FBIOGETCMAP
, &fb_oldcmap
)) {
862 mp_msg(MSGT_VO
, MSGL_ERR
, "can't get cmap: %s\n",
866 if (!(cmap
= make_directcolor_cmap(&fb_vinfo
)))
868 if (ioctl(fb_dev_fd
, FBIOPUTCMAP
, cmap
)) {
869 mp_msg(MSGT_VO
, MSGL_ERR
, "can't put cmap: %s\n",
880 mp_msg(MSGT_VO
, MSGL_ERR
, "visual: %d not yet supported\n",
885 fb_line_len
= fb_finfo
.line_length
;
886 fb_size
= fb_finfo
.smem_len
;
890 unsigned image_width
, image_height
, x_offset
, y_offset
;
892 aspect_save_orig(width
, height
);
893 aspect_save_prescale(d_width
, d_height
);
894 aspect_save_screenres(fb_xres
, fb_yres
);
895 aspect(&image_width
, &image_height
, fs
? A_ZOOM
: A_NOZOOM
);
898 image_height
= height
;
901 if (fb_xres
> image_width
)
902 x_offset
= (fb_xres
- image_width
) / 2;
905 if (fb_yres
> image_height
)
906 y_offset
= (fb_yres
- image_height
) / 2;
910 if (vidix_init(width
, height
, x_offset
, y_offset
, image_width
,
911 image_height
, format
, fb_bpp
, fb_xres
, fb_yres
) != 0) {
912 mp_msg(MSGT_VO
, MSGL_ERR
, "Can't initialize VIDIX driver\n");
917 mp_msg(MSGT_VO
, MSGL_V
, "Using VIDIX\n");
919 if (vidix_grkey_support()) {
920 vidix_grkey_get(&gr_key
);
921 gr_key
.key_op
= KEYS_PUT
;
922 if (!(vo_colorkey
& 0xff000000)) {
923 gr_key
.ckey
.op
= CKEY_TRUE
;
924 gr_key
.ckey
.red
= (vo_colorkey
& 0x00ff0000) >> 16;
925 gr_key
.ckey
.green
= (vo_colorkey
& 0x0000ff00) >> 8;
926 gr_key
.ckey
.blue
= vo_colorkey
& 0x000000ff;
928 gr_key
.ckey
.op
= CKEY_FALSE
;
929 vidix_grkey_set(&gr_key
);
934 int x_offset
= 0, y_offset
= 0;
935 geometry(&x_offset
, &y_offset
, &out_width
, &out_height
, fb_xres
, fb_yres
);
937 frame_buffer
= (uint8_t *) mmap(0, fb_size
, PROT_READ
| PROT_WRITE
,
938 MAP_SHARED
, fb_dev_fd
, 0);
939 if (frame_buffer
== (uint8_t *) -1) {
940 mp_msg(MSGT_VO
, MSGL_ERR
, "Can't mmap %s: %s\n", fb_dev_name
, strerror(errno
));
944 center
= frame_buffer
+
945 ( (out_width
- in_width
) / 2 ) * fb_pixel_size
+
946 ( (out_height
- in_height
) / 2 ) * fb_line_len
+
947 x_offset
* fb_pixel_size
+ y_offset
* fb_line_len
;
949 mp_msg(MSGT_VO
, MSGL_DBG2
, "frame_buffer @ %p\n", frame_buffer
);
950 mp_msg(MSGT_VO
, MSGL_DBG2
, "center @ %p\n", center
);
951 mp_msg(MSGT_VO
, MSGL_V
, "pixel per line: %d\n", fb_line_len
/ fb_pixel_size
);
954 memset(frame_buffer
, '\0', fb_line_len
* fb_yres
);
956 if (vt_doit
&& (vt_fd
= open("/dev/tty", O_WRONLY
)) == -1) {
957 mp_msg(MSGT_VO
, MSGL_ERR
, "can't open /dev/tty: %s\n", strerror(errno
));
960 if (vt_doit
&& !(vt_fp
= fdopen(vt_fd
, "w"))) {
961 mp_msg(MSGT_VO
, MSGL_ERR
, "can't fdopen /dev/tty: %s\n", strerror(errno
));
966 vt_set_textarea(last_row
, fb_yres
);
971 static int query_format(uint32_t format
)
977 return vidix_query_fourcc(format
);
979 if ((format
& IMGFMT_BGR_MASK
) == IMGFMT_BGR
) {
980 int bpp
= format
& 0xff;
983 return VFCAP_ACCEPT_STRIDE
| VFCAP_CSP_SUPPORTED
| VFCAP_CSP_SUPPORTED_BY_HW
;
988 static void draw_alpha(int x0
, int y0
, int w
, int h
, unsigned char *src
,
989 unsigned char *srca
, int stride
)
993 dst
= center
+ fb_line_len
* y0
+ fb_pixel_size
* x0
;
995 (*draw_alpha_p
)(w
, h
, src
, srca
, stride
, dst
, fb_line_len
);
998 static int draw_frame(uint8_t *src
[])
1003 static int draw_slice(uint8_t *src
[], int stride
[], int w
, int h
, int x
, int y
)
1007 d
= center
+ fb_line_len
* y
+ fb_pixel_size
* x
;
1011 fast_memcpy(d
, s
, w
* fb_pixel_size
);
1020 static void check_events(void)
1024 static void flip_page(void)
1028 static void draw_osd(void)
1030 vo_draw_text(in_width
, in_height
, draw_alpha
);
1033 static void uninit(void)
1035 if (fb_cmap_changed
) {
1036 if (ioctl(fb_dev_fd
, FBIOPUTCMAP
, &fb_oldcmap
))
1037 mp_msg(MSGT_VO
, MSGL_WARN
, "Can't restore original cmap\n");
1038 fb_cmap_changed
= 0;
1040 if (ioctl(fb_dev_fd
, FBIOGET_VSCREENINFO
, &fb_vinfo
))
1041 mp_msg(MSGT_VO
, MSGL_WARN
, "ioctl FBIOGET_VSCREENINFO: %s\n", strerror(errno
));
1042 fb_orig_vinfo
.xoffset
= fb_vinfo
.xoffset
;
1043 fb_orig_vinfo
.yoffset
= fb_vinfo
.yoffset
;
1044 if (ioctl(fb_dev_fd
, FBIOPUT_VSCREENINFO
, &fb_orig_vinfo
))
1045 mp_msg(MSGT_VO
, MSGL_WARN
, "Can't reset original fb_var_screeninfo: %s\n", strerror(errno
));
1046 if (fb_tty_fd
>= 0) {
1047 if (ioctl(fb_tty_fd
, KDSETMODE
, KD_TEXT
) < 0)
1048 mp_msg(MSGT_VO
, MSGL_WARN
, "Can't restore text mode: %s\n", strerror(errno
));
1051 vt_set_textarea(0, fb_orig_vinfo
.yres
);
1055 munmap(frame_buffer
, fb_size
);
1056 frame_buffer
= NULL
;
1064 static int preinit(const char *vo_subdevice
)
1070 if (memcmp(vo_subdevice
, "vidix", 5) == 0)
1071 vidix_name
= &vo_subdevice
[5];
1073 pre_init_err
= vidix_preinit(vidix_name
, &video_out_fbdev
);
1079 fb_dev_name
= strdup(vo_subdevice
);
1083 return pre_init_err
= (fb_preinit(0) ? 0 : -1);
1087 static uint32_t get_image(mp_image_t
*mpi
)
1089 if (!IMGFMT_IS_BGR(mpi
->imgfmt
) ||
1090 (IMGFMT_BGR_DEPTH(mpi
->imgfmt
) != fb_bpp
) ||
1091 ((mpi
->type
!= MP_IMGTYPE_STATIC
) && (mpi
->type
!= MP_IMGTYPE_TEMP
)) ||
1092 (mpi
->flags
& MP_IMGFLAG_PLANAR
) ||
1093 (mpi
->flags
& MP_IMGFLAG_YUV
) ||
1094 (mpi
->width
!= in_width
) ||
1095 (mpi
->height
!= in_height
)
1099 mpi
->planes
[0] = center
;
1100 mpi
->stride
[0] = fb_line_len
;
1101 mpi
->flags
|= MP_IMGFLAG_DIRECT
;
1105 static int control(uint32_t request
, void *data
, ...)
1108 case VOCTRL_GET_IMAGE
:
1109 return get_image(data
);
1110 case VOCTRL_QUERY_FORMAT
:
1111 return query_format(*((uint32_t*)data
));
1117 case VOCTRL_SET_EQUALIZER
:
1123 value
= va_arg(ap
, int);
1126 return vidix_control(request
, data
, value
);
1128 case VOCTRL_GET_EQUALIZER
:
1134 value
= va_arg(ap
, int*);
1137 return vidix_control(request
, data
, value
);