Merge svn changes up to r27441
[mplayer.git] / libvo / vo_xmga.c
blob0a91b57415ce07569c3d0508fa5942d64c576ecb
2 //#define SHOW_TIME
4 /*
5 * vo_xmga.c
7 * Copyright (C) Zoltan Ponekker - Jan 2001
9 */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
15 #include "config.h"
17 #include "video_out.h"
18 #include "video_out_internal.h"
21 #include <sys/ioctl.h>
22 #include <unistd.h>
23 #include <fcntl.h>
24 #include <sys/mman.h>
26 #include "drivers/mga_vid.h"
28 #include <X11/Xlib.h>
29 #include <X11/Xutil.h>
30 #include <errno.h>
32 #ifdef CONFIG_XINERAMA
33 #include <X11/extensions/Xinerama.h>
34 #endif
36 #include "x11_common.h"
37 #include "sub.h"
38 #include "aspect.h"
40 #ifdef SHOW_TIME
41 #include "osdep/timer.h"
42 static unsigned int timer = 0;
43 static unsigned int timerd = 0;
44 #endif
46 #ifdef CONFIG_GUI
47 #include "gui/interface.h"
48 #endif
50 static const vo_info_t info = {
51 "Matrox G200/G4x0/G550 overlay in X11 window (using /dev/mga_vid)",
52 "xmga",
53 "Zoltan Ponekker <pontscho@makacs.poliod.hu>",
57 const LIBVO_EXTERN(xmga)
58 static XGCValues wGCV;
60 static uint32_t mDepth;
61 static XWindowAttributes attribs;
62 static int colorkey;
64 static uint32_t mvHeight;
65 static uint32_t mvWidth;
67 static Window mRoot;
69 static XSetWindowAttributes xWAttribs;
71 static int initialized = 0;
73 #define VO_XMGA
74 #include "mga_common.c"
75 #undef VO_XMGA
77 static void mDrawColorKey(void)
79 XSetBackground(mDisplay, vo_gc, 0);
80 XClearWindow(mDisplay, vo_window);
81 XSetForeground(mDisplay, vo_gc, colorkey);
82 XFillRectangle(mDisplay, vo_window, vo_gc, drwX, drwY, drwWidth,
83 (vo_fs ? drwHeight - 1 : drwHeight));
84 XFlush(mDisplay);
87 static void check_events(void)
89 int e = vo_x11_check_events(mDisplay);
91 if (!(e & VO_EVENT_RESIZE) && !(e & VO_EVENT_EXPOSE))
92 return;
93 set_window();
94 mDrawColorKey();
95 if (ioctl(f, MGA_VID_CONFIG, &mga_vid_config))
96 mp_msg(MSGT_VO, MSGL_WARN,
97 "Error in mga_vid_config ioctl (wrong mga_vid.o version?)");
100 static void flip_page(void)
102 #ifdef SHOW_TIME
103 unsigned int t;
105 t = GetTimer();
106 mp_msg(MSGT_VO, MSGL_STATUS,
107 " [timer: %08X diff: %6d dd: %6d ] \n", t, t - timer,
108 (t - timer) - timerd);
109 timerd = t - timer;
110 timer = t;
111 #endif
113 vo_mga_flip_page();
116 static int config(uint32_t width, uint32_t height, uint32_t d_width,
117 uint32_t d_height, uint32_t flags, char *title,
118 uint32_t format)
120 XVisualInfo vinfo;
121 unsigned long xswamask;
122 int r, g, b;
124 if (mga_init(width, height, format))
125 return -1; // ioctl errors?
127 aspect_save_orig(width, height);
128 aspect_save_prescale(d_width, d_height);
129 update_xinerama_info();
131 mvWidth = width;
132 mvHeight = height;
134 vo_panscan_x = vo_panscan_y = vo_panscan_amount = 0;
136 aspect(&d_width, &d_height, A_NOZOOM);
137 vo_dx = (vo_screenwidth - d_width) / 2;
138 vo_dy = (vo_screenheight - d_height) / 2;
139 geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth,
140 vo_screenheight);
141 vo_dx += xinerama_x;
142 vo_dy += xinerama_y;
143 vo_dwidth = d_width;
144 vo_dheight = d_height;
145 vo_mouse_autohide = 1;
147 r = (vo_colorkey & 0x00ff0000) >> 16;
148 g = (vo_colorkey & 0x0000ff00) >> 8;
149 b = vo_colorkey & 0x000000ff;
150 switch (vo_depthonscreen)
152 case 32:
153 colorkey = vo_colorkey;
154 break;
155 case 24:
156 colorkey = vo_colorkey & 0x00ffffff;
157 break;
158 case 16:
159 colorkey = ((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3);
160 break;
161 case 15:
162 colorkey = ((r >> 3) << 10) | ((g >> 3) << 5) | (b >> 3);
163 break;
164 default:
165 mp_msg(MSGT_VO, MSGL_ERR,
166 "Sorry, this (%d) color depth not supported.\n",
167 vo_depthonscreen);
168 return -1;
170 mp_msg(MSGT_VO, MSGL_V, "Using colorkey: %x\n", colorkey);
172 initialized = 1;
174 #ifdef CONFIG_GUI
175 if (use_gui)
176 guiGetEvent(guiSetShVideo, 0); // the GUI will set up / resize the window
177 else
178 #endif
180 if (flags & VOFLAG_FULLSCREEN)
181 aspect(&dwidth, &dheight, A_ZOOM);
183 XGetWindowAttributes(mDisplay, mRootWin, &attribs);
184 mDepth = attribs.depth;
185 if (mDepth != 15 && mDepth != 16 && mDepth != 24 && mDepth != 32)
186 mDepth = 24;
187 XMatchVisualInfo(mDisplay, mScreen, mDepth, TrueColor, &vinfo);
188 xWAttribs.colormap =
189 XCreateColormap(mDisplay, mRootWin, vinfo.visual, AllocNone);
190 xWAttribs.background_pixel = 0;
191 xWAttribs.border_pixel = 0;
192 xWAttribs.event_mask =
193 StructureNotifyMask | ExposureMask | KeyPressMask |
194 ((WinID ==
195 0) ? 0 : (ButtonPressMask | ButtonReleaseMask |
196 PointerMotionMask | PropertyChangeMask));
197 xswamask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
199 if (WinID >= 0)
202 vo_window = WinID ? ((Window) WinID) : mRootWin;
203 if (WinID)
205 XUnmapWindow(mDisplay, vo_window);
206 XChangeWindowAttributes(mDisplay, vo_window, xswamask,
207 &xWAttribs);
208 vo_x11_selectinput_witherr(mDisplay, vo_window,
209 StructureNotifyMask |
210 KeyPressMask |
211 PropertyChangeMask |
212 PointerMotionMask |
213 ButtonPressMask |
214 ButtonReleaseMask |
215 ExposureMask);
216 XMapWindow(mDisplay, vo_window);
217 } else
218 XSelectInput(mDisplay, vo_window, ExposureMask);
220 } else
222 vo_x11_create_vo_window(&vinfo, vo_dx, vo_dy, d_width, d_height,
223 flags, xWAttribs.colormap, "xmga", title);
224 XChangeWindowAttributes(mDisplay, vo_window, xswamask, &xWAttribs);
227 if (vo_gc != None)
228 XFreeGC(mDisplay, vo_gc);
229 vo_gc = XCreateGC(mDisplay, vo_window, GCForeground, &wGCV);
231 } // !GUI
233 if ((flags & VOFLAG_FULLSCREEN) && (!WinID))
235 vo_dx = 0;
236 vo_dy = 0;
237 vo_dwidth = vo_screenwidth;
238 vo_dheight = vo_screenheight;
239 vo_fs = 1;
242 panscan_calc();
244 mga_vid_config.colkey_on = 1;
245 mga_vid_config.colkey_red = r;
246 mga_vid_config.colkey_green = g;
247 mga_vid_config.colkey_blue = b;
249 set_window(); // set up mga_vid_config.dest_width etc
251 if (vo_ontop)
252 vo_x11_setlayer(mDisplay, vo_window, vo_ontop);
254 XSync(mDisplay, False);
256 ioctl(f, MGA_VID_ON, 0);
258 return 0;
261 static void uninit(void)
263 mp_msg(MSGT_VO, MSGL_V, "vo: uninit!\n");
264 mga_uninit();
265 if (!initialized)
266 return; // no window?
267 initialized = 0;
268 vo_x11_uninit(); // destroy the window