Mercurial > mplayer.hg
annotate libvo/vo_xmga.c @ 548:c5c2d4e41a4a
added sdl versiondetect and removed sdl warning (it's autodetect now)
author | atmosfear |
---|---|
date | Fri, 20 Apr 2001 17:27:38 +0000 |
parents | 8e101a5d9dc2 |
children | 77e0094f0cce |
rev | line source |
---|---|
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; |
470 | 188 case IMGFMT_I420: |
189 mga_vid_config.format=MGA_VID_FORMAT_I420; | |
190 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; | |
191 break; | |
192 case IMGFMT_IYUV: | |
193 mga_vid_config.format=MGA_VID_FORMAT_IYUV; | |
194 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; | |
195 break; | |
56 | 196 case IMGFMT_YUY2: |
197 mga_vid_config.format=MGA_VID_FORMAT_YUY2; | |
182 | 198 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height * 2; |
56 | 199 break; |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
200 case IMGFMT_UYVY: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
201 mga_vid_config.format=MGA_VID_FORMAT_UYVY; |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
202 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height * 2; |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
203 break; |
1 | 204 default: fprintf(stderr,"mga: invalid output format %0X\n",format); return (-1); |
205 } | |
206 | |
207 if ( X_already_started ) return -1; | |
208 | |
209 vo_init(); | |
210 | |
211 if ( getenv( "DISPLAY" ) ) name=getenv( "DISPLAY" ); | |
212 mDisplay=XOpenDisplay(name); | |
213 if ( mDisplay == NULL ) | |
214 { | |
340 | 215 fprintf( stderr,"Can not open X11 display\n" ); |
1 | 216 return -1; |
217 } | |
218 | |
219 mScreen=DefaultScreen( mDisplay ); | |
220 | |
221 mvWidth=width; mvHeight=height; | |
222 | |
223 wndX=0; wndY=0; | |
224 wndWidth=d_width; wndHeight=d_height; | |
225 dwidth=d_width; dheight=d_height; | |
226 mFullscreen=fullscreen; | |
227 | |
228 if ( fullscreen ) | |
229 { | |
230 wndWidth=vo_screenwidth; | |
231 wndHeight=vo_screenheight; | |
232 } | |
233 | |
234 XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs ); | |
235 mDepth=attribs.depth; | |
236 if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24; | |
237 XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo ); | |
238 xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone ); | |
239 switch ( vo_depthonscreen ) | |
240 { | |
241 case 32: | |
242 case 24: fgColor=0x00ff00ffL; break; | |
243 case 16: fgColor=0xf81fL; break; | |
244 case 15: fgColor=0x7c1fL; break; | |
245 default: fprintf( stderr,"Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1; | |
246 } | |
247 xWAttribs.background_pixel=0; | |
248 xWAttribs.border_pixel=0; | |
249 xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask; | |
250 xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; | |
251 | |
252 mWindow=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ), | |
253 wndX,wndY, | |
254 wndWidth,wndHeight, | |
255 xWAttribs.border_pixel, | |
256 mDepth, | |
257 InputOutput, | |
258 vinfo.visual,xswamask,&xWAttribs ); | |
384 | 259 vo_hidecursor(mDisplay,mWindow); |
1 | 260 |
31 | 261 if ( fullscreen ) vo_x11_decoration( mDisplay,mWindow,0 ); |
1 | 262 |
263 XGetNormalHints( mDisplay,mWindow,&hint ); | |
264 hint.x=wndX; hint.y=wndY; | |
265 hint.width=wndWidth; hint.height=wndHeight; | |
266 hint.base_width=wndWidth; hint.base_height=wndHeight; | |
267 hint.flags=USPosition | USSize; | |
268 XSetNormalHints( mDisplay,mWindow,&hint ); | |
269 XStoreName( mDisplay,mWindow,mTitle ); | |
270 | |
271 mGC=XCreateGC( mDisplay,mWindow,GCForeground,&wGCV ); | |
272 | |
273 XMapWindow( mDisplay,mWindow ); | |
182 | 274 |
120 | 275 set_window(); |
1 | 276 |
277 mga_vid_config.src_width=width; | |
278 mga_vid_config.src_height=height; | |
279 | |
280 mga_vid_config.colkey_on=1; | |
281 mga_vid_config.colkey_red=255; | |
282 mga_vid_config.colkey_green=0; | |
283 mga_vid_config.colkey_blue=255; | |
284 | |
56 | 285 if(mga_init()) return -1; |
1 | 286 |
287 XFlush( mDisplay ); | |
288 XSync( mDisplay,False ); | |
289 | |
324 | 290 saver_off(mDisplay); |
291 | |
1 | 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 { | |
324 | 302 saver_on(mDisplay); |
1 | 303 ioctl( f,MGA_VID_OFF,0 ); |
304 printf("vo: uninit!\n"); | |
305 } |