Showing the changes to java/pkg/sun/java2d/opengl/OGLBlitLoops.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,762 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2003, 2007, Oracle and/or its affiliates. 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. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle 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 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. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package sun.java2d.opengl; | |
| 27 | + | |
| 28 | +import java.awt.Composite; | |
| 29 | +import java.awt.Transparency; | |
| 30 | +import java.awt.geom.AffineTransform; | |
| 31 | +import java.awt.image.AffineTransformOp; | |
| 32 | +import java.awt.image.BufferedImage; | |
| 33 | +import java.awt.image.BufferedImageOp; | |
| 34 | +import java.lang.ref.WeakReference; | |
| 35 | +import sun.java2d.SurfaceData; | |
| 36 | +import sun.java2d.loops.Blit; | |
| 37 | +import sun.java2d.loops.CompositeType; | |
| 38 | +import sun.java2d.loops.GraphicsPrimitive; | |
| 39 | +import sun.java2d.loops.GraphicsPrimitiveMgr; | |
| 40 | +import sun.java2d.loops.ScaledBlit; | |
| 41 | +import sun.java2d.loops.SurfaceType; | |
| 42 | +import sun.java2d.loops.TransformBlit; | |
| 43 | +import sun.java2d.pipe.Region; | |
| 44 | +import sun.java2d.pipe.RenderBuffer; | |
| 45 | +import sun.java2d.pipe.RenderQueue; | |
| 46 | +import static sun.java2d.pipe.BufferedOpCodes.*; | |
| 47 | + | |
| 48 | +class OGLBlitLoops { | |
| 49 | + | |
| 50 | + static void register() { | |
| 51 | + Blit blitIntArgbPreToSurface = | |
| 52 | + new OGLSwToSurfaceBlit(SurfaceType.IntArgbPre, | |
| 53 | + OGLSurfaceData.PF_INT_ARGB_PRE); | |
| 54 | + Blit blitIntArgbPreToTexture = | |
| 55 | + new OGLSwToTextureBlit(SurfaceType.IntArgbPre, | |
| 56 | + OGLSurfaceData.PF_INT_ARGB_PRE); | |
| 57 | + | |
| 58 | + GraphicsPrimitive[] primitives = { | |
| 59 | + // surface->surface ops | |
| 60 | + new OGLSurfaceToSurfaceBlit(), | |
| 61 | + new OGLSurfaceToSurfaceScale(), | |
| 62 | + new OGLSurfaceToSurfaceTransform(), | |
| 63 | + | |
| 64 | + // render-to-texture surface->surface ops | |
| 65 | + new OGLRTTSurfaceToSurfaceBlit(), | |
| 66 | + new OGLRTTSurfaceToSurfaceScale(), | |
| 67 | + new OGLRTTSurfaceToSurfaceTransform(), | |
| 68 | + | |
| 69 | + // surface->sw ops | |
| 70 | + new OGLSurfaceToSwBlit(SurfaceType.IntArgb, | |
| 71 | + OGLSurfaceData.PF_INT_ARGB), | |
| 72 | + | |
| 73 | + // sw->surface ops | |
| 74 | + blitIntArgbPreToSurface, | |
| 75 | + new OGLSwToSurfaceBlit(SurfaceType.IntRgb, | |
| 76 | + OGLSurfaceData.PF_INT_RGB), | |
| 77 | + new OGLSwToSurfaceBlit(SurfaceType.IntRgbx, | |
| 78 | + OGLSurfaceData.PF_INT_RGBX), | |
| 79 | + new OGLSwToSurfaceBlit(SurfaceType.IntBgr, | |
| 80 | + OGLSurfaceData.PF_INT_BGR), | |
| 81 | + new OGLSwToSurfaceBlit(SurfaceType.IntBgrx, | |
| 82 | + OGLSurfaceData.PF_INT_BGRX), | |
| 83 | + new OGLSwToSurfaceBlit(SurfaceType.ThreeByteBgr, | |
| 84 | + OGLSurfaceData.PF_3BYTE_BGR), | |
| 85 | + new OGLSwToSurfaceBlit(SurfaceType.Ushort565Rgb, | |
| 86 | + OGLSurfaceData.PF_USHORT_565_RGB), | |
| 87 | + new OGLSwToSurfaceBlit(SurfaceType.Ushort555Rgb, | |
| 88 | + OGLSurfaceData.PF_USHORT_555_RGB), | |
| 89 | + new OGLSwToSurfaceBlit(SurfaceType.Ushort555Rgbx, | |
| 90 | + OGLSurfaceData.PF_USHORT_555_RGBX), | |
| 91 | + new OGLSwToSurfaceBlit(SurfaceType.ByteGray, | |
| 92 | + OGLSurfaceData.PF_BYTE_GRAY), | |
| 93 | + new OGLSwToSurfaceBlit(SurfaceType.UshortGray, | |
| 94 | + OGLSurfaceData.PF_USHORT_GRAY), | |
| 95 | + new OGLGeneralBlit(OGLSurfaceData.OpenGLSurface, | |
| 96 | + CompositeType.AnyAlpha, | |
| 97 | + blitIntArgbPreToSurface), | |
| 98 | + | |
| 99 | + new OGLSwToSurfaceScale(SurfaceType.IntRgb, | |
| 100 | + OGLSurfaceData.PF_INT_RGB), | |
| 101 | + new OGLSwToSurfaceScale(SurfaceType.IntRgbx, | |
| 102 | + OGLSurfaceData.PF_INT_RGBX), | |
| 103 | + new OGLSwToSurfaceScale(SurfaceType.IntBgr, | |
| 104 | + OGLSurfaceData.PF_INT_BGR), | |
| 105 | + new OGLSwToSurfaceScale(SurfaceType.IntBgrx, | |
| 106 | + OGLSurfaceData.PF_INT_BGRX), | |
| 107 | + new OGLSwToSurfaceScale(SurfaceType.ThreeByteBgr, | |
| 108 | + OGLSurfaceData.PF_3BYTE_BGR), | |
| 109 | + new OGLSwToSurfaceScale(SurfaceType.Ushort565Rgb, | |
| 110 | + OGLSurfaceData.PF_USHORT_565_RGB), | |
| 111 | + new OGLSwToSurfaceScale(SurfaceType.Ushort555Rgb, | |
| 112 | + OGLSurfaceData.PF_USHORT_555_RGB), | |
| 113 | + new OGLSwToSurfaceScale(SurfaceType.Ushort555Rgbx, | |
| 114 | + OGLSurfaceData.PF_USHORT_555_RGBX), | |
| 115 | + new OGLSwToSurfaceScale(SurfaceType.ByteGray, | |
| 116 | + OGLSurfaceData.PF_BYTE_GRAY), | |
| 117 | + new OGLSwToSurfaceScale(SurfaceType.UshortGray, | |
| 118 | + OGLSurfaceData.PF_USHORT_GRAY), | |
| 119 | + new OGLSwToSurfaceScale(SurfaceType.IntArgbPre, | |
| 120 | + OGLSurfaceData.PF_INT_ARGB_PRE), | |
| 121 | + | |
| 122 | + new OGLSwToSurfaceTransform(SurfaceType.IntRgb, | |
| 123 | + OGLSurfaceData.PF_INT_RGB), | |
| 124 | + new OGLSwToSurfaceTransform(SurfaceType.IntRgbx, | |
| 125 | + OGLSurfaceData.PF_INT_RGBX), | |
| 126 | + new OGLSwToSurfaceTransform(SurfaceType.IntBgr, | |
| 127 | + OGLSurfaceData.PF_INT_BGR), | |
| 128 | + new OGLSwToSurfaceTransform(SurfaceType.IntBgrx, | |
| 129 | + OGLSurfaceData.PF_INT_BGRX), | |
| 130 | + new OGLSwToSurfaceTransform(SurfaceType.ThreeByteBgr, | |
| 131 | + OGLSurfaceData.PF_3BYTE_BGR), | |
| 132 | + new OGLSwToSurfaceTransform(SurfaceType.Ushort565Rgb, | |
| 133 | + OGLSurfaceData.PF_USHORT_565_RGB), | |
| 134 | + new OGLSwToSurfaceTransform(SurfaceType.Ushort555Rgb, | |
| 135 | + OGLSurfaceData.PF_USHORT_555_RGB), | |
| 136 | + new OGLSwToSurfaceTransform(SurfaceType.Ushort555Rgbx, | |
| 137 | + OGLSurfaceData.PF_USHORT_555_RGBX), | |
| 138 | + new OGLSwToSurfaceTransform(SurfaceType.ByteGray, | |
| 139 | + OGLSurfaceData.PF_BYTE_GRAY), | |
| 140 | + new OGLSwToSurfaceTransform(SurfaceType.UshortGray, | |
| 141 | + OGLSurfaceData.PF_USHORT_GRAY), | |
| 142 | + new OGLSwToSurfaceTransform(SurfaceType.IntArgbPre, | |
| 143 | + OGLSurfaceData.PF_INT_ARGB_PRE), | |
| 144 | + | |
| 145 | + // texture->surface ops | |
| 146 | + new OGLTextureToSurfaceBlit(), | |
| 147 | + new OGLTextureToSurfaceScale(), | |
| 148 | + new OGLTextureToSurfaceTransform(), | |
| 149 | + | |
| 150 | + // sw->texture ops | |
| 151 | + blitIntArgbPreToTexture, | |
| 152 | + new OGLSwToTextureBlit(SurfaceType.IntRgb, | |
| 153 | + OGLSurfaceData.PF_INT_RGB), | |
| 154 | + new OGLSwToTextureBlit(SurfaceType.IntRgbx, | |
| 155 | + OGLSurfaceData.PF_INT_RGBX), | |
| 156 | + new OGLSwToTextureBlit(SurfaceType.IntBgr, | |
| 157 | + OGLSurfaceData.PF_INT_BGR), | |
| 158 | + new OGLSwToTextureBlit(SurfaceType.IntBgrx, | |
| 159 | + OGLSurfaceData.PF_INT_BGRX), | |
| 160 | + new OGLSwToTextureBlit(SurfaceType.ThreeByteBgr, | |
| 161 | + OGLSurfaceData.PF_3BYTE_BGR), | |
| 162 | + new OGLSwToTextureBlit(SurfaceType.Ushort565Rgb, | |
| 163 | + OGLSurfaceData.PF_USHORT_565_RGB), | |
| 164 | + new OGLSwToTextureBlit(SurfaceType.Ushort555Rgb, | |
| 165 | + OGLSurfaceData.PF_USHORT_555_RGB), | |
| 166 | + new OGLSwToTextureBlit(SurfaceType.Ushort555Rgbx, | |
| 167 | + OGLSurfaceData.PF_USHORT_555_RGBX), | |
| 168 | + new OGLSwToTextureBlit(SurfaceType.ByteGray, | |
| 169 | + OGLSurfaceData.PF_BYTE_GRAY), | |
| 170 | + new OGLSwToTextureBlit(SurfaceType.UshortGray, | |
| 171 | + OGLSurfaceData.PF_USHORT_GRAY), | |
| 172 | + new OGLGeneralBlit(OGLSurfaceData.OpenGLTexture, | |
| 173 | + CompositeType.SrcNoEa, | |
| 174 | + blitIntArgbPreToTexture), | |
| 175 | + }; | |
| 176 | + GraphicsPrimitiveMgr.register(primitives); | |
| 177 | + } | |
| 178 | + | |
| 179 | + /** | |
| 180 | + * The following offsets are used to pack the parameters in | |
| 181 | + * createPackedParams(). (They are also used at the native level when | |
| 182 | + * unpacking the params.) | |
| 183 | + */ | |
| 184 | + private static final int OFFSET_SRCTYPE = 16; | |
| 185 | + private static final int OFFSET_HINT = 8; | |
| 186 | + private static final int OFFSET_TEXTURE = 3; | |
| 187 | + private static final int OFFSET_RTT = 2; | |
| 188 | + private static final int OFFSET_XFORM = 1; | |
| 189 | + private static final int OFFSET_ISOBLIT = 0; | |
| 190 | + | |
| 191 | + /** | |
| 192 | + * Packs the given parameters into a single int value in order to save | |
| 193 | + * space on the rendering queue. | |
| 194 | + */ | |
| 195 | + private static int createPackedParams(boolean isoblit, boolean texture, | |
| 196 | + boolean rtt, boolean xform, | |
| 197 | + int hint, int srctype) | |
| 198 | + { | |
| 199 | + return | |
| 200 | + ((srctype << OFFSET_SRCTYPE) | | |
| 201 | + (hint << OFFSET_HINT ) | | |
| 202 | + ((texture ? 1 : 0) << OFFSET_TEXTURE) | | |
| 203 | + ((rtt ? 1 : 0) << OFFSET_RTT ) | | |
| 204 | + ((xform ? 1 : 0) << OFFSET_XFORM ) | | |
| 205 | + ((isoblit ? 1 : 0) << OFFSET_ISOBLIT)); | |
| 206 | + } | |
| 207 | + | |
| 208 | + /** | |
| 209 | + * Enqueues a BLIT operation with the given parameters. Note that the | |
| 210 | + * RenderQueue lock must be held before calling this method. | |
| 211 | + */ | |
| 212 | + private static void enqueueBlit(RenderQueue rq, | |
| 213 | + SurfaceData src, SurfaceData dst, | |
| 214 | + int packedParams, | |
| 215 | + int sx1, int sy1, | |
| 216 | + int sx2, int sy2, | |
| 217 | + double dx1, double dy1, | |
| 218 | + double dx2, double dy2) | |
| 219 | + { | |
| 220 | + // assert rq.lock.isHeldByCurrentThread(); | |
| 221 | + RenderBuffer buf = rq.getBuffer(); | |
| 222 | + rq.ensureCapacityAndAlignment(72, 24); | |
| 223 | + buf.putInt(BLIT); | |
| 224 | + buf.putInt(packedParams); | |
| 225 | + buf.putInt(sx1).putInt(sy1); | |
| 226 | + buf.putInt(sx2).putInt(sy2); | |
| 227 | + buf.putDouble(dx1).putDouble(dy1); | |
| 228 | + buf.putDouble(dx2).putDouble(dy2); | |
| 229 | + buf.putLong(src.getNativeOps()); | |
| 230 | + buf.putLong(dst.getNativeOps()); | |
| 231 | + } | |
| 232 | + | |
| 233 | + static void Blit(SurfaceData srcData, SurfaceData dstData, | |
| 234 | + Composite comp, Region clip, | |
| 235 | + AffineTransform xform, int hint, | |
| 236 | + int sx1, int sy1, | |
| 237 | + int sx2, int sy2, | |
| 238 | + double dx1, double dy1, | |
| 239 | + double dx2, double dy2, | |
| 240 | + int srctype, boolean texture) | |
| 241 | + { | |
| 242 | + int ctxflags = 0; | |
| 243 | + if (srcData.getTransparency() == Transparency.OPAQUE) { | |
| 244 | + ctxflags |= OGLContext.SRC_IS_OPAQUE; | |
| 245 | + } | |
| 246 | + | |
| 247 | + OGLRenderQueue rq = OGLRenderQueue.getInstance(); | |
| 248 | + rq.lock(); | |
| 249 | + try { | |
| 250 | + // make sure the RenderQueue keeps a hard reference to the | |
| 251 | + // source (sysmem) SurfaceData to prevent it from being | |
| 252 | + // disposed while the operation is processed on the QFT | |
| 253 | + rq.addReference(srcData); | |
| 254 | + | |
| 255 | + OGLSurfaceData oglDst = (OGLSurfaceData)dstData; | |
| 256 | + if (texture) { | |
| 257 | + // make sure we have a current context before uploading | |
| 258 | + // the sysmem data to the texture object | |
| 259 | + OGLGraphicsConfig gc = oglDst.getOGLGraphicsConfig(); | |
| 260 | + OGLContext.setScratchSurface(gc); | |
| 261 | + } else { | |
| 262 | + OGLContext.validateContext(oglDst, oglDst, | |
| 263 | + clip, comp, xform, null, null, | |
| 264 | + ctxflags); | |
| 265 | + } | |
| 266 | + | |
| 267 | + int packedParams = createPackedParams(false, texture, | |
| 268 | + false, xform != null, | |
| 269 | + hint, srctype); | |
| 270 | + enqueueBlit(rq, srcData, dstData, | |
| 271 | + packedParams, | |
| 272 | + sx1, sy1, sx2, sy2, | |
| 273 | + dx1, dy1, dx2, dy2); | |
| 274 | + | |
| 275 | + // always flush immediately, since we (currently) have no means | |
| 276 | + // of tracking changes to the system memory surface | |
| 277 | + rq.flushNow(); | |
| 278 | + } finally { | |
| 279 | + rq.unlock(); | |
| 280 | + } | |
| 281 | + } | |
| 282 | + | |
| 283 | + /** | |
| 284 | + * Note: The srcImg and biop parameters are only used when invoked | |
| 285 | + * from the OGLBufImgOps.renderImageWithOp() method; in all other cases, | |
| 286 | + * this method can be called with null values for those two parameters, | |
| 287 | + * and they will be effectively ignored. | |
| 288 | + */ | |
| 289 | + static void IsoBlit(SurfaceData srcData, SurfaceData dstData, | |
| 290 | + BufferedImage srcImg, BufferedImageOp biop, | |
| 291 | + Composite comp, Region clip, | |
| 292 | + AffineTransform xform, int hint, | |
| 293 | + int sx1, int sy1, | |
| 294 | + int sx2, int sy2, | |
| 295 | + double dx1, double dy1, | |
| 296 | + double dx2, double dy2, | |
| 297 | + boolean texture) | |
| 298 | + { | |
| 299 | + int ctxflags = 0; | |
| 300 | + if (srcData.getTransparency() == Transparency.OPAQUE) { | |
| 301 | + ctxflags |= OGLContext.SRC_IS_OPAQUE; | |
| 302 | + } | |
| 303 | + | |
| 304 | + OGLRenderQueue rq = OGLRenderQueue.getInstance(); | |
| 305 | + rq.lock(); | |
| 306 | + try { | |
| 307 | + OGLSurfaceData oglSrc = (OGLSurfaceData)srcData; | |
| 308 | + OGLSurfaceData oglDst = (OGLSurfaceData)dstData; | |
| 309 | + int srctype = oglSrc.getType(); | |
| 310 | + boolean rtt; | |
| 311 | + OGLSurfaceData srcCtxData; | |
| 312 | + if (srctype == OGLSurfaceData.TEXTURE) { | |
| 313 | + // the source is a regular texture object; we substitute | |
| 314 | + // the destination surface for the purposes of making a | |
| 315 | + // context current | |
| 316 | + rtt = false; | |
| 317 | + srcCtxData = oglDst; | |
| 318 | + } else { | |
| 319 | + // the source is a pbuffer, backbuffer, or render-to-texture | |
| 320 | + // surface; we set rtt to true to differentiate this kind | |
| 321 | + // of surface from a regular texture object | |
| 322 | + rtt = true; | |
| 323 | + if (srctype == OGLSurfaceData.FBOBJECT) { | |
| 324 | + srcCtxData = oglDst; | |
| 325 | + } else { | |
| 326 | + srcCtxData = oglSrc; | |
| 327 | + } | |
| 328 | + } | |
| 329 | + | |
| 330 | + OGLContext.validateContext(srcCtxData, oglDst, | |
| 331 | + clip, comp, xform, null, null, | |
| 332 | + ctxflags); | |
| 333 | + | |
| 334 | + if (biop != null) { | |
| 335 | + OGLBufImgOps.enableBufImgOp(rq, oglSrc, srcImg, biop); | |
| 336 | + } | |
| 337 | + | |
| 338 | + int packedParams = createPackedParams(true, texture, | |
| 339 | + rtt, xform != null, | |
| 340 | + hint, 0 /*unused*/); | |
| 341 | + enqueueBlit(rq, srcData, dstData, | |
| 342 | + packedParams, | |
| 343 | + sx1, sy1, sx2, sy2, | |
| 344 | + dx1, dy1, dx2, dy2); | |
| 345 | + | |
| 346 | + if (biop != null) { | |
| 347 | + OGLBufImgOps.disableBufImgOp(rq, biop); | |
| 348 | + } | |
| 349 | + | |
| 350 | + if (rtt && (oglDst.getType() == OGLSurfaceData.WINDOW)) { | |
| 351 | + // we only have to flush immediately when copying from a | |
| 352 | + // (non-texture) surface to the screen; otherwise Swing apps | |
| 353 | + // might appear unresponsive until the auto-flush completes | |
| 354 | + rq.flushNow(); | |
| 355 | + } | |
| 356 | + } finally { | |
| 357 | + rq.unlock(); | |
| 358 | + } | |
| 359 | + } | |
| 360 | +} | |
| 361 | + | |
| 362 | +class OGLSurfaceToSurfaceBlit extends Blit { | |
| 363 | + | |
| 364 | + OGLSurfaceToSurfaceBlit() { | |
| 365 | + super(OGLSurfaceData.OpenGLSurface, | |
| 366 | + CompositeType.AnyAlpha, | |
| 367 | + OGLSurfaceData.OpenGLSurface); | |
| 368 | + } | |
| 369 | + | |
| 370 | + public void Blit(SurfaceData src, SurfaceData dst, | |
| 371 | + Composite comp, Region clip, | |
| 372 | + int sx, int sy, int dx, int dy, int w, int h) | |
| 373 | + { | |
| 374 | + OGLBlitLoops.IsoBlit(src, dst, | |
| 375 | + null, null, | |
| 376 | + comp, clip, null, | |
| 377 | + AffineTransformOp.TYPE_NEAREST_NEIGHBOR, | |
| 378 | + sx, sy, sx+w, sy+h, | |
| 379 | + dx, dy, dx+w, dy+h, | |
| 380 | + false); | |
| 381 | + } | |
| 382 | +} | |
| 383 | + | |
| 384 | +class OGLSurfaceToSurfaceScale extends ScaledBlit { | |
| 385 | + | |
| 386 | + OGLSurfaceToSurfaceScale() { | |
| 387 | + super(OGLSurfaceData.OpenGLSurface, | |
| 388 | + CompositeType.AnyAlpha, | |
| 389 | + OGLSurfaceData.OpenGLSurface); | |
| 390 | + } | |
| 391 | + | |
| 392 | + public void Scale(SurfaceData src, SurfaceData dst, | |
| 393 | + Composite comp, Region clip, | |
| 394 | + int sx1, int sy1, | |
| 395 | + int sx2, int sy2, | |
| 396 | + double dx1, double dy1, | |
| 397 | + double dx2, double dy2) | |
| 398 | + { | |
| 399 | + OGLBlitLoops.IsoBlit(src, dst, | |
| 400 | + null, null, | |
| 401 | + comp, clip, null, | |
| 402 | + AffineTransformOp.TYPE_NEAREST_NEIGHBOR, | |
| 403 | + sx1, sy1, sx2, sy2, | |
| 404 | + dx1, dy1, dx2, dy2, | |
| 405 | + false); | |
| 406 | + } | |
| 407 | +} | |
| 408 | + | |
| 409 | +class OGLSurfaceToSurfaceTransform extends TransformBlit { | |
| 410 | + | |
| 411 | + OGLSurfaceToSurfaceTransform() { | |
| 412 | + super(OGLSurfaceData.OpenGLSurface, | |
| 413 | + CompositeType.AnyAlpha, | |
| 414 | + OGLSurfaceData.OpenGLSurface); | |
| 415 | + } | |
| 416 | + | |
| 417 | + public void Transform(SurfaceData src, SurfaceData dst, | |
| 418 | + Composite comp, Region clip, | |
| 419 | + AffineTransform at, int hint, | |
| 420 | + int sx, int sy, int dx, int dy, | |
| 421 | + int w, int h) | |
| 422 | + { | |
| 423 | + OGLBlitLoops.IsoBlit(src, dst, | |
| 424 | + null, null, | |
| 425 | + comp, clip, at, hint, | |
| 426 | + sx, sy, sx+w, sy+h, | |
| 427 | + dx, dy, dx+w, dy+h, | |
| 428 | + false); | |
| 429 | + } | |
| 430 | +} | |
| 431 | + | |
| 432 | +class OGLRTTSurfaceToSurfaceBlit extends Blit { | |
| 433 | + | |
| 434 | + OGLRTTSurfaceToSurfaceBlit() { | |
| 435 | + super(OGLSurfaceData.OpenGLSurfaceRTT, | |
| 436 | + CompositeType.AnyAlpha, | |
| 437 | + OGLSurfaceData.OpenGLSurface); | |
| 438 | + } | |
| 439 | + | |
| 440 | + public void Blit(SurfaceData src, SurfaceData dst, | |
| 441 | + Composite comp, Region clip, | |
| 442 | + int sx, int sy, int dx, int dy, int w, int h) | |
| 443 | + { | |
| 444 | + OGLBlitLoops.IsoBlit(src, dst, | |
| 445 | + null, null, | |
| 446 | + comp, clip, null, | |
| 447 | + AffineTransformOp.TYPE_NEAREST_NEIGHBOR, | |
| 448 | + sx, sy, sx+w, sy+h, | |
| 449 | + dx, dy, dx+w, dy+h, | |
| 450 | + true); | |
| 451 | + } | |
| 452 | +} | |
| 453 | + | |
| 454 | +class OGLRTTSurfaceToSurfaceScale extends ScaledBlit { | |
| 455 | + | |
| 456 | + OGLRTTSurfaceToSurfaceScale() { | |
| 457 | + super(OGLSurfaceData.OpenGLSurfaceRTT, | |
| 458 | + CompositeType.AnyAlpha, | |
| 459 | + OGLSurfaceData.OpenGLSurface); | |
| 460 | + } | |
| 461 | + | |
| 462 | + public void Scale(SurfaceData src, SurfaceData dst, | |
| 463 | + Composite comp, Region clip, | |
| 464 | + int sx1, int sy1, | |
| 465 | + int sx2, int sy2, | |
| 466 | + double dx1, double dy1, | |
| 467 | + double dx2, double dy2) | |
| 468 | + { | |
| 469 | + OGLBlitLoops.IsoBlit(src, dst, | |
| 470 | + null, null, | |
| 471 | + comp, clip, null, | |
| 472 | + AffineTransformOp.TYPE_NEAREST_NEIGHBOR, | |
| 473 | + sx1, sy1, sx2, sy2, | |
| 474 | + dx1, dy1, dx2, dy2, | |
| 475 | + true); | |
| 476 | + } | |
| 477 | +} | |
| 478 | + | |
| 479 | +class OGLRTTSurfaceToSurfaceTransform extends TransformBlit { | |
| 480 | + | |
| 481 | + OGLRTTSurfaceToSurfaceTransform() { | |
| 482 | + super(OGLSurfaceData.OpenGLSurfaceRTT, | |
| 483 | + CompositeType.AnyAlpha, | |
| 484 | + OGLSurfaceData.OpenGLSurface); | |
| 485 | + } | |
| 486 | + | |
| 487 | + public void Transform(SurfaceData src, SurfaceData dst, | |
| 488 | + Composite comp, Region clip, | |
| 489 | + AffineTransform at, int hint, | |
| 490 | + int sx, int sy, int dx, int dy, int w, int h) | |
| 491 | + { | |
| 492 | + OGLBlitLoops.IsoBlit(src, dst, | |
| 493 | + null, null, | |
| 494 | + comp, clip, at, hint, | |
| 495 | + sx, sy, sx+w, sy+h, | |
| 496 | + dx, dy, dx+w, dy+h, | |
| 497 | + true); | |
| 498 | + } | |
| 499 | +} | |
| 500 | + | |
| 501 | +class OGLSurfaceToSwBlit extends Blit { | |
| 502 | + | |
| 503 | + private int typeval; | |
| 504 | + | |
| 505 | + // REMIND: destination will actually be opaque/premultiplied... | |
| 506 | + OGLSurfaceToSwBlit(SurfaceType dstType, int typeval) { | |
| 507 | + super(OGLSurfaceData.OpenGLSurface, | |
| 508 | + CompositeType.SrcNoEa, | |
| 509 | + dstType); | |
| 510 | + this.typeval = typeval; | |
| 511 | + } | |
| 512 | + | |
| 513 | + public void Blit(SurfaceData src, SurfaceData dst, | |
| 514 | + Composite comp, Region clip, | |
| 515 | + int sx, int sy, int dx, int dy, | |
| 516 | + int w, int h) | |
| 517 | + { | |
| 518 | + OGLRenderQueue rq = OGLRenderQueue.getInstance(); | |
| 519 | + rq.lock(); | |
| 520 | + try { | |
| 521 | + // make sure the RenderQueue keeps a hard reference to the | |
| 522 | + // destination (sysmem) SurfaceData to prevent it from being | |
| 523 | + // disposed while the operation is processed on the QFT | |
| 524 | + rq.addReference(dst); | |
| 525 | + | |
| 526 | + RenderBuffer buf = rq.getBuffer(); | |
| 527 | + OGLContext.validateContext((OGLSurfaceData)src); | |
| 528 | + | |
| 529 | + rq.ensureCapacityAndAlignment(48, 32); | |
| 530 | + buf.putInt(SURFACE_TO_SW_BLIT); | |
| 531 | + buf.putInt(sx).putInt(sy); | |
| 532 | + buf.putInt(dx).putInt(dy); | |
| 533 | + buf.putInt(w).putInt(h); | |
| 534 | + buf.putInt(typeval); | |
| 535 | + buf.putLong(src.getNativeOps()); | |
| 536 | + buf.putLong(dst.getNativeOps()); | |
| 537 | + | |
| 538 | + // always flush immediately | |
| 539 | + rq.flushNow(); | |
| 540 | + } finally { | |
| 541 | + rq.unlock(); | |
| 542 | + } | |
| 543 | + } | |
| 544 | +} | |
| 545 | + | |
| 546 | +class OGLSwToSurfaceBlit extends Blit { | |
| 547 | + | |
| 548 | + private int typeval; | |
| 549 | + | |
| 550 | + OGLSwToSurfaceBlit(SurfaceType srcType, int typeval) { | |
| 551 | + super(srcType, | |
| 552 | + CompositeType.AnyAlpha, | |
| 553 | + OGLSurfaceData.OpenGLSurface); | |
| 554 | + this.typeval = typeval; | |
| 555 | + } | |
| 556 | + | |
| 557 | + public void Blit(SurfaceData src, SurfaceData dst, | |
| 558 | + Composite comp, Region clip, | |
| 559 | + int sx, int sy, int dx, int dy, int w, int h) | |
| 560 | + { | |
| 561 | + OGLBlitLoops.Blit(src, dst, | |
| 562 | + comp, clip, null, | |
| 563 | + AffineTransformOp.TYPE_NEAREST_NEIGHBOR, | |
| 564 | + sx, sy, sx+w, sy+h, | |
| 565 | + dx, dy, dx+w, dy+h, | |
| 566 | + typeval, false); | |
| 567 | + } | |
| 568 | +} | |
| 569 | + | |
| 570 | +class OGLSwToSurfaceScale extends ScaledBlit { | |
| 571 | + | |
| 572 | + private int typeval; | |
| 573 | + | |
| 574 | + OGLSwToSurfaceScale(SurfaceType srcType, int typeval) { | |
| 575 | + super(srcType, | |
| 576 | + CompositeType.AnyAlpha, | |
| 577 | + OGLSurfaceData.OpenGLSurface); | |
| 578 | + this.typeval = typeval; | |
| 579 | + } | |
| 580 | + | |
| 581 | + public void Scale(SurfaceData src, SurfaceData dst, | |
| 582 | + Composite comp, Region clip, | |
| 583 | + int sx1, int sy1, | |
| 584 | + int sx2, int sy2, | |
| 585 | + double dx1, double dy1, | |
| 586 | + double dx2, double dy2) | |
| 587 | + { | |
| 588 | + OGLBlitLoops.Blit(src, dst, | |
| 589 | + comp, clip, null, | |
| 590 | + AffineTransformOp.TYPE_NEAREST_NEIGHBOR, | |
| 591 | + sx1, sy1, sx2, sy2, | |
| 592 | + dx1, dy1, dx2, dy2, | |
| 593 | + typeval, false); | |
| 594 | + } | |
| 595 | +} | |
| 596 | + | |
| 597 | +class OGLSwToSurfaceTransform extends TransformBlit { | |
| 598 | + | |
| 599 | + private int typeval; | |
| 600 | + | |
| 601 | + OGLSwToSurfaceTransform(SurfaceType srcType, int typeval) { | |
| 602 | + super(srcType, | |
| 603 | + CompositeType.AnyAlpha, | |
| 604 | + OGLSurfaceData.OpenGLSurface); | |
| 605 | + this.typeval = typeval; | |
| 606 | + } | |
| 607 | + | |
| 608 | + public void Transform(SurfaceData src, SurfaceData dst, | |
| 609 | + Composite comp, Region clip, | |
| 610 | + AffineTransform at, int hint, | |
| 611 | + int sx, int sy, int dx, int dy, int w, int h) | |
| 612 | + { | |
| 613 | + OGLBlitLoops.Blit(src, dst, | |
| 614 | + comp, clip, at, hint, | |
| 615 | + sx, sy, sx+w, sy+h, | |
| 616 | + dx, dy, dx+w, dy+h, | |
| 617 | + typeval, false); | |
| 618 | + } | |
| 619 | +} | |
| 620 | + | |
| 621 | +class OGLSwToTextureBlit extends Blit { | |
| 622 | + | |
| 623 | + private int typeval; | |
| 624 | + | |
| 625 | + OGLSwToTextureBlit(SurfaceType srcType, int typeval) { | |
| 626 | + super(srcType, | |
| 627 | + CompositeType.SrcNoEa, | |
| 628 | + OGLSurfaceData.OpenGLTexture); | |
| 629 | + this.typeval = typeval; | |
| 630 | + } | |
| 631 | + | |
| 632 | + public void Blit(SurfaceData src, SurfaceData dst, | |
| 633 | + Composite comp, Region clip, | |
| 634 | + int sx, int sy, int dx, int dy, int w, int h) | |
| 635 | + { | |
| 636 | + OGLBlitLoops.Blit(src, dst, | |
| 637 | + comp, clip, null, | |
| 638 | + AffineTransformOp.TYPE_NEAREST_NEIGHBOR, | |
| 639 | + sx, sy, sx+w, sy+h, | |
| 640 | + dx, dy, dx+w, dy+h, | |
| 641 | + typeval, true); | |
| 642 | + } | |
| 643 | +} | |
| 644 | + | |
| 645 | +class OGLTextureToSurfaceBlit extends Blit { | |
| 646 | + | |
| 647 | + OGLTextureToSurfaceBlit() { | |
| 648 | + super(OGLSurfaceData.OpenGLTexture, | |
| 649 | + CompositeType.AnyAlpha, | |
| 650 | + OGLSurfaceData.OpenGLSurface); | |
| 651 | + } | |
| 652 | + | |
| 653 | + public void Blit(SurfaceData src, SurfaceData dst, | |
| 654 | + Composite comp, Region clip, | |
| 655 | + int sx, int sy, int dx, int dy, int w, int h) | |
| 656 | + { | |
| 657 | + OGLBlitLoops.IsoBlit(src, dst, | |
| 658 | + null, null, | |
| 659 | + comp, clip, null, | |
| 660 | + AffineTransformOp.TYPE_NEAREST_NEIGHBOR, | |
| 661 | + sx, sy, sx+w, sy+h, | |
| 662 | + dx, dy, dx+w, dy+h, | |
| 663 | + true); | |
| 664 | + } | |
| 665 | +} | |
| 666 | + | |
| 667 | +class OGLTextureToSurfaceScale extends ScaledBlit { | |
| 668 | + | |
| 669 | + OGLTextureToSurfaceScale() { | |
| 670 | + super(OGLSurfaceData.OpenGLTexture, | |
| 671 | + CompositeType.AnyAlpha, | |
| 672 | + OGLSurfaceData.OpenGLSurface); | |
| 673 | + } | |
| 674 | + | |
| 675 | + public void Scale(SurfaceData src, SurfaceData dst, | |
| 676 | + Composite comp, Region clip, | |
| 677 | + int sx1, int sy1, | |
| 678 | + int sx2, int sy2, | |
| 679 | + double dx1, double dy1, | |
| 680 | + double dx2, double dy2) | |
| 681 | + { | |
| 682 | + OGLBlitLoops.IsoBlit(src, dst, | |
| 683 | + null, null, | |
| 684 | + comp, clip, null, | |
| 685 | + AffineTransformOp.TYPE_NEAREST_NEIGHBOR, | |
| 686 | + sx1, sy1, sx2, sy2, | |
| 687 | + dx1, dy1, dx2, dy2, | |
| 688 | + true); | |
| 689 | + } | |
| 690 | +} | |
| 691 | + | |
| 692 | +class OGLTextureToSurfaceTransform extends TransformBlit { | |
| 693 | + | |
| 694 | + OGLTextureToSurfaceTransform() { | |
| 695 | + super(OGLSurfaceData.OpenGLTexture, | |
| 696 | + CompositeType.AnyAlpha, | |
| 697 | + OGLSurfaceData.OpenGLSurface); | |
| 698 | + } | |
| 699 | + | |
| 700 | + public void Transform(SurfaceData src, SurfaceData dst, | |
| 701 | + Composite comp, Region clip, | |
| 702 | + AffineTransform at, int hint, | |
| 703 | + int sx, int sy, int dx, int dy, | |
| 704 | + int w, int h) | |
| 705 | + { | |
| 706 | + OGLBlitLoops.IsoBlit(src, dst, | |
| 707 | + null, null, | |
| 708 | + comp, clip, at, hint, | |
| 709 | + sx, sy, sx+w, sy+h, | |
| 710 | + dx, dy, dx+w, dy+h, | |
| 711 | + true); | |
| 712 | + } | |
| 713 | +} | |
| 714 | + | |
| 715 | +/** | |
| 716 | + * This general Blit implemenation converts any source surface to an | |
| 717 | + * intermediate IntArgbPre surface, and then uses the more specific | |
| 718 | + * IntArgbPre->OpenGLSurface/Texture loop to get the intermediate | |
| 719 | + * (premultiplied) surface down to OpenGL. | |
| 720 | + */ | |
| 721 | +class OGLGeneralBlit extends Blit { | |
| 722 | + | |
| 723 | + private Blit performop; | |
| 724 | + private WeakReference srcTmp; | |
| 725 | + | |
| 726 | + OGLGeneralBlit(SurfaceType dstType, | |
| 727 | + CompositeType compType, | |
| 728 | + Blit performop) | |
| 729 | + { | |
| 730 | + super(SurfaceType.Any, compType, dstType); | |
| 731 | + this.performop = performop; | |
| 732 | + } | |
| 733 | + | |
| 734 | + public synchronized void Blit(SurfaceData src, SurfaceData dst, | |
| 735 | + Composite comp, Region clip, | |
| 736 | + int sx, int sy, int dx, int dy, | |
| 737 | + int w, int h) | |
| 738 | + { | |
| 739 | + Blit convertsrc = Blit.getFromCache(src.getSurfaceType(), | |
| 740 | + CompositeType.SrcNoEa, | |
| 741 | + SurfaceType.IntArgbPre); | |
| 742 | + | |
| 743 | + SurfaceData cachedSrc = null; | |
| 744 | + if (srcTmp != null) { | |
| 745 | + // use cached intermediate surface, if available | |
| 746 | + cachedSrc = (SurfaceData)srcTmp.get(); | |
| 747 | + } | |
| 748 | + | |
| 749 | + // convert source to IntArgbPre | |
| 750 | + src = convertFrom(convertsrc, src, sx, sy, w, h, | |
| 751 | + cachedSrc, BufferedImage.TYPE_INT_ARGB_PRE); | |
| 752 | + | |
| 753 | + // copy IntArgbPre intermediate surface to OpenGL surface | |
| 754 | + performop.Blit(src, dst, comp, clip, | |
| 755 | + 0, 0, dx, dy, w, h); | |
| 756 | + | |
| 757 | + if (src != cachedSrc) { | |
| 758 | + // cache the intermediate surface | |
| 759 | + srcTmp = new WeakReference(src); | |
| 760 | + } | |
| 761 | + } | |
| 762 | +} | |