2
* Id: kcmap.c,v 1.1 1999/11/02 03:54:46 keithp Exp $
4
* Copyright ļæ½ 1999 Keith Packard
6
* Permission to use, copy, modify, distribute, and sell this software and its
7
* documentation for any purpose is hereby granted without fee, provided that
8
* the above copyright notice appear in all copies and that both that
9
* copyright notice and this permission notice appear in supporting
10
* documentation, and that the name of Keith Packard not be used in
11
* advertising or publicity pertaining to distribution of the software without
12
* specific, written prior permission. Keith Packard makes no
13
* representations about the suitability of this software for any purpose. It
14
* is provided "as is" without express or implied warranty.
16
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22
* PERFORMANCE OF THIS SOFTWARE.
24
/* $RCSId: xc/programs/Xserver/hw/kdrive/kcmap.c,v 1.4 2000/05/24 23:57:56 keithp Exp $ */
27
#include <kdrive-config.h>
32
* Put the entire colormap into the DAC
36
KdSetColormap (ScreenPtr pScreen, int fb)
38
KdScreenPriv(pScreen);
39
ColormapPtr pCmap = pScreenPriv->pInstalledmap[fb];
40
Pixel pixels[KD_MAX_PSEUDO_SIZE];
41
xrgb colors[KD_MAX_PSEUDO_SIZE];
42
xColorItem defs[KD_MAX_PSEUDO_SIZE];
45
if (!pScreenPriv->card->cfuncs->putColors)
47
if (pScreenPriv->screen->fb[fb].depth > KD_MAX_PSEUDO_DEPTH)
50
if (!pScreenPriv->enabled)
57
* Make DIX convert pixels into RGB values -- this handles
58
* true/direct as well as pseudo/static visuals
61
for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
64
QueryColors (pCmap, (1 << pScreenPriv->screen->fb[fb].depth), pixels, colors);
66
for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
69
defs[i].red = colors[i].red;
70
defs[i].green = colors[i].green;
71
defs[i].blue = colors[i].blue;
72
defs[i].flags = DoRed|DoGreen|DoBlue;
75
(*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen, fb,
76
(1 << pScreenPriv->screen->fb[fb].depth),
79
/* recolor hardware cursor */
80
if (pScreenPriv->card->cfuncs->recolorCursor)
81
(*pScreenPriv->card->cfuncs->recolorCursor) (pCmap->pScreen, 0, 0);
85
* When the hardware is enabled, save the hardware colors and store
86
* the current colormap
89
KdEnableColormap (ScreenPtr pScreen)
91
KdScreenPriv(pScreen);
96
if (!pScreenPriv->card->cfuncs->putColors)
98
for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
100
if (pScreenPriv->screen->fb[fb].depth <= KD_MAX_PSEUDO_DEPTH && !done)
102
for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
103
pScreenPriv->systemPalette[i].pixel = i;
104
(*pScreenPriv->card->cfuncs->getColors) (pScreen, fb,
105
(1 << pScreenPriv->screen->fb[fb].depth),
106
pScreenPriv->systemPalette);
109
KdSetColormap (pScreen, fb);
114
KdDisableColormap (ScreenPtr pScreen)
116
KdScreenPriv(pScreen);
119
if (!pScreenPriv->card->cfuncs->putColors)
121
for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
123
if (pScreenPriv->screen->fb[fb].depth <= KD_MAX_PSEUDO_DEPTH)
125
(*pScreenPriv->card->cfuncs->putColors) (pScreen, fb,
126
(1 << pScreenPriv->screen->fb[fb].depth),
127
pScreenPriv->systemPalette);
134
KdColormapFb (ColormapPtr pCmap)
136
ScreenPtr pScreen = pCmap->pScreen;
137
KdScreenPriv (pScreen);
138
KdScreenInfo *screen = pScreenPriv->screen;
142
VisualID vid = pCmap->pVisual->vid;
145
if (screen->fb[1].depth)
147
for (d = 0; d < pScreen->numDepths; d++)
149
depth = &pScreen->allowedDepths[d];
150
for (v = 0; v < depth->numVids; v++)
152
if (depth->vids[v] == vid)
154
for (fb = 0; fb < KD_MAX_FB && screen->fb[fb].depth; fb++)
156
if (depth->depth == screen->fb[fb].depth)
169
* This function is called when the server receives a request to install a
170
* colormap or when the server needs to install one on its own, like when
171
* there's no window manager running and the user has moved the pointer over
172
* an X client window. It needs to build an identity Windows palette for the
173
* colormap and realize it into the Windows system palette.
176
KdInstallColormap (ColormapPtr pCmap)
178
KdScreenPriv(pCmap->pScreen);
179
int fb = KdColormapFb (pCmap);
181
if (pCmap == pScreenPriv->pInstalledmap[fb])
184
/* Tell X clients that the installed colormap is going away. */
185
if (pScreenPriv->pInstalledmap[fb])
186
WalkTree(pScreenPriv->pInstalledmap[fb]->pScreen, TellLostMap,
187
(pointer) &(pScreenPriv->pInstalledmap[fb]->mid));
189
/* Take note of the new installed colorscreen-> */
190
pScreenPriv->pInstalledmap[fb] = pCmap;
192
KdSetColormap (pCmap->pScreen, fb);
194
/* Tell X clients of the new colormap */
195
WalkTree(pCmap->pScreen, TellGainedMap, (pointer) &(pCmap->mid));
199
* KdUninstallColormap
201
* This function uninstalls a colormap by either installing
202
* the default X colormap or erasing the installed colormap pointer.
203
* The default X colormap itself cannot be uninstalled.
206
KdUninstallColormap (ColormapPtr pCmap)
208
KdScreenPriv(pCmap->pScreen);
209
int fb = KdColormapFb (pCmap);
213
/* ignore if not installed */
214
if (pCmap != pScreenPriv->pInstalledmap[fb])
217
/* ignore attempts to uninstall default colormap */
218
defMapID = pCmap->pScreen->defColormap;
219
if ((Colormap) pCmap->mid == defMapID)
222
/* install default if on same fb */
223
defMap = (ColormapPtr) LookupIDByType(defMapID, RT_COLORMAP);
224
if (defMap && KdColormapFb (defMap) == fb)
225
(*pCmap->pScreen->InstallColormap)(defMap);
228
/* uninstall and clear colormap pointer */
229
WalkTree(pCmap->pScreen, TellLostMap,
230
(pointer) &(pCmap->mid));
231
pScreenPriv->pInstalledmap[fb] = 0;
236
KdListInstalledColormaps (ScreenPtr pScreen, Colormap *pCmaps)
238
KdScreenPriv(pScreen);
242
for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
244
if (pScreenPriv->pInstalledmap[fb])
246
*pCmaps++ = pScreenPriv->pInstalledmap[fb]->mid;
256
* This function is called whenever the server receives a request to store
257
* color values into one or more entries in the currently installed X
258
* colormap; it can be either the default colormap or a private colorscreen->
261
KdStoreColors (ColormapPtr pCmap, int ndef, xColorItem *pdefs)
263
KdScreenPriv(pCmap->pScreen);
265
xColorItem expanddefs[KD_MAX_PSEUDO_SIZE];
266
int fb = KdColormapFb (pCmap);
268
if (pCmap != pScreenPriv->pInstalledmap[fb])
271
if (!pScreenPriv->card->cfuncs->putColors)
274
if (pScreenPriv->screen->fb[fb].depth > KD_MAX_PSEUDO_DEPTH)
277
if (!pScreenPriv->enabled)
280
/* Check for DirectColor or TrueColor being simulated on a PseudoColor device. */
281
pVisual = pCmap->pVisual;
282
if ((pVisual->class | DynamicClass) == DirectColor)
285
* Expand DirectColor or TrueColor color values into a PseudoColor
286
* format. Defer to the Color Framebuffer (CFB) code to do that.
288
ndef = fbExpandDirectColors(pCmap, ndef, pdefs, expanddefs);
292
(*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen, fb, ndef, pdefs);
294
/* recolor hardware cursor */
295
if (pScreenPriv->card->cfuncs->recolorCursor)
296
(*pScreenPriv->card->cfuncs->recolorCursor) (pCmap->pScreen, ndef, pdefs);