author | ohair |
Wed, 06 Apr 2011 22:06:11 -0700 | |
changeset 9035 | 1255eb81cc2f |
parent 8131 | e2932d8114cb |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
8131
diff
changeset
|
2 |
* Copyright (c) 2007, 2011, 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 |
||
26 |
package sun.java2d.pisces; |
|
27 |
||
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
28 |
import sun.awt.geom.PathConsumer2D; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
29 |
|
2 | 30 |
/** |
31 |
* The <code>Dasher</code> class takes a series of linear commands |
|
32 |
* (<code>moveTo</code>, <code>lineTo</code>, <code>close</code> and |
|
33 |
* <code>end</code>) and breaks them into smaller segments according to a |
|
34 |
* dash pattern array and a starting dash phase. |
|
35 |
* |
|
36 |
* <p> Issues: in J2Se, a zero length dash segment as drawn as a very |
|
37 |
* short dash, whereas Pisces does not draw anything. The PostScript |
|
38 |
* semantics are unclear. |
|
39 |
* |
|
40 |
*/ |
|
8131
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
41 |
final class Dasher implements sun.awt.geom.PathConsumer2D { |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
42 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
43 |
private final PathConsumer2D out; |
6284 | 44 |
private final float[] dash; |
45 |
private final float startPhase; |
|
46 |
private final boolean startDashOn; |
|
47 |
private final int startIdx; |
|
2 | 48 |
|
6284 | 49 |
private boolean starting; |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
50 |
private boolean needsMoveTo; |
2 | 51 |
|
6284 | 52 |
private int idx; |
53 |
private boolean dashOn; |
|
54 |
private float phase; |
|
2 | 55 |
|
6284 | 56 |
private float sx, sy; |
57 |
private float x0, y0; |
|
58 |
||
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
59 |
// temporary storage for the current curve |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
60 |
private float[] curCurvepts; |
2 | 61 |
|
62 |
/** |
|
63 |
* Constructs a <code>Dasher</code>. |
|
64 |
* |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
65 |
* @param out an output <code>PathConsumer2D</code>. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
66 |
* @param dash an array of <code>float</code>s containing the dash pattern |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
67 |
* @param phase a <code>float</code> containing the dash phase |
2 | 68 |
*/ |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
69 |
public Dasher(PathConsumer2D out, float[] dash, float phase) { |
2 | 70 |
if (phase < 0) { |
71 |
throw new IllegalArgumentException("phase < 0 !"); |
|
72 |
} |
|
73 |
||
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
74 |
this.out = out; |
6284 | 75 |
|
2 | 76 |
// Normalize so 0 <= phase < dash[0] |
77 |
int idx = 0; |
|
2380
822dcdd94e7a
6793344: BasicStroke's first element dash pattern is not a dash
jgodinez
parents:
2
diff
changeset
|
78 |
dashOn = true; |
6284 | 79 |
float d; |
2 | 80 |
while (phase >= (d = dash[idx])) { |
81 |
phase -= d; |
|
82 |
idx = (idx + 1) % dash.length; |
|
83 |
dashOn = !dashOn; |
|
84 |
} |
|
85 |
||
6284 | 86 |
this.dash = dash; |
2 | 87 |
this.startPhase = this.phase = phase; |
88 |
this.startDashOn = dashOn; |
|
89 |
this.startIdx = idx; |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
90 |
this.starting = true; |
2 | 91 |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
92 |
// we need curCurvepts to be able to contain 2 curves because when |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
93 |
// dashing curves, we need to subdivide it |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
94 |
curCurvepts = new float[8 * 2]; |
2 | 95 |
} |
96 |
||
6284 | 97 |
public void moveTo(float x0, float y0) { |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
98 |
if (firstSegidx > 0) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
99 |
out.moveTo(sx, sy); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
100 |
emitFirstSegments(); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
101 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
102 |
needsMoveTo = true; |
2 | 103 |
this.idx = startIdx; |
104 |
this.dashOn = this.startDashOn; |
|
105 |
this.phase = this.startPhase; |
|
106 |
this.sx = this.x0 = x0; |
|
107 |
this.sy = this.y0 = y0; |
|
108 |
this.starting = true; |
|
109 |
} |
|
110 |
||
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
111 |
private void emitSeg(float[] buf, int off, int type) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
112 |
switch (type) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
113 |
case 8: |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
114 |
out.curveTo(buf[off+0], buf[off+1], |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
115 |
buf[off+2], buf[off+3], |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
116 |
buf[off+4], buf[off+5]); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
117 |
break; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
118 |
case 6: |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
119 |
out.quadTo(buf[off+0], buf[off+1], |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
120 |
buf[off+2], buf[off+3]); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
121 |
break; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
122 |
case 4: |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
123 |
out.lineTo(buf[off], buf[off+1]); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
124 |
} |
2 | 125 |
} |
126 |
||
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
127 |
private void emitFirstSegments() { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
128 |
for (int i = 0; i < firstSegidx; ) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
129 |
emitSeg(firstSegmentsBuffer, i+1, (int)firstSegmentsBuffer[i]); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
130 |
i += (((int)firstSegmentsBuffer[i]) - 1); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
131 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
132 |
firstSegidx = 0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
133 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
134 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
135 |
// We don't emit the first dash right away. If we did, caps would be |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
136 |
// drawn on it, but we need joins to be drawn if there's a closePath() |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
137 |
// So, we store the path elements that make up the first dash in the |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
138 |
// buffer below. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
139 |
private float[] firstSegmentsBuffer = new float[7]; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
140 |
private int firstSegidx = 0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
141 |
// precondition: pts must be in relative coordinates (relative to x0,y0) |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
142 |
// fullCurve is true iff the curve in pts has not been split. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
143 |
private void goTo(float[] pts, int off, final int type) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
144 |
float x = pts[off + type - 4]; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
145 |
float y = pts[off + type - 3]; |
2 | 146 |
if (dashOn) { |
147 |
if (starting) { |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
148 |
firstSegmentsBuffer = Helpers.widenArray(firstSegmentsBuffer, |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
149 |
firstSegidx, type - 2); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
150 |
firstSegmentsBuffer[firstSegidx++] = type; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
151 |
System.arraycopy(pts, off, firstSegmentsBuffer, firstSegidx, type - 2); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
152 |
firstSegidx += type - 2; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
153 |
} else { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
154 |
if (needsMoveTo) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
155 |
out.moveTo(x0, y0); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
156 |
needsMoveTo = false; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
157 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
158 |
emitSeg(pts, off, type); |
2 | 159 |
} |
160 |
} else { |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
161 |
starting = false; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
162 |
needsMoveTo = true; |
2 | 163 |
} |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
164 |
this.x0 = x; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
165 |
this.y0 = y; |
2 | 166 |
} |
167 |
||
6284 | 168 |
public void lineTo(float x1, float y1) { |
169 |
float dx = x1 - x0; |
|
170 |
float dy = y1 - y0; |
|
2 | 171 |
|
8131
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
172 |
float len = (float) Math.sqrt(dx*dx + dy*dy); |
2 | 173 |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
174 |
if (len == 0) { |
6284 | 175 |
return; |
176 |
} |
|
177 |
||
178 |
// The scaling factors needed to get the dx and dy of the |
|
179 |
// transformed dash segments. |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
180 |
float cx = dx / len; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
181 |
float cy = dy / len; |
6284 | 182 |
|
183 |
while (true) { |
|
184 |
float leftInThisDashSegment = dash[idx] - phase; |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
185 |
if (len <= leftInThisDashSegment) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
186 |
curCurvepts[0] = x1; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
187 |
curCurvepts[1] = y1; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
188 |
goTo(curCurvepts, 0, 4); |
2 | 189 |
// Advance phase within current dash segment |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
190 |
phase += len; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
191 |
if (len == leftInThisDashSegment) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
192 |
phase = 0f; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
193 |
idx = (idx + 1) % dash.length; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
194 |
dashOn = !dashOn; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
195 |
} |
2 | 196 |
return; |
197 |
} |
|
198 |
||
6284 | 199 |
float dashdx = dash[idx] * cx; |
200 |
float dashdy = dash[idx] * cy; |
|
201 |
if (phase == 0) { |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
202 |
curCurvepts[0] = x0 + dashdx; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
203 |
curCurvepts[1] = y0 + dashdy; |
6284 | 204 |
} else { |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
205 |
float p = leftInThisDashSegment / dash[idx]; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
206 |
curCurvepts[0] = x0 + p * dashdx; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
207 |
curCurvepts[1] = y0 + p * dashdy; |
6284 | 208 |
} |
2 | 209 |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
210 |
goTo(curCurvepts, 0, 4); |
6284 | 211 |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
212 |
len -= leftInThisDashSegment; |
2 | 213 |
// Advance to next dash segment |
214 |
idx = (idx + 1) % dash.length; |
|
215 |
dashOn = !dashOn; |
|
216 |
phase = 0; |
|
217 |
} |
|
218 |
} |
|
219 |
||
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
220 |
private LengthIterator li = null; |
6284 | 221 |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
222 |
// preconditions: curCurvepts must be an array of length at least 2 * type, |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
223 |
// that contains the curve we want to dash in the first type elements |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
224 |
private void somethingTo(int type) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
225 |
if (pointCurve(curCurvepts, type)) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
226 |
return; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
227 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
228 |
if (li == null) { |
8131
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
229 |
li = new LengthIterator(4, 0.01f); |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
230 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
231 |
li.initializeIterationOnCurve(curCurvepts, type); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
232 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
233 |
int curCurveoff = 0; // initially the current curve is at curCurvepts[0...type] |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
234 |
float lastSplitT = 0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
235 |
float t = 0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
236 |
float leftInThisDashSegment = dash[idx] - phase; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
237 |
while ((t = li.next(leftInThisDashSegment)) < 1) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
238 |
if (t != 0) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
239 |
Helpers.subdivideAt((t - lastSplitT) / (1 - lastSplitT), |
8131
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
240 |
curCurvepts, curCurveoff, |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
241 |
curCurvepts, 0, |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
242 |
curCurvepts, type, type); |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
243 |
lastSplitT = t; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
244 |
goTo(curCurvepts, 2, type); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
245 |
curCurveoff = type; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
246 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
247 |
// Advance to next dash segment |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
248 |
idx = (idx + 1) % dash.length; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
249 |
dashOn = !dashOn; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
250 |
phase = 0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
251 |
leftInThisDashSegment = dash[idx]; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
252 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
253 |
goTo(curCurvepts, curCurveoff+2, type); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
254 |
phase += li.lastSegLen(); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
255 |
if (phase >= dash[idx]) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
256 |
phase = 0f; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
257 |
idx = (idx + 1) % dash.length; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
258 |
dashOn = !dashOn; |
2 | 259 |
} |
260 |
} |
|
261 |
||
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
262 |
private static boolean pointCurve(float[] curve, int type) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
263 |
for (int i = 2; i < type; i++) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
264 |
if (curve[i] != curve[i-2]) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
265 |
return false; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
266 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
267 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
268 |
return true; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
269 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
270 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
271 |
// Objects of this class are used to iterate through curves. They return |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
272 |
// t values where the left side of the curve has a specified length. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
273 |
// It does this by subdividing the input curve until a certain error |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
274 |
// condition has been met. A recursive subdivision procedure would |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
275 |
// return as many as 1<<limit curves, but this is an iterator and we |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
276 |
// don't need all the curves all at once, so what we carry out a |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
277 |
// lazy inorder traversal of the recursion tree (meaning we only move |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
278 |
// through the tree when we need the next subdivided curve). This saves |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
279 |
// us a lot of memory because at any one time we only need to store |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
280 |
// limit+1 curves - one for each level of the tree + 1. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
281 |
// NOTE: the way we do things here is not enough to traverse a general |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
282 |
// tree; however, the trees we are interested in have the property that |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
283 |
// every non leaf node has exactly 2 children |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
284 |
private static class LengthIterator { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
285 |
private enum Side {LEFT, RIGHT}; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
286 |
// Holds the curves at various levels of the recursion. The root |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
287 |
// (i.e. the original curve) is at recCurveStack[0] (but then it |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
288 |
// gets subdivided, the left half is put at 1, so most of the time |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
289 |
// only the right half of the original curve is at 0) |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
290 |
private float[][] recCurveStack; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
291 |
// sides[i] indicates whether the node at level i+1 in the path from |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
292 |
// the root to the current leaf is a left or right child of its parent. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
293 |
private Side[] sides; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
294 |
private int curveType; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
295 |
private final int limit; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
296 |
private final float ERR; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
297 |
private final float minTincrement; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
298 |
// lastT and nextT delimit the current leaf. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
299 |
private float nextT; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
300 |
private float lenAtNextT; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
301 |
private float lastT; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
302 |
private float lenAtLastT; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
303 |
private float lenAtLastSplit; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
304 |
private float lastSegLen; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
305 |
// the current level in the recursion tree. 0 is the root. limit |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
306 |
// is the deepest possible leaf. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
307 |
private int recLevel; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
308 |
private boolean done; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
309 |
|
8131
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
310 |
// the lengths of the lines of the control polygon. Only its first |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
311 |
// curveType/2 - 1 elements are valid. This is an optimization. See |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
312 |
// next(float) for more detail. |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
313 |
private float[] curLeafCtrlPolyLengths = new float[3]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
314 |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
315 |
public LengthIterator(int reclimit, float err) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
316 |
this.limit = reclimit; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
317 |
this.minTincrement = 1f / (1 << limit); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
318 |
this.ERR = err; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
319 |
this.recCurveStack = new float[reclimit+1][8]; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
320 |
this.sides = new Side[reclimit]; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
321 |
// if any methods are called without first initializing this object on |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
322 |
// a curve, we want it to fail ASAP. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
323 |
this.nextT = Float.MAX_VALUE; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
324 |
this.lenAtNextT = Float.MAX_VALUE; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
325 |
this.lenAtLastSplit = Float.MIN_VALUE; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
326 |
this.recLevel = Integer.MIN_VALUE; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
327 |
this.lastSegLen = Float.MAX_VALUE; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
328 |
this.done = true; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
329 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
330 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
331 |
public void initializeIterationOnCurve(float[] pts, int type) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
332 |
System.arraycopy(pts, 0, recCurveStack[0], 0, type); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
333 |
this.curveType = type; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
334 |
this.recLevel = 0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
335 |
this.lastT = 0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
336 |
this.lenAtLastT = 0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
337 |
this.nextT = 0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
338 |
this.lenAtNextT = 0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
339 |
goLeft(); // initializes nextT and lenAtNextT properly |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
340 |
this.lenAtLastSplit = 0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
341 |
if (recLevel > 0) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
342 |
this.sides[0] = Side.LEFT; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
343 |
this.done = false; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
344 |
} else { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
345 |
// the root of the tree is a leaf so we're done. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
346 |
this.sides[0] = Side.RIGHT; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
347 |
this.done = true; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
348 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
349 |
this.lastSegLen = 0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
350 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
351 |
|
8131
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
352 |
// 0 == false, 1 == true, -1 == invalid cached value. |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
353 |
private int cachedHaveLowAcceleration = -1; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
354 |
|
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
355 |
private boolean haveLowAcceleration(float err) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
356 |
if (cachedHaveLowAcceleration == -1) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
357 |
final float len1 = curLeafCtrlPolyLengths[0]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
358 |
final float len2 = curLeafCtrlPolyLengths[1]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
359 |
// the test below is equivalent to !within(len1/len2, 1, err). |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
360 |
// It is using a multiplication instead of a division, so it |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
361 |
// should be a bit faster. |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
362 |
if (!Helpers.within(len1, len2, err*len2)) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
363 |
cachedHaveLowAcceleration = 0; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
364 |
return false; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
365 |
} |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
366 |
if (curveType == 8) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
367 |
final float len3 = curLeafCtrlPolyLengths[2]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
368 |
// if len1 is close to 2 and 2 is close to 3, that probably |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
369 |
// means 1 is close to 3 so the second part of this test might |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
370 |
// not be needed, but it doesn't hurt to include it. |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
371 |
if (!(Helpers.within(len2, len3, err*len3) && |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
372 |
Helpers.within(len1, len3, err*len3))) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
373 |
cachedHaveLowAcceleration = 0; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
374 |
return false; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
375 |
} |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
376 |
} |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
377 |
cachedHaveLowAcceleration = 1; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
378 |
return true; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
379 |
} |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
380 |
|
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
381 |
return (cachedHaveLowAcceleration == 1); |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
382 |
} |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
383 |
|
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
384 |
// we want to avoid allocations/gc so we keep this array so we |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
385 |
// can put roots in it, |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
386 |
private float[] nextRoots = new float[4]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
387 |
|
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
388 |
// caches the coefficients of the current leaf in its flattened |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
389 |
// form (see inside next() for what that means). The cache is |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
390 |
// invalid when it's third element is negative, since in any |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
391 |
// valid flattened curve, this would be >= 0. |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
392 |
private float[] flatLeafCoefCache = new float[] {0, 0, -1, 0}; |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
393 |
// returns the t value where the remaining curve should be split in |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
394 |
// order for the left subdivided curve to have length len. If len |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
395 |
// is >= than the length of the uniterated curve, it returns 1. |
8131
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
396 |
public float next(final float len) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
397 |
final float targetLength = lenAtLastSplit + len; |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
398 |
while(lenAtNextT < targetLength) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
399 |
if (done) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
400 |
lastSegLen = lenAtNextT - lenAtLastSplit; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
401 |
return 1; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
402 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
403 |
goToNextLeaf(); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
404 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
405 |
lenAtLastSplit = targetLength; |
8131
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
406 |
final float leaflen = lenAtNextT - lenAtLastT; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
407 |
float t = (targetLength - lenAtLastT) / leaflen; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
408 |
|
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
409 |
// cubicRootsInAB is a fairly expensive call, so we just don't do it |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
410 |
// if the acceleration in this section of the curve is small enough. |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
411 |
if (!haveLowAcceleration(0.05f)) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
412 |
// We flatten the current leaf along the x axis, so that we're |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
413 |
// left with a, b, c which define a 1D Bezier curve. We then |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
414 |
// solve this to get the parameter of the original leaf that |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
415 |
// gives us the desired length. |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
416 |
|
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
417 |
if (flatLeafCoefCache[2] < 0) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
418 |
float x = 0+curLeafCtrlPolyLengths[0], |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
419 |
y = x+curLeafCtrlPolyLengths[1]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
420 |
if (curveType == 8) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
421 |
float z = y + curLeafCtrlPolyLengths[2]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
422 |
flatLeafCoefCache[0] = 3*(x - y) + z; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
423 |
flatLeafCoefCache[1] = 3*(y - 2*x); |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
424 |
flatLeafCoefCache[2] = 3*x; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
425 |
flatLeafCoefCache[3] = -z; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
426 |
} else if (curveType == 6) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
427 |
flatLeafCoefCache[0] = 0f; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
428 |
flatLeafCoefCache[1] = y - 2*x; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
429 |
flatLeafCoefCache[2] = 2*x; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
430 |
flatLeafCoefCache[3] = -y; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
431 |
} |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
432 |
} |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
433 |
float a = flatLeafCoefCache[0]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
434 |
float b = flatLeafCoefCache[1]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
435 |
float c = flatLeafCoefCache[2]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
436 |
float d = t*flatLeafCoefCache[3]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
437 |
|
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
438 |
// we use cubicRootsInAB here, because we want only roots in 0, 1, |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
439 |
// and our quadratic root finder doesn't filter, so it's just a |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
440 |
// matter of convenience. |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
441 |
int n = Helpers.cubicRootsInAB(a, b, c, d, nextRoots, 0, 0, 1); |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
442 |
if (n == 1 && !Float.isNaN(nextRoots[0])) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
443 |
t = nextRoots[0]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
444 |
} |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
445 |
} |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
446 |
// t is relative to the current leaf, so we must make it a valid parameter |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
447 |
// of the original curve. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
448 |
t = t * (nextT - lastT) + lastT; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
449 |
if (t >= 1) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
450 |
t = 1; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
451 |
done = true; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
452 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
453 |
// even if done = true, if we're here, that means targetLength |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
454 |
// is equal to, or very, very close to the total length of the |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
455 |
// curve, so lastSegLen won't be too high. In cases where len |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
456 |
// overshoots the curve, this method will exit in the while |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
457 |
// loop, and lastSegLen will still be set to the right value. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
458 |
lastSegLen = len; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
459 |
return t; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
460 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
461 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
462 |
public float lastSegLen() { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
463 |
return lastSegLen; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
464 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
465 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
466 |
// go to the next leaf (in an inorder traversal) in the recursion tree |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
467 |
// preconditions: must be on a leaf, and that leaf must not be the root. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
468 |
private void goToNextLeaf() { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
469 |
// We must go to the first ancestor node that has an unvisited |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
470 |
// right child. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
471 |
recLevel--; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
472 |
while(sides[recLevel] == Side.RIGHT) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
473 |
if (recLevel == 0) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
474 |
done = true; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
475 |
return; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
476 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
477 |
recLevel--; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
478 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
479 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
480 |
sides[recLevel] = Side.RIGHT; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
481 |
System.arraycopy(recCurveStack[recLevel], 0, recCurveStack[recLevel+1], 0, curveType); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
482 |
recLevel++; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
483 |
goLeft(); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
484 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
485 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
486 |
// go to the leftmost node from the current node. Return its length. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
487 |
private void goLeft() { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
488 |
float len = onLeaf(); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
489 |
if (len >= 0) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
490 |
lastT = nextT; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
491 |
lenAtLastT = lenAtNextT; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
492 |
nextT += (1 << (limit - recLevel)) * minTincrement; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
493 |
lenAtNextT += len; |
8131
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
494 |
// invalidate caches |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
495 |
flatLeafCoefCache[2] = -1; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
496 |
cachedHaveLowAcceleration = -1; |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
497 |
} else { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
498 |
Helpers.subdivide(recCurveStack[recLevel], 0, |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
499 |
recCurveStack[recLevel+1], 0, |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
500 |
recCurveStack[recLevel], 0, curveType); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
501 |
sides[recLevel] = Side.LEFT; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
502 |
recLevel++; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
503 |
goLeft(); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
504 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
505 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
506 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
507 |
// this is a bit of a hack. It returns -1 if we're not on a leaf, and |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
508 |
// the length of the leaf if we are on a leaf. |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
509 |
private float onLeaf() { |
8131
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
510 |
float[] curve = recCurveStack[recLevel]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
511 |
float polyLen = 0; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
512 |
|
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
513 |
float x0 = curve[0], y0 = curve[1]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
514 |
for (int i = 2; i < curveType; i += 2) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
515 |
final float x1 = curve[i], y1 = curve[i+1]; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
516 |
final float len = Helpers.linelen(x0, y0, x1, y1); |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
517 |
polyLen += len; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
518 |
curLeafCtrlPolyLengths[i/2 - 1] = len; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
519 |
x0 = x1; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
520 |
y0 = y1; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
521 |
} |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
522 |
|
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
523 |
final float lineLen = Helpers.linelen(curve[0], curve[1], curve[curveType-2], curve[curveType-1]); |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
524 |
if (polyLen - lineLen < ERR || recLevel == limit) { |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
525 |
return (polyLen + lineLen)/2; |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
526 |
} |
e2932d8114cb
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents:
7668
diff
changeset
|
527 |
return -1; |
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
528 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
529 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
530 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
531 |
@Override |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
532 |
public void curveTo(float x1, float y1, |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
533 |
float x2, float y2, |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
534 |
float x3, float y3) |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
535 |
{ |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
536 |
curCurvepts[0] = x0; curCurvepts[1] = y0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
537 |
curCurvepts[2] = x1; curCurvepts[3] = y1; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
538 |
curCurvepts[4] = x2; curCurvepts[5] = y2; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
539 |
curCurvepts[6] = x3; curCurvepts[7] = y3; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
540 |
somethingTo(8); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
541 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
542 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
543 |
@Override |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
544 |
public void quadTo(float x1, float y1, float x2, float y2) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
545 |
curCurvepts[0] = x0; curCurvepts[1] = y0; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
546 |
curCurvepts[2] = x1; curCurvepts[3] = y1; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
547 |
curCurvepts[4] = x2; curCurvepts[5] = y2; |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
548 |
somethingTo(6); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
549 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
550 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
551 |
public void closePath() { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
552 |
lineTo(sx, sy); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
553 |
if (firstSegidx > 0) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
554 |
if (!dashOn || needsMoveTo) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
555 |
out.moveTo(sx, sy); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
556 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
557 |
emitFirstSegments(); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
558 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
559 |
moveTo(sx, sy); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
560 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
561 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
562 |
public void pathDone() { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
563 |
if (firstSegidx > 0) { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
564 |
out.moveTo(sx, sy); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
565 |
emitFirstSegments(); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
566 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
567 |
out.pathDone(); |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
568 |
} |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
569 |
|
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
570 |
@Override |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
571 |
public long getNativeConsumer() { |
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
572 |
throw new InternalError("Dasher does not use a native consumer"); |
2 | 573 |
} |
574 |
} |
|
6997
3642614e2282
6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents:
6284
diff
changeset
|
575 |