3 Copyright 1993, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
29 #ifdef HAVE_DIX_CONFIG_H
30 #include <dix-config.h>
34 #include "scrnintstr.h"
37 #include "windowstr.h"
39 #include "dixstruct.h"
41 #include "colormapst.h"
45 #include "extnsionst.h"
48 * See the Wrappers and devPrivates section in "Definition of the
49 * Porting Layer for the X v11 Sample Server" (doc/Server/ddx.tbl.ms)
50 * for information on how to use devPrivates.
54 * extension private machinery
57 static int extensionPrivateCount
;
58 int extensionPrivateLen
;
59 unsigned *extensionPrivateSizes
;
60 unsigned totalExtensionSize
;
63 ResetExtensionPrivates(void)
65 extensionPrivateCount
= 0;
66 extensionPrivateLen
= 0;
67 xfree(extensionPrivateSizes
);
68 extensionPrivateSizes
= (unsigned *)NULL
;
70 ((sizeof(ExtensionEntry
) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
74 AllocateExtensionPrivateIndex(void)
76 return extensionPrivateCount
++;
80 AllocateExtensionPrivate(int index2
, unsigned amount
)
84 /* Round up sizes for proper alignment */
85 amount
= ((amount
+ (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
87 if (index2
>= extensionPrivateLen
)
90 nsizes
= (unsigned *)xrealloc(extensionPrivateSizes
,
91 (index2
+ 1) * sizeof(unsigned));
94 while (extensionPrivateLen
<= index2
)
96 nsizes
[extensionPrivateLen
++] = 0;
97 totalExtensionSize
+= sizeof(DevUnion
);
99 extensionPrivateSizes
= nsizes
;
101 oldamount
= extensionPrivateSizes
[index2
];
102 if (amount
> oldamount
)
104 extensionPrivateSizes
[index2
] = amount
;
105 totalExtensionSize
+= (amount
- oldamount
);
111 * client private machinery
114 static int clientPrivateCount
;
115 int clientPrivateLen
;
116 unsigned *clientPrivateSizes
;
117 unsigned totalClientSize
;
120 ResetClientPrivates(void)
122 clientPrivateCount
= 0;
123 clientPrivateLen
= 0;
124 xfree(clientPrivateSizes
);
125 clientPrivateSizes
= (unsigned *)NULL
;
127 ((sizeof(ClientRec
) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
131 AllocateClientPrivateIndex(void)
133 return clientPrivateCount
++;
137 AllocateClientPrivate(int index2
, unsigned amount
)
141 /* Round up sizes for proper alignment */
142 amount
= ((amount
+ (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
144 if (index2
>= clientPrivateLen
)
147 nsizes
= (unsigned *)xrealloc(clientPrivateSizes
,
148 (index2
+ 1) * sizeof(unsigned));
151 while (clientPrivateLen
<= index2
)
153 nsizes
[clientPrivateLen
++] = 0;
154 totalClientSize
+= sizeof(DevUnion
);
156 clientPrivateSizes
= nsizes
;
158 oldamount
= clientPrivateSizes
[index2
];
159 if (amount
> oldamount
)
161 clientPrivateSizes
[index2
] = amount
;
162 totalClientSize
+= (amount
- oldamount
);
168 * screen private machinery
171 int screenPrivateCount
;
174 ResetScreenPrivates(void)
176 screenPrivateCount
= 0;
179 /* this can be called after some screens have been created,
180 * so we have to worry about resizing existing devPrivates
183 AllocateScreenPrivateIndex(void)
190 idx
= screenPrivateCount
++;
191 for (i
= 0; i
< screenInfo
.numScreens
; i
++)
193 pScreen
= screenInfo
.screens
[i
];
194 nprivs
= (DevUnion
*)xrealloc(pScreen
->devPrivates
,
195 screenPrivateCount
* sizeof(DevUnion
));
198 screenPrivateCount
--;
201 /* Zero the new private */
202 bzero(&nprivs
[idx
], sizeof(DevUnion
));
203 pScreen
->devPrivates
= nprivs
;
210 * window private machinery
213 static int windowPrivateCount
;
216 ResetWindowPrivates(void)
218 windowPrivateCount
= 0;
222 AllocateWindowPrivateIndex(void)
224 return windowPrivateCount
++;
228 AllocateWindowPrivate(ScreenPtr pScreen
, int index2
, unsigned amount
)
232 /* Round up sizes for proper alignment */
233 amount
= ((amount
+ (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
235 if (index2
>= pScreen
->WindowPrivateLen
)
238 nsizes
= (unsigned *)xrealloc(pScreen
->WindowPrivateSizes
,
239 (index2
+ 1) * sizeof(unsigned));
242 while (pScreen
->WindowPrivateLen
<= index2
)
244 nsizes
[pScreen
->WindowPrivateLen
++] = 0;
245 pScreen
->totalWindowSize
+= sizeof(DevUnion
);
247 pScreen
->WindowPrivateSizes
= nsizes
;
249 oldamount
= pScreen
->WindowPrivateSizes
[index2
];
250 if (amount
> oldamount
)
252 pScreen
->WindowPrivateSizes
[index2
] = amount
;
253 pScreen
->totalWindowSize
+= (amount
- oldamount
);
260 * gc private machinery
263 static int gcPrivateCount
;
266 ResetGCPrivates(void)
272 AllocateGCPrivateIndex(void)
274 return gcPrivateCount
++;
278 AllocateGCPrivate(ScreenPtr pScreen
, int index2
, unsigned amount
)
282 /* Round up sizes for proper alignment */
283 amount
= ((amount
+ (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
285 if (index2
>= pScreen
->GCPrivateLen
)
288 nsizes
= (unsigned *)xrealloc(pScreen
->GCPrivateSizes
,
289 (index2
+ 1) * sizeof(unsigned));
292 while (pScreen
->GCPrivateLen
<= index2
)
294 nsizes
[pScreen
->GCPrivateLen
++] = 0;
295 pScreen
->totalGCSize
+= sizeof(DevUnion
);
297 pScreen
->GCPrivateSizes
= nsizes
;
299 oldamount
= pScreen
->GCPrivateSizes
[index2
];
300 if (amount
> oldamount
)
302 pScreen
->GCPrivateSizes
[index2
] = amount
;
303 pScreen
->totalGCSize
+= (amount
- oldamount
);
310 * pixmap private machinery
312 static int pixmapPrivateCount
;
315 ResetPixmapPrivates(void)
317 pixmapPrivateCount
= 0;
321 AllocatePixmapPrivateIndex(void)
323 return pixmapPrivateCount
++;
327 AllocatePixmapPrivate(ScreenPtr pScreen
, int index2
, unsigned amount
)
331 /* Round up sizes for proper alignment */
332 amount
= ((amount
+ (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
334 if (index2
>= pScreen
->PixmapPrivateLen
)
337 nsizes
= (unsigned *)xrealloc(pScreen
->PixmapPrivateSizes
,
338 (index2
+ 1) * sizeof(unsigned));
341 while (pScreen
->PixmapPrivateLen
<= index2
)
343 nsizes
[pScreen
->PixmapPrivateLen
++] = 0;
344 pScreen
->totalPixmapSize
+= sizeof(DevUnion
);
346 pScreen
->PixmapPrivateSizes
= nsizes
;
348 oldamount
= pScreen
->PixmapPrivateSizes
[index2
];
349 if (amount
> oldamount
)
351 pScreen
->PixmapPrivateSizes
[index2
] = amount
;
352 pScreen
->totalPixmapSize
+= (amount
- oldamount
);
354 pScreen
->totalPixmapSize
= BitmapBytePad(pScreen
->totalPixmapSize
* 8);
360 * colormap private machinery
363 int colormapPrivateCount
;
366 ResetColormapPrivates(void)
368 colormapPrivateCount
= 0;
373 AllocateColormapPrivateIndex (InitCmapPrivFunc initPrivFunc
)
377 ColormapPtr pColormap
;
380 index
= colormapPrivateCount
++;
382 for (i
= 0; i
< screenInfo
.numScreens
; i
++)
385 * AllocateColormapPrivateIndex may be called after the
386 * default colormap has been created on each screen!
388 * We must resize the devPrivates array for the default
389 * colormap on each screen, making room for this new private.
390 * We also call the initialization function 'initPrivFunc' on
391 * the new private allocated for each default colormap.
394 ScreenPtr pScreen
= screenInfo
.screens
[i
];
396 pColormap
= (ColormapPtr
) LookupIDByType (
397 pScreen
->defColormap
, RT_COLORMAP
);
401 privs
= (DevUnion
*) xrealloc (pColormap
->devPrivates
,
402 colormapPrivateCount
* sizeof(DevUnion
));
404 colormapPrivateCount
--;
407 bzero(&privs
[index
], sizeof(DevUnion
));
408 pColormap
->devPrivates
= privs
;
409 if (!(*initPrivFunc
)(pColormap
,index
))
411 colormapPrivateCount
--;
421 * device private machinery
424 static int devicePrivateIndex
= 0;
427 AllocateDevicePrivateIndex(void)
429 return devicePrivateIndex
++;
433 AllocateDevicePrivate(DeviceIntPtr device
, int index
)
435 if (device
->nPrivates
< ++index
) {
436 DevUnion
*nprivs
= (DevUnion
*) xrealloc(device
->devPrivates
,
437 index
* sizeof(DevUnion
));
440 device
->devPrivates
= nprivs
;
441 bzero(&nprivs
[device
->nPrivates
], sizeof(DevUnion
)
442 * (index
- device
->nPrivates
));
443 device
->nPrivates
= index
;
451 ResetDevicePrivateIndex(void)
453 devicePrivateIndex
= 0;