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