Mercurial > mplayer.hg
annotate libvo/vo_fbdev.c @ 245:cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
author | szabii |
---|---|
date | Thu, 29 Mar 2001 13:58:54 +0000 |
parents | 0e430b433f63 |
children | 5673f9146c54 |
rev | line source |
---|---|
225 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <fcntl.h> | |
5 #include <unistd.h> | |
6 #include <errno.h> | |
7 | |
8 #include <sys/mman.h> | |
9 #include <sys/ioctl.h> | |
10 #include <linux/fb.h> | |
11 #include <linux/vt.h> | |
12 | |
13 #include "config.h" | |
14 #include "video_out.h" | |
15 #include "video_out_internal.h" | |
16 | |
17 #include "yuv2rgb.h" | |
18 | |
19 LIBVO_EXTERN(fbdev) | |
20 | |
21 //#include "yuv2rgb.h" | |
22 | |
23 static vo_info_t vo_info = { | |
24 "Framebuffer Device", | |
25 "fbdev", | |
26 "Szabolcs Berecz <szabi@inf.elte.hu>", | |
27 "" | |
28 }; | |
29 | |
230 | 30 static int vt_active = -1; |
225 | 31 static int vt_fd; |
32 | |
33 char *fb_dev_name = NULL; | |
34 static int fb_dev_fd; | |
35 static size_t fb_size; | |
36 static uint8_t *frame_buffer; | |
37 static int fb_bpp; | |
229 | 38 struct fb_fix_screeninfo fb_fix_info; |
39 struct fb_var_screeninfo fb_var_info; | |
225 | 40 |
41 static int in_width; | |
42 static int in_height; | |
43 static int out_width; | |
44 static int out_height; | |
45 static uint8_t *next_frame; | |
46 static int screen_width; | |
47 static uint32_t pixel_format; | |
48 | |
229 | 49 static int fb_init_done = 0; |
225 | 50 |
229 | 51 static int fb_init(void) |
225 | 52 { |
53 int fd, vt; | |
54 char vt_name[11]; | |
55 struct vt_stat vt_state; | |
56 struct vt_mode vt_mode; | |
57 | |
229 | 58 #if 0 |
225 | 59 /* get a free vt */ |
60 if ((fd = open("/dev/tty0", O_WRONLY, 0)) == -1) { | |
61 printf("Can't open /dev/tty0: %s\n", strerror(errno)); | |
62 return 1; | |
63 } | |
64 if (ioctl(fd, VT_OPENQRY, &vt) < 0 || vt == -1) { | |
65 printf("Can't open a free VT: %s\n", strerror(errno)); | |
66 return 1; | |
67 } | |
68 close(fd); | |
229 | 69 #endif |
70 #if 0 | |
225 | 71 /* open the vt */ |
72 snprintf(vt_name, 10, "/dev/tty%d", vt); | |
73 if ((vt_fd = open(vt_name, O_RDWR | O_NONBLOCK, 0)) == -1) { | |
74 printf("Can't open %s: %s\n", vt_name, strerror(errno)); | |
75 return 1; | |
76 } | |
77 | |
78 /* save the current vtnum */ | |
79 if (!ioctl(vt_fd, VT_GETSTATE, &vt_state)) | |
80 vt_active = vt_state.v_active; | |
81 | |
82 /* detach the controlling tty */ | |
83 if ((fd = open("/dev/tty", O_RDWR)) >= 0) { | |
84 ioctl(fd, TIOCNOTTY, 0); | |
85 close(fd); | |
86 } | |
229 | 87 #endif |
225 | 88 #if 0 |
89 /* switch to the new vt */ | |
90 if (ioctl(vt_fd, VT_ACTIVATE, vt_active)) | |
91 printf("ioctl VT_ACTIVATE: %s\n", strerror(errno)); | |
92 if (ioctl(vt_fd, VT_WAITACTIVE, vt_active)) | |
93 printf("ioctl VT_WAITACTIVE: %s\n", strerror(errno)); | |
94 if (ioctl(vt_fd, VT_GETMODE, &vt_mode) < 0) { | |
95 printf("ioctl VT_GETMODE: %s\n", strerror(errno)); | |
96 return 1; | |
97 } | |
98 signal(SIGUSR1, vt_request); | |
99 vt_mode.mode = VT_PROCESS; | |
100 vt_mode.relsig = SIGUSR1; | |
101 vt_mode.acqsig = SIGUSR1; | |
102 if (ioctl(vt_fd, VT_SETMODE, &vt_mode) < 0) { | |
103 printf("ioctl VT_SETMODE: %s\n", strerror(errno)); | |
104 return 1; | |
105 } | |
106 #endif | |
107 if (!fb_dev_name && !(fb_dev_name = getenv("FRAMEBUFFER"))) | |
108 fb_dev_name = "/dev/fb0"; | |
229 | 109 printf("fb_init: using %s\n", fb_dev_name); |
245
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
110 |
225 | 111 if ((fb_dev_fd = open(fb_dev_name, O_RDWR)) == -1) { |
229 | 112 printf("fb_init: Can't open %s: %s\n", fb_dev_name, strerror(errno)); |
225 | 113 return 1; |
114 } | |
245
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
115 |
229 | 116 if (ioctl(fb_dev_fd, FBIOGET_VSCREENINFO, &fb_var_info)) { |
117 printf("fb_init: Can't get VSCREENINFO: %s\n", strerror(errno)); | |
225 | 118 return 1; |
119 } | |
245
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
120 |
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
121 /* disable scrolling */ |
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
122 fb_var_info.xres_virtual = fb_var_info.xres; |
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
123 fb_var_info.yres_virtual = fb_var_info.yres; |
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
124 |
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
125 if (ioctl(fb_dev_fd, FBIOPUT_VSCREENINFO, &fb_var_info)) { |
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
126 printf("fb_init: Can't put VSCREENINFO: %s\n", strerror(errno)); |
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
127 return 1; |
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
128 } |
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
129 |
229 | 130 if (ioctl(fb_dev_fd, FBIOGET_FSCREENINFO, &fb_fix_info)) { |
131 printf("fb_init: Can't get VSCREENINFO: %s\n", strerror(errno)); | |
225 | 132 return 1; |
133 } | |
229 | 134 switch (fb_fix_info.type) { |
225 | 135 case FB_TYPE_VGA_PLANES: |
229 | 136 printf("fb_init: FB_TYPE_VGA_PLANES not supported.\n"); |
225 | 137 return 1; |
138 break; | |
139 case FB_TYPE_PLANES: | |
229 | 140 printf("fb_init: FB_TYPE_PLANES not supported.\n"); |
225 | 141 return 1; |
142 break; | |
143 case FB_TYPE_INTERLEAVED_PLANES: | |
229 | 144 printf("fb_init: FB_TYPE_INTERLEAVED_PLANES not supported.\n"); |
225 | 145 return 1; |
146 break; | |
147 #ifdef FB_TYPE_TEXT | |
148 case FB_TYPE_TEXT: | |
229 | 149 printf("fb_init: FB_TYPE_TEXT not supported.\n"); |
225 | 150 return 1; |
151 break; | |
152 #endif | |
153 case FB_TYPE_PACKED_PIXELS: | |
154 /* OK */ | |
229 | 155 printf("fb_init: FB_TYPE_PACKED_PIXELS: OK\n"); |
225 | 156 break; |
157 default: | |
229 | 158 printf("fb_init: unknown FB_TYPE: %d\n", fb_fix_info.type); |
225 | 159 return 1; |
245
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
160 } |
cb4c682746c0
disabled scrollback buffer (virtual fb size set to real screen size)
szabii
parents:
231
diff
changeset
|
161 |
229 | 162 fb_bpp = fb_var_info.bits_per_pixel; |
163 screen_width = fb_fix_info.line_length; | |
164 fb_size = fb_fix_info.smem_len; | |
225 | 165 if ((frame_buffer = (uint8_t *) mmap(0, fb_size, PROT_READ | PROT_WRITE, |
166 MAP_SHARED, fb_dev_fd, 0)) == (uint8_t *) -1) { | |
229 | 167 printf("fb_init: Can't mmap %s: %s\n", fb_dev_name, strerror(errno)); |
225 | 168 return 1; |
169 } | |
170 close(fb_dev_fd); | |
229 | 171 |
172 printf("fb_init: framebuffer @ %p\n", frame_buffer); | |
173 printf("fb_init: framebuffer size: %d bytes\n", fb_size); | |
174 printf("fb_init: bpp: %d\n", fb_bpp); | |
175 printf("fb_init: pixel per line: %d\n", screen_width / (fb_bpp / 8)); | |
176 printf("fb_init: visual: %d\n", fb_fix_info.visual); | |
225 | 177 |
229 | 178 fb_init_done = 1; |
179 return 0; | |
180 } | |
181 | |
182 static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, | |
183 uint32_t d_height, uint32_t fullscreen, char *title, | |
184 uint32_t format) | |
185 { | |
186 if (!fb_init_done) | |
187 if (fb_init()) | |
188 return 1; | |
225 | 189 |
190 in_width = width; | |
191 in_height = height; | |
192 out_width = width; | |
193 out_height = height; | |
194 pixel_format = format; | |
195 if (!(next_frame = (uint8_t *) malloc(in_width * in_height * (fb_bpp / 8)))) { | |
196 printf("Can't malloc next_frame: %s\n", strerror(errno)); | |
197 return 1; | |
198 } | |
199 | |
200 if (format == IMGFMT_YV12) | |
201 yuv2rgb_init(fb_bpp, MODE_RGB); | |
202 return 0; | |
203 } | |
204 | |
205 static uint32_t query_format(uint32_t format) | |
206 { | |
229 | 207 if (!fb_init_done) |
208 if (fb_init()) | |
209 return 0; | |
210 printf("vo_fbdev: query_format(%#x): ", format); | |
230 | 211 // if (format & IMGFMT_BGR_MASK == IMGFMT_BGR) |
212 // goto not_supported; | |
225 | 213 switch (format) { |
214 case IMGFMT_YV12: | |
229 | 215 goto supported; |
225 | 216 case IMGFMT_RGB32: |
217 if (fb_bpp == 32) | |
229 | 218 goto supported; |
225 | 219 break; |
220 case IMGFMT_RGB24: | |
221 if (fb_bpp == 24) | |
229 | 222 goto supported; |
225 | 223 break; |
224 case IMGFMT_RGB16: | |
225 if (fb_bpp == 16) | |
229 | 226 goto supported; |
225 | 227 break; |
228 case IMGFMT_RGB15: | |
229 if (fb_bpp == 15) | |
229 | 230 goto supported; |
231 break; | |
232 case IMGFMT_BGR|32: | |
233 if (fb_bpp == 32) | |
234 goto supported; | |
235 break; | |
236 case IMGFMT_BGR|24: | |
237 if (fb_bpp == 24) | |
238 goto supported; | |
239 break; | |
240 case IMGFMT_BGR|16: | |
241 if (fb_bpp == 16) | |
242 goto supported; | |
243 break; | |
244 case IMGFMT_BGR|15: | |
245 if (fb_bpp == 15) | |
246 goto supported; | |
225 | 247 break; |
248 } | |
229 | 249 not_supported: |
250 printf("not_supported\n"); | |
225 | 251 return 0; |
229 | 252 supported: |
253 printf("supported\n"); | |
254 return 1; | |
225 | 255 } |
256 | |
257 static const vo_info_t *get_info(void) | |
258 { | |
259 return &vo_info; | |
260 } | |
261 | |
262 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, | |
263 unsigned char *srca, int stride) | |
264 { | |
265 int x, y; | |
266 uint8_t *dst; | |
267 | |
268 if (pixel_format == IMGFMT_YV12) { | |
269 for (y = 0; y < h; y++){ | |
270 dst = next_frame + (in_width * (y0 + y) + x0) * (fb_bpp / 8); | |
271 for (x = 0; x < w; x++) { | |
272 if (srca[x]) { | |
273 dst[0] = (dst[0]*(srca[x]^255)+src[x]*(srca[x]))>>8; | |
274 dst[1] = (dst[1]*(srca[x]^255)+src[x]*(srca[x]))>>8; | |
275 dst[2] = (dst[2]*(srca[x]^255)+src[x]*(srca[x]))>>8; | |
276 } | |
277 dst += fb_bpp / 8; | |
278 } | |
279 src += stride; | |
280 srca += stride; | |
281 } | |
282 } | |
283 } | |
284 | |
285 static uint32_t draw_frame(uint8_t *src[]) | |
286 { | |
287 if (pixel_format == IMGFMT_YV12) { | |
288 yuv2rgb(next_frame, src[0], src[1], src[2], in_width, | |
289 in_height, in_width * (fb_bpp / 8), | |
290 in_width, in_width / 2); | |
230 | 291 } else if ((pixel_format & IMGFMT_BGR_MASK) == IMGFMT_BGR) { |
231 | 292 memcpy(next_frame, src[0], in_width * in_height * (fb_bpp / 8)); |
230 | 293 } else if ((pixel_format & IMGFMT_RGB_MASK) == IMGFMT_RGB) { |
225 | 294 } |
295 return 0; | |
296 } | |
297 | |
298 static uint32_t draw_slice(uint8_t *src[], int stride[], int w, int h, int x, | |
299 int y) | |
300 { | |
301 uint8_t *dest; | |
302 | |
303 dest = next_frame + (in_width * y + x) * (fb_bpp / 8); | |
304 yuv2rgb(dest, src[0], src[1], src[2], w, h, in_width * (fb_bpp / 8), | |
305 stride[0], stride[1]); | |
306 return 0; | |
307 } | |
308 | |
309 static void check_events(void) | |
310 { | |
311 } | |
312 | |
313 static void flip_page(void) | |
314 { | |
315 int i, out_offset = 0, in_offset = 0; | |
316 | |
317 vo_draw_text(in_width, in_height, draw_alpha); | |
318 check_events(); | |
319 for (i = 0; i < in_height; i++) { | |
320 memcpy(frame_buffer + out_offset, next_frame + in_offset, | |
321 in_width * (fb_bpp / 8)); | |
322 out_offset += screen_width; | |
323 in_offset += in_width * (fb_bpp / 8); | |
324 } | |
325 } | |
326 | |
327 static void uninit(void) | |
328 { | |
329 if (vt_active >= 0) | |
330 ioctl(vt_fd, VT_ACTIVATE, vt_active); | |
331 printf("vo_fbdev: uninit\n"); | |
332 free(next_frame); | |
333 munmap(frame_buffer, fb_size); | |
334 } |