105b261ecSmrg/*********************************************************** 205b261ecSmrg 305b261ecSmrgCopyright 1987, 1989, 1998 The Open Group 405b261ecSmrg 505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its 605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that 705b261ecSmrgthe above copyright notice appear in all copies and that both that 805b261ecSmrgcopyright notice and this permission notice appear in supporting 905b261ecSmrgdocumentation. 1005b261ecSmrg 1105b261ecSmrgThe above copyright notice and this permission notice shall be included in 1205b261ecSmrgall copies or substantial portions of the Software. 1305b261ecSmrg 1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1505b261ecSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1605b261ecSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1705b261ecSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1805b261ecSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1905b261ecSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2005b261ecSmrg 2105b261ecSmrgExcept as contained in this notice, the name of The Open Group shall not be 2205b261ecSmrgused in advertising or otherwise to promote the sale, use or other dealings 2305b261ecSmrgin this Software without prior written authorization from The Open Group. 2405b261ecSmrg 2505b261ecSmrgCopyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. 2605b261ecSmrg 2705b261ecSmrg All Rights Reserved 2805b261ecSmrg 2935c4bbdfSmrgPermission to use, copy, modify, and distribute this software and its 3035c4bbdfSmrgdocumentation for any purpose and without fee is hereby granted, 3105b261ecSmrgprovided that the above copyright notice appear in all copies and that 3235c4bbdfSmrgboth that copyright notice and this permission notice appear in 3305b261ecSmrgsupporting documentation, and that the name of Digital not be 3405b261ecSmrgused in advertising or publicity pertaining to distribution of the 3535c4bbdfSmrgsoftware without specific, written prior permission. 3605b261ecSmrg 3705b261ecSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 3805b261ecSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 3905b261ecSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 4005b261ecSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 4105b261ecSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 4205b261ecSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 4305b261ecSmrgSOFTWARE. 4405b261ecSmrg 4505b261ecSmrg******************************************************************/ 4605b261ecSmrg 4705b261ecSmrg#ifndef RESOURCE_H 4805b261ecSmrg#define RESOURCE_H 1 4905b261ecSmrg#include "misc.h" 504642e01fSmrg#include "dixaccess.h" 5105b261ecSmrg 5205b261ecSmrg/***************************************************************** 5335c4bbdfSmrg * STUFF FOR RESOURCES 5405b261ecSmrg *****************************************************************/ 5505b261ecSmrg 5605b261ecSmrg/* classes for Resource routines */ 5705b261ecSmrg 5835c4bbdfSmrgtypedef uint32_t RESTYPE; 5905b261ecSmrg 6005b261ecSmrg#define RC_VANILLA ((RESTYPE)0) 6105b261ecSmrg#define RC_CACHED ((RESTYPE)1<<31) 6205b261ecSmrg#define RC_DRAWABLE ((RESTYPE)1<<30) 6305b261ecSmrg/* Use class RC_NEVERRETAIN for resources that should not be retained 6405b261ecSmrg * regardless of the close down mode when the client dies. (A client's 6505b261ecSmrg * event selections on objects that it doesn't own are good candidates.) 6605b261ecSmrg * Extensions can use this too! 6705b261ecSmrg */ 6805b261ecSmrg#define RC_NEVERRETAIN ((RESTYPE)1<<29) 6905b261ecSmrg#define RC_LASTPREDEF RC_NEVERRETAIN 7005b261ecSmrg#define RC_ANY (~(RESTYPE)0) 7105b261ecSmrg 7205b261ecSmrg/* types for Resource routines */ 7305b261ecSmrg 744642e01fSmrg#define RT_WINDOW ((RESTYPE)1|RC_DRAWABLE) 754642e01fSmrg#define RT_PIXMAP ((RESTYPE)2|RC_DRAWABLE) 764642e01fSmrg#define RT_GC ((RESTYPE)3) 7705b261ecSmrg#undef RT_FONT 7805b261ecSmrg#undef RT_CURSOR 7905b261ecSmrg#define RT_FONT ((RESTYPE)4) 8005b261ecSmrg#define RT_CURSOR ((RESTYPE)5) 8105b261ecSmrg#define RT_COLORMAP ((RESTYPE)6) 8205b261ecSmrg#define RT_CMAPENTRY ((RESTYPE)7) 8305b261ecSmrg#define RT_OTHERCLIENT ((RESTYPE)8|RC_NEVERRETAIN) 8405b261ecSmrg#define RT_PASSIVEGRAB ((RESTYPE)9|RC_NEVERRETAIN) 8505b261ecSmrg#define RT_LASTPREDEF ((RESTYPE)9) 8605b261ecSmrg#define RT_NONE ((RESTYPE)0) 8705b261ecSmrg 8835c4bbdfSmrgextern _X_EXPORT unsigned int ResourceClientBits(void); 8905b261ecSmrg/* bits and fields within a resource id */ 9035c4bbdfSmrg#define RESOURCE_AND_CLIENT_COUNT 29 /* 29 bits for XIDs */ 9135c4bbdfSmrg#define RESOURCE_CLIENT_BITS ResourceClientBits() /* client field offset */ 9205b261ecSmrg#define CLIENTOFFSET (RESOURCE_AND_CLIENT_COUNT - RESOURCE_CLIENT_BITS) 9305b261ecSmrg/* resource field */ 9405b261ecSmrg#define RESOURCE_ID_MASK ((1 << CLIENTOFFSET) - 1) 9505b261ecSmrg/* client field */ 9605b261ecSmrg#define RESOURCE_CLIENT_MASK (((1 << RESOURCE_CLIENT_BITS) - 1) << CLIENTOFFSET) 9705b261ecSmrg/* extract the client mask from an XID */ 9805b261ecSmrg#define CLIENT_BITS(id) ((id) & RESOURCE_CLIENT_MASK) 9905b261ecSmrg/* extract the client id from an XID */ 10005b261ecSmrg#define CLIENT_ID(id) ((int)(CLIENT_BITS(id) >> CLIENTOFFSET)) 10135c4bbdfSmrg#define SERVER_BIT (Mask)0x40000000 /* use illegal bit */ 10205b261ecSmrg 10305b261ecSmrg#ifdef INVALID 10435c4bbdfSmrg#undef INVALID /* needed on HP/UX */ 10505b261ecSmrg#endif 10605b261ecSmrg 10705b261ecSmrg/* Invalid resource id */ 10805b261ecSmrg#define INVALID (0) 10905b261ecSmrg 11005b261ecSmrg#define BAD_RESOURCE 0xe0000000 11105b261ecSmrg 1129ace9065Smrg#define rClient(obj) (clients[CLIENT_ID((obj)->resource)]) 1139ace9065Smrg 1144642e01fSmrg/* Resource state callback */ 1156747b715Smrgextern _X_EXPORT CallbackListPtr ResourceStateCallback; 1164642e01fSmrg 11735c4bbdfSmrgtypedef enum { ResourceStateAdding, 11835c4bbdfSmrg ResourceStateFreeing 11935c4bbdfSmrg} ResourceState; 1204642e01fSmrg 1214642e01fSmrgtypedef struct { 1224642e01fSmrg ResourceState state; 1234642e01fSmrg XID id; 1244642e01fSmrg RESTYPE type; 12535c4bbdfSmrg void *value; 1264642e01fSmrg} ResourceStateInfoRec; 1274642e01fSmrg 12835c4bbdfSmrgtypedef int (*DeleteType) (void *value, 12935c4bbdfSmrg XID id); 13035c4bbdfSmrg 13135c4bbdfSmrgtypedef void (*FindResType) (void *value, 13235c4bbdfSmrg XID id, 13335c4bbdfSmrg void *cdata); 13405b261ecSmrg 13535c4bbdfSmrgtypedef void (*FindAllRes) (void *value, 13635c4bbdfSmrg XID id, 13735c4bbdfSmrg RESTYPE type, 13835c4bbdfSmrg void *cdata); 13905b261ecSmrg 14035c4bbdfSmrgtypedef Bool (*FindComplexResType) (void *value, 14135c4bbdfSmrg XID id, 14235c4bbdfSmrg void *cdata); 14335c4bbdfSmrg 14435c4bbdfSmrg/* Structure for estimating resource memory usage. Memory usage 14535c4bbdfSmrg * consists of space allocated for the resource itself and of 14635c4bbdfSmrg * references to other resources. Currently the most important use for 14735c4bbdfSmrg * this structure is to estimate pixmap usage of different resources 14835c4bbdfSmrg * more accurately. */ 14935c4bbdfSmrgtypedef struct { 15035c4bbdfSmrg /* Size of resource itself. Zero if not implemented. */ 15135c4bbdfSmrg unsigned long resourceSize; 15235c4bbdfSmrg /* Size attributed to pixmap references from the resource. */ 15335c4bbdfSmrg unsigned long pixmapRefSize; 15435c4bbdfSmrg /* Number of references to this resource; typically 1 */ 15535c4bbdfSmrg unsigned long refCnt; 15635c4bbdfSmrg} ResourceSizeRec, *ResourceSizePtr; 15705b261ecSmrg 15835c4bbdfSmrgtypedef void (*SizeType)(void *value, 15935c4bbdfSmrg XID id, 16035c4bbdfSmrg ResourceSizePtr size); 16105b261ecSmrg 16235c4bbdfSmrgextern _X_EXPORT RESTYPE CreateNewResourceType(DeleteType deleteFunc, 16335c4bbdfSmrg const char *name); 16435c4bbdfSmrg 16535c4bbdfSmrgtypedef void (*FindTypeSubResources)(void *value, 16635c4bbdfSmrg FindAllRes func, 16735c4bbdfSmrg void *cdata); 16835c4bbdfSmrg 16935c4bbdfSmrgextern _X_EXPORT SizeType GetResourceTypeSizeFunc( 17035c4bbdfSmrg RESTYPE /*type*/); 17135c4bbdfSmrg 17235c4bbdfSmrgextern _X_EXPORT void SetResourceTypeFindSubResFunc( 17335c4bbdfSmrg RESTYPE /*type*/, FindTypeSubResources /*findFunc*/); 17435c4bbdfSmrg 17535c4bbdfSmrgextern _X_EXPORT void SetResourceTypeSizeFunc( 17635c4bbdfSmrg RESTYPE /*type*/, SizeType /*sizeFunc*/); 17705b261ecSmrg 1786747b715Smrgextern _X_EXPORT void SetResourceTypeErrorValue( 1796747b715Smrg RESTYPE /*type*/, int /*errorValue*/); 18005b261ecSmrg 1816747b715Smrgextern _X_EXPORT RESTYPE CreateNewResourceClass(void); 1826747b715Smrg 18335c4bbdfSmrgextern _X_EXPORT Bool InitClientResources(ClientPtr /*client */ ); 18405b261ecSmrg 18535c4bbdfSmrgextern _X_EXPORT XID FakeClientID(int /*client */ ); 18605b261ecSmrg 18705b261ecSmrg/* Quartz support on Mac OS X uses the CarbonCore 18805b261ecSmrg framework whose AddResource function conflicts here. */ 1894642e01fSmrg#ifdef __APPLE__ 19005b261ecSmrg#define AddResource Darwin_X_AddResource 19105b261ecSmrg#endif 19235c4bbdfSmrgextern _X_EXPORT Bool AddResource(XID id, 19335c4bbdfSmrg RESTYPE type, 19435c4bbdfSmrg void *value); 19535c4bbdfSmrg 19635c4bbdfSmrgextern _X_EXPORT void FreeResource(XID /*id */ , 19735c4bbdfSmrg RESTYPE /*skipDeleteFuncType */ ); 19835c4bbdfSmrg 19935c4bbdfSmrgextern _X_EXPORT void FreeResourceByType(XID /*id */ , 20035c4bbdfSmrg RESTYPE /*type */ , 20135c4bbdfSmrg Bool /*skipFree */ ); 20235c4bbdfSmrg 20335c4bbdfSmrgextern _X_EXPORT Bool ChangeResourceValue(XID id, 20435c4bbdfSmrg RESTYPE rtype, 20535c4bbdfSmrg void *value); 20635c4bbdfSmrg 20735c4bbdfSmrgextern _X_EXPORT void FindClientResourcesByType(ClientPtr client, 20835c4bbdfSmrg RESTYPE type, 20935c4bbdfSmrg FindResType func, 21035c4bbdfSmrg void *cdata); 21135c4bbdfSmrg 21235c4bbdfSmrgextern _X_EXPORT void FindAllClientResources(ClientPtr client, 21335c4bbdfSmrg FindAllRes func, 21435c4bbdfSmrg void *cdata); 21535c4bbdfSmrg 21635c4bbdfSmrg/** @brief Iterate through all subresources of a resource. 21735c4bbdfSmrg 21835c4bbdfSmrg @note The XID argument provided to the FindAllRes function 21935c4bbdfSmrg may be 0 for subresources that don't have an XID */ 22035c4bbdfSmrgextern _X_EXPORT void FindSubResources(void *resource, 22135c4bbdfSmrg RESTYPE type, 22235c4bbdfSmrg FindAllRes func, 22335c4bbdfSmrg void *cdata); 22435c4bbdfSmrg 22535c4bbdfSmrgextern _X_EXPORT void FreeClientNeverRetainResources(ClientPtr /*client */ ); 22635c4bbdfSmrg 22735c4bbdfSmrgextern _X_EXPORT void FreeClientResources(ClientPtr /*client */ ); 22805b261ecSmrg 2296747b715Smrgextern _X_EXPORT void FreeAllResources(void); 23005b261ecSmrg 23135c4bbdfSmrgextern _X_EXPORT Bool LegalNewID(XID /*id */ , 23235c4bbdfSmrg ClientPtr /*client */ ); 23335c4bbdfSmrg 23435c4bbdfSmrgextern _X_EXPORT void *LookupClientResourceComplex(ClientPtr client, 23535c4bbdfSmrg RESTYPE type, 23635c4bbdfSmrg FindComplexResType func, 23735c4bbdfSmrg void *cdata); 23835c4bbdfSmrg 23935c4bbdfSmrgextern _X_EXPORT int dixLookupResourceByType(void **result, 24035c4bbdfSmrg XID id, 24135c4bbdfSmrg RESTYPE rtype, 24235c4bbdfSmrg ClientPtr client, 24335c4bbdfSmrg Mask access_mode); 24435c4bbdfSmrg 24535c4bbdfSmrgextern _X_EXPORT int dixLookupResourceByClass(void **result, 24635c4bbdfSmrg XID id, 24735c4bbdfSmrg RESTYPE rclass, 24835c4bbdfSmrg ClientPtr client, 24935c4bbdfSmrg Mask access_mode); 25035c4bbdfSmrg 25135c4bbdfSmrgextern _X_EXPORT void GetXIDRange(int /*client */ , 25235c4bbdfSmrg Bool /*server */ , 25335c4bbdfSmrg XID * /*minp */ , 25435c4bbdfSmrg XID * /*maxp */ ); 25535c4bbdfSmrg 25635c4bbdfSmrgextern _X_EXPORT unsigned int GetXIDList(ClientPtr /*client */ , 25735c4bbdfSmrg unsigned int /*count */ , 25835c4bbdfSmrg XID * /*pids */ ); 25905b261ecSmrg 2606747b715Smrgextern _X_EXPORT RESTYPE lastResourceType; 2616747b715Smrgextern _X_EXPORT RESTYPE TypeMask; 26205b261ecSmrg 26335c4bbdfSmrg/** @brief A hashing function to be used for hashing resource IDs 2644642e01fSmrg 26535c4bbdfSmrg @param id The resource ID to hash 26635c4bbdfSmrg @param numBits The number of bits in the resulting hash. Must be >=0. 26705b261ecSmrg 26835c4bbdfSmrg @note This function is really only for handling 26935c4bbdfSmrg INITHASHSIZE..MAXHASHSIZE bit hashes, but will handle any number 27035c4bbdfSmrg of bits by either masking numBits lower bits of the ID or by 27135c4bbdfSmrg providing at most MAXHASHSIZE hashes. 27235c4bbdfSmrg*/ 273ed6184dfSmrgextern _X_EXPORT int HashResourceID(XID id, unsigned int numBits); 27405b261ecSmrg 27535c4bbdfSmrg#endif /* RESOURCE_H */ 276