X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram.connection%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fconnection%2Frendering%2FStyledRouteGraphRenderer.java;h=fa14474691f281ad312df693dec50e242bdb9503;hb=refs%2Fchanges%2F06%2F4106%2F2;hp=b084e5875714938026400e5a8b6c938659e3ca71;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/rendering/StyledRouteGraphRenderer.java b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/rendering/StyledRouteGraphRenderer.java index b084e5875..fa1447469 100644 --- a/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/rendering/StyledRouteGraphRenderer.java +++ b/bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/rendering/StyledRouteGraphRenderer.java @@ -36,9 +36,13 @@ public class StyledRouteGraphRenderer implements IRouteGraphRenderer, Serializab protected final ConnectionStyle style; + private static class Cache { + Path2D path = new Path2D.Double(); + THashSet branchPoints = new THashSet<>(); + } + // Caches to avoid creating new objects all the time during rendering - protected transient Path2D path; - protected transient THashSet branchPoints; + protected static ThreadLocal caches = ThreadLocal.withInitial(() -> new Cache()); public StyledRouteGraphRenderer(ConnectionStyle style) { if (style == null) @@ -52,14 +56,18 @@ public class StyledRouteGraphRenderer implements IRouteGraphRenderer, Serializab @Override public void render(Graphics2D g, RouteGraph rg) { - if (path == null) - path = new Path2D.Double(); + Cache cache = caches.get(); + Path2D path = cache.path; + THashSet branchPoints = cache.branchPoints; + path.reset(); rg.getPath2D(path); + PathModifier pm = (PathModifier) g.getRenderingHint(ConnectionRenderingHints.KEY_PATH_MODIFIER); + if (pm != null) { + path = pm.modify(path); + } style.drawPath(g, path, false); - if (branchPoints == null) - branchPoints = new THashSet(); branchPoints.clear(); for(RouteLine line : rg.getLines()) { renderLine(g, line, false);