src/java.desktop/share/classes/sun/java2d/pipe/ShapeSpanIterator.java
author tvaleev
Thu, 04 Oct 2018 12:40:55 -0700
changeset 52248 2e330da7cbf4
parent 47216 71c04702a3d5
permissions -rw-r--r--
8211300: Convert C-style array declarations in JDK client code Reviewed-by: prr, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2018, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.geom.PathIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.awt.geom.PathConsumer2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This class can iterate individual span elements generated by scan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * converting a Shape.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * This particular implementation flattens the incoming path and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * performs simple polygon tracing to calculate the spans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Note that this class holds pointers to native data which must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * disposed.  It is not marked as finalizable since it is intended
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * to be very lightweight and finalization is a comparitively expensive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * procedure.  The caller must specifically use try{} finally{} to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * manually ensure that the object is disposed after use, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * native data structures might be leaked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Here is a code sample for using this class:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * public void fillShape(Shape s, Rectangle clipRect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *     ShapeSpanIterator ssi = new ShapeSpanIterator(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *     try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *         ssi.setOutputArea(clipRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *         ssi.appendPath(s.getPathIterator(null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *         int spanbox[] = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *         while (ssi.nextSpan(spanbox)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *             int x = spanbox[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *             int y = spanbox[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *             int w = spanbox[2] - x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *             int h = spanbox[3] - y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *             fillRect(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *     } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *         ssi.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
public final class ShapeSpanIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    implements SpanIterator, PathConsumer2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    long pData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public ShapeSpanIterator(boolean adjust) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        setNormalize(adjust);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Appends the geometry and winding rule from the indicated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * path iterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public void appendPath(PathIterator pi) {
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
    85
        float[] coords = new float[6];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        setRule(pi.getWindingRule());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        while (!pi.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            addSegment(pi.currentSegment(coords), coords);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            pi.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        pathDone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Appends the geometry from the indicated set of polygon points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
    98
    public native void appendPoly(int[] xPoints, int[] yPoints, int nPoints,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                  int xoff, int yoff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Sets the normalization flag so that incoming data is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * adjusted to nearest (0.25, 0.25) subpixel position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private native void setNormalize(boolean adjust);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Sets the rectangle of interest for storing and returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * span segments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public void setOutputAreaXYWH(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        setOutputAreaXYXY(x, y, Region.dimAdd(x, w), Region.dimAdd(y, h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Sets the rectangle of interest for storing and returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * span segments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public native void setOutputAreaXYXY(int lox, int loy, int hix, int hiy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Sets the rectangle of interest for storing and returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * span segments to the specified Rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public void setOutputArea(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        setOutputAreaXYWH(r.x, r.y, r.width, r.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
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Sets the rectangle of interest for storing and returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * span segments to the bounds of the specified Region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public void setOutputArea(Region r) {
38979
bb8a8e95780a 8156894: Cleanup of sun.java2d.pipe.Region
serb
parents: 25859
diff changeset
   134
        setOutputAreaXYXY(r.getLoX(), r.getLoY(), r.getHiX(), r.getHiY());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Sets the winding rule in the native data structures.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public native void setRule(int rule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Adds a single PathIterator segment to the internal list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * path element structures.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   146
    public native void addSegment(int type, float[] coords);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * Gets the bbox of the available path segments, clipped to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * OutputArea.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   152
    public native void getPathBox(int[] pathbox);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Intersects the path box with the given bbox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Returned spans are clipped to this region, or discarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * altogether if they lie outside it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public native void intersectClipBox(int lox, int loy, int hix, int hiy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Fetches the next span that needs to be operated on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * If the return value is false then there are no more spans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
52248
2e330da7cbf4 8211300: Convert C-style array declarations in JDK client code
tvaleev
parents: 47216
diff changeset
   165
    public native boolean nextSpan(int[] spanbox);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * This method tells the iterator that it may skip all spans
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * whose Y range is completely above the indicated Y coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public native void skipDownTo(int y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * This method returns a native pointer to a function block that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * can be used by a native method to perform the same iteration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * cycle that the above methods provide while avoiding upcalls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * the Java object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * The definition of the structure whose pointer is returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * this method is defined in:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *     src/share/native/sun/java2d/pipe/SpanIterator.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public native long getNativeIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Cleans out all internal data structures.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public native void dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public native void moveTo(float x, float y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public native void lineTo(float x, float y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public native void quadTo(float x1, float y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                              float x2, float y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public native void curveTo(float x1, float y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                               float x2, float y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                               float x3, float y3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public native void closePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public native void pathDone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public native long getNativeConsumer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
}