From abc833631e0ab30a06c7aff47a39a551544fd735 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 2 Apr 2014 19:25:16 +0200 Subject: Bug 801: Reduce temp. object creation, i.e. GC load --- .../jogamp/graph/curve/opengl/TextRegionUtil.java | 54 ++++++++++++++------ src/jogl/classes/com/jogamp/graph/font/Font.java | 58 ++++++++++++---------- .../classes/com/jogamp/graph/geom/Outline.java | 44 ++++++++-------- .../classes/com/jogamp/graph/geom/SVertex.java | 13 ++--- 4 files changed, 95 insertions(+), 74 deletions(-) (limited to 'src/jogl/classes/com/jogamp/graph') 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 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 { *

* 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. *

* @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 stringCacheMap = new HashMap(DEFAULT_CACHE_LIMIT); private final ArrayList stringCacheArray = new ArrayList(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. *

{@link #getName(StringBuilder, int)} w/ {@link #NAME_FAMILY} and {@link #NAME_SUBFAMILY}

*

Example: "{@code Ubuntu-Regular}"

*/ - 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); /** *
@@ -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 layout bounding box as computed by each glyph's metrics.
      * The result is not pixel correct, bit reflects layout specific metrics.
      * 

- * See {@link #getPointsBounds(AffineTransform, CharSequence, float)} for pixel correct results. + * See {@link #getPointsBounds(AffineTransform, CharSequence, float, AffineTransform, AffineTransform)} for pixel correct results. *

* @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 { +public class Outline implements Comparable { - private ArrayList vertices = new ArrayList(3); - private boolean closed = false; - private AABBox bbox = new AABBox(); - private boolean dirtyBBox = false; + private ArrayList 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(3); + closed = false; + bbox = new AABBox(); + dirtyBBox = false; + } + + /** + * Copy ctor + */ + public Outline(final Outline src) { + vertices = new ArrayList(src.vertices.size()); + for(int i=0; i { } 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(vertices.size()); - for(int i=0; i