DrRect.c revision 1ab64890
1/* $Xorg: DrRect.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/DrRect.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(xPolyRectangleReq) + WRCTSPERBATCH * SIZEOF(xRectangle))
37#define zsize (SIZEOF(xPolyRectangleReq) + ZRCTSPERBATCH * SIZEOF(xRectangle))
38
39int
40XDrawRectangle(
41    register Display *dpy,
42    Drawable d,
43    GC gc,
44    int x,
45    int y, /* INT16 */
46    unsigned int width,
47    unsigned int height) /* CARD16 */
48{
49    xRectangle *rect;
50#ifdef MUSTCOPY
51    xRectangle rectdata;
52    long len = SIZEOF(xRectangle);
53
54    rect = &rectdata;
55#endif /* MUSTCOPY */
56
57    LockDisplay(dpy);
58    FlushGC(dpy, gc);
59
60    {
61    register xPolyRectangleReq *req = (xPolyRectangleReq *) dpy->last_req;
62
63    /* if same as previous request, with same drawable, batch requests */
64    if (
65          (req->reqType == X_PolyRectangle)
66       && (req->drawable == d)
67       && (req->gc == gc->gid)
68       && ((dpy->bufptr + SIZEOF(xRectangle)) <= dpy->bufmax)
69       && (((char *)dpy->bufptr - (char *)req) < (gc->values.line_width ?
70						  wsize : zsize)) ) {
71	 req->length += SIZEOF(xRectangle) >> 2;
72#ifndef MUSTCOPY
73         rect = (xRectangle *) dpy->bufptr;
74	 dpy->bufptr += SIZEOF(xRectangle);
75#endif /* not MUSTCOPY */
76	 }
77
78    else {
79	GetReqExtra(PolyRectangle, SIZEOF(xRectangle), req);
80	req->drawable = d;
81	req->gc = gc->gid;
82#ifdef MUSTCOPY
83	dpy->bufptr -= SIZEOF(xRectangle);
84#else
85	rect = (xRectangle *) NEXTPTR(req,xPolyRectangleReq);
86#endif /* MUSTCOPY */
87	}
88
89    rect->x = x;
90    rect->y = y;
91    rect->width = width;
92    rect->height = height;
93
94#ifdef MUSTCOPY
95    Data (dpy, (char *) rect, len);	/* subtracted bufptr up above */
96#endif /* MUSTCOPY */
97
98    }
99    UnlockDisplay(dpy);
100    SyncHandle();
101    return 1;
102}
103