]> git.sesse.net Git - vlc/blob - plugins/mga/vout_mga.c
* Ported Glide and MGA plugins to the new module API. MGA never worked,
[vlc] / plugins / mga / vout_mga.c
1 /*****************************************************************************
2  * vout_mga.c: MGA video output display method
3  *****************************************************************************
4  * Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
5  *
6  * Authors: Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
7  *          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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #define MODULE_NAME mga
25 #include "modules_inner.h"
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30 #include "defs.h"
31
32 #include <errno.h>                                                 /* ENOMEM */
33 #include <unistd.h>                                               /* close() */
34 #include <stdlib.h>                                                /* free() */
35 #include <string.h>                                            /* strerror() */
36 #include <fcntl.h>                                                 /* open() */
37 #include <sys/ioctl.h>                                            /* ioctl() */
38 #include <sys/mman.h>                                          /* PROT_WRITE */
39
40 #ifdef SYS_BSD
41 #include <sys/types.h>                                     /* typedef ushort */
42 #endif
43
44 #include "config.h"
45 #include "common.h"
46 #include "threads.h"
47 #include "mtime.h"
48 #include "tests.h"
49 #include "modules.h"
50
51 #include "video.h"
52 #include "video_output.h"
53
54 #include "intf_msg.h"
55
56 #include "vout_mga.h"
57
58 /*****************************************************************************
59  * vout_sys_t: video output MGA method descriptor
60  *****************************************************************************
61  * This structure is part of the video output thread descriptor.
62  * It describes the MGA specific properties of an output thread.
63  *****************************************************************************/
64 #ifndef __LINUX_MGAVID_H
65 #   define __LINUX_MGAVID_H
66 #   define MGA_VID_CONFIG _IOR('J', 1, mga_vid_config_t)
67 #   define MGA_VID_ON     _IO ('J', 2)
68 #   define MGA_VID_OFF    _IO ('J', 3)
69 #   define MGA_G200 0x1234
70 #   define MGA_G400 0x5678
71 typedef struct mga_vid_config_s
72 {
73     u32     card_type;
74     u32     ram_size;
75     u32     src_width;
76     u32     src_height;
77     u32     dest_width;
78     u32     dest_height;
79     u32     x_org;
80     u32     y_org;
81     u8      colkey_on;
82     u8      colkey_red;
83     u8      colkey_green;
84     u8      colkey_blue;
85 } mga_vid_config_t;
86 #endif
87
88 typedef struct vout_sys_s
89 {
90     int                 i_page_size;
91     byte_t             *p_video;
92
93     /* MGA specific variables */
94     int                 i_fd;
95     int                 i_size;
96     mga_vid_config_t    mga;
97     byte_t *            p_mga_vid_base;
98     boolean_t           b_g400;
99
100 } vout_sys_t;
101
102 #define DUMMY_WIDTH 16
103 #define DUMMY_HEIGHT 16
104 #define DUMMY_BITS_PER_PLANE 16
105 #define DUMMY_BYTES_PER_PIXEL 2
106
107 /*****************************************************************************
108  * Local prototypes
109  *****************************************************************************/
110 static int  vout_Probe     ( probedata_t *p_data );
111 static int  vout_Create    ( struct vout_thread_s * );
112 static int  vout_Init      ( struct vout_thread_s * );
113 static void vout_End       ( struct vout_thread_s * );
114 static void vout_Destroy   ( struct vout_thread_s * );
115 static int  vout_Manage    ( struct vout_thread_s * );
116 static void vout_Display   ( struct vout_thread_s * );
117
118 /*****************************************************************************
119  * Functions exported as capabilities. They are declared as static so that
120  * we don't pollute the namespace too much.
121  *****************************************************************************/
122 void _M( vout_getfunctions )( function_list_t * p_function_list )
123 {
124     p_function_list->pf_probe = vout_Probe;
125     p_function_list->functions.vout.pf_create     = vout_Create;
126     p_function_list->functions.vout.pf_init       = vout_Init;
127     p_function_list->functions.vout.pf_end        = vout_End;
128     p_function_list->functions.vout.pf_destroy    = vout_Destroy;
129     p_function_list->functions.vout.pf_manage     = vout_Manage;
130     p_function_list->functions.vout.pf_display    = vout_Display;
131     p_function_list->functions.vout.pf_setpalette = NULL;
132 }
133
134 /*****************************************************************************
135  * intf_Probe: return a score
136  *****************************************************************************/
137 static int vout_Probe( probedata_t *p_data )
138 {
139     if( TestMethod( VOUT_METHOD_VAR, "mga" ) )
140     {
141         return( 999 );
142     }
143
144     return( 10 );
145 }
146
147 /*****************************************************************************
148  * vout_Create: allocates dummy video thread output method
149  *****************************************************************************
150  * This function allocates and initializes a dummy vout method.
151  *****************************************************************************/
152 static int vout_Create( vout_thread_t *p_vout )
153 {
154     /* Allocate structure */
155     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
156     if( p_vout->p_sys == NULL )
157     {
158         intf_ErrMsg("vout error: %s", strerror(ENOMEM) );
159         return( 1 );
160     }
161
162     if( (p_vout->p_sys->i_fd = open( "/dev/mga_vid", O_RDWR )) == -1 )
163     {
164         intf_ErrMsg( "vout error: can't open MGA driver /dev/mga_vid" );
165         free( p_vout->p_sys );
166         return( 1 );
167     }
168
169     p_vout->i_width            = DUMMY_WIDTH;
170     p_vout->i_height           = DUMMY_HEIGHT;
171     p_vout->i_screen_depth     = DUMMY_BITS_PER_PLANE;
172     p_vout->i_bytes_per_pixel  = DUMMY_BYTES_PER_PIXEL;
173     p_vout->i_bytes_per_line   = DUMMY_WIDTH * DUMMY_BYTES_PER_PIXEL;
174
175     p_vout->p_sys->i_page_size = DUMMY_WIDTH * DUMMY_HEIGHT
176                                   * DUMMY_BYTES_PER_PIXEL;
177
178     /* Map two framebuffers a the very beginning of the fb */
179     p_vout->p_sys->p_video = malloc( 2 * p_vout->p_sys->i_page_size );
180     if( p_vout->p_sys->p_video == NULL )
181     {
182         intf_ErrMsg( "vout error: can't map video memory (%s)",
183                      strerror(errno) );
184         free( p_vout->p_sys );
185         return( 1 );
186     }
187
188     /* Set and initialize buffers */
189     vout_SetBuffers( p_vout, p_vout->p_sys->p_video,
190                      p_vout->p_sys->p_video + p_vout->p_sys->i_page_size );
191
192     return( 0 );
193 }
194
195 /*****************************************************************************
196  * vout_Init: initialize dummy video thread output method
197  *****************************************************************************/
198 static int vout_Init( vout_thread_t *p_vout )
199 {
200     /* create the MGA output */
201     p_vout->p_sys->mga.src_width = p_vout->i_width;
202     p_vout->p_sys->mga.src_height = p_vout->i_height;
203     /* FIXME: we should initialize these ones according to the streams */
204     p_vout->p_sys->mga.dest_width = p_vout->i_width;
205     p_vout->p_sys->mga.dest_height = p_vout->i_height;
206     //p_vout->p_sys->mga?dest_width = 400;
207     //p_vout->p_sys->mga.dest_height = 300;
208     p_vout->p_sys->mga.x_org = 100;
209     p_vout->p_sys->mga.y_org = 100;
210     p_vout->p_sys->mga.colkey_on = 0;
211
212     if( ioctl(p_vout->p_sys->i_fd, MGA_VID_CONFIG, &p_vout->p_sys->mga) )
213     {
214         intf_ErrMsg("error in config ioctl");
215     }
216
217     if (p_vout->p_sys->mga.card_type == MGA_G200)
218     {
219         intf_Msg( "vout: detected MGA G200 (%d MB Ram)",
220                   p_vout->p_sys->mga.ram_size );
221         p_vout->p_sys->b_g400 = 0;
222     }
223     else
224     {
225         intf_Msg( "vout: detected MGA G400 (%d MB Ram)",
226                   p_vout->p_sys->mga.ram_size );
227         p_vout->p_sys->b_g400 = 1;
228     }
229
230     ioctl( p_vout->p_sys->i_fd, MGA_VID_ON, 0 );
231
232     p_vout->p_sys->i_size = ( (p_vout->p_sys->mga.src_width + 31) & ~31 )
233                              * p_vout->p_sys->mga.src_height;
234
235     p_vout->p_sys->p_mga_vid_base = mmap( 0, p_vout->p_sys->i_size
236                                              + p_vout->p_sys->i_size / 2,
237                                           PROT_WRITE, MAP_SHARED,
238                                           p_vout->p_sys->i_fd, 0 );
239
240     memset( p_vout->p_sys->p_mga_vid_base,
241             0x00, p_vout->p_sys->i_size );
242
243     memset( p_vout->p_sys->p_mga_vid_base + p_vout->p_sys->i_size,
244             0x80, p_vout->p_sys->i_size / 2 );
245
246     return( 0 );
247 }
248
249 /*****************************************************************************
250  * vout_End: terminate dummy video thread output method
251  *****************************************************************************/
252 static void vout_End( vout_thread_t *p_vout )
253 {
254     ioctl( p_vout->p_sys->i_fd, MGA_VID_OFF, 0 );
255 }
256
257 /*****************************************************************************
258  * vout_Destroy: destroy dummy video thread output method
259  *****************************************************************************
260  * Terminate an output method created by DummyCreateOutputMethod
261  *****************************************************************************/
262 static void vout_Destroy( vout_thread_t *p_vout )
263 {
264     close( p_vout->p_sys->i_fd );
265
266     free( p_vout->p_sys->p_video );
267     free( p_vout->p_sys );
268 }
269
270 /*****************************************************************************
271  * vout_Manage: handle dummy events
272  *****************************************************************************
273  * This function should be called regularly by video output thread. It manages
274  * console events. It returns a non null value on error.
275  *****************************************************************************/
276 static int vout_Manage( vout_thread_t *p_vout )
277 {
278     return( 0 );
279 }
280
281 /*****************************************************************************
282  * vout_Display: displays previously rendered output
283  *****************************************************************************
284  * This function send the currently rendered image to dummy image, waits until
285  * it is displayed and switch the two rendering buffers, preparing next frame.
286  *****************************************************************************/
287 static void vout_Display( vout_thread_t *p_vout )
288 {
289     ;
290 }
291