devPrivates rework: hook up new mechanism in backwards-compatibility mode

on existing structures that support devPrivates.
This commit is contained in:
Eamon Walsh 2007-03-07 11:22:42 -05:00 committed by Eamon Walsh
parent aaef4d6a41
commit c45f676208
4 changed files with 76 additions and 39 deletions

View File

@ -124,8 +124,15 @@ AddInputDevice(DeviceProc deviceProc, Bool autoStart)
#ifdef XKB
dev->xkb_interest = NULL;
#endif
dev->nPrivates = 0;
dev->devPrivates = NULL;
/* must pre-allocate one private for the new devPrivates support */
dev->nPrivates = 1;
dev->devPrivates = (DevUnion *)xalloc(sizeof(DevUnion));
if (!dev->devPrivates) {
xfree(dev);
return NULL;
}
dev->devPrivates[0].ptr = NULL;
dev->unwrapProc = NULL;
dev->coreEvents = TRUE;
dev->inited = FALSE;

View File

@ -715,18 +715,28 @@ AddScreen(
xfree(pScreen);
return -1;
}
/* must pre-allocate one private for the new devPrivates support */
pScreen->WindowPrivateLen = 1;
pScreen->WindowPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
pScreen->totalWindowSize = PadToLong(sizeof(WindowRec)) + sizeof(DevUnion);
pScreen->GCPrivateLen = 1;
pScreen->GCPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
pScreen->totalGCSize = PadToLong(sizeof(GC)) + sizeof(DevUnion);
pScreen->PixmapPrivateLen = 1;
pScreen->PixmapPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
pScreen->totalPixmapSize = BitmapBytePad(8 * (sizeof(PixmapRec) +
sizeof(DevUnion)));
if (pScreen->WindowPrivateSizes && pScreen->GCPrivateSizes &&
pScreen->PixmapPrivateSizes)
*pScreen->WindowPrivateSizes = *pScreen->GCPrivateSizes =
*pScreen->PixmapPrivateSizes = 0;
else {
xfree(pScreen);
return -1;
}
pScreen->myNum = i;
pScreen->WindowPrivateLen = 0;
pScreen->WindowPrivateSizes = (unsigned *)NULL;
pScreen->totalWindowSize =
((sizeof(WindowRec) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
pScreen->GCPrivateLen = 0;
pScreen->GCPrivateSizes = (unsigned *)NULL;
pScreen->totalGCSize =
((sizeof(GC) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
pScreen->PixmapPrivateLen = 0;
pScreen->PixmapPrivateSizes = (unsigned *)NULL;
pScreen->totalPixmapSize = BitmapBytePad(sizeof(PixmapRec)*8);
pScreen->ClipNotify = 0; /* for R4 ddx compatibility */
pScreen->CreateScreenResources = 0;

View File

@ -279,8 +279,8 @@ dixLookupPrivateOffset(RESTYPE type)
/*
* Called from the main loop to reset the subsystem.
*/
static void ResetExtensionPrivates(void);
static void ResetClientPrivates(void);
static int ResetExtensionPrivates(void);
static int ResetClientPrivates(void);
static void ResetScreenPrivates(void);
static void ResetWindowPrivates(void);
static void ResetGCPrivates(void);
@ -307,8 +307,8 @@ dixResetPrivates(void)
return FALSE;
/* reset legacy devPrivates support */
ResetExtensionPrivates();
ResetClientPrivates();
if (!ResetExtensionPrivates() || !ResetClientPrivates())
return FALSE;
ResetScreenPrivates();
ResetWindowPrivates();
ResetGCPrivates();
@ -317,10 +317,14 @@ dixResetPrivates(void)
ResetDevicePrivateIndex();
/* register basic resource offsets */
if (!dixRegisterPrivateOffset(RT_WINDOW, offsetof(WindowRec,devPrivates)))
return FALSE;
return TRUE;
return dixRegisterPrivateOffset(RT_WINDOW,
offsetof(WindowRec, devPrivates)) &&
dixRegisterPrivateOffset(RT_PIXMAP,
offsetof(PixmapRec, devPrivates)) &&
dixRegisterPrivateOffset(RT_GC,
offsetof(GC, devPrivates)) &&
dixRegisterPrivateOffset(RT_COLORMAP,
offsetof(ColormapRec, devPrivates));
}
/*
@ -343,15 +347,18 @@ int extensionPrivateLen;
unsigned *extensionPrivateSizes;
unsigned totalExtensionSize;
static void
static int
ResetExtensionPrivates()
{
extensionPrivateCount = 0;
extensionPrivateLen = 0;
extensionPrivateCount = 1;
extensionPrivateLen = 1;
xfree(extensionPrivateSizes);
extensionPrivateSizes = (unsigned *)NULL;
totalExtensionSize =
((sizeof(ExtensionEntry) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
extensionPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
if (!extensionPrivateSizes)
return FALSE;
*extensionPrivateSizes = 0;
totalExtensionSize = PadToLong(sizeof(ExtensionEntry)) + sizeof(DevUnion);
return TRUE;
}
_X_EXPORT int
@ -400,15 +407,18 @@ int clientPrivateLen;
unsigned *clientPrivateSizes;
unsigned totalClientSize;
static void
static int
ResetClientPrivates()
{
clientPrivateCount = 0;
clientPrivateLen = 0;
clientPrivateCount = 1;
clientPrivateLen = 1;
xfree(clientPrivateSizes);
clientPrivateSizes = (unsigned *)NULL;
totalClientSize =
((sizeof(ClientRec) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
clientPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
if (!clientPrivateSizes)
return FALSE;
*clientPrivateSizes = 0;
totalClientSize = PadToLong(sizeof(ClientRec)) + sizeof(DevUnion);
return TRUE;
}
_X_EXPORT int
@ -457,7 +467,7 @@ int screenPrivateCount;
static void
ResetScreenPrivates()
{
screenPrivateCount = 0;
screenPrivateCount = 1;
}
/* this can be called after some screens have been created,
@ -499,7 +509,7 @@ static int windowPrivateCount;
static void
ResetWindowPrivates()
{
windowPrivateCount = 0;
windowPrivateCount = 1;
}
_X_EXPORT int
@ -549,7 +559,7 @@ static int gcPrivateCount;
static void
ResetGCPrivates()
{
gcPrivateCount = 0;
gcPrivateCount = 1;
}
_X_EXPORT int
@ -598,7 +608,7 @@ static int pixmapPrivateCount;
static void
ResetPixmapPrivates()
{
pixmapPrivateCount = 0;
pixmapPrivateCount = 1;
}
_X_EXPORT int
@ -649,7 +659,7 @@ int colormapPrivateCount;
static void
ResetColormapPrivates()
{
colormapPrivateCount = 0;
colormapPrivateCount = 1;
}
@ -734,5 +744,5 @@ AllocateDevicePrivate(DeviceIntPtr device, int index)
static void
ResetDevicePrivateIndex(void)
{
devicePrivateIndex = 0;
devicePrivateIndex = 1;
}

View File

@ -30,6 +30,13 @@ typedef struct _Private {
struct _Private *next;
} PrivateRec;
/*
* Backwards compatibility macro. Use to get the proper PrivateRec
* reference from any of the structure types that supported the old
* devPrivates mechanism.
*/
#define DEVPRIV_PTR(foo) ((PrivateRec **)(&(foo)->devPrivates[0].ptr))
/*
* Request pre-allocated private space for your driver/module.
* A non-null pScreen argument restricts to objects on a given screen.
@ -156,4 +163,7 @@ dixLookupPrivateOffset(RESTYPE type);
extern int
dixRegisterPrivateOffset(RESTYPE type, unsigned offset);
/* Used by the legacy support, don't rely on this being here */
#define PadToLong(w) ((((w) + sizeof(long)-1) / sizeof(long)) * sizeof(long))
#endif /* PRIVATES_H */