diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 4394360b7..1c680709e 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -810,6 +810,7 @@ public class PApplet implements PConstants { boolean fullScreen; int display = -1; // use default GraphicsDevice[] displayDevices; + int pixelDensity = 1; String outputPath; OutputStream outputStream; @@ -967,6 +968,14 @@ public class PApplet implements PConstants { } + final public int sketchPixelDensity() { + return pixelDensity; + } + + + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + public int displayDensity() { if (display == SPAN) { // walk through all displays, use lowest common denominator @@ -1029,6 +1038,15 @@ public class PApplet implements PConstants { } + public void pixelDensity(int density) { + if (density != this.pixelDensity) { + if (insideSettings("pixelDensity", density)) { + this.pixelDensity = density; + } + } + } + + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @@ -5237,7 +5255,7 @@ public class PApplet implements PConstants { vessel.pixelWidth = actual.width; vessel.pixelHeight = actual.height; - vessel.pixelFactor = 1; + vessel.pixelDensity = 1; } requestImageCount--; } diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index 540d24c5f..23a733de3 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -698,9 +698,11 @@ public class PGraphics extends PImage implements PConstants { public void setParent(PApplet parent) { // ignore this.parent = parent; + // Some renderers (OpenGL) need to know what smoothing level will be used // before the rendering surface is even created. smooth = parent.sketchSmooth(); + pixelDensity = parent.sketchPixelDensity(); } @@ -747,8 +749,8 @@ public class PGraphics extends PImage implements PConstants { height = h; /** {@link PImage.pixelFactor} set in {@link PImage#PImage()} */ - pixelWidth = width * pixelFactor; - pixelHeight = height * pixelFactor; + pixelWidth = width * pixelDensity; + pixelHeight = height * pixelDensity; // if (surface != null) { // allocate(); @@ -8064,6 +8066,6 @@ public class PGraphics extends PImage implements PConstants { public boolean is2X() { - return pixelFactor == 2; + return pixelDensity == 2; } } diff --git a/core/src/processing/core/PGraphicsFX2D.java b/core/src/processing/core/PGraphicsFX2D.java index 07d0e1d76..30664d826 100644 --- a/core/src/processing/core/PGraphicsFX2D.java +++ b/core/src/processing/core/PGraphicsFX2D.java @@ -1900,8 +1900,8 @@ public class PGraphicsFX2D extends PGraphics { @Override public void loadPixels() { // pixelFactor = 2; - int wide = width * pixelFactor; - int high = height * pixelFactor; + int wide = width * pixelDensity; + int high = height * pixelDensity; if ((pixels == null) || (pixels.length != wide*high)) { pixels = new int[wide * high]; @@ -1917,7 +1917,7 @@ public class PGraphicsFX2D extends PGraphics { // } // } SnapshotParameters sp = new SnapshotParameters(); - if (pixelFactor == 2) { + if (pixelDensity == 2) { sp.setTransform(Transform.scale(2, 2)); } WritableImage wi = ((PSurfaceFX) surface).canvas.snapshot(sp, null); diff --git a/core/src/processing/core/PGraphicsFX2D2X.java b/core/src/processing/core/PGraphicsFX2D2X.java index 9fda4b8b3..f4c9bb179 100644 --- a/core/src/processing/core/PGraphicsFX2D2X.java +++ b/core/src/processing/core/PGraphicsFX2D2X.java @@ -25,6 +25,6 @@ package processing.core; public class PGraphicsFX2D2X extends PGraphics { public PGraphicsFX2D2X() { - pixelFactor = 2; + pixelDensity = 2; } } diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index 5e32599ca..1860abafe 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -272,8 +272,8 @@ public class PGraphicsJava2D extends PGraphics { public Graphics2D checkImage() { if (image == null || - ((BufferedImage) image).getWidth() != width*pixelFactor || - ((BufferedImage) image).getHeight() != height*pixelFactor) { + ((BufferedImage) image).getWidth() != width*pixelDensity || + ((BufferedImage) image).getHeight() != height*pixelDensity) { // ((VolatileImage) image).getWidth() != width || // ((VolatileImage) image).getHeight() != height) { // image = new BufferedImage(width * pixelFactor, height * pixelFactor @@ -299,8 +299,8 @@ public class PGraphicsJava2D extends PGraphics { // Formerly this was broken into separate versions based on offscreen or // not, but we may as well create a compatible image; it won't hurt, right? - int wide = width * pixelFactor; - int high = height * pixelFactor; + int wide = width * pixelDensity; + int high = height * pixelDensity; // System.out.println("re-creating image"); image = gc.createCompatibleImage(wide, high); // image = gc.createCompatibleVolatileImage(wide, high); @@ -375,6 +375,8 @@ public class PGraphicsJava2D extends PGraphics { checkSettings(); resetMatrix(); // reset model matrix vertexCount = 0; + + g2.scale(pixelDensity, pixelDensity); } diff --git a/core/src/processing/core/PGraphicsJava2D2X.java b/core/src/processing/core/PGraphicsJava2D2X.java index f17620211..db51b68a6 100644 --- a/core/src/processing/core/PGraphicsJava2D2X.java +++ b/core/src/processing/core/PGraphicsJava2D2X.java @@ -13,7 +13,7 @@ public class PGraphicsJava2D2X extends PGraphicsJava2D { public PGraphicsJava2D2X() { - pixelFactor = 2; + pixelDensity = 2; // retina = new PImage(); // retina.format = RGB; } diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index 4747ca59d..c8142540d 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -95,7 +95,7 @@ public class PImage implements PConstants, Cloneable { public int[] pixels; /** 1 for most images, 2 for hi-dpi/retina */ - public int pixelFactor; + public int pixelDensity = 1; /** Actual dimensions of pixels array, taking into account the 2x setting. */ public int pixelWidth; @@ -210,7 +210,7 @@ public class PImage implements PConstants, Cloneable { */ public PImage() { format = ARGB; // default to ARGB images for release 0116 - pixelFactor = 1; + pixelDensity = 1; } @@ -266,10 +266,10 @@ public class PImage implements PConstants, Cloneable { this.width = width; this.height = height; this.format = format; - this.pixelFactor = factor; + this.pixelDensity = factor; - pixelWidth = width * pixelFactor; - pixelHeight = height * pixelFactor; + pixelWidth = width * pixelDensity; + pixelHeight = height * pixelDensity; this.pixels = new int[pixelWidth * pixelHeight]; } @@ -330,7 +330,7 @@ public class PImage implements PConstants, Cloneable { pg.grabPixels(); } catch (InterruptedException e) { } } - pixelFactor = 1; + pixelDensity = 1; pixelWidth = width; pixelHeight = height; } @@ -632,7 +632,7 @@ public class PImage implements PConstants, Cloneable { } BufferedImage img = - shrinkImage((BufferedImage) getNative(), w*pixelFactor, h*pixelFactor); + shrinkImage((BufferedImage) getNative(), w*pixelDensity, h*pixelDensity); PImage temp = new PImage(img); this.pixelWidth = temp.width; @@ -641,8 +641,8 @@ public class PImage implements PConstants, Cloneable { // Get the resized pixel array this.pixels = temp.pixels; - this.width = pixelWidth / pixelFactor; - this.height = pixelHeight / pixelFactor; + this.width = pixelWidth / pixelDensity; + this.height = pixelHeight / pixelDensity; // Mark the pixels array as altered updatePixels(); @@ -858,9 +858,9 @@ public class PImage implements PConstants, Cloneable { targetFormat = ARGB; } - PImage target = new PImage(targetWidth / pixelFactor, - targetHeight / pixelFactor, - targetFormat, pixelFactor); + PImage target = new PImage(targetWidth / pixelDensity, + targetHeight / pixelDensity, + targetFormat, pixelDensity); target.parent = parent; // parent may be null so can't use createImage() if (w > 0 && h > 0) { getImpl(x, y, w, h, target, targetX, targetY); diff --git a/core/src/processing/opengl/PGraphics2D2X.java b/core/src/processing/opengl/PGraphics2D2X.java index f9246f36f..f9d01e9d2 100644 --- a/core/src/processing/opengl/PGraphics2D2X.java +++ b/core/src/processing/opengl/PGraphics2D2X.java @@ -26,6 +26,6 @@ public class PGraphics2D2X extends PGraphics2D { public PGraphics2D2X() { super(); - pixelFactor = 2; + pixelDensity = 2; } } \ No newline at end of file diff --git a/core/src/processing/opengl/PGraphics3D2X.java b/core/src/processing/opengl/PGraphics3D2X.java index 5d5600835..7315c338b 100644 --- a/core/src/processing/opengl/PGraphics3D2X.java +++ b/core/src/processing/opengl/PGraphics3D2X.java @@ -26,6 +26,6 @@ public class PGraphics3D2X extends PGraphics3D { public PGraphics3D2X() { super(); - pixelFactor = 2; + pixelDensity = 2; } } \ No newline at end of file diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index a867ca277..dc0f9e56f 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -706,7 +706,7 @@ public class PGraphicsOpenGL extends PGraphics { public float getPixelScale() { - if (surfaceJOGL == null) return pixelFactor; + if (surfaceJOGL == null) return pixelDensity; else return surfaceJOGL.getPixelScale(); }