Skip to content

Commit cdc4bed

Browse files
committed
clean up unused code, queue size changes (fixes #186)
1 parent dd74806 commit cdc4bed

File tree

1 file changed

+15
-59
lines changed

1 file changed

+15
-59
lines changed

core/src/processing/awt/PGraphicsJava2D.java

Lines changed: 15 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,8 @@
5050
* Advanced <a href="http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/java2d.html">debugging notes</a> for Java2D.
5151
*/
5252
public class PGraphicsJava2D extends PGraphics {
53-
//// BufferStrategy strategy;
54-
//// BufferedImage bimage;
55-
//// VolatileImage vimage;
56-
// Canvas canvas;
57-
//// boolean useCanvas = true;
58-
// boolean useCanvas = false;
59-
//// boolean useRetina = true;
60-
//// boolean useOffscreen = true; // ~40fps
61-
// boolean useOffscreen = false;
62-
6353
public Graphics2D g2;
64-
// protected BufferedImage offscreen;
54+
private Dimension sizeChange;
6555

6656
Composite defaultComposite;
6757

@@ -121,21 +111,13 @@ public PGraphicsJava2D() { }
121111
//public void setPath(String path)
122112

123113

124-
// /**
125-
// * Called in response to a resize event, handles setting the
126-
// * new width and height internally, as well as re-allocating
127-
// * the pixel buffer for the new size.
128-
// *
129-
// * Note that this will nuke any cameraMode() settings.
130-
// */
131-
// @Override
132-
// public void setSize(int iwidth, int iheight) { // ignore
133-
// width = iwidth;
134-
// height = iheight;
135-
//
136-
// allocate();
137-
// reapplySettings();
138-
// }
114+
/**
115+
* Queues a size change, won't happen until beginDraw().
116+
*/
117+
@Override
118+
public void setSize(int w, int h) { // ignore
119+
sizeChange = new Dimension(w, h);
120+
}
139121

140122

141123
// @Override
@@ -292,47 +274,24 @@ public Object getNative() {
292274
// Graphics2D g2old;
293275

294276
public Graphics2D checkImage() {
277+
if (sizeChange != null) {
278+
// Size changes are queued here where they're safe to run.
279+
// https://github.com/processing/processing4/issues/186
280+
super.setSize(sizeChange.width, sizeChange.height);
281+
sizeChange = null;
282+
}
295283
if (image == null ||
296284
((BufferedImage) image).getWidth() != width*pixelDensity ||
297285
((BufferedImage) image).getHeight() != height*pixelDensity) {
298-
// ((VolatileImage) image).getWidth() != width ||
299-
// ((VolatileImage) image).getHeight() != height) {
300-
// image = new BufferedImage(width * pixelFactor, height * pixelFactor
301-
// format == RGB ? BufferedImage.TYPE_INT_ARGB);
302286

303-
// Commenting this out, because we are not drawing directly to the screen [jv 2018-06-01]
304-
//
305-
// GraphicsConfiguration gc = null;
306-
// if (surface != null) {
307-
// Component comp = null; //surface.getComponent();
308-
// if (comp == null) {
309-
//// System.out.println("component null, but parent.frame is " + parent.frame);
310-
// comp = parent.frame;
311-
// }
312-
// if (comp != null) {
313-
// gc = comp.getGraphicsConfiguration();
314-
// }
315-
// }
316-
// // If not realized (off-screen, i.e the Color Selector Tool), gc will be null.
317-
// if (gc == null) {
318-
// //System.err.println("GraphicsConfiguration null in initImage()");
319-
// GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
320-
// gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
321-
// }
322-
323-
// Formerly this was broken into separate versions based on offscreen or
324-
// not, but we may as well create a compatible image; it won't hurt, right?
325-
// P.S.: Three years later, I'm happy to report it did in fact hurt [jv 2018-06-01]
326287
int wide = width * pixelDensity;
327288
int high = height * pixelDensity;
328-
// System.out.println("re-creating image");
329289

330-
// For now we expect non-premultiplied INT ARGB and the compatible image
290+
// For now, we expect non-pre-multiplied INT ARGB and the compatible image
331291
// might not be it... create the image directly. It's important that the
332292
// image has all four bands, otherwise we get garbage alpha during blending
333293
// (see https://github.com/processing/processing/pull/2645,
334294
// https://github.com/processing/processing/pull/3523)
335-
//
336295
// image = gc.createCompatibleImage(wide, high, Transparency.TRANSLUCENT);
337296
image = new BufferedImage(wide, high, BufferedImage.TYPE_INT_ARGB);
338297
}
@@ -2802,9 +2761,6 @@ public void loadPixels() {
28022761
pixels[i] = 0xff000000 | pixels[i];
28032762
}
28042763
}
2805-
//((BufferedImage) image).getRGB(0, 0, width, height, pixels, 0, width);
2806-
// WritableRaster raster = ((BufferedImage) (useOffscreen && primarySurface ? offscreen : image)).getRaster();
2807-
// WritableRaster raster = image.getRaster();
28082764
}
28092765

28102766

0 commit comments

Comments
 (0)