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