001: /*
002: * Copyright 2000-2007 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.x11;
027:
028: import sun.awt.SunToolkit;
029: import sun.java2d.loops.GraphicsPrimitive;
030: import sun.java2d.loops.GraphicsPrimitiveMgr;
031: import sun.java2d.loops.GraphicsPrimitiveProxy;
032: import sun.java2d.loops.CompositeType;
033: import sun.java2d.loops.SurfaceType;
034: import sun.java2d.loops.Blit;
035: import sun.java2d.loops.MaskBlit;
036: import sun.java2d.pipe.Region;
037: import sun.java2d.SurfaceData;
038: import java.awt.Composite;
039: import java.awt.image.IndexColorModel;
040:
041: /**
042: * X11PMBlitLoops
043: *
044: * This class accelerates Blits between two surfaces of types *PM. Since
045: * the onscreen surface is of that type and some of the offscreen surfaces
046: * may be of that type (if they were created via X11OffScreenImage), then
047: * this type of Blit will accelerated double-buffer copies between those
048: * two surfaces.
049: */
050: public class X11PMBlitLoops extends Blit {
051:
052: public static void register() {
053: GraphicsPrimitive[] primitives = {
054: new X11PMBlitLoops(X11SurfaceData.IntBgrX11,
055: X11SurfaceData.IntBgrX11, false),
056: new X11PMBlitLoops(X11SurfaceData.IntRgbX11,
057: X11SurfaceData.IntRgbX11, false),
058: new X11PMBlitLoops(X11SurfaceData.ThreeByteBgrX11,
059: X11SurfaceData.ThreeByteBgrX11, false),
060: new X11PMBlitLoops(X11SurfaceData.ThreeByteRgbX11,
061: X11SurfaceData.ThreeByteRgbX11, false),
062: new X11PMBlitLoops(X11SurfaceData.ByteIndexedOpaqueX11,
063: X11SurfaceData.ByteIndexedOpaqueX11, false),
064: new X11PMBlitLoops(X11SurfaceData.ByteGrayX11,
065: X11SurfaceData.ByteGrayX11, false),
066: new X11PMBlitLoops(X11SurfaceData.Index8GrayX11,
067: X11SurfaceData.Index8GrayX11, false),
068: new X11PMBlitLoops(X11SurfaceData.UShort555RgbX11,
069: X11SurfaceData.UShort555RgbX11, false),
070: new X11PMBlitLoops(X11SurfaceData.UShort565RgbX11,
071: X11SurfaceData.UShort565RgbX11, false),
072: new X11PMBlitLoops(X11SurfaceData.UShortIndexedX11,
073: X11SurfaceData.UShortIndexedX11, false),
074:
075: // 1-bit transparent to opaque loops
076: new X11PMBlitLoops(X11SurfaceData.IntBgrX11_BM,
077: X11SurfaceData.IntBgrX11, true),
078: new X11PMBlitLoops(X11SurfaceData.IntRgbX11_BM,
079: X11SurfaceData.IntRgbX11, true),
080: new X11PMBlitLoops(X11SurfaceData.ThreeByteBgrX11_BM,
081: X11SurfaceData.ThreeByteBgrX11, true),
082: new X11PMBlitLoops(X11SurfaceData.ThreeByteRgbX11_BM,
083: X11SurfaceData.ThreeByteRgbX11, true),
084: new X11PMBlitLoops(X11SurfaceData.ByteIndexedX11_BM,
085: X11SurfaceData.ByteIndexedOpaqueX11, true),
086: new X11PMBlitLoops(X11SurfaceData.ByteGrayX11_BM,
087: X11SurfaceData.ByteGrayX11, true),
088: new X11PMBlitLoops(X11SurfaceData.Index8GrayX11_BM,
089: X11SurfaceData.Index8GrayX11, true),
090: new X11PMBlitLoops(X11SurfaceData.UShort555RgbX11_BM,
091: X11SurfaceData.UShort555RgbX11, true),
092: new X11PMBlitLoops(X11SurfaceData.UShort565RgbX11_BM,
093: X11SurfaceData.UShort565RgbX11, true),
094: new X11PMBlitLoops(X11SurfaceData.UShortIndexedX11_BM,
095: X11SurfaceData.UShortIndexedX11, true),
096:
097: // delegate loops
098: new DelegateBlitLoop(X11SurfaceData.IntBgrX11_BM,
099: X11SurfaceData.IntBgrX11),
100: new DelegateBlitLoop(X11SurfaceData.IntRgbX11_BM,
101: X11SurfaceData.IntRgbX11),
102: new DelegateBlitLoop(X11SurfaceData.ThreeByteBgrX11_BM,
103: X11SurfaceData.ThreeByteBgrX11),
104: new DelegateBlitLoop(X11SurfaceData.ThreeByteRgbX11_BM,
105: X11SurfaceData.ThreeByteRgbX11),
106: new DelegateBlitLoop(X11SurfaceData.ByteIndexedX11_BM,
107: X11SurfaceData.ByteIndexedOpaqueX11),
108: new DelegateBlitLoop(X11SurfaceData.ByteGrayX11_BM,
109: X11SurfaceData.ByteGrayX11),
110: new DelegateBlitLoop(X11SurfaceData.Index8GrayX11_BM,
111: X11SurfaceData.Index8GrayX11),
112: new DelegateBlitLoop(X11SurfaceData.UShort555RgbX11_BM,
113: X11SurfaceData.UShort555RgbX11),
114: new DelegateBlitLoop(X11SurfaceData.UShort565RgbX11_BM,
115: X11SurfaceData.UShort565RgbX11),
116: new DelegateBlitLoop(
117: X11SurfaceData.UShortIndexedX11_BM,
118: X11SurfaceData.UShortIndexedX11),
119:
120: };
121: GraphicsPrimitiveMgr.register(primitives);
122: }
123:
124: public X11PMBlitLoops(SurfaceType srcType, SurfaceType dstType,
125: boolean over) {
126: super (srcType, over ? CompositeType.SrcOverNoEa
127: : CompositeType.SrcNoEa, dstType);
128: }
129:
130: public void Blit(SurfaceData src, SurfaceData dst, Composite comp,
131: Region clip, int sx, int sy, int dx, int dy, int w, int h) {
132: SunToolkit.awtLock();
133: try {
134: X11SurfaceData x11sd = (X11SurfaceData) dst;
135: // pass null clip region here since we clip manually in native code
136: // also use false for needExposures since we clip to the pixmap
137: long xgc = x11sd.getBlitGC(null, false);
138: nativeBlit(src.getNativeOps(), dst.getNativeOps(), xgc,
139: clip, sx, sy, dx, dy, w, h);
140: } finally {
141: SunToolkit.awtUnlock();
142: }
143: }
144:
145: /**
146: * Blit
147: * This native method is where all of the work happens in the
148: * accelerated Blit.
149: */
150: private native void nativeBlit(long srcData, long dstData,
151: long xgc, Region clip, int sx, int sy, int dx, int dy,
152: int w, int h);
153:
154: /**
155: * This loop is used to render from a BITMASK Sw surface data
156: * to the Hw cached copies managed by SurfaceDataProxies.
157: * It first uses a delegate opaque Blit to perform the copy of
158: * the pixel data and then updates the X11 clipping bitmask from
159: * the transparent pixels in the source.
160: */
161: static class DelegateBlitLoop extends Blit {
162: SurfaceType dstType;
163:
164: /**
165: * @param realDstType SurfaceType for which the loop should be
166: * registered
167: * @param delegateDstType SurfaceType which will be used
168: * for finding delegate loop
169: */
170: public DelegateBlitLoop(SurfaceType realDstType,
171: SurfaceType delegateDstType) {
172: super (SurfaceType.Any, CompositeType.SrcNoEa, realDstType);
173: this .dstType = delegateDstType;
174: }
175:
176: public void Blit(SurfaceData src, SurfaceData dst,
177: Composite comp, Region clip, int sx, int sy, int dx,
178: int dy, int w, int h) {
179: Blit blit = Blit.getFromCache(src.getSurfaceType(),
180: CompositeType.SrcNoEa, dstType);
181: blit.Blit(src, dst, comp, clip, sx, sy, dx, dy, w, h);
182: updateBitmask(src, dst,
183: src.getColorModel() instanceof IndexColorModel);
184: }
185: }
186:
187: private static native void updateBitmask(SurfaceData src,
188: SurfaceData dst, boolean isICM);
189: }
|