5252public class PGraphicsJava2D extends PGraphics {
5353 BufferStrategy strategy ;
5454 BufferedImage bimage ;
55- VolatileImage vimage ;
55+ // VolatileImage vimage;
5656 Canvas canvas ;
5757// boolean useCanvas = true;
5858 boolean useCanvas = false ;
5959// boolean useRetina = true;
6060// boolean useOffscreen = true; // ~40fps
6161 boolean useOffscreen = false ;
6262
63- /**
64- * Java AWT Image object associated with this renderer. For the 1.0 version
65- * of P2D and P3D, this was be associated with their MemoryImageSource.
66- * For PGraphicsJava2D, it will be the offscreen drawing buffer.
67- */
68- public Image image ; // moved from PGraphics, not sure about this yet
69-
7063 public Graphics2D g2 ;
7164 protected BufferedImage offscreen ;
7265
@@ -255,27 +248,21 @@ public void beginDraw() {
255248 // and 2) minimal overhead, however. Instinct suggests #1 may be true,
256249 // but #2 seems a problem.
257250 if (primarySurface && !useOffscreen ) {
251+ GraphicsConfiguration gc = canvas .getGraphicsConfiguration ();
258252 if (false ) {
259- GraphicsConfiguration gc = parent .getGraphicsConfiguration ();
260253 if (image == null || ((VolatileImage ) image ).validate (gc ) == VolatileImage .IMAGE_INCOMPATIBLE ) {
261254 image = gc .createCompatibleVolatileImage (width , height );
262255 g2 = (Graphics2D ) image .getGraphics ();
263256 reapplySettings = true ;
264257 }
265258 } else {
266259 if (image == null ) {
267- GraphicsConfiguration gc = parent .getGraphicsConfiguration ();
268260 image = gc .createCompatibleImage (width , height );
269261 PApplet .debug ("created new image, type is " + image );
270262 g2 = (Graphics2D ) image .getGraphics ();
271263 reapplySettings = true ;
272264 }
273265 }
274- //g2 = (Graphics2D) image.getGraphics();
275- // if (g2 != g2old) {
276- // System.out.println("new g2: " + g2);
277- // g2old = g2;
278- // }
279266 }
280267
281268 if (useCanvas && primarySurface ) {
@@ -291,10 +278,6 @@ public void beginDraw() {
291278 "/" + caps .getBackBufferCapabilities ().isAccelerated ());
292279 }
293280 GraphicsConfiguration gc = canvas .getGraphicsConfiguration ();
294- // if (vimage == null || vimage.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
295- // vimage = gc.createCompatibleVolatileImage(width, height);
296- // }
297- // g2 = (Graphics2D) vimage.getGraphics();
298281
299282 if (bimage == null ||
300283 bimage .getWidth () != width ||
@@ -375,18 +358,18 @@ private void redraw() {
375358 PApplet .debug ("PGraphicsJava2D.redraw() top of inner do { } block" );
376359 PApplet .debug ("strategy is " + strategy );
377360 Graphics bsg = strategy .getDrawGraphics ();
378- if (vimage != null ) {
379- bsg .drawImage (vimage , 0 , 0 , null );
380- } else {
381- bsg .drawImage (bimage , 0 , 0 , null );
361+ // if (vimage != null) {
362+ // bsg.drawImage(vimage, 0, 0, null);
363+ // } else {
364+ bsg .drawImage (bimage , 0 , 0 , null );
382365// if (parent.frameCount == 0) {
383366// try {
384367// ImageIO.write(image, "jpg", new java.io.File("/Users/fry/Desktop/buff.jpg"));
385368// } catch (IOException e) {
386369// e.printStackTrace();
387370// }
388371// }
389- }
372+ // }
390373 bsg .dispose ();
391374
392375 // the strategy version
@@ -1691,7 +1674,7 @@ public float textAscent() {
16911674
16921675 Font font = (Font ) textFont .getNative ();
16931676 if (font != null ) {
1694- FontMetrics metrics = Toolkit . getDefaultToolkit () .getFontMetrics (font );
1677+ FontMetrics metrics = canvas .getFontMetrics (font );
16951678 return metrics .getAscent ();
16961679 }
16971680 return super .textAscent ();
@@ -1706,7 +1689,7 @@ public float textDescent() {
17061689 Font font = (Font ) textFont .getNative ();
17071690 //if (font != null && (textFont.isStream() || hints[ENABLE_NATIVE_FONTS])) {
17081691 if (font != null ) {
1709- FontMetrics metrics = parent .getFontMetrics (font );
1692+ FontMetrics metrics = canvas .getFontMetrics (font );
17101693 return metrics .getDescent ();
17111694 }
17121695 return super .textDescent ();
0 commit comments