2 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Except as contained in this notice, the name of the copyright holder(s)
23 * and author(s) shall not be used in advertising or otherwise to promote
24 * the sale, use or other dealings in this Software without prior written
25 * authorization from the copyright holder(s) and author(s).
29 * This file contains the DPMS functions required by the extension.
32 #ifdef HAVE_XORG_CONFIG_H
33 #include <xorg-config.h>
39 #include "windowstr.h"
43 #include <X11/extensions/dpmsconst.h>
46 #ifdef XSERVER_LIBPCIACCESS
47 #include "xf86VGAarbiter.h"
51 static DevPrivateKeyRec DPMSKeyRec
;
52 static DevPrivateKey DPMSKey
;
53 static Bool
DPMSClose(ScreenPtr pScreen
);
54 static int DPMSCount
= 0;
58 xf86DPMSInit(ScreenPtr pScreen
, DPMSSetProcPtr set
, int flags
)
61 ScrnInfoPtr pScrn
= xf86ScreenToScrn(pScreen
);
64 MessageType enabled_from
;
66 DPMSKey
= &DPMSKeyRec
;
68 if (!dixRegisterPrivateKey(&DPMSKeyRec
, PRIVATE_SCREEN
, sizeof(DPMSRec
)))
71 pDPMS
= dixLookupPrivate(&pScreen
->devPrivates
, DPMSKey
);
74 DPMSOpt
= xf86FindOption(pScrn
->options
, "dpms");
75 if (DPMSDisabledSwitch
) {
76 enabled_from
= X_CMDLINE
;
80 enabled_from
= X_CONFIG
;
81 DPMSEnabled
= xf86CheckBoolOption(pScrn
->options
, "dpms", FALSE
);
82 xf86MarkOptionUsed(DPMSOpt
);
85 enabled_from
= X_DEFAULT
;
89 xf86DrvMsg(pScreen
->myNum
, enabled_from
, "DPMS enabled\n");
90 pDPMS
->Enabled
= DPMSEnabled
;
91 pDPMS
->CloseScreen
= pScreen
->CloseScreen
;
92 pScreen
->CloseScreen
= DPMSClose
;
103 DPMSClose(ScreenPtr pScreen
)
107 /* This shouldn't happen */
111 pDPMS
= dixLookupPrivate(&pScreen
->devPrivates
, DPMSKey
);
113 /* This shouldn't happen */
117 pScreen
->CloseScreen
= pDPMS
->CloseScreen
;
118 pScrn
= xf86ScreenToScrn(pScreen
);
120 * Turn on DPMS when shutting down. If this function can be used
121 * depends on the order the driver wraps things. If this is called
122 * after the driver has shut down everything the driver will have
123 * to deal with this internally.
125 if (pScrn
->vtSema
&& pScrn
->DPMSSet
) {
126 pScrn
->DPMSSet(pScrn
, DPMSModeOn
, 0);
129 if (--DPMSCount
== 0)
131 return pScreen
->CloseScreen(pScreen
);
135 DPMSSetScreen(ScrnInfoPtr pScrn
, int level
)
137 ScreenPtr pScreen
= xf86ScrnToScreen(pScrn
);
138 DPMSPtr pDPMS
= dixLookupPrivate(&pScreen
->devPrivates
, DPMSKey
);
140 if (pDPMS
&& pScrn
->DPMSSet
&& pDPMS
->Enabled
&& pScrn
->vtSema
) {
141 xf86VGAarbiterLock(pScrn
);
142 pScrn
->DPMSSet(pScrn
, level
, 0);
143 xf86VGAarbiterUnlock(pScrn
);
149 * Device dependent DPMS mode setting hook. This is called whenever
150 * the DPMS mode is to be changed.
153 DPMSSet(ClientPtr client
, int level
)
157 DPMSPowerLevel
= level
;
162 if (level
!= DPMSModeOn
) {
163 if (xf86IsUnblank(screenIsSaved
)) {
164 rc
= dixSaveScreens(client
, SCREEN_SAVER_FORCER
, ScreenSaverActive
);
168 } else if (!xf86IsUnblank(screenIsSaved
)) {
169 rc
= dixSaveScreens(client
, SCREEN_SAVER_FORCER
, ScreenSaverReset
);
174 /* For each screen, set the DPMS level */
175 for (i
= 0; i
< xf86NumScreens
; i
++) {
176 DPMSSetScreen(xf86Screens
[i
], level
);
178 for (i
= 0; i
< xf86NumGPUScreens
; i
++) {
179 DPMSSetScreen(xf86GPUScreens
[i
], level
);
185 DPMSSupportedOnScreen(ScrnInfoPtr pScrn
)
187 ScreenPtr pScreen
= xf86ScrnToScreen(pScrn
);
188 DPMSPtr pDPMS
= dixLookupPrivate(&pScreen
->devPrivates
, DPMSKey
);
190 return pDPMS
&& pScrn
->DPMSSet
;
195 * Return TRUE if any screen supports DPMS.
202 if (DPMSKey
== NULL
) {
206 /* For each screen, check if DPMS is supported */
207 for (i
= 0; i
< xf86NumScreens
; i
++) {
208 if (DPMSSupportedOnScreen(xf86Screens
[i
]))
211 for (i
= 0; i
< xf86NumGPUScreens
; i
++) {
212 if (DPMSSupportedOnScreen(xf86GPUScreens
[i
]))
218 #endif /* DPMSExtension */