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