27375
|
1 /*
|
|
2 * Video driver for Nintendo Wii/GameCube Framebuffer device
|
|
3 *
|
|
4 * Copyright (C) 2008 Jing Liu <fatersh-1@yahoo.com>
|
|
5 *
|
|
6 * Maintainer: Benjamin Zores <ben@geexbox.org>
|
|
7 *
|
|
8 * This file is part of MPlayer.
|
|
9 *
|
|
10 * MPlayer is free software; you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU General Public License as published by
|
|
12 * the Free Software Foundation; either version 2 of the License, or
|
|
13 * (at your option) any later version.
|
|
14 *
|
|
15 * MPlayer is distributed in the hope that it will be useful,
|
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 * GNU General Public License for more details.
|
|
19 *
|
|
20 * You should have received a copy of the GNU General Public License along
|
|
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
23 */
|
|
24
|
|
25 /*
|
|
26 * This driver handles dedicated ATI GPU, which can be found in:
|
|
27 * - Nintendo GameCube (ATI LSI Flipper @ 162 MHz)
|
|
28 * - Nintendo Wii (ATI Hollywood @ 243 MHz)
|
|
29 *
|
|
30 * Flipper and Hollywood chipsets are pretty similar, except from clock speed:
|
|
31 * - Embedded framebuffer is 2MB.
|
|
32 * - Texture cache is 1MB.
|
|
33 * - Vertex cache is 0.1 MB.
|
|
34 * - Framebuffer is YUY2, not RGB.
|
|
35 * - Best resolution is 480p (854x480)
|
|
36 */
|
|
37
|
|
38 #include <stdio.h>
|
|
39 #include <stdlib.h>
|
|
40 #include <string.h>
|
|
41 #include <fcntl.h>
|
|
42 #include <unistd.h>
|
|
43 #include <errno.h>
|
|
44 #include <ctype.h>
|
|
45
|
|
46 #include <sys/mman.h>
|
|
47 #include <sys/ioctl.h>
|
|
48 #include <sys/kd.h>
|
|
49 #include <linux/fb.h>
|
|
50
|
|
51 #include "config.h"
|
|
52 #include "video_out.h"
|
|
53 #include "video_out_internal.h"
|
|
54 #include "sub.h"
|
|
55 #include "mp_msg.h"
|
|
56
|
|
57 #define WII_DEV_NAME "/dev/fb0"
|
|
58 #define TTY_DEV_NAME "/dev/tty"
|
|
59 #define FB_PIXEL_SIZE 2
|
|
60
|
|
61 static const vo_info_t info = {
|
|
62 "Nintendo Wii/GameCube Framebuffer Device",
|
|
63 "wii",
|
|
64 "Jing Liu <fartersh-1@yahoo.com>",
|
|
65 ""
|
|
66 };
|
|
67
|
|
68 LIBVO_EXTERN(wii)
|
|
69
|
|
70 static signed int pre_init_err = -2;
|
|
71
|
|
72 static FILE *vt_fp = NULL;
|
|
73 static int vt_doit = 1;
|
|
74 static int fb_dev_fd = -1;
|
|
75 static int fb_tty_fd = -1;
|
|
76
|
|
77 static uint8_t *frame_buffer;
|
|
78 static uint8_t *center;
|
|
79
|
|
80 static struct fb_var_screeninfo fb_orig_vinfo;
|
|
81 static struct fb_var_screeninfo fb_vinfo;
|
|
82 static int fb_line_len;
|
|
83 static size_t fb_size;
|
|
84
|
|
85 static int in_width, out_width;
|
|
86 static int in_height, out_height;
|
|
87 static int fs;
|
|
88
|
|
89 static int
|
|
90 fb_preinit (int reset)
|
|
91 {
|
|
92 static int fb_preinit_done = 0;
|
|
93 static int fb_works = 0;
|
|
94
|
|
95 if (reset)
|
|
96 {
|
|
97 fb_preinit_done = 0;
|
|
98 return 0;
|
|
99 }
|
|
100
|
|
101 if (fb_preinit_done)
|
|
102 return fb_works;
|
|
103
|
|
104 if ((fb_dev_fd = open (WII_DEV_NAME, O_RDWR)) == -1)
|
|
105 {
|
|
106 mp_msg (MSGT_VO, MSGL_ERR,
|
|
107 "Can't open %s: %s\n", WII_DEV_NAME, strerror (errno));
|
|
108 goto err_out;
|
|
109 }
|
|
110
|
|
111 if (ioctl (fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo))
|
|
112 {
|
|
113 mp_msg (MSGT_VO, MSGL_ERR,
|
|
114 "Can't get VSCREENINFO: %s\n", strerror (errno));
|
|
115 goto err_out_fd;
|
|
116 }
|
|
117
|
|
118 fb_orig_vinfo = fb_vinfo;
|
|
119
|
|
120 if ((fb_tty_fd = open (TTY_DEV_NAME, O_RDWR)) < 0)
|
|
121 {
|
|
122 mp_msg (MSGT_VO, MSGL_ERR,
|
|
123 "Notice: Can't open %s: %s\n", TTY_DEV_NAME, strerror (errno));
|
|
124 goto err_out_fd;
|
|
125 }
|
|
126
|
|
127 fb_preinit_done = 1;
|
|
128 fb_works = 1;
|
|
129 return 1;
|
|
130
|
|
131 err_out_fd:
|
|
132 close (fb_dev_fd);
|
|
133 fb_dev_fd = -1;
|
|
134 err_out:
|
|
135 fb_preinit_done = 1;
|
|
136 fb_works = 0;
|
|
137
|
|
138 return 0;
|
|
139 }
|
|
140
|
|
141 static void
|
|
142 vt_set_textarea (int u, int l)
|
|
143 {
|
|
144 /* how can I determine the font height?
|
|
145 * just use 16 for now
|
|
146 */
|
|
147 int urow = ((u + 15) / 16) + 1;
|
|
148 int lrow = l / 16;
|
|
149
|
|
150 mp_msg (MSGT_VO, MSGL_DBG2,
|
|
151 "vt_set_textarea (%d, %d): %d,%d\n", u, l, urow, lrow);
|
|
152
|
|
153 if (vt_fp)
|
|
154 {
|
|
155 fprintf (vt_fp, "\33[%d;%dr\33[%d;%dH", urow, lrow, lrow, 0);
|
|
156 fflush (vt_fp);
|
|
157 }
|
|
158 }
|
|
159
|
|
160 static int
|
|
161 config (uint32_t width, uint32_t height, uint32_t d_width,
|
|
162 uint32_t d_height, uint32_t flags, char *title, uint32_t format)
|
|
163 {
|
|
164 struct fb_fix_screeninfo fb_finfo;
|
|
165 uint32_t black = 0x00800080;
|
|
166 long temp;
|
|
167 int vt_fd;
|
|
168
|
|
169 fs = flags & VOFLAG_FULLSCREEN;
|
|
170
|
|
171 if (pre_init_err == -2)
|
|
172 {
|
|
173 mp_msg (MSGT_VO, MSGL_ERR,
|
|
174 "Internal fatal error: config() was called before preinit()\n");
|
|
175 return -1;
|
|
176 }
|
|
177
|
|
178 if (pre_init_err)
|
|
179 return 1;
|
|
180
|
|
181 in_width = width;
|
|
182 in_height = height;
|
|
183
|
|
184 out_width = (d_width && fs) ? d_width : width;
|
|
185 out_height = (d_width && fs) ? d_height : height;
|
|
186
|
|
187 fb_vinfo.xres_virtual = fb_vinfo.xres;
|
|
188 fb_vinfo.yres_virtual = fb_vinfo.yres;
|
|
189
|
|
190 if (fb_tty_fd >= 0 && ioctl (fb_tty_fd, KDSETMODE, KD_GRAPHICS) < 0)
|
|
191 {
|
|
192 mp_msg (MSGT_VO, MSGL_V,
|
|
193 "Can't set graphics mode: %s\n", strerror (errno));
|
|
194 close (fb_tty_fd);
|
|
195 fb_tty_fd = -1;
|
|
196 }
|
|
197
|
|
198 if (ioctl (fb_dev_fd, FBIOPUT_VSCREENINFO, &fb_vinfo))
|
|
199 {
|
|
200 mp_msg (MSGT_VO, MSGL_ERR,
|
|
201 "Can't put VSCREENINFO: %s\n", strerror (errno));
|
|
202 if (fb_tty_fd >= 0 && ioctl (fb_tty_fd, KDSETMODE, KD_TEXT) < 0)
|
|
203 {
|
|
204 mp_msg (MSGT_VO, MSGL_ERR,
|
|
205 "Can't restore text mode: %s\n", strerror (errno));
|
|
206 }
|
|
207 return 1;
|
|
208 }
|
|
209
|
|
210 if (fs)
|
|
211 {
|
|
212 out_width = fb_vinfo.xres;
|
|
213 out_height = fb_vinfo.yres;
|
|
214 }
|
|
215
|
|
216 if (out_width < in_width || out_height < in_height)
|
|
217 {
|
|
218 mp_msg (MSGT_VO, MSGL_ERR, "Screensize is smaller than video size\n");
|
|
219 return 1;
|
|
220 }
|
|
221
|
|
222 if (ioctl (fb_dev_fd, FBIOGET_FSCREENINFO, &fb_finfo))
|
|
223 {
|
|
224 mp_msg (MSGT_VO, MSGL_ERR,
|
|
225 "Can't get FSCREENINFO: %s\n", strerror (errno));
|
|
226 return 1;
|
|
227 }
|
|
228
|
|
229 if (fb_finfo.type != FB_TYPE_PACKED_PIXELS)
|
|
230 {
|
|
231 mp_msg (MSGT_VO, MSGL_ERR, "Type %d not supported\n", fb_finfo.type);
|
|
232 return 1;
|
|
233 }
|
|
234
|
|
235 fb_line_len = fb_finfo.line_length;
|
|
236 fb_size = fb_finfo.smem_len;
|
|
237 frame_buffer = NULL;
|
|
238
|
|
239 frame_buffer = (uint8_t *) mmap (0, fb_size, PROT_READ | PROT_WRITE,
|
|
240 MAP_SHARED, fb_dev_fd, 0);
|
|
241 if (frame_buffer == (uint8_t *) -1)
|
|
242 {
|
|
243 mp_msg (MSGT_VO, MSGL_ERR,
|
|
244 "Can't mmap %s: %s\n", WII_DEV_NAME, strerror (errno));
|
|
245 return 1;
|
|
246 }
|
|
247
|
|
248 center = frame_buffer +
|
|
249 ((out_width - in_width) / 2) * FB_PIXEL_SIZE +
|
|
250 ((out_height - in_height) / 2) * fb_line_len;
|
|
251
|
|
252 mp_msg (MSGT_VO, MSGL_DBG2, "Frame_buffer @ %p\n", frame_buffer);
|
|
253 mp_msg (MSGT_VO, MSGL_DBG2, "Center @ %p\n", center);
|
|
254 mp_msg (MSGT_VO, MSGL_V,
|
|
255 "Pixel per line: %d\n", fb_line_len / FB_PIXEL_SIZE);
|
|
256
|
|
257 /* blanking screen */
|
|
258 for (temp = 0; temp < fb_size; temp += 4)
|
|
259 memcpy (frame_buffer + temp, (void *) &black, 4);
|
|
260
|
|
261 vt_fd = open (TTY_DEV_NAME, O_WRONLY);
|
|
262 if (vt_doit && vt_fd == -1)
|
|
263 {
|
|
264 mp_msg (MSGT_VO, MSGL_ERR,
|
|
265 "Can't open %s: %s\n", TTY_DEV_NAME, strerror (errno));
|
|
266 vt_doit = 0;
|
|
267 }
|
|
268
|
|
269 vt_fp = fdopen (vt_fd, "w");
|
|
270 if (vt_doit && !vt_fp)
|
|
271 {
|
|
272 mp_msg (MSGT_VO, MSGL_ERR,
|
|
273 "Can't fdopen %s: %s\n", TTY_DEV_NAME, strerror (errno));
|
|
274 vt_doit = 0;
|
|
275 }
|
|
276
|
|
277 if (vt_doit)
|
|
278 vt_set_textarea ((out_height + in_height) / 2, fb_vinfo.yres);
|
|
279
|
|
280 return 0;
|
|
281 }
|
|
282
|
|
283 static int
|
|
284 query_format (uint32_t format)
|
|
285 {
|
|
286 if (!fb_preinit (0))
|
|
287 return 0;
|
|
288
|
|
289 if (format != IMGFMT_YUY2)
|
|
290 return 0;
|
|
291
|
|
292 return VFCAP_ACCEPT_STRIDE | VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
|
|
293 }
|
|
294
|
|
295 static void
|
|
296 draw_alpha (int x0, int y0, int w, int h,
|
|
297 unsigned char *src, unsigned char *srca, int stride)
|
|
298 {
|
|
299 unsigned char *dst;
|
|
300
|
|
301 dst = center + fb_line_len * y0 + FB_PIXEL_SIZE * x0;
|
|
302 vo_draw_alpha_yuy2 (w, h, src, srca, stride, dst, fb_line_len);
|
|
303 }
|
|
304
|
|
305 static int
|
|
306 draw_frame (uint8_t *src[])
|
|
307 {
|
|
308 return 1;
|
|
309 }
|
|
310
|
|
311 static int
|
|
312 draw_slice (uint8_t *src[], int stride[], int w, int h, int x, int y)
|
|
313 {
|
|
314 uint8_t *d, *s;
|
|
315
|
|
316 d = center + fb_line_len * y + FB_PIXEL_SIZE * x;
|
|
317 s = src[0];
|
|
318
|
|
319 while (h)
|
|
320 {
|
|
321 memcpy (d, s, w * FB_PIXEL_SIZE);
|
|
322 d += fb_line_len;
|
|
323 s += stride[0];
|
|
324 h--;
|
|
325 }
|
|
326
|
|
327 return 0;
|
|
328 }
|
|
329
|
|
330 static void
|
|
331 check_events(void)
|
|
332 {
|
|
333 /* unused */
|
|
334 }
|
|
335
|
|
336 static void
|
|
337 flip_page (void)
|
|
338 {
|
|
339 /* unused */
|
|
340 }
|
|
341
|
|
342 static void
|
|
343 draw_osd (void)
|
|
344 {
|
|
345 vo_draw_text (in_width, in_height, draw_alpha);
|
|
346 }
|
|
347
|
|
348 static void
|
|
349 uninit (void)
|
|
350 {
|
|
351 if (ioctl (fb_dev_fd, FBIOGET_VSCREENINFO, &fb_vinfo))
|
|
352 mp_msg (MSGT_VO, MSGL_WARN,
|
|
353 "ioctl FBIOGET_VSCREENINFO: %s\n", strerror (errno));
|
|
354
|
|
355 fb_orig_vinfo.xoffset = fb_vinfo.xoffset;
|
|
356 fb_orig_vinfo.yoffset = fb_vinfo.yoffset;
|
|
357
|
|
358 if (ioctl (fb_dev_fd, FBIOPUT_VSCREENINFO, &fb_orig_vinfo))
|
|
359 mp_msg (MSGT_VO, MSGL_WARN,
|
|
360 "Can't reset original fb_var_screeninfo: %s\n", strerror (errno));
|
|
361
|
|
362 if (fb_tty_fd >= 0)
|
|
363 {
|
|
364 if (ioctl (fb_tty_fd, KDSETMODE, KD_TEXT) < 0)
|
|
365 mp_msg (MSGT_VO, MSGL_WARN,
|
|
366 "Can't restore text mode: %s\n", strerror (errno));
|
|
367 }
|
|
368
|
|
369 if (vt_doit)
|
|
370 vt_set_textarea (0, fb_orig_vinfo.yres);
|
|
371
|
|
372 close (fb_tty_fd);
|
|
373 close (fb_dev_fd);
|
|
374
|
|
375 if (frame_buffer)
|
|
376 munmap (frame_buffer, fb_size);
|
|
377
|
|
378 frame_buffer = NULL;
|
|
379 fb_preinit (1);
|
|
380 }
|
|
381
|
|
382 static int
|
|
383 preinit (const char *vo_subdevice)
|
|
384 {
|
|
385 pre_init_err = 0;
|
|
386
|
|
387 if (!pre_init_err)
|
|
388 return pre_init_err = (fb_preinit (0) ? 0 : -1);
|
|
389
|
|
390 return -1;
|
|
391 }
|
|
392
|
|
393 static uint32_t
|
|
394 get_image(mp_image_t *mpi)
|
|
395 {
|
|
396 if (((mpi->type != MP_IMGTYPE_STATIC) && (mpi->type != MP_IMGTYPE_TEMP)) ||
|
|
397 (mpi->flags & MP_IMGFLAG_PLANAR) ||
|
|
398 (mpi->flags & MP_IMGFLAG_YUV) ||
|
|
399 (mpi->width != in_width) ||
|
|
400 (mpi->height != in_height))
|
|
401 return VO_FALSE;
|
|
402
|
|
403 mpi->planes[0] = center;
|
|
404 mpi->stride[0] = fb_line_len;
|
|
405 mpi->flags |= MP_IMGFLAG_DIRECT;
|
|
406
|
|
407 return VO_TRUE;
|
|
408 }
|
|
409
|
|
410 static int
|
|
411 control (uint32_t request, void *data, ...)
|
|
412 {
|
|
413 if (request == VOCTRL_GET_IMAGE)
|
|
414 return get_image (data);
|
|
415 else if (request == VOCTRL_QUERY_FORMAT)
|
|
416 return query_format (*((uint32_t*) data));
|
|
417
|
|
418 return VO_NOTIMPL;
|
|
419 }
|