From 94d7dc1e445f781e057c15b0e47d847a09a01cb6 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Wed, 17 Jun 2015 19:46:27 -0400 Subject: [PATCH] remove dead code, remove danger, rename methods to avoid mix-ups --- core/src/processing/core/PConstants.java | 2 +- .../processing/core/PGraphicsDanger2D.java | 198 ------------------ core/src/processing/core/PSurfaceAWT.java | 51 ++--- core/src/processing/core/PSurfaceDanger.java | 79 ------- core/src/processing/core/PSurfaceNone.java | 7 +- 5 files changed, 32 insertions(+), 305 deletions(-) delete mode 100644 core/src/processing/core/PGraphicsDanger2D.java delete mode 100644 core/src/processing/core/PSurfaceDanger.java diff --git a/core/src/processing/core/PConstants.java b/core/src/processing/core/PConstants.java index 30d13f2d8..e2c9941da 100644 --- a/core/src/processing/core/PConstants.java +++ b/core/src/processing/core/PConstants.java @@ -67,7 +67,7 @@ public interface PConstants { static final String OPENGL = P3D; // Experimental, higher-performance Java 2D renderer (but no pixel ops) - static final String E2D = PGraphicsDanger2D.class.getName(); +// static final String E2D = PGraphicsDanger2D.class.getName(); // Experimental JavaFX renderer; even better 2D performance static final String FX2D = PGraphicsFX2D.class.getName(); diff --git a/core/src/processing/core/PGraphicsDanger2D.java b/core/src/processing/core/PGraphicsDanger2D.java deleted file mode 100644 index b828010fc..000000000 --- a/core/src/processing/core/PGraphicsDanger2D.java +++ /dev/null @@ -1,198 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - Part of the Processing project - http://processing.org - - Copyright (c) 2015 The Processing Foundation - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, version 2.1. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General - Public License along with this library; if not, write to the - Free Software Foundation, Inc., 59 Temple Place, Suite 330, - Boston, MA 02111-1307 USA -*/ - -package processing.core; - - -/** - * Experimental/enhanced renderer that draws directly to the Graphics context - * without an intermediate image. This greatly speeds up performance - * (especially on hidpi displays), but prevents pixel access. It also causes - * some rendering hiccups (frame rate is not as smooth), but that's why it's - * experimental. - * - * Works with both normal and hidpi, without need for an extra E2D_2X. - * - * This is not the final class name, and it's not clear in what form (or if) - * this will ship with 3.0. - */ -public class PGraphicsDanger2D extends PGraphicsJava2D { - // doesn't exist/not necessary because Java2D will do this automatically - //static final boolean HIDPI = true; - //static final boolean HIDPI = false; - - -// public PGraphicsDanger2D() { -// if (HIDPI) { -// pixelFactor = 2; -// } -// } - - - @Override - public PSurface createSurface() { - return surface = new PSurfaceDanger(this); - } - - - @Override - public void beginDraw() { - //g2 = checkImage(); // already set g2 - -// if (HIDPI) { -// g2.scale(2, 2); -// } - - // Calling getGraphics() seems to nuke the smoothing settings - smooth(smooth); - - checkSettings(); - resetMatrix(); // reset model matrix - vertexCount = 0; - } - - - // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . - - - @Override - public void loadPixels() { - nope("loadPixels"); - } - - @Override - public void updatePixels() { - nope("updatePixels"); - } - - @Override - public void updatePixels(int x, int y, int c, int d) { - nope("updatePixels"); - } - - // - - @Override - public int get(int x, int y) { - nope("get"); - return 0; // not reached - } - - @Override - public PImage get(int x, int y, int c, int d) { - nope("get"); - return null; // not reached - } - - @Override - public PImage get() { - nope("get"); - return null; // not reached - } - - @Override - public void set(int x, int y, int argb) { - nope("set"); - } - - @Override - public void set(int x, int y, PImage image) { - nope("set"); - } - - // - - @Override - public void mask(int alpha[]) { - nope("mask"); - } - - @Override - public void mask(PImage alpha) { - nope("mask"); - } - - // - - @Override - public void filter(int kind) { - nope("filter"); - } - - @Override - public void filter(int kind, float param) { - nope("filter"); - } - - // - - @Override - public void copy(int sx1, int sy1, int sx2, int sy2, - int dx1, int dy1, int dx2, int dy2) { - nope("copy"); - } - - @Override - public void copy(PImage src, - int sx1, int sy1, int sx2, int sy2, - int dx1, int dy1, int dx2, int dy2) { - nope("copy"); - } - - // - - public void blend(int sx, int sy, int dx, int dy, int mode) { - nope("blend"); - } - - public void blend(PImage src, - int sx, int sy, int dx, int dy, int mode) { - nope("blend"); - } - - @Override - public void blend(int sx1, int sy1, int sx2, int sy2, - int dx1, int dy1, int dx2, int dy2, int mode) { - nope("blend"); - } - - @Override - public void blend(PImage src, - int sx1, int sy1, int sx2, int sy2, - int dx1, int dy1, int dx2, int dy2, int mode) { - nope("blend"); - } - - // - - @Override - public boolean save(String filename) { - nope("save"); - return false; - } - - // - - protected void nope(String function) { - throw new RuntimeException(function + "() is unavailable with E2D"); - } -} \ No newline at end of file diff --git a/core/src/processing/core/PSurfaceAWT.java b/core/src/processing/core/PSurfaceAWT.java index d5e274ca2..265503fde 100644 --- a/core/src/processing/core/PSurfaceAWT.java +++ b/core/src/processing/core/PSurfaceAWT.java @@ -49,7 +49,7 @@ public class PSurfaceAWT extends PSurfaceNone { Rectangle screenRect; // 3.0a5 didn't use strategy, and active was shut off during init() w/ retina - boolean useStrategy = true; +// boolean useStrategy = true; // Canvas canvas; Component canvas; @@ -85,9 +85,9 @@ public class PSurfaceAWT extends PSurfaceNone { // useStrategy = false; } canvas = new SmoothCanvas(); - if (useStrategy) { - canvas.setIgnoreRepaint(true); - } +// if (useStrategy) { + canvas.setIgnoreRepaint(true); +// } // Pass tab key to the sketch, rather than moving between components canvas.setFocusTraversalKeysEnabled(false); @@ -191,22 +191,21 @@ public class PSurfaceAWT extends PSurfaceNone { @Override public void paint(Graphics screen) { // System.out.println("painting"); -// validate(); - if (useStrategy) { - render(); +// if (useStrategy) { + render(); - } else { -// new Exception("painting").printStackTrace(System.out); -// if (graphics.image != null) { // && !sketch.insideDraw) { - if (onscreen != null) { -// synchronized (graphics.image) { - // Needs the width/height to be set so that retina images are properly scaled down -// screen.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null); - synchronized (offscreenLock) { - screen.drawImage(onscreen, 0, 0, sketchWidth, sketchHeight, null); - } - } - } +// } else { +//// new Exception("painting").printStackTrace(System.out); +//// if (graphics.image != null) { // && !sketch.insideDraw) { +// if (onscreen != null) { +//// synchronized (graphics.image) { +// // Needs the width/height to be set so that retina images are properly scaled down +//// screen.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null); +// synchronized (offscreenLock) { +// screen.drawImage(onscreen, 0, 0, sketchWidth, sketchHeight, null); +// } +// } +// } } } @@ -313,12 +312,12 @@ public class PSurfaceAWT extends PSurfaceNone { } - Object offscreenLock = new Object(); - BufferedImage offscreen; - BufferedImage onscreen; -// Graphics off; +// Object offscreenLock = new Object(); +// BufferedImage offscreen; +// BufferedImage onscreen; + /* protected void blit() { // Other folks that call render() (i.e. paint()) are already on the EDT. // We need to be using the EDT since we're messing with the Canvas @@ -360,6 +359,7 @@ public class PSurfaceAWT extends PSurfaceNone { } } } + */ // what needs to happen here? @@ -1372,9 +1372,10 @@ public class PSurfaceAWT extends PSurfaceNone { public Thread createThread() { return new AnimationThread() { @Override - public void render() { + public void callDraw() { sketch.handleDraw(); - blit(); + //blit(); + render(); } }; } diff --git a/core/src/processing/core/PSurfaceDanger.java b/core/src/processing/core/PSurfaceDanger.java deleted file mode 100644 index 408dc22da..000000000 --- a/core/src/processing/core/PSurfaceDanger.java +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ - -/* - Part of the Processing project - http://processing.org - - Copyright (c) 2015 The Processing Foundation - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation, version 2.1. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General - Public License along with this library; if not, write to the - Free Software Foundation, Inc., 59 Temple Place, Suite 330, - Boston, MA 02111-1307 USA -*/ - -package processing.core; - -import java.awt.Canvas; -import java.awt.Graphics2D; -import java.awt.image.BufferStrategy; - - -public class PSurfaceDanger extends PSurfaceAWT { - - public PSurfaceDanger(PGraphics graphics) { - super(graphics); - } - - - @Override - public Thread createThread() { - return new AnimationThread() { - @Override - public void render() { - //sketch.handleDraw(); - blit(); - } - }; - } - - - @Override - protected synchronized void render() { - if (!canvas.isDisplayable()) { - return; - } - - Canvas c = (Canvas) canvas; - if (c.getBufferStrategy() == null) { // whole block [121222] - c.createBufferStrategy(2); - } - BufferStrategy strategy = c.getBufferStrategy(); - if (strategy == null) { - return; - } - do { - do { - Graphics2D draw = (Graphics2D) strategy.getDrawGraphics(); - - // draw the Java2D feller here - ((PGraphicsJava2D) sketch.g).g2 = draw; - sketch.handleDraw(); - - draw.dispose(); - - } while (strategy.contentsRestored()); - - strategy.show(); - - } while (strategy.contentsLost()); - } -} \ No newline at end of file diff --git a/core/src/processing/core/PSurfaceNone.java b/core/src/processing/core/PSurfaceNone.java index c9695140c..70aa1fe41 100644 --- a/core/src/processing/core/PSurfaceNone.java +++ b/core/src/processing/core/PSurfaceNone.java @@ -236,7 +236,8 @@ public class PSurfaceNone implements PSurface { super("Animation Thread"); } - public void render() { + // broken out so it can be overridden by Danger et al + public void callDraw() { sketch.handleDraw(); } @@ -291,7 +292,9 @@ public class PSurfaceNone implements PSurface { // try { // EventQueue.invokeAndWait(new Runnable() { // public void run() { - render(); +// System.out.println("calling draw, finished = " + sketch.finished); + //System.out.println("calling draw, looping = " + sketch.looping + ", frameCount = " + sketch.frameCount); + callDraw(); // EventQueue.invokeLater(new Runnable() { // public void run() {