Path: blob/master/src/java.desktop/share/classes/sun/java2d/loops/ScaledBlit.java
41159 views
/*1* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.loops;2627import java.awt.Composite;2829import sun.java2d.SurfaceData;30import sun.java2d.pipe.Region;3132/**33* ScaledBlit34* 1) copies rectangle of pixels from one surface to another35* while scaling the pixels to meet the sizes specified36* 2) performs compositing of colors based upon a Composite37* parameter38*39* precise behavior is undefined if the source surface40* and the destination surface are the same surface41* with overlapping regions of pixels42*/4344public class ScaledBlit extends GraphicsPrimitive45{46public static final String methodSignature = "ScaledBlit(...)".toString();4748public static final int primTypeID = makePrimTypeID();4950private static RenderCache blitcache = new RenderCache(20);5152public static ScaledBlit locate(SurfaceType srctype,53CompositeType comptype,54SurfaceType dsttype)55{56return (ScaledBlit)57GraphicsPrimitiveMgr.locate(primTypeID,58srctype, comptype, dsttype);59}6061public static ScaledBlit getFromCache(SurfaceType src,62CompositeType comp,63SurfaceType dst)64{65Object o = blitcache.get(src, comp, dst);66if (o != null) {67return (ScaledBlit) o;68}69ScaledBlit blit = locate(src, comp, dst);70if (blit == null) {71/*72System.out.println("blit loop not found for:");73System.out.println("src: "+src);74System.out.println("comp: "+comp);75System.out.println("dst: "+dst);76*/77} else {78blitcache.put(src, comp, dst, blit);79}80return blit;81}8283protected ScaledBlit(SurfaceType srctype,84CompositeType comptype,85SurfaceType dsttype)86{87super(methodSignature, primTypeID, srctype, comptype, dsttype);88}8990public ScaledBlit(long pNativePrim,91SurfaceType srctype,92CompositeType comptype,93SurfaceType dsttype)94{95super(pNativePrim, methodSignature, primTypeID,96srctype, comptype, dsttype);97}9899public native void Scale(SurfaceData src, SurfaceData dst,100Composite comp, Region clip,101int sx1, int sy1,102int sx2, int sy2,103double dx1, double dy1,104double dx2, double dy2);105106public GraphicsPrimitive traceWrap() {107return new TraceScaledBlit(this);108}109110private static class TraceScaledBlit extends ScaledBlit {111ScaledBlit target;112113public TraceScaledBlit(ScaledBlit target) {114super(target.getSourceType(),115target.getCompositeType(),116target.getDestType());117this.target = target;118}119120public GraphicsPrimitive traceWrap() {121return this;122}123124public void Scale(SurfaceData src, SurfaceData dst,125Composite comp, Region clip,126int sx1, int sy1,127int sx2, int sy2,128double dx1, double dy1,129double dx2, double dy2)130{131tracePrimitive(target);132target.Scale(src, dst, comp, clip,133sx1, sy1, sx2, sy2,134dx1, dy1, dx2, dy2);135}136}137}138139140