diff options
author | Sven Gothel <[email protected]> | 2011-04-01 06:48:52 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-04-01 06:48:52 +0200 |
commit | 4b8bd5ec58cb2edfb51bd9ee930beb9c539a8a0b (patch) | |
tree | 5567f56606ea248707fe002015b90a9635250e91 /src/com/jogamp/graph/curve/opengl/TextRenderer.java | |
parent | e8c69e69374b6650e37594ebf104602fb06b548b (diff) |
Final core and demo changes for jogl merge
Core:
- Region: Cleanup up constant names
- Renderer: Add getRenderType()
- TextRenderer: Add cache size limit
- JavaFontLoader: Add FIXME 'Add cache size to limit memory usage'
- UbuntuFontLoader: Add cache and FIXME 'Add cache size to limit memory usage'
- TypecastFont: Add FIXME 'Add cache size to limit memory usage ??'
Demos:
- Relocated and split (main/listener) for jogl merge
- Add 's' for screenshot
- Text:
- Add 'i' for live editing mode (until CR, backspace supported)
Diffstat (limited to 'src/com/jogamp/graph/curve/opengl/TextRenderer.java')
-rw-r--r-- | src/com/jogamp/graph/curve/opengl/TextRenderer.java | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/src/com/jogamp/graph/curve/opengl/TextRenderer.java b/src/com/jogamp/graph/curve/opengl/TextRenderer.java index 83f2c93ca..2bb99d27c 100644 --- a/src/com/jogamp/graph/curve/opengl/TextRenderer.java +++ b/src/com/jogamp/graph/curve/opengl/TextRenderer.java @@ -1,5 +1,6 @@ package com.jogamp.graph.curve.opengl; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -15,8 +16,6 @@ import com.jogamp.graph.geom.Vertex; public abstract class TextRenderer extends Renderer { - protected HashMap<String, GlyphString> strings = new HashMap<String, GlyphString>(); - /** * Create a Hardware accelerated Text Renderer. * @param factory optional Point.Factory for Vertex construction. Default is Vertex.Factory. @@ -58,22 +57,47 @@ public abstract class TextRenderer extends Renderer { GlyphString glyphString = new GlyphString(pointFactory, font.getName(), str); glyphString.createfromFontPath(paths, affineTransform); - glyphString.generateRegion(gl.getContext(), sharpness, st, regionType); + glyphString.generateRegion(gl.getContext(), sharpness, st, renderType); return glyphString; } - protected static String getTextHashCode(Font font, String str, int fontSize) { - // FIXME: use integer hash code - return font.getName() + "." + str.hashCode() + "." + fontSize; - } - public void flushCache() { - Iterator<GlyphString> iterator = strings.values().iterator(); + Iterator<GlyphString> iterator = stringCacheMap.values().iterator(); while(iterator.hasNext()){ GlyphString glyphString = iterator.next(); glyphString.destroy(); } - strings.clear(); - } + stringCacheMap.clear(); + stringCacheArray.clear(); + } + + public final void setCacheMaxSize(int newSize ) { stringCacheMaxSize = newSize; validateCache(0); } + public final int getCacheMaxSize() { return stringCacheMaxSize; } + public final int getCacheSize() { return stringCacheArray.size(); } + + protected void validateCache(int space) { + while ( getCacheSize() + space > getCacheMaxSize() ) { + String key = stringCacheArray.remove(0); + stringCacheMap.remove(key); + } + } + + protected GlyphString getCachedGlyphString(Font font, String str, int fontSize) { + final String key = font.getName() + "." + str.hashCode() + "." + fontSize; + return stringCacheMap.get(key); + } + + protected void addCachedGlyphString(Font font, String str, int fontSize, GlyphString glyphString) { + final String key = font.getName() + "." + str.hashCode() + "." + fontSize; + validateCache(1); + stringCacheMap.put(key, glyphString); + stringCacheArray.add(stringCacheArray.size(), key); + } + + // Cache is adding at the end of the array + public static final int DEFAULT_CACHE_SIZE = 32; + private HashMap<String, GlyphString> stringCacheMap = new HashMap<String, GlyphString>(DEFAULT_CACHE_SIZE); + private ArrayList<String> stringCacheArray = new ArrayList<String>(DEFAULT_CACHE_SIZE); + private int stringCacheMaxSize = DEFAULT_CACHE_SIZE; // -1 unlimited, 0 off, >0 limited }
\ No newline at end of file |