diff options
author | Keith Packard <keithp@keithp.com> | 2010-05-15 14:52:39 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2010-06-05 19:11:32 -0700 |
commit | 431781a921251d54782f0a4f194bbef1fabd1380 (patch) | |
tree | 474de8723f4d328709c5d92c4df68263cb4fec96 | |
parent | 7ef612de784daaed09ba13f4615c10714614033f (diff) |
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>
-rw-r--r-- | dbe/dbe.c | 4 | ||||
-rw-r--r-- | dix/privates.c | 58 | ||||
-rw-r--r-- | dix/resource.c | 2 | ||||
-rw-r--r-- | include/privates.h | 18 |
4 files changed, 19 insertions, 63 deletions
@@ -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 diff --git a/dix/privates.c b/dix/privates.c index 4a8a186dc..9ec6c46be 100644 --- a/dix/privates.c +++ b/dix/privates.c @@ -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; } diff --git a/dix/resource.c b/dix/resource.c index a6d115f65..ce025f9f0 100644 --- a/dix/resource.c +++ b/dix/resource.c @@ -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; diff --git a/include/privates.h b/include/privates.h index 7850dea6d..72f4d4028 100644 --- a/include/privates.h +++ b/include/privates.h @@ -108,26 +108,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 */ |