2
* nvidia-settings: A tool for configuring the NVIDIA X driver on Unix
5
* Copyright (C) 2004 NVIDIA Corporation.
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.
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.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the:
19
* Free Software Foundation, Inc.
20
* 59 Temple Place - Suite 330
21
* Boston, MA 02111-1307, USA
25
#include "NvCtrlAttributes.h"
26
#include "NvCtrlAttributesPrivate.h"
28
#include "NVCtrlLib.h"
34
#include <X11/extensions/xf86vmode.h>
35
#include <X11/extensions/Xvlib.h>
40
#include <sys/utsname.h>
45
* NvCtrlAttributeInit() - XXX not sure how to handle errors
48
NvCtrlAttributeHandle *NvCtrlAttributeInit(Display *dpy, int screen,
49
unsigned int subsystems)
51
NvCtrlAttributePrivateHandle *h = NULL;
53
h = calloc(1, sizeof (NvCtrlAttributePrivateHandle));
55
nv_error_msg("Memory allocation failure!");
59
/* initialize the display and screen to the parameter values */
64
/* initialize the NV-CONTROL attributes; give up if this fails */
66
if (subsystems & NV_CTRL_ATTRIBUTES_NV_CONTROL_SUBSYSTEM) {
67
h->nv = NvCtrlInitNvControlAttributes(h);
68
if (!h->nv) goto failed;
72
* initialize the XF86VidMode attributes; it is OK if this
76
if (subsystems & NV_CTRL_ATTRIBUTES_XF86VIDMODE_SUBSYSTEM) {
77
h->vm = NvCtrlInitVidModeAttributes(h);
81
* initialize the XVideo extension and attributes; it is OK if
85
if (subsystems & NV_CTRL_ATTRIBUTES_XVIDEO_SUBSYSTEM) {
86
NvCtrlInitXvOverlayAttributes(h);
89
return (NvCtrlAttributeHandle *) h;
95
} /* NvCtrlAttributeInit() */
99
* NvCtrlGetDisplayName() - return a string of the form:
101
* [host]:[display].[screen]
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.
110
char *NvCtrlGetDisplayName(NvCtrlAttributeHandle *handle)
112
NvCtrlAttributePrivateHandle *h;
115
if (!handle) return NULL;
117
h = (NvCtrlAttributePrivateHandle *) handle;
119
display_name = DisplayString(h->dpy);
121
return nv_standardize_screen_name(display_name, h->screen);
123
} /* NvCtrlGetDisplayName() */
127
* NvCtrlDisplayPtr() - returns the Display pointer associated with
128
* this NvCtrlAttributeHandle.
131
Display *NvCtrlGetDisplayPtr(NvCtrlAttributeHandle *handle)
133
NvCtrlAttributePrivateHandle *h;
135
if (!handle) return NULL;
137
h = (NvCtrlAttributePrivateHandle *) handle;
141
} /* NvCtrlDisplayPtr() */
144
int NvCtrlGetEventBase(NvCtrlAttributeHandle *handle)
146
NvCtrlAttributePrivateHandle *h;
148
if (!handle) return 0;
150
h = (NvCtrlAttributePrivateHandle *) handle;
152
if (!h->nv) return 0;
153
return (h->nv->event_base);
155
} /* NvCtrlGetEventBase() */
158
ReturnStatus NvCtrlGetAttribute(NvCtrlAttributeHandle *handle,
161
if (!handle) return NvCtrlBadArgument;
162
return NvCtrlGetDisplayAttribute(handle, 0, attr, val);
164
} /* NvCtrlGetAttribute() */
167
ReturnStatus NvCtrlSetAttribute(NvCtrlAttributeHandle *handle,
170
if (!handle) return NvCtrlBadArgument;
171
return NvCtrlSetDisplayAttribute(handle, 0, attr, val);
173
} /* NvCtrlSetAttribute() */
176
ReturnStatus NvCtrlGetValidAttributeValues(NvCtrlAttributeHandle *handle,
178
NVCTRLAttributeValidValuesRec *val)
180
if (!handle) return NvCtrlBadArgument;
181
return NvCtrlGetValidDisplayAttributeValues(handle, 0, attr, val);
183
} /* NvCtrlGetValidAttributeValues() */
186
ReturnStatus NvCtrlGetStringAttribute(NvCtrlAttributeHandle *handle,
187
int attr, char **ptr)
189
if (!handle) return NvCtrlBadArgument;
190
return NvCtrlGetStringDisplayAttribute(handle, 0, attr, ptr);
192
} /* NvCtrlGetStringAttribute() */
196
NvCtrlGetDisplayAttribute(NvCtrlAttributeHandle *handle,
197
unsigned int display_mask, int attr, int *val)
199
NvCtrlAttributePrivateHandle *h;
201
h = (NvCtrlAttributePrivateHandle *) handle;
203
if ((attr >= NV_CTRL_ATTR_EXT_BASE) &&
204
(attr <= NV_CTRL_ATTR_EXT_LAST_ATTRIBUTE)) {
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;
217
return NvCtrlNoAttribute;
219
return NvCtrlSuccess;
222
if ((attr >= 0) && (attr <= NV_CTRL_LAST_ATTRIBUTE)) {
223
if (!h->nv) return NvCtrlMissingExtension;
224
return NvCtrlNvControlGetAttribute(h, display_mask, attr, val);
227
if ((attr >= NV_CTRL_ATTR_XV_BASE) &&
228
(attr <= NV_CTRL_ATTR_XV_LAST_ATTRIBUTE)) {
230
return NvCtrlXvGetAttribute(h, attr, val);
232
return NvCtrlNoAttribute;
234
} /* NvCtrlGetDisplayAttribute() */
238
NvCtrlSetDisplayAttribute(NvCtrlAttributeHandle *handle,
239
unsigned int display_mask, int attr, int val)
241
NvCtrlAttributePrivateHandle *h;
243
h = (NvCtrlAttributePrivateHandle *) handle;
245
if ((attr >= 0) && (attr <= NV_CTRL_LAST_ATTRIBUTE)) {
246
if (!h->nv) return NvCtrlMissingExtension;
247
return NvCtrlNvControlSetAttribute(h, display_mask, attr, val);
250
if ((attr >= NV_CTRL_ATTR_XV_BASE) &&
251
(attr <= NV_CTRL_ATTR_XV_LAST_ATTRIBUTE)) {
253
return NvCtrlXvSetAttribute(h, attr, val);
256
return NvCtrlNoAttribute;
258
} /* NvCtrlSetDisplayAttribute() */
262
NvCtrlGetValidDisplayAttributeValues(NvCtrlAttributeHandle *handle,
263
unsigned int display_mask, int attr,
264
NVCTRLAttributeValidValuesRec *val)
266
NvCtrlAttributePrivateHandle *h;
268
h = (NvCtrlAttributePrivateHandle *) handle;
270
if ((attr >= 0) && (attr <= NV_CTRL_LAST_ATTRIBUTE)) {
271
if (!h->nv) return NvCtrlMissingExtension;
272
return NvCtrlNvControlGetValidAttributeValues(h, display_mask,
276
if ((attr >= NV_CTRL_ATTR_XV_BASE) &&
277
(attr <= NV_CTRL_ATTR_XV_LAST_ATTRIBUTE)) {
279
return NvCtrlXvGetValidAttributeValues(h, attr, val);
282
return NvCtrlNoAttribute;
284
} /* NvCtrlGetValidDisplayAttributeValues() */
288
NvCtrlGetStringDisplayAttribute(NvCtrlAttributeHandle *handle,
289
unsigned int display_mask,
290
int attr, char **ptr)
292
NvCtrlAttributePrivateHandle *h;
294
h = (NvCtrlAttributePrivateHandle *) handle;
296
if ((attr >= 0) && (attr <= NV_CTRL_LAST_ATTRIBUTE)) {
297
if (!h->nv) return NvCtrlMissingExtension;
298
return NvCtrlNvControlGetStringAttribute(h, display_mask, attr, ptr);
301
return NvCtrlNoAttribute;
303
} /* NvCtrlGetStringDisplayAttribute() */
306
char *NvCtrlAttributesStrError(ReturnStatus status)
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 */
327
return "Unknown Error"; break;
329
} /* NvCtrlAttributesStrError() */
332
void NvCtrlAttributeClose(NvCtrlAttributeHandle *handle)
334
NvCtrlAttributePrivateHandle *h;
338
h = (NvCtrlAttributePrivateHandle *) handle;
341
* XXX should free any additional resources allocated by each
347
} /* NvCtrlAttributeClose() */