Update of /cvsroot/arianne/stendhal/src/games/stendhal/client/gui/j2d
In directory vz-cvs-4.sog:/tmp/cvs-serv5851/src/games/stendhal/client/gui/j2d
Modified Files:
Blend.java
Log Message:
Cache composite contexts with high creation overhead
Index: Blend.java
===================================================================
RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/client/gui/j2d/Blend.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** Blend.java 27 Nov 2012 21:28:39 -0000 1.21
--- Blend.java 27 Nov 2012 22:27:04 -0000 1.22
***************
*** 21,24 ****
--- 21,26 ----
import static games.stendhal.common.color.HSL.rgb2hsl;
+ import games.stendhal.client.MemoryCache;
+
import java.awt.Color;
import java.awt.Composite;
***************
*** 33,36 ****
--- 35,41 ----
*/
public class Blend implements Composite {
+ /** Cached composers. */
+ private static final MemoryCache<Object, CompositeContext> cache = new MemoryCache<Object, CompositeContext>();
+
/**
* Possible blending modes.
***************
*** 94,97 ****
--- 99,110 ----
case MULTIPLY:
return new MultiplyContext();
+ // Modes with significant creation overhead (lookup tables). Cache those
+ case SOFT_LIGHT:
+ CompositeContext ctx = cache.get(Mode.SOFT_LIGHT);
+ if (ctx == null) {
+ ctx = new BlendContext(mode, srcColorModel, dstColorModel, color);
+ cache.put(Mode.SOFT_LIGHT, ctx);
+ }
+ return ctx;
default:
return new BlendContext(mode, srcColorModel, dstColorModel, color);
|