1 /*
   2  * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.java2d.marlin;
  27 
  28 import java.security.AccessController;
  29 import static sun.java2d.marlin.MarlinUtils.logInfo;
  30 import sun.security.action.GetPropertyAction;
  31 
  32 public final class MarlinProperties {
  33 
  34     private MarlinProperties() {
  35         // no-op
  36     }
  37 
  38     // marlin system properties
  39 
  40     public static boolean isUseThreadLocal() {
  41         return getBoolean("sun.java2d.renderer.useThreadLocal", "true");
  42     }
  43 
  44     /**
  45      * Return the initial pixel size used to define initial arrays
  46      * (tile AA chunk, alpha line, buckets)
  47      *
  48      * @return 64 < initial pixel size < 32768 (2048 by default)
  49      */
  50     public static int getInitialImageSize() {
  51         return getInteger("sun.java2d.renderer.pixelsize", 2048, 64, 32 * 1024);
  52     }
  53 
  54     /**
  55      * Return the log(2) corresponding to subpixel on x-axis (
  56      *
  57      * @return 1 (2 subpixels) < initial pixel size < 4 (256 subpixels)
  58      * (3 by default ie 8 subpixels)
  59      */
  60     public static int getSubPixel_Log2_X() {
  61         return getInteger("sun.java2d.renderer.subPixel_log2_X", 3, 1, 8);
  62     }
  63 
  64     /**
  65      * Return the log(2) corresponding to subpixel on y-axis (
  66      *
  67      * @return 1 (2 subpixels) < initial pixel size < 8 (256 subpixels)
  68      * (3 by default ie 8 subpixels)
  69      */
  70     public static int getSubPixel_Log2_Y() {
  71         return getInteger("sun.java2d.renderer.subPixel_log2_Y", 3, 1, 8);
  72     }
  73 
  74     /**
  75      * Return the log(2) corresponding to the square tile size in pixels
  76      *
  77      * @return 3 (8x8 pixels) < tile size < 8 (256x256 pixels)
  78      * (5 by default ie 32x32 pixels)
  79      */
  80     public static int getTileSize_Log2() {
  81         return getInteger("sun.java2d.renderer.tileSize_log2", 5, 3, 8);
  82     }
  83 
  84     /**
  85      * Return the log(2) corresponding to the block size in pixels
  86      *
  87      * @return 3 (8 pixels) < block size < 8 (256 pixels)
  88      * (5 by default ie 32 pixels)
  89      */
  90     public static int getBlockSize_Log2() {
  91         return getInteger("sun.java2d.renderer.blockSize_log2", 5, 3, 8);
  92     }
  93 
  94     // RLE / blockFlags settings
  95 
  96     public static boolean isForceRLE() {
  97         return getBoolean("sun.java2d.renderer.forceRLE", "false");
  98     }
  99 
 100     public static boolean isForceNoRLE() {
 101         return getBoolean("sun.java2d.renderer.forceNoRLE", "false");
 102     }
 103 
 104     public static boolean isUseTileFlags() {
 105         return getBoolean("sun.java2d.renderer.useTileFlags", "true");
 106     }
 107 
 108     public static boolean isUseTileFlagsWithHeuristics() {
 109         return isUseTileFlags()
 110         && getBoolean("sun.java2d.renderer.useTileFlags.useHeuristics", "true");
 111     }
 112 
 113     public static int getRLEMinWidth() {
 114         return getInteger("sun.java2d.renderer.rleMinWidth", 64, 0, Integer.MAX_VALUE);
 115     }
 116 
 117     // optimisation parameters
 118 
 119     public static boolean isUseSimplifier() {
 120         return getBoolean("sun.java2d.renderer.useSimplifier", "false");
 121     }
 122 
 123     // debugging parameters
 124 
 125     public static boolean isDoStats() {
 126         return getBoolean("sun.java2d.renderer.doStats", "false");
 127     }
 128 
 129     public static boolean isDoMonitors() {
 130         return getBoolean("sun.java2d.renderer.doMonitors", "false");
 131     }
 132 
 133     public static boolean isDoChecks() {
 134         return getBoolean("sun.java2d.renderer.doChecks", "false");
 135     }
 136 
 137     // logging parameters
 138 
 139     public static boolean isUseLogger() {
 140         return getBoolean("sun.java2d.renderer.useLogger", "false");
 141     }
 142 
 143     public static boolean isLogCreateContext() {
 144         return getBoolean("sun.java2d.renderer.logCreateContext", "false");
 145     }
 146 
 147     public static boolean isLogUnsafeMalloc() {
 148         return getBoolean("sun.java2d.renderer.logUnsafeMalloc", "false");
 149     }
 150 
 151     // system property utilities
 152     static boolean getBoolean(final String key, final String def) {
 153         return Boolean.valueOf(AccessController.doPrivileged(
 154                   new GetPropertyAction(key, def)));
 155     }
 156 
 157     static int getInteger(final String key, final int def,
 158                                  final int min, final int max)
 159     {
 160         final String property = AccessController.doPrivileged(
 161                                     new GetPropertyAction(key));
 162 
 163         int value = def;
 164         if (property != null) {
 165             try {
 166                 value = Integer.decode(property);
 167             } catch (NumberFormatException e) {
 168                 logInfo("Invalid integer value for " + key + " = " + property);
 169             }
 170         }
 171 
 172         // check for invalid values
 173         if ((value < min) || (value > max)) {
 174             logInfo("Invalid value for " + key + " = " + value
 175                     + "; expected value in range[" + min + ", " + max + "] !");
 176             value = def;
 177         }
 178         return value;
 179     }
 180 
 181 }