1
|
1
|
|
2 /*
|
|
3 * video_out_xmga.c
|
|
4 *
|
|
5 * Copyright (C) Zoltan Ponekker - Jan 2001
|
|
6 *
|
|
7 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
|
|
8 *
|
|
9 * mpeg2dec 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, or (at your option)
|
|
12 * any later version.
|
|
13 *
|
|
14 * mpeg2dec 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 GNU Make; see the file COPYING. If not, write to
|
|
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 #include <stdio.h>
|
|
26 #include <stdlib.h>
|
|
27 #include <string.h>
|
|
28
|
|
29 #include "config.h"
|
|
30 #include "video_out.h"
|
|
31 #include "video_out_internal.h"
|
|
32
|
|
33 LIBVO_EXTERN( xmga )
|
|
34
|
|
35 #include <sys/ioctl.h>
|
|
36 #include <unistd.h>
|
|
37 #include <fcntl.h>
|
|
38 #include <sys/mman.h>
|
|
39
|
|
40 #include "drivers/mga_vid.h"
|
|
41
|
|
42 #include <X11/Xlib.h>
|
|
43 #include <X11/Xutil.h>
|
|
44 #include <errno.h>
|
|
45
|
|
46 static vo_info_t vo_info =
|
|
47 {
|
|
48 "X11 (Matrox G200/G400 overlay in window using /dev/mga_vid)",
|
|
49 "xmga",
|
|
50 "Zoltan Ponekker <pontscho@makacs.poliod.hu>",
|
|
51 ""
|
|
52 };
|
|
53
|
|
54 static mga_vid_config_t mga_vid_config;
|
|
55 static uint8_t * vid_data;
|
|
56 static uint8_t * frame0;
|
|
57 static uint8_t * frame1;
|
|
58 static int next_frame=0;
|
|
59 static int f;
|
|
60
|
|
61 static Display * mDisplay;
|
|
62 static Window mWindow;
|
|
63 static GC mGC;
|
|
64 static XGCValues wGCV;
|
|
65
|
|
66 static XImage * myximage;
|
|
67
|
|
68 static uint32_t mDepth, bpp, mode;
|
|
69 static XWindowAttributes attribs;
|
|
70 static uint32_t X_already_started=0;
|
|
71
|
|
72 static uint32_t wndHeight;
|
|
73 static uint32_t wndWidth;
|
|
74 static uint32_t wndX;
|
|
75 static uint32_t wndY;
|
|
76
|
|
77 static uint32_t fgColor;
|
|
78
|
|
79 static uint32_t mvHeight;
|
|
80 static uint32_t mvWidth;
|
|
81
|
|
82 static Window mRoot;
|
|
83 static uint32_t drwX,drwY,drwWidth,drwHeight,drwBorderWidth,drwDepth;
|
|
84 static uint32_t drwcX,drwcY,dwidth,dheight,mFullscreen;
|
|
85
|
|
86 static XSetWindowAttributes xWAttribs;
|
|
87
|
|
88 #include "mga_common.c"
|
|
89
|
|
90
|
|
91 static void mDrawColorKey( void )
|
|
92 {
|
|
93 XClearWindow( mDisplay,mWindow );
|
|
94 XSetForeground( mDisplay,mGC,fgColor );
|
|
95 XFillRectangle( mDisplay,mWindow,mGC,drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight) );
|
|
96 XFlush( mDisplay );
|
|
97 }
|
|
98
|
|
99 static Bool mEvents( Display * display,XEvent * Event,XPointer arg )
|
|
100 {
|
|
101 int i;
|
|
102 char buf[100];
|
|
103 KeySym keySym;
|
|
104 XComposeStatus stat;
|
|
105 unsigned long vo_KeyTable[512];
|
|
106
|
|
107 switch( Event->type )
|
|
108 {
|
|
109 case Expose:
|
|
110 mDrawColorKey();
|
|
111 break;
|
|
112 case ConfigureNotify:
|
|
113 XGetGeometry( mDisplay,mWindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
|
|
114 drwX=0; drwY=0;
|
|
115 XTranslateCoordinates( mDisplay,mWindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
|
|
116 if ( mFullscreen )
|
|
117 {
|
|
118 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2;
|
|
119 drwcX=drwX;
|
|
120 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2;
|
|
121 drwcY=drwY;
|
|
122 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth);
|
|
123 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight);
|
|
124 }
|
|
125
|
|
126 mDrawColorKey();
|
|
127 mga_vid_config.x_org=drwcX;
|
|
128 mga_vid_config.y_org=drwcY;
|
|
129 mga_vid_config.dest_width=drwWidth;
|
|
130 mga_vid_config.dest_height=drwHeight;
|
|
131
|
|
132 fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
|
|
133
|
|
134 if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) )
|
|
135 {
|
|
136 fprintf( stderr,"Error in mga_vid_config ioctl" );
|
|
137 exit( 0 );
|
|
138 }
|
|
139 break;
|
|
140 case KeyPress:
|
|
141 XLookupString( &Event->xkey,buf,sizeof(buf),&keySym,&stat );
|
|
142 vo_keyboard( ( (keySym&0xff00) != 0?( (keySym&0x00ff) + 256 ):( keySym ) ) );
|
|
143 break;
|
|
144 }
|
|
145 return 0;
|
|
146 }
|
|
147
|
|
148 static XEvent mEvent;
|
|
149
|
|
150 static uint32_t init( uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format )
|
|
151 {
|
|
152 char * frame_mem;
|
|
153 uint32_t frame_size;
|
|
154 int mScreen;
|
|
155 unsigned int fg, bg;
|
|
156 char * mTitle=(title == NULL) ? "XMGA render" : title;
|
|
157 char * name=":0.0";
|
|
158 XSizeHints hint;
|
|
159 XVisualInfo vinfo;
|
|
160 XEvent xev;
|
|
161
|
|
162 XGCValues xgcv;
|
|
163 unsigned long xswamask;
|
|
164
|
|
165 f=open( "/dev/mga_vid",O_RDWR );
|
|
166 if ( f == -1 )
|
|
167 {
|
|
168 fprintf(stderr,"Couldn't open /dev/mga_vid\n");
|
|
169 return(-1);
|
|
170 }
|
|
171
|
|
172 switch(format)
|
|
173 {
|
|
174 case IMGFMT_YV12: mga_vid_config.format=MGA_VID_FORMAT_YV12; break;
|
|
175 case IMGFMT_YUY2: mga_vid_config.format=MGA_VID_FORMAT_YUY2; break;
|
|
176 default: fprintf(stderr,"mga: invalid output format %0X\n",format); return (-1);
|
|
177 }
|
|
178
|
|
179 if ( X_already_started ) return -1;
|
|
180
|
|
181 vo_init();
|
|
182
|
|
183 if ( getenv( "DISPLAY" ) ) name=getenv( "DISPLAY" );
|
|
184 mDisplay=XOpenDisplay(name);
|
|
185 if ( mDisplay == NULL )
|
|
186 {
|
|
187 fprintf( stderr,"Can not open display\n" );
|
|
188 return -1;
|
|
189 }
|
|
190
|
|
191 mScreen=DefaultScreen( mDisplay );
|
|
192
|
|
193 mvWidth=width; mvHeight=height;
|
|
194
|
|
195 wndX=0; wndY=0;
|
|
196 wndWidth=d_width; wndHeight=d_height;
|
|
197 dwidth=d_width; dheight=d_height;
|
|
198 mFullscreen=fullscreen;
|
|
199
|
|
200 if ( fullscreen )
|
|
201 {
|
|
202 wndWidth=vo_screenwidth;
|
|
203 wndHeight=vo_screenheight;
|
|
204 }
|
|
205
|
|
206 XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs );
|
|
207 mDepth=attribs.depth;
|
|
208 if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24;
|
|
209 XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo );
|
|
210 xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone );
|
|
211 switch ( vo_depthonscreen )
|
|
212 {
|
|
213 case 32:
|
|
214 case 24: fgColor=0x00ff00ffL; break;
|
|
215 case 16: fgColor=0xf81fL; break;
|
|
216 case 15: fgColor=0x7c1fL; break;
|
|
217 default: fprintf( stderr,"Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1;
|
|
218 }
|
|
219 xWAttribs.background_pixel=0;
|
|
220 xWAttribs.border_pixel=0;
|
|
221 xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask;
|
|
222 xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
|
223
|
|
224 mWindow=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ),
|
|
225 wndX,wndY,
|
|
226 wndWidth,wndHeight,
|
|
227 xWAttribs.border_pixel,
|
|
228 mDepth,
|
|
229 InputOutput,
|
|
230 vinfo.visual,xswamask,&xWAttribs );
|
|
231
|
|
232 if ( fullscreen ) vo_decoration( mDisplay,mWindow,0 );
|
|
233
|
|
234 XGetNormalHints( mDisplay,mWindow,&hint );
|
|
235 hint.x=wndX; hint.y=wndY;
|
|
236 hint.width=wndWidth; hint.height=wndHeight;
|
|
237 hint.base_width=wndWidth; hint.base_height=wndHeight;
|
|
238 hint.flags=USPosition | USSize;
|
|
239 XSetNormalHints( mDisplay,mWindow,&hint );
|
|
240 XStoreName( mDisplay,mWindow,mTitle );
|
|
241
|
|
242 mGC=XCreateGC( mDisplay,mWindow,GCForeground,&wGCV );
|
|
243
|
|
244 XMapWindow( mDisplay,mWindow );
|
|
245
|
|
246 XGetGeometry( mDisplay,mWindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
|
|
247 drwX=0; drwY=0; drwWidth=wndWidth; drwHeight=wndHeight;
|
|
248 XTranslateCoordinates( mDisplay,mWindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
|
|
249
|
|
250 if ( fullscreen )
|
|
251 {
|
|
252 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2;
|
|
253 drwcX=drwX;
|
|
254 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2;
|
|
255 drwcY=drwY;
|
|
256 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth);
|
|
257 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight);
|
|
258 }
|
|
259
|
|
260 mDrawColorKey();
|
|
261
|
|
262 mga_vid_config.src_width=width;
|
|
263 mga_vid_config.src_height=height;
|
|
264 mga_vid_config.x_org=drwcX;
|
|
265 mga_vid_config.y_org=drwcY;
|
|
266 mga_vid_config.dest_width=drwWidth;
|
|
267 mga_vid_config.dest_height=drwHeight;
|
|
268
|
|
269 fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
|
|
270
|
|
271 mga_vid_config.colkey_on=1;
|
|
272 mga_vid_config.colkey_red=255;
|
|
273 mga_vid_config.colkey_green=0;
|
|
274 mga_vid_config.colkey_blue=255;
|
|
275
|
|
276 #if 1
|
|
277 if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) )
|
|
278 {
|
|
279 fprintf( stderr,"Error in mga_vid_config ioctl" );
|
|
280 return -1;
|
|
281 }
|
|
282 ioctl( f,MGA_VID_ON,0 );
|
|
283 #endif
|
|
284
|
|
285 frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2;
|
|
286 frame_mem=(char*)mmap( 0,frame_size*2,PROT_WRITE,MAP_SHARED,f,0 );
|
|
287 frame0=frame_mem;
|
|
288 frame1=frame_mem + frame_size;
|
|
289 vid_data=frame0;
|
|
290 next_frame=0;
|
|
291 memset( frame_mem,0x80,frame_size * 2 );
|
|
292
|
|
293 XFlush( mDisplay );
|
|
294 XSync( mDisplay,False );
|
|
295
|
|
296 // vo_initthread( mThread );
|
|
297
|
|
298 if((vo_eventhandler_pid=fork())==0){
|
|
299 XIfEvent( mDisplay,&mEvent,mEvents,NULL );
|
|
300 exit(0);
|
|
301 }
|
|
302
|
|
303 return 0;
|
|
304 }
|
|
305
|
|
306 static const vo_info_t* get_info( void )
|
|
307 { return &vo_info; }
|
|
308
|
|
309
|
|
310 static void
|
|
311 uninit(void)
|
|
312 {
|
|
313 ioctl( f,MGA_VID_OFF,0 );
|
|
314 printf("vo: uninit!\n");
|
|
315 vo_kill_eventhandler();
|
|
316 }
|
|
317
|
|
318
|
|
319
|