~ubuntu-branches/ubuntu/hardy/nvidia-settings/hardy-proposed

« back to all changes in this revision

Viewing changes to nvidia-settings-1.0/src/libXNVCtrlAttributes/NvCtrlAttributes.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2006-12-20 15:27:47 UTC
  • mfrom: (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20061220152747-jp2ogyvcua2nkhah
Tags: 1.0+20060516-3ubuntu1
* Resynchronise with Debian. Remaining changes:
  - Make the nvidia-glx recommendation unversioned, as nvidia-glx-legacy
    provides nvidia-glx.
* Change preferred libgl-dev provider to libgl1-mesa-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * nvidia-settings: A tool for configuring the NVIDIA X driver on Unix
3
 
 * and Linux systems.
4
 
 *
5
 
 * Copyright (C) 2004 NVIDIA Corporation.
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or
8
 
 * modify it under the terms of Version 2 of the GNU General Public
9
 
 * License as published by the Free Software Foundation.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful, but
12
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See Version 2
14
 
 * of the GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the:
18
 
 *
19
 
 *           Free Software Foundation, Inc.
20
 
 *           59 Temple Place - Suite 330
21
 
 *           Boston, MA 02111-1307, USA
22
 
 *
23
 
 */
24
 
 
25
 
#include "NvCtrlAttributes.h"
26
 
#include "NvCtrlAttributesPrivate.h"
27
 
 
28
 
#include "NVCtrlLib.h"
29
 
 
30
 
#include "msg.h"
31
 
 
32
 
#include "parse.h"
33
 
 
34
 
#include <X11/extensions/xf86vmode.h>
35
 
#include <X11/extensions/Xvlib.h>
36
 
#include <stdlib.h>
37
 
#include <string.h>
38
 
#include <stdio.h>
39
 
 
40
 
#include <sys/utsname.h>
41
 
 
42
 
 
43
 
 
44
 
/*
45
 
 * NvCtrlAttributeInit() - XXX not sure how to handle errors
46
 
 */
47
 
 
48
 
NvCtrlAttributeHandle *NvCtrlAttributeInit(Display *dpy, int screen,
49
 
                                           unsigned int subsystems)
50
 
{
51
 
    NvCtrlAttributePrivateHandle *h = NULL;
52
 
 
53
 
    h = calloc(1, sizeof (NvCtrlAttributePrivateHandle));
54
 
    if (!h) {
55
 
        nv_error_msg("Memory allocation failure!");
56
 
        goto failed;
57
 
    }
58
 
 
59
 
    /* initialize the display and screen to the parameter values */
60
 
 
61
 
    h->dpy = dpy;
62
 
    h->screen = screen;
63
 
       
64
 
    /* initialize the NV-CONTROL attributes; give up if this fails */
65
 
 
66
 
    if (subsystems & NV_CTRL_ATTRIBUTES_NV_CONTROL_SUBSYSTEM) {
67
 
        h->nv = NvCtrlInitNvControlAttributes(h);
68
 
        if (!h->nv) goto failed;
69
 
    }
70
 
 
71
 
    /*
72
 
     * initialize the XF86VidMode attributes; it is OK if this
73
 
     * fails
74
 
     */
75
 
 
76
 
    if (subsystems & NV_CTRL_ATTRIBUTES_XF86VIDMODE_SUBSYSTEM) {
77
 
        h->vm = NvCtrlInitVidModeAttributes(h);
78
 
    }
79
 
 
80
 
    /*
81
 
     * initialize the XVideo extension and attributes; it is OK if
82
 
     * this fails
83
 
     */
84
 
 
85
 
    if (subsystems & NV_CTRL_ATTRIBUTES_XVIDEO_SUBSYSTEM) {
86
 
        NvCtrlInitXvOverlayAttributes(h);
87
 
    }
88
 
    
89
 
    return (NvCtrlAttributeHandle *) h;
90
 
 
91
 
 failed:
92
 
    if (h) free (h);
93
 
    return NULL;
94
 
 
95
 
} /* NvCtrlAttributeInit() */
96
 
 
97
 
 
98
 
/*
99
 
 * NvCtrlGetDisplayName() - return a string of the form:
100
 
 * 
101
 
 * [host]:[display].[screen]
102
 
 *
103
 
 * that describes the X screen associated with this
104
 
 * NvCtrlAttributeHandle.  This is done by getting the string that
105
 
 * describes the display connection, and then substituting the correct
106
 
 * screen number.  If no hostname is present in the display string,
107
 
 * uname.nodename is prepended.  Returns NULL if any error occors.
108
 
 */
109
 
 
110
 
char *NvCtrlGetDisplayName(NvCtrlAttributeHandle *handle)
111
 
{
112
 
    NvCtrlAttributePrivateHandle *h;
113
 
    char *display_name;
114
 
        
115
 
    if (!handle) return NULL;
116
 
    
117
 
    h = (NvCtrlAttributePrivateHandle *) handle;
118
 
    
119
 
    display_name = DisplayString(h->dpy);
120
 
    
121
 
    return nv_standardize_screen_name(display_name, h->screen);
122
 
    
123
 
} /* NvCtrlGetDisplayName() */
124
 
 
125
 
 
126
 
/*
127
 
 * NvCtrlDisplayPtr() - returns the Display pointer associated with
128
 
 * this NvCtrlAttributeHandle.
129
 
 */
130
 
  
131
 
Display *NvCtrlGetDisplayPtr(NvCtrlAttributeHandle *handle)
132
 
{
133
 
    NvCtrlAttributePrivateHandle *h;
134
 
 
135
 
    if (!handle) return NULL;
136
 
 
137
 
    h = (NvCtrlAttributePrivateHandle *) handle;
138
 
    
139
 
    return h->dpy;
140
 
 
141
 
} /* NvCtrlDisplayPtr() */
142
 
 
143
 
 
144
 
int NvCtrlGetEventBase(NvCtrlAttributeHandle *handle)
145
 
{
146
 
    NvCtrlAttributePrivateHandle *h;
147
 
 
148
 
    if (!handle) return 0;
149
 
 
150
 
    h = (NvCtrlAttributePrivateHandle *) handle;
151
 
 
152
 
    if (!h->nv) return 0;
153
 
    return (h->nv->event_base);
154
 
    
155
 
} /* NvCtrlGetEventBase() */
156
 
 
157
 
 
158
 
ReturnStatus NvCtrlGetAttribute(NvCtrlAttributeHandle *handle,
159
 
                                int attr, int *val)
160
 
{
161
 
    if (!handle) return NvCtrlBadArgument;
162
 
    return NvCtrlGetDisplayAttribute(handle, 0, attr, val);
163
 
    
164
 
} /* NvCtrlGetAttribute() */
165
 
 
166
 
 
167
 
ReturnStatus NvCtrlSetAttribute(NvCtrlAttributeHandle *handle,
168
 
                                int attr, int val)
169
 
{
170
 
    if (!handle) return NvCtrlBadArgument;
171
 
    return NvCtrlSetDisplayAttribute(handle, 0, attr, val);
172
 
 
173
 
} /* NvCtrlSetAttribute() */
174
 
 
175
 
 
176
 
ReturnStatus NvCtrlGetValidAttributeValues(NvCtrlAttributeHandle *handle,
177
 
                                           int attr,
178
 
                                           NVCTRLAttributeValidValuesRec *val)
179
 
{
180
 
    if (!handle) return NvCtrlBadArgument;
181
 
    return NvCtrlGetValidDisplayAttributeValues(handle, 0, attr, val);
182
 
    
183
 
} /* NvCtrlGetValidAttributeValues() */
184
 
 
185
 
 
186
 
ReturnStatus NvCtrlGetStringAttribute(NvCtrlAttributeHandle *handle,
187
 
                                      int attr, char **ptr)
188
 
{
189
 
    if (!handle) return NvCtrlBadArgument;
190
 
    return NvCtrlGetStringDisplayAttribute(handle, 0, attr, ptr);
191
 
 
192
 
} /* NvCtrlGetStringAttribute() */
193
 
 
194
 
 
195
 
ReturnStatus
196
 
NvCtrlGetDisplayAttribute(NvCtrlAttributeHandle *handle,
197
 
                          unsigned int display_mask, int attr, int *val)
198
 
{
199
 
    NvCtrlAttributePrivateHandle *h;
200
 
 
201
 
    h = (NvCtrlAttributePrivateHandle *) handle;
202
 
 
203
 
    if ((attr >= NV_CTRL_ATTR_EXT_BASE) &&
204
 
        (attr <= NV_CTRL_ATTR_EXT_LAST_ATTRIBUTE)) {
205
 
        switch (attr) {
206
 
          case NV_CTRL_ATTR_EXT_NV_PRESENT:
207
 
            *val = (h->nv) ? True : False; break;
208
 
          case NV_CTRL_ATTR_EXT_VM_PRESENT:
209
 
            *val = (h->vm) ? True : False; break;
210
 
          case NV_CTRL_ATTR_EXT_XV_OVERLAY_PRESENT:
211
 
            *val = (h->xv_overlay) ? True : False; break;
212
 
          case NV_CTRL_ATTR_EXT_XV_TEXTURE_PRESENT:
213
 
            *val = (h->xv_texture) ? True : False; break;
214
 
          case NV_CTRL_ATTR_EXT_XV_BLITTER_PRESENT:
215
 
            *val = (h->xv_blitter) ? True : False; break;
216
 
          default:
217
 
            return NvCtrlNoAttribute;
218
 
        }
219
 
        return NvCtrlSuccess;
220
 
    }
221
 
    
222
 
    if ((attr >= 0) && (attr <= NV_CTRL_LAST_ATTRIBUTE)) {
223
 
        if (!h->nv) return NvCtrlMissingExtension;
224
 
        return NvCtrlNvControlGetAttribute(h, display_mask, attr, val);
225
 
    }
226
 
 
227
 
    if ((attr >= NV_CTRL_ATTR_XV_BASE) &&
228
 
        (attr <= NV_CTRL_ATTR_XV_LAST_ATTRIBUTE)) {
229
 
        
230
 
        return NvCtrlXvGetAttribute(h, attr, val);
231
 
    }
232
 
    return NvCtrlNoAttribute;
233
 
    
234
 
} /* NvCtrlGetDisplayAttribute() */
235
 
 
236
 
 
237
 
ReturnStatus
238
 
NvCtrlSetDisplayAttribute(NvCtrlAttributeHandle *handle,
239
 
                          unsigned int display_mask, int attr, int val)
240
 
{
241
 
    NvCtrlAttributePrivateHandle *h;
242
 
 
243
 
    h = (NvCtrlAttributePrivateHandle *) handle;
244
 
    
245
 
    if ((attr >= 0) && (attr <= NV_CTRL_LAST_ATTRIBUTE)) {
246
 
        if (!h->nv) return NvCtrlMissingExtension;
247
 
        return NvCtrlNvControlSetAttribute(h, display_mask, attr, val);
248
 
    }
249
 
 
250
 
    if ((attr >= NV_CTRL_ATTR_XV_BASE) &&
251
 
        (attr <= NV_CTRL_ATTR_XV_LAST_ATTRIBUTE)) {
252
 
        
253
 
        return NvCtrlXvSetAttribute(h, attr, val);
254
 
    }
255
 
    
256
 
    return NvCtrlNoAttribute;
257
 
 
258
 
} /* NvCtrlSetDisplayAttribute() */
259
 
 
260
 
 
261
 
ReturnStatus
262
 
NvCtrlGetValidDisplayAttributeValues(NvCtrlAttributeHandle *handle,
263
 
                                     unsigned int display_mask, int attr,
264
 
                                     NVCTRLAttributeValidValuesRec *val)
265
 
{
266
 
    NvCtrlAttributePrivateHandle *h;
267
 
    
268
 
    h = (NvCtrlAttributePrivateHandle *) handle;
269
 
    
270
 
    if ((attr >= 0) && (attr <= NV_CTRL_LAST_ATTRIBUTE)) {
271
 
        if (!h->nv) return NvCtrlMissingExtension;
272
 
        return NvCtrlNvControlGetValidAttributeValues(h, display_mask,
273
 
                                                      attr, val);
274
 
    }
275
 
 
276
 
    if ((attr >= NV_CTRL_ATTR_XV_BASE) &&
277
 
        (attr <= NV_CTRL_ATTR_XV_LAST_ATTRIBUTE)) {
278
 
 
279
 
        return NvCtrlXvGetValidAttributeValues(h, attr, val);
280
 
    }
281
 
    
282
 
    return NvCtrlNoAttribute;
283
 
    
284
 
} /* NvCtrlGetValidDisplayAttributeValues() */
285
 
 
286
 
 
287
 
ReturnStatus
288
 
NvCtrlGetStringDisplayAttribute(NvCtrlAttributeHandle *handle,
289
 
                                unsigned int display_mask,
290
 
                                int attr, char **ptr)
291
 
{
292
 
    NvCtrlAttributePrivateHandle *h;
293
 
 
294
 
    h = (NvCtrlAttributePrivateHandle *) handle;
295
 
 
296
 
    if ((attr >= 0) && (attr <= NV_CTRL_LAST_ATTRIBUTE)) {
297
 
        if (!h->nv) return NvCtrlMissingExtension;
298
 
        return NvCtrlNvControlGetStringAttribute(h, display_mask, attr, ptr);
299
 
    }
300
 
 
301
 
    return NvCtrlNoAttribute;
302
 
 
303
 
} /* NvCtrlGetStringDisplayAttribute() */
304
 
 
305
 
 
306
 
char *NvCtrlAttributesStrError(ReturnStatus status)
307
 
{
308
 
    switch (status) {
309
 
      case NvCtrlSuccess:
310
 
          return "Success"; break;
311
 
      case NvCtrlBadArgument:
312
 
          return "Bad argument"; break;
313
 
      case NvCtrlBadHandle:
314
 
          return "Bad handle"; break;
315
 
      case NvCtrlNoAttribute:
316
 
          return "No such attribute"; break;
317
 
      case NvCtrlMissingExtension:
318
 
          return "Missing Extension"; break;
319
 
      case NvCtrlReadOnlyAttribute:
320
 
          return "Read only attribute"; break;
321
 
      case NvCtrlWriteOnlyAttribute:
322
 
          return "Write only attribute"; break;
323
 
      case NvCtrlAttributeNotAvailable:
324
 
          return "Attribute not available"; break;
325
 
      case NvCtrlError: /* fall through to default */
326
 
      default:
327
 
        return "Unknown Error"; break;
328
 
    }
329
 
} /* NvCtrlAttributesStrError() */
330
 
 
331
 
 
332
 
void NvCtrlAttributeClose(NvCtrlAttributeHandle *handle)
333
 
{
334
 
    NvCtrlAttributePrivateHandle *h;
335
 
    
336
 
    if (!handle) return;
337
 
    
338
 
    h = (NvCtrlAttributePrivateHandle *) handle;
339
 
 
340
 
    /*
341
 
     * XXX should free any additional resources allocated by each
342
 
     * subsystem
343
 
     */
344
 
 
345
 
    free(h);
346
 
 
347
 
} /* NvCtrlAttributeClose() */