diff options
author | Keith Packard <keithp@neko.keithp.com> | 2006-11-30 21:56:59 -0800 |
---|---|---|
committer | Keith Packard <keithp@neko.keithp.com> | 2006-11-30 21:56:59 -0800 |
commit | 370fa28a6afd70ec91411edf1413c0e448ae45b6 (patch) | |
tree | a45560c98ad4bc79331ffbbc2321e9d1e62c9ced | |
parent | 0dba1be7969aa56f934d93889cbd589b3dafd3d4 (diff) |
Add initial implementation of crtc gamma and mode adding requests.randr-1.2
They build. More testing seems indicated.
-rw-r--r-- | include/X11/extensions/Xrandr.h | 8 | ||||
-rw-r--r-- | src/XrrCrtc.c | 96 | ||||
-rw-r--r-- | src/XrrMode.c | 89 | ||||
-rw-r--r-- | src/XrrProperty.c | 9 |
4 files changed, 191 insertions, 11 deletions
diff --git a/include/X11/extensions/Xrandr.h b/include/X11/extensions/Xrandr.h index bd64e84..448c32d 100644 --- a/include/X11/extensions/Xrandr.h +++ b/include/X11/extensions/Xrandr.h @@ -353,10 +353,10 @@ int XRRGetCrtcGammaSize (Display *dpy, RRCrtc crtc); typedef struct _XRRCrtcGamma { - int size; - CARD16 *red; - CARD16 *green; - CARD16 *blue; + int size; + unsigned short *red; + unsigned short *green; + unsigned short *blue; } XRRCrtcGamma; XRRCrtcGamma * diff --git a/src/XrrCrtc.c b/src/XrrCrtc.c index a1372a1..afad82c 100644 --- a/src/XrrCrtc.c +++ b/src/XrrCrtc.c @@ -155,24 +155,116 @@ XRRSetCrtcConfig (Display *dpy, int XRRGetCrtcGammaSize (Display *dpy, RRCrtc crtc) { + XExtDisplayInfo *info = XRRFindDisplay(dpy); + xRRGetCrtcGammaSizeReply rep; + xRRGetCrtcGammaSizeReq *req; + int i; + + RRCheckExtension (dpy, info, 0); + + LockDisplay(dpy); + GetReq (RRGetCrtcGammaSize, req); + req->reqType = info->codes->major_opcode; + req->randrReqType = X_RRGetCrtcGammaSize; + req->crtc = crtc; + + if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) + rep.status = RRSetConfigFailed; + UnlockDisplay (dpy); + SyncHandle (); + return rep.size; } XRRCrtcGamma * XRRGetCrtcGamma (Display *dpy, RRCrtc crtc) { + XExtDisplayInfo *info = XRRFindDisplay(dpy); + xRRGetCrtcGammaReply rep; + xRRGetCrtcGammaReq *req; + int i; + XRRCrtcGamma *crtc_gamma; + long nbytes; + long nbytesRead; + + RRCheckExtension (dpy, info, 0); + + LockDisplay(dpy); + GetReq (RRGetCrtcGamma, req); + req->reqType = info->codes->major_opcode; + req->randrReqType = X_RRGetCrtcGamma; + req->crtc = crtc; + + if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) + rep.status = RRSetConfigFailed; + + nbytes = (long) rep.length << 2; + + /* three channels of CARD16 data */ + nbytesRead = (rep.size * 2 * 3); + + crtc_gamma = XRRAllocGamma (rep.size); + + if (!crtc_gamma) + { + _XEatData (dpy, (unsigned long) nbytes); + UnlockDisplay (dpy); + SyncHandle (); + return NULL; + } + _XRead16 (dpy, crtc_gamma->red, rep.size * 2); + _XRead16 (dpy, crtc_gamma->green, rep.size * 2); + _XRead16 (dpy, crtc_gamma->blue, rep.size * 2); + + if (nbytes > nbytesRead) + _XEatData (dpy, (unsigned long) (nbytes - nbytesRead)); + + UnlockDisplay (dpy); + SyncHandle (); + return crtc_gamma; } XRRCrtcGamma * XRRAllocGamma (int size) { + XRRCrtcGamma *crtc_gamma; + + crtc_gamma = Xmalloc (sizeof (XRRCrtcGamma) + + sizeof (crtc_gamma->red[0]) * size * 3); + if (!crtc_gamma) + return NULL; + crtc_gamma->size = size; + crtc_gamma->red = (unsigned short *) (crtc_gamma + 1); + crtc_gamma->green = crtc_gamma->red + size; + crtc_gamma->blue = crtc_gamma->green + size; + return crtc_gamma; } void -XRRSetCrtcGamma (Display *dpy, RRCrtc crtc, XRRCrtcGamma *gamma) +XRRSetCrtcGamma (Display *dpy, RRCrtc crtc, XRRCrtcGamma *crtc_gamma) { + XExtDisplayInfo *info = XRRFindDisplay(dpy); + xRRSetCrtcGammaReq *req; + + RRSimpleCheckExtension (dpy, info); + + LockDisplay(dpy); + GetReq (RRSetCrtcGamma, req); + req->reqType = info->codes->major_opcode; + req->randrReqType = X_RRSetCrtcGamma; + req->crtc = crtc; + req->length += (crtc_gamma->size * 2 * 3 + 3) >> 2; + /* + * Note this assumes the structure was allocated with XRRAllocGamma, + * otherwise the channels might not be contiguous + */ + Data16 (dpy, crtc_gamma->red, crtc_gamma->size * 2 * 3); + + UnlockDisplay (dpy); + SyncHandle (); } void -XRRFreeGamma (XRRCrtcGamma *gamma) +XRRFreeGamma (XRRCrtcGamma *crtc_gamma) { + Xfree (crtc_gamma); } diff --git a/src/XrrMode.c b/src/XrrMode.c index 65b60f9..fc624e1 100644 --- a/src/XrrMode.c +++ b/src/XrrMode.c @@ -35,29 +35,116 @@ XRRModeInfo * XRRAllocModeInfo (char *name, int nameLength) { + XRRModeInfo *mode_info; + + mode_info = Xmalloc (sizeof (XRRModeInfo) + nameLength + 1); + if (!mode_info) + return NULL; + memset (mode_info, '\0', sizeof (XRRModeInfo)); + mode_info->nameLength = nameLength; + mode_info->name = (char *) (mode_info + 1); + memcpy (mode_info->name, name, nameLength); + mode_info->name[nameLength] = '\0'; + return mode_info; } RRMode -XRRCreateMode (Display *dpy, Window window, XRRModeInfo *modeInfo) +XRRCreateMode (Display *dpy, Window window, XRRModeInfo *mode_info) { + XExtDisplayInfo *info = XRRFindDisplay(dpy); + xRRCreateModeReq *req; + xRRCreateModeReply rep; + long channelSize; + + RRSimpleCheckExtension (dpy, info); + + LockDisplay(dpy); + GetReq (RRCreateMode, req); + req->reqType = info->codes->major_opcode; + req->randrReqType = X_RRCreateMode; + req->length += (mode_info->nameLength + 3) >> 2; + + req->window = window; + + req->modeInfo.id = 0; + req->modeInfo.width = mode_info->width; + req->modeInfo.height = mode_info->height; + req->modeInfo.dotClock = mode_info->dotClock; + req->modeInfo.hSyncStart = mode_info->hSyncStart; + req->modeInfo.hSyncEnd = mode_info->hSyncEnd; + req->modeInfo.hTotal = mode_info->hTotal; + req->modeInfo.hSkew = mode_info->hSkew; + req->modeInfo.vSyncStart = mode_info->vSyncStart; + req->modeInfo.vSyncEnd = mode_info->vSyncEnd; + req->modeInfo.vTotal = mode_info->vTotal; + req->modeInfo.nameLength = mode_info->nameLength; + req->modeInfo.modeFlags = mode_info->modeFlags; + + Data (dpy, mode_info->name, mode_info->nameLength); + if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) + { + UnlockDisplay (dpy); + SyncHandle (); + return None; + } + + UnlockDisplay (dpy); + SyncHandle (); + return rep.mode; } void XRRDestroyMode (Display *dpy, RRMode mode) { + XExtDisplayInfo *info = XRRFindDisplay(dpy); + xRRDestroyModeReq *req; + RRSimpleCheckExtension (dpy, info); + + LockDisplay(dpy); + GetReq (RRDestroyMode, req); + req->reqType = info->codes->major_opcode; + req->randrReqType = X_RRDestroyMode; + req->mode = mode; + UnlockDisplay (dpy); + SyncHandle (); } void XRRAddOutputMode (Display *dpy, RROutput output, RRMode mode) { + XExtDisplayInfo *info = XRRFindDisplay(dpy); + xRRAddOutputModeReq *req; + RRSimpleCheckExtension (dpy, info); + + LockDisplay(dpy); + GetReq (RRAddOutputMode, req); + req->reqType = info->codes->major_opcode; + req->randrReqType = X_RRAddOutputMode; + req->output = output; + req->mode = mode; + UnlockDisplay (dpy); + SyncHandle (); } void XRRDeleteOutputMode (Display *dpy, RROutput output, RRMode mode) { + XExtDisplayInfo *info = XRRFindDisplay(dpy); + xRRDeleteOutputModeReq *req; + RRSimpleCheckExtension (dpy, info); + + LockDisplay(dpy); + GetReq (RRDeleteOutputMode, req); + req->reqType = info->codes->major_opcode; + req->randrReqType = X_RRDeleteOutputMode; + req->output = output; + req->mode = mode; + UnlockDisplay (dpy); + SyncHandle (); } void XRRFreeModeInfo (XRRModeInfo *modeInfo) { + Xfree (modeInfo); } diff --git a/src/XrrProperty.c b/src/XrrProperty.c index 3b16491..5367e1e 100644 --- a/src/XrrProperty.c +++ b/src/XrrProperty.c @@ -58,9 +58,9 @@ XRRListOutputProperties (Display *dpy, RROutput output, int *nprop) return NULL; } - if (rep.nProperties) { - nbytes = rep.nProperties * sizeof (Atom); - netbytes = rep.nProperties << 2; + if (rep.nAtoms) { + nbytes = rep.nAtoms * sizeof (Atom); + netbytes = rep.nAtoms << 2; props = (Atom *) Xmalloc (nbytes); if (props == NULL) { @@ -74,7 +74,7 @@ XRRListOutputProperties (Display *dpy, RROutput output, int *nprop) _XRead32 (dpy, props, nbytes); } - *nprop = rep.nProperties; + *nprop = rep.nAtoms; UnlockDisplay (dpy); SyncHandle (); return props; @@ -98,6 +98,7 @@ XRRQueryOutputProperty (Display *dpy, RROutput output, Atom property) req->reqType = info->codes->major_opcode; req->randrReqType = X_RRQueryOutputProperty; req->output = output; + req->property = property; if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) { UnlockDisplay (dpy); |