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