1/* 2 * Copyright (c) 2003, 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 * TransformBlit 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 */ 45 46public class TransformBlit extends GraphicsPrimitive 47{ 48 public static final String methodSignature = 49 "TransformBlit(...)".toString(); 50 51 public static final int primTypeID = makePrimTypeID(); 52 53 private static RenderCache blitcache = new RenderCache(10); 54 55 public static TransformBlit locate(SurfaceType srctype, 56 CompositeType comptype, 57 SurfaceType dsttype) 58 { 59 return (TransformBlit) 60 GraphicsPrimitiveMgr.locate(primTypeID, 61 srctype, comptype, dsttype); 62 } 63 64 public static TransformBlit getFromCache(SurfaceType src, 65 CompositeType comp, 66 SurfaceType dst) 67 { 68 Object o = blitcache.get(src, comp, dst); 69 if (o != null) { 70 return (TransformBlit) o; 71 } 72 TransformBlit blit = locate(src, comp, dst); 73 if (blit == null) { 74 /* 75 System.out.println("blit loop not found for:"); 76 System.out.println("src: "+src); 77 System.out.println("comp: "+comp); 78 System.out.println("dst: "+dst); 79 */ 80 } else { 81 blitcache.put(src, comp, dst, blit); 82 } 83 return blit; 84 } 85 86 protected TransformBlit(SurfaceType srctype, 87 CompositeType comptype, 88 SurfaceType dsttype) 89 { 90 super(methodSignature, primTypeID, srctype, comptype, dsttype); 91 } 92 93 public TransformBlit(long pNativePrim, 94 SurfaceType srctype, 95 CompositeType comptype, 96 SurfaceType dsttype) 97 { 98 super(pNativePrim, methodSignature, primTypeID, 99 srctype, comptype, dsttype); 100 } 101 102 public native void Transform(SurfaceData src, SurfaceData dst, 103 Composite comp, Region clip, 104 AffineTransform at, int hint, 105 int srcx, int srcy, int dstx, int dsty, 106 int width, int height); 107 108 // REMIND: do we have a general loop? 109 static { 110 GraphicsPrimitiveMgr.registerGeneral(new TransformBlit(null, null, 111 null)); 112 } 113 114 public GraphicsPrimitive makePrimitive(SurfaceType srctype, 115 CompositeType comptype, 116 SurfaceType dsttype) 117 { 118 /* 119 System.out.println("Constructing general blit for:"); 120 System.out.println("src: "+srctype); 121 System.out.println("comp: "+comptype); 122 System.out.println("dst: "+dsttype); 123 */ 124 return null; 125 } 126 127 public GraphicsPrimitive traceWrap() { 128 return new TraceTransformBlit(this); 129 } 130 131 private static class TraceTransformBlit extends TransformBlit { 132 TransformBlit target; 133 134 public TraceTransformBlit(TransformBlit target) { 135 super(target.getSourceType(), 136 target.getCompositeType(), 137 target.getDestType()); 138 this.target = target; 139 } 140 141 public GraphicsPrimitive traceWrap() { 142 return this; 143 } 144 145 public void Transform(SurfaceData src, SurfaceData dst, 146 Composite comp, Region clip, 147 AffineTransform at, int hint, 148 int srcx, int srcy, int dstx, int dsty, 149 int width, int height) 150 { 151 tracePrimitive(target); 152 target.Transform(src, dst, comp, clip, at, hint, 153 srcx, srcy, dstx, dsty, width, height); 154 } 155 } 156} 157