xfree86: Clean up DPMS support

Rather than setting up a per-screen private, just conditionally
initialize ScrnInfoRec::DPMSSet based on the config options, and inspect
that to determine whether DPMS is supported.

We also move the "turn the screen back on at CloseScreen" logic into the
DPMS extension's (new) reset hook. This would be a behavior change for
the non-xfree86 servers, if any of them had non-stub DPMS support.

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
Adam Jackson 2017-03-24 12:30:56 -04:00
parent 21eda7464d
commit 8ed0b00fce
3 changed files with 16 additions and 85 deletions

View File

@ -354,10 +354,16 @@ SProcDPMSDispatch(ClientPtr client)
}
}
static void
DPMSCloseDownExtension(ExtensionEntry *e)
{
DPMSSet(serverClient, DPMSModeOn);
}
void
DPMSExtensionInit(void)
{
AddExtension(DPMSExtensionName, 0, 0,
ProcDPMSDispatch, SProcDPMSDispatch,
NULL, StandardMinorOpcode);
DPMSCloseDownExtension, StandardMinorOpcode);
}

View File

@ -47,50 +47,29 @@
#include "xf86VGAarbiter.h"
#endif
#ifdef DPMSExtension
static DevPrivateKeyRec DPMSKeyRec;
static DevPrivateKey DPMSKey;
static Bool DPMSClose(ScreenPtr pScreen);
static int DPMSCount = 0;
#endif
Bool
xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
{
#ifdef DPMSExtension
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
DPMSPtr pDPMS;
void *DPMSOpt;
MessageType enabled_from;
MessageType enabled_from = X_DEFAULT;
Bool enabled = TRUE;
DPMSKey = &DPMSKeyRec;
if (!dixRegisterPrivateKey(&DPMSKeyRec, PRIVATE_SCREEN, sizeof(DPMSRec)))
return FALSE;
pDPMS = dixLookupPrivate(&pScreen->devPrivates, DPMSKey);
pScrn->DPMSSet = set;
pDPMS->Flags = flags;
DPMSOpt = xf86FindOption(pScrn->options, "dpms");
if (DPMSDisabledSwitch) {
enabled_from = X_CMDLINE;
DPMSEnabled = FALSE;
enabled = FALSE;
}
else if (DPMSOpt) {
enabled_from = X_CONFIG;
DPMSEnabled = xf86CheckBoolOption(pScrn->options, "dpms", FALSE);
enabled = xf86CheckBoolOption(pScrn->options, "dpms", FALSE);
xf86MarkOptionUsed(DPMSOpt);
}
else {
enabled_from = X_DEFAULT;
DPMSEnabled = TRUE;
}
if (DPMSEnabled)
if (enabled) {
xf86DrvMsg(pScreen->myNum, enabled_from, "DPMS enabled\n");
pDPMS->Enabled = DPMSEnabled;
pDPMS->CloseScreen = pScreen->CloseScreen;
pScreen->CloseScreen = DPMSClose;
DPMSCount++;
pScrn->DPMSSet = set;
}
return TRUE;
#else
return FALSE;
@ -99,45 +78,10 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
#ifdef DPMSExtension
static Bool
DPMSClose(ScreenPtr pScreen)
{
DPMSPtr pDPMS;
ScrnInfoPtr pScrn;
/* This shouldn't happen */
if (DPMSKey == NULL)
return FALSE;
pDPMS = dixLookupPrivate(&pScreen->devPrivates, DPMSKey);
/* This shouldn't happen */
if (!pDPMS)
return FALSE;
pScreen->CloseScreen = pDPMS->CloseScreen;
pScrn = xf86ScreenToScrn(pScreen);
/*
* Turn on DPMS when shutting down. If this function can be used
* depends on the order the driver wraps things. If this is called
* after the driver has shut down everything the driver will have
* to deal with this internally.
*/
if (pScrn->vtSema && pScrn->DPMSSet) {
pScrn->DPMSSet(pScrn, DPMSModeOn, 0);
}
if (--DPMSCount == 0)
DPMSKey = NULL;
return pScreen->CloseScreen(pScreen);
}
static void
DPMSSetScreen(ScrnInfoPtr pScrn, int level)
{
ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
DPMSPtr pDPMS = dixLookupPrivate(&pScreen->devPrivates, DPMSKey);
if (pDPMS && pScrn->DPMSSet && pDPMS->Enabled && pScrn->vtSema) {
if (pScrn->DPMSSet && pScrn->vtSema) {
xf86VGAarbiterLock(pScrn);
pScrn->DPMSSet(pScrn, level, 0);
xf86VGAarbiterUnlock(pScrn);
@ -156,9 +100,6 @@ DPMSSet(ClientPtr client, int level)
DPMSPowerLevel = level;
if (DPMSKey == NULL)
return Success;
if (level != DPMSModeOn) {
if (xf86IsUnblank(screenIsSaved)) {
rc = dixSaveScreens(client, SCREEN_SAVER_FORCER, ScreenSaverActive);
@ -184,10 +125,7 @@ DPMSSet(ClientPtr client, int level)
static Bool
DPMSSupportedOnScreen(ScrnInfoPtr pScrn)
{
ScreenPtr pScreen = xf86ScrnToScreen(pScrn);
DPMSPtr pDPMS = dixLookupPrivate(&pScreen->devPrivates, DPMSKey);
return pDPMS && pScrn->DPMSSet;
return pScrn->DPMSSet != NULL;
}
/*
@ -199,10 +137,6 @@ DPMSSupported(void)
{
int i;
if (DPMSKey == NULL) {
return FALSE;
}
/* For each screen, check if DPMS is supported */
for (i = 0; i < xf86NumScreens; i++) {
if (DPMSSupportedOnScreen(xf86Screens[i]))

View File

@ -102,15 +102,6 @@ typedef struct {
Bool autoAddGPU;
} xf86InfoRec, *xf86InfoPtr;
#ifdef DPMSExtension
/* Private info for DPMS */
typedef struct {
CloseScreenProcPtr CloseScreen;
Bool Enabled;
int Flags;
} DPMSRec, *DPMSPtr;
#endif
/* ISC's cc can't handle ~ of UL constants, so explicitly type cast them. */
#define XLED1 ((unsigned long) 0x00000001)
#define XLED2 ((unsigned long) 0x00000002)