< prev index next >
src/java.desktop/share/classes/sun/java2d/pipe/Region.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 60,100 ****
* bands[rowstart+3+N*2-1] = XN1; // ending X coord of last band
*
* bands[rowstart+3+N*2] = ... // start of next Y row
* </pre>
*/
! public class Region {
! static final int INIT_SIZE = 50;
! static final int GROW_SIZE = 50;
! /**
! * Immutable Region.
! */
! private static final class ImmutableRegion extends Region {
! protected ImmutableRegion(int lox, int loy, int hix, int hiy) {
! super(lox, loy, hix, hiy);
! }
!
! // Override all the methods that mutate the object
! public void appendSpans(sun.java2d.pipe.SpanIterator si) {}
! public void setOutputArea(java.awt.Rectangle r) {}
! public void setOutputAreaXYWH(int x, int y, int w, int h) {}
! public void setOutputArea(int[] box) {}
! public void setOutputAreaXYXY(int lox, int loy, int hix, int hiy) {}
! }
!
! public static final Region EMPTY_REGION = new ImmutableRegion(0, 0, 0, 0);
! public static final Region WHOLE_REGION = new ImmutableRegion(
Integer.MIN_VALUE,
Integer.MIN_VALUE,
Integer.MAX_VALUE,
Integer.MAX_VALUE);
! int lox;
! int loy;
! int hix;
! int hiy;
int endIndex;
int[] bands;
private static native void initIDs();
--- 60,84 ----
* bands[rowstart+3+N*2-1] = XN1; // ending X coord of last band
*
* bands[rowstart+3+N*2] = ... // start of next Y row
* </pre>
*/
! public final class Region {
! private static final int INIT_SIZE = 50;
! private static final int GROW_SIZE = 50;
! public static final Region EMPTY_REGION = new Region(0, 0, 0, 0);
! public static final Region WHOLE_REGION = new Region(
Integer.MIN_VALUE,
Integer.MIN_VALUE,
Integer.MAX_VALUE,
Integer.MAX_VALUE);
! private int lox;
! private int loy;
! private int hix;
! private int hiy;
int endIndex;
int[] bands;
private static native void initIDs();
*** 153,163 ****
return Integer.MAX_VALUE;
}
return (int) Math.round(newv);
}
! protected Region(int lox, int loy, int hix, int hiy) {
this.lox = lox;
this.loy = loy;
this.hix = hix;
this.hiy = hiy;
}
--- 137,147 ----
return Integer.MAX_VALUE;
}
return (int) Math.round(newv);
}
! private Region(int lox, int loy, int hix, int hiy) {
this.lox = lox;
this.loy = loy;
this.hix = hix;
this.hiy = hiy;
}
*** 256,268 ****
ShapeSpanIterator sr = new ShapeSpanIterator(normalize);
try {
sr.setOutputArea(devBounds);
sr.appendPath(s.getPathIterator(at));
sr.getPathBox(box);
! Region r = Region.getInstance(box);
! r.appendSpans(sr);
! return r;
} finally {
sr.dispose();
}
}
--- 240,250 ----
ShapeSpanIterator sr = new ShapeSpanIterator(normalize);
try {
sr.setOutputArea(devBounds);
sr.appendPath(s.getPathIterator(at));
sr.getPathBox(box);
! return Region.getInstance(box, sr);
} finally {
sr.dispose();
}
}
*** 347,416 ****
public static Region getInstanceXYXY(int lox, int loy, int hix, int hiy) {
return new Region(lox, loy, hix, hiy);
}
/**
! * Sets the rectangle of interest for storing and returning
! * region bands.
! * <p>
! * This method can also be used to initialize a simple rectangular
! * region.
! */
! public void setOutputArea(Rectangle r) {
! setOutputAreaXYWH(r.x, r.y, r.width, r.height);
! }
!
! /**
! * Sets the rectangle of interest for storing and returning
! * region bands. The rectangle is specified in x, y, width, height
! * format and appropriate clipping is performed as per the method
! * {@code dimAdd}.
! * <p>
! * This method can also be used to initialize a simple rectangular
! * region.
! */
! public void setOutputAreaXYWH(int x, int y, int w, int h) {
! setOutputAreaXYXY(x, y, dimAdd(x, w), dimAdd(y, h));
! }
!
! /**
! * Sets the rectangle of interest for storing and returning
! * region bands. The rectangle is specified as a span array.
! * <p>
! * This method can also be used to initialize a simple rectangular
! * region.
! */
! public void setOutputArea(int box[]) {
! this.lox = box[0];
! this.loy = box[1];
! this.hix = box[2];
! this.hiy = box[3];
! }
!
! /**
! * Sets the rectangle of interest for storing and returning
! * region bands. The rectangle is specified in lox, loy,
! * hix, hiy format.
! * <p>
! * This method can also be used to initialize a simple rectangular
! * region.
*/
! public void setOutputAreaXYXY(int lox, int loy, int hix, int hiy) {
! this.lox = lox;
! this.loy = loy;
! this.hix = hix;
! this.hiy = hiy;
}
/**
* Appends the list of spans returned from the indicated
* SpanIterator. Each span must be at a higher starting
* Y coordinate than the previous data or it must have a
* Y range equal to the highest Y band in the region and a
* higher X coordinate than any of the spans in that band.
*/
! public void appendSpans(SpanIterator si) {
int[] box = new int[6];
while (si.nextSpan(box)) {
appendSpan(box);
}
--- 329,360 ----
public static Region getInstanceXYXY(int lox, int loy, int hix, int hiy) {
return new Region(lox, loy, hix, hiy);
}
/**
! * Returns a Region object with a rectangle of interest specified by the
! * indicated rectangular area in lox, loy, hix, hiy format.
! * <p/>
! * Appends the list of spans returned from the indicated SpanIterator. Each
! * span must be at a higher starting Y coordinate than the previous data or
! * it must have a Y range equal to the highest Y band in the region and a
! * higher X coordinate than any of the spans in that band.
*/
! public static Region getInstance(int box[], SpanIterator si) {
! Region ret = new Region(box[0], box[1], box[2], box[3]);
! ret.appendSpans(si);
! return ret;
}
/**
* Appends the list of spans returned from the indicated
* SpanIterator. Each span must be at a higher starting
* Y coordinate than the previous data or it must have a
* Y range equal to the highest Y band in the region and a
* higher X coordinate than any of the spans in that band.
*/
! private void appendSpans(SpanIterator si) {
int[] box = new int[6];
while (si.nextSpan(box)) {
appendSpan(box);
}
*** 737,749 ****
(r.hiy < this.hiy) ? this.hiy : r.hiy);
ret.filterSpans(this, r, INCLUDE_A | INCLUDE_B);
return ret;
}
! static final int INCLUDE_A = 1;
! static final int INCLUDE_B = 2;
! static final int INCLUDE_COMMON = 4;
private void filterSpans(Region ra, Region rb, int flags) {
int abands[] = ra.bands;
int bbands[] = rb.bands;
if (abands == null) {
--- 681,693 ----
(r.hiy < this.hiy) ? this.hiy : r.hiy);
ret.filterSpans(this, r, INCLUDE_A | INCLUDE_B);
return ret;
}
! private static final int INCLUDE_A = 1;
! private static final int INCLUDE_B = 2;
! private static final int INCLUDE_COMMON = 4;
private void filterSpans(Region ra, Region rb, int flags) {
int abands[] = ra.bands;
int bbands[] = rb.bands;
if (abands == null) {
*** 1078,1102 ****
}
/**
* Returns the lowest X coordinate in the Region.
*/
! public final int getLoX() {
return lox;
}
/**
* Returns the lowest Y coordinate in the Region.
*/
! public final int getLoY() {
return loy;
}
/**
* Returns the highest X coordinate in the Region.
*/
! public final int getHiX() {
return hix;
}
/**
* Returns the highest Y coordinate in the Region.
--- 1022,1046 ----
}
/**
* Returns the lowest X coordinate in the Region.
*/
! public int getLoX() {
return lox;
}
/**
* Returns the lowest Y coordinate in the Region.
*/
! public int getLoY() {
return loy;
}
/**
* Returns the highest X coordinate in the Region.
*/
! public int getHiX() {
return hix;
}
/**
* Returns the highest Y coordinate in the Region.
*** 1323,1372 ****
si = new RegionClipSpanIterator(this, si);
}
return si;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Region[[");
sb.append(lox);
sb.append(", ");
sb.append(loy);
sb.append(" => ");
sb.append(hix);
sb.append(", ");
sb.append(hiy);
! sb.append("]");
if (bands != null) {
int col = 0;
while (col < endIndex) {
sb.append("y{");
sb.append(bands[col++]);
! sb.append(",");
sb.append(bands[col++]);
sb.append("}[");
int end = bands[col++];
end = col + end * 2;
while (col < end) {
sb.append("x(");
sb.append(bands[col++]);
sb.append(", ");
sb.append(bands[col++]);
! sb.append(")");
}
! sb.append("]");
}
}
! sb.append("]");
return sb.toString();
}
public int hashCode() {
return (isEmpty() ? 0 : (lox * 3 + loy * 5 + hix * 7 + hiy * 9));
}
public boolean equals(Object o) {
if (!(o instanceof Region)) {
return false;
}
Region r = (Region) o;
if (this.isEmpty()) {
--- 1267,1322 ----
si = new RegionClipSpanIterator(this, si);
}
return si;
}
+ @Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("Region[[");
sb.append(lox);
sb.append(", ");
sb.append(loy);
sb.append(" => ");
sb.append(hix);
sb.append(", ");
sb.append(hiy);
! sb.append(']');
if (bands != null) {
int col = 0;
while (col < endIndex) {
sb.append("y{");
sb.append(bands[col++]);
! sb.append(',');
sb.append(bands[col++]);
sb.append("}[");
int end = bands[col++];
end = col + end * 2;
while (col < end) {
sb.append("x(");
sb.append(bands[col++]);
sb.append(", ");
sb.append(bands[col++]);
! sb.append(')');
}
! sb.append(']');
}
}
! sb.append(']');
return sb.toString();
}
+ @Override
public int hashCode() {
return (isEmpty() ? 0 : (lox * 3 + loy * 5 + hix * 7 + hiy * 9));
}
+ @Override
public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
if (!(o instanceof Region)) {
return false;
}
Region r = (Region) o;
if (this.isEmpty()) {
< prev index next >