Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/java2d/pipe/RegionSpanIterator.java
38918 views
/*1* Copyright (c) 1999, 2002, 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/*50REMIND: For native implementation51long pData; // Private storage of rect info5253static {54initIDs();55}5657public static native void initIDs();58*/5960/**61* Constructs an instance based on the given Region62*/63public RegionSpanIterator(Region r) {64int[] bounds = new int[4];6566r.getBounds(bounds);67lox = bounds[0];68loy = bounds[1];69hix = bounds[2];70hiy = bounds[3];71isrect = r.isRectangular();7273ri = r.getIterator();74}7576/**77* Gets the bbox of the available region spans.78*/79public void getPathBox(int pathbox[]) {80pathbox[0] = lox;81pathbox[1] = loy;82pathbox[2] = hix;83pathbox[3] = hiy;84}8586/**87* Intersect the box used for clipping the output spans with the88* given box.89*/90public void intersectClipBox(int clox, int cloy, int chix, int chiy) {91if (clox > lox) {92lox = clox;93}94if (cloy > loy) {95loy = cloy;96}97if (chix < hix) {98hix = chix;99}100if (chiy < hiy) {101hiy = chiy;102}103done = lox >= hix || loy >= hiy;104}105106/**107* Fetches the next span that needs to be operated on.108* If the return value is false then there are no more spans.109*/110public boolean nextSpan(int spanbox[]) {111112// Quick test for end conditions113if (done) {114return false;115}116117// If the Region is rectangular, we store our bounds (possibly118// clipped via intersectClipBox()) in spanbox and return true119// so that the caller will process the single span. We set done120// to true to ensure that this will be the last span processed.121if (isrect) {122getPathBox(spanbox);123done = true;124return true;125}126127// Local cache of current span's bounds128int curlox, curhix;129int curloy = this.curloy;130int curhiy = this.curhiy;131132while (true) {133if (!ri.nextXBand(spanbox)) {134if (!ri.nextYRange(spanbox)) {135done = true;136return false;137}138// Update the current y band and clip it139curloy = spanbox[1];140curhiy = spanbox[3];141if (curloy < loy) {142curloy = loy;143}144if (curhiy > hiy) {145curhiy = hiy;146}147// Check for moving below the clip rect148if (curloy >= hiy) {149done = true;150return false;151}152continue;153}154// Clip the x box155curlox = spanbox[0];156curhix = spanbox[2];157if (curlox < lox) {158curlox = lox;159}160if (curhix > hix) {161curhix = hix;162}163// If it's non- box, we're done164if (curlox < curhix && curloy < curhiy) {165break;166}167}168169// Update the result and the store y range170spanbox[0] = curlox;171spanbox[1] = this.curloy = curloy;172spanbox[2] = curhix;173spanbox[3] = this.curhiy = curhiy;174return true;175}176177/**178* This method tells the iterator that it may skip all spans179* whose Y range is completely above the indicated Y coordinate.180*/181public void skipDownTo(int y) {182loy = y;183}184185/**186* This method returns a native pointer to a function block that187* can be used by a native method to perform the same iteration188* cycle that the above methods provide while avoiding upcalls to189* the Java object.190* The definition of the structure whose pointer is returned by191* this method is defined in:192* <pre>193* src/share/native/sun/java2d/pipe/SpanIterator.h194* </pre>195*/196public long getNativeIterator() {197return 0;198}199200/*201* Cleans out all internal data structures.202* REMIND: Native implementation203public native void dispose();204205protected void finalize() {206dispose();207}208*/209}210211212