options: move lavfdopts to option struct
[mplayer/glamo.git] / libvo / vo_xmga.c
blob817ce2d2e8629581f6d9958d29640f253e8bbc74
1 /*
2 * copyright (C) 2001 Zoltan Ponekker
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 //#define SHOW_TIME
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "config.h"
29 #include "video_out.h"
30 #include "video_out_internal.h"
33 #include <sys/ioctl.h>
34 #include <unistd.h>
35 #include <fcntl.h>
36 #include <sys/mman.h>
38 #include "drivers/mga_vid.h"
40 #include <X11/Xlib.h>
41 #include <X11/Xutil.h>
42 #include <errno.h>
44 #ifdef CONFIG_XINERAMA
45 #include <X11/extensions/Xinerama.h>
46 #endif
48 #include "x11_common.h"
49 #include "sub.h"
50 #include "aspect.h"
52 #ifdef SHOW_TIME
53 #include "osdep/timer.h"
54 static unsigned int timer = 0;
55 static unsigned int timerd = 0;
56 #endif
58 static const vo_info_t info = {
59 "Matrox G200/G4x0/G550 overlay in X11 window (using /dev/mga_vid)",
60 "xmga",
61 "Zoltan Ponekker <pontscho@makacs.poliod.hu>",
65 const LIBVO_EXTERN(xmga)
67 static uint32_t mDepth;
68 static XWindowAttributes attribs;
69 static int colorkey;
71 static uint32_t mvHeight;
72 static uint32_t mvWidth;
74 static Window mRoot;
76 static XSetWindowAttributes xWAttribs;
78 static int initialized = 0;
80 #define VO_XMGA
81 #include "mga_common.c"
82 #undef VO_XMGA
84 static void mDrawColorKey(void)
86 XSetBackground(mDisplay, vo_gc, 0);
87 XClearWindow(mDisplay, vo_window);
88 XSetForeground(mDisplay, vo_gc, colorkey);
89 XFillRectangle(mDisplay, vo_window, vo_gc, drwX, drwY, drwWidth,
90 (vo_fs ? drwHeight - 1 : drwHeight));
91 XFlush(mDisplay);
94 static void check_events(void)
96 int e = vo_x11_check_events(mDisplay);
98 if (!(e & VO_EVENT_RESIZE) && !(e & VO_EVENT_EXPOSE))
99 return;
100 set_window();
101 mDrawColorKey();
102 if (ioctl(f, MGA_VID_CONFIG, &mga_vid_config))
103 mp_msg(MSGT_VO, MSGL_WARN,
104 "Error in mga_vid_config ioctl (wrong mga_vid.o version?)");
107 static void flip_page(void)
109 #ifdef SHOW_TIME
110 unsigned int t;
112 t = GetTimer();
113 mp_msg(MSGT_VO, MSGL_STATUS,
114 " [timer: %08X diff: %6d dd: %6d ] \n", t, t - timer,
115 (t - timer) - timerd);
116 timerd = t - timer;
117 timer = t;
118 #endif
120 vo_mga_flip_page();
123 static int config(uint32_t width, uint32_t height, uint32_t d_width,
124 uint32_t d_height, uint32_t flags, char *title,
125 uint32_t format)
127 XVisualInfo vinfo;
128 unsigned long xswamask;
129 int r, g, b;
131 if (mga_init(width, height, format))
132 return -1; // ioctl errors?
134 aspect_save_orig(width, height);
135 aspect_save_prescale(d_width, d_height);
136 update_xinerama_info();
138 mvWidth = width;
139 mvHeight = height;
141 vo_panscan_x = vo_panscan_y = vo_panscan_amount = 0;
143 aspect(&d_width, &d_height, A_NOZOOM);
144 vo_dx = (vo_screenwidth - d_width) / 2;
145 vo_dy = (vo_screenheight - d_height) / 2;
146 geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth,
147 vo_screenheight);
148 vo_dx += xinerama_x;
149 vo_dy += xinerama_y;
150 vo_dwidth = d_width;
151 vo_dheight = d_height;
153 r = (vo_colorkey & 0x00ff0000) >> 16;
154 g = (vo_colorkey & 0x0000ff00) >> 8;
155 b = vo_colorkey & 0x000000ff;
156 switch (vo_depthonscreen)
158 case 32:
159 colorkey = vo_colorkey;
160 break;
161 case 24:
162 colorkey = vo_colorkey & 0x00ffffff;
163 break;
164 case 16:
165 colorkey = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
166 break;
167 case 15:
168 colorkey = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3);
169 break;
170 default:
171 mp_msg(MSGT_VO, MSGL_ERR,
172 "Sorry, this (%d) color depth not supported.\n",
173 vo_depthonscreen);
174 return -1;
176 mp_msg(MSGT_VO, MSGL_V, "Using colorkey: %x\n", colorkey);
178 initialized = 1;
181 if (flags & VOFLAG_FULLSCREEN)
182 aspect(&dwidth, &dheight, A_ZOOM);
184 XGetWindowAttributes(mDisplay, mRootWin, &attribs);
185 mDepth = attribs.depth;
186 if (mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32)
187 mDepth = 24;
188 XMatchVisualInfo(mDisplay, mScreen, mDepth, TrueColor, &vinfo);
189 xWAttribs.colormap =
190 XCreateColormap(mDisplay, mRootWin, vinfo.visual, AllocNone);
191 xWAttribs.background_pixel = 0;
192 xWAttribs.border_pixel = 0;
193 xswamask = CWBackPixel | CWBorderPixel | CWColormap;
195 vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,
196 flags, xWAttribs.colormap, "xmga", title);
197 XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xWAttribs);
201 if ((flags & VOFLAG_FULLSCREEN) && (!WinID))
203 vo_dx = 0;
204 vo_dy = 0;
205 vo_dwidth = vo_screenwidth;
206 vo_dheight = vo_screenheight;
207 vo_fs = 1;
210 panscan_calc();
212 mga_vid_config.colkey_on = 1;
213 mga_vid_config.colkey_red = r;
214 mga_vid_config.colkey_green = g;
215 mga_vid_config.colkey_blue = b;
217 set_window(); // set up mga_vid_config.dest_width etc
219 XSync(mDisplay, False);
221 ioctl(f, MGA_VID_ON, 0);
223 return 0;
226 static void uninit(void)
228 mp_msg(MSGT_VO, MSGL_V, "vo: uninit!\n");
229 mga_uninit();
230 if (!initialized)
231 return; // no window?
232 initialized = 0;
233 vo_x11_uninit(); // destroy the window