Lines Matching +full:client +full:- +full:id
75 * Copyright (c) 2005-2006, Oracle and/or its affiliates. All rights reserved.
105 * A resource ID is a 32 bit quantity, the upper 2 bits of which are
106 * off-limits for client-visible resources. The next 8 bits are
107 * used as client ID, and the low 22 bits come from the client.
108 * A resource ID is "hashed" by extracting and xoring subfields
111 * It is sometimes necessary for the server to create an ID that looks
112 * like it belongs to a client. This ID, however, must not be one
113 * the client actually can create, or we have the potential for conflict.
114 * The 31st bit of the ID is reserved for the server's use for this
115 * purpose. By setting CLIENT_ID(id) to the client, the SERVER_BIT to
116 * 1, and an otherwise arbitrary ID in the low 22 bits, we can create a
117 * resource "owned" by the client.
121 #include <dix-config.h>
152 static void RebuildTable(int /*client */
163 XID id; member
197 * @param[in] id Resource ID for the object.
203 GetDefaultBytes(void *value, XID id, ResourceSizePtr size) in GetDefaultBytes() argument
205 size->resourceSize = 0; in GetDefaultBytes()
206 size->pixmapRefSize = 0; in GetDefaultBytes()
207 size->refCnt = 1; in GetDefaultBytes()
244 int bytesPerPixel = drawable->bitsPerPixel >> 3; in GetDrawableBytes()
245 int numberOfPixels = drawable->width * drawable->height; in GetDrawableBytes()
261 * @param[in] id Resource ID of pixmap. If the pixmap hasn't been
262 * added as resource, just pass value->drawable.id.
268 GetPixmapBytes(void *value, XID id, ResourceSizePtr size) in GetPixmapBytes() argument
272 size->resourceSize = 0; in GetPixmapBytes()
273 size->pixmapRefSize = 0; in GetPixmapBytes()
274 size->refCnt = pixmap->refcnt; in GetPixmapBytes()
276 if (pixmap && pixmap->refcnt) in GetPixmapBytes()
278 DrawablePtr drawable = &pixmap->drawable; in GetPixmapBytes()
279 size->resourceSize = GetDrawableBytes(drawable); in GetPixmapBytes()
280 size->pixmapRefSize = size->resourceSize / pixmap->refcnt; in GetPixmapBytes()
291 * @param[in] id Resource ID of window.
297 GetWindowBytes(void *value, XID id, ResourceSizePtr size) in GetWindowBytes() argument
304 size->resourceSize = 0; in GetWindowBytes()
307 size->pixmapRefSize = 0; in GetWindowBytes()
309 size->refCnt = 1; in GetWindowBytes()
311 if (window->backgroundState == BackgroundPixmap) in GetWindowBytes()
313 PixmapPtr pixmap = window->background.pixmap; in GetWindowBytes()
314 pixmapSizeFunc(pixmap, pixmap->drawable.id, &pixmapSize); in GetWindowBytes()
315 size->pixmapRefSize += pixmapSize.pixmapRefSize; in GetWindowBytes()
317 if (window->border.pixmap && !window->borderIsPixel) in GetWindowBytes()
319 PixmapPtr pixmap = window->border.pixmap; in GetWindowBytes()
320 pixmapSizeFunc(pixmap, pixmap->drawable.id, &pixmapSize); in GetWindowBytes()
321 size->pixmapRefSize += pixmapSize.pixmapRefSize; in GetWindowBytes()
330 * @note Currently only sub-pixmaps are iterated
345 if (window->backgroundState == BackgroundPixmap) in FindWindowSubRes()
347 PixmapPtr pixmap = window->background.pixmap; in FindWindowSubRes()
348 func(window->background.pixmap, pixmap->drawable.id, RT_PIXMAP, cdata); in FindWindowSubRes()
350 if (window->border.pixmap && !window->borderIsPixel) in FindWindowSubRes()
352 PixmapPtr pixmap = window->border.pixmap; in FindWindowSubRes()
353 func(window->background.pixmap, pixmap->drawable.id, RT_PIXMAP, cdata); in FindWindowSubRes()
364 * @param[in] id Resource ID of graphics context.
370 GetGcBytes(void *value, XID id, ResourceSizePtr size) in GetGcBytes() argument
377 size->resourceSize = 0; in GetGcBytes()
380 size->pixmapRefSize = 0; in GetGcBytes()
382 size->refCnt = 1; in GetGcBytes()
383 if (gc->stipple) in GetGcBytes()
385 PixmapPtr pixmap = gc->stipple; in GetGcBytes()
386 pixmapSizeFunc(pixmap, pixmap->drawable.id, &pixmapSize); in GetGcBytes()
387 size->pixmapRefSize += pixmapSize.pixmapRefSize; in GetGcBytes()
389 if (gc->tile.pixmap && !gc->tileIsPixel) in GetGcBytes()
391 PixmapPtr pixmap = gc->tile.pixmap; in GetGcBytes()
392 pixmapSizeFunc(pixmap, pixmap->drawable.id, &pixmapSize); in GetGcBytes()
393 size->pixmapRefSize += pixmapSize.pixmapRefSize; in GetGcBytes()
402 * @note Currently only sub-pixmaps are iterated
417 if (gc->stipple) in FindGCSubRes()
419 PixmapPtr pixmap = gc->stipple; in FindGCSubRes()
420 func(pixmap, pixmap->drawable.id, RT_PIXMAP, cdata); in FindGCSubRes()
422 if (gc->tile.pixmap && !gc->tileIsPixel) in FindGCSubRes()
424 PixmapPtr pixmap = gc->tile.pixmap; in FindGCSubRes()
425 func(pixmap, pixmap->drawable.id, RT_PIXMAP, cdata); in FindGCSubRes()
432 [RT_NONE & (RC_LASTPREDEF - 1)] = {
438 [RT_WINDOW & (RC_LASTPREDEF - 1)] = {
444 [RT_PIXMAP & (RC_LASTPREDEF - 1)] = {
450 [RT_GC & (RC_LASTPREDEF - 1)] = {
456 [RT_FONT & (RC_LASTPREDEF - 1)] = {
462 [RT_CURSOR & (RC_LASTPREDEF - 1)] = {
468 [RT_COLORMAP & (RC_LASTPREDEF - 1)] = {
474 [RT_CMAPENTRY & (RC_LASTPREDEF - 1)] = {
480 [RT_OTHERCLIENT & (RC_LASTPREDEF - 1)] = {
486 [RT_PASSIVEGRAB & (RC_LASTPREDEF - 1)] = {
500 ResourceStateInfoRec rsi = { state, res->id, res->type, res->value }; in CallResourceStateCallback()
597 TypeMask = next - 1; in CreateNewResourceClass()
612 return bits - 1; in ilog2()
617 * Returns the client bit offset in the client + resources ID field
628 * When a new client is created, call this to allocate space
633 InitClientResources(ClientPtr client) in InitClientResources() argument
637 if (client == serverClient) { in InitClientResources()
640 TypeMask = RC_LASTPREDEF - 1; in InitClientResources()
647 clientTable[i = client->index].resources = in InitClientResources()
654 /* Many IDs allocated from the server client are visible to clients, in InitClientResources()
659 clientTable[i].fakeID = client->clientAsMask | in InitClientResources()
660 (client->index ? SERVER_BIT : SERVER_MINID); in InitClientResources()
669 HashResourceID(XID id, int numBits) in HashResourceID() argument
675 id &= mask; in HashResourceID()
677 return (id ^ (id >> numBits) ^ (id >> (numBits<<1))) & ~((~0) << numBits); in HashResourceID()
678 return (id ^ (id >> numBits)) & ~((~0) << numBits); in HashResourceID()
682 AvailableID(int client, XID id, XID maxid, XID goodid) in AvailableID() argument
686 if ((goodid >= id) && (goodid <= maxid)) in AvailableID()
688 for (; id <= maxid; id++) { in AvailableID()
689 res = clientTable[client].resources[HashResourceID(id, clientTable[client].hashsize)]; in AvailableID()
690 while (res && (res->id != id)) in AvailableID()
691 res = res->next; in AvailableID()
693 return id; in AvailableID()
699 GetXIDRange(int client, Bool server, XID *minp, XID *maxp) in GetXIDRange() argument
701 XID id, maxid; in GetXIDRange() local
707 id = (Mask) client << CLIENTOFFSET; in GetXIDRange()
709 id |= client ? SERVER_BIT : SERVER_MINID; in GetXIDRange()
710 maxid = id | RESOURCE_ID_MASK; in GetXIDRange()
712 for (resp = clientTable[client].resources, i = clientTable[client].buckets; in GetXIDRange()
713 --i >= 0;) { in GetXIDRange()
714 for (res = *resp++; res; res = res->next) { in GetXIDRange()
715 if ((res->id < id) || (res->id > maxid)) in GetXIDRange()
717 if (((res->id - id) >= (maxid - res->id)) ? in GetXIDRange()
718 (goodid = AvailableID(client, id, res->id - 1, goodid)) : in GetXIDRange()
719 !(goodid = AvailableID(client, res->id + 1, maxid, goodid))) in GetXIDRange()
720 maxid = res->id - 1; in GetXIDRange()
722 id = res->id + 1; in GetXIDRange()
725 if (id > maxid) in GetXIDRange()
726 id = maxid = 0; in GetXIDRange()
727 *minp = id; in GetXIDRange()
732 * GetXIDList is called by the XC-MISC extension's MiscGetXIDList function.
733 * This function tries to find count unused XIDs for the given client. It
739 * multiple ID's, like the Multi-buffering CreateImageBuffers request.
742 * possible IDs for the given client and pick the first count IDs
751 XID rc, id = pClient->clientAsMask; in GetXIDList() local
755 maxid = id | RESOURCE_ID_MASK; in GetXIDList()
756 while ((found < count) && (id <= maxid)) { in GetXIDList()
757 rc = dixLookupResourceByClass(&val, id, RC_ANY, serverClient, in GetXIDList()
760 pids[found++] = id; in GetXIDList()
762 id++; in GetXIDList()
768 * Return the next usable fake client ID.
772 * over-running another client.
776 FakeClientID(int client) in FakeClientID() argument
778 XID id, maxid; in FakeClientID() local
780 id = clientTable[client].fakeID++; in FakeClientID()
781 if (id != clientTable[client].endFakeID) in FakeClientID()
782 return id; in FakeClientID()
783 GetXIDRange(client, TRUE, &id, &maxid); in FakeClientID()
784 if (!id) { in FakeClientID()
785 if (!client) in FakeClientID()
787 MarkClientException(clients[client]); in FakeClientID()
788 id = ((Mask) client << CLIENTOFFSET) | (SERVER_BIT * 3); in FakeClientID()
789 maxid = id | RESOURCE_ID_MASK; in FakeClientID()
791 clientTable[client].fakeID = id + 1; in FakeClientID()
792 clientTable[client].endFakeID = maxid + 1; in FakeClientID()
793 return id; in FakeClientID()
797 AddResource(XID id, RESTYPE type, void *value) in AddResource() argument
799 int client; in AddResource() local
804 XSERVER_RESOURCE_ALLOC(id, type, value, TypeNameString(type)); in AddResource()
806 client = CLIENT_ID(id); in AddResource()
807 rrec = &clientTable[client]; in AddResource()
808 if (!rrec->buckets) { in AddResource()
809 ErrorF("[dix] AddResource(%lx, %x, %lx), client=%d \n", in AddResource()
810 (unsigned long) id, type, (unsigned long) value, client); in AddResource()
811 FatalError("client not in use\n"); in AddResource()
813 if ((rrec->elements >= 4 * rrec->buckets) && (rrec->hashsize < MAXHASHSIZE)) in AddResource()
814 RebuildTable(client); in AddResource()
815 head = &rrec->resources[HashResourceID(id, clientTable[client].hashsize)]; in AddResource()
818 (*resourceTypes[type & TypeMask].deleteFunc) (value, id); in AddResource()
821 res->next = *head; in AddResource()
822 res->id = id; in AddResource()
823 res->type = type; in AddResource()
824 res->value = value; in AddResource()
826 rrec->elements++; in AddResource()
832 RebuildTable(int client) in RebuildTable() argument
844 j = 2 * clientTable[client].buckets; in RebuildTable()
853 for (rptr = resources, tptr = tails; --j >= 0; rptr++, tptr++) { in RebuildTable()
857 clientTable[client].hashsize++; in RebuildTable()
858 for (j = clientTable[client].buckets, in RebuildTable()
859 rptr = clientTable[client].resources; --j >= 0; rptr++) { in RebuildTable()
861 next = res->next; in RebuildTable()
862 res->next = NULL; in RebuildTable()
863 tptr = &tails[HashResourceID(res->id, clientTable[client].hashsize)]; in RebuildTable()
865 *tptr = &res->next; in RebuildTable()
869 clientTable[client].buckets *= 2; in RebuildTable()
870 free(clientTable[client].resources); in RebuildTable()
871 clientTable[client].resources = resources; in RebuildTable()
880 resourceTypes[res->type & TypeMask].deleteFunc(res->value, res->id); in doFreeResource()
886 FreeResource(XID id, RESTYPE skipDeleteFuncType) in FreeResource() argument
894 if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) { in FreeResource()
895 head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)]; in FreeResource()
900 if (res->id == id) { in FreeResource()
901 RESTYPE rtype = res->type; in FreeResource()
904 XSERVER_RESOURCE_FREE(res->id, res->type, in FreeResource()
905 res->value, TypeNameString(res->type)); in FreeResource()
907 *prev = res->next; in FreeResource()
908 elements = --*eltptr; in FreeResource()
916 prev = &res->next; in FreeResource()
922 FreeResourceByType(XID id, RESTYPE type, Bool skipFree) in FreeResourceByType() argument
928 if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) { in FreeResourceByType()
929 head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)]; in FreeResourceByType()
933 if (res->id == id && res->type == type) { in FreeResourceByType()
935 XSERVER_RESOURCE_FREE(res->id, res->type, in FreeResourceByType()
936 res->value, TypeNameString(res->type)); in FreeResourceByType()
938 *prev = res->next; in FreeResourceByType()
939 clientTable[cid].elements--; in FreeResourceByType()
946 prev = &res->next; in FreeResourceByType()
952 * Change the value associated with a resource id. Caller
958 ChangeResourceValue(XID id, RESTYPE rtype, void *value) in ChangeResourceValue() argument
963 if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) { in ChangeResourceValue()
964 res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)]; in ChangeResourceValue()
966 for (; res; res = res->next) in ChangeResourceValue()
967 if ((res->id == id) && (res->type == rtype)) { in ChangeResourceValue()
968 res->value = value; in ChangeResourceValue()
982 FindClientResourcesByType(ClientPtr client, in FindClientResourcesByType() argument
990 if (!client) in FindClientResourcesByType()
991 client = serverClient; in FindClientResourcesByType()
993 resources = clientTable[client->index].resources; in FindClientResourcesByType()
994 eltptr = &clientTable[client->index].elements; in FindClientResourcesByType()
995 for (i = 0; i < clientTable[client->index].buckets; i++) { in FindClientResourcesByType()
997 next = this->next; in FindClientResourcesByType()
998 if (!type || this->type == type) { in FindClientResourcesByType()
1000 (*func) (this->value, this->id, cdata); in FindClientResourcesByType()
1018 FindAllClientResources(ClientPtr client, FindAllRes func, void *cdata) in FindAllClientResources() argument
1025 if (!client) in FindAllClientResources()
1026 client = serverClient; in FindAllClientResources()
1028 resources = clientTable[client->index].resources; in FindAllClientResources()
1029 eltptr = &clientTable[client->index].elements; in FindAllClientResources()
1030 for (i = 0; i < clientTable[client->index].buckets; i++) { in FindAllClientResources()
1032 next = this->next; in FindAllClientResources()
1034 (*func) (this->value, this->id, this->type, cdata); in FindAllClientResources()
1042 LookupClientResourceComplex(ClientPtr client, in LookupClientResourceComplex() argument
1051 if (!client) in LookupClientResourceComplex()
1052 client = serverClient; in LookupClientResourceComplex()
1054 resources = clientTable[client->index].resources; in LookupClientResourceComplex()
1055 for (i = 0; i < clientTable[client->index].buckets; i++) { in LookupClientResourceComplex()
1057 next = this->next; in LookupClientResourceComplex()
1058 if (!type || this->type == type) { in LookupClientResourceComplex()
1060 value = this->value; in LookupClientResourceComplex()
1061 if ((*func) (value, this->id, cdata)) in LookupClientResourceComplex()
1070 FreeClientNeverRetainResources(ClientPtr client) in FreeClientNeverRetainResources() argument
1078 if (!client) in FreeClientNeverRetainResources()
1081 resources = clientTable[client->index].resources; in FreeClientNeverRetainResources()
1082 eltptr = &clientTable[client->index].elements; in FreeClientNeverRetainResources()
1083 for (j = 0; j < clientTable[client->index].buckets; j++) { in FreeClientNeverRetainResources()
1086 RESTYPE rtype = this->type; in FreeClientNeverRetainResources()
1090 XSERVER_RESOURCE_FREE(this->id, this->type, in FreeClientNeverRetainResources()
1091 this->value, TypeNameString(this->type)); in FreeClientNeverRetainResources()
1093 *prev = this->next; in FreeClientNeverRetainResources()
1094 clientTable[client->index].elements--; in FreeClientNeverRetainResources()
1103 prev = &this->next; in FreeClientNeverRetainResources()
1109 FreeClientResources(ClientPtr client) in FreeClientResources() argument
1115 /* This routine shouldn't be called with a null client, but just in in FreeClientResources()
1118 if (!client) in FreeClientResources()
1121 HandleSaveSet(client); in FreeClientResources()
1123 resources = clientTable[client->index].resources; in FreeClientResources()
1124 for (j = 0; j < clientTable[client->index].buckets; j++) { in FreeClientResources()
1128 one which do a LookupID on another resource id (a Colormap id in this in FreeClientResources()
1140 XSERVER_RESOURCE_FREE(this->id, this->type, in FreeClientResources()
1141 this->value, TypeNameString(this->type)); in FreeClientResources()
1143 *head = this->next; in FreeClientResources()
1144 clientTable[client->index].elements--; in FreeClientResources()
1149 free(clientTable[client->index].resources); in FreeClientResources()
1150 clientTable[client->index].resources = NULL; in FreeClientResources()
1151 clientTable[client->index].buckets = 0; in FreeClientResources()
1159 for (i = currentMaxClients; --i >= 0;) { in FreeAllResources()
1166 LegalNewID(XID id, ClientPtr client) in LegalNewID() argument
1175 minid = client->clientAsMask | (client->index ? in LegalNewID()
1177 maxid = (clientTable[client->index].fakeID | RESOURCE_ID_MASK) + 1; in LegalNewID()
1178 if ((id >= minid) && (id <= maxid)) in LegalNewID()
1182 if (client->clientAsMask == (id & ~RESOURCE_ID_MASK)) { in LegalNewID()
1183 rc = dixLookupResourceByClass(&val, id, RC_ANY, serverClient, in LegalNewID()
1191 dixLookupResourceByType(void **result, XID id, RESTYPE rtype, in dixLookupResourceByType() argument
1192 ClientPtr client, Mask mode) in dixLookupResourceByType() argument
1194 int cid = CLIENT_ID(id); in dixLookupResourceByType()
1202 res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)]; in dixLookupResourceByType()
1204 for (; res; res = res->next) in dixLookupResourceByType()
1205 if (res->id == id && res->type == rtype) in dixLookupResourceByType()
1208 if (client) { in dixLookupResourceByType()
1209 client->errorValue = id; in dixLookupResourceByType()
1214 if (client) { in dixLookupResourceByType()
1215 cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type, in dixLookupResourceByType()
1216 res->value, RT_NONE, NULL, mode); in dixLookupResourceByType()
1223 *result = res->value; in dixLookupResourceByType()
1228 dixLookupResourceByClass(void **result, XID id, RESTYPE rclass, in dixLookupResourceByClass() argument
1229 ClientPtr client, Mask mode) in dixLookupResourceByClass() argument
1231 int cid = CLIENT_ID(id); in dixLookupResourceByClass()
1237 res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)]; in dixLookupResourceByClass()
1239 for (; res; res = res->next) in dixLookupResourceByClass()
1240 if (res->id == id && (res->type & rclass)) in dixLookupResourceByClass()
1243 if (client) { in dixLookupResourceByClass()
1244 client->errorValue = id; in dixLookupResourceByClass()
1249 if (client) { in dixLookupResourceByClass()
1250 cid = XaceHook(XACE_RESOURCE_ACCESS, client, id, res->type, in dixLookupResourceByClass()
1251 res->value, RT_NONE, NULL, mode); in dixLookupResourceByClass()
1256 *result = res->value; in dixLookupResourceByClass()