2 * Copyright 2001-2004 Red Hat Inc., Durham, North Carolina.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation on the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * Kevin E. Martin <kem@redhat.com>
35 * Colormap support. */
37 #ifdef HAVE_DMX_CONFIG_H
38 #include <dmx-config.h>
45 #include "dmxvisual.h"
49 static Bool dmxAllocateColormapPrivates(ColormapPtr pColormap)
51 dmxColormapPrivPtr pCmapPriv;
53 pCmapPriv = (dmxColormapPrivPtr)malloc(sizeof(*pCmapPriv));
56 pCmapPriv->cmap = (Colormap)0;
58 DMX_SET_COLORMAP_PRIV(pColormap, pCmapPriv);
63 /** Create \a pColormap on the back-end server. */
64 Bool dmxBECreateColormap(ColormapPtr pColormap)
66 ScreenPtr pScreen = pColormap->pScreen;
67 DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
68 dmxColormapPrivPtr pCmapPriv = DMX_GET_COLORMAP_PRIV(pColormap);
69 VisualPtr pVisual = pColormap->pVisual;
70 Visual *visual = dmxLookupVisual(pScreen, pVisual);
73 pCmapPriv->cmap = XCreateColormap(dmxScreen->beDisplay,
76 (pVisual->class & DynamicClass ?
77 AllocAll : AllocNone));
78 return pCmapPriv->cmap != 0;
81 dmxLog(dmxWarning, "dmxBECreateColormap: No visual found\n");
86 /** Create colormap on back-end server associated with \a pColormap's
88 Bool dmxCreateColormap(ColormapPtr pColormap)
90 ScreenPtr pScreen = pColormap->pScreen;
91 DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
94 if (!dmxAllocateColormapPrivates(pColormap))
97 if (dmxScreen->beDisplay) {
98 if (!dmxBECreateColormap(pColormap))
102 DMX_UNWRAP(CreateColormap, dmxScreen, pScreen);
103 if (pScreen->CreateColormap)
104 ret = pScreen->CreateColormap(pColormap);
105 DMX_WRAP(CreateColormap, dmxCreateColormap, dmxScreen, pScreen);
110 /** Destroy \a pColormap on the back-end server. */
111 Bool dmxBEFreeColormap(ColormapPtr pColormap)
113 ScreenPtr pScreen = pColormap->pScreen;
114 DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
115 dmxColormapPrivPtr pCmapPriv = DMX_GET_COLORMAP_PRIV(pColormap);
117 if (pCmapPriv->cmap) {
118 XFreeColormap(dmxScreen->beDisplay, pCmapPriv->cmap);
119 pCmapPriv->cmap = (Colormap)0;
126 /** Destroy colormap on back-end server associated with \a pColormap's
128 void dmxDestroyColormap(ColormapPtr pColormap)
130 ScreenPtr pScreen = pColormap->pScreen;
131 DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
132 dmxColormapPrivPtr pCmapPriv = DMX_GET_COLORMAP_PRIV(pColormap);
134 if (dmxScreen->beDisplay)
135 dmxBEFreeColormap(pColormap);
137 DMX_SET_COLORMAP_PRIV(pColormap, NULL);
139 DMX_UNWRAP(DestroyColormap, dmxScreen, pScreen);
140 if (pScreen->DestroyColormap)
141 pScreen->DestroyColormap(pColormap);
142 DMX_WRAP(DestroyColormap, dmxDestroyColormap, dmxScreen, pScreen);
145 /** Install colormap on back-end server associated with \a pColormap's
147 void dmxInstallColormap(ColormapPtr pColormap)
149 ScreenPtr pScreen = pColormap->pScreen;
150 DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
151 dmxColormapPrivPtr pCmapPriv = DMX_GET_COLORMAP_PRIV(pColormap);
153 DMX_UNWRAP(InstallColormap, dmxScreen, pScreen);
154 if (pScreen->InstallColormap)
155 pScreen->InstallColormap(pColormap);
156 DMX_WRAP(InstallColormap, dmxInstallColormap, dmxScreen, pScreen);
158 if (dmxScreen->beDisplay) {
159 XInstallColormap(dmxScreen->beDisplay, pCmapPriv->cmap);
160 dmxSync(dmxScreen, FALSE);
164 /** Store colors in \a pColormap on back-end server associated with \a
165 * pColormap's screen. */
166 void dmxStoreColors(ColormapPtr pColormap, int ndef, xColorItem *pdef)
168 ScreenPtr pScreen = pColormap->pScreen;
169 DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
170 dmxColormapPrivPtr pCmapPriv = DMX_GET_COLORMAP_PRIV(pColormap);
172 if (dmxScreen->beDisplay && (pColormap->pVisual->class & DynamicClass)) {
173 XColor *color = malloc(sizeof(*color) * ndef);
177 for (i = 0; i < ndef; i++) {
178 color[i].pixel = pdef[i].pixel;
179 color[i].red = pdef[i].red;
180 color[i].blue = pdef[i].blue;
181 color[i].green = pdef[i].green;
182 color[i].flags = pdef[i].flags;
183 color[i].pad = pdef[i].pad;
185 XStoreColors(dmxScreen->beDisplay, pCmapPriv->cmap, color, ndef);
187 } else { /* xalloc failed, so fallback */
189 for (i = 0; i < ndef; i++) {
190 c.pixel = pdef[i].pixel;
192 c.blue = pdef[i].blue;
193 c.green = pdef[i].green;
194 c.flags = pdef[i].flags;
196 XStoreColor(dmxScreen->beDisplay, pCmapPriv->cmap, &c);
199 dmxSync(dmxScreen, FALSE);
202 DMX_UNWRAP(StoreColors, dmxScreen, pScreen);
203 if (pScreen->StoreColors)
204 pScreen->StoreColors(pColormap, ndef, pdef);
205 DMX_WRAP(StoreColors, dmxStoreColors, dmxScreen, pScreen);
208 /** Create the DMX server's default colormap. */
209 Bool dmxCreateDefColormap(ScreenPtr pScreen)
211 return miCreateDefColormap(pScreen);