100
|
1
|
|
2 //#define SHOW_TIME
|
1
|
3
|
|
4 /*
|
|
5 * video_out_xmga.c
|
|
6 *
|
|
7 * Copyright (C) Zoltan Ponekker - Jan 2001
|
|
8 *
|
|
9 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
|
|
10 *
|
|
11 * mpeg2dec is free software; you can redistribute it and/or modify
|
|
12 * it under the terms of the GNU General Public License as published by
|
|
13 * the Free Software Foundation; either version 2, or (at your option)
|
|
14 * any later version.
|
|
15 *
|
|
16 * mpeg2dec is distributed in the hope that it will be useful,
|
|
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 * GNU General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with GNU Make; see the file COPYING. If not, write to
|
|
23 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
24 *
|
|
25 */
|
|
26
|
|
27 #include <stdio.h>
|
|
28 #include <stdlib.h>
|
|
29 #include <string.h>
|
|
30
|
|
31 #include "config.h"
|
|
32 #include "video_out.h"
|
|
33 #include "video_out_internal.h"
|
|
34
|
|
35 LIBVO_EXTERN( xmga )
|
|
36
|
|
37 #include <sys/ioctl.h>
|
|
38 #include <unistd.h>
|
|
39 #include <fcntl.h>
|
|
40 #include <sys/mman.h>
|
|
41
|
|
42 #include "drivers/mga_vid.h"
|
|
43
|
|
44 #include <X11/Xlib.h>
|
|
45 #include <X11/Xutil.h>
|
|
46 #include <errno.h>
|
|
47
|
31
|
48 #include "x11_common.h"
|
|
49
|
182
|
50 #ifdef SHOW_TIME
|
100
|
51 #include "../linux/timer.h"
|
|
52 static unsigned int timer=0;
|
|
53 static unsigned int timerd=0;
|
|
54 #endif
|
|
55
|
1
|
56 static vo_info_t vo_info =
|
|
57 {
|
|
58 "X11 (Matrox G200/G400 overlay in window using /dev/mga_vid)",
|
|
59 "xmga",
|
|
60 "Zoltan Ponekker <pontscho@makacs.poliod.hu>",
|
|
61 ""
|
|
62 };
|
|
63
|
|
64 static Display * mDisplay;
|
|
65 static Window mWindow;
|
|
66 static GC mGC;
|
|
67 static XGCValues wGCV;
|
|
68
|
|
69 static XImage * myximage;
|
|
70
|
|
71 static uint32_t mDepth, bpp, mode;
|
|
72 static XWindowAttributes attribs;
|
|
73 static uint32_t X_already_started=0;
|
|
74
|
|
75 static uint32_t wndHeight;
|
|
76 static uint32_t wndWidth;
|
|
77 static uint32_t wndX;
|
|
78 static uint32_t wndY;
|
|
79
|
|
80 static uint32_t fgColor;
|
|
81
|
|
82 static uint32_t mvHeight;
|
|
83 static uint32_t mvWidth;
|
|
84
|
|
85 static Window mRoot;
|
|
86 static uint32_t drwX,drwY,drwWidth,drwHeight,drwBorderWidth,drwDepth;
|
|
87 static uint32_t drwcX,drwcY,dwidth,dheight,mFullscreen;
|
|
88
|
|
89 static XSetWindowAttributes xWAttribs;
|
|
90
|
|
91 #include "mga_common.c"
|
|
92
|
|
93 static void mDrawColorKey( void )
|
|
94 {
|
|
95 XClearWindow( mDisplay,mWindow );
|
|
96 XSetForeground( mDisplay,mGC,fgColor );
|
|
97 XFillRectangle( mDisplay,mWindow,mGC,drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight) );
|
|
98 XFlush( mDisplay );
|
|
99 }
|
|
100
|
120
|
101 static void set_window(){
|
|
102
|
|
103 XGetGeometry( mDisplay,mWindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth );
|
|
104 drwX=0; drwY=0; // drwWidth=wndWidth; drwHeight=wndHeight;
|
|
105 XTranslateCoordinates( mDisplay,mWindow,mRoot,0,0,&drwcX,&drwcY,&mRoot );
|
340
|
106 //fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
|
120
|
107
|
|
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);
|
340
|
116 //fprintf( stderr,"[xmga-fs] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight );
|
120
|
117 }
|
|
118
|
|
119 mDrawColorKey();
|
|
120
|
|
121 mga_vid_config.x_org=drwcX;
|
|
122 mga_vid_config.y_org=drwcY;
|
|
123 mga_vid_config.dest_width=drwWidth;
|
|
124 mga_vid_config.dest_height=drwHeight;
|
|
125
|
|
126 }
|
|
127
|
31
|
128 static void check_events(void)
|
1
|
129 {
|
31
|
130 int e=vo_x11_check_events(mDisplay);
|
1
|
131
|
31
|
132 if(e&VO_EVENT_RESIZE){
|
120
|
133 set_window();
|
1
|
134 if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) )
|
|
135 {
|
340
|
136 fprintf( stderr,"Error in mga_vid_config ioctl (wrong mga_vid.o version?)" );
|
31
|
137 // exit( 0 );
|
1
|
138 }
|
31
|
139
|
|
140 } else
|
|
141 if(e&VO_EVENT_EXPOSE) mDrawColorKey();
|
|
142
|
1
|
143 }
|
|
144
|
31
|
145 static void flip_page(void){
|
182
|
146 #ifdef SHOW_TIME
|
100
|
147 unsigned int t;
|
|
148 t=GetTimer();
|
|
149 printf(" [timer: %08X diff: %6d dd: %6d ] \n",t,t-timer,(t-timer)-timerd);
|
|
150 timerd=t-timer;
|
|
151 timer=t;
|
182
|
152 #endif
|
100
|
153
|
213
|
154 vo_draw_text(mga_vid_config.src_width,mga_vid_config.src_height,draw_alpha);
|
202
|
155
|
31
|
156 check_events();
|
|
157 vo_mga_flip_page();
|
|
158 }
|
1
|
159
|
|
160 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 )
|
|
161 {
|
|
162 char * frame_mem;
|
56
|
163 // uint32_t frame_size;
|
1
|
164 int mScreen;
|
|
165 unsigned int fg, bg;
|
|
166 char * mTitle=(title == NULL) ? "XMGA render" : title;
|
|
167 char * name=":0.0";
|
|
168 XSizeHints hint;
|
|
169 XVisualInfo vinfo;
|
|
170 XEvent xev;
|
|
171
|
|
172 XGCValues xgcv;
|
|
173 unsigned long xswamask;
|
|
174
|
|
175 f=open( "/dev/mga_vid",O_RDWR );
|
|
176 if ( f == -1 )
|
|
177 {
|
|
178 fprintf(stderr,"Couldn't open /dev/mga_vid\n");
|
|
179 return(-1);
|
|
180 }
|
|
181
|
|
182 switch(format)
|
|
183 {
|
182
|
184 case IMGFMT_YV12:
|
56
|
185 mga_vid_config.format=MGA_VID_FORMAT_YV12;
|
182
|
186 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2;
|
56
|
187 break;
|
|
188 case IMGFMT_YUY2:
|
|
189 mga_vid_config.format=MGA_VID_FORMAT_YUY2;
|
182
|
190 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height * 2;
|
56
|
191 break;
|
1
|
192 default: fprintf(stderr,"mga: invalid output format %0X\n",format); return (-1);
|
|
193 }
|
|
194
|
|
195 if ( X_already_started ) return -1;
|
|
196
|
|
197 vo_init();
|
|
198
|
|
199 if ( getenv( "DISPLAY" ) ) name=getenv( "DISPLAY" );
|
|
200 mDisplay=XOpenDisplay(name);
|
|
201 if ( mDisplay == NULL )
|
|
202 {
|
340
|
203 fprintf( stderr,"Can not open X11 display\n" );
|
1
|
204 return -1;
|
|
205 }
|
|
206
|
|
207 mScreen=DefaultScreen( mDisplay );
|
|
208
|
|
209 mvWidth=width; mvHeight=height;
|
|
210
|
|
211 wndX=0; wndY=0;
|
|
212 wndWidth=d_width; wndHeight=d_height;
|
|
213 dwidth=d_width; dheight=d_height;
|
|
214 mFullscreen=fullscreen;
|
|
215
|
|
216 if ( fullscreen )
|
|
217 {
|
|
218 wndWidth=vo_screenwidth;
|
|
219 wndHeight=vo_screenheight;
|
|
220 }
|
|
221
|
|
222 XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs );
|
|
223 mDepth=attribs.depth;
|
|
224 if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24;
|
|
225 XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo );
|
|
226 xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone );
|
|
227 switch ( vo_depthonscreen )
|
|
228 {
|
|
229 case 32:
|
|
230 case 24: fgColor=0x00ff00ffL; break;
|
|
231 case 16: fgColor=0xf81fL; break;
|
|
232 case 15: fgColor=0x7c1fL; break;
|
|
233 default: fprintf( stderr,"Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1;
|
|
234 }
|
|
235 xWAttribs.background_pixel=0;
|
|
236 xWAttribs.border_pixel=0;
|
|
237 xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask;
|
|
238 xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
|
|
239
|
|
240 mWindow=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ),
|
|
241 wndX,wndY,
|
|
242 wndWidth,wndHeight,
|
|
243 xWAttribs.border_pixel,
|
|
244 mDepth,
|
|
245 InputOutput,
|
|
246 vinfo.visual,xswamask,&xWAttribs );
|
384
|
247 vo_hidecursor(mDisplay,mWindow);
|
1
|
248
|
31
|
249 if ( fullscreen ) vo_x11_decoration( mDisplay,mWindow,0 );
|
1
|
250
|
|
251 XGetNormalHints( mDisplay,mWindow,&hint );
|
|
252 hint.x=wndX; hint.y=wndY;
|
|
253 hint.width=wndWidth; hint.height=wndHeight;
|
|
254 hint.base_width=wndWidth; hint.base_height=wndHeight;
|
|
255 hint.flags=USPosition | USSize;
|
|
256 XSetNormalHints( mDisplay,mWindow,&hint );
|
|
257 XStoreName( mDisplay,mWindow,mTitle );
|
|
258
|
|
259 mGC=XCreateGC( mDisplay,mWindow,GCForeground,&wGCV );
|
|
260
|
|
261 XMapWindow( mDisplay,mWindow );
|
182
|
262
|
120
|
263 set_window();
|
1
|
264
|
|
265 mga_vid_config.src_width=width;
|
|
266 mga_vid_config.src_height=height;
|
|
267
|
|
268 mga_vid_config.colkey_on=1;
|
|
269 mga_vid_config.colkey_red=255;
|
|
270 mga_vid_config.colkey_green=0;
|
|
271 mga_vid_config.colkey_blue=255;
|
|
272
|
56
|
273 if(mga_init()) return -1;
|
1
|
274
|
|
275 XFlush( mDisplay );
|
|
276 XSync( mDisplay,False );
|
|
277
|
324
|
278 saver_off(mDisplay);
|
|
279
|
1
|
280 return 0;
|
|
281 }
|
|
282
|
|
283 static const vo_info_t* get_info( void )
|
|
284 { return &vo_info; }
|
|
285
|
|
286
|
|
287 static void
|
|
288 uninit(void)
|
|
289 {
|
324
|
290 saver_on(mDisplay);
|
1
|
291 ioctl( f,MGA_VID_OFF,0 );
|
|
292 printf("vo: uninit!\n");
|
|
293 }
|