]> git.sesse.net Git - vlc/blob - plugins/glide/vout_glide.c
. autod�tection des plugins
[vlc] / plugins / glide / vout_glide.c
1 /*****************************************************************************
2  * vout_glide.c: 3dfx video output display method for 3dfx cards
3  *****************************************************************************
4  * Copyright (C) 2000 VideoLAN
5  *
6  * Authors:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include "defs.h"
27
28 #include <errno.h>                                                 /* ENOMEM */
29 #include <stdlib.h>                                                /* free() */
30 #include <string.h>                                            /* strerror() */
31
32 #ifndef __linux__
33 #include <conio.h>                                            /* for glide ? */
34 #endif
35 #include <glide.h>
36
37 #include "config.h"
38 #include "common.h"
39 #include "threads.h"
40 #include "mtime.h"
41 #include "plugins.h"
42
43 #include "video.h"
44 #include "video_output.h"
45
46 #include "intf_msg.h"
47 #include "main.h"
48
49 #define WIDTH 640
50 #define HEIGHT 480
51 #define BITS_PER_PLANE 16
52 #define BYTES_PER_PIXEL 2
53
54 /*****************************************************************************
55  * vout_sys_t: Glide video output method descriptor
56  *****************************************************************************
57  * This structure is part of the video output thread descriptor.
58  * It describes the Glide specific properties of an output thread.
59  *****************************************************************************/
60 typedef struct vout_sys_s
61 {
62     GrLfbInfo_t                 p_buffer_info;           /* back buffer info */
63
64     /* Dummy video memory */
65     byte_t *                    p_video;                      /* base adress */
66     size_t                      i_page_size;                    /* page size */
67
68 } vout_sys_t;
69
70 /*****************************************************************************
71  * Local prototypes
72  *****************************************************************************/
73 static int     GlideOpenDisplay   ( vout_thread_t *p_vout );
74 static void    GlideCloseDisplay  ( vout_thread_t *p_vout );
75
76 /*****************************************************************************
77  * vout_GlideCreate: allocates Glide video thread output method
78  *****************************************************************************
79  * This function allocates and initializes a Glide vout method.
80  *****************************************************************************/
81 int vout_GlideCreate( vout_thread_t *p_vout, char *psz_display,
82                     int i_root_window, void *p_data )
83 {
84     /* Allocate structure */
85     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
86     if( p_vout->p_sys == NULL )
87     {
88         intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
89         return( 1 );
90     }
91
92     /* Open and initialize device */
93     if( GlideOpenDisplay( p_vout ) )
94     {
95         intf_ErrMsg("vout error: can't open display\n");
96         free( p_vout->p_sys );
97         return( 1 );
98     }
99
100     return( 0 );
101 }
102
103 /*****************************************************************************
104  * vout_GlideInit: initialize Glide video thread output method
105  *****************************************************************************/
106 int vout_GlideInit( vout_thread_t *p_vout )
107 {
108     return( 0 );
109 }
110
111 /*****************************************************************************
112  * vout_GlideEnd: terminate Glide video thread output method
113  *****************************************************************************/
114 void vout_GlideEnd( vout_thread_t *p_vout )
115 {
116     ;
117 }
118
119 /*****************************************************************************
120  * vout_GlideDestroy: destroy Glide video thread output method
121  *****************************************************************************
122  * Terminate an output method created by vout_CreateOutputMethod
123  *****************************************************************************/
124 void vout_GlideDestroy( vout_thread_t *p_vout )
125 {
126     GlideCloseDisplay( p_vout );
127     free( p_vout->p_sys );
128 }
129
130 /*****************************************************************************
131  * vout_GlideManage: handle Glide events
132  *****************************************************************************
133  * This function should be called regularly by video output thread. It manages
134  * console events. It returns a non null value on error.
135  *****************************************************************************/
136 int vout_GlideManage( vout_thread_t *p_vout )
137 {
138     return 0;
139 }
140
141 /*****************************************************************************
142  * vout_GlideDisplay: displays previously rendered output
143  *****************************************************************************
144  * This function send the currently rendered image to Glide image, waits until
145  * it is displayed and switch the two rendering buffers, preparing next frame.
146  *****************************************************************************/
147 void vout_GlideDisplay( vout_thread_t *p_vout )
148 {
149     grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
150
151     grBufferSwap( 0 );
152
153     if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
154                    GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
155                    &p_vout->p_sys->p_buffer_info) == FXFALSE )
156     {
157         intf_ErrMsg( "vout error: can't take 3dfx back buffer lock\n" );
158     }
159 }
160
161 /* following functions are local */
162
163 /*****************************************************************************
164  * GlideOpenDisplay: open and initialize 3dfx device
165  *****************************************************************************/
166
167 static int GlideOpenDisplay( vout_thread_t *p_vout )
168 {
169     static char version[80];
170     GrHwConfiguration hwconfig;
171     GrScreenResolution_t resolution = GR_RESOLUTION_640x480;
172     GrLfbInfo_t p_front_buffer_info;                    /* front buffer info */
173
174     p_vout->i_width =                   WIDTH;
175     p_vout->i_height =                  HEIGHT;
176     p_vout->i_screen_depth =            BITS_PER_PLANE;
177     p_vout->i_bytes_per_pixel =         BYTES_PER_PIXEL;
178     /* bytes per line value overriden later */
179     p_vout->i_bytes_per_line =          1024 * BYTES_PER_PIXEL;
180
181     p_vout->p_sys->i_page_size = WIDTH * HEIGHT * BYTES_PER_PIXEL;
182
183     p_vout->i_red_mask =   0xf800;
184     p_vout->i_green_mask = 0x07e0;
185     p_vout->i_blue_mask =  0x001f;
186
187     /* Map two framebuffers a the very beginning of the fb */
188     p_vout->p_sys->p_video = malloc( p_vout->p_sys->i_page_size * 2 );
189     if( (int)p_vout->p_sys->p_video == -1 )
190     {
191         intf_ErrMsg( "vout error: can't map video memory (%s)\n",
192                      strerror(errno) );
193         return( 1 );
194     }
195
196     grGlideGetVersion( version );
197     grGlideInit();
198
199     if( !grSstQueryHardware(&hwconfig) )
200     {
201         intf_ErrMsg( "vout error: can't get 3dfx hardware config\n" );
202         return( 1 );
203     }
204
205     grSstSelect( 0 );
206     if( !grSstWinOpen(0, resolution, GR_REFRESH_60Hz,
207                         GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1) )
208     {
209         intf_ErrMsg( "vout error: can't open 3dfx screen\n" );
210         return( 1 );
211     }
212
213     /* disable dithering */
214     //grDitherMode( GR_DITHER_DISABLE );
215
216     /* clear both buffers */
217     grRenderBuffer( GR_BUFFER_BACKBUFFER );
218     grBufferClear( 0, 0, 0 );
219     grRenderBuffer( GR_BUFFER_FRONTBUFFER );
220     grBufferClear( 0, 0, 0 );
221     grRenderBuffer( GR_BUFFER_BACKBUFFER );
222
223     p_vout->p_sys->p_buffer_info.size = sizeof( GrLfbInfo_t );
224     p_front_buffer_info.size          = sizeof( GrLfbInfo_t );
225
226     /* lock the buffers to find their adresses */
227     if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER,
228                    GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
229                    &p_front_buffer_info) == FXFALSE )
230     {
231         intf_ErrMsg( "vout error: can't take 3dfx front buffer lock\n" );
232         grGlideShutdown();
233         return( 1 );
234     }
235     grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER );
236
237     if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
238                    GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
239                    &p_vout->p_sys->p_buffer_info) == FXFALSE )
240     {
241         intf_ErrMsg( "vout error: can't take 3dfx back buffer lock\n" );
242         grGlideShutdown();
243         return( 1 );
244     }
245     grLfbUnlock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
246     
247     /* Get the number of bytes per line */
248     p_vout->i_bytes_per_line = p_vout->p_sys->p_buffer_info.strideInBytes;
249
250     grBufferClear( 0, 0, 0 );
251
252     /* Set and initialize buffers */
253     vout_SetBuffers( p_vout, p_vout->p_sys->p_buffer_info.lfbPtr,
254                      p_front_buffer_info.lfbPtr );
255
256     return( 0 );
257 }
258
259 /*****************************************************************************
260  * GlideCloseDisplay: close and reset 3dfx device
261  *****************************************************************************
262  * Returns all resources allocated by GlideOpenDisplay and restore the original
263  * state of the device.
264  *****************************************************************************/
265 static void GlideCloseDisplay( vout_thread_t *p_vout )
266 {
267     /* unlock the hidden buffer */
268     grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
269
270     /* shutdown Glide */
271     grGlideShutdown();
272     free( p_vout->p_sys->p_video );
273 }
274