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 Display * mDisplay;
|
|
57 static Window mWindow;
|
|
58 static GC mGC;
|
|
59 static XGCValues wGCV;
|
|
60
|
|
61 static XImage * myximage;
|
|
62
|
|
63 static uint32_t mDepth, bpp, mode;
|
|
64 static XWindowAttributes attribs;
|
|
65 static uint32_t X_already_started=0;
|
|
66
|
|
67 static uint32_t wndHeight;
|
|
68 static uint32_t wndWidth;
|
|
69 static uint32_t wndX;
|
|
70 static uint32_t wndY;
|
|
71
|
|
72 static uint32_t fgColor;
|
|
73
|
|
74 static uint32_t mvHeight;
|
|
75 static uint32_t mvWidth;
|
|
76
|
|
77 static Window mRoot;
|
|
78 static uint32_t drwX,drwY,drwWidth,drwHeight,drwBorderWidth,drwDepth;
|
|
79 static uint32_t drwcX,drwcY,dwidth,dheight,mFullscreen;
|
|
80
|
|
81 static XSetWindowAttributes xWAttribs;
|
|
82
|
|
83 #include "mga_common.c"
|
|
84
|
|
85
|
31
|
86
|
1
|
87 static void mDrawColorKey( void )
|
|
88 {
|
|
89 XClearWindow( mDisplay,mWindow );
|
|
90 XSetForeground( mDisplay,mGC,fgColor );
|
|
91 XFillRectangle( mDisplay,mWindow,mGC,drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight) );
|
|
92 XFlush( mDisplay );
|
|
93 }
|
|
94
|
31
|
95 static void check_events(void)
|
1
|
96 {
|
31
|
97 int e=vo_x11_check_events(mDisplay);
|
1
|
98
|
31
|
99 if(e&VO_EVENT_RESIZE){
|
1
|
100 XGetGeometry( mDisplay,mWindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
|
|
101 drwX=0; drwY=0;
|
|
102 XTranslateCoordinates( mDisplay,mWindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
|
|
103 if ( mFullscreen )
|
|
104 {
|
|
105 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2;
|
|
106 drwcX=drwX;
|
|
107 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2;
|
|
108 drwcY=drwY;
|
|
109 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth);
|
|
110 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight);
|
|
111 }
|
|
112
|
|
113 mDrawColorKey();
|
|
114 mga_vid_config.x_org=drwcX;
|
|
115 mga_vid_config.y_org=drwcY;
|
|
116 mga_vid_config.dest_width=drwWidth;
|
|
117 mga_vid_config.dest_height=drwHeight;
|
|
118
|
|
119 fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
|
|
120
|
|
121 if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) )
|
|
122 {
|
|
123 fprintf( stderr,"Error in mga_vid_config ioctl" );
|
31
|
124 // exit( 0 );
|
1
|
125 }
|
31
|
126
|
|
127 } else
|
|
128 if(e&VO_EVENT_EXPOSE) mDrawColorKey();
|
|
129
|
1
|
130 }
|
|
131
|
31
|
132 static void flip_page(void){
|
|
133 check_events();
|
|
134 vo_mga_flip_page();
|
|
135 }
|
1
|
136
|
|
137 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 )
|
|
138 {
|
|
139 char * frame_mem;
|
56
|
140 // uint32_t frame_size;
|
1
|
141 int mScreen;
|
|
142 unsigned int fg, bg;
|
|
143 char * mTitle=(title == NULL) ? "XMGA render" : title;
|
|
144 char * name=":0.0";
|
|
145 XSizeHints hint;
|
|
146 XVisualInfo vinfo;
|
|
147 XEvent xev;
|
|
148
|
|
149 XGCValues xgcv;
|
|
150 unsigned long xswamask;
|
|
151
|
|
152 f=open( "/dev/mga_vid",O_RDWR );
|
|
153 if ( f == -1 )
|
|
154 {
|
|
155 fprintf(stderr,"Couldn't open /dev/mga_vid\n");
|
|
156 return(-1);
|
|
157 }
|
|
158
|
|
159 switch(format)
|
|
160 {
|
56
|
161 case IMGFMT_YV12:
|
|
162 mga_vid_config.format=MGA_VID_FORMAT_YV12;
|
|
163 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2;
|
|
164 break;
|
|
165 case IMGFMT_YUY2:
|
|
166 mga_vid_config.format=MGA_VID_FORMAT_YUY2;
|
|
167 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height * 2;
|
|
168 break;
|
1
|
169 default: fprintf(stderr,"mga: invalid output format %0X\n",format); return (-1);
|
|
170 }
|
|
171
|
|
172 if ( X_already_started ) return -1;
|
|
173
|
|
174 vo_init();
|
|
175
|
|
176 if ( getenv( "DISPLAY" ) ) name=getenv( "DISPLAY" );
|
|
177 mDisplay=XOpenDisplay(name);
|
|
178 if ( mDisplay == NULL )
|
|
179 {
|
|
180 fprintf( stderr,"Can not open display\n" );
|
|
181 return -1;
|
|
182 }
|
|
183
|
|
184 mScreen=DefaultScreen( mDisplay );
|
|
185
|
|
186 mvWidth=width; mvHeight=height;
|
|
187
|
|
188 wndX=0; wndY=0;
|
|
189 wndWidth=d_width; wndHeight=d_height;
|
|
190 dwidth=d_width; dheight=d_height;
|
|
191 mFullscreen=fullscreen;
|
|
192
|
|
193 if ( fullscreen )
|
|
194 {
|
|
195 wndWidth=vo_screenwidth;
|
|
196 wndHeight=vo_screenheight;
|
|
197 }
|
|
198
|
|
199 XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs );
|
|
200 mDepth=attribs.depth;
|
|
201 if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24;
|
|
202 XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo );
|
|
203 xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone );
|
|
204 switch ( vo_depthonscreen )
|
|
205 {
|
|
206 case 32:
|
|
207 case 24: fgColor=0x00ff00ffL; break;
|
|
208 case 16: fgColor=0xf81fL; break;
|
|
209 case 15: fgColor=0x7c1fL; break;
|
|
210 default: fprintf( stderr,"Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1;
|
|
211 }
|
|
212 xWAttribs.background_pixel=0;
|
|
213 xWAttribs.border_pixel=0;
|
|
214 xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask;
|
|
215 xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
|
216
|
|
217 mWindow=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ),
|
|
218 wndX,wndY,
|
|
219 wndWidth,wndHeight,
|
|
220 xWAttribs.border_pixel,
|
|
221 mDepth,
|
|
222 InputOutput,
|
|
223 vinfo.visual,xswamask,&xWAttribs );
|
|
224
|
31
|
225 if ( fullscreen ) vo_x11_decoration( mDisplay,mWindow,0 );
|
1
|
226
|
|
227 XGetNormalHints( mDisplay,mWindow,&hint );
|
|
228 hint.x=wndX; hint.y=wndY;
|
|
229 hint.width=wndWidth; hint.height=wndHeight;
|
|
230 hint.base_width=wndWidth; hint.base_height=wndHeight;
|
|
231 hint.flags=USPosition | USSize;
|
|
232 XSetNormalHints( mDisplay,mWindow,&hint );
|
|
233 XStoreName( mDisplay,mWindow,mTitle );
|
|
234
|
|
235 mGC=XCreateGC( mDisplay,mWindow,GCForeground,&wGCV );
|
|
236
|
|
237 XMapWindow( mDisplay,mWindow );
|
|
238
|
|
239 XGetGeometry( mDisplay,mWindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
|
|
240 drwX=0; drwY=0; drwWidth=wndWidth; drwHeight=wndHeight;
|
|
241 XTranslateCoordinates( mDisplay,mWindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
|
|
242
|
|
243 if ( fullscreen )
|
|
244 {
|
|
245 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2;
|
|
246 drwcX=drwX;
|
|
247 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2;
|
|
248 drwcY=drwY;
|
|
249 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth);
|
|
250 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight);
|
|
251 }
|
|
252
|
|
253 mDrawColorKey();
|
|
254
|
|
255 mga_vid_config.src_width=width;
|
|
256 mga_vid_config.src_height=height;
|
56
|
257 mga_vid_config.dest_width=drwWidth;
|
|
258 mga_vid_config.dest_height=drwHeight;
|
1
|
259 mga_vid_config.x_org=drwcX;
|
|
260 mga_vid_config.y_org=drwcY;
|
|
261
|
|
262 fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
|
|
263
|
|
264 mga_vid_config.colkey_on=1;
|
|
265 mga_vid_config.colkey_red=255;
|
|
266 mga_vid_config.colkey_green=0;
|
|
267 mga_vid_config.colkey_blue=255;
|
|
268
|
56
|
269 if(mga_init()) return -1;
|
1
|
270
|
|
271 XFlush( mDisplay );
|
|
272 XSync( mDisplay,False );
|
|
273
|
|
274 return 0;
|
|
275 }
|
|
276
|
|
277 static const vo_info_t* get_info( void )
|
|
278 { return &vo_info; }
|
|
279
|
|
280
|
|
281 static void
|
|
282 uninit(void)
|
|
283 {
|
|
284 ioctl( f,MGA_VID_OFF,0 );
|
|
285 printf("vo: uninit!\n");
|
|
286 }
|