- Timestamp:
- 2014-05-08T23:02:32+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r7059 r7080 25 25 import java.awt.geom.Point2D; 26 26 import java.awt.geom.Rectangle2D; 27 import java.util.AbstractList; 27 28 import java.util.ArrayList; 28 29 import java.util.Collection; … … 35 36 import java.util.concurrent.Executors; 36 37 import java.util.concurrent.Future; 37 38 38 import javax.swing.AbstractButton; 39 39 import javax.swing.FocusManager; 40 41 40 import org.openstreetmap.josm.Main; 42 41 import org.openstreetmap.josm.data.Bounds; … … 83 82 84 83 static { 85 noThreads = Runtime.getRuntime().availableProcessors(); 86 styleCreatorPool = Executors.newFixedThreadPool(noThreads); 84 noThreads = Main.pref.getInteger( 85 "mappaint.StyledMapRenderer.style_creation.numberOfThreads", 86 Runtime.getRuntime().availableProcessors()); 87 styleCreatorPool = noThreads <= 1 ? null : Executors.newFixedThreadPool(noThreads); 87 88 } 88 89 … … 234 235 235 236 return Float.compare(this.style.object_z_index, other.style.object_z_index); 237 } 238 } 239 240 /** 241 * Joined List build from two Lists (read-only). 242 * 243 * Extremely simple single-purpose implementation. 244 * @param <T> 245 */ 246 public static class CompositeList<T> extends AbstractList<T> { 247 List<T> a,b; 248 249 public CompositeList(List<T> a, List<T> b) { 250 this.a = a; 251 this.b = b; 252 } 253 254 @Override 255 public T get(int index) { 256 return index < a.size() ? a.get(index) : b.get(index - a.size()); 257 } 258 259 @Override 260 public int size() { 261 return a.size() + b.size(); 236 262 } 237 263 } … … 1315 1341 styles = MapPaintStyles.getStyles(); 1316 1342 styles.setDrawMultipolygon(drawMultipolygon); 1317 1343 1318 1344 highlightWaySegments = data.getHighlightedWaySegments(); 1319 1345 … … 1326 1352 1327 1353 class ComputeStyleListWorker implements Callable<List<StyleRecord>>, Visitor { 1328 private final List<StyleRecord> styleList;1329 1354 private final List<? extends OsmPrimitive> input; 1330 1355 private final int from; 1331 1356 private final int to; 1357 private final List<StyleRecord> output; 1332 1358 1333 1359 /** … … 1337 1363 * @param to last index + 1 1338 1364 */ 1339 public ComputeStyleListWorker(List<? extends OsmPrimitive> input, int from, int to) { 1340 this.styleList = new ArrayList<>(to - from); 1365 public ComputeStyleListWorker(final List<? extends OsmPrimitive> input, int from, int to, List<StyleRecord> output) { 1341 1366 this.input = input; 1342 1367 this.from = from; 1343 1368 this.to = to; 1369 this.output = output; 1344 1370 } 1345 1371 … … 1352 1378 } 1353 1379 } 1354 return styleList;1380 return output; 1355 1381 } 1356 1382 … … 1400 1426 StyleList sl = styles.get(osm, circum, nc); 1401 1427 for (ElemStyle s : sl) { 1402 styleList.add(new StyleRecord(s, osm, flags));1428 output.add(new StyleRecord(s, osm, flags)); 1403 1429 } 1404 1430 } … … 1408 1434 for (ElemStyle s : sl) { 1409 1435 if (drawMultipolygon && drawArea && s instanceof AreaElemStyle && (flags & FLAG_DISABLED) == 0) { 1410 styleList.add(new StyleRecord(s, osm, flags));1436 output.add(new StyleRecord(s, osm, flags)); 1411 1437 } else if (drawRestriction && s instanceof NodeElemStyle) { 1412 styleList.add(new StyleRecord(s, osm, flags));1438 output.add(new StyleRecord(s, osm, flags)); 1413 1439 } 1414 1440 } … … 1421 1447 continue; 1422 1448 } 1423 styleList.add(new StyleRecord(s, osm, flags)); 1424 } 1425 } 1426 } 1427 1428 final List<ComputeStyleListWorker> tasks = new ArrayList<>(); 1429 final List<StyleRecord> allStyleElems = new ArrayList<>(); 1449 output.add(new StyleRecord(s, osm, flags)); 1450 } 1451 } 1452 } 1453 List<Node> nodes = data.searchNodes(bbox); 1454 List<Way> ways = data.searchWays(bbox); 1455 List<Relation> relations = data.searchRelations(bbox); 1456 1457 final List<StyleRecord> allStyleElems = new ArrayList<>(nodes.size()+ways.size()+relations.size()); 1430 1458 1431 1459 class ConcurrentTasksHelper { 1432 void createTasks(List<? extends OsmPrimitive> prims) {1433 int bucketsize = Math.max(100, prims.size()/noThreads/3);1434 for (int i=0; i*bucketsize < prims.size(); i++) {1435 tasks.add(new ComputeStyleListWorker(prims, i*bucketsize, Math.min((i+1)*bucketsize, prims.size())));1436 }1437 }1438 1460 1439 void runIt() { 1440 if (tasks.size() == 1) { 1461 void process(List<? extends OsmPrimitive> prims) { 1462 final List<ComputeStyleListWorker> tasks = new ArrayList<>(); 1463 final int bucketsize = Math.max(100, prims.size()/noThreads/3); 1464 final int noBuckets = (prims.size() + bucketsize - 1) / bucketsize; 1465 final boolean singleThread = noThreads == 1 || noBuckets == 1; 1466 for (int i=0; i<noBuckets; i++) { 1467 int from = i*bucketsize; 1468 int to = Math.min((i+1)*bucketsize, prims.size()); 1469 List<StyleRecord> target = singleThread ? allStyleElems : new ArrayList<StyleRecord>(to - from); 1470 tasks.add(new ComputeStyleListWorker(prims, from, to, target)); 1471 } 1472 if (singleThread) { 1441 1473 try { 1442 allStyleElems.addAll(tasks.get(0).call()); 1474 for (ComputeStyleListWorker task : tasks) { 1475 task.call(); 1476 } 1443 1477 } catch (Exception ex) { 1444 1478 throw new RuntimeException(ex); … … 1462 1496 // (Could be synchronized, but try to avoid this for 1463 1497 // performance reasons.) 1464 helper.createTasks(data.searchRelations(bbox)); 1465 helper.runIt(); 1466 1467 tasks.clear(); 1468 helper.createTasks(data.searchNodes(bbox)); 1469 helper.createTasks(data.searchWays(bbox)); 1470 helper.runIt(); 1471 1498 helper.process(relations); 1499 @SuppressWarnings("unchecked") 1500 List<OsmPrimitive> nodesAndWays = (List) new CompositeList(nodes, ways); 1501 helper.process(nodesAndWays); 1472 1502 1473 1503 if (Main.isTraceEnabled()) {
Note:
See TracChangeset
for help on using the changeset viewer.