[PATCH xserver 2/3] dix: Lift DPMS to a screen hook

Adam Jackson ajax at redhat.com
Fri Mar 24 16:30:57 UTC 2017


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>
---
 Xext/Makefile.am             |  4 +-
 Xext/dpms.c                  | 64 +++++++++++++++++++++++++++++++
 Xext/dpmsstubs.c             | 47 -----------------------
 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/xf86DPMS.c | 89 +++++++-------------------------------------
 hw/xnest/Makefile.am         |  6 ---
 hw/xwayland/Makefile.am      |  1 -
 hw/xwin/Makefile.am          |  1 -
 include/scrnintstr.h         |  3 ++
 13 files changed, 114 insertions(+), 200 deletions(-)
 delete mode 100644 Xext/dpmsstubs.c

diff --git a/Xext/Makefile.am b/Xext/Makefile.am
index 1ceb980..32a27eb 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 291dad0..abc67ef 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 f05d1e9..0000000
--- 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 d53a3d9..15a2cbd 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)
+void
+dmxDPMSBackend(DMXScreenInfo *dmxScreen, int level)
 {
-    return dpmsSupported;
-}
-
-/** This is used by clients (e.g., xset) to set the DPMS level. */
-int
-DPMSSet(ClientPtr client, 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 772fa2f..8c4fe9d 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 e441dce..ae095e3 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 b2b4996..5d2f403 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 f0f9fee..7033397 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 a5324e0..ee49548 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 eb550c0..c77da64 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 a3c9fce..770e87f 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 0846230..e71240a 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 f174549..207289a 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
-- 
2.9.3



More information about the xorg-devel mailing list