Skip to content

Commit

Permalink
DRI2: Allow multiple driver names.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Kristian Høgsberg <[email protected]>
Signed-off-by: Keith Packard <[email protected]>
  • Loading branch information
aaronp24 authored and keith-packard committed Jan 27, 2010
1 parent f57bc0e commit f311f2d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
44 changes: 37 additions & 7 deletions hw/xfree86/dri2/dri2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand All @@ -840,6 +869,7 @@ DRI2CloseScreen(ScreenPtr pScreen)
{
DRI2ScreenPtr ds = DRI2GetScreen(pScreen);

xfree(ds->driverNames);
xfree(ds);
dixSetPrivate(&pScreen->devPrivates, dri2ScreenPrivateKey, NULL);
}
Expand Down
9 changes: 9 additions & 0 deletions hw/xfree86/dri2/dri2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f311f2d

Please sign in to comment.