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.pipe;
27
28 import java.awt.Shape;
29 import java.awt.BasicStroke;
30 import java.awt.geom.PathIterator;
31 import java.awt.geom.AffineTransform;
32
33 import java.security.PrivilegedAction;
34 import java.security.AccessController;
35 import java.util.ServiceLoader;
36 import sun.security.action.GetPropertyAction;
37
38 import sun.awt.geom.PathConsumer2D;
39
40 /**
41 * This class abstracts a number of features for which the Java 2D
42 * implementation relies on proprietary licensed software libraries.
43 * Access to those features is now achieved by retrieving the singleton
44 * instance of this class and calling the appropriate methods on it.
45 * The 3 primary features abstracted here include:
46 * <dl>
47 * <dt>Shape createStrokedShape(Shape, [BasicStroke attributes]);
48 * <dd>This method implements the functionality of the method of the
49 * same name on the {@link BasicStroke} class.
50 * <dt>void strokeTo(Shape, [rendering parameters], PathConsumer2D);
51 * <dd>This method performs widening of the source path on the fly
52 * and sends the results to the given {@link PathConsumer2D} object.
53 * This procedure avoids having to create an intermediate Shape
54 * object to hold the results of the {@code createStrokedShape} method.
55 * The main user of this method is the Java 2D non-antialiasing renderer.
80 * setting the sun.java2d.renderer.trace property to any non-null value.
81 * <p>
82 * Parts of the system that need to use any of the above features should
83 * call {@code RenderingEngine.getInstance()} to obtain the properly
84 * registered (and possibly trace-enabled) version of the RenderingEngine.
85 */
86 public abstract class RenderingEngine {
87 private static RenderingEngine reImpl;
88
89 /**
90 * Returns an instance of {@code RenderingEngine} as determined
91 * by the installation environment and runtime flags.
92 * <p>
93 * A specific instance of the {@code RenderingEngine} can be
94 * chosen by specifying the runtime flag:
95 * <pre>
96 * java -Dsun.java2d.renderer=<classname>
97 * </pre>
98 *
99 * If no specific {@code RenderingEngine} is specified on the command
100 * or Ductus renderer is specified, it will attempt loading the
101 * sun.dc.DuctusRenderingEngine class using Class.forName as a fastpath;
102 * if not found, use the ServiceLoader.
103 * If no specific {@code RenderingEngine} is specified on the command
104 * line then the last one returned by enumerating all subclasses of
105 * {@code RenderingEngine} known to the ServiceLoader is used.
106 * <p>
107 * Runtime tracing of the actions of the {@code RenderingEngine}
108 * can be enabled by specifying the runtime flag:
109 * <pre>
110 * java -Dsun.java2d.renderer.trace=<any string>
111 * </pre>
112 * @return an instance of {@code RenderingEngine}
113 * @since 1.7
114 */
115 public static synchronized RenderingEngine getInstance() {
116 if (reImpl != null) {
117 return reImpl;
118 }
119
120 reImpl =
121 AccessController.doPrivileged(new PrivilegedAction<RenderingEngine>() {
122 public RenderingEngine run() {
123 final String ductusREClass = "sun.dc.DuctusRenderingEngine";
124 String reClass =
125 System.getProperty("sun.java2d.renderer", ductusREClass);
126 if (reClass.equals(ductusREClass)) {
127 try {
128 Class<?> cls = Class.forName(ductusREClass);
129 return (RenderingEngine) cls.newInstance();
130 } catch (ReflectiveOperationException ignored) {
131 // not found
132 }
133 }
134
135 ServiceLoader<RenderingEngine> reLoader =
136 ServiceLoader.loadInstalled(RenderingEngine.class);
137
138 RenderingEngine service = null;
139
140 for (RenderingEngine re : reLoader) {
141 service = re;
142 if (re.getClass().getName().equals(reClass)) {
143 break;
144 }
145 }
146 return service;
147 }
148 });
149
150 if (reImpl == null) {
151 throw new InternalError("No RenderingEngine module found");
152 }
153
154 GetPropertyAction gpa =
155 new GetPropertyAction("sun.java2d.renderer.trace");
156 String reTrace = AccessController.doPrivileged(gpa);
157 if (reTrace != null) {
158 reImpl = new Tracer(reImpl);
159 }
160
161 return reImpl;
162 }
163
164 /**
165 * Create a widened path as specified by the parameters.
166 * <p>
|
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.pipe;
27
28 import java.awt.Shape;
29 import java.awt.BasicStroke;
30 import java.awt.geom.PathIterator;
31 import java.awt.geom.AffineTransform;
32
33 import java.security.PrivilegedAction;
34 import java.security.AccessController;
35 import sun.security.action.GetPropertyAction;
36
37 import sun.awt.geom.PathConsumer2D;
38
39 /**
40 * This class abstracts a number of features for which the Java 2D
41 * implementation relies on proprietary licensed software libraries.
42 * Access to those features is now achieved by retrieving the singleton
43 * instance of this class and calling the appropriate methods on it.
44 * The 3 primary features abstracted here include:
45 * <dl>
46 * <dt>Shape createStrokedShape(Shape, [BasicStroke attributes]);
47 * <dd>This method implements the functionality of the method of the
48 * same name on the {@link BasicStroke} class.
49 * <dt>void strokeTo(Shape, [rendering parameters], PathConsumer2D);
50 * <dd>This method performs widening of the source path on the fly
51 * and sends the results to the given {@link PathConsumer2D} object.
52 * This procedure avoids having to create an intermediate Shape
53 * object to hold the results of the {@code createStrokedShape} method.
54 * The main user of this method is the Java 2D non-antialiasing renderer.
79 * setting the sun.java2d.renderer.trace property to any non-null value.
80 * <p>
81 * Parts of the system that need to use any of the above features should
82 * call {@code RenderingEngine.getInstance()} to obtain the properly
83 * registered (and possibly trace-enabled) version of the RenderingEngine.
84 */
85 public abstract class RenderingEngine {
86 private static RenderingEngine reImpl;
87
88 /**
89 * Returns an instance of {@code RenderingEngine} as determined
90 * by the installation environment and runtime flags.
91 * <p>
92 * A specific instance of the {@code RenderingEngine} can be
93 * chosen by specifying the runtime flag:
94 * <pre>
95 * java -Dsun.java2d.renderer=<classname>
96 * </pre>
97 *
98 * If no specific {@code RenderingEngine} is specified on the command
99 * or Ductus renderer is specified, it will first attempt loading the
100 * sun.dc.DuctusRenderingEngine class using Class.forName, if that
101 * is not found, then it will look for Pisces.
102 * <p>
103 * Runtime tracing of the actions of the {@code RenderingEngine}
104 * can be enabled by specifying the runtime flag:
105 * <pre>
106 * java -Dsun.java2d.renderer.trace=<any string>
107 * </pre>
108 * @return an instance of {@code RenderingEngine}
109 * @since 1.7
110 */
111 public static synchronized RenderingEngine getInstance() {
112 if (reImpl != null) {
113 return reImpl;
114 }
115
116 reImpl =
117 AccessController.doPrivileged(new PrivilegedAction<RenderingEngine>() {
118 public RenderingEngine run() {
119 /* Look first for ductus or an app-override renderer,
120 * if not specified or present, then look for pisces.
121 */
122 final String ductusREClass = "sun.dc.DuctusRenderingEngine";
123 final String piscesREClass = "sun.java2d.pisces.PiscesRenderingEngine";
124 String reClass = System.getProperty("sun.java2d.renderer");
125 if (reClass == null) {
126 reClass = ductusREClass;
127 }
128 try {
129 Class<?> cls = Class.forName(reClass);
130 return (RenderingEngine) cls.newInstance();
131 } catch (ReflectiveOperationException ignored) {
132 // not found
133 }
134 try {
135 Class<?> cls = Class.forName(piscesREClass);
136 return (RenderingEngine) cls.newInstance();
137 } catch (ReflectiveOperationException ignored) {
138 // not found
139 }
140
141 return null;
142 }
143 });
144
145 if (reImpl == null) {
146 throw new InternalError("No RenderingEngine module found");
147 }
148
149 GetPropertyAction gpa =
150 new GetPropertyAction("sun.java2d.renderer.trace");
151 String reTrace = AccessController.doPrivileged(gpa);
152 if (reTrace != null) {
153 reImpl = new Tracer(reImpl);
154 }
155
156 return reImpl;
157 }
158
159 /**
160 * Create a widened path as specified by the parameters.
161 * <p>
|