devPrivates rework: hook up new mechanism in backwards-compatibility mode
on existing structures that support devPrivates.
This commit is contained in:
parent
aaef4d6a41
commit
c45f676208
|
@ -124,8 +124,15 @@ AddInputDevice(DeviceProc deviceProc, Bool autoStart)
|
||||||
#ifdef XKB
|
#ifdef XKB
|
||||||
dev->xkb_interest = NULL;
|
dev->xkb_interest = NULL;
|
||||||
#endif
|
#endif
|
||||||
dev->nPrivates = 0;
|
/* must pre-allocate one private for the new devPrivates support */
|
||||||
dev->devPrivates = NULL;
|
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->unwrapProc = NULL;
|
||||||
dev->coreEvents = TRUE;
|
dev->coreEvents = TRUE;
|
||||||
dev->inited = FALSE;
|
dev->inited = FALSE;
|
||||||
|
|
32
dix/main.c
32
dix/main.c
|
@ -715,18 +715,28 @@ AddScreen(
|
||||||
xfree(pScreen);
|
xfree(pScreen);
|
||||||
return -1;
|
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->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->ClipNotify = 0; /* for R4 ddx compatibility */
|
||||||
pScreen->CreateScreenResources = 0;
|
pScreen->CreateScreenResources = 0;
|
||||||
|
|
||||||
|
|
|
@ -279,8 +279,8 @@ dixLookupPrivateOffset(RESTYPE type)
|
||||||
/*
|
/*
|
||||||
* Called from the main loop to reset the subsystem.
|
* Called from the main loop to reset the subsystem.
|
||||||
*/
|
*/
|
||||||
static void ResetExtensionPrivates(void);
|
static int ResetExtensionPrivates(void);
|
||||||
static void ResetClientPrivates(void);
|
static int ResetClientPrivates(void);
|
||||||
static void ResetScreenPrivates(void);
|
static void ResetScreenPrivates(void);
|
||||||
static void ResetWindowPrivates(void);
|
static void ResetWindowPrivates(void);
|
||||||
static void ResetGCPrivates(void);
|
static void ResetGCPrivates(void);
|
||||||
|
@ -307,8 +307,8 @@ dixResetPrivates(void)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* reset legacy devPrivates support */
|
/* reset legacy devPrivates support */
|
||||||
ResetExtensionPrivates();
|
if (!ResetExtensionPrivates() || !ResetClientPrivates())
|
||||||
ResetClientPrivates();
|
return FALSE;
|
||||||
ResetScreenPrivates();
|
ResetScreenPrivates();
|
||||||
ResetWindowPrivates();
|
ResetWindowPrivates();
|
||||||
ResetGCPrivates();
|
ResetGCPrivates();
|
||||||
|
@ -317,10 +317,14 @@ dixResetPrivates(void)
|
||||||
ResetDevicePrivateIndex();
|
ResetDevicePrivateIndex();
|
||||||
|
|
||||||
/* register basic resource offsets */
|
/* register basic resource offsets */
|
||||||
if (!dixRegisterPrivateOffset(RT_WINDOW, offsetof(WindowRec,devPrivates)))
|
return dixRegisterPrivateOffset(RT_WINDOW,
|
||||||
return FALSE;
|
offsetof(WindowRec, devPrivates)) &&
|
||||||
|
dixRegisterPrivateOffset(RT_PIXMAP,
|
||||||
return TRUE;
|
offsetof(PixmapRec, devPrivates)) &&
|
||||||
|
dixRegisterPrivateOffset(RT_GC,
|
||||||
|
offsetof(GC, devPrivates)) &&
|
||||||
|
dixRegisterPrivateOffset(RT_COLORMAP,
|
||||||
|
offsetof(ColormapRec, devPrivates));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -343,15 +347,18 @@ int extensionPrivateLen;
|
||||||
unsigned *extensionPrivateSizes;
|
unsigned *extensionPrivateSizes;
|
||||||
unsigned totalExtensionSize;
|
unsigned totalExtensionSize;
|
||||||
|
|
||||||
static void
|
static int
|
||||||
ResetExtensionPrivates()
|
ResetExtensionPrivates()
|
||||||
{
|
{
|
||||||
extensionPrivateCount = 0;
|
extensionPrivateCount = 1;
|
||||||
extensionPrivateLen = 0;
|
extensionPrivateLen = 1;
|
||||||
xfree(extensionPrivateSizes);
|
xfree(extensionPrivateSizes);
|
||||||
extensionPrivateSizes = (unsigned *)NULL;
|
extensionPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
|
||||||
totalExtensionSize =
|
if (!extensionPrivateSizes)
|
||||||
((sizeof(ExtensionEntry) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
|
return FALSE;
|
||||||
|
*extensionPrivateSizes = 0;
|
||||||
|
totalExtensionSize = PadToLong(sizeof(ExtensionEntry)) + sizeof(DevUnion);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_X_EXPORT int
|
_X_EXPORT int
|
||||||
|
@ -400,15 +407,18 @@ int clientPrivateLen;
|
||||||
unsigned *clientPrivateSizes;
|
unsigned *clientPrivateSizes;
|
||||||
unsigned totalClientSize;
|
unsigned totalClientSize;
|
||||||
|
|
||||||
static void
|
static int
|
||||||
ResetClientPrivates()
|
ResetClientPrivates()
|
||||||
{
|
{
|
||||||
clientPrivateCount = 0;
|
clientPrivateCount = 1;
|
||||||
clientPrivateLen = 0;
|
clientPrivateLen = 1;
|
||||||
xfree(clientPrivateSizes);
|
xfree(clientPrivateSizes);
|
||||||
clientPrivateSizes = (unsigned *)NULL;
|
clientPrivateSizes = (unsigned *)xalloc(sizeof(unsigned));
|
||||||
totalClientSize =
|
if (!clientPrivateSizes)
|
||||||
((sizeof(ClientRec) + sizeof(long) - 1) / sizeof(long)) * sizeof(long);
|
return FALSE;
|
||||||
|
*clientPrivateSizes = 0;
|
||||||
|
totalClientSize = PadToLong(sizeof(ClientRec)) + sizeof(DevUnion);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_X_EXPORT int
|
_X_EXPORT int
|
||||||
|
@ -457,7 +467,7 @@ int screenPrivateCount;
|
||||||
static void
|
static void
|
||||||
ResetScreenPrivates()
|
ResetScreenPrivates()
|
||||||
{
|
{
|
||||||
screenPrivateCount = 0;
|
screenPrivateCount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this can be called after some screens have been created,
|
/* this can be called after some screens have been created,
|
||||||
|
@ -499,7 +509,7 @@ static int windowPrivateCount;
|
||||||
static void
|
static void
|
||||||
ResetWindowPrivates()
|
ResetWindowPrivates()
|
||||||
{
|
{
|
||||||
windowPrivateCount = 0;
|
windowPrivateCount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_X_EXPORT int
|
_X_EXPORT int
|
||||||
|
@ -549,7 +559,7 @@ static int gcPrivateCount;
|
||||||
static void
|
static void
|
||||||
ResetGCPrivates()
|
ResetGCPrivates()
|
||||||
{
|
{
|
||||||
gcPrivateCount = 0;
|
gcPrivateCount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_X_EXPORT int
|
_X_EXPORT int
|
||||||
|
@ -598,7 +608,7 @@ static int pixmapPrivateCount;
|
||||||
static void
|
static void
|
||||||
ResetPixmapPrivates()
|
ResetPixmapPrivates()
|
||||||
{
|
{
|
||||||
pixmapPrivateCount = 0;
|
pixmapPrivateCount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_X_EXPORT int
|
_X_EXPORT int
|
||||||
|
@ -649,7 +659,7 @@ int colormapPrivateCount;
|
||||||
static void
|
static void
|
||||||
ResetColormapPrivates()
|
ResetColormapPrivates()
|
||||||
{
|
{
|
||||||
colormapPrivateCount = 0;
|
colormapPrivateCount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -734,5 +744,5 @@ AllocateDevicePrivate(DeviceIntPtr device, int index)
|
||||||
static void
|
static void
|
||||||
ResetDevicePrivateIndex(void)
|
ResetDevicePrivateIndex(void)
|
||||||
{
|
{
|
||||||
devicePrivateIndex = 0;
|
devicePrivateIndex = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,13 @@ typedef struct _Private {
|
||||||
struct _Private *next;
|
struct _Private *next;
|
||||||
} PrivateRec;
|
} 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.
|
* Request pre-allocated private space for your driver/module.
|
||||||
* A non-null pScreen argument restricts to objects on a given screen.
|
* A non-null pScreen argument restricts to objects on a given screen.
|
||||||
|
@ -156,4 +163,7 @@ dixLookupPrivateOffset(RESTYPE type);
|
||||||
extern int
|
extern int
|
||||||
dixRegisterPrivateOffset(RESTYPE type, unsigned offset);
|
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 */
|
#endif /* PRIVATES_H */
|
||||||
|
|
Loading…
Reference in New Issue