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