From: Keith Packard <[email protected]> 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 <[email protected]> Reviewed-by: Jamey Sharp <[email protected]> --- dbe/dbe.c | 4 --- dix/privates.c | 53 +++++++++++++-------------------------------------- dix/resource.c | 2 - include/privates.h | 18 +++------------- 4 files changed, 18 insertions(+), 59 deletions(-) diff --git a/dbe/dbe.c b/dbe/dbe.c index 825d2e0..73142df 100644 --- a/dbe/dbe.c +++ b/dbe/dbe.c @@ -1583,10 +1583,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 diff --git a/dix/privates.c b/dix/privates.c index e3e7274..76e79ed 100644 --- a/dix/privates.c +++ b/dix/privates.c @@ -246,7 +246,7 @@ dixRegisterPrivateDeleteFunc(const DevPrivateKey key, } /* 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 */ @@ -258,40 +258,25 @@ static const int offsetDefaults[] = { -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 *)xrealloc(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); + + assert(type < NUM_OFFSETS); return offsets[type]; } @@ -308,15 +293,5 @@ dixResetPrivates(void) DeleteCallbackList(&items[i].deletefuncs); } nextPriv = 1; - - /* reset offsets */ - if (offsets) - xfree(offsets); - offsetsSize = sizeof(offsetDefaults); - offsets = xalloc(offsetsSize); - offsetsSize /= sizeof(int); - if (!offsets) - return FALSE; - memcpy(offsets, offsetDefaults, sizeof(offsetDefaults)); return TRUE; } diff --git a/dix/resource.c b/dix/resource.c index 91d0cfb..3c9a37c 100644 --- a/dix/resource.c +++ b/dix/resource.c @@ -208,8 +208,6 @@ CreateNewResourceType(DeleteType deleteFunc, char *name) (next + 1) * sizeof(DeleteType)); if (!funcs) return 0; - if (!dixRegisterPrivateOffset(next, -1)) - return 0; lastResourceType = next; DeleteFuncs = funcs; diff --git a/include/privates.h b/include/privates.h index 3c5c321..f8a6fbf 100644 --- a/include/privates.h +++ b/include/privates.h @@ -84,26 +84,16 @@ 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 */ -- 1.7.0 _______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel
