Revision: 4036 http://vexi.svn.sourceforge.net/vexi/?rev=4036&view=rev Author: clrg Date: 2011-02-17 01:34:52 +0000 (Thu, 17 Feb 2011)
Log Message: ----------- Small optimization for glyph rendering (only pre-prepare glyph image once until color change) Modified Paths: -------------- trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Java2.java Modified: trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Java2.java =================================================================== --- trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Java2.java 2011-02-15 22:58:53 UTC (rev 4035) +++ trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Java2.java 2011-02-17 01:34:52 UTC (rev 4036) @@ -202,6 +202,8 @@ protected Font.Glyph _createGlyph(Font f, char c) { return new Java2Glyph(f, c); } protected static class Java2Glyph extends AWTGlyph { private BufferedImage i2 = null; + int lastcolor = 0; + Graphics2D g = null; public Java2Glyph(Font f, char c) { super(f, c); } BufferedImage getBufferedImage() { if (i2 == null) { @@ -223,20 +225,24 @@ private DataBuffer buf = null; public void drawGlyph(org.vexi.graphics.Font.Glyph glyph, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int argb) { - if (glyph.width == 0 || glyph.height == 0) { + if (glyph.width == 0 || glyph.height == 0 || argb == 0) { return; } int w = cx2 - cx1; int h = cy2 - cy1; - BufferedImage g = ((Java2Glyph)glyph).getBufferedImage(); + Java2Glyph j2g = ((Java2Glyph)glyph); + BufferedImage g = j2g.getBufferedImage(); + if (j2g.lastcolor!=argb) { + j2g.lastcolor = argb; + Graphics2D src = (Graphics2D)g.getGraphics(); + src.setClip(0, 0, glyph.width, glyph.height); + src.setComposite(AlphaComposite.Src); + src.setColor(new Color((argb & 0x00ff0000) >> 16, (argb & 0x0000ff00) >> 8, argb & 0x000000ff, (argb >> 24) & 0x000000ff)); + src.drawImage(j2g.getImage(), 0, 0, null); + src.setComposite(AlphaComposite.SrcIn); + src.fillRect(0, 0, glyph.width, glyph.height); + } Graphics2D dst = (Graphics2D)i.getGraphics(); - Graphics2D src = (Graphics2D)g.getGraphics(); - src.setClip(0, 0, glyph.width, glyph.height); - src.setComposite(AlphaComposite.Src); - src.setColor(new Color((argb & 0x00ff0000) >> 16, (argb & 0x0000ff00) >> 8, argb & 0x000000ff, (argb >> 24) & 0x000000ff)); - src.drawImage(((AWTGlyph)glyph).getImage(), 0, 0, null); - src.setComposite(AlphaComposite.SrcIn); - src.fillRect(0, 0, glyph.width, glyph.height); dst.setClip(cx1, cy1, w, h); dst.setComposite(AlphaComposite.SrcOver); dst.drawImage(g, dx, dy, null); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn