Path: blob/master/src/java.desktop/share/classes/sun/java2d/pipe/RegionSpanIterator.java
41159 views
/*1* Copyright (c) 1999, 2020, 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;2627/**28* This class implements the ShapeIterator interface for a Region.29* This is useful as the source iterator of a device clip region30* (in its native guise), and also as the result of clipping a31* Region to a rectangle.32*/33public class RegionSpanIterator implements SpanIterator {34// The RegionIterator that we use to do the work35RegionIterator ri;3637// Clipping bounds38int lox, loy, hix, hiy;3940// Current Y band limits41int curloy, curhiy;4243// Are we done?44boolean done = false;4546// Is the associated Region rectangular?47boolean isrect;4849/**50* Constructs an instance based on the given Region51*/52public RegionSpanIterator(Region r) {53int[] bounds = new int[4];5455r.getBounds(bounds);56lox = bounds[0];57loy = bounds[1];58hix = bounds[2];59hiy = bounds[3];60isrect = r.isRectangular();6162ri = r.getIterator();63}6465/**66* Gets the bbox of the available region spans.67*/68public void getPathBox(int[] pathbox) {69pathbox[0] = lox;70pathbox[1] = loy;71pathbox[2] = hix;72pathbox[3] = hiy;73}7475/**76* Intersect the box used for clipping the output spans with the77* given box.78*/79public void intersectClipBox(int clox, int cloy, int chix, int chiy) {80if (clox > lox) {81lox = clox;82}83if (cloy > loy) {84loy = cloy;85}86if (chix < hix) {87hix = chix;88}89if (chiy < hiy) {90hiy = chiy;91}92done = lox >= hix || loy >= hiy;93}9495/**96* Fetches the next span that needs to be operated on.97* If the return value is false then there are no more spans.98*/99public boolean nextSpan(int[] spanbox) {100101// Quick test for end conditions102if (done) {103return false;104}105106// If the Region is rectangular, we store our bounds (possibly107// clipped via intersectClipBox()) in spanbox and return true108// so that the caller will process the single span. We set done109// to true to ensure that this will be the last span processed.110if (isrect) {111getPathBox(spanbox);112done = true;113return true;114}115116// Local cache of current span's bounds117int curlox, curhix;118int curloy = this.curloy;119int curhiy = this.curhiy;120121while (true) {122if (!ri.nextXBand(spanbox)) {123if (!ri.nextYRange(spanbox)) {124done = true;125return false;126}127// Update the current y band and clip it128curloy = spanbox[1];129curhiy = spanbox[3];130if (curloy < loy) {131curloy = loy;132}133if (curhiy > hiy) {134curhiy = hiy;135}136// Check for moving below the clip rect137if (curloy >= hiy) {138done = true;139return false;140}141continue;142}143// Clip the x box144curlox = spanbox[0];145curhix = spanbox[2];146if (curlox < lox) {147curlox = lox;148}149if (curhix > hix) {150curhix = hix;151}152// If it's non- box, we're done153if (curlox < curhix && curloy < curhiy) {154break;155}156}157158// Update the result and the store y range159spanbox[0] = curlox;160spanbox[1] = this.curloy = curloy;161spanbox[2] = curhix;162spanbox[3] = this.curhiy = curhiy;163return true;164}165166/**167* This method tells the iterator that it may skip all spans168* whose Y range is completely above the indicated Y coordinate.169*/170public void skipDownTo(int y) {171loy = y;172}173174/**175* This method returns a native pointer to a function block that176* can be used by a native method to perform the same iteration177* cycle that the above methods provide while avoiding upcalls to178* the Java object.179* The definition of the structure whose pointer is returned by180* this method is defined in:181* <pre>182* src/share/native/sun/java2d/pipe/SpanIterator.h183* </pre>184*/185public long getNativeIterator() {186return 0;187}188}189190191