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