1 | /*
|
---|
2 | * Copyright © 2004 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
|
---|
7 | * copyright notice and this permission notice appear in supporting
|
---|
8 | * documentation, and that the name of Keith Packard not be used in
|
---|
9 | * advertising or publicity pertaining to distribution of the software without
|
---|
10 | * specific, written prior permission. Keith Packard makes no
|
---|
11 | * representations about the suitability of this software for any purpose. It
|
---|
12 | * is provided "as is" without express or implied warranty.
|
---|
13 | *
|
---|
14 | * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
---|
15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
---|
16 | * EVENT SHALL KEITH PACKARD 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
|
---|
20 | * PERFORMANCE OF THIS SOFTWARE.
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef rasterize_span
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | static void
|
---|
27 | RASTERIZE_EDGES (pixman_image_t *image,
|
---|
28 | pixman_edge_t *l,
|
---|
29 | pixman_edge_t *r,
|
---|
30 | pixman_fixed_t t,
|
---|
31 | pixman_fixed_t b)
|
---|
32 | {
|
---|
33 | pixman_fixed_t y = t;
|
---|
34 | uint32_t *line;
|
---|
35 | uint32_t *buf = (image)->bits.bits;
|
---|
36 | int stride = (image)->bits.rowstride;
|
---|
37 | int width = (image)->bits.width;
|
---|
38 |
|
---|
39 | line = buf + pixman_fixed_to_int (y) * stride;
|
---|
40 |
|
---|
41 | for (;;)
|
---|
42 | {
|
---|
43 | pixman_fixed_t lx;
|
---|
44 | pixman_fixed_t rx;
|
---|
45 | int lxi;
|
---|
46 | int rxi;
|
---|
47 |
|
---|
48 | lx = l->x;
|
---|
49 | rx = r->x;
|
---|
50 | #if N_BITS == 1
|
---|
51 | /* For the non-antialiased case, round the coordinates up, in effect
|
---|
52 | * sampling the center of the pixel. (The AA case does a similar
|
---|
53 | * adjustment in RENDER_SAMPLES_X) */
|
---|
54 | lx += X_FRAC_FIRST(1);
|
---|
55 | rx += X_FRAC_FIRST(1);
|
---|
56 | #endif
|
---|
57 | /* clip X */
|
---|
58 | if (lx < 0)
|
---|
59 | lx = 0;
|
---|
60 | if (pixman_fixed_to_int (rx) >= width)
|
---|
61 | #if N_BITS == 1
|
---|
62 | rx = pixman_int_to_fixed (width);
|
---|
63 | #else
|
---|
64 | /* Use the last pixel of the scanline, covered 100%.
|
---|
65 | * We can't use the first pixel following the scanline,
|
---|
66 | * because accessing it could result in a buffer overrun.
|
---|
67 | */
|
---|
68 | rx = pixman_int_to_fixed (width) - 1;
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | /* Skip empty (or backwards) sections */
|
---|
72 | if (rx > lx)
|
---|
73 | {
|
---|
74 |
|
---|
75 | /* Find pixel bounds for span */
|
---|
76 | lxi = pixman_fixed_to_int (lx);
|
---|
77 | rxi = pixman_fixed_to_int (rx);
|
---|
78 |
|
---|
79 | #if N_BITS == 1
|
---|
80 | {
|
---|
81 |
|
---|
82 | #ifdef WORDS_BIGENDIAN
|
---|
83 | # define SCREEN_SHIFT_LEFT(x,n) ((x) << (n))
|
---|
84 | # define SCREEN_SHIFT_RIGHT(x,n) ((x) >> (n))
|
---|
85 | #else
|
---|
86 | # define SCREEN_SHIFT_LEFT(x,n) ((x) >> (n))
|
---|
87 | # define SCREEN_SHIFT_RIGHT(x,n) ((x) << (n))
|
---|
88 | #endif
|
---|
89 |
|
---|
90 | #define LEFT_MASK(x) \
|
---|
91 | (((x) & 0x1f) ? \
|
---|
92 | SCREEN_SHIFT_RIGHT (0xffffffff, (x) & 0x1f) : 0)
|
---|
93 | #define RIGHT_MASK(x) \
|
---|
94 | (((32 - (x)) & 0x1f) ? \
|
---|
95 | SCREEN_SHIFT_LEFT (0xffffffff, (32 - (x)) & 0x1f) : 0)
|
---|
96 |
|
---|
97 | #define MASK_BITS(x,w,l,n,r) { \
|
---|
98 | n = (w); \
|
---|
99 | r = RIGHT_MASK ((x) + n); \
|
---|
100 | l = LEFT_MASK (x); \
|
---|
101 | if (l) { \
|
---|
102 | n -= 32 - ((x) & 0x1f); \
|
---|
103 | if (n < 0) { \
|
---|
104 | n = 0; \
|
---|
105 | l &= r; \
|
---|
106 | r = 0; \
|
---|
107 | } \
|
---|
108 | } \
|
---|
109 | n >>= 5; \
|
---|
110 | }
|
---|
111 |
|
---|
112 | uint32_t *a = line;
|
---|
113 | uint32_t startmask;
|
---|
114 | uint32_t endmask;
|
---|
115 | int nmiddle;
|
---|
116 | int width = rxi - lxi;
|
---|
117 | int x = lxi;
|
---|
118 |
|
---|
119 | a += x >> 5;
|
---|
120 | x &= 0x1f;
|
---|
121 |
|
---|
122 | MASK_BITS (x, width, startmask, nmiddle, endmask);
|
---|
123 |
|
---|
124 | if (startmask) {
|
---|
125 | WRITE(image, a, READ(image, a) | startmask);
|
---|
126 | a++;
|
---|
127 | }
|
---|
128 | while (nmiddle--)
|
---|
129 | WRITE(image, a++, 0xffffffff);
|
---|
130 | if (endmask)
|
---|
131 | WRITE(image, a, READ(image, a) | endmask);
|
---|
132 | }
|
---|
133 | #else
|
---|
134 | {
|
---|
135 | DEFINE_ALPHA(line,lxi);
|
---|
136 | int lxs;
|
---|
137 | int rxs;
|
---|
138 |
|
---|
139 | /* Sample coverage for edge pixels */
|
---|
140 | lxs = RENDER_SAMPLES_X (lx, N_BITS);
|
---|
141 | rxs = RENDER_SAMPLES_X (rx, N_BITS);
|
---|
142 |
|
---|
143 | /* Add coverage across row */
|
---|
144 | if (lxi == rxi)
|
---|
145 | {
|
---|
146 | ADD_ALPHA (rxs - lxs);
|
---|
147 | }
|
---|
148 | else
|
---|
149 | {
|
---|
150 | int xi;
|
---|
151 |
|
---|
152 | ADD_ALPHA (N_X_FRAC(N_BITS) - lxs);
|
---|
153 | STEP_ALPHA;
|
---|
154 | for (xi = lxi + 1; xi < rxi; xi++)
|
---|
155 | {
|
---|
156 | ADD_ALPHA (N_X_FRAC(N_BITS));
|
---|
157 | STEP_ALPHA;
|
---|
158 | }
|
---|
159 | ADD_ALPHA (rxs);
|
---|
160 | }
|
---|
161 | }
|
---|
162 | #endif
|
---|
163 | }
|
---|
164 |
|
---|
165 | if (y == b)
|
---|
166 | break;
|
---|
167 |
|
---|
168 | #if N_BITS > 1
|
---|
169 | if (pixman_fixed_frac (y) != Y_FRAC_LAST(N_BITS))
|
---|
170 | {
|
---|
171 | RENDER_EDGE_STEP_SMALL (l);
|
---|
172 | RENDER_EDGE_STEP_SMALL (r);
|
---|
173 | y += STEP_Y_SMALL(N_BITS);
|
---|
174 | }
|
---|
175 | else
|
---|
176 | #endif
|
---|
177 | {
|
---|
178 | RENDER_EDGE_STEP_BIG (l);
|
---|
179 | RENDER_EDGE_STEP_BIG (r);
|
---|
180 | y += STEP_Y_BIG(N_BITS);
|
---|
181 | line += stride;
|
---|
182 | }
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | #undef rasterize_span
|
---|