author | lbourges |
Wed, 07 Aug 2019 10:25:50 +0200 | |
changeset 57929 | 13178f7e75d5 |
parent 51933 | 4ec74929fbfe |
permissions | -rw-r--r-- |
47126 | 1 |
/* |
49496 | 2 |
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved. |
47126 | 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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
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 |
* |
|
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. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.java2d.marlin; |
|
27 |
||
28 |
import java.awt.geom.AffineTransform; |
|
29 |
import java.awt.geom.Path2D; |
|
49496 | 30 |
import java.util.Arrays; |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
31 |
import sun.java2d.marlin.DHelpers.IndexStack; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
32 |
import sun.java2d.marlin.DHelpers.PolyStack; |
47126 | 33 |
|
34 |
final class DTransformingPathConsumer2D { |
|
35 |
||
49496 | 36 |
// smaller uncertainty in double variant |
37 |
static final double CLIP_RECT_PADDING = 0.25d; |
|
38 |
||
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
39 |
private final DRendererContext rdrCtx; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
40 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
41 |
// recycled ClosedPathDetector instance from detectClosedPath() |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
42 |
private final ClosedPathDetector cpDetector; |
47126 | 43 |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
44 |
// recycled PathClipFilter instance from pathClipper() |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
45 |
private final PathClipFilter pathClipper; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
46 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
47 |
// recycled DPathConsumer2D instance from wrapPath2D() |
47126 | 48 |
private final Path2DWrapper wp_Path2DWrapper = new Path2DWrapper(); |
49 |
||
50 |
// recycled DPathConsumer2D instances from deltaTransformConsumer() |
|
51 |
private final DeltaScaleFilter dt_DeltaScaleFilter = new DeltaScaleFilter(); |
|
52 |
private final DeltaTransformFilter dt_DeltaTransformFilter = new DeltaTransformFilter(); |
|
53 |
||
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
54 |
// recycled DPathConsumer2D instances from inverseDeltaTransformConsumer() |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
55 |
private final DeltaScaleFilter iv_DeltaScaleFilter = new DeltaScaleFilter(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
56 |
private final DeltaTransformFilter iv_DeltaTransformFilter = new DeltaTransformFilter(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
57 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
58 |
// recycled PathTracer instances from tracer...() methods |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
59 |
private final PathTracer tracerInput = new PathTracer("[Input]"); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
60 |
private final PathTracer tracerCPDetector = new PathTracer("ClosedPathDetector"); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
61 |
private final PathTracer tracerFiller = new PathTracer("Filler"); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
62 |
private final PathTracer tracerStroker = new PathTracer("Stroker"); |
49496 | 63 |
private final PathTracer tracerDasher = new PathTracer("Dasher"); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
64 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
65 |
DTransformingPathConsumer2D(final DRendererContext rdrCtx) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
66 |
// used by RendererContext |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
67 |
this.rdrCtx = rdrCtx; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
68 |
this.cpDetector = new ClosedPathDetector(rdrCtx); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
69 |
this.pathClipper = new PathClipFilter(rdrCtx); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
70 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
71 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
72 |
DPathConsumer2D wrapPath2D(Path2D.Double p2d) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
73 |
return wp_Path2DWrapper.init(p2d); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
74 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
75 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
76 |
DPathConsumer2D traceInput(DPathConsumer2D out) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
77 |
return tracerInput.init(out); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
78 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
79 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
80 |
DPathConsumer2D traceClosedPathDetector(DPathConsumer2D out) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
81 |
return tracerCPDetector.init(out); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
82 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
83 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
84 |
DPathConsumer2D traceFiller(DPathConsumer2D out) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
85 |
return tracerFiller.init(out); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
86 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
87 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
88 |
DPathConsumer2D traceStroker(DPathConsumer2D out) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
89 |
return tracerStroker.init(out); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
90 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
91 |
|
49496 | 92 |
DPathConsumer2D traceDasher(DPathConsumer2D out) { |
93 |
return tracerDasher.init(out); |
|
94 |
} |
|
95 |
||
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
96 |
DPathConsumer2D detectClosedPath(DPathConsumer2D out) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
97 |
return cpDetector.init(out); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
98 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
99 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
100 |
DPathConsumer2D pathClipper(DPathConsumer2D out) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
101 |
return pathClipper.init(out); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
102 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
103 |
|
47126 | 104 |
DPathConsumer2D deltaTransformConsumer(DPathConsumer2D out, |
105 |
AffineTransform at) |
|
106 |
{ |
|
107 |
if (at == null) { |
|
108 |
return out; |
|
109 |
} |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
110 |
final double mxx = at.getScaleX(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
111 |
final double mxy = at.getShearX(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
112 |
final double myx = at.getShearY(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
113 |
final double myy = at.getScaleY(); |
47126 | 114 |
|
115 |
if (mxy == 0.0d && myx == 0.0d) { |
|
116 |
if (mxx == 1.0d && myy == 1.0d) { |
|
117 |
return out; |
|
118 |
} else { |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
119 |
// Scale only |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
120 |
if (rdrCtx.doClip) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
121 |
// adjust clip rectangle (ymin, ymax, xmin, xmax): |
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
122 |
rdrCtx.clipInvScale = adjustClipScale(rdrCtx.clipRect, |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
123 |
mxx, myy); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
124 |
} |
47126 | 125 |
return dt_DeltaScaleFilter.init(out, mxx, myy); |
126 |
} |
|
127 |
} else { |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
128 |
if (rdrCtx.doClip) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
129 |
// adjust clip rectangle (ymin, ymax, xmin, xmax): |
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
130 |
rdrCtx.clipInvScale = adjustClipInverseDelta(rdrCtx.clipRect, |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
131 |
mxx, mxy, myx, myy); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
132 |
} |
47126 | 133 |
return dt_DeltaTransformFilter.init(out, mxx, mxy, myx, myy); |
134 |
} |
|
135 |
} |
|
136 |
||
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
137 |
private static double adjustClipScale(final double[] clipRect, |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
138 |
final double mxx, final double myy) |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
139 |
{ |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
140 |
// Adjust the clipping rectangle (iv_DeltaScaleFilter): |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
141 |
final double scaleY = 1.0d / myy; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
142 |
clipRect[0] *= scaleY; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
143 |
clipRect[1] *= scaleY; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
144 |
|
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
145 |
if (clipRect[1] < clipRect[0]) { |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
146 |
double tmp = clipRect[0]; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
147 |
clipRect[0] = clipRect[1]; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
148 |
clipRect[1] = tmp; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
149 |
} |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
150 |
|
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
151 |
final double scaleX = 1.0d / mxx; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
152 |
clipRect[2] *= scaleX; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
153 |
clipRect[3] *= scaleX; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
154 |
|
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
155 |
if (clipRect[3] < clipRect[2]) { |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
156 |
double tmp = clipRect[2]; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
157 |
clipRect[2] = clipRect[3]; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
158 |
clipRect[3] = tmp; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
159 |
} |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
160 |
|
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
161 |
if (MarlinConst.DO_LOG_CLIP) { |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
162 |
MarlinUtils.logInfo("clipRect (ClipScale): " |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
163 |
+ Arrays.toString(clipRect)); |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
164 |
} |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
165 |
return 0.5d * (Math.abs(scaleX) + Math.abs(scaleY)); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
166 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
167 |
|
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
168 |
private static double adjustClipInverseDelta(final double[] clipRect, |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
169 |
final double mxx, final double mxy, |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
170 |
final double myx, final double myy) |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
171 |
{ |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
172 |
// Adjust the clipping rectangle (iv_DeltaTransformFilter): |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
173 |
final double det = mxx * myy - mxy * myx; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
174 |
final double imxx = myy / det; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
175 |
final double imxy = -mxy / det; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
176 |
final double imyx = -myx / det; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
177 |
final double imyy = mxx / det; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
178 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
179 |
double xmin, xmax, ymin, ymax; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
180 |
double x, y; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
181 |
// xmin, ymin: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
182 |
x = clipRect[2] * imxx + clipRect[0] * imxy; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
183 |
y = clipRect[2] * imyx + clipRect[0] * imyy; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
184 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
185 |
xmin = xmax = x; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
186 |
ymin = ymax = y; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
187 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
188 |
// xmax, ymin: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
189 |
x = clipRect[3] * imxx + clipRect[0] * imxy; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
190 |
y = clipRect[3] * imyx + clipRect[0] * imyy; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
191 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
192 |
if (x < xmin) { xmin = x; } else if (x > xmax) { xmax = x; } |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
193 |
if (y < ymin) { ymin = y; } else if (y > ymax) { ymax = y; } |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
194 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
195 |
// xmin, ymax: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
196 |
x = clipRect[2] * imxx + clipRect[1] * imxy; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
197 |
y = clipRect[2] * imyx + clipRect[1] * imyy; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
198 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
199 |
if (x < xmin) { xmin = x; } else if (x > xmax) { xmax = x; } |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
200 |
if (y < ymin) { ymin = y; } else if (y > ymax) { ymax = y; } |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
201 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
202 |
// xmax, ymax: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
203 |
x = clipRect[3] * imxx + clipRect[1] * imxy; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
204 |
y = clipRect[3] * imyx + clipRect[1] * imyy; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
205 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
206 |
if (x < xmin) { xmin = x; } else if (x > xmax) { xmax = x; } |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
207 |
if (y < ymin) { ymin = y; } else if (y > ymax) { ymax = y; } |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
208 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
209 |
clipRect[0] = ymin; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
210 |
clipRect[1] = ymax; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
211 |
clipRect[2] = xmin; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
212 |
clipRect[3] = xmax; |
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
213 |
|
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
214 |
if (MarlinConst.DO_LOG_CLIP) { |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
215 |
MarlinUtils.logInfo("clipRect (ClipInverseDelta): " |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
216 |
+ Arrays.toString(clipRect)); |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
217 |
} |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
218 |
|
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
219 |
final double scaleX = Math.sqrt(imxx * imxx + imxy * imxy); |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
220 |
final double scaleY = Math.sqrt(imyx * imyx + imyy * imyy); |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
221 |
|
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
222 |
return 0.5d * (scaleX + scaleY); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
223 |
} |
47126 | 224 |
|
225 |
DPathConsumer2D inverseDeltaTransformConsumer(DPathConsumer2D out, |
|
226 |
AffineTransform at) |
|
227 |
{ |
|
228 |
if (at == null) { |
|
229 |
return out; |
|
230 |
} |
|
231 |
double mxx = at.getScaleX(); |
|
232 |
double mxy = at.getShearX(); |
|
233 |
double myx = at.getShearY(); |
|
234 |
double myy = at.getScaleY(); |
|
235 |
||
236 |
if (mxy == 0.0d && myx == 0.0d) { |
|
237 |
if (mxx == 1.0d && myy == 1.0d) { |
|
238 |
return out; |
|
239 |
} else { |
|
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
240 |
return iv_DeltaScaleFilter.init(out, 1.0d / mxx, 1.0d / myy); |
47126 | 241 |
} |
242 |
} else { |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
243 |
final double det = mxx * myy - mxy * myx; |
47126 | 244 |
return iv_DeltaTransformFilter.init(out, |
245 |
myy / det, |
|
246 |
-mxy / det, |
|
247 |
-myx / det, |
|
248 |
mxx / det); |
|
249 |
} |
|
250 |
} |
|
251 |
||
252 |
static final class DeltaScaleFilter implements DPathConsumer2D { |
|
253 |
private DPathConsumer2D out; |
|
254 |
private double sx, sy; |
|
255 |
||
256 |
DeltaScaleFilter() {} |
|
257 |
||
258 |
DeltaScaleFilter init(DPathConsumer2D out, |
|
259 |
double mxx, double myy) |
|
260 |
{ |
|
261 |
this.out = out; |
|
262 |
sx = mxx; |
|
263 |
sy = myy; |
|
264 |
return this; // fluent API |
|
265 |
} |
|
266 |
||
267 |
@Override |
|
268 |
public void moveTo(double x0, double y0) { |
|
269 |
out.moveTo(x0 * sx, y0 * sy); |
|
270 |
} |
|
271 |
||
272 |
@Override |
|
273 |
public void lineTo(double x1, double y1) { |
|
274 |
out.lineTo(x1 * sx, y1 * sy); |
|
275 |
} |
|
276 |
||
277 |
@Override |
|
278 |
public void quadTo(double x1, double y1, |
|
279 |
double x2, double y2) |
|
280 |
{ |
|
281 |
out.quadTo(x1 * sx, y1 * sy, |
|
282 |
x2 * sx, y2 * sy); |
|
283 |
} |
|
284 |
||
285 |
@Override |
|
286 |
public void curveTo(double x1, double y1, |
|
287 |
double x2, double y2, |
|
288 |
double x3, double y3) |
|
289 |
{ |
|
290 |
out.curveTo(x1 * sx, y1 * sy, |
|
291 |
x2 * sx, y2 * sy, |
|
292 |
x3 * sx, y3 * sy); |
|
293 |
} |
|
294 |
||
295 |
@Override |
|
296 |
public void closePath() { |
|
297 |
out.closePath(); |
|
298 |
} |
|
299 |
||
300 |
@Override |
|
301 |
public void pathDone() { |
|
302 |
out.pathDone(); |
|
303 |
} |
|
304 |
||
305 |
@Override |
|
306 |
public long getNativeConsumer() { |
|
307 |
return 0; |
|
308 |
} |
|
309 |
} |
|
310 |
||
311 |
static final class DeltaTransformFilter implements DPathConsumer2D { |
|
312 |
private DPathConsumer2D out; |
|
313 |
private double mxx, mxy, myx, myy; |
|
314 |
||
315 |
DeltaTransformFilter() {} |
|
316 |
||
317 |
DeltaTransformFilter init(DPathConsumer2D out, |
|
318 |
double mxx, double mxy, |
|
319 |
double myx, double myy) |
|
320 |
{ |
|
321 |
this.out = out; |
|
322 |
this.mxx = mxx; |
|
323 |
this.mxy = mxy; |
|
324 |
this.myx = myx; |
|
325 |
this.myy = myy; |
|
326 |
return this; // fluent API |
|
327 |
} |
|
328 |
||
329 |
@Override |
|
330 |
public void moveTo(double x0, double y0) { |
|
331 |
out.moveTo(x0 * mxx + y0 * mxy, |
|
332 |
x0 * myx + y0 * myy); |
|
333 |
} |
|
334 |
||
335 |
@Override |
|
336 |
public void lineTo(double x1, double y1) { |
|
337 |
out.lineTo(x1 * mxx + y1 * mxy, |
|
338 |
x1 * myx + y1 * myy); |
|
339 |
} |
|
340 |
||
341 |
@Override |
|
342 |
public void quadTo(double x1, double y1, |
|
343 |
double x2, double y2) |
|
344 |
{ |
|
345 |
out.quadTo(x1 * mxx + y1 * mxy, |
|
346 |
x1 * myx + y1 * myy, |
|
347 |
x2 * mxx + y2 * mxy, |
|
348 |
x2 * myx + y2 * myy); |
|
349 |
} |
|
350 |
||
351 |
@Override |
|
352 |
public void curveTo(double x1, double y1, |
|
353 |
double x2, double y2, |
|
354 |
double x3, double y3) |
|
355 |
{ |
|
356 |
out.curveTo(x1 * mxx + y1 * mxy, |
|
357 |
x1 * myx + y1 * myy, |
|
358 |
x2 * mxx + y2 * mxy, |
|
359 |
x2 * myx + y2 * myy, |
|
360 |
x3 * mxx + y3 * mxy, |
|
361 |
x3 * myx + y3 * myy); |
|
362 |
} |
|
363 |
||
364 |
@Override |
|
365 |
public void closePath() { |
|
366 |
out.closePath(); |
|
367 |
} |
|
368 |
||
369 |
@Override |
|
370 |
public void pathDone() { |
|
371 |
out.pathDone(); |
|
372 |
} |
|
373 |
||
374 |
@Override |
|
375 |
public long getNativeConsumer() { |
|
376 |
return 0; |
|
377 |
} |
|
378 |
} |
|
379 |
||
380 |
static final class Path2DWrapper implements DPathConsumer2D { |
|
381 |
private Path2D.Double p2d; |
|
382 |
||
383 |
Path2DWrapper() {} |
|
384 |
||
385 |
Path2DWrapper init(Path2D.Double p2d) { |
|
386 |
this.p2d = p2d; |
|
387 |
return this; |
|
388 |
} |
|
389 |
||
390 |
@Override |
|
391 |
public void moveTo(double x0, double y0) { |
|
392 |
p2d.moveTo(x0, y0); |
|
393 |
} |
|
394 |
||
395 |
@Override |
|
396 |
public void lineTo(double x1, double y1) { |
|
397 |
p2d.lineTo(x1, y1); |
|
398 |
} |
|
399 |
||
400 |
@Override |
|
401 |
public void closePath() { |
|
402 |
p2d.closePath(); |
|
403 |
} |
|
404 |
||
405 |
@Override |
|
406 |
public void pathDone() {} |
|
407 |
||
408 |
@Override |
|
409 |
public void curveTo(double x1, double y1, |
|
410 |
double x2, double y2, |
|
411 |
double x3, double y3) |
|
412 |
{ |
|
413 |
p2d.curveTo(x1, y1, x2, y2, x3, y3); |
|
414 |
} |
|
415 |
||
416 |
@Override |
|
417 |
public void quadTo(double x1, double y1, double x2, double y2) { |
|
418 |
p2d.quadTo(x1, y1, x2, y2); |
|
419 |
} |
|
420 |
||
421 |
@Override |
|
422 |
public long getNativeConsumer() { |
|
423 |
throw new InternalError("Not using a native peer"); |
|
424 |
} |
|
425 |
} |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
426 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
427 |
static final class ClosedPathDetector implements DPathConsumer2D { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
428 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
429 |
private final DRendererContext rdrCtx; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
430 |
private final PolyStack stack; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
431 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
432 |
private DPathConsumer2D out; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
433 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
434 |
ClosedPathDetector(final DRendererContext rdrCtx) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
435 |
this.rdrCtx = rdrCtx; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
436 |
this.stack = (rdrCtx.stats != null) ? |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
437 |
new PolyStack(rdrCtx, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
438 |
rdrCtx.stats.stat_cpd_polystack_types, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
439 |
rdrCtx.stats.stat_cpd_polystack_curves, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
440 |
rdrCtx.stats.hist_cpd_polystack_curves, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
441 |
rdrCtx.stats.stat_array_cpd_polystack_curves, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
442 |
rdrCtx.stats.stat_array_cpd_polystack_types) |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
443 |
: new PolyStack(rdrCtx); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
444 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
445 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
446 |
ClosedPathDetector init(DPathConsumer2D out) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
447 |
this.out = out; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
448 |
return this; // fluent API |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
449 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
450 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
451 |
/** |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
452 |
* Disposes this instance: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
453 |
* clean up before reusing this instance |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
454 |
*/ |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
455 |
void dispose() { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
456 |
stack.dispose(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
457 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
458 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
459 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
460 |
public void pathDone() { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
461 |
// previous path is not closed: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
462 |
finish(false); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
463 |
out.pathDone(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
464 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
465 |
// TODO: fix possible leak if exception happened |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
466 |
// Dispose this instance: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
467 |
dispose(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
468 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
469 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
470 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
471 |
public void closePath() { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
472 |
// path is closed |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
473 |
finish(true); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
474 |
out.closePath(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
475 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
476 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
477 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
478 |
public void moveTo(double x0, double y0) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
479 |
// previous path is not closed: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
480 |
finish(false); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
481 |
out.moveTo(x0, y0); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
482 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
483 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
484 |
private void finish(final boolean closed) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
485 |
rdrCtx.closedPath = closed; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
486 |
stack.pullAll(out); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
487 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
488 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
489 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
490 |
public void lineTo(double x1, double y1) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
491 |
stack.pushLine(x1, y1); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
492 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
493 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
494 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
495 |
public void curveTo(double x3, double y3, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
496 |
double x2, double y2, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
497 |
double x1, double y1) |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
498 |
{ |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
499 |
stack.pushCubic(x1, y1, x2, y2, x3, y3); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
500 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
501 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
502 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
503 |
public void quadTo(double x2, double y2, double x1, double y1) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
504 |
stack.pushQuad(x1, y1, x2, y2); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
505 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
506 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
507 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
508 |
public long getNativeConsumer() { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
509 |
throw new InternalError("Not using a native peer"); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
510 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
511 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
512 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
513 |
static final class PathClipFilter implements DPathConsumer2D { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
514 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
515 |
private DPathConsumer2D out; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
516 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
517 |
// Bounds of the drawing region, at pixel precision. |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
518 |
private final double[] clipRect; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
519 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
520 |
private final double[] corners = new double[8]; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
521 |
private boolean init_corners = false; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
522 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
523 |
private final IndexStack stack; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
524 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
525 |
// the current outcode of the current sub path |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
526 |
private int cOutCode = 0; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
527 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
528 |
// the cumulated (and) outcode of the complete path |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
529 |
private int gOutCode = MarlinConst.OUTCODE_MASK_T_B_L_R; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
530 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
531 |
private boolean outside = false; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
532 |
|
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
533 |
// The starting point of the path |
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
534 |
private double sx0, sy0; |
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
535 |
|
49496 | 536 |
// The current point (TODO stupid repeated info) |
537 |
private double cx0, cy0; |
|
538 |
||
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
539 |
// The current point OUTSIDE |
49496 | 540 |
private double cox0, coy0; |
541 |
||
542 |
private boolean subdivide = MarlinConst.DO_CLIP_SUBDIVIDER; |
|
543 |
private final CurveClipSplitter curveSplitter; |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
544 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
545 |
PathClipFilter(final DRendererContext rdrCtx) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
546 |
this.clipRect = rdrCtx.clipRect; |
49496 | 547 |
this.curveSplitter = rdrCtx.curveClipSplitter; |
548 |
||
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
549 |
this.stack = (rdrCtx.stats != null) ? |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
550 |
new IndexStack(rdrCtx, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
551 |
rdrCtx.stats.stat_pcf_idxstack_indices, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
552 |
rdrCtx.stats.hist_pcf_idxstack_indices, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
553 |
rdrCtx.stats.stat_array_pcf_idxstack_indices) |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
554 |
: new IndexStack(rdrCtx); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
555 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
556 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
557 |
PathClipFilter init(final DPathConsumer2D out) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
558 |
this.out = out; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
559 |
|
49496 | 560 |
if (MarlinConst.DO_CLIP_SUBDIVIDER) { |
561 |
// adjust padded clip rectangle: |
|
562 |
curveSplitter.init(); |
|
563 |
} |
|
564 |
||
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
565 |
this.init_corners = true; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
566 |
this.gOutCode = MarlinConst.OUTCODE_MASK_T_B_L_R; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
567 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
568 |
return this; // fluent API |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
569 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
570 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
571 |
/** |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
572 |
* Disposes this instance: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
573 |
* clean up before reusing this instance |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
574 |
*/ |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
575 |
void dispose() { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
576 |
stack.dispose(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
577 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
578 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
579 |
private void finishPath() { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
580 |
if (outside) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
581 |
// criteria: inside or totally outside ? |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
582 |
if (gOutCode == 0) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
583 |
finish(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
584 |
} else { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
585 |
this.outside = false; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
586 |
stack.reset(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
587 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
588 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
589 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
590 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
591 |
private void finish() { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
592 |
this.outside = false; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
593 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
594 |
if (!stack.isEmpty()) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
595 |
if (init_corners) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
596 |
init_corners = false; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
597 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
598 |
final double[] _corners = corners; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
599 |
final double[] _clipRect = clipRect; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
600 |
// Top Left (0): |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
601 |
_corners[0] = _clipRect[2]; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
602 |
_corners[1] = _clipRect[0]; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
603 |
// Bottom Left (1): |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
604 |
_corners[2] = _clipRect[2]; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
605 |
_corners[3] = _clipRect[1]; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
606 |
// Top right (2): |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
607 |
_corners[4] = _clipRect[3]; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
608 |
_corners[5] = _clipRect[0]; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
609 |
// Bottom Right (3): |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
610 |
_corners[6] = _clipRect[3]; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
611 |
_corners[7] = _clipRect[1]; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
612 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
613 |
stack.pullAll(corners, out); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
614 |
} |
49496 | 615 |
out.lineTo(cox0, coy0); |
616 |
this.cx0 = cox0; |
|
617 |
this.cy0 = coy0; |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
618 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
619 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
620 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
621 |
public void pathDone() { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
622 |
finishPath(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
623 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
624 |
out.pathDone(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
625 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
626 |
// TODO: fix possible leak if exception happened |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
627 |
// Dispose this instance: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
628 |
dispose(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
629 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
630 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
631 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
632 |
public void closePath() { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
633 |
finishPath(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
634 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
635 |
out.closePath(); |
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
636 |
|
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
637 |
// back to starting point: |
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
638 |
this.cOutCode = DHelpers.outcode(sx0, sy0, clipRect); |
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
639 |
this.cx0 = sx0; |
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
640 |
this.cy0 = sy0; |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
641 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
642 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
643 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
644 |
public void moveTo(final double x0, final double y0) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
645 |
finishPath(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
646 |
|
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
647 |
out.moveTo(x0, y0); |
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
648 |
|
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
649 |
// update starting point: |
49496 | 650 |
this.cOutCode = DHelpers.outcode(x0, y0, clipRect); |
651 |
this.cx0 = x0; |
|
652 |
this.cy0 = y0; |
|
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
653 |
|
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
654 |
this.sx0 = x0; |
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
655 |
this.sy0 = y0; |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
656 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
657 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
658 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
659 |
public void lineTo(final double xe, final double ye) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
660 |
final int outcode0 = this.cOutCode; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
661 |
final int outcode1 = DHelpers.outcode(xe, ye, clipRect); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
662 |
|
49496 | 663 |
// Should clip |
664 |
final int orCode = (outcode0 | outcode1); |
|
665 |
if (orCode != 0) { |
|
666 |
final int sideCode = (outcode0 & outcode1); |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
667 |
|
49496 | 668 |
// basic rejection criteria: |
669 |
if (sideCode == 0) { |
|
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
670 |
// overlap clip: |
49496 | 671 |
if (subdivide) { |
672 |
// avoid reentrance |
|
673 |
subdivide = false; |
|
674 |
boolean ret; |
|
675 |
// subdivide curve => callback with subdivided parts: |
|
676 |
if (outside) { |
|
677 |
ret = curveSplitter.splitLine(cox0, coy0, xe, ye, |
|
678 |
orCode, this); |
|
679 |
} else { |
|
680 |
ret = curveSplitter.splitLine(cx0, cy0, xe, ye, |
|
681 |
orCode, this); |
|
682 |
} |
|
683 |
// reentrance is done: |
|
684 |
subdivide = true; |
|
685 |
if (ret) { |
|
686 |
return; |
|
687 |
} |
|
688 |
} |
|
689 |
// already subdivided so render it |
|
690 |
} else { |
|
691 |
this.cOutCode = outcode1; |
|
692 |
this.gOutCode &= sideCode; |
|
693 |
// keep last point coordinate before entering the clip again: |
|
694 |
this.outside = true; |
|
695 |
this.cox0 = xe; |
|
696 |
this.coy0 = ye; |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
697 |
|
49496 | 698 |
clip(sideCode, outcode0, outcode1); |
699 |
return; |
|
700 |
} |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
701 |
} |
49496 | 702 |
|
703 |
this.cOutCode = outcode1; |
|
704 |
this.gOutCode = 0; |
|
705 |
||
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
706 |
if (outside) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
707 |
finish(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
708 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
709 |
// clipping disabled: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
710 |
out.lineTo(xe, ye); |
49496 | 711 |
this.cx0 = xe; |
712 |
this.cy0 = ye; |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
713 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
714 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
715 |
private void clip(final int sideCode, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
716 |
final int outcode0, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
717 |
final int outcode1) |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
718 |
{ |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
719 |
// corner or cross-boundary on left or right side: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
720 |
if ((outcode0 != outcode1) |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
721 |
&& ((sideCode & MarlinConst.OUTCODE_MASK_L_R) != 0)) |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
722 |
{ |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
723 |
// combine outcodes: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
724 |
final int mergeCode = (outcode0 | outcode1); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
725 |
final int tbCode = mergeCode & MarlinConst.OUTCODE_MASK_T_B; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
726 |
final int lrCode = mergeCode & MarlinConst.OUTCODE_MASK_L_R; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
727 |
final int off = (lrCode == MarlinConst.OUTCODE_LEFT) ? 0 : 2; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
728 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
729 |
// add corners to outside stack: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
730 |
switch (tbCode) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
731 |
case MarlinConst.OUTCODE_TOP: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
732 |
stack.push(off); // top |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
733 |
return; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
734 |
case MarlinConst.OUTCODE_BOTTOM: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
735 |
stack.push(off + 1); // bottom |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
736 |
return; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
737 |
default: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
738 |
// both TOP / BOTTOM: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
739 |
if ((outcode0 & MarlinConst.OUTCODE_TOP) != 0) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
740 |
// top to bottom |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
741 |
stack.push(off); // top |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
742 |
stack.push(off + 1); // bottom |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
743 |
} else { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
744 |
// bottom to top |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
745 |
stack.push(off + 1); // bottom |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
746 |
stack.push(off); // top |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
747 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
748 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
749 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
750 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
751 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
752 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
753 |
public void curveTo(final double x1, final double y1, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
754 |
final double x2, final double y2, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
755 |
final double xe, final double ye) |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
756 |
{ |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
757 |
final int outcode0 = this.cOutCode; |
49496 | 758 |
final int outcode1 = DHelpers.outcode(x1, y1, clipRect); |
759 |
final int outcode2 = DHelpers.outcode(x2, y2, clipRect); |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
760 |
final int outcode3 = DHelpers.outcode(xe, ye, clipRect); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
761 |
|
49496 | 762 |
// Should clip |
763 |
final int orCode = (outcode0 | outcode1 | outcode2 | outcode3); |
|
764 |
if (orCode != 0) { |
|
765 |
final int sideCode = outcode0 & outcode1 & outcode2 & outcode3; |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
766 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
767 |
// basic rejection criteria: |
49496 | 768 |
if (sideCode == 0) { |
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
769 |
// overlap clip: |
49496 | 770 |
if (subdivide) { |
771 |
// avoid reentrance |
|
772 |
subdivide = false; |
|
773 |
// subdivide curve => callback with subdivided parts: |
|
774 |
boolean ret; |
|
775 |
if (outside) { |
|
776 |
ret = curveSplitter.splitCurve(cox0, coy0, x1, y1, |
|
777 |
x2, y2, xe, ye, |
|
778 |
orCode, this); |
|
779 |
} else { |
|
780 |
ret = curveSplitter.splitCurve(cx0, cy0, x1, y1, |
|
781 |
x2, y2, xe, ye, |
|
782 |
orCode, this); |
|
783 |
} |
|
784 |
// reentrance is done: |
|
785 |
subdivide = true; |
|
786 |
if (ret) { |
|
787 |
return; |
|
788 |
} |
|
789 |
} |
|
790 |
// already subdivided so render it |
|
791 |
} else { |
|
792 |
this.cOutCode = outcode3; |
|
793 |
this.gOutCode &= sideCode; |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
794 |
// keep last point coordinate before entering the clip again: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
795 |
this.outside = true; |
49496 | 796 |
this.cox0 = xe; |
797 |
this.coy0 = ye; |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
798 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
799 |
clip(sideCode, outcode0, outcode3); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
800 |
return; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
801 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
802 |
} |
49496 | 803 |
|
804 |
this.cOutCode = outcode3; |
|
805 |
this.gOutCode = 0; |
|
806 |
||
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
807 |
if (outside) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
808 |
finish(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
809 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
810 |
// clipping disabled: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
811 |
out.curveTo(x1, y1, x2, y2, xe, ye); |
49496 | 812 |
this.cx0 = xe; |
813 |
this.cy0 = ye; |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
814 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
815 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
816 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
817 |
public void quadTo(final double x1, final double y1, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
818 |
final double xe, final double ye) |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
819 |
{ |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
820 |
final int outcode0 = this.cOutCode; |
49496 | 821 |
final int outcode1 = DHelpers.outcode(x1, y1, clipRect); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
822 |
final int outcode2 = DHelpers.outcode(xe, ye, clipRect); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
823 |
|
49496 | 824 |
// Should clip |
825 |
final int orCode = (outcode0 | outcode1 | outcode2); |
|
826 |
if (orCode != 0) { |
|
827 |
final int sideCode = outcode0 & outcode1 & outcode2; |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
828 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
829 |
// basic rejection criteria: |
49496 | 830 |
if (sideCode == 0) { |
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
831 |
// overlap clip: |
49496 | 832 |
if (subdivide) { |
833 |
// avoid reentrance |
|
834 |
subdivide = false; |
|
835 |
// subdivide curve => callback with subdivided parts: |
|
836 |
boolean ret; |
|
837 |
if (outside) { |
|
838 |
ret = curveSplitter.splitQuad(cox0, coy0, x1, y1, |
|
839 |
xe, ye, orCode, this); |
|
840 |
} else { |
|
841 |
ret = curveSplitter.splitQuad(cx0, cy0, x1, y1, |
|
842 |
xe, ye, orCode, this); |
|
843 |
} |
|
844 |
// reentrance is done: |
|
845 |
subdivide = true; |
|
846 |
if (ret) { |
|
847 |
return; |
|
848 |
} |
|
849 |
} |
|
850 |
// already subdivided so render it |
|
851 |
} else { |
|
852 |
this.cOutCode = outcode2; |
|
853 |
this.gOutCode &= sideCode; |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
854 |
// keep last point coordinate before entering the clip again: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
855 |
this.outside = true; |
49496 | 856 |
this.cox0 = xe; |
857 |
this.coy0 = ye; |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
858 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
859 |
clip(sideCode, outcode0, outcode2); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
860 |
return; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
861 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
862 |
} |
49496 | 863 |
|
864 |
this.cOutCode = outcode2; |
|
865 |
this.gOutCode = 0; |
|
866 |
||
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
867 |
if (outside) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
868 |
finish(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
869 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
870 |
// clipping disabled: |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
871 |
out.quadTo(x1, y1, xe, ye); |
49496 | 872 |
this.cx0 = xe; |
873 |
this.cy0 = ye; |
|
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
874 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
875 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
876 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
877 |
public long getNativeConsumer() { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
878 |
throw new InternalError("Not using a native peer"); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
879 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
880 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
881 |
|
49496 | 882 |
static final class CurveClipSplitter { |
883 |
||
884 |
static final double LEN_TH = MarlinProperties.getSubdividerMinLength(); |
|
885 |
static final boolean DO_CHECK_LENGTH = (LEN_TH > 0.0d); |
|
886 |
||
887 |
private static final boolean TRACE = false; |
|
888 |
||
889 |
private static final int MAX_N_CURVES = 3 * 4; |
|
890 |
||
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
891 |
private final DRendererContext rdrCtx; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
892 |
|
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
893 |
// scaled length threshold: |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
894 |
private double minLength; |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
895 |
|
49496 | 896 |
// clip rectangle (ymin, ymax, xmin, xmax): |
897 |
final double[] clipRect; |
|
898 |
||
899 |
// clip rectangle (ymin, ymax, xmin, xmax) including padding: |
|
900 |
final double[] clipRectPad = new double[4]; |
|
901 |
private boolean init_clipRectPad = false; |
|
902 |
||
903 |
// This is where the curve to be processed is put. We give it |
|
904 |
// enough room to store all curves. |
|
905 |
final double[] middle = new double[MAX_N_CURVES * 8 + 2]; |
|
906 |
// t values at subdivision points |
|
907 |
private final double[] subdivTs = new double[MAX_N_CURVES]; |
|
908 |
||
909 |
// dirty curve |
|
910 |
private final DCurve curve; |
|
911 |
||
912 |
CurveClipSplitter(final DRendererContext rdrCtx) { |
|
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
913 |
this.rdrCtx = rdrCtx; |
49496 | 914 |
this.clipRect = rdrCtx.clipRect; |
915 |
this.curve = rdrCtx.curve; |
|
916 |
} |
|
917 |
||
918 |
void init() { |
|
919 |
this.init_clipRectPad = true; |
|
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
920 |
|
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
921 |
if (DO_CHECK_LENGTH) { |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
922 |
this.minLength = (this.rdrCtx.clipInvScale == 0.0d) ? LEN_TH |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
923 |
: (LEN_TH * this.rdrCtx.clipInvScale); |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
924 |
|
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
925 |
if (MarlinConst.DO_LOG_CLIP) { |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
926 |
MarlinUtils.logInfo("CurveClipSplitter.minLength = " |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
927 |
+ minLength); |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
928 |
} |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
929 |
} |
49496 | 930 |
} |
931 |
||
932 |
private void initPaddedClip() { |
|
933 |
// bounds as half-open intervals: minX <= x < maxX and minY <= y < maxY |
|
934 |
// adjust padded clip rectangle (ymin, ymax, xmin, xmax): |
|
935 |
// add a rounding error (curve subdivision ~ 0.1px): |
|
936 |
final double[] _clipRect = clipRect; |
|
937 |
final double[] _clipRectPad = clipRectPad; |
|
938 |
||
939 |
_clipRectPad[0] = _clipRect[0] - CLIP_RECT_PADDING; |
|
940 |
_clipRectPad[1] = _clipRect[1] + CLIP_RECT_PADDING; |
|
941 |
_clipRectPad[2] = _clipRect[2] - CLIP_RECT_PADDING; |
|
942 |
_clipRectPad[3] = _clipRect[3] + CLIP_RECT_PADDING; |
|
943 |
||
944 |
if (TRACE) { |
|
945 |
MarlinUtils.logInfo("clip: X [" + _clipRectPad[2] + " .. " + _clipRectPad[3] +"] " |
|
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
946 |
+ "Y [" + _clipRectPad[0] + " .. " + _clipRectPad[1] +"]"); |
49496 | 947 |
} |
948 |
} |
|
949 |
||
950 |
boolean splitLine(final double x0, final double y0, |
|
951 |
final double x1, final double y1, |
|
952 |
final int outCodeOR, |
|
953 |
final DPathConsumer2D out) |
|
954 |
{ |
|
955 |
if (TRACE) { |
|
956 |
MarlinUtils.logInfo("divLine P0(" + x0 + ", " + y0 + ") P1(" + x1 + ", " + y1 + ")"); |
|
957 |
} |
|
958 |
||
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
959 |
if (DO_CHECK_LENGTH && DHelpers.fastLineLen(x0, y0, x1, y1) <= minLength) { |
49496 | 960 |
return false; |
961 |
} |
|
962 |
||
963 |
final double[] mid = middle; |
|
964 |
mid[0] = x0; mid[1] = y0; |
|
965 |
mid[2] = x1; mid[3] = y1; |
|
966 |
||
967 |
return subdivideAtIntersections(4, outCodeOR, out); |
|
968 |
} |
|
969 |
||
970 |
boolean splitQuad(final double x0, final double y0, |
|
971 |
final double x1, final double y1, |
|
972 |
final double x2, final double y2, |
|
973 |
final int outCodeOR, |
|
974 |
final DPathConsumer2D out) |
|
975 |
{ |
|
976 |
if (TRACE) { |
|
977 |
MarlinUtils.logInfo("divQuad P0(" + x0 + ", " + y0 + ") P1(" + x1 + ", " + y1 + ") P2(" + x2 + ", " + y2 + ")"); |
|
978 |
} |
|
979 |
||
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
980 |
if (DO_CHECK_LENGTH && DHelpers.fastQuadLen(x0, y0, x1, y1, x2, y2) <= minLength) { |
49496 | 981 |
return false; |
982 |
} |
|
983 |
||
984 |
final double[] mid = middle; |
|
985 |
mid[0] = x0; mid[1] = y0; |
|
986 |
mid[2] = x1; mid[3] = y1; |
|
987 |
mid[4] = x2; mid[5] = y2; |
|
988 |
||
989 |
return subdivideAtIntersections(6, outCodeOR, out); |
|
990 |
} |
|
991 |
||
992 |
boolean splitCurve(final double x0, final double y0, |
|
993 |
final double x1, final double y1, |
|
994 |
final double x2, final double y2, |
|
995 |
final double x3, final double y3, |
|
996 |
final int outCodeOR, |
|
997 |
final DPathConsumer2D out) |
|
998 |
{ |
|
999 |
if (TRACE) { |
|
1000 |
MarlinUtils.logInfo("divCurve P0(" + x0 + ", " + y0 + ") P1(" + x1 + ", " + y1 + ") P2(" + x2 + ", " + y2 + ") P3(" + x3 + ", " + y3 + ")"); |
|
1001 |
} |
|
1002 |
||
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
1003 |
if (DO_CHECK_LENGTH && DHelpers.fastCurvelen(x0, y0, x1, y1, x2, y2, x3, y3) <= minLength) { |
49496 | 1004 |
return false; |
1005 |
} |
|
1006 |
||
1007 |
final double[] mid = middle; |
|
1008 |
mid[0] = x0; mid[1] = y0; |
|
1009 |
mid[2] = x1; mid[3] = y1; |
|
1010 |
mid[4] = x2; mid[5] = y2; |
|
1011 |
mid[6] = x3; mid[7] = y3; |
|
1012 |
||
1013 |
return subdivideAtIntersections(8, outCodeOR, out); |
|
1014 |
} |
|
1015 |
||
1016 |
private boolean subdivideAtIntersections(final int type, final int outCodeOR, |
|
1017 |
final DPathConsumer2D out) |
|
1018 |
{ |
|
1019 |
final double[] mid = middle; |
|
1020 |
final double[] subTs = subdivTs; |
|
1021 |
||
1022 |
if (init_clipRectPad) { |
|
1023 |
init_clipRectPad = false; |
|
1024 |
initPaddedClip(); |
|
1025 |
} |
|
1026 |
||
1027 |
final int nSplits = DHelpers.findClipPoints(curve, mid, subTs, type, |
|
1028 |
outCodeOR, clipRectPad); |
|
1029 |
||
1030 |
if (TRACE) { |
|
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
1031 |
MarlinUtils.logInfo("nSplits: " + nSplits); |
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
1032 |
MarlinUtils.logInfo("subTs: " + Arrays.toString(Arrays.copyOfRange(subTs, 0, nSplits))); |
49496 | 1033 |
} |
1034 |
if (nSplits == 0) { |
|
1035 |
// only curve support shortcut |
|
1036 |
return false; |
|
1037 |
} |
|
1038 |
double prevT = 0.0d; |
|
1039 |
||
1040 |
for (int i = 0, off = 0; i < nSplits; i++, off += type) { |
|
1041 |
final double t = subTs[i]; |
|
1042 |
||
1043 |
DHelpers.subdivideAt((t - prevT) / (1.0d - prevT), |
|
1044 |
mid, off, mid, off, type); |
|
1045 |
prevT = t; |
|
1046 |
} |
|
1047 |
||
1048 |
for (int i = 0, off = 0; i <= nSplits; i++, off += type) { |
|
1049 |
if (TRACE) { |
|
51933
4ec74929fbfe
8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents:
49496
diff
changeset
|
1050 |
MarlinUtils.logInfo("Part Curve " + Arrays.toString(Arrays.copyOfRange(mid, off, off + type))); |
49496 | 1051 |
} |
1052 |
emitCurrent(type, mid, off, out); |
|
1053 |
} |
|
1054 |
return true; |
|
1055 |
} |
|
1056 |
||
1057 |
static void emitCurrent(final int type, final double[] pts, |
|
1058 |
final int off, final DPathConsumer2D out) |
|
1059 |
{ |
|
1060 |
// if instead of switch (perf + most probable cases first) |
|
1061 |
if (type == 8) { |
|
1062 |
out.curveTo(pts[off + 2], pts[off + 3], |
|
1063 |
pts[off + 4], pts[off + 5], |
|
1064 |
pts[off + 6], pts[off + 7]); |
|
1065 |
} else if (type == 4) { |
|
1066 |
out.lineTo(pts[off + 2], pts[off + 3]); |
|
1067 |
} else { |
|
1068 |
out.quadTo(pts[off + 2], pts[off + 3], |
|
1069 |
pts[off + 4], pts[off + 5]); |
|
1070 |
} |
|
1071 |
} |
|
1072 |
} |
|
1073 |
||
1074 |
static final class CurveBasicMonotonizer { |
|
1075 |
||
1076 |
private static final int MAX_N_CURVES = 11; |
|
1077 |
||
1078 |
// squared half line width (for stroker) |
|
1079 |
private double lw2; |
|
1080 |
||
1081 |
// number of splitted curves |
|
1082 |
int nbSplits; |
|
1083 |
||
1084 |
// This is where the curve to be processed is put. We give it |
|
1085 |
// enough room to store all curves. |
|
1086 |
final double[] middle = new double[MAX_N_CURVES * 6 + 2]; |
|
1087 |
// t values at subdivision points |
|
1088 |
private final double[] subdivTs = new double[MAX_N_CURVES - 1]; |
|
1089 |
||
1090 |
// dirty curve |
|
1091 |
private final DCurve curve; |
|
1092 |
||
1093 |
CurveBasicMonotonizer(final DRendererContext rdrCtx) { |
|
1094 |
this.curve = rdrCtx.curve; |
|
1095 |
} |
|
1096 |
||
1097 |
void init(final double lineWidth) { |
|
1098 |
this.lw2 = (lineWidth * lineWidth) / 4.0d; |
|
1099 |
} |
|
1100 |
||
1101 |
CurveBasicMonotonizer curve(final double x0, final double y0, |
|
1102 |
final double x1, final double y1, |
|
1103 |
final double x2, final double y2, |
|
1104 |
final double x3, final double y3) |
|
1105 |
{ |
|
1106 |
final double[] mid = middle; |
|
1107 |
mid[0] = x0; mid[1] = y0; |
|
1108 |
mid[2] = x1; mid[3] = y1; |
|
1109 |
mid[4] = x2; mid[5] = y2; |
|
1110 |
mid[6] = x3; mid[7] = y3; |
|
1111 |
||
1112 |
final double[] subTs = subdivTs; |
|
1113 |
final int nSplits = DHelpers.findSubdivPoints(curve, mid, subTs, 8, lw2); |
|
1114 |
||
1115 |
double prevT = 0.0d; |
|
1116 |
for (int i = 0, off = 0; i < nSplits; i++, off += 6) { |
|
1117 |
final double t = subTs[i]; |
|
1118 |
||
1119 |
DHelpers.subdivideCubicAt((t - prevT) / (1.0d - prevT), |
|
1120 |
mid, off, mid, off, off + 6); |
|
1121 |
prevT = t; |
|
1122 |
} |
|
1123 |
||
1124 |
this.nbSplits = nSplits; |
|
1125 |
return this; |
|
1126 |
} |
|
1127 |
||
1128 |
CurveBasicMonotonizer quad(final double x0, final double y0, |
|
1129 |
final double x1, final double y1, |
|
1130 |
final double x2, final double y2) |
|
1131 |
{ |
|
1132 |
final double[] mid = middle; |
|
1133 |
mid[0] = x0; mid[1] = y0; |
|
1134 |
mid[2] = x1; mid[3] = y1; |
|
1135 |
mid[4] = x2; mid[5] = y2; |
|
1136 |
||
1137 |
final double[] subTs = subdivTs; |
|
1138 |
final int nSplits = DHelpers.findSubdivPoints(curve, mid, subTs, 6, lw2); |
|
1139 |
||
1140 |
double prevt = 0.0d; |
|
1141 |
for (int i = 0, off = 0; i < nSplits; i++, off += 4) { |
|
1142 |
final double t = subTs[i]; |
|
1143 |
DHelpers.subdivideQuadAt((t - prevt) / (1.0d - prevt), |
|
1144 |
mid, off, mid, off, off + 4); |
|
1145 |
prevt = t; |
|
1146 |
} |
|
1147 |
||
1148 |
this.nbSplits = nSplits; |
|
1149 |
return this; |
|
1150 |
} |
|
1151 |
} |
|
1152 |
||
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1153 |
static final class PathTracer implements DPathConsumer2D { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1154 |
private final String prefix; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1155 |
private DPathConsumer2D out; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1156 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1157 |
PathTracer(String name) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1158 |
this.prefix = name + ": "; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1159 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1160 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1161 |
PathTracer init(DPathConsumer2D out) { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1162 |
this.out = out; |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1163 |
return this; // fluent API |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1164 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1165 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1166 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1167 |
public void moveTo(double x0, double y0) { |
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
1168 |
log("p.moveTo(" + x0 + ", " + y0 + ");"); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1169 |
out.moveTo(x0, y0); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1170 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1171 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1172 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1173 |
public void lineTo(double x1, double y1) { |
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
1174 |
log("p.lineTo(" + x1 + ", " + y1 + ");"); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1175 |
out.lineTo(x1, y1); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1176 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1177 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1178 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1179 |
public void curveTo(double x1, double y1, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1180 |
double x2, double y2, |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1181 |
double x3, double y3) |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1182 |
{ |
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
1183 |
log("p.curveTo(" + x1 + ", " + y1 + ", " + x2 + ", " + y2 + ", " + x3 + ", " + y3 + ");"); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1184 |
out.curveTo(x1, y1, x2, y2, x3, y3); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1185 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1186 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1187 |
@Override |
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
1188 |
public void quadTo(double x1, double y1, |
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
1189 |
double x2, double y2) { |
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
1190 |
log("p.quadTo(" + x1 + ", " + y1 + ", " + x2 + ", " + y2 + ");"); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1191 |
out.quadTo(x1, y1, x2, y2); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1192 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1193 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1194 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1195 |
public void closePath() { |
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
1196 |
log("p.closePath();"); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1197 |
out.closePath(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1198 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1199 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1200 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1201 |
public void pathDone() { |
57929
13178f7e75d5
8228711: Path rendered incorrectly when it goes outside the clipping region
lbourges
parents:
51933
diff
changeset
|
1202 |
log("p.pathDone();"); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1203 |
out.pathDone(); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1204 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1205 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1206 |
private void log(final String message) { |
49496 | 1207 |
MarlinUtils.logInfo(prefix + message); |
48284
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1208 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1209 |
|
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1210 |
@Override |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1211 |
public long getNativeConsumer() { |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1212 |
throw new InternalError("Not using a native peer"); |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1213 |
} |
fd7fbc929001
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
47216
diff
changeset
|
1214 |
} |
47126 | 1215 |
} |