summaryrefslogtreecommitdiff
path: root/pixman/src/icrect.c
blob: 85375e524d4a08e923db634ae47cfcb7b771181a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * Copyright © 2000 Keith Packard
 *
 * Permission to use, copy, modify, distribute, and sell this software and its
 * documentation for any purpose is hereby granted without fee, provided that
 * the above copyright notice appear in all copies and that both that
 * copyright notice and this permission notice appear in supporting
 * documentation, and that the name of Keith Packard not be used in
 * advertising or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Keith Packard makes no
 * representations about the suitability of this software for any purpose.  It
 * is provided "as is" without express or implied warranty.
 *
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 */

#include "icint.h"

/* XXX: I haven't ported this yet
static void
IcColorRects (IcImage	 *dst,
	      IcImage	 *clipPict,
	      IcColor	 *color,
	      int	 nRect,
	      IcRectangle *rects,
	      int	 xoff,
	      int	 yoff)
{
    uint32_t		pixel;
    uint32_t		tmpval[4];
    Region		*clip;
    unsigned long	mask;

    IcRenderColorToPixel (dst->image_format, color, &pixel);

    if (clipPict->clientClipType == CT_REGION)
    {
	tmpval[2] = dst->clipOrigin.x - xoff;
	tmpval[3] = dst->clipOrigin.y - yoff;
	mask |= CPClipXOrigin|CPClipYOrigin;
	
	clip = PixRegionCreate ();
	PixRegionCopy (clip, pClipPict->clientClip);
	(*pGC->funcs->ChangeClip) (pGC, CT_REGION, pClip, 0);
    }

    if (xoff || yoff)
    {
	int	i;
	for (i = 0; i < nRect; i++)
	{
	    rects[i].x -= xoff;
	    rects[i].y -= yoff;
	}
    }
    (*pGC->ops->PolyFillRect) (pDst->pDrawable, pGC, nRect, rects);
    if (xoff || yoff)
    {
	int	i;
	for (i = 0; i < nRect; i++)
	{
	    rects[i].x += xoff;
	    rects[i].y += yoff;
	}
    }
}
*/

void IcFillRectangle (IcOperator	op,
		      IcImage		*dst,
		      const IcColor	*color,
		      int		x,
		      int		y,
		      unsigned int	width,
		      unsigned int	height)
{
    IcRectangle rect;

    rect.x = x;
    rect.y = y;
    rect.width = width;
    rect.height = height;

    IcFillRectangles (op, dst, color, &rect, 1);
}

void
IcFillRectangles (IcOperator		op,
		  IcImage		*dst,
		  const IcColor		*color,
		  const IcRectangle	*rects,
		  int			nRects)
{
    IcColor color_s = *color;

    if (color_s.alpha == 0xffff)
    {
	if (op == IcOperatorOver)
	    op = IcOperatorSrc;
    }
    if (op == IcOperatorClear)
	color_s.red = color_s.green = color_s.blue = color_s.alpha = 0;

/* XXX: Really need this to optimize solid rectangles
    if (op == IcOperatorSource || op == IcOperatorClear)
    {
	IcColorRects (dst, dst, &color_s, nRects, rects, 0, 0);
	if (dst->alphaMap)
	    IcColorRects (dst->alphaMap, dst,
			  &color_s, nRects, rects,
			  dst->alphaOrigin.x,
			  dst->alphaOrigin.y);
    }
    else
*/
    {
	IcFormat	rgbaFormat;
	IcPixels	*pixels;
	IcImage		*src;
	IcBits		pixel;

	IcFormatInit (&rgbaFormat, PICT_a8r8g8b8);
	
	pixels = IcPixelsCreate (1, 1, rgbaFormat.depth);
	if (!pixels)
	    goto bail1;
	
	IcColorToPixel (&rgbaFormat, &color_s, &pixel);

	/* XXX: Originally, fb had the following:

	   (*pGC->ops->PolyFillRect) (&pPixmap->drawable, pGC, 1, &one);

	   I haven't checked to see what I might be breaking with a
	   trivial assignment instead.
	*/
	pixels->data[0] = pixel;

	src = IcImageCreateForPixels (pixels, &rgbaFormat);
	if (!src)
	    goto bail2;

	IcImageSetRepeat (src, 1);

	while (nRects--)
	{
	    IcComposite (op, src, 0, dst, 0, 0, 0, 0, 
			 rects->x,
			 rects->y,
			 rects->width,
			 rects->height);
	    rects++;
	}

	IcImageDestroy (src);
bail2:
	IcPixelsDestroy (pixels);
bail1:
	;
    }
}
slim_hidden_def(IcFillRectangles);