DrLine.c revision 1ab64890
1/* $Xorg: DrLine.c,v 1.4 2001/02/09 02:03:32 xorgcvs Exp $ */
2/*
3
4Copyright 1986, 1998  The Open Group
5
6Permission to use, copy, modify, distribute, and sell this software and its
7documentation for any purpose is hereby granted without fee, provided that
8the above copyright notice appear in all copies and that both that
9copyright notice and this permission notice appear in supporting
10documentation.
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall not be
23used in advertising or otherwise to promote the sale, use or other dealings
24in this Software without prior written authorization from The Open Group.
25
26*/
27/* $XFree86: xc/lib/X11/DrLine.c,v 1.3 2001/01/17 19:41:34 dawes Exp $ */
28
29#ifdef HAVE_CONFIG_H
30#include <config.h>
31#endif
32#include "Xlibint.h"
33
34/* precompute the maximum size of batching request allowed */
35
36#define wsize (SIZEOF(xPolySegmentReq) + WLNSPERBATCH * SIZEOF(xSegment))
37#define zsize (SIZEOF(xPolySegmentReq) + ZLNSPERBATCH * SIZEOF(xSegment))
38
39int
40XDrawLine (
41    register Display *dpy,
42    Drawable d,
43    GC gc,
44    int x1,
45    int y1,
46    int x2,
47    int y2)
48{
49    register xSegment *segment;
50#ifdef MUSTCOPY
51    xSegment segmentdata;
52    long len = SIZEOF(xSegment);
53
54    segment = &segmentdata;
55#endif /* not MUSTCOPY */
56
57    LockDisplay(dpy);
58    FlushGC(dpy, gc);
59
60    {
61    register xPolySegmentReq *req = (xPolySegmentReq *) dpy->last_req;
62
63    /* if same as previous request, with same drawable, batch requests */
64    if (
65          (req->reqType == X_PolySegment)
66       && (req->drawable == d)
67       && (req->gc == gc->gid)
68       && ((dpy->bufptr + SIZEOF(xSegment)) <= dpy->bufmax)
69       && (((char *)dpy->bufptr - (char *)req) < (gc->values.line_width ?
70						  wsize : zsize)) ) {
71	 req->length += SIZEOF(xSegment) >> 2;
72#ifndef MUSTCOPY
73         segment = (xSegment *) dpy->bufptr;
74	 dpy->bufptr += SIZEOF(xSegment);
75#endif /* not MUSTCOPY */
76	 }
77
78    else {
79	GetReqExtra (PolySegment, SIZEOF(xSegment), req);
80	req->drawable = d;
81	req->gc = gc->gid;
82#ifdef MUSTCOPY
83	dpy->bufptr -= SIZEOF(xSegment);
84#else
85	segment = (xSegment *) NEXTPTR(req,xPolySegmentReq);
86#endif /* MUSTCOPY */
87	}
88
89    segment->x1 = x1;
90    segment->y1 = y1;
91    segment->x2 = x2;
92    segment->y2 = y2;
93
94#ifdef MUSTCOPY
95    Data (dpy, (char *) &segmentdata, len);
96#endif /* MUSTCOPY */
97
98    UnlockDisplay(dpy);
99    SyncHandle();
100    }
101    return 1;
102}
103
104