Allow RandR objects to be created before the associated ScreenRec.

xf86 drivers need to create RandR object in the PreInit stage,
before the ScreenRec is allocated. Changing the RandR DIX code
to permit this required the addition of functions that later associate the
objects with the related screen.

An additional change is that modes are now global, and no longer associated
with a specific screen. This change actually makes mode management cleaner
as there is no more per-screen list of modes to deal with.

This changes the RandR 1.2 ABI/API for drivers.
This commit is contained in:
Keith Packard 2006-11-08 21:36:35 -08:00
parent 20e9144c07
commit ec77a95a02
9 changed files with 255 additions and 170 deletions

View File

@ -51,7 +51,7 @@ sdk_HEADERS = compiler.h fourcc.h xf86.h xf86Module.h xf86Opt.h \
xf86PciInfo.h xf86Priv.h xf86Privstr.h xf86Resources.h \
xf86cmap.h xf86fbman.h xf86str.h $(XISDKINCS) \
$(XVSDKINCS) atKeynames.h xf86Version.h xorgVersion.h \
xf86sbusBus.h xf86xv.h xf86xvmc.h xf86xvpriv.h
xf86sbusBus.h xf86xv.h xf86xvmc.h xf86xvpriv.h xf86Keymap.h
DISTCLEANFILES = xf86Build.h
CLEANFILES = $(BUILT_SOURCES)

View File

@ -113,17 +113,24 @@ miRandRInit (ScreenPtr pScreen)
modeInfo.height = pScreen->height;
modeInfo.nameLength = strlen (name);
mode = RRModeGet (pScreen, &modeInfo, name);
mode = RRModeGet (&modeInfo, name);
if (!mode)
return FALSE;
crtc = RRCrtcCreate (pScreen, NULL);
crtc = RRCrtcCreate (NULL);
if (!crtc)
return FALSE;
if (!RRCrtcAttachScreen (crtc, pScreen))
{
RRCrtcDestroy (crtc);
return FALSE;
}
output = RROutputCreate (pScreen, "screen", 6, NULL);
output = RROutputCreate ("screen", 6, NULL);
if (!output)
return FALSE;
if (!RROutputAttachScreen (output, pScreen))
return FALSE;
if (!RROutputSetClones (output, NULL, 0))
return FALSE;
if (!RROutputSetModes (output, &mode, 1, 0))

View File

@ -103,8 +103,6 @@ RRCloseScreen (int i, ScreenPtr pScreen)
RRCrtcDestroy (pScrPriv->crtcs[j]);
for (j = pScrPriv->numOutputs - 1; j >= 0; j--)
RROutputDestroy (pScrPriv->outputs[j]);
for (j = pScrPriv->numModes - 1; j >= 0; j--)
RRModeDestroy (pScrPriv->modes[j]);
xfree (pScrPriv);
RRNScreens -= 1; /* ok, one fewer screen with RandR running */
@ -257,8 +255,6 @@ Bool RRScreenInit(ScreenPtr pScreen)
wrap (pScrPriv, pScreen, CloseScreen, RRCloseScreen);
pScrPriv->numModes = 0;
pScrPriv->modes = NULL;
pScrPriv->numOutputs = 0;
pScrPriv->outputs = NULL;
pScrPriv->numCrtcs = 0;

View File

@ -79,7 +79,6 @@ struct _rrMode {
xRRModeInfo mode;
char *name;
void *devPrivate;
ScreenPtr screen;
Bool userDefined;
};
@ -210,10 +209,6 @@ typedef struct _rrScrPriv {
CARD16 width, height; /* last known screen size */
Bool layoutChanged; /* screen layout changed */
/* modes, outputs and crtcs */
int numModes;
RRModePtr *modes;
int numOutputs;
RROutputPtr *outputs;
@ -457,8 +452,15 @@ RRCrtcChanged (RRCrtcPtr crtc, Bool layoutChanged);
* Create a CRTC
*/
RRCrtcPtr
RRCrtcCreate (ScreenPtr pScreen,
void *devPrivate);
RRCrtcCreate (void *devPrivate);
/*
* Attach a CRTC to a screen. Once done, this cannot be
* undone without destroying the CRTC; it is separate from Create
* only to allow an xf86-based driver to create objects in preinit
*/
Bool
RRCrtcAttachScreen (RRCrtcPtr crtc, ScreenPtr pScreen);
/*
* Notify the extension that the Crtc has been reconfigured,
@ -556,8 +558,7 @@ RRClientKnowsRates (ClientPtr pClient);
*/
RRModePtr
RRModeGet (ScreenPtr pScreen,
xRRModeInfo *modeInfo,
RRModeGet (xRRModeInfo *modeInfo,
const char *name);
void
@ -570,6 +571,12 @@ RRModePruneUnused (ScreenPtr pScreen);
void
RRModeDestroy (RRModePtr mode);
/*
* Return a list of modes that are valid for some output in pScreen
*/
RRModePtr *
RRModesForScreen (ScreenPtr pScreen, int *num_ret);
/*
* Initialize mode type
*/
@ -601,11 +608,18 @@ RROutputChanged (RROutputPtr output);
*/
RROutputPtr
RROutputCreate (ScreenPtr pScreen,
const char *name,
RROutputCreate (const char *name,
int nameLength,
void *devPrivate);
/*
* Attach an output to a screen, again split from creation so
* xf86 DDXen can create randr resources before the ScreenRec
* exists
*/
Bool
RROutputAttachScreen (RROutputPtr output, ScreenPtr pScreen);
/*
* Notify extension that output parameters have been changed
*/

View File

@ -32,43 +32,34 @@ void
RRCrtcChanged (RRCrtcPtr crtc, Bool layoutChanged)
{
ScreenPtr pScreen = crtc->pScreen;
rrScrPriv(pScreen);
crtc->changed = TRUE;
if (pScreen)
{
rrScrPriv(pScreen);
pScrPriv->changed = TRUE;
/*
* Send ConfigureNotify on any layout change
*/
if (layoutChanged)
pScrPriv->layoutChanged = TRUE;
}
}
/*
* Create a CRTC
*/
RRCrtcPtr
RRCrtcCreate (ScreenPtr pScreen,
void *devPrivate)
RRCrtcCreate (void *devPrivate)
{
rrScrPriv (pScreen);
RRCrtcPtr crtc;
RRCrtcPtr *crtcs;
crtc = xalloc (sizeof (RRCrtcRec));
if (!crtc)
return NULL;
if (pScrPriv->numCrtcs)
crtcs = xrealloc (pScrPriv->crtcs,
(pScrPriv->numCrtcs + 1) * sizeof (RRCrtcPtr));
else
crtcs = xalloc (sizeof (RRCrtcPtr));
if (!crtcs)
{
xfree (crtc);
return NULL;
}
crtc->id = FakeClientID (0);
crtc->pScreen = pScreen;
crtc->pScreen = NULL;
crtc->mode = NULL;
crtc->x = 0;
crtc->y = 0;
@ -84,11 +75,37 @@ RRCrtcCreate (ScreenPtr pScreen,
if (!AddResource (crtc->id, RRCrtcType, (pointer) crtc))
return NULL;
return crtc;
}
/*
* Attach a Crtc to a screen. This is done as a separate step
* so that an xf86-based driver can create CRTCs in PreInit
* before the Screen has been created
*/
Bool
RRCrtcAttachScreen (RRCrtcPtr crtc, ScreenPtr pScreen)
{
rrScrPriv (pScreen);
RRCrtcPtr *crtcs;
/* make space for the crtc pointer */
if (pScrPriv->numCrtcs)
crtcs = xrealloc (pScrPriv->crtcs,
(pScrPriv->numCrtcs + 1) * sizeof (RRCrtcPtr));
else
crtcs = xalloc (sizeof (RRCrtcPtr));
if (!crtcs)
return FALSE;
/* attach the screen and crtc together */
crtc->pScreen = pScreen;
pScrPriv->crtcs = crtcs;
pScrPriv->crtcs[pScrPriv->numCrtcs++] = crtc;
RRCrtcChanged (crtc, TRUE);
return crtc;
return TRUE;
}
/*
@ -243,7 +260,6 @@ RRCrtcSet (RRCrtcPtr crtc,
RROutputConfigPtr outputs)
{
ScreenPtr pScreen = crtc->pScreen;
rrScrPriv(pScreen);
/* See if nothing changed */
if (crtc->mode == mode &&
@ -255,7 +271,10 @@ RRCrtcSet (RRCrtcPtr crtc,
{
return TRUE;
}
if (pScreen)
{
#if RANDR_12_INTERFACE
rrScrPriv(pScreen);
if (pScrPriv->rrCrtcSet)
{
return (*pScrPriv->rrCrtcSet) (pScreen, crtc, mode, x, y,
@ -294,6 +313,7 @@ RRCrtcSet (RRCrtcPtr crtc,
}
#endif
RRTellChanged (pScreen);
}
return FALSE;
}
@ -311,6 +331,9 @@ RRCrtcDestroyResource (pointer value, XID pid)
{
RRCrtcPtr crtc = (RRCrtcPtr) value;
ScreenPtr pScreen = crtc->pScreen;
if (pScreen)
{
rrScrPriv(pScreen);
int i;
@ -324,9 +347,10 @@ RRCrtcDestroyResource (pointer value, XID pid)
break;
}
}
}
if (crtc->gammaRed)
xfree (crtc->gammaRed);
xfree (value);
xfree (crtc);
return 1;
}
@ -343,15 +367,18 @@ RRCrtcGammaSet (RRCrtcPtr crtc,
Bool ret = TRUE;
#if RANDR_12_INTERFACE
ScreenPtr pScreen = crtc->pScreen;
rrScrPriv(pScreen);
#endif
memcpy (crtc->gammaRed, red, crtc->gammaSize * sizeof (CARD16));
memcpy (crtc->gammaGreen, green, crtc->gammaSize * sizeof (CARD16));
memcpy (crtc->gammaBlue, blue, crtc->gammaSize * sizeof (CARD16));
#if RANDR_12_INTERFACE
if (pScreen)
{
rrScrPriv(pScreen);
if (pScrPriv->rrCrtcSetGamma)
ret = (*pScrPriv->rrCrtcSetGamma) (pScreen, crtc);
}
#endif
return ret;
}
@ -433,6 +460,9 @@ ProcRRGetCrtcInfo (ClientPtr client)
if (!crtc)
return RRErrorBase + BadRRCrtc;
/* All crtcs must be associated with screens before client
* requests are processed
*/
pScreen = crtc->pScreen;
pScrPriv = rrGetScrPriv(pScreen);
@ -589,7 +619,7 @@ ProcRRSetCrtcConfig (ClientPtr client)
for (j = 0; j < outputs[i].output->numCrtcs; j++)
if (outputs[i].output->crtcs[j] == crtc)
break;
if (j == outputs[j].output->numCrtcs)
if (j == outputs[i].output->numCrtcs)
{
if (outputs)
xfree (outputs);

View File

@ -44,7 +44,7 @@ RROldModeAdd (RROutputPtr output, RRScreenSizePtr size, int refresh)
modeInfo.dotClock = ((CARD32) size->width * (CARD32) size->height *
(CARD32) refresh);
modeInfo.nameLength = strlen (name);
mode = RRModeGet (pScreen, &modeInfo, name);
mode = RRModeGet (&modeInfo, name);
if (!mode)
return NULL;
for (i = 0; i < output->numModes; i++)
@ -90,12 +90,19 @@ RRScanOldConfig (ScreenPtr pScreen, Rotation rotations)
if (pScrPriv->numOutputs == 0 &&
pScrPriv->numCrtcs == 0)
{
crtc = RRCrtcCreate (pScreen, NULL);
crtc = RRCrtcCreate (NULL);
if (!crtc)
return;
output = RROutputCreate (pScreen, "default", 7, NULL);
if (!RRCrtcAttachScreen (crtc, pScreen))
{
RRCrtcDestroy (crtc);
return;
}
output = RROutputCreate ("default", 7, NULL);
if (!output)
return;
if (!RROutputAttachScreen (output, pScreen))
return;
RROutputSetCrtcs (output, &crtc, 1);
RROutputSetCrtc (output, crtc);
RROutputSetConnection (output, RR_Connected);
@ -206,7 +213,6 @@ RRGetInfo (ScreenPtr pScreen)
if (pScrPriv->nSizes)
RRScanOldConfig (pScreen, rotations);
#endif
RRModePruneUnused (pScreen);
RRTellChanged (pScreen);
return TRUE;
}

View File

@ -42,19 +42,23 @@ RRModeEqual (xRRModeInfo *a, xRRModeInfo *b)
return TRUE;
}
/*
* Keep a list so it's easy to find modes in the resource database.
*/
static int num_modes;
static RRModePtr *modes;
RRModePtr
RRModeGet (ScreenPtr pScreen,
xRRModeInfo *modeInfo,
RRModeGet (xRRModeInfo *modeInfo,
const char *name)
{
rrScrPriv (pScreen);
int i;
RRModePtr mode;
RRModePtr *modes;
RRModePtr *newModes;
for (i = 0; i < pScrPriv->numModes; i++)
for (i = 0; i < num_modes; i++)
{
mode = pScrPriv->modes[i];
mode = modes[i];
if (RRModeEqual (&mode->mode, modeInfo) &&
!memcmp (name, mode->name, modeInfo->nameLength))
{
@ -71,16 +75,14 @@ RRModeGet (ScreenPtr pScreen,
mode->name = (char *) (mode + 1);
memcpy (mode->name, name, modeInfo->nameLength);
mode->name[modeInfo->nameLength] = '\0';
mode->screen = pScreen;
mode->userDefined = FALSE;
if (pScrPriv->numModes)
modes = xrealloc (pScrPriv->modes,
(pScrPriv->numModes + 1) * sizeof (RRModePtr));
if (num_modes)
newModes = xrealloc (modes, (num_modes + 1) * sizeof (RRModePtr));
else
modes = xalloc (sizeof (RRModePtr));
newModes = xalloc (sizeof (RRModePtr));
if (!modes)
if (!newModes)
{
xfree (mode);
return NULL;
@ -89,37 +91,64 @@ RRModeGet (ScreenPtr pScreen,
mode->mode.id = FakeClientID(0);
if (!AddResource (mode->mode.id, RRModeType, (pointer) mode))
return NULL;
modes = newModes;
modes[num_modes++] = mode;
/*
* give the caller a reference to this mode
*/
++mode->refcnt;
pScrPriv->modes = modes;
pScrPriv->modes[pScrPriv->numModes++] = mode;
pScrPriv->changed = TRUE;
return mode;
}
RRModePtr *
RRModesForScreen (ScreenPtr pScreen, int *num_ret)
{
rrScrPriv(pScreen);
int o;
RRModePtr *screen_modes;
int num_screen_modes = 0;
screen_modes = xalloc ((num_modes ? num_modes : 1) * sizeof (RRModePtr));
for (o = 0; o < pScrPriv->numOutputs; o++)
{
RROutputPtr output = pScrPriv->outputs[o];
int m, n;
for (m = 0; m < output->numModes; m++)
{
RRModePtr mode = output->modes[m];
for (n = 0; n < num_screen_modes; n++)
if (screen_modes[n] == mode)
break;
if (n == num_screen_modes)
screen_modes[num_screen_modes++] = mode;
}
}
*num_ret = num_screen_modes;
return screen_modes;
}
void
RRModeDestroy (RRModePtr mode)
{
ScreenPtr pScreen;
rrScrPrivPtr pScrPriv;
int m;
if (--mode->refcnt > 0)
return;
pScreen = mode->screen;
pScrPriv = rrGetScrPriv (pScreen);
for (m = 0; m < pScrPriv->numModes; m++)
for (m = 0; m < num_modes; m++)
{
if (pScrPriv->modes[m] == mode)
if (modes[m] == mode)
{
memmove (pScrPriv->modes + m, pScrPriv->modes + m + 1,
(pScrPriv->numModes - m - 1) * sizeof (RRModePtr));
pScrPriv->numModes--;
if (!pScrPriv->numModes)
memmove (modes + m, modes + m + 1,
(num_modes - m - 1) * sizeof (RRModePtr));
num_modes--;
if (!num_modes)
{
xfree (pScrPriv->modes);
pScrPriv->modes = NULL;
xfree (modes);
modes = NULL;
}
pScrPriv->changed = TRUE;
break;
}
}
@ -137,6 +166,8 @@ RRModeDestroyResource (pointer value, XID pid)
Bool
RRModeInit (void)
{
assert (num_modes == 0);
assert (modes == NULL);
RRModeType = CreateNewResourceType (RRModeDestroyResource);
if (!RRModeType)
return FALSE;
@ -146,26 +177,6 @@ RRModeInit (void)
return TRUE;
}
void
RRModePruneUnused (ScreenPtr pScreen)
{
rrScrPriv (pScreen);
RRModePtr *unused, mode;
int m;
int num = pScrPriv->numModes;
unused = xalloc (num * sizeof (RRModePtr));
if (!unused)
return;
memcpy (unused, pScrPriv->modes, num * sizeof (RRModePtr));
for (m = 0; m < num; m++) {
mode = unused[m];
if (mode->refcnt == 1 && !mode->userDefined)
FreeResource (mode->mode.id, 0);
}
xfree (unused);
}
int
ProcRRCreateMode (ClientPtr client)
{
@ -205,4 +216,3 @@ ProcRRDeleteOutputMode (ClientPtr client)
(void) stuff;
return BadImplementation;
}

View File

@ -42,30 +42,17 @@ RROutputChanged (RROutputPtr output)
*/
RROutputPtr
RROutputCreate (ScreenPtr pScreen,
const char *name,
RROutputCreate (const char *name,
int nameLength,
void *devPrivate)
{
rrScrPriv (pScreen);
RROutputPtr output;
RROutputPtr *outputs;
output = xalloc (sizeof (RROutputRec) + nameLength + 1);
if (!output)
return NULL;
if (pScrPriv->numOutputs)
outputs = xrealloc (pScrPriv->outputs,
(pScrPriv->numOutputs + 1) * sizeof (RROutputPtr));
else
outputs = xalloc (sizeof (RROutputPtr));
if (!outputs)
{
xfree (output);
return NULL;
}
output->id = FakeClientID (0);
output->pScreen = pScreen;
output->pScreen = NULL;
output->name = (char *) (output + 1);
output->nameLength = nameLength;
memcpy (output->name, name, nameLength);
@ -91,10 +78,33 @@ RROutputCreate (ScreenPtr pScreen,
if (!AddResource (output->id, RROutputType, (pointer) output))
return NULL;
return output;
}
/*
* Attach an Output to a screen. This is done as a separate step
* so that an xf86-based driver can create Outputs in PreInit
* before the Screen has been created
*/
Bool
RROutputAttachScreen (RROutputPtr output, ScreenPtr pScreen)
{
rrScrPriv (pScreen);
RROutputPtr *outputs;
if (pScrPriv->numOutputs)
outputs = xrealloc (pScrPriv->outputs,
(pScrPriv->numOutputs + 1) * sizeof (RROutputPtr));
else
outputs = xalloc (sizeof (RROutputPtr));
if (!outputs)
return FALSE;
output->pScreen = pScreen;
pScrPriv->outputs = outputs;
pScrPriv->outputs[pScrPriv->numOutputs++] = output;
RROutputChanged (output);
return output;
return TRUE;
}
/*

View File

@ -360,6 +360,13 @@ ProcRRGetScreenResources (ClientPtr client)
}
else
{
RRModePtr *modes;
int num_modes;
modes = RRModesForScreen (pScreen, &num_modes);
if (!modes)
return BadAlloc;
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.length = 0;
@ -367,15 +374,15 @@ ProcRRGetScreenResources (ClientPtr client)
rep.configTimestamp = pScrPriv->lastConfigTime.milliseconds;
rep.nCrtcs = pScrPriv->numCrtcs;
rep.nOutputs = pScrPriv->numOutputs;
rep.nModes = pScrPriv->numModes;;
rep.nModes = num_modes;
rep.nbytesNames = 0;
for (i = 0; i < pScrPriv->numModes; i++)
rep.nbytesNames += pScrPriv->modes[i]->mode.nameLength;
for (i = 0; i < num_modes; i++)
rep.nbytesNames += modes[i]->mode.nameLength;
rep.length = (pScrPriv->numCrtcs +
pScrPriv->numOutputs +
pScrPriv->numModes * (SIZEOF(xRRModeInfo) >> 2) +
num_modes * (SIZEOF(xRRModeInfo) >> 2) +
((rep.nbytesNames + 3) >> 2));
extraLen = rep.length << 2;
@ -383,15 +390,18 @@ ProcRRGetScreenResources (ClientPtr client)
{
extra = xalloc (extraLen);
if (!extra)
{
xfree (modes);
return BadAlloc;
}
}
else
extra = NULL;
crtcs = (RRCrtc *) extra;
outputs = (RROutput *) (crtcs + pScrPriv->numCrtcs);
modeinfos = (xRRModeInfo *) (outputs + pScrPriv->numOutputs);
names = (CARD8 *) (modeinfos + pScrPriv->numModes);
names = (CARD8 *) (modeinfos + num_modes);
for (i = 0; i < pScrPriv->numCrtcs; i++)
{
@ -407,9 +417,10 @@ ProcRRGetScreenResources (ClientPtr client)
swapl (&outputs[i], n);
}
for (i = 0; i < pScrPriv->numModes; i++)
for (i = 0; i < num_modes; i++)
{
modeinfos[i] = pScrPriv->modes[i]->mode;
RRModePtr mode = modes[i];
modeinfos[i] = mode->mode;
if (client->swapped)
{
swapl (&modeinfos[i].id, n);
@ -426,10 +437,11 @@ ProcRRGetScreenResources (ClientPtr client)
swaps (&modeinfos[i].nameLength, n);
swapl (&modeinfos[i].modeFlags, n);
}
memcpy (names, pScrPriv->modes[i]->name,
pScrPriv->modes[i]->mode.nameLength);
names += pScrPriv->modes[i]->mode.nameLength;
memcpy (names, mode->name,
mode->mode.nameLength);
names += mode->mode.nameLength;
}
xfree (modes);
assert (((((char *) names - (char *) extra) + 3) >> 2) == rep.length);
}