1 /***********************************************************
3 Copyright 1987, 1989, 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 in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
25 Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of Digital not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
37 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 ******************************************************************/
50 #include "dixaccess.h"
52 /*****************************************************************
54 *****************************************************************/
56 /* classes for Resource routines */
58 typedef uint32_t RESTYPE
;
60 #define RC_VANILLA ((RESTYPE)0)
61 #define RC_CACHED ((RESTYPE)1<<31)
62 #define RC_DRAWABLE ((RESTYPE)1<<30)
63 /* Use class RC_NEVERRETAIN for resources that should not be retained
64 * regardless of the close down mode when the client dies. (A client's
65 * event selections on objects that it doesn't own are good candidates.)
66 * Extensions can use this too!
68 #define RC_NEVERRETAIN ((RESTYPE)1<<29)
69 #define RC_LASTPREDEF RC_NEVERRETAIN
70 #define RC_ANY (~(RESTYPE)0)
72 /* types for Resource routines */
74 #define RT_WINDOW ((RESTYPE)1|RC_DRAWABLE)
75 #define RT_PIXMAP ((RESTYPE)2|RC_DRAWABLE)
76 #define RT_GC ((RESTYPE)3)
79 #define RT_FONT ((RESTYPE)4)
80 #define RT_CURSOR ((RESTYPE)5)
81 #define RT_COLORMAP ((RESTYPE)6)
82 #define RT_CMAPENTRY ((RESTYPE)7)
83 #define RT_OTHERCLIENT ((RESTYPE)8|RC_NEVERRETAIN)
84 #define RT_PASSIVEGRAB ((RESTYPE)9|RC_NEVERRETAIN)
85 #define RT_LASTPREDEF ((RESTYPE)9)
86 #define RT_NONE ((RESTYPE)0)
88 /* bits and fields within a resource id */
89 #define RESOURCE_AND_CLIENT_COUNT 29 /* 29 bits for XIDs */
91 #define RESOURCE_CLIENT_BITS 6
94 #define RESOURCE_CLIENT_BITS 7
97 #define RESOURCE_CLIENT_BITS 8
100 #define RESOURCE_CLIENT_BITS 9
102 /* client field offset */
103 #define CLIENTOFFSET (RESOURCE_AND_CLIENT_COUNT - RESOURCE_CLIENT_BITS)
105 #define RESOURCE_ID_MASK ((1 << CLIENTOFFSET) - 1)
107 #define RESOURCE_CLIENT_MASK (((1 << RESOURCE_CLIENT_BITS) - 1) << CLIENTOFFSET)
108 /* extract the client mask from an XID */
109 #define CLIENT_BITS(id) ((id) & RESOURCE_CLIENT_MASK)
110 /* extract the client id from an XID */
111 #define CLIENT_ID(id) ((int)(CLIENT_BITS(id) >> CLIENTOFFSET))
112 #define SERVER_BIT (Mask)0x40000000 /* use illegal bit */
115 #undef INVALID /* needed on HP/UX */
118 /* Invalid resource id */
121 #define BAD_RESOURCE 0xe0000000
123 #define rClient(obj) (clients[CLIENT_ID((obj)->resource)])
125 /* Resource state callback */
126 extern _X_EXPORT CallbackListPtr ResourceStateCallback
;
128 typedef enum { ResourceStateAdding
,
137 } ResourceStateInfoRec
;
139 typedef int (*DeleteType
) (pointer
/*value */ ,
142 typedef void (*FindResType
) (pointer
/*value */ ,
144 pointer
/*cdata */ );
146 typedef void (*FindAllRes
) (pointer
/*value */ ,
149 pointer
/*cdata */ );
151 typedef Bool (*FindComplexResType
) (pointer
/*value */ ,
153 pointer
/*cdata */ );
155 /* Structure for estimating resource memory usage. Memory usage
156 * consists of space allocated for the resource itself and of
157 * references to other resources. Currently the most important use for
158 * this structure is to estimate pixmap usage of different resources
159 * more accurately. */
161 /* Size of resource itself. Zero if not implemented. */
162 unsigned long resourceSize
;
163 /* Size attributed to pixmap references from the resource. */
164 unsigned long pixmapRefSize
;
165 /* Number of references to this resource; typically 1 */
166 unsigned long refCnt
;
167 } ResourceSizeRec
, *ResourceSizePtr
;
169 typedef void (*SizeType
)(pointer
/*value*/,
171 ResourceSizePtr
/*size*/);
173 extern _X_EXPORT RESTYPE
CreateNewResourceType(DeleteType
/*deleteFunc */ ,
174 const char * /*name */ );
176 typedef void (*FindTypeSubResources
)(pointer
/* value */,
177 FindAllRes
/* func */,
178 pointer
/* cdata */);
180 extern _X_EXPORT SizeType
GetResourceTypeSizeFunc(
183 extern _X_EXPORT
void SetResourceTypeFindSubResFunc(
184 RESTYPE
/*type*/, FindTypeSubResources
/*findFunc*/);
186 extern _X_EXPORT
void SetResourceTypeSizeFunc(
187 RESTYPE
/*type*/, SizeType
/*sizeFunc*/);
189 extern _X_EXPORT
void SetResourceTypeErrorValue(
190 RESTYPE
/*type*/, int /*errorValue*/);
192 extern _X_EXPORT RESTYPE
CreateNewResourceClass(void);
194 extern _X_EXPORT Bool
InitClientResources(ClientPtr
/*client */ );
196 extern _X_EXPORT XID
FakeClientID(int /*client */ );
198 /* Quartz support on Mac OS X uses the CarbonCore
199 framework whose AddResource function conflicts here. */
201 #define AddResource Darwin_X_AddResource
203 extern _X_EXPORT Bool
AddResource(XID
/*id */ ,
205 pointer
/*value */ );
207 extern _X_EXPORT
void FreeResource(XID
/*id */ ,
208 RESTYPE
/*skipDeleteFuncType */ );
210 extern _X_EXPORT
void FreeResourceByType(XID
/*id */ ,
212 Bool
/*skipFree */ );
214 extern _X_EXPORT Bool
ChangeResourceValue(XID
/*id */ ,
216 pointer
/*value */ );
218 extern _X_EXPORT
void FindClientResourcesByType(ClientPtr
/*client */ ,
220 FindResType
/*func */ ,
221 pointer
/*cdata */ );
223 extern _X_EXPORT
void FindAllClientResources(ClientPtr
/*client */ ,
224 FindAllRes
/*func */ ,
225 pointer
/*cdata */ );
227 /** @brief Iterate through all subresources of a resource.
229 @note The XID argument provided to the FindAllRes function
230 may be 0 for subresources that don't have an XID */
231 extern _X_EXPORT
void FindSubResources(pointer
/*resource*/,
236 extern _X_EXPORT
void FreeClientNeverRetainResources(ClientPtr
/*client */ );
238 extern _X_EXPORT
void FreeClientResources(ClientPtr
/*client */ );
240 extern _X_EXPORT
void FreeAllResources(void);
242 extern _X_EXPORT Bool
LegalNewID(XID
/*id */ ,
243 ClientPtr
/*client */ );
245 extern _X_EXPORT pointer
LookupClientResourceComplex(ClientPtr client
,
247 FindComplexResType func
,
250 extern _X_EXPORT
int dixLookupResourceByType(pointer
*result
,
256 extern _X_EXPORT
int dixLookupResourceByClass(pointer
*result
,
262 extern _X_EXPORT
void GetXIDRange(int /*client */ ,
267 extern _X_EXPORT
unsigned int GetXIDList(ClientPtr
/*client */ ,
268 unsigned int /*count */ ,
271 extern _X_EXPORT RESTYPE lastResourceType
;
272 extern _X_EXPORT RESTYPE TypeMask
;
274 /** @brief A hashing function to be used for hashing resource IDs
276 @param id The resource ID to hash
277 @param numBits The number of bits in the resulting hash. Must be >=0.
279 @note This function is really only for handling
280 INITHASHSIZE..MAXHASHSIZE bit hashes, but will handle any number
281 of bits by either masking numBits lower bits of the ID or by
282 providing at most MAXHASHSIZE hashes.
284 extern _X_EXPORT
int HashResourceID(XID id
,
287 #endif /* RESOURCE_H */