src/share/classes/sun/java2d/pipe/RenderingEngine.java

Print this page




  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=&lt;classname&gt;
  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=&lt;any string&gt;
 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>
 167      * The specified {@code src} {@link Shape} is widened according
 168      * to the specified attribute parameters as per the
 169      * {@link BasicStroke} specification.
 170      *
 171      * @param src the source path to be widened
 172      * @param width the width of the widened path as per {@code BasicStroke}
 173      * @param caps the end cap decorations as per {@code BasicStroke}
 174      * @param join the segment join decorations as per {@code BasicStroke}
 175      * @param miterlimit the miter limit as per {@code BasicStroke}




  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=&lt;classname&gt;
  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=&lt;any string&gt;
 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         /* Look first for ductus or an app-override renderer,
 117          * if not specified or present, then look for pisces.
 118          */
 119         final String ductusREClass = "sun.dc.DuctusRenderingEngine";
 120         final String piscesREClass = "sun.java2d.pisces.PiscesRenderingEngine";
 121         GetPropertyAction gpa =
 122             new GetPropertyAction("sun.java2d.renderer", ductusREClass);
 123         String reClass = AccessController.doPrivileged(gpa);
 124         try {
 125             Class<?> cls = Class.forName(reClass);
 126             reImpl = (RenderingEngine) cls.newInstance();
 127         } catch (ReflectiveOperationException ignored0) {
 128             try {
 129                 Class<?> cls = Class.forName(piscesREClass);
 130                 reImpl = (RenderingEngine) cls.newInstance();
 131             } catch (ReflectiveOperationException ignored1) {










 132             }

 133         }

 134 
 135         if (reImpl == null) {
 136             throw new InternalError("No RenderingEngine module found");
 137         }
 138 
 139         gpa = new GetPropertyAction("sun.java2d.renderer.trace");

 140         String reTrace = AccessController.doPrivileged(gpa);
 141         if (reTrace != null) {
 142             reImpl = new Tracer(reImpl);
 143         }
 144 
 145         return reImpl;
 146     }
 147 
 148     /**
 149      * Create a widened path as specified by the parameters.
 150      * <p>
 151      * The specified {@code src} {@link Shape} is widened according
 152      * to the specified attribute parameters as per the
 153      * {@link BasicStroke} specification.
 154      *
 155      * @param src the source path to be widened
 156      * @param width the width of the widened path as per {@code BasicStroke}
 157      * @param caps the end cap decorations as per {@code BasicStroke}
 158      * @param join the segment join decorations as per {@code BasicStroke}
 159      * @param miterlimit the miter limit as per {@code BasicStroke}