1 /*
2 * Copyright © 2014 Keith Packard
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
23 #include "glamor_priv.h"
24
25 void
glamor_solid_boxes(PixmapPtr pixmap,BoxPtr box,int nbox,unsigned long fg_pixel)26 glamor_solid_boxes(PixmapPtr pixmap,
27 BoxPtr box, int nbox, unsigned long fg_pixel)
28 {
29 DrawablePtr drawable = &pixmap->drawable;
30 GCPtr gc;
31 xRectangle *rect;
32 int n;
33
34 rect = xallocarray(nbox, sizeof(xRectangle));
35 if (!rect)
36 return;
37 for (n = 0; n < nbox; n++) {
38 rect[n].x = box[n].x1;
39 rect[n].y = box[n].y1;
40 rect[n].width = box[n].x2 - box[n].x1;
41 rect[n].height = box[n].y2 - box[n].y1;
42 }
43
44 gc = GetScratchGC(drawable->depth, drawable->pScreen);
45 if (gc) {
46 ChangeGCVal vals[1];
47
48 vals[0].val = fg_pixel;
49 ChangeGC(NullClient, gc, GCForeground, vals);
50 ValidateGC(drawable, gc);
51 gc->ops->PolyFillRect(drawable, gc, nbox, rect);
52 FreeScratchGC(gc);
53 }
54 free(rect);
55 }
56
57 void
glamor_solid(PixmapPtr pixmap,int x,int y,int width,int height,unsigned long fg_pixel)58 glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height,
59 unsigned long fg_pixel)
60 {
61 DrawablePtr drawable = &pixmap->drawable;
62 GCPtr gc;
63 ChangeGCVal vals[1];
64 xRectangle rect;
65
66 vals[0].val = fg_pixel;
67 gc = GetScratchGC(drawable->depth, drawable->pScreen);
68 if (!gc)
69 return;
70 ChangeGC(NullClient, gc, GCForeground, vals);
71 ValidateGC(drawable, gc);
72 rect.x = x;
73 rect.y = y;
74 rect.width = width;
75 rect.height = height;
76 gc->ops->PolyFillRect(drawable, gc, 1, &rect);
77 FreeScratchGC(gc);
78 }
79
80