001: /*
002: * Copyright 2002-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.Composite;
029: import java.awt.Transparency;
030: import java.awt.geom.AffineTransform;
031: import java.awt.image.AffineTransformOp;
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.Blit;
037: import sun.java2d.loops.ScaledBlit;
038: import sun.java2d.loops.TransformBlit;
039: import sun.java2d.pipe.Region;
040: import sun.java2d.SurfaceData;
041:
042: import static sun.java2d.d3d.D3DSurfaceData.*;
043:
044: /**
045: * This class contains accelerated blits/scales/transforms
046: * between textures and DD surfaces.
047: */
048: public class D3DBlitLoops {
049:
050: static void register() {
051: GraphicsPrimitive[] primitives = {
052: new D3DTextureToSurfaceBlit(IntRgbD3D),
053: new D3DTextureToSurfaceBlit(Ushort565RgbD3D),
054: new D3DTextureToSurfaceBlit(IntRgbxD3D),
055: new D3DTextureToSurfaceBlit(Ushort555RgbD3D),
056: new D3DTextureToSurfaceBlit(ThreeByteBgrD3D),
057:
058: new D3DTextureToSurfaceScale(IntRgbD3D),
059: new D3DTextureToSurfaceScale(Ushort565RgbD3D),
060: new D3DTextureToSurfaceScale(IntRgbxD3D),
061: new D3DTextureToSurfaceScale(Ushort555RgbD3D),
062: new D3DTextureToSurfaceScale(ThreeByteBgrD3D),
063:
064: new D3DTextureToSurfaceTransform(D3DTexture, IntRgbD3D),
065: new D3DTextureToSurfaceTransform(D3DTexture,
066: Ushort565RgbD3D),
067: new D3DTextureToSurfaceTransform(D3DTexture, IntRgbxD3D),
068: new D3DTextureToSurfaceTransform(D3DTexture,
069: Ushort555RgbD3D),
070: new D3DTextureToSurfaceTransform(D3DTexture,
071: ThreeByteBgrD3D),
072:
073: new DelegateSwToTextureLoop(),
074:
075: };
076: GraphicsPrimitiveMgr.register(primitives);
077: }
078:
079: static native void doTransform(long pSrc, long pDst, long pCtx,
080: int hint, int sx1, int sy1, int sx2, int sy2, float dx1,
081: float dy1, float dx2, float dy2);
082:
083: static long getContext(SurfaceData src, SurfaceData dst,
084: Region clip, Composite comp, AffineTransform at) {
085: int ctxFlags;
086: if (src.getTransparency() == Transparency.OPAQUE) {
087: ctxFlags = D3DContext.SRC_IS_OPAQUE;
088: } else {
089: ctxFlags = D3DContext.NO_CONTEXT_FLAGS;
090: }
091:
092: return D3DContext.getContext(src, dst, clip, comp, at,
093: 0xffffffff /* rgb */, ctxFlags);
094: }
095: }
096:
097: class D3DTextureToSurfaceBlit extends Blit {
098: D3DTextureToSurfaceBlit(SurfaceType dstType) {
099: super (D3DTexture, CompositeType.AnyAlpha, dstType);
100: }
101:
102: /**
103: * Blit
104: * This native method is where all of the work happens in the
105: * accelerated Blit.
106: */
107: @Override
108: public void Blit(SurfaceData src, SurfaceData dst, Composite comp,
109: Region clip, int sx, int sy, int dx, int dy, int w, int h) {
110: synchronized (D3DContext.LOCK) {
111: long pCtx = D3DBlitLoops.getContext(src, dst, clip, comp,
112: null);
113: D3DBlitLoops.doTransform(src.getNativeOps(), dst
114: .getNativeOps(), pCtx,
115: AffineTransformOp.TYPE_NEAREST_NEIGHBOR, sx, sy, sx
116: + w, sy + h, (float) dx, (float) dy,
117: (float) (dx + w), (float) (dy + h));
118: }
119: }
120: }
121:
122: class D3DTextureToSurfaceTransform extends TransformBlit {
123:
124: D3DTextureToSurfaceTransform(SurfaceType srcType,
125: SurfaceType dstType) {
126: super (srcType, CompositeType.AnyAlpha, dstType);
127: }
128:
129: @Override
130: public void Transform(SurfaceData src, SurfaceData dst,
131: Composite comp, Region clip, AffineTransform at, int hint,
132: int sx, int sy, int dx, int dy, int w, int h) {
133: synchronized (D3DContext.LOCK) {
134: long pCtx = D3DBlitLoops.getContext(src, dst, clip, comp,
135: at);
136: D3DBlitLoops.doTransform(src.getNativeOps(), dst
137: .getNativeOps(), pCtx, hint, sx, sy, sx + w,
138: sy + h, (float) dx, (float) dy, (float) (dx + w),
139: (float) (dy + h));
140: }
141: }
142: }
143:
144: class D3DTextureToSurfaceScale extends ScaledBlit {
145:
146: D3DTextureToSurfaceScale(SurfaceType dstType) {
147: super (D3DTexture, CompositeType.AnyAlpha, dstType);
148: }
149:
150: @Override
151: public void Scale(SurfaceData src, SurfaceData dst, Composite comp,
152: Region clip, int sx1, int sy1, int sx2, int sy2,
153: double dx1, double dy1, double dx2, double dy2) {
154: synchronized (D3DContext.LOCK) {
155: long pCtx = D3DBlitLoops.getContext(src, dst, clip, comp,
156: null);
157: D3DBlitLoops.doTransform(src.getNativeOps(), dst
158: .getNativeOps(), pCtx,
159: AffineTransformOp.TYPE_NEAREST_NEIGHBOR, sx1, sy1,
160: sx2, sy2, (float) dx1, (float) dy1, (float) dx2,
161: (float) dy2);
162: }
163: }
164: }
165:
166: class DelegateSwToTextureLoop extends Blit {
167:
168: DelegateSwToTextureLoop() {
169: super (SurfaceType.Any, CompositeType.SrcNoEa, D3DTexture);
170: }
171:
172: @Override
173: public void Blit(SurfaceData src, SurfaceData dst, Composite comp,
174: Region clip, int sx, int sy, int dx, int dy, int w, int h) {
175: Blit realBlit = null;
176: int pf = ((D3DSurfaceData) dst).getPixelFormat();
177: switch (pf) {
178: case PF_INT_ARGB:
179: realBlit = Blit.getFromCache(src.getSurfaceType(),
180: CompositeType.SrcNoEa, SurfaceType.IntArgbPre);
181: break;
182: case PF_INT_RGB:
183: realBlit = Blit.getFromCache(src.getSurfaceType(),
184: CompositeType.SrcNoEa, SurfaceType.IntRgb);
185: break;
186: case PF_USHORT_565_RGB:
187: realBlit = Blit.getFromCache(src.getSurfaceType(),
188: CompositeType.SrcNoEa, SurfaceType.Ushort565Rgb);
189: break;
190: case PF_USHORT_555_RGB:
191: realBlit = Blit.getFromCache(src.getSurfaceType(),
192: CompositeType.SrcNoEa, SurfaceType.Ushort555Rgb);
193: break;
194: case PF_USHORT_4444_ARGB:
195: // REMIND: this should really be premultiplied!
196: realBlit = Blit.getFromCache(src.getSurfaceType(),
197: CompositeType.SrcNoEa, SurfaceType.Ushort4444Argb);
198: break;
199: default:
200: throw new InternalError(
201: "Can't yet handle dest pixel format: " + pf);
202: }
203:
204: if (realBlit != null) {
205: realBlit.Blit(src, dst, comp, clip, sx, sy, dx, dy, w, h);
206: }
207: }
208: }
|