Mercurial > mplayer.hg
annotate libvo/vo_xmga.c @ 6016:be9cd7d845c2
-zoom, -fs with x[11|mga|v] fix -- round two
author | pontscho |
---|---|
date | Wed, 08 May 2002 20:24:35 +0000 |
parents | bb1f3552f118 |
children | 421781c5b128 |
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 | |
5955
caac20b1ca79
fix xmga fs, resize to movie size and mouse auto hide + dga
pontscho
parents:
5945
diff
changeset
|
62 #ifdef HAVE_NEW_GUI |
caac20b1ca79
fix xmga fs, resize to movie size and mouse auto hide + dga
pontscho
parents:
5945
diff
changeset
|
63 #include "../Gui/interface.h" |
caac20b1ca79
fix xmga fs, resize to movie size and mouse auto hide + dga
pontscho
parents:
5945
diff
changeset
|
64 #endif |
caac20b1ca79
fix xmga fs, resize to movie size and mouse auto hide + dga
pontscho
parents:
5945
diff
changeset
|
65 |
1 | 66 static vo_info_t vo_info = |
67 { | |
4993 | 68 "X11 (Matrox G200/G4x0/G550 overlay in window using /dev/mga_vid)", |
1 | 69 "xmga", |
70 "Zoltan Ponekker <pontscho@makacs.poliod.hu>", | |
71 "" | |
72 }; | |
73 | |
74 static XGCValues wGCV; | |
75 | |
76 static XImage * myximage; | |
77 | |
78 static uint32_t mDepth, bpp, mode; | |
79 static XWindowAttributes attribs; | |
80 static uint32_t X_already_started=0; | |
81 | |
82 static uint32_t wndX; | |
83 static uint32_t wndY; | |
84 | |
85 static uint32_t fgColor; | |
86 | |
87 static uint32_t mvHeight; | |
88 static uint32_t mvWidth; | |
89 | |
90 static Window mRoot; | |
91 static uint32_t drwX,drwY,drwWidth,drwHeight,drwBorderWidth,drwDepth; | |
4981 | 92 static uint32_t drwcX,drwcY,dwidth,dheight; |
1 | 93 |
94 static XSetWindowAttributes xWAttribs; | |
95 | |
4981 | 96 #define VO_XMGA |
1 | 97 #include "mga_common.c" |
4981 | 98 #undef VO_XMGA |
1 | 99 |
100 static void mDrawColorKey( void ) | |
101 { | |
4795 | 102 XSetBackground( mDisplay,vo_gc,0 ); |
103 XClearWindow( mDisplay,vo_window ); | |
104 XSetForeground( mDisplay,vo_gc,fgColor ); | |
4981 | 105 XFillRectangle( mDisplay,vo_window,vo_gc,drwX,drwY,drwWidth,(vo_fs?drwHeight - 1:drwHeight) ); |
1 | 106 XFlush( mDisplay ); |
107 } | |
108 | |
120 | 109 static void set_window(){ |
110 | |
4795 | 111 XGetGeometry( mDisplay,vo_window,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth ); |
4993 | 112 fprintf( stderr,"[xmga] x: %d y: %d w: %d h: %d\n",drwX,drwY,drwWidth,drwHeight ); |
5945 | 113 drwX=0; drwY=0; |
4795 | 114 XTranslateCoordinates( mDisplay,vo_window,mRoot,0,0,&drwcX,&drwcY,&mRoot ); |
1852 | 115 fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); |
116 | |
3558 | 117 aspect(&dwidth,&dheight,A_NOZOOM); |
4981 | 118 if ( vo_fs ) |
120 | 119 { |
3558 | 120 aspect(&dwidth,&dheight,A_ZOOM); |
120 | 121 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2; |
122 drwcX+=drwX; | |
123 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2; | |
124 drwcY+=drwY; | |
125 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth); | |
126 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight); | |
1852 | 127 fprintf( stderr,"[xmga-fs] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); |
120 | 128 } |
129 | |
130 mDrawColorKey(); | |
131 | |
4017 | 132 #ifdef HAVE_XINERAMA |
133 if(XineramaIsActive(mDisplay)) | |
134 { | |
135 XineramaScreenInfo *screens; | |
136 int num_screens; | |
137 int i; | |
138 | |
139 screens = XineramaQueryScreens(mDisplay,&num_screens); | |
140 | |
141 /* find the screen we are on */ | |
142 i = 0; | |
143 while(!(screens[i].x_org <= drwcX && screens[i].y_org <= drwcY && | |
144 screens[i].x_org + screens[i].width >= drwcX && | |
145 screens[i].y_org + screens[i].height >= drwcY )) | |
146 { | |
147 i++; | |
148 } | |
149 | |
150 /* set drwcX and drwcY to the right values */ | |
151 drwcX = drwcX - screens[i].x_org; | |
152 drwcY = drwcY - screens[i].y_org; | |
153 XFree(screens); | |
154 } | |
155 | |
156 #endif | |
120 | 157 mga_vid_config.x_org=drwcX; |
158 mga_vid_config.y_org=drwcY; | |
159 mga_vid_config.dest_width=drwWidth; | |
160 mga_vid_config.dest_height=drwHeight; | |
161 | |
162 } | |
163 | |
31 | 164 static void check_events(void) |
1 | 165 { |
4303 | 166 int e=vo_x11_check_events(mDisplay); |
167 if ( !(e&VO_EVENT_RESIZE) && !(e&VO_EVENT_EXPOSE) ) return; | |
5945 | 168 set_window(); |
4303 | 169 if(e&VO_EVENT_EXPOSE) mDrawColorKey(); |
170 if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) ) | |
171 printf( "Error in mga_vid_config ioctl (wrong mga_vid.o version?)" ); | |
1 | 172 } |
173 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
174 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
175 { 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
|
176 |
31 | 177 static void flip_page(void){ |
182 | 178 #ifdef SHOW_TIME |
100 | 179 unsigned int t; |
180 t=GetTimer(); | |
181 printf(" [timer: %08X diff: %6d dd: %6d ] \n",t,t-timer,(t-timer)-timerd); | |
182 timerd=t-timer; | |
183 timer=t; | |
182 | 184 #endif |
100 | 185 |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1210
diff
changeset
|
186 vo_mga_flip_page(); |
31 | 187 } |
1 | 188 |
5158 | 189 static int inited=0; |
190 | |
4433 | 191 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 | 192 { |
193 char * mTitle=(title == NULL) ? "XMGA render" : title; | |
194 XVisualInfo vinfo; | |
195 | |
196 unsigned long xswamask; | |
197 | |
6016 | 198 if ( X_already_started ) return -1; |
199 if (!vo_init()) return -1; | |
200 | |
5007 | 201 width+=width&1; |
202 | |
1 | 203 switch(format) |
204 { | |
182 | 205 case IMGFMT_YV12: |
5007 | 206 height+=height&1; |
5317 | 207 mga_vid_config.format=MGA_VID_FORMAT_IYUV; |
182 | 208 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; |
56 | 209 break; |
470 | 210 case IMGFMT_I420: |
211 case IMGFMT_IYUV: | |
5007 | 212 height+=height&1; |
5317 | 213 mga_vid_config.format=MGA_VID_FORMAT_YV12; |
470 | 214 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; |
215 break; | |
56 | 216 case IMGFMT_YUY2: |
217 mga_vid_config.format=MGA_VID_FORMAT_YUY2; | |
182 | 218 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height * 2; |
56 | 219 break; |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
220 case IMGFMT_UYVY: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
221 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
|
222 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
|
223 break; |
614 | 224 default: printf("mga: invalid output format %0X\n",format); return (-1); |
1 | 225 } |
226 | |
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
|
227 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
|
228 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
|
229 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
|
230 |
1 | 231 mvWidth=width; mvHeight=height; |
232 | |
233 wndX=0; wndY=0; | |
4981 | 234 vo_dwidth=d_width; vo_dheight=d_height; |
5955
caac20b1ca79
fix xmga fs, resize to movie size and mouse auto hide + dga
pontscho
parents:
5945
diff
changeset
|
235 vo_mouse_autohide=1; |
1 | 236 |
237 switch ( vo_depthonscreen ) | |
238 { | |
239 case 32: | |
240 case 24: fgColor=0x00ff00ffL; break; | |
241 case 16: fgColor=0xf81fL; break; | |
242 case 15: fgColor=0x7c1fL; break; | |
614 | 243 default: printf( "Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1; |
1 | 244 } |
245 | |
5158 | 246 inited=1; |
247 | |
6016 | 248 aspect(&vo_dwidth,&vo_dheight,A_NOZOOM); |
5985 | 249 |
1723
5e4214a7540e
GUI stuff. now seeking works, and xmga renders to video window
arpi
parents:
1637
diff
changeset
|
250 #ifdef HAVE_NEW_GUI |
5985 | 251 if(use_gui) |
252 guiGetEvent( guiSetShVideo,0 ); // the GUI will set up / resize the window | |
253 else | |
254 #endif | |
723 | 255 { |
2039 | 256 #ifdef X11_FULLSCREEN |
6016 | 257 if ( fullscreen&1 ) aspect(&dwidth,&dheight,A_ZOOM); |
2039 | 258 #endif |
723 | 259 |
260 XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs ); | |
261 mDepth=attribs.depth; | |
262 if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24; | |
263 XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo ); | |
264 xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone ); | |
265 xWAttribs.background_pixel=0; | |
266 xWAttribs.border_pixel=0; | |
5835 | 267 xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask | PropertyChangeMask | |
5823 | 268 ((WinID==0)?0:(ButtonPressMask | ButtonReleaseMask | PointerMotionMask)); |
723 | 269 xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; |
1 | 270 |
3847 | 271 if ( WinID>=0 ){ |
4795 | 272 vo_window = WinID ? ((Window)WinID) : RootWindow(mDisplay,mScreen); |
273 XUnmapWindow( mDisplay,vo_window ); | |
274 XChangeWindowAttributes( mDisplay,vo_window,xswamask,&xWAttribs); | |
3847 | 275 } else |
6016 | 276 vo_window=XCreateWindow( mDisplay,mRootWin, |
723 | 277 wndX,wndY, |
5945 | 278 vo_dwidth,vo_dheight, |
723 | 279 xWAttribs.border_pixel, |
280 mDepth, | |
281 InputOutput, | |
282 vinfo.visual,xswamask,&xWAttribs ); | |
4795 | 283 vo_x11_classhint( mDisplay,vo_window,"xmga" ); |
284 vo_hidecursor(mDisplay,vo_window); | |
723 | 285 |
4795 | 286 XStoreName( mDisplay,vo_window,mTitle ); |
287 XMapWindow( mDisplay,vo_window ); | |
5999 | 288 |
289 if ( fullscreen&1 ) vo_x11_fullscreen(); | |
4762 | 290 |
3990 | 291 #ifdef HAVE_XINERAMA |
4795 | 292 vo_x11_xinerama_move(mDisplay,vo_window); |
3990 | 293 #endif |
4795 | 294 vo_gc=XCreateGC( mDisplay,vo_window,GCForeground,&wGCV ); |
5985 | 295 } |
1 | 296 |
120 | 297 set_window(); |
1 | 298 |
299 mga_vid_config.src_width=width; | |
300 mga_vid_config.src_height=height; | |
301 | |
302 mga_vid_config.colkey_on=1; | |
303 mga_vid_config.colkey_red=255; | |
304 mga_vid_config.colkey_green=0; | |
305 mga_vid_config.colkey_blue=255; | |
306 | |
56 | 307 if(mga_init()) return -1; |
1852 | 308 |
309 set_window(); | |
1 | 310 |
4795 | 311 XFlush( mDisplay ); |
312 XSync( mDisplay,False ); | |
4316 | 313 |
314 saver_off(mDisplay); | |
324 | 315 |
1 | 316 return 0; |
317 } | |
318 | |
319 static const vo_info_t* get_info( void ) | |
320 { return &vo_info; } | |
321 | |
322 | |
323 static void | |
324 uninit(void) | |
325 { | |
5158 | 326 if(!inited) return; |
327 inited=0; | |
5651
b8d8d72776f2
fix playlist bug with gui and rewrite mousecursor show/hide code
pontscho
parents:
5433
diff
changeset
|
328 XSetBackground( mDisplay,vo_gc,0 ); |
b8d8d72776f2
fix playlist bug with gui and rewrite mousecursor show/hide code
pontscho
parents:
5433
diff
changeset
|
329 XClearWindow( mDisplay,vo_window ); |
5158 | 330 mga_uninit(); |
4316 | 331 saver_on(mDisplay); |
5158 | 332 vo_x11_uninit(mDisplay, vo_window); |
1637 | 333 printf("vo: uninit!\n"); |
1 | 334 } |
4352 | 335 |