deal with JAVA2D update problem for complex sketches

This commit is contained in:
benfry
2011-03-10 22:48:54 +00:00
parent 53e15e43c7
commit 818fd2164f
3 changed files with 29 additions and 14 deletions
+3 -11
View File
@@ -1422,7 +1422,6 @@ public class PApplet extends Applet
}
//synchronized public void paint(Graphics screen) { // shutting off for 0146
public void paint(Graphics screen) {
// ignore the very first call to paint, since it's coming
// from the o.s., and the applet will soon update itself anyway.
@@ -1447,16 +1446,13 @@ public class PApplet extends Applet
// (also prevents over-drawing when using PGraphicsOpenGL)
if (g != null) {
// added synchronization for 0194 because of flicker issues with JAVA2D
//
synchronized (g) {
if (g.image != null) {
// http://code.google.com/p/processing/issues/detail?id=558
if (g.image != null) {
synchronized (g.image) {
screen.drawImage(g.image, 0, 0, null);
}
}
}
// if ((g != null) && (g.image != null)) {
// screen.drawImage(g.image, 0, 0, null);
// }
}
@@ -1571,9 +1567,6 @@ public class PApplet extends Applet
return;
}
//System.out.println("handleDraw() " + frameCount);
synchronized (g) {
g.beginDraw();
if (recorder != null) {
recorder.beginDraw();
@@ -1636,7 +1629,6 @@ public class PApplet extends Applet
frameRateLastNanos = now;
frameCount++;
}
repaint();
getToolkit().sync(); // force repaint now (proper method)
+21 -3
View File
@@ -50,6 +50,8 @@ import java.awt.image.*;
public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ {
public Graphics2D g2;
protected BufferedImage offscreen;
GeneralPath gpath;
/// break the shape at the next vertex (next vertex() call is a moveto())
@@ -122,8 +124,18 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ {
protected void allocate() {
// System.out.println("PGraphicsJava2D allocate() " + width + " " + height);
// System.out.println("allocate " + Thread.currentThread().getName());
// Tried this with RGB instead of ARGB for the primarySurface version,
// but didn't see any performance difference (OS X 10.6, Java 6u24)
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
g2 = (Graphics2D) image.getGraphics();
if (primarySurface) {
offscreen = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
g2 = (Graphics2D) offscreen.getGraphics();
} else {
// if the buffer's offscreen anyway, no need for the extra offscreen buffer
g2 = (Graphics2D) image.getGraphics();
}
// can't un-set this because this may be only a resize
// http://dev.processing.org/bugs/show_bug.cgi?id=463
//defaultsInited = false;
@@ -161,8 +173,14 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ {
// copy of all the pixels to the surface.. so that's kind of a mess.
//updatePixels();
// TODO this is probably overkill for most tasks...
if (!primarySurface) {
if (primarySurface) {
// don't copy the pixels/data elements of the buffered image directly,
// since it'll disable the nice speedy pipeline stuff, sending all drawing
// into a world of suck that's rough 6 trillion times slower.
image.getGraphics().drawImage(offscreen, 0, 0, null);
} else {
// TODO this is probably overkill for most tasks...
loadPixels();
}
modified = true;
+5
View File
@@ -1,4 +1,9 @@
0195 core
X deal with bad screen updates for sketches running < 60 fps in JAVA2D
X had to add an additional offscreen buffer, which is more memory
X however hopefully not a problem on modern machines
X and probably no worse than what MemoryImageSource does
X removed large synchronized block
_ bug: textAlign(RIGHT) is shutting off native fonts