rendering performance optimization

This commit is contained in:
Bane Stojkovic
2025-05-08 22:55:52 +02:00
parent b2dcf354e6
commit e4f7fb40d7
8 changed files with 63 additions and 40 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
<configuration default="false" name="DIYLCStarter" type="Application" factoryName="Application" nameIsGenerated="true"> <configuration default="false" name="DIYLCStarter" type="Application" factoryName="Application" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="org.diylc.DIYLCStarter" /> <option name="MAIN_CLASS_NAME" value="org.diylc.DIYLCStarter" />
<module name="diylc-swing" /> <module name="diylc-swing" />
<option name="VM_PARAMETERS" value="-Xms1024m -Xmx4096m -Dorg.diylc.scriptRun=true -Dfile.encoding=UTF-8 --add-exports java.desktop/com.apple.eawt.event=ALL-UNNAMED --add-exports java.desktop/com.apple.eio=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens java.desktop/java.awt.geom=ALL-UNNAMED" /> <option name="VM_PARAMETERS" value="-Xms1024m -Xmx4096m -Ddorg.diylc.debugAreaPerformance=true -Dorg.diylc.scriptRun=true -Dfile.encoding=UTF-8 --add-exports java.desktop/com.apple.eawt.event=ALL-UNNAMED --add-exports java.desktop/com.apple.eio=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED --add-opens java.desktop/java.awt.geom=ALL-UNNAMED" />
<extension name="coverage"> <extension name="coverage">
<pattern> <pattern>
<option name="PATTERN" value="org.diylc.*" /> <option name="PATTERN" value="org.diylc.*" />
@@ -63,6 +63,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.apache.log4j.Logger;
import org.diylc.common.ObjectCache; import org.diylc.common.ObjectCache;
import org.diylc.common.ZoomableStroke; import org.diylc.common.ZoomableStroke;
import org.diylc.core.IDrawingObserver; import org.diylc.core.IDrawingObserver;
@@ -81,7 +82,12 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
public static int LINE_SENSITIVITY_MARGIN = 2; public static int LINE_SENSITIVITY_MARGIN = 2;
public static int CURVE_SENSITIVITY = 6; public static int CURVE_SENSITIVITY = 6;
private static final Logger LOG = Logger.getLogger(G2DWrapper.class);
public static String DEBUG_AREA_PERFORMANCE = "org.diylc.debugAreaPerformance";
private boolean drawingComponent = false; private boolean drawingComponent = false;
private final boolean debugAreaPerformance;
private boolean trackingAllowed = true; private boolean trackingAllowed = true;
private boolean trackingContinuityAllowed = false; private boolean trackingContinuityAllowed = false;
private boolean trackingContinuityPositive = true; private boolean trackingContinuityPositive = true;
@@ -115,6 +121,8 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
public G2DWrapper(Graphics2D canvasGraphics, double zoom) { public G2DWrapper(Graphics2D canvasGraphics, double zoom) {
super(); super();
this.canvasGraphics = canvasGraphics; this.canvasGraphics = canvasGraphics;
String debugAreaPerformanceStr = System.getProperty(DEBUG_AREA_PERFORMANCE);
debugAreaPerformance = "true".equalsIgnoreCase(debugAreaPerformanceStr);
this.zoom = zoom; this.zoom = zoom;
currentArea = new Area(); currentArea = new Area();
continuityPositiveAreas = new HashMap<String, Area>(); continuityPositiveAreas = new HashMap<String, Area>();
@@ -236,9 +244,19 @@ class G2DWrapper extends Graphics2D implements IDrawingObserver {
Area area = new Area(s); Area area = new Area(s);
area.transform(currentTx); area.transform(currentTx);
if (trackingAllowed) Area areaBefore = null;
if (debugAreaPerformance) {
areaBefore = new Area(currentArea);
}
if (trackingAllowed) {
currentArea.add(area); currentArea.add(area);
if (debugAreaPerformance && currentArea.equals(areaBefore)) {
LOG.warn("Detected unnecessary shape tracking at", new Throwable());
}
}
Map<String, Area> toAdd; Map<String, Area> toAdd;
if (trackingContinuityAllowed) { if (trackingContinuityAllowed) {
if (trackingContinuityPositive) if (trackingContinuityPositive)
@@ -355,6 +355,7 @@ public abstract class AbstractLeadedComponent<T> extends AbstractLabeledComponen
if (getDisplay() == Display.BOTH) { if (getDisplay() == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString()); label = getName() + " " + (getValue() == null ? "" : getValue().toString());
} }
if (!label.isEmpty()) {
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d); Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
// Don't offset in outline mode. // Don't offset in outline mode.
int offset = outlineMode ? 0 : getLabelOffset((int) length, (int) width, (int) textRect.getWidth()); int offset = outlineMode ? 0 : getLabelOffset((int) length, (int) width, (int) textRect.getWidth());
@@ -366,9 +367,8 @@ public abstract class AbstractLeadedComponent<T> extends AbstractLabeledComponen
offset = -offset; offset = -offset;
} }
drawingObserver.startTracking();
if (getMoveLabel()) { if (getMoveLabel()) {
drawingObserver.startTracking();
g2d.setTransform(oldTransform); g2d.setTransform(oldTransform);
g2d.translate(getPoints()[2].getX(), getPoints()[2].getY()); g2d.translate(getPoints()[2].getX(), getPoints()[2].getY());
if (getLabelOriantation() != LabelOriantation.Horizontal) { if (getLabelOriantation() != LabelOriantation.Horizontal) {
@@ -378,17 +378,20 @@ public abstract class AbstractLeadedComponent<T> extends AbstractLabeledComponen
g2d.setTransform(oldTransform); g2d.setTransform(oldTransform);
} else { } else {
if (isStanding() || getLabelOriantation() == LabelOriantation.Horizontal) { if (isStanding() || getLabelOriantation() == LabelOriantation.Horizontal) {
drawingObserver.startTracking();
g2d.setTransform(oldTransform); g2d.setTransform(oldTransform);
double x = (getPoints()[0].getX() + getPoints()[1].getX() - length) / 2.0; double x = (getPoints()[0].getX() + getPoints()[1].getX() - length) / 2.0;
double y = (getPoints()[0].getY() + getPoints()[1].getY() - width) / 2.0; double y = (getPoints()[0].getY() + getPoints()[1].getY() - width) / 2.0;
g2d.drawString(label, (int) (x + (length - textRect.getWidth()) / 2 + offset), g2d.drawString(label, (int) (x + (length - textRect.getWidth()) / 2 + offset),
(int) (y + calculateLabelYOffset(shapeRect, textRect, fontMetrics))); (int) (y + calculateLabelYOffset(shapeRect, textRect, fontMetrics)));
} else { } else {
drawingObserver.stopTracking();
g2d.drawString(label, (int) (length - textRect.getWidth()) / 2 + offset, g2d.drawString(label, (int) (length - textRect.getWidth()) / 2 + offset,
calculateLabelYOffset(shapeRect, textRect, fontMetrics)); calculateLabelYOffset(shapeRect, textRect, fontMetrics));
g2d.setTransform(oldTransform); g2d.setTransform(oldTransform);
} }
} }
}
// if (getLabelOriantation() == LabelOriantation.Horizontal) { // if (getLabelOriantation() == LabelOriantation.Horizontal) {
// //
// drawCenteredText(g2d, label, getNewPoints()[2].getX(), getNewPoints()[2].getX(), HorizontalAlignment.CENTER, VerticalAlignment.CENTER); // drawCenteredText(g2d, label, getNewPoints()[2].getX(), getNewPoints()[2].getX(), HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
@@ -109,6 +109,7 @@ public class SolderPad extends AbstractTransparentComponent<Void>
g2d.fill(new Rectangle2D.Double(point.getX() - diameter / 2, point.getY() - diameter / 2, g2d.fill(new Rectangle2D.Double(point.getX() - diameter / 2, point.getY() - diameter / 2,
diameter, diameter)); diameter, diameter));
} }
drawingObserver.stopTracking();
drawingObserver.stopTrackingContinuityArea(); drawingObserver.stopTrackingContinuityArea();
if (gerberDrawingObserver != null) if (gerberDrawingObserver != null)
gerberDrawingObserver.stopGerberOutput(org.diylc.core.gerber.GerberLayer.SolderMaskBot); gerberDrawingObserver.stopGerberOutput(org.diylc.core.gerber.GerberLayer.SolderMaskBot);
@@ -166,8 +166,6 @@ public class OpenJack1_4 extends AbstractMultiPartComponent<OpenJackType> {
if (body[3] != null) if (body[3] != null)
g2d.draw(body[3]); g2d.draw(body[3]);
drawingObserver.startTracking();
// draw labels // draw labels
if (showLabels) { if (showLabels) {
g2d.setColor(BASE_COLOR.darker()); g2d.setColor(BASE_COLOR.darker());
@@ -110,6 +110,7 @@ public class SchallerMegaSwitch extends AbstractAngledComponent<String> implemen
} }
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BASE_COLOR); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : BASE_COLOR);
g2d.fill(body[0]); g2d.fill(body[0]);
drawingObserver.stopTracking();
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : WAFER_COLOR); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : WAFER_COLOR);
g2d.fill(body[1]); g2d.fill(body[1]);
g2d.setComposite(oldComposite); g2d.setComposite(oldComposite);
@@ -308,6 +308,9 @@ public class PotentiometerPanel extends AbstractPotentiometer implements ILayere
g2d.draw(shape); g2d.draw(shape);
} }
} }
drawingObserver.stopTracking();
// Draw caption. // Draw caption.
g2d.setFont(project.getFont()); g2d.setFont(project.getFont());
@@ -375,14 +375,13 @@ public class TrimmerPotentiometer extends AbstractPotentiometer {
Shape shaftShape = getBody()[1]; Shape shaftShape = getBody()[1];
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
if (mainShape != null) { if (mainShape != null) {
g2d.setColor(bodyColor); g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
Composite oldComposite = g2d.getComposite(); Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) { if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
} }
if (!outlineMode) {
g2d.fill(mainShape); g2d.fill(mainShape);
} drawingObserver.stopTracking();
if (!outlineMode && shaftShape != null) { if (!outlineMode && shaftShape != null) {
g2d.setColor(SHAFT_COLOR); g2d.setColor(SHAFT_COLOR);
g2d.fill(shaftShape); g2d.fill(shaftShape);