xserver: Branch 'master' - 3 commits

Adam Jackson ajax at kemper.freedesktop.org
Mon Mar 27 20:11:00 UTC 2017


 Xext/Makefile.am                |    4 
 Xext/dpms.c                     |   98 +++++++++++++++++++++---
 Xext/dpmsproc.h                 |   11 ++
 Xext/dpmsstubs.c                |   47 -----------
 Xext/saver.c                    |    1 
 dix/globals.c                   |   10 --
 dix/main.c                      |   13 ---
 hw/dmx/dmxdpms.c                |   69 ++++------------
 hw/dmx/dmxdpms.h                |    3 
 hw/dmx/dmxscrinit.c             |   14 +++
 hw/kdrive/src/kdrive.c          |   12 --
 hw/vfb/Makefile.am              |    1 
 hw/xfree86/common/xf86Config.c  |    4 
 hw/xfree86/common/xf86DPMS.c    |  163 ++++------------------------------------
 hw/xfree86/common/xf86Privstr.h |    9 --
 hw/xnest/Makefile.am            |    6 -
 hw/xwayland/Makefile.am         |    1 
 hw/xwin/Makefile.am             |    1 
 include/globals.h               |   10 --
 include/scrnintstr.h            |    3 
 os/utils.c                      |    1 
 21 files changed, 158 insertions(+), 323 deletions(-)

New commits:
commit 33604187674ec78b2c0bf7f67af250acc80cf23a
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Mar 24 12:30:58 2017 -0400

    dpms: Consolidate a bunch of stuff into Xext/dpms.c
    
    Most of this is a legacy of the old "extmod" design where you could load
    _some_ extensions dynamically but only if the server had been built with
    support for them in the first place.
    
    Note that since we now only initialize the DPMS extension if at least
    one screen supports it, we no longer need DPMSCapableFlag: if it would
    be false, we would never read its value.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/Xext/dpms.c b/Xext/dpms.c
index abc67ef1f..efa715428 100644
--- a/Xext/dpms.c
+++ b/Xext/dpms.c
@@ -43,6 +43,13 @@ Equipment Corporation.
 #include "scrnintstr.h"
 #include "windowstr.h"
 
+CARD16 DPMSPowerLevel = 0;
+Bool DPMSDisabledSwitch = FALSE;
+CARD32 DPMSStandbyTime;
+CARD32 DPMSSuspendTime;
+CARD32 DPMSOffTime;
+Bool DPMSEnabled;
+
 Bool
 DPMSSupported(void)
 {
@@ -136,7 +143,7 @@ ProcDPMSCapable(ClientPtr client)
         .type = X_Reply,
         .sequenceNumber = client->sequence,
         .length = 0,
-        .capable = DPMSCapableFlag
+        .capable = TRUE
     };
 
     REQUEST_SIZE_MATCH(xDPMSCapableReq);
@@ -204,11 +211,9 @@ ProcDPMSEnable(ClientPtr client)
 
     REQUEST_SIZE_MATCH(xDPMSEnableReq);
 
-    if (DPMSCapableFlag) {
-        DPMSEnabled = TRUE;
-        if (!was_enabled)
-            SetScreenSaverTimer();
-    }
+    DPMSEnabled = TRUE;
+    if (!was_enabled)
+        SetScreenSaverTimer();
 
     return Success;
 }
@@ -427,7 +432,12 @@ DPMSCloseDownExtension(ExtensionEntry *e)
 void
 DPMSExtensionInit(void)
 {
-    AddExtension(DPMSExtensionName, 0, 0,
-                 ProcDPMSDispatch, SProcDPMSDispatch,
-                 DPMSCloseDownExtension, StandardMinorOpcode);
+    DPMSStandbyTime = DPMSSuspendTime = DPMSOffTime = ScreenSaverTime;
+    DPMSPowerLevel = DPMSModeOn;
+    DPMSEnabled = DPMSSupported();
+
+    if (DPMSEnabled)
+        AddExtension(DPMSExtensionName, 0, 0,
+                     ProcDPMSDispatch, SProcDPMSDispatch,
+                     DPMSCloseDownExtension, StandardMinorOpcode);
 }
diff --git a/Xext/dpmsproc.h b/Xext/dpmsproc.h
index 82dccbd67..1e24f1f55 100644
--- a/Xext/dpmsproc.h
+++ b/Xext/dpmsproc.h
@@ -9,7 +9,14 @@
 
 #include "dixstruct.h"
 
-int _X_EXPORT DPMSSet(ClientPtr client, int level);
-Bool _X_EXPORT DPMSSupported(void);
+extern int DPMSSet(ClientPtr client, int level);
+extern Bool DPMSSupported(void);
+
+extern CARD32 DPMSStandbyTime;
+extern CARD32 DPMSSuspendTime;
+extern CARD32 DPMSOffTime;
+extern CARD16 DPMSPowerLevel;
+extern Bool DPMSEnabled;
+extern Bool DPMSDisabledSwitch;
 
 #endif
diff --git a/Xext/saver.c b/Xext/saver.c
index bf3a23d9a..09497610a 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -53,6 +53,7 @@ in this Software without prior written authorization from the X Consortium.
 #endif
 #ifdef DPMSExtension
 #include <X11/extensions/dpmsconst.h>
+#include "dpmsproc.h"
 #endif
 #include "protocol-versions.h"
 
diff --git a/dix/globals.c b/dix/globals.c
index f36a938f7..acd5c4412 100644
--- a/dix/globals.c
+++ b/dix/globals.c
@@ -93,16 +93,6 @@ CARD32 ScreenSaverInterval;
 int ScreenSaverBlanking;
 int ScreenSaverAllowExposures;
 
-#ifdef DPMSExtension
-CARD16 DPMSPowerLevel = 0;
-Bool DPMSDisabledSwitch = FALSE;
-Bool DPMSCapableFlag = FALSE;
-CARD32 DPMSStandbyTime;
-CARD32 DPMSSuspendTime;
-CARD32 DPMSOffTime;
-Bool DPMSEnabled;
-#endif
-
 CARD32 defaultScreenSaverTime = DEFAULT_SCREEN_SAVER_TIME;
 CARD32 defaultScreenSaverInterval = DEFAULT_SCREEN_SAVER_INTERVAL;
 int defaultScreenSaverBlanking = DEFAULT_SCREEN_SAVER_BLANKING;
diff --git a/dix/main.c b/dix/main.c
index 4947062a5..f98643aa5 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -148,11 +148,7 @@ dix_main(int argc, char *argv[], char *envp[])
         ScreenSaverInterval = defaultScreenSaverInterval;
         ScreenSaverBlanking = defaultScreenSaverBlanking;
         ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
-#ifdef DPMSExtension
-        DPMSStandbyTime = DPMSSuspendTime = DPMSOffTime = ScreenSaverTime;
-        DPMSEnabled = TRUE;
-        DPMSPowerLevel = 0;
-#endif
+
         InitBlockAndWakeupHandlers();
         /* Perform any operating system dependent initializations you'd like */
         OsInit();
@@ -239,13 +235,6 @@ dix_main(int argc, char *argv[], char *envp[])
                        defaultCursorFont);
         }
 
-#ifdef DPMSExtension
-        /* check all screens, looking for DPMS Capabilities */
-        DPMSCapableFlag = DPMSSupported();
-        if (!DPMSCapableFlag)
-            DPMSEnabled = FALSE;
-#endif
-
 #ifdef PANORAMIX
         /*
          * Consolidate window and colourmap information for each screen
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 49b898da1..c2b522a18 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -64,8 +64,10 @@
 #include "loaderProcs.h"
 
 #include "xkbsrv.h"
-
 #include "picture.h"
+#ifdef DPMSExtension
+#include "dpmsproc.h"
+#endif
 
 /*
  * These paths define the way the config file search is done.  The escape
diff --git a/include/globals.h b/include/globals.h
index 693bdf4f2..44314f03f 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -26,16 +26,6 @@ extern _X_EXPORT char *SeatId;
 extern _X_EXPORT char *ConnectionInfo;
 extern _X_EXPORT sig_atomic_t inSignalContext;
 
-#ifdef DPMSExtension
-extern _X_EXPORT CARD32 DPMSStandbyTime;
-extern _X_EXPORT CARD32 DPMSSuspendTime;
-extern _X_EXPORT CARD32 DPMSOffTime;
-extern _X_EXPORT CARD16 DPMSPowerLevel;
-extern _X_EXPORT Bool DPMSEnabled;
-extern _X_EXPORT Bool DPMSDisabledSwitch;
-extern _X_EXPORT Bool DPMSCapableFlag;
-#endif
-
 #ifdef PANORAMIX
 extern _X_EXPORT Bool PanoramiXExtensionDisabledHack;
 #endif
diff --git a/os/utils.c b/os/utils.c
index ac55cd79f..3f8bac5c6 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -135,6 +135,7 @@ Bool noDamageExtension = FALSE;
 Bool noDbeExtension = FALSE;
 #endif
 #ifdef DPMSExtension
+#include "dpmsproc.h"
 Bool noDPMSExtension = FALSE;
 #endif
 #ifdef GLXEXT
commit 7f1ef9289d974fc2bacc968ae0b5d7714382cb9e
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Mar 24 12:30:57 2017 -0400

    dix: Lift DPMS to a screen hook
    
    Following on from the previous change, this adds a DPMS hook to the
    ScreenRec and uses that to infer DPMS support. As a result we can drop
    the dpms stub code from Xext.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 1ceb9803d..32a27eba8 100644
--- a/Xext/Makefile.am
+++ b/Xext/Makefile.am
@@ -1,4 +1,4 @@
-noinst_LTLIBRARIES = libXext.la libXextdpmsstubs.la libXvidmode.la
+noinst_LTLIBRARIES = libXext.la libXvidmode.la
 
 AM_CFLAGS = $(DIX_CFLAGS)
 
@@ -96,8 +96,6 @@ endif
 libXext_la_SOURCES =		$(BUILTIN_SRCS)
 libXext_la_LIBADD =		$(BUILTIN_LIBS)
 
-libXextdpmsstubs_la_SOURCES = dpmsstubs.c
-
 # XVidMode extension
 libXvidmode_la_SOURCES = vidmode.c
 
diff --git a/Xext/dpms.c b/Xext/dpms.c
index 291dad023..abc67ef1f 100644
--- a/Xext/dpms.c
+++ b/Xext/dpms.c
@@ -40,6 +40,70 @@ Equipment Corporation.
 #include <X11/extensions/dpmsproto.h>
 #include "dpmsproc.h"
 #include "extinit.h"
+#include "scrnintstr.h"
+#include "windowstr.h"
+
+Bool
+DPMSSupported(void)
+{
+    int i;
+
+    /* For each screen, check if DPMS is supported */
+    for (i = 0; i < screenInfo.numScreens; i++)
+        if (screenInfo.screens[i]->DPMS != NULL)
+            return TRUE;
+
+    for (i = 0; i < screenInfo.numGPUScreens; i++)
+        if (screenInfo.gpuscreens[i]->DPMS != NULL)
+            return TRUE;
+
+    return FALSE;
+}
+
+static Bool
+isUnblank(int mode)
+{
+    switch (mode) {
+    case SCREEN_SAVER_OFF:
+    case SCREEN_SAVER_FORCER:
+        return TRUE;
+    case SCREEN_SAVER_ON:
+    case SCREEN_SAVER_CYCLE:
+        return FALSE;
+    default:
+        return TRUE;
+    }
+}
+
+int
+DPMSSet(ClientPtr client, int level)
+{
+    int rc, i;
+
+    DPMSPowerLevel = level;
+
+    if (level != DPMSModeOn) {
+        if (isUnblank(screenIsSaved)) {
+            rc = dixSaveScreens(client, SCREEN_SAVER_FORCER, ScreenSaverActive);
+            if (rc != Success)
+                return rc;
+        }
+    } else if (!isUnblank(screenIsSaved)) {
+        rc = dixSaveScreens(client, SCREEN_SAVER_OFF, ScreenSaverReset);
+        if (rc != Success)
+            return rc;
+    }
+
+    for (i = 0; i < screenInfo.numScreens; i++)
+        if (screenInfo.screens[i]->DPMS != NULL)
+            screenInfo.screens[i]->DPMS(screenInfo.screens[i], level);
+
+    for (i = 0; i < screenInfo.numGPUScreens; i++)
+        if (screenInfo.gpuscreens[i]->DPMS != NULL)
+            screenInfo.gpuscreens[i]->DPMS(screenInfo.gpuscreens[i], level);
+
+    return Success;
+}
 
 static int
 ProcDPMSGetVersion(ClientPtr client)
diff --git a/Xext/dpmsstubs.c b/Xext/dpmsstubs.c
deleted file mode 100644
index f05d1e9f9..000000000
--- a/Xext/dpmsstubs.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*****************************************************************
-
-Copyright (c) 1996 Digital Equipment Corporation, Maynard, Massachusetts.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
-DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
-BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
-IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of Digital Equipment Corporation
-shall not be used in advertising or otherwise to promote the sale, use or other
-dealings in this Software without prior written authorization from Digital
-Equipment Corporation.
-
-******************************************************************/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "dpmsproc.h"
-
-#define FALSE 0
-
-Bool
-DPMSSupported(void)
-{
-    return FALSE;
-}
-
-int
-DPMSSet(ClientPtr client, int level)
-{
-    return Success;
-}
diff --git a/hw/dmx/dmxdpms.c b/hw/dmx/dmxdpms.c
index d53a3d998..15a2cbd8d 100644
--- a/hw/dmx/dmxdpms.c
+++ b/hw/dmx/dmxdpms.c
@@ -53,10 +53,7 @@
 #include "windowstr.h"          /* For screenIsSaved */
 #include <X11/extensions/dpms.h>
 
-static unsigned long dpmsGeneration = 0;
-static Bool dpmsSupported = TRUE;
-
-static void
+static int
 _dmxDPMSInit(DMXScreenInfo * dmxScreen)
 {
     int event_base, error_base;
@@ -65,14 +62,9 @@ _dmxDPMSInit(DMXScreenInfo * dmxScreen)
     BOOL state;
     const char *monitor;
 
-    if (dpmsGeneration != serverGeneration) {
-        dpmsSupported = TRUE;   /* On unless a backend doesn't support it */
-        dpmsGeneration = serverGeneration;
-    }
-
 #ifdef DPMSExtension
     if (DPMSDisabledSwitch)
-        dpmsSupported = FALSE;  /* -dpms turns off */
+        return FALSE;
 #endif
 
     dmxScreen->dpmsCapable = 0;
@@ -80,25 +72,21 @@ _dmxDPMSInit(DMXScreenInfo * dmxScreen)
     if (!dmxScreen->beDisplay) {
         dmxLogOutput(dmxScreen,
                      "Cannot determine if DPMS supported (detached screen)\n");
-        dpmsSupported = FALSE;
-        return;
+        return FALSE;
     }
 
     if (!DPMSQueryExtension(dmxScreen->beDisplay, &event_base, &error_base)) {
         dmxLogOutput(dmxScreen, "DPMS not supported\n");
-        dpmsSupported = FALSE;
-        return;
+        return FALSE;
     }
     if (!DPMSGetVersion(dmxScreen->beDisplay, &major, &minor)) {
         dmxLogOutput(dmxScreen, "DPMS not supported\n");
-        dpmsSupported = FALSE;
-        return;
+        return FALSE;
     }
     if (!DPMSCapable(dmxScreen->beDisplay)) {
         dmxLogOutput(dmxScreen, "DPMS %d.%d (not DPMS capable)\n",
                      major, minor);
-        dpmsSupported = FALSE;
-        return;
+        return FALSE;
     }
 
     DPMSInfo(dmxScreen->beDisplay, &level, &state);
@@ -134,20 +122,22 @@ _dmxDPMSInit(DMXScreenInfo * dmxScreen)
                  "DPMS %d.%d (%s, %s, %d %d %d)\n",
                  major, minor, monitor, state ? "enabled" : "disabled",
                  standby, suspend, off);
+    return TRUE;
 }
 
 /** Initialize DPMS support.  We save the current settings and turn off
  * DPMS.  The settings are restored in #dmxDPMSTerm. */
-void
+int
 dmxDPMSInit(DMXScreenInfo * dmxScreen)
 {
     int interval, preferBlanking, allowExposures;
 
     /* Turn off DPMS */
-    _dmxDPMSInit(dmxScreen);
+    if (!_dmxDPMSInit(dmxScreen))
+        return FALSE;
 
     if (!dmxScreen->beDisplay)
-        return;
+        return FALSE;
 
     /* Turn off screen saver */
     XGetScreenSaver(dmxScreen->beDisplay, &dmxScreen->savedTimeout, &interval,
@@ -156,6 +146,7 @@ dmxDPMSInit(DMXScreenInfo * dmxScreen)
                     preferBlanking, allowExposures);
     XResetScreenSaver(dmxScreen->beDisplay);
     dmxSync(dmxScreen, FALSE);
+    return TRUE;
 }
 
 /** Terminate DPMS support on \a dmxScreen.  We restore the settings
@@ -199,38 +190,12 @@ dmxDPMSWakeup(void)
 }
 
 #ifdef DPMSExtension
-/** This is called on each server generation.  It should determine if
- * DPMS is supported on all of the backends and, if so, return TRUE. */
-Bool
-DPMSSupported(void)
-{
-    return dpmsSupported;
-}
-
-/** This is used by clients (e.g., xset) to set the DPMS level. */
-int
-DPMSSet(ClientPtr client, int level)
+void
+dmxDPMSBackend(DMXScreenInfo *dmxScreen, int level)
 {
-    int i;
-
-    if (!dpmsSupported)
-        return Success;
-
-    if (level < 0)
-        level = DPMSModeOn;
-    if (level > 3)
-        level = DPMSModeOff;
-
-    DPMSPowerLevel = level;
-
-    for (i = 0; i < dmxNumScreens; i++) {
-        DMXScreenInfo *dmxScreen = &dmxScreens[i];
-
-        if (dmxScreen->beDisplay) {
-            DPMSForceLevel(dmxScreen->beDisplay, level);
-            dmxSync(dmxScreen, FALSE);
-        }
+    if (dmxScreen->beDisplay) {
+        DPMSForceLevel(dmxScreen->beDisplay, level);
+        dmxSync(dmxScreen, FALSE);
     }
-    return Success;
 }
 #endif
diff --git a/hw/dmx/dmxdpms.h b/hw/dmx/dmxdpms.h
index 772fa2f11..8c4fe9d4f 100644
--- a/hw/dmx/dmxdpms.h
+++ b/hw/dmx/dmxdpms.h
@@ -36,7 +36,8 @@
 
 #ifndef _DMXDPMS_H_
 #define _DMXDPMS_H_
-extern void dmxDPMSInit(DMXScreenInfo * dmxScreen);
+extern int dmxDPMSInit(DMXScreenInfo * dmxScreen);
 extern void dmxDPMSTerm(DMXScreenInfo * dmxScreen);
 extern void dmxDPMSWakeup(void);        /* Call when input is processed */
+extern void dmxDPMSBackend(DMXScreenInfo *dmxScreen, int level);
 #endif
diff --git a/hw/dmx/dmxscrinit.c b/hw/dmx/dmxscrinit.c
index e441dceef..ae095e300 100644
--- a/hw/dmx/dmxscrinit.c
+++ b/hw/dmx/dmxscrinit.c
@@ -75,6 +75,17 @@ DevPrivateKeyRec dmxColormapPrivateKeyRec;
 DevPrivateKeyRec dmxPictPrivateKeyRec;
 DevPrivateKeyRec dmxGlyphSetPrivateKeyRec;
 
+#ifdef DPMSExtension
+static void
+dmxDPMS(ScreenPtr pScreen, int level)
+{
+    DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
+    dmxDPMSBackend(dmxScreen, level);
+}
+#else
+#define dmxDPMS NULL
+#endif
+
 /** Initialize the parts of screen \a idx that require access to the
  *  back-end server. */
 void
@@ -103,7 +114,8 @@ dmxBEScreenInit(ScreenPtr pScreen)
     pScreen->blackPixel = dmxScreen->beBlackPixel;
 
     /* Handle screen savers and DPMS on the backend */
-    dmxDPMSInit(dmxScreen);
+    if (dmxDPMSInit(dmxScreen))
+        pScreen->DPMS = dmxDPMS;
 
     /* Create root window for screen */
     mask = CWBackPixel | CWEventMask | CWColormap | CWOverrideRedirect;
diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index b2b499669..5d2f403d6 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -1193,18 +1193,6 @@ OsVendorFatalError(const char *f, va_list args)
 {
 }
 
-int
-DPMSSet(ClientPtr client, int level)
-{
-    return Success;
-}
-
-Bool
-DPMSSupported(void)
-{
-    return FALSE;
-}
-
 /* These stubs can be safely removed once we can
  * split input and GPU parts in hotplug.h et al. */
 #ifdef CONFIG_UDEV_KMS
diff --git a/hw/vfb/Makefile.am b/hw/vfb/Makefile.am
index f0f9fee47..70333976c 100644
--- a/hw/vfb/Makefile.am
+++ b/hw/vfb/Makefile.am
@@ -16,7 +16,6 @@ XVFB_LIBS = \
         @XVFB_LIBS@ \
 	$(MAIN_LIB) \
 	$(XSERVER_LIBS) \
-	$(top_builddir)/Xext/libXextdpmsstubs.la \
 	$(top_builddir)/Xi/libXistubs.la
 
 Xvfb_LDADD = $(XVFB_LIBS) $(XVFB_SYS_LIBS) $(XSERVER_SYS_LIBS)
diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c
index a5324e0b1..ee495483e 100644
--- a/hw/xfree86/common/xf86DPMS.c
+++ b/hw/xfree86/common/xf86DPMS.c
@@ -47,6 +47,19 @@
 #include "xf86VGAarbiter.h"
 #endif
 
+#ifdef DPMSExtension
+static void
+xf86DPMS(ScreenPtr pScreen, int level)
+{
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
+    if (pScrn->DPMSSet && pScrn->vtSema) {
+        xf86VGAarbiterLock(pScrn);
+        pScrn->DPMSSet(pScrn, level, 0);
+        xf86VGAarbiterUnlock(pScrn);
+    }
+}
+#endif
+
 Bool
 xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
 {
@@ -69,84 +82,10 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
     if (enabled) {
         xf86DrvMsg(pScreen->myNum, enabled_from, "DPMS enabled\n");
         pScrn->DPMSSet = set;
+        pScreen->DPMS = xf86DPMS;
     }
     return TRUE;
 #else
     return FALSE;
 #endif
 }
-
-#ifdef DPMSExtension
-
-static void
-DPMSSetScreen(ScrnInfoPtr pScrn, int level)
-{
-    if (pScrn->DPMSSet && pScrn->vtSema) {
-        xf86VGAarbiterLock(pScrn);
-        pScrn->DPMSSet(pScrn, level, 0);
-        xf86VGAarbiterUnlock(pScrn);
-    }
-}
-
-/*
- * DPMSSet --
- *	Device dependent DPMS mode setting hook.  This is called whenever
- *	the DPMS mode is to be changed.
- */
-int
-DPMSSet(ClientPtr client, int level)
-{
-    int rc, i;
-
-    DPMSPowerLevel = level;
-
-    if (level != DPMSModeOn) {
-        if (xf86IsUnblank(screenIsSaved)) {
-            rc = dixSaveScreens(client, SCREEN_SAVER_FORCER, ScreenSaverActive);
-            if (rc != Success)
-                return rc;
-        }
-    } else if (!xf86IsUnblank(screenIsSaved)) {
-        rc = dixSaveScreens(client, SCREEN_SAVER_OFF, ScreenSaverReset);
-        if (rc != Success)
-            return rc;
-    }
-
-    /* For each screen, set the DPMS level */
-    for (i = 0; i < xf86NumScreens; i++) {
-        DPMSSetScreen(xf86Screens[i], level);
-    }
-    for (i = 0; i < xf86NumGPUScreens; i++) {
-        DPMSSetScreen(xf86GPUScreens[i], level);
-    }
-    return Success;
-}
-
-static Bool
-DPMSSupportedOnScreen(ScrnInfoPtr pScrn)
-{
-    return pScrn->DPMSSet != NULL;
-}
-
-/*
- * DPMSSupported --
- *	Return TRUE if any screen supports DPMS.
- */
-Bool
-DPMSSupported(void)
-{
-    int i;
-
-    /* For each screen, check if DPMS is supported */
-    for (i = 0; i < xf86NumScreens; i++) {
-        if (DPMSSupportedOnScreen(xf86Screens[i]))
-            return TRUE;
-    }
-    for (i = 0; i < xf86NumGPUScreens; i++) {
-        if (DPMSSupportedOnScreen(xf86GPUScreens[i]))
-            return TRUE;
-    }
-    return FALSE;
-}
-
-#endif                          /* DPMSExtension */
diff --git a/hw/xnest/Makefile.am b/hw/xnest/Makefile.am
index eb550c0f7..c77da6412 100644
--- a/hw/xnest/Makefile.am
+++ b/hw/xnest/Makefile.am
@@ -45,7 +45,6 @@ SRCS =	Args.c \
 
 XNEST_LIBS = \
         @XNEST_LIBS@ \
-	$(top_builddir)/Xext/libXextdpmsstubs.la \
 	$(top_builddir)/Xi/libXistubs.la
 
 Xnest_SOURCES = $(SRCS)
@@ -57,10 +56,5 @@ Xnest_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
 EXTRA_DIST = icon \
              screensaver
 
-# -UDPMSExtension for miinitext? can't put into 
-# OS_DEFINES???
-# EXT_DEFINES???
-# ICONFIGFILES -- SpecialCObjectRule
-
 relink:
 	$(AM_V_at)rm -f Xnest$(EXEEXT) && $(MAKE) Xnest$(EXEEXT)
diff --git a/hw/xwayland/Makefile.am b/hw/xwayland/Makefile.am
index a3c9fce48..770e87f9b 100644
--- a/hw/xwayland/Makefile.am
+++ b/hw/xwayland/Makefile.am
@@ -18,7 +18,6 @@ Xwayland_SOURCES =				\
 	xwayland-cvt.c				\
 	xwayland-vidmode.c			\
 	xwayland.h				\
-	$(top_srcdir)/Xext/dpmsstubs.c		\
 	$(top_srcdir)/Xi/stubs.c		\
 	$(top_srcdir)/mi/miinitext.c
 
diff --git a/hw/xwin/Makefile.am b/hw/xwin/Makefile.am
index 0846230b0..e71240a79 100644
--- a/hw/xwin/Makefile.am
+++ b/hw/xwin/Makefile.am
@@ -138,7 +138,6 @@ XWIN_SYS_LIBS += -ldxguid
 
 XWIN_LIBS += \
 	$(top_builddir)/pseudoramiX/libPseudoramiX.la \
-	$(top_builddir)/Xext/libXextdpmsstubs.la \
 	$(top_builddir)/Xi/libXistubs.la
 
 XWin_DEPENDENCIES = \
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index f174549c4..207289a91 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -400,6 +400,8 @@ typedef WindowPtr (*XYToWindowProcPtr)(ScreenPtr pScreen,
 
 typedef int (*NameWindowPixmapProcPtr)(WindowPtr, PixmapPtr, CARD32);
 
+typedef void (*DPMSProcPtr)(ScreenPtr pScreen, int level);
+
 /* Wrapping Screen procedures
 
    There are a few modules in the X server which dynamically add and
@@ -657,6 +659,7 @@ typedef struct _Screen {
 
     ReplaceScanoutPixmapProcPtr ReplaceScanoutPixmap;
     XYToWindowProcPtr XYToWindow;
+    DPMSProcPtr DPMS;
 } ScreenRec;
 
 static inline RegionPtr
commit 8ed0b00fceb34cdb54a0ea113c3cdff3b4c9e7e1
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Mar 24 12:30:56 2017 -0400

    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 at redhat.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/Xext/dpms.c b/Xext/dpms.c
index 4b620d58c..291dad023 100644
--- a/Xext/dpms.c
+++ b/Xext/dpms.c
@@ -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);
 }
diff --git a/hw/xfree86/common/xf86DPMS.c b/hw/xfree86/common/xf86DPMS.c
index 2b5a3ed1e..a5324e0b1 100644
--- a/hw/xfree86/common/xf86DPMS.c
+++ b/hw/xfree86/common/xf86DPMS.c
@@ -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]))
diff --git a/hw/xfree86/common/xf86Privstr.h b/hw/xfree86/common/xf86Privstr.h
index bb8f3ab68..e4b479f4f 100644
--- a/hw/xfree86/common/xf86Privstr.h
+++ b/hw/xfree86/common/xf86Privstr.h
@@ -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)


More information about the xorg-commit mailing list