001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.java2d.d3d;
027:
028: import java.awt.AlphaComposite;
029: import java.awt.Composite;
030: import sun.java2d.SunGraphics2D;
031: import sun.java2d.SurfaceData;
032: import sun.java2d.loops.GraphicsPrimitive;
033: import sun.java2d.loops.GraphicsPrimitiveMgr;
034: import sun.java2d.loops.CompositeType;
035: import sun.java2d.loops.SurfaceType;
036: import sun.java2d.loops.MaskFill;
037: import static sun.java2d.d3d.D3DSurfaceData.*;
038:
039: /**
040: * The MaskFill operation is expressed as:
041: * dst = ((src <MODE> dst) * pathA) + (dst * (1 - pathA))
042: *
043: * The D3D implementation of the MaskFill operation differs from the above
044: * equation because it is not possible to perform such a complex operation in
045: * D3d (without the use of advanced techniques like fragment shaders and
046: * multitexturing). Therefore, the D3DMaskFill operation is expressed as:
047: * dst = (src * pathA) <SrcOver> dst
048: *
049: * This simplified formula is only equivalent to the "true" MaskFill equation
050: * in the following situations:
051: * - <MODE> is SrcOver
052: * - <MODE> is Src, extra alpha == 1.0, and the source color is opaque
053: *
054: * Therefore, we register D3DMaskFill primitives for only the SurfaceType and
055: * CompositeType restrictions mentioned above. In addition for the Src
056: * case, we must override the composite with a SrcOver (no extra alpha)
057: * instance, so that we set up the D3d blending mode to match the
058: * D3DMaskFill equation.
059: */
060: public class D3DMaskFill extends MaskFill {
061:
062: public static void register() {
063: GraphicsPrimitive[] primitives = {
064: new D3DMaskFill(SurfaceType.AnyColor,
065: CompositeType.SrcOver, IntRgbD3D),
066: new D3DMaskFill(SurfaceType.OpaqueColor,
067: CompositeType.SrcNoEa, IntRgbD3D),
068:
069: new D3DMaskFill(SurfaceType.AnyColor,
070: CompositeType.SrcOver, Ushort565RgbD3D),
071: new D3DMaskFill(SurfaceType.OpaqueColor,
072: CompositeType.SrcNoEa, Ushort565RgbD3D),
073:
074: new D3DMaskFill(SurfaceType.AnyColor,
075: CompositeType.SrcOver, IntRgbxD3D),
076: new D3DMaskFill(SurfaceType.OpaqueColor,
077: CompositeType.SrcNoEa, IntRgbxD3D),
078:
079: new D3DMaskFill(SurfaceType.AnyColor,
080: CompositeType.SrcOver, Ushort555RgbD3D),
081: new D3DMaskFill(SurfaceType.OpaqueColor,
082: CompositeType.SrcNoEa, Ushort555RgbD3D),
083:
084: new D3DMaskFill(SurfaceType.AnyColor,
085: CompositeType.SrcOver, Ushort555RgbxD3D),
086: new D3DMaskFill(SurfaceType.OpaqueColor,
087: CompositeType.SrcNoEa, Ushort555RgbxD3D),
088:
089: new D3DMaskFill(SurfaceType.AnyColor,
090: CompositeType.SrcOver, ThreeByteBgrD3D),
091: new D3DMaskFill(SurfaceType.OpaqueColor,
092: CompositeType.SrcNoEa, ThreeByteBgrD3D), };
093: GraphicsPrimitiveMgr.register(primitives);
094: }
095:
096: D3DMaskFill(SurfaceType srcType, CompositeType compType,
097: SurfaceType dstType) {
098: super (srcType, compType, dstType);
099: }
100:
101: private native void MaskFill(long pData, long pCtx, int x, int y,
102: int w, int h, byte[] mask, int maskoff, int maskscan);
103:
104: @Override
105: public void MaskFill(SunGraphics2D sg2d, SurfaceData sData,
106: Composite comp, int x, int y, int w, int h, byte[] mask,
107: int maskoff, int maskscan) {
108: AlphaComposite acomp = (AlphaComposite) comp;
109: if (acomp.getRule() != AlphaComposite.SRC_OVER) {
110: comp = AlphaComposite.SrcOver;
111: }
112:
113: synchronized (D3DContext.LOCK) {
114: long pCtx = D3DContext.getContext(sData, sData, sg2d
115: .getCompClip(), comp, null, sg2d.eargb,
116: D3DContext.NO_CONTEXT_FLAGS);
117:
118: MaskFill(sData.getNativeOps(), pCtx, x, y, w, h, mask,
119: maskoff, maskscan);
120: }
121: }
122: }
|