blob: 1f0abcbbf3272a2dc2831e72cecabaf27cefd3db [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.java2d.d3d;
27
28import java.awt.AlphaComposite;
29import java.awt.Composite;
30import sun.java2d.SunGraphics2D;
31import sun.java2d.SurfaceData;
32import sun.java2d.loops.GraphicsPrimitive;
33import sun.java2d.loops.GraphicsPrimitiveMgr;
34import sun.java2d.loops.CompositeType;
35import sun.java2d.loops.SurfaceType;
36import sun.java2d.loops.MaskFill;
37import static sun.java2d.d3d.D3DSurfaceData.*;
38
39/**
40 * The MaskFill operation is expressed as:
41 * dst = ((src <MODE> dst) * pathA) + (dst * (1 - pathA))
42 *
43 * The D3D implementation of the MaskFill operation differs from the above
44 * equation because it is not possible to perform such a complex operation in
45 * D3d (without the use of advanced techniques like fragment shaders and
46 * multitexturing). Therefore, the D3DMaskFill operation is expressed as:
47 * dst = (src * pathA) <SrcOver> dst
48 *
49 * This simplified formula is only equivalent to the "true" MaskFill equation
50 * in the following situations:
51 * - <MODE> is SrcOver
52 * - <MODE> is Src, extra alpha == 1.0, and the source color is opaque
53 *
54 * Therefore, we register D3DMaskFill primitives for only the SurfaceType and
55 * CompositeType restrictions mentioned above. In addition for the Src
56 * case, we must override the composite with a SrcOver (no extra alpha)
57 * instance, so that we set up the D3d blending mode to match the
58 * D3DMaskFill equation.
59 */
60public class D3DMaskFill extends MaskFill {
61
62 public static void register() {
63 GraphicsPrimitive[] primitives = {
64 new D3DMaskFill(SurfaceType.AnyColor,
65 CompositeType.SrcOver,
66 IntRgbD3D),
67 new D3DMaskFill(SurfaceType.OpaqueColor,
68 CompositeType.SrcNoEa,
69 IntRgbD3D),
70
71 new D3DMaskFill(SurfaceType.AnyColor,
72 CompositeType.SrcOver,
73 Ushort565RgbD3D),
74 new D3DMaskFill(SurfaceType.OpaqueColor,
75 CompositeType.SrcNoEa,
76 Ushort565RgbD3D),
77
78 new D3DMaskFill(SurfaceType.AnyColor,
79 CompositeType.SrcOver,
80 IntRgbxD3D),
81 new D3DMaskFill(SurfaceType.OpaqueColor,
82 CompositeType.SrcNoEa,
83 IntRgbxD3D),
84
85 new D3DMaskFill(SurfaceType.AnyColor,
86 CompositeType.SrcOver,
87 Ushort555RgbD3D),
88 new D3DMaskFill(SurfaceType.OpaqueColor,
89 CompositeType.SrcNoEa,
90 Ushort555RgbD3D),
91
92 new D3DMaskFill(SurfaceType.AnyColor,
93 CompositeType.SrcOver,
94 Ushort555RgbxD3D),
95 new D3DMaskFill(SurfaceType.OpaqueColor,
96 CompositeType.SrcNoEa,
97 Ushort555RgbxD3D),
98
99 new D3DMaskFill(SurfaceType.AnyColor,
100 CompositeType.SrcOver,
101 ThreeByteBgrD3D),
102 new D3DMaskFill(SurfaceType.OpaqueColor,
103 CompositeType.SrcNoEa,
104 ThreeByteBgrD3D),
105 };
106 GraphicsPrimitiveMgr.register(primitives);
107 }
108
109 D3DMaskFill(SurfaceType srcType, CompositeType compType,
110 SurfaceType dstType) {
111 super(srcType, compType, dstType);
112 }
113
114 private native void MaskFill(long pData, long pCtx,
115 int x, int y, int w, int h,
116 byte[] mask, int maskoff, int maskscan);
117
118 @Override
119 public void MaskFill(SunGraphics2D sg2d, SurfaceData sData,
120 Composite comp,
121 int x, int y, int w, int h,
122 byte[] mask, int maskoff, int maskscan)
123 {
124 AlphaComposite acomp = (AlphaComposite)comp;
125 if (acomp.getRule() != AlphaComposite.SRC_OVER) {
126 comp = AlphaComposite.SrcOver;
127 }
128
129 synchronized (D3DContext.LOCK) {
130 long pCtx = D3DContext.getContext(sData, sData,
131 sg2d.getCompClip(), comp,
132 null, sg2d.eargb,
133 D3DContext.NO_CONTEXT_FLAGS);
134
135 MaskFill(sData.getNativeOps(), pCtx, x, y, w, h,
136 mask, maskoff, maskscan);
137 }
138 }
139}