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 /src/XrrCrtc.c | |
parent | 0dba1be7969aa56f934d93889cbd589b3dafd3d4 (diff) |
Add initial implementation of crtc gamma and mode adding requests.
They build. More testing seems indicated.
Diffstat (limited to 'src/XrrCrtc.c')
-rw-r--r-- | src/XrrCrtc.c | 96 |
1 files changed, 94 insertions, 2 deletions
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); } |