0N/A/*
2362N/A * Copyright (c) 2007, 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.pipe;
0N/A
0N/Aimport java.awt.AlphaComposite;
0N/Aimport java.awt.Composite;
0N/Aimport sun.java2d.SurfaceData;
0N/Aimport sun.java2d.loops.Blit;
0N/Aimport sun.java2d.loops.CompositeType;
0N/Aimport sun.java2d.loops.MaskBlit;
0N/Aimport sun.java2d.loops.SurfaceType;
0N/Aimport static sun.java2d.pipe.BufferedOpCodes.*;
0N/A
0N/A/**
0N/A * The MaskBlit operation is expressed as:
0N/A * dst = ((src <MODE> dst) * pathA) + (dst * (1 - pathA))
0N/A *
0N/A * The OGL/D3D implementation of the MaskBlit operation differs from the above
0N/A * equation because it is not possible to perform such a complex operation in
0N/A * OpenGL/Direct3D (without the use of advanced techniques like fragment
0N/A * shaders and multitexturing). Therefore, the BufferedMaskBlit operation
0N/A * is expressed as:
0N/A * dst = (src * pathA) <SrcOver> dst
0N/A *
0N/A * This simplified formula is only equivalent to the "true" MaskBlit equation
0N/A * in the following situations:
0N/A * - <MODE> is SrcOver
0N/A * - <MODE> is Src, extra alpha == 1.0, and the source surface is opaque
0N/A *
0N/A * Therefore, we register BufferedMaskBlit primitives for only the SurfaceType
0N/A * and CompositeType restrictions mentioned above. In addition for the Src
0N/A * case, we must override the composite with a SrcOver (no extra alpha)
0N/A * instance, so that we set up the OpenGL/Direct3D blending mode to match the
0N/A * BufferedMaskBlit equation.
0N/A */
0N/Apublic abstract class BufferedMaskBlit extends MaskBlit {
0N/A
0N/A private static final int ST_INT_ARGB = 0;
0N/A private static final int ST_INT_ARGB_PRE = 1;
0N/A private static final int ST_INT_RGB = 2;
0N/A private static final int ST_INT_BGR = 3;
0N/A
0N/A private final RenderQueue rq;
0N/A private final int srcTypeVal;
0N/A private Blit blitop;
0N/A
0N/A protected BufferedMaskBlit(RenderQueue rq,
0N/A SurfaceType srcType,
0N/A CompositeType compType,
0N/A SurfaceType dstType)
0N/A {
0N/A super(srcType, compType, dstType);
0N/A this.rq = rq;
0N/A if (srcType == SurfaceType.IntArgb) {
0N/A this.srcTypeVal = ST_INT_ARGB;
0N/A } else if (srcType == SurfaceType.IntArgbPre) {
0N/A this.srcTypeVal = ST_INT_ARGB_PRE;
0N/A } else if (srcType == SurfaceType.IntRgb) {
0N/A this.srcTypeVal = ST_INT_RGB;
0N/A } else if (srcType == SurfaceType.IntBgr) {
0N/A this.srcTypeVal = ST_INT_BGR;
0N/A } else {
0N/A throw new InternalError("unrecognized source surface type");
0N/A }
0N/A }
0N/A
0N/A @Override
0N/A public void MaskBlit(SurfaceData src, SurfaceData dst,
0N/A Composite comp, Region clip,
0N/A int srcx, int srcy,
0N/A int dstx, int dsty,
0N/A int width, int height,
0N/A byte[] mask, int maskoff, int maskscan)
0N/A {
0N/A if (width <= 0 || height <= 0) {
0N/A return;
0N/A }
0N/A
0N/A if (mask == null) {
0N/A // no mask involved; delegate to regular blit loop
0N/A if (blitop == null) {
0N/A blitop = Blit.getFromCache(src.getSurfaceType(),
0N/A CompositeType.AnyAlpha,
0N/A this.getDestType());
0N/A }
0N/A blitop.Blit(src, dst,
0N/A comp, clip,
0N/A srcx, srcy, dstx, dsty,
0N/A width, height);
0N/A return;
0N/A }
0N/A
0N/A AlphaComposite acomp = (AlphaComposite)comp;
0N/A if (acomp.getRule() != AlphaComposite.SRC_OVER) {
0N/A comp = AlphaComposite.SrcOver;
0N/A }
0N/A
0N/A rq.lock();
0N/A try {
0N/A validateContext(dst, comp, clip);
0N/A
0N/A RenderBuffer buf = rq.getBuffer();
0N/A int totalBytesRequired = 20 + (width * height * 4);
0N/A
0N/A /*
0N/A * REMIND: we should fix this so that it works with tiles that
0N/A * are larger than the entire buffer, but the native
0N/A * OGL/D3DMaskBlit isn't even prepared for tiles larger
0N/A * than 32x32 pixels, so there's no urgency here...
0N/A */
0N/A rq.ensureCapacity(totalBytesRequired);
0N/A
0N/A // enqueue parameters and tile pixels
0N/A int newpos = enqueueTile(buf.getAddress(), buf.position(),
0N/A src, src.getNativeOps(), srcTypeVal,
0N/A mask, mask.length, maskoff, maskscan,
0N/A srcx, srcy, dstx, dsty,
0N/A width, height);
0N/A
0N/A buf.position(newpos);
0N/A } finally {
0N/A rq.unlock();
0N/A }
0N/A }
0N/A
0N/A private native int enqueueTile(long buf, int bpos,
0N/A SurfaceData srcData,
0N/A long pSrcOps, int srcType,
0N/A byte[] mask, int masklen,
0N/A int maskoff, int maskscan,
0N/A int srcx, int srcy, int dstx, int dsty,
0N/A int width, int height);
0N/A
0N/A /**
0N/A * Validates the context state using the given destination surface
0N/A * and composite/clip values.
0N/A */
0N/A protected abstract void validateContext(SurfaceData dstData,
0N/A Composite comp, Region clip);
0N/A}