Mercurial > mplayer.hg
annotate libvo/vo_xmga.c @ 924:c18f0a1bee08
bugfix: font_name -> sub_name (when error)
author | laaz |
---|---|
date | Fri, 01 Jun 2001 12:17:09 +0000 |
parents | db06ae8967eb |
children | 2098be9cb19b |
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 | |
31 | 48 #include "x11_common.h" |
616 | 49 #include "sub.h" |
31 | 50 |
182 | 51 #ifdef SHOW_TIME |
100 | 52 #include "../linux/timer.h" |
53 static unsigned int timer=0; | |
54 static unsigned int timerd=0; | |
55 #endif | |
56 | |
1 | 57 static vo_info_t vo_info = |
58 { | |
59 "X11 (Matrox G200/G400 overlay in window using /dev/mga_vid)", | |
60 "xmga", | |
61 "Zoltan Ponekker <pontscho@makacs.poliod.hu>", | |
62 "" | |
63 }; | |
64 | |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
844
diff
changeset
|
65 //static Display * mDisplay; |
1 | 66 static Window mWindow; |
67 static GC mGC; | |
68 static XGCValues wGCV; | |
69 | |
70 static XImage * myximage; | |
71 | |
72 static uint32_t mDepth, bpp, mode; | |
73 static XWindowAttributes attribs; | |
74 static uint32_t X_already_started=0; | |
75 | |
76 static uint32_t wndHeight; | |
77 static uint32_t wndWidth; | |
78 static uint32_t wndX; | |
79 static uint32_t wndY; | |
80 | |
81 static uint32_t fgColor; | |
82 | |
83 static uint32_t mvHeight; | |
84 static uint32_t mvWidth; | |
85 | |
86 static Window mRoot; | |
87 static uint32_t drwX,drwY,drwWidth,drwHeight,drwBorderWidth,drwDepth; | |
88 static uint32_t drwcX,drwcY,dwidth,dheight,mFullscreen; | |
89 | |
723 | 90 #ifdef HAVE_GUI |
91 static uint32_t mdwidth,mdheight; | |
92 #endif | |
93 | |
1 | 94 static XSetWindowAttributes xWAttribs; |
95 | |
96 #include "mga_common.c" | |
97 | |
98 static void mDrawColorKey( void ) | |
99 { | |
100 XClearWindow( mDisplay,mWindow ); | |
101 XSetForeground( mDisplay,mGC,fgColor ); | |
102 XFillRectangle( mDisplay,mWindow,mGC,drwX,drwY,drwWidth,(mFullscreen?drwHeight - 1:drwHeight) ); | |
103 XFlush( mDisplay ); | |
104 } | |
105 | |
120 | 106 static void set_window(){ |
107 | |
108 XGetGeometry( mDisplay,mWindow,&mRoot,&drwX,&drwY,&drwWidth,&drwHeight,&drwBorderWidth,&drwDepth ); | |
109 drwX=0; drwY=0; // drwWidth=wndWidth; drwHeight=wndHeight; | |
110 XTranslateCoordinates( mDisplay,mWindow,mRoot,0,0,&drwcX,&drwcY,&mRoot ); | |
340 | 111 //fprintf( stderr,"[xmga] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); |
120 | 112 |
723 | 113 #ifdef HAVE_GUI |
114 if ( vo_window != None ) | |
115 { | |
116 mFullscreen=0; | |
117 dwidth=mdwidth; dheight=mdheight; | |
118 if ( ( drwWidth == vo_screenwidth )&&( drwHeight == vo_screenheight ) ) | |
119 { | |
120 mFullscreen=1; | |
121 dwidth=vo_screenwidth; | |
122 dheight=vo_screenwidth * mdheight / mdwidth; | |
123 } | |
124 } | |
125 #endif | |
126 | |
120 | 127 if ( mFullscreen ) |
128 { | |
129 drwX=( vo_screenwidth - (dwidth > vo_screenwidth?vo_screenwidth:dwidth) ) / 2; | |
130 drwcX+=drwX; | |
131 drwY=( vo_screenheight - (dheight > vo_screenheight?vo_screenheight:dheight) ) / 2; | |
132 drwcY+=drwY; | |
133 drwWidth=(dwidth > vo_screenwidth?vo_screenwidth:dwidth); | |
134 drwHeight=(dheight > vo_screenheight?vo_screenheight:dheight); | |
340 | 135 //fprintf( stderr,"[xmga-fs] dcx: %d dcy: %d dx: %d dy: %d dw: %d dh: %d\n",drwcX,drwcY,drwX,drwY,drwWidth,drwHeight ); |
120 | 136 } |
137 | |
138 mDrawColorKey(); | |
139 | |
140 mga_vid_config.x_org=drwcX; | |
141 mga_vid_config.y_org=drwcY; | |
142 mga_vid_config.dest_width=drwWidth; | |
143 mga_vid_config.dest_height=drwHeight; | |
144 | |
145 } | |
146 | |
31 | 147 static void check_events(void) |
1 | 148 { |
31 | 149 int e=vo_x11_check_events(mDisplay); |
1 | 150 |
31 | 151 if(e&VO_EVENT_RESIZE){ |
120 | 152 set_window(); |
1 | 153 if ( ioctl( f,MGA_VID_CONFIG,&mga_vid_config ) ) |
154 { | |
614 | 155 printf( "Error in mga_vid_config ioctl (wrong mga_vid.o version?)" ); |
31 | 156 // exit( 0 ); |
1 | 157 } |
31 | 158 |
159 } else | |
160 if(e&VO_EVENT_EXPOSE) mDrawColorKey(); | |
161 | |
1 | 162 } |
163 | |
31 | 164 static void flip_page(void){ |
182 | 165 #ifdef SHOW_TIME |
100 | 166 unsigned int t; |
167 t=GetTimer(); | |
168 printf(" [timer: %08X diff: %6d dd: %6d ] \n",t,t-timer,(t-timer)-timerd); | |
169 timerd=t-timer; | |
170 timer=t; | |
182 | 171 #endif |
100 | 172 |
213 | 173 vo_draw_text(mga_vid_config.src_width,mga_vid_config.src_height,draw_alpha); |
202 | 174 |
31 | 175 check_events(); |
176 vo_mga_flip_page(); | |
177 } | |
1 | 178 |
179 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 ) | |
180 { | |
181 char * frame_mem; | |
56 | 182 // uint32_t frame_size; |
1 | 183 int mScreen; |
184 unsigned int fg, bg; | |
185 char * mTitle=(title == NULL) ? "XMGA render" : title; | |
186 char * name=":0.0"; | |
187 XSizeHints hint; | |
188 XVisualInfo vinfo; | |
189 XEvent xev; | |
190 | |
191 XGCValues xgcv; | |
192 unsigned long xswamask; | |
193 | |
194 f=open( "/dev/mga_vid",O_RDWR ); | |
195 if ( f == -1 ) | |
196 { | |
614 | 197 printf("Couldn't open /dev/mga_vid\n"); |
1 | 198 return(-1); |
199 } | |
200 | |
201 switch(format) | |
202 { | |
182 | 203 case IMGFMT_YV12: |
56 | 204 mga_vid_config.format=MGA_VID_FORMAT_YV12; |
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 mga_vid_config.format=MGA_VID_FORMAT_I420; | |
209 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; | |
210 break; | |
211 case IMGFMT_IYUV: | |
212 mga_vid_config.format=MGA_VID_FORMAT_IYUV; | |
213 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height + ( ( ( width + 31 ) & ~31 ) * height ) / 2; | |
214 break; | |
56 | 215 case IMGFMT_YUY2: |
216 mga_vid_config.format=MGA_VID_FORMAT_YUY2; | |
182 | 217 mga_vid_config.frame_size=( ( width + 31 ) & ~31 ) * height * 2; |
56 | 218 break; |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
219 case IMGFMT_UYVY: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
384
diff
changeset
|
220 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
|
221 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
|
222 break; |
614 | 223 default: printf("mga: invalid output format %0X\n",format); return (-1); |
1 | 224 } |
225 | |
226 if ( X_already_started ) return -1; | |
227 | |
922
db06ae8967eb
Centralized and cleaned up X11 connecting, fixed remote X11 playing, -display option for mplayer. SHOULD BE TESTED.
lgb
parents:
844
diff
changeset
|
228 if (!vo_init()) return -1; |
1 | 229 |
230 mvWidth=width; mvHeight=height; | |
231 | |
232 wndX=0; wndY=0; | |
233 wndWidth=d_width; wndHeight=d_height; | |
234 dwidth=d_width; dheight=d_height; | |
723 | 235 #ifdef HAVE_GUI |
236 mdwidth=d_width; mdheight=d_height; | |
237 #endif | |
844 | 238 mFullscreen=fullscreen&1; |
1 | 239 |
240 switch ( vo_depthonscreen ) | |
241 { | |
242 case 32: | |
243 case 24: fgColor=0x00ff00ffL; break; | |
244 case 16: fgColor=0xf81fL; break; | |
245 case 15: fgColor=0x7c1fL; break; | |
614 | 246 default: printf( "Sorry, this (%d) color depth not supported.\n",vo_depthonscreen ); return -1; |
1 | 247 } |
248 | |
723 | 249 #ifdef HAVE_GUI |
250 if ( vo_window == None ) | |
251 { | |
252 #endif | |
844 | 253 if ( mFullscreen ) |
723 | 254 { |
255 wndWidth=vo_screenwidth; | |
256 wndHeight=vo_screenheight; | |
257 } | |
258 | |
259 XGetWindowAttributes( mDisplay,DefaultRootWindow( mDisplay ),&attribs ); | |
260 mDepth=attribs.depth; | |
261 if ( mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32 ) mDepth=24; | |
262 XMatchVisualInfo( mDisplay,mScreen,mDepth,TrueColor,&vinfo ); | |
263 xWAttribs.colormap=XCreateColormap( mDisplay,RootWindow( mDisplay,mScreen ),vinfo.visual,AllocNone ); | |
264 xWAttribs.background_pixel=0; | |
265 xWAttribs.border_pixel=0; | |
266 xWAttribs.event_mask=StructureNotifyMask | ExposureMask | KeyPressMask; | |
267 xswamask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; | |
1 | 268 |
723 | 269 mWindow=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ), |
270 wndX,wndY, | |
271 wndWidth,wndHeight, | |
272 xWAttribs.border_pixel, | |
273 mDepth, | |
274 InputOutput, | |
275 vinfo.visual,xswamask,&xWAttribs ); | |
276 vo_hidecursor(mDisplay,mWindow); | |
277 | |
844 | 278 if ( mFullscreen ) vo_x11_decoration( mDisplay,mWindow,0 ); |
1 | 279 |
723 | 280 XGetNormalHints( mDisplay,mWindow,&hint ); |
281 hint.x=wndX; hint.y=wndY; | |
282 hint.width=wndWidth; hint.height=wndHeight; | |
283 hint.base_width=wndWidth; hint.base_height=wndHeight; | |
284 hint.flags=USPosition | USSize; | |
285 XSetNormalHints( mDisplay,mWindow,&hint ); | |
286 XStoreName( mDisplay,mWindow,mTitle ); | |
287 XMapWindow( mDisplay,mWindow ); | |
288 #ifdef HAVE_GUI | |
289 } | |
290 else | |
291 { | |
292 mWindow=vo_window; | |
293 fprintf( stderr,"[xmga] width: %d height: %d d_width: %d d_height: %d\n",width,height,d_width,d_height ); | |
294 if ( vo_screenwidth != d_width ) | |
295 { | |
296 XMoveWindow( mDisplay,mWindow,( vo_screenwidth - d_width ) / 2,( vo_screenheight - d_height ) / 2 ); | |
297 XResizeWindow( mDisplay,mWindow,d_width,d_height ); | |
298 } | |
299 else mFullscreen=1; | |
300 } | |
301 #endif | |
1 | 302 mGC=XCreateGC( mDisplay,mWindow,GCForeground,&wGCV ); |
303 | |
120 | 304 set_window(); |
1 | 305 |
306 mga_vid_config.src_width=width; | |
307 mga_vid_config.src_height=height; | |
308 | |
309 mga_vid_config.colkey_on=1; | |
310 mga_vid_config.colkey_red=255; | |
311 mga_vid_config.colkey_green=0; | |
312 mga_vid_config.colkey_blue=255; | |
313 | |
56 | 314 if(mga_init()) return -1; |
1 | 315 |
723 | 316 #ifdef HAVE_GUI |
317 if ( vo_window == None ) | |
318 { | |
319 #endif | |
320 XFlush( mDisplay ); | |
321 XSync( mDisplay,False ); | |
322 #ifdef HAVE_GUI | |
323 } | |
324 #endif | |
1 | 325 |
324 | 326 saver_off(mDisplay); |
327 | |
1 | 328 return 0; |
329 } | |
330 | |
331 static const vo_info_t* get_info( void ) | |
332 { return &vo_info; } | |
333 | |
334 | |
335 static void | |
336 uninit(void) | |
337 { | |
324 | 338 saver_on(mDisplay); |
1 | 339 ioctl( f,MGA_VID_OFF,0 ); |
340 printf("vo: uninit!\n"); | |
341 } |