diff --git a/core/src/processing/core/PConstants.java b/core/src/processing/core/PConstants.java index f2cef656a..60a8ae048 100644 --- a/core/src/processing/core/PConstants.java +++ b/core/src/processing/core/PConstants.java @@ -61,7 +61,8 @@ public interface PConstants { static final String E2D = PGraphicsDanger2D.class.getName(); // Experimental JavaFX renderer; even better 2D performance? - static final String FX2D = PGraphicsFX.class.getName(); + static final String FX2D = PGraphicsFX2D.class.getName(); + static final String FX2D_2X = PGraphicsFX2D2X.class.getName(); static final String PDF = "processing.pdf.PGraphicsPDF"; static final String DXF = "processing.dxf.RawDXF"; diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index e81919001..64a45a792 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -7950,7 +7950,7 @@ public class PGraphics extends PImage implements PConstants { */ static public void showDepthWarning(String method) { showWarning(method + "() can only be used with a renderer that " + - "supports 3D, such as P3D or OPENGL."); + "supports 3D, such as P3D."); } @@ -7962,7 +7962,7 @@ public class PGraphics extends PImage implements PConstants { static public void showDepthWarningXYZ(String method) { showWarning(method + "() with x, y, and z coordinates " + "can only be used with a renderer that " + - "supports 3D, such as P3D or OPENGL. " + + "supports 3D, such as P3D. " + "Use a version without a z-coordinate instead."); } diff --git a/core/src/processing/core/PGraphicsFX.java b/core/src/processing/core/PGraphicsFX2D.java similarity index 95% rename from core/src/processing/core/PGraphicsFX.java rename to core/src/processing/core/PGraphicsFX2D.java index 11949f524..312305d96 100644 --- a/core/src/processing/core/PGraphicsFX.java +++ b/core/src/processing/core/PGraphicsFX2D.java @@ -40,7 +40,7 @@ import javafx.scene.shape.StrokeLineJoin; import javafx.scene.transform.Transform; -public class PGraphicsFX extends PGraphics { +public class PGraphicsFX2D extends PGraphics { GraphicsContext context; static final WritablePixelFormat argbFormat = @@ -89,7 +89,7 @@ public class PGraphicsFX extends PGraphics { // INTERNAL - public PGraphicsFX() { } + public PGraphicsFX2D() { } //public void setParent(PApplet parent) @@ -433,14 +433,14 @@ public class PGraphicsFX extends PGraphics { @Override protected void clipImpl(float x1, float y1, float x2, float y2) { //g2.setClip(new Rectangle2D.Float(x1, y1, x2 - x1, y2 - y1)); - showMethodWarning("clip()"); + showTodoWarning("clip()", 3274); } @Override public void noClip() { //g2.setClip(null); - showMethodWarning("noClip()"); + showTodoWarning("noClip()", 3274); } @@ -452,7 +452,7 @@ public class PGraphicsFX extends PGraphics { @Override protected void blendModeImpl() { - showMethodWarning("blendMode()"); + showTodoWarning("blendMode()", 3275); } @@ -832,7 +832,7 @@ public class PGraphicsFX extends PGraphics { //public float curveTangent(float a, float b, float c, float d, float t) - /** Ignored (not needed) in Java 2D. */ + /** Ignored (not needed) by this renderer. */ @Override public void curveDetail(int detail) { } @@ -965,28 +965,6 @@ public class PGraphicsFX extends PGraphics { context.drawImage(((ImageCache) getCache(who)).image, u1, v1, u2-u1, v2-v1, x1, y1, x2-x1, y2-y1); - - // Every few years I think "nah, Java2D couldn't possibly be that f*king - // slow, why are we doing this by hand?" then comes the affirmation: -// Composite oldComp = null; -// if (false && tint) { -// oldComp = g2.getComposite(); -// int alpha = (tintColor >> 24) & 0xff; -// System.out.println("using alpha composite"); -// Composite alphaComp = -// AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha / 255f); -// g2.setComposite(alphaComp); -// } -// -// long t = System.currentTimeMillis(); -// g2.drawImage(who.getImage(), -// (int) x1, (int) y1, (int) x2, (int) y2, -// u1, v1, u2, v2, null); -// System.out.println(System.currentTimeMillis() - t); -// -// if (oldComp != null) { -// g2.setComposite(oldComp); -// } } @@ -2033,48 +2011,14 @@ public class PGraphicsFX extends PGraphics { // // // -// ////////////////////////////////////////////////////////////// -// -// // PIMAGE METHODS -// -// -// // getImage, setCache, getCache, removeCache, isModified, setModified -// -// -// protected WritableRaster getRaster() { -// WritableRaster raster = null; -// if (primarySurface) { -// /* -// // 'offscreen' will probably be removed in the next release -// if (useOffscreen) { -// raster = offscreen.getRaster(); -// } else*/ if (image instanceof VolatileImage) { -// // when possible, we'll try VolatileImage -// raster = ((VolatileImage) image).getSnapshot().getRaster(); -// } -// } -// if (raster == null) { -// raster = ((BufferedImage) image).getRaster(); -// } -// -// // On Raspberry Pi (and perhaps other platforms, the color buffer won't -// // necessarily be the int array that we'd like. Need to convert it here. -// // Not that this would probably mean getRaster() would need to work more -// // like loadRaster/updateRaster because the pixels will need to be -// // temporarily moved to (and later from) a buffer that's understood by -// // the rest of the Processing source. -// // https://github.com/processing/processing/issues/2010 -// if (raster.getTransferType() != DataBuffer.TYPE_INT) { -// System.err.println("See https://github.com/processing/processing/issues/2010"); -// throw new RuntimeException("Pixel operations are not supported on this device."); -// } -// return raster; -// } + ////////////////////////////////////////////////////////////// + + // PIMAGE METHODS @Override public void loadPixels() { - pixelFactor = 2; +// pixelFactor = 2; int wide = width * pixelFactor; int high = height * pixelFactor; @@ -2103,21 +2047,6 @@ public class PGraphicsFX extends PGraphics { } -//// /** -//// * Update the pixels[] buffer to the PGraphics image. -//// *

-//// * Unlike in PImage, where updatePixels() only requests that the -//// * update happens, in PGraphicsJava2D, this will happen immediately. -//// */ -//// @Override -//// public void updatePixels() { -//// //updatePixels(0, 0, width, height); -////// WritableRaster raster = ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster(); -////// WritableRaster raster = image.getRaster(); -//// updatePixels(0, 0, width, height); -//// } -// -// // /** // * Update the pixels[] buffer to the PGraphics image. // *

@@ -2367,4 +2296,16 @@ public class PGraphicsFX extends PGraphics { //public void save(String filename) + + + + ////////////////////////////////////////////////////////////// + + /** + * Display a warning that the specified method is simply unavailable. + */ + static public void showTodoWarning(String method, int issue) { + showWarning(method + "() is not yet available: " + + "https://github.com/processing/processing/issues/" + issue); + } } diff --git a/core/src/processing/core/PGraphicsFX2D2X.java b/core/src/processing/core/PGraphicsFX2D2X.java new file mode 100644 index 000000000..9fda4b8b3 --- /dev/null +++ b/core/src/processing/core/PGraphicsFX2D2X.java @@ -0,0 +1,30 @@ +/* -*- 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; + + +public class PGraphicsFX2D2X extends PGraphics { + public PGraphicsFX2D2X() { + pixelFactor = 2; + } +} diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index 15256916a..a3a6981ee 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -3,7 +3,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2013-14 The Processing Foundation + Copyright (c) 2013-15 The Processing Foundation Copyright (c) 2005-13 Ben Fry and Casey Reas This library is free software; you can redistribute it and/or @@ -2639,12 +2639,12 @@ public class PGraphicsJava2D extends PGraphics { @Override public void loadPixels() { - if ((pixels == null) || (pixels.length != width * height)) { - pixels = new int[width * height]; + if (pixels == null || (pixels.length != pixelWidth*pixelHeight)) { + pixels = new int[pixelWidth * pixelHeight]; } WritableRaster raster = getRaster(); - raster.getDataElements(0, 0, width, height, pixels); + raster.getDataElements(0, 0, pixelWidth, pixelHeight, pixels); if (raster.getNumBands() == 3) { // Java won't set the high bits when RGB, returns 0 for alpha // https://github.com/processing/processing/issues/2030 @@ -2690,7 +2690,7 @@ public class PGraphicsJava2D extends PGraphics { } // updatePixels(); if (pixels != null) { - getRaster().setDataElements(0, 0, width, height, pixels); + getRaster().setDataElements(0, 0, pixelWidth, pixelHeight, pixels); } modified = true; } diff --git a/core/src/processing/core/PSurfaceFX.java b/core/src/processing/core/PSurfaceFX.java index fe2a2e446..a376fa261 100644 --- a/core/src/processing/core/PSurfaceFX.java +++ b/core/src/processing/core/PSurfaceFX.java @@ -62,7 +62,7 @@ public class PSurfaceFX implements PSurface { //Application app; //Stage stage; - PGraphicsFX fx; + PGraphicsFX2D fx; Stage stage; Canvas canvas; // Frame dummy; @@ -70,7 +70,7 @@ public class PSurfaceFX implements PSurface { AnimationTimer timer; - public PSurfaceFX(PGraphicsFX graphics) { + public PSurfaceFX(PGraphicsFX2D graphics) { fx = graphics; canvas = new ResizableCanvas(); fx.context = canvas.getGraphicsContext2D(); diff --git a/core/todo.txt b/core/todo.txt index 9de09e2e3..a6df5654f 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -18,6 +18,13 @@ _ and optionally the corner radii _ createShape(ELLIPSE) is x/y/w/h, and optionally adds a mode param +javafx +_ clip/noClip +_ https://github.com/processing/processing/issues/3274 +_ blendMode +_ https://github.com/processing/processing/issues/3275 +_ getNative() is problematic because it gives back a BufferedImage + opengl _ why is createShape() implemented 4x (for P2D, P3D, and 2x versions)? _ shouldn't be static, run it from the renderer, that's point of createXxx()