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
|
31
|
46 #include "x11_common.h"
|
|
47
|
1
|
48 static vo_info_t vo_info =
|
|
49 {
|
|
50 "X11 (Matrox G200/G400 overlay in window using /dev/mga_vid)",
|
|
51 "xmga",
|
|
52 "Zoltan Ponekker <pontscho@makacs.poliod.hu>",
|
|
53 ""
|
|
54 };
|
|
55
|
|
56 static mga_vid_config_t mga_vid_config;
|
|
57 static uint8_t * vid_data;
|
47
|
58 static uint8_t * frames[4];
|
1
|
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
|
31
|
91
|
1
|
92 static void mDrawColorKey( void )
|
|
93 {
|
|
94 XClearWindow( mDisplay,mWindow );
|
|
95 XSetForeground( mDisplay,mGC,fgColor );
|
|
96 XFillRectangle( mDisplay,mWindow,mGC,drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight) );
|
|
97 XFlush( mDisplay );
|
|
98 }
|
|
99
|
31
|
100 static void check_events(void)
|
1
|
101 {
|
31
|
102 int e=vo_x11_check_events(mDisplay);
|
1
|
103
|
31
|
104 if(e&VO_EVENT_RESIZE){
|
1
|
105 XGetGeometry( mDisplay,mWindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
|
|
106 drwX=0; drwY=0;
|
|
107 XTranslateCoordinates( mDisplay,mWindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
|
|
108 if ( mFullscreen )
|
|
109 {
|
|
110 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2;
|
|
111 drwcX=drwX;
|
|
112 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2;
|
|
113 drwcY=drwY;
|
|
114 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth);
|
|
115 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight);
|
|
116 }
|
|
117
|
|
118 mDrawColorKey();
|
|
119 mga_vid_config.x_org=drwcX;
|
|
120 mga_vid_config.y_org=drwcY;
|
|
121 mga_vid_config.dest_width=drwWidth;
|
|
122 mga_vid_config.dest_height=drwHeight;
|
|
123
|
|
124 fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
|
|
125
|
|
126 if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) )
|
|
127 {
|
|
128 fprintf( stderr,"Error in mga_vid_config ioctl" );
|
31
|
129 // exit( 0 );
|
1
|
130 }
|
31
|
131
|
|
132 } else
|
|
133 if(e&VO_EVENT_EXPOSE) mDrawColorKey();
|
|
134
|
1
|
135 }
|
|
136
|
31
|
137 static void flip_page(void){
|
|
138 check_events();
|
|
139 vo_mga_flip_page();
|
|
140 }
|
1
|
141
|
|
142 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 )
|
|
143 {
|
|
144 char * frame_mem;
|
|
145 uint32_t frame_size;
|
|
146 int mScreen;
|
|
147 unsigned int fg, bg;
|
|
148 char * mTitle=(title == NULL) ? "XMGA render" : title;
|
|
149 char * name=":0.0";
|
|
150 XSizeHints hint;
|
|
151 XVisualInfo vinfo;
|
|
152 XEvent xev;
|
|
153
|
|
154 XGCValues xgcv;
|
|
155 unsigned long xswamask;
|
|
156
|
|
157 f=open( "/dev/mga_vid",O_RDWR );
|
|
158 if ( f == -1 )
|
|
159 {
|
|
160 fprintf(stderr,"Couldn't open /dev/mga_vid\n");
|
|
161 return(-1);
|
|
162 }
|
|
163
|
|
164 switch(format)
|
|
165 {
|
|
166 case IMGFMT_YV12: mga_vid_config.format=MGA_VID_FORMAT_YV12; break;
|
|
167 case IMGFMT_YUY2: mga_vid_config.format=MGA_VID_FORMAT_YUY2; break;
|
|
168 default: fprintf(stderr,"mga: invalid output format %0X\n",format); return (-1);
|
|
169 }
|
|
170
|
|
171 if ( X_already_started ) return -1;
|
|
172
|
|
173 vo_init();
|
|
174
|
|
175 if ( getenv( "DISPLAY" ) ) name=getenv( "DISPLAY" );
|
|
176 mDisplay=XOpenDisplay(name);
|
|
177 if ( mDisplay == NULL )
|
|
178 {
|
|
179 fprintf( stderr,"Can not open display\n" );
|
|
180 return -1;
|
|
181 }
|
|
182
|
|
183 mScreen=DefaultScreen( mDisplay );
|
|
184
|
|
185 mvWidth=width; mvHeight=height;
|
|
186
|
|
187 wndX=0; wndY=0;
|
|
188 wndWidth=d_width; wndHeight=d_height;
|
|
189 dwidth=d_width; dheight=d_height;
|
|
190 mFullscreen=fullscreen;
|
|
191
|
|
192 if ( fullscreen )
|
|
193 {
|
|
194 wndWidth=vo_screenwidth;
|
|
195 wndHeight=vo_screenheight;
|
|
196 }
|
|
197
|
|
198 XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs );
|
|
199 mDepth=attribs.depth;
|
|
200 if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24;
|
|
201 XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo );
|
|
202 xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone );
|
|
203 switch ( vo_depthonscreen )
|
|
204 {
|
|
205 case 32:
|
|
206 case 24: fgColor=0x00ff00ffL; break;
|
|
207 case 16: fgColor=0xf81fL; break;
|
|
208 case 15: fgColor=0x7c1fL; break;
|
|
209 default: fprintf( stderr,"Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1;
|
|
210 }
|
|
211 xWAttribs.background_pixel=0;
|
|
212 xWAttribs.border_pixel=0;
|
|
213 xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask;
|
|
214 xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
|
215
|
|
216 mWindow=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ),
|
|
217 wndX,wndY,
|
|
218 wndWidth,wndHeight,
|
|
219 xWAttribs.border_pixel,
|
|
220 mDepth,
|
|
221 InputOutput,
|
|
222 vinfo.visual,xswamask,&xWAttribs );
|
|
223
|
31
|
224 if ( fullscreen ) vo_x11_decoration( mDisplay,mWindow,0 );
|
1
|
225
|
|
226 XGetNormalHints( mDisplay,mWindow,&hint );
|
|
227 hint.x=wndX; hint.y=wndY;
|
|
228 hint.width=wndWidth; hint.height=wndHeight;
|
|
229 hint.base_width=wndWidth; hint.base_height=wndHeight;
|
|
230 hint.flags=USPosition | USSize;
|
|
231 XSetNormalHints( mDisplay,mWindow,&hint );
|
|
232 XStoreName( mDisplay,mWindow,mTitle );
|
|
233
|
|
234 mGC=XCreateGC( mDisplay,mWindow,GCForeground,&wGCV );
|
|
235
|
|
236 XMapWindow( mDisplay,mWindow );
|
|
237
|
|
238 XGetGeometry( mDisplay,mWindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
|
|
239 drwX=0; drwY=0; drwWidth=wndWidth; drwHeight=wndHeight;
|
|
240 XTranslateCoordinates( mDisplay,mWindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
|
|
241
|
|
242 if ( fullscreen )
|
|
243 {
|
|
244 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2;
|
|
245 drwcX=drwX;
|
|
246 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2;
|
|
247 drwcY=drwY;
|
|
248 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth);
|
|
249 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight);
|
|
250 }
|
|
251
|
|
252 mDrawColorKey();
|
|
253
|
|
254 mga_vid_config.src_width=width;
|
|
255 mga_vid_config.src_height=height;
|
|
256 mga_vid_config.x_org=drwcX;
|
|
257 mga_vid_config.y_org=drwcY;
|
|
258 mga_vid_config.dest_width=drwWidth;
|
|
259 mga_vid_config.dest_height=drwHeight;
|
|
260
|
|
261 fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
|
|
262
|
|
263 mga_vid_config.colkey_on=1;
|
|
264 mga_vid_config.colkey_red=255;
|
|
265 mga_vid_config.colkey_green=0;
|
|
266 mga_vid_config.colkey_blue=255;
|
|
267
|
|
268 #if 1
|
|
269 if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) )
|
|
270 {
|
|
271 fprintf( stderr,"Error in mga_vid_config ioctl" );
|
|
272 return -1;
|
|
273 }
|
|
274 ioctl( f,MGA_VID_ON,0 );
|
|
275 #endif
|
|
276
|
|
277 frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2;
|
47
|
278 frame_mem=(char*)mmap( 0,frame_size*4,PROT_WRITE,MAP_SHARED,f,0 );
|
|
279 frames[0] = frame_mem;
|
|
280 frames[1] = frame_mem + 1*frame_size;
|
|
281 frames[2] = frame_mem + 2*frame_size;
|
|
282 frames[3] = frame_mem + 3*frame_size;
|
|
283 mga_next_frame=0;
|
|
284 vid_data=frames[mga_next_frame];
|
|
285 memset( frame_mem,0x80,frame_size * 4 );
|
1
|
286
|
|
287 XFlush( mDisplay );
|
|
288 XSync( mDisplay,False );
|
|
289
|
|
290 // vo_initthread( mThread );
|
|
291
|
|
292 return 0;
|
|
293 }
|
|
294
|
|
295 static const vo_info_t* get_info( void )
|
|
296 { return &vo_info; }
|
|
297
|
|
298
|
|
299 static void
|
|
300 uninit(void)
|
|
301 {
|
|
302 ioctl( f,MGA_VID_OFF,0 );
|
|
303 printf("vo: uninit!\n");
|
|
304 }
|
|
305
|
|
306
|
|
307
|