1 /*****************************************************************************
2 * glide.c : 3dfx Glide plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 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 *****************************************************************************/
27 #include <errno.h> /* ENOMEM */
30 #include <vlc_interface.h>
34 # include <conio.h> /* for glide ? */
37 #include <linutil.h> /* Glide kbhit() and getch() */
39 #define GLIDE_WIDTH 800
40 #define GLIDE_HEIGHT 600
41 #define GLIDE_BITS_PER_PLANE 16
42 #define GLIDE_BYTES_PER_PIXEL 2
44 /*****************************************************************************
46 *****************************************************************************/
47 static int Create ( vlc_object_t * );
48 static void Destroy ( vlc_object_t * );
50 static int Init ( vout_thread_t * );
51 static void End ( vout_thread_t * );
52 static int Manage ( vout_thread_t * );
53 static void Display ( vout_thread_t *, picture_t * );
55 static int OpenDisplay ( vout_thread_t * );
56 static void CloseDisplay ( vout_thread_t * );
58 /*****************************************************************************
60 *****************************************************************************/
62 set_description( _("3dfx Glide video output") );
63 set_capability( "video output", 20 );
64 add_shortcut( "3dfx" );
65 set_callbacks( Create, Destroy );
68 /*****************************************************************************
69 * vout_sys_t: Glide video output method descriptor
70 *****************************************************************************
71 * This structure is part of the video output thread descriptor.
72 * It describes the Glide specific properties of an output thread.
73 *****************************************************************************/
76 GrLfbInfo_t p_buffer_info; /* back buffer info */
78 uint8_t * pp_buffer[2];
82 /*****************************************************************************
83 * Create: allocates Glide video thread output method
84 *****************************************************************************
85 * This function allocates and initializes a Glide vout method.
86 *****************************************************************************/
87 static int Create( vlc_object_t *p_this )
89 vout_thread_t *p_vout = (vout_thread_t *)p_this;
91 /* Allocate structure */
92 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
93 if( p_vout->p_sys == NULL )
95 msg_Err( p_vout, "out of memory" );
99 /* Open and initialize device */
100 if( OpenDisplay( p_vout ) )
102 msg_Err( p_vout, "cannot open display" );
103 free( p_vout->p_sys );
107 p_vout->pf_init = Init;
108 p_vout->pf_end = End;
109 p_vout->pf_manage = Manage;
110 p_vout->pf_render = NULL;
111 p_vout->pf_display = Display;
116 /*****************************************************************************
117 * Init: initialize Glide video thread output method
118 *****************************************************************************/
119 static int Init( vout_thread_t *p_vout )
124 /* FIXME: we don't set i_chroma !! */
125 p_vout->output.i_rmask = 0xf800;
126 p_vout->output.i_gmask = 0x07e0;
127 p_vout->output.i_bmask = 0x001f;
129 I_OUTPUTPICTURES = 0;
133 /* Find an empty picture slot */
134 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
136 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
138 p_pic = p_vout->p_picture + i_index;
148 /* We know the chroma, allocate a buffer which will be used
149 * directly by the decoder */
152 p_pic->p->p_pixels = p_vout->p_sys->pp_buffer[p_vout->p_sys->i_index];
153 p_pic->p->i_lines = GLIDE_HEIGHT;
154 p_pic->p->i_visible_lines = GLIDE_HEIGHT;
155 p_pic->p->i_pitch = p_vout->p_sys->p_buffer_info.strideInBytes;
156 /*1024 * GLIDE_BYTES_PER_PIXEL*/
157 p_pic->p->i_pixel_pitch = GLIDE_BYTES_PER_PIXEL;
158 p_pic->p->i_visible_pitch = GLIDE_WIDTH * GLIDE_BYTES_PER_PIXEL;
160 p_pic->i_status = DESTROYED_PICTURE;
161 p_pic->i_type = DIRECT_PICTURE;
163 PP_OUTPUTPICTURE[ 0 ] = p_pic;
165 I_OUTPUTPICTURES = 1;
170 /*****************************************************************************
171 * End: terminate Glide video thread output method
172 *****************************************************************************/
173 static void End( vout_thread_t *p_vout )
178 /*****************************************************************************
179 * Destroy: destroy Glide video thread output method
180 *****************************************************************************
181 * Terminate an output method created by Create
182 *****************************************************************************/
183 static void Destroy( vlc_object_t *p_this )
185 vout_thread_t *p_vout = (vout_thread_t *)p_this;
186 CloseDisplay( p_vout );
187 free( p_vout->p_sys );
190 /*****************************************************************************
191 * Manage: handle Glide events
192 *****************************************************************************
193 * This function should be called regularly by video output thread. It manages
194 * console events. It returns a non null value on error.
195 *****************************************************************************/
196 static int Manage( vout_thread_t *p_vout )
200 /* very Linux specific - see tlib.c in Glide for other versions */
208 vlc_object_kill( p_vout->p_libvlc );
219 /*****************************************************************************
220 * Display: displays previously rendered output
221 *****************************************************************************/
222 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
225 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
229 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
230 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
231 &p_vout->p_sys->p_buffer_info) == FXFALSE )
233 msg_Err( p_vout, "cannot take 3dfx back buffer lock" );
237 /* following functions are local */
239 /*****************************************************************************
240 * OpenDisplay: open and initialize 3dfx device
241 *****************************************************************************/
243 static int OpenDisplay( vout_thread_t *p_vout )
245 static char version[80];
246 GrHwConfiguration hwconfig;
247 GrScreenResolution_t resolution = GR_RESOLUTION_800x600;
248 GrLfbInfo_t p_front_buffer_info; /* front buffer info */
250 grGlideGetVersion( version );
253 if( !grSstQueryHardware(&hwconfig) )
255 msg_Err( p_vout, "cannot get 3dfx hardware config" );
260 if( !grSstWinOpen( 0, resolution, GR_REFRESH_60Hz,
261 GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1 ) )
263 msg_Err( p_vout, "cannot open 3dfx screen" );
267 /* disable dithering */
268 /*grDitherMode( GR_DITHER_DISABLE );*/
270 /* clear both buffers */
271 grRenderBuffer( GR_BUFFER_BACKBUFFER );
272 grBufferClear( 0, 0, 0 );
273 grRenderBuffer( GR_BUFFER_FRONTBUFFER );
274 grBufferClear( 0, 0, 0 );
275 grRenderBuffer( GR_BUFFER_BACKBUFFER );
277 p_vout->p_sys->p_buffer_info.size = sizeof( GrLfbInfo_t );
278 p_front_buffer_info.size = sizeof( GrLfbInfo_t );
280 /* lock the buffers to find their adresses */
281 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER,
282 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
283 &p_front_buffer_info) == FXFALSE )
285 msg_Err( p_vout, "cannot take 3dfx front buffer lock" );
289 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER );
291 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
292 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
293 &p_vout->p_sys->p_buffer_info) == FXFALSE )
295 msg_Err( p_vout, "cannot take 3dfx back buffer lock" );
299 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
301 grBufferClear( 0, 0, 0 );
303 p_vout->p_sys->pp_buffer[0] = p_vout->p_sys->p_buffer_info.lfbPtr;
304 p_vout->p_sys->pp_buffer[1] = p_front_buffer_info.lfbPtr;
305 p_vout->p_sys->i_index = 0;
310 /*****************************************************************************
311 * CloseDisplay: close and reset 3dfx device
312 *****************************************************************************
313 * Returns all resources allocated by OpenDisplay and restore the original
314 * state of the device.
315 *****************************************************************************/
316 static void CloseDisplay( vout_thread_t *p_vout )
318 /* unlock the hidden buffer */
319 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );