- Timestamp:
- 2016-08-01T22:56:04+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm/visitor/paint
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
r10662 r10697 37 37 import java.util.concurrent.ForkJoinTask; 38 38 import java.util.concurrent.RecursiveTask; 39 import java.util.function.Supplier; 39 40 40 41 import javax.swing.AbstractButton; … … 63 64 import org.openstreetmap.josm.gui.mappaint.StyleElementList; 64 65 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 65 import org.openstreetmap.josm.gui.mappaint.mapcss.Selector;66 66 import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement; 67 67 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement; … … 192 192 } 193 193 194 p rivatestatic class StyleRecord implements Comparable<StyleRecord> {194 public static class StyleRecord implements Comparable<StyleRecord> { 195 195 private final StyleElement style; 196 196 private final OsmPrimitive osm; … … 240 240 return Float.compare(this.style.objectZIndex, other.style.objectZIndex); 241 241 } 242 } 243 244 /** 245 * Saves benchmark data for tests. 246 */ 247 public static class BenchmarkData { 248 public long generateTime; 249 public long sortTime; 250 public long drawTime; 251 public Map<Class<? extends StyleElement>, Integer> styleElementCount; 252 public boolean skipDraw; 253 254 private void recordElementStats(List<StyleRecord> srs) { 255 styleElementCount = new HashMap<>(); 256 for (StyleRecord r : srs) { 257 Class<? extends StyleElement> klass = r.style.getClass(); 258 Integer count = styleElementCount.get(klass); 259 if (count == null) { 260 count = 0; 261 } 262 styleElementCount.put(klass, count + 1); 263 } 264 265 } 266 } 267 268 /* can be set by tests, if detailed benchmark data is requested */ 269 public BenchmarkData benchmarkData; 242 243 /** 244 * Get the style for this style element. 245 * @return The style 246 */ 247 public StyleElement getStyle() { 248 return style; 249 } 250 } 270 251 271 252 private static Map<Font, Boolean> IS_GLYPH_VECTOR_DOUBLE_TRANSLATION_BUG = new HashMap<>(); … … 373 354 private boolean leftHandTraffic; 374 355 private Object antialiasing; 356 357 private Supplier<RenderBenchmarkCollector> benchmarkFactory = RenderBenchmarkCollector.defaultBenchmarkSupplier(); 375 358 376 359 /** … … 1902 1885 } 1903 1886 1887 /** 1888 * Sets the factory that creates the benchmark data receivers. 1889 * @param benchmarkFactory The factory. 1890 * @since 10697 1891 */ 1892 public void setBenchmarkFactory(Supplier<RenderBenchmarkCollector> benchmarkFactory) { 1893 this.benchmarkFactory = benchmarkFactory; 1894 } 1895 1904 1896 @Override 1905 1897 public void render(final DataSet data, boolean renderVirtualNodes, Bounds bounds) { 1898 RenderBenchmarkCollector benchmark = benchmarkFactory.get(); 1906 1899 BBox bbox = bounds.toBBox(); 1907 1900 getSettings(renderVirtualNodes); 1908 boolean benchmarkOutput = Main.isTraceEnabled() || Main.pref.getBoolean("mappaint.render.benchmark", false);1909 boolean benchmark = benchmarkOutput || benchmarkData != null;1910 1901 1911 1902 data.getReadLock().lock(); … … 1913 1904 highlightWaySegments = data.getHighlightedWaySegments(); 1914 1905 1915 long timeStart = 0, timeGenerateDone = 0, timeSortingDone = 0, timeFinished; 1916 if (benchmark) { 1917 timeStart = System.currentTimeMillis(); 1918 if (benchmarkOutput) { 1919 System.err.print("BENCHMARK: rendering "); 1920 } 1921 } 1906 benchmark.renderStart(circum); 1922 1907 1923 1908 List<Node> nodes = data.searchNodes(bbox); … … 1937 1922 Math.max(100, (nodes.size() + ways.size()) / THREAD_POOL.getParallelism() / 3))); 1938 1923 1939 if (benchmark) { 1940 timeGenerateDone = System.currentTimeMillis(); 1941 if (benchmarkOutput) { 1942 System.err.print("phase 1 (calculate styles): " + Utils.getDurationString(timeGenerateDone - timeStart)); 1943 } 1944 if (benchmarkData != null) { 1945 benchmarkData.generateTime = timeGenerateDone - timeStart; 1946 } 1924 if (!benchmark.renderSort()) { 1925 return; 1947 1926 } 1948 1927 1949 1928 Collections.sort(allStyleElems); // TODO: try parallel sort when switching to Java 8 1950 1929 1951 if (benchmarkData != null) { 1952 timeSortingDone = System.currentTimeMillis(); 1953 benchmarkData.sortTime = timeSortingDone - timeGenerateDone; 1954 if (benchmarkData.skipDraw) { 1955 benchmarkData.recordElementStats(allStyleElems); 1956 return; 1957 } 1930 if (!benchmark.renderDraw(allStyleElems)) { 1931 return; 1958 1932 } 1959 1933 … … 1969 1943 } 1970 1944 1971 if (benchmark) {1972 timeFinished = System.currentTimeMillis();1973 if (benchmarkData != null) {1974 benchmarkData.drawTime = timeFinished - timeGenerateDone;1975 benchmarkData.recordElementStats(allStyleElems);1976 }1977 if (benchmarkOutput) {1978 System.err.println("; phase 2 (draw): " + Utils.getDurationString(timeFinished - timeGenerateDone) +1979 "; total: " + Utils.getDurationString(timeFinished - timeStart) +1980 " (scale: " + circum + " zoom level: " + Selector.GeneralSelector.scale2level(circum) + ')');1981 }1982 }1983 1984 1945 drawVirtualNodes(data, bbox); 1946 1947 benchmark.renderDone(); 1985 1948 } finally { 1986 1949 data.getReadLock().unlock();
Note:
See TracChangeset
for help on using the changeset viewer.