DRI2: Allow multiple driver names.

Each driver type (e.g. DRI2DriverDRI or DRI2DriverVDPAU) can have a name in the
driverNames array in DRI2InfoRec.  DRI2Connect returns the name for the driver
specified by driverType.  Also print names of supported drivers in
DRI2ScreenInit.

Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Aaron Plattner 2010-01-13 11:35:52 -08:00 committed by Keith Packard
parent f57bc0ede8
commit f311f2d047
2 changed files with 46 additions and 7 deletions

View File

@ -70,7 +70,8 @@ typedef struct _DRI2Drawable {
typedef struct _DRI2Screen *DRI2ScreenPtr;
typedef struct _DRI2Screen {
const char *driverName;
unsigned int numDrivers;
const char **driverNames;
const char *deviceName;
int fd;
unsigned int lastSequence;
@ -772,14 +773,12 @@ DRI2Connect(ScreenPtr pScreen, unsigned int driverType, int *fd,
{
DRI2ScreenPtr ds = DRI2GetScreen(pScreen);
if (ds == NULL)
if (ds == NULL || driverType >= ds->numDrivers ||
!ds->driverNames[driverType])
return FALSE;
if (driverType != DRI2DriverDRI)
return BadValue;
*fd = ds->fd;
*driverName = ds->driverName;
*driverName = ds->driverNames[driverType];
*deviceName = ds->deviceName;
return TRUE;
@ -800,6 +799,11 @@ Bool
DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
{
DRI2ScreenPtr ds;
const char* driverTypeNames[] = {
"DRI", /* DRI2DriverDRI */
"VDPAU", /* DRI2DriverVDPAU */
};
unsigned int i;
if (info->version < 3)
return FALSE;
@ -815,7 +819,6 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
return FALSE;
ds->fd = info->fd;
ds->driverName = info->driverName;
ds->deviceName = info->deviceName;
ds->CreateBuffer = info->CreateBuffer;
@ -828,9 +831,35 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
ds->GetMSC = info->GetMSC;
}
if (info->version == 3 || info->numDrivers == 0) {
/* Driver too old: use the old-style driverName field */
ds->numDrivers = 1;
ds->driverNames = xalloc(sizeof(*ds->driverNames));
if (!ds->driverNames) {
xfree(ds);
return FALSE;
}
ds->driverNames[0] = info->driverName;
} else {
ds->numDrivers = info->numDrivers;
ds->driverNames = xalloc(info->numDrivers * sizeof(*ds->driverNames));
if (!ds->driverNames) {
xfree(ds);
return FALSE;
}
memcpy(ds->driverNames, info->driverNames,
info->numDrivers * sizeof(*ds->driverNames));
}
dixSetPrivate(&pScreen->devPrivates, dri2ScreenPrivateKey, ds);
xf86DrvMsg(pScreen->myNum, X_INFO, "[DRI2] Setup complete\n");
for (i = 0; i < sizeof(driverTypeNames) / sizeof(driverTypeNames[0]); i++) {
if (i < ds->numDrivers && ds->driverNames[i]) {
xf86DrvMsg(pScreen->myNum, X_INFO, "[DRI2] %s driver: %s\n",
driverTypeNames[i], ds->driverNames[i]);
}
}
return TRUE;
}
@ -840,6 +869,7 @@ DRI2CloseScreen(ScreenPtr pScreen)
{
DRI2ScreenPtr ds = DRI2GetScreen(pScreen);
xfree(ds->driverNames);
xfree(ds);
dixSetPrivate(&pScreen->devPrivates, dri2ScreenPrivateKey, NULL);
}

View File

@ -164,9 +164,18 @@ typedef struct {
DRI2DestroyBufferProcPtr DestroyBuffer;
DRI2CopyRegionProcPtr CopyRegion;
DRI2WaitProcPtr Wait;
/* added in version 4 */
DRI2ScheduleSwapProcPtr ScheduleSwap;
DRI2GetMSCProcPtr GetMSC;
DRI2ScheduleWaitMSCProcPtr ScheduleWaitMSC;
/* number of drivers in the driverNames array */
unsigned int numDrivers;
/* array of driver names, indexed by DRI2Driver* driver types */
/* a name of NULL means that driver is not supported */
const char * const *driverNames;
} DRI2InfoRec, *DRI2InfoPtr;
extern _X_EXPORT int DRI2EventBase;