1/*
2 * Copyright (c) 2004, 2016, Oracle and/or its affiliates. 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.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 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.
24 */
25
26package sun.java2d.loops;
27
28import java.awt.Composite;
29import java.awt.geom.AffineTransform;
30import sun.java2d.SurfaceData;
31import sun.java2d.loops.GraphicsPrimitive;
32import sun.java2d.pipe.Region;
33
34/**
35 * TransformHelper
36 * 1) applies an AffineTransform to a rectangle of pixels while copying
37 *    from one surface to another
38 * 2) performs compositing of colors based upon a Composite
39 *    parameter
40 *
41 * precise behavior is undefined if the source surface
42 * and the destination surface are the same surface
43 * with overlapping regions of pixels
44 */
45public class TransformHelper extends GraphicsPrimitive
46{
47    public static final String methodSignature =
48        "TransformHelper(...)".toString();
49
50    public static final int primTypeID = makePrimTypeID();
51
52    private static RenderCache helpercache = new RenderCache(10);
53
54    public static TransformHelper locate(SurfaceType srctype) {
55        return (TransformHelper)
56            GraphicsPrimitiveMgr.locate(primTypeID,
57                                        srctype,
58                                        CompositeType.SrcNoEa,
59                                        SurfaceType.IntArgbPre);
60    }
61
62    public static synchronized TransformHelper getFromCache(SurfaceType src) {
63        Object o = helpercache.get(src, null, null);
64        if (o != null) {
65            return (TransformHelper) o;
66        }
67        TransformHelper helper = locate(src);
68        if (helper == null) {
69            /*
70            System.out.println("helper loop not found for:");
71            System.out.println("src:  "+src);
72            */
73        } else {
74            helpercache.put(src, null, null, helper);
75        }
76        return helper;
77    }
78
79    protected TransformHelper(SurfaceType srctype) {
80        super(methodSignature, primTypeID, srctype,
81              CompositeType.SrcNoEa,
82              SurfaceType.IntArgbPre);
83    }
84
85    public TransformHelper(long pNativePrim, SurfaceType srctype,
86                           CompositeType comptype,
87                           SurfaceType dsttype)
88    {
89        super(pNativePrim, methodSignature, primTypeID,
90              srctype, comptype, dsttype);
91    }
92
93    public native void Transform(MaskBlit output,
94                                 SurfaceData src, SurfaceData dst,
95                                 Composite comp, Region clip,
96                                 AffineTransform itx, int txtype,
97                                 int sx1, int sy1, int sx2, int sy2,
98                                 int dx1, int dy1, int dx2, int dy2,
99                                 int edges[], int dxoff, int dyoff);
100
101    public GraphicsPrimitive makePrimitive(SurfaceType srctype,
102                                           CompositeType comptype,
103                                           SurfaceType dsttype)
104    {
105        return null;
106    }
107
108    public GraphicsPrimitive traceWrap() {
109        return new TraceTransformHelper(this);
110    }
111
112    private static class TraceTransformHelper extends TransformHelper {
113        TransformHelper target;
114
115        public TraceTransformHelper(TransformHelper target) {
116            super(target.getSourceType());
117            this.target = target;
118        }
119
120        public GraphicsPrimitive traceWrap() {
121            return this;
122        }
123
124        public void Transform(MaskBlit output,
125                              SurfaceData src, SurfaceData dst,
126                              Composite comp, Region clip,
127                              AffineTransform itx, int txtype,
128                              int sx1, int sy1, int sx2, int sy2,
129                              int dx1, int dy1, int dx2, int dy2,
130                              int edges[], int dxoff, int dyoff)
131        {
132            tracePrimitive(target);
133            target.Transform(output, src, dst, comp, clip, itx, txtype,
134                             sx1, sy1, sx2, sy2,
135                             dx1, dy1, dx2, dy2,
136                             edges, dxoff, dyoff);
137        }
138    }
139}
140