blob: e519e71ded458578fd6e1d0d8cb05a866069d2fe [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2000-2007 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.x11;
27
28import sun.awt.SunToolkit;
29import sun.java2d.loops.GraphicsPrimitive;
30import sun.java2d.loops.GraphicsPrimitiveMgr;
31import sun.java2d.loops.GraphicsPrimitiveProxy;
32import sun.java2d.loops.CompositeType;
33import sun.java2d.loops.SurfaceType;
34import sun.java2d.loops.Blit;
35import sun.java2d.loops.MaskBlit;
36import sun.java2d.pipe.Region;
37import sun.java2d.SurfaceData;
38import java.awt.Composite;
39import java.awt.image.IndexColorModel;
40
41/**
42 * X11PMBlitLoops
43 *
44 * This class accelerates Blits between two surfaces of types *PM. Since
45 * the onscreen surface is of that type and some of the offscreen surfaces
46 * may be of that type (if they were created via X11OffScreenImage), then
47 * this type of Blit will accelerated double-buffer copies between those
48 * two surfaces.
49*/
50public class X11PMBlitLoops extends Blit {
51
52 public static void register()
53 {
54 GraphicsPrimitive[] primitives = {
55 new X11PMBlitLoops(X11SurfaceData.IntBgrX11,
56 X11SurfaceData.IntBgrX11, false),
57 new X11PMBlitLoops(X11SurfaceData.IntRgbX11,
58 X11SurfaceData.IntRgbX11, false),
59 new X11PMBlitLoops(X11SurfaceData.ThreeByteBgrX11,
60 X11SurfaceData.ThreeByteBgrX11, false),
61 new X11PMBlitLoops(X11SurfaceData.ThreeByteRgbX11,
62 X11SurfaceData.ThreeByteRgbX11, false),
63 new X11PMBlitLoops(X11SurfaceData.ByteIndexedOpaqueX11,
64 X11SurfaceData.ByteIndexedOpaqueX11, false),
65 new X11PMBlitLoops(X11SurfaceData.ByteGrayX11,
66 X11SurfaceData.ByteGrayX11, false),
67 new X11PMBlitLoops(X11SurfaceData.Index8GrayX11,
68 X11SurfaceData.Index8GrayX11, false),
69 new X11PMBlitLoops(X11SurfaceData.UShort555RgbX11,
70 X11SurfaceData.UShort555RgbX11, false),
71 new X11PMBlitLoops(X11SurfaceData.UShort565RgbX11,
72 X11SurfaceData.UShort565RgbX11, false),
73 new X11PMBlitLoops(X11SurfaceData.UShortIndexedX11,
74 X11SurfaceData.UShortIndexedX11, false),
75
76 // 1-bit transparent to opaque loops
77 new X11PMBlitLoops(X11SurfaceData.IntBgrX11_BM,
78 X11SurfaceData.IntBgrX11, true),
79 new X11PMBlitLoops(X11SurfaceData.IntRgbX11_BM,
80 X11SurfaceData.IntRgbX11, true),
81 new X11PMBlitLoops(X11SurfaceData.ThreeByteBgrX11_BM,
82 X11SurfaceData.ThreeByteBgrX11, true),
83 new X11PMBlitLoops(X11SurfaceData.ThreeByteRgbX11_BM,
84 X11SurfaceData.ThreeByteRgbX11, true),
85 new X11PMBlitLoops(X11SurfaceData.ByteIndexedX11_BM,
86 X11SurfaceData.ByteIndexedOpaqueX11, true),
87 new X11PMBlitLoops(X11SurfaceData.ByteGrayX11_BM,
88 X11SurfaceData.ByteGrayX11, true),
89 new X11PMBlitLoops(X11SurfaceData.Index8GrayX11_BM,
90 X11SurfaceData.Index8GrayX11, true),
91 new X11PMBlitLoops(X11SurfaceData.UShort555RgbX11_BM,
92 X11SurfaceData.UShort555RgbX11, true),
93 new X11PMBlitLoops(X11SurfaceData.UShort565RgbX11_BM,
94 X11SurfaceData.UShort565RgbX11, true),
95 new X11PMBlitLoops(X11SurfaceData.UShortIndexedX11_BM,
96 X11SurfaceData.UShortIndexedX11, true),
97
98 // delegate loops
99 new DelegateBlitLoop(X11SurfaceData.IntBgrX11_BM,
100 X11SurfaceData.IntBgrX11),
101 new DelegateBlitLoop(X11SurfaceData.IntRgbX11_BM,
102 X11SurfaceData.IntRgbX11),
103 new DelegateBlitLoop(X11SurfaceData.ThreeByteBgrX11_BM,
104 X11SurfaceData.ThreeByteBgrX11),
105 new DelegateBlitLoop(X11SurfaceData.ThreeByteRgbX11_BM,
106 X11SurfaceData.ThreeByteRgbX11),
107 new DelegateBlitLoop(X11SurfaceData.ByteIndexedX11_BM,
108 X11SurfaceData.ByteIndexedOpaqueX11),
109 new DelegateBlitLoop(X11SurfaceData.ByteGrayX11_BM,
110 X11SurfaceData.ByteGrayX11),
111 new DelegateBlitLoop(X11SurfaceData.Index8GrayX11_BM,
112 X11SurfaceData.Index8GrayX11),
113 new DelegateBlitLoop(X11SurfaceData.UShort555RgbX11_BM,
114 X11SurfaceData.UShort555RgbX11),
115 new DelegateBlitLoop(X11SurfaceData.UShort565RgbX11_BM,
116 X11SurfaceData.UShort565RgbX11),
117 new DelegateBlitLoop(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,
127 over ? CompositeType.SrcOverNoEa : CompositeType.SrcNoEa,
128 dstType);
129 }
130
131 public void Blit(SurfaceData src, SurfaceData dst,
132 Composite comp, Region clip,
133 int sx, int sy,
134 int dx, int dy,
135 int w, int h)
136 {
137 SunToolkit.awtLock();
138 try {
139 X11SurfaceData x11sd = (X11SurfaceData)dst;
140 // pass null clip region here since we clip manually in native code
141 // also use false for needExposures since we clip to the pixmap
142 long xgc = x11sd.getBlitGC(null, false);
143 nativeBlit(src.getNativeOps(), dst.getNativeOps(), xgc, clip,
144 sx, sy, dx, dy, w, h);
145 } finally {
146 SunToolkit.awtUnlock();
147 }
148 }
149
150 /**
151 * Blit
152 * This native method is where all of the work happens in the
153 * accelerated Blit.
154 */
155 private native void nativeBlit(long srcData, long dstData,
156 long xgc, Region clip,
157 int sx, int sy, int dx, int dy,
158 int w, int h);
159
160 /**
161 * This loop is used to render from a BITMASK Sw surface data
162 * to the Hw cached copies managed by SurfaceDataProxies.
163 * It first uses a delegate opaque Blit to perform the copy of
164 * the pixel data and then updates the X11 clipping bitmask from
165 * the transparent pixels in the source.
166 */
167 static class DelegateBlitLoop extends Blit {
168 SurfaceType dstType;
169
170 /**
171 * @param realDstType SurfaceType for which the loop should be
172 * registered
173 * @param delegateDstType SurfaceType which will be used
174 * for finding delegate loop
175 */
176 public DelegateBlitLoop(SurfaceType realDstType, SurfaceType delegateDstType) {
177 super(SurfaceType.Any, CompositeType.SrcNoEa, realDstType);
178 this.dstType = delegateDstType;
179 }
180
181 public void Blit(SurfaceData src, SurfaceData dst,
182 Composite comp, Region clip,
183 int sx, int sy, int dx, int dy, int w, int h)
184 {
185 Blit blit = Blit.getFromCache(src.getSurfaceType(),
186 CompositeType.SrcNoEa,
187 dstType);
188 blit.Blit(src, dst, comp, clip, sx, sy, dx, dy, w, h);
189 updateBitmask(src, dst,
190 src.getColorModel() instanceof IndexColorModel);
191 }
192 }
193
194 private static native void updateBitmask(SurfaceData src,
195 SurfaceData dst,
196 boolean isICM);
197}