Skip to content

Commit f4396f1

Browse files
committed
inching closer
1 parent 95cf72f commit f4396f1

4 files changed

Lines changed: 133 additions & 113 deletions

File tree

core/src/processing/core/PGraphics.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
package processing.core;
2727

28-
//import java.awt.*;
2928
import java.awt.Color;
29+
import java.awt.Image;
3030
import java.util.HashMap;
3131
import java.util.WeakHashMap;
3232

@@ -501,12 +501,12 @@ public class PGraphics extends PImage implements PConstants {
501501

502502
// ........................................................
503503

504-
// /**
505-
// * Java AWT Image object associated with this renderer. For the 1.0 version
506-
// * of P2D and P3D, this was be associated with their MemoryImageSource.
507-
// * For PGraphicsJava2D, it will be the offscreen drawing buffer.
508-
// */
509-
// public Image image;
504+
/**
505+
* Java AWT Image object associated with this renderer. For the 1.0 version
506+
* of P2D and P3D, this was associated with their MemoryImageSource.
507+
* For PGraphicsJava2D, it will be the offscreen drawing buffer.
508+
*/
509+
public Image image;
510510

511511
// ........................................................
512512

core/src/processing/core/PGraphicsJava2D.java

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,14 @@
5252
public 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();

core/src/processing/core/PSurface.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
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) 2014 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+
123
package processing.core;
224

325
import java.awt.Color;

0 commit comments

Comments
 (0)