commit d4439ab61149abe4a1093e5cb735d7eb473689ee Author: Michel Dänzer Date: Sat Nov 28 16:50:47 2015 +0900 Hook up colormaps to RandR 1.2 gamma code diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index c42e93e..b0b58a7 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -54,7 +54,6 @@ #include "xf86Xinput.h" #include "xf86InPriv.h" #include "mivalidate.h" -#include "xf86Crtc.h" /* For xf86GetClocks */ #if defined(CSRG_BASED) || defined(__GNU__) @@ -908,11 +907,7 @@ xf86SetGamma(ScrnInfoPtr scrp, Gamma gamma) scrp->gamma.green = 1.0; scrp->gamma.blue = 1.0; } - /* Pretend we succeeded if we support better a gamma system. - * This avoids a confusing message. - */ - if (xf86_crtc_supports_gamma(scrp)) - return TRUE; + xf86DrvMsg(scrp->scrnIndex, from, "Using gamma correction (%.1f, %.1f, %.1f)\n", scrp->gamma.red, scrp->gamma.green, scrp->gamma.blue); diff --git a/hw/xfree86/common/xf86cmap.c b/hw/xfree86/common/xf86cmap.c index ba0b277..16cd146 100644 --- a/hw/xfree86/common/xf86cmap.c +++ b/hw/xfree86/common/xf86cmap.c @@ -49,6 +49,7 @@ #include "xf86_OSproc.h" #include "xf86str.h" #include "micmap.h" +#include "xf86RandR12.h" #include "xf86Crtc.h" #ifdef XFreeXDGA @@ -132,9 +133,6 @@ static void CMapUnwrapScreen(ScreenPtr pScreen); Bool xf86ColormapAllocatePrivates(ScrnInfoPtr pScrn) { - /* If we support a better colormap system, then pretend we succeeded. */ - if (xf86_crtc_supports_gamma(pScrn)) - return TRUE; if (!dixRegisterPrivateKey(&CMapScreenKeyRec, PRIVATE_SCREEN, 0)) return FALSE; @@ -157,10 +155,6 @@ xf86HandleColormaps(ScreenPtr pScreen, int *indices; int elements; - /* If we support a better colormap system, then pretend we succeeded. */ - if (xf86_crtc_supports_gamma(pScrn)) - return TRUE; - if (!maxColors || !sigRGBbits || !loadPalette) return FALSE; @@ -193,7 +187,10 @@ xf86HandleColormaps(ScreenPtr pScreen, pScreen->InstallColormap = CMapInstallColormap; pScreen->StoreColors = CMapStoreColors; - pScrn->LoadPalette = loadPalette; + if (xf86_crtc_supports_gamma(pScrn)) + pScrn->LoadPalette = xf86Randr12LoadPalette; + else + pScrn->LoadPalette = loadPalette; pScrn->SetOverscan = setOverscan; pScreenPriv->maxColors = maxColors; pScreenPriv->sigRGBbits = sigRGBbits; @@ -1005,19 +1002,6 @@ xf86ChangeGammaRamp(ScreenPtr pScreen, CMapScreenPtr pScreenPriv; CMapLinkPtr pLink; - if (xf86_crtc_supports_gamma(pScrn)) { - RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn); - - if (crtc) { - if (crtc->gammaSize != size) - return BadValue; - - RRCrtcGammaSet(crtc, red, green, blue); - - return Success; - } - } - if (!CMapScreenKeyRegistered) return BadImplementation; @@ -1077,16 +1061,8 @@ xf86ChangeGammaRamp(ScreenPtr pScreen, int xf86GetGammaRampSize(ScreenPtr pScreen) { - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); CMapScreenPtr pScreenPriv; - if (xf86_crtc_supports_gamma(pScrn)) { - RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn); - - if (crtc) - return crtc->gammaSize; - } - if (!CMapScreenKeyRegistered) return 0; @@ -1104,29 +1080,10 @@ xf86GetGammaRamp(ScreenPtr pScreen, unsigned short *red, unsigned short *green, unsigned short *blue) { - ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen); CMapScreenPtr pScreenPriv; LOCO *entry; int shift, sigbits; - if (xf86_crtc_supports_gamma(pScrn)) { - RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn); - - if (crtc) { - if (crtc->gammaSize < size) - return BadValue; - - if (!RRCrtcGammaGet(crtc)) - return BadImplementation; - - memcpy(red, crtc->gammaRed, size * sizeof(*red)); - memcpy(green, crtc->gammaGreen, size * sizeof(*green)); - memcpy(blue, crtc->gammaBlue, size * sizeof(*blue)); - - return Success; - } - } - if (!CMapScreenKeyRegistered) return BadImplementation; diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c index 38bc58c..c2f58ff 100644 --- a/hw/xfree86/modes/xf86Crtc.c +++ b/hw/xfree86/modes/xf86Crtc.c @@ -2671,10 +2671,6 @@ xf86InitialConfiguration(ScrnInfoPtr scrn, Bool canGrow) xf86CrtcSetInitialGamma(crtc, 1.0, 1.0, 1.0); } - if (xf86_crtc_supports_gamma(scrn)) - xf86DrvMsg(scrn->scrnIndex, X_INFO, - "Using default gamma of (1.0, 1.0, 1.0) unless otherwise stated.\n"); - /* * Set initial configuration */ diff --git a/hw/xfree86/modes/xf86RandR12.c b/hw/xfree86/modes/xf86RandR12.c index eae7016..6916584 100644 --- a/hw/xfree86/modes/xf86RandR12.c +++ b/hw/xfree86/modes/xf86RandR12.c @@ -40,6 +40,7 @@ #include #include +#include "xf86cmap.h" #include "xf86Crtc.h" #include "xf86RandR12.h" @@ -1235,6 +1236,49 @@ xf86RandR12CrtcSet(ScreenPtr pScreen, return xf86RandR12CrtcNotify(randr_crtc); } +static void +xf86RandR12CrtcComputeGamma(ScreenPtr pScreen, RRCrtcPtr randr_crtc) +{ + xf86CrtcPtr crtc = randr_crtc->devPrivate; + int gamma_ramp_size = xf86GetGammaRampSize(pScreen); + int i, j; + + for (i = 0; i < randr_crtc->paletteSize; i++) { + j = i * crtc->gamma_size / randr_crtc->paletteSize; + crtc->gamma_red[j] = randr_crtc->gammaRed[randr_crtc->palette[i].red * + crtc->gamma_size / + gamma_ramp_size]; + crtc->gamma_green[j] = randr_crtc->gammaGreen[randr_crtc->palette[i].green * + crtc->gamma_size / + gamma_ramp_size]; + crtc->gamma_blue[j] = randr_crtc->gammaBlue[randr_crtc->palette[i].blue * + crtc->gamma_size / + gamma_ramp_size]; + + while (++j < (i + 1) * crtc->gamma_size / randr_crtc->paletteSize) { + crtc->gamma_red[j] = crtc->gamma_red[j - 1]; + crtc->gamma_green[j] = crtc->gamma_green[j - 1]; + crtc->gamma_blue[j] = crtc->gamma_blue[j - 1]; + } + } +} + +static void +xf86RandR12CrtcResetGamma(RRCrtcPtr randr_crtc) +{ + xf86CrtcPtr crtc = randr_crtc->devPrivate; + + if (!crtc->scrn->vtSema || !crtc->funcs->gamma_set) + return; + + /* Only set it when the crtc is actually running. + * Otherwise it will be set when it's activated. + */ + if (crtc->active) + crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green, + crtc->gamma_blue, crtc->gamma_size); +} + static Bool xf86RandR12CrtcSetGamma(ScreenPtr pScreen, RRCrtcPtr randr_crtc) { @@ -1243,9 +1287,6 @@ xf86RandR12CrtcSetGamma(ScreenPtr pScreen, RRCrtcPtr randr_crtc) if (crtc->funcs->gamma_set == NULL) return FALSE; - if (!crtc->scrn->vtSema) - return TRUE; - /* Realloc local gamma if needed. */ if (randr_crtc->gammaSize != crtc->gamma_size) { CARD16 *tmp_ptr; @@ -1257,22 +1298,11 @@ xf86RandR12CrtcSetGamma(ScreenPtr pScreen, RRCrtcPtr randr_crtc) crtc->gamma_red = tmp_ptr; crtc->gamma_green = crtc->gamma_red + randr_crtc->gammaSize; crtc->gamma_blue = crtc->gamma_green + randr_crtc->gammaSize; + crtc->gamma_size = randr_crtc->gammaSize; } - crtc->gamma_size = randr_crtc->gammaSize; - memcpy(crtc->gamma_red, randr_crtc->gammaRed, - crtc->gamma_size * sizeof(CARD16)); - memcpy(crtc->gamma_green, randr_crtc->gammaGreen, - crtc->gamma_size * sizeof(CARD16)); - memcpy(crtc->gamma_blue, randr_crtc->gammaBlue, - crtc->gamma_size * sizeof(CARD16)); - - /* Only set it when the crtc is actually running. - * Otherwise it will be set when it's activated. - */ - if (crtc->active) - crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green, - crtc->gamma_blue, crtc->gamma_size); + xf86RandR12CrtcComputeGamma(pScreen, randr_crtc); + xf86RandR12CrtcResetGamma(randr_crtc); return TRUE; } @@ -1757,6 +1787,40 @@ gamma_to_ramp(float gamma, CARD16 *ramp, int size) } } +void +xf86Randr12LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices, + LOCO *colors, VisualPtr pVisual) +{ + ScreenPtr pScreen = pScrn->pScreen; + xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn); + int reds, greens, blues, maxValue, index, shift; + int c, i; + + reds = pVisual->redMask >> pVisual->offsetRed; + greens = pVisual->greenMask >> pVisual->offsetGreen; + blues = pVisual->blueMask >> pVisual->offsetBlue; + + for (c = 0; c < config->num_crtc; c++) { + xf86CrtcPtr crtc = config->crtc[c]; + RRCrtcPtr randr_crtc = crtc->randr_crtc; + + if (randr_crtc->paletteSize != numColors) { + randr_crtc->palette = reallocarray(randr_crtc->palette, + numColors, sizeof(colors[0])); + randr_crtc->paletteSize = numColors; + } + + for (i = 0; i < numColors; i++) { + index = indices[i]; + + randr_crtc->palette[index] = colors[index]; + } + + xf86RandR12CrtcComputeGamma(pScreen, randr_crtc); + xf86RandR12CrtcResetGamma(randr_crtc); + } +} + static int xf86RandR12ChangeGamma(ScrnInfoPtr pScrn, Gamma gamma) { @@ -1811,7 +1875,7 @@ xf86RandR12EnterVT(ScrnInfoPtr pScrn) /* reload gamma */ for (i = 0; i < rp->numCrtcs; i++) - xf86RandR12CrtcSetGamma(pScreen, rp->crtcs[i]); + xf86RandR12CrtcResetGamma(rp->crtcs[i]); return RRGetInfo(pScreen, TRUE); /* force a re-probe of outputs and notify clients about changes */ } diff --git a/hw/xfree86/modes/xf86RandR12.h b/hw/xfree86/modes/xf86RandR12.h index e603799..037c313 100644 --- a/hw/xfree86/modes/xf86RandR12.h +++ b/hw/xfree86/modes/xf86RandR12.h @@ -39,5 +39,8 @@ extern _X_EXPORT void xf86RandR12GetOriginalVirtualSize(ScrnInfoPtr pScrn, int *x, int *y); extern _X_EXPORT Bool xf86RandR12PreInit(ScrnInfoPtr pScrn); extern _X_EXPORT void xf86RandR12TellChanged(ScreenPtr pScreen); +extern _X_EXPORT void xf86Randr12LoadPalette(ScrnInfoPtr pScrn, int numColors, + int *indices, LOCO *colors, + VisualPtr pVisual); #endif /* _XF86_RANDR_H_ */ diff --git a/randr/randrstr.h b/randr/randrstr.h index 472721a..bcb482f 100644 --- a/randr/randrstr.h +++ b/randr/randrstr.h @@ -37,6 +37,7 @@ #include #include "misc.h" #include "os.h" +#include "colormapst.h" #include "dixstruct.h" #include "resource.h" #include "scrnintstr.h" @@ -130,6 +131,9 @@ struct _rrCrtc { struct pict_f_transform f_inverse; PixmapPtr scanout_pixmap; + + int paletteSize; + LOCO *palette; }; struct _rrOutput {