|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package sun.java2d.marlin; |
|
|
|
import java.awt.BasicStroke; |
|
import java.awt.Shape; |
|
import java.awt.geom.AffineTransform; |
|
import java.awt.geom.Path2D; |
|
import java.awt.geom.PathIterator; |
|
import java.security.AccessController; |
|
import static sun.java2d.marlin.MarlinUtils.logInfo; |
|
import sun.awt.geom.PathConsumer2D; |
|
import sun.java2d.ReentrantContextProvider; |
|
import sun.java2d.ReentrantContextProviderCLQ; |
|
import sun.java2d.ReentrantContextProviderTL; |
|
import sun.java2d.pipe.AATileGenerator; |
|
import sun.java2d.pipe.Region; |
|
import sun.java2d.pipe.RenderingEngine; |
|
import sun.security.action.GetPropertyAction; |
|
|
|
|
|
|
|
*/ |
|
public class MarlinRenderingEngine extends RenderingEngine |
|
implements MarlinConst |
|
{ |
|
private static enum NormMode {ON_WITH_AA, ON_NO_AA, OFF} |
|
|
|
private static final float MIN_PEN_SIZE = 1f / NORM_SUBPIXELS; |
|
|
|
|
|
|
|
*/ |
|
public MarlinRenderingEngine() { |
|
super(); |
|
logSettings(MarlinRenderingEngine.class.getName()); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
public Shape createStrokedShape(Shape src, |
|
float width, |
|
int caps, |
|
int join, |
|
float miterlimit, |
|
float dashes[], |
|
float dashphase) |
|
{ |
|
final RendererContext rdrCtx = getRendererContext(); |
|
try { |
|
|
|
final Path2D.Float p2d = |
|
(rdrCtx.p2d == null) ? |
|
(rdrCtx.p2d = new Path2D.Float(Path2D.WIND_NON_ZERO, |
|
INITIAL_MEDIUM_ARRAY)) |
|
: rdrCtx.p2d; |
|
|
|
p2d.reset(); |
|
|
|
strokeTo(rdrCtx, |
|
src, |
|
null, |
|
width, |
|
NormMode.OFF, |
|
caps, |
|
join, |
|
miterlimit, |
|
dashes, |
|
dashphase, |
|
rdrCtx.transformerPC2D.wrapPath2d(p2d) |
|
); |
|
|
|
|
|
return new Path2D.Float(p2d); |
|
|
|
} finally { |
|
|
|
returnRendererContext(rdrCtx); |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
public void strokeTo(Shape src, |
|
AffineTransform at, |
|
BasicStroke bs, |
|
boolean thin, |
|
boolean normalize, |
|
boolean antialias, |
|
final PathConsumer2D consumer) |
|
{ |
|
final NormMode norm = (normalize) ? |
|
((antialias) ? NormMode.ON_WITH_AA : NormMode.ON_NO_AA) |
|
: NormMode.OFF; |
|
|
|
final RendererContext rdrCtx = getRendererContext(); |
|
try { |
|
strokeTo(rdrCtx, src, at, bs, thin, norm, antialias, consumer); |
|
} finally { |
|
|
|
returnRendererContext(rdrCtx); |
|
} |
|
} |
|
|
|
final void strokeTo(final RendererContext rdrCtx, |
|
Shape src, |
|
AffineTransform at, |
|
BasicStroke bs, |
|
boolean thin, |
|
NormMode normalize, |
|
boolean antialias, |
|
PathConsumer2D pc2d) |
|
{ |
|
float lw; |
|
if (thin) { |
|
if (antialias) { |
|
lw = userSpaceLineWidth(at, MIN_PEN_SIZE); |
|
} else { |
|
lw = userSpaceLineWidth(at, 1.0f); |
|
} |
|
} else { |
|
lw = bs.getLineWidth(); |
|
} |
|
strokeTo(rdrCtx, |
|
src, |
|
at, |
|
lw, |
|
normalize, |
|
bs.getEndCap(), |
|
bs.getLineJoin(), |
|
bs.getMiterLimit(), |
|
bs.getDashArray(), |
|
bs.getDashPhase(), |
|
pc2d); |
|
} |
|
|
|
private final float userSpaceLineWidth(AffineTransform at, float lw) { |
|
|
|
float widthScale; |
|
|
|
if (at == null) { |
|
widthScale = 1.0f; |
|
} else if ((at.getType() & (AffineTransform.TYPE_GENERAL_TRANSFORM | |
|
AffineTransform.TYPE_GENERAL_SCALE)) != 0) { |
|
widthScale = (float)Math.sqrt(at.getDeterminant()); |
|
} else { |
|
// First calculate the "maximum scale" of this transform. |
|
double A = at.getScaleX(); |
|
double C = at.getShearX(); |
|
double B = at.getShearY(); |
|
double D = at.getScaleY(); |
|
|
|
/* |
|
* Given a 2 x 2 affine matrix [ A B ] such that |
|
* [ C D ] |
|
* v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to |
|
* find the maximum magnitude (norm) of the vector v' |
|
* with the constraint (x^2 + y^2 = 1). |
|
* The equation to maximize is |
|
* |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2) |
|
* or |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2). |
|
* Since sqrt is monotonic we can maximize |v'|^2 |
|
* instead and plug in the substitution y = sqrt(1 - x^2). |
|
* Trigonometric equalities can then be used to get |
|
* rid of most of the sqrt terms. |
|
*/ |
|
|
|
double EA = A*A + B*B; |
|
double EB = 2.0*(A*C + B*D); |
|
double EC = C*C + D*D; |
|
|
|
/* |
|
* There is a lot of calculus omitted here. |
|
* |
|
* Conceptually, in the interests of understanding the |
|
* terms that the calculus produced we can consider |
|
* that EA and EC end up providing the lengths along |
|
* the major axes and the hypot term ends up being an |
|
* adjustment for the additional length along the off-axis |
|
* angle of rotated or sheared ellipses as well as an |
|
* adjustment for the fact that the equation below |
|
* averages the two major axis lengths. (Notice that |
|
* the hypot term contains a part which resolves to the |
|
* difference of these two axis lengths in the absence |
|
* of rotation.) |
|
* |
|
* In the calculus, the ratio of the EB and (EA-EC) terms |
|
* ends up being the tangent of 2*theta where theta is |
|
* the angle that the long axis of the ellipse makes |
|
* with the horizontal axis. Thus, this equation is |
|
* calculating the length of the hypotenuse of a triangle |
|
* along that axis. |
|
*/ |
|
|
|
double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC)); |
|
|
|
double widthsquared = ((EA + EC + hypot)/2.0); |
|
|
|
widthScale = (float)Math.sqrt(widthsquared); |
|
} |
|
|
|
return (lw / widthScale); |
|
} |
|
|
|
final void strokeTo(final RendererContext rdrCtx, |
|
Shape src, |
|
AffineTransform at, |
|
float width, |
|
NormMode normalize, |
|
int caps, |
|
int join, |
|
float miterlimit, |
|
float dashes[], |
|
float dashphase, |
|
PathConsumer2D pc2d) |
|
{ |
|
// We use strokerat and outat so that in Stroker and Dasher we can work only |
|
// with the pre-transformation coordinates. This will repeat a lot of |
|
// computations done in the path iterator, but the alternative is to |
|
// work with transformed paths and compute untransformed coordinates |
|
// as needed. This would be faster but I do not think the complexity |
|
// of working with both untransformed and transformed coordinates in |
|
// the same code is worth it. |
|
// However, if a path's width is constant after a transformation, |
|
// we can skip all this untransforming. |
|
|
|
// If normalization is off we save some transformations by not |
|
// transforming the input to pisces. Instead, we apply the |
|
// transformation after the path processing has been done. |
|
// We can't do this if normalization is on, because it isn't a good |
|
|
|
AffineTransform strokerat = null; |
|
AffineTransform outat = null; |
|
|
|
PathIterator pi; |
|
int dashLen = -1; |
|
boolean recycleDashes = false; |
|
|
|
if (at != null && !at.isIdentity()) { |
|
final double a = at.getScaleX(); |
|
final double b = at.getShearX(); |
|
final double c = at.getShearY(); |
|
final double d = at.getScaleY(); |
|
final double det = a * d - c * b; |
|
|
|
if (Math.abs(det) <= (2f * Float.MIN_VALUE)) { |
|
// this rendering engine takes one dimensional curves and turns |
|
// them into 2D shapes by giving them width. |
|
// However, if everything is to be passed through a singular |
|
// transformation, these 2D shapes will be squashed down to 1D |
|
// again so, nothing can be drawn. |
|
|
|
// Every path needs an initial moveTo and a pathDone. If these |
|
// are not there this causes a SIGSEGV in libawt.so (at the time |
|
// of writing of this comment (September 16, 2010)). Actually, |
|
// I am not sure if the moveTo is necessary to avoid the SIGSEGV |
|
|
|
pc2d.moveTo(0f, 0f); |
|
pc2d.pathDone(); |
|
return; |
|
} |
|
|
|
// If the transform is a constant multiple of an orthogonal transformation |
|
// then every length is just multiplied by a constant, so we just |
|
// need to transform input paths to stroker and tell stroker |
|
// the scaled width. This condition is satisfied if |
|
// a*b == -c*d && a*a+c*c == b*b+d*d. In the actual check below, we |
|
|
|
if (nearZero(a*b + c*d) && nearZero(a*a + c*c - (b*b + d*d))) { |
|
final float scale = (float) Math.sqrt(a*a + c*c); |
|
if (dashes != null) { |
|
recycleDashes = true; |
|
dashLen = dashes.length; |
|
final float[] newDashes; |
|
if (dashLen <= INITIAL_ARRAY) { |
|
newDashes = rdrCtx.dasher.dashes_initial; |
|
} else { |
|
if (doStats) { |
|
RendererContext.stats.stat_array_dasher_dasher |
|
.add(dashLen); |
|
} |
|
newDashes = rdrCtx.getDirtyFloatArray(dashLen); |
|
} |
|
System.arraycopy(dashes, 0, newDashes, 0, dashLen); |
|
dashes = newDashes; |
|
for (int i = 0; i < dashLen; i++) { |
|
dashes[i] = scale * dashes[i]; |
|
} |
|
dashphase = scale * dashphase; |
|
} |
|
width = scale * width; |
|
pi = getNormalizingPathIterator(rdrCtx, normalize, |
|
src.getPathIterator(at)); |
|
|
|
// by now strokerat == null && outat == null. Input paths to |
|
// stroker (and maybe dasher) will have the full transform at |
|
// applied to them and nothing will happen to the output paths. |
|
} else { |
|
if (normalize != NormMode.OFF) { |
|
strokerat = at; |
|
pi = getNormalizingPathIterator(rdrCtx, normalize, |
|
src.getPathIterator(at)); |
|
|
|
// by now strokerat == at && outat == null. Input paths to |
|
// stroker (and maybe dasher) will have the full transform at |
|
// applied to them, then they will be normalized, and then |
|
// the inverse of *only the non translation part of at* will |
|
// be applied to the normalized paths. This won't cause problems |
|
// in stroker, because, suppose at = T*A, where T is just the |
|
// translation part of at, and A is the rest. T*A has already |
|
// been applied to Stroker/Dasher's input. Then Ainv will be |
|
// applied. Ainv*T*A is not equal to T, but it is a translation, |
|
// which means that none of stroker's assumptions about its |
|
// input will be violated. After all this, A will be applied |
|
// to stroker's output. |
|
} else { |
|
outat = at; |
|
pi = src.getPathIterator(null); |
|
// outat == at && strokerat == null. This is because if no |
|
// normalization is done, we can just apply all our |
|
// transformations to stroker's output. |
|
} |
|
} |
|
} else { |
|
// either at is null or it's the identity. In either case |
|
|
|
pi = getNormalizingPathIterator(rdrCtx, normalize, |
|
src.getPathIterator(null)); |
|
} |
|
|
|
if (useSimplifier) { |
|
// Use simplifier after stroker before Renderer |
|
|
|
pc2d = rdrCtx.simplifier.init(pc2d); |
|
} |
|
|
|
// by now, at least one of outat and strokerat will be null. Unless at is not |
|
// a constant multiple of an orthogonal transformation, they will both be |
|
// null. In other cases, outat == at if normalization is off, and if |
|
|
|
final TransformingPathConsumer2D transformerPC2D = rdrCtx.transformerPC2D; |
|
pc2d = transformerPC2D.transformConsumer(pc2d, outat); |
|
pc2d = transformerPC2D.deltaTransformConsumer(pc2d, strokerat); |
|
|
|
pc2d = rdrCtx.stroker.init(pc2d, width, caps, join, miterlimit); |
|
|
|
if (dashes != null) { |
|
if (!recycleDashes) { |
|
dashLen = dashes.length; |
|
} |
|
pc2d = rdrCtx.dasher.init(pc2d, dashes, dashLen, dashphase, |
|
recycleDashes); |
|
} |
|
pc2d = transformerPC2D.inverseDeltaTransformConsumer(pc2d, strokerat); |
|
pathTo(rdrCtx, pi, pc2d); |
|
|
|
/* |
|
* Pipeline seems to be: |
|
* shape.getPathIterator |
|
* -> NormalizingPathIterator |
|
* -> inverseDeltaTransformConsumer |
|
* -> Dasher |
|
* -> Stroker |
|
* -> deltaTransformConsumer OR transformConsumer |
|
* |
|
* -> CollinearSimplifier to remove redundant segments |
|
* |
|
* -> pc2d = Renderer (bounding box) |
|
*/ |
|
} |
|
|
|
private static boolean nearZero(final double num) { |
|
return Math.abs(num) < 2.0 * Math.ulp(num); |
|
} |
|
|
|
PathIterator getNormalizingPathIterator(final RendererContext rdrCtx, |
|
final NormMode mode, |
|
final PathIterator src) |
|
{ |
|
switch (mode) { |
|
case ON_WITH_AA: |
|
|
|
return rdrCtx.nPCPathIterator.init(src); |
|
case ON_NO_AA: |
|
|
|
return rdrCtx.nPQPathIterator.init(src); |
|
case OFF: |
|
|
|
return src; |
|
default: |
|
throw new InternalError("Unrecognized normalization mode"); |
|
} |
|
} |
|
|
|
abstract static class NormalizingPathIterator implements PathIterator { |
|
|
|
private PathIterator src; |
|
|
|
|
|
private float curx_adjust, cury_adjust; |
|
|
|
private float movx_adjust, movy_adjust; |
|
|
|
private final float[] tmp; |
|
|
|
NormalizingPathIterator(final float[] tmp) { |
|
this.tmp = tmp; |
|
} |
|
|
|
final NormalizingPathIterator init(final PathIterator src) { |
|
this.src = src; |
|
return this; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
final void dispose() { |
|
|
|
this.src = null; |
|
} |
|
|
|
@Override |
|
public final int currentSegment(final float[] coords) { |
|
if (doMonitors) { |
|
RendererContext.stats.mon_npi_currentSegment.start(); |
|
} |
|
int lastCoord; |
|
final int type = src.currentSegment(coords); |
|
|
|
switch(type) { |
|
case PathIterator.SEG_MOVETO: |
|
case PathIterator.SEG_LINETO: |
|
lastCoord = 0; |
|
break; |
|
case PathIterator.SEG_QUADTO: |
|
lastCoord = 2; |
|
break; |
|
case PathIterator.SEG_CUBICTO: |
|
lastCoord = 4; |
|
break; |
|
case PathIterator.SEG_CLOSE: |
|
|
|
curx_adjust = movx_adjust; |
|
cury_adjust = movy_adjust; |
|
|
|
if (doMonitors) { |
|
RendererContext.stats.mon_npi_currentSegment.stop(); |
|
} |
|
return type; |
|
default: |
|
throw new InternalError("Unrecognized curve type"); |
|
} |
|
|
|
// TODO: handle NaN, Inf and overflow |
|
|
|
|
|
float coord, x_adjust, y_adjust; |
|
|
|
coord = coords[lastCoord]; |
|
x_adjust = normCoord(coord); |
|
coords[lastCoord] = x_adjust; |
|
x_adjust -= coord; |
|
|
|
coord = coords[lastCoord + 1]; |
|
y_adjust = normCoord(coord); |
|
coords[lastCoord + 1] = y_adjust; |
|
y_adjust -= coord; |
|
|
|
|
|
switch(type) { |
|
case PathIterator.SEG_MOVETO: |
|
movx_adjust = x_adjust; |
|
movy_adjust = y_adjust; |
|
break; |
|
case PathIterator.SEG_LINETO: |
|
break; |
|
case PathIterator.SEG_QUADTO: |
|
coords[0] += (curx_adjust + x_adjust) / 2f; |
|
coords[1] += (cury_adjust + y_adjust) / 2f; |
|
break; |
|
case PathIterator.SEG_CUBICTO: |
|
coords[0] += curx_adjust; |
|
coords[1] += cury_adjust; |
|
coords[2] += x_adjust; |
|
coords[3] += y_adjust; |
|
break; |
|
case PathIterator.SEG_CLOSE: |
|
|
|
default: |
|
} |
|
curx_adjust = x_adjust; |
|
cury_adjust = y_adjust; |
|
|
|
if (doMonitors) { |
|
RendererContext.stats.mon_npi_currentSegment.stop(); |
|
} |
|
return type; |
|
} |
|
|
|
abstract float normCoord(final float coord); |
|
|
|
@Override |
|
public final int currentSegment(final double[] coords) { |
|
final float[] _tmp = tmp; |
|
int type = this.currentSegment(_tmp); |
|
for (int i = 0; i < 6; i++) { |
|
coords[i] = _tmp[i]; |
|
} |
|
return type; |
|
} |
|
|
|
@Override |
|
public final int getWindingRule() { |
|
return src.getWindingRule(); |
|
} |
|
|
|
@Override |
|
public final boolean isDone() { |
|
if (src.isDone()) { |
|
|
|
dispose(); |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
@Override |
|
public final void next() { |
|
src.next(); |
|
} |
|
|
|
static final class NearestPixelCenter |
|
extends NormalizingPathIterator |
|
{ |
|
NearestPixelCenter(final float[] tmp) { |
|
super(tmp); |
|
} |
|
|
|
@Override |
|
float normCoord(final float coord) { |
|
|
|
return FloatMath.floor_f(coord) + 0.5f; |
|
} |
|
} |
|
|
|
static final class NearestPixelQuarter |
|
extends NormalizingPathIterator |
|
{ |
|
NearestPixelQuarter(final float[] tmp) { |
|
super(tmp); |
|
} |
|
|
|
@Override |
|
float normCoord(final float coord) { |
|
|
|
return FloatMath.floor_f(coord + 0.25f) + 0.25f; |
|
} |
|
} |
|
} |
|
|
|
private static void pathTo(final RendererContext rdrCtx, final PathIterator pi, |
|
final PathConsumer2D pc2d) |
|
{ |
|
|
|
rdrCtx.dirty = true; |
|
|
|
final float[] coords = rdrCtx.float6; |
|
|
|
pathToLoop(coords, pi, pc2d); |
|
|
|
|
|
rdrCtx.dirty = false; |
|
} |
|
|
|
private static void pathToLoop(final float[] coords, final PathIterator pi, |
|
final PathConsumer2D pc2d) |
|
{ |
|
for (; !pi.isDone(); pi.next()) { |
|
switch (pi.currentSegment(coords)) { |
|
case PathIterator.SEG_MOVETO: |
|
pc2d.moveTo(coords[0], coords[1]); |
|
continue; |
|
case PathIterator.SEG_LINETO: |
|
pc2d.lineTo(coords[0], coords[1]); |
|
continue; |
|
case PathIterator.SEG_QUADTO: |
|
pc2d.quadTo(coords[0], coords[1], |
|
coords[2], coords[3]); |
|
continue; |
|
case PathIterator.SEG_CUBICTO: |
|
pc2d.curveTo(coords[0], coords[1], |
|
coords[2], coords[3], |
|
coords[4], coords[5]); |
|
continue; |
|
case PathIterator.SEG_CLOSE: |
|
pc2d.closePath(); |
|
continue; |
|
default: |
|
} |
|
} |
|
pc2d.pathDone(); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
public AATileGenerator getAATileGenerator(Shape s, |
|
AffineTransform at, |
|
Region clip, |
|
BasicStroke bs, |
|
boolean thin, |
|
boolean normalize, |
|
int bbox[]) |
|
{ |
|
MarlinTileGenerator ptg = null; |
|
Renderer r = null; |
|
|
|
final RendererContext rdrCtx = getRendererContext(); |
|
try { |
|
|
|
final AffineTransform _at = (at != null && !at.isIdentity()) ? at |
|
: null; |
|
|
|
final NormMode norm = (normalize) ? NormMode.ON_WITH_AA : NormMode.OFF; |
|
|
|
if (bs == null) { |
|
|
|
final PathIterator pi = getNormalizingPathIterator(rdrCtx, norm, |
|
s.getPathIterator(_at)); |
|
|
|
r = rdrCtx.renderer.init(clip.getLoX(), clip.getLoY(), |
|
clip.getWidth(), clip.getHeight(), |
|
pi.getWindingRule()); |
|
|
|
|
|
pathTo(rdrCtx, pi, r); |
|
} else { |
|
|
|
r = rdrCtx.renderer.init(clip.getLoX(), clip.getLoY(), |
|
clip.getWidth(), clip.getHeight(), |
|
PathIterator.WIND_NON_ZERO); |
|
|
|
strokeTo(rdrCtx, s, _at, bs, thin, norm, true, r); |
|
} |
|
if (r.endRendering()) { |
|
ptg = rdrCtx.ptg.init(); |
|
ptg.getBbox(bbox); |
|
// note: do not returnRendererContext(rdrCtx) |
|
|
|
r = null; |
|
} |
|
} finally { |
|
if (r != null) { |
|
|
|
r.dispose(); |
|
|
|
MarlinRenderingEngine.returnRendererContext(rdrCtx); |
|
} |
|
} |
|
|
|
|
|
return ptg; |
|
} |
|
|
|
@Override |
|
public final AATileGenerator getAATileGenerator(double x, double y, |
|
double dx1, double dy1, |
|
double dx2, double dy2, |
|
double lw1, double lw2, |
|
Region clip, |
|
int bbox[]) |
|
{ |
|
|
|
double ldx1, ldy1, ldx2, ldy2; |
|
boolean innerpgram = (lw1 > 0.0 && lw2 > 0.0); |
|
|
|
if (innerpgram) { |
|
ldx1 = dx1 * lw1; |
|
ldy1 = dy1 * lw1; |
|
ldx2 = dx2 * lw2; |
|
ldy2 = dy2 * lw2; |
|
x -= (ldx1 + ldx2) / 2.0; |
|
y -= (ldy1 + ldy2) / 2.0; |
|
dx1 += ldx1; |
|
dy1 += ldy1; |
|
dx2 += ldx2; |
|
dy2 += ldy2; |
|
if (lw1 > 1.0 && lw2 > 1.0) { |
|
|
|
innerpgram = false; |
|
} |
|
} else { |
|
ldx1 = ldy1 = ldx2 = ldy2 = 0.0; |
|
} |
|
|
|
MarlinTileGenerator ptg = null; |
|
Renderer r = null; |
|
|
|
final RendererContext rdrCtx = getRendererContext(); |
|
try { |
|
r = rdrCtx.renderer.init(clip.getLoX(), clip.getLoY(), |
|
clip.getWidth(), clip.getHeight(), |
|
Renderer.WIND_EVEN_ODD); |
|
|
|
r.moveTo((float) x, (float) y); |
|
r.lineTo((float) (x+dx1), (float) (y+dy1)); |
|
r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2)); |
|
r.lineTo((float) (x+dx2), (float) (y+dy2)); |
|
r.closePath(); |
|
|
|
if (innerpgram) { |
|
x += ldx1 + ldx2; |
|
y += ldy1 + ldy2; |
|
dx1 -= 2.0 * ldx1; |
|
dy1 -= 2.0 * ldy1; |
|
dx2 -= 2.0 * ldx2; |
|
dy2 -= 2.0 * ldy2; |
|
r.moveTo((float) x, (float) y); |
|
r.lineTo((float) (x+dx1), (float) (y+dy1)); |
|
r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2)); |
|
r.lineTo((float) (x+dx2), (float) (y+dy2)); |
|
r.closePath(); |
|
} |
|
r.pathDone(); |
|
|
|
if (r.endRendering()) { |
|
ptg = rdrCtx.ptg.init(); |
|
ptg.getBbox(bbox); |
|
// note: do not returnRendererContext(rdrCtx) |
|
|
|
r = null; |
|
} |
|
} finally { |
|
if (r != null) { |
|
|
|
r.dispose(); |
|
|
|
MarlinRenderingEngine.returnRendererContext(rdrCtx); |
|
} |
|
} |
|
|
|
|
|
return ptg; |
|
} |
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
@Override |
|
public float getMinimumAAPenSize() { |
|
return MIN_PEN_SIZE; |
|
} |
|
|
|
static { |
|
if (PathIterator.WIND_NON_ZERO != Renderer.WIND_NON_ZERO || |
|
PathIterator.WIND_EVEN_ODD != Renderer.WIND_EVEN_ODD || |
|
BasicStroke.JOIN_MITER != Stroker.JOIN_MITER || |
|
BasicStroke.JOIN_ROUND != Stroker.JOIN_ROUND || |
|
BasicStroke.JOIN_BEVEL != Stroker.JOIN_BEVEL || |
|
BasicStroke.CAP_BUTT != Stroker.CAP_BUTT || |
|
BasicStroke.CAP_ROUND != Stroker.CAP_ROUND || |
|
BasicStroke.CAP_SQUARE != Stroker.CAP_SQUARE) |
|
{ |
|
throw new InternalError("mismatched renderer constants"); |
|
} |
|
} |
|
|
|
// --- RendererContext handling --- |
|
|
|
private static final boolean useThreadLocal; |
|
|
|
|
|
static final int REF_TYPE; |
|
|
|
|
|
private static final ReentrantContextProvider<RendererContext> rdrCtxProvider; |
|
|
|
|
|
static { |
|
useThreadLocal = MarlinProperties.isUseThreadLocal(); |
|
|
|
|
|
final String refType = AccessController.doPrivileged( |
|
new GetPropertyAction("sun.java2d.renderer.useRef", |
|
"soft")); |
|
switch (refType) { |
|
default: |
|
case "soft": |
|
REF_TYPE = ReentrantContextProvider.REF_SOFT; |
|
break; |
|
case "weak": |
|
REF_TYPE = ReentrantContextProvider.REF_WEAK; |
|
break; |
|
case "hard": |
|
REF_TYPE = ReentrantContextProvider.REF_HARD; |
|
break; |
|
} |
|
|
|
if (useThreadLocal) { |
|
rdrCtxProvider = new ReentrantContextProviderTL<RendererContext>(REF_TYPE) |
|
{ |
|
@Override |
|
protected RendererContext newContext() { |
|
return RendererContext.createContext(); |
|
} |
|
}; |
|
} else { |
|
rdrCtxProvider = new ReentrantContextProviderCLQ<RendererContext>(REF_TYPE) |
|
{ |
|
@Override |
|
protected RendererContext newContext() { |
|
return RendererContext.createContext(); |
|
} |
|
}; |
|
} |
|
} |
|
|
|
private static boolean settingsLogged = !enableLogs; |
|
|
|
private static void logSettings(final String reClass) { |
|
|
|
if (settingsLogged) { |
|
return; |
|
} |
|
settingsLogged = true; |
|
|
|
String refType; |
|
switch (REF_TYPE) { |
|
default: |
|
case ReentrantContextProvider.REF_HARD: |
|
refType = "hard"; |
|
break; |
|
case ReentrantContextProvider.REF_SOFT: |
|
refType = "soft"; |
|
break; |
|
case ReentrantContextProvider.REF_WEAK: |
|
refType = "weak"; |
|
break; |
|
} |
|
|
|
logInfo("==========================================================" |
|
+ "====================="); |
|
|
|
logInfo("Marlin software rasterizer = ENABLED"); |
|
logInfo("Version = [" |
|
+ Version.getVersion() + "]"); |
|
logInfo("sun.java2d.renderer = " |
|
+ reClass); |
|
logInfo("sun.java2d.renderer.useThreadLocal = " |
|
+ useThreadLocal); |
|
logInfo("sun.java2d.renderer.useRef = " |
|
+ refType); |
|
|
|
logInfo("sun.java2d.renderer.pixelsize = " |
|
+ MarlinConst.INITIAL_PIXEL_DIM); |
|
logInfo("sun.java2d.renderer.subPixel_log2_X = " |
|
+ MarlinConst.SUBPIXEL_LG_POSITIONS_X); |
|
logInfo("sun.java2d.renderer.subPixel_log2_Y = " |
|
+ MarlinConst.SUBPIXEL_LG_POSITIONS_Y); |
|
logInfo("sun.java2d.renderer.tileSize_log2 = " |
|
+ MarlinConst.TILE_SIZE_LG); |
|
|
|
logInfo("sun.java2d.renderer.blockSize_log2 = " |
|
+ MarlinConst.BLOCK_SIZE_LG); |
|
|
|
logInfo("sun.java2d.renderer.blockSize_log2 = " |
|
+ MarlinConst.BLOCK_SIZE_LG); |
|
|
|
// RLE / blockFlags settings |
|
|
|
logInfo("sun.java2d.renderer.forceRLE = " |
|
+ MarlinProperties.isForceRLE()); |
|
logInfo("sun.java2d.renderer.forceNoRLE = " |
|
+ MarlinProperties.isForceNoRLE()); |
|
logInfo("sun.java2d.renderer.useTileFlags = " |
|
+ MarlinProperties.isUseTileFlags()); |
|
logInfo("sun.java2d.renderer.useTileFlags.useHeuristics = " |
|
+ MarlinProperties.isUseTileFlagsWithHeuristics()); |
|
logInfo("sun.java2d.renderer.rleMinWidth = " |
|
+ MarlinCache.RLE_MIN_WIDTH); |
|
|
|
|
|
logInfo("sun.java2d.renderer.useSimplifier = " |
|
+ MarlinConst.useSimplifier); |
|
|
|
|
|
logInfo("sun.java2d.renderer.doStats = " |
|
+ MarlinConst.doStats); |
|
logInfo("sun.java2d.renderer.doMonitors = " |
|
+ MarlinConst.doMonitors); |
|
logInfo("sun.java2d.renderer.doChecks = " |
|
+ MarlinConst.doChecks); |
|
|
|
|
|
logInfo("sun.java2d.renderer.useLogger = " |
|
+ MarlinConst.useLogger); |
|
logInfo("sun.java2d.renderer.logCreateContext = " |
|
+ MarlinConst.logCreateContext); |
|
logInfo("sun.java2d.renderer.logUnsafeMalloc = " |
|
+ MarlinConst.logUnsafeMalloc); |
|
|
|
|
|
logInfo("Renderer settings:"); |
|
logInfo("CUB_COUNT_LG = " + Renderer.CUB_COUNT_LG); |
|
logInfo("CUB_DEC_BND = " + Renderer.CUB_DEC_BND); |
|
logInfo("CUB_INC_BND = " + Renderer.CUB_INC_BND); |
|
logInfo("QUAD_DEC_BND = " + Renderer.QUAD_DEC_BND); |
|
|
|
logInfo("==========================================================" |
|
+ "====================="); |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
@SuppressWarnings({"unchecked"}) |
|
static RendererContext getRendererContext() { |
|
final RendererContext rdrCtx = rdrCtxProvider.acquire(); |
|
if (doMonitors) { |
|
RendererContext.stats.mon_pre_getAATileGenerator.start(); |
|
} |
|
return rdrCtx; |
|
} |
|
|
|
|
|
|
|
|
|
*/ |
|
static void returnRendererContext(final RendererContext rdrCtx) { |
|
rdrCtx.dispose(); |
|
|
|
if (doMonitors) { |
|
RendererContext.stats.mon_pre_getAATileGenerator.stop(); |
|
} |
|
rdrCtxProvider.release(rdrCtx); |
|
} |
|
} |