From 02ff0a5d7e32ce8460d6d0669f532d65ad212fcd Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Sat, 17 Sep 2016 11:33:13 +0200 Subject: [PATCH] xf86RandR12: Fix XF86VidModeSetGamma triggering a BadImplementation error Commit b4e46c0444bb ("xfree86: Hook up colormaps and RandR 1.2 gamma code") dropped the providing of a pScrn->ChangeGamma callback from the xf86RandR12 code. Leaving pScrn->ChangeGamma NULL in most cases. This triggers the BadImplementation error in xf86ChangeGamma() : if (pScrn->ChangeGamma) return (*pScrn->ChangeGamma) (pScrn, gamma); return BadImplementation; Which causes X-apps using XF86VidModeSetGamma to crash with a X protocol error. This commit fixes this by re-introducing the xf86RandR12ChangeGamma helper removed by the commit and adjusting it to work with the new combined palette / gamma code. Fixes: b4e46c0444bb ("xfree86: Hook up colormaps and RandR 1.2 gamma code") Signed-off-by: Hans de Goede Reviewed-by: Alex Deucher --- hw/xfree86/modes/xf86RandR12.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c index b1ca8b41d..d83461997 100644 --- a/hw/xfree86/modes/xf86RandR12.c +++ b/hw/xfree86/modes/xf86RandR12.c @@ -1924,6 +1924,35 @@ xf86RandR12LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, } } +/* + * Compatibility pScrn->ChangeGamma provider for ddx drivers which do not call + * xf86HandleColormaps(). Note such drivers really should be fixed to call + * xf86HandleColormaps() as this clobbers the per-CRTC gamma ramp of the CRTC + * assigned to the RandR compatibility output. + */ +static int +xf86RandR12ChangeGamma(ScrnInfoPtr pScrn, Gamma gamma) +{ + RRCrtcPtr randr_crtc = xf86CompatRRCrtc(pScrn); + int size; + + if (!randr_crtc) + return Success; + + size = max(0, randr_crtc->gammaSize); + if (!size) + return Success; + + init_one_component(randr_crtc->gammaRed, size, gamma.red); + init_one_component(randr_crtc->gammaGreen, size, gamma.green); + init_one_component(randr_crtc->gammaBlue, size, gamma.blue); + xf86RandR12CrtcSetGamma(xf86ScrnToScreen(pScrn), randr_crtc); + + pScrn->gamma = gamma; + + return Success; +} + static Bool xf86RandR12EnterVT(ScrnInfoPtr pScrn) { @@ -2123,6 +2152,7 @@ xf86RandR12Init12(ScreenPtr pScreen) rp->rrProviderDestroy = xf86RandR14ProviderDestroy; pScrn->PointerMoved = xf86RandR12PointerMoved; + pScrn->ChangeGamma = xf86RandR12ChangeGamma; randrp->orig_EnterVT = pScrn->EnterVT; pScrn->EnterVT = xf86RandR12EnterVT;