2 * Copyright © 1999 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
24 #include <kdrive-config.h>
29 * Put the entire colormap into the DAC
33 KdSetColormap(ScreenPtr pScreen
)
35 KdScreenPriv(pScreen
);
36 ColormapPtr pCmap
= pScreenPriv
->pInstalledmap
;
37 Pixel pixels
[KD_MAX_PSEUDO_SIZE
];
38 xrgb colors
[KD_MAX_PSEUDO_SIZE
];
39 xColorItem defs
[KD_MAX_PSEUDO_SIZE
];
42 if (!pScreenPriv
->card
->cfuncs
->putColors
)
44 if (pScreenPriv
->screen
->fb
.depth
> KD_MAX_PSEUDO_DEPTH
)
47 if (!pScreenPriv
->enabled
)
54 * Make DIX convert pixels into RGB values -- this handles
55 * true/direct as well as pseudo/static visuals
58 for (i
= 0; i
< (1 << pScreenPriv
->screen
->fb
.depth
); i
++)
61 QueryColors(pCmap
, (1 << pScreenPriv
->screen
->fb
.depth
), pixels
, colors
,
64 for (i
= 0; i
< (1 << pScreenPriv
->screen
->fb
.depth
); i
++) {
66 defs
[i
].red
= colors
[i
].red
;
67 defs
[i
].green
= colors
[i
].green
;
68 defs
[i
].blue
= colors
[i
].blue
;
69 defs
[i
].flags
= DoRed
| DoGreen
| DoBlue
;
72 (*pScreenPriv
->card
->cfuncs
->putColors
) (pCmap
->pScreen
,
73 (1 << pScreenPriv
->screen
->fb
.
76 /* recolor hardware cursor */
77 if (pScreenPriv
->card
->cfuncs
->recolorCursor
)
78 (*pScreenPriv
->card
->cfuncs
->recolorCursor
) (pCmap
->pScreen
, 0, 0);
82 * When the hardware is enabled, save the hardware colors and store
83 * the current colormap
86 KdEnableColormap(ScreenPtr pScreen
)
88 KdScreenPriv(pScreen
);
91 if (!pScreenPriv
->card
->cfuncs
->putColors
)
94 if (pScreenPriv
->screen
->fb
.depth
<= KD_MAX_PSEUDO_DEPTH
) {
95 for (i
= 0; i
< (1 << pScreenPriv
->screen
->fb
.depth
); i
++)
96 pScreenPriv
->systemPalette
[i
].pixel
= i
;
97 (*pScreenPriv
->card
->cfuncs
->getColors
) (pScreen
,
98 (1 << pScreenPriv
->screen
->fb
.
100 pScreenPriv
->systemPalette
);
102 KdSetColormap(pScreen
);
106 KdDisableColormap(ScreenPtr pScreen
)
108 KdScreenPriv(pScreen
);
110 if (!pScreenPriv
->card
->cfuncs
->putColors
)
113 if (pScreenPriv
->screen
->fb
.depth
<= KD_MAX_PSEUDO_DEPTH
) {
114 (*pScreenPriv
->card
->cfuncs
->putColors
) (pScreen
,
115 (1 << pScreenPriv
->screen
->fb
.
117 pScreenPriv
->systemPalette
);
124 * This function is called when the server receives a request to install a
125 * colormap or when the server needs to install one on its own, like when
126 * there's no window manager running and the user has moved the pointer over
127 * an X client window. It needs to build an identity Windows palette for the
128 * colormap and realize it into the Windows system palette.
131 KdInstallColormap(ColormapPtr pCmap
)
133 KdScreenPriv(pCmap
->pScreen
);
135 if (pCmap
== pScreenPriv
->pInstalledmap
)
138 /* Tell X clients that the installed colormap is going away. */
139 if (pScreenPriv
->pInstalledmap
)
140 WalkTree(pScreenPriv
->pInstalledmap
->pScreen
, TellLostMap
,
141 (pointer
) &(pScreenPriv
->pInstalledmap
->mid
));
143 /* Take note of the new installed colorscreen-> */
144 pScreenPriv
->pInstalledmap
= pCmap
;
146 KdSetColormap(pCmap
->pScreen
);
148 /* Tell X clients of the new colormap */
149 WalkTree(pCmap
->pScreen
, TellGainedMap
, (pointer
) &(pCmap
->mid
));
153 * KdUninstallColormap
155 * This function uninstalls a colormap by either installing
156 * the default X colormap or erasing the installed colormap pointer.
157 * The default X colormap itself cannot be uninstalled.
160 KdUninstallColormap(ColormapPtr pCmap
)
162 KdScreenPriv(pCmap
->pScreen
);
166 /* ignore if not installed */
167 if (pCmap
!= pScreenPriv
->pInstalledmap
)
170 /* ignore attempts to uninstall default colormap */
171 defMapID
= pCmap
->pScreen
->defColormap
;
172 if ((Colormap
) pCmap
->mid
== defMapID
)
175 /* install default */
176 dixLookupResourceByType((pointer
*) &defMap
, defMapID
, RT_COLORMAP
,
177 serverClient
, DixInstallAccess
);
179 (*pCmap
->pScreen
->InstallColormap
) (defMap
);
181 /* uninstall and clear colormap pointer */
182 WalkTree(pCmap
->pScreen
, TellLostMap
, (pointer
) &(pCmap
->mid
));
183 pScreenPriv
->pInstalledmap
= 0;
188 KdListInstalledColormaps(ScreenPtr pScreen
, Colormap
* pCmaps
)
190 KdScreenPriv(pScreen
);
193 if (pScreenPriv
->pInstalledmap
) {
194 *pCmaps
++ = pScreenPriv
->pInstalledmap
->mid
;
203 * This function is called whenever the server receives a request to store
204 * color values into one or more entries in the currently installed X
205 * colormap; it can be either the default colormap or a private colorscreen->
208 KdStoreColors(ColormapPtr pCmap
, int ndef
, xColorItem
* pdefs
)
210 KdScreenPriv(pCmap
->pScreen
);
212 xColorItem expanddefs
[KD_MAX_PSEUDO_SIZE
];
214 if (pCmap
!= pScreenPriv
->pInstalledmap
)
217 if (!pScreenPriv
->card
->cfuncs
->putColors
)
220 if (pScreenPriv
->screen
->fb
.depth
> KD_MAX_PSEUDO_DEPTH
)
223 if (!pScreenPriv
->enabled
)
226 /* Check for DirectColor or TrueColor being simulated on a PseudoColor device. */
227 pVisual
= pCmap
->pVisual
;
228 if ((pVisual
->class | DynamicClass
) == DirectColor
) {
230 * Expand DirectColor or TrueColor color values into a PseudoColor
231 * format. Defer to the Color Framebuffer (CFB) code to do that.
233 ndef
= fbExpandDirectColors(pCmap
, ndef
, pdefs
, expanddefs
);
237 (*pScreenPriv
->card
->cfuncs
->putColors
) (pCmap
->pScreen
, ndef
, pdefs
);
239 /* recolor hardware cursor */
240 if (pScreenPriv
->card
->cfuncs
->recolorCursor
)
241 (*pScreenPriv
->card
->cfuncs
->recolorCursor
) (pCmap
->pScreen
, ndef
,