Skip to content

Commit

Permalink
merge: profile setting (quality/speed) + render queue tuning (buffer …
Browse files Browse the repository at this point in the history
…/ delay)
  • Loading branch information
bourgesl committed May 9, 2018
1 parent 06d619e commit 060a4d3
Show file tree
Hide file tree
Showing 9 changed files with 686 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/marlin/pisces/DDasher.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ public void moveTo(final double x0, final double y0) {

private void emitSeg(double[] buf, int off, int type) {
switch (type) {
case 4:
out.lineTo(buf[off], buf[off + 1]);
return;
case 8:
out.curveTo(buf[off ], buf[off + 1],
buf[off + 2], buf[off + 3],
Expand All @@ -278,9 +281,6 @@ private void emitSeg(double[] buf, int off, int type) {
out.quadTo(buf[off ], buf[off + 1],
buf[off + 2], buf[off + 3]);
return;
case 4:
out.lineTo(buf[off], buf[off + 1]);
return;
default:
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/marlin/pisces/DHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -765,17 +765,17 @@ void pullAll(final DPathConsumer2D io) {
io.lineTo(_curves[e], _curves[e+1]);
e += 2;
continue;
case TYPE_QUADTO:
io.quadTo(_curves[e], _curves[e+1],
_curves[e+2], _curves[e+3]);
e += 4;
continue;
case TYPE_CUBICTO:
io.curveTo(_curves[e], _curves[e+1],
_curves[e+2], _curves[e+3],
_curves[e+4], _curves[e+5]);
e += 6;
continue;
case TYPE_QUADTO:
io.quadTo(_curves[e], _curves[e+1],
_curves[e+2], _curves[e+3]);
e += 4;
continue;
default:
}
}
Expand Down Expand Up @@ -807,17 +807,17 @@ void popAll(final DPathConsumer2D io) {
e -= 2;
io.lineTo(_curves[e], _curves[e+1]);
continue;
case TYPE_QUADTO:
e -= 4;
io.quadTo(_curves[e], _curves[e+1],
_curves[e+2], _curves[e+3]);
continue;
case TYPE_CUBICTO:
e -= 6;
io.curveTo(_curves[e], _curves[e+1],
_curves[e+2], _curves[e+3],
_curves[e+4], _curves[e+5]);
continue;
case TYPE_QUADTO:
e -= 4;
io.quadTo(_curves[e], _curves[e+1],
_curves[e+2], _curves[e+3]);
continue;
default:
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/marlin/pisces/DMarlinRenderingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,10 @@ private static void logSettings(final String reClass) {
logInfo("sun.java2d.renderer.pixelHeight = "
+ MarlinConst.INITIAL_PIXEL_HEIGHT);

logInfo("sun.java2d.renderer.profile = "
+ (MarlinProperties.isProfileQuality() ?
"quality" : "speed"));

logInfo("sun.java2d.renderer.subPixel_log2_X = "
+ MarlinConst.SUBPIXEL_LG_POSITIONS_X);
logInfo("sun.java2d.renderer.subPixel_log2_Y = "
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/marlin/pisces/Dasher.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ public void moveTo(final float x0, final float y0) {

private void emitSeg(float[] buf, int off, int type) {
switch (type) {
case 4:
out.lineTo(buf[off], buf[off + 1]);
return;
case 8:
out.curveTo(buf[off ], buf[off + 1],
buf[off + 2], buf[off + 3],
Expand All @@ -279,9 +282,6 @@ private void emitSeg(float[] buf, int off, int type) {
out.quadTo(buf[off ], buf[off + 1],
buf[off + 2], buf[off + 3]);
return;
case 4:
out.lineTo(buf[off], buf[off + 1]);
return;
default:
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/marlin/pisces/Helpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -773,17 +773,17 @@ void pullAll(final PathConsumer2D io) {
io.lineTo(_curves[e], _curves[e+1]);
e += 2;
continue;
case TYPE_QUADTO:
io.quadTo(_curves[e], _curves[e+1],
_curves[e+2], _curves[e+3]);
e += 4;
continue;
case TYPE_CUBICTO:
io.curveTo(_curves[e], _curves[e+1],
_curves[e+2], _curves[e+3],
_curves[e+4], _curves[e+5]);
e += 6;
continue;
case TYPE_QUADTO:
io.quadTo(_curves[e], _curves[e+1],
_curves[e+2], _curves[e+3]);
e += 4;
continue;
default:
}
}
Expand Down Expand Up @@ -815,17 +815,17 @@ void popAll(final PathConsumer2D io) {
e -= 2;
io.lineTo(_curves[e], _curves[e+1]);
continue;
case TYPE_QUADTO:
e -= 4;
io.quadTo(_curves[e], _curves[e+1],
_curves[e+2], _curves[e+3]);
continue;
case TYPE_CUBICTO:
e -= 6;
io.curveTo(_curves[e], _curves[e+1],
_curves[e+2], _curves[e+3],
_curves[e+4], _curves[e+5]);
continue;
case TYPE_QUADTO:
e -= 4;
io.quadTo(_curves[e], _curves[e+1],
_curves[e+2], _curves[e+3]);
continue;
default:
}
}
Expand Down
119 changes: 109 additions & 10 deletions src/main/java/org/marlin/pisces/MarlinProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,82 @@
package org.marlin.pisces;

import java.security.AccessController;
import java.security.PrivilegedAction;
import static org.marlin.pisces.MarlinUtils.logInfo;
import sun.security.action.GetPropertyAction;

public final class MarlinProperties {

private static Boolean SUPPORT_LARGE_TILES = null;

private MarlinProperties() {
// no-op
}

// Specific AWT / Java2D Graphics Environment checks

private static boolean supportsLargeTiles() {
if (SUPPORT_LARGE_TILES != null) {
return SUPPORT_LARGE_TILES.booleanValue();
}
boolean useLargeTiles = false;
try {
// Due to bootstrapping issue with GraphicsEnvironment static initializers,
// Try detecting the awt / java2d pipeline in action using only
// system & env properties:
if (isHeadless()) {
useLargeTiles = true;
} else {
final String osName = getString("os.name", "");
// Ignore Windows / Mac, only Linux:
if ("Linux".equals(osName)) {
final boolean useGL = getBoolean("sun.java2d.opengl", "false");
final boolean useXR = getBoolean("sun.java2d.xrender", "true");
if (!useGL && useXR) {
// !OpenGL AND XRender on Linux:
useLargeTiles = true;
}
}
}
} finally {
SUPPORT_LARGE_TILES = Boolean.valueOf(useLargeTiles);
}
return useLargeTiles;
}

private static boolean isHeadless() {
// Mimics java.awt.GraphicsEnvironment.getHeadlessProperty():
return AccessController.doPrivileged(
new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
String nm = System.getProperty("java.awt.headless");

if (nm == null) {
String osName = System.getProperty("os.name");
if (osName.contains("OS X") && "sun.awt.HToolkit".equals(
System.getProperty("awt.toolkit")))
{
return Boolean.TRUE;
} else {
final String display = System.getenv("DISPLAY");
return Boolean.valueOf(
("Linux".equals(osName) ||
"SunOS".equals(osName) ||
"FreeBSD".equals(osName) ||
"NetBSD".equals(osName) ||
"OpenBSD".equals(osName) ||
"AIX".equals(osName)) &&
(display == null || display.trim().isEmpty()));
}
} else {
return Boolean.valueOf(nm);
}
}
}
);
}

// marlin system properties

public static boolean isUseThreadLocal() {
Expand Down Expand Up @@ -77,6 +144,25 @@ public static int getInitialPixelHeight() {
64);
}

/**
* Return true if the profile is 'quality' (default) over 'speed'
*
* @return true if the profile is 'quality' (default), false otherwise
*/
public static boolean isProfileQuality() {
final String key = "sun.java2d.renderer.profile";
final String profile = getString(key, "quality");
if ("quality".equals(profile)) {
return true;
}
if ("speed".equals(profile)) {
return false;
}
logInfo("Invalid value for " + key + " = " + profile
+ "; expect value in [quality, speed] !");
return true;
}

/**
* Return the log(2) corresponding to subpixel on x-axis
*
Expand All @@ -91,30 +177,36 @@ public static int getSubPixel_Log2_X() {
* Return the log(2) corresponding to subpixel on y-axis
*
* @return 0 (1 subpixels) < initial pixel size < 8 (256 subpixels)
* (3 by default ie 8 subpixels)
* (3 by default ie 8 subpixels for the quality profile)
* (2 by default ie 4 subpixels for the speed profile)
*/
public static int getSubPixel_Log2_Y() {
return getInteger("sun.java2d.renderer.subPixel_log2_Y", 3, 0, 8);
final int def = isProfileQuality() ? 3 : 2;
return getInteger("sun.java2d.renderer.subPixel_log2_Y", def, 0, 8);
}

/**
* Return the log(2) corresponding to the square tile size in pixels
*
* @return 3 (8x8 pixels) < tile size < 10 (1024x1024 pixels)
* (5 by default ie 32x32 pixels)
* (6 by default ie 128x64 pixels if large tile supported)
* (5 by default ie 32x32 pixels otherwise)
*/
public static int getTileSize_Log2() {
return getInteger("sun.java2d.renderer.tileSize_log2", 5, 3, 10);
final int def = supportsLargeTiles() ? 6 : 5;
return getInteger("sun.java2d.renderer.tileSize_log2", def, 3, 10);
}

/**
* Return the log(2) corresponding to the tile width in pixels
*
* @return 3 (8 pixels) < tile width < 10 (1024 pixels)
* (5 by default ie 32x32 pixels)
* (7 by default ie 128x64 pixels if large tile supported)
* (5 by default ie 32x32 pixels otherwise)
*/
public static int getTileWidth_Log2() {
return getInteger("sun.java2d.renderer.tileWidth_log2", 5, 3, 10);
final int def = supportsLargeTiles() ? 7 : 5;
return getInteger("sun.java2d.renderer.tileWidth_log2", def, 3, 10);
}

/**
Expand Down Expand Up @@ -221,24 +313,31 @@ public static boolean isLogUnsafeMalloc() {
}

// quality settings

public static float getCurveLengthError() {
return getFloat("sun.java2d.renderer.curve_len_err", 0.01f, 1e-6f, 1.0f);
}

public static float getCubicDecD2() {
return getFloat("sun.java2d.renderer.cubic_dec_d2", 1.0f, 1e-5f, 4.0f);
final float def = isProfileQuality() ? 1.0f : 2.5f;
return getFloat("sun.java2d.renderer.cubic_dec_d2", def, 1e-5f, 4.0f);
}

public static float getCubicIncD1() {
return getFloat("sun.java2d.renderer.cubic_inc_d1", 0.2f, 1e-6f, 1.0f);
final float def = isProfileQuality() ? 0.2f : 0.5f;
return getFloat("sun.java2d.renderer.cubic_inc_d1", def, 1e-6f, 1.0f);
}

public static float getQuadDecD2() {
return getFloat("sun.java2d.renderer.quad_dec_d2", 0.5f, 1e-5f, 4.0f);
final float def = isProfileQuality() ? 0.5f : 1.0f;
return getFloat("sun.java2d.renderer.quad_dec_d2", def, 1e-5f, 4.0f);
}

// system property utilities
static String getString(final String key, final String def) {
return AccessController.doPrivileged(
new GetPropertyAction(key, def));
}

static boolean getBoolean(final String key, final String def) {
return Boolean.valueOf(AccessController.doPrivileged(
new GetPropertyAction(key, def)));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/marlin/pisces/MarlinRenderingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,10 @@ private static void logSettings(final String reClass) {
logInfo("sun.java2d.renderer.pixelHeight = "
+ MarlinConst.INITIAL_PIXEL_HEIGHT);

logInfo("sun.java2d.renderer.profile = "
+ (MarlinProperties.isProfileQuality() ?
"quality" : "speed"));

logInfo("sun.java2d.renderer.subPixel_log2_X = "
+ MarlinConst.SUBPIXEL_LG_POSITIONS_X);
logInfo("sun.java2d.renderer.subPixel_log2_Y = "
Expand Down
Loading

0 comments on commit 060a4d3

Please sign in to comment.