--- old/src/java.desktop/share/classes/sun/java2d/pipe/Region.java 2014-11-14 15:28:25.000000000 +0300 +++ new/src/java.desktop/share/classes/sun/java2d/pipe/Region.java 2014-11-14 15:28:25.000000000 +0300 @@ -30,6 +30,8 @@ import java.awt.geom.AffineTransform; import java.awt.geom.RectangularShape; +import sun.java2d.loops.TransformHelper; + /** * This class encapsulates a definition of a two dimensional region which * consists of a number of Y ranges each containing multiple X bands. @@ -160,6 +162,15 @@ this.hiy = hiy; } + private Region(int lox, int loy, int hix, int hiy, int[] bands, int end) { + this.lox = lox; + this.loy = loy; + this.hix = hix; + this.hiy = hiy; + this.bands = bands; + this.endIndex = end; + } + /** * Returns a Region object covering the pixels which would be * touched by a fill or clip operation on a Graphics implementation @@ -256,6 +267,38 @@ } /** + * Returns a Region object with a rectangle of interest specified by the + * indicated rectangular area in lox, loy, hix, hiy and edges array, which + * is located relative to the rectangular area. Edges array - 0,1 are y + * range, 2N,2N+1 are x ranges, 1 per y range. + *

+ * Note that we trust to the edges array, which means that edges should be: + * {@code edges + (lox, loy) < (hix, hiy)}, otherwise result is undefined + * + * @see TransformHelper + */ + static Region getInstance(final int lox, final int loy, final int hix, + final int hiy, final int edges[]) { + // rowsNum * (3 + 1 * 2), plus one byte for endIndex + final int[] bands = new int[(edges[1] - edges[0]) * 5 + 1]; + int end = 0; + int index = 2; + for (int y = edges[0]; end < bands.length && y < edges[1]; ++y) { + final int x1 = edges[index++]; + final int x2 = edges[index++]; + if (x1 < x2) { + bands[end++] = loy + y; // spanloy + bands[end++] = loy + y + 1; // spanhiy + bands[end++] = 1; // 1 span per row + bands[end++] = lox + x1; // spanlox + bands[end++] = lox + x2; // spanhix + } + } + return end != 0 ? new Region(lox, loy, hix, hiy, bands, end) + : EMPTY_REGION; + } + + /** * Returns a Region object with a rectangle of interest specified * by the indicated Rectangle object. *