privates.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*
  2. Copyright 1993, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included
  9. in all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  13. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  14. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  15. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  16. OTHER DEALINGS IN THE SOFTWARE.
  17. Except as contained in this notice, the name of The Open Group shall
  18. not be used in advertising or otherwise to promote the sale, use or
  19. other dealings in this Software without prior written authorization
  20. from The Open Group.
  21. */
  22. #ifdef HAVE_DIX_CONFIG_H
  23. #include <dix-config.h>
  24. #endif
  25. #include <X11/X.h>
  26. #include "scrnintstr.h"
  27. #include "misc.h"
  28. #include "os.h"
  29. #include "windowstr.h"
  30. #include "resource.h"
  31. #include "dixstruct.h"
  32. #include "gcstruct.h"
  33. #include "colormapst.h"
  34. #include "servermd.h"
  35. #include "site.h"
  36. #include "inputstr.h"
  37. #include "extnsionst.h"
  38. /*
  39. * See the Wrappers and devPrivates section in "Definition of the
  40. * Porting Layer for the X v11 Sample Server" (doc/Server/ddx.tbl.ms)
  41. * for information on how to use devPrivates.
  42. */
  43. /*
  44. * extension private machinery
  45. */
  46. static int extensionPrivateCount;
  47. int extensionPrivateLen;
  48. unsigned *extensionPrivateSizes;
  49. unsigned totalExtensionSize;
  50. void
  51. ResetExtensionPrivates()
  52. {
  53. extensionPrivateCount = 0;
  54. extensionPrivateLen = 0;
  55. free(extensionPrivateSizes);
  56. extensionPrivateSizes = (unsigned *) NULL;
  57. totalExtensionSize =
  58. ((sizeof(ExtensionEntry) + sizeof(long) -
  59. 1) / sizeof(long)) * sizeof(long);
  60. }
  61. /*
  62. * client private machinery
  63. */
  64. static int clientPrivateCount;
  65. int clientPrivateLen;
  66. unsigned *clientPrivateSizes;
  67. unsigned totalClientSize;
  68. void
  69. ResetClientPrivates()
  70. {
  71. clientPrivateCount = 0;
  72. clientPrivateLen = 0;
  73. free(clientPrivateSizes);
  74. clientPrivateSizes = (unsigned *) NULL;
  75. totalClientSize =
  76. ((sizeof(ClientRec) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
  77. }
  78. _X_EXPORT int
  79. AllocateClientPrivateIndex()
  80. {
  81. return clientPrivateCount++;
  82. }
  83. _X_EXPORT Bool
  84. AllocateClientPrivate(int index2, unsigned amount)
  85. {
  86. unsigned oldamount;
  87. /* Round up sizes for proper alignment */
  88. amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
  89. if (index2 >= clientPrivateLen) {
  90. unsigned *nsizes;
  91. nsizes = (unsigned *) realloc(clientPrivateSizes,
  92. (index2 + 1) * sizeof(unsigned));
  93. if (!nsizes)
  94. return FALSE;
  95. while (clientPrivateLen <= index2) {
  96. nsizes[clientPrivateLen++] = 0;
  97. totalClientSize += sizeof(DevUnion);
  98. }
  99. clientPrivateSizes = nsizes;
  100. }
  101. oldamount = clientPrivateSizes[index2];
  102. if (amount > oldamount) {
  103. clientPrivateSizes[index2] = amount;
  104. totalClientSize += (amount - oldamount);
  105. }
  106. return TRUE;
  107. }
  108. /*
  109. * screen private machinery
  110. */
  111. int screenPrivateCount;
  112. void
  113. ResetScreenPrivates()
  114. {
  115. screenPrivateCount = 0;
  116. }
  117. /* this can be called after some screens have been created,
  118. * so we have to worry about resizing existing devPrivates
  119. */
  120. _X_EXPORT int
  121. AllocateScreenPrivateIndex()
  122. {
  123. int idx;
  124. int i;
  125. ScreenPtr pScreen;
  126. DevUnion *nprivs;
  127. idx = screenPrivateCount++;
  128. for (i = 0; i < screenInfo.numScreens; i++) {
  129. pScreen = screenInfo.screens[i];
  130. nprivs = (DevUnion *) realloc(pScreen->devPrivates,
  131. screenPrivateCount * sizeof(DevUnion));
  132. if (!nprivs) {
  133. screenPrivateCount--;
  134. return -1;
  135. }
  136. /* Zero the new private */
  137. bzero(&nprivs[idx], sizeof(DevUnion));
  138. pScreen->devPrivates = nprivs;
  139. }
  140. return idx;
  141. }
  142. /*
  143. * window private machinery
  144. */
  145. static int windowPrivateCount;
  146. void
  147. ResetWindowPrivates()
  148. {
  149. windowPrivateCount = 0;
  150. }
  151. _X_EXPORT int
  152. AllocateWindowPrivateIndex()
  153. {
  154. return windowPrivateCount++;
  155. }
  156. _X_EXPORT Bool
  157. AllocateWindowPrivate(register ScreenPtr pScreen, int index2, unsigned amount)
  158. {
  159. unsigned oldamount;
  160. /* Round up sizes for proper alignment */
  161. amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
  162. if (index2 >= pScreen->WindowPrivateLen) {
  163. unsigned *nsizes;
  164. nsizes = (unsigned *) realloc(pScreen->WindowPrivateSizes,
  165. (index2 + 1) * sizeof(unsigned));
  166. if (!nsizes)
  167. return FALSE;
  168. while (pScreen->WindowPrivateLen <= index2) {
  169. nsizes[pScreen->WindowPrivateLen++] = 0;
  170. pScreen->totalWindowSize += sizeof(DevUnion);
  171. }
  172. pScreen->WindowPrivateSizes = nsizes;
  173. }
  174. oldamount = pScreen->WindowPrivateSizes[index2];
  175. if (amount > oldamount) {
  176. pScreen->WindowPrivateSizes[index2] = amount;
  177. pScreen->totalWindowSize += (amount - oldamount);
  178. }
  179. return TRUE;
  180. }
  181. /*
  182. * gc private machinery
  183. */
  184. static int gcPrivateCount;
  185. void
  186. ResetGCPrivates()
  187. {
  188. gcPrivateCount = 0;
  189. }
  190. _X_EXPORT int
  191. AllocateGCPrivateIndex()
  192. {
  193. return gcPrivateCount++;
  194. }
  195. _X_EXPORT Bool
  196. AllocateGCPrivate(register ScreenPtr pScreen, int index2, unsigned amount)
  197. {
  198. unsigned oldamount;
  199. /* Round up sizes for proper alignment */
  200. amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
  201. if (index2 >= pScreen->GCPrivateLen) {
  202. unsigned *nsizes;
  203. nsizes = (unsigned *) realloc(pScreen->GCPrivateSizes,
  204. (index2 + 1) * sizeof(unsigned));
  205. if (!nsizes)
  206. return FALSE;
  207. while (pScreen->GCPrivateLen <= index2) {
  208. nsizes[pScreen->GCPrivateLen++] = 0;
  209. pScreen->totalGCSize += sizeof(DevUnion);
  210. }
  211. pScreen->GCPrivateSizes = nsizes;
  212. }
  213. oldamount = pScreen->GCPrivateSizes[index2];
  214. if (amount > oldamount) {
  215. pScreen->GCPrivateSizes[index2] = amount;
  216. pScreen->totalGCSize += (amount - oldamount);
  217. }
  218. return TRUE;
  219. }
  220. /*
  221. * pixmap private machinery
  222. */
  223. static int pixmapPrivateCount;
  224. void
  225. ResetPixmapPrivates()
  226. {
  227. pixmapPrivateCount = 0;
  228. }
  229. _X_EXPORT int
  230. AllocatePixmapPrivateIndex()
  231. {
  232. return pixmapPrivateCount++;
  233. }
  234. _X_EXPORT Bool
  235. AllocatePixmapPrivate(register ScreenPtr pScreen, int index2, unsigned amount)
  236. {
  237. unsigned oldamount;
  238. /* Round up sizes for proper alignment */
  239. amount = ((amount + (sizeof(long) - 1)) / sizeof(long)) * sizeof(long);
  240. if (index2 >= pScreen->PixmapPrivateLen) {
  241. unsigned *nsizes;
  242. nsizes = (unsigned *) realloc(pScreen->PixmapPrivateSizes,
  243. (index2 + 1) * sizeof(unsigned));
  244. if (!nsizes)
  245. return FALSE;
  246. while (pScreen->PixmapPrivateLen <= index2) {
  247. nsizes[pScreen->PixmapPrivateLen++] = 0;
  248. pScreen->totalPixmapSize += sizeof(DevUnion);
  249. }
  250. pScreen->PixmapPrivateSizes = nsizes;
  251. }
  252. oldamount = pScreen->PixmapPrivateSizes[index2];
  253. if (amount > oldamount) {
  254. pScreen->PixmapPrivateSizes[index2] = amount;
  255. pScreen->totalPixmapSize += (amount - oldamount);
  256. }
  257. pScreen->totalPixmapSize = BitmapBytePad(pScreen->totalPixmapSize * 8);
  258. return TRUE;
  259. }
  260. /*
  261. * colormap private machinery
  262. */
  263. int colormapPrivateCount;
  264. void
  265. ResetColormapPrivates()
  266. {
  267. colormapPrivateCount = 0;
  268. }
  269. /*
  270. * device private machinery
  271. */
  272. static int devicePrivateIndex = 0;
  273. void
  274. ResetDevicePrivateIndex(void)
  275. {
  276. devicePrivateIndex = 0;
  277. }