]> git.sesse.net Git - vlc/blob - src/video_output/video_ggi.c
Integration de display.c � vout.
[vlc] / src / video_output / video_ggi.c
1 /*******************************************************************************
2  * vout_ggi.c: GGI video output display method
3  * (c)1998 VideoLAN
4  *******************************************************************************/
5
6 /*******************************************************************************
7  * Preamble
8  *******************************************************************************/
9 #include <errno.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <ggi/ggi.h>
13
14 #include "config.h"
15 #include "common.h"
16 #include "mtime.h"
17 #include "vlc_thread.h"
18
19 #include "video.h"
20 #include "video_output.h"
21 #include "video_sys.h"
22 #include "intf_msg.h"
23
24 /*******************************************************************************
25  * vout_sys_t: video output GGI method descriptor
26  *******************************************************************************
27  * This structure is part of the video output thread descriptor.
28  * It describes the GGI specific properties of an output thread. 
29  *******************************************************************************/
30 typedef struct vout_sys_s
31
32     /* GGI system informations */
33     ggi_visual_t        p_display;                           /* display device */
34
35     /* Buffer index */
36     int                 i_buffer_index;    
37 } vout_sys_t;
38
39 /*******************************************************************************
40  * Local prototypes
41  *******************************************************************************/
42 static int     GGIOpenDisplay   ( vout_thread_t *p_vout );
43 static void    GGICloseDisplay  ( vout_thread_t *p_vout );
44
45 /*******************************************************************************
46  * vout_SysCreate: allocate GGI video thread output method
47  *******************************************************************************
48  * This function allocate and initialize a GGI vout method. It uses some of the
49  * vout properties to choose the correct mode, and change them according to the 
50  * mode actually used.
51  *******************************************************************************/
52 int vout_SysCreate( vout_thread_t *p_vout )
53 {    
54     /* Allocate structure */
55     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );    
56     if( p_vout->p_sys == NULL )
57     {
58         intf_ErrMsg("error: %s\n", strerror(ENOMEM) );
59         return( 1 );
60     }
61
62     /* Open and initialize device */
63     if( GGIOpenDisplay( p_vout ) )
64     {
65         intf_ErrMsg("error: can't initialize GGI display\n");        
66         free( p_vout->p_sys );
67         return( 1 );        
68     }
69     
70     return( 0 );
71 }
72
73 /*******************************************************************************
74  * vout_SysInit: initialize GGI video thread output method
75  *******************************************************************************
76  * This function initialize the GGI display device.
77  *******************************************************************************/
78 int vout_SysInit( vout_thread_t *p_vout )
79 {
80     p_vout->p_sys->i_buffer_index = 0;
81     return( 0 );
82 }
83
84 /*******************************************************************************
85  * vout_SysEnd: terminate Sys video thread output method
86  *******************************************************************************
87  * Terminate an output method created by vout_SysCreateOutputMethod
88  *******************************************************************************/
89 void vout_SysEnd( vout_thread_t *p_vout )
90 {
91     ;
92 }
93
94 /*******************************************************************************
95  * vout_SysDestroy: destroy Sys video thread output method
96  *******************************************************************************
97  * Terminate an output method created by vout_SysCreateOutputMethod
98  *******************************************************************************/
99 void vout_SysDestroy( vout_thread_t *p_vout )
100 {
101     GGICloseDisplay( p_vout );
102     free( p_vout->p_sys );
103 }
104
105 /*******************************************************************************
106  * vout_SysManage: handle Sys events
107  *******************************************************************************
108  * This function should be called regularly by video output thread. It returns 
109  * a negative value if something happened which does not allow the thread to 
110  * continue, and a positive one if the thread can go on, but the images have 
111  * been modified and therefore it is useless to display them.
112  *******************************************************************************/
113 int vout_SysManage( vout_thread_t *p_vout )
114 {
115     //??
116
117     return( 0 );
118 }
119
120 /*******************************************************************************
121  * vout_SysDisplay: displays previously rendered output
122  *******************************************************************************
123  * This function send the currently rendered image to the display, wait until
124  * it is displayed and switch the two rendering buffer, preparing next frame.
125  *******************************************************************************/
126 void vout_SysDisplay( vout_thread_t *p_vout )
127 {
128     /* Change display frame */
129     ggiFlush( p_vout->p_sys->p_display ); // ??    
130     ggiSetDisplayFrame( p_vout->p_sys->p_display, p_vout->p_sys->i_buffer_index );      
131         
132     /* Swap buffers and change write frame */
133     p_vout->p_sys->i_buffer_index = ++p_vout->p_sys->i_buffer_index & 1;
134     ggiSetWriteFrame( p_vout->p_sys->p_display, p_vout->p_sys->i_buffer_index );        
135 }
136
137 /*******************************************************************************
138  * vout_SysGetPicture: get current display buffer informations
139  *******************************************************************************
140  * This function returns the address of the current display buffer.
141  *******************************************************************************/
142 byte_t * vout_SysGetPicture( vout_thread_t *p_vout )
143 {
144 //????
145 //    return( p_vout->p_sys->p_ximage[ p_vout->p_sys->i_buffer_index ].data );        
146 }
147
148 /* following functions are local */
149
150 /*******************************************************************************
151  * GGIOpenDisplay: open and initialize GGI device 
152  *******************************************************************************
153  * Open and initialize display according to preferences specified in the vout
154  * thread fields.
155  *******************************************************************************/
156 static int GGIOpenDisplay( vout_thread_t *p_vout )
157 {
158     ggi_mode    mode;                                       /* mode descriptor */    
159     
160     /* Initialize library */
161     if( ggiInit() )
162     {
163         intf_ErrMsg("error: can't initialize GGI library\n");
164         return( 1 );        
165     }
166
167     /* Open display */
168     p_vout->p_sys->p_display = ggiOpen( NULL );
169     if( p_vout->p_sys->p_display == NULL )
170     {
171         intf_ErrMsg("error: can't open GGI default display\n");
172         ggiExit();
173         return( 1 );        
174     }
175     
176     /* Find most appropriate mode */
177     mode.frames =       2;                                        /* 2 buffers */
178     mode.visible.x =    p_vout->i_width;                      /* minimum width */
179     mode.visible.y =    p_vout->i_width;                      /* maximum width */    
180     mode.virt.x =       GGI_AUTO;
181     mode.virt.y =       GGI_AUTO;
182     mode.size.x =       GGI_AUTO;
183     mode.size.y =       GGI_AUTO;
184     mode.graphtype =    GT_15BIT;               /* minimum usable screen depth */
185     mode.dpp.x =        GGI_AUTO;
186     mode.dpp.y =        GGI_AUTO;    
187     ggiCheckMode( p_vout->p_sys->p_display, &mode );
188
189     /* Check that returned mode has some minimum properties */
190     //??
191     
192     /* Set mode */
193     if( ggiSetMode( p_vout->p_sys->p_display, &mode ) )
194     {
195         intf_ErrMsg("error: can't set GGI mode\n");
196         ggiClose( p_vout->p_sys->p_display );        
197         ggiExit();
198         return( 1 );        
199     }            
200
201     /* Set thread information */
202     p_vout->i_width =           mode.visible.x;    
203     p_vout->i_height =          mode.visible.y;
204     switch( mode.graphtype )
205     {
206     case GT_15BIT:
207         p_vout->i_screen_depth =        15;
208         p_vout->i_bytes_per_pixel =     2;
209         break;        
210     case GT_16BIT:
211         p_vout->i_screen_depth =        16;
212         p_vout->i_bytes_per_pixel =     2;
213         break;        
214     case GT_24BIT:
215         p_vout->i_screen_depth =        24;
216         p_vout->i_bytes_per_pixel =     3;
217         break;        
218     case GT_32BIT:
219         p_vout->i_screen_depth =        32;
220         p_vout->i_bytes_per_pixel =     4;
221        break;        
222     default:
223         intf_ErrMsg("error: unsupported screen depth\n");        
224         ggiClose( p_vout->p_sys->p_display );
225         ggiExit();        
226         return( 1 );        
227         break;        
228     }
229
230     return( 0 );    
231 }
232
233 /*******************************************************************************
234  * GGICloseDisplay: close and reset GGI device 
235  *******************************************************************************
236  * This function returns all resources allocated by GGIOpenDisplay and restore
237  * the original state of the device.
238  *******************************************************************************/
239 static void GGICloseDisplay( vout_thread_t *p_vout )
240 {
241     // Restore original mode and close display
242     ggiClose( p_vout->p_sys->p_display );    
243
244     // Exit library
245     ggiExit();    
246 }
247