AllPlanes.c revision 366
366N/A/* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
366N/A *
366N/A * Permission is hereby granted, free of charge, to any person obtaining a
366N/A * copy of this software and associated documentation files (the
366N/A * "Software"), to deal in the Software without restriction, including
366N/A * without limitation the rights to use, copy, modify, merge, publish,
366N/A * distribute, and/or sell copies of the Software, and to permit persons
366N/A * to whom the Software is furnished to do so, provided that the above
366N/A * copyright notice(s) and this permission notice appear in all copies of
366N/A * the Software and that both the above copyright notice(s) and this
366N/A * permission notice appear in supporting documentation.
366N/A *
366N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
366N/A * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
366N/A * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
366N/A * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
366N/A * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
366N/A * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
366N/A * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
366N/A * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
366N/A * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
366N/A *
366N/A * Except as contained in this notice, the name of a copyright holder
366N/A * shall not be used in advertising or otherwise to promote the sale, use
366N/A * or other dealings in this Software without prior written authorization
366N/A * of the copyright holder.
366N/A */
366N/A
366N/A#pragma ident "@(#)AllPlanes.c 35.6 08/03/12 SMI"
366N/A
366N/A/*
366N/A * AllPlanes.c - the client side interface to the SUN_ALLPLANES extension.
366N/A */
366N/A
366N/A#define NEED_EVENTS
366N/A#define NEED_REPLIES
366N/A#include <stdio.h>
366N/A#include <X11/Xlibint.h>
366N/A#include <X11/extensions/Xext.h>
366N/A#include <X11/extensions/extutil.h>
366N/A#include <X11/extensions/allplanesstr.h>
366N/A
366N/Astatic int close_display();
366N/A
366N/Astatic XExtensionInfo *ext_info;
366N/Astatic char *ext_name = ALLPLANESNAME;
366N/Astatic XExtensionHooks ext_hooks = {
366N/A NULL, /* create_gc */
366N/A NULL, /* copy_gc */
366N/A NULL, /* flush_gc */
366N/A NULL, /* free_gc */
366N/A NULL, /* create_font */
366N/A NULL, /* free_font */
366N/A close_display, /* close_display */
366N/A NULL, /* wire_to_event */
366N/A NULL, /* event_to_wire */
366N/A NULL, /* error */
366N/A NULL, /* error_string */
366N/A};
366N/A
366N/Astatic
366N/AXEXT_GENERATE_CLOSE_DISPLAY(close_display,
366N/A ext_info)
366N/A
366N/Astatic
366N/AXEXT_GENERATE_FIND_DISPLAY(find_display,
366N/A ext_info, ext_name, &ext_hooks,
366N/A AllPlanesNumberEvents, NULL)
366N/A
366N/A#define AllPlanesCheckExtension(dpy,i,val) \
366N/A XextCheckExtension (dpy, i, ext_name, val)
366N/A#define AllPlanesSimpleCheckExtension(dpy,i) \
366N/A XextSimpleCheckExtension (dpy, i, ext_name)
366N/A
366N/A/**********************************************************************/
366N/A
366N/ABool
366N/AXAllPlanesQueryExtension(dpy, event_basep, error_basep)
366N/A Display *dpy;
366N/A int *event_basep,
366N/A *error_basep;
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A
366N/A if (XextHasExtension(info)) {
366N/A *event_basep = info->codes->first_event;
366N/A *error_basep = info->codes->first_error;
366N/A return True;
366N/A } else {
366N/A return False;
366N/A }
366N/A}
366N/A
366N/A
366N/AStatus
366N/AXAllPlanesQueryVersion(dpy, major_versionp, minor_versionp)
366N/A Display *dpy;
366N/A int *major_versionp,
366N/A *minor_versionp;
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A xAllPlanesQueryVersionReply rep;
366N/A xAllPlanesQueryVersionReq *req;
366N/A
366N/A AllPlanesCheckExtension(dpy, info, 0);
366N/A
366N/A LockDisplay(dpy);
366N/A GetReq(AllPlanesQueryVersion, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->allplanesReqType = X_AllPlanesQueryVersion;
366N/A if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) {
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return 0;
366N/A }
366N/A *major_versionp = rep.majorVersion;
366N/A *minor_versionp = rep.minorVersion;
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A return 1;
366N/A}
366N/A
366N/A
366N/Avoid
366N/AXAllPlanesDrawPoints(dpy, d, points, n_points, mode)
366N/A Display *dpy;
366N/A Drawable d;
366N/A XPoint *points;
366N/A int n_points;
366N/A int mode; /* CoordMode */
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A xAllPlanesPolyPointReq *req;
366N/A long nbytes;
366N/A int n;
366N/A int xoff,
366N/A yoff;
366N/A XPoint pt;
366N/A
366N/A AllPlanesSimpleCheckExtension(dpy, info);
366N/A
366N/A xoff = yoff = 0;
366N/A LockDisplay(dpy);
366N/A while (n_points) {
366N/A GetReq(AllPlanesPolyPoint, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->allplanesReqType = X_AllPlanesPolyPoint;
366N/A req->drawable = d;
366N/A req->coordMode = mode;
366N/A n = n_points;
366N/A if (n > (dpy->max_request_size - req->length))
366N/A n = dpy->max_request_size - req->length;
366N/A req->length += n;
366N/A nbytes = ((long) n) << 2;
366N/A if (xoff || yoff) {
366N/A pt.x = xoff + points->x;
366N/A pt.y = yoff + points->y;
366N/A Data16(dpy, (short *) &pt, 4);
366N/A if (nbytes > 4) {
366N/A Data16(dpy, (short *) (points + 1), nbytes - 4);
366N/A }
366N/A } else {
366N/A Data16(dpy, (short *) points, nbytes);
366N/A }
366N/A n_points -= n;
366N/A if (n_points && (mode == CoordModePrevious)) {
366N/A XPoint *pptr = points;
366N/A points += n;
366N/A while (pptr != points) {
366N/A xoff += pptr->x;
366N/A yoff += pptr->y;
366N/A pptr++;
366N/A }
366N/A } else
366N/A points += n;
366N/A }
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A}
366N/A
366N/A
366N/Avoid
366N/AXAllPlanesDrawLines(dpy, d, points, npoints, mode)
366N/A Display *dpy;
366N/A Drawable d;
366N/A XPoint *points;
366N/A int npoints;
366N/A int mode;
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A xAllPlanesPolyLineReq *req;
366N/A long len;
366N/A
366N/A AllPlanesSimpleCheckExtension(dpy, info);
366N/A
366N/A LockDisplay(dpy);
366N/A GetReq(AllPlanesPolyLine, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->allplanesReqType = X_AllPlanesPolyLine;
366N/A req->drawable = d;
366N/A req->coordMode = mode;
366N/A if ((req->length + npoints) > 65535)
366N/A npoints = 65535 - req->length; /* force BadLength, if possible */
366N/A req->length += npoints;
366N/A /* each point is 2 16-bit integers */
366N/A len = npoints << 2;
366N/A Data16(dpy, (short *) points, len);
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A}
366N/A
366N/A
366N/Avoid
366N/AXAllPlanesDrawSegments(dpy, d, segments, nsegments)
366N/A Display *dpy;
366N/A Drawable d;
366N/A XSegment *segments;
366N/A int nsegments;
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A xAllPlanesPolySegmentReq *req;
366N/A long len;
366N/A int n;
366N/A
366N/A AllPlanesSimpleCheckExtension(dpy, info);
366N/A
366N/A LockDisplay(dpy);
366N/A while (nsegments) {
366N/A GetReq(AllPlanesPolySegment, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->allplanesReqType = X_AllPlanesPolySegment;
366N/A req->drawable = d;
366N/A n = nsegments;
366N/A len = ((long) n) << 1;
366N/A if (len > (dpy->max_request_size - req->length)) {
366N/A n = (dpy->max_request_size - req->length) >> 1;
366N/A len = ((long) n) << 1;
366N/A }
366N/A req->length += len;
366N/A len <<= 2;
366N/A Data16(dpy, (short *) segments, len);
366N/A nsegments -= n;
366N/A segments += n;
366N/A }
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A}
366N/A
366N/A
366N/Avoid
366N/AXAllPlanesDrawRectangles(dpy, d, rects, n_rects)
366N/A Display *dpy;
366N/A Drawable d;
366N/A XRectangle *rects;
366N/A int n_rects;
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A xAllPlanesPolyRectangleReq *req;
366N/A long len;
366N/A int n;
366N/A
366N/A AllPlanesSimpleCheckExtension(dpy, info);
366N/A
366N/A LockDisplay(dpy);
366N/A while (n_rects) {
366N/A GetReq(AllPlanesPolyRectangle, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->allplanesReqType = X_AllPlanesPolyRectangle;
366N/A req->drawable = d;
366N/A n = n_rects;
366N/A len = ((long) n) << 1;
366N/A if (len > (dpy->max_request_size - req->length)) {
366N/A n = (dpy->max_request_size - req->length) >> 1;
366N/A len = ((long) n) << 1;
366N/A }
366N/A req->length += len;
366N/A len <<= 2;
366N/A Data16(dpy, (short *) rects, len);
366N/A n_rects -= n;
366N/A rects += n;
366N/A }
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A}
366N/A
366N/A
366N/Avoid
366N/AXAllPlanesFillRectangles(dpy, d, rectangles, n_rects)
366N/A Display *dpy;
366N/A Drawable d;
366N/A XRectangle *rectangles;
366N/A int n_rects;
366N/A{
366N/A XExtDisplayInfo *info = find_display(dpy);
366N/A xAllPlanesPolyFillRectangleReq *req;
366N/A long len;
366N/A int n;
366N/A
366N/A AllPlanesSimpleCheckExtension(dpy, info);
366N/A
366N/A LockDisplay(dpy);
366N/A while (n_rects) {
366N/A GetReq(AllPlanesPolyFillRectangle, req);
366N/A req->reqType = info->codes->major_opcode;
366N/A req->allplanesReqType = X_AllPlanesPolyFillRectangle;
366N/A req->drawable = d;
366N/A n = n_rects;
366N/A len = ((long) n) << 1;
366N/A if (len > (dpy->max_request_size - req->length)) {
366N/A n = (dpy->max_request_size - req->length) >> 1;
366N/A len = ((long) n) << 1;
366N/A }
366N/A req->length += len;
366N/A len <<= 2;
366N/A Data16(dpy, (short *) rectangles, len);
366N/A n_rects -= n;
366N/A rectangles += n;
366N/A }
366N/A UnlockDisplay(dpy);
366N/A SyncHandle();
366N/A}