Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/java2d/xr/DirtyRegion.java
32288 views
/*1* Copyright (c) 2010, 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.xr;2627import static java.lang.Math.min;28import static java.lang.Math.max;29import static sun.java2d.xr.MaskTileManager.MASK_SIZE;3031/**32* This class implements region tracking, used by the tiled-mask code.33*34* @author Clemens Eisserer35*/3637public class DirtyRegion implements Cloneable {38int x, y, x2, y2;3940public DirtyRegion() {41clear();42}4344public void clear() {45x = Integer.MAX_VALUE;46y = Integer.MAX_VALUE;47x2 = Integer.MIN_VALUE;48y2 = Integer.MIN_VALUE;49}5051public void growDirtyRegion(int x, int y, int x2, int y2) {52this.x = min(x, this.x);53this.y = min(y, this.y);54this.x2 = max(x2, this.x2);55this.y2 = max(y2, this.y2);56}5758public int getWidth() {59return x2 - x;60}6162public int getHeight() {63return y2 - y;64}6566public void growDirtyRegionTileLimit(int x, int y, int x2, int y2) {67if (x < this.x) {68this.x = max(x, 0);69}70if (y < this.y) {71this.y = max(y, 0);72}73if (x2 > this.x2) {74this.x2 = min(x2, MASK_SIZE);75}76if (y2 > this.y2) {77this.y2 = min(y2, MASK_SIZE);78}79}8081public static DirtyRegion combineRegion(DirtyRegion region1,82DirtyRegion region2) {83DirtyRegion region = new DirtyRegion();84region.x = min(region1.x, region2.x);85region.y = min(region1.y, region2.y);86region.x2 = max(region1.x2, region2.x2);87region.y2 = max(region1.y2, region2.y2);88return region;89}9091public void setDirtyLineRegion(int x1, int y1, int x2, int y2) {92if (x1 < x2) {93this.x = x1;94this.x2 = x2;95} else {96this.x = x2;97this.x2 = x1;98}99100if (y1 < y2) {101this.y = y1;102this.y2 = y2;103} else {104this.y = y2;105this.y2 = y1;106}107}108109public void translate(int x, int y) {110if (this.x != Integer.MAX_VALUE) {111this.x += x;112this.x2 += x;113this.y += y;114this.y2 += y;115}116}117118public String toString() {119return this.getClass().getName() +120"(x: " + x + ", y:" + y + ", x2:" + x2 + ", y2:" + y2 + ")";121}122123public DirtyRegion cloneRegion() {124try {125return (DirtyRegion) clone();126} catch (CloneNotSupportedException ex) {127ex.printStackTrace();128}129130return null;131}132}133134135