1 /* $XConsortium: privates.c /main/5 1996/06/17 10:56:22 mor $ */
2 /* $XFree86: xc/programs/Xserver/dix/privates.c,v 3.2 1997/01/23 10:57:19 dawes Exp $ */
5 Copyright (c) 1993 X Consortium
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
26 Except as contained in this notice, the name of the X Consortium shall
27 not be used in advertising or otherwise to promote the sale, use or
28 other dealings in this Software without prior written authorization
29 from the X Consortium.
34 #include "scrnintstr.h"
37 #include "windowstr.h"
39 #include "dixstruct.h"
41 #include "colormapst.h"
46 * See the Wrappers and devPrivates section in "Definition of the
47 * Porting Layer for the X v11 Sample Server" (doc/Server/ddx.tbl.ms)
48 * for information on how to use devPrivates.
52 * client private machinery
55 static int clientPrivateCount;
57 unsigned *clientPrivateSizes;
58 unsigned totalClientSize;
63 clientPrivateCount = 0;
65 xfree(clientPrivateSizes);
66 clientPrivateSizes = (unsigned *)NULL;
67 totalClientSize = sizeof(ClientRec);
72 AllocateClientPrivateIndex()
74 return clientPrivateCount++;
78 AllocateClientPrivate(index2, amount)
84 if (index2 >= clientPrivateLen)
87 nsizes = (unsigned *)xrealloc(clientPrivateSizes,
88 (index2 + 1) * sizeof(unsigned));
91 while (clientPrivateLen <= index2)
93 nsizes[clientPrivateLen++] = 0;
94 totalClientSize += sizeof(DevUnion);
96 clientPrivateSizes = nsizes;
98 oldamount = clientPrivateSizes[index2];
99 if (amount > oldamount)
101 clientPrivateSizes[index2] = amount;
102 totalClientSize += (amount - oldamount);
108 * screen private machinery
111 int screenPrivateCount;
114 ResetScreenPrivates()
116 screenPrivateCount = 0;
119 /* this can be called after some screens have been created,
120 * so we have to worry about resizing existing devPrivates
123 AllocateScreenPrivateIndex()
130 index2 = screenPrivateCount++;
131 for (i = 0; i < screenInfo.numScreens; i++)
133 pScreen = screenInfo.screens[i];
134 nprivs = (DevUnion *)xrealloc(pScreen->devPrivates,
135 screenPrivateCount * sizeof(DevUnion));
138 screenPrivateCount--;
141 pScreen->devPrivates = nprivs;
148 * window private machinery
151 static int windowPrivateCount;
154 ResetWindowPrivates()
156 windowPrivateCount = 0;
160 AllocateWindowPrivateIndex()
162 return windowPrivateCount++;
166 AllocateWindowPrivate(pScreen, index2, amount)
167 register ScreenPtr pScreen;
173 if (index2 >= pScreen->WindowPrivateLen)
176 nsizes = (unsigned *)xrealloc(pScreen->WindowPrivateSizes,
177 (index2 + 1) * sizeof(unsigned));
180 while (pScreen->WindowPrivateLen <= index2)
182 nsizes[pScreen->WindowPrivateLen++] = 0;
183 pScreen->totalWindowSize += sizeof(DevUnion);
185 pScreen->WindowPrivateSizes = nsizes;
187 oldamount = pScreen->WindowPrivateSizes[index2];
188 if (amount > oldamount)
190 pScreen->WindowPrivateSizes[index2] = amount;
191 pScreen->totalWindowSize += (amount - oldamount);
198 * gc private machinery
201 static int gcPrivateCount;
210 AllocateGCPrivateIndex()
212 return gcPrivateCount++;
216 AllocateGCPrivate(pScreen, index2, amount)
217 register ScreenPtr pScreen;
223 if (index2 >= pScreen->GCPrivateLen)
226 nsizes = (unsigned *)xrealloc(pScreen->GCPrivateSizes,
227 (index2 + 1) * sizeof(unsigned));
230 while (pScreen->GCPrivateLen <= index2)
232 nsizes[pScreen->GCPrivateLen++] = 0;
233 pScreen->totalGCSize += sizeof(DevUnion);
235 pScreen->GCPrivateSizes = nsizes;
237 oldamount = pScreen->GCPrivateSizes[index2];
238 if (amount > oldamount)
240 pScreen->GCPrivateSizes[index2] = amount;
241 pScreen->totalGCSize += (amount - oldamount);
248 * pixmap private machinery
251 static int pixmapPrivateCount;
254 ResetPixmapPrivates()
256 pixmapPrivateCount = 0;
260 AllocatePixmapPrivateIndex()
262 return pixmapPrivateCount++;
266 AllocatePixmapPrivate(pScreen, index2, amount)
267 register ScreenPtr pScreen;
273 if (index2 >= pScreen->PixmapPrivateLen)
276 nsizes = (unsigned *)xrealloc(pScreen->PixmapPrivateSizes,
277 (index2 + 1) * sizeof(unsigned));
280 while (pScreen->PixmapPrivateLen <= index2)
282 nsizes[pScreen->PixmapPrivateLen++] = 0;
283 pScreen->totalPixmapSize += sizeof(DevUnion);
285 pScreen->PixmapPrivateSizes = nsizes;
287 oldamount = pScreen->PixmapPrivateSizes[index2];
288 if (amount > oldamount)
290 pScreen->PixmapPrivateSizes[index2] = amount;
291 pScreen->totalPixmapSize += (amount - oldamount);
293 pScreen->totalPixmapSize = BitmapBytePad(pScreen->totalPixmapSize * 8);
300 * colormap private machinery
303 int colormapPrivateCount;
306 ResetColormapPrivates()
308 colormapPrivateCount = 0;
313 AllocateColormapPrivateIndex (initPrivFunc)
315 InitCmapPrivFunc initPrivFunc;
320 ColormapPtr pColormap;
323 index = colormapPrivateCount++;
325 for (i = 0; i < screenInfo.numScreens; i++)
328 * AllocateColormapPrivateIndex may be called after the
329 * default colormap has been created on each screen!
331 * We must resize the devPrivates array for the default
332 * colormap on each screen, making room for this new private.
333 * We also call the initialization function 'initPrivFunc' on
334 * the new private allocated for each default colormap.
337 ScreenPtr pScreen = screenInfo.screens[i];
339 pColormap = (ColormapPtr) LookupIDByType (
340 pScreen->defColormap, RT_COLORMAP);
342 privs = (DevUnion *) xrealloc (pColormap->devPrivates,
343 colormapPrivateCount * sizeof(DevUnion));
345 pColormap->devPrivates = privs;
347 if (!privs || !(*initPrivFunc)(pColormap))
349 colormapPrivateCount--;