< prev index next >

src/java.desktop/windows/classes/sun/java2d/d3d/D3DSurfaceData.java

Print this page




  46 import sun.awt.image.SurfaceManager;
  47 import sun.awt.image.WritableRasterNative;
  48 import sun.awt.windows.WComponentPeer;
  49 import sun.java2d.pipe.hw.AccelSurface;
  50 import sun.java2d.InvalidPipeException;
  51 import sun.java2d.SunGraphics2D;
  52 import sun.java2d.SurfaceData;
  53 import sun.java2d.loops.GraphicsPrimitive;
  54 import sun.java2d.loops.MaskFill;
  55 import sun.java2d.loops.SurfaceType;
  56 import sun.java2d.loops.CompositeType;
  57 import sun.java2d.pipe.ParallelogramPipe;
  58 import sun.java2d.pipe.PixelToParallelogramConverter;
  59 import sun.java2d.pipe.RenderBuffer;
  60 import sun.java2d.pipe.TextPipe;
  61 import static sun.java2d.pipe.BufferedOpCodes.*;
  62 import static sun.java2d.d3d.D3DContext.D3DContextCaps.*;
  63 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
  64 import sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType;
  65 import java.awt.BufferCapabilities.FlipContents;

  66 import java.awt.Window;

  67 import sun.awt.SunToolkit;
  68 import sun.awt.image.SunVolatileImage;

  69 import sun.java2d.ScreenUpdateManager;
  70 import sun.java2d.StateTracker;
  71 import sun.java2d.SurfaceDataProxy;
  72 import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
  73 
  74 /**
  75  * This class describes a D3D "surface", that is, a region of pixels
  76  * managed via D3D.  An D3DSurfaceData can be tagged with one of three
  77  * different SurfaceType objects for the purpose of registering loops, etc.
  78  * This diagram shows the hierarchy of D3D SurfaceTypes:
  79  *
  80  *                               Any
  81  *                             /     \
  82  *                    D3DSurface     D3DTexture
  83  *                         |
  84  *                   D3DSurfaceRTT
  85  *
  86  * D3DSurface
  87  * This kind of surface can be rendered to using D3D APIs.  It is also
  88  * possible to copy a D3DSurface to another D3DSurface (or to itself).


 145     public static final int SWAP_COPY          = 3;
 146     /*
 147      * SurfaceTypes
 148      */
 149     private static final String DESC_D3D_SURFACE = "D3D Surface";
 150     private static final String DESC_D3D_SURFACE_RTT =
 151         "D3D Surface (render-to-texture)";
 152     private static final String DESC_D3D_TEXTURE = "D3D Texture";
 153 
 154     // REMIND: regarding ArgbPre??
 155     static final SurfaceType D3DSurface =
 156         SurfaceType.Any.deriveSubType(DESC_D3D_SURFACE,
 157                                       PixelConverter.ArgbPre.instance);
 158     static final SurfaceType D3DSurfaceRTT =
 159         D3DSurface.deriveSubType(DESC_D3D_SURFACE_RTT);
 160     static final SurfaceType D3DTexture =
 161         SurfaceType.Any.deriveSubType(DESC_D3D_TEXTURE);
 162 
 163     private int type;
 164     private int width, height;


 165     // these fields are set from the native code when the surface is
 166     // initialized
 167     private int nativeWidth, nativeHeight;
 168     protected WComponentPeer peer;
 169     private Image offscreenImage;
 170     protected D3DGraphicsDevice graphicsDevice;
 171 
 172     private int swapEffect;
 173     private VSyncType syncType;
 174     private int backBuffersNum;
 175 
 176     private WritableRasterNative wrn;
 177 
 178     protected static D3DRenderer d3dRenderPipe;
 179     protected static PixelToParallelogramConverter d3dTxRenderPipe;
 180     protected static ParallelogramPipe d3dAAPgramPipe;
 181     protected static D3DTextRenderer d3dTextPipe;
 182     protected static D3DDrawImage d3dImagePipe;
 183 
 184     private native boolean initTexture(long pData, boolean isRTT,


 201             //d3dAAPgramPipe = d3dRenderPipe.traceWrap();
 202         }
 203         d3dAAPgramPipe = d3dRenderPipe.getAAParallelogramPipe();
 204         d3dTxRenderPipe =
 205             new PixelToParallelogramConverter(d3dRenderPipe, d3dRenderPipe,
 206                                               1.0, 0.25, true);
 207 
 208         D3DBlitLoops.register();
 209         D3DMaskFill.register();
 210         D3DMaskBlit.register();
 211     }
 212 
 213     protected D3DSurfaceData(WComponentPeer peer, D3DGraphicsConfig gc,
 214                              int width, int height, Image image,
 215                              ColorModel cm, int numBackBuffers,
 216                              int swapEffect, VSyncType vSyncType,
 217                              int type)
 218     {
 219         super(getCustomSurfaceType(type), cm);
 220         this.graphicsDevice = gc.getD3DDevice();


 221         this.peer = peer;
 222         this.type = type;


 223         this.width = width;
 224         this.height = height;









 225         this.offscreenImage = image;
 226         this.backBuffersNum = numBackBuffers;
 227         this.swapEffect = swapEffect;
 228         this.syncType = vSyncType;
 229 
 230         initOps(graphicsDevice.getScreen(), width, height);
 231         if (type == WINDOW) {
 232             // we put the surface into the "lost"
 233             // state; it will be restored by the D3DScreenUpdateManager
 234             // prior to rendering to it for the first time. This is done
 235             // so that vram is not wasted for surfaces never rendered to
 236             setSurfaceLost(true);
 237         } else {
 238             initSurface();
 239         }
 240         setBlitProxyKey(gc.getProxyKey());
 241     }
 242 
 243     @Override










 244     public SurfaceDataProxy makeProxyFor(SurfaceData srcData) {
 245         return D3DSurfaceDataProxy.
 246             createProxy(srcData,
 247                         (D3DGraphicsConfig)graphicsDevice.getDefaultConfiguration());
 248     }
 249 
 250     /**
 251      * Creates a SurfaceData object representing the back buffer of a
 252      * double-buffered on-screen Window.
 253      */
 254     public static D3DSurfaceData createData(WComponentPeer peer, Image image) {
 255         D3DGraphicsConfig gc = getGC(peer);
 256         if (gc == null || !peer.isAccelCapable()) {
 257             return null;
 258         }
 259         BufferCapabilities caps = peer.getBackBufferCaps();
 260         VSyncType vSyncType = VSYNC_DEFAULT;
 261         if (caps instanceof ExtendedBufferCapabilities) {
 262             vSyncType = ((ExtendedBufferCapabilities)caps).getVSync();
 263         }


 760             buf.putLong(pData);
 761             buf.putInt(x1);
 762             buf.putInt(y1);
 763             buf.putInt(x2);
 764             buf.putInt(y2);
 765             rq.flushNow();
 766         } finally {
 767             rq.unlock();
 768         }
 769     }
 770 
 771     /**
 772      * Returns destination Image associated with this SurfaceData.
 773      */
 774     public Object getDestination() {
 775         return offscreenImage;
 776     }
 777 
 778     public Rectangle getBounds() {
 779         if (type == FLIP_BACKBUFFER || type == WINDOW) {


 780             Rectangle r = peer.getBounds();
 781             r.x = r.y = 0;


 782             return r;
 783         } else {
 784             return new Rectangle(width, height);
 785         }
 786     }
 787 
 788     public Rectangle getNativeBounds() {
 789         D3DRenderQueue rq = D3DRenderQueue.getInstance();
 790         // need to lock to make sure nativeWidth and Height are consistent
 791         // since they are set from the render thread from the native
 792         // level
 793         rq.lock();
 794         try {
 795             // REMIND: use xyoffsets?
 796             return new Rectangle(nativeWidth, nativeHeight);
 797         } finally {
 798             rq.unlock();
 799         }
 800     }
 801 




  46 import sun.awt.image.SurfaceManager;
  47 import sun.awt.image.WritableRasterNative;
  48 import sun.awt.windows.WComponentPeer;
  49 import sun.java2d.pipe.hw.AccelSurface;
  50 import sun.java2d.InvalidPipeException;
  51 import sun.java2d.SunGraphics2D;
  52 import sun.java2d.SurfaceData;
  53 import sun.java2d.loops.GraphicsPrimitive;
  54 import sun.java2d.loops.MaskFill;
  55 import sun.java2d.loops.SurfaceType;
  56 import sun.java2d.loops.CompositeType;
  57 import sun.java2d.pipe.ParallelogramPipe;
  58 import sun.java2d.pipe.PixelToParallelogramConverter;
  59 import sun.java2d.pipe.RenderBuffer;
  60 import sun.java2d.pipe.TextPipe;
  61 import static sun.java2d.pipe.BufferedOpCodes.*;
  62 import static sun.java2d.d3d.D3DContext.D3DContextCaps.*;
  63 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
  64 import sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType;
  65 import java.awt.BufferCapabilities.FlipContents;
  66 import java.awt.Dimension;
  67 import java.awt.Window;
  68 import java.awt.geom.AffineTransform;
  69 import sun.awt.SunToolkit;
  70 import sun.awt.image.SunVolatileImage;
  71 import sun.awt.windows.WWindowPeer;
  72 import sun.java2d.ScreenUpdateManager;
  73 import sun.java2d.StateTracker;
  74 import sun.java2d.SurfaceDataProxy;
  75 import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
  76 
  77 /**
  78  * This class describes a D3D "surface", that is, a region of pixels
  79  * managed via D3D.  An D3DSurfaceData can be tagged with one of three
  80  * different SurfaceType objects for the purpose of registering loops, etc.
  81  * This diagram shows the hierarchy of D3D SurfaceTypes:
  82  *
  83  *                               Any
  84  *                             /     \
  85  *                    D3DSurface     D3DTexture
  86  *                         |
  87  *                   D3DSurfaceRTT
  88  *
  89  * D3DSurface
  90  * This kind of surface can be rendered to using D3D APIs.  It is also
  91  * possible to copy a D3DSurface to another D3DSurface (or to itself).


 148     public static final int SWAP_COPY          = 3;
 149     /*
 150      * SurfaceTypes
 151      */
 152     private static final String DESC_D3D_SURFACE = "D3D Surface";
 153     private static final String DESC_D3D_SURFACE_RTT =
 154         "D3D Surface (render-to-texture)";
 155     private static final String DESC_D3D_TEXTURE = "D3D Texture";
 156 
 157     // REMIND: regarding ArgbPre??
 158     static final SurfaceType D3DSurface =
 159         SurfaceType.Any.deriveSubType(DESC_D3D_SURFACE,
 160                                       PixelConverter.ArgbPre.instance);
 161     static final SurfaceType D3DSurfaceRTT =
 162         D3DSurface.deriveSubType(DESC_D3D_SURFACE_RTT);
 163     static final SurfaceType D3DTexture =
 164         SurfaceType.Any.deriveSubType(DESC_D3D_TEXTURE);
 165 
 166     private int type;
 167     private int width, height;
 168     private final double scaleX;
 169     private final double scaleY;
 170     // these fields are set from the native code when the surface is
 171     // initialized
 172     private int nativeWidth, nativeHeight;
 173     protected WComponentPeer peer;
 174     private Image offscreenImage;
 175     protected D3DGraphicsDevice graphicsDevice;
 176 
 177     private int swapEffect;
 178     private VSyncType syncType;
 179     private int backBuffersNum;
 180 
 181     private WritableRasterNative wrn;
 182 
 183     protected static D3DRenderer d3dRenderPipe;
 184     protected static PixelToParallelogramConverter d3dTxRenderPipe;
 185     protected static ParallelogramPipe d3dAAPgramPipe;
 186     protected static D3DTextRenderer d3dTextPipe;
 187     protected static D3DDrawImage d3dImagePipe;
 188 
 189     private native boolean initTexture(long pData, boolean isRTT,


 206             //d3dAAPgramPipe = d3dRenderPipe.traceWrap();
 207         }
 208         d3dAAPgramPipe = d3dRenderPipe.getAAParallelogramPipe();
 209         d3dTxRenderPipe =
 210             new PixelToParallelogramConverter(d3dRenderPipe, d3dRenderPipe,
 211                                               1.0, 0.25, true);
 212 
 213         D3DBlitLoops.register();
 214         D3DMaskFill.register();
 215         D3DMaskBlit.register();
 216     }
 217 
 218     protected D3DSurfaceData(WComponentPeer peer, D3DGraphicsConfig gc,
 219                              int width, int height, Image image,
 220                              ColorModel cm, int numBackBuffers,
 221                              int swapEffect, VSyncType vSyncType,
 222                              int type)
 223     {
 224         super(getCustomSurfaceType(type), cm);
 225         this.graphicsDevice = gc.getD3DDevice();
 226         this.scaleX = type == TEXTURE ? 1 : graphicsDevice.getDefaultScaleX();
 227         this.scaleY = type == TEXTURE ? 1 : graphicsDevice.getDefaultScaleY();
 228         this.peer = peer;
 229         this.type = type;
 230 
 231         if (scaleX == 1 && scaleY == 1) {
 232             this.width = width;
 233             this.height = height;
 234         } else if (peer instanceof WWindowPeer) {
 235             Dimension scaledSize = ((WWindowPeer) peer).getScaledWindowSize();
 236             this.width = scaledSize.width;
 237             this.height = scaledSize.height;
 238         } else {
 239             this.width = (int) Math.ceil(width * scaleX);
 240             this.height = (int) Math.ceil(height * scaleY);
 241         }
 242 
 243         this.offscreenImage = image;
 244         this.backBuffersNum = numBackBuffers;
 245         this.swapEffect = swapEffect;
 246         this.syncType = vSyncType;
 247 
 248         initOps(graphicsDevice.getScreen(), this.width, this.height);
 249         if (type == WINDOW) {
 250             // we put the surface into the "lost"
 251             // state; it will be restored by the D3DScreenUpdateManager
 252             // prior to rendering to it for the first time. This is done
 253             // so that vram is not wasted for surfaces never rendered to
 254             setSurfaceLost(true);
 255         } else {
 256             initSurface();
 257         }
 258         setBlitProxyKey(gc.getProxyKey());
 259     }
 260 
 261     @Override
 262     public double getDefaultScaleX() {
 263         return scaleX;
 264     }
 265 
 266     @Override
 267     public double getDefaultScaleY() {
 268         return scaleY;
 269     }
 270 
 271     @Override
 272     public SurfaceDataProxy makeProxyFor(SurfaceData srcData) {
 273         return D3DSurfaceDataProxy.
 274             createProxy(srcData,
 275                         (D3DGraphicsConfig)graphicsDevice.getDefaultConfiguration());
 276     }
 277 
 278     /**
 279      * Creates a SurfaceData object representing the back buffer of a
 280      * double-buffered on-screen Window.
 281      */
 282     public static D3DSurfaceData createData(WComponentPeer peer, Image image) {
 283         D3DGraphicsConfig gc = getGC(peer);
 284         if (gc == null || !peer.isAccelCapable()) {
 285             return null;
 286         }
 287         BufferCapabilities caps = peer.getBackBufferCaps();
 288         VSyncType vSyncType = VSYNC_DEFAULT;
 289         if (caps instanceof ExtendedBufferCapabilities) {
 290             vSyncType = ((ExtendedBufferCapabilities)caps).getVSync();
 291         }


 788             buf.putLong(pData);
 789             buf.putInt(x1);
 790             buf.putInt(y1);
 791             buf.putInt(x2);
 792             buf.putInt(y2);
 793             rq.flushNow();
 794         } finally {
 795             rq.unlock();
 796         }
 797     }
 798 
 799     /**
 800      * Returns destination Image associated with this SurfaceData.
 801      */
 802     public Object getDestination() {
 803         return offscreenImage;
 804     }
 805 
 806     public Rectangle getBounds() {
 807         if (type == FLIP_BACKBUFFER || type == WINDOW) {
 808             double scaleX = getDefaultScaleX();
 809             double scaleY = getDefaultScaleY();
 810             Rectangle r = peer.getBounds();
 811             r.x = r.y = 0;
 812             r.width = (int) Math.ceil(r.width * scaleX);
 813             r.height = (int) Math.ceil(r.height * scaleY);
 814             return r;
 815         } else {
 816             return new Rectangle(width, height);
 817         }
 818     }
 819 
 820     public Rectangle getNativeBounds() {
 821         D3DRenderQueue rq = D3DRenderQueue.getInstance();
 822         // need to lock to make sure nativeWidth and Height are consistent
 823         // since they are set from the render thread from the native
 824         // level
 825         rq.lock();
 826         try {
 827             // REMIND: use xyoffsets?
 828             return new Rectangle(nativeWidth, nativeHeight);
 829         } finally {
 830             rq.unlock();
 831         }
 832     }
 833 


< prev index next >