AllPlanes.c revision 919
341N/A/* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
341N/A * Use is subject to license terms.
341N/A *
341N/A * Permission is hereby granted, free of charge, to any person obtaining a
341N/A * copy of this software and associated documentation files (the "Software"),
341N/A * to deal in the Software without restriction, including without limitation
341N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
341N/A * and/or sell copies of the Software, and to permit persons to whom the
341N/A * Software is furnished to do so, subject to the following conditions:
341N/A *
341N/A * The above copyright notice and this permission notice (including the next
341N/A * paragraph) shall be included in all copies or substantial portions of the
341N/A * Software.
341N/A *
341N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
341N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
341N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
341N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
341N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
341N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
341N/A * DEALINGS IN THE SOFTWARE.
341N/A */
341N/A
341N/A
341N/A/*
341N/A * AllPlanes.c - the client side interface to the SUN_ALLPLANES extension.
341N/A */
341N/A
341N/A#define NEED_EVENTS
341N/A#define NEED_REPLIES
341N/A#include <stdio.h>
341N/A#include <X11/Xlibint.h>
657N/A#include <X11/extensions/Xext.h>
341N/A#include <X11/extensions/extutil.h>
341N/A#include <X11/extensions/allplanesstr.h>
341N/A
493N/Astatic int close_display();
341N/A
341N/Astatic XExtensionInfo *ext_info;
493N/Astatic char *ext_name = ALLPLANESNAME;
341N/Astatic XExtensionHooks ext_hooks = {
341N/A NULL, /* create_gc */
341N/A NULL, /* copy_gc */
341N/A NULL, /* flush_gc */
341N/A NULL, /* free_gc */
341N/A NULL, /* create_font */
449N/A NULL, /* free_font */
563N/A close_display, /* close_display */
341N/A NULL, /* wire_to_event */
341N/A NULL, /* event_to_wire */
341N/A NULL, /* error */
341N/A NULL, /* error_string */
341N/A};
341N/A
341N/Astatic
341N/AXEXT_GENERATE_CLOSE_DISPLAY(close_display,
341N/A ext_info)
341N/A
341N/Astatic
392N/AXEXT_GENERATE_FIND_DISPLAY(find_display,
396N/A ext_info, ext_name, &ext_hooks,
409N/A AllPlanesNumberEvents, NULL)
422N/A
426N/A#define AllPlanesCheckExtension(dpy,i,val) \
447N/A XextCheckExtension (dpy, i, ext_name, val)
447N/A#define AllPlanesSimpleCheckExtension(dpy,i) \
604N/A XextSimpleCheckExtension (dpy, i, ext_name)
604N/A
646N/A/**********************************************************************/
657N/A
657N/ABool
341N/AXAllPlanesQueryExtension(dpy, event_basep, error_basep)
341N/A Display *dpy;
341N/A int *event_basep,
341N/A *error_basep;
341N/A{
341N/A XExtDisplayInfo *info = find_display(dpy);
341N/A
493N/A if (XextHasExtension(info)) {
341N/A *event_basep = info->codes->first_event;
341N/A *error_basep = info->codes->first_error;
341N/A return True;
493N/A } else {
341N/A return False;
341N/A }
341N/A}
341N/A
341N/A
493N/AStatus
341N/AXAllPlanesQueryVersion(dpy, major_versionp, minor_versionp)
341N/A Display *dpy;
341N/A int *major_versionp,
341N/A *minor_versionp;
493N/A{
341N/A XExtDisplayInfo *info = find_display(dpy);
341N/A xAllPlanesQueryVersionReply rep;
493N/A xAllPlanesQueryVersionReq *req;
341N/A
341N/A AllPlanesCheckExtension(dpy, info, 0);
341N/A
341N/A LockDisplay(dpy);
341N/A GetReq(AllPlanesQueryVersion, req);
341N/A req->reqType = info->codes->major_opcode;
341N/A req->allplanesReqType = X_AllPlanesQueryVersion;
493N/A if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) {
341N/A UnlockDisplay(dpy);
341N/A SyncHandle();
341N/A return 0;
341N/A }
341N/A *major_versionp = rep.majorVersion;
493N/A *minor_versionp = rep.minorVersion;
493N/A UnlockDisplay(dpy);
493N/A SyncHandle();
493N/A return 1;
341N/A}
341N/A
341N/A
341N/Avoid
341N/AXAllPlanesDrawPoints(dpy, d, points, n_points, mode)
341N/A Display *dpy;
341N/A Drawable d;
341N/A XPoint *points;
341N/A int n_points;
341N/A int mode; /* CoordMode */
341N/A{
341N/A XExtDisplayInfo *info = find_display(dpy);
341N/A xAllPlanesPolyPointReq *req;
341N/A long nbytes;
341N/A int n;
341N/A int xoff,
341N/A yoff;
341N/A XPoint pt;
341N/A
AllPlanesSimpleCheckExtension(dpy, info);
xoff = yoff = 0;
LockDisplay(dpy);
while (n_points) {
GetReq(AllPlanesPolyPoint, req);
req->reqType = info->codes->major_opcode;
req->allplanesReqType = X_AllPlanesPolyPoint;
req->drawable = d;
req->coordMode = mode;
n = n_points;
if (n > (dpy->max_request_size - req->length))
n = dpy->max_request_size - req->length;
req->length += n;
nbytes = ((long) n) << 2;
if (xoff || yoff) {
pt.x = xoff + points->x;
pt.y = yoff + points->y;
Data16(dpy, (short *) &pt, 4);
if (nbytes > 4) {
Data16(dpy, (short *) (points + 1), nbytes - 4);
}
} else {
Data16(dpy, (short *) points, nbytes);
}
n_points -= n;
if (n_points && (mode == CoordModePrevious)) {
XPoint *pptr = points;
points += n;
while (pptr != points) {
xoff += pptr->x;
yoff += pptr->y;
pptr++;
}
} else
points += n;
}
UnlockDisplay(dpy);
SyncHandle();
}
void
XAllPlanesDrawLines(dpy, d, points, npoints, mode)
Display *dpy;
Drawable d;
XPoint *points;
int npoints;
int mode;
{
XExtDisplayInfo *info = find_display(dpy);
xAllPlanesPolyLineReq *req;
long len;
AllPlanesSimpleCheckExtension(dpy, info);
LockDisplay(dpy);
GetReq(AllPlanesPolyLine, req);
req->reqType = info->codes->major_opcode;
req->allplanesReqType = X_AllPlanesPolyLine;
req->drawable = d;
req->coordMode = mode;
if ((req->length + npoints) > 65535)
npoints = 65535 - req->length; /* force BadLength, if possible */
req->length += npoints;
/* each point is 2 16-bit integers */
len = npoints << 2;
Data16(dpy, (short *) points, len);
UnlockDisplay(dpy);
SyncHandle();
}
void
XAllPlanesDrawSegments(dpy, d, segments, nsegments)
Display *dpy;
Drawable d;
XSegment *segments;
int nsegments;
{
XExtDisplayInfo *info = find_display(dpy);
xAllPlanesPolySegmentReq *req;
long len;
int n;
AllPlanesSimpleCheckExtension(dpy, info);
LockDisplay(dpy);
while (nsegments) {
GetReq(AllPlanesPolySegment, req);
req->reqType = info->codes->major_opcode;
req->allplanesReqType = X_AllPlanesPolySegment;
req->drawable = d;
n = nsegments;
len = ((long) n) << 1;
if (len > (dpy->max_request_size - req->length)) {
n = (dpy->max_request_size - req->length) >> 1;
len = ((long) n) << 1;
}
req->length += len;
len <<= 2;
Data16(dpy, (short *) segments, len);
nsegments -= n;
segments += n;
}
UnlockDisplay(dpy);
SyncHandle();
}
void
XAllPlanesDrawRectangles(dpy, d, rects, n_rects)
Display *dpy;
Drawable d;
XRectangle *rects;
int n_rects;
{
XExtDisplayInfo *info = find_display(dpy);
xAllPlanesPolyRectangleReq *req;
long len;
int n;
AllPlanesSimpleCheckExtension(dpy, info);
LockDisplay(dpy);
while (n_rects) {
GetReq(AllPlanesPolyRectangle, req);
req->reqType = info->codes->major_opcode;
req->allplanesReqType = X_AllPlanesPolyRectangle;
req->drawable = d;
n = n_rects;
len = ((long) n) << 1;
if (len > (dpy->max_request_size - req->length)) {
n = (dpy->max_request_size - req->length) >> 1;
len = ((long) n) << 1;
}
req->length += len;
len <<= 2;
Data16(dpy, (short *) rects, len);
n_rects -= n;
rects += n;
}
UnlockDisplay(dpy);
SyncHandle();
}
void
XAllPlanesFillRectangles(dpy, d, rectangles, n_rects)
Display *dpy;
Drawable d;
XRectangle *rectangles;
int n_rects;
{
XExtDisplayInfo *info = find_display(dpy);
xAllPlanesPolyFillRectangleReq *req;
long len;
int n;
AllPlanesSimpleCheckExtension(dpy, info);
LockDisplay(dpy);
while (n_rects) {
GetReq(AllPlanesPolyFillRectangle, req);
req->reqType = info->codes->major_opcode;
req->allplanesReqType = X_AllPlanesPolyFillRectangle;
req->drawable = d;
n = n_rects;
len = ((long) n) << 1;
if (len > (dpy->max_request_size - req->length)) {
n = (dpy->max_request_size - req->length) >> 1;
len = ((long) n) << 1;
}
req->length += len;
len <<= 2;
Data16(dpy, (short *) rectangles, len);
n_rects -= n;
rectangles += n;
}
UnlockDisplay(dpy);
SyncHandle();
}