Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/java2d/pipe/RegionIterator.java
38918 views
/*1* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.pipe;2627import java.awt.Rectangle;2829/**30* This class defines the API for iterating through the bands31* of a region object.32*/33public class RegionIterator {34Region region;35int curIndex;36int numXbands;3738RegionIterator(Region r) {39region = r;40}4142/**43* Returns a new RegionIterator object representing the same44* iteration state as this object to allow multiple iteration45* branches from the current position.46*/47public RegionIterator createCopy() {48RegionIterator r = new RegionIterator(region);49r.curIndex = this.curIndex;50r.numXbands = this.numXbands;51return r;52}5354/**55* Copies the iteration state from this RegionIterator object56* into another RegionIterator object to allow multiple iteration57* branches from the current position.58*/59public void copyStateFrom(RegionIterator ri) {60if (this.region != ri.region) {61throw new InternalError("region mismatch");62}63this.curIndex = ri.curIndex;64this.numXbands = ri.numXbands;65}6667/**68* Moves the iteration state to the beginning of the next69* Y range in the region returning true if one is found70* and recording the low and high Y coordinates of the71* range in the array at locations 1 and 3 respectively.72*/73public boolean nextYRange(int range[]) {74curIndex += numXbands * 2;75numXbands = 0;76if (curIndex >= region.endIndex) {77return false;78}79range[1] = region.bands[curIndex++];80range[3] = region.bands[curIndex++];81numXbands = region.bands[curIndex++];82return true;83}8485/**86* Moves the iteration state to the beginning of the next87* X band in the current Y range returning true if one is88* found and recording the low and high X coordinates of89* the range in the array at locations 0 and 2 respectively.90*/91public boolean nextXBand(int range[]) {92if (numXbands <= 0) {93return false;94}95numXbands--;96range[0] = region.bands[curIndex++];97range[2] = region.bands[curIndex++];98return true;99}100}101102103