blob: 91e098fc40d90dbec12541e07c586ec370ad93b2 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.java2d.loops;
27
28import java.awt.Composite;
29import java.awt.geom.AffineTransform;
30import java.lang.ref.WeakReference;
31import sun.java2d.SurfaceData;
32import sun.java2d.loops.GraphicsPrimitive;
33import sun.java2d.pipe.Region;
34
35/**
36 * TransformHelper
37 * 1) applies an AffineTransform to a rectangle of pixels while copying
38 * from one surface to another
39 * 2) performs compositing of colors based upon a Composite
40 * parameter
41 *
42 * precise behavior is undefined if the source surface
43 * and the destination surface are the same surface
44 * with overlapping regions of pixels
45 */
46public class TransformHelper extends GraphicsPrimitive
47{
48 public static final String methodSignature =
49 "TransformHelper(...)".toString();
50
51 public static final int primTypeID = makePrimTypeID();
52
53 private static RenderCache helpercache = new RenderCache(10);
54
55 public static TransformHelper locate(SurfaceType srctype) {
56 return (TransformHelper)
57 GraphicsPrimitiveMgr.locate(primTypeID,
58 srctype,
59 CompositeType.SrcNoEa,
60 SurfaceType.IntArgbPre);
61 }
62
63 public static synchronized TransformHelper getFromCache(SurfaceType src) {
64 Object o = helpercache.get(src, null, null);
65 if (o != null) {
66 return (TransformHelper) o;
67 }
68 TransformHelper helper = locate(src);
69 if (helper == null) {
70 /*
71 System.out.println("helper loop not found for:");
72 System.out.println("src: "+src);
73 */
74 } else {
75 helpercache.put(src, null, null, helper);
76 }
77 return helper;
78 }
79
80 protected TransformHelper(SurfaceType srctype) {
81 super(methodSignature, primTypeID, srctype,
82 CompositeType.SrcNoEa,
83 SurfaceType.IntArgbPre);
84 }
85
86 public TransformHelper(long pNativePrim, SurfaceType srctype,
87 CompositeType comptype,
88 SurfaceType dsttype)
89 {
90 super(pNativePrim, methodSignature, primTypeID,
91 srctype, comptype, dsttype);
92 }
93
94 public native void Transform(MaskBlit output,
95 SurfaceData src, SurfaceData dst,
96 Composite comp, Region clip,
97 AffineTransform itx, int txtype,
98 int sx1, int sy1, int sx2, int sy2,
99 int dx1, int dy1, int dx2, int dy2,
100 int edges[], int dxoff, int dyoff);
101
102 public GraphicsPrimitive makePrimitive(SurfaceType srctype,
103 CompositeType comptype,
104 SurfaceType dsttype)
105 {
106 return null;
107 }
108
109 public GraphicsPrimitive traceWrap() {
110 return new TraceTransformHelper(this);
111 }
112
113 private static class TraceTransformHelper extends TransformHelper {
114 TransformHelper target;
115
116 public TraceTransformHelper(TransformHelper target) {
117 super(target.getSourceType());
118 this.target = target;
119 }
120
121 public GraphicsPrimitive traceWrap() {
122 return this;
123 }
124
125 public void Transform(MaskBlit output,
126 SurfaceData src, SurfaceData dst,
127 Composite comp, Region clip,
128 AffineTransform itx, int txtype,
129 int sx1, int sy1, int sx2, int sy2,
130 int dx1, int dy1, int dx2, int dy2,
131 int edges[], int dxoff, int dyoff)
132 {
133 tracePrimitive(target);
134 target.Transform(output, src, dst, comp, clip, itx, txtype,
135 sx1, sy1, sx2, sy2,
136 dx1, dy1, dx2, dy2,
137 edges, dxoff, dyoff);
138 }
139 }
140}