PageRenderTime 22ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/include/resource.h

https://github.com/sharad/xserver
C Header | 287 lines | 151 code | 49 blank | 87 comment | 4 complexity | a1bbe56131763452c0ece45ec368e1ab MD5 | raw file
  1. /***********************************************************
  2. Copyright 1987, 1989, 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 in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
  20. All Rights Reserved
  21. Permission to use, copy, modify, and distribute this software and its
  22. documentation for any purpose and without fee is hereby granted,
  23. provided that the above copyright notice appear in all copies and that
  24. both that copyright notice and this permission notice appear in
  25. supporting documentation, and that the name of Digital not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  32. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  33. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34. SOFTWARE.
  35. ******************************************************************/
  36. #ifndef RESOURCE_H
  37. #define RESOURCE_H 1
  38. #include "misc.h"
  39. #include "dixaccess.h"
  40. /*****************************************************************
  41. * STUFF FOR RESOURCES
  42. *****************************************************************/
  43. /* classes for Resource routines */
  44. typedef uint32_t RESTYPE;
  45. #define RC_VANILLA ((RESTYPE)0)
  46. #define RC_CACHED ((RESTYPE)1<<31)
  47. #define RC_DRAWABLE ((RESTYPE)1<<30)
  48. /* Use class RC_NEVERRETAIN for resources that should not be retained
  49. * regardless of the close down mode when the client dies. (A client's
  50. * event selections on objects that it doesn't own are good candidates.)
  51. * Extensions can use this too!
  52. */
  53. #define RC_NEVERRETAIN ((RESTYPE)1<<29)
  54. #define RC_LASTPREDEF RC_NEVERRETAIN
  55. #define RC_ANY (~(RESTYPE)0)
  56. /* types for Resource routines */
  57. #define RT_WINDOW ((RESTYPE)1|RC_DRAWABLE)
  58. #define RT_PIXMAP ((RESTYPE)2|RC_DRAWABLE)
  59. #define RT_GC ((RESTYPE)3)
  60. #undef RT_FONT
  61. #undef RT_CURSOR
  62. #define RT_FONT ((RESTYPE)4)
  63. #define RT_CURSOR ((RESTYPE)5)
  64. #define RT_COLORMAP ((RESTYPE)6)
  65. #define RT_CMAPENTRY ((RESTYPE)7)
  66. #define RT_OTHERCLIENT ((RESTYPE)8|RC_NEVERRETAIN)
  67. #define RT_PASSIVEGRAB ((RESTYPE)9|RC_NEVERRETAIN)
  68. #define RT_LASTPREDEF ((RESTYPE)9)
  69. #define RT_NONE ((RESTYPE)0)
  70. /* bits and fields within a resource id */
  71. #define RESOURCE_AND_CLIENT_COUNT 29 /* 29 bits for XIDs */
  72. #if MAXCLIENTS == 64
  73. #define RESOURCE_CLIENT_BITS 6
  74. #endif
  75. #if MAXCLIENTS == 128
  76. #define RESOURCE_CLIENT_BITS 7
  77. #endif
  78. #if MAXCLIENTS == 256
  79. #define RESOURCE_CLIENT_BITS 8
  80. #endif
  81. #if MAXCLIENTS == 512
  82. #define RESOURCE_CLIENT_BITS 9
  83. #endif
  84. /* client field offset */
  85. #define CLIENTOFFSET (RESOURCE_AND_CLIENT_COUNT - RESOURCE_CLIENT_BITS)
  86. /* resource field */
  87. #define RESOURCE_ID_MASK ((1 << CLIENTOFFSET) - 1)
  88. /* client field */
  89. #define RESOURCE_CLIENT_MASK (((1 << RESOURCE_CLIENT_BITS) - 1) << CLIENTOFFSET)
  90. /* extract the client mask from an XID */
  91. #define CLIENT_BITS(id) ((id) & RESOURCE_CLIENT_MASK)
  92. /* extract the client id from an XID */
  93. #define CLIENT_ID(id) ((int)(CLIENT_BITS(id) >> CLIENTOFFSET))
  94. #define SERVER_BIT (Mask)0x40000000 /* use illegal bit */
  95. #ifdef INVALID
  96. #undef INVALID /* needed on HP/UX */
  97. #endif
  98. /* Invalid resource id */
  99. #define INVALID (0)
  100. #define BAD_RESOURCE 0xe0000000
  101. #define rClient(obj) (clients[CLIENT_ID((obj)->resource)])
  102. /* Resource state callback */
  103. extern _X_EXPORT CallbackListPtr ResourceStateCallback;
  104. typedef enum { ResourceStateAdding,
  105. ResourceStateFreeing
  106. } ResourceState;
  107. typedef struct {
  108. ResourceState state;
  109. XID id;
  110. RESTYPE type;
  111. void *value;
  112. } ResourceStateInfoRec;
  113. typedef int (*DeleteType) (void */*value */ ,
  114. XID /*id */ );
  115. typedef void (*FindResType) (void */*value */ ,
  116. XID /*id */ ,
  117. void */*cdata */ );
  118. typedef void (*FindAllRes) (void */*value */ ,
  119. XID /*id */ ,
  120. RESTYPE /*type */ ,
  121. void */*cdata */ );
  122. typedef Bool (*FindComplexResType) (void */*value */ ,
  123. XID /*id */ ,
  124. void */*cdata */ );
  125. /* Structure for estimating resource memory usage. Memory usage
  126. * consists of space allocated for the resource itself and of
  127. * references to other resources. Currently the most important use for
  128. * this structure is to estimate pixmap usage of different resources
  129. * more accurately. */
  130. typedef struct {
  131. /* Size of resource itself. Zero if not implemented. */
  132. unsigned long resourceSize;
  133. /* Size attributed to pixmap references from the resource. */
  134. unsigned long pixmapRefSize;
  135. /* Number of references to this resource; typically 1 */
  136. unsigned long refCnt;
  137. } ResourceSizeRec, *ResourceSizePtr;
  138. typedef void (*SizeType)(void */*value*/,
  139. XID /*id*/,
  140. ResourceSizePtr /*size*/);
  141. extern _X_EXPORT RESTYPE CreateNewResourceType(DeleteType /*deleteFunc */ ,
  142. const char * /*name */ );
  143. typedef void (*FindTypeSubResources)(void */* value */,
  144. FindAllRes /* func */,
  145. void */* cdata */);
  146. extern _X_EXPORT SizeType GetResourceTypeSizeFunc(
  147. RESTYPE /*type*/);
  148. extern _X_EXPORT void SetResourceTypeFindSubResFunc(
  149. RESTYPE /*type*/, FindTypeSubResources /*findFunc*/);
  150. extern _X_EXPORT void SetResourceTypeSizeFunc(
  151. RESTYPE /*type*/, SizeType /*sizeFunc*/);
  152. extern _X_EXPORT void SetResourceTypeErrorValue(
  153. RESTYPE /*type*/, int /*errorValue*/);
  154. extern _X_EXPORT RESTYPE CreateNewResourceClass(void);
  155. extern _X_EXPORT Bool InitClientResources(ClientPtr /*client */ );
  156. extern _X_EXPORT XID FakeClientID(int /*client */ );
  157. /* Quartz support on Mac OS X uses the CarbonCore
  158. framework whose AddResource function conflicts here. */
  159. #ifdef __APPLE__
  160. #define AddResource Darwin_X_AddResource
  161. #endif
  162. extern _X_EXPORT Bool AddResource(XID /*id */ ,
  163. RESTYPE /*type */ ,
  164. void */*value */ );
  165. extern _X_EXPORT void FreeResource(XID /*id */ ,
  166. RESTYPE /*skipDeleteFuncType */ );
  167. extern _X_EXPORT void FreeResourceByType(XID /*id */ ,
  168. RESTYPE /*type */ ,
  169. Bool /*skipFree */ );
  170. extern _X_EXPORT Bool ChangeResourceValue(XID /*id */ ,
  171. RESTYPE /*rtype */ ,
  172. void */*value */ );
  173. extern _X_EXPORT void FindClientResourcesByType(ClientPtr /*client */ ,
  174. RESTYPE /*type */ ,
  175. FindResType /*func */ ,
  176. void */*cdata */ );
  177. extern _X_EXPORT void FindAllClientResources(ClientPtr /*client */ ,
  178. FindAllRes /*func */ ,
  179. void */*cdata */ );
  180. /** @brief Iterate through all subresources of a resource.
  181. @note The XID argument provided to the FindAllRes function
  182. may be 0 for subresources that don't have an XID */
  183. extern _X_EXPORT void FindSubResources(void */*resource*/,
  184. RESTYPE /*type*/,
  185. FindAllRes /*func*/,
  186. void */*cdata*/);
  187. extern _X_EXPORT void FreeClientNeverRetainResources(ClientPtr /*client */ );
  188. extern _X_EXPORT void FreeClientResources(ClientPtr /*client */ );
  189. extern _X_EXPORT void FreeAllResources(void);
  190. extern _X_EXPORT Bool LegalNewID(XID /*id */ ,
  191. ClientPtr /*client */ );
  192. extern _X_EXPORT void *LookupClientResourceComplex(ClientPtr client,
  193. RESTYPE type,
  194. FindComplexResType func,
  195. void *cdata);
  196. extern _X_EXPORT int dixLookupResourceByType(void **result,
  197. XID id,
  198. RESTYPE rtype,
  199. ClientPtr client,
  200. Mask access_mode);
  201. extern _X_EXPORT int dixLookupResourceByClass(void **result,
  202. XID id,
  203. RESTYPE rclass,
  204. ClientPtr client,
  205. Mask access_mode);
  206. extern _X_EXPORT void GetXIDRange(int /*client */ ,
  207. Bool /*server */ ,
  208. XID * /*minp */ ,
  209. XID * /*maxp */ );
  210. extern _X_EXPORT unsigned int GetXIDList(ClientPtr /*client */ ,
  211. unsigned int /*count */ ,
  212. XID * /*pids */ );
  213. extern _X_EXPORT RESTYPE lastResourceType;
  214. extern _X_EXPORT RESTYPE TypeMask;
  215. /** @brief A hashing function to be used for hashing resource IDs
  216. @param id The resource ID to hash
  217. @param numBits The number of bits in the resulting hash. Must be >=0.
  218. @note This function is really only for handling
  219. INITHASHSIZE..MAXHASHSIZE bit hashes, but will handle any number
  220. of bits by either masking numBits lower bits of the ID or by
  221. providing at most MAXHASHSIZE hashes.
  222. */
  223. extern _X_EXPORT int HashResourceID(XID id,
  224. int numBits);
  225. #endif /* RESOURCE_H */