0N/A/*
3909N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d.loops;
0N/A
0N/Aimport java.awt.Paint;
0N/Aimport java.awt.PaintContext;
0N/Aimport java.awt.Composite;
0N/Aimport java.awt.Rectangle;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.WritableRaster;
0N/Aimport sun.awt.image.BufImgSurfaceData;
0N/Aimport sun.java2d.loops.GraphicsPrimitive;
0N/Aimport sun.java2d.SunGraphics2D;
0N/Aimport sun.java2d.SurfaceData;
6126N/Aimport sun.java2d.pipe.Region;
0N/A
0N/A/**
0N/A * MaskFill
0N/A * 1) fills rectangles of pixels on a surface
0N/A * 2) performs compositing of colors based upon a Composite
0N/A * parameter
0N/A * 3) blends result of composite with destination using an
0N/A * alpha coverage mask
0N/A * 4) the mask may be null in which case it should be treated
0N/A * as if it were an array of all opaque values (0xff)
0N/A */
0N/Apublic class MaskFill extends GraphicsPrimitive
0N/A{
0N/A public static final String methodSignature = "MaskFill(...)".toString();
3265N/A public static final String fillPgramSignature =
3265N/A "FillAAPgram(...)".toString();
3265N/A public static final String drawPgramSignature =
3265N/A "DrawAAPgram(...)".toString();
0N/A
0N/A public static final int primTypeID = makePrimTypeID();
0N/A
0N/A private static RenderCache fillcache = new RenderCache(10);
0N/A
0N/A public static MaskFill locate(SurfaceType srctype,
0N/A CompositeType comptype,
0N/A SurfaceType dsttype)
0N/A {
0N/A return (MaskFill)
0N/A GraphicsPrimitiveMgr.locate(primTypeID,
0N/A srctype, comptype, dsttype);
0N/A }
0N/A
0N/A public static MaskFill locatePrim(SurfaceType srctype,
0N/A CompositeType comptype,
0N/A SurfaceType dsttype)
0N/A {
0N/A return (MaskFill)
0N/A GraphicsPrimitiveMgr.locatePrim(primTypeID,
0N/A srctype, comptype, dsttype);
0N/A }
0N/A
0N/A /*
0N/A * Note that this uses locatePrim, not locate, so it can return
0N/A * null if there is no specific loop to handle this op...
0N/A */
0N/A public static MaskFill getFromCache(SurfaceType src,
0N/A CompositeType comp,
0N/A SurfaceType dst)
0N/A {
0N/A Object o = fillcache.get(src, comp, dst);
0N/A if (o != null) {
0N/A return (MaskFill) o;
0N/A }
0N/A MaskFill fill = locatePrim(src, comp, dst);
0N/A if (fill != null) {
0N/A fillcache.put(src, comp, dst, fill);
0N/A }
0N/A return fill;
0N/A }
0N/A
3265N/A protected MaskFill(String alternateSignature,
3265N/A SurfaceType srctype,
3265N/A CompositeType comptype,
3265N/A SurfaceType dsttype)
3265N/A {
3265N/A super(alternateSignature, primTypeID, srctype, comptype, dsttype);
3265N/A }
3265N/A
0N/A protected MaskFill(SurfaceType srctype,
0N/A CompositeType comptype,
0N/A SurfaceType dsttype)
0N/A {
0N/A super(methodSignature, primTypeID, srctype, comptype, dsttype);
0N/A }
0N/A
0N/A public MaskFill(long pNativePrim,
0N/A SurfaceType srctype,
0N/A CompositeType comptype,
0N/A SurfaceType dsttype)
0N/A {
0N/A super(pNativePrim, methodSignature, primTypeID, srctype, comptype, dsttype);
0N/A }
0N/A
0N/A /**
0N/A * All MaskFill implementors must have this invoker method
0N/A */
0N/A public native void MaskFill(SunGraphics2D sg2d, SurfaceData sData,
0N/A Composite comp,
0N/A int x, int y, int w, int h,
0N/A byte[] mask, int maskoff, int maskscan);
0N/A
3265N/A public native void FillAAPgram(SunGraphics2D sg2d, SurfaceData sData,
3265N/A Composite comp,
3265N/A double x, double y,
3265N/A double dx1, double dy1,
3265N/A double dx2, double dy2);
3265N/A
3265N/A public native void DrawAAPgram(SunGraphics2D sg2d, SurfaceData sData,
3265N/A Composite comp,
3265N/A double x, double y,
3265N/A double dx1, double dy1,
3265N/A double dx2, double dy2,
3265N/A double lw1, double lw2);
3265N/A
3265N/A public boolean canDoParallelograms() {
3265N/A return (getNativePrim() != 0);
3265N/A }
3265N/A
0N/A static {
0N/A GraphicsPrimitiveMgr.registerGeneral(new MaskFill(null, null, null));
0N/A }
0N/A
0N/A public GraphicsPrimitive makePrimitive(SurfaceType srctype,
0N/A CompositeType comptype,
0N/A SurfaceType dsttype)
0N/A {
0N/A if (SurfaceType.OpaqueColor.equals(srctype) ||
0N/A SurfaceType.AnyColor.equals(srctype))
0N/A {
0N/A if (CompositeType.Xor.equals(comptype)) {
0N/A throw new InternalError("Cannot construct MaskFill for " +
0N/A "XOR mode");
0N/A } else {
0N/A return new General(srctype, comptype, dsttype);
0N/A }
0N/A } else {
0N/A throw new InternalError("MaskFill can only fill with colors");
0N/A }
0N/A }
0N/A
0N/A private static class General extends MaskFill {
0N/A FillRect fillop;
0N/A MaskBlit maskop;
0N/A
0N/A public General(SurfaceType srctype,
0N/A CompositeType comptype,
0N/A SurfaceType dsttype)
0N/A {
0N/A super(srctype, comptype, dsttype);
0N/A fillop = FillRect.locate(srctype,
0N/A CompositeType.SrcNoEa,
0N/A SurfaceType.IntArgb);
0N/A maskop = MaskBlit.locate(SurfaceType.IntArgb, comptype, dsttype);
0N/A }
0N/A
0N/A public void MaskFill(SunGraphics2D sg2d,
0N/A SurfaceData sData,
0N/A Composite comp,
0N/A int x, int y, int w, int h,
0N/A byte mask[], int offset, int scan)
0N/A {
0N/A BufferedImage dstBI =
0N/A new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
0N/A SurfaceData tmpData = BufImgSurfaceData.createData(dstBI);
0N/A
0N/A // REMIND: This is not pretty. It would be nicer if we
0N/A // passed a "FillData" object to the Pixel loops, instead
0N/A // of a SunGraphics2D parameter...
6126N/A Region clip = sg2d.clipRegion;
6126N/A sg2d.clipRegion = null;
0N/A int pixel = sg2d.pixel;
0N/A sg2d.pixel = tmpData.pixelFor(sg2d.getColor());
0N/A fillop.FillRect(sg2d, tmpData, 0, 0, w, h);
0N/A sg2d.pixel = pixel;
6126N/A sg2d.clipRegion = clip;
0N/A
0N/A maskop.MaskBlit(tmpData, sData, comp, null,
0N/A 0, 0, x, y, w, h,
0N/A mask, offset, scan);
0N/A }
0N/A }
0N/A
0N/A public GraphicsPrimitive traceWrap() {
0N/A return new TraceMaskFill(this);
0N/A }
0N/A
0N/A private static class TraceMaskFill extends MaskFill {
0N/A MaskFill target;
3265N/A MaskFill fillPgramTarget;
3265N/A MaskFill drawPgramTarget;
0N/A
0N/A public TraceMaskFill(MaskFill target) {
0N/A super(target.getSourceType(),
0N/A target.getCompositeType(),
0N/A target.getDestType());
0N/A this.target = target;
3265N/A this.fillPgramTarget = new MaskFill(fillPgramSignature,
3265N/A target.getSourceType(),
3265N/A target.getCompositeType(),
3265N/A target.getDestType());
3265N/A this.drawPgramTarget = new MaskFill(drawPgramSignature,
3265N/A target.getSourceType(),
3265N/A target.getCompositeType(),
3265N/A target.getDestType());
0N/A }
0N/A
0N/A public GraphicsPrimitive traceWrap() {
0N/A return this;
0N/A }
0N/A
0N/A public void MaskFill(SunGraphics2D sg2d, SurfaceData sData,
0N/A Composite comp,
0N/A int x, int y, int w, int h,
0N/A byte[] mask, int maskoff, int maskscan)
0N/A {
0N/A tracePrimitive(target);
0N/A target.MaskFill(sg2d, sData, comp, x, y, w, h,
0N/A mask, maskoff, maskscan);
0N/A }
3265N/A
3265N/A public void FillAAPgram(SunGraphics2D sg2d, SurfaceData sData,
3265N/A Composite comp,
3265N/A double x, double y,
3265N/A double dx1, double dy1,
3265N/A double dx2, double dy2)
3265N/A {
3265N/A tracePrimitive(fillPgramTarget);
3265N/A target.FillAAPgram(sg2d, sData, comp,
3265N/A x, y, dx1, dy1, dx2, dy2);
3265N/A }
3265N/A
3265N/A public void DrawAAPgram(SunGraphics2D sg2d, SurfaceData sData,
3265N/A Composite comp,
3265N/A double x, double y,
3265N/A double dx1, double dy1,
3265N/A double dx2, double dy2,
3265N/A double lw1, double lw2)
3265N/A {
3265N/A tracePrimitive(drawPgramTarget);
3265N/A target.DrawAAPgram(sg2d, sData, comp,
3265N/A x, y, dx1, dy1, dx2, dy2, lw1, lw2);
3265N/A }
3265N/A
3265N/A public boolean canDoParallelograms() {
3265N/A return target.canDoParallelograms();
3265N/A }
0N/A }
0N/A}