]> git.sesse.net Git - vlc/blob - plugins/glide/vout_glide.c
. nouveaux plugins - ne fonctionnent pas encore tous
[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_SysCreate: allocates Glide video thread output method
78  *****************************************************************************
79  * This function allocates and initializes a Glide vout method.
80  *****************************************************************************/
81 int vout_SysCreate( 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_SysInit: initialize Glide video thread output method
105  *****************************************************************************/
106 int vout_SysInit( vout_thread_t *p_vout )
107 {
108     return( 0 );
109 }
110
111 /*****************************************************************************
112  * vout_SysEnd: terminate Glide video thread output method
113  *****************************************************************************/
114 void vout_SysEnd( vout_thread_t *p_vout )
115 {
116     ;
117 }
118
119 /*****************************************************************************
120  * vout_SysDestroy: destroy Glide video thread output method
121  *****************************************************************************
122  * Terminate an output method created by vout_CreateOutputMethod
123  *****************************************************************************/
124 void vout_SysDestroy( vout_thread_t *p_vout )
125 {
126     GlideCloseDisplay( p_vout );
127     free( p_vout->p_sys );
128 }
129
130 /*****************************************************************************
131  * vout_SysManage: 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_SysManage( vout_thread_t *p_vout )
137 {
138     return 0;
139 }
140
141 /*****************************************************************************
142  * vout_SysDisplay: 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_SysDisplay( 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", strerror(errno) );
192         return( 1 );
193     }
194
195     grGlideGetVersion( version );
196     grGlideInit();
197
198     if( !grSstQueryHardware(&hwconfig) )
199     {
200         intf_ErrMsg( "vout error: can't get 3dfx hardware config\n" );
201         return( 1 );
202     }
203
204     grSstSelect( 0 );
205     if( !grSstWinOpen(0, resolution, GR_REFRESH_60Hz,
206                         GR_COLORFORMAT_ABGR, GR_ORIGIN_UPPER_LEFT, 2, 1) )
207     {
208         intf_ErrMsg( "vout error: can't open 3dfx screen\n" );
209         return( 1 );
210     }
211
212     /* disable dithering */
213     //grDitherMode( GR_DITHER_DISABLE );
214
215     /* clear both buffers */
216     grRenderBuffer( GR_BUFFER_BACKBUFFER );
217     grBufferClear( 0, 0, 0 );
218     grRenderBuffer( GR_BUFFER_FRONTBUFFER );
219     grBufferClear( 0, 0, 0 );
220     grRenderBuffer( GR_BUFFER_BACKBUFFER );
221
222     p_vout->p_sys->p_buffer_info.size = sizeof( GrLfbInfo_t );
223     p_front_buffer_info.size          = sizeof( GrLfbInfo_t );
224
225     /* lock the buffers to find their adresses */
226     if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER,
227                    GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
228                    &p_front_buffer_info) == FXFALSE )
229     {
230         intf_ErrMsg( "vout error: can't take 3dfx front buffer lock\n" );
231         grGlideShutdown();
232         return( 1 );
233     }
234     grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_FRONTBUFFER );
235
236     if ( grLfbLock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER,
237                    GR_LFBWRITEMODE_565, GR_ORIGIN_UPPER_LEFT, FXFALSE,
238                    &p_vout->p_sys->p_buffer_info) == FXFALSE )
239     {
240         intf_ErrMsg( "vout error: can't take 3dfx back buffer lock\n" );
241         grGlideShutdown();
242         return( 1 );
243     }
244     grLfbUnlock(GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
245     
246     /* Get the number of bytes per line */
247     p_vout->i_bytes_per_line = p_vout->p_sys->p_buffer_info.strideInBytes;
248
249     grBufferClear( 0, 0, 0 );
250
251     /* Set and initialize buffers */
252     vout_SetBuffers( p_vout, p_vout->p_sys->p_buffer_info.lfbPtr,
253                      p_front_buffer_info.lfbPtr );
254
255     return( 0 );
256 }
257
258 /*****************************************************************************
259  * GlideCloseDisplay: close and reset 3dfx device
260  *****************************************************************************
261  * Returns all resources allocated by GlideOpenDisplay and restore the original
262  * state of the device.
263  *****************************************************************************/
264 static void GlideCloseDisplay( vout_thread_t *p_vout )
265 {
266     /* unlock the hidden buffer */
267     grLfbUnlock( GR_LFB_WRITE_ONLY, GR_BUFFER_BACKBUFFER );
268
269     /* shutdown Glide */
270     grGlideShutdown();
271     free( p_vout->p_sys->p_video );
272 }
273