});
}
void initJAI(JAIInfo jai) {
JAI jaiDef = JAI.getDefaultInstance();
jai.setJAI( jaiDef );
// setting JAI wide hints
jaiDef.setRenderingHint(JAI.KEY_CACHED_TILE_RECYCLING_ENABLED, jai.isRecycling());
// tile factory and recycler
if(jai.isRecycling() && !(jaiDef.getRenderingHint(JAI.KEY_TILE_FACTORY) instanceof ConcurrentTileFactory)) {
final ConcurrentTileFactory recyclingFactory = new ConcurrentTileFactory();
jaiDef.setRenderingHint(JAI.KEY_TILE_FACTORY, recyclingFactory);
jaiDef.setRenderingHint(JAI.KEY_TILE_RECYCLER, recyclingFactory);
} else {
if(!jai.isRecycling()){
final PassThroughTileFactory passThroughFactory = new PassThroughTileFactory();
jaiDef.setRenderingHint(JAI.KEY_TILE_FACTORY, passThroughFactory);
jaiDef.setRenderingHint(JAI.KEY_TILE_RECYCLER, passThroughFactory);
}
}
// Setting up Cache Capacity
SunTileCache jaiCache = (SunTileCache) jaiDef.getTileCache();
jai.setTileCache( jaiCache );
long jaiMemory = (long) (jai.getMemoryCapacity() * Runtime.getRuntime().maxMemory());
jaiCache.setMemoryCapacity(jaiMemory);
// Setting up Cache Threshold
jaiCache.setMemoryThreshold((float) jai.getMemoryThreshold());
jaiDef.getTileScheduler().setParallelism(jai.getTileThreads());
jaiDef.getTileScheduler().setPrefetchParallelism(jai.getTileThreads());
jaiDef.getTileScheduler().setPriority(jai.getTilePriority());
jaiDef.getTileScheduler().setPrefetchPriority(jai.getTilePriority());
// Workaround for native mosaic BUG
Registry.setNativeAccelerationAllowed("Mosaic", jai.isAllowNativeMosaic(), jaiDef);
// Workaround for native Warp BUG
Registry.setNativeAccelerationAllowed("Warp", jai.isAllowNativeWarp(), jaiDef);