]> git.sesse.net Git - vlc/blob - modules/video_output/glide.c
Fix compilation error with SDL under 1.2.10
[vlc] / modules / video_output / glide.c
1 /*****************************************************************************
2  * glide.c : 3dfx Glide plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <errno.h>                                                 /* ENOMEM */
28
29 #include <vlc/vlc.h>
30 #include <vlc_interface.h>
31 #include <vlc_vout.h>
32
33 #ifndef __linux__
34 #   include <conio.h>                                         /* for glide ? */
35 #endif
36 #include <glide.h>
37 #include <linutil.h>                            /* Glide kbhit() and getch() */
38
39 #define GLIDE_WIDTH 800
40 #define GLIDE_HEIGHT 600
41 #define GLIDE_BITS_PER_PLANE 16
42 #define GLIDE_BYTES_PER_PIXEL 2
43
44 /*****************************************************************************
45  * Local prototypes
46  *****************************************************************************/
47 static int  Create    ( vlc_object_t * );
48 static void Destroy   ( vlc_object_t * );
49
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 * );
54
55 static int  OpenDisplay    ( vout_thread_t * );
56 static void CloseDisplay   ( vout_thread_t * );
57
58 /*****************************************************************************
59  * Module descriptor
60  *****************************************************************************/
61 vlc_module_begin();
62     set_description( _("3dfx Glide video output") );
63     set_capability( "video output", 20 );
64     add_shortcut( "3dfx" );
65     set_callbacks( Create, Destroy );
66 vlc_module_end();
67
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  *****************************************************************************/
74 struct vout_sys_t
75 {
76     GrLfbInfo_t                 p_buffer_info;           /* back buffer info */
77
78     uint8_t * pp_buffer[2];
79     int i_index;
80 };
81
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 )
88 {
89     vout_thread_t *p_vout = (vout_thread_t *)p_this;
90
91     /* Allocate structure */
92     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
93     if( p_vout->p_sys == NULL )
94     {
95         msg_Err( p_vout, "out of memory" );
96         return( 1 );
97     }
98
99     /* Open and initialize device */
100     if( OpenDisplay( p_vout ) )
101     {
102         msg_Err( p_vout, "cannot open display" );
103         free( p_vout->p_sys );
104         return( 1 );
105     }
106
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;
112
113     return( 0 );
114 }
115
116 /*****************************************************************************
117  * Init: initialize Glide video thread output method
118  *****************************************************************************/
119 static int Init( vout_thread_t *p_vout )
120 {
121     int i_index;
122     picture_t *p_pic;
123
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;
128
129     I_OUTPUTPICTURES = 0;
130
131     p_pic = NULL;
132
133     /* Find an empty picture slot */
134     for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
135     {
136         if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
137         {
138             p_pic = p_vout->p_picture + i_index;
139             break;
140         }
141     }
142
143     if( p_pic == NULL )
144     {
145         return -1;
146     }
147
148     /* We know the chroma, allocate a buffer which will be used
149      * directly by the decoder */
150     p_pic->i_planes = 1;
151
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;
159
160     p_pic->i_status = DESTROYED_PICTURE;
161     p_pic->i_type   = DIRECT_PICTURE;
162
163     PP_OUTPUTPICTURE[ 0 ] = p_pic;
164
165     I_OUTPUTPICTURES = 1;
166
167     return 0;
168 }
169
170 /*****************************************************************************
171  * End: terminate Glide video thread output method
172  *****************************************************************************/
173 static void End( vout_thread_t *p_vout )
174 {
175     ;
176 }
177
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 )
184 {
185     vout_thread_t *p_vout = (vout_thread_t *)p_this;
186     CloseDisplay( p_vout );
187     free( p_vout->p_sys );
188 }
189
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 )
197 {
198     int buf;
199
200     /* very Linux specific - see tlib.c in Glide for other versions */
201     while( kbhit() )
202     {
203         buf = getch();
204
205         switch( (char)buf )
206         {
207         case 'q':
208             vlc_object_kill( p_vout->p_libvlc );
209             break;
210
211         default:
212             break;
213         }
214     }
215
216     return 0;
217 }
218
219 /*****************************************************************************
220  * Display: displays previously rendered output
221  *****************************************************************************/
222 static void Display( vout_thread_t *p_vout, picture_t *p_pic )
223
224 {
225     grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
226
227     grBufferSwap( 0 );
228
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 )
232     {
233         msg_Err( p_vout, "cannot take 3dfx back buffer lock" );
234     }
235 }
236
237 /* following functions are local */
238
239 /*****************************************************************************
240  * OpenDisplay: open and initialize 3dfx device
241  *****************************************************************************/
242
243 static int OpenDisplay( vout_thread_t *p_vout )
244 {
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 */
249
250     grGlideGetVersion( version );
251     grGlideInit();
252
253     if( !grSstQueryHardware(&hwconfig) )
254     {
255         msg_Err( p_vout, "cannot get 3dfx hardware config" );
256         return( 1 );
257     }
258
259     grSstSelect( 0 );
260     if( !grSstWinOpen( 0, resolution, GR_REFRESH_60Hz,
261                        GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1 ) )
262     {
263         msg_Err( p_vout, "cannot open 3dfx screen" );
264         return( 1 );
265     }
266
267     /* disable dithering */
268     /*grDitherMode( GR_DITHER_DISABLE );*/
269
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 );
276
277     p_vout->p_sys->p_buffer_info.size = sizeof( GrLfbInfo_t );
278     p_front_buffer_info.size          = sizeof( GrLfbInfo_t );
279
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 )
284     {
285         msg_Err( p_vout, "cannot take 3dfx front buffer lock" );
286         grGlideShutdown();
287         return( 1 );
288     }
289     grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER );
290
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 )
294     {
295         msg_Err( p_vout, "cannot take 3dfx back buffer lock" );
296         grGlideShutdown();
297         return( 1 );
298     }
299     grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
300
301     grBufferClear( 0, 0, 0 );
302
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;
306
307     return( 0 );
308 }
309
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 )
317 {
318     /* unlock the hidden buffer */
319     grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
320
321     /* shutdown Glide */
322     grGlideShutdown();
323 }
324