2001-02-14 00:27:34 +00:00
|
|
|
/*
|
|
|
|
* DirectDraw XVidMode interface
|
|
|
|
*
|
|
|
|
* Copyright 2001 TransGaming Technologies, Inc.
|
2002-03-09 23:29:33 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-02-14 00:27:34 +00:00
|
|
|
*/
|
|
|
|
|
2001-05-18 20:59:22 +00:00
|
|
|
#include "config.h"
|
2008-06-26 12:02:17 +00:00
|
|
|
#include "wine/port.h"
|
|
|
|
|
2001-05-18 20:59:22 +00:00
|
|
|
#include <string.h>
|
2003-04-22 00:15:48 +00:00
|
|
|
#include <stdio.h>
|
2004-01-20 22:48:57 +00:00
|
|
|
#include <math.h>
|
2001-02-14 00:27:34 +00:00
|
|
|
|
2005-04-14 12:48:11 +00:00
|
|
|
#include "x11drv.h"
|
2002-09-24 18:36:51 +00:00
|
|
|
|
2008-06-26 12:02:17 +00:00
|
|
|
#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
|
2002-09-24 18:36:51 +00:00
|
|
|
#include <X11/extensions/xf86vmode.h>
|
2008-06-26 12:02:17 +00:00
|
|
|
#endif
|
2009-09-19 17:08:09 +00:00
|
|
|
#ifdef HAVE_X11_EXTENSIONS_XF86VMPROTO_H
|
|
|
|
#include <X11/extensions/xf86vmproto.h>
|
|
|
|
#endif
|
2002-09-24 18:36:51 +00:00
|
|
|
|
2001-03-20 01:24:08 +00:00
|
|
|
#include "xvidmode.h"
|
2001-02-14 00:27:34 +00:00
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "ddrawi.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
2008-06-26 12:02:17 +00:00
|
|
|
#include "wine/library.h"
|
2001-02-14 00:27:34 +00:00
|
|
|
|
2003-10-16 00:21:42 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(xvidmode);
|
2001-05-18 20:59:22 +00:00
|
|
|
|
2008-06-26 12:02:17 +00:00
|
|
|
#ifdef SONAME_LIBXXF86VM
|
2003-11-27 00:59:36 +00:00
|
|
|
|
2001-09-10 23:05:57 +00:00
|
|
|
extern int usexvidmode;
|
|
|
|
|
2001-03-20 01:24:08 +00:00
|
|
|
static int xf86vm_event, xf86vm_error, xf86vm_major, xf86vm_minor;
|
|
|
|
|
2001-10-21 15:02:01 +00:00
|
|
|
#ifdef X_XF86VidModeSetGammaRamp
|
|
|
|
static int xf86vm_gammaramp_size;
|
|
|
|
static BOOL xf86vm_use_gammaramp;
|
2003-10-16 00:21:42 +00:00
|
|
|
#endif /* X_XF86VidModeSetGammaRamp */
|
2001-10-21 15:02:01 +00:00
|
|
|
|
2003-09-30 00:31:42 +00:00
|
|
|
static LPDDHALMODEINFO dd_modes;
|
|
|
|
static unsigned int dd_mode_count;
|
|
|
|
static XF86VidModeModeInfo** real_xf86vm_modes;
|
|
|
|
static unsigned int real_xf86vm_mode_count;
|
2001-02-14 00:27:34 +00:00
|
|
|
|
2008-12-03 11:10:32 +00:00
|
|
|
#define MAKE_FUNCPTR(f) static typeof(f) * p##f;
|
2008-06-26 12:02:17 +00:00
|
|
|
MAKE_FUNCPTR(XF86VidModeGetAllModeLines)
|
|
|
|
MAKE_FUNCPTR(XF86VidModeGetModeLine)
|
|
|
|
MAKE_FUNCPTR(XF86VidModeLockModeSwitch)
|
|
|
|
MAKE_FUNCPTR(XF86VidModeQueryExtension)
|
|
|
|
MAKE_FUNCPTR(XF86VidModeQueryVersion)
|
|
|
|
MAKE_FUNCPTR(XF86VidModeSetViewPort)
|
|
|
|
MAKE_FUNCPTR(XF86VidModeSwitchToMode)
|
|
|
|
#ifdef X_XF86VidModeSetGamma
|
|
|
|
MAKE_FUNCPTR(XF86VidModeGetGamma)
|
|
|
|
MAKE_FUNCPTR(XF86VidModeSetGamma)
|
|
|
|
#endif
|
|
|
|
#ifdef X_XF86VidModeSetGammaRamp
|
|
|
|
MAKE_FUNCPTR(XF86VidModeGetGammaRamp)
|
|
|
|
MAKE_FUNCPTR(XF86VidModeGetGammaRampSize)
|
|
|
|
MAKE_FUNCPTR(XF86VidModeSetGammaRamp)
|
|
|
|
#endif
|
|
|
|
#undef MAKE_FUNCPTR
|
|
|
|
|
|
|
|
|
2003-10-16 00:21:42 +00:00
|
|
|
static void convert_modeinfo( const XF86VidModeModeInfo *mode)
|
2001-02-14 00:27:34 +00:00
|
|
|
{
|
2003-10-16 00:21:42 +00:00
|
|
|
int rate;
|
2001-09-14 00:05:44 +00:00
|
|
|
if (mode->htotal!=0 && mode->vtotal!=0)
|
2003-10-16 00:21:42 +00:00
|
|
|
rate = mode->dotclock * 1000 / (mode->htotal * mode->vtotal);
|
2001-09-14 00:05:44 +00:00
|
|
|
else
|
2003-10-16 00:21:42 +00:00
|
|
|
rate = 0;
|
|
|
|
X11DRV_Settings_AddOneMode(mode->hdisplay, mode->vdisplay, 0, rate);
|
2001-02-14 00:27:34 +00:00
|
|
|
}
|
|
|
|
|
2003-09-30 00:31:42 +00:00
|
|
|
static void convert_modeline(int dotclock, const XF86VidModeModeLine *mode, LPDDHALMODEINFO info, unsigned int bpp)
|
2001-02-14 00:27:34 +00:00
|
|
|
{
|
2001-09-11 00:32:32 +00:00
|
|
|
info->dwWidth = mode->hdisplay;
|
|
|
|
info->dwHeight = mode->vdisplay;
|
2001-09-14 00:05:44 +00:00
|
|
|
if (mode->htotal!=0 && mode->vtotal!=0)
|
|
|
|
info->wRefreshRate = dotclock * 1000 / (mode->htotal * mode->vtotal);
|
|
|
|
else
|
|
|
|
info->wRefreshRate = 0;
|
2006-10-07 23:34:01 +00:00
|
|
|
TRACE(" width=%d, height=%d, refresh=%d\n",
|
2001-09-11 00:32:32 +00:00
|
|
|
info->dwWidth, info->dwHeight, info->wRefreshRate);
|
|
|
|
info->lPitch = 0;
|
2003-09-30 00:31:42 +00:00
|
|
|
info->dwBPP = bpp;
|
2001-09-11 00:32:32 +00:00
|
|
|
info->wFlags = 0;
|
|
|
|
info->dwRBitMask = 0;
|
|
|
|
info->dwGBitMask = 0;
|
|
|
|
info->dwBBitMask = 0;
|
|
|
|
info->dwAlphaBitMask = 0;
|
2001-02-14 00:27:34 +00:00
|
|
|
}
|
|
|
|
|
2002-07-16 01:16:44 +00:00
|
|
|
static int XVidModeErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-06-05 22:31:58 +00:00
|
|
|
static int X11DRV_XF86VM_GetCurrentMode(void)
|
2003-10-16 00:21:42 +00:00
|
|
|
{
|
|
|
|
XF86VidModeModeLine line;
|
2004-08-11 23:45:34 +00:00
|
|
|
int dotclock;
|
|
|
|
unsigned int i;
|
2003-10-16 00:21:42 +00:00
|
|
|
DDHALMODEINFO cmode;
|
2007-12-16 13:00:45 +00:00
|
|
|
DWORD dwBpp = screen_bpp;
|
2003-10-16 00:21:42 +00:00
|
|
|
|
|
|
|
TRACE("Querying XVidMode current mode\n");
|
|
|
|
wine_tsx11_lock();
|
2008-06-26 12:02:17 +00:00
|
|
|
pXF86VidModeGetModeLine(gdi_display, DefaultScreen(gdi_display), &dotclock, &line);
|
2003-10-16 00:21:42 +00:00
|
|
|
wine_tsx11_unlock();
|
|
|
|
convert_modeline(dotclock, &line, &cmode, dwBpp);
|
|
|
|
for (i=0; i<dd_mode_count; i++)
|
|
|
|
if (memcmp(&dd_modes[i], &cmode, sizeof(cmode)) == 0) {
|
|
|
|
TRACE("mode=%d\n", i);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
ERR("In unknown mode, returning default\n");
|
2004-02-03 00:10:23 +00:00
|
|
|
return 0;
|
2003-10-16 00:21:42 +00:00
|
|
|
}
|
|
|
|
|
2007-02-22 11:42:20 +00:00
|
|
|
static LONG X11DRV_XF86VM_SetCurrentMode(int mode)
|
2003-10-16 00:21:42 +00:00
|
|
|
{
|
2007-12-16 13:00:45 +00:00
|
|
|
DWORD dwBpp = screen_bpp;
|
2003-10-16 00:21:42 +00:00
|
|
|
/* only set modes from the original color depth */
|
|
|
|
if (dwBpp != dd_modes[mode].dwBPP)
|
|
|
|
{
|
2006-10-07 23:34:01 +00:00
|
|
|
FIXME("Cannot change screen BPP from %d to %d\n", dwBpp, dd_modes[mode].dwBPP);
|
2003-10-16 00:21:42 +00:00
|
|
|
}
|
|
|
|
mode = mode % real_xf86vm_mode_count;
|
|
|
|
|
|
|
|
wine_tsx11_lock();
|
|
|
|
TRACE("Resizing X display to %dx%d\n",
|
|
|
|
real_xf86vm_modes[mode]->hdisplay, real_xf86vm_modes[mode]->vdisplay);
|
2008-06-26 12:02:17 +00:00
|
|
|
pXF86VidModeSwitchToMode(gdi_display, DefaultScreen(gdi_display), real_xf86vm_modes[mode]);
|
2003-10-16 00:21:42 +00:00
|
|
|
#if 0 /* it is said that SetViewPort causes problems with some X servers */
|
2008-06-26 12:02:17 +00:00
|
|
|
pXF86VidModeSetViewPort(gdi_display, DefaultScreen(gdi_display), 0, 0);
|
2003-10-16 00:21:42 +00:00
|
|
|
#else
|
|
|
|
XWarpPointer(gdi_display, None, DefaultRootWindow(gdi_display), 0, 0, 0, 0, 0, 0);
|
|
|
|
#endif
|
|
|
|
XSync(gdi_display, False);
|
|
|
|
wine_tsx11_unlock();
|
2008-01-17 18:53:59 +00:00
|
|
|
X11DRV_resize_desktop( real_xf86vm_modes[mode]->hdisplay, real_xf86vm_modes[mode]->vdisplay );
|
2007-02-22 11:42:20 +00:00
|
|
|
return DISP_CHANGE_SUCCESSFUL;
|
2003-10-16 00:21:42 +00:00
|
|
|
}
|
2003-09-16 20:24:29 +00:00
|
|
|
|
2008-06-26 12:02:17 +00:00
|
|
|
|
2001-02-14 00:27:34 +00:00
|
|
|
void X11DRV_XF86VM_Init(void)
|
|
|
|
{
|
2008-06-26 12:02:17 +00:00
|
|
|
void *xvidmode_handle;
|
2002-07-16 01:16:44 +00:00
|
|
|
Bool ok;
|
2004-08-11 23:45:34 +00:00
|
|
|
int nmodes;
|
|
|
|
unsigned int i;
|
2003-09-30 00:31:42 +00:00
|
|
|
|
2001-03-20 01:24:08 +00:00
|
|
|
if (xf86vm_major) return; /* already initialized? */
|
2001-02-14 00:27:34 +00:00
|
|
|
|
2008-06-26 12:02:17 +00:00
|
|
|
xvidmode_handle = wine_dlopen(SONAME_LIBXXF86VM, RTLD_NOW, NULL, 0);
|
|
|
|
if (!xvidmode_handle)
|
|
|
|
{
|
|
|
|
TRACE("Unable to open %s, XVidMode disabled\n", SONAME_LIBXXF86VM);
|
|
|
|
usexvidmode = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LOAD_FUNCPTR(f) \
|
|
|
|
if((p##f = wine_dlsym(xvidmode_handle, #f, NULL, 0)) == NULL) \
|
|
|
|
goto sym_not_found;
|
|
|
|
LOAD_FUNCPTR(XF86VidModeGetAllModeLines)
|
|
|
|
LOAD_FUNCPTR(XF86VidModeGetModeLine)
|
|
|
|
LOAD_FUNCPTR(XF86VidModeLockModeSwitch)
|
|
|
|
LOAD_FUNCPTR(XF86VidModeQueryExtension)
|
|
|
|
LOAD_FUNCPTR(XF86VidModeQueryVersion)
|
|
|
|
LOAD_FUNCPTR(XF86VidModeSetViewPort)
|
|
|
|
LOAD_FUNCPTR(XF86VidModeSwitchToMode)
|
|
|
|
#ifdef X_XF86VidModeSetGamma
|
|
|
|
LOAD_FUNCPTR(XF86VidModeGetGamma)
|
|
|
|
LOAD_FUNCPTR(XF86VidModeSetGamma)
|
|
|
|
#endif
|
|
|
|
#ifdef X_XF86VidModeSetGammaRamp
|
|
|
|
LOAD_FUNCPTR(XF86VidModeGetGammaRamp)
|
|
|
|
LOAD_FUNCPTR(XF86VidModeGetGammaRampSize)
|
|
|
|
LOAD_FUNCPTR(XF86VidModeSetGammaRamp)
|
|
|
|
#endif
|
|
|
|
#undef LOAD_FUNCPTR
|
|
|
|
|
2001-03-20 01:24:08 +00:00
|
|
|
/* see if XVidMode is available */
|
2002-09-24 18:36:51 +00:00
|
|
|
wine_tsx11_lock();
|
2008-06-26 12:02:17 +00:00
|
|
|
ok = pXF86VidModeQueryExtension(gdi_display, &xf86vm_event, &xf86vm_error);
|
2002-09-24 18:36:51 +00:00
|
|
|
if (ok)
|
2001-10-21 15:02:01 +00:00
|
|
|
{
|
2002-09-24 18:36:51 +00:00
|
|
|
X11DRV_expect_error(gdi_display, XVidModeErrorHandler, NULL);
|
2008-06-26 12:02:17 +00:00
|
|
|
ok = pXF86VidModeQueryVersion(gdi_display, &xf86vm_major, &xf86vm_minor);
|
2002-09-24 18:36:51 +00:00
|
|
|
if (X11DRV_check_error()) ok = FALSE;
|
2001-10-21 15:02:01 +00:00
|
|
|
}
|
2002-09-24 18:36:51 +00:00
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
#ifdef X_XF86VidModeSetGammaRamp
|
|
|
|
if (xf86vm_major > 2 || (xf86vm_major == 2 && xf86vm_minor >= 1))
|
|
|
|
{
|
2008-06-26 12:02:17 +00:00
|
|
|
pXF86VidModeGetGammaRampSize(gdi_display, DefaultScreen(gdi_display),
|
2002-09-24 18:36:51 +00:00
|
|
|
&xf86vm_gammaramp_size);
|
|
|
|
if (xf86vm_gammaramp_size == 256)
|
|
|
|
xf86vm_use_gammaramp = TRUE;
|
|
|
|
}
|
2003-10-16 00:21:42 +00:00
|
|
|
#endif /* X_XF86VidModeSetGammaRamp */
|
2001-10-21 15:02:01 +00:00
|
|
|
|
2002-09-24 18:36:51 +00:00
|
|
|
/* retrieve modes */
|
2006-04-04 01:38:10 +00:00
|
|
|
if (usexvidmode && root_window == DefaultRootWindow( gdi_display ))
|
2008-06-26 12:02:17 +00:00
|
|
|
ok = pXF86VidModeGetAllModeLines(gdi_display, DefaultScreen(gdi_display), &nmodes, &real_xf86vm_modes);
|
2006-03-27 13:33:43 +00:00
|
|
|
else
|
|
|
|
ok = FALSE; /* In desktop mode, do not switch resolution... But still use the Gamma ramp stuff */
|
2002-09-24 18:36:51 +00:00
|
|
|
}
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
if (!ok) return;
|
2001-02-14 00:27:34 +00:00
|
|
|
|
|
|
|
TRACE("XVidMode modes: count=%d\n", nmodes);
|
|
|
|
|
2003-09-30 00:31:42 +00:00
|
|
|
real_xf86vm_mode_count = nmodes;
|
|
|
|
|
2003-10-16 00:21:42 +00:00
|
|
|
dd_modes = X11DRV_Settings_SetHandlers("XF86VidMode",
|
|
|
|
X11DRV_XF86VM_GetCurrentMode,
|
|
|
|
X11DRV_XF86VM_SetCurrentMode,
|
|
|
|
nmodes, 1);
|
2001-02-14 00:27:34 +00:00
|
|
|
|
|
|
|
/* convert modes to DDHALMODEINFO format */
|
2003-09-30 00:31:42 +00:00
|
|
|
for (i=0; i<real_xf86vm_mode_count; i++)
|
|
|
|
{
|
2003-10-16 00:21:42 +00:00
|
|
|
convert_modeinfo(real_xf86vm_modes[i]);
|
2003-09-30 00:31:42 +00:00
|
|
|
}
|
|
|
|
/* add modes for different color depths */
|
2003-10-16 00:21:42 +00:00
|
|
|
X11DRV_Settings_AddDepthModes();
|
|
|
|
dd_mode_count = X11DRV_Settings_GetModeCount();
|
2003-09-30 00:31:42 +00:00
|
|
|
|
|
|
|
TRACE("Available DD modes: count=%d\n", dd_mode_count);
|
2001-02-14 00:27:34 +00:00
|
|
|
TRACE("Enabling XVidMode\n");
|
2008-06-26 12:02:17 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
sym_not_found:
|
|
|
|
TRACE("Unable to load function pointers from %s, XVidMode disabled\n", SONAME_LIBXXF86VM);
|
|
|
|
wine_dlclose(xvidmode_handle, NULL, 0);
|
|
|
|
xvidmode_handle = NULL;
|
|
|
|
usexvidmode = 0;
|
2001-02-14 00:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void X11DRV_XF86VM_Cleanup(void)
|
|
|
|
{
|
2003-11-21 21:48:36 +00:00
|
|
|
wine_tsx11_lock();
|
|
|
|
if (real_xf86vm_modes) XFree(real_xf86vm_modes);
|
|
|
|
wine_tsx11_unlock();
|
2001-02-14 00:27:34 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 01:24:08 +00:00
|
|
|
/***** GAMMA CONTROL *****/
|
|
|
|
/* (only available in XF86VidMode 2.x) */
|
|
|
|
|
|
|
|
#ifdef X_XF86VidModeSetGamma
|
|
|
|
|
|
|
|
static void GenerateRampFromGamma(WORD ramp[256], float gamma)
|
|
|
|
{
|
|
|
|
float r_gamma = 1/gamma;
|
|
|
|
unsigned i;
|
|
|
|
TRACE("gamma is %f\n", r_gamma);
|
|
|
|
for (i=0; i<256; i++)
|
|
|
|
ramp[i] = pow(i/255.0, r_gamma) * 65535.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL ComputeGammaFromRamp(WORD ramp[256], float *gamma)
|
|
|
|
{
|
|
|
|
float r_x, r_y, r_lx, r_ly, r_d, r_v, r_e, g_avg, g_min, g_max;
|
|
|
|
unsigned i, f, l, g_n, c;
|
|
|
|
f = ramp[0];
|
|
|
|
l = ramp[255];
|
|
|
|
if (f >= l) {
|
|
|
|
ERR("inverted or flat gamma ramp (%d->%d), rejected\n", f, l);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
r_d = l - f;
|
|
|
|
g_min = g_max = g_avg = 0.0;
|
|
|
|
/* check gamma ramp entries to estimate the gamma */
|
|
|
|
TRACE("analyzing gamma ramp (%d->%d)\n", f, l);
|
|
|
|
for (i=1, g_n=0; i<255; i++) {
|
|
|
|
if (ramp[i] < f || ramp[i] > l) {
|
|
|
|
ERR("strange gamma ramp ([%d]=%d for %d->%d), rejected\n", i, ramp[i], f, l);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
c = ramp[i] - f;
|
|
|
|
if (!c) continue; /* avoid log(0) */
|
|
|
|
|
|
|
|
/* normalize entry values into 0..1 range */
|
|
|
|
r_x = i/255.0; r_y = c / r_d;
|
|
|
|
/* compute logarithms of values */
|
|
|
|
r_lx = log(r_x); r_ly = log(r_y);
|
|
|
|
/* compute gamma for this entry */
|
|
|
|
r_v = r_ly / r_lx;
|
|
|
|
/* compute differential (error estimate) for this entry */
|
|
|
|
/* some games use table-based logarithms that magnifies the error by 128 */
|
|
|
|
r_e = -r_lx * 128 / (c * r_lx * r_lx);
|
|
|
|
|
|
|
|
/* compute min & max while compensating for estimated error */
|
|
|
|
if (!g_n || g_min > (r_v + r_e)) g_min = r_v + r_e;
|
|
|
|
if (!g_n || g_max < (r_v - r_e)) g_max = r_v - r_e;
|
2001-09-11 00:32:32 +00:00
|
|
|
|
2001-03-20 01:24:08 +00:00
|
|
|
/* add to average */
|
|
|
|
g_avg += r_v;
|
|
|
|
g_n++;
|
|
|
|
/* TRACE("[%d]=%d, gamma=%f, error=%f\n", i, ramp[i], r_v, r_e); */
|
|
|
|
}
|
|
|
|
if (!g_n) {
|
|
|
|
ERR("no gamma data, shouldn't happen\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
g_avg /= g_n;
|
|
|
|
TRACE("low bias is %d, high is %d, gamma is %5.3f\n", f, 65535-l, g_avg);
|
|
|
|
/* the bias could be because the app wanted something like a "red shift"
|
|
|
|
* like when you're hit in Quake, but XVidMode doesn't support it,
|
|
|
|
* so we have to reject a significant bias */
|
|
|
|
if (f && f > (pow(1/255.0, g_avg) * 65536.0)) {
|
|
|
|
ERR("low-biased gamma ramp (%d), rejected\n", f);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* check that the gamma is reasonably uniform across the ramp */
|
2011-09-18 17:07:33 +00:00
|
|
|
if (g_max - g_min > 12.8) {
|
2001-03-20 01:24:08 +00:00
|
|
|
ERR("ramp not uniform (max=%f, min=%f, avg=%f), rejected\n", g_max, g_min, g_avg);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-08-23 21:16:26 +00:00
|
|
|
/* check that the gamma is not too bright */
|
|
|
|
if (g_avg < 0.2) {
|
|
|
|
ERR("too bright gamma ( %5.3f), rejected\n", g_avg);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-03-20 01:24:08 +00:00
|
|
|
/* ok, now we're pretty sure we can set the desired gamma ramp,
|
|
|
|
* so go for it */
|
|
|
|
*gamma = 1/g_avg;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* X_XF86VidModeSetGamma */
|
|
|
|
|
|
|
|
/* Hmm... should gamma control be available in desktop mode or not?
|
|
|
|
* I'll assume that it should */
|
|
|
|
|
2008-12-03 11:10:32 +00:00
|
|
|
static BOOL X11DRV_XF86VM_GetGammaRamp(LPDDGAMMARAMP ramp)
|
2001-03-20 01:24:08 +00:00
|
|
|
{
|
|
|
|
#ifdef X_XF86VidModeSetGamma
|
|
|
|
XF86VidModeGamma gamma;
|
|
|
|
Bool ret;
|
|
|
|
|
|
|
|
if (xf86vm_major < 2) return FALSE; /* no gamma control */
|
2001-10-21 15:02:01 +00:00
|
|
|
#ifdef X_XF86VidModeSetGammaRamp
|
|
|
|
else if (xf86vm_use_gammaramp)
|
|
|
|
{
|
|
|
|
Bool ret;
|
|
|
|
wine_tsx11_lock();
|
2008-06-26 12:02:17 +00:00
|
|
|
ret = pXF86VidModeGetGammaRamp(gdi_display, DefaultScreen(gdi_display), 256,
|
2001-10-21 15:02:01 +00:00
|
|
|
ramp->red, ramp->green, ramp->blue);
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wine_tsx11_lock();
|
2008-06-26 12:02:17 +00:00
|
|
|
ret = pXF86VidModeGetGamma(gdi_display, DefaultScreen(gdi_display), &gamma);
|
2001-10-21 15:02:01 +00:00
|
|
|
wine_tsx11_unlock();
|
|
|
|
if (ret) {
|
|
|
|
GenerateRampFromGamma(ramp->red, gamma.red);
|
|
|
|
GenerateRampFromGamma(ramp->green, gamma.green);
|
|
|
|
GenerateRampFromGamma(ramp->blue, gamma.blue);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-03-20 01:24:08 +00:00
|
|
|
}
|
|
|
|
#endif /* X_XF86VidModeSetGamma */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-12-03 11:10:32 +00:00
|
|
|
static BOOL X11DRV_XF86VM_SetGammaRamp(LPDDGAMMARAMP ramp)
|
2001-03-20 01:24:08 +00:00
|
|
|
{
|
2011-08-11 18:35:11 +00:00
|
|
|
Bool ret = FALSE;
|
2001-03-20 01:24:08 +00:00
|
|
|
#ifdef X_XF86VidModeSetGamma
|
|
|
|
XF86VidModeGamma gamma;
|
|
|
|
|
2011-08-02 20:28:36 +00:00
|
|
|
if (xf86vm_major < 2 || !usexvidmode) return FALSE; /* no gamma control */
|
2011-08-11 18:35:11 +00:00
|
|
|
if (!ComputeGammaFromRamp(ramp->red, &gamma.red) || /* ramp validation */
|
|
|
|
!ComputeGammaFromRamp(ramp->green, &gamma.green) ||
|
|
|
|
!ComputeGammaFromRamp(ramp->blue, &gamma.blue)) return FALSE;
|
|
|
|
wine_tsx11_lock();
|
2001-10-21 15:02:01 +00:00
|
|
|
#ifdef X_XF86VidModeSetGammaRamp
|
2011-08-11 18:35:11 +00:00
|
|
|
if (xf86vm_use_gammaramp)
|
2008-06-26 12:02:17 +00:00
|
|
|
ret = pXF86VidModeSetGammaRamp(gdi_display, DefaultScreen(gdi_display), 256,
|
2001-10-21 15:02:01 +00:00
|
|
|
ramp->red, ramp->green, ramp->blue);
|
|
|
|
else
|
2011-08-11 18:35:11 +00:00
|
|
|
#endif
|
|
|
|
ret = pXF86VidModeSetGamma(gdi_display, DefaultScreen(gdi_display), &gamma);
|
|
|
|
wine_tsx11_unlock();
|
2001-03-20 01:24:08 +00:00
|
|
|
#endif /* X_XF86VidModeSetGamma */
|
2011-08-11 18:35:11 +00:00
|
|
|
return ret;
|
2001-03-20 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
2008-06-26 12:02:17 +00:00
|
|
|
#endif /* SONAME_LIBXXF86VM */
|
2001-03-20 01:24:08 +00:00
|
|
|
|
2001-08-09 21:36:39 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* GetDeviceGammaRamp (X11DRV.@)
|
|
|
|
*
|
|
|
|
* FIXME: should move to somewhere appropriate, but probably not before
|
2001-03-20 01:24:08 +00:00
|
|
|
* the stuff in graphics/x11drv/ has been moved to dlls/x11drv, so that
|
2001-09-11 00:32:32 +00:00
|
|
|
* they can include xvidmode.h directly
|
2001-08-09 21:36:39 +00:00
|
|
|
*/
|
2011-07-13 12:56:12 +00:00
|
|
|
BOOL X11DRV_GetDeviceGammaRamp(PHYSDEV dev, LPVOID ramp)
|
2001-03-20 01:24:08 +00:00
|
|
|
{
|
2008-06-26 12:02:17 +00:00
|
|
|
#ifdef SONAME_LIBXXF86VM
|
2001-03-20 01:24:08 +00:00
|
|
|
return X11DRV_XF86VM_GetGammaRamp(ramp);
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2001-08-09 21:36:39 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* SetDeviceGammaRamp (X11DRV.@)
|
|
|
|
*
|
|
|
|
* FIXME: should move to somewhere appropriate, but probably not before
|
|
|
|
* the stuff in graphics/x11drv/ has been moved to dlls/x11drv, so that
|
2001-09-11 00:32:32 +00:00
|
|
|
* they can include xvidmode.h directly
|
2001-08-09 21:36:39 +00:00
|
|
|
*/
|
2011-07-13 12:56:12 +00:00
|
|
|
BOOL X11DRV_SetDeviceGammaRamp(PHYSDEV dev, LPVOID ramp)
|
2001-03-20 01:24:08 +00:00
|
|
|
{
|
2008-06-26 12:02:17 +00:00
|
|
|
#ifdef SONAME_LIBXXF86VM
|
2001-03-20 01:24:08 +00:00
|
|
|
return X11DRV_XF86VM_SetGammaRamp(ramp);
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|