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 int dmxInitColormapPrivateFunc(ColormapPtr pColormap
, int index
)
54 static Bool
dmxAllocateColormapPrivates(ColormapPtr pColormap
)
56 static unsigned long dmxColormapGeneration
;
57 dmxColormapPrivPtr pCmapPriv
;
59 if (dmxColormapGeneration
!= serverGeneration
) {
60 if ((dmxColormapPrivateIndex
61 = AllocateColormapPrivateIndex(dmxInitColormapPrivateFunc
)) < 0)
64 dmxColormapGeneration
= serverGeneration
;
67 pCmapPriv
= (dmxColormapPrivPtr
)xalloc(sizeof(*pCmapPriv
));
70 pCmapPriv
->cmap
= (Colormap
)0;
72 DMX_SET_COLORMAP_PRIV(pColormap
, pCmapPriv
);
77 /** Create \a pColormap on the back-end server. */
78 Bool
dmxBECreateColormap(ColormapPtr pColormap
)
80 ScreenPtr pScreen
= pColormap
->pScreen
;
81 DMXScreenInfo
*dmxScreen
= &dmxScreens
[pScreen
->myNum
];
82 dmxColormapPrivPtr pCmapPriv
= DMX_GET_COLORMAP_PRIV(pColormap
);
83 VisualPtr pVisual
= pColormap
->pVisual
;
84 Visual
*visual
= dmxLookupVisual(pScreen
, pVisual
);
87 pCmapPriv
->cmap
= XCreateColormap(dmxScreen
->beDisplay
,
90 (pVisual
->class & DynamicClass
?
91 AllocAll
: AllocNone
));
92 return (pCmapPriv
->cmap
!= 0);
95 dmxLog(dmxWarning
, "dmxBECreateColormap: No visual found\n");
100 /** Create colormap on back-end server associated with \a pColormap's
102 Bool
dmxCreateColormap(ColormapPtr pColormap
)
104 ScreenPtr pScreen
= pColormap
->pScreen
;
105 DMXScreenInfo
*dmxScreen
= &dmxScreens
[pScreen
->myNum
];
108 if (!dmxAllocateColormapPrivates(pColormap
))
111 if (dmxScreen
->beDisplay
) {
112 if (!dmxBECreateColormap(pColormap
))
116 DMX_UNWRAP(CreateColormap
, dmxScreen
, pScreen
);
117 if (pScreen
->CreateColormap
)
118 ret
= pScreen
->CreateColormap(pColormap
);
119 DMX_WRAP(CreateColormap
, dmxCreateColormap
, dmxScreen
, pScreen
);
124 /** Destroy \a pColormap on the back-end server. */
125 Bool
dmxBEFreeColormap(ColormapPtr pColormap
)
127 ScreenPtr pScreen
= pColormap
->pScreen
;
128 DMXScreenInfo
*dmxScreen
= &dmxScreens
[pScreen
->myNum
];
129 dmxColormapPrivPtr pCmapPriv
= DMX_GET_COLORMAP_PRIV(pColormap
);
131 if (pCmapPriv
->cmap
) {
132 XFreeColormap(dmxScreen
->beDisplay
, pCmapPriv
->cmap
);
133 pCmapPriv
->cmap
= (Colormap
)0;
140 /** Destroy colormap on back-end server associated with \a pColormap's
142 void dmxDestroyColormap(ColormapPtr pColormap
)
144 ScreenPtr pScreen
= pColormap
->pScreen
;
145 DMXScreenInfo
*dmxScreen
= &dmxScreens
[pScreen
->myNum
];
146 dmxColormapPrivPtr pCmapPriv
= DMX_GET_COLORMAP_PRIV(pColormap
);
148 if (dmxScreen
->beDisplay
)
149 dmxBEFreeColormap(pColormap
);
151 DMX_SET_COLORMAP_PRIV(pColormap
, NULL
);
153 DMX_UNWRAP(DestroyColormap
, dmxScreen
, pScreen
);
154 if (pScreen
->DestroyColormap
)
155 pScreen
->DestroyColormap(pColormap
);
156 DMX_WRAP(DestroyColormap
, dmxDestroyColormap
, dmxScreen
, pScreen
);
159 /** Install colormap on back-end server associated with \a pColormap's
161 void dmxInstallColormap(ColormapPtr pColormap
)
163 ScreenPtr pScreen
= pColormap
->pScreen
;
164 DMXScreenInfo
*dmxScreen
= &dmxScreens
[pScreen
->myNum
];
165 dmxColormapPrivPtr pCmapPriv
= DMX_GET_COLORMAP_PRIV(pColormap
);
167 DMX_UNWRAP(InstallColormap
, dmxScreen
, pScreen
);
168 if (pScreen
->InstallColormap
)
169 pScreen
->InstallColormap(pColormap
);
170 DMX_WRAP(InstallColormap
, dmxInstallColormap
, dmxScreen
, pScreen
);
172 if (dmxScreen
->beDisplay
) {
173 XInstallColormap(dmxScreen
->beDisplay
, pCmapPriv
->cmap
);
174 dmxSync(dmxScreen
, FALSE
);
178 /** Store colors in \a pColormap on back-end server associated with \a
179 * pColormap's screen. */
180 void dmxStoreColors(ColormapPtr pColormap
, int ndef
, xColorItem
*pdef
)
182 ScreenPtr pScreen
= pColormap
->pScreen
;
183 DMXScreenInfo
*dmxScreen
= &dmxScreens
[pScreen
->myNum
];
184 dmxColormapPrivPtr pCmapPriv
= DMX_GET_COLORMAP_PRIV(pColormap
);
186 if (dmxScreen
->beDisplay
&& (pColormap
->pVisual
->class & DynamicClass
)) {
187 XColor
*color
= xalloc(sizeof(*color
) * ndef
);
191 for (i
= 0; i
< ndef
; i
++) {
192 color
[i
].pixel
= pdef
[i
].pixel
;
193 color
[i
].red
= pdef
[i
].red
;
194 color
[i
].blue
= pdef
[i
].blue
;
195 color
[i
].green
= pdef
[i
].green
;
196 color
[i
].flags
= pdef
[i
].flags
;
197 color
[i
].pad
= pdef
[i
].pad
;
199 XStoreColors(dmxScreen
->beDisplay
, pCmapPriv
->cmap
, color
, ndef
);
201 } else { /* xalloc failed, so fallback */
203 for (i
= 0; i
< ndef
; i
++) {
204 c
.pixel
= pdef
[i
].pixel
;
206 c
.blue
= pdef
[i
].blue
;
207 c
.green
= pdef
[i
].green
;
208 c
.flags
= pdef
[i
].flags
;
210 XStoreColor(dmxScreen
->beDisplay
, pCmapPriv
->cmap
, &c
);
213 dmxSync(dmxScreen
, FALSE
);
216 DMX_UNWRAP(StoreColors
, dmxScreen
, pScreen
);
217 if (pScreen
->StoreColors
)
218 pScreen
->StoreColors(pColormap
, ndef
, pdef
);
219 DMX_WRAP(StoreColors
, dmxStoreColors
, dmxScreen
, pScreen
);
222 /** Create the DMX server's default colormap. */
223 Bool
dmxCreateDefColormap(ScreenPtr pScreen
)
225 return miCreateDefColormap(pScreen
);