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