2006-11-26 11:13:41 -07:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 1998-2001 by The XFree86 Project, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* Except as contained in this notice, the name of the copyright holder(s)
|
|
|
|
|
* and author(s) shall not be used in advertising or otherwise to promote
|
|
|
|
|
* the sale, use or other dealings in this Software without prior written
|
|
|
|
|
* authorization from the copyright holder(s) and author(s).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_XORG_CONFIG_H
|
|
|
|
|
#include <xorg-config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
|
#if defined(_XOPEN_SOURCE) || defined(sun) && defined(__SVR4)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#include <math.h>
|
|
|
|
|
#else
|
2012-06-10 07:21:05 -06:00
|
|
|
|
#define _XOPEN_SOURCE /* to get prototype for pow on some systems */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#include <math.h>
|
|
|
|
|
#undef _XOPEN_SOURCE
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
|
#include "misc.h"
|
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
|
#include "colormapst.h"
|
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
|
|
|
|
|
|
#include "resource.h"
|
|
|
|
|
|
|
|
|
|
#include "xf86.h"
|
|
|
|
|
#include "xf86_OSproc.h"
|
|
|
|
|
#include "xf86str.h"
|
|
|
|
|
#include "micmap.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
|
#include "xf86Crtc.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
#ifdef XFreeXDGA
|
2010-07-27 13:02:24 -06:00
|
|
|
|
#include <X11/extensions/xf86dgaproto.h>
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#include "dgaproc.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "xf86cmap.h"
|
|
|
|
|
|
|
|
|
|
#define SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = \
|
2008-11-02 08:26:08 -07:00
|
|
|
|
((CMapScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, CMapScreenKey))->field)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#define SCREEN_EPILOGUE(pScreen, field, wrapper)\
|
|
|
|
|
((pScreen)->field = wrapper)
|
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
|
#define LOAD_PALETTE(pmap) \
|
|
|
|
|
((pmap == GetInstalledmiColormap(pmap->pScreen)) && \
|
2006-11-26 11:13:41 -07:00
|
|
|
|
((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) || \
|
2013-06-07 11:28:45 -06:00
|
|
|
|
xf86ScreenToScrn(pmap->pScreen)->vtSema || pScreenPriv->isDGAmode))
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
typedef struct _CMapLink {
|
2012-06-10 07:21:05 -06:00
|
|
|
|
ColormapPtr cmap;
|
|
|
|
|
struct _CMapLink *next;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
} CMapLink, *CMapLinkPtr;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CloseScreenProcPtr CloseScreen;
|
|
|
|
|
CreateColormapProcPtr CreateColormap;
|
|
|
|
|
DestroyColormapProcPtr DestroyColormap;
|
|
|
|
|
InstallColormapProcPtr InstallColormap;
|
|
|
|
|
StoreColorsProcPtr StoreColors;
|
2013-06-07 11:28:45 -06:00
|
|
|
|
Bool (*EnterVT) (ScrnInfoPtr);
|
|
|
|
|
Bool (*SwitchMode) (ScrnInfoPtr, DisplayModePtr);
|
|
|
|
|
int (*SetDGAMode) (ScrnInfoPtr, int, DGADevicePtr);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
xf86ChangeGammaProc *ChangeGamma;
|
|
|
|
|
int maxColors;
|
|
|
|
|
int sigRGBbits;
|
|
|
|
|
int gammaElements;
|
|
|
|
|
LOCO *gamma;
|
|
|
|
|
int *PreAllocIndices;
|
|
|
|
|
CMapLinkPtr maps;
|
|
|
|
|
unsigned int flags;
|
|
|
|
|
Bool isDGAmode;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
} CMapScreenRec, *CMapScreenPtr;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2012-06-10 07:21:05 -06:00
|
|
|
|
int numColors;
|
|
|
|
|
LOCO *colors;
|
|
|
|
|
Bool recalculate;
|
|
|
|
|
int overscan;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
} CMapColormapRec, *CMapColormapPtr;
|
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
|
static DevPrivateKeyRec CMapScreenKeyRec;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
|
#define CMapScreenKeyRegistered dixPrivateKeyRegistered(&CMapScreenKeyRec)
|
|
|
|
|
#define CMapScreenKey (&CMapScreenKeyRec)
|
|
|
|
|
static DevPrivateKeyRec CMapColormapKeyRec;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
|
#define CMapColormapKey (&CMapColormapKeyRec)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
static void CMapInstallColormap(ColormapPtr);
|
|
|
|
|
static void CMapStoreColors(ColormapPtr, int, xColorItem *);
|
2013-06-07 11:28:45 -06:00
|
|
|
|
static Bool CMapCloseScreen(ScreenPtr);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
static Bool CMapCreateColormap(ColormapPtr);
|
|
|
|
|
static void CMapDestroyColormap(ColormapPtr);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
|
static Bool CMapEnterVT(ScrnInfoPtr);
|
|
|
|
|
static Bool CMapSwitchMode(ScrnInfoPtr, DisplayModePtr);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
|
#ifdef XFreeXDGA
|
2013-06-07 11:28:45 -06:00
|
|
|
|
static int CMapSetDGAMode(ScrnInfoPtr, int, DGADevicePtr);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
#endif
|
2013-06-07 11:28:45 -06:00
|
|
|
|
static int CMapChangeGamma(ScrnInfoPtr, Gamma);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
|
static void ComputeGamma(ScrnInfoPtr, CMapScreenPtr);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
static Bool CMapAllocateColormapPrivate(ColormapPtr);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
static void CMapRefreshColors(ColormapPtr, int, int *);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
static void CMapSetOverscan(ColormapPtr, int, int *);
|
|
|
|
|
static void CMapReinstallMap(ColormapPtr);
|
|
|
|
|
static void CMapUnwrapScreen(ScreenPtr pScreen);
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
Bool
|
|
|
|
|
xf86ColormapAllocatePrivates(ScrnInfoPtr pScrn)
|
2010-12-05 08:36:02 -07:00
|
|
|
|
{
|
|
|
|
|
/* If we support a better colormap system, then pretend we succeeded. */
|
|
|
|
|
if (xf86_crtc_supports_gamma(pScrn))
|
2012-06-10 07:21:05 -06:00
|
|
|
|
return TRUE;
|
2010-12-05 08:36:02 -07:00
|
|
|
|
if (!dixRegisterPrivateKey(&CMapScreenKeyRec, PRIVATE_SCREEN, 0))
|
2012-06-10 07:21:05 -06:00
|
|
|
|
return FALSE;
|
2010-12-05 08:36:02 -07:00
|
|
|
|
|
|
|
|
|
if (!dixRegisterPrivateKey(&CMapColormapKeyRec, PRIVATE_COLORMAP, 0))
|
2012-06-10 07:21:05 -06:00
|
|
|
|
return FALSE;
|
2010-12-05 08:36:02 -07:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
Bool
|
|
|
|
|
xf86HandleColormaps(ScreenPtr pScreen,
|
|
|
|
|
int maxColors,
|
|
|
|
|
int sigRGBbits,
|
|
|
|
|
xf86LoadPaletteProc * loadPalette,
|
|
|
|
|
xf86SetOverscanProc * setOverscan, unsigned int flags)
|
|
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
ColormapPtr pDefMap = NULL;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapScreenPtr pScreenPriv;
|
|
|
|
|
LOCO *gamma;
|
|
|
|
|
int *indices;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
int elements;
|
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
|
/* If we support a better colormap system, then pretend we succeeded. */
|
|
|
|
|
if (xf86_crtc_supports_gamma(pScrn))
|
2012-06-10 07:21:05 -06:00
|
|
|
|
return TRUE;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (!maxColors || !sigRGBbits || !loadPalette)
|
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
elements = 1 << sigRGBbits;
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (!(gamma = malloc(elements * sizeof(LOCO))))
|
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (!(indices = malloc(maxColors * sizeof(int)))) {
|
|
|
|
|
free(gamma);
|
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
|
|
if (!(pScreenPriv = malloc(sizeof(CMapScreenRec)))) {
|
|
|
|
|
free(gamma);
|
|
|
|
|
free(indices);
|
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
|
dixSetPrivate(&pScreen->devPrivates, &CMapScreenKeyRec, pScreenPriv);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
|
pScreenPriv->CloseScreen = pScreen->CloseScreen;
|
|
|
|
|
pScreenPriv->CreateColormap = pScreen->CreateColormap;
|
|
|
|
|
pScreenPriv->DestroyColormap = pScreen->DestroyColormap;
|
|
|
|
|
pScreenPriv->InstallColormap = pScreen->InstallColormap;
|
|
|
|
|
pScreenPriv->StoreColors = pScreen->StoreColors;
|
|
|
|
|
pScreen->CloseScreen = CMapCloseScreen;
|
|
|
|
|
pScreen->CreateColormap = CMapCreateColormap;
|
|
|
|
|
pScreen->DestroyColormap = CMapDestroyColormap;
|
|
|
|
|
pScreen->InstallColormap = CMapInstallColormap;
|
|
|
|
|
pScreen->StoreColors = CMapStoreColors;
|
|
|
|
|
|
|
|
|
|
pScrn->LoadPalette = loadPalette;
|
|
|
|
|
pScrn->SetOverscan = setOverscan;
|
|
|
|
|
pScreenPriv->maxColors = maxColors;
|
|
|
|
|
pScreenPriv->sigRGBbits = sigRGBbits;
|
|
|
|
|
pScreenPriv->gammaElements = elements;
|
|
|
|
|
pScreenPriv->gamma = gamma;
|
|
|
|
|
pScreenPriv->PreAllocIndices = indices;
|
|
|
|
|
pScreenPriv->maps = NULL;
|
|
|
|
|
pScreenPriv->flags = flags;
|
|
|
|
|
pScreenPriv->isDGAmode = FALSE;
|
|
|
|
|
|
|
|
|
|
pScreenPriv->EnterVT = pScrn->EnterVT;
|
|
|
|
|
pScreenPriv->SwitchMode = pScrn->SwitchMode;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
pScreenPriv->SetDGAMode = pScrn->SetDGAMode;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
pScreenPriv->ChangeGamma = pScrn->ChangeGamma;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
if (!(flags & CMAP_LOAD_EVEN_IF_OFFSCREEN)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
|
pScrn->EnterVT = CMapEnterVT;
|
|
|
|
|
if ((flags & CMAP_RELOAD_ON_MODE_SWITCH) && pScrn->SwitchMode)
|
|
|
|
|
pScrn->SwitchMode = CMapSwitchMode;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
#ifdef XFreeXDGA
|
|
|
|
|
pScrn->SetDGAMode = CMapSetDGAMode;
|
|
|
|
|
#endif
|
|
|
|
|
pScrn->ChangeGamma = CMapChangeGamma;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
|
ComputeGamma(pScrn, pScreenPriv);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
/* get the default map */
|
2014-09-27 11:52:59 -06:00
|
|
|
|
dixLookupResourceByType((void **) &pDefMap, pScreen->defColormap,
|
2012-06-10 07:21:05 -06:00
|
|
|
|
RT_COLORMAP, serverClient, DixInstallAccess);
|
|
|
|
|
|
|
|
|
|
if (!CMapAllocateColormapPrivate(pDefMap)) {
|
2006-11-26 11:13:41 -07:00
|
|
|
|
CMapUnwrapScreen(pScreen);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Force the initial map to be loaded */
|
2010-12-05 08:36:02 -07:00
|
|
|
|
SetInstalledmiColormap(pScreen, NULL);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
CMapInstallColormap(pDefMap);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**** Screen functions ****/
|
|
|
|
|
|
|
|
|
|
static Bool
|
2013-06-07 11:28:45 -06:00
|
|
|
|
CMapCloseScreen(ScreenPtr pScreen)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
{
|
|
|
|
|
CMapUnwrapScreen(pScreen);
|
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
|
return (*pScreen->CloseScreen) (pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
|
CMapColormapUseMax(VisualPtr pVisual, CMapScreenPtr pScreenPriv)
|
|
|
|
|
{
|
|
|
|
|
if (pVisual->nplanes > 16)
|
|
|
|
|
return TRUE;
|
|
|
|
|
return ((1 << pVisual->nplanes) > pScreenPriv->maxColors);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Bool
|
|
|
|
|
CMapAllocateColormapPrivate(ColormapPtr pmap)
|
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapScreenPtr pScreenPriv =
|
|
|
|
|
(CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates,
|
|
|
|
|
CMapScreenKey);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
CMapColormapPtr pColPriv;
|
|
|
|
|
CMapLinkPtr pLink;
|
|
|
|
|
int numColors;
|
|
|
|
|
LOCO *colors;
|
|
|
|
|
|
|
|
|
|
if (CMapColormapUseMax(pmap->pVisual, pScreenPriv))
|
2012-06-10 07:21:05 -06:00
|
|
|
|
numColors = pmap->pVisual->ColormapEntries;
|
|
|
|
|
else
|
|
|
|
|
numColors = 1 << pmap->pVisual->nplanes;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (!(colors = malloc(numColors * sizeof(LOCO))))
|
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (!(pColPriv = malloc(sizeof(CMapColormapRec)))) {
|
|
|
|
|
free(colors);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
|
dixSetPrivate(&pmap->devPrivates, CMapColormapKey, pColPriv);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
|
pColPriv->numColors = numColors;
|
|
|
|
|
pColPriv->colors = colors;
|
|
|
|
|
pColPriv->recalculate = TRUE;
|
|
|
|
|
pColPriv->overscan = -1;
|
|
|
|
|
|
|
|
|
|
/* add map to list */
|
2010-12-05 08:36:02 -07:00
|
|
|
|
pLink = malloc(sizeof(CMapLink));
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (pLink) {
|
|
|
|
|
pLink->cmap = pmap;
|
|
|
|
|
pLink->next = pScreenPriv->maps;
|
|
|
|
|
pScreenPriv->maps = pLink;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
static Bool
|
|
|
|
|
CMapCreateColormap(ColormapPtr pmap)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
{
|
|
|
|
|
ScreenPtr pScreen = pmap->pScreen;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapScreenPtr pScreenPriv =
|
|
|
|
|
(CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
Bool ret = FALSE;
|
|
|
|
|
|
|
|
|
|
pScreen->CreateColormap = pScreenPriv->CreateColormap;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if ((*pScreen->CreateColormap) (pmap)) {
|
|
|
|
|
if (CMapAllocateColormapPrivate(pmap))
|
|
|
|
|
ret = TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
pScreen->CreateColormap = CMapCreateColormap;
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapDestroyColormap(ColormapPtr cmap)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
{
|
|
|
|
|
ScreenPtr pScreen = cmap->pScreen;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapScreenPtr pScreenPriv =
|
|
|
|
|
(CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
|
|
|
|
|
CMapColormapPtr pColPriv =
|
|
|
|
|
(CMapColormapPtr) dixLookupPrivate(&cmap->devPrivates, CMapColormapKey);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
CMapLinkPtr prevLink = NULL, pLink = pScreenPriv->maps;
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (pColPriv) {
|
|
|
|
|
free(pColPriv->colors);
|
|
|
|
|
free(pColPriv);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
|
/* remove map from list */
|
2012-06-10 07:21:05 -06:00
|
|
|
|
while (pLink) {
|
|
|
|
|
if (pLink->cmap == cmap) {
|
|
|
|
|
if (prevLink)
|
|
|
|
|
prevLink->next = pLink->next;
|
|
|
|
|
else
|
|
|
|
|
pScreenPriv->maps = pLink->next;
|
|
|
|
|
free(pLink);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
prevLink = pLink;
|
|
|
|
|
pLink = pLink->next;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (pScreenPriv->DestroyColormap) {
|
|
|
|
|
pScreen->DestroyColormap = pScreenPriv->DestroyColormap;
|
|
|
|
|
(*pScreen->DestroyColormap) (cmap);
|
|
|
|
|
pScreen->DestroyColormap = CMapDestroyColormap;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapStoreColors(ColormapPtr pmap, int ndef, xColorItem * pdefs)
|
|
|
|
|
{
|
|
|
|
|
ScreenPtr pScreen = pmap->pScreen;
|
|
|
|
|
VisualPtr pVisual = pmap->pVisual;
|
|
|
|
|
CMapScreenPtr pScreenPriv =
|
|
|
|
|
(CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
|
|
|
|
|
int *indices = pScreenPriv->PreAllocIndices;
|
|
|
|
|
int num = ndef;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
/* At the moment this isn't necessary since there's nobody below us */
|
|
|
|
|
pScreen->StoreColors = pScreenPriv->StoreColors;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
(*pScreen->StoreColors) (pmap, ndef, pdefs);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
pScreen->StoreColors = CMapStoreColors;
|
|
|
|
|
|
|
|
|
|
/* should never get here for these */
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if ((pVisual->class == TrueColor) ||
|
|
|
|
|
(pVisual->class == StaticColor) || (pVisual->class == StaticGray))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (pVisual->class == DirectColor) {
|
|
|
|
|
CMapColormapPtr pColPriv =
|
|
|
|
|
(CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates,
|
|
|
|
|
CMapColormapKey);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (CMapColormapUseMax(pVisual, pScreenPriv)) {
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
|
|
num = 0;
|
|
|
|
|
while (ndef--) {
|
|
|
|
|
if (pdefs[ndef].flags & DoRed) {
|
|
|
|
|
index = (pdefs[ndef].pixel & pVisual->redMask) >>
|
|
|
|
|
pVisual->offsetRed;
|
|
|
|
|
i = num;
|
|
|
|
|
while (i--)
|
|
|
|
|
if (indices[i] == index)
|
|
|
|
|
break;
|
|
|
|
|
if (i == -1)
|
|
|
|
|
indices[num++] = index;
|
|
|
|
|
}
|
|
|
|
|
if (pdefs[ndef].flags & DoGreen) {
|
|
|
|
|
index = (pdefs[ndef].pixel & pVisual->greenMask) >>
|
|
|
|
|
pVisual->offsetGreen;
|
|
|
|
|
i = num;
|
|
|
|
|
while (i--)
|
|
|
|
|
if (indices[i] == index)
|
|
|
|
|
break;
|
|
|
|
|
if (i == -1)
|
|
|
|
|
indices[num++] = index;
|
|
|
|
|
}
|
|
|
|
|
if (pdefs[ndef].flags & DoBlue) {
|
|
|
|
|
index = (pdefs[ndef].pixel & pVisual->blueMask) >>
|
|
|
|
|
pVisual->offsetBlue;
|
|
|
|
|
i = num;
|
|
|
|
|
while (i--)
|
|
|
|
|
if (indices[i] == index)
|
|
|
|
|
break;
|
|
|
|
|
if (i == -1)
|
|
|
|
|
indices[num++] = index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* not really as overkill as it seems */
|
|
|
|
|
num = pColPriv->numColors;
|
|
|
|
|
for (i = 0; i < pColPriv->numColors; i++)
|
|
|
|
|
indices[i] = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
while (ndef--)
|
|
|
|
|
indices[ndef] = pdefs[ndef].pixel;
|
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
CMapRefreshColors(pmap, num, indices);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
CMapInstallColormap(ColormapPtr pmap)
|
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
|
ScreenPtr pScreen = pmap->pScreen;
|
|
|
|
|
CMapScreenPtr pScreenPriv =
|
|
|
|
|
(CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
|
if (pmap == GetInstalledmiColormap(pmap->pScreen))
|
2012-06-10 07:21:05 -06:00
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
pScreen->InstallColormap = pScreenPriv->InstallColormap;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
(*pScreen->InstallColormap) (pmap);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
pScreen->InstallColormap = CMapInstallColormap;
|
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
|
/* Important. We let the lower layers, namely DGA,
|
2006-11-26 11:13:41 -07:00
|
|
|
|
overwrite the choice of Colormap to install */
|
2010-12-05 08:36:02 -07:00
|
|
|
|
if (GetInstalledmiColormap(pmap->pScreen))
|
2012-06-10 07:21:05 -06:00
|
|
|
|
pmap = GetInstalledmiColormap(pmap->pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
|
2012-06-10 07:21:05 -06:00
|
|
|
|
(pmap->pVisual->class == TrueColor) &&
|
|
|
|
|
CMapColormapUseMax(pmap->pVisual, pScreenPriv))
|
|
|
|
|
return;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (LOAD_PALETTE(pmap))
|
|
|
|
|
CMapReinstallMap(pmap);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**** ScrnInfoRec functions ****/
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
static Bool
|
2013-06-07 11:28:45 -06:00
|
|
|
|
CMapEnterVT(ScrnInfoPtr pScrn)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
|
2010-12-05 08:36:02 -07:00
|
|
|
|
Bool ret;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapScreenPtr pScreenPriv =
|
|
|
|
|
(CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
|
pScrn->EnterVT = pScreenPriv->EnterVT;
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ret = (*pScreenPriv->EnterVT) (pScrn);
|
2010-12-05 08:36:02 -07:00
|
|
|
|
pScreenPriv->EnterVT = pScrn->EnterVT;
|
|
|
|
|
pScrn->EnterVT = CMapEnterVT;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (ret) {
|
|
|
|
|
if (GetInstalledmiColormap(pScreen))
|
|
|
|
|
CMapReinstallMap(GetInstalledmiColormap(pScreen));
|
|
|
|
|
return TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
static Bool
|
2013-06-07 11:28:45 -06:00
|
|
|
|
CMapSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapScreenPtr pScreenPriv =
|
|
|
|
|
(CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
|
if ((*pScreenPriv->SwitchMode) (pScrn, mode)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (GetInstalledmiColormap(pScreen))
|
|
|
|
|
CMapReinstallMap(GetInstalledmiColormap(pScreen));
|
|
|
|
|
return TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef XFreeXDGA
|
2012-06-10 07:21:05 -06:00
|
|
|
|
static int
|
2013-06-07 11:28:45 -06:00
|
|
|
|
CMapSetDGAMode(ScrnInfoPtr pScrn, int num, DGADevicePtr dev)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapScreenPtr pScreenPriv =
|
|
|
|
|
(CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
int ret;
|
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ret = (*pScreenPriv->SetDGAMode) (pScrn, num, dev);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
|
pScreenPriv->isDGAmode = DGAActive(pScrn->scrnIndex);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (!pScreenPriv->isDGAmode && GetInstalledmiColormap(pScreen)
|
2013-06-07 11:28:45 -06:00
|
|
|
|
&& xf86ScreenToScrn(pScreen)->vtSema)
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapReinstallMap(GetInstalledmiColormap(pScreen));
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/**** Utilities ****/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
CMapReinstallMap(ColormapPtr pmap)
|
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapScreenPtr pScreenPriv =
|
|
|
|
|
(CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates,
|
|
|
|
|
CMapScreenKey);
|
|
|
|
|
CMapColormapPtr cmapPriv =
|
|
|
|
|
(CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, CMapColormapKey);
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScrnInfoPtr pScrn = xf86ScreenToScrn(pmap->pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
int i = cmapPriv->numColors;
|
|
|
|
|
int *indices = pScreenPriv->PreAllocIndices;
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
while (i--)
|
|
|
|
|
indices[i] = i;
|
|
|
|
|
|
|
|
|
|
if (cmapPriv->recalculate)
|
|
|
|
|
CMapRefreshColors(pmap, cmapPriv->numColors, indices);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
else {
|
2012-06-10 07:21:05 -06:00
|
|
|
|
(*pScrn->LoadPalette) (pScrn, cmapPriv->numColors,
|
|
|
|
|
indices, cmapPriv->colors, pmap->pVisual);
|
|
|
|
|
if (pScrn->SetOverscan) {
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#ifdef DEBUGOVERSCAN
|
2012-06-10 07:21:05 -06:00
|
|
|
|
ErrorF("SetOverscan() called from CMapReinstallMap\n");
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
|
pScrn->SetOverscan(pScrn, cmapPriv->overscan);
|
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmapPriv->recalculate = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
static void
|
|
|
|
|
CMapRefreshColors(ColormapPtr pmap, int defs, int *indices)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapScreenPtr pScreenPriv =
|
|
|
|
|
(CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates,
|
|
|
|
|
CMapScreenKey);
|
|
|
|
|
CMapColormapPtr pColPriv =
|
|
|
|
|
(CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, CMapColormapKey);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
VisualPtr pVisual = pmap->pVisual;
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScrnInfoPtr pScrn = xf86ScreenToScrn(pmap->pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
int numColors, i;
|
|
|
|
|
LOCO *gamma, *colors;
|
|
|
|
|
EntryPtr entry;
|
|
|
|
|
int reds, greens, blues, maxValue, index, shift;
|
|
|
|
|
|
|
|
|
|
numColors = pColPriv->numColors;
|
|
|
|
|
shift = 16 - pScreenPriv->sigRGBbits;
|
|
|
|
|
maxValue = (1 << pScreenPriv->sigRGBbits) - 1;
|
|
|
|
|
gamma = pScreenPriv->gamma;
|
|
|
|
|
colors = pColPriv->colors;
|
|
|
|
|
|
|
|
|
|
reds = pVisual->redMask >> pVisual->offsetRed;
|
|
|
|
|
greens = pVisual->greenMask >> pVisual->offsetGreen;
|
|
|
|
|
blues = pVisual->blueMask >> pVisual->offsetBlue;
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
switch (pVisual->class) {
|
2006-11-26 11:13:41 -07:00
|
|
|
|
case StaticGray:
|
2012-06-10 07:21:05 -06:00
|
|
|
|
for (i = 0; i < numColors; i++) {
|
|
|
|
|
index = (i + 1) * maxValue / numColors;
|
|
|
|
|
colors[i].red = gamma[index].red;
|
|
|
|
|
colors[i].green = gamma[index].green;
|
|
|
|
|
colors[i].blue = gamma[index].blue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
case TrueColor:
|
|
|
|
|
if (CMapColormapUseMax(pVisual, pScreenPriv)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
|
for (i = 0; i <= reds; i++)
|
|
|
|
|
colors[i].red = gamma[i * maxValue / reds].red;
|
|
|
|
|
for (i = 0; i <= greens; i++)
|
|
|
|
|
colors[i].green = gamma[i * maxValue / greens].green;
|
|
|
|
|
for (i = 0; i <= blues; i++)
|
|
|
|
|
colors[i].blue = gamma[i * maxValue / blues].blue;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < numColors; i++) {
|
|
|
|
|
colors[i].red = gamma[((i >> pVisual->offsetRed) & reds) *
|
|
|
|
|
maxValue / reds].red;
|
|
|
|
|
colors[i].green = gamma[((i >> pVisual->offsetGreen) & greens) *
|
|
|
|
|
maxValue / greens].green;
|
|
|
|
|
colors[i].blue = gamma[((i >> pVisual->offsetBlue) & blues) *
|
|
|
|
|
maxValue / blues].blue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
case StaticColor:
|
|
|
|
|
case PseudoColor:
|
|
|
|
|
case GrayScale:
|
2012-06-10 07:21:05 -06:00
|
|
|
|
for (i = 0; i < defs; i++) {
|
|
|
|
|
index = indices[i];
|
2013-06-07 11:28:45 -06:00
|
|
|
|
entry = (EntryPtr) &pmap->red[index];
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
|
|
if (entry->fShared) {
|
|
|
|
|
colors[index].red =
|
|
|
|
|
gamma[entry->co.shco.red->color >> shift].red;
|
|
|
|
|
colors[index].green =
|
|
|
|
|
gamma[entry->co.shco.green->color >> shift].green;
|
|
|
|
|
colors[index].blue =
|
|
|
|
|
gamma[entry->co.shco.blue->color >> shift].blue;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
colors[index].red = gamma[entry->co.local.red >> shift].red;
|
|
|
|
|
colors[index].green =
|
|
|
|
|
gamma[entry->co.local.green >> shift].green;
|
|
|
|
|
colors[index].blue = gamma[entry->co.local.blue >> shift].blue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
case DirectColor:
|
|
|
|
|
if (CMapColormapUseMax(pVisual, pScreenPriv)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
|
for (i = 0; i < defs; i++) {
|
|
|
|
|
index = indices[i];
|
|
|
|
|
if (index <= reds)
|
|
|
|
|
colors[index].red =
|
|
|
|
|
gamma[pmap->red[index].co.local.red >> shift].red;
|
|
|
|
|
if (index <= greens)
|
|
|
|
|
colors[index].green =
|
|
|
|
|
gamma[pmap->green[index].co.local.green >> shift].green;
|
|
|
|
|
if (index <= blues)
|
|
|
|
|
colors[index].blue =
|
|
|
|
|
gamma[pmap->blue[index].co.local.blue >> shift].blue;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < defs; i++) {
|
|
|
|
|
index = indices[i];
|
|
|
|
|
|
|
|
|
|
colors[index].red = gamma[pmap->red[(index >> pVisual->
|
|
|
|
|
offsetRed) & reds].co.local.
|
|
|
|
|
red >> shift].red;
|
|
|
|
|
colors[index].green =
|
|
|
|
|
gamma[pmap->green[(index >> pVisual->offsetGreen) & greens].co.
|
|
|
|
|
local.green >> shift].green;
|
|
|
|
|
colors[index].blue =
|
|
|
|
|
gamma[pmap->blue[(index >> pVisual->offsetBlue) & blues].co.
|
|
|
|
|
local.blue >> shift].blue;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (LOAD_PALETTE(pmap))
|
2015-09-16 13:10:19 -06:00
|
|
|
|
(*pScrn->LoadPalette) (pScrn, defs, indices, colors, pmap->pVisual);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
if (pScrn->SetOverscan)
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapSetOverscan(pmap, defs, indices);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapCompareColors(LOCO * color1, LOCO * color2)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
{
|
|
|
|
|
/* return TRUE if the color1 is "closer" to black than color2 */
|
|
|
|
|
#ifdef DEBUGOVERSCAN
|
|
|
|
|
ErrorF("#%02x%02x%02x vs #%02x%02x%02x (%d vs %d)\n",
|
2012-06-10 07:21:05 -06:00
|
|
|
|
color1->red, color1->green, color1->blue,
|
|
|
|
|
color2->red, color2->green, color2->blue,
|
|
|
|
|
color1->red + color1->green + color1->blue,
|
|
|
|
|
color2->red + color2->green + color2->blue);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#endif
|
|
|
|
|
return (color1->red + color1->green + color1->blue <
|
2012-06-10 07:21:05 -06:00
|
|
|
|
color2->red + color2->green + color2->blue);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
CMapSetOverscan(ColormapPtr pmap, int defs, int *indices)
|
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapScreenPtr pScreenPriv =
|
|
|
|
|
(CMapScreenPtr) dixLookupPrivate(&pmap->pScreen->devPrivates,
|
|
|
|
|
CMapScreenKey);
|
|
|
|
|
CMapColormapPtr pColPriv =
|
|
|
|
|
(CMapColormapPtr) dixLookupPrivate(&pmap->devPrivates, CMapColormapKey);
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScrnInfoPtr pScrn = xf86ScreenToScrn(pmap->pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
VisualPtr pVisual = pmap->pVisual;
|
|
|
|
|
int i;
|
|
|
|
|
LOCO *colors;
|
|
|
|
|
int index;
|
|
|
|
|
Bool newOverscan = FALSE;
|
|
|
|
|
int overscan, tmpOverscan;
|
|
|
|
|
|
|
|
|
|
colors = pColPriv->colors;
|
|
|
|
|
overscan = pColPriv->overscan;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Search for a new overscan index in the following cases:
|
|
|
|
|
*
|
|
|
|
|
* - The index hasn't yet been initialised. In this case search
|
|
|
|
|
* for an index that is black or a close match to black.
|
|
|
|
|
*
|
|
|
|
|
* - The colour of the old index is changed. In this case search
|
|
|
|
|
* all indices for a black or close match to black.
|
|
|
|
|
*
|
|
|
|
|
* - The colour of the old index wasn't black. In this case only
|
|
|
|
|
* search the indices that were changed for a better match to black.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
switch (pVisual->class) {
|
|
|
|
|
case StaticGray:
|
|
|
|
|
case TrueColor:
|
2012-06-10 07:21:05 -06:00
|
|
|
|
/* Should only come here once. Initialise the overscan index to 0 */
|
|
|
|
|
overscan = 0;
|
|
|
|
|
newOverscan = TRUE;
|
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
case StaticColor:
|
2012-06-10 07:21:05 -06:00
|
|
|
|
/*
|
2006-11-26 11:13:41 -07:00
|
|
|
|
* Only come here once, but search for the overscan in the same way
|
|
|
|
|
* as for the other cases.
|
2012-06-10 07:21:05 -06:00
|
|
|
|
*/
|
2006-11-26 11:13:41 -07:00
|
|
|
|
case DirectColor:
|
|
|
|
|
case PseudoColor:
|
|
|
|
|
case GrayScale:
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (overscan < 0 || overscan > pScreenPriv->maxColors - 1) {
|
|
|
|
|
/* Uninitialised */
|
|
|
|
|
newOverscan = TRUE;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Check if the overscan was changed */
|
|
|
|
|
for (i = 0; i < defs; i++) {
|
|
|
|
|
index = indices[i];
|
|
|
|
|
if (index == overscan) {
|
|
|
|
|
newOverscan = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (newOverscan) {
|
|
|
|
|
/* The overscan is either uninitialised or it has been changed */
|
|
|
|
|
|
|
|
|
|
if (overscan < 0 || overscan > pScreenPriv->maxColors - 1)
|
|
|
|
|
tmpOverscan = pScreenPriv->maxColors - 1;
|
|
|
|
|
else
|
|
|
|
|
tmpOverscan = overscan;
|
|
|
|
|
|
|
|
|
|
/* search all entries for a close match to black */
|
|
|
|
|
for (i = pScreenPriv->maxColors - 1; i >= 0; i--) {
|
|
|
|
|
if (colors[i].red == 0 && colors[i].green == 0 &&
|
|
|
|
|
colors[i].blue == 0) {
|
|
|
|
|
overscan = i;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#ifdef DEBUGOVERSCAN
|
2012-06-10 07:21:05 -06:00
|
|
|
|
ErrorF("Black found at index 0x%02x\n", i);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#ifdef DEBUGOVERSCAN
|
2012-06-10 07:21:05 -06:00
|
|
|
|
ErrorF("0x%02x: ", i);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (CMapCompareColors(&colors[i], &colors[tmpOverscan])) {
|
|
|
|
|
tmpOverscan = i;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#ifdef DEBUGOVERSCAN
|
2012-06-10 07:21:05 -06:00
|
|
|
|
ErrorF("possible \"Black\" at index 0x%02x\n", i);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (i < 0)
|
|
|
|
|
overscan = tmpOverscan;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Check of the old overscan wasn't black */
|
|
|
|
|
if (colors[overscan].red != 0 || colors[overscan].green != 0 ||
|
|
|
|
|
colors[overscan].blue != 0) {
|
|
|
|
|
int oldOverscan = tmpOverscan = overscan;
|
|
|
|
|
|
|
|
|
|
/* See of there is now a better match */
|
|
|
|
|
for (i = 0; i < defs; i++) {
|
|
|
|
|
index = indices[i];
|
|
|
|
|
if (colors[index].red == 0 && colors[index].green == 0 &&
|
|
|
|
|
colors[index].blue == 0) {
|
|
|
|
|
overscan = index;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#ifdef DEBUGOVERSCAN
|
2012-06-10 07:21:05 -06:00
|
|
|
|
ErrorF("Black found at index 0x%02x\n", index);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#ifdef DEBUGOVERSCAN
|
2012-06-10 07:21:05 -06:00
|
|
|
|
ErrorF("0x%02x: ", index);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (CMapCompareColors(&colors[index],
|
|
|
|
|
&colors[tmpOverscan])) {
|
|
|
|
|
tmpOverscan = index;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#ifdef DEBUGOVERSCAN
|
2012-06-10 07:21:05 -06:00
|
|
|
|
ErrorF("possible \"Black\" at index 0x%02x\n",
|
|
|
|
|
index);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (i == defs)
|
|
|
|
|
overscan = tmpOverscan;
|
|
|
|
|
if (overscan != oldOverscan)
|
|
|
|
|
newOverscan = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
if (newOverscan) {
|
2012-06-10 07:21:05 -06:00
|
|
|
|
pColPriv->overscan = overscan;
|
|
|
|
|
if (LOAD_PALETTE(pmap)) {
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#ifdef DEBUGOVERSCAN
|
2012-06-10 07:21:05 -06:00
|
|
|
|
ErrorF("SetOverscan() called from CmapSetOverscan\n");
|
2006-11-26 11:13:41 -07:00
|
|
|
|
#endif
|
2015-09-16 13:10:19 -06:00
|
|
|
|
pScrn->SetOverscan(pScrn, overscan);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
CMapUnwrapScreen(ScreenPtr pScreen)
|
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapScreenPtr pScreenPriv =
|
|
|
|
|
(CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates, CMapScreenKey);
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
pScreen->CloseScreen = pScreenPriv->CloseScreen;
|
|
|
|
|
pScreen->CreateColormap = pScreenPriv->CreateColormap;
|
|
|
|
|
pScreen->DestroyColormap = pScreenPriv->DestroyColormap;
|
|
|
|
|
pScreen->InstallColormap = pScreenPriv->InstallColormap;
|
|
|
|
|
pScreen->StoreColors = pScreenPriv->StoreColors;
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
pScrn->EnterVT = pScreenPriv->EnterVT;
|
|
|
|
|
pScrn->SwitchMode = pScreenPriv->SwitchMode;
|
|
|
|
|
pScrn->SetDGAMode = pScreenPriv->SetDGAMode;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
pScrn->ChangeGamma = pScreenPriv->ChangeGamma;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
|
free(pScreenPriv->gamma);
|
|
|
|
|
free(pScreenPriv->PreAllocIndices);
|
|
|
|
|
free(pScreenPriv);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
static void
|
2015-09-16 13:10:19 -06:00
|
|
|
|
ComputeGamma(ScrnInfoPtr pScrn, CMapScreenPtr priv)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
{
|
|
|
|
|
int elements = priv->gammaElements - 1;
|
|
|
|
|
double RedGamma, GreenGamma, BlueGamma;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
#ifndef DONT_CHECK_GAMMA
|
|
|
|
|
/* This check is to catch drivers that are not initialising pScrn->gamma */
|
2015-09-16 13:10:19 -06:00
|
|
|
|
if (pScrn->gamma.red < GAMMA_MIN || pScrn->gamma.red > GAMMA_MAX ||
|
|
|
|
|
pScrn->gamma.green < GAMMA_MIN || pScrn->gamma.green > GAMMA_MAX ||
|
|
|
|
|
pScrn->gamma.blue < GAMMA_MIN || pScrn->gamma.blue > GAMMA_MAX) {
|
|
|
|
|
|
|
|
|
|
xf86DrvMsgVerb(pScrn->scrnIndex, X_WARNING, 0,
|
2012-06-10 07:21:05 -06:00
|
|
|
|
"The %s driver didn't call xf86SetGamma() to initialise\n"
|
2015-09-16 13:10:19 -06:00
|
|
|
|
"\tthe gamma values.\n", pScrn->driverName);
|
|
|
|
|
xf86DrvMsgVerb(pScrn->scrnIndex, X_WARNING, 0,
|
2012-06-10 07:21:05 -06:00
|
|
|
|
"PLEASE FIX THE `%s' DRIVER!\n",
|
2015-09-16 13:10:19 -06:00
|
|
|
|
pScrn->driverName);
|
|
|
|
|
pScrn->gamma.red = 1.0;
|
|
|
|
|
pScrn->gamma.green = 1.0;
|
|
|
|
|
pScrn->gamma.blue = 1.0;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
|
RedGamma = 1.0 / (double) pScrn->gamma.red;
|
|
|
|
|
GreenGamma = 1.0 / (double) pScrn->gamma.green;
|
|
|
|
|
BlueGamma = 1.0 / (double) pScrn->gamma.blue;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
|
|
for (i = 0; i <= elements; i++) {
|
|
|
|
|
if (RedGamma == 1.0)
|
|
|
|
|
priv->gamma[i].red = i;
|
|
|
|
|
else
|
|
|
|
|
priv->gamma[i].red = (CARD16) (pow((double) i / (double) elements,
|
|
|
|
|
RedGamma) * (double) elements +
|
|
|
|
|
0.5);
|
|
|
|
|
|
|
|
|
|
if (GreenGamma == 1.0)
|
|
|
|
|
priv->gamma[i].green = i;
|
|
|
|
|
else
|
|
|
|
|
priv->gamma[i].green = (CARD16) (pow((double) i / (double) elements,
|
|
|
|
|
GreenGamma) *
|
|
|
|
|
(double) elements + 0.5);
|
|
|
|
|
|
|
|
|
|
if (BlueGamma == 1.0)
|
|
|
|
|
priv->gamma[i].blue = i;
|
|
|
|
|
else
|
|
|
|
|
priv->gamma[i].blue = (CARD16) (pow((double) i / (double) elements,
|
|
|
|
|
BlueGamma) * (double) elements +
|
|
|
|
|
0.5);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2013-06-07 11:28:45 -06:00
|
|
|
|
CMapChangeGamma(ScrnInfoPtr pScrn, Gamma gamma)
|
2012-06-10 07:21:05 -06:00
|
|
|
|
{
|
2010-07-27 13:02:24 -06:00
|
|
|
|
int ret = Success;
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
CMapColormapPtr pColPriv;
|
|
|
|
|
CMapScreenPtr pScreenPriv;
|
|
|
|
|
CMapLinkPtr pLink;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
|
/* Is this sufficient checking ? */
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (!CMapScreenKeyRegistered)
|
|
|
|
|
return BadImplementation;
|
|
|
|
|
|
|
|
|
|
pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
|
|
|
|
|
CMapScreenKey);
|
|
|
|
|
if (!pScreenPriv)
|
|
|
|
|
return BadImplementation;
|
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
|
if (gamma.red < GAMMA_MIN || gamma.red > GAMMA_MAX ||
|
2012-06-10 07:21:05 -06:00
|
|
|
|
gamma.green < GAMMA_MIN || gamma.green > GAMMA_MAX ||
|
|
|
|
|
gamma.blue < GAMMA_MIN || gamma.blue > GAMMA_MAX)
|
|
|
|
|
return BadValue;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
pScrn->gamma.red = gamma.red;
|
|
|
|
|
pScrn->gamma.green = gamma.green;
|
|
|
|
|
pScrn->gamma.blue = gamma.blue;
|
|
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
|
ComputeGamma(pScrn, pScreenPriv);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
/* mark all colormaps on this screen */
|
|
|
|
|
pLink = pScreenPriv->maps;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
while (pLink) {
|
|
|
|
|
pColPriv = (CMapColormapPtr) dixLookupPrivate(&pLink->cmap->devPrivates,
|
|
|
|
|
CMapColormapKey);
|
|
|
|
|
pColPriv->recalculate = TRUE;
|
|
|
|
|
pLink = pLink->next;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (GetInstalledmiColormap(pScreen) &&
|
|
|
|
|
((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) ||
|
|
|
|
|
pScrn->vtSema || pScreenPriv->isDGAmode)) {
|
|
|
|
|
ColormapPtr pMap = GetInstalledmiColormap(pScreen);
|
|
|
|
|
|
|
|
|
|
if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
|
|
|
|
|
(pMap->pVisual->class == TrueColor) &&
|
|
|
|
|
CMapColormapUseMax(pMap->pVisual, pScreenPriv)) {
|
|
|
|
|
|
|
|
|
|
/* if the current map doesn't have a palette look
|
|
|
|
|
for another map to change the gamma on. */
|
|
|
|
|
|
|
|
|
|
pLink = pScreenPriv->maps;
|
|
|
|
|
while (pLink) {
|
|
|
|
|
if (pLink->cmap->pVisual->class == PseudoColor)
|
|
|
|
|
break;
|
|
|
|
|
pLink = pLink->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pLink) {
|
2015-09-16 13:10:19 -06:00
|
|
|
|
/* need to trick CMapRefreshColors() into thinking
|
2012-06-10 07:21:05 -06:00
|
|
|
|
this is the currently installed map */
|
|
|
|
|
SetInstalledmiColormap(pScreen, pLink->cmap);
|
|
|
|
|
CMapReinstallMap(pLink->cmap);
|
|
|
|
|
SetInstalledmiColormap(pScreen, pMap);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
CMapReinstallMap(pMap);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
|
pScrn->ChangeGamma = pScreenPriv->ChangeGamma;
|
|
|
|
|
if (pScrn->ChangeGamma)
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ret = pScrn->ChangeGamma(pScrn, gamma);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
pScrn->ChangeGamma = CMapChangeGamma;
|
|
|
|
|
|
|
|
|
|
return ret;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
|
ComputeGammaRamp(CMapScreenPtr priv,
|
|
|
|
|
unsigned short *red,
|
|
|
|
|
unsigned short *green, unsigned short *blue)
|
|
|
|
|
{
|
2006-11-26 11:13:41 -07:00
|
|
|
|
int elements = priv->gammaElements;
|
|
|
|
|
LOCO *entry = priv->gamma;
|
|
|
|
|
int shift = 16 - priv->sigRGBbits;
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
while (elements--) {
|
|
|
|
|
entry->red = *(red++) >> shift;
|
|
|
|
|
entry->green = *(green++) >> shift;
|
|
|
|
|
entry->blue = *(blue++) >> shift;
|
|
|
|
|
entry++;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
|
xf86ChangeGammaRamp(ScreenPtr pScreen,
|
|
|
|
|
int size,
|
|
|
|
|
unsigned short *red,
|
|
|
|
|
unsigned short *green, unsigned short *blue)
|
|
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
CMapColormapPtr pColPriv;
|
|
|
|
|
CMapScreenPtr pScreenPriv;
|
|
|
|
|
CMapLinkPtr pLink;
|
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
|
if (xf86_crtc_supports_gamma(pScrn)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
|
RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (crtc) {
|
|
|
|
|
if (crtc->gammaSize != size)
|
|
|
|
|
return BadValue;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
RRCrtcGammaSet(crtc, red, green, blue);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
return Success;
|
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (!CMapScreenKeyRegistered)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
return BadImplementation;
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
|
|
|
|
|
CMapScreenKey);
|
|
|
|
|
if (!pScreenPriv)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
return BadImplementation;
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (pScreenPriv->gammaElements != size)
|
|
|
|
|
return BadValue;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
ComputeGammaRamp(pScreenPriv, red, green, blue);
|
|
|
|
|
|
|
|
|
|
/* mark all colormaps on this screen */
|
|
|
|
|
pLink = pScreenPriv->maps;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
while (pLink) {
|
|
|
|
|
pColPriv = (CMapColormapPtr) dixLookupPrivate(&pLink->cmap->devPrivates,
|
|
|
|
|
CMapColormapKey);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
pColPriv->recalculate = TRUE;
|
|
|
|
|
pLink = pLink->next;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (GetInstalledmiColormap(pScreen) &&
|
|
|
|
|
((pScreenPriv->flags & CMAP_LOAD_EVEN_IF_OFFSCREEN) ||
|
|
|
|
|
pScrn->vtSema || pScreenPriv->isDGAmode)) {
|
2010-12-05 08:36:02 -07:00
|
|
|
|
ColormapPtr pMap = GetInstalledmiColormap(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
if (!(pScreenPriv->flags & CMAP_PALETTED_TRUECOLOR) &&
|
|
|
|
|
(pMap->pVisual->class == TrueColor) &&
|
2012-06-10 07:21:05 -06:00
|
|
|
|
CMapColormapUseMax(pMap->pVisual, pScreenPriv)) {
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
/* if the current map doesn't have a palette look
|
2012-06-10 07:21:05 -06:00
|
|
|
|
for another map to change the gamma on. */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
pLink = pScreenPriv->maps;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
while (pLink) {
|
|
|
|
|
if (pLink->cmap->pVisual->class == PseudoColor)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
break;
|
|
|
|
|
pLink = pLink->next;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (pLink) {
|
2006-11-26 11:13:41 -07:00
|
|
|
|
/* need to trick CMapRefreshColors() into thinking
|
|
|
|
|
this is the currently installed map */
|
2010-12-05 08:36:02 -07:00
|
|
|
|
SetInstalledmiColormap(pScreen, pLink->cmap);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
CMapReinstallMap(pLink->cmap);
|
2010-12-05 08:36:02 -07:00
|
|
|
|
SetInstalledmiColormap(pScreen, pMap);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
}
|
|
|
|
|
else
|
2006-11-26 11:13:41 -07:00
|
|
|
|
CMapReinstallMap(pMap);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Success;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
|
int
|
2006-11-26 11:13:41 -07:00
|
|
|
|
xf86GetGammaRampSize(ScreenPtr pScreen)
|
|
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
CMapScreenPtr pScreenPriv;
|
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
|
if (xf86_crtc_supports_gamma(pScrn)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
|
RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (crtc)
|
|
|
|
|
return crtc->gammaSize;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (!CMapScreenKeyRegistered)
|
|
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
|
|
|
|
|
CMapScreenKey);
|
|
|
|
|
if (!pScreenPriv)
|
|
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
return pScreenPriv->gammaElements;
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
|
xf86GetGammaRamp(ScreenPtr pScreen,
|
|
|
|
|
int size,
|
|
|
|
|
unsigned short *red,
|
|
|
|
|
unsigned short *green, unsigned short *blue)
|
|
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
CMapScreenPtr pScreenPriv;
|
|
|
|
|
LOCO *entry;
|
|
|
|
|
int shift, sigbits;
|
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
|
if (xf86_crtc_supports_gamma(pScrn)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
|
RRCrtcPtr crtc = xf86CompatRRCrtc(pScrn);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (crtc) {
|
|
|
|
|
if (crtc->gammaSize < size)
|
|
|
|
|
return BadValue;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (!RRCrtcGammaGet(crtc))
|
|
|
|
|
return BadImplementation;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
memcpy(red, crtc->gammaRed, size * sizeof(*red));
|
|
|
|
|
memcpy(green, crtc->gammaGreen, size * sizeof(*green));
|
|
|
|
|
memcpy(blue, crtc->gammaBlue, size * sizeof(*blue));
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
return Success;
|
|
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (!CMapScreenKeyRegistered)
|
|
|
|
|
return BadImplementation;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
pScreenPriv = (CMapScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
|
|
|
|
|
CMapScreenKey);
|
|
|
|
|
if (!pScreenPriv)
|
|
|
|
|
return BadImplementation;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (size > pScreenPriv->gammaElements)
|
|
|
|
|
return BadValue;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
|
|
entry = pScreenPriv->gamma;
|
|
|
|
|
sigbits = pScreenPriv->sigRGBbits;
|
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
while (size--) {
|
|
|
|
|
*red = entry->red << (16 - sigbits);
|
|
|
|
|
*green = entry->green << (16 - sigbits);
|
|
|
|
|
*blue = entry->blue << (16 - sigbits);
|
|
|
|
|
shift = sigbits;
|
|
|
|
|
while (shift < 16) {
|
|
|
|
|
*red |= *red >> shift;
|
|
|
|
|
*green |= *green >> shift;
|
|
|
|
|
*blue |= *blue >> shift;
|
|
|
|
|
shift += sigbits;
|
|
|
|
|
}
|
|
|
|
|
red++;
|
|
|
|
|
green++;
|
|
|
|
|
blue++;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
entry++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
|
xf86ChangeGamma(ScreenPtr pScreen, Gamma gamma)
|
|
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
|
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
|
if (pScrn->ChangeGamma)
|
2013-06-07 11:28:45 -06:00
|
|
|
|
return (*pScrn->ChangeGamma) (pScrn, gamma);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
|
return BadImplementation;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
}
|