jdk/src/share/classes/sun/java2d/pipe/LoopPipe.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 9653 6a1eff16874d
child 11080 7e18e343964e
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7487
diff changeset
     2
 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4250
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4250
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4250
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4250
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4250
diff changeset
    23
 * questions.
2
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;
7487
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
    44
import sun.java2d.loops.FillParallelogram;
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
    45
import sun.java2d.loops.DrawParallelogram;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.awt.SunHints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class LoopPipe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    implements PixelDrawPipe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
               PixelFillPipe,
7487
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
    51
               ParallelogramPipe,
4250
e88776b21913 6896068: SunGraphics2D exposes a reference to itself while non fully initialised.
neugens
parents: 2
diff changeset
    52
               ShapeDrawPipe,
e88776b21913 6896068: SunGraphics2D exposes a reference to itself while non fully initialised.
neugens
parents: 2
diff changeset
    53
               LoopBasedPipe
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    final static RenderingEngine RenderEngine = RenderingEngine.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public void drawLine(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                         int x1, int y1, int x2, int y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        int tX = sg2d.transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        int tY = sg2d.transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        sg2d.loops.drawLineLoop.DrawLine(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                                         x1 + tX, y1 + tY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                                         x2 + tX, y2 + tY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public void drawRect(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                         int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        sg2d.loops.drawRectLoop.DrawRect(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                                         x + sg2d.transX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                         y + sg2d.transY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                                         width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public void drawRoundRect(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                              int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                              int arcWidth, int arcHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        sg2d.shapepipe.draw(sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                            new RoundRectangle2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                                       arcWidth, arcHeight));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public void drawOval(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                         int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        sg2d.shapepipe.draw(sg2d, new Ellipse2D.Float(x, y, width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public void drawArc(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                        int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                        int startAngle, int arcAngle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        sg2d.shapepipe.draw(sg2d, new Arc2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                                  startAngle, arcAngle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                                  Arc2D.OPEN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public void drawPolyline(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                             int xPoints[], int yPoints[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                             int nPoints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        int nPointsArray[] = { nPoints };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        sg2d.loops.drawPolygonsLoop.DrawPolygons(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                                                 xPoints, yPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                                 nPointsArray, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                                 sg2d.transX, sg2d.transY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                                 false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public void drawPolygon(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                            int xPoints[], int yPoints[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                            int nPoints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        int nPointsArray[] = { nPoints };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        sg2d.loops.drawPolygonsLoop.DrawPolygons(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                                 xPoints, yPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                                 nPointsArray, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                                 sg2d.transX, sg2d.transY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                                 true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public void fillRect(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                         int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        sg2d.loops.fillRectLoop.FillRect(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                         x + sg2d.transX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                         y + sg2d.transY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                         width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public void fillRoundRect(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                              int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                              int arcWidth, int arcHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        sg2d.shapepipe.fill(sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                            new RoundRectangle2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                                       arcWidth, arcHeight));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public void fillOval(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                         int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        sg2d.shapepipe.fill(sg2d, new Ellipse2D.Float(x, y, width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public void fillArc(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                        int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                        int startAngle, int arcAngle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        sg2d.shapepipe.fill(sg2d, new Arc2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                                  startAngle, arcAngle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                                  Arc2D.PIE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public void fillPolygon(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                            int xPoints[], int yPoints[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                            int nPoints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        ShapeSpanIterator sr = getFillSSI(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            sr.setOutputArea(sg2d.getCompClip());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            sr.appendPoly(xPoints, yPoints, nPoints, sg2d.transX, sg2d.transY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            fillSpans(sg2d, sr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            sr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public void draw(SunGraphics2D sg2d, Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (sg2d.strokeState == sg2d.STROKE_THIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            Path2D.Float p2df;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            int transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            int transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            if (sg2d.transformState <= sg2d.TRANSFORM_INT_TRANSLATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                if (s instanceof Path2D.Float) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    p2df = (Path2D.Float)s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    p2df = new Path2D.Float(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                transX = sg2d.transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                transY = sg2d.transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                p2df = new Path2D.Float(s, sg2d.transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                transX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                transY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            sg2d.loops.drawPathLoop.DrawPath(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                                             transX, transY, p2df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (sg2d.strokeState == sg2d.STROKE_CUSTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            fill(sg2d, sg2d.stroke.createStrokedShape(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        ShapeSpanIterator sr = getStrokeSpans(sg2d, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            fillSpans(sg2d, sr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            sr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Return a ShapeSpanIterator instance that normalizes as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * appropriate for a fill operation as per the settings in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * the specified SunGraphics2D object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * The ShapeSpanIterator will be newly constructed and ready
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * to start taking in geometry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Note that the caller is responsible for calling dispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * on the returned ShapeSpanIterator inside a try/finally block:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *     ShapeSpanIterator ssi = LoopPipe.getFillSSI(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *     try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *         ssi.setOutputArea(clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *         ssi.appendPath(...); // or appendPoly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *         // iterate the spans from ssi and operate on them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *     } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *         ssi.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public static ShapeSpanIterator getFillSSI(SunGraphics2D sg2d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        boolean adjust = ((sg2d.stroke instanceof BasicStroke) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                          sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return new ShapeSpanIterator(adjust);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Return a ShapeSpanIterator ready to iterate the spans of the wide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * outline of Shape s using the attributes of the SunGraphics2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * The ShapeSpanIterator returned will be fully constructed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * and filled with the geometry from the Shape widened by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * appropriate BasicStroke and normalization parameters taken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * from the SunGraphics2D object and be ready to start returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * spans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Note that the caller is responsible for calling dispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * on the returned ShapeSpanIterator inside a try/finally block.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *     ShapeSpanIterator ssi = LoopPipe.getStrokeSpans(sg2d, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *     try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *         // iterate the spans from ssi and operate on them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *     } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *         ssi.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * REMIND: This should return a SpanIterator interface object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * but the caller needs to dispose() the object and that method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * is only on ShapeSpanIterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * TODO: Add a dispose() method to the SpanIterator interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public static ShapeSpanIterator getStrokeSpans(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                                   Shape s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        ShapeSpanIterator sr = new ShapeSpanIterator(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            sr.setOutputArea(sg2d.getCompClip());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            sr.setRule(PathIterator.WIND_NON_ZERO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            BasicStroke bs = (BasicStroke) sg2d.stroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            boolean thin = (sg2d.strokeState <= sg2d.STROKE_THINDASHED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            boolean normalize =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                (sg2d.strokeHint != SunHints.INTVAL_STROKE_PURE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            RenderEngine.strokeTo(s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                  sg2d.transform, bs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                                  thin, normalize, false, sr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            sr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            sr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            throw new InternalError("Unable to Stroke shape ("+
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 9653
diff changeset
   285
                                    t.getMessage()+")", t);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return sr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    public void fill(SunGraphics2D sg2d, Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (sg2d.strokeState == sg2d.STROKE_THIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            Path2D.Float p2df;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            int transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            int transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            if (sg2d.transformState <= sg2d.TRANSFORM_INT_TRANSLATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                if (s instanceof Path2D.Float) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    p2df = (Path2D.Float)s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    p2df = new Path2D.Float(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                transX = sg2d.transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                transY = sg2d.transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                p2df = new Path2D.Float(s, sg2d.transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                transX = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                transY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            sg2d.loops.fillPathLoop.FillPath(sg2d, sg2d.getSurfaceData(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                             transX, transY, p2df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        ShapeSpanIterator sr = getFillSSI(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            sr.setOutputArea(sg2d.getCompClip());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            AffineTransform at =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                ((sg2d.transformState == sg2d.TRANSFORM_ISIDENT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                 ? null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                 : sg2d.transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            sr.appendPath(s.getPathIterator(at));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            fillSpans(sg2d, sr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            sr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    private static void fillSpans(SunGraphics2D sg2d, SpanIterator si) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        // REMIND: Eventually, the plan is that it will not be possible for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // fs to be null since the FillSpans loop will be the fundamental
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        // loop implemented for any destination type...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (sg2d.clipState == sg2d.CLIP_SHAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            si = sg2d.clipRegion.filter(si);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            // REMIND: Region.filter produces a Java-only iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            // with no native counterpart...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            sun.java2d.loops.FillSpans fs = sg2d.loops.fillSpansLoop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            if (fs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                fs.FillSpans(sg2d, sg2d.getSurfaceData(), si);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        int spanbox[] = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        SurfaceData sd = sg2d.getSurfaceData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        while (si.nextSpan(spanbox)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            int x = spanbox[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            int y = spanbox[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            int w = spanbox[2] - x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            int h = spanbox[3] - y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            sg2d.loops.fillRectLoop.FillRect(sg2d, sd, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
7487
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   352
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   353
    public void fillParallelogram(SunGraphics2D sg2d,
9653
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents: 7668
diff changeset
   354
                                  double ux1, double uy1,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents: 7668
diff changeset
   355
                                  double ux2, double uy2,
7487
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   356
                                  double x, double y,
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   357
                                  double dx1, double dy1,
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   358
                                  double dx2, double dy2)
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   359
    {
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   360
        FillParallelogram fp = sg2d.loops.fillParallelogramLoop;
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   361
        fp.FillParallelogram(sg2d, sg2d.getSurfaceData(),
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   362
                             x, y, dx1, dy1, dx2, dy2);
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   363
    }
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   364
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   365
    public void drawParallelogram(SunGraphics2D sg2d,
9653
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents: 7668
diff changeset
   366
                                  double ux1, double uy1,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents: 7668
diff changeset
   367
                                  double ux2, double uy2,
7487
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   368
                                  double x, double y,
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   369
                                  double dx1, double dy1,
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   370
                                  double dx2, double dy2,
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   371
                                  double lw1, double lw2)
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   372
    {
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   373
        DrawParallelogram dp = sg2d.loops.drawParallelogramLoop;
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   374
        dp.DrawParallelogram(sg2d, sg2d.getSurfaceData(),
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   375
                             x, y, dx1, dy1, dx2, dy2, lw1, lw2);
9b031d062ede 6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines
flar
parents: 5506
diff changeset
   376
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
}