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 <keithp@keithp.com> Reviewed-by: Jamey Sharp <jamey@minilop.net>
This commit is contained in:
parent
7ef612de78
commit
431781a921
|
@ -1576,10 +1576,6 @@ DbeExtensionInit(void)
|
||||||
if (!dbeWindowPrivResType)
|
if (!dbeWindowPrivResType)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!dixRegisterPrivateOffset(dbeDrawableResType,
|
|
||||||
offsetof(PixmapRec, devPrivates)))
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (i = 0; i < screenInfo.numScreens; i++)
|
for (i = 0; i < screenInfo.numScreens; i++)
|
||||||
{
|
{
|
||||||
/* For each screen, set up DBE screen privates and init DIX and DDX
|
/* For each screen, set up DBE screen privates and init DIX and DDX
|
||||||
|
|
|
@ -208,7 +208,7 @@ dixFreePrivates(PrivateRec *privates)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Table of devPrivates offsets */
|
/* Table of devPrivates offsets */
|
||||||
static const int offsetDefaults[] = {
|
static const int offsets[] = {
|
||||||
-1, /* RT_NONE */
|
-1, /* RT_NONE */
|
||||||
offsetof(WindowRec, devPrivates), /* RT_WINDOW */
|
offsetof(WindowRec, devPrivates), /* RT_WINDOW */
|
||||||
offsetof(PixmapRec, devPrivates), /* RT_PIXMAP */
|
offsetof(PixmapRec, devPrivates), /* RT_PIXMAP */
|
||||||
|
@ -216,45 +216,27 @@ static const int offsetDefaults[] = {
|
||||||
-1, /* RT_FONT */
|
-1, /* RT_FONT */
|
||||||
offsetof(CursorRec, devPrivates), /* RT_CURSOR */
|
offsetof(CursorRec, devPrivates), /* RT_CURSOR */
|
||||||
offsetof(ColormapRec, devPrivates), /* RT_COLORMAP */
|
offsetof(ColormapRec, devPrivates), /* RT_COLORMAP */
|
||||||
-1, /* RT_CMAPENTRY */
|
|
||||||
-1, /* RT_OTHERCLIENT */
|
|
||||||
-1 /* RT_PASSIVEGRAB */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int *offsets = NULL;
|
|
||||||
static int offsetsSize = 0;
|
|
||||||
|
|
||||||
/*
|
#define NUM_OFFSETS (sizeof (offsets) / sizeof (offsets[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;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
dixLookupPrivateOffset(RESTYPE type)
|
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;
|
type = type & TypeMask;
|
||||||
assert(type < offsetsSize);
|
if (type < NUM_OFFSETS)
|
||||||
return offsets[type];
|
return offsets[type];
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -268,15 +250,5 @@ dixResetPrivates(void)
|
||||||
items[i].size = 0;
|
items[i].size = 0;
|
||||||
}
|
}
|
||||||
nextPriv = 1;
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -254,8 +254,6 @@ CreateNewResourceType(DeleteType deleteFunc, char *name)
|
||||||
types = realloc(resourceTypes, (next + 1) * sizeof(*resourceTypes));
|
types = realloc(resourceTypes, (next + 1) * sizeof(*resourceTypes));
|
||||||
if (!types)
|
if (!types)
|
||||||
return 0;
|
return 0;
|
||||||
if (!dixRegisterPrivateOffset(next, -1))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
lastResourceType = next;
|
lastResourceType = next;
|
||||||
resourceTypes = types;
|
resourceTypes = types;
|
||||||
|
|
|
@ -107,26 +107,16 @@ dixFreePrivates(PrivateRec *privates);
|
||||||
extern _X_EXPORT int
|
extern _X_EXPORT int
|
||||||
dixResetPrivates(void);
|
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.
|
* 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
|
extern _X_EXPORT int
|
||||||
dixLookupPrivateOffset(RESTYPE type);
|
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
|
* Convenience macro for adding an offset to an object pointer
|
||||||
* when making a call to one of the devPrivates functions
|
* when making a call to one of the devPrivates functions
|
||||||
|
|
Loading…
Reference in New Issue