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 $
7 * Authors: Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
8 * Samuel Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
25 #define MODULE_NAME mga
26 #include "modules_inner.h"
28 /*****************************************************************************
30 *****************************************************************************/
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 */
42 #include <sys/types.h> /* typedef ushort */
53 #include "video_output.h"
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
89 typedef struct vout_sys_s
94 /* MGA specific variables */
98 byte_t * p_mga_vid_base;
103 #define DUMMY_WIDTH 16
104 #define DUMMY_HEIGHT 16
105 #define DUMMY_BITS_PER_PLANE 16
106 #define DUMMY_BYTES_PER_PIXEL 2
108 /*****************************************************************************
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 * );
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 )
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;
135 /*****************************************************************************
136 * intf_Probe: return a score
137 *****************************************************************************/
138 static int vout_Probe( probedata_t *p_data )
140 if( TestMethod( VOUT_METHOD_VAR, "mga" ) )
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 )
155 /* Allocate structure */
156 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
157 if( p_vout->p_sys == NULL )
159 intf_ErrMsg("vout error: %s", strerror(ENOMEM) );
163 if( (p_vout->p_sys->i_fd = open( "/dev/mga_vid", O_RDWR )) == -1 )
165 intf_ErrMsg( "vout error: can't open MGA driver /dev/mga_vid" );
166 free( p_vout->p_sys );
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;
176 p_vout->p_sys->i_page_size = DUMMY_WIDTH * DUMMY_HEIGHT
177 * DUMMY_BYTES_PER_PIXEL;
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 )
183 intf_ErrMsg( "vout error: can't map video memory (%s)",
185 free( p_vout->p_sys );
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 );
196 /*****************************************************************************
197 * vout_Init: initialize dummy video thread output method
198 *****************************************************************************/
199 static int vout_Init( vout_thread_t *p_vout )
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;
213 if( ioctl(p_vout->p_sys->i_fd, MGA_VID_CONFIG, &p_vout->p_sys->mga) )
215 intf_ErrMsg("error in config ioctl");
218 if (p_vout->p_sys->mga.card_type == MGA_G200)
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;
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;
231 ioctl( p_vout->p_sys->i_fd, MGA_VID_ON, 0 );
233 p_vout->p_sys->i_size = ( (p_vout->p_sys->mga.src_width + 31) & ~31 )
234 * p_vout->p_sys->mga.src_height;
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 );
241 memset( p_vout->p_sys->p_mga_vid_base,
242 0x00, p_vout->p_sys->i_size );
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 );
250 /*****************************************************************************
251 * vout_End: terminate dummy video thread output method
252 *****************************************************************************/
253 static void vout_End( vout_thread_t *p_vout )
255 ioctl( p_vout->p_sys->i_fd, MGA_VID_OFF, 0 );
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 )
265 close( p_vout->p_sys->i_fd );
267 free( p_vout->p_sys->p_video );
268 free( p_vout->p_sys );
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 )
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 )