diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index e87f355bc..324d37e57 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -6637,6 +6637,11 @@ public class PGraphics extends PImage implements PConstants { // BACKGROUND + public void clear() { + showMethodWarning("clear"); + } + + /** * ( begin auto-generated from background.xml ) * diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index dafb47f84..3cd339176 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -1817,6 +1817,33 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { // BACKGROUND + + @Override + public void clear() { + clearPixels(0); + } + + + int[] clearPixels; + + protected void clearPixels(int color) { + // Create a small array that can be used to set the pixels several times. + // Using a single-pixel line of length 'width' is a tradeoff between + // speed (setting each pixel individually is too slow) and memory + // (an array for width*height would waste lots of memory if it stayed + // resident, and would terrify the gc if it were re-created on each trip + // to background(). + WritableRaster raster = ((BufferedImage) image).getRaster(); +// WritableRaster raster = image.getRaster(); + if ((clearPixels == null) || (clearPixels.length < width)) { + clearPixels = new int[width]; + } + Arrays.fill(clearPixels, backgroundColor); + for (int i = 0; i < height; i++) { + raster.setDataElements(0, i, width, 1, clearPixels); + } + } + // background() methods inherited from PGraphics, along with the // PImage version of backgroundImpl(), since it just calls set(). @@ -1824,26 +1851,11 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { //public void backgroundImpl(PImage image) - int[] clearPixels; - @Override public void backgroundImpl() { if (backgroundAlpha) { - // Create a small array that can be used to set the pixels several times. - // Using a single-pixel line of length 'width' is a tradeoff between - // speed (setting each pixel individually is too slow) and memory - // (an array for width*height would waste lots of memory if it stayed - // resident, and would terrify the gc if it were re-created on each trip - // to background(). - WritableRaster raster = ((BufferedImage) image).getRaster(); -// WritableRaster raster = image.getRaster(); - if ((clearPixels == null) || (clearPixels.length < width)) { - clearPixels = new int[width]; - } - Arrays.fill(clearPixels, backgroundColor); - for (int i = 0; i < height; i++) { - raster.setDataElements(0, i, width, 1, clearPixels); - } + clearPixels(backgroundColor); + } else { Color bgColor = new Color(backgroundColor); // seems to fire an additional event that causes flickering, diff --git a/core/todo.txt b/core/todo.txt index 526593c51..37f0d3edb 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -36,10 +36,12 @@ _ delete()/dispose() being used in the movie _ buffer sink methods in movie _ 'newFrame' is 'available', and ready() is part of that -_ loadShape() mess -_ get things out of PGraphics -_ separate PShape2/3D from OpenGL -_ incorporate SVG loader into the 2D class +_ loadShape() cleanup +_ remove PShape2D/3D +_ make PShapeOpenGL a cache object +_ make PShapeOBJ the 3D loader +o separate PShape2/3D from OpenGL +o incorporate SVG loader into the 2D class _ loadPixels() implementation