Skip to content

Commit f1fc693

Browse files
committed
rework non-visible surface handling, fix size() parser
1 parent ba0fbd6 commit f1fc693

File tree

6 files changed

+143
-75
lines changed

6 files changed

+143
-75
lines changed

core/src/processing/core/PApplet.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545

4646

47+
4748
// used by loadImage() functions
4849
import javax.imageio.ImageIO;
4950
import javax.swing.ImageIcon;
@@ -1489,23 +1490,34 @@ public void size(int w, int h) {
14891490
size(w, h, sketchRenderer(), null);
14901491
}
14911492

1493+
14921494
/**
14931495
* @param renderer Either P2D, P3D, or PDF
14941496
*/
14951497
public void size(int w, int h, String renderer) {
14961498
size(w, h, renderer, null);
14971499
}
14981500

1499-
/**
1500-
* @nowebref
1501-
*/
1501+
1502+
/**
1503+
* @nowebref
1504+
*/
15021505
public void size(final int w, final int h, String renderer, String path) {
15031506
if (!renderer.equals(sketchRenderer())) {
1504-
System.err.println("Because you're not running from the PDE, add this to your code:");
1505-
System.err.println("public String sketchRenderer() {");
1506-
System.err.println(" return \"" + renderer + "\";");
1507-
System.err.println("}");
1508-
throw new RuntimeException("The sketchRenderer() method is not implemented.");
1507+
if (external) {
1508+
// The PDE should have parsed it, but something still went wrong
1509+
final String msg =
1510+
String.format("Something bad happened when calling " +
1511+
"size(%d, %d, %s, %s)", w, h, renderer, path);
1512+
throw new RuntimeException(msg);
1513+
1514+
} else {
1515+
System.err.println("Because you're not running from the PDE, add this to your code:");
1516+
System.err.println("public String sketchRenderer() {");
1517+
System.err.println(" return \"" + renderer + "\";");
1518+
System.err.println("}");
1519+
throw new RuntimeException("The sketchRenderer() method is not implemented.");
1520+
}
15091521
}
15101522
surface.setSize(w, h);
15111523
g.setPath(path); // finally, a path
@@ -1700,6 +1712,7 @@ protected PGraphics makeGraphics(int w, int h,
17001712

17011713
pg.setParent(this);
17021714
pg.setPrimary(primary);
1715+
System.out.println("path is " + path);
17031716
if (path != null) {
17041717
pg.setPath(path);
17051718
}
@@ -1770,7 +1783,8 @@ protected PGraphics makeGraphics(int w, int h,
17701783

17711784
/** Create default renderer, likely to be resized, but needed for surface init. */
17721785
protected PGraphics createPrimaryGraphics() {
1773-
return makeGraphics(sketchWidth(), sketchHeight(), sketchRenderer(), null, true);
1786+
return makeGraphics(sketchWidth(), sketchHeight(),
1787+
sketchRenderer(), sketchOutputPath(), true);
17741788
}
17751789

17761790

@@ -9643,9 +9657,8 @@ private void deprecationWarning(String method) {
96439657
surface.initFrame(this, backgroundColor, displayIndex, present, spanDisplays);
96449658
surface.setTitle(getClass().getName());
96459659
//frame.setTitle(getClass().getName());
9646-
// } else {
9647-
// // TODO necessary?
9648-
// surface.initOffscreen(this);
9660+
} else {
9661+
surface.initOffscreen(this); // for PDF, PSurfaceNone, and friends
96499662
}
96509663

96519664
init();

core/src/processing/core/PConstants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.awt.Cursor;
2828
import java.awt.event.KeyEvent;
2929

30-
import processing.data.StringList;
31-
3230

3331
/**
3432
* Numbers shared throughout processing.core.
@@ -48,6 +46,7 @@ public interface PConstants {
4846

4947
// renderers known to processing.core
5048

49+
/*
5150
// List of renderers used inside PdePreprocessor
5251
static final StringList rendererList = new StringList(new String[] {
5352
"JAVA2D", "JAVA2D_2X",
@@ -56,6 +55,7 @@ public interface PConstants {
5655
"LWJGL.P2D", "LWJGL.P3D", // hmm
5756
"PDF" // no DXF because that's only for beginRaw()
5857
});
58+
*/
5959

6060
static final String JAVA2D = "processing.core.PGraphicsJava2D";
6161
static final String JAVA2D_2X = "processing.core.PGraphicsJava2D2X";

core/src/processing/core/PSurfaceNone.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public PSurfaceNone() { }
4646

4747
@Override
4848
public void initOffscreen(PApplet sketch) {
49-
// TODO Auto-generated method stub
49+
this.sketch = sketch;
5050
}
5151

5252

@@ -57,8 +57,9 @@ public void initOffscreen(PApplet sketch) {
5757

5858
@Override
5959
public void initFrame(PApplet sketch, int backgroundColor,
60-
int deviceIndex, boolean fullScreen,
61-
boolean spanDisplays) {
60+
int deviceIndex, boolean fullScreen,
61+
boolean spanDisplays) {
62+
this.sketch = sketch;
6263
}
6364

6465

core/todo.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ _ implement frameRate()
3838
_ implement external messages (moving the window)
3939

4040
opengl
41+
X deal with some performance issues
42+
X https://github.com/processing/processing/issues/3210
43+
X Can't run sketches with offscreen PGraphics
44+
X https://github.com/processing/processing/issues/3259
45+
_ Merge glw code into the OpenGL library
46+
_ https://github.com/processing/processing/issues/3284
4147
_ why is createShape() implemented 4x (for P2D, P3D, and 2x versions)?
4248
_ shouldn't be static, run it from the renderer, that's point of createXxx()
4349
_ when did setPath() sneak into PShape? API is nothing like anything else
4450
_ public createShape() method that takes another shape as param?
4551
_ should just be the constructor doing this, or copy()
46-
_ drawing 100k lines is slow (example from Reas)
47-
_ figure out what the bottleneck is here
4852

4953

5054
high priority

java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,14 @@ public void beginDraw() {
118118

119119
if (document == null) {
120120
document = new Document(new Rectangle(width, height));
121+
boolean missingPath = false;
121122
try {
122123
if (file != null) {
123124
//BufferedOutputStream output = new BufferedOutputStream(stream, 16384);
124125
output = new BufferedOutputStream(new FileOutputStream(file), 16384);
125126

126127
} else if (output == null) {
128+
missingPath = true;
127129
throw new RuntimeException("PGraphicsPDF requires a path " +
128130
"for the location of the output file.");
129131
}
@@ -132,25 +134,26 @@ public void beginDraw() {
132134
content = writer.getDirectContent();
133135
// template = content.createTemplate(width, height);
134136

135-
} catch (Exception e) {
136-
e.printStackTrace();
137-
throw new RuntimeException("Problem saving the PDF file.");
137+
} catch (RuntimeException re) {
138+
if (missingPath) {
139+
throw re; // don't re-package our own error
140+
} else {
141+
throw new RuntimeException("Problem saving the PDF file.", re);
142+
}
143+
144+
} catch (FileNotFoundException fnfe) {
145+
throw new RuntimeException("Can't save the PDF file to " + path, fnfe);
146+
147+
} catch (DocumentException de) {
148+
throw new RuntimeException("Error inside the PDF library.", de);
138149
}
139150

140-
// System.out.println("beginDraw fonts " + (System.currentTimeMillis() - t));
141-
// g2 = content.createGraphics(width, height, getMapper());
142-
// if (textMode == SHAPE) {
143151
g2 = content.createGraphicsShapes(width, height);
144-
// } else if (textMode == MODEL) {
145-
// g2 = content.createGraphics(width, height, getMapper());
146-
// }
147-
// g2 = createGraphics();
148-
// g2 = template.createGraphics(width, height, mapper);
149152
}
150-
// System.out.println("beginDraw " + (System.currentTimeMillis() - t0));
151153

152154
// super in Java2D now creates an image buffer, don't do that
153-
// super.beginDraw();
155+
//super.beginDraw();
156+
154157
checkSettings();
155158
resetMatrix(); // reset model matrix
156159
vertexCount = 0;

0 commit comments

Comments
 (0)