< prev index next >

src/java.desktop/share/classes/sun/java2d/pipe/Region.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
+ * 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,41 +60,25 @@
  * 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;
+public final class Region {
+    private static final int INIT_SIZE = 50;
+    private 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(
+    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);
 
-    int lox;
-    int loy;
-    int hix;
-    int hiy;
+    private int lox;
+    private int loy;
+    private int hix;
+    private int hiy;
 
     int endIndex;
     int[] bands;
 
     private static native void initIDs();

@@ -153,11 +137,11 @@
             return Integer.MAX_VALUE;
         }
         return (int) Math.round(newv);
     }
 
-    protected Region(int lox, int loy, int hix, int hiy) {
+    private Region(int lox, int loy, int hix, int hiy) {
         this.lox = lox;
         this.loy = loy;
         this.hix = hix;
         this.hiy = hiy;
     }

@@ -256,13 +240,11 @@
         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;
+            return Region.getInstance(box, sr);
         } finally {
             sr.dispose();
         }
     }
 

@@ -347,70 +329,32 @@
     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.
+     * 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 void setOutputAreaXYXY(int lox, int loy, int hix, int hiy) {
-        this.lox = lox;
-        this.loy = loy;
-        this.hix = hix;
-        this.hiy = hiy;
+    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.
      */
-    public void appendSpans(SpanIterator si) {
+    private void appendSpans(SpanIterator si) {
         int[] box = new int[6];
 
         while (si.nextSpan(box)) {
             appendSpan(box);
         }

@@ -737,13 +681,13 @@
                                 (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 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,39 +1022,39 @@
     }
 
     /**
      * Returns the lowest X coordinate in the Region.
      */
-    public final int getLoX() {
+    public int getLoX() {
         return lox;
     }
 
     /**
      * Returns the lowest Y coordinate in the Region.
      */
-    public final int getLoY() {
+    public int getLoY() {
         return loy;
     }
 
     /**
      * Returns the highest X coordinate in the Region.
      */
-    public final int getHiX() {
+    public int getHiX() {
         return hix;
     }
 
     /**
      * Returns the highest Y coordinate in the Region.
      */
-    public final int getHiY() {
+    public int getHiY() {
         return hiy;
     }
 
     /**
      * Returns the width of this Region clipped to the range (0 - MAX_INT).
      */
-    public final int getWidth() {
+    public int getWidth() {
         if (hix < lox) return 0;
         int w;
         if ((w = hix - lox) < 0) {
             w = Integer.MAX_VALUE;
         }

@@ -1118,11 +1062,11 @@
     }
 
     /**
      * Returns the height of this Region clipped to the range (0 - MAX_INT).
      */
-    public final int getHeight() {
+    public int getHeight() {
         if (hiy < loy) return 0;
         int h;
         if ((h = hiy - loy) < 0) {
             h = Integer.MAX_VALUE;
         }

@@ -1323,50 +1267,56 @@
             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("]");
+        sb.append(']');
         if (bands != null) {
             int col = 0;
             while (col < endIndex) {
                 sb.append("y{");
                 sb.append(bands[col++]);
-                sb.append(",");
+                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("]");
+                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 >