Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/java2d/loops/MaskFill.java
38918 views
/*1* Copyright (c) 1999, 2013, 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.Paint;28import java.awt.PaintContext;29import java.awt.Composite;30import java.awt.Rectangle;31import java.awt.image.ColorModel;32import java.awt.image.BufferedImage;33import java.awt.image.WritableRaster;34import sun.awt.image.BufImgSurfaceData;35import sun.java2d.loops.GraphicsPrimitive;36import sun.java2d.SunGraphics2D;37import sun.java2d.SurfaceData;38import sun.java2d.pipe.Region;3940/**41* MaskFill42* 1) fills rectangles of pixels on a surface43* 2) performs compositing of colors based upon a Composite44* parameter45* 3) blends result of composite with destination using an46* alpha coverage mask47* 4) the mask may be null in which case it should be treated48* as if it were an array of all opaque values (0xff)49*/50public class MaskFill extends GraphicsPrimitive51{52public static final String methodSignature = "MaskFill(...)".toString();53public static final String fillPgramSignature =54"FillAAPgram(...)".toString();55public static final String drawPgramSignature =56"DrawAAPgram(...)".toString();5758public static final int primTypeID = makePrimTypeID();5960private static RenderCache fillcache = new RenderCache(10);6162public static MaskFill locate(SurfaceType srctype,63CompositeType comptype,64SurfaceType dsttype)65{66return (MaskFill)67GraphicsPrimitiveMgr.locate(primTypeID,68srctype, comptype, dsttype);69}7071public static MaskFill locatePrim(SurfaceType srctype,72CompositeType comptype,73SurfaceType dsttype)74{75return (MaskFill)76GraphicsPrimitiveMgr.locatePrim(primTypeID,77srctype, comptype, dsttype);78}7980/*81* Note that this uses locatePrim, not locate, so it can return82* null if there is no specific loop to handle this op...83*/84public static MaskFill getFromCache(SurfaceType src,85CompositeType comp,86SurfaceType dst)87{88Object o = fillcache.get(src, comp, dst);89if (o != null) {90return (MaskFill) o;91}92MaskFill fill = locatePrim(src, comp, dst);93if (fill != null) {94fillcache.put(src, comp, dst, fill);95}96return fill;97}9899protected MaskFill(String alternateSignature,100SurfaceType srctype,101CompositeType comptype,102SurfaceType dsttype)103{104super(alternateSignature, primTypeID, srctype, comptype, dsttype);105}106107protected MaskFill(SurfaceType srctype,108CompositeType comptype,109SurfaceType dsttype)110{111super(methodSignature, primTypeID, srctype, comptype, dsttype);112}113114public MaskFill(long pNativePrim,115SurfaceType srctype,116CompositeType comptype,117SurfaceType dsttype)118{119super(pNativePrim, methodSignature, primTypeID, srctype, comptype, dsttype);120}121122/**123* All MaskFill implementors must have this invoker method124*/125public native void MaskFill(SunGraphics2D sg2d, SurfaceData sData,126Composite comp,127int x, int y, int w, int h,128byte[] mask, int maskoff, int maskscan);129130public native void FillAAPgram(SunGraphics2D sg2d, SurfaceData sData,131Composite comp,132double x, double y,133double dx1, double dy1,134double dx2, double dy2);135136public native void DrawAAPgram(SunGraphics2D sg2d, SurfaceData sData,137Composite comp,138double x, double y,139double dx1, double dy1,140double dx2, double dy2,141double lw1, double lw2);142143public boolean canDoParallelograms() {144return (getNativePrim() != 0);145}146147static {148GraphicsPrimitiveMgr.registerGeneral(new MaskFill(null, null, null));149}150151public GraphicsPrimitive makePrimitive(SurfaceType srctype,152CompositeType comptype,153SurfaceType dsttype)154{155if (SurfaceType.OpaqueColor.equals(srctype) ||156SurfaceType.AnyColor.equals(srctype))157{158if (CompositeType.Xor.equals(comptype)) {159throw new InternalError("Cannot construct MaskFill for " +160"XOR mode");161} else {162return new General(srctype, comptype, dsttype);163}164} else {165throw new InternalError("MaskFill can only fill with colors");166}167}168169private static class General extends MaskFill {170FillRect fillop;171MaskBlit maskop;172173public General(SurfaceType srctype,174CompositeType comptype,175SurfaceType dsttype)176{177super(srctype, comptype, dsttype);178fillop = FillRect.locate(srctype,179CompositeType.SrcNoEa,180SurfaceType.IntArgb);181maskop = MaskBlit.locate(SurfaceType.IntArgb, comptype, dsttype);182}183184public void MaskFill(SunGraphics2D sg2d,185SurfaceData sData,186Composite comp,187int x, int y, int w, int h,188byte mask[], int offset, int scan)189{190BufferedImage dstBI =191new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);192SurfaceData tmpData = BufImgSurfaceData.createData(dstBI);193194// REMIND: This is not pretty. It would be nicer if we195// passed a "FillData" object to the Pixel loops, instead196// of a SunGraphics2D parameter...197Region clip = sg2d.clipRegion;198sg2d.clipRegion = null;199int pixel = sg2d.pixel;200sg2d.pixel = tmpData.pixelFor(sg2d.getColor());201fillop.FillRect(sg2d, tmpData, 0, 0, w, h);202sg2d.pixel = pixel;203sg2d.clipRegion = clip;204205maskop.MaskBlit(tmpData, sData, comp, null,2060, 0, x, y, w, h,207mask, offset, scan);208}209}210211public GraphicsPrimitive traceWrap() {212return new TraceMaskFill(this);213}214215private static class TraceMaskFill extends MaskFill {216MaskFill target;217MaskFill fillPgramTarget;218MaskFill drawPgramTarget;219220public TraceMaskFill(MaskFill target) {221super(target.getSourceType(),222target.getCompositeType(),223target.getDestType());224this.target = target;225this.fillPgramTarget = new MaskFill(fillPgramSignature,226target.getSourceType(),227target.getCompositeType(),228target.getDestType());229this.drawPgramTarget = new MaskFill(drawPgramSignature,230target.getSourceType(),231target.getCompositeType(),232target.getDestType());233}234235public GraphicsPrimitive traceWrap() {236return this;237}238239public void MaskFill(SunGraphics2D sg2d, SurfaceData sData,240Composite comp,241int x, int y, int w, int h,242byte[] mask, int maskoff, int maskscan)243{244tracePrimitive(target);245target.MaskFill(sg2d, sData, comp, x, y, w, h,246mask, maskoff, maskscan);247}248249public void FillAAPgram(SunGraphics2D sg2d, SurfaceData sData,250Composite comp,251double x, double y,252double dx1, double dy1,253double dx2, double dy2)254{255tracePrimitive(fillPgramTarget);256target.FillAAPgram(sg2d, sData, comp,257x, y, dx1, dy1, dx2, dy2);258}259260public void DrawAAPgram(SunGraphics2D sg2d, SurfaceData sData,261Composite comp,262double x, double y,263double dx1, double dy1,264double dx2, double dy2,265double lw1, double lw2)266{267tracePrimitive(drawPgramTarget);268target.DrawAAPgram(sg2d, sData, comp,269x, y, dx1, dy1, dx2, dy2, lw1, lw2);270}271272public boolean canDoParallelograms() {273return target.canDoParallelograms();274}275}276}277278279