Mercurial > mplayer.hg
annotate libvo/vo_xmga.c @ 4965:923605707de6
sorry, 10l:)
author | pontscho |
---|---|
date | Thu, 07 Mar 2002 00:03:51 +0000 |
parents | b18e61cb457a |
children | f21d15f0cba6 |
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; | |
91 static uint32_t drwcX,drwcY,dwidth,dheight,mFullscreen; | |
92 | |
1783 | 93 #ifdef HAVE_NEW_GUI |
723 | 94 static uint32_t mdwidth,mdheight; |
95 #endif | |
96 | |
1 | 97 static XSetWindowAttributes xWAttribs; |
98 | |
99 #include "mga_common.c" | |
100 | |
101 static void mDrawColorKey( void ) | |
102 { | |
4795 | 103 XSetBackground( mDisplay,vo_gc,0 ); |
104 XClearWindow( mDisplay,vo_window ); | |
105 XSetForeground( mDisplay,vo_gc,fgColor ); | |
106 XFillRectangle( mDisplay,vo_window,vo_gc,drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight) ); | |
1 | 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 | |
4795 | 126 XGetGeometry( mDisplay,vo_window,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth ); |
1852 | 127 drwX=0; drwY=0; // drwWidth=wndWidth; drwHeight=wndHeight; |
4795 | 128 XTranslateCoordinates( mDisplay,vo_window,mRoot,0,0,&drwcX,&drwcY,&mRoot ); |
1852 | 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 { |
4303 | 180 int e=vo_x11_check_events(mDisplay); |
181 if ( !(e&VO_EVENT_RESIZE) && !(e&VO_EVENT_EXPOSE) ) return; | |
182 if(e&VO_EVENT_EXPOSE) mDrawColorKey(); | |
183 set_window(); | |
184 if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) ) | |
185 printf( "Error in mga_vid_config ioctl (wrong mga_vid.o version?)" ); | |
1 | 186 } |
187 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
188 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
189 { 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
|
190 |
31 | 191 static void flip_page(void){ |
182 | 192 #ifdef SHOW_TIME |
100 | 193 unsigned int t; |
194 t=GetTimer(); | |
195 printf(" [timer: %08X diff: %6d dd: %6d ] \n",t,t-timer,(t-timer)-timerd); | |
196 timerd=t-timer; | |
197 timer=t; | |
182 | 198 #endif |
100 | 199 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
200 vo_mga_flip_page(); |
31 | 201 } |
1 | 202 |
4433 | 203 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 | 204 { |
205 char * frame_mem; | |
56 | 206 // uint32_t frame_size; |
927 | 207 // int mScreen; |
1 | 208 unsigned int fg, bg; |
209 char * mTitle=(title == NULL) ? "XMGA render" : title; | |
210 char * name=":0.0"; | |
211 XSizeHints hint; | |
212 XVisualInfo vinfo; | |
213 XEvent xev; | |
214 | |
215 XGCValues xgcv; | |
216 unsigned long xswamask; | |
217 | |
1210 | 218 char *devname=vo_subdevice?vo_subdevice:"/dev/mga_vid"; |
219 | |
220 f = open(devname,O_RDWR); | |
221 if(f == -1) | |
222 { | |
1637 | 223 perror("open"); |
1210 | 224 printf("Couldn't open %s\n",devname); |
225 return(-1); | |
226 } | |
1 | 227 |
228 switch(format) | |
229 { | |
182 | 230 case IMGFMT_YV12: |
56 | 231 mga_vid_config.format=MGA_VID_FORMAT_YV12; |
182 | 232 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; |
56 | 233 break; |
470 | 234 case IMGFMT_I420: |
235 mga_vid_config.format=MGA_VID_FORMAT_I420; | |
236 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; | |
237 break; | |
238 case IMGFMT_IYUV: | |
239 mga_vid_config.format=MGA_VID_FORMAT_IYUV; | |
240 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; | |
241 break; | |
56 | 242 case IMGFMT_YUY2: |
243 mga_vid_config.format=MGA_VID_FORMAT_YUY2; | |
182 | 244 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height * 2; |
56 | 245 break; |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
246 case IMGFMT_UYVY: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
247 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
|
248 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
|
249 break; |
614 | 250 default: printf("mga: invalid output format %0X\n",format); return (-1); |
1 | 251 } |
252 | |
253 if ( X_already_started ) return -1; | |
254 | |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
844
diff
changeset
|
255 if (!vo_init()) return -1; |
1 | 256 |
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
|
257 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
|
258 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
|
259 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
|
260 |
1 | 261 mvWidth=width; mvHeight=height; |
262 | |
263 wndX=0; wndY=0; | |
264 wndWidth=d_width; wndHeight=d_height; | |
844 | 265 mFullscreen=fullscreen&1; |
1 | 266 |
267 switch ( vo_depthonscreen ) | |
268 { | |
269 case 32: | |
270 case 24: fgColor=0x00ff00ffL; break; | |
271 case 16: fgColor=0xf81fL; break; | |
272 case 15: fgColor=0x7c1fL; break; | |
614 | 273 default: printf( "Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1; |
1 | 274 } |
275 | |
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
|
276 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
|
277 #ifdef HAVE_NEW_GUI |
4795 | 278 mdwidth=width; mdheight=height; |
723 | 279 if ( vo_window == None ) |
280 { | |
281 #endif | |
844 | 282 if ( mFullscreen ) |
723 | 283 { |
284 wndWidth=vo_screenwidth; | |
285 wndHeight=vo_screenheight; | |
2039 | 286 #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
|
287 aspect(&d_width,&d_height,A_ZOOM); |
2039 | 288 #endif |
723 | 289 } |
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
|
290 dwidth=d_width; dheight=d_height; |
723 | 291 |
292 XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs ); | |
293 mDepth=attribs.depth; | |
294 if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24; | |
295 XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo ); | |
296 xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone ); | |
297 xWAttribs.background_pixel=0; | |
298 xWAttribs.border_pixel=0; | |
4784 | 299 xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask; |
723 | 300 xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; |
1 | 301 |
3847 | 302 if ( WinID>=0 ){ |
4795 | 303 vo_window = WinID ? ((Window)WinID) : RootWindow(mDisplay,mScreen); |
304 XUnmapWindow( mDisplay,vo_window ); | |
305 XChangeWindowAttributes( mDisplay,vo_window,xswamask,&xWAttribs); | |
3847 | 306 } else |
4795 | 307 vo_window=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ), |
723 | 308 wndX,wndY, |
309 wndWidth,wndHeight, | |
310 xWAttribs.border_pixel, | |
311 mDepth, | |
312 InputOutput, | |
313 vinfo.visual,xswamask,&xWAttribs ); | |
4795 | 314 vo_x11_classhint( mDisplay,vo_window,"xmga" ); |
315 vo_hidecursor(mDisplay,vo_window); | |
723 | 316 |
4795 | 317 if ( mFullscreen ) vo_x11_decoration( mDisplay,vo_window,0 ); |
1 | 318 |
4795 | 319 XGetNormalHints( mDisplay,vo_window,&hint ); |
723 | 320 hint.x=wndX; hint.y=wndY; |
321 hint.width=wndWidth; hint.height=wndHeight; | |
322 hint.base_width=wndWidth; hint.base_height=wndHeight; | |
323 hint.flags=USPosition | USSize; | |
4795 | 324 XSetNormalHints( mDisplay,vo_window,&hint ); |
325 XStoreName( mDisplay,vo_window,mTitle ); | |
326 XMapWindow( mDisplay,vo_window ); | |
4762 | 327 |
3990 | 328 #ifdef HAVE_XINERAMA |
4795 | 329 vo_x11_xinerama_move(mDisplay,vo_window); |
3990 | 330 #endif |
4795 | 331 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
|
332 #ifdef HAVE_NEW_GUI |
723 | 333 } |
334 #endif | |
1 | 335 |
120 | 336 set_window(); |
1 | 337 |
338 mga_vid_config.src_width=width; | |
339 mga_vid_config.src_height=height; | |
340 | |
341 mga_vid_config.colkey_on=1; | |
342 mga_vid_config.colkey_red=255; | |
343 mga_vid_config.colkey_green=0; | |
344 mga_vid_config.colkey_blue=255; | |
345 | |
56 | 346 if(mga_init()) return -1; |
1852 | 347 |
348 set_window(); | |
1 | 349 |
4795 | 350 XFlush( mDisplay ); |
351 XSync( mDisplay,False ); | |
4316 | 352 |
353 saver_off(mDisplay); | |
324 | 354 |
1 | 355 return 0; |
356 } | |
357 | |
358 static const vo_info_t* get_info( void ) | |
359 { return &vo_info; } | |
360 | |
361 | |
362 static void | |
363 uninit(void) | |
364 { | |
4316 | 365 saver_on(mDisplay); |
1852 | 366 #ifdef HAVE_NEW_GUI |
367 if ( vo_window == None ) | |
368 #endif | |
1924 | 369 { |
4795 | 370 XDestroyWindow( mDisplay,vo_window ); |
1924 | 371 } |
1637 | 372 mga_uninit(); |
373 printf("vo: uninit!\n"); | |
1 | 374 } |
4352 | 375 |
376 static uint32_t preinit(const char *arg) | |
377 { | |
378 return 0; | |
379 } | |
380 | |
4596 | 381 static uint32_t control(uint32_t request, void *data, ...) |
4352 | 382 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4568
diff
changeset
|
383 switch (request) { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4568
diff
changeset
|
384 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4568
diff
changeset
|
385 return query_format(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4568
diff
changeset
|
386 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4568
diff
changeset
|
387 return VO_NOTIMPL; |
4352 | 388 } |