001: /*
002: * Copyright 2004 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.loops;
027:
028: import java.awt.Composite;
029: import java.awt.geom.AffineTransform;
030: import java.lang.ref.WeakReference;
031: import sun.java2d.SurfaceData;
032: import sun.java2d.loops.GraphicsPrimitive;
033: import sun.java2d.pipe.Region;
034:
035: /**
036: * TransformHelper
037: * 1) applies an AffineTransform to a rectangle of pixels while copying
038: * from one surface to another
039: * 2) performs compositing of colors based upon a Composite
040: * parameter
041: *
042: * precise behavior is undefined if the source surface
043: * and the destination surface are the same surface
044: * with overlapping regions of pixels
045: */
046: public class TransformHelper extends GraphicsPrimitive {
047: public static final String methodSignature = "TransformHelper(...)"
048: .toString();
049:
050: public static final int primTypeID = makePrimTypeID();
051:
052: private static RenderCache helpercache = new RenderCache(10);
053:
054: public static TransformHelper locate(SurfaceType srctype) {
055: return (TransformHelper) GraphicsPrimitiveMgr.locate(
056: primTypeID, srctype, CompositeType.SrcNoEa,
057: SurfaceType.IntArgbPre);
058: }
059:
060: public static synchronized TransformHelper getFromCache(
061: SurfaceType src) {
062: Object o = helpercache.get(src, null, null);
063: if (o != null) {
064: return (TransformHelper) o;
065: }
066: TransformHelper helper = locate(src);
067: if (helper == null) {
068: /*
069: System.out.println("helper loop not found for:");
070: System.out.println("src: "+src);
071: */
072: } else {
073: helpercache.put(src, null, null, helper);
074: }
075: return helper;
076: }
077:
078: protected TransformHelper(SurfaceType srctype) {
079: super (methodSignature, primTypeID, srctype,
080: CompositeType.SrcNoEa, SurfaceType.IntArgbPre);
081: }
082:
083: public TransformHelper(long pNativePrim, SurfaceType srctype,
084: CompositeType comptype, SurfaceType dsttype) {
085: super (pNativePrim, methodSignature, primTypeID, srctype,
086: comptype, dsttype);
087: }
088:
089: public native void Transform(MaskBlit output, SurfaceData src,
090: SurfaceData dst, Composite comp, Region clip,
091: AffineTransform itx, int txtype, int sx1, int sy1, int sx2,
092: int sy2, int dx1, int dy1, int dx2, int dy2, int edges[],
093: int dxoff, int dyoff);
094:
095: public GraphicsPrimitive makePrimitive(SurfaceType srctype,
096: CompositeType comptype, SurfaceType dsttype) {
097: return null;
098: }
099:
100: public GraphicsPrimitive traceWrap() {
101: return new TraceTransformHelper(this );
102: }
103:
104: private static class TraceTransformHelper extends TransformHelper {
105: TransformHelper target;
106:
107: public TraceTransformHelper(TransformHelper target) {
108: super (target.getSourceType());
109: this .target = target;
110: }
111:
112: public GraphicsPrimitive traceWrap() {
113: return this ;
114: }
115:
116: public void Transform(MaskBlit output, SurfaceData src,
117: SurfaceData dst, Composite comp, Region clip,
118: AffineTransform itx, int txtype, int sx1, int sy1,
119: int sx2, int sy2, int dx1, int dy1, int dx2, int dy2,
120: int edges[], int dxoff, int dyoff) {
121: tracePrimitive(target);
122: target.Transform(output, src, dst, comp, clip, itx, txtype,
123: sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2, edges,
124: dxoff, dyoff);
125: }
126: }
127: }
|