jdk/src/share/classes/sun/java2d/pipe/LoopPipe.java
author tdv
Tue, 22 Jul 2008 11:24:32 -0700
changeset 888 c7009cf0001f
parent 2 90ce3da70b43
child 4250 e88776b21913
permissions -rw-r--r--
6728492: typo in copyrights in some files touched by the d3d pipeline port Reviewed-by: 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 1999-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.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Shape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.BasicStroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Polygon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.geom.PathIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.geom.RoundRectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.geom.Ellipse2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.geom.Arc2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.geom.IllegalPathStateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.geom.Path2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.font.GlyphVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.java2d.SunGraphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.java2d.SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.java2d.loops.FontInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.java2d.loops.DrawPolygons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.awt.SunHints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class LoopPipe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    implements PixelDrawPipe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
               PixelFillPipe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
               ShapeDrawPipe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    final static RenderingEngine RenderEngine = RenderingEngine.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public void drawLine(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                         int x1, int y1, int x2, int y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        int tX = sg2d.transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        int tY = sg2d.transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        sg2d.loops.drawLineLoop.DrawLine(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                                         x1 + tX, y1 + tY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                                         x2 + tX, y2 + tY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public void drawRect(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                         int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        sg2d.loops.drawRectLoop.DrawRect(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                                         x + sg2d.transX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                         y + sg2d.transY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                         width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public void drawRoundRect(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                              int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                              int arcWidth, int arcHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        sg2d.shapepipe.draw(sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                            new RoundRectangle2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                                       arcWidth, arcHeight));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public void drawOval(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                         int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        sg2d.shapepipe.draw(sg2d, new Ellipse2D.Float(x, y, width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public void drawArc(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                        int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                        int startAngle, int arcAngle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        sg2d.shapepipe.draw(sg2d, new Arc2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                                  startAngle, arcAngle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                                  Arc2D.OPEN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public void drawPolyline(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                             int xPoints[], int yPoints[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                             int nPoints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        int nPointsArray[] = { nPoints };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        sg2d.loops.drawPolygonsLoop.DrawPolygons(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                                 xPoints, yPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                                                 nPointsArray, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                                 sg2d.transX, sg2d.transY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                                 false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public void drawPolygon(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                            int xPoints[], int yPoints[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                            int nPoints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        int nPointsArray[] = { nPoints };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        sg2d.loops.drawPolygonsLoop.DrawPolygons(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                                 xPoints, yPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                                 nPointsArray, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                                 sg2d.transX, sg2d.transY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                                 true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public void fillRect(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                         int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        sg2d.loops.fillRectLoop.FillRect(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                                         x + sg2d.transX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                         y + sg2d.transY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                                         width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public void fillRoundRect(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                              int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                              int arcWidth, int arcHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        sg2d.shapepipe.fill(sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                            new RoundRectangle2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                                       arcWidth, arcHeight));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void fillOval(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                         int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        sg2d.shapepipe.fill(sg2d, new Ellipse2D.Float(x, y, width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public void fillArc(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                        int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                        int startAngle, int arcAngle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        sg2d.shapepipe.fill(sg2d, new Arc2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                                  startAngle, arcAngle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                                  Arc2D.PIE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public void fillPolygon(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                            int xPoints[], int yPoints[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                            int nPoints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        ShapeSpanIterator sr = getFillSSI(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            sr.setOutputArea(sg2d.getCompClip());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            sr.appendPoly(xPoints, yPoints, nPoints, sg2d.transX, sg2d.transY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            fillSpans(sg2d, sr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            sr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
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
    public void draw(SunGraphics2D sg2d, Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (sg2d.strokeState == sg2d.STROKE_THIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            Path2D.Float p2df;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            int transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            int transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (sg2d.transformState <= sg2d.TRANSFORM_INT_TRANSLATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                if (s instanceof Path2D.Float) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    p2df = (Path2D.Float)s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    p2df = new Path2D.Float(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                transX = sg2d.transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                transY = sg2d.transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                p2df = new Path2D.Float(s, sg2d.transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                transX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                transY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            sg2d.loops.drawPathLoop.DrawPath(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                             transX, transY, p2df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (sg2d.strokeState == sg2d.STROKE_CUSTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            fill(sg2d, sg2d.stroke.createStrokedShape(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        ShapeSpanIterator sr = getStrokeSpans(sg2d, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            fillSpans(sg2d, sr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            sr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * Return a ShapeSpanIterator instance that normalizes as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * appropriate for a fill operation as per the settings in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * the specified SunGraphics2D object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * The ShapeSpanIterator will be newly constructed and ready
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * to start taking in geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Note that the caller is responsible for calling dispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * on the returned ShapeSpanIterator inside a try/finally block:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *     ShapeSpanIterator ssi = LoopPipe.getFillSSI(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *     try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *         ssi.setOutputArea(clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *         ssi.appendPath(...); // or appendPoly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *         // iterate the spans from ssi and operate on them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *     } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *         ssi.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public static ShapeSpanIterator getFillSSI(SunGraphics2D sg2d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        boolean adjust = ((sg2d.stroke instanceof BasicStroke) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                          sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return new ShapeSpanIterator(adjust);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Return a ShapeSpanIterator ready to iterate the spans of the wide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * outline of Shape s using the attributes of the SunGraphics2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * The ShapeSpanIterator returned will be fully constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * and filled with the geometry from the Shape widened by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * appropriate BasicStroke and normalization parameters taken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * from the SunGraphics2D object and be ready to start returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * spans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Note that the caller is responsible for calling dispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * on the returned ShapeSpanIterator inside a try/finally block.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *     ShapeSpanIterator ssi = LoopPipe.getStrokeSpans(sg2d, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *     try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *         // iterate the spans from ssi and operate on them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *     } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *         ssi.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * REMIND: This should return a SpanIterator interface object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * but the caller needs to dispose() the object and that method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * is only on ShapeSpanIterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * TODO: Add a dispose() method to the SpanIterator interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public static ShapeSpanIterator getStrokeSpans(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                                   Shape s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        ShapeSpanIterator sr = new ShapeSpanIterator(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            sr.setOutputArea(sg2d.getCompClip());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            sr.setRule(PathIterator.WIND_NON_ZERO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            BasicStroke bs = (BasicStroke) sg2d.stroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            boolean thin = (sg2d.strokeState <= sg2d.STROKE_THINDASHED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            boolean normalize =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                (sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            RenderEngine.strokeTo(s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                  sg2d.transform, bs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                  thin, normalize, false, sr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            sr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            sr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            t.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            throw new InternalError("Unable to Stroke shape ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                                    t.getMessage()+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return sr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public void fill(SunGraphics2D sg2d, Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (sg2d.strokeState == sg2d.STROKE_THIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            Path2D.Float p2df;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            int transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            int transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (sg2d.transformState <= sg2d.TRANSFORM_INT_TRANSLATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                if (s instanceof Path2D.Float) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    p2df = (Path2D.Float)s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    p2df = new Path2D.Float(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                transX = sg2d.transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                transY = sg2d.transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                p2df = new Path2D.Float(s, sg2d.transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                transX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                transY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            sg2d.loops.fillPathLoop.FillPath(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                             transX, transY, p2df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        ShapeSpanIterator sr = getFillSSI(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            sr.setOutputArea(sg2d.getCompClip());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            AffineTransform at =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                ((sg2d.transformState == sg2d.TRANSFORM_ISIDENT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                 ? null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                 : sg2d.transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            sr.appendPath(s.getPathIterator(at));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            fillSpans(sg2d, sr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            sr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    private static void fillSpans(SunGraphics2D sg2d, SpanIterator si) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        // REMIND: Eventually, the plan is that it will not be possible for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // fs to be null since the FillSpans loop will be the fundamental
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        // loop implemented for any destination type...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (sg2d.clipState == sg2d.CLIP_SHAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            si = sg2d.clipRegion.filter(si);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            // REMIND: Region.filter produces a Java-only iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            // with no native counterpart...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            sun.java2d.loops.FillSpans fs = sg2d.loops.fillSpansLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            if (fs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                fs.FillSpans(sg2d, sg2d.getSurfaceData(), si);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        int spanbox[] = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        SurfaceData sd = sg2d.getSurfaceData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        while (si.nextSpan(spanbox)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            int x = spanbox[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            int y = spanbox[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            int w = spanbox[2] - x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            int h = spanbox[3] - y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            sg2d.loops.fillRectLoop.FillRect(sg2d, sd, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
}