diff options
author | Sven Gothel <[email protected]> | 2014-04-02 19:25:16 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-04-02 19:25:16 +0200 |
commit | abc833631e0ab30a06c7aff47a39a551544fd735 (patch) | |
tree | 1d6e5a94d2149d7b2635de5b5eccb330bc41cd2c /src/jogl/classes/jogamp/graph | |
parent | e8a5a1cbb988670ca206ab1ac633e19a91bfa478 (diff) |
Bug 801: Reduce temp. object creation, i.e. GC load
Diffstat (limited to 'src/jogl/classes/jogamp/graph')
4 files changed, 77 insertions, 104 deletions
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index cd48cd8d6..5fb61387a 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -38,10 +38,8 @@ import jogamp.graph.geom.plane.AffineTransform; import com.jogamp.common.util.IntObjectHashMap; import com.jogamp.graph.curve.OutlineShape; -import com.jogamp.graph.curve.Region; import com.jogamp.graph.font.Font; import com.jogamp.graph.font.FontFactory; -import com.jogamp.graph.font.Font.Glyph; import com.jogamp.graph.geom.SVertex; import com.jogamp.graph.geom.Vertex; import com.jogamp.opengl.math.geom.AABBox; @@ -251,7 +249,7 @@ class TypecastFont implements Font { if (character == '\n') { width = 0; } else { - Glyph glyph = getGlyph(character); + final Glyph glyph = getGlyph(character); width += glyph.getAdvance(pixelSize, false); } } @@ -259,14 +257,14 @@ class TypecastFont implements Font { } @Override - public float getMetricHeight(CharSequence string, float pixelSize) { + public float getMetricHeight(CharSequence string, float pixelSize, final AABBox tmp) { int height = 0; for (int i=0; i<string.length(); i++) { final char character = string.charAt(i); if (character != ' ') { final Glyph glyph = getGlyph(character); - AABBox bbox = glyph.getBBox(pixelSize, tmpV3); + final AABBox bbox = glyph.getBBox(tmp, pixelSize, tmpV3); height = (int)Math.ceil(Math.max(bbox.getHeight(), height)); } } @@ -301,14 +299,14 @@ class TypecastFont implements Font { return new AABBox(0, 0, 0, totalWidth, totalHeight,0); } @Override - public AABBox getPointsBounds(final AffineTransform transform, CharSequence string, float pixelSize) { + public AABBox getPointsBounds(final AffineTransform transform, final CharSequence string, final float pixelSize, + final AffineTransform temp1, final AffineTransform temp2) { if (string == null) { return new AABBox(); } final int charCount = string.length(); final float lineHeight = getLineHeight(pixelSize); final float scale = getMetrics().getScale(pixelSize); - final AffineTransform t = null != transform ? new AffineTransform(transform) : new AffineTransform(); final AABBox tbox = new AABBox(); final AABBox res = new AABBox(); @@ -325,16 +323,16 @@ class TypecastFont implements Font { } else { // reset transform if( null != transform ) { - t.setTransform(transform); + temp1.setTransform(transform); } else { - t.setToIdentity(); + temp1.setToIdentity(); } - t.translate(advanceTotal, y); - t.scale(scale, scale); + temp1.translate(advanceTotal, y, temp2); + temp1.scale(scale, scale, temp2); tbox.reset(); final Font.Glyph glyph = getGlyph(character); - res.resize(t.transform(glyph.getBBox(), tbox)); + res.resize(temp1.transform(glyph.getBBox(), tbox)); final OutlineShape glyphShape = glyph.getShape(); if( null == glyphShape ) { diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java index b0e283278..2246b4a3c 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java @@ -27,8 +27,7 @@ */ package jogamp.graph.font.typecast; -import java.util.HashMap; - +import com.jogamp.common.util.IntIntHashMap; import com.jogamp.graph.curve.OutlineShape; import com.jogamp.graph.font.Font; import com.jogamp.opengl.math.geom.AABBox; @@ -38,42 +37,45 @@ public class TypecastGlyph implements Font.Glyph { { private final Font font; private final float advance; - HashMap<Float, Float> size2advance = new HashMap<Float, Float>(); + private final IntIntHashMap size2advanceI = new IntIntHashMap(); - public Advance(Font font, float advance) + public Advance(final Font font, final float advance) { this.font = font; this.advance = advance; + size2advanceI.setKeyNotFoundValue(0); } public void reset() { - size2advance.clear(); + size2advanceI.clear(); } - public float getScale(float pixelSize) + public float getScale(final float pixelSize) { return this.font.getMetrics().getScale(pixelSize); } - public void add(float advance, float size) + public void add(final float advance, final float size) { - size2advance.put(size, advance); + size2advanceI.put(Float.floatToIntBits(size), Float.floatToIntBits(advance)); } - public float get(float size, boolean useFrationalMetrics) + public float get(final float size, final boolean useFrationalMetrics) { - final Float fo = size2advance.get(size); - if(null == fo) { - float value = (this.advance * getScale(size)); - if (useFrationalMetrics == false) { - //value = (float)Math.ceil(value); - // value = (int)value; - value = (int) ( value + 0.5f ) ; // TODO: check - } - size2advance.put(size, value); - return value; + final int sI = Float.floatToIntBits(size); + final int aI = size2advanceI.get(sI); + if( 0 != aI ) { + return Float.intBitsToFloat(aI); + } + final float a; + if ( useFrationalMetrics ) { + a = this.advance * getScale(size); + } else { + // a = Math.ceil(this.advance * getScale(size)); + a = Math.round(this.advance * getScale(size)); // TODO: check whether ceil should be used instead? } - return fo.floatValue(); + size2advanceI.put(sI, Float.floatToIntBits(a)); + return a; } @Override @@ -81,7 +83,7 @@ public class TypecastGlyph implements Font.Glyph { { return "\nAdvance:"+ "\n advance: "+this.advance+ - "\n advances: \n"+size2advance; + "\n advances: \n"+size2advanceI; } } @@ -90,7 +92,7 @@ public class TypecastGlyph implements Font.Glyph { private final AABBox bbox; private final Advance advance; - public Metrics(Font font, AABBox bbox, float advance) + public Metrics(final Font font, final AABBox bbox, final float advance) { this.bbox = bbox; this.advance = new Advance(font, advance); @@ -100,7 +102,7 @@ public class TypecastGlyph implements Font.Glyph { advance.reset(); } - public float getScale(float pixelSize) + public float getScale(final float pixelSize) { return this.advance.getScale(pixelSize); } @@ -110,12 +112,12 @@ public class TypecastGlyph implements Font.Glyph { return this.bbox; } - public void addAdvance(float advance, float size) + public void addAdvance(final float advance, final float size) { this.advance.add(advance, size); } - public float getAdvance(float size, boolean useFrationalMetrics) + public float getAdvance(final float size, final boolean useFrationalMetrics) { return this.advance.get(size, useFrationalMetrics); } @@ -139,7 +141,7 @@ public class TypecastGlyph implements Font.Glyph { private final int advance; private final Metrics metrics; - protected TypecastGlyph(Font font, char symbol, short id, AABBox bbox, int advance, OutlineShape shape) { + protected TypecastGlyph(final Font font, final char symbol, final short id, final AABBox bbox, final int advance, final OutlineShape shape) { this.font = font; this.symbol = symbol; this.shape = shape; @@ -183,24 +185,21 @@ public class TypecastGlyph implements Font.Glyph { } @Override - public final float getScale(float pixelSize) { + public final float getScale(final float pixelSize) { return this.metrics.getScale(pixelSize); } @Override - public final AABBox getBBox(float pixelSize, float[] tmpV3) { - final float size = getScale(pixelSize); - AABBox newBox = getBBox().clone(); - newBox.scale(size, tmpV3); - return newBox; + public final AABBox getBBox(final AABBox dest, final float pixelSize, final float[] tmpV3) { + return dest.copy(getBBox()).scale(getScale(pixelSize), tmpV3); } - protected final void addAdvance(float advance, float size) { + protected final void addAdvance(final float advance, final float size) { this.metrics.addAdvance(advance, size); } @Override - public final float getAdvance(float pixelSize, boolean useFrationalMetrics) { + public final float getAdvance(final float pixelSize, final boolean useFrationalMetrics) { return this.metrics.getAdvance(pixelSize, useFrationalMetrics); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java index 4064e6463..be8ab8f69 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastHMetrics.java @@ -45,7 +45,7 @@ class TypecastHMetrics implements Metrics { // VheaTable (for horizontal fonts) // private final VheaTable vheaTable; - public TypecastHMetrics(TypecastFont fontImpl) { + public TypecastHMetrics(final TypecastFont fontImpl) { this.fontImpl = fontImpl; headTable = this.fontImpl.font.getHeadTable(); hheaTable = this.fontImpl.font.getHheaTable(); @@ -62,29 +62,27 @@ class TypecastHMetrics implements Metrics { } @Override - public final float getAscent(float pixelSize) { + public final float getAscent(final float pixelSize) { return getScale(pixelSize) * -hheaTable.getAscender(); // invert } @Override - public final float getDescent(float pixelSize) { + public final float getDescent(final float pixelSize) { return getScale(pixelSize) * -hheaTable.getDescender(); // invert } @Override - public final float getLineGap(float pixelSize) { + public final float getLineGap(final float pixelSize) { return getScale(pixelSize) * -hheaTable.getLineGap(); // invert } @Override - public final float getMaxExtend(float pixelSize) { + public final float getMaxExtend(final float pixelSize) { return getScale(pixelSize) * hheaTable.getXMaxExtent(); } @Override - public final float getScale(float pixelSize) { + public final float getScale(final float pixelSize) { return pixelSize * unitsPerEM_Inv; } @Override - public final AABBox getBBox(float pixelSize, float[] tmpV3) { - AABBox res = new AABBox(bbox.getLow(), bbox.getHigh()); - res.scale(getScale(pixelSize), tmpV3); - return res; + public final AABBox getBBox(final AABBox dest, final float pixelSize, final float[] tmpV3) { + return dest.setSize(bbox.getLow(), bbox.getHigh()).scale(getScale(pixelSize), tmpV3); } }
\ No newline at end of file diff --git a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java index 04b9d3bcd..2a30fa6ec 100644 --- a/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java +++ b/src/jogl/classes/jogamp/graph/geom/plane/AffineTransform.java @@ -208,7 +208,7 @@ public class AffineTransform implements Cloneable { return m00 * m11 - m01 * m10; } - public final void setTransform(float m00, float m10, float m01, float m11, float m02, float m12) { + public final AffineTransform setTransform(float m00, float m10, float m01, float m11, float m02, float m12) { this.type = TYPE_UNKNOWN; this.m00 = m00; this.m10 = m10; @@ -216,20 +216,23 @@ public class AffineTransform implements Cloneable { this.m11 = m11; this.m02 = m02; this.m12 = m12; + return this; } - public final void setTransform(AffineTransform t) { + public final AffineTransform setTransform(AffineTransform t) { type = t.type; setTransform(t.m00, t.m10, t.m01, t.m11, t.m02, t.m12); + return this; } - public final void setToIdentity() { + public final AffineTransform setToIdentity() { type = TYPE_IDENTITY; m00 = m11 = 1.0f; m10 = m01 = m02 = m12 = 0.0f; + return this; } - public final void setToTranslation(float mx, float my) { + public final AffineTransform setToTranslation(float mx, float my) { m00 = m11 = 1.0f; m01 = m10 = 0.0f; m02 = mx; @@ -239,9 +242,10 @@ public class AffineTransform implements Cloneable { } else { type = TYPE_TRANSLATION; } + return this; } - public final void setToScale(float scx, float scy) { + public final AffineTransform setToScale(float scx, float scy) { m00 = scx; m11 = scy; m10 = m01 = m02 = m12 = 0.0f; @@ -250,9 +254,10 @@ public class AffineTransform implements Cloneable { } else { type = TYPE_IDENTITY; } + return this; } - public final void setToShear(float shx, float shy) { + public final AffineTransform setToShear(float shx, float shy) { m00 = m11 = 1.0f; m02 = m12 = 0.0f; m01 = shx; @@ -262,9 +267,10 @@ public class AffineTransform implements Cloneable { } else { type = TYPE_IDENTITY; } + return this; } - public final void setToRotation(float angle) { + public final AffineTransform setToRotation(float angle) { float sin = FloatUtil.sin(angle); float cos = FloatUtil.cos(angle); if (FloatUtil.abs(cos) < ZERO) { @@ -280,63 +286,35 @@ public class AffineTransform implements Cloneable { m10 = sin; m02 = m12 = 0.0f; type = TYPE_UNKNOWN; + return this; } - public final void setToRotation(float angle, float px, float py) { + public final AffineTransform setToRotation(float angle, float px, float py) { setToRotation(angle); m02 = px * (1.0f - m00) + py * m10; m12 = py * (1.0f - m00) - px * m10; type = TYPE_UNKNOWN; + return this; } - public static AffineTransform getTranslateInstance(float mx, float my) { - AffineTransform t = new AffineTransform(); - t.setToTranslation(mx, my); - return t; - } - - public static AffineTransform getScaleInstance(float scx, float scY) { - AffineTransform t = new AffineTransform(); - t.setToScale(scx, scY); - return t; - } - - public static AffineTransform getShearInstance(float shx, float shy) { - AffineTransform t = new AffineTransform(); - t.setToShear(shx, shy); - return t; - } - - public static AffineTransform getRotateInstance(float angle) { - AffineTransform t = new AffineTransform(); - t.setToRotation(angle); - return t; - } - - public static AffineTransform getRotateInstance(float angle, float x, float y) { - AffineTransform t = new AffineTransform(); - t.setToRotation(angle, x, y); - return t; - } - - public final AffineTransform translate(float mx, float my) { - return concatenate(AffineTransform.getTranslateInstance(mx, my)); + public final AffineTransform translate(float mx, float my, AffineTransform tmp) { + return concatenate(tmp.setToTranslation(mx, my)); } - public final AffineTransform scale(float scx, float scy) { - return concatenate(AffineTransform.getScaleInstance(scx, scy)); + public final AffineTransform scale(float scx, float scy, AffineTransform tmp) { + return concatenate(tmp.setToScale(scx, scy)); } - public final AffineTransform shear(float shx, float shy) { - return concatenate(AffineTransform.getShearInstance(shx, shy)); + public final AffineTransform shear(float shx, float shy, AffineTransform tmp) { + return concatenate(tmp.setToShear(shx, shy)); } - public final AffineTransform rotate(float angle) { - return concatenate(AffineTransform.getRotateInstance(angle)); + public final AffineTransform rotate(float angle, AffineTransform tmp) { + return concatenate(tmp.setToRotation(angle)); } - public final AffineTransform rotate(float angle, float px, float py) { - return concatenate(AffineTransform.getRotateInstance(angle, px, py)); + public final AffineTransform rotate(float angle, float px, float py, AffineTransform tmp) { + return concatenate(tmp.setToRotation(angle, px, py)); } /** |