2370N/A/*
2685N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2370N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2370N/A *
2370N/A * This code is free software; you can redistribute it and/or modify it
2370N/A * under the terms of the GNU General Public License version 2 only, as
2685N/A * published by the Free Software Foundation. Oracle designates this
2370N/A * particular file as subject to the "Classpath" exception as provided
2685N/A * by Oracle in the LICENSE file that accompanied this code.
2370N/A *
2370N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2370N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2370N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2370N/A * version 2 for more details (a copy is included in the LICENSE file that
2370N/A * accompanied this code).
2370N/A *
2370N/A * You should have received a copy of the GNU General Public License version
2370N/A * 2 along with this work; if not, write to the Free Software Foundation,
2370N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2370N/A *
2685N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2685N/A * or visit www.oracle.com if you need additional information or have any
2685N/A * questions.
2370N/A */
2370N/A
2370N/Apackage sun.java2d.xr;
2370N/A
2370N/Aimport static java.lang.Math.min;
2370N/Aimport static java.lang.Math.max;
2370N/Aimport static sun.java2d.xr.MaskTileManager.MASK_SIZE;
2370N/A
2370N/A/**
2370N/A * This class implements region tracking, used by the tiled-mask code.
2370N/A *
2370N/A * @author Clemens Eisserer
2370N/A */
2370N/A
2370N/Apublic class DirtyRegion implements Cloneable {
2370N/A int x, y, x2, y2;
2370N/A
2370N/A public DirtyRegion() {
2370N/A clear();
2370N/A }
2370N/A
2370N/A public void clear() {
2370N/A x = Integer.MAX_VALUE;
2370N/A y = Integer.MAX_VALUE;
2370N/A x2 = Integer.MIN_VALUE;
2370N/A y2 = Integer.MIN_VALUE;
2370N/A }
2370N/A
2370N/A public void growDirtyRegion(int x, int y, int x2, int y2) {
2370N/A this.x = min(x, this.x);
2370N/A this.y = min(y, this.y);
2370N/A this.x2 = max(x2, this.x2);
2370N/A this.y2 = max(y2, this.y2);
2370N/A }
2370N/A
2370N/A public int getWidth() {
2370N/A return x2 - x;
2370N/A }
2370N/A
2370N/A public int getHeight() {
2370N/A return y2 - y;
2370N/A }
2370N/A
2370N/A public void growDirtyRegionTileLimit(int x, int y, int x2, int y2) {
2370N/A if (x < this.x) {
2370N/A this.x = max(x, 0);
2370N/A }
2370N/A if (y < this.y) {
2370N/A this.y = max(y, 0);
2370N/A }
2370N/A if (x2 > this.x2) {
2370N/A this.x2 = min(x2, MASK_SIZE);
2370N/A }
2370N/A if (y2 > this.y2) {
2370N/A this.y2 = min(y2, MASK_SIZE);
2370N/A }
2370N/A }
2370N/A
2370N/A public static DirtyRegion combineRegion(DirtyRegion region1,
2370N/A DirtyRegion region2) {
2370N/A DirtyRegion region = new DirtyRegion();
2370N/A region.x = min(region1.x, region2.x);
2370N/A region.y = min(region1.y, region2.y);
2370N/A region.x2 = max(region1.x2, region2.x2);
2370N/A region.y2 = max(region1.y2, region2.y2);
2370N/A return region;
2370N/A }
2370N/A
2370N/A public void setDirtyLineRegion(int x1, int y1, int x2, int y2) {
2370N/A if (x1 < x2) {
2370N/A this.x = x1;
2370N/A this.x2 = x2;
2370N/A } else {
2370N/A this.x = x2;
2370N/A this.x2 = x1;
2370N/A }
2370N/A
2370N/A if (y1 < y2) {
2370N/A this.y = y1;
2370N/A this.y2 = y2;
2370N/A } else {
2370N/A this.y = y2;
2370N/A this.y2 = y1;
2370N/A }
2370N/A }
2370N/A
2370N/A public void translate(int x, int y) {
2370N/A if (this.x != Integer.MAX_VALUE) {
2370N/A this.x += x;
2370N/A this.x2 += x;
2370N/A this.y += y;
2370N/A this.y2 += y;
2370N/A }
2370N/A }
2370N/A
2370N/A public String toString() {
2370N/A return this.getClass().getName() +
2370N/A "(x: " + x + ", y:" + y + ", x2:" + x2 + ", y2:" + y2 + ")";
2370N/A }
2370N/A
2370N/A public DirtyRegion cloneRegion() {
2370N/A try {
2370N/A return (DirtyRegion) clone();
2370N/A } catch (CloneNotSupportedException ex) {
2370N/A ex.printStackTrace();
2370N/A }
2370N/A
2370N/A return null;
2370N/A }
2370N/A}