Mercurial > mplayer.hg
annotate libvo/vo_xmga.c @ 4985:01bcb7a9bb4e
+10l to .so
author | arpi |
---|---|
date | Thu, 07 Mar 2002 20:14:52 +0000 |
parents | bfc652fc7f43 |
children | 53c569d36b2c |
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 | |
4017 | 48 #ifdef HAVE_XINERAMA |
49 #include <X11/extensions/Xinerama.h> | |
50 #endif | |
51 | |
31 | 52 #include "x11_common.h" |
616 | 53 #include "sub.h" |
2057 | 54 #include "aspect.h" |
31 | 55 |
182 | 56 #ifdef SHOW_TIME |
100 | 57 #include "../linux/timer.h" |
58 static unsigned int timer=0; | |
59 static unsigned int timerd=0; | |
60 #endif | |
61 | |
1 | 62 static vo_info_t vo_info = |
63 { | |
64 "X11 (Matrox G200/G400 overlay in window using /dev/mga_vid)", | |
65 "xmga", | |
66 "Zoltan Ponekker <pontscho@makacs.poliod.hu>", | |
67 "" | |
68 }; | |
69 | |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
844
diff
changeset
|
70 //static Display * mDisplay; |
1 | 71 static XGCValues wGCV; |
72 | |
73 static XImage * myximage; | |
74 | |
75 static uint32_t mDepth, bpp, mode; | |
76 static XWindowAttributes attribs; | |
77 static uint32_t X_already_started=0; | |
78 | |
79 static uint32_t wndHeight; | |
80 static uint32_t wndWidth; | |
81 static uint32_t wndX; | |
82 static uint32_t wndY; | |
83 | |
84 static uint32_t fgColor; | |
85 | |
86 static uint32_t mvHeight; | |
87 static uint32_t mvWidth; | |
88 | |
89 static Window mRoot; | |
90 static uint32_t drwX,drwY,drwWidth,drwHeight,drwBorderWidth,drwDepth; | |
4981 | 91 static uint32_t drwcX,drwcY,dwidth,dheight; |
1 | 92 |
4985 | 93 //#ifdef HAVE_NEW_GUI |
723 | 94 static uint32_t mdwidth,mdheight; |
4985 | 95 //#endif |
723 | 96 |
1 | 97 static XSetWindowAttributes xWAttribs; |
98 | |
4981 | 99 #define VO_XMGA |
1 | 100 #include "mga_common.c" |
4981 | 101 #undef VO_XMGA |
1 | 102 |
103 static void mDrawColorKey( void ) | |
104 { | |
4795 | 105 XSetBackground( mDisplay,vo_gc,0 ); |
106 XClearWindow( mDisplay,vo_window ); | |
107 XSetForeground( mDisplay,vo_gc,fgColor ); | |
4981 | 108 XFillRectangle( mDisplay,vo_window,vo_gc,drwX,drwY,drwWidth,(vo_fs?drwHeight - 1:drwHeight) ); |
1 | 109 XFlush( mDisplay ); |
110 } | |
111 | |
120 | 112 static void set_window(){ |
113 | |
4981 | 114 dwidth=mdwidth; dheight=mdheight; |
115 if ( vo_fs ) | |
116 { | |
117 dwidth=vo_screenwidth; | |
118 dheight=vo_screenwidth * mdheight / mdwidth; | |
119 } | |
723 | 120 |
4795 | 121 XGetGeometry( mDisplay,vo_window,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth ); |
1852 | 122 drwX=0; drwY=0; // drwWidth=wndWidth; drwHeight=wndHeight; |
4795 | 123 XTranslateCoordinates( mDisplay,vo_window,mRoot,0,0,&drwcX,&drwcY,&mRoot ); |
1852 | 124 fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); |
125 | |
3558 | 126 aspect(&dwidth,&dheight,A_NOZOOM); |
4981 | 127 if ( vo_fs ) |
120 | 128 { |
3558 | 129 aspect(&dwidth,&dheight,A_ZOOM); |
120 | 130 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2; |
131 drwcX+=drwX; | |
132 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2; | |
133 drwcY+=drwY; | |
134 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth); | |
135 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight); | |
1852 | 136 fprintf( stderr,"[xmga-fs] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); |
120 | 137 } |
138 | |
139 mDrawColorKey(); | |
140 | |
4017 | 141 #ifdef HAVE_XINERAMA |
142 if(XineramaIsActive(mDisplay)) | |
143 { | |
144 XineramaScreenInfo *screens; | |
145 int num_screens; | |
146 int i; | |
147 | |
148 screens = XineramaQueryScreens(mDisplay,&num_screens); | |
149 | |
150 /* find the screen we are on */ | |
151 i = 0; | |
152 while(!(screens[i].x_org <= drwcX && screens[i].y_org <= drwcY && | |
153 screens[i].x_org + screens[i].width >= drwcX && | |
154 screens[i].y_org + screens[i].height >= drwcY )) | |
155 { | |
156 i++; | |
157 } | |
158 | |
159 /* set drwcX and drwcY to the right values */ | |
160 drwcX = drwcX - screens[i].x_org; | |
161 drwcY = drwcY - screens[i].y_org; | |
162 XFree(screens); | |
163 } | |
164 | |
165 #endif | |
120 | 166 mga_vid_config.x_org=drwcX; |
167 mga_vid_config.y_org=drwcY; | |
168 mga_vid_config.dest_width=drwWidth; | |
169 mga_vid_config.dest_height=drwHeight; | |
170 | |
171 } | |
172 | |
31 | 173 static void check_events(void) |
1 | 174 { |
4303 | 175 int e=vo_x11_check_events(mDisplay); |
176 if ( !(e&VO_EVENT_RESIZE) && !(e&VO_EVENT_EXPOSE) ) return; | |
177 if(e&VO_EVENT_EXPOSE) mDrawColorKey(); | |
178 set_window(); | |
179 if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) ) | |
180 printf( "Error in mga_vid_config ioctl (wrong mga_vid.o version?)" ); | |
1 | 181 } |
182 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
183 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
184 { vo_draw_text(mga_vid_config.src_width,mga_vid_config.src_height,draw_alpha);} |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
185 |
31 | 186 static void flip_page(void){ |
182 | 187 #ifdef SHOW_TIME |
100 | 188 unsigned int t; |
189 t=GetTimer(); | |
190 printf(" [timer: %08X diff: %6d dd: %6d ] \n",t,t-timer,(t-timer)-timerd); | |
191 timerd=t-timer; | |
192 timer=t; | |
182 | 193 #endif |
100 | 194 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
195 vo_mga_flip_page(); |
31 | 196 } |
1 | 197 |
4433 | 198 static uint32_t config( uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format,const vo_tune_info_t* info) |
1 | 199 { |
200 char * frame_mem; | |
56 | 201 // uint32_t frame_size; |
927 | 202 // int mScreen; |
1 | 203 unsigned int fg, bg; |
204 char * mTitle=(title == NULL) ? "XMGA render" : title; | |
205 char * name=":0.0"; | |
206 XSizeHints hint; | |
207 XVisualInfo vinfo; | |
208 XEvent xev; | |
209 | |
210 XGCValues xgcv; | |
211 unsigned long xswamask; | |
212 | |
1210 | 213 char *devname=vo_subdevice?vo_subdevice:"/dev/mga_vid"; |
214 | |
215 f = open(devname,O_RDWR); | |
216 if(f == -1) | |
217 { | |
1637 | 218 perror("open"); |
1210 | 219 printf("Couldn't open %s\n",devname); |
220 return(-1); | |
221 } | |
1 | 222 |
223 switch(format) | |
224 { | |
182 | 225 case IMGFMT_YV12: |
56 | 226 mga_vid_config.format=MGA_VID_FORMAT_YV12; |
182 | 227 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; |
56 | 228 break; |
470 | 229 case IMGFMT_I420: |
230 mga_vid_config.format=MGA_VID_FORMAT_I420; | |
231 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; | |
232 break; | |
233 case IMGFMT_IYUV: | |
234 mga_vid_config.format=MGA_VID_FORMAT_IYUV; | |
235 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; | |
236 break; | |
56 | 237 case IMGFMT_YUY2: |
238 mga_vid_config.format=MGA_VID_FORMAT_YUY2; | |
182 | 239 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height * 2; |
56 | 240 break; |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
241 case IMGFMT_UYVY: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
242 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
|
243 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
|
244 break; |
614 | 245 default: printf("mga: invalid output format %0X\n",format); return (-1); |
1 | 246 } |
247 | |
248 if ( X_already_started ) return -1; | |
249 | |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
844
diff
changeset
|
250 if (!vo_init()) return -1; |
1 | 251 |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
252 aspect_save_orig(width,height); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
253 aspect_save_prescale(d_width,d_height); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
254 aspect_save_screenres(vo_screenwidth,vo_screenheight); |
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
255 |
1 | 256 mvWidth=width; mvHeight=height; |
257 | |
258 wndX=0; wndY=0; | |
259 wndWidth=d_width; wndHeight=d_height; | |
4981 | 260 vo_fs=fullscreen&1; |
261 vo_dwidth=d_width; vo_dheight=d_height; | |
262 if ( vo_fs ) | |
263 { vo_old_width=d_width; vo_old_height=d_height; } | |
1 | 264 |
265 switch ( vo_depthonscreen ) | |
266 { | |
267 case 32: | |
268 case 24: fgColor=0x00ff00ffL; break; | |
269 case 16: fgColor=0xf81fL; break; | |
270 case 15: fgColor=0x7c1fL; break; | |
614 | 271 default: printf( "Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1; |
1 | 272 } |
273 | |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
274 aspect(&d_width,&d_height,A_NOZOOM); |
1723
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1637
diff
changeset
|
275 #ifdef HAVE_NEW_GUI |
4795 | 276 mdwidth=width; mdheight=height; |
723 | 277 if ( vo_window == None ) |
278 { | |
279 #endif | |
4981 | 280 if ( vo_fs ) |
723 | 281 { |
282 wndWidth=vo_screenwidth; | |
283 wndHeight=vo_screenheight; | |
2039 | 284 #ifdef X11_FULLSCREEN |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
285 aspect(&d_width,&d_height,A_ZOOM); |
2039 | 286 #endif |
723 | 287 } |
2249
48f0ac1e9d13
Update to new (cleaner, more bugfree, better) aspect api. vo_gl vo_gl2 and vo_xmga are untested!
atmos4
parents:
2057
diff
changeset
|
288 dwidth=d_width; dheight=d_height; |
723 | 289 |
290 XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs ); | |
291 mDepth=attribs.depth; | |
292 if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24; | |
293 XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo ); | |
294 xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone ); | |
295 xWAttribs.background_pixel=0; | |
296 xWAttribs.border_pixel=0; | |
4784 | 297 xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask; |
723 | 298 xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; |
1 | 299 |
3847 | 300 if ( WinID>=0 ){ |
4795 | 301 vo_window = WinID ? ((Window)WinID) : RootWindow(mDisplay,mScreen); |
302 XUnmapWindow( mDisplay,vo_window ); | |
303 XChangeWindowAttributes( mDisplay,vo_window,xswamask,&xWAttribs); | |
3847 | 304 } else |
4795 | 305 vo_window=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ), |
723 | 306 wndX,wndY, |
307 wndWidth,wndHeight, | |
308 xWAttribs.border_pixel, | |
309 mDepth, | |
310 InputOutput, | |
311 vinfo.visual,xswamask,&xWAttribs ); | |
4795 | 312 vo_x11_classhint( mDisplay,vo_window,"xmga" ); |
313 vo_hidecursor(mDisplay,vo_window); | |
723 | 314 |
4981 | 315 if ( vo_fs ) vo_x11_decoration( mDisplay,vo_window,0 ); |
1 | 316 |
4795 | 317 XGetNormalHints( mDisplay,vo_window,&hint ); |
723 | 318 hint.x=wndX; hint.y=wndY; |
319 hint.width=wndWidth; hint.height=wndHeight; | |
320 hint.base_width=wndWidth; hint.base_height=wndHeight; | |
321 hint.flags=USPosition | USSize; | |
4795 | 322 XSetNormalHints( mDisplay,vo_window,&hint ); |
323 XStoreName( mDisplay,vo_window,mTitle ); | |
324 XMapWindow( mDisplay,vo_window ); | |
4762 | 325 |
3990 | 326 #ifdef HAVE_XINERAMA |
4795 | 327 vo_x11_xinerama_move(mDisplay,vo_window); |
3990 | 328 #endif |
4795 | 329 vo_gc=XCreateGC( mDisplay,vo_window,GCForeground,&wGCV ); |
1723
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1637
diff
changeset
|
330 #ifdef HAVE_NEW_GUI |
723 | 331 } |
332 #endif | |
1 | 333 |
120 | 334 set_window(); |
1 | 335 |
336 mga_vid_config.src_width=width; | |
337 mga_vid_config.src_height=height; | |
338 | |
339 mga_vid_config.colkey_on=1; | |
340 mga_vid_config.colkey_red=255; | |
341 mga_vid_config.colkey_green=0; | |
342 mga_vid_config.colkey_blue=255; | |
343 | |
56 | 344 if(mga_init()) return -1; |
1852 | 345 |
346 set_window(); | |
1 | 347 |
4795 | 348 XFlush( mDisplay ); |
349 XSync( mDisplay,False ); | |
4316 | 350 |
351 saver_off(mDisplay); | |
324 | 352 |
1 | 353 return 0; |
354 } | |
355 | |
356 static const vo_info_t* get_info( void ) | |
357 { return &vo_info; } | |
358 | |
359 | |
360 static void | |
361 uninit(void) | |
362 { | |
4316 | 363 saver_on(mDisplay); |
1852 | 364 #ifdef HAVE_NEW_GUI |
365 if ( vo_window == None ) | |
366 #endif | |
1924 | 367 { |
4795 | 368 XDestroyWindow( mDisplay,vo_window ); |
1924 | 369 } |
1637 | 370 mga_uninit(); |
371 printf("vo: uninit!\n"); | |
1 | 372 } |
4352 | 373 |