mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
painting optimization
This commit is contained in:
+34
-16
@@ -6,6 +6,7 @@ import java.awt.Graphics2D;
|
|||||||
import java.awt.GraphicsConfiguration;
|
import java.awt.GraphicsConfiguration;
|
||||||
import java.awt.GraphicsDevice;
|
import java.awt.GraphicsDevice;
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
|
import java.awt.Image;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
@@ -46,9 +47,11 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
|
|
||||||
private IPlugInPort plugInPort;
|
private IPlugInPort plugInPort;
|
||||||
|
|
||||||
private VolatileImage bufferImage;
|
private Image bufferImage;
|
||||||
private GraphicsConfiguration screenGraphicsConfiguration;
|
private GraphicsConfiguration screenGraphicsConfiguration;
|
||||||
|
|
||||||
|
private static boolean USE_HARDWARE_ACCELLERATION = false;
|
||||||
|
|
||||||
private static final EnumSet<DrawOption> drawOptions = EnumSet.of(DrawOption.GRID,
|
private static final EnumSet<DrawOption> drawOptions = EnumSet.of(DrawOption.GRID,
|
||||||
DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.ANTIALIASING,
|
DrawOption.SELECTION, DrawOption.ZOOM, DrawOption.ANTIALIASING,
|
||||||
DrawOption.CONTROL_POINTS);
|
DrawOption.CONTROL_POINTS);
|
||||||
@@ -95,9 +98,13 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void createBufferImage() {
|
protected void createBufferImage() {
|
||||||
bufferImage = screenGraphicsConfiguration.createCompatibleVolatileImage(getWidth(),
|
if (USE_HARDWARE_ACCELLERATION) {
|
||||||
getHeight());
|
bufferImage = screenGraphicsConfiguration.createCompatibleVolatileImage(getWidth(),
|
||||||
bufferImage.validate(screenGraphicsConfiguration);
|
getHeight());
|
||||||
|
((VolatileImage) bufferImage).validate(screenGraphicsConfiguration);
|
||||||
|
} else {
|
||||||
|
bufferImage = createImage(getWidth(), getHeight());
|
||||||
|
}
|
||||||
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
||||||
plugInPort.draw(g2d, drawOptions);
|
plugInPort.draw(g2d, drawOptions);
|
||||||
}
|
}
|
||||||
@@ -109,21 +116,32 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
|||||||
}
|
}
|
||||||
if (bufferImage == null) {
|
if (bufferImage == null) {
|
||||||
createBufferImage();
|
createBufferImage();
|
||||||
|
} else {
|
||||||
|
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
||||||
|
plugInPort.draw(g2d, drawOptions);
|
||||||
}
|
}
|
||||||
do {
|
if (USE_HARDWARE_ACCELLERATION) {
|
||||||
try {
|
VolatileImage volatileImage = (VolatileImage) bufferImage;
|
||||||
if (bufferImage.contentsLost()) {
|
do {
|
||||||
|
try {
|
||||||
|
if (volatileImage.contentsLost()) {
|
||||||
|
createBufferImage();
|
||||||
|
}
|
||||||
|
int validation = volatileImage.validate(screenGraphicsConfiguration);
|
||||||
|
if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
|
||||||
|
createBufferImage();
|
||||||
|
}
|
||||||
|
g.drawImage(bufferImage, 0, 0, this);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
createBufferImage();
|
createBufferImage();
|
||||||
}
|
}
|
||||||
int validation = bufferImage.validate(screenGraphicsConfiguration);
|
} while (volatileImage == null || volatileImage.contentsLost());
|
||||||
if (validation == VolatileImage.IMAGE_INCOMPATIBLE) {
|
} else {
|
||||||
createBufferImage();
|
Graphics2D g2d = (Graphics2D) bufferImage.getGraphics();
|
||||||
}
|
plugInPort.draw(g2d, drawOptions);
|
||||||
g.drawImage(bufferImage, 0, 0, this);
|
g.drawImage(bufferImage, 0, 0, this);
|
||||||
} catch (NullPointerException e) {
|
bufferImage.flush();
|
||||||
createBufferImage();
|
}
|
||||||
}
|
|
||||||
} while (bufferImage == null || bufferImage.contentsLost());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
-1
@@ -92,7 +92,6 @@ public class CanvasPlugin implements IPlugIn {
|
|||||||
refreshSize();
|
refreshSize();
|
||||||
break;
|
break;
|
||||||
case REPAINT:
|
case REPAINT:
|
||||||
canvasPanel.invalidateCache();
|
|
||||||
canvasPanel.repaint();
|
canvasPanel.repaint();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user