7 * Copyright (C) Zoltan Ponekker - Jan 2001
17 #include "video_out.h"
18 #include "video_out_internal.h"
21 #include <sys/ioctl.h>
26 #include "drivers/mga_vid.h"
29 #include <X11/Xutil.h>
33 #include <X11/extensions/Xinerama.h>
36 #include "x11_common.h"
41 #include "osdep/timer.h"
42 static unsigned int timer
= 0;
43 static unsigned int timerd
= 0;
47 #include "Gui/interface.h"
50 static vo_info_t info
= {
51 "Matrox G200/G4x0/G550 overlay in X11 window (using /dev/mga_vid)",
53 "Zoltan Ponekker <pontscho@makacs.poliod.hu>",
58 static XGCValues wGCV
;
60 static uint32_t mDepth
;
61 static XWindowAttributes attribs
;
64 static uint32_t mvHeight
;
65 static uint32_t mvWidth
;
69 static XSetWindowAttributes xWAttribs
;
71 static int inited
= 0;
74 #include "mga_common.c"
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
));
87 static void check_events(void)
89 int e
= vo_x11_check_events(mDisplay
);
91 if (!(e
& VO_EVENT_RESIZE
) && !(e
& VO_EVENT_EXPOSE
))
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)
106 mp_msg(MSGT_VO
, MSGL_STATUS
,
107 " [timer: %08X diff: %6d dd: %6d ] \n", t
, t
- timer
,
108 (t
- timer
) - timerd
);
116 static int config(uint32_t width
, uint32_t height
, uint32_t d_width
,
117 uint32_t d_height
, uint32_t flags
, char *title
,
120 char *mTitle
= (title
== NULL
) ? "XMGA render" : title
;
122 unsigned long xswamask
;
125 if (mga_init(width
, height
, format
))
126 return -1; // ioctl errors?
128 aspect_save_orig(width
, height
);
129 aspect_save_prescale(d_width
, d_height
);
130 update_xinerama_info();
135 vo_panscan_x
= vo_panscan_y
= vo_panscan_amount
= 0;
137 aspect(&d_width
, &d_height
, A_NOZOOM
);
138 vo_dx
= (vo_screenwidth
- d_width
) / 2;
139 vo_dy
= (vo_screenheight
- d_height
) / 2;
140 geometry(&vo_dx
, &vo_dy
, &d_width
, &d_height
, vo_screenwidth
,
145 vo_dheight
= d_height
;
146 vo_mouse_autohide
= 1;
148 r
= (vo_colorkey
& 0x00ff0000) >> 16;
149 g
= (vo_colorkey
& 0x0000ff00) >> 8;
150 b
= vo_colorkey
& 0x000000ff;
151 switch (vo_depthonscreen
)
154 colorkey
= vo_colorkey
;
157 colorkey
= vo_colorkey
& 0x00ffffff;
160 colorkey
= ((r
>> 3) << 11) | ((g
>> 2) << 5) | (b
>> 3);
163 colorkey
= ((r
>> 3) << 10) | ((g
>> 3) << 5) | (b
>> 3);
166 mp_msg(MSGT_VO
, MSGL_ERR
,
167 "Sorry, this (%d) color depth not supported.\n",
171 mp_msg(MSGT_VO
, MSGL_V
, "Using colorkey: %x\n", colorkey
);
177 guiGetEvent(guiSetShVideo
, 0); // the GUI will set up / resize the window
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)
188 XMatchVisualInfo(mDisplay
, mScreen
, mDepth
, TrueColor
, &vinfo
);
190 XCreateColormap(mDisplay
, mRootWin
, vinfo
.visual
, AllocNone
);
191 xWAttribs
.background_pixel
= 0;
192 xWAttribs
.border_pixel
= 0;
193 xWAttribs
.event_mask
=
194 StructureNotifyMask
| ExposureMask
| KeyPressMask
|
196 0) ? 0 : (ButtonPressMask
| ButtonReleaseMask
|
197 PointerMotionMask
| PropertyChangeMask
));
198 xswamask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
203 vo_window
= WinID
? ((Window
) WinID
) : mRootWin
;
206 XUnmapWindow(mDisplay
, vo_window
);
207 XChangeWindowAttributes(mDisplay
, vo_window
, xswamask
,
209 vo_x11_selectinput_witherr(mDisplay
, vo_window
,
210 StructureNotifyMask
|
217 XMapWindow(mDisplay
, vo_window
);
219 XSelectInput(mDisplay
, vo_window
, ExposureMask
);
224 if (vo_window
== None
)
226 vo_window
= XCreateWindow(mDisplay
, mRootWin
,
228 vo_dwidth
, vo_dheight
,
229 xWAttribs
.border_pixel
,
232 vinfo
.visual
, xswamask
,
235 vo_x11_classhint(mDisplay
, vo_window
, "xmga");
236 vo_hidecursor(mDisplay
, vo_window
);
237 vo_x11_sizehint(vo_dx
, vo_dy
, vo_dwidth
, vo_dheight
, 0);
239 XStoreName(mDisplay
, vo_window
, mTitle
);
240 XMapWindow(mDisplay
, vo_window
);
241 vo_x11_nofs_sizepos(vo_dx
, vo_dy
, vo_dwidth
, vo_dheight
);
243 if (flags
& VOFLAG_FULLSCREEN
)
247 vo_x11_nofs_sizepos(vo_dx
, vo_dy
, vo_dwidth
, vo_dheight
);
251 XFreeGC(mDisplay
, vo_gc
);
252 vo_gc
= XCreateGC(mDisplay
, vo_window
, GCForeground
, &wGCV
);
256 if ((flags
& VOFLAG_FULLSCREEN
) && (!WinID
))
260 vo_dwidth
= vo_screenwidth
;
261 vo_dheight
= vo_screenheight
;
267 mga_vid_config
.colkey_on
= 1;
268 mga_vid_config
.colkey_red
= r
;
269 mga_vid_config
.colkey_green
= g
;
270 mga_vid_config
.colkey_blue
= b
;
272 set_window(); // set up mga_vid_config.dest_width etc
275 vo_x11_setlayer(mDisplay
, vo_window
, vo_ontop
);
277 XSync(mDisplay
, False
);
279 ioctl(f
, MGA_VID_ON
, 0);
284 static void uninit(void)
286 mp_msg(MSGT_VO
, MSGL_V
, "vo: uninit!\n");
289 return; // no window?
291 vo_x11_uninit(); // destroy the window