1233N/A/* Copyright (c) 1990, 2011, Oracle and/or its affiliates. All rights reserved.
366N/A *
366N/A * Permission is hereby granted, free of charge, to any person obtaining a
919N/A * copy of this software and associated documentation files (the "Software"),
919N/A * to deal in the Software without restriction, including without limitation
919N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
919N/A * and/or sell copies of the Software, and to permit persons to whom the
919N/A * Software is furnished to do so, subject to the following conditions:
366N/A *
919N/A * The above copyright notice and this permission notice (including the next
919N/A * paragraph) shall be included in all copies or substantial portions of the
919N/A * Software.
366N/A *
919N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
919N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
919N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
919N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
919N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
919N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
919N/A * DEALINGS IN THE SOFTWARE.
366N/A */
366N/A
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
1233N/AXAllPlanesQueryExtension(
1233N/A Display *dpy,
366N/A int *event_basep,
1233N/A int *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
1233N/AXAllPlanesQueryVersion(
1233N/A Display *dpy,
366N/A int *major_versionp,
1233N/A int *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
1233N/AXAllPlanesDrawPoints(
1233N/A Display *dpy,
1233N/A Drawable d,
1233N/A XPoint *points,
1233N/A int n_points,
1233N/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
1233N/AXAllPlanesDrawLines(
1233N/A Display *dpy,
1233N/A Drawable d,
1233N/A XPoint *points,
1233N/A int npoints,
1233N/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
1233N/AXAllPlanesDrawSegments(
1233N/A Display *dpy,
1233N/A Drawable d,
1233N/A XSegment *segments,
1233N/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
1233N/AXAllPlanesDrawRectangles(
1233N/A Display *dpy,
1233N/A Drawable d,
1233N/A XRectangle *rects,
1233N/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
1233N/AXAllPlanesFillRectangles(
1233N/A Display *dpy,
1233N/A Drawable d,
1233N/A XRectangle *rectangles,
1233N/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}