Skip to content

Commit da8f487

Browse files
committed
more javafx work, fighting with pixelFactor, preparing for the end times
1 parent 943086b commit da8f487

7 files changed

Lines changed: 70 additions & 91 deletions

File tree

core/src/processing/core/PConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public interface PConstants {
6161
static final String E2D = PGraphicsDanger2D.class.getName();
6262

6363
// Experimental JavaFX renderer; even better 2D performance?
64-
static final String FX2D = PGraphicsFX.class.getName();
64+
static final String FX2D = PGraphicsFX2D.class.getName();
65+
static final String FX2D_2X = PGraphicsFX2D2X.class.getName();
6566

6667
static final String PDF = "processing.pdf.PGraphicsPDF";
6768
static final String DXF = "processing.dxf.RawDXF";

core/src/processing/core/PGraphics.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7950,7 +7950,7 @@ static public void showWarning(String msg, Object... args) { // ignore
79507950
*/
79517951
static public void showDepthWarning(String method) {
79527952
showWarning(method + "() can only be used with a renderer that " +
7953-
"supports 3D, such as P3D or OPENGL.");
7953+
"supports 3D, such as P3D.");
79547954
}
79557955

79567956

@@ -7962,7 +7962,7 @@ static public void showDepthWarning(String method) {
79627962
static public void showDepthWarningXYZ(String method) {
79637963
showWarning(method + "() with x, y, and z coordinates " +
79647964
"can only be used with a renderer that " +
7965-
"supports 3D, such as P3D or OPENGL. " +
7965+
"supports 3D, such as P3D. " +
79667966
"Use a version without a z-coordinate instead.");
79677967
}
79687968

core/src/processing/core/PGraphicsFX.java renamed to core/src/processing/core/PGraphicsFX2D.java

Lines changed: 22 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import javafx.scene.transform.Transform;
4141

4242

43-
public class PGraphicsFX extends PGraphics {
43+
public class PGraphicsFX2D extends PGraphics {
4444
GraphicsContext context;
4545

4646
static final WritablePixelFormat<IntBuffer> argbFormat =
@@ -89,7 +89,7 @@ public class PGraphicsFX extends PGraphics {
8989
// INTERNAL
9090

9191

92-
public PGraphicsFX() { }
92+
public PGraphicsFX2D() { }
9393

9494

9595
//public void setParent(PApplet parent)
@@ -433,14 +433,14 @@ public void endShape(int mode) {
433433
@Override
434434
protected void clipImpl(float x1, float y1, float x2, float y2) {
435435
//g2.setClip(new Rectangle2D.Float(x1, y1, x2 - x1, y2 - y1));
436-
showMethodWarning("clip()");
436+
showTodoWarning("clip()", 3274);
437437
}
438438

439439

440440
@Override
441441
public void noClip() {
442442
//g2.setClip(null);
443-
showMethodWarning("noClip()");
443+
showTodoWarning("noClip()", 3274);
444444
}
445445

446446

@@ -452,7 +452,7 @@ public void noClip() {
452452

453453
@Override
454454
protected void blendModeImpl() {
455-
showMethodWarning("blendMode()");
455+
showTodoWarning("blendMode()", 3275);
456456
}
457457

458458

@@ -832,7 +832,7 @@ public void bezierDetail(int detail) { }
832832
//public float curveTangent(float a, float b, float c, float d, float t)
833833

834834

835-
/** Ignored (not needed) in Java 2D. */
835+
/** Ignored (not needed) by this renderer. */
836836
@Override
837837
public void curveDetail(int detail) { }
838838

@@ -965,28 +965,6 @@ protected void imageImpl(PImage who,
965965
context.drawImage(((ImageCache) getCache(who)).image,
966966
u1, v1, u2-u1, v2-v1,
967967
x1, y1, x2-x1, y2-y1);
968-
969-
// Every few years I think "nah, Java2D couldn't possibly be that f*king
970-
// slow, why are we doing this by hand?" then comes the affirmation:
971-
// Composite oldComp = null;
972-
// if (false && tint) {
973-
// oldComp = g2.getComposite();
974-
// int alpha = (tintColor >> 24) & 0xff;
975-
// System.out.println("using alpha composite");
976-
// Composite alphaComp =
977-
// AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha / 255f);
978-
// g2.setComposite(alphaComp);
979-
// }
980-
//
981-
// long t = System.currentTimeMillis();
982-
// g2.drawImage(who.getImage(),
983-
// (int) x1, (int) y1, (int) x2, (int) y2,
984-
// u1, v1, u2, v2, null);
985-
// System.out.println(System.currentTimeMillis() - t);
986-
//
987-
// if (oldComp != null) {
988-
// g2.setComposite(oldComp);
989-
// }
990968
}
991969

992970

@@ -2033,48 +2011,14 @@ public void backgroundImpl() {
20332011
//
20342012
//
20352013
//
2036-
// //////////////////////////////////////////////////////////////
2037-
//
2038-
// // PIMAGE METHODS
2039-
//
2040-
//
2041-
// // getImage, setCache, getCache, removeCache, isModified, setModified
2042-
//
2043-
//
2044-
// protected WritableRaster getRaster() {
2045-
// WritableRaster raster = null;
2046-
// if (primarySurface) {
2047-
// /*
2048-
// // 'offscreen' will probably be removed in the next release
2049-
// if (useOffscreen) {
2050-
// raster = offscreen.getRaster();
2051-
// } else*/ if (image instanceof VolatileImage) {
2052-
// // when possible, we'll try VolatileImage
2053-
// raster = ((VolatileImage) image).getSnapshot().getRaster();
2054-
// }
2055-
// }
2056-
// if (raster == null) {
2057-
// raster = ((BufferedImage) image).getRaster();
2058-
// }
2059-
//
2060-
// // On Raspberry Pi (and perhaps other platforms, the color buffer won't
2061-
// // necessarily be the int array that we'd like. Need to convert it here.
2062-
// // Not that this would probably mean getRaster() would need to work more
2063-
// // like loadRaster/updateRaster because the pixels will need to be
2064-
// // temporarily moved to (and later from) a buffer that's understood by
2065-
// // the rest of the Processing source.
2066-
// // https://github.com/processing/processing/issues/2010
2067-
// if (raster.getTransferType() != DataBuffer.TYPE_INT) {
2068-
// System.err.println("See https://github.com/processing/processing/issues/2010");
2069-
// throw new RuntimeException("Pixel operations are not supported on this device.");
2070-
// }
2071-
// return raster;
2072-
// }
2014+
//////////////////////////////////////////////////////////////
2015+
2016+
// PIMAGE METHODS
20732017

20742018

20752019
@Override
20762020
public void loadPixels() {
2077-
pixelFactor = 2;
2021+
// pixelFactor = 2;
20782022
int wide = width * pixelFactor;
20792023
int high = height * pixelFactor;
20802024

@@ -2103,21 +2047,6 @@ public void loadPixels() {
21032047
}
21042048

21052049

2106-
//// /**
2107-
//// * Update the pixels[] buffer to the PGraphics image.
2108-
//// * <P>
2109-
//// * Unlike in PImage, where updatePixels() only requests that the
2110-
//// * update happens, in PGraphicsJava2D, this will happen immediately.
2111-
//// */
2112-
//// @Override
2113-
//// public void updatePixels() {
2114-
//// //updatePixels(0, 0, width, height);
2115-
////// WritableRaster raster = ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
2116-
////// WritableRaster raster = image.getRaster();
2117-
//// updatePixels(0, 0, width, height);
2118-
//// }
2119-
//
2120-
//
21212050
// /**
21222051
// * Update the pixels[] buffer to the PGraphics image.
21232052
// * <P>
@@ -2367,4 +2296,16 @@ public void loadPixels() {
23672296

23682297

23692298
//public void save(String filename)
2299+
2300+
2301+
2302+
//////////////////////////////////////////////////////////////
2303+
2304+
/**
2305+
* Display a warning that the specified method is simply unavailable.
2306+
*/
2307+
static public void showTodoWarning(String method, int issue) {
2308+
showWarning(method + "() is not yet available: " +
2309+
"https://github.com/processing/processing/issues/" + issue);
2310+
}
23702311
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
3+
/*
4+
Part of the Processing project - http://processing.org
5+
6+
Copyright (c) 2015 The Processing Foundation
7+
8+
This library is free software; you can redistribute it and/or
9+
modify it under the terms of the GNU Lesser General Public
10+
License as published by the Free Software Foundation, version 2.1.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General
18+
Public License along with this library; if not, write to the
19+
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20+
Boston, MA 02111-1307 USA
21+
*/
22+
23+
package processing.core;
24+
25+
26+
public class PGraphicsFX2D2X extends PGraphics {
27+
public PGraphicsFX2D2X() {
28+
pixelFactor = 2;
29+
}
30+
}

core/src/processing/core/PGraphicsJava2D.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2013-14 The Processing Foundation
6+
Copyright (c) 2013-15 The Processing Foundation
77
Copyright (c) 2005-13 Ben Fry and Casey Reas
88
99
This library is free software; you can redistribute it and/or
@@ -2639,12 +2639,12 @@ protected WritableRaster getRaster() {
26392639

26402640
@Override
26412641
public void loadPixels() {
2642-
if ((pixels == null) || (pixels.length != width * height)) {
2643-
pixels = new int[width * height];
2642+
if (pixels == null || (pixels.length != pixelWidth*pixelHeight)) {
2643+
pixels = new int[pixelWidth * pixelHeight];
26442644
}
26452645

26462646
WritableRaster raster = getRaster();
2647-
raster.getDataElements(0, 0, width, height, pixels);
2647+
raster.getDataElements(0, 0, pixelWidth, pixelHeight, pixels);
26482648
if (raster.getNumBands() == 3) {
26492649
// Java won't set the high bits when RGB, returns 0 for alpha
26502650
// https://github.com/processing/processing/issues/2030
@@ -2690,7 +2690,7 @@ public void updatePixels(int x, int y, int c, int d) {
26902690
}
26912691
// updatePixels();
26922692
if (pixels != null) {
2693-
getRaster().setDataElements(0, 0, width, height, pixels);
2693+
getRaster().setDataElements(0, 0, pixelWidth, pixelHeight, pixels);
26942694
}
26952695
modified = true;
26962696
}

core/src/processing/core/PSurfaceFX.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ public class PSurfaceFX implements PSurface {
6262

6363
//Application app;
6464
//Stage stage;
65-
PGraphicsFX fx;
65+
PGraphicsFX2D fx;
6666
Stage stage;
6767
Canvas canvas;
6868
// Frame dummy;
6969

7070
AnimationTimer timer;
7171

7272

73-
public PSurfaceFX(PGraphicsFX graphics) {
73+
public PSurfaceFX(PGraphicsFX2D graphics) {
7474
fx = graphics;
7575
canvas = new ResizableCanvas();
7676
fx.context = canvas.getGraphicsContext2D();

core/todo.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ _ and optionally the corner radii
1818
_ createShape(ELLIPSE) is x/y/w/h, and optionally adds a mode param
1919

2020

21+
javafx
22+
_ clip/noClip
23+
_ https://github.com/processing/processing/issues/3274
24+
_ blendMode
25+
_ https://github.com/processing/processing/issues/3275
26+
_ getNative() is problematic because it gives back a BufferedImage
27+
2128
opengl
2229
_ why is createShape() implemented 4x (for P2D, P3D, and 2x versions)?
2330
_ shouldn't be static, run it from the renderer, that's point of createXxx()

0 commit comments

Comments
 (0)