jdk/src/share/classes/sun/java2d/pipe/RegionClipSpanIterator.java
author flar
Mon, 06 Dec 2010 21:45:48 -0800
changeset 7487 9b031d062ede
parent 5506 202f599c92aa
permissions -rw-r--r--
6775317: Improve performance of non-AA transformed rectangles and single wide lines in software pipelines Reviewed-by: jgodinez, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This class clips a SpanIterator to a Region and outputs the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * resulting spans as another SpanIterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Spans are output in the usual y/x order, unless the input span
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * iterator doesn't conform to this order, or the iterator's span
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * straddle more than one band of the Region used for clipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Principle of operation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The iterator maintains a several cursors onto the RegionIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * in order to avoid having to buffer spans from the SpanIterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * They are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  resetState    The initial state of the RegionIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *  lwm             Low Water Mark, a running start point for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *                  processing each band. Usually goes down, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *                  can be reset to resetState if a span has a lower
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *                  start coordinate than the previous one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *  row             The start of the current band of the RegionIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *  box             The current span of the current row
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * The main nextSpan() loop implements a coroutine like structure, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * three producers to get the next span, row and box calling each other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * to iterate through the span iterator and region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * REMIND: Needs a native implementation!
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class RegionClipSpanIterator implements SpanIterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    // The inputs to the filter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    Region rgn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    SpanIterator spanIter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // The cursors that track the progress through the region
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    RegionIterator resetState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    RegionIterator lwm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    RegionIterator row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    RegionIterator box;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // The bounds of the current span iterator span
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    int spanlox, spanhix, spanloy, spanhiy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    // The extent of the region band marking the low water mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    int lwmloy, lwmhiy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // The bounds of the current region box
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    int rgnlox, rgnloy, rgnhix, rgnhiy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    // The bounding box of the input Region. Used for click
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // rejection of iterator spans
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    int rgnbndslox, rgnbndsloy, rgnbndshix, rgnbndshiy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    // The array used to hold coordinates from the region iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    int rgnbox[] = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // The array used to hold coordinates from the span iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    int spanbox[] = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // True if the next iterator span should be read on the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // iteration of the main nextSpan() loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    boolean doNextSpan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    // True if the next region box should be read on the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // iteration of the main nextSpan() loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    boolean doNextBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    // True if there are no more spans or the Region is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    boolean done = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Creates an instance that filters the spans generated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * spanIter through the region described by rgn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public RegionClipSpanIterator(Region rgn, SpanIterator spanIter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        this.spanIter = spanIter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        resetState = rgn.getIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        lwm = resetState.createCopy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (!lwm.nextYRange(rgnbox)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        rgnloy = lwmloy = rgnbox[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        rgnhiy = lwmhiy = rgnbox[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        rgn.getBounds(rgnbox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        rgnbndslox = rgnbox[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        rgnbndsloy = rgnbox[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        rgnbndshix = rgnbox[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        rgnbndshiy = rgnbox[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (rgnbndslox >= rgnbndshix ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            rgnbndsloy >= rgnbndshiy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        this.rgn = rgn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        row = lwm.createCopy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        box = row.createCopy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        doNextSpan = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        doNextBox = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Gets the bbox of the available path segments, clipped to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public void getPathBox(int pathbox[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        int[] rgnbox = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        rgn.getBounds(rgnbox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        spanIter.getPathBox(pathbox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (pathbox[0] < rgnbox[0]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            pathbox[0] = rgnbox[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (pathbox[1] < rgnbox[1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            pathbox[1] = rgnbox[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (pathbox[2] > rgnbox[2]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            pathbox[2] = rgnbox[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (pathbox[3] > rgnbox[3]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            pathbox[3] = rgnbox[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Intersects the path box with the given bbox.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Returned spans are clipped to this region, or discarded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * altogether if they lie outside it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public void intersectClipBox(int lox, int loy, int hix, int hiy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        spanIter.intersectClipBox(lox, loy, hix, hiy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Fetches the next span that needs to be operated on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * If the return value is false then there are no more spans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public boolean nextSpan(int resultbox[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (done) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        int resultlox, resultloy, resulthix, resulthiy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        boolean doNextRow = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        // REMIND: Cache the coordinate inst vars used in this loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        // in locals vars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            // We've exhausted the current span so get the next one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            if (doNextSpan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                if (!spanIter.nextSpan(spanbox)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    done = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    spanlox = spanbox[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    // Clip out spans that lie outside of the rgn's bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    if (spanlox >= rgnbndshix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                    spanloy = spanbox[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    if (spanloy >= rgnbndshiy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    spanhix = spanbox[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    if (spanhix <= rgnbndslox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    spanhiy = spanbox[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    if (spanhiy <= rgnbndsloy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                // If the span starts higher up than the low-water mark,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                // reset the lwm. This can only happen if spans aren't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                // returned in strict y/x order, or the first time through.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                if (lwmloy > spanloy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                    lwm.copyStateFrom(resetState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    lwm.nextYRange(rgnbox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                    lwmloy = rgnbox[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    lwmhiy = rgnbox[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                // Skip to the first rgn row whose bottom edge is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                // below the top of the current span. This will only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                // execute >0 times when the current span starts in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                // lower region row than the previous one, or possibly the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                // first time through.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                while (lwmhiy <= spanloy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    if (!lwm.nextYRange(rgnbox))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    lwmloy = rgnbox[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                    lwmhiy = rgnbox[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                // If the row overlaps the span, process it, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                // fetch another span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                if (lwmhiy > spanloy && lwmloy < spanhiy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    // Update the current row if it's different from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    // new lwm
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    if (rgnloy != lwmloy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                        row.copyStateFrom(lwm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        rgnloy = lwmloy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                        rgnhiy = lwmhiy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                    box.copyStateFrom(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    doNextBox = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                    doNextSpan = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            // The current row's spans are exhausted, do the next one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            if (doNextRow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                // Next time we either do the next span or the next box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                doNextRow = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                // Get the next row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                boolean ok = row.nextYRange(rgnbox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                // If there was one, update the bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                if (ok) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    rgnloy = rgnbox[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    rgnhiy = rgnbox[3];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                if (!ok || rgnloy >= spanhiy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    // If we've exhausted the rows or this one is below the span,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    // go onto the next span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    doNextSpan = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    // Otherwise get the first box on this row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    box.copyStateFrom(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    doNextBox = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            // Process the next box in the current row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            if (doNextBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                boolean ok = box.nextXBand(rgnbox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                if (ok) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    rgnlox = rgnbox[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    rgnhix = rgnbox[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                if (!ok || rgnlox >= spanhix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    // If there was no next rgn span or it's beyond the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    // source span, go onto the next row or span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    doNextBox = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    if (rgnhiy >= spanhiy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                        // If the current row totally overlaps the span,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                        // go onto the next span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                        doNextSpan = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                        // otherwise go onto the next rgn row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                        doNextRow = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    // Otherwise, if the new rgn span overlaps the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    // spanbox, no need to get another box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                    doNextBox = rgnhix <= spanlox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            // Prepare to do the next box either on this call or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            // or the subsequent one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            doNextBox = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            // Clip the current span against the current box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            if (spanlox > rgnlox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                resultlox = spanlox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                resultlox = rgnlox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            if (spanloy > rgnloy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                resultloy = spanloy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                resultloy = rgnloy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            if (spanhix < rgnhix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                resulthix = spanhix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                resulthix = rgnhix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            if (spanhiy < rgnhiy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                resulthiy = spanhiy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                resulthiy = rgnhiy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            // If the result is empty, try then next box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            // otherwise return the box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            // REMIND: I think by definition it's non-empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            // if we're here. Need to think about this some more.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            if (resultlox >= resulthix ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                resultloy >= resulthiy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        resultbox[0] = resultlox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        resultbox[1] = resultloy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        resultbox[2] = resulthix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        resultbox[3] = resulthiy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * This method tells the iterator that it may skip all spans
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * whose Y range is completely above the indicated Y coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public void skipDownTo(int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        spanIter.skipDownTo(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * This method returns a native pointer to a function block that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * can be used by a native method to perform the same iteration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * cycle that the above methods provide while avoiding upcalls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * the Java object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * The definition of the structure whose pointer is returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * this method is defined in:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *     src/share/native/sun/java2d/pipe/SpanIterator.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public long getNativeIterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * Cleans out all internal data structures.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    //public native void dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    protected void finalize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        //dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
}