diff options
Diffstat (limited to 'src/libXNVCtrlAttributes')
-rw-r--r-- | src/libXNVCtrlAttributes/Makefile.inc | 4 | ||||
-rw-r--r-- | src/libXNVCtrlAttributes/NvCtrlAttributes.c | 186 | ||||
-rw-r--r-- | src/libXNVCtrlAttributes/NvCtrlAttributes.h | 24 | ||||
-rw-r--r-- | src/libXNVCtrlAttributes/NvCtrlAttributesGlx.c | 2 | ||||
-rw-r--r-- | src/libXNVCtrlAttributes/NvCtrlAttributesNvControl.c | 22 | ||||
-rw-r--r-- | src/libXNVCtrlAttributes/NvCtrlAttributesPrivate.h | 12 | ||||
-rw-r--r-- | src/libXNVCtrlAttributes/NvCtrlAttributesXrandr.c | 92 | ||||
-rw-r--r-- | src/libXNVCtrlAttributes/NvCtrlAttributesXv.c | 2 |
8 files changed, 340 insertions, 4 deletions
diff --git a/src/libXNVCtrlAttributes/Makefile.inc b/src/libXNVCtrlAttributes/Makefile.inc index 257cc7f..7c2a87c 100644 --- a/src/libXNVCtrlAttributes/Makefile.inc +++ b/src/libXNVCtrlAttributes/Makefile.inc @@ -34,5 +34,9 @@ SRC += \ NvCtrlAttributesXrandr.c EXTRA_DIST += \ + Makefile.inc \ NvCtrlAttributes.h \ NvCtrlAttributesPrivate.h + +dist_list:: + @ echo $(SRC) $(EXTRA_DIST) diff --git a/src/libXNVCtrlAttributes/NvCtrlAttributes.c b/src/libXNVCtrlAttributes/NvCtrlAttributes.c index 5cea7c5..172acf0 100644 --- a/src/libXNVCtrlAttributes/NvCtrlAttributes.c +++ b/src/libXNVCtrlAttributes/NvCtrlAttributes.c @@ -299,6 +299,163 @@ int NvCtrlGetXrandrEventBase(NvCtrlAttributeHandle *handle) } /* NvCtrlGetXrandrEventBase() */ +/* + * NvCtrlGetServerVendor() - return the server vendor + * information string associated with this + * NvCtrlAttributeHandle. + */ + +char *NvCtrlGetServerVendor(NvCtrlAttributeHandle *handle) +{ + NvCtrlAttributePrivateHandle *h; + + if (!handle) return NULL; + + h = (NvCtrlAttributePrivateHandle *) handle; + + if (!h->dpy) return NULL; + return ServerVendor(h->dpy); + +} /* NvCtrlGetServerVendor() */ + + +/* + * NvCtrlGetVendorRelease() - return the server vendor + * release number associated with this NvCtrlAttributeHandle. + */ + +int NvCtrlGetVendorRelease(NvCtrlAttributeHandle *handle) +{ + NvCtrlAttributePrivateHandle *h; + + if (!handle) return -1; + + h = (NvCtrlAttributePrivateHandle *) handle; + + if (!h->dpy) return -1; + return VendorRelease(h->dpy); + +} /* NvCtrlGetVendorRelease() */ + + +/* + * NvCtrlGetScreenCount() - return the number of (logical) + * X Screens associated with this NvCtrlAttributeHandle. + */ + +int NvCtrlGetScreenCount(NvCtrlAttributeHandle *handle) +{ + NvCtrlAttributePrivateHandle *h; + + if (!handle) return -1; + + h = (NvCtrlAttributePrivateHandle *) handle; + + if (!h->dpy) return -1; + return ScreenCount(h->dpy); + +} /* NvCtrlGetScreenCount() */ + + +/* + * NvCtrlGetProtocolVersion() - Returns the majoy version + * number of the X protocol (server). + */ + +int NvCtrlGetProtocolVersion(NvCtrlAttributeHandle *handle) +{ + NvCtrlAttributePrivateHandle *h; + + if (!handle) return -1; + + h = (NvCtrlAttributePrivateHandle *) handle; + + if (!h->dpy) return -1; + return ProtocolVersion(h->dpy); + +} /* NvCtrlGetProtocolVersion() */ + + +/* + * NvCtrlGetProtocolRevision() - Returns the revision number + * of the X protocol (server). + */ + +int NvCtrlGetProtocolRevision(NvCtrlAttributeHandle *handle) +{ + NvCtrlAttributePrivateHandle *h; + + if (!handle) return -1; + + h = (NvCtrlAttributePrivateHandle *) handle; + + if (!h->dpy) return -1; + return ProtocolRevision(h->dpy); + +} /* NvCtrlGetProtocolRevision() */ + + +/* + * NvCtrlGetScreenWidthMM() - return the width (in Millimeters) of the + * screen associated with this NvCtrlAttributeHandle. + */ + +int NvCtrlGetScreenWidthMM(NvCtrlAttributeHandle *handle) +{ + NvCtrlAttributePrivateHandle *h; + + if (!handle) return -1; + + h = (NvCtrlAttributePrivateHandle *) handle; + + if (h->target_type != NV_CTRL_TARGET_TYPE_X_SCREEN) return -1; + + return DisplayWidthMM(h->dpy, h->target_id); + +} /* NvCtrlGetScreenWidthMM() */ + + +/* + * NvCtrlGetScreenHeightMM() - return the height (in Millimeters) of the + * screen associated with this NvCtrlAttributeHandle. + */ + +int NvCtrlGetScreenHeightMM(NvCtrlAttributeHandle *handle) +{ + NvCtrlAttributePrivateHandle *h; + + if (!handle) return -1; + + h = (NvCtrlAttributePrivateHandle *) handle; + + if (h->target_type != NV_CTRL_TARGET_TYPE_X_SCREEN) return -1; + + return DisplayHeightMM(h->dpy, h->target_id); + +} /* NvCtrlGetScreenHeightMM() */ + + +/* + * NvCtrlGetScreenPlanes() - return the number of planes (the depth) + * of the screen associated with this NvCtrlAttributeHandle. + */ + +int NvCtrlGetScreenPlanes(NvCtrlAttributeHandle *handle) +{ + NvCtrlAttributePrivateHandle *h; + + if (!handle) return -1; + + h = (NvCtrlAttributePrivateHandle *) handle; + + if (h->target_type != NV_CTRL_TARGET_TYPE_X_SCREEN) return -1; + + return DisplayPlanes(h->dpy, h->target_id); + +} /* NvCtrlGetScreenPlanes() */ + + + ReturnStatus NvCtrlQueryTargetCount(NvCtrlAttributeHandle *handle, int target_type, int *val) @@ -550,6 +707,26 @@ NvCtrlGetBinaryAttribute(NvCtrlAttributeHandle *handle, } /* NvCtrlGetBinaryAttribute() */ +ReturnStatus +NvCtrlStringOperation(NvCtrlAttributeHandle *handle, + unsigned int display_mask, int attr, + char *ptrIn, char **ptrOut) +{ + NvCtrlAttributePrivateHandle *h; + + h = (NvCtrlAttributePrivateHandle *) handle; + + if ((attr >= 0) && (attr <= NV_CTRL_STRING_OPERATION_LAST_ATTRIBUTE)) { + if (!h->nv) return NvCtrlMissingExtension; + return NvCtrlNvControlStringOperation(h, display_mask, attr, ptrIn, + ptrOut); + } + + return NvCtrlNoAttribute; + +} /* NvCtrlStringOperation() */ + + char *NvCtrlAttributesStrError(ReturnStatus status) { switch (status) { @@ -610,3 +787,12 @@ NvCtrlXrandrSetScreenMode (NvCtrlAttributeHandle *handle, return NvCtrlXrandrSetScreenMagicMode ((NvCtrlAttributePrivateHandle *)handle, width, height, refresh); } /* NvCtrlXrandrSetScreenMode() */ + + +ReturnStatus +NvCtrlXrandrGetScreenMode (NvCtrlAttributeHandle *handle, + int *width, int *height, int *refresh) +{ + return NvCtrlXrandrGetScreenMagicMode + ((NvCtrlAttributePrivateHandle *)handle, width, height, refresh); +} /* NvCtrlXrandrGetScreenMode() */ diff --git a/src/libXNVCtrlAttributes/NvCtrlAttributes.h b/src/libXNVCtrlAttributes/NvCtrlAttributes.h index 08f958d..3cdad09 100644 --- a/src/libXNVCtrlAttributes/NvCtrlAttributes.h +++ b/src/libXNVCtrlAttributes/NvCtrlAttributes.h @@ -265,6 +265,14 @@ int NvCtrlGetScreenWidth(NvCtrlAttributeHandle *handle); int NvCtrlGetScreenHeight(NvCtrlAttributeHandle *handle); int NvCtrlGetEventBase(NvCtrlAttributeHandle *handle); int NvCtrlGetXrandrEventBase(NvCtrlAttributeHandle *handle); +char *NvCtrlGetServerVendor(NvCtrlAttributeHandle *handle); +int NvCtrlGetVendorRelease(NvCtrlAttributeHandle *handle); +int NvCtrlGetProtocolVersion(NvCtrlAttributeHandle *handle); +int NvCtrlGetProtocolRevision(NvCtrlAttributeHandle *handle); +int NvCtrlGetScreenCount(NvCtrlAttributeHandle *handle); +int NvCtrlGetScreenWidthMM(NvCtrlAttributeHandle *handle); +int NvCtrlGetScreenHeightMM(NvCtrlAttributeHandle *handle); +int NvCtrlGetScreenPlanes(NvCtrlAttributeHandle *handle); ReturnStatus NvCtrlGetColorAttributes (NvCtrlAttributeHandle *handle, float contrast[3], @@ -390,6 +398,18 @@ NvCtrlGetBinaryAttribute(NvCtrlAttributeHandle *handle, unsigned char **data, int *len); /* + * NvCtrlStringOperation() - Performs the string operation associated + * with the specified attribute, where valid values are the + * NV_CTRL_STRING_OPERATION_* #defines in NVCtrl.h. If 'ptrOut' + * is specified, (string) result information is returned. + */ + +ReturnStatus +NvCtrlStringOperation(NvCtrlAttributeHandle *handle, + unsigned int display_mask, int attr, + char *ptrIn, char **ptrOut); + +/* * NvCtrl[SG]etGvoColorConversion() - get and set the color conversion * matrix and offset used in the Graphics to Video Out (GVO) * extension. These should only be used if the NV_CTRL_GVO_SUPPORTED @@ -416,4 +436,8 @@ ReturnStatus NvCtrlXrandrSetScreenMode (NvCtrlAttributeHandle *handle, int width, int height, int refresh); +ReturnStatus +NvCtrlXrandrGetScreenMode (NvCtrlAttributeHandle *handle, + int *width, int *height, int *refresh); + #endif /* __NVCTRL_ATTRIBUTES__ */ diff --git a/src/libXNVCtrlAttributes/NvCtrlAttributesGlx.c b/src/libXNVCtrlAttributes/NvCtrlAttributesGlx.c index 08a40b6..9d99c39 100644 --- a/src/libXNVCtrlAttributes/NvCtrlAttributesGlx.c +++ b/src/libXNVCtrlAttributes/NvCtrlAttributesGlx.c @@ -137,6 +137,7 @@ static Bool open_libgl(void) if ( !__libGL ) { __libGL = (__libGLInfo *) calloc(1, sizeof(__libGLInfo)); if ( !__libGL ) { + error_str = "Could not allocate memory."; goto fail; } } @@ -152,6 +153,7 @@ static Bool open_libgl(void) /* We are the first to open the library */ __libGL->handle = dlopen("libGL.so.1", RTLD_LAZY); if ( !__libGL->handle ) { + error_str = dlerror(); goto fail; } diff --git a/src/libXNVCtrlAttributes/NvCtrlAttributesNvControl.c b/src/libXNVCtrlAttributes/NvCtrlAttributesNvControl.c index 32177e8..e0929ac 100644 --- a/src/libXNVCtrlAttributes/NvCtrlAttributesNvControl.c +++ b/src/libXNVCtrlAttributes/NvCtrlAttributesNvControl.c @@ -174,7 +174,7 @@ NvCtrlNvControlGetStringAttribute (NvCtrlAttributePrivateHandle *h, return NvCtrlNoAttribute; -} /* NvCtrlGetStringAttribute() */ +} /* NvCtrlNvControlGetStringAttribute() */ ReturnStatus @@ -235,6 +235,26 @@ NvCtrlNvControlGetBinaryAttribute(NvCtrlAttributePrivateHandle *h, ReturnStatus +NvCtrlNvControlStringOperation(NvCtrlAttributePrivateHandle *h, + unsigned int display_mask, int attr, + char *ptrIn, char **ptrOut) +{ + if (attr <= NV_CTRL_STRING_OPERATION_LAST_ATTRIBUTE) { + if (XNVCTRLStringOperation (h->dpy, h->target_type, + h->target_id, display_mask, + attr, ptrIn, ptrOut)) { + return NvCtrlSuccess; + } else { + return NvCtrlAttributeNotAvailable; + } + } + + return NvCtrlNoAttribute; + +} /* NvCtrlNvControlStringOperation() */ + + +ReturnStatus NvCtrlSetGvoColorConversion(NvCtrlAttributeHandle *handle, float colorMatrix[3][3], float colorOffset[3], diff --git a/src/libXNVCtrlAttributes/NvCtrlAttributesPrivate.h b/src/libXNVCtrlAttributes/NvCtrlAttributesPrivate.h index 314234d..43841e9 100644 --- a/src/libXNVCtrlAttributes/NvCtrlAttributesPrivate.h +++ b/src/libXNVCtrlAttributes/NvCtrlAttributesPrivate.h @@ -58,7 +58,7 @@ /* minimum required version for the NV-CONTROL extension */ #define NV_MINMAJOR 1 -#define NV_MINMINOR 9 +#define NV_MINMINOR 11 /* minimum required version for the XF86VidMode extension */ @@ -205,6 +205,10 @@ NvCtrlXrandrSetAttribute (NvCtrlAttributePrivateHandle *, int, int); ReturnStatus NvCtrlXrandrSetScreenMagicMode (NvCtrlAttributePrivateHandle *, int, int, int); +ReturnStatus +NvCtrlXrandrGetScreenMagicMode (NvCtrlAttributePrivateHandle *, int *, int *, + int *); + /* Generic attribute functions */ @@ -235,6 +239,12 @@ ReturnStatus NvCtrlNvControlGetBinaryAttribute(NvCtrlAttributePrivateHandle *h, unsigned int display_mask, int attr, unsigned char **data, int *len); + +ReturnStatus +NvCtrlNvControlStringOperation (NvCtrlAttributePrivateHandle *h, + unsigned int display_mask, int attr, + char *ptrIn, char **ptrOut); + ReturnStatus NvCtrlXvGetAttribute (NvCtrlAttributePrivateHandle *, int, int *); diff --git a/src/libXNVCtrlAttributes/NvCtrlAttributesXrandr.c b/src/libXNVCtrlAttributes/NvCtrlAttributesXrandr.c index 29b0412..60c3d78 100644 --- a/src/libXNVCtrlAttributes/NvCtrlAttributesXrandr.c +++ b/src/libXNVCtrlAttributes/NvCtrlAttributesXrandr.c @@ -42,17 +42,26 @@ #include "msg.h" #include "parse.h" +/* Make sure we are compiling with XRandR version 1.1 or greater */ +#define MIN_RANDR_MAJOR 1 +#define MIN_RANDR_MINOR 1 +#if (RANDR_MAJOR < MIN_RANDR_MAJOR) || ((RANDR_MAJOR == MIN_RANDR_MAJOR) && (RANDR_MINOR < MIN_RANDR_MINOR)) +#error XRandR version 1.1 or greater is required. +#endif typedef struct __libXrandrInfoRec { /* libXrandr.so library handle */ void *handle; int ref_count; /* # users of the library */ - - + + /* XRandR functions used */ Bool (* XRRQueryExtension) (Display *dpy, int *event_base, int *error_base); + + Status (* XRRQueryVersion) + (Display *dpy, int *major_versionp, int *minor_versionp); void (* XRRSelectInput) (Display *dpy, Window window, int mask); @@ -62,6 +71,9 @@ typedef struct __libXrandrInfoRec { SizeID (* XRRConfigCurrentConfiguration) (XRRScreenConfiguration *config, Rotation *rotation); + + short (* XRRConfigCurrentRate) + (XRRScreenConfiguration *config); Rotation (* XRRConfigRotations) (XRRScreenConfiguration *config, Rotation *rotation); @@ -104,6 +116,7 @@ static Bool open_libxrandr(void) if ( !__libXrandr ) { __libXrandr = (__libXrandrInfo *) calloc(1, sizeof(__libXrandrInfo)); if ( !__libXrandr ) { + error_str = "Could not allocate memory."; goto fail; } } @@ -118,6 +131,7 @@ static Bool open_libxrandr(void) /* We are the first to open the library */ __libXrandr->handle = dlopen("libXrandr.so.2", RTLD_LAZY); if ( !__libXrandr->handle ) { + error_str = dlerror(); goto fail; } @@ -127,6 +141,10 @@ static Bool open_libxrandr(void) NV_DLSYM(__libXrandr->handle, "XRRQueryExtension"); if ((error_str = dlerror()) != NULL) goto fail; + __libXrandr->XRRQueryVersion = + NV_DLSYM(__libXrandr->handle, "XRRQueryVersion"); + if ((error_str = dlerror()) != NULL) goto fail; + __libXrandr->XRRSelectInput = NV_DLSYM(__libXrandr->handle, "XRRSelectInput"); if ((error_str = dlerror()) != NULL) goto fail; @@ -139,6 +157,10 @@ static Bool open_libxrandr(void) NV_DLSYM(__libXrandr->handle, "XRRConfigCurrentConfiguration"); if ((error_str = dlerror()) != NULL) goto fail; + __libXrandr->XRRConfigCurrentRate = + NV_DLSYM(__libXrandr->handle, "XRRConfigCurrentRate"); + if ((error_str = dlerror()) != NULL) goto fail; + __libXrandr->XRRConfigRotations = NV_DLSYM(__libXrandr->handle, "XRRConfigRotations"); if ((error_str = dlerror()) != NULL) goto fail; @@ -249,6 +271,8 @@ NvCtrlInitXrandrAttributes (NvCtrlAttributePrivateHandle *h) NvCtrlXrandrAttributes * xrandr = NULL; XRRScreenConfiguration *sc; Rotation rotation, rotations; + int ver_major; + int ver_minor; /* Check parameters */ @@ -285,6 +309,15 @@ NvCtrlInitXrandrAttributes (NvCtrlAttributePrivateHandle *h) goto fail; } + /* Verify server version of the XRandR extension */ + if ( !__libXrandr->XRRQueryVersion(h->dpy, &(ver_major), &(ver_minor)) || + ((ver_major < MIN_RANDR_MAJOR) || + ((ver_major == MIN_RANDR_MAJOR) && + (ver_minor < MIN_RANDR_MINOR)))) { + XSync(h->dpy, False); + XSetErrorHandler(old_error_handler); + goto fail; + } /* Register to receive XRandR events */ __libXrandr->XRRSelectInput(h->dpy, RootWindow(h->dpy, h->target_id), @@ -564,3 +597,58 @@ NvCtrlXrandrSetScreenMagicMode (NvCtrlAttributePrivateHandle *h, return NvCtrlError; } /* NvCtrlXrandrSetScreenMagicMode */ + + + +/****************************************************************************** + * + * Gets XRandR size and refresh rate. + * + ****/ + +ReturnStatus +NvCtrlXrandrGetScreenMagicMode (NvCtrlAttributePrivateHandle *h, + int *width, int *height, int *magic_ref_rate) +{ + XRRScreenConfiguration *sc; + Rotation cur_rotation; + int nsizes; + XRRScreenSize *sizes; + int cur_size; + short cur_rate; + + + /* Validate */ + if ( !h || !h->dpy || h->target_type != NV_CTRL_TARGET_TYPE_X_SCREEN ) { + return NvCtrlBadHandle; + } + + if ( !h->xrandr || !__libXrandr ) { + return NvCtrlMissingExtension; + } + + + /* Get current screen configuration information */ + sc = __libXrandr->XRRGetScreenInfo(h->dpy, RootWindow(h->dpy, + h->target_id)); + if ( !sc ) { + return NvCtrlError; + } + cur_size = __libXrandr->XRRConfigCurrentConfiguration(sc, &cur_rotation); + cur_rate = __libXrandr->XRRConfigCurrentRate(sc); + sizes = __libXrandr->XRRConfigSizes(sc, &nsizes); + if (cur_size >= nsizes) { + __libXrandr->XRRFreeScreenConfigInfo(sc); + return NvCtrlError; + } + + + /* Get the width & height from the size information */ + *width = sizes[cur_size].width; + *height = sizes[cur_size].height; + *magic_ref_rate = (int)cur_rate; + + __libXrandr->XRRFreeScreenConfigInfo(sc); + return NvCtrlSuccess; + +} /* NvCtrlXrandrGetScreenMagicMode */ diff --git a/src/libXNVCtrlAttributes/NvCtrlAttributesXv.c b/src/libXNVCtrlAttributes/NvCtrlAttributesXv.c index 5d061d6..07ede41 100644 --- a/src/libXNVCtrlAttributes/NvCtrlAttributesXv.c +++ b/src/libXNVCtrlAttributes/NvCtrlAttributesXv.c @@ -79,6 +79,7 @@ static Bool open_libxv(void) if ( !__libXv ) { __libXv = (__libXvInfo *) calloc(1, sizeof(__libXvInfo)); if ( !__libXv ) { + error_str = "Could not allocate memory."; goto fail; } } @@ -94,6 +95,7 @@ static Bool open_libxv(void) /* We are the first to open the library */ __libXv->handle = dlopen("libXv.so.1", RTLD_LAZY); if ( __libXv->handle == NULL ) { + error_str = dlerror(); goto fail; } |