1 /*****************************************************************************
2 * glide.c : 3dfx Glide plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: glide.c,v 1.16 2002/07/20 18:01:42 sam Exp $
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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <errno.h> /* ENOMEM */
28 #include <stdlib.h> /* malloc(), free() */
36 # include <conio.h> /* for glide ? */
39 #include <linutil.h> /* Glide kbhit() and getch() */
41 #define GLIDE_WIDTH 800
42 #define GLIDE_HEIGHT 600
43 #define GLIDE_BITS_PER_PLANE 16
44 #define GLIDE_BYTES_PER_PIXEL 2
46 /*****************************************************************************
48 *****************************************************************************/
49 static void vout_getfunctions( function_list_t * p_function_list );
51 static int vout_Create ( vout_thread_t * );
52 static int vout_Init ( vout_thread_t * );
53 static void vout_End ( vout_thread_t * );
54 static void vout_Destroy ( vout_thread_t * );
55 static int vout_Manage ( vout_thread_t * );
56 static void vout_Render ( vout_thread_t *, picture_t * );
57 static void vout_Display ( vout_thread_t *, picture_t * );
59 static int OpenDisplay ( vout_thread_t * );
60 static void CloseDisplay ( vout_thread_t * );
62 /*****************************************************************************
63 * Building configuration tree
64 *****************************************************************************/
69 SET_DESCRIPTION( _("3dfx Glide module") )
70 ADD_CAPABILITY( VOUT, 20 )
71 ADD_SHORTCUT( "3dfx" )
75 vout_getfunctions( &p_module->p_functions->vout );
78 MODULE_DEACTIVATE_START
79 MODULE_DEACTIVATE_STOP
81 /*****************************************************************************
82 * vout_sys_t: Glide video output method descriptor
83 *****************************************************************************
84 * This structure is part of the video output thread descriptor.
85 * It describes the Glide specific properties of an output thread.
86 *****************************************************************************/
89 GrLfbInfo_t p_buffer_info; /* back buffer info */
95 /*****************************************************************************
96 * Functions exported as capabilities. They are declared as static so that
97 * we don't pollute the namespace too much.
98 *****************************************************************************/
99 void _M( vout_getfunctions )( function_list_t * p_function_list )
101 p_function_list->functions.vout.pf_create = vout_Create;
102 p_function_list->functions.vout.pf_init = vout_Init;
103 p_function_list->functions.vout.pf_end = vout_End;
104 p_function_list->functions.vout.pf_destroy = vout_Destroy;
105 p_function_list->functions.vout.pf_manage = vout_Manage;
106 p_function_list->functions.vout.pf_render = vout_Render;
107 p_function_list->functions.vout.pf_display = vout_Display;
110 /*****************************************************************************
111 * vout_Create: allocates Glide video thread output method
112 *****************************************************************************
113 * This function allocates and initializes a Glide vout method.
114 *****************************************************************************/
115 int vout_Create( vout_thread_t *p_vout )
117 /* Allocate structure */
118 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
119 if( p_vout->p_sys == NULL )
121 msg_Err( p_vout, "out of memory" );
125 /* Open and initialize device */
126 if( OpenDisplay( p_vout ) )
128 msg_Err( p_vout, "cannot open display" );
129 free( p_vout->p_sys );
136 /*****************************************************************************
137 * vout_Init: initialize Glide video thread output method
138 *****************************************************************************/
139 int vout_Init( vout_thread_t *p_vout )
144 /* FIXME: we don't set i_chroma !! */
145 p_vout->output.i_rmask = 0xf800;
146 p_vout->output.i_gmask = 0x07e0;
147 p_vout->output.i_bmask = 0x001f;
149 I_OUTPUTPICTURES = 0;
153 /* Find an empty picture slot */
154 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
156 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
158 p_pic = p_vout->p_picture + i_index;
168 /* We know the chroma, allocate a buffer which will be used
169 * directly by the decoder */
172 p_pic->p->p_pixels = p_vout->p_sys->pp_buffer[p_vout->p_sys->i_index];
173 p_pic->p->i_pixel_bytes = GLIDE_BYTES_PER_PIXEL;
174 p_pic->p->i_lines = GLIDE_HEIGHT;
176 p_pic->p->b_margin = 1;
177 p_pic->p->b_hidden = 1;
178 p_pic->p->i_visible_bytes = GLIDE_WIDTH * GLIDE_BYTES_PER_PIXEL;
179 p_pic->p->i_pitch = p_vout->p_sys->p_buffer_info.strideInBytes;
180 /*1024 * GLIDE_BYTES_PER_PIXEL*/
182 p_pic->i_status = DESTROYED_PICTURE;
183 p_pic->i_type = DIRECT_PICTURE;
185 PP_OUTPUTPICTURE[ 0 ] = p_pic;
187 I_OUTPUTPICTURES = 1;
192 /*****************************************************************************
193 * vout_End: terminate Glide video thread output method
194 *****************************************************************************/
195 void vout_End( vout_thread_t *p_vout )
200 /*****************************************************************************
201 * vout_Destroy: destroy Glide video thread output method
202 *****************************************************************************
203 * Terminate an output method created by vout_CreateOutputMethod
204 *****************************************************************************/
205 void vout_Destroy( vout_thread_t *p_vout )
207 CloseDisplay( p_vout );
208 free( p_vout->p_sys );
211 /*****************************************************************************
212 * vout_Manage: handle Glide events
213 *****************************************************************************
214 * This function should be called regularly by video output thread. It manages
215 * console events. It returns a non null value on error.
216 *****************************************************************************/
217 int vout_Manage( vout_thread_t *p_vout )
221 /* very Linux specific - see tlib.c in Glide for other versions */
229 p_vout->p_vlc->b_die = 1;
240 /*****************************************************************************
241 * vout_Render: renders previously calculated output
242 *****************************************************************************/
243 void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
248 /*****************************************************************************
249 * vout_Display: displays previously rendered output
250 *****************************************************************************/
251 void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
254 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
258 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
259 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
260 &p_vout->p_sys->p_buffer_info) == FXFALSE )
262 msg_Err( p_vout, "cannot take 3dfx back buffer lock" );
266 /* following functions are local */
268 /*****************************************************************************
269 * OpenDisplay: open and initialize 3dfx device
270 *****************************************************************************/
272 static int OpenDisplay( vout_thread_t *p_vout )
274 static char version[80];
275 GrHwConfiguration hwconfig;
276 GrScreenResolution_t resolution = GR_RESOLUTION_800x600;
277 GrLfbInfo_t p_front_buffer_info; /* front buffer info */
279 grGlideGetVersion( version );
282 if( !grSstQueryHardware(&hwconfig) )
284 msg_Err( p_vout, "cannot get 3dfx hardware config" );
289 if( !grSstWinOpen( 0, resolution, GR_REFRESH_60Hz,
290 GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1 ) )
292 msg_Err( p_vout, "cannot open 3dfx screen" );
296 /* disable dithering */
297 //grDitherMode( GR_DITHER_DISABLE );
299 /* clear both buffers */
300 grRenderBuffer( GR_BUFFER_BACKBUFFER );
301 grBufferClear( 0, 0, 0 );
302 grRenderBuffer( GR_BUFFER_FRONTBUFFER );
303 grBufferClear( 0, 0, 0 );
304 grRenderBuffer( GR_BUFFER_BACKBUFFER );
306 p_vout->p_sys->p_buffer_info.size = sizeof( GrLfbInfo_t );
307 p_front_buffer_info.size = sizeof( GrLfbInfo_t );
309 /* lock the buffers to find their adresses */
310 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER,
311 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
312 &p_front_buffer_info) == FXFALSE )
314 msg_Err( p_vout, "cannot take 3dfx front buffer lock" );
318 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER );
320 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
321 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
322 &p_vout->p_sys->p_buffer_info) == FXFALSE )
324 msg_Err( p_vout, "cannot take 3dfx back buffer lock" );
328 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
330 grBufferClear( 0, 0, 0 );
332 p_vout->p_sys->pp_buffer[0] = p_vout->p_sys->p_buffer_info.lfbPtr;
333 p_vout->p_sys->pp_buffer[1] = p_front_buffer_info.lfbPtr;
334 p_vout->p_sys->i_index = 0;
339 /*****************************************************************************
340 * CloseDisplay: close and reset 3dfx device
341 *****************************************************************************
342 * Returns all resources allocated by OpenDisplay and restore the original
343 * state of the device.
344 *****************************************************************************/
345 static void CloseDisplay( vout_thread_t *p_vout )
347 /* unlock the hidden buffer */
348 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );