author | trims |
Thu, 11 Nov 2010 23:30:49 -0800 | |
changeset 7128 | a683e80b9ca8 |
parent 5506 | 202f599c92aa |
child 12813 | c10ab96dcf41 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.java2d.d3d; |
|
27 |
||
28 |
import java.awt.Composite; |
|
29 |
import java.awt.Transparency; |
|
30 |
import java.awt.geom.AffineTransform; |
|
31 |
import java.awt.image.AffineTransformOp; |
|
887 | 32 |
import java.awt.image.BufferedImage; |
33 |
import java.awt.image.BufferedImageOp; |
|
34 |
import java.lang.ref.WeakReference; |
|
35 |
import sun.java2d.ScreenUpdateManager; |
|
36 |
import sun.java2d.SurfaceData; |
|
37 |
import sun.java2d.loops.Blit; |
|
38 |
import sun.java2d.loops.CompositeType; |
|
2 | 39 |
import sun.java2d.loops.GraphicsPrimitive; |
40 |
import sun.java2d.loops.GraphicsPrimitiveMgr; |
|
887 | 41 |
import sun.java2d.loops.ScaledBlit; |
2 | 42 |
import sun.java2d.loops.SurfaceType; |
43 |
import sun.java2d.loops.TransformBlit; |
|
44 |
import sun.java2d.pipe.Region; |
|
887 | 45 |
import sun.java2d.pipe.RenderBuffer; |
46 |
import sun.java2d.pipe.RenderQueue; |
|
47 |
import static sun.java2d.pipe.BufferedOpCodes.*; |
|
48 |
import sun.java2d.windows.GDIWindowSurfaceData; |
|
2 | 49 |
|
887 | 50 |
class D3DBlitLoops { |
2 | 51 |
|
887 | 52 |
static void register() { |
53 |
Blit blitIntArgbPreToSurface = |
|
54 |
new D3DSwToSurfaceBlit(SurfaceType.IntArgbPre, |
|
55 |
D3DSurfaceData.ST_INT_ARGB_PRE); |
|
56 |
Blit blitIntArgbPreToTexture = |
|
57 |
new D3DSwToTextureBlit(SurfaceType.IntArgbPre, |
|
58 |
D3DSurfaceData.ST_INT_ARGB_PRE); |
|
2 | 59 |
|
60 |
GraphicsPrimitive[] primitives = { |
|
887 | 61 |
// prevent D3DSurface -> Screen blits |
62 |
new D3DSurfaceToGDIWindowSurfaceBlit(), |
|
63 |
new D3DSurfaceToGDIWindowSurfaceScale(), |
|
64 |
new D3DSurfaceToGDIWindowSurfaceTransform(), |
|
65 |
||
66 |
// surface->surface ops |
|
67 |
new D3DSurfaceToSurfaceBlit(), |
|
68 |
new D3DSurfaceToSurfaceScale(), |
|
69 |
new D3DSurfaceToSurfaceTransform(), |
|
70 |
||
71 |
// render-to-texture surface->surface ops |
|
72 |
new D3DRTTSurfaceToSurfaceBlit(), |
|
73 |
new D3DRTTSurfaceToSurfaceScale(), |
|
74 |
new D3DRTTSurfaceToSurfaceTransform(), |
|
75 |
||
76 |
// surface->sw ops |
|
77 |
new D3DSurfaceToSwBlit(SurfaceType.IntArgb, |
|
78 |
D3DSurfaceData.ST_INT_ARGB), |
|
79 |
||
80 |
// sw->surface ops |
|
81 |
blitIntArgbPreToSurface, |
|
82 |
new D3DSwToSurfaceBlit(SurfaceType.IntArgb, |
|
83 |
D3DSurfaceData.ST_INT_ARGB), |
|
84 |
new D3DSwToSurfaceBlit(SurfaceType.IntRgb, |
|
85 |
D3DSurfaceData.ST_INT_RGB), |
|
86 |
new D3DSwToSurfaceBlit(SurfaceType.IntBgr, |
|
87 |
D3DSurfaceData.ST_INT_BGR), |
|
1723
4a616c1eac0b
6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents:
887
diff
changeset
|
88 |
new D3DSwToSurfaceBlit(SurfaceType.ThreeByteBgr, |
4a616c1eac0b
6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents:
887
diff
changeset
|
89 |
D3DSurfaceData.ST_3BYTE_BGR), |
887 | 90 |
new D3DSwToSurfaceBlit(SurfaceType.Ushort565Rgb, |
91 |
D3DSurfaceData.ST_USHORT_565_RGB), |
|
92 |
new D3DSwToSurfaceBlit(SurfaceType.Ushort555Rgb, |
|
93 |
D3DSurfaceData.ST_USHORT_555_RGB), |
|
94 |
new D3DSwToSurfaceBlit(SurfaceType.ByteIndexed, |
|
95 |
D3DSurfaceData.ST_BYTE_INDEXED), |
|
96 |
// REMIND: we don't have a native sw loop to back this loop up |
|
97 |
// new D3DSwToSurfaceBlit(SurfaceType.ByteIndexedBm, |
|
98 |
// D3DSurfaceData.ST_BYTE_INDEXED_BM), |
|
99 |
new D3DGeneralBlit(D3DSurfaceData.D3DSurface, |
|
100 |
CompositeType.AnyAlpha, |
|
101 |
blitIntArgbPreToSurface), |
|
2 | 102 |
|
887 | 103 |
new D3DSwToSurfaceScale(SurfaceType.IntArgb, |
104 |
D3DSurfaceData.ST_INT_ARGB), |
|
105 |
new D3DSwToSurfaceScale(SurfaceType.IntArgbPre, |
|
106 |
D3DSurfaceData.ST_INT_ARGB_PRE), |
|
107 |
new D3DSwToSurfaceScale(SurfaceType.IntRgb, |
|
108 |
D3DSurfaceData.ST_INT_RGB), |
|
109 |
new D3DSwToSurfaceScale(SurfaceType.IntBgr, |
|
110 |
D3DSurfaceData.ST_INT_BGR), |
|
1723
4a616c1eac0b
6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents:
887
diff
changeset
|
111 |
new D3DSwToSurfaceScale(SurfaceType.ThreeByteBgr, |
4a616c1eac0b
6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents:
887
diff
changeset
|
112 |
D3DSurfaceData.ST_3BYTE_BGR), |
887 | 113 |
new D3DSwToSurfaceScale(SurfaceType.Ushort565Rgb, |
114 |
D3DSurfaceData.ST_USHORT_565_RGB), |
|
115 |
new D3DSwToSurfaceScale(SurfaceType.Ushort555Rgb, |
|
116 |
D3DSurfaceData.ST_USHORT_555_RGB), |
|
117 |
new D3DSwToSurfaceScale(SurfaceType.ByteIndexed, |
|
118 |
D3DSurfaceData.ST_BYTE_INDEXED), |
|
119 |
// REMIND: we don't have a native sw loop to back this loop up |
|
120 |
// new D3DSwToSurfaceScale(SurfaceType.ByteIndexedBm, |
|
121 |
// D3DSurfaceData.ST_BYTE_INDEXED_BM), |
|
2 | 122 |
|
887 | 123 |
new D3DSwToSurfaceTransform(SurfaceType.IntArgb, |
124 |
D3DSurfaceData.ST_INT_ARGB), |
|
125 |
new D3DSwToSurfaceTransform(SurfaceType.IntArgbPre, |
|
126 |
D3DSurfaceData.ST_INT_ARGB_PRE), |
|
127 |
new D3DSwToSurfaceTransform(SurfaceType.IntRgb, |
|
128 |
D3DSurfaceData.ST_INT_RGB), |
|
129 |
new D3DSwToSurfaceTransform(SurfaceType.IntBgr, |
|
130 |
D3DSurfaceData.ST_INT_BGR), |
|
1723
4a616c1eac0b
6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents:
887
diff
changeset
|
131 |
new D3DSwToSurfaceTransform(SurfaceType.ThreeByteBgr, |
4a616c1eac0b
6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents:
887
diff
changeset
|
132 |
D3DSurfaceData.ST_3BYTE_BGR), |
887 | 133 |
new D3DSwToSurfaceTransform(SurfaceType.Ushort565Rgb, |
134 |
D3DSurfaceData.ST_USHORT_565_RGB), |
|
135 |
new D3DSwToSurfaceTransform(SurfaceType.Ushort555Rgb, |
|
136 |
D3DSurfaceData.ST_USHORT_555_RGB), |
|
137 |
new D3DSwToSurfaceTransform(SurfaceType.ByteIndexed, |
|
138 |
D3DSurfaceData.ST_BYTE_INDEXED), |
|
139 |
// REMIND: we don't have a native sw loop to back this loop up |
|
140 |
// new D3DSwToSurfaceTransform(SurfaceType.ByteIndexedBm, |
|
141 |
// D3DSurfaceData.ST_BYTE_INDEXED_BM), |
|
2 | 142 |
|
887 | 143 |
// texture->surface ops |
144 |
new D3DTextureToSurfaceBlit(), |
|
145 |
new D3DTextureToSurfaceScale(), |
|
146 |
new D3DTextureToSurfaceTransform(), |
|
2 | 147 |
|
887 | 148 |
// sw->texture ops |
149 |
blitIntArgbPreToTexture, |
|
150 |
new D3DSwToTextureBlit(SurfaceType.IntRgb, |
|
151 |
D3DSurfaceData.ST_INT_RGB), |
|
152 |
new D3DSwToTextureBlit(SurfaceType.IntArgb, |
|
153 |
D3DSurfaceData.ST_INT_ARGB), |
|
154 |
new D3DSwToTextureBlit(SurfaceType.IntBgr, |
|
155 |
D3DSurfaceData.ST_INT_BGR), |
|
1723
4a616c1eac0b
6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents:
887
diff
changeset
|
156 |
new D3DSwToTextureBlit(SurfaceType.ThreeByteBgr, |
4a616c1eac0b
6739267: D3D/OGL: add missing ThreeByteBgr to texture upload blit loop
tdv
parents:
887
diff
changeset
|
157 |
D3DSurfaceData.ST_3BYTE_BGR), |
887 | 158 |
new D3DSwToTextureBlit(SurfaceType.Ushort565Rgb, |
159 |
D3DSurfaceData.ST_USHORT_565_RGB), |
|
160 |
new D3DSwToTextureBlit(SurfaceType.Ushort555Rgb, |
|
161 |
D3DSurfaceData.ST_USHORT_555_RGB), |
|
162 |
new D3DSwToTextureBlit(SurfaceType.ByteIndexed, |
|
163 |
D3DSurfaceData.ST_BYTE_INDEXED), |
|
164 |
// REMIND: we don't have a native sw loop to back this loop up |
|
165 |
// new D3DSwToTextureBlit(SurfaceType.ByteIndexedBm, |
|
166 |
// D3DSurfaceData.ST_BYTE_INDEXED_BM), |
|
167 |
new D3DGeneralBlit(D3DSurfaceData.D3DTexture, |
|
168 |
CompositeType.SrcNoEa, |
|
169 |
blitIntArgbPreToTexture), |
|
2 | 170 |
}; |
171 |
GraphicsPrimitiveMgr.register(primitives); |
|
172 |
} |
|
887 | 173 |
|
174 |
/** |
|
175 |
* The following offsets are used to pack the parameters in |
|
176 |
* createPackedParams(). (They are also used at the native level when |
|
177 |
* unpacking the params.) |
|
178 |
*/ |
|
179 |
private static final int OFFSET_SRCTYPE = 16; |
|
180 |
private static final int OFFSET_HINT = 8; |
|
181 |
private static final int OFFSET_TEXTURE = 3; |
|
182 |
private static final int OFFSET_RTT = 2; |
|
183 |
private static final int OFFSET_XFORM = 1; |
|
184 |
private static final int OFFSET_ISOBLIT = 0; |
|
185 |
||
186 |
/** |
|
187 |
* Packs the given parameters into a single int value in order to save |
|
188 |
* space on the rendering queue. |
|
189 |
*/ |
|
190 |
private static int createPackedParams(boolean isoblit, boolean texture, |
|
191 |
boolean rtt, boolean xform, |
|
192 |
int hint, int srctype) |
|
193 |
{ |
|
194 |
return |
|
195 |
((srctype << OFFSET_SRCTYPE) | |
|
196 |
(hint << OFFSET_HINT ) | |
|
197 |
((texture ? 1 : 0) << OFFSET_TEXTURE) | |
|
198 |
((rtt ? 1 : 0) << OFFSET_RTT ) | |
|
199 |
((xform ? 1 : 0) << OFFSET_XFORM ) | |
|
200 |
((isoblit ? 1 : 0) << OFFSET_ISOBLIT)); |
|
201 |
} |
|
2 | 202 |
|
887 | 203 |
/** |
204 |
* Enqueues a BLIT operation with the given parameters. Note that the |
|
205 |
* RenderQueue lock must be held before calling this method. |
|
206 |
*/ |
|
207 |
private static void enqueueBlit(RenderQueue rq, |
|
208 |
SurfaceData src, SurfaceData dst, |
|
209 |
int packedParams, |
|
210 |
int sx1, int sy1, |
|
211 |
int sx2, int sy2, |
|
212 |
double dx1, double dy1, |
|
213 |
double dx2, double dy2) |
|
2 | 214 |
{ |
887 | 215 |
// assert rq.lock.isHeldByCurrentThread(); |
216 |
RenderBuffer buf = rq.getBuffer(); |
|
217 |
rq.ensureCapacityAndAlignment(72, 24); |
|
218 |
buf.putInt(BLIT); |
|
219 |
buf.putInt(packedParams); |
|
220 |
buf.putInt(sx1).putInt(sy1); |
|
221 |
buf.putInt(sx2).putInt(sy2); |
|
222 |
buf.putDouble(dx1).putDouble(dy1); |
|
223 |
buf.putDouble(dx2).putDouble(dy2); |
|
224 |
buf.putLong(src.getNativeOps()); |
|
225 |
buf.putLong(dst.getNativeOps()); |
|
226 |
} |
|
227 |
||
228 |
static void Blit(SurfaceData srcData, SurfaceData dstData, |
|
229 |
Composite comp, Region clip, |
|
230 |
AffineTransform xform, int hint, |
|
231 |
int sx1, int sy1, |
|
232 |
int sx2, int sy2, |
|
233 |
double dx1, double dy1, |
|
234 |
double dx2, double dy2, |
|
235 |
int srctype, boolean texture) |
|
236 |
{ |
|
237 |
int ctxflags = 0; |
|
238 |
if (srcData.getTransparency() == Transparency.OPAQUE) { |
|
239 |
ctxflags |= D3DContext.SRC_IS_OPAQUE; |
|
2 | 240 |
} |
241 |
||
887 | 242 |
D3DSurfaceData d3dDst = (D3DSurfaceData)dstData; |
243 |
D3DRenderQueue rq = D3DRenderQueue.getInstance(); |
|
244 |
rq.lock(); |
|
245 |
try { |
|
246 |
// make sure the RenderQueue keeps a hard reference to the |
|
247 |
// source (sysmem) SurfaceData to prevent it from being |
|
248 |
// disposed while the operation is processed on the QFT |
|
249 |
rq.addReference(srcData); |
|
250 |
||
251 |
if (texture) { |
|
252 |
// make sure we have a current context before uploading |
|
253 |
// the sysmem data to the texture object |
|
254 |
D3DContext.setScratchSurface(d3dDst.getContext()); |
|
255 |
} else { |
|
256 |
D3DContext.validateContext(d3dDst, d3dDst, |
|
257 |
clip, comp, xform, null, null, |
|
258 |
ctxflags); |
|
259 |
} |
|
260 |
||
261 |
int packedParams = createPackedParams(false, texture, |
|
262 |
false, xform != null, |
|
263 |
hint, srctype); |
|
264 |
enqueueBlit(rq, srcData, dstData, |
|
265 |
packedParams, |
|
266 |
sx1, sy1, sx2, sy2, |
|
267 |
dx1, dy1, dx2, dy2); |
|
268 |
||
269 |
// always flush immediately, since we (currently) have no means |
|
270 |
// of tracking changes to the system memory surface |
|
271 |
rq.flushNow(); |
|
272 |
} finally { |
|
273 |
rq.unlock(); |
|
274 |
} |
|
275 |
||
276 |
if (d3dDst.getType() == D3DSurfaceData.WINDOW) { |
|
277 |
// flush immediately when copying to the screen to improve |
|
278 |
// responsiveness of applications using VI or BI backbuffers |
|
279 |
D3DScreenUpdateManager mgr = |
|
280 |
(D3DScreenUpdateManager)ScreenUpdateManager.getInstance(); |
|
281 |
mgr.runUpdateNow(); |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
/** |
|
286 |
* Note: The srcImg and biop parameters are only used when invoked |
|
287 |
* from the D3DBufImgOps.renderImageWithOp() method; in all other cases, |
|
288 |
* this method can be called with null values for those two parameters, |
|
289 |
* and they will be effectively ignored. |
|
290 |
*/ |
|
291 |
static void IsoBlit(SurfaceData srcData, SurfaceData dstData, |
|
292 |
BufferedImage srcImg, BufferedImageOp biop, |
|
293 |
Composite comp, Region clip, |
|
294 |
AffineTransform xform, int hint, |
|
295 |
int sx1, int sy1, |
|
296 |
int sx2, int sy2, |
|
297 |
double dx1, double dy1, |
|
298 |
double dx2, double dy2, |
|
299 |
boolean texture) |
|
300 |
{ |
|
301 |
int ctxflags = 0; |
|
302 |
if (srcData.getTransparency() == Transparency.OPAQUE) { |
|
303 |
ctxflags |= D3DContext.SRC_IS_OPAQUE; |
|
304 |
} |
|
305 |
||
306 |
D3DSurfaceData d3dDst = (D3DSurfaceData)dstData; |
|
307 |
D3DRenderQueue rq = D3DRenderQueue.getInstance(); |
|
308 |
boolean rtt = false; |
|
309 |
rq.lock(); |
|
310 |
try { |
|
311 |
D3DSurfaceData d3dSrc = (D3DSurfaceData)srcData; |
|
312 |
int srctype = d3dSrc.getType(); |
|
313 |
D3DSurfaceData srcCtxData = d3dSrc; |
|
314 |
if (srctype == D3DSurfaceData.TEXTURE) { |
|
315 |
rtt = false; |
|
316 |
} else { |
|
317 |
// the source is a backbuffer, or render-to-texture |
|
318 |
// surface; we set rtt to true to differentiate this kind |
|
319 |
// of surface from a regular texture object |
|
320 |
rtt = true; |
|
321 |
} |
|
322 |
||
323 |
D3DContext.validateContext(srcCtxData, d3dDst, |
|
324 |
clip, comp, xform, null, null, |
|
325 |
ctxflags); |
|
326 |
||
327 |
if (biop != null) { |
|
328 |
D3DBufImgOps.enableBufImgOp(rq, d3dSrc, srcImg, biop); |
|
329 |
} |
|
330 |
||
331 |
int packedParams = createPackedParams(true, texture, |
|
332 |
rtt, xform != null, |
|
333 |
hint, 0 /*unused*/); |
|
334 |
enqueueBlit(rq, srcData, dstData, |
|
335 |
packedParams, |
|
336 |
sx1, sy1, sx2, sy2, |
|
337 |
dx1, dy1, dx2, dy2); |
|
338 |
||
339 |
if (biop != null) { |
|
340 |
D3DBufImgOps.disableBufImgOp(rq, biop); |
|
341 |
} |
|
342 |
} finally { |
|
343 |
rq.unlock(); |
|
344 |
} |
|
345 |
||
346 |
if (rtt && (d3dDst.getType() == D3DSurfaceData.WINDOW)) { |
|
347 |
// we only have to flush immediately when copying from a |
|
348 |
// (non-texture) surface to the screen; otherwise Swing apps |
|
349 |
// might appear unresponsive until the auto-flush completes |
|
350 |
D3DScreenUpdateManager mgr = |
|
351 |
(D3DScreenUpdateManager)ScreenUpdateManager.getInstance(); |
|
352 |
mgr.runUpdateNow(); |
|
353 |
} |
|
2 | 354 |
} |
355 |
} |
|
356 |
||
887 | 357 |
class D3DSurfaceToSurfaceBlit extends Blit { |
358 |
||
359 |
D3DSurfaceToSurfaceBlit() { |
|
360 |
super(D3DSurfaceData.D3DSurface, |
|
361 |
CompositeType.AnyAlpha, |
|
362 |
D3DSurfaceData.D3DSurface); |
|
2 | 363 |
} |
364 |
||
365 |
public void Blit(SurfaceData src, SurfaceData dst, |
|
366 |
Composite comp, Region clip, |
|
367 |
int sx, int sy, int dx, int dy, int w, int h) |
|
368 |
{ |
|
887 | 369 |
D3DBlitLoops.IsoBlit(src, dst, |
370 |
null, null, |
|
371 |
comp, clip, null, |
|
372 |
AffineTransformOp.TYPE_NEAREST_NEIGHBOR, |
|
373 |
sx, sy, sx+w, sy+h, |
|
374 |
dx, dy, dx+w, dy+h, |
|
375 |
false); |
|
2 | 376 |
} |
377 |
} |
|
378 |
||
887 | 379 |
class D3DSurfaceToSurfaceScale extends ScaledBlit { |
2 | 380 |
|
887 | 381 |
D3DSurfaceToSurfaceScale() { |
382 |
super(D3DSurfaceData.D3DSurface, |
|
383 |
CompositeType.AnyAlpha, |
|
384 |
D3DSurfaceData.D3DSurface); |
|
2 | 385 |
} |
386 |
||
887 | 387 |
public void Scale(SurfaceData src, SurfaceData dst, |
388 |
Composite comp, Region clip, |
|
389 |
int sx1, int sy1, |
|
390 |
int sx2, int sy2, |
|
391 |
double dx1, double dy1, |
|
392 |
double dx2, double dy2) |
|
393 |
{ |
|
394 |
D3DBlitLoops.IsoBlit(src, dst, |
|
395 |
null, null, |
|
396 |
comp, clip, null, |
|
397 |
AffineTransformOp.TYPE_NEAREST_NEIGHBOR, |
|
398 |
sx1, sy1, sx2, sy2, |
|
399 |
dx1, dy1, dx2, dy2, |
|
400 |
false); |
|
401 |
} |
|
402 |
} |
|
403 |
||
404 |
class D3DSurfaceToSurfaceTransform extends TransformBlit { |
|
405 |
||
406 |
D3DSurfaceToSurfaceTransform() { |
|
407 |
super(D3DSurfaceData.D3DSurface, |
|
408 |
CompositeType.AnyAlpha, |
|
409 |
D3DSurfaceData.D3DSurface); |
|
410 |
} |
|
411 |
||
2 | 412 |
public void Transform(SurfaceData src, SurfaceData dst, |
413 |
Composite comp, Region clip, |
|
414 |
AffineTransform at, int hint, |
|
415 |
int sx, int sy, int dx, int dy, |
|
416 |
int w, int h) |
|
417 |
{ |
|
887 | 418 |
D3DBlitLoops.IsoBlit(src, dst, |
419 |
null, null, |
|
420 |
comp, clip, at, hint, |
|
421 |
sx, sy, sx+w, sy+h, |
|
422 |
dx, dy, dx+w, dy+h, |
|
423 |
false); |
|
424 |
} |
|
425 |
} |
|
426 |
||
427 |
class D3DRTTSurfaceToSurfaceBlit extends Blit { |
|
428 |
||
429 |
D3DRTTSurfaceToSurfaceBlit() { |
|
430 |
super(D3DSurfaceData.D3DSurfaceRTT, |
|
431 |
CompositeType.AnyAlpha, |
|
432 |
D3DSurfaceData.D3DSurface); |
|
433 |
} |
|
434 |
||
435 |
public void Blit(SurfaceData src, SurfaceData dst, |
|
436 |
Composite comp, Region clip, |
|
437 |
int sx, int sy, int dx, int dy, int w, int h) |
|
438 |
{ |
|
439 |
D3DBlitLoops.IsoBlit(src, dst, |
|
440 |
null, null, |
|
441 |
comp, clip, null, |
|
442 |
AffineTransformOp.TYPE_NEAREST_NEIGHBOR, |
|
443 |
sx, sy, sx+w, sy+h, |
|
444 |
dx, dy, dx+w, dy+h, |
|
445 |
true); |
|
446 |
} |
|
447 |
} |
|
448 |
||
449 |
class D3DRTTSurfaceToSurfaceScale extends ScaledBlit { |
|
450 |
||
451 |
D3DRTTSurfaceToSurfaceScale() { |
|
452 |
super(D3DSurfaceData.D3DSurfaceRTT, |
|
453 |
CompositeType.AnyAlpha, |
|
454 |
D3DSurfaceData.D3DSurface); |
|
455 |
} |
|
456 |
||
457 |
public void Scale(SurfaceData src, SurfaceData dst, |
|
458 |
Composite comp, Region clip, |
|
459 |
int sx1, int sy1, |
|
460 |
int sx2, int sy2, |
|
461 |
double dx1, double dy1, |
|
462 |
double dx2, double dy2) |
|
463 |
{ |
|
464 |
D3DBlitLoops.IsoBlit(src, dst, |
|
465 |
null, null, |
|
466 |
comp, clip, null, |
|
467 |
AffineTransformOp.TYPE_NEAREST_NEIGHBOR, |
|
468 |
sx1, sy1, sx2, sy2, |
|
469 |
dx1, dy1, dx2, dy2, |
|
470 |
true); |
|
471 |
} |
|
472 |
} |
|
473 |
||
474 |
class D3DRTTSurfaceToSurfaceTransform extends TransformBlit { |
|
475 |
||
476 |
D3DRTTSurfaceToSurfaceTransform() { |
|
477 |
super(D3DSurfaceData.D3DSurfaceRTT, |
|
478 |
CompositeType.AnyAlpha, |
|
479 |
D3DSurfaceData.D3DSurface); |
|
480 |
} |
|
481 |
||
482 |
public void Transform(SurfaceData src, SurfaceData dst, |
|
483 |
Composite comp, Region clip, |
|
484 |
AffineTransform at, int hint, |
|
485 |
int sx, int sy, int dx, int dy, int w, int h) |
|
486 |
{ |
|
487 |
D3DBlitLoops.IsoBlit(src, dst, |
|
488 |
null, null, |
|
489 |
comp, clip, at, hint, |
|
490 |
sx, sy, sx+w, sy+h, |
|
491 |
dx, dy, dx+w, dy+h, |
|
492 |
true); |
|
493 |
} |
|
494 |
} |
|
495 |
||
496 |
class D3DSurfaceToSwBlit extends Blit { |
|
497 |
||
498 |
private int typeval; |
|
499 |
||
500 |
// REMIND: destination will actually be opaque/premultiplied... |
|
501 |
D3DSurfaceToSwBlit(SurfaceType dstType, int typeval) { |
|
502 |
super(D3DSurfaceData.D3DSurface, |
|
503 |
CompositeType.SrcNoEa, |
|
504 |
dstType); |
|
505 |
this.typeval = typeval; |
|
506 |
} |
|
507 |
||
508 |
public void Blit(SurfaceData src, SurfaceData dst, |
|
509 |
Composite comp, Region clip, |
|
510 |
int sx, int sy, int dx, int dy, |
|
511 |
int w, int h) |
|
512 |
{ |
|
513 |
D3DRenderQueue rq = D3DRenderQueue.getInstance(); |
|
514 |
rq.lock(); |
|
515 |
try { |
|
516 |
// make sure the RenderQueue keeps a hard reference to the |
|
517 |
// destination (sysmem) SurfaceData to prevent it from being |
|
518 |
// disposed while the operation is processed on the QFT |
|
519 |
rq.addReference(dst); |
|
520 |
||
521 |
RenderBuffer buf = rq.getBuffer(); |
|
522 |
D3DContext.setScratchSurface(((D3DSurfaceData)src).getContext()); |
|
523 |
||
524 |
rq.ensureCapacityAndAlignment(48, 32); |
|
525 |
buf.putInt(SURFACE_TO_SW_BLIT); |
|
526 |
buf.putInt(sx).putInt(sy); |
|
527 |
buf.putInt(dx).putInt(dy); |
|
528 |
buf.putInt(w).putInt(h); |
|
529 |
buf.putInt(typeval); |
|
530 |
buf.putLong(src.getNativeOps()); |
|
531 |
buf.putLong(dst.getNativeOps()); |
|
532 |
||
533 |
// always flush immediately |
|
534 |
rq.flushNow(); |
|
535 |
} finally { |
|
536 |
rq.unlock(); |
|
2 | 537 |
} |
538 |
} |
|
539 |
} |
|
540 |
||
887 | 541 |
class D3DSwToSurfaceBlit extends Blit { |
542 |
||
543 |
private int typeval; |
|
544 |
||
545 |
D3DSwToSurfaceBlit(SurfaceType srcType, int typeval) { |
|
546 |
super(srcType, |
|
547 |
CompositeType.AnyAlpha, |
|
548 |
D3DSurfaceData.D3DSurface); |
|
549 |
this.typeval = typeval; |
|
550 |
} |
|
551 |
||
552 |
public void Blit(SurfaceData src, SurfaceData dst, |
|
553 |
Composite comp, Region clip, |
|
554 |
int sx, int sy, int dx, int dy, int w, int h) |
|
555 |
{ |
|
556 |
D3DBlitLoops.Blit(src, dst, |
|
557 |
comp, clip, null, |
|
558 |
AffineTransformOp.TYPE_NEAREST_NEIGHBOR, |
|
559 |
sx, sy, sx+w, sy+h, |
|
560 |
dx, dy, dx+w, dy+h, |
|
561 |
typeval, false); |
|
562 |
} |
|
563 |
} |
|
564 |
||
565 |
class D3DSwToSurfaceScale extends ScaledBlit { |
|
566 |
||
567 |
private int typeval; |
|
568 |
||
569 |
D3DSwToSurfaceScale(SurfaceType srcType, int typeval) { |
|
570 |
super(srcType, |
|
571 |
CompositeType.AnyAlpha, |
|
572 |
D3DSurfaceData.D3DSurface); |
|
573 |
this.typeval = typeval; |
|
574 |
} |
|
575 |
||
576 |
public void Scale(SurfaceData src, SurfaceData dst, |
|
577 |
Composite comp, Region clip, |
|
578 |
int sx1, int sy1, |
|
579 |
int sx2, int sy2, |
|
580 |
double dx1, double dy1, |
|
581 |
double dx2, double dy2) |
|
582 |
{ |
|
583 |
D3DBlitLoops.Blit(src, dst, |
|
584 |
comp, clip, null, |
|
585 |
AffineTransformOp.TYPE_NEAREST_NEIGHBOR, |
|
586 |
sx1, sy1, sx2, sy2, |
|
587 |
dx1, dy1, dx2, dy2, |
|
588 |
typeval, false); |
|
589 |
} |
|
590 |
} |
|
591 |
||
592 |
class D3DSwToSurfaceTransform extends TransformBlit { |
|
593 |
||
594 |
private int typeval; |
|
595 |
||
596 |
D3DSwToSurfaceTransform(SurfaceType srcType, int typeval) { |
|
597 |
super(srcType, |
|
598 |
CompositeType.AnyAlpha, |
|
599 |
D3DSurfaceData.D3DSurface); |
|
600 |
this.typeval = typeval; |
|
601 |
} |
|
602 |
||
603 |
public void Transform(SurfaceData src, SurfaceData dst, |
|
604 |
Composite comp, Region clip, |
|
605 |
AffineTransform at, int hint, |
|
606 |
int sx, int sy, int dx, int dy, int w, int h) |
|
607 |
{ |
|
608 |
D3DBlitLoops.Blit(src, dst, |
|
609 |
comp, clip, at, hint, |
|
610 |
sx, sy, sx+w, sy+h, |
|
611 |
dx, dy, dx+w, dy+h, |
|
612 |
typeval, false); |
|
613 |
} |
|
614 |
} |
|
615 |
||
616 |
class D3DSwToTextureBlit extends Blit { |
|
617 |
||
618 |
private int typeval; |
|
619 |
||
620 |
D3DSwToTextureBlit(SurfaceType srcType, int typeval) { |
|
621 |
super(srcType, |
|
622 |
CompositeType.SrcNoEa, |
|
623 |
D3DSurfaceData.D3DTexture); |
|
624 |
this.typeval = typeval; |
|
625 |
} |
|
626 |
||
627 |
public void Blit(SurfaceData src, SurfaceData dst, |
|
628 |
Composite comp, Region clip, |
|
629 |
int sx, int sy, int dx, int dy, int w, int h) |
|
630 |
{ |
|
631 |
D3DBlitLoops.Blit(src, dst, |
|
632 |
comp, clip, null, |
|
633 |
AffineTransformOp.TYPE_NEAREST_NEIGHBOR, |
|
634 |
sx, sy, sx+w, sy+h, |
|
635 |
dx, dy, dx+w, dy+h, |
|
636 |
typeval, true); |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
class D3DTextureToSurfaceBlit extends Blit { |
|
641 |
||
642 |
D3DTextureToSurfaceBlit() { |
|
643 |
super(D3DSurfaceData.D3DTexture, |
|
644 |
CompositeType.AnyAlpha, |
|
645 |
D3DSurfaceData.D3DSurface); |
|
646 |
} |
|
647 |
||
648 |
public void Blit(SurfaceData src, SurfaceData dst, |
|
649 |
Composite comp, Region clip, |
|
650 |
int sx, int sy, int dx, int dy, int w, int h) |
|
651 |
{ |
|
652 |
D3DBlitLoops.IsoBlit(src, dst, |
|
653 |
null, null, |
|
654 |
comp, clip, null, |
|
655 |
AffineTransformOp.TYPE_NEAREST_NEIGHBOR, |
|
656 |
sx, sy, sx+w, sy+h, |
|
657 |
dx, dy, dx+w, dy+h, |
|
658 |
true); |
|
659 |
} |
|
660 |
} |
|
661 |
||
2 | 662 |
class D3DTextureToSurfaceScale extends ScaledBlit { |
663 |
||
887 | 664 |
D3DTextureToSurfaceScale() { |
665 |
super(D3DSurfaceData.D3DTexture, |
|
666 |
CompositeType.AnyAlpha, |
|
667 |
D3DSurfaceData.D3DSurface); |
|
668 |
} |
|
669 |
||
670 |
public void Scale(SurfaceData src, SurfaceData dst, |
|
671 |
Composite comp, Region clip, |
|
672 |
int sx1, int sy1, |
|
673 |
int sx2, int sy2, |
|
674 |
double dx1, double dy1, |
|
675 |
double dx2, double dy2) |
|
676 |
{ |
|
677 |
D3DBlitLoops.IsoBlit(src, dst, |
|
678 |
null, null, |
|
679 |
comp, clip, null, |
|
680 |
AffineTransformOp.TYPE_NEAREST_NEIGHBOR, |
|
681 |
sx1, sy1, sx2, sy2, |
|
682 |
dx1, dy1, dx2, dy2, |
|
683 |
true); |
|
684 |
} |
|
685 |
} |
|
686 |
||
687 |
class D3DTextureToSurfaceTransform extends TransformBlit { |
|
688 |
||
689 |
D3DTextureToSurfaceTransform() { |
|
690 |
super(D3DSurfaceData.D3DTexture, |
|
691 |
CompositeType.AnyAlpha, |
|
692 |
D3DSurfaceData.D3DSurface); |
|
693 |
} |
|
694 |
||
695 |
public void Transform(SurfaceData src, SurfaceData dst, |
|
696 |
Composite comp, Region clip, |
|
697 |
AffineTransform at, int hint, |
|
698 |
int sx, int sy, int dx, int dy, |
|
699 |
int w, int h) |
|
700 |
{ |
|
701 |
D3DBlitLoops.IsoBlit(src, dst, |
|
702 |
null, null, |
|
703 |
comp, clip, at, hint, |
|
704 |
sx, sy, sx+w, sy+h, |
|
705 |
dx, dy, dx+w, dy+h, |
|
706 |
true); |
|
707 |
} |
|
708 |
} |
|
709 |
||
710 |
/** |
|
711 |
* This general Blit implemenation converts any source surface to an |
|
712 |
* intermediate IntArgbPre surface, and then uses the more specific |
|
713 |
* IntArgbPre->D3DSurface/Texture loop to get the intermediate |
|
714 |
* (premultiplied) surface down to D3D. |
|
715 |
*/ |
|
716 |
class D3DGeneralBlit extends Blit { |
|
717 |
||
718 |
private Blit performop; |
|
719 |
private WeakReference srcTmp; |
|
720 |
||
721 |
D3DGeneralBlit(SurfaceType dstType, |
|
722 |
CompositeType compType, |
|
723 |
Blit performop) |
|
724 |
{ |
|
725 |
super(SurfaceType.Any, compType, dstType); |
|
726 |
this.performop = performop; |
|
2 | 727 |
} |
728 |
||
887 | 729 |
public synchronized void Blit(SurfaceData src, SurfaceData dst, |
730 |
Composite comp, Region clip, |
|
731 |
int sx, int sy, int dx, int dy, |
|
732 |
int w, int h) |
|
733 |
{ |
|
734 |
Blit convertsrc = Blit.getFromCache(src.getSurfaceType(), |
|
735 |
CompositeType.SrcNoEa, |
|
736 |
SurfaceType.IntArgbPre); |
|
737 |
||
738 |
SurfaceData cachedSrc = null; |
|
739 |
if (srcTmp != null) { |
|
740 |
// use cached intermediate surface, if available |
|
741 |
cachedSrc = (SurfaceData)srcTmp.get(); |
|
742 |
} |
|
743 |
||
744 |
// convert source to IntArgbPre |
|
745 |
src = convertFrom(convertsrc, src, sx, sy, w, h, |
|
746 |
cachedSrc, BufferedImage.TYPE_INT_ARGB_PRE); |
|
747 |
||
748 |
// copy IntArgbPre intermediate surface to D3D surface |
|
749 |
performop.Blit(src, dst, comp, clip, |
|
750 |
0, 0, dx, dy, w, h); |
|
751 |
||
752 |
if (src != cachedSrc) { |
|
753 |
// cache the intermediate surface |
|
754 |
srcTmp = new WeakReference(src); |
|
755 |
} |
|
756 |
} |
|
757 |
} |
|
758 |
||
759 |
/* |
|
760 |
* The following classes prohibit copying D3DSurfaces to the screen |
|
761 |
* (the D3D->sysmem->GDI path is known to be very very slow). |
|
762 |
* |
|
763 |
* Note: we used to disable hw acceleration for the surafce manager associated |
|
764 |
* with the source surface in these loops but it proved to be too cautious. |
|
765 |
* |
|
766 |
* In most cases d3d->screen copy happens only during some transitional |
|
767 |
* period where the accelerated destination surface is being recreated or |
|
768 |
* restored (for example, when Swing's backbuffer VI is copied to the screen |
|
769 |
* but the D3DScreenSurfaceManager couldn't restore its surface). |
|
770 |
* |
|
771 |
* An exception is if for some reason we could not enable accelerated on-screen |
|
772 |
* rendering for this window for some permanent reason (like window being too |
|
773 |
* small, or a present BufferStrategy). |
|
774 |
* |
|
775 |
* This meant that we'd disable hw acceleration after the first failure |
|
776 |
* completely (at least until the src image is recreated which in case of |
|
777 |
* Swing back-buffer happens only after resize). |
|
778 |
* |
|
779 |
* Now we delegate to the VISM to figure out if the acceleration needs to |
|
780 |
* be disabled or if we can wait for a while until the onscreen accelerated |
|
781 |
* can resume (by marking the source surface lost and making sure the |
|
782 |
* VISM has a chance to use the backup surface). |
|
783 |
* |
|
784 |
*/ |
|
785 |
||
786 |
class D3DSurfaceToGDIWindowSurfaceBlit extends Blit { |
|
787 |
||
788 |
D3DSurfaceToGDIWindowSurfaceBlit() { |
|
789 |
super(D3DSurfaceData.D3DSurface, |
|
790 |
CompositeType.AnyAlpha, |
|
791 |
GDIWindowSurfaceData.AnyGdi); |
|
792 |
} |
|
793 |
@Override |
|
794 |
public void Blit(SurfaceData src, SurfaceData dst, |
|
795 |
Composite comp, Region clip, |
|
796 |
int sx, int sy, int dx, int dy, int w, int h) |
|
797 |
{ |
|
798 |
// see comment above |
|
799 |
D3DVolatileSurfaceManager.handleVItoScreenOp(src, dst); |
|
800 |
} |
|
801 |
||
802 |
} |
|
803 |
||
804 |
class D3DSurfaceToGDIWindowSurfaceScale extends ScaledBlit { |
|
805 |
||
806 |
D3DSurfaceToGDIWindowSurfaceScale() { |
|
807 |
super(D3DSurfaceData.D3DSurface, |
|
808 |
CompositeType.AnyAlpha, |
|
809 |
GDIWindowSurfaceData.AnyGdi); |
|
810 |
} |
|
2 | 811 |
@Override |
812 |
public void Scale(SurfaceData src, SurfaceData dst, |
|
813 |
Composite comp, Region clip, |
|
814 |
int sx1, int sy1, |
|
815 |
int sx2, int sy2, |
|
816 |
double dx1, double dy1, |
|
817 |
double dx2, double dy2) |
|
818 |
{ |
|
887 | 819 |
// see comment above |
820 |
D3DVolatileSurfaceManager.handleVItoScreenOp(src, dst); |
|
2 | 821 |
} |
822 |
} |
|
823 |
||
887 | 824 |
class D3DSurfaceToGDIWindowSurfaceTransform extends TransformBlit { |
2 | 825 |
|
887 | 826 |
D3DSurfaceToGDIWindowSurfaceTransform() { |
827 |
super(D3DSurfaceData.D3DSurface, |
|
828 |
CompositeType.AnyAlpha, |
|
829 |
GDIWindowSurfaceData.AnyGdi); |
|
2 | 830 |
} |
831 |
@Override |
|
887 | 832 |
public void Transform(SurfaceData src, SurfaceData dst, |
833 |
Composite comp, Region clip, |
|
834 |
AffineTransform at, int hint, |
|
835 |
int sx, int sy, int dx, int dy, |
|
836 |
int w, int h) |
|
2 | 837 |
{ |
887 | 838 |
// see comment above |
839 |
D3DVolatileSurfaceManager.handleVItoScreenOp(src, dst); |
|
2 | 840 |
} |
841 |
} |