001: /*
002: * Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.java2d.pipe;
027:
028: import java.awt.Rectangle;
029: import java.awt.Shape;
030: import java.awt.geom.PathIterator;
031: import sun.java2d.SunGraphics2D;
032:
033: /**
034: * This class uses a Region iterator to modify the extents of alpha
035: * tiles created during Shape rendering based upon a non-rectangular
036: * clipping path.
037: */
038: public class SpanClipRenderer implements CompositePipe {
039: CompositePipe outpipe;
040:
041: static Class RegionClass = Region.class;
042: static Class RegionIteratorClass = RegionIterator.class;
043:
044: static {
045: initIDs(RegionClass, RegionIteratorClass);
046: }
047:
048: static native void initIDs(Class rc, Class ric);
049:
050: public SpanClipRenderer(CompositePipe pipe) {
051: outpipe = pipe;
052: }
053:
054: class SCRcontext {
055: RegionIterator iterator;
056: Object outcontext;
057: int band[];
058: byte tile[];
059:
060: public SCRcontext(RegionIterator ri, Object outctx) {
061: iterator = ri;
062: outcontext = outctx;
063: band = new int[4];
064: }
065: }
066:
067: public Object startSequence(SunGraphics2D sg, Shape s,
068: Rectangle devR, int[] abox) {
069: RegionIterator ri = sg.clipRegion.getIterator();
070:
071: return new SCRcontext(ri, outpipe.startSequence(sg, s, devR,
072: abox));
073: }
074:
075: public boolean needTile(Object ctx, int x, int y, int w, int h) {
076: SCRcontext context = (SCRcontext) ctx;
077: return (outpipe.needTile(context.outcontext, x, y, w, h));
078: }
079:
080: public void renderPathTile(Object ctx, byte[] atile, int offset,
081: int tsize, int x, int y, int w, int h, ShapeSpanIterator sr) {
082: renderPathTile(ctx, atile, offset, tsize, x, y, w, h);
083: }
084:
085: public void renderPathTile(Object ctx, byte[] atile, int offset,
086: int tsize, int x, int y, int w, int h) {
087: SCRcontext context = (SCRcontext) ctx;
088: RegionIterator ri = context.iterator.createCopy();
089: int[] band = context.band;
090: band[0] = x;
091: band[1] = y;
092: band[2] = x + w;
093: band[3] = y + h;
094: if (atile == null) {
095: int size = w * h;
096: atile = context.tile;
097: if (atile != null && atile.length < size) {
098: atile = null;
099: }
100: if (atile == null) {
101: atile = new byte[size];
102: context.tile = atile;
103: }
104: offset = 0;
105: tsize = w;
106: fillTile(ri, atile, offset, tsize, band);
107: } else {
108: eraseTile(ri, atile, offset, tsize, band);
109: }
110:
111: if (band[2] > band[0] && band[3] > band[1]) {
112: offset += (band[1] - y) * tsize + (band[0] - x);
113: outpipe.renderPathTile(context.outcontext, atile, offset,
114: tsize, band[0], band[1], band[2] - band[0], band[3]
115: - band[1]);
116: }
117: }
118:
119: public native void fillTile(RegionIterator ri, byte[] alpha,
120: int offset, int tsize, int[] band);
121:
122: public native void eraseTile(RegionIterator ri, byte[] alpha,
123: int offset, int tsize, int[] band);
124:
125: public void skipTile(Object ctx, int x, int y) {
126: SCRcontext context = (SCRcontext) ctx;
127: outpipe.skipTile(context.outcontext, x, y);
128: }
129:
130: public void endSequence(Object ctx) {
131: SCRcontext context = (SCRcontext) ctx;
132: outpipe.endSequence(context.outcontext);
133: }
134: }
|