1 /*****************************************************************************
2 * vout_mga.c: MGA video output display method
3 *****************************************************************************
4 * Copyright (C) 1998, 1999, 2000, 2001 VideoLAN
6 * Authors: Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
7 * Samuel Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
24 #define MODULE_NAME mga
25 #include "modules_inner.h"
27 /*****************************************************************************
29 *****************************************************************************/
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 */
41 #include <sys/types.h> /* typedef ushort */
52 #include "video_output.h"
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
88 typedef struct vout_sys_s
93 /* MGA specific variables */
97 byte_t * p_mga_vid_base;
102 #define DUMMY_WIDTH 16
103 #define DUMMY_HEIGHT 16
104 #define DUMMY_BITS_PER_PLANE 16
105 #define DUMMY_BYTES_PER_PIXEL 2
107 /*****************************************************************************
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 * );
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 )
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;
134 /*****************************************************************************
135 * intf_Probe: return a score
136 *****************************************************************************/
137 static int vout_Probe( probedata_t *p_data )
139 if( TestMethod( VOUT_METHOD_VAR, "mga" ) )
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 )
154 /* Allocate structure */
155 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
156 if( p_vout->p_sys == NULL )
158 intf_ErrMsg("vout error: %s", strerror(ENOMEM) );
162 if( (p_vout->p_sys->i_fd = open( "/dev/mga_vid", O_RDWR )) == -1 )
164 intf_ErrMsg( "vout error: can't open MGA driver /dev/mga_vid" );
165 free( p_vout->p_sys );
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;
175 p_vout->p_sys->i_page_size = DUMMY_WIDTH * DUMMY_HEIGHT
176 * DUMMY_BYTES_PER_PIXEL;
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 )
182 intf_ErrMsg( "vout error: can't map video memory (%s)",
184 free( p_vout->p_sys );
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 );
195 /*****************************************************************************
196 * vout_Init: initialize dummy video thread output method
197 *****************************************************************************/
198 static int vout_Init( vout_thread_t *p_vout )
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;
212 if( ioctl(p_vout->p_sys->i_fd, MGA_VID_CONFIG, &p_vout->p_sys->mga) )
214 intf_ErrMsg("error in config ioctl");
217 if (p_vout->p_sys->mga.card_type == MGA_G200)
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;
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;
230 ioctl( p_vout->p_sys->i_fd, MGA_VID_ON, 0 );
232 p_vout->p_sys->i_size = ( (p_vout->p_sys->mga.src_width + 31) & ~31 )
233 * p_vout->p_sys->mga.src_height;
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 );
240 memset( p_vout->p_sys->p_mga_vid_base,
241 0x00, p_vout->p_sys->i_size );
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 );
249 /*****************************************************************************
250 * vout_End: terminate dummy video thread output method
251 *****************************************************************************/
252 static void vout_End( vout_thread_t *p_vout )
254 ioctl( p_vout->p_sys->i_fd, MGA_VID_OFF, 0 );
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 )
264 close( p_vout->p_sys->i_fd );
266 free( p_vout->p_sys->p_video );
267 free( p_vout->p_sys );
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 )
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 )