Path: blob/master/src/java.desktop/share/classes/sun/java2d/marlin/MarlinProperties.java
41159 views
/*1* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.marlin;2627import java.security.AccessController;28import static sun.java2d.marlin.MarlinUtils.logInfo;29import sun.security.action.GetPropertyAction;3031public final class MarlinProperties {3233private MarlinProperties() {34// no-op35}3637// marlin system properties3839public static boolean isUseThreadLocal() {40return getBoolean("sun.java2d.renderer.useThreadLocal", "true");41}4243/**44* Return the initial edge capacity used to define initial arrays45* (edges, polystack, crossings)46*47* @return 256 < initial edges < 65536 (4096 by default)48*/49public static int getInitialEdges() {50return align(51getInteger("sun.java2d.renderer.edges", 4096, 64, 64 * 1024),5264);53}5455/**56* Return the initial pixel width used to define initial arrays57* (tile AA chunk, alpha line)58*59* @return 64 < initial pixel size < 32768 (4096 by default)60*/61public static int getInitialPixelWidth() {62return align(63getInteger("sun.java2d.renderer.pixelWidth", 4096, 64, 32 * 1024),6464);65}6667/**68* Return the initial pixel height used to define initial arrays69* (buckets)70*71* @return 64 < initial pixel size < 32768 (2176 by default)72*/73public static int getInitialPixelHeight() {74return align(75getInteger("sun.java2d.renderer.pixelHeight", 2176, 64, 32 * 1024),7664);77}7879/**80* Return the log(2) corresponding to subpixel on x-axis81*82* @return 0 (1 subpixels) < initial pixel size < 8 (256 subpixels)83* (8 by default ie 256 subpixels)84*/85public static int getSubPixel_Log2_X() {86return getInteger("sun.java2d.renderer.subPixel_log2_X", 8, 0, 8);87}8889/**90* Return the log(2) corresponding to subpixel on y-axis91*92* @return 0 (1 subpixels) < initial pixel size < 8 (256 subpixels)93* (3 by default ie 8 subpixels)94*/95public static int getSubPixel_Log2_Y() {96return getInteger("sun.java2d.renderer.subPixel_log2_Y", 3, 0, 8);97}9899/**100* Return the log(2) corresponding to the square tile size in pixels101*102* @return 3 (8x8 pixels) < tile size < 10 (1024x1024 pixels)103* (5 by default ie 32x32 pixels)104*/105public static int getTileSize_Log2() {106return getInteger("sun.java2d.renderer.tileSize_log2", 5, 3, 10);107}108109/**110* Return the log(2) corresponding to the tile width in pixels111*112* @return 3 (8 pixels) < tile width < 10 (1024 pixels)113* (5 by default ie 32x32 pixels)114*/115public static int getTileWidth_Log2() {116return getInteger("sun.java2d.renderer.tileWidth_log2", 5, 3, 10);117}118119/**120* Return the log(2) corresponding to the block size in pixels121*122* @return 3 (8 pixels) < block size < 8 (256 pixels)123* (5 by default ie 32 pixels)124*/125public static int getBlockSize_Log2() {126return getInteger("sun.java2d.renderer.blockSize_log2", 5, 3, 8);127}128129// RLE / blockFlags settings130131public static boolean isForceRLE() {132return getBoolean("sun.java2d.renderer.forceRLE", "false");133}134135public static boolean isForceNoRLE() {136return getBoolean("sun.java2d.renderer.forceNoRLE", "false");137}138139public static boolean isUseTileFlags() {140return getBoolean("sun.java2d.renderer.useTileFlags", "true");141}142143public static boolean isUseTileFlagsWithHeuristics() {144return isUseTileFlags()145&& getBoolean("sun.java2d.renderer.useTileFlags.useHeuristics", "true");146}147148public static int getRLEMinWidth() {149return getInteger("sun.java2d.renderer.rleMinWidth", 64, 0, Integer.MAX_VALUE);150}151152// optimisation parameters153154public static boolean isUseSimplifier() {155return getBoolean("sun.java2d.renderer.useSimplifier", "false");156}157158public static boolean isUsePathSimplifier() {159return getBoolean("sun.java2d.renderer.usePathSimplifier", "false");160}161162public static float getPathSimplifierPixelTolerance() {163// default: MIN_PEN_SIZE or less ?164return getFloat("sun.java2d.renderer.pathSimplifier.pixTol",165(1.0f / MarlinConst.MIN_SUBPIXELS),1661e-3f,16710.0f);168}169170public static boolean isDoClip() {171return getBoolean("sun.java2d.renderer.clip", "true");172}173174public static boolean isDoClipRuntimeFlag() {175return getBoolean("sun.java2d.renderer.clip.runtime.enable", "false");176}177178public static boolean isDoClipAtRuntime() {179return getBoolean("sun.java2d.renderer.clip.runtime", "true");180}181182public static boolean isDoClipSubdivider() {183return getBoolean("sun.java2d.renderer.clip.subdivider", "true");184}185186public static float getSubdividerMinLength() {187return getFloat("sun.java2d.renderer.clip.subdivider.minLength", 100.0f, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY);188}189190// debugging parameters191192public static boolean isDoStats() {193return getBoolean("sun.java2d.renderer.doStats", "false");194}195196public static boolean isDoMonitors() {197return getBoolean("sun.java2d.renderer.doMonitors", "false");198}199200public static boolean isDoChecks() {201return getBoolean("sun.java2d.renderer.doChecks", "false");202}203204// logging parameters205206public static boolean isLoggingEnabled() {207return getBoolean("sun.java2d.renderer.log", "false");208}209210public static boolean isUseLogger() {211return getBoolean("sun.java2d.renderer.useLogger", "false");212}213214public static boolean isLogCreateContext() {215return getBoolean("sun.java2d.renderer.logCreateContext", "false");216}217218public static boolean isLogUnsafeMalloc() {219return getBoolean("sun.java2d.renderer.logUnsafeMalloc", "false");220}221222// quality settings223224public static float getCurveLengthError() {225return getFloat("sun.java2d.renderer.curve_len_err", 0.01f, 1e-6f, 1.0f);226}227228public static float getCubicDecD2() {229return getFloat("sun.java2d.renderer.cubic_dec_d2", 1.0f, 1e-5f, 4.0f);230}231232public static float getCubicIncD1() {233return getFloat("sun.java2d.renderer.cubic_inc_d1", 0.2f, 1e-6f, 1.0f);234}235236public static float getQuadDecD2() {237return getFloat("sun.java2d.renderer.quad_dec_d2", 0.5f, 1e-5f, 4.0f);238}239240// system property utilities241@SuppressWarnings("removal")242static boolean getBoolean(final String key, final String def) {243return Boolean.valueOf(AccessController.doPrivileged(244new GetPropertyAction(key, def)));245}246247static int getInteger(final String key, final int def,248final int min, final int max)249{250@SuppressWarnings("removal")251final String property = AccessController.doPrivileged(252new GetPropertyAction(key));253254int value = def;255if (property != null) {256try {257value = Integer.decode(property);258} catch (NumberFormatException e) {259logInfo("Invalid integer value for " + key + " = " + property);260}261}262263// check for invalid values264if ((value < min) || (value > max)) {265logInfo("Invalid value for " + key + " = " + value266+ "; expected value in range[" + min + ", " + max + "] !");267value = def;268}269return value;270}271272static int align(final int val, final int norm) {273final int ceil = FloatMath.ceil_int( ((float) val) / norm);274return ceil * norm;275}276277public static double getDouble(final String key, final double def,278final double min, final double max)279{280double value = def;281@SuppressWarnings("removal")282final String property = AccessController.doPrivileged(283new GetPropertyAction(key));284285if (property != null) {286try {287value = Double.parseDouble(property);288} catch (NumberFormatException nfe) {289logInfo("Invalid value for " + key + " = " + property + " !");290}291}292// check for invalid values293if (value < min || value > max) {294logInfo("Invalid value for " + key + " = " + value295+ "; expect value in range[" + min + ", " + max + "] !");296value = def;297}298return value;299}300301public static float getFloat(final String key, final float def,302final float min, final float max)303{304return (float)getDouble(key, def, min, max);305}306}307308309