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