2 * DirectDraw XVidMode interface
4 * Copyright 2001 TransGaming Technologies, Inc.
9 /* FIXME: XVidMode also includes gamma functions,
10 * we could perhaps use it to implement Get/SetGammaRamp */
12 /* FIXME: ChangeDisplaySettings ought to be able to use this */
14 #ifdef HAVE_LIBXXF86VM
17 #include "ts_xf86vmode.h"
23 #include "debugtools.h"
25 DEFAULT_DEBUG_CHANNEL(x11drv
);
27 LPDDHALMODEINFO xf86vm_modes
;
28 unsigned xf86vm_mode_count
;
29 XF86VidModeModeInfo
** modes
;
31 #define CONVERT_MODE(dotclock) \
32 info->dwWidth = mode->hdisplay; \
33 info->dwHeight = mode->vdisplay; \
34 info->wRefreshRate = dotclock * 1000 / (mode->htotal * mode->vtotal); \
35 TRACE(" width=%ld, height=%ld, refresh=%d\n", \
36 info->dwWidth, info->dwHeight, info->wRefreshRate); \
37 /* XVidMode cannot change display depths... */ \
38 /* let's not bother with filling out these then... */ \
42 info->dwRBitMask = 0; \
43 info->dwGBitMask = 0; \
44 info->dwBBitMask = 0; \
45 info->dwAlphaBitMask = 0;
47 static void convert_modeinfo(XF86VidModeModeInfo
*mode
, LPDDHALMODEINFO info
)
49 CONVERT_MODE(mode
->dotclock
)
52 static void convert_modeline(int dotclock
, XF86VidModeModeLine
*mode
, LPDDHALMODEINFO info
)
54 CONVERT_MODE(dotclock
)
57 void X11DRV_XF86VM_Init(void)
59 int nmodes
, major
, minor
, i
;
61 if (xf86vm_modes
) return; /* already initialized? */
63 /* if in desktop mode, don't use XVidMode */
64 if (X11DRV_GetXRootWindow() != DefaultRootWindow(display
)) return;
66 /* see if XVidMode is available */
67 if (!TSXF86VidModeQueryVersion(display
, &major
, &minor
)) return;
70 if (!TSXF86VidModeGetAllModeLines(display
, DefaultScreen(display
), &nmodes
,
74 TRACE("XVidMode modes: count=%d\n", nmodes
);
76 xf86vm_mode_count
= nmodes
;
77 xf86vm_modes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DDHALMODEINFO
) * nmodes
);
79 /* convert modes to DDHALMODEINFO format */
80 for (i
=0; i
<nmodes
; i
++)
81 convert_modeinfo(modes
[i
], &xf86vm_modes
[i
]);
83 TRACE("Enabling XVidMode\n");
86 void X11DRV_XF86VM_Cleanup(void)
91 int X11DRV_XF86VM_GetCurrentMode(void)
93 XF86VidModeModeLine line
;
97 TRACE("Querying XVidMode current mode\n");
98 TSXF86VidModeGetModeLine(display
, DefaultScreen(display
), &dotclock
, &line
);
99 convert_modeline(dotclock
, &line
, &cmode
);
100 for (i
=0; i
<xf86vm_mode_count
; i
++)
101 if (memcmp(&xf86vm_modes
[i
], &cmode
, sizeof(cmode
)) == 0) {
102 TRACE("mode=%d\n", i
);
105 ERR("unknown mode, shouldn't happen\n");
106 return 0; /* return first mode */
109 void X11DRV_XF86VM_SetCurrentMode(int mode
)
111 TSXF86VidModeSwitchToMode(display
, DefaultScreen(display
), modes
[mode
]);
112 TSXF86VidModeSetViewPort(display
, DefaultScreen(display
), 0, 0);
113 TSXSync(display
, False
);
116 void X11DRV_XF86VM_SetExclusiveMode(int lock
)
118 TSXF86VidModeLockModeSwitch(display
, DefaultScreen(display
), lock
);
121 #endif /* HAVE_LIBXXF86VM */