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>
32 #ifdef CONFIG_XINERAMA
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 const vo_info_t info
= {
51 "Matrox G200/G4x0/G550 overlay in X11 window (using /dev/mga_vid)",
53 "Zoltan Ponekker <pontscho@makacs.poliod.hu>",
57 const LIBVO_EXTERN(xmga
)
59 static uint32_t mDepth
;
60 static XWindowAttributes attribs
;
63 static uint32_t mvHeight
;
64 static uint32_t mvWidth
;
68 static XSetWindowAttributes xWAttribs
;
70 static int initialized
= 0;
73 #include "mga_common.c"
76 static void mDrawColorKey(void)
78 XSetBackground(mDisplay
, vo_gc
, 0);
79 XClearWindow(mDisplay
, vo_window
);
80 XSetForeground(mDisplay
, vo_gc
, colorkey
);
81 XFillRectangle(mDisplay
, vo_window
, vo_gc
, drwX
, drwY
, drwWidth
,
82 (vo_fs
? drwHeight
- 1 : drwHeight
));
86 static void check_events(void)
88 int e
= vo_x11_check_events(mDisplay
);
90 if (!(e
& VO_EVENT_RESIZE
) && !(e
& VO_EVENT_EXPOSE
))
94 if (ioctl(f
, MGA_VID_CONFIG
, &mga_vid_config
))
95 mp_msg(MSGT_VO
, MSGL_WARN
,
96 "Error in mga_vid_config ioctl (wrong mga_vid.o version?)");
99 static void flip_page(void)
105 mp_msg(MSGT_VO
, MSGL_STATUS
,
106 " [timer: %08X diff: %6d dd: %6d ] \n", t
, t
- timer
,
107 (t
- timer
) - timerd
);
115 static int config(uint32_t width
, uint32_t height
, uint32_t d_width
,
116 uint32_t d_height
, uint32_t flags
, char *title
,
120 unsigned long xswamask
;
123 if (mga_init(width
, height
, format
))
124 return -1; // ioctl errors?
126 aspect_save_orig(width
, height
);
127 aspect_save_prescale(d_width
, d_height
);
128 update_xinerama_info();
133 vo_panscan_x
= vo_panscan_y
= vo_panscan_amount
= 0;
135 aspect(&d_width
, &d_height
, A_NOZOOM
);
136 vo_dx
= (vo_screenwidth
- d_width
) / 2;
137 vo_dy
= (vo_screenheight
- d_height
) / 2;
138 geometry(&vo_dx
, &vo_dy
, &d_width
, &d_height
, vo_screenwidth
,
143 vo_dheight
= d_height
;
145 r
= (vo_colorkey
& 0x00ff0000) >> 16;
146 g
= (vo_colorkey
& 0x0000ff00) >> 8;
147 b
= vo_colorkey
& 0x000000ff;
148 switch (vo_depthonscreen
)
151 colorkey
= vo_colorkey
;
154 colorkey
= vo_colorkey
& 0x00ffffff;
157 colorkey
= ((r
>> 3) << 11) | ((g
>> 2) << 5) | (b
>> 3);
160 colorkey
= ((r
>> 3) << 10) | ((g
>> 3) << 5) | (b
>> 3);
163 mp_msg(MSGT_VO
, MSGL_ERR
,
164 "Sorry, this (%d) color depth not supported.\n",
168 mp_msg(MSGT_VO
, MSGL_V
, "Using colorkey: %x\n", colorkey
);
174 guiGetEvent(guiSetShVideo
, 0); // the GUI will set up / resize the window
178 if (flags
& VOFLAG_FULLSCREEN
)
179 aspect(&dwidth
, &dheight
, A_ZOOM
);
181 XGetWindowAttributes(mDisplay
, mRootWin
, &attribs
);
182 mDepth
= attribs
.depth
;
183 if (mDepth
!= 15 && mDepth
!= 16 && mDepth
!= 24 && mDepth
!= 32)
185 XMatchVisualInfo(mDisplay
, mScreen
, mDepth
, TrueColor
, &vinfo
);
187 XCreateColormap(mDisplay
, mRootWin
, vinfo
.visual
, AllocNone
);
188 xWAttribs
.background_pixel
= 0;
189 xWAttribs
.border_pixel
= 0;
190 xswamask
= CWBackPixel
| CWBorderPixel
| CWColormap
;
192 vo_x11_create_vo_window(&vinfo
, vo_dx
, vo_dy
, d_width
, d_height
,
193 flags
, xWAttribs
.colormap
, "xmga", title
);
194 XChangeWindowAttributes(mDisplay
, vo_window
, xswamask
, &xWAttribs
);
198 if ((flags
& VOFLAG_FULLSCREEN
) && (!WinID
))
202 vo_dwidth
= vo_screenwidth
;
203 vo_dheight
= vo_screenheight
;
209 mga_vid_config
.colkey_on
= 1;
210 mga_vid_config
.colkey_red
= r
;
211 mga_vid_config
.colkey_green
= g
;
212 mga_vid_config
.colkey_blue
= b
;
214 set_window(); // set up mga_vid_config.dest_width etc
216 XSync(mDisplay
, False
);
218 ioctl(f
, MGA_VID_ON
, 0);
223 static void uninit(void)
225 mp_msg(MSGT_VO
, MSGL_V
, "vo: uninit!\n");
228 return; // no window?
230 vo_x11_uninit(); // destroy the window