Qt: it's Qt::Key_Backspace not Qt::Key_Back
[vlc.git] / modules / video_output / svgalib.c
blobfb50526cbc3a6a6993f63d5c7223b1fdfc963d18
1 /*****************************************************************************
2 * svgalib.c : SVGAlib plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 the VideoLAN team
5 * $Id$
7 * Authors: Samuel Hocevar <sam@zoy.org>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_vout.h>
35 #include <vlc_interface.h>
37 #include <vga.h>
38 #include <vgagl.h>
39 #include <vgakeyboard.h>
41 /*****************************************************************************
42 * Local prototypes
43 *****************************************************************************/
44 static int Create ( vlc_object_t * );
45 static void Destroy ( vlc_object_t * );
47 static int Init ( vout_thread_t * );
48 static void End ( vout_thread_t * );
49 static int Manage ( vout_thread_t * );
50 static void Display ( vout_thread_t *, picture_t * );
52 static void SetPalette( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
54 /*****************************************************************************
55 * Module descriptor
56 *****************************************************************************/
57 vlc_module_begin ()
58 set_shortname( "SVGAlib" )
59 set_category( CAT_VIDEO )
60 set_subcategory( SUBCAT_VIDEO_VOUT )
61 set_description( N_("SVGAlib video output") )
62 set_capability( "video output", 0 )
63 set_callbacks( Create, Destroy )
64 linked_with_a_crap_library_which_uses_atexit ()
65 vlc_module_end ()
67 /*****************************************************************************
68 * vout_sys_t: video output descriptor
69 *****************************************************************************
70 * This structure is part of the video output thread descriptor.
71 * It describes the SVGAlib specific properties of an output thread.
72 *****************************************************************************/
73 struct vout_sys_t
75 int i_vgamode;
78 /*****************************************************************************
79 * Create: allocates video thread
80 *****************************************************************************
81 * This function allocates and initializes a vout method.
82 *****************************************************************************/
83 static int Create( vlc_object_t *p_this )
85 vout_thread_t *p_vout = (vout_thread_t *)p_this;
87 /* Allocate instance and initialize some members */
88 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
89 if( p_vout->p_sys == NULL )
91 return VLC_ENOMEM;
94 /* FIXME: find a way to test for SVGAlib availability. We cannot call
95 * vga_init from here because it needs to be closed from the same thread
96 * and we might give away the video output to another thread. Bah, it
97 * doesn't matter anyway ... SVGAlib is being an UGLY DIRTY PIG and calls
98 * atexit() and exit() so what can we do? */
100 p_vout->pf_init = Init;
101 p_vout->pf_end = End;
102 p_vout->pf_manage = Manage;
103 p_vout->pf_render = NULL;
104 p_vout->pf_display = Display;
106 return VLC_SUCCESS;
109 /*****************************************************************************
110 * Init: initialize video thread
111 *****************************************************************************/
112 static int Init( vout_thread_t *p_vout )
114 int i_index;
115 picture_t *p_pic;
117 I_OUTPUTPICTURES = 0;
119 /* SVGAlib shut up! */
120 vga_disabledriverreport();
122 /* We cannot call vga_init() in Create() because it has to be run
123 * from the same thread as the other vga calls. */
124 vga_init();
126 /* Check that we have a 8bpp mode available */
127 p_vout->p_sys->i_vgamode = vga_getdefaultmode();
128 if( p_vout->p_sys->i_vgamode == -1
129 || vga_getmodeinfo(p_vout->p_sys->i_vgamode)->bytesperpixel != 1 )
131 p_vout->p_sys->i_vgamode = G320x200x256;
134 if( !vga_hasmode( p_vout->p_sys->i_vgamode ) )
136 msg_Err( p_vout, "mode %i not available", p_vout->p_sys->i_vgamode );
137 return VLC_EGENERIC;
140 vga_setmode( p_vout->p_sys->i_vgamode );
141 gl_setcontextvga( p_vout->p_sys->i_vgamode );
142 gl_enableclipping();
144 if( keyboard_init() )
146 msg_Err( p_vout, "could not initialize keyboard" );
147 vga_setmode( TEXT );
148 return VLC_EGENERIC;
151 /* Just in case */
152 keyboard_translatekeys( TRANSLATE_CURSORKEYS |
153 TRANSLATE_KEYPADENTER |
154 TRANSLATE_DIAGONAL );
156 /* Initialize the output structure: RGB with square pixels, whatever
157 * the input format is, since it's the only format we know */
158 p_vout->output.i_chroma = VLC_CODEC_RGB8;
159 p_vout->output.pf_setpalette = SetPalette;
160 p_vout->output.i_width = vga_getxdim();
161 p_vout->output.i_height = vga_getydim();
162 p_vout->output.i_aspect = p_vout->output.i_width
163 * VOUT_ASPECT_FACTOR / p_vout->output.i_height;
165 /* Try to initialize 1 direct buffer */
166 p_pic = NULL;
168 /* Find an empty picture slot */
169 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
171 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
173 p_pic = p_vout->p_picture + i_index;
174 break;
178 /* Allocate the picture */
179 if( p_pic == NULL )
181 return VLC_SUCCESS;
184 vout_AllocatePicture( p_vout, p_pic, p_vout->output.i_chroma,
185 p_vout->output.i_width, p_vout->output.i_height,
186 p_vout->output.i_aspect * p_vout->output.i_height,
187 VOUT_ASPECT_FACTOR * p_vout->output.i_width );
189 if( p_pic->i_planes == 0 )
191 return VLC_SUCCESS;
194 p_pic->i_status = DESTROYED_PICTURE;
195 p_pic->i_type = DIRECT_PICTURE;
197 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
199 I_OUTPUTPICTURES++;
201 return VLC_SUCCESS;
204 /*****************************************************************************
205 * End: terminate video thread
206 *****************************************************************************/
207 static void End( vout_thread_t *p_vout )
209 keyboard_close();
210 vga_clear();
211 vga_setmode( TEXT );
214 /*****************************************************************************
215 * Destroy: destroy video thread
216 *****************************************************************************
217 * Terminate an output method created by Create
218 *****************************************************************************/
219 static void Destroy( vlc_object_t *p_this )
221 vout_thread_t *p_vout = (vout_thread_t *)p_this;
223 /* Destroy structure */
224 free( p_vout->p_sys );
227 /*****************************************************************************
228 * Manage: handle SVGAlib events
229 *****************************************************************************
230 * This function should be called regularly by video output thread. It manages
231 * console events. It returns a non null value on error.
232 *****************************************************************************/
233 static int Manage( vout_thread_t *p_vout )
235 keyboard_update();
237 if( keyboard_keypressed(SCANCODE_ESCAPE)
238 || keyboard_keypressed(SCANCODE_Q ) )
240 libvlc_Quit( p_vout->p_libvlc );
243 return VLC_SUCCESS;
246 /*****************************************************************************
247 * Display: displays previously rendered output
248 *****************************************************************************
249 * This function sends the currently rendered image to the VGA card.
250 *****************************************************************************/
251 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
253 gl_putbox( 0, 0, p_vout->output.i_width,
254 p_vout->output.i_height, p_pic->p->p_pixels );
257 /*****************************************************************************
258 * SetPalette: set a 8bpp palette
259 *****************************************************************************
260 * TODO: support 8 bits clut (for Mach32 cards and others).
261 *****************************************************************************/
262 static void SetPalette( vout_thread_t *p_vout,
263 uint16_t *red, uint16_t *green, uint16_t *blue )
265 int i = 256;
267 while( i-- )
269 vga_setpalette( i, red[i]>>10, green[i]>>10, blue[i]>>10 );