#ifdef HAVE_CONFIG_H
#include <kdrive-config.h>
#endif
#include "kdrive.h"
void
KdSetColormap (ScreenPtr pScreen, int fb)
{
KdScreenPriv(pScreen);
ColormapPtr pCmap = pScreenPriv->pInstalledmap[fb];
Pixel pixels[KD_MAX_PSEUDO_SIZE];
xrgb colors[KD_MAX_PSEUDO_SIZE];
xColorItem defs[KD_MAX_PSEUDO_SIZE];
int i;
if (!pScreenPriv->card->cfuncs->putColors)
return;
if (pScreenPriv->screen->fb[fb].depth > KD_MAX_PSEUDO_DEPTH)
return;
if (!pScreenPriv->enabled)
return;
if (!pCmap)
return;
for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
pixels[i] = i;
QueryColors (pCmap, (1 << pScreenPriv->screen->fb[fb].depth), pixels, colors);
for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
{
defs[i].pixel = i;
defs[i].red = colors[i].red;
defs[i].green = colors[i].green;
defs[i].blue = colors[i].blue;
defs[i].flags = DoRed|DoGreen|DoBlue;
}
(*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen, fb,
(1 << pScreenPriv->screen->fb[fb].depth),
defs);
if (pScreenPriv->card->cfuncs->recolorCursor)
(*pScreenPriv->card->cfuncs->recolorCursor) (pCmap->pScreen, 0, 0);
}
void
KdEnableColormap (ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
int i;
int fb;
Bool done = FALSE;
if (!pScreenPriv->card->cfuncs->putColors)
return;
for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
{
if (pScreenPriv->screen->fb[fb].depth <= KD_MAX_PSEUDO_DEPTH && !done)
{
for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
pScreenPriv->systemPalette[i].pixel = i;
(*pScreenPriv->card->cfuncs->getColors) (pScreen, fb,
(1 << pScreenPriv->screen->fb[fb].depth),
pScreenPriv->systemPalette);
done = TRUE;
}
KdSetColormap (pScreen, fb);
}
}
void
KdDisableColormap (ScreenPtr pScreen)
{
KdScreenPriv(pScreen);
int fb;
if (!pScreenPriv->card->cfuncs->putColors)
return;
for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
{
if (pScreenPriv->screen->fb[fb].depth <= KD_MAX_PSEUDO_DEPTH)
{
(*pScreenPriv->card->cfuncs->putColors) (pScreen, fb,
(1 << pScreenPriv->screen->fb[fb].depth),
pScreenPriv->systemPalette);
break;
}
}
}
static int
KdColormapFb (ColormapPtr pCmap)
{
ScreenPtr pScreen = pCmap->pScreen;
KdScreenPriv (pScreen);
KdScreenInfo *screen = pScreenPriv->screen;
int d;
DepthPtr depth;
int v;
VisualID vid = pCmap->pVisual->vid;
int fb;
if (screen->fb[1].depth)
{
for (d = 0; d < pScreen->numDepths; d++)
{
depth = &pScreen->allowedDepths[d];
for (v = 0; v < depth->numVids; v++)
{
if (depth->vids[v] == vid)
{
for (fb = 0; fb < KD_MAX_FB && screen->fb[fb].depth; fb++)
{
if (depth->depth == screen->fb[fb].depth)
return fb;
}
}
}
}
}
return 0;
}
void
KdInstallColormap (ColormapPtr pCmap)
{
KdScreenPriv(pCmap->pScreen);
int fb = KdColormapFb (pCmap);
if (pCmap == pScreenPriv->pInstalledmap[fb])
return;
if (pScreenPriv->pInstalledmap[fb])
WalkTree(pScreenPriv->pInstalledmap[fb]->pScreen, TellLostMap,
(pointer) &(pScreenPriv->pInstalledmap[fb]->mid));
pScreenPriv->pInstalledmap[fb] = pCmap;
KdSetColormap (pCmap->pScreen, fb);
WalkTree(pCmap->pScreen, TellGainedMap, (pointer) &(pCmap->mid));
}
void
KdUninstallColormap (ColormapPtr pCmap)
{
KdScreenPriv(pCmap->pScreen);
int fb = KdColormapFb (pCmap);
Colormap defMapID;
ColormapPtr defMap;
if (pCmap != pScreenPriv->pInstalledmap[fb])
return;
defMapID = pCmap->pScreen->defColormap;
if ((Colormap) pCmap->mid == defMapID)
return;
defMap = (ColormapPtr) LookupIDByType(defMapID, RT_COLORMAP);
if (defMap && KdColormapFb (defMap) == fb)
(*pCmap->pScreen->InstallColormap)(defMap);
else
{
WalkTree(pCmap->pScreen, TellLostMap,
(pointer) &(pCmap->mid));
pScreenPriv->pInstalledmap[fb] = 0;
}
}
int
KdListInstalledColormaps (ScreenPtr pScreen, Colormap *pCmaps)
{
KdScreenPriv(pScreen);
int fb;
int n = 0;
for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
{
if (pScreenPriv->pInstalledmap[fb])
{
*pCmaps++ = pScreenPriv->pInstalledmap[fb]->mid;
n++;
}
}
return n;
}
void
KdStoreColors (ColormapPtr pCmap, int ndef, xColorItem *pdefs)
{
KdScreenPriv(pCmap->pScreen);
VisualPtr pVisual;
xColorItem expanddefs[KD_MAX_PSEUDO_SIZE];
int fb = KdColormapFb (pCmap);
if (pCmap != pScreenPriv->pInstalledmap[fb])
return;
if (!pScreenPriv->card->cfuncs->putColors)
return;
if (pScreenPriv->screen->fb[fb].depth > KD_MAX_PSEUDO_DEPTH)
return;
if (!pScreenPriv->enabled)
return;
pVisual = pCmap->pVisual;
if ((pVisual->class | DynamicClass) == DirectColor)
{
ndef = fbExpandDirectColors(pCmap, ndef, pdefs, expanddefs);
pdefs = expanddefs;
}
(*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen, fb, ndef, pdefs);
if (pScreenPriv->card->cfuncs->recolorCursor)
(*pScreenPriv->card->cfuncs->recolorCursor) (pCmap->pScreen, ndef, pdefs);
}