author | ohair |
Wed, 06 Apr 2011 22:06:11 -0700 | |
changeset 9035 | 1255eb81cc2f |
parent 7745 | ebd6382e93fd |
child 20421 | 8fab9959a1bc |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
7745
diff
changeset
|
2 |
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
7745 | 26 |
#include <math.h> |
27 |
#include <stdlib.h> |
|
28 |
#include <string.h> |
|
2 | 29 |
#include "GraphicsPrimitiveMgr.h" |
7745 | 30 |
#include "ParallelogramUtils.h" |
2 | 31 |
|
32 |
#include "sun_java2d_loops_MaskFill.h" |
|
33 |
||
34 |
/* |
|
35 |
* Class: sun_java2d_loops_MaskFill |
|
36 |
* Method: MaskFill |
|
37 |
* Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;Ljava/awt/Composite;IIII[BII)V |
|
38 |
*/ |
|
39 |
JNIEXPORT void JNICALL |
|
40 |
Java_sun_java2d_loops_MaskFill_MaskFill |
|
41 |
(JNIEnv *env, jobject self, |
|
42 |
jobject sg2d, jobject sData, jobject comp, |
|
43 |
jint x, jint y, jint w, jint h, |
|
44 |
jbyteArray maskArray, jint maskoff, jint maskscan) |
|
45 |
{ |
|
46 |
SurfaceDataOps *sdOps; |
|
47 |
SurfaceDataRasInfo rasInfo; |
|
48 |
NativePrimitive *pPrim; |
|
49 |
CompositeInfo compInfo; |
|
50 |
||
51 |
pPrim = GetNativePrim(env, self); |
|
52 |
if (pPrim == NULL) { |
|
53 |
return; |
|
54 |
} |
|
55 |
if (pPrim->pCompType->getCompInfo != NULL) { |
|
56 |
(*pPrim->pCompType->getCompInfo)(env, &compInfo, comp); |
|
57 |
} |
|
58 |
||
59 |
sdOps = SurfaceData_GetOps(env, sData); |
|
60 |
if (sdOps == 0) { |
|
61 |
return; |
|
62 |
} |
|
63 |
||
64 |
rasInfo.bounds.x1 = x; |
|
65 |
rasInfo.bounds.y1 = y; |
|
66 |
rasInfo.bounds.x2 = x + w; |
|
67 |
rasInfo.bounds.y2 = y + h; |
|
68 |
if (sdOps->Lock(env, sdOps, &rasInfo, pPrim->dstflags) != SD_SUCCESS) { |
|
69 |
return; |
|
70 |
} |
|
71 |
||
72 |
if (rasInfo.bounds.x2 > rasInfo.bounds.x1 && |
|
73 |
rasInfo.bounds.y2 > rasInfo.bounds.y1) |
|
74 |
{ |
|
75 |
jint color = GrPrim_Sg2dGetEaRGB(env, sg2d); |
|
76 |
sdOps->GetRasInfo(env, sdOps, &rasInfo); |
|
77 |
if (rasInfo.rasBase) { |
|
78 |
jint width = rasInfo.bounds.x2 - rasInfo.bounds.x1; |
|
79 |
jint height = rasInfo.bounds.y2 - rasInfo.bounds.y1; |
|
80 |
void *pDst = PtrCoord(rasInfo.rasBase, |
|
81 |
rasInfo.bounds.x1, rasInfo.pixelStride, |
|
82 |
rasInfo.bounds.y1, rasInfo.scanStride); |
|
83 |
unsigned char *pMask = |
|
84 |
(maskArray |
|
85 |
? (*env)->GetPrimitiveArrayCritical(env, maskArray, 0) |
|
86 |
: 0); |
|
87 |
maskoff += ((rasInfo.bounds.y1 - y) * maskscan + |
|
88 |
(rasInfo.bounds.x1 - x)); |
|
89 |
(*pPrim->funcs.maskfill)(pDst, |
|
90 |
pMask, maskoff, maskscan, |
|
91 |
width, height, |
|
92 |
color, &rasInfo, |
|
93 |
pPrim, &compInfo); |
|
94 |
if (pMask) { |
|
95 |
(*env)->ReleasePrimitiveArrayCritical(env, maskArray, |
|
96 |
pMask, JNI_ABORT); |
|
97 |
} |
|
98 |
} |
|
99 |
SurfaceData_InvokeRelease(env, sdOps, &rasInfo); |
|
7745 | 100 |
} |
101 |
SurfaceData_InvokeUnlock(env, sdOps, &rasInfo); |
|
102 |
} |
|
103 |
||
104 |
#define MASK_BUF_LEN 1024 |
|
105 |
||
106 |
#define DblToMask(v) ((unsigned char) ((v)*255.9999)) |
|
107 |
||
108 |
/* Fills an aligned rectangle with potentially translucent edges. */ |
|
109 |
static void |
|
110 |
fillAARect(NativePrimitive *pPrim, SurfaceDataRasInfo *pRasInfo, |
|
111 |
CompositeInfo *pCompInfo, jint color, unsigned char *pMask, |
|
112 |
void *pDst, |
|
113 |
jdouble x1, jdouble y1, jdouble x2, jdouble y2) |
|
114 |
{ |
|
115 |
jint cx1 = pRasInfo->bounds.x1; |
|
116 |
jint cy1 = pRasInfo->bounds.y1; |
|
117 |
jint cx2 = pRasInfo->bounds.x2; |
|
118 |
jint cy2 = pRasInfo->bounds.y2; |
|
119 |
jint rx1 = (jint) ceil(x1); |
|
120 |
jint ry1 = (jint) ceil(y1); |
|
121 |
jint rx2 = (jint) floor(x2); |
|
122 |
jint ry2 = (jint) floor(y2); |
|
123 |
jint width = cx2 - cx1; |
|
124 |
jint scan = pRasInfo->scanStride; |
|
125 |
/* Convert xy12 into the edge coverage fractions for those edges. */ |
|
126 |
x1 = rx1-x1; |
|
127 |
y1 = ry1-y1; |
|
128 |
x2 = x2-rx2; |
|
129 |
y2 = y2-ry2; |
|
130 |
if (ry2 < ry1) { |
|
131 |
/* Accumulate bottom coverage into top coverage. */ |
|
132 |
y1 = y1 + y2 - 1.0; |
|
133 |
/* prevent processing of "bottom fractional row" */ |
|
134 |
ry2 = cy2; |
|
135 |
} |
|
136 |
if (rx2 < rx1) { |
|
137 |
/* Accumulate right coverage into left coverage. */ |
|
138 |
x1 = x1 + x2 - 1.0; |
|
139 |
/* prevent processing of "right fractional column" */ |
|
140 |
rx2 = cx2; |
|
141 |
} |
|
142 |
/* Check for a visible "top fractional row" and process it */ |
|
143 |
if (cy1 < ry1) { |
|
144 |
unsigned char midcov = DblToMask(y1); |
|
145 |
jint x; |
|
146 |
for (x = 0; x < width; x++) { |
|
147 |
pMask[x] = midcov; |
|
148 |
} |
|
149 |
if (cx1 < rx1) { |
|
150 |
pMask[0] = DblToMask(y1 * x1); |
|
151 |
} |
|
152 |
if (cx2 > rx2) { |
|
153 |
pMask[width-1] = DblToMask(y1 * x2); |
|
154 |
} |
|
155 |
(*pPrim->funcs.maskfill)(pDst, |
|
156 |
pMask, 0, 0, |
|
157 |
width, 1, |
|
158 |
color, pRasInfo, |
|
159 |
pPrim, pCompInfo); |
|
160 |
pDst = PtrAddBytes(pDst, scan); |
|
161 |
cy1++; |
|
162 |
} |
|
163 |
/* Check for a visible "left fract, solid middle, right fract" section. */ |
|
164 |
if (cy1 < ry2 && cy1 < cy2) { |
|
165 |
jint midh = ((ry2 < cy2) ? ry2 : cy2) - cy1; |
|
166 |
jint midx = cx1; |
|
167 |
void *pMid = pDst; |
|
168 |
/* First process the left "fractional column" if it is visible. */ |
|
169 |
if (midx < rx1) { |
|
170 |
pMask[0] = DblToMask(x1); |
|
171 |
/* Note: maskscan == 0 means we reuse this value for every row. */ |
|
172 |
(*pPrim->funcs.maskfill)(pMid, |
|
173 |
pMask, 0, 0, |
|
174 |
1, midh, |
|
175 |
color, pRasInfo, |
|
176 |
pPrim, pCompInfo); |
|
177 |
pMid = PtrAddBytes(pMid, pRasInfo->pixelStride); |
|
178 |
midx++; |
|
179 |
} |
|
180 |
/* Process the central solid section if it is visible. */ |
|
181 |
if (midx < rx2 && midx < cx2) { |
|
182 |
jint midw = ((rx2 < cx2) ? rx2 : cx2) - midx; |
|
183 |
/* A NULL mask buffer means "all coverages are 0xff" */ |
|
184 |
(*pPrim->funcs.maskfill)(pMid, |
|
185 |
NULL, 0, 0, |
|
186 |
midw, midh, |
|
187 |
color, pRasInfo, |
|
188 |
pPrim, pCompInfo); |
|
189 |
pMid = PtrCoord(pMid, midw, pRasInfo->pixelStride, 0, 0); |
|
190 |
midx += midw; |
|
191 |
} |
|
192 |
/* Finally process the right "fractional column" if it is visible. */ |
|
193 |
if (midx < cx2) { |
|
194 |
pMask[0] = DblToMask(x2); |
|
195 |
/* Note: maskscan == 0 means we reuse this value for every row. */ |
|
196 |
(*pPrim->funcs.maskfill)(pMid, |
|
197 |
pMask, 0, 0, |
|
198 |
1, midh, |
|
199 |
color, pRasInfo, |
|
200 |
pPrim, pCompInfo); |
|
201 |
} |
|
202 |
cy1 += midh; |
|
203 |
pDst = PtrCoord(pDst, 0, 0, midh, scan); |
|
204 |
} |
|
205 |
/* Check for a visible "bottom fractional row" and process it */ |
|
206 |
if (cy1 < cy2) { |
|
207 |
unsigned char midcov = DblToMask(y2); |
|
208 |
jint x; |
|
209 |
for (x = 0; x < width; x++) { |
|
210 |
pMask[x] = midcov; |
|
211 |
} |
|
212 |
if (cx1 < rx1) { |
|
213 |
pMask[0] = DblToMask(y2 * x1); |
|
214 |
} |
|
215 |
if (cx2 > rx2) { |
|
216 |
pMask[width-1] = DblToMask(y2 * x2); |
|
217 |
} |
|
218 |
(*pPrim->funcs.maskfill)(pDst, |
|
219 |
pMask, 0, 0, |
|
220 |
width, 1, |
|
221 |
color, pRasInfo, |
|
222 |
pPrim, pCompInfo); |
|
223 |
} |
|
224 |
} |
|
225 |
||
226 |
/* |
|
227 |
* Support code for arbitrary tracing and MaskFill filling of |
|
228 |
* non-rectilinear (diagonal) parallelograms. |
|
229 |
* |
|
230 |
* This code is based upon the following model of AA coverage. |
|
231 |
* |
|
232 |
* Each edge of a parallelogram (for fillPgram) or a double |
|
233 |
* parallelogram (inner and outer parallelograms for drawPgram) |
|
234 |
* can be rasterized independently because the geometry is well |
|
235 |
* defined in such a way that none of the sides will ever cross |
|
236 |
* each other and they have a fixed ordering that is fairly |
|
237 |
* well predetermined. |
|
238 |
* |
|
239 |
* So, for each edge we will look at the diagonal line that |
|
240 |
* the edge makes as it passes through a row of pixels. Some |
|
241 |
* such diagonal lines may pass entirely through the row of |
|
242 |
* pixels in a single pixel column. Some may cut across the |
|
243 |
* row and pass through several pixel columns before they pass |
|
244 |
* on to the next row. |
|
245 |
* |
|
246 |
* As the edge passes through the row of pixels it will affect |
|
247 |
* the coverage of the pixels it passes through as well as all |
|
248 |
* of the pixels to the right of the edge. The coverage will |
|
249 |
* either be increased (by a left edge of a parallelogram) or |
|
250 |
* decreased (by a right edge) for all pixels to the right, until |
|
251 |
* another edge passing the opposite direction is encountered. |
|
252 |
* |
|
253 |
* The coverage added or subtracted by an edge as it crosses a |
|
254 |
* given pixel is calculated using a trapezoid formula in the |
|
255 |
* following manner: |
|
256 |
* |
|
257 |
* / |
|
258 |
* +-----+---/-+-----+ |
|
259 |
* | | / | | |
|
260 |
* | | / | | |
|
261 |
* +-----+/----+-----+ |
|
262 |
* / |
|
263 |
* |
|
264 |
* The area to the right of that edge for the pixel where it |
|
265 |
* crosses is given as: |
|
266 |
* |
|
267 |
* trapheight * (topedge + bottomedge)/2 |
|
268 |
* |
|
269 |
* Another thing to note is that the above formula gives the |
|
270 |
* contribution of that edge to the given pixel where it crossed, |
|
271 |
* but in so crossing the pixel row, it also created 100% coverage |
|
272 |
* for all of the pixels to the right. |
|
273 |
* |
|
274 |
* This example was simplified in that the edge depicted crossed |
|
275 |
* the complete pixel row and it did so entirely within the bounds |
|
276 |
* of a single pixel column. In practice, many edges may start or |
|
277 |
* end in a given row and thus provide only partial row coverage |
|
278 |
* (i.e. the total "trapheight" in the formula never reaches 1.0). |
|
279 |
* And in other cases, edges may travel sideways through several |
|
280 |
* pixel columns on a given pixel row from where they enter it to |
|
281 |
* where the leave it (which also mans that the trapheight for a |
|
282 |
* given pixel will be less than 1.0, but by the time the edge |
|
283 |
* completes its journey through the pixel row the "coverage shadow" |
|
284 |
* that it casts on all pixels to the right eventually reaches 100%). |
|
285 |
* |
|
286 |
* In order to simplify the calculations so that we don't have to |
|
287 |
* keep propagating coverages we calculate for one edge "until we |
|
288 |
* reach another edge" we will process one edge at a time and |
|
289 |
* simply record in a buffer the amount that an edge added to |
|
290 |
* or subtracted from the coverage for a given pixel and its |
|
291 |
* following right-side neighbors. Thus, the true total coverage |
|
292 |
* of a given pixel is only determined by summing the deltas for |
|
293 |
* that pixel and all of the pixels to its left. Since we already |
|
294 |
* have to scan the buffer to change floating point coverages into |
|
295 |
* mask values for a MaskFill loop, it is simple enough to sum the |
|
296 |
* values as we perform that scan from left to right. |
|
297 |
* |
|
298 |
* In the above example, note that 2 deltas need to be recorded even |
|
299 |
* though the edge only intersected a single pixel. The delta recorded |
|
300 |
* for the pixel where the edge crossed will be approximately 55% |
|
301 |
* (guesstimating by examining the poor ascii art) which is fine for |
|
302 |
* determining how to render that pixel, but the rest of the pixels |
|
303 |
* to its right should have their coverage modified by a full 100% |
|
304 |
* and the 55% delta value we recorded for the pixel that the edge |
|
305 |
* crossed will not get them there. We adjust for this by adding |
|
306 |
* the "remainder" of the coverage implied by the shadow to the |
|
307 |
* pixel immediately to the right of where we record a trapezoidal |
|
308 |
* contribution. In this case a delta of 45% will be recorded in |
|
309 |
* the pixel immediately to the right to raise the total to 100%. |
|
310 |
* |
|
311 |
* As we sum these delta values as we process the line from left |
|
312 |
* to right, these delta values will typically drive the sum from |
|
313 |
* 0% up to 100% and back down to 0% over the course of a single |
|
314 |
* pixel row. In the case of a drawn (double) parallelogram the |
|
315 |
* sum will go to 100% and back to 0% twice on most scanlines. |
|
316 |
* |
|
317 |
* The fillAAPgram and drawAAPgram functions drive the main flow |
|
318 |
* of the algorithm with help from the following structures, |
|
319 |
* macros, and functions. It is probably best to start with |
|
320 |
* those 2 functions to gain an understanding of the algorithm. |
|
321 |
*/ |
|
322 |
typedef struct { |
|
323 |
jdouble x; |
|
324 |
jdouble y; |
|
325 |
jdouble xbot; |
|
326 |
jdouble ybot; |
|
327 |
jdouble xnexty; |
|
328 |
jdouble ynextx; |
|
329 |
jdouble xnextx; |
|
330 |
jdouble linedx; |
|
331 |
jdouble celldx; |
|
332 |
jdouble celldy; |
|
333 |
jboolean isTrailing; |
|
334 |
} EdgeInfo; |
|
335 |
||
336 |
#define MIN_DELTA (1.0/256.0) |
|
337 |
||
338 |
/* |
|
339 |
* Calculates slopes and deltas for an edge and stores results in an EdgeInfo. |
|
340 |
* Returns true if the edge was valid (i.e. not ignored for some reason). |
|
341 |
*/ |
|
342 |
static jboolean |
|
343 |
storeEdge(EdgeInfo *pEdge, |
|
344 |
jdouble x, jdouble y, jdouble dx, jdouble dy, |
|
345 |
jint cx1, jint cy1, jint cx2, jint cy2, |
|
346 |
jboolean isTrailing) |
|
347 |
{ |
|
348 |
jdouble xbot = x + dx; |
|
349 |
jdouble ybot = y + dy; |
|
350 |
jboolean ret; |
|
351 |
||
352 |
pEdge->x = x; |
|
353 |
pEdge->y = y; |
|
354 |
pEdge->xbot = xbot; |
|
355 |
pEdge->ybot = ybot; |
|
356 |
||
357 |
/* Note that parallelograms are sorted so dy is always non-negative */ |
|
358 |
if (dy > MIN_DELTA && /* NaN and horizontal protection */ |
|
359 |
ybot > cy1 && /* NaN and "OUT_ABOVE" protection */ |
|
360 |
y < cy2 && /* NaN and "OUT_BELOW" protection */ |
|
361 |
xbot == xbot && /* NaN protection */ |
|
362 |
(x < cx2 || xbot < cx2)) /* "OUT_RIGHT" protection */ |
|
363 |
/* Note: "OUT_LEFT" segments may still contribute coverage... */ |
|
364 |
{ |
|
365 |
/* no NaNs, dy is not horizontal, and segment contributes to clip */ |
|
366 |
if (dx < -MIN_DELTA || dx > MIN_DELTA) { |
|
367 |
/* dx is not vertical */ |
|
368 |
jdouble linedx; |
|
369 |
jdouble celldy; |
|
370 |
jdouble nextx; |
|
371 |
||
372 |
linedx = dx / dy; |
|
373 |
celldy = dy / dx; |
|
374 |
if (y < cy1) { |
|
375 |
pEdge->x = x = x + (cy1 - y) * linedx; |
|
376 |
pEdge->y = y = cy1; |
|
377 |
} |
|
378 |
pEdge->linedx = linedx; |
|
379 |
if (dx < 0) { |
|
380 |
pEdge->celldx = -1.0; |
|
381 |
pEdge->celldy = -celldy; |
|
382 |
pEdge->xnextx = nextx = ceil(x) - 1.0; |
|
383 |
} else { |
|
384 |
pEdge->celldx = +1.0; |
|
385 |
pEdge->celldy = celldy; |
|
386 |
pEdge->xnextx = nextx = floor(x) + 1.0; |
|
387 |
} |
|
388 |
pEdge->ynextx = y + (nextx - x) * celldy; |
|
389 |
pEdge->xnexty = x + ((floor(y) + 1) - y) * linedx; |
|
390 |
} else { |
|
391 |
/* dx is essentially vertical */ |
|
392 |
if (y < cy1) { |
|
393 |
pEdge->y = y = cy1; |
|
394 |
} |
|
395 |
pEdge->xbot = x; |
|
396 |
pEdge->linedx = 0.0; |
|
397 |
pEdge->celldx = 0.0; |
|
398 |
pEdge->celldy = 1.0; |
|
399 |
pEdge->xnextx = x; |
|
400 |
pEdge->xnexty = x; |
|
401 |
pEdge->ynextx = ybot; |
|
402 |
} |
|
403 |
ret = JNI_TRUE; |
|
404 |
} else { |
|
405 |
/* There is some reason to ignore this segment, "celldy=0" omits it */ |
|
406 |
pEdge->ybot = y; |
|
407 |
pEdge->linedx = dx; |
|
408 |
pEdge->celldx = dx; |
|
409 |
pEdge->celldy = 0.0; |
|
410 |
pEdge->xnextx = xbot; |
|
411 |
pEdge->xnexty = xbot; |
|
412 |
pEdge->ynextx = y; |
|
413 |
ret = JNI_FALSE; |
|
414 |
} |
|
415 |
pEdge->isTrailing = isTrailing; |
|
416 |
return ret; |
|
417 |
} |
|
418 |
||
419 |
/* |
|
420 |
* Calculates and stores slopes and deltas for all edges of a parallelogram. |
|
421 |
* Returns true if at least 1 edge was valid (i.e. not ignored for some reason). |
|
422 |
* |
|
423 |
* The inverted flag is true for an outer parallelogram (left and right |
|
424 |
* edges are leading and trailing) and false for an inner parallelogram |
|
425 |
* (where the left edge is trailing and the right edge is leading). |
|
426 |
*/ |
|
427 |
static jboolean |
|
428 |
storePgram(EdgeInfo *pLeftEdge, EdgeInfo *pRightEdge, |
|
429 |
jdouble x, jdouble y, |
|
430 |
jdouble dx1, jdouble dy1, |
|
431 |
jdouble dx2, jdouble dy2, |
|
432 |
jint cx1, jint cy1, jint cx2, jint cy2, |
|
433 |
jboolean inverted) |
|
434 |
{ |
|
435 |
jboolean ret = JNI_FALSE; |
|
436 |
ret = (storeEdge(pLeftEdge + 0, |
|
437 |
x , y , dx1, dy1, |
|
438 |
cx1, cy1, cx2, cy2, inverted) || ret); |
|
439 |
ret = (storeEdge(pLeftEdge + 1, |
|
440 |
x+dx1, y+dy1, dx2, dy2, |
|
441 |
cx1, cy1, cx2, cy2, inverted) || ret); |
|
442 |
ret = (storeEdge(pRightEdge + 0, |
|
443 |
x , y , dx2, dy2, |
|
444 |
cx1, cy1, cx2, cy2, !inverted) || ret); |
|
445 |
ret = (storeEdge(pRightEdge + 1, |
|
446 |
x+dx2, y+dy2, dx1, dy1, |
|
447 |
cx1, cy1, cx2, cy2, !inverted) || ret); |
|
448 |
return ret; |
|
449 |
} |
|
450 |
||
451 |
/* |
|
452 |
* The X0,Y0,X1,Y1 values represent a trapezoidal fragment whose |
|
453 |
* coverage must be accounted for in the accum buffer. |
|
454 |
* |
|
455 |
* All four values are assumed to fall within (or on the edge of) |
|
456 |
* a single pixel. |
|
457 |
* |
|
458 |
* The trapezoid area is accumulated into the proper element of |
|
459 |
* the accum buffer and the remainder of the "slice height" is |
|
460 |
* accumulated into the element to its right. |
|
461 |
*/ |
|
462 |
#define INSERT_ACCUM(pACCUM, IMIN, IMAX, X0, Y0, X1, Y1, CX1, CX2, MULT) \ |
|
463 |
do { \ |
|
464 |
jdouble xmid = ((X0) + (X1)) * 0.5; \ |
|
465 |
if (xmid <= (CX2)) { \ |
|
466 |
jdouble sliceh = ((Y1) - (Y0)); \ |
|
467 |
jdouble slicearea; \ |
|
468 |
jint i; \ |
|
469 |
if (xmid < (CX1)) { \ |
|
470 |
/* Accumulate the entire slice height into accum[0]. */ \ |
|
471 |
i = 0; \ |
|
472 |
slicearea = sliceh; \ |
|
473 |
} else { \ |
|
474 |
jdouble xpos = floor(xmid); \ |
|
475 |
i = ((jint) xpos) - (CX1); \ |
|
476 |
slicearea = (xpos+1-xmid) * sliceh; \ |
|
477 |
} \ |
|
478 |
if (IMIN > i) { \ |
|
479 |
IMIN = i; \ |
|
480 |
} \ |
|
481 |
(pACCUM)[i++] += (jfloat) ((MULT) * slicearea); \ |
|
482 |
(pACCUM)[i++] += (jfloat) ((MULT) * (sliceh - slicearea)); \ |
|
483 |
if (IMAX < i) { \ |
|
484 |
IMAX = i; \ |
|
485 |
} \ |
|
486 |
} \ |
|
487 |
} while (0) |
|
488 |
||
489 |
/* |
|
490 |
* Accumulate the contributions for a given edge crossing a given |
|
491 |
* scan line into the corresponding entries of the accum buffer. |
|
492 |
* CY1 is the Y coordinate of the top edge of the scanline and CY2 |
|
493 |
* is equal to (CY1 + 1) and is the Y coordinate of the bottom edge |
|
494 |
* of the scanline. CX1 and CX2 are the left and right edges of the |
|
495 |
* clip (or area of interest) being rendered. |
|
496 |
* |
|
497 |
* The edge is processed from the top edge to the bottom edge and |
|
498 |
* a single pixel column at a time. |
|
499 |
*/ |
|
500 |
#define ACCUM_EDGE(pEDGE, pACCUM, IMIN, IMAX, CX1, CY1, CX2, CY2) \ |
|
501 |
do { \ |
|
502 |
jdouble x, y, xnext, ynext, xlast, ylast, dx, dy, mult; \ |
|
503 |
y = (pEDGE)->y; \ |
|
504 |
dy = (pEDGE)->celldy; \ |
|
505 |
ylast = (pEDGE)->ybot; \ |
|
506 |
if (ylast <= (CY1) || y >= (CY2) || dy == 0.0) { \ |
|
507 |
break; \ |
|
508 |
} \ |
|
509 |
x = (pEDGE)->x; \ |
|
510 |
dx = (pEDGE)->celldx; \ |
|
511 |
if (ylast > (CY2)) { \ |
|
512 |
ylast = (CY2); \ |
|
513 |
xlast = (pEDGE)->xnexty; \ |
|
514 |
} else { \ |
|
515 |
xlast = (pEDGE)->xbot; \ |
|
516 |
} \ |
|
517 |
xnext = (pEDGE)->xnextx; \ |
|
518 |
ynext = (pEDGE)->ynextx; \ |
|
519 |
mult = ((pEDGE)->isTrailing) ? -1.0 : 1.0; \ |
|
520 |
while (ynext <= ylast) { \ |
|
521 |
INSERT_ACCUM(pACCUM, IMIN, IMAX, \ |
|
522 |
x, y, xnext, ynext, \ |
|
523 |
CX1, CX2, mult); \ |
|
524 |
x = xnext; \ |
|
525 |
y = ynext; \ |
|
526 |
xnext += dx; \ |
|
527 |
ynext += dy; \ |
|
528 |
} \ |
|
529 |
(pEDGE)->ynextx = ynext; \ |
|
530 |
(pEDGE)->xnextx = xnext; \ |
|
531 |
INSERT_ACCUM(pACCUM, IMIN, IMAX, \ |
|
532 |
x, y, xlast, ylast, \ |
|
533 |
CX1, CX2, mult); \ |
|
534 |
(pEDGE)->x = xlast; \ |
|
535 |
(pEDGE)->y = ylast; \ |
|
536 |
(pEDGE)->xnexty = xlast + (pEDGE)->linedx; \ |
|
537 |
} while(0) |
|
538 |
||
539 |
/* Main function to fill a single Parallelogram */ |
|
540 |
static void |
|
541 |
fillAAPgram(NativePrimitive *pPrim, SurfaceDataRasInfo *pRasInfo, |
|
542 |
CompositeInfo *pCompInfo, jint color, unsigned char *pMask, |
|
543 |
void *pDst, |
|
544 |
jdouble x1, jdouble y1, |
|
545 |
jdouble dx1, jdouble dy1, |
|
546 |
jdouble dx2, jdouble dy2) |
|
547 |
{ |
|
548 |
jint cx1 = pRasInfo->bounds.x1; |
|
549 |
jint cy1 = pRasInfo->bounds.y1; |
|
550 |
jint cx2 = pRasInfo->bounds.x2; |
|
551 |
jint cy2 = pRasInfo->bounds.y2; |
|
552 |
jint width = cx2 - cx1; |
|
553 |
EdgeInfo edges[4]; |
|
554 |
jfloat localaccum[MASK_BUF_LEN + 1]; |
|
555 |
jfloat *pAccum; |
|
556 |
||
557 |
if (!storePgram(edges + 0, edges + 2, |
|
558 |
x1, y1, dx1, dy1, dx2, dy2, |
|
559 |
cx1, cy1, cx2, cy2, |
|
560 |
JNI_FALSE)) |
|
561 |
{ |
|
562 |
return; |
|
563 |
} |
|
564 |
||
565 |
pAccum = ((width > MASK_BUF_LEN) |
|
566 |
? malloc((width + 1) * sizeof(jfloat)) |
|
567 |
: localaccum); |
|
568 |
if (pAccum == NULL) { |
|
569 |
return; |
|
570 |
} |
|
571 |
memset(pAccum, 0, (width+1) * sizeof(jfloat)); |
|
572 |
||
573 |
while (cy1 < cy2) { |
|
574 |
jint lmin, lmax, rmin, rmax; |
|
575 |
jint moff, x; |
|
576 |
jdouble accum; |
|
577 |
unsigned char lastcov; |
|
578 |
||
579 |
lmin = rmin = width + 2; |
|
580 |
lmax = rmax = 0; |
|
581 |
ACCUM_EDGE(&edges[0], pAccum, lmin, lmax, |
|
582 |
cx1, cy1, cx2, cy1+1); |
|
583 |
ACCUM_EDGE(&edges[1], pAccum, lmin, lmax, |
|
584 |
cx1, cy1, cx2, cy1+1); |
|
585 |
ACCUM_EDGE(&edges[2], pAccum, rmin, rmax, |
|
586 |
cx1, cy1, cx2, cy1+1); |
|
587 |
ACCUM_EDGE(&edges[3], pAccum, rmin, rmax, |
|
588 |
cx1, cy1, cx2, cy1+1); |
|
589 |
if (lmax > width) { |
|
590 |
lmax = width; /* Extra col has data we do not need. */ |
|
591 |
} |
|
592 |
if (rmax > width) { |
|
593 |
rmax = width; /* Extra col has data we do not need. */ |
|
594 |
} |
|
595 |
/* If ranges overlap, handle both in the first pass. */ |
|
596 |
if (rmin <= lmax) { |
|
597 |
lmax = rmax; |
|
598 |
} |
|
599 |
||
600 |
x = lmin; |
|
601 |
accum = 0.0; |
|
602 |
moff = 0; |
|
603 |
lastcov = 0; |
|
604 |
while (x < lmax) { |
|
605 |
accum += pAccum[x]; |
|
606 |
pAccum[x] = 0.0f; |
|
607 |
pMask[moff++] = lastcov = DblToMask(accum); |
|
608 |
x++; |
|
609 |
} |
|
610 |
/* Check for a solid center section. */ |
|
611 |
if (lastcov == 0xFF) { |
|
612 |
jint endx; |
|
613 |
void *pRow; |
|
614 |
||
615 |
/* First process the existing partial coverage data. */ |
|
616 |
if (moff > 0) { |
|
617 |
pRow = PtrCoord(pDst, x-moff, pRasInfo->pixelStride, 0, 0); |
|
618 |
(*pPrim->funcs.maskfill)(pRow, |
|
619 |
pMask, 0, 0, |
|
620 |
moff, 1, |
|
621 |
color, pRasInfo, |
|
622 |
pPrim, pCompInfo); |
|
623 |
moff = 0; |
|
624 |
} |
|
625 |
||
626 |
/* Where does the center section end? */ |
|
627 |
/* If there is no right AA edge in the accum buffer, then */ |
|
628 |
/* the right edge was beyond the clip, so fill out to width */ |
|
629 |
endx = (rmin < rmax) ? rmin : width; |
|
630 |
if (x < endx) { |
|
631 |
pRow = PtrCoord(pDst, x, pRasInfo->pixelStride, 0, 0); |
|
632 |
(*pPrim->funcs.maskfill)(pRow, |
|
633 |
NULL, 0, 0, |
|
634 |
endx - x, 1, |
|
635 |
color, pRasInfo, |
|
636 |
pPrim, pCompInfo); |
|
637 |
x = endx; |
|
638 |
} |
|
639 |
} else if (lastcov > 0 && rmin >= rmax) { |
|
640 |
/* We are not at 0 coverage, but there is no right edge, */ |
|
641 |
/* force a right edge so we process pixels out to width. */ |
|
642 |
rmax = width; |
|
643 |
} |
|
644 |
/* The following loop will process the right AA edge and/or any */ |
|
645 |
/* partial coverage center section not processed above. */ |
|
646 |
while (x < rmax) { |
|
647 |
accum += pAccum[x]; |
|
648 |
pAccum[x] = 0.0f; |
|
649 |
pMask[moff++] = DblToMask(accum); |
|
650 |
x++; |
|
651 |
} |
|
652 |
if (moff > 0) { |
|
653 |
void *pRow = PtrCoord(pDst, x-moff, pRasInfo->pixelStride, 0, 0); |
|
654 |
(*pPrim->funcs.maskfill)(pRow, |
|
655 |
pMask, 0, 0, |
|
656 |
moff, 1, |
|
657 |
color, pRasInfo, |
|
658 |
pPrim, pCompInfo); |
|
659 |
} |
|
660 |
pDst = PtrAddBytes(pDst, pRasInfo->scanStride); |
|
661 |
cy1++; |
|
662 |
} |
|
663 |
if (pAccum != localaccum) { |
|
664 |
free(pAccum); |
|
665 |
} |
|
666 |
} |
|
667 |
||
668 |
/* |
|
669 |
* Class: sun_java2d_loops_MaskFill |
|
670 |
* Method: FillAAPgram |
|
671 |
* Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;Ljava/awt/Composite;DDDDDD)V |
|
672 |
*/ |
|
673 |
JNIEXPORT void JNICALL |
|
674 |
Java_sun_java2d_loops_MaskFill_FillAAPgram |
|
675 |
(JNIEnv *env, jobject self, |
|
676 |
jobject sg2d, jobject sData, jobject comp, |
|
677 |
jdouble x0, jdouble y0, |
|
678 |
jdouble dx1, jdouble dy1, |
|
679 |
jdouble dx2, jdouble dy2) |
|
680 |
{ |
|
681 |
SurfaceDataOps *sdOps; |
|
682 |
SurfaceDataRasInfo rasInfo; |
|
683 |
NativePrimitive *pPrim; |
|
684 |
CompositeInfo compInfo; |
|
685 |
jint ix1, iy1, ix2, iy2; |
|
686 |
||
687 |
if ((dy1 == 0 && dx1 == 0) || (dy2 == 0 && dx2 == 0)) { |
|
688 |
return; |
|
689 |
} |
|
690 |
||
691 |
/* |
|
692 |
* Sort parallelogram by y values, ensure that each delta vector |
|
693 |
* has a non-negative y delta. |
|
694 |
*/ |
|
695 |
SORT_PGRAM(x0, y0, dx1, dy1, dx2, dy2, ); |
|
696 |
||
697 |
PGRAM_MIN_MAX(ix1, ix2, x0, dx1, dx2, JNI_TRUE); |
|
698 |
iy1 = (jint) floor(y0); |
|
699 |
iy2 = (jint) ceil(y0 + dy1 + dy2); |
|
700 |
||
701 |
pPrim = GetNativePrim(env, self); |
|
702 |
if (pPrim == NULL) { |
|
703 |
return; |
|
704 |
} |
|
705 |
if (pPrim->pCompType->getCompInfo != NULL) { |
|
706 |
(*pPrim->pCompType->getCompInfo)(env, &compInfo, comp); |
|
707 |
} |
|
708 |
||
709 |
sdOps = SurfaceData_GetOps(env, sData); |
|
710 |
if (sdOps == 0) { |
|
711 |
return; |
|
712 |
} |
|
713 |
||
714 |
GrPrim_Sg2dGetClip(env, sg2d, &rasInfo.bounds); |
|
715 |
SurfaceData_IntersectBoundsXYXY(&rasInfo.bounds, ix1, iy1, ix2, iy2); |
|
716 |
if (rasInfo.bounds.y2 <= rasInfo.bounds.y1 || |
|
717 |
rasInfo.bounds.x2 <= rasInfo.bounds.x1) |
|
718 |
{ |
|
719 |
return; |
|
720 |
} |
|
721 |
||
722 |
if (sdOps->Lock(env, sdOps, &rasInfo, pPrim->dstflags) != SD_SUCCESS) { |
|
723 |
return; |
|
724 |
} |
|
725 |
||
726 |
ix1 = rasInfo.bounds.x1; |
|
727 |
iy1 = rasInfo.bounds.y1; |
|
728 |
ix2 = rasInfo.bounds.x2; |
|
729 |
iy2 = rasInfo.bounds.y2; |
|
730 |
if (ix2 > ix1 && iy2 > iy1) { |
|
731 |
jint width = ix2 - ix1; |
|
732 |
jint color = GrPrim_Sg2dGetEaRGB(env, sg2d); |
|
733 |
unsigned char localmask[MASK_BUF_LEN]; |
|
734 |
unsigned char *pMask = ((width > MASK_BUF_LEN) |
|
735 |
? malloc(width) |
|
736 |
: localmask); |
|
737 |
||
738 |
sdOps->GetRasInfo(env, sdOps, &rasInfo); |
|
739 |
if (rasInfo.rasBase != NULL && pMask != NULL) { |
|
740 |
void *pDst = PtrCoord(rasInfo.rasBase, |
|
741 |
ix1, rasInfo.pixelStride, |
|
742 |
iy1, rasInfo.scanStride); |
|
743 |
if (dy1 == 0 && dx2 == 0) { |
|
744 |
if (dx1 < 0) { |
|
745 |
// We sorted by Y above, but not by X |
|
746 |
x0 += dx1; |
|
747 |
dx1 = -dx1; |
|
748 |
} |
|
749 |
fillAARect(pPrim, &rasInfo, &compInfo, |
|
750 |
color, pMask, pDst, |
|
751 |
x0, y0, x0+dx1, y0+dy2); |
|
752 |
} else if (dx1 == 0 && dy2 == 0) { |
|
753 |
if (dx2 < 0) { |
|
754 |
// We sorted by Y above, but not by X |
|
755 |
x0 += dx2; |
|
756 |
dx2 = -dx2; |
|
757 |
} |
|
758 |
fillAARect(pPrim, &rasInfo, &compInfo, |
|
759 |
color, pMask, pDst, |
|
760 |
x0, y0, x0+dx2, y0+dy1); |
|
761 |
} else { |
|
762 |
fillAAPgram(pPrim, &rasInfo, &compInfo, |
|
763 |
color, pMask, pDst, |
|
764 |
x0, y0, dx1, dy1, dx2, dy2); |
|
765 |
} |
|
766 |
} |
|
767 |
SurfaceData_InvokeRelease(env, sdOps, &rasInfo); |
|
768 |
if (pMask != NULL && pMask != localmask) { |
|
769 |
free(pMask); |
|
770 |
} |
|
2 | 771 |
} |
772 |
SurfaceData_InvokeUnlock(env, sdOps, &rasInfo); |
|
773 |
} |
|
7745 | 774 |
|
775 |
/* Main function to fill a double pair of (inner and outer) parallelograms */ |
|
776 |
static void |
|
777 |
drawAAPgram(NativePrimitive *pPrim, SurfaceDataRasInfo *pRasInfo, |
|
778 |
CompositeInfo *pCompInfo, jint color, unsigned char *pMask, |
|
779 |
void *pDst, |
|
780 |
jdouble ox0, jdouble oy0, |
|
781 |
jdouble dx1, jdouble dy1, |
|
782 |
jdouble dx2, jdouble dy2, |
|
783 |
jdouble ldx1, jdouble ldy1, |
|
784 |
jdouble ldx2, jdouble ldy2) |
|
785 |
{ |
|
786 |
jint cx1 = pRasInfo->bounds.x1; |
|
787 |
jint cy1 = pRasInfo->bounds.y1; |
|
788 |
jint cx2 = pRasInfo->bounds.x2; |
|
789 |
jint cy2 = pRasInfo->bounds.y2; |
|
790 |
jint width = cx2 - cx1; |
|
791 |
EdgeInfo edges[8]; |
|
792 |
jfloat localaccum[MASK_BUF_LEN + 1]; |
|
793 |
jfloat *pAccum; |
|
794 |
||
795 |
if (!storePgram(edges + 0, edges + 6, |
|
796 |
ox0, oy0, |
|
797 |
dx1 + ldx1, dy1 + ldy1, |
|
798 |
dx2 + ldx2, dy2 + ldy2, |
|
799 |
cx1, cy1, cx2, cy2, |
|
800 |
JNI_FALSE)) |
|
801 |
{ |
|
802 |
/* If outer pgram does not contribute, then inner cannot either. */ |
|
803 |
return; |
|
804 |
} |
|
805 |
storePgram(edges + 2, edges + 4, |
|
806 |
ox0 + ldx1 + ldx2, oy0 + ldy1 + ldy2, |
|
807 |
dx1 - ldx1, dy1 - ldy1, |
|
808 |
dx2 - ldx2, dy2 - ldy2, |
|
809 |
cx1, cy1, cx2, cy2, |
|
810 |
JNI_TRUE); |
|
811 |
||
812 |
pAccum = ((width > MASK_BUF_LEN) |
|
813 |
? malloc((width + 1) * sizeof(jfloat)) |
|
814 |
: localaccum); |
|
815 |
if (pAccum == NULL) { |
|
816 |
return; |
|
817 |
} |
|
818 |
memset(pAccum, 0, (width+1) * sizeof(jfloat)); |
|
819 |
||
820 |
while (cy1 < cy2) { |
|
821 |
jint lmin, lmax, rmin, rmax; |
|
822 |
jint moff, x; |
|
823 |
jdouble accum; |
|
824 |
unsigned char lastcov; |
|
825 |
||
826 |
lmin = rmin = width + 2; |
|
827 |
lmax = rmax = 0; |
|
828 |
ACCUM_EDGE(&edges[0], pAccum, lmin, lmax, |
|
829 |
cx1, cy1, cx2, cy1+1); |
|
830 |
ACCUM_EDGE(&edges[1], pAccum, lmin, lmax, |
|
831 |
cx1, cy1, cx2, cy1+1); |
|
832 |
ACCUM_EDGE(&edges[2], pAccum, lmin, lmax, |
|
833 |
cx1, cy1, cx2, cy1+1); |
|
834 |
ACCUM_EDGE(&edges[3], pAccum, lmin, lmax, |
|
835 |
cx1, cy1, cx2, cy1+1); |
|
836 |
ACCUM_EDGE(&edges[4], pAccum, rmin, rmax, |
|
837 |
cx1, cy1, cx2, cy1+1); |
|
838 |
ACCUM_EDGE(&edges[5], pAccum, rmin, rmax, |
|
839 |
cx1, cy1, cx2, cy1+1); |
|
840 |
ACCUM_EDGE(&edges[6], pAccum, rmin, rmax, |
|
841 |
cx1, cy1, cx2, cy1+1); |
|
842 |
ACCUM_EDGE(&edges[7], pAccum, rmin, rmax, |
|
843 |
cx1, cy1, cx2, cy1+1); |
|
844 |
if (lmax > width) { |
|
845 |
lmax = width; /* Extra col has data we do not need. */ |
|
846 |
} |
|
847 |
if (rmax > width) { |
|
848 |
rmax = width; /* Extra col has data we do not need. */ |
|
849 |
} |
|
850 |
/* If ranges overlap, handle both in the first pass. */ |
|
851 |
if (rmin <= lmax) { |
|
852 |
lmax = rmax; |
|
853 |
} |
|
854 |
||
855 |
x = lmin; |
|
856 |
accum = 0.0; |
|
857 |
moff = 0; |
|
858 |
lastcov = 0; |
|
859 |
while (x < lmax) { |
|
860 |
accum += pAccum[x]; |
|
861 |
pAccum[x] = 0.0f; |
|
862 |
pMask[moff++] = lastcov = DblToMask(accum); |
|
863 |
x++; |
|
864 |
} |
|
865 |
/* Check for an empty or solidcenter section. */ |
|
866 |
if (lastcov == 0 || lastcov == 0xFF) { |
|
867 |
jint endx; |
|
868 |
void *pRow; |
|
869 |
||
870 |
/* First process the existing partial coverage data. */ |
|
871 |
if (moff > 0) { |
|
872 |
pRow = PtrCoord(pDst, x-moff, pRasInfo->pixelStride, 0, 0); |
|
873 |
(*pPrim->funcs.maskfill)(pRow, |
|
874 |
pMask, 0, 0, |
|
875 |
moff, 1, |
|
876 |
color, pRasInfo, |
|
877 |
pPrim, pCompInfo); |
|
878 |
moff = 0; |
|
879 |
} |
|
880 |
||
881 |
/* Where does the center section end? */ |
|
882 |
/* If there is no right AA edge in the accum buffer, then */ |
|
883 |
/* the right edge was beyond the clip, so fill out to width */ |
|
884 |
endx = (rmin < rmax) ? rmin : width; |
|
885 |
if (x < endx) { |
|
886 |
if (lastcov == 0xFF) { |
|
887 |
pRow = PtrCoord(pDst, x, pRasInfo->pixelStride, 0, 0); |
|
888 |
(*pPrim->funcs.maskfill)(pRow, |
|
889 |
NULL, 0, 0, |
|
890 |
endx - x, 1, |
|
891 |
color, pRasInfo, |
|
892 |
pPrim, pCompInfo); |
|
893 |
} |
|
894 |
x = endx; |
|
895 |
} |
|
896 |
} else if (rmin >= rmax) { |
|
897 |
/* We are not at 0 coverage, but there is no right edge, */ |
|
898 |
/* force a right edge so we process pixels out to width. */ |
|
899 |
rmax = width; |
|
900 |
} |
|
901 |
/* The following loop will process the right AA edge and/or any */ |
|
902 |
/* partial coverage center section not processed above. */ |
|
903 |
while (x < rmax) { |
|
904 |
accum += pAccum[x]; |
|
905 |
pAccum[x] = 0.0f; |
|
906 |
pMask[moff++] = lastcov = DblToMask(accum); |
|
907 |
x++; |
|
908 |
} |
|
909 |
if (moff > 0) { |
|
910 |
void *pRow = PtrCoord(pDst, x-moff, pRasInfo->pixelStride, 0, 0); |
|
911 |
(*pPrim->funcs.maskfill)(pRow, |
|
912 |
pMask, 0, 0, |
|
913 |
moff, 1, |
|
914 |
color, pRasInfo, |
|
915 |
pPrim, pCompInfo); |
|
916 |
} |
|
917 |
if (lastcov == 0xFF && x < width) { |
|
918 |
void *pRow = PtrCoord(pDst, x, pRasInfo->pixelStride, 0, 0); |
|
919 |
(*pPrim->funcs.maskfill)(pRow, |
|
920 |
NULL, 0, 0, |
|
921 |
width - x, 1, |
|
922 |
color, pRasInfo, |
|
923 |
pPrim, pCompInfo); |
|
924 |
} |
|
925 |
pDst = PtrAddBytes(pDst, pRasInfo->scanStride); |
|
926 |
cy1++; |
|
927 |
} |
|
928 |
if (pAccum != localaccum) { |
|
929 |
free(pAccum); |
|
930 |
} |
|
931 |
} |
|
932 |
||
933 |
/* |
|
934 |
* Class: sun_java2d_loops_MaskFill |
|
935 |
* Method: DrawAAPgram |
|
936 |
* Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;Ljava/awt/Composite;DDDDDDDD)V |
|
937 |
*/ |
|
938 |
JNIEXPORT void JNICALL |
|
939 |
Java_sun_java2d_loops_MaskFill_DrawAAPgram |
|
940 |
(JNIEnv *env, jobject self, |
|
941 |
jobject sg2d, jobject sData, jobject comp, |
|
942 |
jdouble x0, jdouble y0, |
|
943 |
jdouble dx1, jdouble dy1, |
|
944 |
jdouble dx2, jdouble dy2, |
|
945 |
jdouble lw1, jdouble lw2) |
|
946 |
{ |
|
947 |
SurfaceDataOps *sdOps; |
|
948 |
SurfaceDataRasInfo rasInfo; |
|
949 |
NativePrimitive *pPrim; |
|
950 |
CompositeInfo compInfo; |
|
951 |
jint ix1, iy1, ix2, iy2; |
|
952 |
jdouble ldx1, ldy1, ldx2, ldy2; |
|
953 |
jdouble ox0, oy0; |
|
954 |
||
955 |
if ((dy1 == 0 && dx1 == 0) || (dy2 == 0 && dx2 == 0)) { |
|
956 |
return; |
|
957 |
} |
|
958 |
||
959 |
/* |
|
960 |
* Sort parallelogram by y values, ensure that each delta vector |
|
961 |
* has a non-negative y delta. |
|
962 |
*/ |
|
963 |
SORT_PGRAM(x0, y0, dx1, dy1, dx2, dy2, |
|
964 |
v = lw1; lw1 = lw2; lw2 = v;); |
|
965 |
||
966 |
// dx,dy for line width in the "1" and "2" directions. |
|
967 |
ldx1 = dx1 * lw1; |
|
968 |
ldy1 = dy1 * lw1; |
|
969 |
ldx2 = dx2 * lw2; |
|
970 |
ldy2 = dy2 * lw2; |
|
971 |
||
972 |
// calculate origin of the outer parallelogram |
|
973 |
ox0 = x0 - (ldx1 + ldx2) / 2.0; |
|
974 |
oy0 = y0 - (ldy1 + ldy2) / 2.0; |
|
975 |
||
976 |
if (lw1 >= 1.0 || lw2 >= 1.0) { |
|
977 |
/* Only need to fill an outer pgram if the interior no longer |
|
978 |
* has a hole in it (i.e. if either of the line width ratios |
|
979 |
* were greater than or equal to 1.0). |
|
980 |
*/ |
|
981 |
Java_sun_java2d_loops_MaskFill_FillAAPgram(env, self, |
|
982 |
sg2d, sData, comp, |
|
983 |
ox0, oy0, |
|
984 |
dx1 + ldx1, dy1 + ldy1, |
|
985 |
dx2 + ldx2, dy2 + ldy2); |
|
986 |
return; |
|
987 |
} |
|
988 |
||
989 |
PGRAM_MIN_MAX(ix1, ix2, ox0, dx1+ldx1, dx2+ldx2, JNI_TRUE); |
|
990 |
iy1 = (jint) floor(oy0); |
|
991 |
iy2 = (jint) ceil(oy0 + dy1 + ldy1 + dy2 + ldy2); |
|
992 |
||
993 |
pPrim = GetNativePrim(env, self); |
|
994 |
if (pPrim == NULL) { |
|
995 |
return; |
|
996 |
} |
|
997 |
if (pPrim->pCompType->getCompInfo != NULL) { |
|
998 |
(*pPrim->pCompType->getCompInfo)(env, &compInfo, comp); |
|
999 |
} |
|
1000 |
||
1001 |
sdOps = SurfaceData_GetOps(env, sData); |
|
1002 |
if (sdOps == 0) { |
|
1003 |
return; |
|
1004 |
} |
|
1005 |
||
1006 |
GrPrim_Sg2dGetClip(env, sg2d, &rasInfo.bounds); |
|
1007 |
SurfaceData_IntersectBoundsXYXY(&rasInfo.bounds, ix1, iy1, ix2, iy2); |
|
1008 |
if (rasInfo.bounds.y2 <= rasInfo.bounds.y1 || |
|
1009 |
rasInfo.bounds.x2 <= rasInfo.bounds.x1) |
|
1010 |
{ |
|
1011 |
return; |
|
1012 |
} |
|
1013 |
||
1014 |
if (sdOps->Lock(env, sdOps, &rasInfo, pPrim->dstflags) != SD_SUCCESS) { |
|
1015 |
return; |
|
1016 |
} |
|
1017 |
||
1018 |
ix1 = rasInfo.bounds.x1; |
|
1019 |
iy1 = rasInfo.bounds.y1; |
|
1020 |
ix2 = rasInfo.bounds.x2; |
|
1021 |
iy2 = rasInfo.bounds.y2; |
|
1022 |
if (ix2 > ix1 && iy2 > iy1) { |
|
1023 |
jint width = ix2 - ix1; |
|
1024 |
jint color = GrPrim_Sg2dGetEaRGB(env, sg2d); |
|
1025 |
unsigned char localmask[MASK_BUF_LEN]; |
|
1026 |
unsigned char *pMask = ((width > MASK_BUF_LEN) |
|
1027 |
? malloc(width) |
|
1028 |
: localmask); |
|
1029 |
||
1030 |
sdOps->GetRasInfo(env, sdOps, &rasInfo); |
|
1031 |
if (rasInfo.rasBase != NULL && pMask != NULL) { |
|
1032 |
void *pDst = PtrCoord(rasInfo.rasBase, |
|
1033 |
ix1, rasInfo.pixelStride, |
|
1034 |
iy1, rasInfo.scanStride); |
|
1035 |
/* |
|
1036 |
* NOTE: aligned rects could probably be drawn |
|
1037 |
* even faster with a little work here. |
|
1038 |
* if (dy1 == 0 && dx2 == 0) { |
|
1039 |
* drawAARect(pPrim, &rasInfo, &compInfo, |
|
1040 |
* color, pMask, pDst, |
|
1041 |
* ox0, oy0, ox0+dx1+ldx1, oy0+dy2+ldy2, ldx1, ldy2); |
|
1042 |
* } else if (dx1 == 0 && dy2 == 0) { |
|
1043 |
* drawAARect(pPrim, &rasInfo, &compInfo, |
|
1044 |
* color, pMask, pDst, |
|
1045 |
* ox0, oy0, ox0+dx2+ldx2, oy0+dy1+ldy1, ldx2, ldy1); |
|
1046 |
* } else { |
|
1047 |
*/ |
|
1048 |
drawAAPgram(pPrim, &rasInfo, &compInfo, |
|
1049 |
color, pMask, pDst, |
|
1050 |
ox0, oy0, |
|
1051 |
dx1, dy1, dx2, dy2, |
|
1052 |
ldx1, ldy1, ldx2, ldy2); |
|
1053 |
/* |
|
1054 |
* } |
|
1055 |
*/ |
|
1056 |
} |
|
1057 |
SurfaceData_InvokeRelease(env, sdOps, &rasInfo); |
|
1058 |
if (pMask != NULL && pMask != localmask) { |
|
1059 |
free(pMask); |
|
1060 |
} |
|
1061 |
} |
|
1062 |
SurfaceData_InvokeUnlock(env, sdOps, &rasInfo); |
|
1063 |
} |