author | lbourges |
Wed, 15 Jun 2016 21:43:39 +0200 | |
changeset 39519 | 21bfc4452441 |
parent 36902 | bb30d89aa00e |
permissions | -rw-r--r-- |
2 | 1 |
/* |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
2 |
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package sun.java2d.pipe; |
|
26 |
||
27 |
import java.awt.BasicStroke; |
|
28 |
import java.awt.Rectangle; |
|
29 |
import java.awt.Shape; |
|
7745 | 30 |
import java.awt.geom.Rectangle2D; |
2 | 31 |
import sun.awt.SunHints; |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
32 |
import sun.java2d.ReentrantContext; |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
33 |
import sun.java2d.ReentrantContextProvider; |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
34 |
import sun.java2d.ReentrantContextProviderTL; |
2 | 35 |
import sun.java2d.SunGraphics2D; |
36 |
||
37 |
/** |
|
38 |
* This class is used to convert raw geometry into 8-bit alpha tiles |
|
39 |
* using an AATileGenerator for application by the next stage of |
|
40 |
* the pipeline. |
|
41 |
* This class sets up the Generator and computes the alpha tiles |
|
42 |
* and then passes them on to a CompositePipe object for painting. |
|
43 |
*/ |
|
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
44 |
public final class AAShapePipe |
7745 | 45 |
implements ShapeDrawPipe, ParallelogramPipe |
46 |
{ |
|
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36902
diff
changeset
|
47 |
static final RenderingEngine RDR_ENGINE = RenderingEngine.getInstance(); |
2 | 48 |
|
34419 | 49 |
// Per-thread TileState (~1K very small so do not use any Weak Reference) |
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36902
diff
changeset
|
50 |
private static final ReentrantContextProvider<TileState> TILE_STATE_PROVIDER = |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
51 |
new ReentrantContextProviderTL<TileState>( |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
52 |
ReentrantContextProvider.REF_HARD) |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
53 |
{ |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
54 |
@Override |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
55 |
protected TileState newContext() { |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
56 |
return new TileState(); |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
57 |
} |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
58 |
}; |
34419 | 59 |
|
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
60 |
final CompositePipe outpipe; |
2 | 61 |
|
62 |
public AAShapePipe(CompositePipe pipe) { |
|
63 |
outpipe = pipe; |
|
64 |
} |
|
65 |
||
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
66 |
@Override |
2 | 67 |
public void draw(SunGraphics2D sg, Shape s) { |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
68 |
final BasicStroke bs; |
2 | 69 |
|
70 |
if (sg.stroke instanceof BasicStroke) { |
|
71 |
bs = (BasicStroke) sg.stroke; |
|
72 |
} else { |
|
73 |
s = sg.stroke.createStrokedShape(s); |
|
74 |
bs = null; |
|
75 |
} |
|
76 |
||
77 |
renderPath(sg, s, bs); |
|
78 |
} |
|
79 |
||
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
80 |
@Override |
2 | 81 |
public void fill(SunGraphics2D sg, Shape s) { |
82 |
renderPath(sg, s, null); |
|
83 |
} |
|
84 |
||
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
85 |
@Override |
7745 | 86 |
public void fillParallelogram(SunGraphics2D sg, |
9653
6a1eff16874d
7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
9035
diff
changeset
|
87 |
double ux1, double uy1, |
6a1eff16874d
7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
9035
diff
changeset
|
88 |
double ux2, double uy2, |
7745 | 89 |
double x, double y, |
90 |
double dx1, double dy1, |
|
91 |
double dx2, double dy2) |
|
92 |
{ |
|
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36902
diff
changeset
|
93 |
final TileState ts = TILE_STATE_PROVIDER.acquire(); |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
94 |
try { |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
95 |
final int[] abox = ts.abox; |
34419 | 96 |
|
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
97 |
final AATileGenerator aatg = |
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36902
diff
changeset
|
98 |
RDR_ENGINE.getAATileGenerator(x, y, dx1, dy1, dx2, dy2, 0, 0, |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
99 |
sg.getCompClip(), abox); |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
100 |
if (aatg != null) { |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
101 |
renderTiles(sg, ts.computeBBox(ux1, uy1, ux2, uy2), |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
102 |
aatg, abox, ts); |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
103 |
} |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
104 |
} finally { |
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36902
diff
changeset
|
105 |
TILE_STATE_PROVIDER.release(ts); |
7745 | 106 |
} |
107 |
} |
|
108 |
||
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
109 |
@Override |
7745 | 110 |
public void drawParallelogram(SunGraphics2D sg, |
9653
6a1eff16874d
7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
9035
diff
changeset
|
111 |
double ux1, double uy1, |
6a1eff16874d
7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents:
9035
diff
changeset
|
112 |
double ux2, double uy2, |
7745 | 113 |
double x, double y, |
114 |
double dx1, double dy1, |
|
115 |
double dx2, double dy2, |
|
116 |
double lw1, double lw2) |
|
117 |
{ |
|
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36902
diff
changeset
|
118 |
final TileState ts = TILE_STATE_PROVIDER.acquire(); |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
119 |
try { |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
120 |
final int[] abox = ts.abox; |
34419 | 121 |
|
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
122 |
final AATileGenerator aatg = |
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36902
diff
changeset
|
123 |
RDR_ENGINE.getAATileGenerator(x, y, dx1, dy1, dx2, dy2, lw1, |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
124 |
lw2, sg.getCompClip(), abox); |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
125 |
if (aatg != null) { |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
126 |
// Note that bbox is of the original shape, not the wide path. |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
127 |
// This is appropriate for handing to Paint methods... |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
128 |
renderTiles(sg, ts.computeBBox(ux1, uy1, ux2, uy2), |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
129 |
aatg, abox, ts); |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
130 |
} |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
131 |
} finally { |
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36902
diff
changeset
|
132 |
TILE_STATE_PROVIDER.release(ts); |
7745 | 133 |
} |
2 | 134 |
} |
135 |
||
136 |
public void renderPath(SunGraphics2D sg, Shape s, BasicStroke bs) { |
|
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
137 |
final boolean adjust = (bs != null && |
2 | 138 |
sg.strokeHint != SunHints.INTVAL_STROKE_PURE); |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
139 |
final boolean thin = (sg.strokeState <= SunGraphics2D.STROKE_THINDASHED); |
2 | 140 |
|
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36902
diff
changeset
|
141 |
final TileState ts = TILE_STATE_PROVIDER.acquire(); |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
142 |
try { |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
143 |
final int[] abox = ts.abox; |
34419 | 144 |
|
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
145 |
final AATileGenerator aatg = |
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36902
diff
changeset
|
146 |
RDR_ENGINE.getAATileGenerator(s, sg.transform, sg.getCompClip(), |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
147 |
bs, thin, adjust, abox); |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
148 |
if (aatg != null) { |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
149 |
renderTiles(sg, s, aatg, abox, ts); |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
150 |
} |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
151 |
} finally { |
39519
21bfc4452441
8159093: Fix coding conventions in Marlin renderer
lbourges
parents:
36902
diff
changeset
|
152 |
TILE_STATE_PROVIDER.release(ts); |
2 | 153 |
} |
7745 | 154 |
} |
155 |
||
156 |
public void renderTiles(SunGraphics2D sg, Shape s, |
|
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
157 |
final AATileGenerator aatg, |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
158 |
final int[] abox, final TileState ts) |
7745 | 159 |
{ |
160 |
Object context = null; |
|
2 | 161 |
try { |
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
162 |
// reentrance: outpipe may also use AAShapePipe: |
2 | 163 |
context = outpipe.startSequence(sg, s, |
34419 | 164 |
ts.computeDevBox(abox), |
2 | 165 |
abox); |
166 |
||
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
167 |
// copy of int[] abox as local variables for performance: |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
168 |
final int x0 = abox[0]; |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
169 |
final int y0 = abox[1]; |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
170 |
final int x1 = abox[2]; |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
171 |
final int y1 = abox[3]; |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
172 |
|
34419 | 173 |
final int tw = aatg.getTileWidth(); |
174 |
final int th = aatg.getTileHeight(); |
|
2 | 175 |
|
34419 | 176 |
// get tile from thread local storage: |
177 |
final byte[] alpha = ts.getAlphaTile(tw * th); |
|
2 | 178 |
byte[] atile; |
179 |
||
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
180 |
for (int y = y0; y < y1; y += th) { |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
181 |
final int h = Math.min(th, y1 - y); |
34419 | 182 |
|
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
183 |
for (int x = x0; x < x1; x += tw) { |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
184 |
final int w = Math.min(tw, x1 - x); |
2 | 185 |
|
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
186 |
final int a = aatg.getTypicalAlpha(); |
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
187 |
|
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
188 |
if (a == 0x00 || !outpipe.needTile(context, x, y, w, h)) { |
2 | 189 |
aatg.nextTile(); |
190 |
outpipe.skipTile(context, x, y); |
|
191 |
continue; |
|
192 |
} |
|
193 |
if (a == 0xff) { |
|
194 |
atile = null; |
|
195 |
aatg.nextTile(); |
|
196 |
} else { |
|
197 |
atile = alpha; |
|
198 |
aatg.getAlpha(alpha, 0, tw); |
|
199 |
} |
|
200 |
||
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
201 |
outpipe.renderPathTile(context, atile, 0, tw, x, y, w, h); |
2 | 202 |
} |
203 |
} |
|
204 |
} finally { |
|
205 |
aatg.dispose(); |
|
206 |
if (context != null) { |
|
207 |
outpipe.endSequence(context); |
|
208 |
} |
|
209 |
} |
|
210 |
} |
|
34419 | 211 |
|
212 |
// Tile state used by AAShapePipe |
|
36458
25786a73a5fc
8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents:
34419
diff
changeset
|
213 |
static final class TileState extends ReentrantContext { |
34419 | 214 |
// cached tile (32 x 32 tile by default) |
215 |
private byte[] theTile = new byte[32 * 32]; |
|
216 |
// dirty aabox array |
|
217 |
final int[] abox = new int[4]; |
|
218 |
// dirty bbox rectangle |
|
219 |
private final Rectangle dev = new Rectangle(); |
|
220 |
// dirty bbox rectangle2D.Double |
|
221 |
private final Rectangle2D.Double bbox2D = new Rectangle2D.Double(); |
|
222 |
||
223 |
byte[] getAlphaTile(int len) { |
|
224 |
byte[] t = theTile; |
|
225 |
if (t.length < len) { |
|
226 |
// create a larger tile and may free current theTile (too small) |
|
227 |
theTile = t = new byte[len]; |
|
228 |
} |
|
229 |
return t; |
|
230 |
} |
|
231 |
||
232 |
Rectangle computeDevBox(final int[] abox) { |
|
233 |
final Rectangle box = this.dev; |
|
234 |
box.x = abox[0]; |
|
235 |
box.y = abox[1]; |
|
236 |
box.width = abox[2] - abox[0]; |
|
237 |
box.height = abox[3] - abox[1]; |
|
238 |
return box; |
|
239 |
} |
|
240 |
||
241 |
Rectangle2D computeBBox(double ux1, double uy1, |
|
242 |
double ux2, double uy2) |
|
243 |
{ |
|
244 |
if ((ux2 -= ux1) < 0.0) { |
|
245 |
ux1 += ux2; |
|
246 |
ux2 = -ux2; |
|
247 |
} |
|
248 |
if ((uy2 -= uy1) < 0.0) { |
|
249 |
uy1 += uy2; |
|
250 |
uy2 = -uy2; |
|
251 |
} |
|
252 |
final Rectangle2D.Double box = this.bbox2D; |
|
253 |
box.x = ux1; |
|
254 |
box.y = uy1; |
|
255 |
box.width = ux2; |
|
256 |
box.height = uy2; |
|
257 |
return box; |
|
258 |
} |
|
259 |
} |
|
2 | 260 |
} |