jdk/src/share/classes/sun/java2d/pipe/RenderingEngine.java
author mchung
Tue, 14 Apr 2009 17:43:45 -0700
changeset 2695 d75c6ebf3ac6
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6818072: Load Ductus using Class.forName if exist instead of using the service loader Summary: First attempt Class.forName to load Ductus class before using service loader Reviewed-by: flar, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.java2d.pipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Shape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.BasicStroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.geom.PathIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.ServiceLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.awt.geom.PathConsumer2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This class abstracts a number of features for which the Java 2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * implementation relies on proprietary licensed software libraries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Access to those features is now achieved by retrieving the singleton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * instance of this class and calling the appropriate methods on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The 3 primary features abstracted here include:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <dt>Shape createStrokedShape(Shape, [BasicStroke attributes]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <dd>This method implements the functionality of the method of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * same name on the {@link BasicStroke} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <dt>void strokeTo(Shape, [rendering parameters], PathConsumer2D);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <dd>This method performs widening of the source path on the fly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * and sends the results to the given {@link PathConsumer2D} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * This procedure avoids having to create an intermediate Shape
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * object to hold the results of the {@code createStrokedShape} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * The main user of this method is the Java 2D non-antialiasing renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <dt>AATileGenerator getAATileGenerator(Shape, [rendering parameters]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <dd>This method returns an object which can iterate over the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * specified bounding box and produce tiles of coverage values for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * antialiased rendering.  The details of the operation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * {@link AATileGenerator} object are explained in its class comments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Additionally, the following informational method supplies important
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * data about the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <dt>float getMinimumAAPenSize()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <dd>This method provides information on how small the BasicStroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * line width can get before dropouts occur.  Rendering with a BasicStroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * is defined to never allow the line to have breaks, gaps, or dropouts
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * even if the width is set to 0.0f, so this information allows the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * {@link SunGraphics2D} class to detect the "thin line" case and set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * the rendering attributes accordingly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * At startup the runtime will load a single instance of this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * It searches the classpath for a registered provider of this API
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * and returns either the last one it finds, or the instance whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * class name matches the value supplied in the System property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * {@code sun.java2d.renderer}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * Additionally, a runtime System property flag can be set to trace
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * all calls to methods on the {@code RenderingEngine} in use by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * setting the sun.java2d.renderer.trace property to any non-null value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * Parts of the system that need to use any of the above features should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * call {@code RenderingEngine.getInstance()} to obtain the properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * registered (and possibly trace-enabled) version of the RenderingEngine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
public abstract class RenderingEngine {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static RenderingEngine reImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Returns an instance of {@code RenderingEngine} as determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * by the installation environment and runtime flags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * A specific instance of the {@code RenderingEngine} can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * chosen by specifying the runtime flag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *     java -Dsun.java2d.renderer=&lt;classname&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * </pre>
2695
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
    98
     *
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
    99
     * If no specific {@code RenderingEngine} is specified on the command
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   100
     * or Ductus renderer is specified, it will attempt loading the
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   101
     * sun.dc.DuctusRenderingEngine class using Class.forName as a fastpath;
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   102
     * if not found, use the ServiceLoader.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * If no specific {@code RenderingEngine} is specified on the command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * line then the last one returned by enumerating all subclasses of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * {@code RenderingEngine} known to the ServiceLoader is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Runtime tracing of the actions of the {@code RenderingEngine}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * can be enabled by specifying the runtime flag:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *     java -Dsun.java2d.renderer.trace=&lt;any string&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @return an instance of {@code RenderingEngine}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public static synchronized RenderingEngine getInstance() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (reImpl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            return reImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        reImpl = (RenderingEngine)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            AccessController.doPrivileged(new PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                public Object run() {
2695
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   123
                    final String ductusREClass = "sun.dc.DuctusRenderingEngine";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    String reClass =
2695
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   125
                        System.getProperty("sun.java2d.renderer", ductusREClass);
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   126
                    if (reClass.equals(ductusREClass)) {
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   127
                        try {
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   128
                            Class cls = Class.forName(ductusREClass);
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   129
                            return cls.newInstance();
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   130
                        } catch (ClassNotFoundException x) {
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   131
                            // not found
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   132
                        } catch (IllegalAccessException x) {
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   133
                            // should not reach here
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   134
                        } catch (InstantiationException x) {
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   135
                            // should not reach here
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   136
                        }
d75c6ebf3ac6 6818072: Load Ductus using Class.forName if exist instead of using the service loader
mchung
parents: 2
diff changeset
   137
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    ServiceLoader<RenderingEngine> reLoader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                        ServiceLoader.loadInstalled(RenderingEngine.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    RenderingEngine service = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    for (RenderingEngine re : reLoader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                        service = re;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                        if (re.getClass().getName().equals(reClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    return service;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (reImpl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            throw new InternalError("No RenderingEngine module found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        GetPropertyAction gpa =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            new GetPropertyAction("sun.java2d.renderer.trace");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        String reTrace = (String) AccessController.doPrivileged(gpa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (reTrace != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            reImpl = new Tracer(reImpl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return reImpl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Create a widened path as specified by the parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * The specified {@code src} {@link Shape} is widened according
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * to the specified attribute parameters as per the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * {@link BasicStroke} specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param src the source path to be widened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param width the width of the widened path as per {@code BasicStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @param caps the end cap decorations as per {@code BasicStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @param join the segment join decorations as per {@code BasicStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param miterlimit the miter limit as per {@code BasicStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param dashes the dash length array as per {@code BasicStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param dashphase the initial dash phase as per {@code BasicStroke}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @return the widened path stored in a new {@code Shape} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public abstract Shape createStrokedShape(Shape src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                             float width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                             int caps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                             int join,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                             float miterlimit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                                             float dashes[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                                             float dashphase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Sends the geometry for a widened path as specified by the parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * to the specified consumer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * The specified {@code src} {@link Shape} is widened according
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * to the parameters specified by the {@link BasicStroke} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Adjustments are made to the path as appropriate for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * {@link VALUE_STROKE_NORMALIZE} hint if the {@code normalize}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * boolean parameter is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Adjustments are made to the path as appropriate for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * {@link VALUE_ANTIALIAS_ON} hint if the {@code antialias}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * boolean parameter is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * The geometry of the widened path is forwarded to the indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * {@link PathConsumer2D} object as it is calculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param src the source path to be widened
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param bs the {@code BasicSroke} object specifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *           decorations to be applied to the widened path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param normalize indicates whether stroke normalization should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *                  be applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param antialias indicates whether or not adjustments appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *                  to antialiased rendering should be applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param consumer the {@code PathConsumer2D} instance to forward
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *                 the widened geometry to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public abstract void strokeTo(Shape src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                  AffineTransform at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                  BasicStroke bs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                  boolean thin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                                  boolean normalize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                                  boolean antialias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                                  PathConsumer2D consumer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Construct an antialiased tile generator for the given shape with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * the given rendering attributes and store the bounds of the tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * iteration in the bbox parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * The {@code at} parameter specifies a transform that should affect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * both the shape and the {@code BasicStroke} attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * The {@code clip} parameter specifies the current clip in effect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * in device coordinates and can be used to prune the data for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * operation, but the renderer is not required to perform any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * clipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * If the {@code BasicStroke} parameter is null then the shape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * should be filled as is, otherwise the attributes of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * {@code BasicStroke} should be used to specify a draw operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * The {@code thin} parameter indicates whether or not the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * transformed {@code BasicStroke} represents coordinates smaller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * than the minimum resolution of the antialiasing rasterizer as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * specified by the {@code getMinimumAAPenWidth()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Upon returning, this method will fill the {@code bbox} parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * with 4 values indicating the bounds of the iteration of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * tile generator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * The iteration order of the tiles will be as specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * pseudo-code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *     for (y = bbox[1]; y < bbox[3]; y += tileheight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *         for (x = bbox[0]; x < bbox[2]; x += tilewidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * If there is no output to be rendered, this method may return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @param s the shape to be rendered (fill or draw)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param at the transform to be applied to the shape and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *           stroke attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param clip the current clip in effect in device coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param bs if non-null, a {@code BasicStroke} whose attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *           should be applied to this operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param thin true if the transformed stroke attributes are smaller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *             than the minimum dropout pen width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param normalize true if the {@code VALUE_STROKE_NORMALIZE}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *                  {@code RenderingHint} is in effect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @param bbox returns the bounds of the iteration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @return the {@code AATileGenerator} instance to be consulted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *         for tile coverages, or null if there is no output to render
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public abstract AATileGenerator getAATileGenerator(Shape s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                                       AffineTransform at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                                                       Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                                       BasicStroke bs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                                       boolean thin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                                                       boolean normalize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                                                       int bbox[]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * Returns the minimum pen width that the antialiasing rasterizer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * can represent without dropouts occuring.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public abstract float getMinimumAAPenSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Utility method to feed a {@link PathConsumer2D} object from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * given {@link PathIterator}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * This method deals with the details of running the iterator and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * feeding the consumer a segment at a time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public static void feedConsumer(PathIterator pi, PathConsumer2D consumer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        float coords[] = new float[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        while (!pi.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            switch (pi.currentSegment(coords)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                consumer.moveTo(coords[0], coords[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                consumer.lineTo(coords[0], coords[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                consumer.quadTo(coords[0], coords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                coords[2], coords[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                consumer.curveTo(coords[0], coords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                                 coords[2], coords[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                                 coords[4], coords[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                consumer.closePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            pi.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    static class Tracer extends RenderingEngine {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        RenderingEngine target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        public Tracer(RenderingEngine target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            name = target.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        public Shape createStrokedShape(Shape src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                                        float width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                                        int caps,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                                        int join,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                                        float miterlimit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                                        float dashes[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                        float dashphase)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            System.out.println(name+".createStrokedShape("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                               src.getClass().getName()+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                               "width = "+width+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                               "caps = "+caps+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                               "join = "+join+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                               "miter = "+miterlimit+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                               "dashes = "+dashes+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                               "dashphase = "+dashphase+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            return target.createStrokedShape(src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                                             width, caps, join, miterlimit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                             dashes, dashphase);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        public void strokeTo(Shape src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                             AffineTransform at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                             BasicStroke bs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                             boolean thin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                             boolean normalize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                             boolean antialias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                             PathConsumer2D consumer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            System.out.println(name+".strokeTo("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                               src.getClass().getName()+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                               at+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                               bs+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                               (thin ? "thin" : "wide")+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                               (normalize ? "normalized" : "pure")+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                               (antialias ? "AA" : "non-AA")+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                               consumer.getClass().getName()+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            target.strokeTo(src, at, bs, thin, normalize, antialias, consumer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        public float getMinimumAAPenSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            System.out.println(name+".getMinimumAAPenSize()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            return target.getMinimumAAPenSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        public AATileGenerator getAATileGenerator(Shape s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                                                  AffineTransform at,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                                                  Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                                                  BasicStroke bs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                                                  boolean thin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                                                  boolean normalize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                                                  int bbox[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            System.out.println(name+".getAATileGenerator("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                               s.getClass().getName()+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                               at+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                               clip+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                               bs+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                               (thin ? "thin" : "wide")+", "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                               (normalize ? "normalized" : "pure")+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            return target.getAATileGenerator(s, at, clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                                             bs, thin, normalize,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                                             bbox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
}