Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/classes/sun/java2d/d3d/D3DBlitLoops.java
32288 views
/*1* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.d3d;2627import java.awt.Composite;28import java.awt.Transparency;29import java.awt.geom.AffineTransform;30import java.awt.image.AffineTransformOp;31import java.awt.image.BufferedImage;32import java.awt.image.BufferedImageOp;33import java.lang.ref.WeakReference;34import java.lang.annotation.Native;35import sun.java2d.ScreenUpdateManager;36import sun.java2d.SurfaceData;37import sun.java2d.loops.Blit;38import sun.java2d.loops.CompositeType;39import sun.java2d.loops.GraphicsPrimitive;40import sun.java2d.loops.GraphicsPrimitiveMgr;41import sun.java2d.loops.ScaledBlit;42import sun.java2d.loops.SurfaceType;43import sun.java2d.loops.TransformBlit;44import sun.java2d.pipe.Region;45import sun.java2d.pipe.RenderBuffer;46import sun.java2d.pipe.RenderQueue;47import static sun.java2d.pipe.BufferedOpCodes.*;48import sun.java2d.windows.GDIWindowSurfaceData;4950final class D3DBlitLoops {5152static void register() {53Blit blitIntArgbPreToSurface =54new D3DSwToSurfaceBlit(SurfaceType.IntArgbPre,55D3DSurfaceData.ST_INT_ARGB_PRE);56Blit blitIntArgbPreToTexture =57new D3DSwToTextureBlit(SurfaceType.IntArgbPre,58D3DSurfaceData.ST_INT_ARGB_PRE);59TransformBlit transformBlitIntArgbPreToSurface =60new D3DSwToSurfaceTransform(SurfaceType.IntArgbPre,61D3DSurfaceData.ST_INT_ARGB_PRE);62GraphicsPrimitive[] primitives = {63// prevent D3DSurface -> Screen blits64new D3DSurfaceToGDIWindowSurfaceBlit(),65new D3DSurfaceToGDIWindowSurfaceScale(),66new D3DSurfaceToGDIWindowSurfaceTransform(),6768// surface->surface ops69new D3DSurfaceToSurfaceBlit(),70new D3DSurfaceToSurfaceScale(),71new D3DSurfaceToSurfaceTransform(),7273// render-to-texture surface->surface ops74new D3DRTTSurfaceToSurfaceBlit(),75new D3DRTTSurfaceToSurfaceScale(),76new D3DRTTSurfaceToSurfaceTransform(),7778// surface->sw ops79new D3DSurfaceToSwBlit(SurfaceType.IntArgb,80D3DSurfaceData.ST_INT_ARGB),8182// sw->surface ops83blitIntArgbPreToSurface,84new D3DSwToSurfaceBlit(SurfaceType.IntArgb,85D3DSurfaceData.ST_INT_ARGB),86new D3DSwToSurfaceBlit(SurfaceType.IntRgb,87D3DSurfaceData.ST_INT_RGB),88new D3DSwToSurfaceBlit(SurfaceType.IntBgr,89D3DSurfaceData.ST_INT_BGR),90new D3DSwToSurfaceBlit(SurfaceType.ThreeByteBgr,91D3DSurfaceData.ST_3BYTE_BGR),92new D3DSwToSurfaceBlit(SurfaceType.Ushort565Rgb,93D3DSurfaceData.ST_USHORT_565_RGB),94new D3DSwToSurfaceBlit(SurfaceType.Ushort555Rgb,95D3DSurfaceData.ST_USHORT_555_RGB),96new D3DSwToSurfaceBlit(SurfaceType.ByteIndexed,97D3DSurfaceData.ST_BYTE_INDEXED),98// REMIND: we don't have a native sw loop to back this loop up99// new D3DSwToSurfaceBlit(SurfaceType.ByteIndexedBm,100// D3DSurfaceData.ST_BYTE_INDEXED_BM),101new D3DGeneralBlit(D3DSurfaceData.D3DSurface,102CompositeType.AnyAlpha,103blitIntArgbPreToSurface),104105new D3DSwToSurfaceScale(SurfaceType.IntArgb,106D3DSurfaceData.ST_INT_ARGB),107new D3DSwToSurfaceScale(SurfaceType.IntArgbPre,108D3DSurfaceData.ST_INT_ARGB_PRE),109new D3DSwToSurfaceScale(SurfaceType.IntRgb,110D3DSurfaceData.ST_INT_RGB),111new D3DSwToSurfaceScale(SurfaceType.IntBgr,112D3DSurfaceData.ST_INT_BGR),113new D3DSwToSurfaceScale(SurfaceType.ThreeByteBgr,114D3DSurfaceData.ST_3BYTE_BGR),115new D3DSwToSurfaceScale(SurfaceType.Ushort565Rgb,116D3DSurfaceData.ST_USHORT_565_RGB),117new D3DSwToSurfaceScale(SurfaceType.Ushort555Rgb,118D3DSurfaceData.ST_USHORT_555_RGB),119new D3DSwToSurfaceScale(SurfaceType.ByteIndexed,120D3DSurfaceData.ST_BYTE_INDEXED),121// REMIND: we don't have a native sw loop to back this loop up122// new D3DSwToSurfaceScale(SurfaceType.ByteIndexedBm,123// D3DSurfaceData.ST_BYTE_INDEXED_BM),124125new D3DSwToSurfaceTransform(SurfaceType.IntArgb,126D3DSurfaceData.ST_INT_ARGB),127new D3DSwToSurfaceTransform(SurfaceType.IntRgb,128D3DSurfaceData.ST_INT_RGB),129new D3DSwToSurfaceTransform(SurfaceType.IntBgr,130D3DSurfaceData.ST_INT_BGR),131new D3DSwToSurfaceTransform(SurfaceType.ThreeByteBgr,132D3DSurfaceData.ST_3BYTE_BGR),133new D3DSwToSurfaceTransform(SurfaceType.Ushort565Rgb,134D3DSurfaceData.ST_USHORT_565_RGB),135new D3DSwToSurfaceTransform(SurfaceType.Ushort555Rgb,136D3DSurfaceData.ST_USHORT_555_RGB),137new D3DSwToSurfaceTransform(SurfaceType.ByteIndexed,138D3DSurfaceData.ST_BYTE_INDEXED),139// REMIND: we don't have a native sw loop to back this loop up140// new D3DSwToSurfaceTransform(SurfaceType.ByteIndexedBm,141// D3DSurfaceData.ST_BYTE_INDEXED_BM),142transformBlitIntArgbPreToSurface,143144new D3DGeneralTransformedBlit(transformBlitIntArgbPreToSurface),145146// texture->surface ops147new D3DTextureToSurfaceBlit(),148new D3DTextureToSurfaceScale(),149new D3DTextureToSurfaceTransform(),150151// sw->texture ops152blitIntArgbPreToTexture,153new D3DSwToTextureBlit(SurfaceType.IntRgb,154D3DSurfaceData.ST_INT_RGB),155new D3DSwToTextureBlit(SurfaceType.IntArgb,156D3DSurfaceData.ST_INT_ARGB),157new D3DSwToTextureBlit(SurfaceType.IntBgr,158D3DSurfaceData.ST_INT_BGR),159new D3DSwToTextureBlit(SurfaceType.ThreeByteBgr,160D3DSurfaceData.ST_3BYTE_BGR),161new D3DSwToTextureBlit(SurfaceType.Ushort565Rgb,162D3DSurfaceData.ST_USHORT_565_RGB),163new D3DSwToTextureBlit(SurfaceType.Ushort555Rgb,164D3DSurfaceData.ST_USHORT_555_RGB),165new D3DSwToTextureBlit(SurfaceType.ByteIndexed,166D3DSurfaceData.ST_BYTE_INDEXED),167// REMIND: we don't have a native sw loop to back this loop up168// new D3DSwToTextureBlit(SurfaceType.ByteIndexedBm,169// D3DSurfaceData.ST_BYTE_INDEXED_BM),170new D3DGeneralBlit(D3DSurfaceData.D3DTexture,171CompositeType.SrcNoEa,172blitIntArgbPreToTexture),173};174GraphicsPrimitiveMgr.register(primitives);175}176177/**178* The following offsets are used to pack the parameters in179* createPackedParams(). (They are also used at the native level when180* unpacking the params.)181*/182@Native private static final int OFFSET_SRCTYPE = 16;183@Native private static final int OFFSET_HINT = 8;184@Native private static final int OFFSET_TEXTURE = 3;185@Native private static final int OFFSET_RTT = 2;186@Native private static final int OFFSET_XFORM = 1;187@Native private static final int OFFSET_ISOBLIT = 0;188189/**190* Packs the given parameters into a single int value in order to save191* space on the rendering queue.192*/193private static int createPackedParams(boolean isoblit, boolean texture,194boolean rtt, boolean xform,195int hint, int srctype)196{197return198((srctype << OFFSET_SRCTYPE) |199(hint << OFFSET_HINT ) |200((texture ? 1 : 0) << OFFSET_TEXTURE) |201((rtt ? 1 : 0) << OFFSET_RTT ) |202((xform ? 1 : 0) << OFFSET_XFORM ) |203((isoblit ? 1 : 0) << OFFSET_ISOBLIT));204}205206/**207* Enqueues a BLIT operation with the given parameters. Note that the208* RenderQueue lock must be held before calling this method.209*/210private static void enqueueBlit(RenderQueue rq,211SurfaceData src, SurfaceData dst,212int packedParams,213int sx1, int sy1,214int sx2, int sy2,215double dx1, double dy1,216double dx2, double dy2)217{218// assert rq.lock.isHeldByCurrentThread();219RenderBuffer buf = rq.getBuffer();220rq.ensureCapacityAndAlignment(72, 24);221buf.putInt(BLIT);222buf.putInt(packedParams);223buf.putInt(sx1).putInt(sy1);224buf.putInt(sx2).putInt(sy2);225buf.putDouble(dx1).putDouble(dy1);226buf.putDouble(dx2).putDouble(dy2);227buf.putLong(src.getNativeOps());228buf.putLong(dst.getNativeOps());229}230231static void Blit(SurfaceData srcData, SurfaceData dstData,232Composite comp, Region clip,233AffineTransform xform, int hint,234int sx1, int sy1,235int sx2, int sy2,236double dx1, double dy1,237double dx2, double dy2,238int srctype, boolean texture)239{240int ctxflags = 0;241if (srcData.getTransparency() == Transparency.OPAQUE) {242ctxflags |= D3DContext.SRC_IS_OPAQUE;243}244245D3DSurfaceData d3dDst = (D3DSurfaceData)dstData;246D3DRenderQueue rq = D3DRenderQueue.getInstance();247rq.lock();248try {249// make sure the RenderQueue keeps a hard reference to the250// source (sysmem) SurfaceData to prevent it from being251// disposed while the operation is processed on the QFT252rq.addReference(srcData);253254if (texture) {255// make sure we have a current context before uploading256// the sysmem data to the texture object257D3DContext.setScratchSurface(d3dDst.getContext());258} else {259D3DContext.validateContext(d3dDst, d3dDst,260clip, comp, xform, null, null,261ctxflags);262}263264int packedParams = createPackedParams(false, texture,265false, xform != null,266hint, srctype);267enqueueBlit(rq, srcData, dstData,268packedParams,269sx1, sy1, sx2, sy2,270dx1, dy1, dx2, dy2);271272// always flush immediately, since we (currently) have no means273// of tracking changes to the system memory surface274rq.flushNow();275} finally {276rq.unlock();277}278279if (d3dDst.getType() == D3DSurfaceData.WINDOW) {280// flush immediately when copying to the screen to improve281// responsiveness of applications using VI or BI backbuffers282D3DScreenUpdateManager mgr =283(D3DScreenUpdateManager)ScreenUpdateManager.getInstance();284mgr.runUpdateNow();285}286}287288/**289* Note: The srcImg and biop parameters are only used when invoked290* from the D3DBufImgOps.renderImageWithOp() method; in all other cases,291* this method can be called with null values for those two parameters,292* and they will be effectively ignored.293*/294static void IsoBlit(SurfaceData srcData, SurfaceData dstData,295BufferedImage srcImg, BufferedImageOp biop,296Composite comp, Region clip,297AffineTransform xform, int hint,298int sx1, int sy1,299int sx2, int sy2,300double dx1, double dy1,301double dx2, double dy2,302boolean texture)303{304int ctxflags = 0;305if (srcData.getTransparency() == Transparency.OPAQUE) {306ctxflags |= D3DContext.SRC_IS_OPAQUE;307}308309D3DSurfaceData d3dDst = (D3DSurfaceData)dstData;310D3DRenderQueue rq = D3DRenderQueue.getInstance();311boolean rtt = false;312rq.lock();313try {314D3DSurfaceData d3dSrc = (D3DSurfaceData)srcData;315int srctype = d3dSrc.getType();316D3DSurfaceData srcCtxData = d3dSrc;317if (srctype == D3DSurfaceData.TEXTURE) {318rtt = false;319} else {320// the source is a backbuffer, or render-to-texture321// surface; we set rtt to true to differentiate this kind322// of surface from a regular texture object323rtt = true;324}325326D3DContext.validateContext(srcCtxData, d3dDst,327clip, comp, xform, null, null,328ctxflags);329330if (biop != null) {331D3DBufImgOps.enableBufImgOp(rq, d3dSrc, srcImg, biop);332}333334int packedParams = createPackedParams(true, texture,335rtt, xform != null,336hint, 0 /*unused*/);337enqueueBlit(rq, srcData, dstData,338packedParams,339sx1, sy1, sx2, sy2,340dx1, dy1, dx2, dy2);341342if (biop != null) {343D3DBufImgOps.disableBufImgOp(rq, biop);344}345} finally {346rq.unlock();347}348349if (rtt && (d3dDst.getType() == D3DSurfaceData.WINDOW)) {350// we only have to flush immediately when copying from a351// (non-texture) surface to the screen; otherwise Swing apps352// might appear unresponsive until the auto-flush completes353D3DScreenUpdateManager mgr =354(D3DScreenUpdateManager)ScreenUpdateManager.getInstance();355mgr.runUpdateNow();356}357}358}359360class D3DSurfaceToSurfaceBlit extends Blit {361362D3DSurfaceToSurfaceBlit() {363super(D3DSurfaceData.D3DSurface,364CompositeType.AnyAlpha,365D3DSurfaceData.D3DSurface);366}367368public void Blit(SurfaceData src, SurfaceData dst,369Composite comp, Region clip,370int sx, int sy, int dx, int dy, int w, int h)371{372D3DBlitLoops.IsoBlit(src, dst,373null, null,374comp, clip, null,375AffineTransformOp.TYPE_NEAREST_NEIGHBOR,376sx, sy, sx+w, sy+h,377dx, dy, dx+w, dy+h,378false);379}380}381382class D3DSurfaceToSurfaceScale extends ScaledBlit {383384D3DSurfaceToSurfaceScale() {385super(D3DSurfaceData.D3DSurface,386CompositeType.AnyAlpha,387D3DSurfaceData.D3DSurface);388}389390public void Scale(SurfaceData src, SurfaceData dst,391Composite comp, Region clip,392int sx1, int sy1,393int sx2, int sy2,394double dx1, double dy1,395double dx2, double dy2)396{397D3DBlitLoops.IsoBlit(src, dst,398null, null,399comp, clip, null,400AffineTransformOp.TYPE_NEAREST_NEIGHBOR,401sx1, sy1, sx2, sy2,402dx1, dy1, dx2, dy2,403false);404}405}406407class D3DSurfaceToSurfaceTransform extends TransformBlit {408409D3DSurfaceToSurfaceTransform() {410super(D3DSurfaceData.D3DSurface,411CompositeType.AnyAlpha,412D3DSurfaceData.D3DSurface);413}414415public void Transform(SurfaceData src, SurfaceData dst,416Composite comp, Region clip,417AffineTransform at, int hint,418int sx, int sy, int dx, int dy,419int w, int h)420{421D3DBlitLoops.IsoBlit(src, dst,422null, null,423comp, clip, at, hint,424sx, sy, sx+w, sy+h,425dx, dy, dx+w, dy+h,426false);427}428}429430class D3DRTTSurfaceToSurfaceBlit extends Blit {431432D3DRTTSurfaceToSurfaceBlit() {433super(D3DSurfaceData.D3DSurfaceRTT,434CompositeType.AnyAlpha,435D3DSurfaceData.D3DSurface);436}437438public void Blit(SurfaceData src, SurfaceData dst,439Composite comp, Region clip,440int sx, int sy, int dx, int dy, int w, int h)441{442D3DBlitLoops.IsoBlit(src, dst,443null, null,444comp, clip, null,445AffineTransformOp.TYPE_NEAREST_NEIGHBOR,446sx, sy, sx+w, sy+h,447dx, dy, dx+w, dy+h,448true);449}450}451452class D3DRTTSurfaceToSurfaceScale extends ScaledBlit {453454D3DRTTSurfaceToSurfaceScale() {455super(D3DSurfaceData.D3DSurfaceRTT,456CompositeType.AnyAlpha,457D3DSurfaceData.D3DSurface);458}459460public void Scale(SurfaceData src, SurfaceData dst,461Composite comp, Region clip,462int sx1, int sy1,463int sx2, int sy2,464double dx1, double dy1,465double dx2, double dy2)466{467D3DBlitLoops.IsoBlit(src, dst,468null, null,469comp, clip, null,470AffineTransformOp.TYPE_NEAREST_NEIGHBOR,471sx1, sy1, sx2, sy2,472dx1, dy1, dx2, dy2,473true);474}475}476477class D3DRTTSurfaceToSurfaceTransform extends TransformBlit {478479D3DRTTSurfaceToSurfaceTransform() {480super(D3DSurfaceData.D3DSurfaceRTT,481CompositeType.AnyAlpha,482D3DSurfaceData.D3DSurface);483}484485public void Transform(SurfaceData src, SurfaceData dst,486Composite comp, Region clip,487AffineTransform at, int hint,488int sx, int sy, int dx, int dy, int w, int h)489{490D3DBlitLoops.IsoBlit(src, dst,491null, null,492comp, clip, at, hint,493sx, sy, sx+w, sy+h,494dx, dy, dx+w, dy+h,495true);496}497}498499class D3DSurfaceToSwBlit extends Blit {500501private int typeval;502503// REMIND: destination will actually be opaque/premultiplied...504D3DSurfaceToSwBlit(SurfaceType dstType, int typeval) {505super(D3DSurfaceData.D3DSurface,506CompositeType.SrcNoEa,507dstType);508this.typeval = typeval;509}510511public void Blit(SurfaceData src, SurfaceData dst,512Composite comp, Region clip,513int sx, int sy, int dx, int dy,514int w, int h)515{516D3DRenderQueue rq = D3DRenderQueue.getInstance();517rq.lock();518try {519// make sure the RenderQueue keeps a hard reference to the520// destination (sysmem) SurfaceData to prevent it from being521// disposed while the operation is processed on the QFT522rq.addReference(dst);523524RenderBuffer buf = rq.getBuffer();525D3DContext.setScratchSurface(((D3DSurfaceData)src).getContext());526527rq.ensureCapacityAndAlignment(48, 32);528buf.putInt(SURFACE_TO_SW_BLIT);529buf.putInt(sx).putInt(sy);530buf.putInt(dx).putInt(dy);531buf.putInt(w).putInt(h);532buf.putInt(typeval);533buf.putLong(src.getNativeOps());534buf.putLong(dst.getNativeOps());535536// always flush immediately537rq.flushNow();538} finally {539rq.unlock();540}541}542}543544class D3DSwToSurfaceBlit extends Blit {545546private int typeval;547548D3DSwToSurfaceBlit(SurfaceType srcType, int typeval) {549super(srcType,550CompositeType.AnyAlpha,551D3DSurfaceData.D3DSurface);552this.typeval = typeval;553}554555public void Blit(SurfaceData src, SurfaceData dst,556Composite comp, Region clip,557int sx, int sy, int dx, int dy, int w, int h)558{559D3DBlitLoops.Blit(src, dst,560comp, clip, null,561AffineTransformOp.TYPE_NEAREST_NEIGHBOR,562sx, sy, sx+w, sy+h,563dx, dy, dx+w, dy+h,564typeval, false);565}566}567568class D3DSwToSurfaceScale extends ScaledBlit {569570private int typeval;571572D3DSwToSurfaceScale(SurfaceType srcType, int typeval) {573super(srcType,574CompositeType.AnyAlpha,575D3DSurfaceData.D3DSurface);576this.typeval = typeval;577}578579public void Scale(SurfaceData src, SurfaceData dst,580Composite comp, Region clip,581int sx1, int sy1,582int sx2, int sy2,583double dx1, double dy1,584double dx2, double dy2)585{586D3DBlitLoops.Blit(src, dst,587comp, clip, null,588AffineTransformOp.TYPE_NEAREST_NEIGHBOR,589sx1, sy1, sx2, sy2,590dx1, dy1, dx2, dy2,591typeval, false);592}593}594595class D3DSwToSurfaceTransform extends TransformBlit {596597private int typeval;598599D3DSwToSurfaceTransform(SurfaceType srcType, int typeval) {600super(srcType,601CompositeType.AnyAlpha,602D3DSurfaceData.D3DSurface);603this.typeval = typeval;604}605606public void Transform(SurfaceData src, SurfaceData dst,607Composite comp, Region clip,608AffineTransform at, int hint,609int sx, int sy, int dx, int dy, int w, int h)610{611D3DBlitLoops.Blit(src, dst,612comp, clip, at, hint,613sx, sy, sx+w, sy+h,614dx, dy, dx+w, dy+h,615typeval, false);616}617}618619class D3DSwToTextureBlit extends Blit {620621private int typeval;622623D3DSwToTextureBlit(SurfaceType srcType, int typeval) {624super(srcType,625CompositeType.SrcNoEa,626D3DSurfaceData.D3DTexture);627this.typeval = typeval;628}629630public void Blit(SurfaceData src, SurfaceData dst,631Composite comp, Region clip,632int sx, int sy, int dx, int dy, int w, int h)633{634D3DBlitLoops.Blit(src, dst,635comp, clip, null,636AffineTransformOp.TYPE_NEAREST_NEIGHBOR,637sx, sy, sx+w, sy+h,638dx, dy, dx+w, dy+h,639typeval, true);640}641}642643class D3DTextureToSurfaceBlit extends Blit {644645D3DTextureToSurfaceBlit() {646super(D3DSurfaceData.D3DTexture,647CompositeType.AnyAlpha,648D3DSurfaceData.D3DSurface);649}650651public void Blit(SurfaceData src, SurfaceData dst,652Composite comp, Region clip,653int sx, int sy, int dx, int dy, int w, int h)654{655D3DBlitLoops.IsoBlit(src, dst,656null, null,657comp, clip, null,658AffineTransformOp.TYPE_NEAREST_NEIGHBOR,659sx, sy, sx+w, sy+h,660dx, dy, dx+w, dy+h,661true);662}663}664665class D3DTextureToSurfaceScale extends ScaledBlit {666667D3DTextureToSurfaceScale() {668super(D3DSurfaceData.D3DTexture,669CompositeType.AnyAlpha,670D3DSurfaceData.D3DSurface);671}672673public void Scale(SurfaceData src, SurfaceData dst,674Composite comp, Region clip,675int sx1, int sy1,676int sx2, int sy2,677double dx1, double dy1,678double dx2, double dy2)679{680D3DBlitLoops.IsoBlit(src, dst,681null, null,682comp, clip, null,683AffineTransformOp.TYPE_NEAREST_NEIGHBOR,684sx1, sy1, sx2, sy2,685dx1, dy1, dx2, dy2,686true);687}688}689690class D3DTextureToSurfaceTransform extends TransformBlit {691692D3DTextureToSurfaceTransform() {693super(D3DSurfaceData.D3DTexture,694CompositeType.AnyAlpha,695D3DSurfaceData.D3DSurface);696}697698public void Transform(SurfaceData src, SurfaceData dst,699Composite comp, Region clip,700AffineTransform at, int hint,701int sx, int sy, int dx, int dy,702int w, int h)703{704D3DBlitLoops.IsoBlit(src, dst,705null, null,706comp, clip, at, hint,707sx, sy, sx+w, sy+h,708dx, dy, dx+w, dy+h,709true);710}711}712713/**714* This general Blit implementation converts any source surface to an715* intermediate IntArgbPre surface, and then uses the more specific716* IntArgbPre->D3DSurface/Texture loop to get the intermediate717* (premultiplied) surface down to D3D using simple blit.718*/719class D3DGeneralBlit extends Blit {720721private final Blit performop;722private WeakReference srcTmp;723724D3DGeneralBlit(SurfaceType dstType,725CompositeType compType,726Blit performop)727{728super(SurfaceType.Any, compType, dstType);729this.performop = performop;730}731732public synchronized void Blit(SurfaceData src, SurfaceData dst,733Composite comp, Region clip,734int sx, int sy, int dx, int dy,735int w, int h)736{737Blit convertsrc = Blit.getFromCache(src.getSurfaceType(),738CompositeType.SrcNoEa,739SurfaceType.IntArgbPre);740741SurfaceData cachedSrc = null;742if (srcTmp != null) {743// use cached intermediate surface, if available744cachedSrc = (SurfaceData)srcTmp.get();745}746747// convert source to IntArgbPre748src = convertFrom(convertsrc, src, sx, sy, w, h,749cachedSrc, BufferedImage.TYPE_INT_ARGB_PRE);750751// copy IntArgbPre intermediate surface to D3D surface752performop.Blit(src, dst, comp, clip,7530, 0, dx, dy, w, h);754755if (src != cachedSrc) {756// cache the intermediate surface757srcTmp = new WeakReference(src);758}759}760}761762/**763* This general TransformedBlit implementation converts any source surface to an764* intermediate IntArgbPre surface, and then uses the more specific765* IntArgbPre->D3DSurface/Texture loop to get the intermediate766* (premultiplied) surface down to D3D using simple transformBlit.767*/768final class D3DGeneralTransformedBlit extends TransformBlit {769770private final TransformBlit performop;771private WeakReference<SurfaceData> srcTmp;772773D3DGeneralTransformedBlit(final TransformBlit performop) {774super(SurfaceType.Any, CompositeType.AnyAlpha,775D3DSurfaceData.D3DSurface);776this.performop = performop;777}778779@Override780public synchronized void Transform(SurfaceData src, SurfaceData dst,781Composite comp, Region clip,782AffineTransform at, int hint, int srcx,783int srcy, int dstx, int dsty, int width,784int height){785Blit convertsrc = Blit.getFromCache(src.getSurfaceType(),786CompositeType.SrcNoEa,787SurfaceType.IntArgbPre);788// use cached intermediate surface, if available789final SurfaceData cachedSrc = srcTmp != null ? srcTmp.get() : null;790// convert source to IntArgbPre791src = convertFrom(convertsrc, src, srcx, srcy, width, height, cachedSrc,792BufferedImage.TYPE_INT_ARGB_PRE);793794// transform IntArgbPre intermediate surface to D3D surface795performop.Transform(src, dst, comp, clip, at, hint, 0, 0, dstx, dsty,796width, height);797798if (src != cachedSrc) {799// cache the intermediate surface800srcTmp = new WeakReference<>(src);801}802}803}804805/*806* The following classes prohibit copying D3DSurfaces to the screen807* (the D3D->sysmem->GDI path is known to be very very slow).808*809* Note: we used to disable hw acceleration for the surafce manager associated810* with the source surface in these loops but it proved to be too cautious.811*812* In most cases d3d->screen copy happens only during some transitional813* period where the accelerated destination surface is being recreated or814* restored (for example, when Swing's backbuffer VI is copied to the screen815* but the D3DScreenSurfaceManager couldn't restore its surface).816*817* An exception is if for some reason we could not enable accelerated on-screen818* rendering for this window for some permanent reason (like window being too819* small, or a present BufferStrategy).820*821* This meant that we'd disable hw acceleration after the first failure822* completely (at least until the src image is recreated which in case of823* Swing back-buffer happens only after resize).824*825* Now we delegate to the VISM to figure out if the acceleration needs to826* be disabled or if we can wait for a while until the onscreen accelerated827* can resume (by marking the source surface lost and making sure the828* VISM has a chance to use the backup surface).829*830*/831832class D3DSurfaceToGDIWindowSurfaceBlit extends Blit {833834D3DSurfaceToGDIWindowSurfaceBlit() {835super(D3DSurfaceData.D3DSurface,836CompositeType.AnyAlpha,837GDIWindowSurfaceData.AnyGdi);838}839@Override840public void Blit(SurfaceData src, SurfaceData dst,841Composite comp, Region clip,842int sx, int sy, int dx, int dy, int w, int h)843{844// see comment above845D3DVolatileSurfaceManager.handleVItoScreenOp(src, dst);846}847848}849850class D3DSurfaceToGDIWindowSurfaceScale extends ScaledBlit {851852D3DSurfaceToGDIWindowSurfaceScale() {853super(D3DSurfaceData.D3DSurface,854CompositeType.AnyAlpha,855GDIWindowSurfaceData.AnyGdi);856}857@Override858public void Scale(SurfaceData src, SurfaceData dst,859Composite comp, Region clip,860int sx1, int sy1,861int sx2, int sy2,862double dx1, double dy1,863double dx2, double dy2)864{865// see comment above866D3DVolatileSurfaceManager.handleVItoScreenOp(src, dst);867}868}869870class D3DSurfaceToGDIWindowSurfaceTransform extends TransformBlit {871872D3DSurfaceToGDIWindowSurfaceTransform() {873super(D3DSurfaceData.D3DSurface,874CompositeType.AnyAlpha,875GDIWindowSurfaceData.AnyGdi);876}877@Override878public void Transform(SurfaceData src, SurfaceData dst,879Composite comp, Region clip,880AffineTransform at, int hint,881int sx, int sy, int dx, int dy,882int w, int h)883{884// see comment above885D3DVolatileSurfaceManager.handleVItoScreenOp(src, dst);886}887}888889890