Skip to content
Snippets Groups Projects
Commit 80d145ce authored by stepan's avatar stepan
Browse files

Grid AWT: cache last used BasicStroke

parent 411e8423
Branches
No related tags found
No related merge requests found
...@@ -72,6 +72,7 @@ public class Graphics2DDevice implements GridDevice { ...@@ -72,6 +72,7 @@ public class Graphics2DDevice implements GridDevice {
private Graphics2D graphics; private Graphics2D graphics;
private final boolean graphicsIsExclusive; private final boolean graphicsIsExclusive;
private DrawingContext cachedContext; private DrawingContext cachedContext;
private BasicStroke stokeCache;
/** /**
* @param graphics Object that should be used for the drawing. * @param graphics Object that should be used for the drawing.
...@@ -329,7 +330,7 @@ public class Graphics2DDevice implements GridDevice { ...@@ -329,7 +330,7 @@ public class Graphics2DDevice implements GridDevice {
return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
} }
private static BasicStroke getStrokeFromCtx(DrawingContext ctx) { private BasicStroke getStrokeFromCtx(DrawingContext ctx) {
byte[] type = ctx.getLineType(); byte[] type = ctx.getLineType();
double width = ctx.getLineWidth(); double width = ctx.getLineWidth();
int lineJoin = fromGridLineJoin(ctx.getLineJoin()); int lineJoin = fromGridLineJoin(ctx.getLineJoin());
...@@ -338,7 +339,10 @@ public class Graphics2DDevice implements GridDevice { ...@@ -338,7 +339,10 @@ public class Graphics2DDevice implements GridDevice {
if (type == DrawingContext.GRID_LINE_BLANK) { if (type == DrawingContext.GRID_LINE_BLANK) {
return blankStroke; return blankStroke;
} else if (type == DrawingContext.GRID_LINE_SOLID) { } else if (type == DrawingContext.GRID_LINE_SOLID) {
return new BasicStroke((float) (width), endCap, lineJoin, lineMitre); if (stokeCache == null || !areEqual(stokeCache, (float) width, endCap, lineJoin, lineMitre)) {
stokeCache = new BasicStroke((float) (width), endCap, lineJoin, lineMitre);
}
return stokeCache;
} }
float[] pattern = new float[type.length]; float[] pattern = new float[type.length];
for (int i = 0; i < pattern.length; i++) { for (int i = 0; i < pattern.length; i++) {
...@@ -383,4 +387,11 @@ public class Graphics2DDevice implements GridDevice { ...@@ -383,4 +387,11 @@ public class Graphics2DDevice implements GridDevice {
private static int iround(double val) { private static int iround(double val) {
return (int) Math.round(val); return (int) Math.round(val);
} }
private static boolean areEqual(BasicStroke s, float width, int endCap, int lineJoin, float lineMitre) {
return s.getLineWidth() == width &&
s.getEndCap() == endCap &&
s.getLineJoin() == lineJoin &&
s.getMiterLimit() == lineMitre;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment