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 *****************************************************************************/
33 #include <vgakeyboard.h>
35 /*****************************************************************************
37 *****************************************************************************/
38 static int Create ( vlc_object_t * );
39 static void Destroy ( vlc_object_t * );
41 static int Init ( vout_thread_t * );
42 static void End ( vout_thread_t * );
43 static int Manage ( vout_thread_t * );
44 static void Display ( vout_thread_t *, picture_t * );
46 static void SetPalette( vout_thread_t *, uint16_t *, uint16_t *, uint16_t * );
48 /*****************************************************************************
50 *****************************************************************************/
52 set_shortname( "SVGAlib" );
53 set_category( CAT_VIDEO );
54 set_subcategory( SUBCAT_VIDEO_VOUT );
55 set_description( _("SVGAlib video output") );
56 set_capability( "video output", 0 );
57 set_callbacks( Create, Destroy );
58 linked_with_a_crap_library_which_uses_atexit();
61 /*****************************************************************************
62 * vout_sys_t: video output descriptor
63 *****************************************************************************
64 * This structure is part of the video output thread descriptor.
65 * It describes the SVGAlib specific properties of an output thread.
66 *****************************************************************************/
72 /*****************************************************************************
73 * Create: allocates video thread
74 *****************************************************************************
75 * This function allocates and initializes a vout method.
76 *****************************************************************************/
77 static int Create( vlc_object_t *p_this )
79 vout_thread_t *p_vout = (vout_thread_t *)p_this;
81 /* Allocate instance and initialize some members */
82 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
83 if( p_vout->p_sys == NULL )
88 /* FIXME: find a way to test for SVGAlib availability. We cannot call
89 * vga_init from here because it needs to be closed from the same thread
90 * and we might give away the video output to another thread. Bah, it
91 * doesn't matter anyway ... SVGAlib is being an UGLY DIRTY PIG and calls
92 * atexit() and exit() so what can we do? */
94 p_vout->pf_init = Init;
96 p_vout->pf_manage = Manage;
97 p_vout->pf_render = NULL;
98 p_vout->pf_display = Display;
103 /*****************************************************************************
104 * Init: initialize video thread
105 *****************************************************************************/
106 static int Init( vout_thread_t *p_vout )
111 I_OUTPUTPICTURES = 0;
113 /* SVGAlib shut up! */
114 vga_disabledriverreport();
116 /* We cannot call vga_init() in Create() because it has to be run
117 * from the same thread as the other vga calls. */
120 /* Check that we have a 8bpp mode available */
121 p_vout->p_sys->i_vgamode = vga_getdefaultmode();
122 if( p_vout->p_sys->i_vgamode == -1
123 || vga_getmodeinfo(p_vout->p_sys->i_vgamode)->bytesperpixel != 1 )
125 p_vout->p_sys->i_vgamode = G320x200x256;
128 if( !vga_hasmode( p_vout->p_sys->i_vgamode ) )
130 msg_Err( p_vout, "mode %i not available", p_vout->p_sys->i_vgamode );
134 vga_setmode( p_vout->p_sys->i_vgamode );
135 gl_setcontextvga( p_vout->p_sys->i_vgamode );
138 if( keyboard_init() )
140 msg_Err( p_vout, "could not initialize keyboard" );
146 keyboard_translatekeys( TRANSLATE_CURSORKEYS |
147 TRANSLATE_KEYPADENTER |
148 TRANSLATE_DIAGONAL );
150 /* Initialize the output structure: RGB with square pixels, whatever
151 * the input format is, since it's the only format we know */
152 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2');
153 p_vout->output.pf_setpalette = SetPalette;
154 p_vout->output.i_width = vga_getxdim();
155 p_vout->output.i_height = vga_getydim();
156 p_vout->output.i_aspect = p_vout->output.i_width
157 * VOUT_ASPECT_FACTOR / p_vout->output.i_height;
159 /* Try to initialize 1 direct buffer */
162 /* Find an empty picture slot */
163 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
165 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
167 p_pic = p_vout->p_picture + i_index;
172 /* Allocate the picture */
178 vout_AllocatePicture( p_vout, p_pic, p_vout->output.i_chroma,
179 p_vout->output.i_width, p_vout->output.i_height,
180 p_vout->output.i_aspect );
182 if( p_pic->i_planes == 0 )
187 p_pic->i_status = DESTROYED_PICTURE;
188 p_pic->i_type = DIRECT_PICTURE;
190 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
197 /*****************************************************************************
198 * End: terminate video thread
199 *****************************************************************************/
200 static void End( vout_thread_t *p_vout )
207 /*****************************************************************************
208 * Destroy: destroy video thread
209 *****************************************************************************
210 * Terminate an output method created by Create
211 *****************************************************************************/
212 static void Destroy( vlc_object_t *p_this )
214 vout_thread_t *p_vout = (vout_thread_t *)p_this;
216 /* Destroy structure */
217 free( p_vout->p_sys );
220 /*****************************************************************************
221 * Manage: handle SVGAlib events
222 *****************************************************************************
223 * This function should be called regularly by video output thread. It manages
224 * console events. It returns a non null value on error.
225 *****************************************************************************/
226 static int Manage( vout_thread_t *p_vout )
230 if( keyboard_keypressed(SCANCODE_ESCAPE)
231 || keyboard_keypressed(SCANCODE_Q ) )
233 vlc_object_kill( p_vout->p_libvlc );
239 /*****************************************************************************
240 * Display: displays previously rendered output
241 *****************************************************************************
242 * This function sends the currently rendered image to the VGA card.
243 *****************************************************************************/
244 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
246 gl_putbox( 0, 0, p_vout->output.i_width,
247 p_vout->output.i_height, p_pic->p->p_pixels );
250 /*****************************************************************************
251 * SetPalette: set a 8bpp palette
252 *****************************************************************************
253 * TODO: support 8 bits clut (for Mach32 cards and others).
254 *****************************************************************************/
255 static void SetPalette( vout_thread_t *p_vout,
256 uint16_t *red, uint16_t *green, uint16_t *blue )
262 vga_setpalette( i, red[i]>>10, green[i]>>10, blue[i]>>10 );