1 /*
2  * Copyright (c) 2001, 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 
26 package sun.java2d.loops;
27 
28 import java.awt.Composite;
29 import sun.java2d.loops.GraphicsPrimitive;
30 import sun.java2d.SurfaceData;
31 import sun.java2d.pipe.Region;
32 
33 /**
34  * ScaledBlit
35  * 1) copies rectangle of pixels from one surface to another
36  *    while scaling the pixels to meet the sizes specified
37  * 2) performs compositing of colors based upon a Composite
38  *    parameter
39  *
40  * precise behavior is undefined if the source surface
41  * and the destination surface are the same surface
42  * with overlapping regions of pixels
43  */
44 
45 public class ScaledBlit extends GraphicsPrimitive
46 {
47     public static final String methodSignature = "ScaledBlit(...)".toString();
48 
49     public static final int primTypeID = makePrimTypeID();
50 
51     private static RenderCache blitcache = new RenderCache(20);
52 
locate(SurfaceType srctype, CompositeType comptype, SurfaceType dsttype)53     public static ScaledBlit locate(SurfaceType srctype,
54                               CompositeType comptype,
55                               SurfaceType dsttype)
56     {
57         return (ScaledBlit)
58             GraphicsPrimitiveMgr.locate(primTypeID,
59                                         srctype, comptype, dsttype);
60     }
61 
getFromCache(SurfaceType src, CompositeType comp, SurfaceType dst)62     public static ScaledBlit getFromCache(SurfaceType src,
63                                           CompositeType comp,
64                                           SurfaceType dst)
65     {
66         Object o = blitcache.get(src, comp, dst);
67         if (o != null) {
68             return (ScaledBlit) o;
69         }
70         ScaledBlit blit = locate(src, comp, dst);
71         if (blit == null) {
72             /*
73             System.out.println("blit loop not found for:");
74             System.out.println("src:  "+src);
75             System.out.println("comp: "+comp);
76             System.out.println("dst:  "+dst);
77             */
78         } else {
79             blitcache.put(src, comp, dst, blit);
80         }
81         return blit;
82     }
83 
ScaledBlit(SurfaceType srctype, CompositeType comptype, SurfaceType dsttype)84     protected ScaledBlit(SurfaceType srctype,
85                    CompositeType comptype,
86                    SurfaceType dsttype)
87     {
88         super(methodSignature, primTypeID, srctype, comptype, dsttype);
89     }
90 
ScaledBlit(long pNativePrim, SurfaceType srctype, CompositeType comptype, SurfaceType dsttype)91     public ScaledBlit(long pNativePrim,
92                       SurfaceType srctype,
93                       CompositeType comptype,
94                       SurfaceType dsttype)
95     {
96         super(pNativePrim, methodSignature, primTypeID,
97               srctype, comptype, dsttype);
98     }
99 
Scale(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx1, int sy1, int sx2, int sy2, double dx1, double dy1, double dx2, double dy2)100     public native void Scale(SurfaceData src, SurfaceData dst,
101                              Composite comp, Region clip,
102                              int sx1, int sy1,
103                              int sx2, int sy2,
104                              double dx1, double dy1,
105                              double dx2, double dy2);
106 
107     static {
GraphicsPrimitiveMgr.registerGeneral(new ScaledBlit(null, null, null))108         GraphicsPrimitiveMgr.registerGeneral(new ScaledBlit(null, null, null));
109     }
110 
makePrimitive(SurfaceType srctype, CompositeType comptype, SurfaceType dsttype)111     public GraphicsPrimitive makePrimitive(SurfaceType srctype,
112                                            CompositeType comptype,
113                                            SurfaceType dsttype)
114     {
115         /*
116         System.out.println("Constructing general blit for:");
117         System.out.println("src:  "+srctype);
118         System.out.println("comp: "+comptype);
119         System.out.println("dst:  "+dsttype);
120         */
121         return null;
122     }
123 
traceWrap()124     public GraphicsPrimitive traceWrap() {
125         return new TraceScaledBlit(this);
126     }
127 
128     private static class TraceScaledBlit extends ScaledBlit {
129         ScaledBlit target;
130 
TraceScaledBlit(ScaledBlit target)131         public TraceScaledBlit(ScaledBlit target) {
132             super(target.getSourceType(),
133                   target.getCompositeType(),
134                   target.getDestType());
135             this.target = target;
136         }
137 
traceWrap()138         public GraphicsPrimitive traceWrap() {
139             return this;
140         }
141 
Scale(SurfaceData src, SurfaceData dst, Composite comp, Region clip, int sx1, int sy1, int sx2, int sy2, double dx1, double dy1, double dx2, double dy2)142         public void Scale(SurfaceData src, SurfaceData dst,
143                           Composite comp, Region clip,
144                           int sx1, int sy1,
145                           int sx2, int sy2,
146                           double dx1, double dy1,
147                           double dx2, double dy2)
148         {
149             tracePrimitive(target);
150             target.Scale(src, dst, comp, clip,
151                          sx1, sy1, sx2, sy2,
152                          dx1, dy1, dx2, dy2);
153         }
154     }
155 }
156