1 /*****************************************************************************
2 * glide.c : 3dfx Glide plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: glide.c,v 1.17 2002/07/23 00:39:17 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_lines = GLIDE_HEIGHT;
174 p_pic->p->i_pitch = p_vout->p_sys->p_buffer_info.strideInBytes;
175 /*1024 * GLIDE_BYTES_PER_PIXEL*/
176 p_pic->p->i_pixel_pitch = GLIDE_BYTES_PER_PIXEL;
177 p_pic->p->i_visible_pitch = GLIDE_WIDTH * GLIDE_BYTES_PER_PIXEL;
179 p_pic->i_status = DESTROYED_PICTURE;
180 p_pic->i_type = DIRECT_PICTURE;
182 PP_OUTPUTPICTURE[ 0 ] = p_pic;
184 I_OUTPUTPICTURES = 1;
189 /*****************************************************************************
190 * vout_End: terminate Glide video thread output method
191 *****************************************************************************/
192 void vout_End( vout_thread_t *p_vout )
197 /*****************************************************************************
198 * vout_Destroy: destroy Glide video thread output method
199 *****************************************************************************
200 * Terminate an output method created by vout_CreateOutputMethod
201 *****************************************************************************/
202 void vout_Destroy( vout_thread_t *p_vout )
204 CloseDisplay( p_vout );
205 free( p_vout->p_sys );
208 /*****************************************************************************
209 * vout_Manage: handle Glide events
210 *****************************************************************************
211 * This function should be called regularly by video output thread. It manages
212 * console events. It returns a non null value on error.
213 *****************************************************************************/
214 int vout_Manage( vout_thread_t *p_vout )
218 /* very Linux specific - see tlib.c in Glide for other versions */
226 p_vout->p_vlc->b_die = 1;
237 /*****************************************************************************
238 * vout_Render: renders previously calculated output
239 *****************************************************************************/
240 void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
245 /*****************************************************************************
246 * vout_Display: displays previously rendered output
247 *****************************************************************************/
248 void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
251 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
255 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
256 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
257 &p_vout->p_sys->p_buffer_info) == FXFALSE )
259 msg_Err( p_vout, "cannot take 3dfx back buffer lock" );
263 /* following functions are local */
265 /*****************************************************************************
266 * OpenDisplay: open and initialize 3dfx device
267 *****************************************************************************/
269 static int OpenDisplay( vout_thread_t *p_vout )
271 static char version[80];
272 GrHwConfiguration hwconfig;
273 GrScreenResolution_t resolution = GR_RESOLUTION_800x600;
274 GrLfbInfo_t p_front_buffer_info; /* front buffer info */
276 grGlideGetVersion( version );
279 if( !grSstQueryHardware(&hwconfig) )
281 msg_Err( p_vout, "cannot get 3dfx hardware config" );
286 if( !grSstWinOpen( 0, resolution, GR_REFRESH_60Hz,
287 GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1 ) )
289 msg_Err( p_vout, "cannot open 3dfx screen" );
293 /* disable dithering */
294 //grDitherMode( GR_DITHER_DISABLE );
296 /* clear both buffers */
297 grRenderBuffer( GR_BUFFER_BACKBUFFER );
298 grBufferClear( 0, 0, 0 );
299 grRenderBuffer( GR_BUFFER_FRONTBUFFER );
300 grBufferClear( 0, 0, 0 );
301 grRenderBuffer( GR_BUFFER_BACKBUFFER );
303 p_vout->p_sys->p_buffer_info.size = sizeof( GrLfbInfo_t );
304 p_front_buffer_info.size = sizeof( GrLfbInfo_t );
306 /* lock the buffers to find their adresses */
307 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER,
308 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
309 &p_front_buffer_info) == FXFALSE )
311 msg_Err( p_vout, "cannot take 3dfx front buffer lock" );
315 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER );
317 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
318 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
319 &p_vout->p_sys->p_buffer_info) == FXFALSE )
321 msg_Err( p_vout, "cannot take 3dfx back buffer lock" );
325 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
327 grBufferClear( 0, 0, 0 );
329 p_vout->p_sys->pp_buffer[0] = p_vout->p_sys->p_buffer_info.lfbPtr;
330 p_vout->p_sys->pp_buffer[1] = p_front_buffer_info.lfbPtr;
331 p_vout->p_sys->i_index = 0;
336 /*****************************************************************************
337 * CloseDisplay: close and reset 3dfx device
338 *****************************************************************************
339 * Returns all resources allocated by OpenDisplay and restore the original
340 * state of the device.
341 *****************************************************************************/
342 static void CloseDisplay( vout_thread_t *p_vout )
344 /* unlock the hidden buffer */
345 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );