Mercurial > mplayer.hg
annotate libvo/vo_fbdev.c @ 2315:c3c73ba53f0e
streaming fixed
author | arpi |
---|---|
date | Sat, 20 Oct 2001 20:35:12 +0000 |
parents | e71337d1e58b |
children | 0e2f4c4e55d4 |
rev | line source |
---|---|
305 | 1 /* |
2 * Video driver for Framebuffer device | |
3 * by Szabolcs Berecz <szabi@inf.elte.hu> | |
359 | 4 * (C) 2001 |
305 | 5 * |
6 * Some idea and code borrowed from Chris Lawrence's ppmtofb-0.27 | |
7 */ | |
8 | |
393 | 9 #define FBDEV "fbdev: " |
10 | |
225 | 11 #include <stdio.h> |
12 #include <stdlib.h> | |
13 #include <string.h> | |
14 #include <fcntl.h> | |
15 #include <unistd.h> | |
16 #include <errno.h> | |
359 | 17 #include <ctype.h> |
18 #include <assert.h> | |
225 | 19 |
20 #include <sys/mman.h> | |
21 #include <sys/ioctl.h> | |
22 #include <linux/fb.h> | |
23 | |
24 #include "config.h" | |
25 #include "video_out.h" | |
26 #include "video_out_internal.h" | |
658 | 27 #include "fastmemcpy.h" |
633 | 28 #include "sub.h" |
225 | 29 #include "yuv2rgb.h" |
30 | |
31 LIBVO_EXTERN(fbdev) | |
32 | |
33 static vo_info_t vo_info = { | |
34 "Framebuffer Device", | |
35 "fbdev", | |
36 "Szabolcs Berecz <szabi@inf.elte.hu>", | |
37 "" | |
38 }; | |
39 | |
950 | 40 extern void rgb15to16_mmx(char *s0, char *d0, int count); |
379 | 41 extern int verbose; |
42 | |
359 | 43 /****************************** |
393 | 44 * fb.modes support * |
359 | 45 ******************************/ |
46 | |
47 typedef struct { | |
48 char *name; | |
49 uint32_t xres, yres, vxres, vyres, depth; | |
50 uint32_t pixclock, left, right, upper, lower, hslen, vslen; | |
51 uint32_t sync; | |
52 uint32_t vmode; | |
53 } fb_mode_t; | |
54 | |
55 #define PRINT_LINENUM printf(" at line %d\n", line_num) | |
56 | |
57 #define MAX_NR_TOKEN 16 | |
58 | |
59 #define MAX_LINE_LEN 1000 | |
60 | |
61 #define RET_EOF -1 | |
62 #define RET_EOL -2 | |
63 | |
64 static int validate_mode(fb_mode_t *m) | |
65 { | |
66 if (!m->xres) { | |
67 printf("needs geometry "); | |
68 return 0; | |
69 } | |
70 if (!m->pixclock) { | |
71 printf("needs timings "); | |
72 return 0; | |
73 } | |
74 return 1; | |
75 } | |
76 | |
77 static FILE *fp; | |
78 static int line_num = 0; | |
79 static char *line; | |
80 static char *token[MAX_NR_TOKEN]; | |
81 | |
82 static int get_token(int num) | |
83 { | |
84 static int read_nextline = 1; | |
85 static int line_pos; | |
86 int i; | |
87 char c; | |
88 | |
89 if (num >= MAX_NR_TOKEN) { | |
90 printf("get_token(): max >= MAX_NR_TOKEN!"); | |
91 goto out_eof; | |
92 } | |
93 | |
94 if (read_nextline) { | |
95 if (!fgets(line, MAX_LINE_LEN, fp)) | |
96 goto out_eof; | |
97 line_pos = 0; | |
98 ++line_num; | |
99 read_nextline = 0; | |
100 } | |
101 for (i = 0; i < num; i++) { | |
102 while (isspace(line[line_pos])) | |
103 ++line_pos; | |
104 if (line[line_pos] == '\0' || line[line_pos] == '#') { | |
105 read_nextline = 1; | |
106 goto out_eol; | |
107 } | |
108 token[i] = line + line_pos; | |
109 c = line[line_pos]; | |
110 if (c == '"' || c == '\'') { | |
111 token[i]++; | |
112 while (line[++line_pos] != c && line[line_pos]) | |
113 /* NOTHING */; | |
950 | 114 if (!line[line_pos]) |
115 goto out_eol; | |
116 line[line_pos] = ' '; | |
359 | 117 } else { |
118 for (/* NOTHING */; !isspace(line[line_pos]) && | |
119 line[line_pos]; line_pos++) | |
120 /* NOTHING */; | |
121 } | |
122 if (!line[line_pos]) { | |
123 read_nextline = 1; | |
124 if (i == num - 1) | |
125 goto out_ok; | |
126 goto out_eol; | |
127 } | |
950 | 128 line[line_pos++] = '\0'; |
359 | 129 } |
130 out_ok: | |
131 return i; | |
132 out_eof: | |
133 return RET_EOF; | |
134 out_eol: | |
135 return RET_EOL; | |
136 } | |
137 | |
138 static fb_mode_t *fb_modes = NULL; | |
139 static int nr_modes = 0; | |
140 | |
141 static int parse_fbmode_cfg(char *cfgfile) | |
142 { | |
977 | 143 #define CHECK_IN_MODE_DEF\ |
144 do {\ | |
145 if (!in_mode_def) {\ | |
146 printf("'needs 'mode' first");\ | |
147 goto err_out_print_linenum;\ | |
148 }\ | |
149 } while (0) | |
150 | |
359 | 151 fb_mode_t *mode = NULL; |
152 char *endptr; // strtoul()... | |
977 | 153 int in_mode_def = 0; |
359 | 154 int tmp, i; |
155 | |
950 | 156 if (verbose > 0) |
157 printf("Reading %s: ", cfgfile); | |
359 | 158 |
159 if ((fp = fopen(cfgfile, "r")) == NULL) { | |
160 printf("can't open '%s': %s\n", cfgfile, strerror(errno)); | |
161 return -1; | |
162 } | |
163 | |
164 if ((line = (char *) malloc(MAX_LINE_LEN + 1)) == NULL) { | |
165 printf("can't get memory for 'line': %s\n", strerror(errno)); | |
166 return -2; | |
167 } | |
168 | |
169 /* | |
170 * check if the cfgfile starts with 'mode' | |
171 */ | |
172 while ((tmp = get_token(1)) == RET_EOL) | |
173 /* NOTHING */; | |
174 if (tmp == RET_EOF) | |
175 goto out; | |
176 if (!strcmp(token[0], "mode")) | |
177 goto loop_enter; | |
178 goto err_out_parse_error; | |
179 | |
180 while ((tmp = get_token(1)) != RET_EOF) { | |
181 if (tmp == RET_EOL) | |
182 continue; | |
183 if (!strcmp(token[0], "mode")) { | |
977 | 184 if (in_mode_def) { |
185 printf("'endmode' required"); | |
186 goto err_out_print_linenum; | |
187 } | |
359 | 188 if (!validate_mode(mode)) |
189 goto err_out_not_valid; | |
190 loop_enter: | |
191 if (!(fb_modes = (fb_mode_t *) realloc(fb_modes, | |
192 sizeof(fb_mode_t) * (nr_modes + 1)))) { | |
950 | 193 printf("can't realloc 'fb_modes' (nr_modes = %d):" |
194 " %s\n", nr_modes, strerror(errno)); | |
359 | 195 goto err_out; |
196 } | |
197 mode=fb_modes + nr_modes; | |
198 ++nr_modes; | |
199 memset(mode,0,sizeof(fb_mode_t)); | |
225 | 200 |
359 | 201 if (get_token(1) < 0) |
202 goto err_out_parse_error; | |
203 for (i = 0; i < nr_modes - 1; i++) { | |
204 if (!strcmp(token[0], fb_modes[i].name)) { | |
205 printf("mode name '%s' isn't unique", token[0]); | |
206 goto err_out_print_linenum; | |
207 } | |
208 } | |
209 if (!(mode->name = strdup(token[0]))) { | |
210 printf("can't strdup -> 'name': %s\n", strerror(errno)); | |
211 goto err_out; | |
212 } | |
977 | 213 in_mode_def = 1; |
359 | 214 } else if (!strcmp(token[0], "geometry")) { |
977 | 215 CHECK_IN_MODE_DEF; |
359 | 216 if (get_token(5) < 0) |
217 goto err_out_parse_error; | |
218 mode->xres = strtoul(token[0], &endptr, 0); | |
219 if (*endptr) | |
220 goto err_out_parse_error; | |
221 mode->yres = strtoul(token[1], &endptr, 0); | |
222 if (*endptr) | |
223 goto err_out_parse_error; | |
224 mode->vxres = strtoul(token[2], &endptr, 0); | |
225 if (*endptr) | |
226 goto err_out_parse_error; | |
227 mode->vyres = strtoul(token[3], &endptr, 0); | |
228 if (*endptr) | |
229 goto err_out_parse_error; | |
230 mode->depth = strtoul(token[4], &endptr, 0); | |
231 if (*endptr) | |
232 goto err_out_parse_error; | |
233 } else if (!strcmp(token[0], "timings")) { | |
977 | 234 CHECK_IN_MODE_DEF; |
359 | 235 if (get_token(7) < 0) |
236 goto err_out_parse_error; | |
237 mode->pixclock = strtoul(token[0], &endptr, 0); | |
238 if (*endptr) | |
239 goto err_out_parse_error; | |
240 mode->left = strtoul(token[1], &endptr, 0); | |
241 if (*endptr) | |
242 goto err_out_parse_error; | |
243 mode->right = strtoul(token[2], &endptr, 0); | |
244 if (*endptr) | |
245 goto err_out_parse_error; | |
246 mode->upper = strtoul(token[3], &endptr, 0); | |
247 if (*endptr) | |
248 goto err_out_parse_error; | |
249 mode->lower = strtoul(token[4], &endptr, 0); | |
250 if (*endptr) | |
251 goto err_out_parse_error; | |
252 mode->hslen = strtoul(token[5], &endptr, 0); | |
253 if (*endptr) | |
254 goto err_out_parse_error; | |
255 mode->vslen = strtoul(token[6], &endptr, 0); | |
256 if (*endptr) | |
257 goto err_out_parse_error; | |
258 } else if (!strcmp(token[0], "endmode")) { | |
977 | 259 CHECK_IN_MODE_DEF; |
260 in_mode_def = 0; | |
383 | 261 } else if (!strcmp(token[0], "accel")) { |
977 | 262 CHECK_IN_MODE_DEF; |
383 | 263 if (get_token(1) < 0) |
264 goto err_out_parse_error; | |
393 | 265 /* |
266 * it's only used for text acceleration | |
267 * so we just ignore it. | |
268 */ | |
359 | 269 } else if (!strcmp(token[0], "hsync")) { |
977 | 270 CHECK_IN_MODE_DEF; |
359 | 271 if (get_token(1) < 0) |
272 goto err_out_parse_error; | |
273 if (!strcmp(token[0], "low")) | |
274 mode->sync &= ~FB_SYNC_HOR_HIGH_ACT; | |
275 else if(!strcmp(token[0], "high")) | |
276 mode->sync |= FB_SYNC_HOR_HIGH_ACT; | |
277 else | |
278 goto err_out_parse_error; | |
279 } else if (!strcmp(token[0], "vsync")) { | |
977 | 280 CHECK_IN_MODE_DEF; |
359 | 281 if (get_token(1) < 0) |
282 goto err_out_parse_error; | |
283 if (!strcmp(token[0], "low")) | |
284 mode->sync &= ~FB_SYNC_VERT_HIGH_ACT; | |
285 else if(!strcmp(token[0], "high")) | |
286 mode->sync |= FB_SYNC_VERT_HIGH_ACT; | |
287 else | |
288 goto err_out_parse_error; | |
289 } else if (!strcmp(token[0], "csync")) { | |
977 | 290 CHECK_IN_MODE_DEF; |
359 | 291 if (get_token(1) < 0) |
292 goto err_out_parse_error; | |
293 if (!strcmp(token[0], "low")) | |
294 mode->sync &= ~FB_SYNC_COMP_HIGH_ACT; | |
295 else if(!strcmp(token[0], "high")) | |
296 mode->sync |= FB_SYNC_COMP_HIGH_ACT; | |
297 else | |
298 goto err_out_parse_error; | |
299 } else if (!strcmp(token[0], "extsync")) { | |
977 | 300 CHECK_IN_MODE_DEF; |
359 | 301 if (get_token(1) < 0) |
302 goto err_out_parse_error; | |
303 if (!strcmp(token[0], "false")) | |
304 mode->sync &= ~FB_SYNC_EXT; | |
305 else if(!strcmp(token[0], "true")) | |
306 mode->sync |= FB_SYNC_EXT; | |
307 else | |
308 goto err_out_parse_error; | |
309 } else if (!strcmp(token[0], "laced")) { | |
977 | 310 CHECK_IN_MODE_DEF; |
359 | 311 if (get_token(1) < 0) |
312 goto err_out_parse_error; | |
313 if (!strcmp(token[0], "false")) | |
314 mode->vmode = FB_VMODE_NONINTERLACED; | |
315 else if (!strcmp(token[0], "true")) | |
316 mode->vmode = FB_VMODE_INTERLACED; | |
317 else | |
318 goto err_out_parse_error; | |
479 | 319 } else if (!strcmp(token[0], "double")) { |
977 | 320 CHECK_IN_MODE_DEF; |
359 | 321 if (get_token(1) < 0) |
322 goto err_out_parse_error; | |
323 if (!strcmp(token[0], "false")) | |
324 ; | |
325 else if (!strcmp(token[0], "true")) | |
326 mode->vmode = FB_VMODE_DOUBLE; | |
327 else | |
328 goto err_out_parse_error; | |
329 } else | |
330 goto err_out_parse_error; | |
331 } | |
332 if (!validate_mode(mode)) | |
333 goto err_out_not_valid; | |
334 out: | |
950 | 335 if (verbose > 0) |
336 printf("%d modes\n", nr_modes); | |
359 | 337 free(line); |
338 fclose(fp); | |
339 return nr_modes; | |
340 err_out_parse_error: | |
341 printf("parse error"); | |
342 err_out_print_linenum: | |
343 PRINT_LINENUM; | |
344 err_out: | |
393 | 345 if (fb_modes) { |
359 | 346 free(fb_modes); |
393 | 347 fb_modes = NULL; |
348 } | |
349 nr_modes = 0; | |
359 | 350 free(line); |
351 free(fp); | |
352 return -2; | |
353 err_out_not_valid: | |
950 | 354 printf("previous mode is not correct"); |
359 | 355 goto err_out_print_linenum; |
356 } | |
357 | |
358 static fb_mode_t *find_mode_by_name(char *name) | |
359 { | |
360 int i; | |
361 | |
658 | 362 for (i = 0; i < nr_modes; i++) |
359 | 363 if (!strcmp(name, fb_modes[i].name)) |
364 return fb_modes + i; | |
365 return NULL; | |
366 } | |
367 | |
393 | 368 static float dcf(fb_mode_t *m) //driving clock frequency |
369 { | |
519 | 370 return 1e12f / m->pixclock; |
393 | 371 } |
372 | |
373 static float hsf(fb_mode_t *m) //horizontal scan frequency | |
374 { | |
375 int htotal = m->left + m->xres + m->right + m->hslen; | |
376 return dcf(m) / htotal; | |
377 } | |
378 | |
379 static float vsf(fb_mode_t *m) //vertical scan frequency | |
380 { | |
381 int vtotal = m->upper + m->yres + m->lower + m->vslen; | |
382 return hsf(m) / vtotal; | |
383 } | |
384 | |
385 typedef struct { | |
386 float min; | |
387 float max; | |
418 | 388 } range_t; |
393 | 389 |
418 | 390 static int in_range(range_t *r, float f) |
393 | 391 { |
658 | 392 for (/* NOTHING */; (r->min != -1 && r->max != -1); r++) |
393 | 393 if (f >= r->min && f <= r->max) |
394 return 1; | |
395 return 0; | |
396 } | |
397 | |
1561 | 398 static int mode_works(fb_mode_t *m, range_t *hfreq, range_t *vfreq, |
399 range_t *dotclock) | |
400 { | |
401 float h = hsf(m); | |
402 float v = vsf(m); | |
403 float d = dcf(m); | |
404 int ret = 1; | |
405 | |
406 if (verbose > 1) | |
407 printf(FBDEV "mode %dx%d:", m->xres, m->yres); | |
408 if (!in_range(hfreq, h)) { | |
409 ret = 0; | |
410 if (verbose > 1) | |
411 printf(" hsync out of range."); | |
412 } | |
413 if (!in_range(vfreq, v)) { | |
414 ret = 0; | |
415 if (verbose > 1) | |
416 printf(" vsync out of range."); | |
417 } | |
418 if (!in_range(dotclock, d)) { | |
419 ret = 0; | |
420 if (verbose > 1) | |
421 printf(" dotclock out of range."); | |
422 } | |
423 if (verbose > 1) { | |
424 if (ret) | |
425 printf(" hsync, vsync, dotclock ok.\n"); | |
426 else | |
427 printf("\n"); | |
428 } | |
429 | |
430 return ret; | |
431 } | |
432 | |
418 | 433 static fb_mode_t *find_best_mode(int xres, int yres, range_t *hfreq, |
434 range_t *vfreq, range_t *dotclock) | |
393 | 435 { |
436 int i; | |
437 fb_mode_t *best = fb_modes; | |
519 | 438 fb_mode_t *curr; |
439 | |
1561 | 440 if (verbose > 1) |
441 printf(FBDEV "Searching for first working mode\n"); | |
442 | |
950 | 443 for (i = 0; i < nr_modes; i++, best++) |
1561 | 444 if (mode_works(best, hfreq, vfreq, dotclock)) |
519 | 445 break; |
446 | |
950 | 447 if (i == nr_modes) |
519 | 448 return NULL; |
950 | 449 if (i == nr_modes - 1) |
519 | 450 return best; |
393 | 451 |
1561 | 452 if (verbose > 1) { |
453 printf(FBDEV "First working mode: %dx%d\n", best->xres, best->yres); | |
454 printf(FBDEV "Searching for better modes\n"); | |
455 } | |
950 | 456 |
1561 | 457 for (curr = best + 1; i < nr_modes - 1; i++, curr++) { |
458 if (!mode_works(curr, hfreq, vfreq, dotclock)) | |
519 | 459 continue; |
1561 | 460 |
519 | 461 if (verbose > 1) |
1561 | 462 printf(FBDEV); |
463 | |
464 if (best->xres < xres || best->yres < yres) { | |
465 if (curr->xres > best->xres || curr->yres > best->yres) { | |
519 | 466 if (verbose > 1) |
1561 | 467 printf("better than %dx%d, which is too small.\n", |
519 | 468 best->xres, best->yres); |
393 | 469 best = curr; |
519 | 470 } else if (verbose > 1) |
1561 | 471 printf("too small.\n"); |
472 } else if (curr->xres == best->xres && curr->yres == best->yres && | |
473 vsf(curr) > vsf(best)) { | |
474 if (verbose > 1) | |
475 printf("faster screen refresh.\n"); | |
476 best = curr; | |
477 } else if ((curr->xres <= best->xres && curr->yres <= best->yres) && | |
478 (curr->xres >= xres && curr->yres >= yres)) { | |
479 if (verbose > 1) | |
480 printf("better than %dx%d, which is too large.\n", | |
481 best->xres, best->yres); | |
482 best = curr; | |
483 } else if (verbose > 1) { | |
484 if (curr->xres < xres || curr->yres < yres) | |
485 printf("too small.\n"); | |
486 else if (curr->xres > best->xres || curr->yres > best->yres) | |
487 printf("too large.\n"); | |
488 else printf("it's worse, don't know why.\n"); | |
489 } | |
393 | 490 } |
1561 | 491 |
393 | 492 return best; |
493 } | |
494 | |
418 | 495 static void set_bpp(struct fb_var_screeninfo *p, int bpp) |
496 { | |
476 | 497 p->bits_per_pixel = (bpp + 1) & ~1; |
1087 | 498 p->red.msb_right = p->green.msb_right = p->blue.msb_right = p->transp.msb_right = 0; |
563 | 499 p->transp.offset = p->transp.length = 0; |
950 | 500 p->blue.offset = 0; |
418 | 501 switch (bpp) { |
502 case 32: | |
563 | 503 p->transp.offset = 24; |
504 p->transp.length = 8; | |
418 | 505 case 24: |
506 p->red.offset = 16; | |
507 p->red.length = 8; | |
508 p->green.offset = 8; | |
509 p->green.length = 8; | |
550 | 510 p->blue.length = 8; |
418 | 511 break; |
512 case 16: | |
513 p->red.offset = 11; | |
550 | 514 p->green.length = 6; |
418 | 515 p->red.length = 5; |
516 p->green.offset = 5; | |
550 | 517 p->blue.length = 5; |
418 | 518 break; |
519 case 15: | |
520 p->red.offset = 10; | |
550 | 521 p->green.length = 5; |
418 | 522 p->red.length = 5; |
523 p->green.offset = 5; | |
550 | 524 p->blue.length = 5; |
418 | 525 break; |
526 } | |
527 } | |
528 | |
529 static void fb_mode2fb_vinfo(fb_mode_t *m, struct fb_var_screeninfo *v) | |
530 { | |
531 v->xres = m->xres; | |
532 v->yres = m->yres; | |
533 v->xres_virtual = m->vxres; | |
534 v->yres_virtual = m->vyres; | |
535 set_bpp(v, m->depth); | |
536 v->pixclock = m->pixclock; | |
537 v->left_margin = m->left; | |
538 v->right_margin = m->right; | |
539 v->upper_margin = m->upper; | |
540 v->lower_margin = m->lower; | |
541 v->hsync_len = m->hslen; | |
542 v->vsync_len = m->vslen; | |
543 v->sync = m->sync; | |
544 v->vmode = m->vmode; | |
545 } | |
546 | |
547 static range_t *str2range(char *s) | |
548 { | |
549 float tmp_min, tmp_max; | |
550 char *endptr = s; // to start the loop | |
551 range_t *r = NULL; | |
950 | 552 int i; |
418 | 553 |
554 if (!s) | |
555 return NULL; | |
556 for (i = 0; *endptr; i++) { | |
557 if (*s == ',') | |
558 goto out_err; | |
538 | 559 if (!(r = (range_t *) realloc(r, sizeof(*r) * (i + 2)))) { |
418 | 560 printf("can't realloc 'r'\n"); |
561 return NULL; | |
562 } | |
563 tmp_min = strtod(s, &endptr); | |
564 if (*endptr == 'k' || *endptr == 'K') { | |
565 tmp_min *= 1000.0; | |
566 endptr++; | |
567 } else if (*endptr == 'm' || *endptr == 'M') { | |
568 tmp_min *= 1000000.0; | |
569 endptr++; | |
570 } | |
571 if (*endptr == '-') { | |
572 tmp_max = strtod(endptr + 1, &endptr); | |
573 if (*endptr == 'k' || *endptr == 'K') { | |
574 tmp_max *= 1000.0; | |
575 endptr++; | |
576 } else if (*endptr == 'm' || *endptr == 'M') { | |
577 tmp_max *= 1000000.0; | |
578 endptr++; | |
579 } | |
580 if (*endptr != ',' && *endptr) | |
581 goto out_err; | |
582 } else if (*endptr == ',' || !*endptr) { | |
583 tmp_max = tmp_min; | |
584 } else | |
585 goto out_err; | |
586 r[i].min = tmp_min; | |
587 r[i].max = tmp_max; | |
950 | 588 if (r[i].min < 0 || r[i].max < 0) |
589 goto out_err; | |
418 | 590 s = endptr + 1; |
591 } | |
592 r[i].min = r[i].max = -1; | |
593 return r; | |
594 out_err: | |
595 if (r) | |
596 free(r); | |
597 return NULL; | |
598 } | |
599 | |
359 | 600 /****************************** |
601 * vo_fbdev * | |
602 ******************************/ | |
603 | |
658 | 604 /* command line/config file options */ |
393 | 605 char *fb_dev_name = NULL; |
606 char *fb_mode_cfgfile = "/etc/fb.modes"; | |
607 char *fb_mode_name = NULL; | |
418 | 608 char *monitor_hfreq_str = NULL; |
609 char *monitor_vfreq_str = NULL; | |
610 char *monitor_dotclock_str = NULL; | |
611 | |
658 | 612 /* fb.modes related variables */ |
1087 | 613 static range_t *monitor_hfreq = NULL; |
614 static range_t *monitor_vfreq = NULL; | |
615 static range_t *monitor_dotclock = NULL; | |
658 | 616 static fb_mode_t *fb_mode = NULL; |
393 | 617 |
950 | 618 /* vt related variables */ |
1087 | 619 static int vt_fd; |
620 static FILE *vt_fp; | |
621 static int vt_doit = 1; | |
950 | 622 |
658 | 623 /* vo_fbdev related variables */ |
225 | 624 static int fb_dev_fd; |
625 static size_t fb_size; | |
626 static uint8_t *frame_buffer; | |
658 | 627 static uint8_t *L123123875; /* thx .so :) */ |
359 | 628 static struct fb_fix_screeninfo fb_finfo; |
629 static struct fb_var_screeninfo fb_orig_vinfo; | |
630 static struct fb_var_screeninfo fb_vinfo; | |
481 | 631 static struct fb_cmap fb_oldcmap; |
632 static int fb_cmap_changed = 0; | |
359 | 633 static int fb_pixel_size; // 32: 4 24: 3 16: 2 15: 2 |
634 static int fb_real_bpp; // 32: 24 24: 24 16: 16 15: 15 | |
635 static int fb_bpp; // 32: 32 24: 24 16: 16 15: 15 | |
393 | 636 static int fb_bpp_we_want; // 32: 32 24: 24 16: 16 15: 15 |
950 | 637 static int fb_line_len; |
638 static int fb_xres; | |
639 static int fb_yres; | |
658 | 640 static void (*draw_alpha_p)(int w, int h, unsigned char *src, |
641 unsigned char *srca, int stride, unsigned char *dst, | |
642 int dstride); | |
359 | 643 |
644 static uint8_t *next_frame; | |
225 | 645 static int in_width; |
646 static int in_height; | |
647 static int out_width; | |
648 static int out_height; | |
950 | 649 static int first_row; |
650 static int last_row; | |
225 | 651 static uint32_t pixel_format; |
804 | 652 static int fs; |
653 static int flip; | |
225 | 654 |
305 | 655 /* |
656 * Note: this function is completely cut'n'pasted from | |
657 * Chris Lawrence's code. | |
311 | 658 * (modified a bit to fit in my code...) |
305 | 659 */ |
660 struct fb_cmap *make_directcolor_cmap(struct fb_var_screeninfo *var) | |
661 { | |
662 /* Hopefully any DIRECTCOLOR device will have a big enough palette | |
663 * to handle mapping the full color depth. | |
664 * e.g. 8 bpp -> 256 entry palette | |
665 * | |
666 * We could handle some sort of gamma here | |
667 */ | |
668 int i, cols, rcols, gcols, bcols; | |
669 uint16_t *red, *green, *blue; | |
670 struct fb_cmap *cmap; | |
671 | |
672 rcols = 1 << var->red.length; | |
673 gcols = 1 << var->green.length; | |
674 bcols = 1 << var->blue.length; | |
675 | |
676 /* Make our palette the length of the deepest color */ | |
677 cols = (rcols > gcols ? rcols : gcols); | |
678 cols = (cols > bcols ? cols : bcols); | |
679 | |
680 red = malloc(cols * sizeof(red[0])); | |
681 if(!red) { | |
682 printf("Can't allocate red palette with %d entries.\n", cols); | |
683 return NULL; | |
684 } | |
685 for(i=0; i< rcols; i++) | |
686 red[i] = (65535/(rcols-1)) * i; | |
687 | |
688 green = malloc(cols * sizeof(green[0])); | |
689 if(!green) { | |
690 printf("Can't allocate green palette with %d entries.\n", cols); | |
691 free(red); | |
692 return NULL; | |
693 } | |
694 for(i=0; i< gcols; i++) | |
695 green[i] = (65535/(gcols-1)) * i; | |
696 | |
697 blue = malloc(cols * sizeof(blue[0])); | |
698 if(!blue) { | |
699 printf("Can't allocate blue palette with %d entries.\n", cols); | |
700 free(red); | |
701 free(green); | |
702 return NULL; | |
703 } | |
704 for(i=0; i< bcols; i++) | |
705 blue[i] = (65535/(bcols-1)) * i; | |
706 | |
707 cmap = malloc(sizeof(struct fb_cmap)); | |
708 if(!cmap) { | |
709 printf("Can't allocate color map\n"); | |
710 free(red); | |
711 free(green); | |
712 free(blue); | |
713 return NULL; | |
714 } | |
715 cmap->start = 0; | |
716 cmap->transp = 0; | |
717 cmap->len = cols; | |
718 cmap->red = red; | |
719 cmap->blue = blue; | |
720 cmap->green = green; | |
721 cmap->transp = NULL; | |
722 | |
723 return cmap; | |
724 } | |
225 | 725 |
393 | 726 static int fb_preinit(void) |
225 | 727 { |
950 | 728 static int fb_preinit_done = 0; |
729 static int fb_works = 0; | |
730 | |
731 if (fb_preinit_done) | |
732 return fb_works; | |
733 | |
393 | 734 if (!fb_dev_name && !(fb_dev_name = getenv("FRAMEBUFFER"))) |
735 fb_dev_name = "/dev/fb0"; | |
736 if (verbose > 0) | |
737 printf(FBDEV "using %s\n", fb_dev_name); | |
225 | 738 |
393 | 739 if ((fb_dev_fd = open(fb_dev_name, O_RDWR)) == -1) { |
740 printf(FBDEV "Can't open %s: %s\n", fb_dev_name, strerror(errno)); | |
741 goto err_out; | |
742 } | |
743 if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo)) { | |
744 printf(FBDEV "Can't get VSCREENINFO: %s\n", strerror(errno)); | |
745 goto err_out_fd; | |
746 } | |
418 | 747 fb_orig_vinfo = fb_vinfo; |
393 | 748 |
663 | 749 fb_bpp = fb_vinfo.bits_per_pixel; |
750 | |
1076 | 751 if (fb_bpp == 8 && !vo_dbpp) { |
752 printf(FBDEV "8 bpp output is not supported.\n"); | |
753 goto err_out_fd; | |
754 } | |
755 | |
1561 | 756 /* 16 and 15 bpp is reported as 16 bpp */ |
663 | 757 if (fb_bpp == 16) |
758 fb_bpp = fb_vinfo.red.length + fb_vinfo.green.length + | |
759 fb_vinfo.blue.length; | |
760 | |
418 | 761 if (vo_dbpp) { |
762 if (vo_dbpp != 15 && vo_dbpp != 16 && vo_dbpp != 24 && | |
763 vo_dbpp != 32) { | |
764 printf(FBDEV "can't switch to %d bpp\n", vo_dbpp); | |
1076 | 765 goto err_out_fd; |
359 | 766 } |
418 | 767 fb_bpp = vo_dbpp; |
359 | 768 } |
245
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
769 |
393 | 770 fb_preinit_done = 1; |
771 fb_works = 1; | |
950 | 772 return 1; |
393 | 773 err_out_fd: |
774 close(fb_dev_fd); | |
775 fb_dev_fd = -1; | |
776 err_out: | |
777 fb_preinit_done = 1; | |
950 | 778 fb_works = 0; |
779 return 0; | |
393 | 780 } |
245
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
781 |
633 | 782 static void lots_of_printf(void) |
783 { | |
784 if (verbose > 0) { | |
785 printf(FBDEV "var info:\n"); | |
786 printf(FBDEV "xres: %u\n", fb_vinfo.xres); | |
787 printf(FBDEV "yres: %u\n", fb_vinfo.yres); | |
788 printf(FBDEV "xres_virtual: %u\n", fb_vinfo.xres_virtual); | |
789 printf(FBDEV "yres_virtual: %u\n", fb_vinfo.yres_virtual); | |
790 printf(FBDEV "xoffset: %u\n", fb_vinfo.xoffset); | |
791 printf(FBDEV "yoffset: %u\n", fb_vinfo.yoffset); | |
792 printf(FBDEV "bits_per_pixel: %u\n", fb_vinfo.bits_per_pixel); | |
793 printf(FBDEV "grayscale: %u\n", fb_vinfo.grayscale); | |
794 printf(FBDEV "red: %lu %lu %lu\n", | |
795 (unsigned long) fb_vinfo.red.offset, | |
796 (unsigned long) fb_vinfo.red.length, | |
797 (unsigned long) fb_vinfo.red.msb_right); | |
798 printf(FBDEV "green: %lu %lu %lu\n", | |
799 (unsigned long) fb_vinfo.green.offset, | |
800 (unsigned long) fb_vinfo.green.length, | |
801 (unsigned long) fb_vinfo.green.msb_right); | |
802 printf(FBDEV "blue: %lu %lu %lu\n", | |
803 (unsigned long) fb_vinfo.blue.offset, | |
804 (unsigned long) fb_vinfo.blue.length, | |
805 (unsigned long) fb_vinfo.blue.msb_right); | |
806 printf(FBDEV "transp: %lu %lu %lu\n", | |
807 (unsigned long) fb_vinfo.transp.offset, | |
808 (unsigned long) fb_vinfo.transp.length, | |
809 (unsigned long) fb_vinfo.transp.msb_right); | |
810 printf(FBDEV "nonstd: %u\n", fb_vinfo.nonstd); | |
811 if (verbose > 1) { | |
812 printf(FBDEV "activate: %u\n", fb_vinfo.activate); | |
813 printf(FBDEV "height: %u\n", fb_vinfo.height); | |
814 printf(FBDEV "width: %u\n", fb_vinfo.width); | |
815 printf(FBDEV "accel_flags: %u\n", fb_vinfo.accel_flags); | |
816 printf(FBDEV "timing:\n"); | |
817 printf(FBDEV "pixclock: %u\n", fb_vinfo.pixclock); | |
818 printf(FBDEV "left_margin: %u\n", fb_vinfo.left_margin); | |
819 printf(FBDEV "right_margin: %u\n", fb_vinfo.right_margin); | |
820 printf(FBDEV "upper_margin: %u\n", fb_vinfo.upper_margin); | |
821 printf(FBDEV "lower_margin: %u\n", fb_vinfo.lower_margin); | |
822 printf(FBDEV "hsync_len: %u\n", fb_vinfo.hsync_len); | |
823 printf(FBDEV "vsync_len: %u\n", fb_vinfo.vsync_len); | |
824 printf(FBDEV "sync: %u\n", fb_vinfo.sync); | |
825 printf(FBDEV "vmode: %u\n", fb_vinfo.vmode); | |
826 } | |
827 printf(FBDEV "fix info:\n"); | |
828 printf(FBDEV "framebuffer size: %d bytes\n", fb_finfo.smem_len); | |
829 printf(FBDEV "type: %lu\n", (unsigned long) fb_finfo.type); | |
830 printf(FBDEV "type_aux: %lu\n", (unsigned long) fb_finfo.type_aux); | |
831 printf(FBDEV "visual: %lu\n", (unsigned long) fb_finfo.visual); | |
832 printf(FBDEV "line_length: %lu bytes\n", (unsigned long) fb_finfo.line_length); | |
833 if (verbose > 1) { | |
834 printf(FBDEV "id: %.16s\n", fb_finfo.id); | |
835 printf(FBDEV "smem_start: %p\n", (void *) fb_finfo.smem_start); | |
836 printf(FBDEV "xpanstep: %u\n", fb_finfo.xpanstep); | |
837 printf(FBDEV "ypanstep: %u\n", fb_finfo.ypanstep); | |
838 printf(FBDEV "ywrapstep: %u\n", fb_finfo.ywrapstep); | |
839 printf(FBDEV "mmio_start: %p\n", (void *) fb_finfo.mmio_start); | |
840 printf(FBDEV "mmio_len: %u bytes\n", fb_finfo.mmio_len); | |
841 printf(FBDEV "accel: %u\n", fb_finfo.accel); | |
842 } | |
950 | 843 printf(FBDEV "fb_bpp: %d\n", fb_bpp); |
844 printf(FBDEV "fb_real_bpp: %d\n", fb_real_bpp); | |
845 printf(FBDEV "fb_pixel_size: %d bytes\n", fb_pixel_size); | |
846 printf(FBDEV "other:\n"); | |
847 printf(FBDEV "in_width: %d\n", in_width); | |
848 printf(FBDEV "in_height: %d\n", in_height); | |
849 printf(FBDEV "out_width: %d\n", out_width); | |
850 printf(FBDEV "out_height: %d\n", out_height); | |
851 printf(FBDEV "first_row: %d\n", first_row); | |
852 printf(FBDEV "last_row: %d\n", last_row); | |
853 if (verbose > 1) | |
854 printf(FBDEV "draw_alpha_p:%dbpp = %p\n", fb_bpp, draw_alpha_p); | |
633 | 855 } |
856 } | |
658 | 857 |
950 | 858 static void vt_set_textarea(int u, int l) |
859 { | |
860 /* how can I determine the font height? | |
861 * just use 16 for now | |
862 */ | |
863 int urow = ((u + 15) / 16) + 1; | |
864 int lrow = l / 16; | |
865 | |
866 if (verbose > 1) | |
867 printf(FBDEV "vt_set_textarea(%d,%d): %d,%d\n", u, l, urow, lrow); | |
868 fprintf(vt_fp, "\33[%d;%dr\33[%d;%dH", urow, lrow, lrow, 0); | |
869 fflush(vt_fp); | |
870 } | |
871 | |
393 | 872 static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, |
873 uint32_t d_height, uint32_t fullscreen, char *title, | |
874 uint32_t format) | |
875 { | |
950 | 876 struct fb_cmap *cmap; |
877 int vm = fullscreen & 0x02; | |
878 int zoom = fullscreen & 0x04; | |
418 | 879 |
950 | 880 fs = fullscreen & 0x01; |
881 flip = fullscreen & 0x08; | |
393 | 882 |
950 | 883 if (!fb_preinit()) |
393 | 884 return 1; |
245
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
885 |
950 | 886 if (zoom) { |
418 | 887 printf(FBDEV "-zoom is not supported\n"); |
888 return 1; | |
889 } | |
950 | 890 if (fb_mode_name && !vm) { |
891 printf(FBDEV "-fbmode can only be used with -vm\n"); | |
418 | 892 return 1; |
893 } | |
950 | 894 if (vm && (parse_fbmode_cfg(fb_mode_cfgfile) < 0)) |
418 | 895 return 1; |
950 | 896 if (d_width && (fs || vm)) { |
418 | 897 out_width = d_width; |
898 out_height = d_height; | |
899 } else { | |
900 out_width = width; | |
901 out_height = height; | |
902 } | |
903 in_width = width; | |
904 in_height = height; | |
905 pixel_format = format; | |
906 | |
393 | 907 if (fb_mode_name) { |
418 | 908 if (!(fb_mode = find_mode_by_name(fb_mode_name))) { |
909 printf(FBDEV "can't find requested video mode\n"); | |
910 return 1; | |
911 } | |
912 fb_mode2fb_vinfo(fb_mode, &fb_vinfo); | |
950 | 913 } else if (vm) { |
418 | 914 monitor_hfreq = str2range(monitor_hfreq_str); |
915 monitor_vfreq = str2range(monitor_vfreq_str); | |
916 monitor_dotclock = str2range(monitor_dotclock_str); | |
917 if (!monitor_hfreq || !monitor_vfreq || !monitor_dotclock) { | |
918 printf(FBDEV "you have to specify the capabilities of" | |
919 " the monitor.\n"); | |
920 return 1; | |
921 } | |
922 if (!(fb_mode = find_best_mode(out_width, out_height, | |
923 monitor_hfreq, monitor_vfreq, | |
924 monitor_dotclock))) { | |
925 printf(FBDEV "can't find best video mode\n"); | |
926 return 1; | |
927 } | |
519 | 928 printf(FBDEV "using mode %dx%d @ %.1fHz\n", fb_mode->xres, |
929 fb_mode->yres, vsf(fb_mode)); | |
418 | 930 fb_mode2fb_vinfo(fb_mode, &fb_vinfo); |
359 | 931 } |
418 | 932 fb_bpp_we_want = fb_bpp; |
933 set_bpp(&fb_vinfo, fb_bpp); | |
359 | 934 fb_vinfo.xres_virtual = fb_vinfo.xres; |
935 fb_vinfo.yres_virtual = fb_vinfo.yres; | |
245
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
936 |
359 | 937 if (ioctl(fb_dev_fd, FBIOPUT_VSCREENINFO, &fb_vinfo)) { |
393 | 938 printf(FBDEV "Can't put VSCREENINFO: %s\n", strerror(errno)); |
939 return 1; | |
940 } | |
950 | 941 |
942 fb_pixel_size = fb_vinfo.bits_per_pixel / 8; | |
943 fb_real_bpp = fb_vinfo.red.length + fb_vinfo.green.length + | |
944 fb_vinfo.blue.length; | |
945 fb_bpp = (fb_pixel_size == 4) ? 32 : fb_real_bpp; | |
946 if (fb_bpp_we_want != fb_bpp) | |
1076 | 947 printf(FBDEV "requested %d bpp, got %d bpp!!!\n", |
950 | 948 fb_bpp_we_want, fb_bpp); |
949 | |
950 switch (fb_bpp) { | |
951 case 32: | |
952 draw_alpha_p = vo_draw_alpha_rgb32; | |
953 break; | |
954 case 24: | |
955 draw_alpha_p = vo_draw_alpha_rgb24; | |
956 break; | |
957 case 16: | |
958 draw_alpha_p = vo_draw_alpha_rgb16; | |
959 break; | |
960 case 15: | |
961 draw_alpha_p = vo_draw_alpha_rgb15; | |
962 break; | |
963 } | |
964 | |
965 if (flip & ((((pixel_format & 0xff) + 7) / 8) != fb_pixel_size)) { | |
966 printf(FBDEV "Flipped output with depth conversion is not " | |
967 "supported\n"); | |
968 return 1; | |
969 } | |
970 | |
971 fb_xres = fb_vinfo.xres; | |
972 fb_yres = fb_vinfo.yres; | |
973 | |
974 if (vm || fs) { | |
975 out_width = fb_xres; | |
976 out_height = fb_yres; | |
977 } | |
978 if (out_width < in_width || out_height < in_height) { | |
979 printf(FBDEV "screensize is smaller than video size\n"); | |
980 return 1; | |
981 } | |
982 | |
983 first_row = (out_height - in_height) / 2; | |
984 last_row = (out_height + in_height) / 2; | |
985 | |
618 | 986 if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo)) { |
987 printf(FBDEV "Can't get FSCREENINFO: %s\n", strerror(errno)); | |
988 return 1; | |
989 } | |
633 | 990 |
991 lots_of_printf(); | |
245
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
992 |
633 | 993 if (fb_finfo.type != FB_TYPE_PACKED_PIXELS) { |
994 printf(FBDEV "type %d not supported\n", fb_finfo.type); | |
995 return 1; | |
305 | 996 } |
618 | 997 |
379 | 998 switch (fb_finfo.visual) { |
393 | 999 case FB_VISUAL_TRUECOLOR: |
1000 break; | |
1001 case FB_VISUAL_DIRECTCOLOR: | |
1002 if (verbose > 0) | |
1003 printf(FBDEV "creating cmap for directcolor\n"); | |
481 | 1004 if (ioctl(fb_dev_fd, FBIOGETCMAP, &fb_oldcmap)) { |
393 | 1005 printf(FBDEV "can't get cmap: %s\n", |
1006 strerror(errno)); | |
1007 return 1; | |
1008 } | |
1009 if (!(cmap = make_directcolor_cmap(&fb_vinfo))) | |
1010 return 1; | |
1011 if (ioctl(fb_dev_fd, FBIOPUTCMAP, cmap)) { | |
1012 printf(FBDEV "can't put cmap: %s\n", | |
1013 strerror(errno)); | |
1014 return 1; | |
1015 } | |
481 | 1016 fb_cmap_changed = 1; |
393 | 1017 free(cmap->red); |
1018 free(cmap->green); | |
1019 free(cmap->blue); | |
1020 free(cmap); | |
1021 break; | |
1022 default: | |
1023 printf(FBDEV "visual: %d not yet supported\n", | |
1024 fb_finfo.visual); | |
1025 return 1; | |
245
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
1026 } |
618 | 1027 |
950 | 1028 fb_line_len = fb_finfo.line_length; |
359 | 1029 fb_size = fb_finfo.smem_len; |
225 | 1030 if ((frame_buffer = (uint8_t *) mmap(0, fb_size, PROT_READ | PROT_WRITE, |
1031 MAP_SHARED, fb_dev_fd, 0)) == (uint8_t *) -1) { | |
393 | 1032 printf(FBDEV "Can't mmap %s: %s\n", fb_dev_name, strerror(errno)); |
1033 return 1; | |
225 | 1034 } |
519 | 1035 L123123875 = frame_buffer + (out_width - in_width) * fb_pixel_size / |
950 | 1036 2 + (out_height - in_height) * fb_line_len / 2; |
229 | 1037 |
393 | 1038 if (verbose > 0) { |
519 | 1039 if (verbose > 1) { |
393 | 1040 printf(FBDEV "frame_buffer @ %p\n", frame_buffer); |
519 | 1041 printf(FBDEV "L123123875 @ %p\n", L123123875); |
1042 } | |
950 | 1043 printf(FBDEV "pixel per line: %d\n", fb_line_len / fb_pixel_size); |
379 | 1044 } |
225 | 1045 |
278 | 1046 if (!(next_frame = (uint8_t *) malloc(in_width * in_height * fb_pixel_size))) { |
393 | 1047 printf(FBDEV "Can't malloc next_frame: %s\n", strerror(errno)); |
225 | 1048 return 1; |
1049 } | |
1050 | |
950 | 1051 if (vt_doit && (vt_fd = open("/dev/tty", O_WRONLY)) == -1) { |
1052 printf(FBDEV "can't open /dev/tty: %s\n", strerror(errno)); | |
1053 vt_doit = 0; | |
1054 } | |
1055 if (vt_doit && !(vt_fp = fdopen(vt_fd, "w"))) { | |
1056 printf(FBDEV "can't fdopen /dev/tty: %s\n", strerror(errno)); | |
1057 vt_doit = 0; | |
804 | 1058 } |
950 | 1059 |
1060 if (vt_doit) | |
1061 vt_set_textarea(last_row, fb_yres); | |
1062 | |
1063 if (fs || vm) | |
1064 memset(frame_buffer, '\0', fb_line_len * fb_yres); | |
1065 | |
225 | 1066 if (format == IMGFMT_YV12) |
359 | 1067 yuv2rgb_init(fb_bpp, MODE_RGB); |
950 | 1068 |
225 | 1069 return 0; |
1070 } | |
1071 | |
1072 static uint32_t query_format(uint32_t format) | |
1073 { | |
658 | 1074 int ret = 0x4; /* osd/sub is supported on every bpp */ |
519 | 1075 |
950 | 1076 if (!fb_preinit()) |
305 | 1077 return 0; |
1078 | |
311 | 1079 if ((format & IMGFMT_BGR_MASK) == IMGFMT_BGR) { |
1080 int bpp = format & 0xff; | |
519 | 1081 |
359 | 1082 if (bpp == fb_bpp) |
519 | 1083 return ret|0x2; |
359 | 1084 else if (bpp == 15 && fb_bpp == 16) |
519 | 1085 return ret|0x1; |
359 | 1086 else if (bpp == 24 && fb_bpp == 32) |
519 | 1087 return ret|0x1; |
311 | 1088 } |
1089 if (format == IMGFMT_YV12) | |
658 | 1090 return ret|0x1; |
311 | 1091 return 0; |
225 | 1092 } |
1093 | |
1094 static const vo_info_t *get_info(void) | |
1095 { | |
1096 return &vo_info; | |
1097 } | |
1098 | |
1099 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, | |
1100 unsigned char *srca, int stride) | |
1101 { | |
658 | 1102 unsigned char *dst = next_frame + (in_width * y0 + x0) * fb_pixel_size; |
359 | 1103 int dstride = in_width * fb_pixel_size; |
1104 | |
658 | 1105 (*draw_alpha_p)(w, h, src, srca, stride, dst, dstride); |
225 | 1106 } |
1107 | |
1108 static uint32_t draw_frame(uint8_t *src[]) | |
1109 { | |
1110 if (pixel_format == IMGFMT_YV12) { | |
1111 yuv2rgb(next_frame, src[0], src[1], src[2], in_width, | |
278 | 1112 in_height, in_width * fb_pixel_size, |
225 | 1113 in_width, in_width / 2); |
804 | 1114 } else if (flip) { |
1115 int h = in_height; | |
1116 int len = in_width * fb_pixel_size; | |
1117 char *d = next_frame + (in_height - 1) * len; | |
1118 char *s = src[0]; | |
1119 while (h--) { | |
1120 memcpy(d, s, len); | |
1121 s += len; | |
1122 d -= len; | |
1123 } | |
311 | 1124 } else { |
1125 int sbpp = ((pixel_format & 0xff) + 7) / 8; | |
1126 char *d = next_frame; | |
1127 char *s = src[0]; | |
1128 if (sbpp == fb_pixel_size) { | |
359 | 1129 if (fb_real_bpp == 16 && pixel_format == (IMGFMT_BGR|15)) { |
311 | 1130 #ifdef HAVE_MMX |
1131 rgb15to16_mmx(s, d, 2 * in_width * in_height); | |
1132 #else | |
1133 unsigned short *s1 = (unsigned short *) s; | |
1134 unsigned short *d1 = (unsigned short *) d; | |
1135 unsigned short *e = s1 + in_width * in_height; | |
1136 while (s1<e) { | |
1137 register x = *(s1++); | |
1138 *(d1++) = (x&0x001f)|((x&0x7fe0)<<1); | |
1139 } | |
1140 #endif | |
1141 } else | |
1142 memcpy(d, s, sbpp * in_width * in_height); | |
1143 } | |
1144 } | |
225 | 1145 return 0; |
1146 } | |
1147 | |
1148 static uint32_t draw_slice(uint8_t *src[], int stride[], int w, int h, int x, | |
1149 int y) | |
1150 { | |
1151 uint8_t *dest; | |
1152 | |
278 | 1153 dest = next_frame + (in_width * y + x) * fb_pixel_size; |
1154 yuv2rgb(dest, src[0], src[1], src[2], w, h, in_width * fb_pixel_size, | |
225 | 1155 stride[0], stride[1]); |
1156 return 0; | |
1157 } | |
1158 | |
1159 static void check_events(void) | |
1160 { | |
1161 } | |
1162 | |
519 | 1163 static void put_frame(void) |
225 | 1164 { |
1165 int i, out_offset = 0, in_offset = 0; | |
1166 | |
1167 for (i = 0; i < in_height; i++) { | |
519 | 1168 memcpy(L123123875 + out_offset, next_frame + in_offset, |
423 | 1169 in_width * fb_pixel_size); |
950 | 1170 out_offset += fb_line_len; |
278 | 1171 in_offset += in_width * fb_pixel_size; |
225 | 1172 } |
1173 } | |
1174 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1087
diff
changeset
|
1175 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1087
diff
changeset
|
1176 { |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1087
diff
changeset
|
1177 vo_draw_text(in_width, in_height, draw_alpha); |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1087
diff
changeset
|
1178 } |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1087
diff
changeset
|
1179 |
246 | 1180 static void flip_page(void) |
1181 { | |
519 | 1182 put_frame(); |
246 | 1183 } |
1184 | |
225 | 1185 static void uninit(void) |
1186 { | |
379 | 1187 if (verbose > 0) |
393 | 1188 printf(FBDEV "uninit\n"); |
481 | 1189 if (fb_cmap_changed) { |
1190 if (ioctl(fb_dev_fd, FBIOPUTCMAP, &fb_oldcmap)) | |
393 | 1191 printf(FBDEV "Can't restore original cmap\n"); |
481 | 1192 fb_cmap_changed = 0; |
306 | 1193 } |
503 | 1194 free(next_frame); |
1195 if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo)) | |
1196 printf(FBDEV "ioctl FBIOGET_VSCREENINFO: %s\n", strerror(errno)); | |
1197 fb_orig_vinfo.xoffset = fb_vinfo.xoffset; | |
1198 fb_orig_vinfo.yoffset = fb_vinfo.yoffset; | |
379 | 1199 if (ioctl(fb_dev_fd, FBIOPUT_VSCREENINFO, &fb_orig_vinfo)) |
503 | 1200 printf(FBDEV "Can't reset original fb_var_screeninfo: %s\n", strerror(errno)); |
950 | 1201 if (vt_doit) |
1202 vt_set_textarea(0, fb_orig_vinfo.yres); | |
359 | 1203 close(fb_dev_fd); |
225 | 1204 munmap(frame_buffer, fb_size); |
1205 } |