1 /*
2  * Copyright (c) 2007, 2018, 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 
MarlinProperties()34     private MarlinProperties() {
35         // no-op
36     }
37 
38     // marlin system properties
39 
isUseThreadLocal()40     public static boolean isUseThreadLocal() {
41         return getBoolean("sun.java2d.renderer.useThreadLocal", "true");
42     }
43 
44     /**
45      * Return the initial edge capacity used to define initial arrays
46      * (edges, polystack, crossings)
47      *
48      * @return 256 < initial edges < 65536 (4096 by default)
49      */
getInitialEdges()50     public static int getInitialEdges() {
51         return align(
52             getInteger("sun.java2d.renderer.edges", 4096, 64, 64 * 1024),
53             64);
54     }
55 
56     /**
57      * Return the initial pixel width used to define initial arrays
58      * (tile AA chunk, alpha line)
59      *
60      * @return 64 < initial pixel size < 32768 (4096 by default)
61      */
getInitialPixelWidth()62     public static int getInitialPixelWidth() {
63         return align(
64             getInteger("sun.java2d.renderer.pixelWidth", 4096, 64, 32 * 1024),
65             64);
66     }
67 
68     /**
69      * Return the initial pixel height used to define initial arrays
70      * (buckets)
71      *
72      * @return 64 < initial pixel size < 32768 (2176 by default)
73      */
getInitialPixelHeight()74     public static int getInitialPixelHeight() {
75         return align(
76             getInteger("sun.java2d.renderer.pixelHeight", 2176, 64, 32 * 1024),
77             64);
78     }
79 
80     /**
81      * Return the log(2) corresponding to subpixel on x-axis
82      *
83      * @return 0 (1 subpixels) < initial pixel size < 8 (256 subpixels)
84      * (8 by default ie 256 subpixels)
85      */
getSubPixel_Log2_X()86     public static int getSubPixel_Log2_X() {
87         return getInteger("sun.java2d.renderer.subPixel_log2_X", 8, 0, 8);
88     }
89 
90     /**
91      * Return the log(2) corresponding to subpixel on y-axis
92      *
93      * @return 0 (1 subpixels) < initial pixel size < 8 (256 subpixels)
94      * (3 by default ie 8 subpixels)
95      */
getSubPixel_Log2_Y()96     public static int getSubPixel_Log2_Y() {
97         return getInteger("sun.java2d.renderer.subPixel_log2_Y", 3, 0, 8);
98     }
99 
100     /**
101      * Return the log(2) corresponding to the square tile size in pixels
102      *
103      * @return 3 (8x8 pixels) < tile size < 10 (1024x1024 pixels)
104      * (5 by default ie 32x32 pixels)
105      */
getTileSize_Log2()106     public static int getTileSize_Log2() {
107         return getInteger("sun.java2d.renderer.tileSize_log2", 5, 3, 10);
108     }
109 
110     /**
111      * Return the log(2) corresponding to the tile width in pixels
112      *
113      * @return 3 (8 pixels) < tile width < 10 (1024 pixels)
114      * (5 by default ie 32x32 pixels)
115      */
getTileWidth_Log2()116     public static int getTileWidth_Log2() {
117         return getInteger("sun.java2d.renderer.tileWidth_log2", 5, 3, 10);
118     }
119 
120     /**
121      * Return the log(2) corresponding to the block size in pixels
122      *
123      * @return 3 (8 pixels) < block size < 8 (256 pixels)
124      * (5 by default ie 32 pixels)
125      */
getBlockSize_Log2()126     public static int getBlockSize_Log2() {
127         return getInteger("sun.java2d.renderer.blockSize_log2", 5, 3, 8);
128     }
129 
130     // RLE / blockFlags settings
131 
isForceRLE()132     public static boolean isForceRLE() {
133         return getBoolean("sun.java2d.renderer.forceRLE", "false");
134     }
135 
isForceNoRLE()136     public static boolean isForceNoRLE() {
137         return getBoolean("sun.java2d.renderer.forceNoRLE", "false");
138     }
139 
isUseTileFlags()140     public static boolean isUseTileFlags() {
141         return getBoolean("sun.java2d.renderer.useTileFlags", "true");
142     }
143 
isUseTileFlagsWithHeuristics()144     public static boolean isUseTileFlagsWithHeuristics() {
145         return isUseTileFlags()
146         && getBoolean("sun.java2d.renderer.useTileFlags.useHeuristics", "true");
147     }
148 
getRLEMinWidth()149     public static int getRLEMinWidth() {
150         return getInteger("sun.java2d.renderer.rleMinWidth", 64, 0, Integer.MAX_VALUE);
151     }
152 
153     // optimisation parameters
154 
isUseSimplifier()155     public static boolean isUseSimplifier() {
156         return getBoolean("sun.java2d.renderer.useSimplifier", "false");
157     }
158 
isUsePathSimplifier()159     public static boolean isUsePathSimplifier() {
160         return getBoolean("sun.java2d.renderer.usePathSimplifier", "false");
161     }
162 
getPathSimplifierPixelTolerance()163     public static float getPathSimplifierPixelTolerance() {
164         // default: MIN_PEN_SIZE or less ?
165         return getFloat("sun.java2d.renderer.pathSimplifier.pixTol",
166                 (1.0f / MarlinConst.MIN_SUBPIXELS),
167                 1e-3f,
168                 10.0f);
169     }
170 
isDoClip()171     public static boolean isDoClip() {
172         return getBoolean("sun.java2d.renderer.clip", "true");
173     }
174 
isDoClipRuntimeFlag()175     public static boolean isDoClipRuntimeFlag() {
176         return getBoolean("sun.java2d.renderer.clip.runtime.enable", "false");
177     }
178 
isDoClipAtRuntime()179     public static boolean isDoClipAtRuntime() {
180         return getBoolean("sun.java2d.renderer.clip.runtime", "true");
181     }
182 
isDoClipSubdivider()183     public static boolean isDoClipSubdivider() {
184         return getBoolean("sun.java2d.renderer.clip.subdivider", "true");
185     }
186 
getSubdividerMinLength()187     public static float getSubdividerMinLength() {
188         return getFloat("sun.java2d.renderer.clip.subdivider.minLength", 100.0f, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY);
189     }
190 
191     // debugging parameters
192 
isDoStats()193     public static boolean isDoStats() {
194         return getBoolean("sun.java2d.renderer.doStats", "false");
195     }
196 
isDoMonitors()197     public static boolean isDoMonitors() {
198         return getBoolean("sun.java2d.renderer.doMonitors", "false");
199     }
200 
isDoChecks()201     public static boolean isDoChecks() {
202         return getBoolean("sun.java2d.renderer.doChecks", "false");
203     }
204 
205     // logging parameters
206 
isLoggingEnabled()207     public static boolean isLoggingEnabled() {
208         return getBoolean("sun.java2d.renderer.log", "false");
209     }
210 
isUseLogger()211     public static boolean isUseLogger() {
212         return getBoolean("sun.java2d.renderer.useLogger", "false");
213     }
214 
isLogCreateContext()215     public static boolean isLogCreateContext() {
216         return getBoolean("sun.java2d.renderer.logCreateContext", "false");
217     }
218 
isLogUnsafeMalloc()219     public static boolean isLogUnsafeMalloc() {
220         return getBoolean("sun.java2d.renderer.logUnsafeMalloc", "false");
221     }
222 
223     // quality settings
224 
getCurveLengthError()225     public static float getCurveLengthError() {
226         return getFloat("sun.java2d.renderer.curve_len_err", 0.01f, 1e-6f, 1.0f);
227     }
228 
getCubicDecD2()229     public static float getCubicDecD2() {
230         return getFloat("sun.java2d.renderer.cubic_dec_d2", 1.0f, 1e-5f, 4.0f);
231     }
232 
getCubicIncD1()233     public static float getCubicIncD1() {
234         return getFloat("sun.java2d.renderer.cubic_inc_d1", 0.2f, 1e-6f, 1.0f);
235     }
236 
getQuadDecD2()237     public static float getQuadDecD2() {
238         return getFloat("sun.java2d.renderer.quad_dec_d2", 0.5f, 1e-5f, 4.0f);
239     }
240 
241     // system property utilities
getBoolean(final String key, final String def)242     static boolean getBoolean(final String key, final String def) {
243         return Boolean.valueOf(AccessController.doPrivileged(
244                   new GetPropertyAction(key, def)));
245     }
246 
getInteger(final String key, final int def, final int min, final int max)247     static int getInteger(final String key, final int def,
248                                  final int min, final int max)
249     {
250         final String property = AccessController.doPrivileged(
251                                     new GetPropertyAction(key));
252 
253         int value = def;
254         if (property != null) {
255             try {
256                 value = Integer.decode(property);
257             } catch (NumberFormatException e) {
258                 logInfo("Invalid integer value for " + key + " = " + property);
259             }
260         }
261 
262         // check for invalid values
263         if ((value < min) || (value > max)) {
264             logInfo("Invalid value for " + key + " = " + value
265                     + "; expected value in range[" + min + ", " + max + "] !");
266             value = def;
267         }
268         return value;
269     }
270 
align(final int val, final int norm)271     static int align(final int val, final int norm) {
272         final int ceil = FloatMath.ceil_int( ((float) val) / norm);
273         return ceil * norm;
274     }
275 
getDouble(final String key, final double def, final double min, final double max)276     public static double getDouble(final String key, final double def,
277                                    final double min, final double max)
278     {
279         double value = def;
280         final String property = AccessController.doPrivileged(
281                                     new GetPropertyAction(key));
282 
283         if (property != null) {
284             try {
285                 value = Double.parseDouble(property);
286             } catch (NumberFormatException nfe) {
287                 logInfo("Invalid value for " + key + " = " + property + " !");
288             }
289         }
290         // check for invalid values
291         if (value < min || value > max) {
292             logInfo("Invalid value for " + key + " = " + value
293                     + "; expect value in range[" + min + ", " + max + "] !");
294             value = def;
295         }
296         return value;
297     }
298 
getFloat(final String key, final float def, final float min, final float max)299     public static float getFloat(final String key, final float def,
300                                  final float min, final float max)
301     {
302         return (float)getDouble(key, def, min, max);
303     }
304 }
305