2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.java2d.loops;
|
|
27 |
|
|
28 |
import java.awt.Composite;
|
|
29 |
import java.awt.geom.AffineTransform;
|
|
30 |
import java.lang.ref.WeakReference;
|
|
31 |
import sun.java2d.SurfaceData;
|
|
32 |
import sun.java2d.loops.GraphicsPrimitive;
|
|
33 |
import sun.java2d.pipe.Region;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* TransformBlit
|
|
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 |
*/
|
|
46 |
|
|
47 |
public class TransformBlit extends GraphicsPrimitive
|
|
48 |
{
|
|
49 |
public static final String methodSignature =
|
|
50 |
"TransformBlit(...)".toString();
|
|
51 |
|
|
52 |
public static final int primTypeID = makePrimTypeID();
|
|
53 |
|
|
54 |
private static RenderCache blitcache = new RenderCache(10);
|
|
55 |
|
|
56 |
public static TransformBlit locate(SurfaceType srctype,
|
|
57 |
CompositeType comptype,
|
|
58 |
SurfaceType dsttype)
|
|
59 |
{
|
|
60 |
return (TransformBlit)
|
|
61 |
GraphicsPrimitiveMgr.locate(primTypeID,
|
|
62 |
srctype, comptype, dsttype);
|
|
63 |
}
|
|
64 |
|
|
65 |
public static TransformBlit getFromCache(SurfaceType src,
|
|
66 |
CompositeType comp,
|
|
67 |
SurfaceType dst)
|
|
68 |
{
|
|
69 |
Object o = blitcache.get(src, comp, dst);
|
|
70 |
if (o != null) {
|
|
71 |
return (TransformBlit) o;
|
|
72 |
}
|
|
73 |
TransformBlit blit = locate(src, comp, dst);
|
|
74 |
if (blit == null) {
|
|
75 |
/*
|
|
76 |
System.out.println("blit loop not found for:");
|
|
77 |
System.out.println("src: "+src);
|
|
78 |
System.out.println("comp: "+comp);
|
|
79 |
System.out.println("dst: "+dst);
|
|
80 |
*/
|
|
81 |
} else {
|
|
82 |
blitcache.put(src, comp, dst, blit);
|
|
83 |
}
|
|
84 |
return blit;
|
|
85 |
}
|
|
86 |
|
|
87 |
protected TransformBlit(SurfaceType srctype,
|
|
88 |
CompositeType comptype,
|
|
89 |
SurfaceType dsttype)
|
|
90 |
{
|
|
91 |
super(methodSignature, primTypeID, srctype, comptype, dsttype);
|
|
92 |
}
|
|
93 |
|
|
94 |
public TransformBlit(long pNativePrim,
|
|
95 |
SurfaceType srctype,
|
|
96 |
CompositeType comptype,
|
|
97 |
SurfaceType dsttype)
|
|
98 |
{
|
|
99 |
super(pNativePrim, methodSignature, primTypeID,
|
|
100 |
srctype, comptype, dsttype);
|
|
101 |
}
|
|
102 |
|
|
103 |
public native void Transform(SurfaceData src, SurfaceData dst,
|
|
104 |
Composite comp, Region clip,
|
|
105 |
AffineTransform at, int hint,
|
|
106 |
int srcx, int srcy, int dstx, int dsty,
|
|
107 |
int width, int height);
|
|
108 |
|
|
109 |
// REMIND: do we have a general loop?
|
|
110 |
static {
|
|
111 |
GraphicsPrimitiveMgr.registerGeneral(new TransformBlit(null, null,
|
|
112 |
null));
|
|
113 |
}
|
|
114 |
|
|
115 |
public GraphicsPrimitive makePrimitive(SurfaceType srctype,
|
|
116 |
CompositeType comptype,
|
|
117 |
SurfaceType dsttype)
|
|
118 |
{
|
|
119 |
/*
|
|
120 |
System.out.println("Constructing general blit for:");
|
|
121 |
System.out.println("src: "+srctype);
|
|
122 |
System.out.println("comp: "+comptype);
|
|
123 |
System.out.println("dst: "+dsttype);
|
|
124 |
*/
|
|
125 |
return null;
|
|
126 |
}
|
|
127 |
|
|
128 |
public GraphicsPrimitive traceWrap() {
|
|
129 |
return new TraceTransformBlit(this);
|
|
130 |
}
|
|
131 |
|
|
132 |
private static class TraceTransformBlit extends TransformBlit {
|
|
133 |
TransformBlit target;
|
|
134 |
|
|
135 |
public TraceTransformBlit(TransformBlit target) {
|
|
136 |
super(target.getSourceType(),
|
|
137 |
target.getCompositeType(),
|
|
138 |
target.getDestType());
|
|
139 |
this.target = target;
|
|
140 |
}
|
|
141 |
|
|
142 |
public GraphicsPrimitive traceWrap() {
|
|
143 |
return this;
|
|
144 |
}
|
|
145 |
|
|
146 |
public void Transform(SurfaceData src, SurfaceData dst,
|
|
147 |
Composite comp, Region clip,
|
|
148 |
AffineTransform at, int hint,
|
|
149 |
int srcx, int srcy, int dstx, int dsty,
|
|
150 |
int width, int height)
|
|
151 |
{
|
|
152 |
tracePrimitive(target);
|
|
153 |
target.Transform(src, dst, comp, clip, at, hint,
|
|
154 |
srcx, srcy, dstx, dsty, width, height);
|
|
155 |
}
|
|
156 |
}
|
|
157 |
}
|