Commit 431781a9 authored by Keith Packard's avatar Keith Packard

Remove dixRegisterPrivateOffset; hard-code devPrivates offsets instead

For predefined resource types, the offset of the devPrivates field was
already kept in a constant table. The only non-predefined type needing
this treatment was dbeDrawableResType, which is just a magic alias for
RT_PIXMAP.

This patch special-cases looking up RC_DRAWABLE offsets and uses the
table directly for everything else.
Signed-off-by: Keith Packard's avatarKeith Packard <keithp@keithp.com>
Reviewed-by: Jamey Sharp's avatarJamey Sharp <jamey@minilop.net>
parent 7ef612de
......@@ -1576,10 +1576,6 @@ DbeExtensionInit(void)
if (!dbeWindowPrivResType)
return;
if (!dixRegisterPrivateOffset(dbeDrawableResType,
offsetof(PixmapRec, devPrivates)))
return;
for (i = 0; i < screenInfo.numScreens; i++)
{
/* For each screen, set up DBE screen privates and init DIX and DDX
......
......@@ -208,7 +208,7 @@ dixFreePrivates(PrivateRec *privates)
}
/* Table of devPrivates offsets */
static const int offsetDefaults[] = {
static const int offsets[] = {
-1, /* RT_NONE */
offsetof(WindowRec, devPrivates), /* RT_WINDOW */
offsetof(PixmapRec, devPrivates), /* RT_PIXMAP */
......@@ -216,45 +216,27 @@ static const int offsetDefaults[] = {
-1, /* RT_FONT */
offsetof(CursorRec, devPrivates), /* RT_CURSOR */
offsetof(ColormapRec, devPrivates), /* RT_COLORMAP */
-1, /* RT_CMAPENTRY */
-1, /* RT_OTHERCLIENT */
-1 /* RT_PASSIVEGRAB */
};
static int *offsets = NULL;
static int offsetsSize = 0;
/*
* Specify where the devPrivates field is located in a structure type
*/
int
dixRegisterPrivateOffset(RESTYPE type, int offset)
{
type = type & TypeMask;
/* resize offsets table if necessary */
while (type >= offsetsSize) {
unsigned i = offsetsSize * 2 * sizeof(int);
offsets = (int *)realloc(offsets, i);
if (!offsets) {
offsetsSize = 0;
return FALSE;
}
for (i=offsetsSize; i < 2*offsetsSize; i++)
offsets[i] = -1;
offsetsSize *= 2;
}
offsets[type] = offset;
return TRUE;
}
#define NUM_OFFSETS (sizeof (offsets) / sizeof (offsets[0]))
int
dixLookupPrivateOffset(RESTYPE type)
{
/*
* Special kludge for DBE which registers a new resource type that
* points at pixmaps (thanks, DBE)
*/
if (type & RC_DRAWABLE) {
if (type == RT_WINDOW)
return offsets[RT_WINDOW & TypeMask];
else
return offsets[RT_PIXMAP & TypeMask];
}
type = type & TypeMask;
assert(type < offsetsSize);
return offsets[type];
if (type < NUM_OFFSETS)
return offsets[type];
return -1;
}
int
......@@ -268,15 +250,5 @@ dixResetPrivates(void)
items[i].size = 0;
}
nextPriv = 1;
/* reset offsets */
if (offsets)
free(offsets);
offsetsSize = sizeof(offsetDefaults);
offsets = malloc(offsetsSize);
offsetsSize /= sizeof(int);
if (!offsets)
return FALSE;
memcpy(offsets, offsetDefaults, sizeof(offsetDefaults));
return TRUE;
}
......@@ -254,8 +254,6 @@ CreateNewResourceType(DeleteType deleteFunc, char *name)
types = realloc(resourceTypes, (next + 1) * sizeof(*resourceTypes));
if (!types)
return 0;
if (!dixRegisterPrivateOffset(next, -1))
return 0;
lastResourceType = next;
resourceTypes = types;
......
......@@ -107,26 +107,16 @@ dixFreePrivates(PrivateRec *privates);
extern _X_EXPORT int
dixResetPrivates(void);
/*
* These next two functions are necessary because the position of
* the devPrivates field varies by structure and calling code might
* only know the resource type, not the structure definition.
*/
/*
* Looks up the offset where the devPrivates field is located.
* Returns -1 if no offset has been registered for the resource type.
* Returns -1 if the specified resource has no dev privates.
* The position of the devPrivates field varies by structure
* and calling code might only know the resource type, not the
* structure definition.
*/
extern _X_EXPORT int
dixLookupPrivateOffset(RESTYPE type);
/*
* Specifies the offset where the devPrivates field is located.
* A negative value indicates no devPrivates field is available.
*/
extern _X_EXPORT int
dixRegisterPrivateOffset(RESTYPE type, int offset);
/*
* Convenience macro for adding an offset to an object pointer
* when making a call to one of the devPrivates functions
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment