~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xfree86/common/xf86DPMS.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86DPMS.c,v 1.11 2003/11/11 21:02:28 dawes Exp $ */
 
2
/* $XdotOrg: xserver/xorg/hw/xfree86/common/xf86DPMS.c,v 1.8 2005/07/03 08:53:42 daniels Exp $ */
 
3
 
 
4
/*
 
5
 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
 
6
 *
 
7
 * Permission is hereby granted, free of charge, to any person obtaining a
 
8
 * copy of this software and associated documentation files (the "Software"),
 
9
 * to deal in the Software without restriction, including without limitation
 
10
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
11
 * and/or sell copies of the Software, and to permit persons to whom the
 
12
 * Software is furnished to do so, subject to the following conditions:
 
13
 *
 
14
 * The above copyright notice and this permission notice shall be included in
 
15
 * all copies or substantial portions of the Software.
 
16
 *
 
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 
20
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 
21
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 
22
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
23
 * OTHER DEALINGS IN THE SOFTWARE.
 
24
 *
 
25
 * Except as contained in this notice, the name of the copyright holder(s)
 
26
 * and author(s) shall not be used in advertising or otherwise to promote
 
27
 * the sale, use or other dealings in this Software without prior written
 
28
 * authorization from the copyright holder(s) and author(s).
 
29
 */
 
30
 
 
31
/*
 
32
 * This file contains the DPMS functions required by the extension.
 
33
 */
 
34
 
 
35
#ifdef HAVE_XORG_CONFIG_H
 
36
#include <xorg-config.h>
 
37
#endif
 
38
 
 
39
#include <X11/X.h>
 
40
#include "os.h"
 
41
#include "globals.h"
 
42
#include "xf86.h"
 
43
#include "xf86Priv.h"
 
44
#ifdef DPMSExtension
 
45
#define DPMS_SERVER
 
46
#include <X11/extensions/dpms.h>
 
47
#include "dpmsproc.h"
 
48
#endif
 
49
 
 
50
 
 
51
#ifdef DPMSExtension
 
52
static int DPMSGeneration = 0;
 
53
static int DPMSIndex = -1;
 
54
static Bool DPMSClose(int i, ScreenPtr pScreen);
 
55
static int DPMSCount = 0;
 
56
#endif
 
57
 
 
58
 
 
59
Bool
 
60
xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
 
61
{
 
62
#ifdef DPMSExtension
 
63
    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
 
64
    DPMSPtr pDPMS;
 
65
    pointer DPMSOpt;
 
66
 
 
67
    if (serverGeneration != DPMSGeneration) {
 
68
        if ((DPMSIndex = AllocateScreenPrivateIndex()) < 0)
 
69
            return FALSE;
 
70
        DPMSGeneration = serverGeneration;
 
71
    }
 
72
 
 
73
    if (DPMSDisabledSwitch)
 
74
        DPMSEnabled = FALSE;
 
75
    if (!(pScreen->devPrivates[DPMSIndex].ptr = xcalloc(sizeof(DPMSRec), 1)))
 
76
        return FALSE;
 
77
 
 
78
    pDPMS = (DPMSPtr)pScreen->devPrivates[DPMSIndex].ptr;
 
79
    pScrn->DPMSSet = set;
 
80
    pDPMS->Flags = flags;
 
81
    DPMSOpt = xf86FindOption(pScrn->options, "dpms");
 
82
    if (DPMSOpt) {
 
83
        if ((pDPMS->Enabled
 
84
            = xf86SetBoolOption(pScrn->options, "dpms", FALSE))
 
85
            && !DPMSDisabledSwitch)
 
86
            DPMSEnabled = TRUE;
 
87
        xf86MarkOptionUsed(DPMSOpt);
 
88
        xf86DrvMsg(pScreen->myNum, X_CONFIG, "DPMS enabled\n");
 
89
    } else if (DPMSEnabledSwitch) {
 
90
        if (!DPMSDisabledSwitch)
 
91
            DPMSEnabled = TRUE;
 
92
        pDPMS->Enabled = TRUE;
 
93
    }  
 
94
    else {
 
95
        pDPMS->Enabled = defaultDPMSEnabled;
 
96
    }
 
97
    pDPMS->CloseScreen = pScreen->CloseScreen;
 
98
    pScreen->CloseScreen = DPMSClose;
 
99
    DPMSCount++;
 
100
    return TRUE;
 
101
#else
 
102
    return FALSE;
 
103
#endif
 
104
}
 
105
 
 
106
 
 
107
#ifdef DPMSExtension
 
108
 
 
109
static Bool
 
110
DPMSClose(int i, ScreenPtr pScreen)
 
111
{
 
112
    DPMSPtr pDPMS;
 
113
 
 
114
    /* This shouldn't happen */
 
115
    if (DPMSIndex < 0)
 
116
        return FALSE;
 
117
 
 
118
    pDPMS = (DPMSPtr)pScreen->devPrivates[DPMSIndex].ptr;
 
119
 
 
120
    /* This shouldn't happen */
 
121
    if (!pDPMS)
 
122
        return FALSE;
 
123
 
 
124
    pScreen->CloseScreen = pDPMS->CloseScreen;
 
125
 
 
126
    /*
 
127
     * Turn on DPMS when shutting down. If this function can be used
 
128
     * depends on the order the driver wraps things. If this is called
 
129
     * after the driver has shut down everything the driver will have
 
130
     * to deal with this internally.
 
131
     */
 
132
    if (xf86Screens[i]->vtSema && xf86Screens[i]->DPMSSet) {
 
133
        xf86Screens[i]->DPMSSet(xf86Screens[i],DPMSModeOn,0);
 
134
    }
 
135
    
 
136
    xfree((pointer)pDPMS);
 
137
    pScreen->devPrivates[DPMSIndex].ptr = NULL;
 
138
    if (--DPMSCount == 0)
 
139
        DPMSIndex = -1;
 
140
    return pScreen->CloseScreen(i, pScreen);
 
141
}
 
142
 
 
143
 
 
144
/*
 
145
 * DPMSSet --
 
146
 *      Device dependent DPMS mode setting hook.  This is called whenever
 
147
 *      the DPMS mode is to be changed.
 
148
 */
 
149
void
 
150
DPMSSet(int level)
 
151
{
 
152
    int i;
 
153
    DPMSPtr pDPMS;
 
154
    ScrnInfoPtr pScrn;
 
155
 
 
156
    DPMSPowerLevel = level;
 
157
 
 
158
    if (DPMSIndex < 0)
 
159
        return;
 
160
 
 
161
    if (level != DPMSModeOn)
 
162
        SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverActive);
 
163
 
 
164
    /* For each screen, set the DPMS level */
 
165
    for (i = 0; i < xf86NumScreens; i++) {
 
166
        pScrn = xf86Screens[i];
 
167
        pDPMS = (DPMSPtr)screenInfo.screens[i]->devPrivates[DPMSIndex].ptr;
 
168
        if (pDPMS && pScrn->DPMSSet && pDPMS->Enabled && pScrn->vtSema) { 
 
169
            xf86EnableAccess(pScrn);
 
170
            pScrn->DPMSSet(pScrn, level, 0);
 
171
        }
 
172
    }
 
173
}
 
174
 
 
175
 
 
176
/*
 
177
 * DPMSSupported --
 
178
 *      Return TRUE if any screen supports DPMS.
 
179
 */
 
180
Bool
 
181
DPMSSupported(void)
 
182
{
 
183
    int i;
 
184
    DPMSPtr pDPMS;
 
185
    ScrnInfoPtr pScrn;
 
186
 
 
187
    if (DPMSIndex < 0) {
 
188
        return FALSE;
 
189
    }
 
190
 
 
191
    /* For each screen, check if DPMS is supported */
 
192
    for (i = 0; i < xf86NumScreens; i++) {
 
193
        pScrn = xf86Screens[i];
 
194
        pDPMS = (DPMSPtr)screenInfo.screens[i]->devPrivates[DPMSIndex].ptr;
 
195
        if (pDPMS && pScrn->DPMSSet)
 
196
            return TRUE;
 
197
    }
 
198
    return FALSE;
 
199
}
 
200
 
 
201
 
 
202
/*
 
203
 * DPMSGet --
 
204
 *      Device dependent DPMS mode getting hook.  This returns the current
 
205
 *      DPMS mode, or -1 if DPMS is not supported.
 
206
 *
 
207
 *      This should hook in to the appropriate driver-level function, which
 
208
 *      will be added to the ScrnInfoRec.
 
209
 *
 
210
 *      NOTES:
 
211
 *       1. the calling interface should be changed to specify which
 
212
 *          screen to check.
 
213
 *       2. It isn't clear that this function is ever used or what it should
 
214
 *          return.
 
215
 */
 
216
int
 
217
DPMSGet(int *level)
 
218
{
 
219
    return DPMSPowerLevel;
 
220
}
 
221
 
 
222
#endif /* DPMSExtension */