]> git.sesse.net Git - vlc/blob - modules/video_output/fb.c
f3d4c25566a21076802337695315e1a7afbb6d69
[vlc] / modules / video_output / fb.c
1 /*****************************************************************************
2  * fb.c : framebuffer plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: fb.c,v 1.2 2003/02/15 04:43:19 ipkiss Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *      
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <errno.h>                                                 /* ENOMEM */
28 #include <signal.h>                                      /* SIGUSR1, SIGUSR2 */
29 #include <stdlib.h>                                                /* free() */
30 #include <string.h>                                            /* strerror() */
31 #include <fcntl.h>                                                 /* open() */
32 #include <unistd.h>                                               /* close() */
33
34 #include <termios.h>                                       /* struct termios */
35 #include <sys/ioctl.h>
36 #include <sys/mman.h>                                              /* mmap() */
37
38 #include <linux/fb.h>
39 #include <linux/vt.h>                                                /* VT_* */
40 #include <linux/kd.h>                                                 /* KD* */
41
42 #include <vlc/vlc.h>
43 #include <vlc/vout.h>
44
45 /*****************************************************************************
46  * Local prototypes
47  *****************************************************************************/
48 static int  Create    ( vlc_object_t * );
49 static void Destroy   ( vlc_object_t * );
50
51 static int  Init      ( vout_thread_t * );
52 static void End       ( vout_thread_t * );
53 static int  Manage    ( vout_thread_t * );
54 static void Display   ( vout_thread_t *, picture_t * );
55
56 static int  OpenDisplay    ( vout_thread_t * );
57 static void CloseDisplay   ( vout_thread_t * );
58 static void SwitchDisplay  ( int i_signal );
59 static void TextMode       ( int i_tty );
60 static void GfxMode        ( int i_tty );
61
62 /*****************************************************************************
63  * Module descriptor
64  *****************************************************************************/
65 #define FB_DEV_VAR "fbdev"
66
67 vlc_module_begin();                                            
68     add_category_hint( N_("Miscellaneous"), NULL );
69     add_string( FB_DEV_VAR, "/dev/fb0", NULL, N_("framebuffer device"), NULL );
70     set_description( _("Linux console framebuffer module") );
71     set_capability( "video output", 30 );
72     set_callbacks( Create, Destroy );
73 vlc_module_end();
74
75 /*****************************************************************************
76  * vout_sys_t: video output framebuffer method descriptor
77  *****************************************************************************
78  * This structure is part of the video output thread descriptor.
79  * It describes the FB specific properties of an output thread.
80  *****************************************************************************/
81 struct vout_sys_t
82 {
83     /* System informations */
84     int                 i_tty;                          /* tty device handle */
85     struct termios      old_termios;
86
87     /* Original configuration informations */
88     struct sigaction            sig_usr1;           /* USR1 previous handler */
89     struct sigaction            sig_usr2;           /* USR2 previous handler */
90     struct vt_mode              vt_mode;                 /* previous VT mode */
91
92     /* Framebuffer information */
93     int                         i_fd;                       /* device handle */
94     struct fb_var_screeninfo    old_info;      /* original mode informations */
95     struct fb_var_screeninfo    var_info;       /* current mode informations */
96     vlc_bool_t                  b_pan;     /* does device supports panning ? */
97     struct fb_cmap              fb_cmap;                /* original colormap */
98     u16                         *p_palette;              /* original palette */
99
100     /* Video information */
101     int i_width;
102     int i_height;
103     int i_bytes_per_pixel;
104
105     /* Video memory */
106     byte_t *    p_video;                                      /* base adress */
107     size_t      i_page_size;                                    /* page size */
108 };
109
110 /*****************************************************************************
111  * Create: allocates FB video thread output method
112  *****************************************************************************
113  * This function allocates and initializes a FB vout method.
114  *****************************************************************************/
115 static int Create( vlc_object_t *p_this )
116 {
117     vout_thread_t *p_vout = (vout_thread_t *)p_this;
118
119     struct sigaction    sig_tty;                 /* sigaction for tty change */
120     struct vt_mode      vt_mode;                          /* vt current mode */
121     struct termios      new_termios;
122
123     /* Allocate instance and initialize some members */
124     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
125     if( p_vout->p_sys == NULL )
126     {
127         return( 1 );
128     };
129
130     p_vout->pf_init = Init;
131     p_vout->pf_end = End;
132     p_vout->pf_manage = Manage;
133     p_vout->pf_render = NULL;
134     p_vout->pf_display = Display;
135
136     /* Set tty and fb devices */
137     p_vout->p_sys->i_tty = 0;           /* 0 == /dev/tty0 == current console */
138
139     GfxMode( p_vout->p_sys->i_tty );
140
141     /* Set keyboard settings */
142     if (tcgetattr(0, &p_vout->p_sys->old_termios) == -1)
143     {
144         msg_Err( p_vout, "tcgetattr failed" );
145     }
146
147     if (tcgetattr(0, &new_termios) == -1)
148     {
149         msg_Err( p_vout, "tcgetattr failed" );
150     }
151
152  /* new_termios.c_lflag &= ~ (ICANON | ISIG);
153     new_termios.c_lflag |= (ECHO | ECHOCTL); */
154     new_termios.c_lflag &= ~ (ICANON);
155     new_termios.c_lflag &= ~(ECHO | ECHOCTL);
156     new_termios.c_iflag = 0;
157     new_termios.c_cc[VMIN] = 1;
158     new_termios.c_cc[VTIME] = 0;
159
160     if (tcsetattr(0, TCSAFLUSH, &new_termios) == -1)
161     {
162         msg_Err( p_vout, "tcsetattr failed" );
163     }
164
165     ioctl( p_vout->p_sys->i_tty, VT_RELDISP, VT_ACKACQ );
166
167     /* Set-up tty signal handler to be aware of tty changes */
168     memset( &sig_tty, 0, sizeof( sig_tty ) );
169     sig_tty.sa_handler = SwitchDisplay;
170     sigemptyset( &sig_tty.sa_mask );
171     if( sigaction( SIGUSR1, &sig_tty, &p_vout->p_sys->sig_usr1 ) ||
172         sigaction( SIGUSR2, &sig_tty, &p_vout->p_sys->sig_usr2 ) )
173     {
174         msg_Err( p_vout, "cannot set signal handler (%s)", strerror(errno) );
175         tcsetattr(0, 0, &p_vout->p_sys->old_termios);
176         TextMode( p_vout->p_sys->i_tty );
177         free( p_vout->p_sys );
178         return( 1 );
179     }
180
181     /* Set-up tty according to new signal handler */
182     if( -1 == ioctl( p_vout->p_sys->i_tty,
183                      VT_GETMODE, &p_vout->p_sys->vt_mode ) )
184     {
185         msg_Err( p_vout, "cannot get terminal mode (%s)", strerror(errno) );
186         sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
187         sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
188         tcsetattr(0, 0, &p_vout->p_sys->old_termios);
189         TextMode( p_vout->p_sys->i_tty );
190         free( p_vout->p_sys );
191         return( 1 );
192     }
193     memcpy( &vt_mode, &p_vout->p_sys->vt_mode, sizeof( vt_mode ) );
194     vt_mode.mode   = VT_PROCESS;
195     vt_mode.waitv  = 0;
196     vt_mode.relsig = SIGUSR1;
197     vt_mode.acqsig = SIGUSR2;
198
199     if( -1 == ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &vt_mode ) )
200     {
201         msg_Err( p_vout, "cannot set terminal mode (%s)", strerror(errno) );
202         sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
203         sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
204         tcsetattr(0, 0, &p_vout->p_sys->old_termios);
205         TextMode( p_vout->p_sys->i_tty );
206         free( p_vout->p_sys );
207         return( 1 );
208     }
209
210     if( OpenDisplay( p_vout ) )
211     {
212         ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
213         sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
214         sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
215         tcsetattr(0, 0, &p_vout->p_sys->old_termios);
216         TextMode( p_vout->p_sys->i_tty );
217         free( p_vout->p_sys );
218         return( 1 );
219     }
220
221     return( 0 );
222 }
223
224 /*****************************************************************************
225  * Init: initialize framebuffer video thread output method
226  *****************************************************************************/
227 static int Init( vout_thread_t *p_vout )
228 {
229     int i_index;
230     picture_t *p_pic;
231
232     I_OUTPUTPICTURES = 0;
233
234     /* Initialize the output structure: RGB with square pixels, whatever
235      * the input format is, since it's the only format we know */
236     switch( p_vout->p_sys->var_info.bits_per_pixel )
237     {
238         case 8: /* FIXME: set the palette */
239             p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;
240         case 15:
241             p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
242         case 16:
243             p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
244         case 24:
245             p_vout->output.i_chroma = VLC_FOURCC('R','V','2','4'); break;
246         case 32:
247             p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
248         default:
249             msg_Err( p_vout, "unknown screen depth %i",
250                      p_vout->p_sys->var_info.bits_per_pixel );
251             return 0;
252     }
253
254     /* Only useful for p_vout->p_sys->var_info.bits_per_pixel != 8 */
255     p_vout->output.i_rmask = ( (1 << p_vout->p_sys->var_info.red.length) - 1 )
256                      << p_vout->p_sys->var_info.red.offset;
257     p_vout->output.i_gmask = ( (1 << p_vout->p_sys->var_info.green.length) - 1 )
258                      << p_vout->p_sys->var_info.green.offset;
259     p_vout->output.i_bmask = ( (1 << p_vout->p_sys->var_info.blue.length) - 1 )
260                      << p_vout->p_sys->var_info.blue.offset;
261
262     p_vout->output.i_width = p_vout->p_sys->i_width;
263     p_vout->output.i_height = p_vout->p_sys->i_height;
264
265     /* Assume we have square pixels */
266     p_vout->output.i_aspect = p_vout->p_sys->i_width
267                                * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
268
269     /* Clear the screen */
270     memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
271
272     /* Try to initialize 1 direct buffer */
273     p_pic = NULL;
274
275     /* Find an empty picture slot */
276     for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
277     {
278         if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
279         {
280             p_pic = p_vout->p_picture + i_index;
281             break;
282         }
283     }
284
285     /* Allocate the picture */
286     if( p_pic == NULL )
287     {
288         return 0;
289     }
290
291     /* We know the chroma, allocate a buffer which will be used
292      * directly by the decoder */
293     p_pic->p->p_pixels = p_vout->p_sys->p_video;
294     p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel;
295     p_pic->p->i_lines = p_vout->p_sys->var_info.yres;
296
297     if( p_vout->p_sys->var_info.xres_virtual )
298     {
299         p_pic->p->i_pitch = p_vout->p_sys->var_info.xres_virtual
300                              * p_vout->p_sys->i_bytes_per_pixel;
301     }
302     else
303     {
304         p_pic->p->i_pitch = p_vout->p_sys->var_info.xres
305                              * p_vout->p_sys->i_bytes_per_pixel;
306     }
307
308     p_pic->p->i_visible_pitch = p_vout->p_sys->var_info.xres
309                                  * p_vout->p_sys->i_bytes_per_pixel;
310
311     p_pic->i_planes = 1;
312
313     p_pic->i_status = DESTROYED_PICTURE;
314     p_pic->i_type   = DIRECT_PICTURE;
315
316     PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
317
318     I_OUTPUTPICTURES++;
319
320     return 0;
321 }
322
323 /*****************************************************************************
324  * End: terminate framebuffer video thread output method
325  *****************************************************************************/
326 static void End( vout_thread_t *p_vout )
327 {
328     /* Clear the screen */
329     memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
330 }
331
332 /*****************************************************************************
333  * Destroy: destroy FB video thread output method
334  *****************************************************************************
335  * Terminate an output method created by Create
336  *****************************************************************************/
337 static void Destroy( vlc_object_t *p_this )
338 {
339     vout_thread_t *p_vout = (vout_thread_t *)p_this;
340     
341     CloseDisplay( p_vout );
342
343     /* Reset the terminal */
344     ioctl( p_vout->p_sys->i_tty, VT_SETMODE, &p_vout->p_sys->vt_mode );
345
346     /* Remove signal handlers */
347     sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
348     sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
349
350     /* Reset the keyboard state */
351     tcsetattr( 0, 0, &p_vout->p_sys->old_termios );
352
353     /* Return to text mode */
354     TextMode( p_vout->p_sys->i_tty );
355
356     /* Destroy structure */
357     free( p_vout->p_sys );
358 }
359
360 /*****************************************************************************
361  * Manage: handle FB events
362  *****************************************************************************
363  * This function should be called regularly by video output thread. It manages
364  * console events. It returns a non null value on error.
365  *****************************************************************************/
366 static int Manage( vout_thread_t *p_vout )
367 {
368 #if 0
369     u8 buf;
370
371     if ( read(0, &buf, 1) == 1)
372     {
373         switch( buf )
374         {
375         case 'q':
376             p_vout->p_vlc->b_die = 1;
377             break;
378
379         default:
380             break;
381         }
382     }
383 #endif
384
385     /*
386      * Size change
387      */
388     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
389     {
390         msg_Dbg( p_vout, "reinitializing framebuffer screen" );
391         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
392
393         /* Destroy XImages to change their size */
394         End( p_vout );
395
396         /* Recreate XImages. If SysInit failed, the thread can't go on. */
397         if( Init( p_vout ) )
398         {
399             msg_Err( p_vout, "cannot reinit framebuffer screen" );
400             return( 1 );
401         }
402
403         /* Clear screen */
404         memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
405
406 #if 0
407         /* Tell the video output thread that it will need to rebuild YUV
408          * tables. This is needed since conversion buffer size may have changed */
409         p_vout->i_changes |= VOUT_YUV_CHANGE;
410 #endif
411     }
412
413     return 0;
414 }
415
416 /*****************************************************************************
417  * Display: displays previously rendered output
418  *****************************************************************************
419  * This function send the currently rendered image to FB image, waits until
420  * it is displayed and switch the two rendering buffers, preparing next frame.
421  *****************************************************************************/
422 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
423 {
424     /* swap the two Y offsets if the drivers supports panning */
425     if( p_vout->p_sys->b_pan )
426     {
427         p_vout->p_sys->var_info.yoffset = 0;
428         /*p_vout->p_sys->var_info.yoffset = p_vout->p_sys->var_info.yres; */
429    
430         /* the X offset should be 0, but who knows ...
431          * some other app might have played with the framebuffer */
432         p_vout->p_sys->var_info.xoffset = 0;
433
434         ioctl( p_vout->p_sys->i_fd,
435                FBIOPAN_DISPLAY, &p_vout->p_sys->var_info );
436     }
437 }
438
439 #if 0
440 static void SetPalette( vout_thread_t *p_vout,
441                              u16 *red, u16 *green, u16 *blue, u16 *transp )
442 {
443     struct fb_cmap cmap = { 0, 256, red, green, blue, transp };
444
445     ioctl( p_vout->p_sys->i_fd, FBIOPUTCMAP, &cmap );
446 }
447 #endif
448
449 /* following functions are local */
450
451 /*****************************************************************************
452  * OpenDisplay: initialize framebuffer
453  *****************************************************************************/
454 static int OpenDisplay( vout_thread_t *p_vout )
455 {
456     char *psz_device;                             /* framebuffer device path */
457     struct fb_fix_screeninfo    fix_info;     /* framebuffer fix information */
458
459     /* Open framebuffer device */
460     if( !(psz_device = config_GetPsz( p_vout, FB_DEV_VAR )) )
461     {
462         msg_Err( p_vout, "don't know which fb device to open" );
463         return( 1 );
464     }
465
466     p_vout->p_sys->i_fd = open( psz_device, O_RDWR);
467
468     if( p_vout->p_sys->i_fd == -1 )
469     {
470         msg_Err( p_vout, "cannot open %s (%s)", psz_device, strerror(errno) );
471         free( psz_device );
472         return( 1 );
473     }
474     free( psz_device );
475
476     /* Get framebuffer device informations */
477     if( ioctl( p_vout->p_sys->i_fd,
478                FBIOGET_VSCREENINFO, &p_vout->p_sys->var_info ) )
479     {
480         msg_Err( p_vout, "cannot get fb info (%s)", strerror(errno) );
481         close( p_vout->p_sys->i_fd );
482         return( 1 );
483     }
484
485     if( ioctl( p_vout->p_sys->i_fd,
486                FBIOGET_VSCREENINFO, &p_vout->p_sys->old_info ) )
487     {
488         msg_Err( p_vout, "cannot get 2nd fb info (%s)", strerror(errno) );
489         close( p_vout->p_sys->i_fd );
490         return( 1 );
491     }
492
493     /* Set some attributes */
494     p_vout->p_sys->var_info.activate = FB_ACTIVATE_NXTOPEN;
495     p_vout->p_sys->var_info.xoffset =  0;
496     p_vout->p_sys->var_info.yoffset =  0;
497
498     if( ioctl( p_vout->p_sys->i_fd,
499                FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info ) )
500     {
501         msg_Err( p_vout, "cannot set fb info (%s)", strerror(errno) );
502         close( p_vout->p_sys->i_fd );
503         return( 1 );
504     }
505
506     /* Get some informations again, in the definitive configuration */
507     if( ioctl( p_vout->p_sys->i_fd, FBIOGET_FSCREENINFO, &fix_info )
508          || ioctl( p_vout->p_sys->i_fd,
509                    FBIOGET_VSCREENINFO, &p_vout->p_sys->var_info ) )
510     {
511         msg_Err( p_vout, "cannot get additional fb info (%s)",
512                           strerror(errno) );
513
514         /* Restore fb config */
515         ioctl( p_vout->p_sys->i_fd,
516                FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info );
517
518         close( p_vout->p_sys->i_fd );
519         return( 1 );
520     }
521
522     /* FIXME: if the image is full-size, it gets cropped on the left
523      * because of the xres / xres_virtual slight difference */
524     msg_Dbg( p_vout, "%ix%i (virtual %ix%i)",
525              p_vout->p_sys->var_info.xres, p_vout->p_sys->var_info.yres,
526              p_vout->p_sys->var_info.xres_virtual,
527              p_vout->p_sys->var_info.yres_virtual );
528
529     p_vout->p_sys->i_height = p_vout->p_sys->var_info.yres;
530     p_vout->p_sys->i_width  = p_vout->p_sys->var_info.xres_virtual
531                                ? p_vout->p_sys->var_info.xres_virtual
532                                : p_vout->p_sys->var_info.xres;
533
534     p_vout->p_sys->p_palette = NULL;
535     p_vout->p_sys->b_pan = ( fix_info.ypanstep || fix_info.ywrapstep );
536
537     switch( p_vout->p_sys->var_info.bits_per_pixel )
538     {
539     case 8:
540         p_vout->p_sys->p_palette = malloc( 8 * 256 * sizeof( u16 ) );
541         p_vout->p_sys->fb_cmap.start = 0;
542         p_vout->p_sys->fb_cmap.len = 256;
543         p_vout->p_sys->fb_cmap.red = p_vout->p_sys->p_palette;
544         p_vout->p_sys->fb_cmap.green = p_vout->p_sys->p_palette + 256 * sizeof( u16 );
545         p_vout->p_sys->fb_cmap.blue = p_vout->p_sys->p_palette + 2 * 256 * sizeof( u16 );
546         p_vout->p_sys->fb_cmap.transp = p_vout->p_sys->p_palette + 3 * 256 * sizeof( u16 );
547
548         /* Save the colormap */
549         ioctl( p_vout->p_sys->i_fd, FBIOGETCMAP, &p_vout->p_sys->fb_cmap );
550
551         p_vout->p_sys->i_bytes_per_pixel = 1;
552         break;
553
554     case 15:
555     case 16:
556         p_vout->p_sys->i_bytes_per_pixel = 2;
557         break;
558
559     case 24:
560         p_vout->p_sys->i_bytes_per_pixel = 3;
561         break;
562
563     case 32:
564         p_vout->p_sys->i_bytes_per_pixel = 4;
565         break;
566
567     default:
568         msg_Err( p_vout, "screen depth %d is not supported",
569                          p_vout->p_sys->var_info.bits_per_pixel );
570
571         /* Restore fb config */
572         ioctl( p_vout->p_sys->i_fd,
573                FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info );
574
575         close( p_vout->p_sys->i_fd );
576         return 1;
577     }
578
579     p_vout->p_sys->i_page_size = p_vout->p_sys->i_width *
580                 p_vout->p_sys->i_height * p_vout->p_sys->i_bytes_per_pixel;
581
582     /* Map a framebuffer at the beginning */
583     p_vout->p_sys->p_video = mmap( 0, p_vout->p_sys->i_page_size,
584                                    PROT_READ | PROT_WRITE, MAP_SHARED,
585                                    p_vout->p_sys->i_fd, 0 );
586
587     if( p_vout->p_sys->p_video == ((void*)-1) )
588     {
589         msg_Err( p_vout, "cannot map video memory (%s)", strerror(errno) );
590
591         if( p_vout->p_sys->var_info.bits_per_pixel == 8 )
592         {
593             free( p_vout->p_sys->p_palette );
594         }
595
596         /* Restore fb config */
597         ioctl( p_vout->p_sys->i_fd,
598                FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info );
599
600         close( p_vout->p_sys->i_fd );
601         return( 1 );
602     }
603
604     msg_Dbg( p_vout, "framebuffer type=%d, visual=%d, ypanstep=%d, "
605              "ywrap=%d, accel=%d", fix_info.type, fix_info.visual,
606              fix_info.ypanstep, fix_info.ywrapstep, fix_info.accel );
607     return( 0 );
608 }
609
610 /*****************************************************************************
611  * CloseDisplay: terminate FB video thread output method
612  *****************************************************************************/
613 static void CloseDisplay( vout_thread_t *p_vout )
614 {
615     /* Clear display */
616     memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size );
617
618     /* Restore palette */
619     if( p_vout->p_sys->var_info.bits_per_pixel == 8 )
620     {
621         ioctl( p_vout->p_sys->i_fd,
622                FBIOPUTCMAP, &p_vout->p_sys->fb_cmap );
623         free( p_vout->p_sys->p_palette );
624     }
625
626     /* Restore fb config */
627     ioctl( p_vout->p_sys->i_fd,
628            FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info );
629
630     /* Close fb */
631     close( p_vout->p_sys->i_fd );
632 }
633
634 /*****************************************************************************
635  * SwitchDisplay: VT change signal handler
636  *****************************************************************************
637  * This function activates or deactivates the output of the thread. It is
638  * called by the VT driver, on terminal change.
639  *****************************************************************************/
640 static void SwitchDisplay(int i_signal)
641 {
642 #if 0
643     vout_thread_t *p_vout;
644
645     vlc_mutex_lock( &p_vout_bank->lock );
646
647     /* XXX: only test the first video output */
648     if( p_vout_bank->i_count )
649     {
650         p_vout = p_vout_bank->pp_vout[0];
651
652         switch( i_signal )
653         {
654         case SIGUSR1:                                /* vt has been released */
655             p_vout->b_active = 0;
656             ioctl( p_vout->p_sys->i_tty, VT_RELDISP, 1 );
657             break;
658         case SIGUSR2:                                /* vt has been acquired */
659             p_vout->b_active = 1;
660             ioctl( p_vout->p_sys->i_tty, VT_RELDISP, VT_ACTIVATE );
661             /* handle blanking */
662             vlc_mutex_lock( &p_vout->change_lock );
663             p_vout->i_changes |= VOUT_SIZE_CHANGE;
664             vlc_mutex_unlock( &p_vout->change_lock );
665             break;
666         }
667     }
668
669     vlc_mutex_unlock( &p_vout_bank->lock );
670 #endif
671 }
672
673 /*****************************************************************************
674  * TextMode and GfxMode : switch tty to text/graphic mode
675  *****************************************************************************
676  * These functions toggle the tty mode.
677  *****************************************************************************/
678 static void TextMode( int i_tty )
679 {
680     /* return to text mode */
681     if( -1 == ioctl(i_tty, KDSETMODE, KD_TEXT) )
682     {
683         /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_TEXT" );*/
684     }
685 }
686
687 static void GfxMode( int i_tty )
688 {
689     /* switch to graphic mode */
690     if( -1 == ioctl(i_tty, KDSETMODE, KD_GRAPHICS) )
691     {
692         /*msg_Err( p_vout, "failed ioctl KDSETMODE KD_GRAPHICS" );*/
693     }
694 }
695