001: /*
002: * Copyright 2003-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: * TransformBlit
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:
047: public class TransformBlit extends GraphicsPrimitive {
048: public static final String methodSignature = "TransformBlit(...)"
049: .toString();
050:
051: public static final int primTypeID = makePrimTypeID();
052:
053: private static RenderCache blitcache = new RenderCache(10);
054:
055: public static TransformBlit locate(SurfaceType srctype,
056: CompositeType comptype, SurfaceType dsttype) {
057: return (TransformBlit) GraphicsPrimitiveMgr.locate(primTypeID,
058: srctype, comptype, dsttype);
059: }
060:
061: public static TransformBlit getFromCache(SurfaceType src,
062: CompositeType comp, SurfaceType dst) {
063: Object o = blitcache.get(src, comp, dst);
064: if (o != null) {
065: return (TransformBlit) o;
066: }
067: TransformBlit blit = locate(src, comp, dst);
068: if (blit == null) {
069: /*
070: System.out.println("blit loop not found for:");
071: System.out.println("src: "+src);
072: System.out.println("comp: "+comp);
073: System.out.println("dst: "+dst);
074: */
075: } else {
076: blitcache.put(src, comp, dst, blit);
077: }
078: return blit;
079: }
080:
081: protected TransformBlit(SurfaceType srctype,
082: CompositeType comptype, SurfaceType dsttype) {
083: super (methodSignature, primTypeID, srctype, comptype, dsttype);
084: }
085:
086: public TransformBlit(long pNativePrim, SurfaceType srctype,
087: CompositeType comptype, SurfaceType dsttype) {
088: super (pNativePrim, methodSignature, primTypeID, srctype,
089: comptype, dsttype);
090: }
091:
092: public native void Transform(SurfaceData src, SurfaceData dst,
093: Composite comp, Region clip, AffineTransform at, int hint,
094: int srcx, int srcy, int dstx, int dsty, int width,
095: int height);
096:
097: // REMIND: do we have a general loop?
098: static {
099: GraphicsPrimitiveMgr.registerGeneral(new TransformBlit(null,
100: null, null));
101: }
102:
103: public GraphicsPrimitive makePrimitive(SurfaceType srctype,
104: CompositeType comptype, SurfaceType dsttype) {
105: /*
106: System.out.println("Constructing general blit for:");
107: System.out.println("src: "+srctype);
108: System.out.println("comp: "+comptype);
109: System.out.println("dst: "+dsttype);
110: */
111: return null;
112: }
113:
114: public GraphicsPrimitive traceWrap() {
115: return new TraceTransformBlit(this );
116: }
117:
118: private static class TraceTransformBlit extends TransformBlit {
119: TransformBlit target;
120:
121: public TraceTransformBlit(TransformBlit target) {
122: super (target.getSourceType(), target.getCompositeType(),
123: target.getDestType());
124: this .target = target;
125: }
126:
127: public GraphicsPrimitive traceWrap() {
128: return this ;
129: }
130:
131: public void Transform(SurfaceData src, SurfaceData dst,
132: Composite comp, Region clip, AffineTransform at,
133: int hint, int srcx, int srcy, int dstx, int dsty,
134: int width, int height) {
135: tracePrimitive(target);
136: target.Transform(src, dst, comp, clip, at, hint, srcx,
137: srcy, dstx, dsty, width, height);
138: }
139: }
140: }
|