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 */
34 #include <vlc_plugin.h>
35 #include <vlc_interface.h>
39 # include <conio.h> /* for glide ? */
42 #include <linutil.h> /* Glide kbhit() and getch() */
44 #define GLIDE_WIDTH 800
45 #define GLIDE_HEIGHT 600
46 #define GLIDE_BITS_PER_PLANE 16
47 #define GLIDE_BYTES_PER_PIXEL 2
49 /*****************************************************************************
51 *****************************************************************************/
52 static int Create ( vlc_object_t * );
53 static void Destroy ( vlc_object_t * );
55 static int Init ( vout_thread_t * );
56 static void End ( vout_thread_t * );
57 static int Manage ( vout_thread_t * );
58 static void Display ( vout_thread_t *, picture_t * );
60 static int OpenDisplay ( vout_thread_t * );
61 static void CloseDisplay ( vout_thread_t * );
63 /*****************************************************************************
65 *****************************************************************************/
67 set_description( _("3dfx Glide video output") );
68 set_capability( "video output", 20 );
69 add_shortcut( "3dfx" );
70 set_callbacks( Create, Destroy );
73 /*****************************************************************************
74 * vout_sys_t: Glide video output method descriptor
75 *****************************************************************************
76 * This structure is part of the video output thread descriptor.
77 * It describes the Glide specific properties of an output thread.
78 *****************************************************************************/
81 GrLfbInfo_t p_buffer_info; /* back buffer info */
83 uint8_t * pp_buffer[2];
87 /*****************************************************************************
88 * Create: allocates Glide video thread output method
89 *****************************************************************************
90 * This function allocates and initializes a Glide vout method.
91 *****************************************************************************/
92 static int Create( vlc_object_t *p_this )
94 vout_thread_t *p_vout = (vout_thread_t *)p_this;
96 /* Allocate structure */
97 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
98 if( p_vout->p_sys == NULL )
100 msg_Err( p_vout, "out of memory" );
104 /* Open and initialize device */
105 if( OpenDisplay( p_vout ) )
107 msg_Err( p_vout, "cannot open display" );
108 free( p_vout->p_sys );
112 p_vout->pf_init = Init;
113 p_vout->pf_end = End;
114 p_vout->pf_manage = Manage;
115 p_vout->pf_render = NULL;
116 p_vout->pf_display = Display;
121 /*****************************************************************************
122 * Init: initialize Glide video thread output method
123 *****************************************************************************/
124 static int Init( vout_thread_t *p_vout )
129 /* FIXME: we don't set i_chroma !! */
130 p_vout->output.i_rmask = 0xf800;
131 p_vout->output.i_gmask = 0x07e0;
132 p_vout->output.i_bmask = 0x001f;
134 I_OUTPUTPICTURES = 0;
138 /* Find an empty picture slot */
139 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
141 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
143 p_pic = p_vout->p_picture + i_index;
153 /* We know the chroma, allocate a buffer which will be used
154 * directly by the decoder */
157 p_pic->p->p_pixels = p_vout->p_sys->pp_buffer[p_vout->p_sys->i_index];
158 p_pic->p->i_lines = GLIDE_HEIGHT;
159 p_pic->p->i_visible_lines = GLIDE_HEIGHT;
160 p_pic->p->i_pitch = p_vout->p_sys->p_buffer_info.strideInBytes;
161 /*1024 * GLIDE_BYTES_PER_PIXEL*/
162 p_pic->p->i_pixel_pitch = GLIDE_BYTES_PER_PIXEL;
163 p_pic->p->i_visible_pitch = GLIDE_WIDTH * GLIDE_BYTES_PER_PIXEL;
165 p_pic->i_status = DESTROYED_PICTURE;
166 p_pic->i_type = DIRECT_PICTURE;
168 PP_OUTPUTPICTURE[ 0 ] = p_pic;
170 I_OUTPUTPICTURES = 1;
175 /*****************************************************************************
176 * End: terminate Glide video thread output method
177 *****************************************************************************/
178 static void End( vout_thread_t *p_vout )
183 /*****************************************************************************
184 * Destroy: destroy Glide video thread output method
185 *****************************************************************************
186 * Terminate an output method created by Create
187 *****************************************************************************/
188 static void Destroy( vlc_object_t *p_this )
190 vout_thread_t *p_vout = (vout_thread_t *)p_this;
191 CloseDisplay( p_vout );
192 free( p_vout->p_sys );
195 /*****************************************************************************
196 * Manage: handle Glide events
197 *****************************************************************************
198 * This function should be called regularly by video output thread. It manages
199 * console events. It returns a non null value on error.
200 *****************************************************************************/
201 static int Manage( vout_thread_t *p_vout )
205 /* very Linux specific - see tlib.c in Glide for other versions */
213 vlc_object_kill( p_vout->p_libvlc );
224 /*****************************************************************************
225 * Display: displays previously rendered output
226 *****************************************************************************/
227 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
230 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
234 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
235 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
236 &p_vout->p_sys->p_buffer_info) == FXFALSE )
238 msg_Err( p_vout, "cannot take 3dfx back buffer lock" );
242 /* following functions are local */
244 /*****************************************************************************
245 * OpenDisplay: open and initialize 3dfx device
246 *****************************************************************************/
248 static int OpenDisplay( vout_thread_t *p_vout )
250 static char version[80];
251 GrHwConfiguration hwconfig;
252 GrScreenResolution_t resolution = GR_RESOLUTION_800x600;
253 GrLfbInfo_t p_front_buffer_info; /* front buffer info */
255 grGlideGetVersion( version );
258 if( !grSstQueryHardware(&hwconfig) )
260 msg_Err( p_vout, "cannot get 3dfx hardware config" );
265 if( !grSstWinOpen( 0, resolution, GR_REFRESH_60Hz,
266 GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1 ) )
268 msg_Err( p_vout, "cannot open 3dfx screen" );
272 /* disable dithering */
273 /*grDitherMode( GR_DITHER_DISABLE );*/
275 /* clear both buffers */
276 grRenderBuffer( GR_BUFFER_BACKBUFFER );
277 grBufferClear( 0, 0, 0 );
278 grRenderBuffer( GR_BUFFER_FRONTBUFFER );
279 grBufferClear( 0, 0, 0 );
280 grRenderBuffer( GR_BUFFER_BACKBUFFER );
282 p_vout->p_sys->p_buffer_info.size = sizeof( GrLfbInfo_t );
283 p_front_buffer_info.size = sizeof( GrLfbInfo_t );
285 /* lock the buffers to find their adresses */
286 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER,
287 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
288 &p_front_buffer_info) == FXFALSE )
290 msg_Err( p_vout, "cannot take 3dfx front buffer lock" );
294 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER );
296 if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
297 GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
298 &p_vout->p_sys->p_buffer_info) == FXFALSE )
300 msg_Err( p_vout, "cannot take 3dfx back buffer lock" );
304 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
306 grBufferClear( 0, 0, 0 );
308 p_vout->p_sys->pp_buffer[0] = p_vout->p_sys->p_buffer_info.lfbPtr;
309 p_vout->p_sys->pp_buffer[1] = p_front_buffer_info.lfbPtr;
310 p_vout->p_sys->i_index = 0;
315 /*****************************************************************************
316 * CloseDisplay: close and reset 3dfx device
317 *****************************************************************************
318 * Returns all resources allocated by OpenDisplay and restore the original
319 * state of the device.
320 *****************************************************************************/
321 static void CloseDisplay( vout_thread_t *p_vout )
323 /* unlock the hidden buffer */
324 grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );