From f9ddbadb61375c54b4e3c13b438bf8bc26a5e6d7 Mon Sep 17 00:00:00 2001 From: benfry Date: Sat, 12 Nov 2011 21:08:00 +0000 Subject: [PATCH] deal with blank canvas performance and Java2D (issue #729) --- core/src/processing/core/PApplet.java | 5 ++--- core/src/processing/core/PGraphicsJava2D.java | 16 ++++++++-------- core/todo.txt | 6 +++--- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 1f73b646c..46e5eab9f 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -236,7 +236,6 @@ public class PApplet extends Applet * inside setup() is a joke, since it's long since the AWT has been invoked. */ static public boolean useQuartz = true; - //static public String useQuartz = "true"; /** * Modifier flags for the shortcut key used to trigger menus. @@ -973,11 +972,11 @@ public class PApplet extends Applet int count; Object objects[]; Method methods[]; - + Object[] convArgs = new Object[] { }; // convenience version for no args public void handle() { - handle(new Object[] { }); + handle(convArgs); } public void handle(Object oargs[]) { diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index 44d38df7a..4bbcbfb27 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -122,22 +122,22 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { // broken out because of subclassing for opengl 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). // For 0196, also attempted RGB instead of ARGB, but that causes // strange things to happen with blending. - image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); +// image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); if (primarySurface) { -// image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); -// offscreen = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + // Needs to be RGB otherwise there's a major performance hit [0204] + // http://code.google.com/p/processing/issues/detail?id=729 + image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); offscreen = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); g2 = (Graphics2D) offscreen.getGraphics(); } else { -// image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - // if the buffer's offscreen anyway, no need for the extra offscreen buffer + // Since this buffer's offscreen anyway, no need for the extra offscreen + // buffer. However, unlike the primary surface, this feller needs to be + // ARGB so that blending ("alpha" compositing) will work properly. + image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); g2 = (Graphics2D) image.getGraphics(); } diff --git a/core/todo.txt b/core/todo.txt index 66bf413a5..0ace50de2 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -1,4 +1,7 @@ 0204 core +X Abnormal high Java CPU usage at empty sketch with draw() +X http://code.google.com/p/processing/issues/detail?id=729 +X https://forum.processing.org/topic/absurd-java-cpu-usage-at-empty-sketch-with-draw _ add inputPath() and outputPath() -> sketch folder or sd card @@ -147,9 +150,6 @@ X remove textMode(SCREEN) references 2.0 -_ Abnormal high Java CPU usage at empty sketch with draw() -_ http://code.google.com/p/processing/issues/detail?id=729 -_ https://forum.processing.org/topic/absurd-java-cpu-usage-at-empty-sketch-with-draw _ PNode.getChildren() shouldn't make a new array.. toArray() can do that _ text using textMode(SCREEN) not displayed in Processing 1.5.1 _ http://code.google.com/p/processing/issues/detail?id=741