Skip to content

Commit ed61c90

Browse files
committed
further work on retina and improving performance
1 parent d1c80d3 commit ed61c90

6 files changed

Lines changed: 441 additions & 92 deletions

File tree

core/src/processing/core/PApplet.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ public class PApplet extends Applet
228228
* This setting must be called before any AWT work happens, so that's why
229229
* it's such a terrible hack in how it's employed here. Calling setProperty()
230230
* inside setup() is a joke, since it's long since the AWT has been invoked.
231+
* <p/>
232+
* On OS X with a retina display, this option is ignored, because Apple's
233+
* Java implementation takes over and forces the Quartz renderer.
231234
*/
232235
// static public boolean useQuartz = true;
233236
static public boolean useQuartz = false;
@@ -254,6 +257,13 @@ public class PApplet extends Applet
254257
/** The frame containing this applet (if any) */
255258
public Frame frame;
256259

260+
// disabled on retina inside init()
261+
boolean useActive = true;
262+
// boolean useActive = false;
263+
// boolean useStrategy = true;
264+
boolean useStrategy = false;
265+
Canvas canvas;
266+
257267
// /**
258268
// * Usually just 0, but with multiple displays, the X and Y coordinates of
259269
// * the screen will depend on the current screen's position relative to
@@ -818,6 +828,11 @@ static public class RendererChangeException extends RuntimeException { }
818828
/** true if this sketch is being run by the PDE */
819829
boolean external = false;
820830

831+
/**
832+
* Not official API, using internally because of the tweaks required.
833+
*/
834+
boolean retina;
835+
821836

822837
static final String ERROR_MIN_MAX =
823838
"Cannot use min() or max() on an empty array.";
@@ -841,6 +856,20 @@ public void init() {
841856
// screenWidth = screen.width;
842857
// screenHeight = screen.height;
843858

859+
if (platform == MACOSX) {
860+
Float prop = (Float)
861+
getToolkit().getDesktopProperty("apple.awt.contentScaleFactor");
862+
if (prop != null) {
863+
retina = prop == 2;
864+
if (retina) {
865+
// The active-mode rendering seems to be 2x slower, so disable it
866+
// with retina. On a non-retina machine, however, useActive seems
867+
// the only (or best?) way to handle the rendering.
868+
useActive = false;
869+
}
870+
}
871+
}
872+
844873
// send tab keys through to the PApplet
845874
setFocusTraversalKeysEnabled(false);
846875

@@ -1930,6 +1959,10 @@ public void paint(Graphics screen) {
19301959
}
19311960
*/
19321961

1962+
// if (useActive) {
1963+
// return;
1964+
// }
1965+
19331966
// if (insideDraw) {
19341967
// new Exception().printStackTrace(System.out);
19351968
// }
@@ -1947,11 +1980,6 @@ public void paint(Graphics screen) {
19471980
}
19481981

19491982

1950-
boolean useActive = true;
1951-
// boolean useStrategy = true;
1952-
boolean useStrategy = false;
1953-
Canvas canvas;
1954-
19551983
protected synchronized void render() {
19561984
if (canvas == null) {
19571985
removeListeners(this);

core/src/processing/core/PConstants.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,10 @@ public interface PConstants {
467467
static final int ENABLE_STROKE_PURE = 9;
468468
static final int DISABLE_STROKE_PURE = -9;
469469

470-
static final int HINT_COUNT = 10;
470+
static final int ENABLE_RETINA_PIXELS = 10;
471+
static final int DISABLE_RETINA_PIXELS = -10;
472+
473+
static final int HINT_COUNT = 11;
471474

472475
// error messages
473476

core/src/processing/core/PGraphicsJava2D.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,12 @@ public int get(int x, int y) {
23632363

23642364

23652365
@Override
2366-
// public PImage getImpl(int x, int y, int w, int h) {
2366+
public PImage get() {
2367+
return get(0, 0, width, height);
2368+
}
2369+
2370+
2371+
@Override
23672372
protected void getImpl(int sourceX, int sourceY,
23682373
int sourceWidth, int sourceHeight,
23692374
PImage target, int targetX, int targetY) {
@@ -2393,12 +2398,6 @@ protected void getImpl(int sourceX, int sourceY,
23932398
}
23942399

23952400

2396-
@Override
2397-
public PImage get() {
2398-
return get(0, 0, width, height);
2399-
}
2400-
2401-
24022401
@Override
24032402
public void set(int x, int y, int argb) {
24042403
if ((x < 0) || (y < 0) || (x >= width) || (y >= height)) return;
@@ -2410,9 +2409,9 @@ public void set(int x, int y, int argb) {
24102409
}
24112410

24122411

2412+
//public void set(int x, int y, PImage img)
2413+
24132414

2414-
// protected void setImpl(int dx, int dy, int sx, int sy, int sw, int sh,
2415-
// PImage src) {
24162415
@Override
24172416
protected void setImpl(PImage sourceImage,
24182417
int sourceX, int sourceY,

0 commit comments

Comments
 (0)