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/com | |
parent | e8a5a1cbb988670ca206ab1ac633e19a91bfa478 (diff) |
Bug 801: Reduce temp. object creation, i.e. GC load
Diffstat (limited to 'src/jogl/classes/com')
5 files changed, 125 insertions, 85 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java index 16b1224bd..f944843e9 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -63,6 +63,17 @@ public class TextRegionUtil { public void visit(final OutlineShape shape, final AffineTransform t); } + public static int getCharCount(final String s, final char c) { + final int sz = s.length(); + int count = 0; + for(int i=0; i<sz; i++) { + if( s.charAt(i) == c ) { + count++; + } + } + return count; + } + /** * Visit each {@link Font.Glyph}'s {@link OutlineShape} with the given {@link ShapeVisitor} * additionally passing the progressed {@link AffineTransform}. @@ -72,9 +83,12 @@ public class TextRegionUtil { * @param font the target {@link Font} * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. * @param str string text + * @param temp1 temporary AffineTransform storage, mandatory, will be passed to {@link ShapeVisitor#visit(OutlineShape, AffineTransform)} and can be modified. + * @param temp2 temporary AffineTransform storage, mandatory, can be re-used in {@link ShapeVisitor#visit(OutlineShape, AffineTransform)} by user code. */ public static void processString(final ShapeVisitor visitor, final AffineTransform transform, - final Font font, final float pixelSize, final CharSequence str) { + final Font font, final float pixelSize, final CharSequence str, + final AffineTransform temp1, AffineTransform temp2) { final int charCount = str.length(); // region.setFlipped(true); @@ -82,7 +96,6 @@ public class TextRegionUtil { final float lineHeight = font.getLineHeight(pixelSize); final float scale = metrics.getScale(pixelSize); - final AffineTransform t = null != transform ? new AffineTransform(transform) : new AffineTransform(); float y = 0; float advanceTotal = 0; @@ -100,19 +113,19 @@ public class TextRegionUtil { } // 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); final Font.Glyph glyph = font.getGlyph(character); final OutlineShape glyphShape = glyph.getShape(); if( null == glyphShape ) { continue; } - visitor.visit(glyphShape, t); + visitor.visit(glyphShape, temp1); advanceTotal += glyph.getAdvance(pixelSize, true); } @@ -127,14 +140,17 @@ public class TextRegionUtil { * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. * @param str string text * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored. + * @param temp1 temporary AffineTransform storage, mandatory + * @param temp2 temporary AffineTransform storage, mandatory */ public static void addStringToRegion(final GLRegion region, final Factory<? extends Vertex> vertexFactory, - final Font font, final float pixelSize, final CharSequence str, final float[] rgbaColor) { + final Font font, final float pixelSize, final CharSequence str, final float[] rgbaColor, + final AffineTransform temp1, final AffineTransform temp2) { final ShapeVisitor visitor = new ShapeVisitor() { public final void visit(final OutlineShape shape, final AffineTransform t) { region.addOutlineShape(shape, t, region.hasColorChannel() ? rgbaColor : null); } }; - processString(visitor, null, font, pixelSize, str); + processString(visitor, null, font, pixelSize, str, temp1, temp2); } /** @@ -163,7 +179,7 @@ public class TextRegionUtil { GLRegion region = getCachedRegion(font, str, pixelSize, special); if(null == region) { region = GLRegion.create(renderModes); - addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor); + addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor, tempT1, tempT2); addCachedRegion(gl, font, str, pixelSize, special, region); } region.draw(gl, renderer, sampleCount); @@ -175,7 +191,7 @@ public class TextRegionUtil { * <p> * In case of a multisampling region renderer, i.e. {@link Region#VBAA_RENDERING_BIT}, recreating the {@link GLRegion} * is a huge performance impact. - * In such case better use {@link #drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, float, CharSequence, float[], int[])} + * In such case better use {@link #drawString3D(GL2ES2, GLRegion, RegionRenderer, Font, float, CharSequence, float[], int[], AffineTransform, AffineTransform)} * instead. * </p> * @param gl the current GL state @@ -186,16 +202,19 @@ public class TextRegionUtil { * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored. * @param sampleCount desired multisampling sample count for msaa-rendering. * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched. + * @param temp1 temporary AffineTransform storage, mandatory + * @param temp2 temporary AffineTransform storage, mandatory * @throws Exception if TextRenderer not initialized */ public static void drawString3D(final GL2ES2 gl, final int renderModes, final RegionRenderer renderer, final Font font, final float pixelSize, - final CharSequence str, final float[] rgbaColor, final int[/*1*/] sampleCount) { + final CharSequence str, final float[] rgbaColor, final int[/*1*/] sampleCount, + final AffineTransform temp1, final AffineTransform temp2) { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } final GLRegion region = GLRegion.create(renderModes); - addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor); + addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor, temp1, temp2); region.draw(gl, renderer, sampleCount); region.destroy(gl); } @@ -210,16 +229,19 @@ public class TextRegionUtil { * @param rgbaColor if {@link Region#hasColorChannel()} RGBA color must be passed, otherwise value is ignored. * @param sampleCount desired multisampling sample count for msaa-rendering. * The actual used scample-count is written back when msaa-rendering is enabled, otherwise the store is untouched. + * @param temp1 temporary AffineTransform storage, mandatory + * @param temp2 temporary AffineTransform storage, mandatory * @throws Exception if TextRenderer not initialized */ public static void drawString3D(final GL2ES2 gl, final GLRegion region, final RegionRenderer renderer, final Font font, final float pixelSize, final CharSequence str, - final float[] rgbaColor, final int[/*1*/] sampleCount) { + final float[] rgbaColor, final int[/*1*/] sampleCount, + final AffineTransform temp1, final AffineTransform temp2) { if(!renderer.isInitialized()){ throw new GLException("TextRendererImpl01: not initialized!"); } region.clear(gl); - addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor); + addStringToRegion(region, renderer.getRenderState().getVertexFactory(), font, pixelSize, str, rgbaColor, temp1, temp2); region.draw(gl, renderer, sampleCount); } @@ -321,6 +343,8 @@ public class TextRegionUtil { /** Default cache limit, see {@link #setCacheLimit(int)} */ public static final int DEFAULT_CACHE_LIMIT = 256; + public final AffineTransform tempT1 = new AffineTransform(); + public final AffineTransform tempT2 = new AffineTransform(); private final HashMap<String, GLRegion> stringCacheMap = new HashMap<String, GLRegion>(DEFAULT_CACHE_LIMIT); private final ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_LIMIT); private int stringCacheLimit = DEFAULT_CACHE_LIMIT; diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java index 811ab9d94..92d35768b 100644 --- a/src/jogl/classes/com/jogamp/graph/font/Font.java +++ b/src/jogl/classes/com/jogamp/graph/font/Font.java @@ -1,5 +1,5 @@ /** - * Copyright 2010 JogAmp Community. All rights reserved. +// * Copyright 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: @@ -30,7 +30,6 @@ package com.jogamp.graph.font; import jogamp.graph.geom.plane.AffineTransform; import com.jogamp.graph.curve.OutlineShape; -import com.jogamp.graph.curve.opengl.TextRegionUtil.ShapeVisitor; import com.jogamp.opengl.math.geom.AABBox; /** @@ -82,17 +81,18 @@ public interface Font { * Horizontal http://developer.apple.com/fonts/TTRefMan/RM06/Chap6hhea.html */ public interface Metrics { - float getAscent(float pixelSize); - float getDescent(float pixelSize); - float getLineGap(float pixelSize); - float getMaxExtend(float pixelSize); - float getScale(float pixelSize); + float getAscent(final float pixelSize); + float getDescent(final float pixelSize); + float getLineGap(final float pixelSize); + float getMaxExtend(final float pixelSize); + float getScale(final float pixelSize); /** + * @param dest AABBox instance set to this metrics boundary w/ given pixelSize * @param pixelSize * @param tmpV3 caller provided temporary 3-component vector - * @return + * @return the given and set AABBox 'dest' */ - AABBox getBBox(float pixelSize, float[] tmpV3); + AABBox getBBox(final AABBox dest, final float pixelSize, final float[] tmpV3); } /** @@ -113,28 +113,29 @@ public interface Font { public char getSymbol(); public short getID(); public AABBox getBBox(); - public float getScale(float pixelSize); + public float getScale(final float pixelSize); /** + * @param dest AABBox instance set to this metrics boundary w/ given pixelSize * @param pixelSize * @param tmpV3 caller provided temporary 3-component vector - * @return + * @return the given and set AABBox 'dest' */ - public AABBox getBBox(float pixelSize, float[] tmpV3); - public float getAdvance(float pixelSize, boolean useFrationalMetrics); + public AABBox getBBox(final AABBox dest, final float pixelSize, float[] tmpV3); + public float getAdvance(final float pixelSize, boolean useFrationalMetrics); public OutlineShape getShape(); public int hashCode(); } - public String getName(int nameIndex); - public StringBuilder getName(StringBuilder string, int nameIndex); + public String getName(final int nameIndex); + public StringBuilder getName(final StringBuilder string, final int nameIndex); /** Shall return the family and subfamily name, separated a dash. * <p>{@link #getName(StringBuilder, int)} w/ {@link #NAME_FAMILY} and {@link #NAME_SUBFAMILY}</p> * <p>Example: "{@code Ubuntu-Regular}"</p> */ - public StringBuilder getFullFamilyName(StringBuilder buffer); + public StringBuilder getFullFamilyName(final StringBuilder buffer); - public StringBuilder getAllNames(StringBuilder string, String separator); + public StringBuilder getAllNames(final StringBuilder string, final String separator); /** * <pre> @@ -150,36 +151,39 @@ public interface Font { * @param resolution display resolution in dots-per-inch * @return pixel-per-inch, pixelSize scale factor for font operations. */ - public float getPixelSize(float fontSize /* points per inch */, float resolution); + public float getPixelSize(final float fontSize /* points per inch */, final float resolution); - public float getAdvanceWidth(int glyphID, float pixelSize); + public float getAdvanceWidth(final int glyphID, final float pixelSize); public Metrics getMetrics(); - public Glyph getGlyph(char symbol); + public Glyph getGlyph(final char symbol); public int getNumGlyphs(); - public float getLineHeight(float pixelSize); - public float getMetricWidth(CharSequence string, float pixelSize); - public float getMetricHeight(CharSequence string, float pixelSize); + public float getLineHeight(final float pixelSize); + public float getMetricWidth(final CharSequence string, final float pixelSize); + public float getMetricHeight(final CharSequence string, final float pixelSize, final AABBox tmp); /** * Return the <i>layout</i> bounding box as computed by each glyph's metrics. * The result is not pixel correct, bit reflects layout specific metrics. * <p> - * See {@link #getPointsBounds(AffineTransform, CharSequence, float)} for pixel correct results. + * See {@link #getPointsBounds(AffineTransform, CharSequence, float, AffineTransform, AffineTransform)} for pixel correct results. * </p> * @param string string text * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. */ - public AABBox getMetricBounds(CharSequence string, float pixelSize); + public AABBox getMetricBounds(final CharSequence string, final float pixelSize); /** * Return the bounding box by taking each glyph's point-based bounding box into account. * @param transform optional given transform * @param string string text * @param pixelSize Use {@link Font#getPixelSize(float, float)} for resolution correct pixel-size. + * @param temp1 temporary AffineTransform storage, mandatory + * @param temp2 temporary AffineTransform storage, mandatory */ - 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); - public boolean isPrintableChar( char c ); + public boolean isPrintableChar(final char c); /** Shall return {@link #getFullFamilyName()} */ @Override diff --git a/src/jogl/classes/com/jogamp/graph/geom/Outline.java b/src/jogl/classes/com/jogamp/graph/geom/Outline.java index 80aea2af4..15a45b056 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/Outline.java +++ b/src/jogl/classes/com/jogamp/graph/geom/Outline.java @@ -47,18 +47,35 @@ import com.jogamp.opengl.math.geom.AABBox; * * @see OutlineShape, Region */ -public class Outline implements Cloneable, Comparable<Outline> { +public class Outline implements Comparable<Outline> { - private ArrayList<Vertex> vertices = new ArrayList<Vertex>(3); - private boolean closed = false; - private AABBox bbox = new AABBox(); - private boolean dirtyBBox = false; + private ArrayList<Vertex> vertices; + private boolean closed; + private final AABBox bbox; + private boolean dirtyBBox; /**Create an outline defined by control vertices. * An outline can contain off Curve vertices which define curved * regions in the outline. */ public Outline() { + vertices = new ArrayList<Vertex>(3); + closed = false; + bbox = new AABBox(); + dirtyBBox = false; + } + + /** + * Copy ctor + */ + public Outline(final Outline src) { + vertices = new ArrayList<Vertex>(src.vertices.size()); + for(int i=0; i<vertices.size(); i++) { + vertices.add( src.vertices.get(i).clone() ); + } + closed = src.closed; + bbox = new AABBox(src.bbox); + dirtyBBox = src.dirtyBBox; } public final int getVertexCount() { @@ -257,21 +274,4 @@ public class Outline implements Cloneable, Comparable<Outline> { } return true; } - - /** - * @return deep clone of this Outline - */ - @Override - public Outline clone() { - Outline o; - try { - o = (Outline) super.clone(); - } catch (CloneNotSupportedException e) { throw new InternalError(); } - o.bbox = bbox.clone(); - o.vertices = new ArrayList<Vertex>(vertices.size()); - for(int i=0; i<vertices.size(); i++) { - o.vertices.add(vertices.get(i).clone()); - } - return o; - } } diff --git a/src/jogl/classes/com/jogamp/graph/geom/SVertex.java b/src/jogl/classes/com/jogamp/graph/geom/SVertex.java index d13607d71..579f92455 100644 --- a/src/jogl/classes/com/jogamp/graph/geom/SVertex.java +++ b/src/jogl/classes/com/jogamp/graph/geom/SVertex.java @@ -75,10 +75,10 @@ public class SVertex implements Vertex { } public SVertex(final Vertex src) { - this.id = src.getId(); + this.id = Integer.MAX_VALUE; System.arraycopy(src.getCoord(), 0, coord, 0, 3); - setOnCurve(src.isOnCurve()); System.arraycopy(src.getTexCoord(), 0, texCoord, 0, 3); + setOnCurve(src.isOnCurve()); } public SVertex(final int id, final boolean onCurve, final float[] texCoordsBuffer) { @@ -99,13 +99,6 @@ public class SVertex implements Vertex { setOnCurve(onCurve); } - public SVertex(float[] coordsBuffer, float[] texCoordsBuffer, boolean onCurve) { - this.id = Integer.MAX_VALUE; - System.arraycopy(coordsBuffer, 0, coord, 0, 3); - System.arraycopy(texCoordsBuffer, 0, texCoord, 0, 3); - setOnCurve(onCurve); - } - @Override public final void setCoord(float x, float y, float z) { coord[0] = x; @@ -215,7 +208,7 @@ public class SVertex implements Vertex { */ @Override public SVertex clone(){ - return new SVertex(this.coord, this.texCoord, this.onCurve); + return new SVertex(this); } @Override diff --git a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java index 23a0032d2..8a0bf37a0 100644 --- a/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java +++ b/src/jogl/classes/com/jogamp/opengl/math/geom/AABBox.java @@ -51,7 +51,7 @@ import com.jogamp.opengl.util.PMVMatrix; * </p> * */ -public class AABBox implements Cloneable { +public class AABBox { private static final boolean DEBUG = FloatUtil.DEBUG; private final float[] low = new float[3]; private final float[] high = new float[3]; @@ -70,9 +70,7 @@ public class AABBox implements Cloneable { * @param src the box value to be used for the new instance */ public AABBox(AABBox src) { - System.arraycopy(src.low, 0, low, 0, 3); - System.arraycopy(src.high, 0, high, 0, 3); - System.arraycopy(src.center, 0, center, 0, 3); + copy(src); } /** @@ -90,12 +88,13 @@ public class AABBox implements Cloneable { setSize(lx, ly, lz, hx, hy, hz); } - /** Create a AABBox defining the low and high + /** + * Create a AABBox defining the low and high * @param low min xyz-coordinates * @param high max xyz-coordinates */ public AABBox(final float[] low, final float[] high) { - setSize(low[0],low[1],low[2], high[0],high[1],high[2]); + setSize(low, high); } /** @@ -144,6 +143,31 @@ public class AABBox implements Cloneable { } /** + * Copy given AABBox 'src' values to this AABBox. + * + * @param src source AABBox + * @return this AABBox for chaining + */ + public final AABBox copy(AABBox src) { + System.arraycopy(src.low, 0, low, 0, 3); + System.arraycopy(src.high, 0, high, 0, 3); + System.arraycopy(src.center, 0, center, 0, 3); + return this; + } + + /** + * Set size of the AABBox specifying the coordinates + * of the low and high. + * + * @param low min xyz-coordinates + * @param high max xyz-coordinates + * @return this AABBox for chaining + */ + public final AABBox setSize(final float[] low, final float[] high) { + return setSize(low[0],low[1],low[2], high[0],high[1],high[2]); + } + + /** * Set size of the AABBox specifying the coordinates * of the low and high. * @@ -510,11 +534,6 @@ public class AABBox implements Cloneable { } @Override - public final AABBox clone() { - return new AABBox(this); - } - - @Override public final boolean equals(Object obj) { if( obj == this ) { return true; |