|
50 | 50 | * Advanced <a href="http://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-Desktop/html/java2d.html">debugging notes</a> for Java2D. |
51 | 51 | */ |
52 | 52 | 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 | | - |
63 | 53 | public Graphics2D g2; |
64 | | -// protected BufferedImage offscreen; |
| 54 | + private Dimension sizeChange; |
65 | 55 |
|
66 | 56 | Composite defaultComposite; |
67 | 57 |
|
@@ -121,21 +111,13 @@ public PGraphicsJava2D() { } |
121 | 111 | //public void setPath(String path) |
122 | 112 |
|
123 | 113 |
|
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 | + } |
139 | 121 |
|
140 | 122 |
|
141 | 123 | // @Override |
@@ -292,47 +274,24 @@ public Object getNative() { |
292 | 274 | // Graphics2D g2old; |
293 | 275 |
|
294 | 276 | 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 | + } |
295 | 283 | if (image == null || |
296 | 284 | ((BufferedImage) image).getWidth() != width*pixelDensity || |
297 | 285 | ((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); |
302 | 286 |
|
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] |
326 | 287 | int wide = width * pixelDensity; |
327 | 288 | int high = height * pixelDensity; |
328 | | -// System.out.println("re-creating image"); |
329 | 289 |
|
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 |
331 | 291 | // might not be it... create the image directly. It's important that the |
332 | 292 | // image has all four bands, otherwise we get garbage alpha during blending |
333 | 293 | // (see https://github.com/processing/processing/pull/2645, |
334 | 294 | // https://github.com/processing/processing/pull/3523) |
335 | | - // |
336 | 295 | // image = gc.createCompatibleImage(wide, high, Transparency.TRANSLUCENT); |
337 | 296 | image = new BufferedImage(wide, high, BufferedImage.TYPE_INT_ARGB); |
338 | 297 | } |
@@ -2802,9 +2761,6 @@ public void loadPixels() { |
2802 | 2761 | pixels[i] = 0xff000000 | pixels[i]; |
2803 | 2762 | } |
2804 | 2763 | } |
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(); |
2808 | 2764 | } |
2809 | 2765 |
|
2810 | 2766 |
|
|
0 commit comments