]> git.sesse.net Git - vlc/blob - plugins/fb/vout_fb.c
bc85718d11282ffa42627b207745ab2046961348
[vlc] / plugins / fb / vout_fb.c
1 /*****************************************************************************
2  * vout_fb.c: framebuffer video output display method
3  *****************************************************************************
4  * Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
5  * $Id: vout_fb.c,v 1.12 2001/05/07 03:14:09 stef 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 #define MODULE_NAME fb
25 #include "modules_inner.h"
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include "defs.h"
31
32 #include <errno.h>                                                 /* ENOMEM */
33 #include <signal.h>                                      /* SIGUSR1, SIGUSR2 */
34 #include <stdlib.h>                                                /* free() */
35 #include <string.h>                                            /* strerror() */
36 #include <fcntl.h>                                                 /* open() */
37 #include <unistd.h>                                               /* close() */
38
39 #include <termios.h>                                       /* struct termios */
40 #include <sys/ioctl.h>
41 #include <sys/mman.h>                                              /* mmap() */
42
43 #include <linux/fb.h>
44 #include <linux/vt.h>                                                /* VT_* */
45 #include <linux/kd.h>                                                 /* KD* */
46
47 #include "config.h"
48 #include "common.h"
49 #include "threads.h"
50 #include "mtime.h"
51 #include "tests.h"
52 #include "modules.h"
53
54 #include "video.h"
55 #include "video_output.h"
56
57 #include "intf_msg.h"
58 #include "main.h"
59
60 /*****************************************************************************
61  * vout_sys_t: video output framebuffer method descriptor
62  *****************************************************************************
63  * This structure is part of the video output thread descriptor.
64  * It describes the FB specific properties of an output thread.
65  *****************************************************************************/
66 typedef struct vout_sys_s
67 {
68     /* System informations */
69     int                 i_tty_dev;                      /* tty device handle */
70     struct termios      old_termios;
71
72     /* Original configuration informations */
73     struct sigaction            sig_usr1;           /* USR1 previous handler */
74     struct sigaction            sig_usr2;           /* USR2 previous handler */
75     struct vt_mode              vt_mode;                 /* previous VT mode */
76
77     /* Framebuffer information */
78     int                         i_fb_dev;                   /* device handle */
79     struct fb_var_screeninfo    old_info;      /* original mode informations */
80     struct fb_var_screeninfo    var_info;       /* current mode informations */
81     boolean_t                   b_pan;     /* does device supports panning ? */
82     struct fb_cmap              fb_cmap;                /* original colormap */
83     u16                         *fb_palette;             /* original palette */
84
85     /* Video memory */
86     byte_t *                    p_video;                      /* base adress */
87     size_t                      i_page_size;                    /* page size */
88
89 } vout_sys_t;
90
91 /*****************************************************************************
92  * Local prototypes.
93  *****************************************************************************/
94 static int  vout_Probe     ( probedata_t *p_data );
95 static int  vout_Create    ( struct vout_thread_s * );
96 static int  vout_Init      ( struct vout_thread_s * );
97 static void vout_End       ( struct vout_thread_s * );
98 static void vout_Destroy   ( struct vout_thread_s * );
99 static int  vout_Manage    ( struct vout_thread_s * );
100 static void vout_Display   ( struct vout_thread_s * );
101 static void vout_SetPalette( p_vout_thread_t p_vout, u16 *red, u16 *green,
102                              u16 *blue, u16 *transp );
103
104 static int  FBOpenDisplay  ( struct vout_thread_s * );
105 static void FBCloseDisplay ( struct vout_thread_s * );
106 static void FBSwitchDisplay( int i_signal );
107 static void FBTextMode     ( int i_tty_dev );
108 static void FBGfxMode      ( int i_tty_dev );
109
110 /*****************************************************************************
111  * Functions exported as capabilities. They are declared as static so that
112  * we don't pollute the namespace too much.
113  *****************************************************************************/
114 void _M( vout_getfunctions )( function_list_t * p_function_list )
115 {
116     p_function_list->pf_probe = vout_Probe;
117     p_function_list->functions.vout.pf_create     = vout_Create;
118     p_function_list->functions.vout.pf_init       = vout_Init;
119     p_function_list->functions.vout.pf_end        = vout_End;
120     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
121     p_function_list->functions.vout.pf_manage     = vout_Manage;
122     p_function_list->functions.vout.pf_display    = vout_Display;
123     p_function_list->functions.vout.pf_setpalette = vout_SetPalette;
124 }
125
126 /*****************************************************************************
127  * vout_Probe: probe the video driver and return a score
128  *****************************************************************************
129  * This function tries to open the framebuffer and returns a score to the
130  * plugin manager so that it can select the best plugin.
131  *****************************************************************************/
132 static int vout_Probe( probedata_t *p_data )
133 {
134     int i_fd;
135
136     if( TestMethod( VOUT_METHOD_VAR, "fb" ) )
137     {
138         return( 999 );
139     }
140
141     i_fd = open( main_GetPszVariable( VOUT_FB_DEV_VAR,
142                                       VOUT_FB_DEV_DEFAULT ), O_RDWR );
143     if( i_fd == -1 )
144     {
145         return( 0 );
146     }
147     close( i_fd );
148
149     return( 30 );
150 }
151
152 /*****************************************************************************
153  * vout_Create: allocates FB video thread output method
154  *****************************************************************************
155  * This function allocates and initializes a FB vout method.
156  *****************************************************************************/
157 static int vout_Create( vout_thread_t *p_vout )
158 {
159     struct sigaction    sig_tty;                 /* sigaction for tty change */
160     struct vt_mode      vt_mode;                          /* vt current mode */
161     struct termios      new_termios;
162
163     /* Allocate instance and initialize some members */
164     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
165     if( p_vout->p_sys == NULL )
166     {
167         return( 1 );
168     };
169
170     /* Set tty and fb devices */
171     p_vout->p_sys->i_tty_dev = 0;       /* 0 == /dev/tty0 == current console */
172
173     FBGfxMode( p_vout->p_sys->i_tty_dev );
174
175     /* Set keyboard settings */
176     if (tcgetattr(0, &p_vout->p_sys->old_termios) == -1)
177     {
178         intf_ErrMsg( "intf error: tcgetattr" );
179     }
180
181     if (tcgetattr(0, &new_termios) == -1)
182     {
183         intf_ErrMsg( "intf error: tcgetattr" );
184     }
185
186  /* new_termios.c_lflag &= ~ (ICANON | ISIG);
187     new_termios.c_lflag |= (ECHO | ECHOCTL); */
188     new_termios.c_lflag &= ~ (ICANON);
189     new_termios.c_lflag &= ~(ECHO | ECHOCTL);
190     new_termios.c_iflag = 0;
191     new_termios.c_cc[VMIN] = 1;
192     new_termios.c_cc[VTIME] = 0;
193
194     if (tcsetattr(0, TCSAFLUSH, &new_termios) == -1)
195     {
196         intf_ErrMsg( "intf error: tcsetattr" );
197     }
198
199     ioctl(p_vout->p_sys->i_tty_dev, VT_RELDISP, VT_ACKACQ);
200
201     /* Set-up tty signal handler to be aware of tty changes */
202     memset( &sig_tty, 0, sizeof( sig_tty ) );
203     sig_tty.sa_handler = FBSwitchDisplay;
204     sigemptyset( &sig_tty.sa_mask );
205     if( sigaction( SIGUSR1, &sig_tty, &p_vout->p_sys->sig_usr1 ) ||
206         sigaction( SIGUSR2, &sig_tty, &p_vout->p_sys->sig_usr2 ) )
207     {
208         intf_ErrMsg( "intf error: can't set up signal handler (%s)",
209                      strerror(errno) );
210         tcsetattr(0, 0, &p_vout->p_sys->old_termios);
211         FBTextMode( p_vout->p_sys->i_tty_dev );
212         free( p_vout->p_sys );
213         return( 1 );
214     }
215
216     /* Set-up tty according to new signal handler */
217     if( ioctl(p_vout->p_sys->i_tty_dev, VT_GETMODE, &p_vout->p_sys->vt_mode)
218         == -1 )
219     {
220         intf_ErrMsg( "intf error: cant get terminal mode (%s)",
221                      strerror(errno) );
222         sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
223         sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
224         tcsetattr(0, 0, &p_vout->p_sys->old_termios);
225         FBTextMode( p_vout->p_sys->i_tty_dev );
226         free( p_vout->p_sys );
227         return( 1 );
228     }
229     memcpy( &vt_mode, &p_vout->p_sys->vt_mode, sizeof( vt_mode ) );
230     vt_mode.mode   = VT_PROCESS;
231     vt_mode.waitv  = 0;
232     vt_mode.relsig = SIGUSR1;
233     vt_mode.acqsig = SIGUSR2;
234
235     if( ioctl(p_vout->p_sys->i_tty_dev, VT_SETMODE, &vt_mode) == -1 )
236     {
237         intf_ErrMsg( "intf error: can't set terminal mode (%s)",
238                      strerror(errno) );
239         sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
240         sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
241         tcsetattr(0, 0, &p_vout->p_sys->old_termios);
242         FBTextMode( p_vout->p_sys->i_tty_dev );
243         free( p_vout->p_sys );
244         return( 1 );
245     }
246
247     if( FBOpenDisplay( p_vout ) )
248     {
249         ioctl(p_vout->p_sys->i_tty_dev, VT_SETMODE, &p_vout->p_sys->vt_mode);
250         sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
251         sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
252         tcsetattr(0, 0, &p_vout->p_sys->old_termios);
253         FBTextMode( p_vout->p_sys->i_tty_dev );
254         free( p_vout->p_sys );
255         return( 1 );
256     }
257
258     return( 0 );
259 }
260
261 /*****************************************************************************
262  * vout_Init: initialize framebuffer video thread output method
263  *****************************************************************************/
264 static int vout_Init( vout_thread_t *p_vout )
265 {
266     /* Clear the screen */
267     memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size * 2 );
268
269     return( 0 );
270 }
271
272 /*****************************************************************************
273  * vout_End: terminate framebuffer video thread output method
274  *****************************************************************************/
275 static void vout_End( vout_thread_t *p_vout )
276 {
277     /* Clear the screen */
278     memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size * 2 );
279 }
280
281 /*****************************************************************************
282  * vout_Destroy: destroy FB video thread output method
283  *****************************************************************************
284  * Terminate an output method created by vout_CreateOutputMethod
285  *****************************************************************************/
286 static void vout_Destroy( vout_thread_t *p_vout )
287 {
288     FBCloseDisplay( p_vout );
289
290     /* Reset the terminal */
291     ioctl(p_vout->p_sys->i_tty_dev, VT_SETMODE, &p_vout->p_sys->vt_mode);
292
293     /* Remove signal handlers */
294     sigaction( SIGUSR1, &p_vout->p_sys->sig_usr1, NULL );
295     sigaction( SIGUSR2, &p_vout->p_sys->sig_usr2, NULL );
296
297     /* Reset the keyboard state */
298     tcsetattr( 0, 0, &p_vout->p_sys->old_termios );
299
300     /* Return to text mode */
301     FBTextMode( p_vout->p_sys->i_tty_dev );
302
303     /* Destroy structure */
304     free( p_vout->p_sys );
305 }
306
307 /*****************************************************************************
308  * vout_Manage: handle FB events
309  *****************************************************************************
310  * This function should be called regularly by video output thread. It manages
311  * console events. It returns a non null value on error.
312  *****************************************************************************/
313 static int vout_Manage( vout_thread_t *p_vout )
314 {
315 #if 0
316     u8 buf;
317
318     if ( read(0, &buf, 1) == 1)
319     {
320         switch( buf )
321         {
322         case 'q':
323             p_main->p_intf->b_die = 1;
324             break;
325
326         default:
327             break;
328         }
329     }
330 #endif
331
332     /*
333      * Size change
334      */
335     if( p_vout->i_changes & VOUT_SIZE_CHANGE )
336     {
337         intf_WarnMsg( 3, "vout: reinitializing framebuffer screen" );
338         p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
339
340         /* Destroy XImages to change their size */
341         vout_End( p_vout );
342
343         /* Recreate XImages. If SysInit failed, the thread can't go on. */
344         if( vout_Init( p_vout ) )
345         {
346             intf_ErrMsg("error: cannot reinit framebuffer screen" );
347             return( 1 );
348         }
349
350         /* Clear screen */
351         memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size * 2 );
352
353 #if 1
354         /* Tell the video output thread that it will need to rebuild YUV
355          * tables. This is needed since conversion buffer size may have changed */
356         p_vout->i_changes |= VOUT_YUV_CHANGE;
357 #endif
358     }
359
360     return 0;
361 }
362
363 /*****************************************************************************
364  * vout_Display: displays previously rendered output
365  *****************************************************************************
366  * This function send the currently rendered image to FB image, waits until
367  * it is displayed and switch the two rendering buffers, preparing next frame.
368  *****************************************************************************/
369 static void vout_Display( vout_thread_t *p_vout )
370 {
371     /* swap the two Y offsets if the drivers supports panning */
372     if( p_vout->p_sys->b_pan )
373     {
374         p_vout->p_sys->var_info.yoffset =
375             p_vout->i_buffer_index ? p_vout->p_sys->var_info.yres : 0;
376    
377         /* the X offset should be 0, but who knows ...
378          * some other app might have played with the framebuffer */
379         p_vout->p_sys->var_info.xoffset = 0;
380
381         ioctl( p_vout->p_sys->i_fb_dev,
382                FBIOPAN_DISPLAY, &p_vout->p_sys->var_info );
383     }
384 }
385
386 /*****************************************************************************
387  * vout_SetPalette: sets an 8 bpp palette
388  *****************************************************************************
389  * This function sets the palette given as an argument. It does not return
390  * anything, but could later send information on which colors it was unable
391  * to set.
392  *****************************************************************************/
393 static void vout_SetPalette( p_vout_thread_t p_vout,
394                              u16 *red, u16 *green, u16 *blue, u16 *transp )
395 {
396     struct fb_cmap cmap = { 0, 256, red, green, blue, transp };
397
398     ioctl( p_vout->p_sys->i_fb_dev, FBIOPUTCMAP, &cmap );
399 }
400
401 /* following functions are local */
402
403 /*****************************************************************************
404  * FBOpenDisplay: initialize framebuffer
405  *****************************************************************************/
406 static int FBOpenDisplay( vout_thread_t *p_vout )
407 {
408     char *psz_device;                             /* framebuffer device path */
409     struct fb_fix_screeninfo    fix_info;     /* framebuffer fix information */
410
411     /* Open framebuffer device */
412     psz_device = main_GetPszVariable( VOUT_FB_DEV_VAR, VOUT_FB_DEV_DEFAULT );
413     p_vout->p_sys->i_fb_dev = open( psz_device, O_RDWR);
414     if( p_vout->p_sys->i_fb_dev == -1 )
415     {
416         intf_ErrMsg("vout error: can't open %s (%s)", psz_device, strerror(errno) );
417         return( 1 );
418     }
419
420     /* Get framebuffer device informations */
421     if( ioctl( p_vout->p_sys->i_fb_dev, FBIOGET_VSCREENINFO, &p_vout->p_sys->var_info ) )
422     {
423         intf_ErrMsg("vout error: can't get fb info (%s)", strerror(errno) );
424         close( p_vout->p_sys->i_fb_dev );
425         return( 1 );
426     }
427
428     if( ioctl( p_vout->p_sys->i_fb_dev, FBIOGET_VSCREENINFO, &p_vout->p_sys->old_info ) )
429     {
430         intf_ErrMsg("vout error: can't get 2nd fb info (%s)", strerror(errno) );
431         close( p_vout->p_sys->i_fb_dev );
432         return( 1 );
433     }
434
435     /* Set some attributes */
436     p_vout->p_sys->var_info.activate = FB_ACTIVATE_NXTOPEN;
437     p_vout->p_sys->var_info.xoffset =  0;
438     p_vout->p_sys->var_info.yoffset =  0;
439
440     if( ioctl( p_vout->p_sys->i_fb_dev, FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info ) )
441     {
442         intf_ErrMsg(" vout error: can't set fb info (%s)", strerror(errno) );
443         close( p_vout->p_sys->i_fb_dev );
444         return( 1 );
445     }
446
447     /* Get some informations again, in the definitive configuration */
448     if( ioctl( p_vout->p_sys->i_fb_dev, FBIOGET_FSCREENINFO, &fix_info ) ||
449         ioctl( p_vout->p_sys->i_fb_dev, FBIOGET_VSCREENINFO, &p_vout->p_sys->var_info ) )
450     {
451         intf_ErrMsg(" vout error: can't get additional fb info (%s)", strerror(errno) );
452
453         /* Restore fb config */
454         ioctl( p_vout->p_sys->i_fb_dev, FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info );
455
456         close( p_vout->p_sys->i_fb_dev );
457         return( 1 );
458     }
459
460     /* FIXME: if the image is full-size, it gets cropped on the left
461      * because of the xres / xres_virtual slight difference */
462     intf_WarnMsg( 3, "vout: %ix%i (virtual %ix%i)",
463                   p_vout->p_sys->var_info.xres,
464                   p_vout->p_sys->var_info.yres,
465                   p_vout->p_sys->var_info.xres_virtual,
466                   p_vout->p_sys->var_info.yres_virtual );
467
468     p_vout->i_height = p_vout->p_sys->var_info.yres;
469     p_vout->i_width  = p_vout->p_sys->var_info.xres_virtual ?
470                            p_vout->p_sys->var_info.xres_virtual
471                            : p_vout->p_sys->var_info.xres;
472
473     p_vout->i_screen_depth = p_vout->p_sys->var_info.bits_per_pixel;
474
475     p_vout->p_sys->fb_palette = NULL;
476     p_vout->p_sys->b_pan = ( fix_info.ypanstep || fix_info.ywrapstep );
477
478     switch( p_vout->i_screen_depth )
479     {
480     case 8:                                                         /* 8 bpp */
481         p_vout->p_sys->fb_palette = malloc( 8 * 256 * sizeof( u16 ) );
482         p_vout->p_sys->fb_cmap.start = 0;
483         p_vout->p_sys->fb_cmap.len = 256;
484         p_vout->p_sys->fb_cmap.red = p_vout->p_sys->fb_palette;
485         p_vout->p_sys->fb_cmap.green = p_vout->p_sys->fb_palette + 256 * sizeof( u16 );
486         p_vout->p_sys->fb_cmap.blue = p_vout->p_sys->fb_palette + 2 * 256 * sizeof( u16 );
487         p_vout->p_sys->fb_cmap.transp = p_vout->p_sys->fb_palette + 3 * 256 * sizeof( u16 );
488
489         /* Save the colormap */
490         ioctl( p_vout->p_sys->i_fb_dev, FBIOGETCMAP, &p_vout->p_sys->fb_cmap );
491
492         p_vout->i_bytes_per_pixel = 1;
493         p_vout->i_bytes_per_line = p_vout->i_width;
494         break;
495
496     case 15:                      /* 15 bpp (16bpp with a missing green bit) */
497     case 16:                                        /* 16 bpp (65536 colors) */
498         p_vout->i_bytes_per_pixel = 2;
499         p_vout->i_bytes_per_line = p_vout->i_width * 2;
500         break;
501
502     case 24:                                  /* 24 bpp (millions of colors) */
503         p_vout->i_bytes_per_pixel = 3;
504         p_vout->i_bytes_per_line = p_vout->i_width * 3;
505         break;
506
507     case 32:                                  /* 32 bpp (millions of colors) */
508         p_vout->i_bytes_per_pixel = 4;
509         p_vout->i_bytes_per_line = p_vout->i_width * 4;
510         break;
511
512     default:                                     /* unsupported screen depth */
513         intf_ErrMsg( "vout error: screen depth %d is not supported",
514                      p_vout->i_screen_depth);
515
516         /* Restore fb config */
517         ioctl( p_vout->p_sys->i_fb_dev, FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info );
518
519         close( p_vout->p_sys->i_fb_dev );
520         return( 1 );
521         break;
522     }
523
524     switch( p_vout->i_screen_depth )
525     {
526     case 15:
527     case 16:
528     case 24:
529     case 32:
530         p_vout->i_red_mask =    ( (1 << p_vout->p_sys->var_info.red.length) - 1 )
531                                     << p_vout->p_sys->var_info.red.offset;
532         p_vout->i_green_mask =    ( (1 << p_vout->p_sys->var_info.green.length) - 1 )
533                                     << p_vout->p_sys->var_info.green.offset;
534         p_vout->i_blue_mask =    ( (1 << p_vout->p_sys->var_info.blue.length) - 1 )
535                                     << p_vout->p_sys->var_info.blue.offset;
536     }
537
538     p_vout->p_sys->i_page_size = p_vout->i_width *
539                 p_vout->i_height * p_vout->i_bytes_per_pixel;
540
541     /* Map two framebuffers a the very beginning of the fb */
542     p_vout->p_sys->p_video = mmap( 0, p_vout->p_sys->i_page_size * 2,
543                                    PROT_READ | PROT_WRITE, MAP_SHARED,
544                                    p_vout->p_sys->i_fb_dev, 0 );
545
546     if( (int)p_vout->p_sys->p_video == -1 ) /* according to man, it is -1.
547                                                What about NULL ? */
548     {
549         intf_ErrMsg("vout error: can't map video memory (%s)", strerror(errno) );
550         /* FIXME: restore fb config ?? */
551         if( p_vout->i_screen_depth == 8 )
552         {
553             free( p_vout->p_sys->fb_palette );
554         }
555
556         /* Restore fb config */
557         ioctl( p_vout->p_sys->i_fb_dev, FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info );
558
559         close( p_vout->p_sys->i_fb_dev );
560         return( 1 );
561     }
562
563     /* Set and initialize buffers */
564     if( p_vout->p_sys->b_pan )
565     {
566         vout_SetBuffers( p_vout, p_vout->p_sys->p_video,
567                                  p_vout->p_sys->p_video
568                                   + p_vout->p_sys->i_page_size );
569     }
570     else
571     {
572         vout_SetBuffers( p_vout, p_vout->p_sys->p_video,
573                                  p_vout->p_sys->p_video );
574     }
575     
576     intf_WarnMsg( 3, "framebuffer type=%d, visual=%d, ypanstep=%d, ywrap=%d, accel=%d",
577                   fix_info.type, fix_info.visual, fix_info.ypanstep, fix_info.ywrapstep, fix_info.accel );
578     return( 0 );
579 }
580
581 /*****************************************************************************
582  * FBCloseDisplay: terminate FB video thread output method
583  *****************************************************************************/
584 static void FBCloseDisplay( vout_thread_t *p_vout )
585 {
586     /* Clear display */
587     memset( p_vout->p_sys->p_video, 0, p_vout->p_sys->i_page_size * 2 );
588
589     /* Restore palette */
590     if( p_vout->i_screen_depth == 8 );
591     {
592         ioctl( p_vout->p_sys->i_fb_dev, FBIOPUTCMAP, &p_vout->p_sys->fb_cmap );
593         free( p_vout->p_sys->fb_palette );
594     }
595
596     /* Restore fb config */
597     ioctl( p_vout->p_sys->i_fb_dev, FBIOPUT_VSCREENINFO, &p_vout->p_sys->var_info );
598
599     /* Close fb */
600     close( p_vout->p_sys->i_fb_dev );
601 }
602
603 /*****************************************************************************
604  * FBSwitchDisplay: VT change signal handler
605  *****************************************************************************
606  * This function activates or deactivates the output of the thread. It is
607  * called by the VT driver, on terminal change.
608  *****************************************************************************/
609 static void FBSwitchDisplay(int i_signal)
610 {
611     vout_thread_t *p_vout;
612
613     vlc_mutex_lock( &p_vout_bank->lock );
614
615     /* XXX: only test the first video output */
616     if( p_vout_bank->i_count )
617     {
618         p_vout = p_vout_bank->pp_vout[0];
619
620         switch( i_signal )
621         {
622         case SIGUSR1:                                /* vt has been released */
623             p_vout->b_active = 0;
624             ioctl( p_vout->p_sys->i_tty_dev, VT_RELDISP, 1 );
625             break;
626         case SIGUSR2:                                /* vt has been acquired */
627             p_vout->b_active = 1;
628             ioctl( p_vout->p_sys->i_tty_dev, VT_RELDISP, VT_ACTIVATE );
629             /* handle blanking */
630             vlc_mutex_lock( &p_vout->change_lock );
631             p_vout->i_changes |= VOUT_SIZE_CHANGE;
632             vlc_mutex_unlock( &p_vout->change_lock );
633             break;
634         }
635     }
636
637     vlc_mutex_unlock( &p_vout_bank->lock );
638 }
639
640 /*****************************************************************************
641  * FBTextMode and FBGfxMode : switch tty to text/graphic mode
642  *****************************************************************************
643  * These functions toggle the tty mode.
644  *****************************************************************************/
645 static void FBTextMode( int i_tty_dev )
646 {
647     /* return to text mode */
648     if (-1 == ioctl(i_tty_dev, KDSETMODE, KD_TEXT))
649     {
650         intf_ErrMsg( "intf error: failed ioctl KDSETMODE KD_TEXT" );
651     }
652 }
653
654 static void FBGfxMode( int i_tty_dev )
655 {
656     /* switch to graphic mode */
657     if (-1 == ioctl(i_tty_dev, KDSETMODE, KD_GRAPHICS))
658     {
659         intf_ErrMsg( "intf error: failed ioctl KDSETMODE KD_GRAPHICS" );
660     }
661 }
662