1 /*****************************************************************************
2 * svgalib.c : SVGAlib plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 the VideoLAN team
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 /*****************************************************************************
26 *****************************************************************************/
34 #include <vgakeyboard.h>
36 /*****************************************************************************
38 *****************************************************************************/
39 static int Create ( vlc_object_t * );
40 static void Destroy ( vlc_object_t * );
42 static int Init ( vout_thread_t * );
43 static void End ( vout_thread_t * );
44 static int Manage ( vout_thread_t * );
45 static void Display ( vout_thread_t *, picture_t * );
47 static void SetPalette( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
49 /*****************************************************************************
51 *****************************************************************************/
53 set_shortname( "SVGAlib" );
54 set_category( CAT_VIDEO );
55 set_subcategory( SUBCAT_VIDEO_VOUT );
56 set_description( _("SVGAlib video output") );
57 set_capability( "video output", 0 );
58 set_callbacks( Create, Destroy );
59 linked_with_a_crap_library_which_uses_atexit();
62 /*****************************************************************************
63 * vout_sys_t: video output descriptor
64 *****************************************************************************
65 * This structure is part of the video output thread descriptor.
66 * It describes the SVGAlib specific properties of an output thread.
67 *****************************************************************************/
73 /*****************************************************************************
74 * Create: allocates video thread
75 *****************************************************************************
76 * This function allocates and initializes a vout method.
77 *****************************************************************************/
78 static int Create( vlc_object_t *p_this )
80 vout_thread_t *p_vout = (vout_thread_t *)p_this;
82 /* Allocate instance and initialize some members */
83 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
84 if( p_vout->p_sys == NULL )
89 /* FIXME: find a way to test for SVGAlib availability. We cannot call
90 * vga_init from here because it needs to be closed from the same thread
91 * and we might give away the video output to another thread. Bah, it
92 * doesn't matter anyway ... SVGAlib is being an UGLY DIRTY PIG and calls
93 * atexit() and exit() so what can we do? */
95 p_vout->pf_init = Init;
97 p_vout->pf_manage = Manage;
98 p_vout->pf_render = NULL;
99 p_vout->pf_display = Display;
104 /*****************************************************************************
105 * Init: initialize video thread
106 *****************************************************************************/
107 static int Init( vout_thread_t *p_vout )
112 I_OUTPUTPICTURES = 0;
114 /* SVGAlib shut up! */
115 vga_disabledriverreport();
117 /* We cannot call vga_init() in Create() because it has to be run
118 * from the same thread as the other vga calls. */
121 /* Check that we have a 8bpp mode available */
122 p_vout->p_sys->i_vgamode = vga_getdefaultmode();
123 if( p_vout->p_sys->i_vgamode == -1
124 || vga_getmodeinfo(p_vout->p_sys->i_vgamode)->bytesperpixel != 1 )
126 p_vout->p_sys->i_vgamode = G320x200x256;
129 if( !vga_hasmode( p_vout->p_sys->i_vgamode ) )
131 msg_Err( p_vout, "mode %i not available", p_vout->p_sys->i_vgamode );
135 vga_setmode( p_vout->p_sys->i_vgamode );
136 gl_setcontextvga( p_vout->p_sys->i_vgamode );
139 if( keyboard_init() )
141 msg_Err( p_vout, "could not initialize keyboard" );
147 keyboard_translatekeys( TRANSLATE_CURSORKEYS |
148 TRANSLATE_KEYPADENTER |
149 TRANSLATE_DIAGONAL );
151 /* Initialize the output structure: RGB with square pixels, whatever
152 * the input format is, since it's the only format we know */
153 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
154 p_vout->output.pf_setpalette = SetPalette;
155 p_vout->output.i_width = vga_getxdim();
156 p_vout->output.i_height = vga_getydim();
157 p_vout->output.i_aspect = p_vout->output.i_width
158 * VOUT_ASPECT_FACTOR / p_vout->output.i_height;
160 /* Try to initialize 1 direct buffer */
163 /* Find an empty picture slot */
164 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
166 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
168 p_pic = p_vout->p_picture + i_index;
173 /* Allocate the picture */
179 vout_AllocatePicture( p_vout, p_pic, p_vout->output.i_chroma,
180 p_vout->output.i_width, p_vout->output.i_height,
181 p_vout->output.i_aspect );
183 if( p_pic->i_planes == 0 )
188 p_pic->i_status = DESTROYED_PICTURE;
189 p_pic->i_type = DIRECT_PICTURE;
191 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
198 /*****************************************************************************
199 * End: terminate video thread
200 *****************************************************************************/
201 static void End( vout_thread_t *p_vout )
208 /*****************************************************************************
209 * Destroy: destroy video thread
210 *****************************************************************************
211 * Terminate an output method created by Create
212 *****************************************************************************/
213 static void Destroy( vlc_object_t *p_this )
215 vout_thread_t *p_vout = (vout_thread_t *)p_this;
217 /* Destroy structure */
218 free( p_vout->p_sys );
221 /*****************************************************************************
222 * Manage: handle SVGAlib events
223 *****************************************************************************
224 * This function should be called regularly by video output thread. It manages
225 * console events. It returns a non null value on error.
226 *****************************************************************************/
227 static int Manage( vout_thread_t *p_vout )
231 if( keyboard_keypressed(SCANCODE_ESCAPE)
232 || keyboard_keypressed(SCANCODE_Q ) )
234 p_vout->p_vlc->b_die = VLC_TRUE;
240 /*****************************************************************************
241 * Display: displays previously rendered output
242 *****************************************************************************
243 * This function sends the currently rendered image to the VGA card.
244 *****************************************************************************/
245 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
247 gl_putbox( 0, 0, p_vout->output.i_width,
248 p_vout->output.i_height, p_pic->p->p_pixels );
251 /*****************************************************************************
252 * SetPalette: set a 8bpp palette
253 *****************************************************************************
254 * TODO: support 8 bits clut (for Mach32 cards and others).
255 *****************************************************************************/
256 static void SetPalette( vout_thread_t *p_vout,
257 uint16_t *red, uint16_t *green, uint16_t *blue )
263 vga_setpalette( i, red[i]>>10, green[i]>>10, blue[i]>>10 );