Пример #1
0
    @Override
    void restoreSurface() {
      if (!peer.isAccelCapable()) {
        throw new InvalidPipeException("Onscreen acceleration " + "disabled for this surface");
      }
      Window fsw = graphicsDevice.getFullScreenWindow();
      if (fsw != null && fsw != peer.getTarget()) {
        throw new InvalidPipeException(
            "Can't restore onscreen surface" + " when in full-screen mode");
      }
      super.restoreSurface();
      // if initialization was unsuccessful, an IPE will be thrown
      // and the surface will remain lost
      setSurfaceLost(false);

      // This is to make sure the render target is reset after this
      // surface is restored. The reason for this is that sometimes this
      // surface can be restored from multiple threads (the screen update
      // manager's thread and app's rendering thread) at the same time,
      // and when that happens the second restoration will create the
      // native resource which will not be set as render target because
      // the BufferedContext's validate method will think that since the
      // surface data object didn't change then the current render target
      // is correct and no rendering will appear on the screen.
      D3DRenderQueue rq = D3DRenderQueue.getInstance();
      rq.lock();
      try {
        getContext().invalidateContext();
      } finally {
        rq.unlock();
      }
    }
Пример #2
0
 /**
  * Initializes the appropriate D3D offscreen surface based on the value of the type parameter. If
  * the surface creation fails for any reason, an OutOfMemoryError will be thrown.
  */
 protected void initSurface() {
   // any time we create or restore the surface, recreate the raster
   synchronized (this) {
     wrn = null;
   }
   // REMIND: somewhere a puppy died
   class Status {
     boolean success = false;
   };
   final Status status = new Status();
   D3DRenderQueue rq = D3DRenderQueue.getInstance();
   rq.lock();
   try {
     rq.flushAndInvokeNow(
         new Runnable() {
           public void run() {
             status.success = initSurfaceNow();
           }
         });
     if (!status.success) {
       throw new InvalidPipeException("Error creating D3DSurface");
     }
   } finally {
     rq.unlock();
   }
 }
Пример #3
0
  static void Blit(
      SurfaceData srcData,
      SurfaceData dstData,
      Composite comp,
      Region clip,
      AffineTransform xform,
      int hint,
      int sx1,
      int sy1,
      int sx2,
      int sy2,
      double dx1,
      double dy1,
      double dx2,
      double dy2,
      int srctype,
      boolean texture) {
    int ctxflags = 0;
    if (srcData.getTransparency() == Transparency.OPAQUE) {
      ctxflags |= D3DContext.SRC_IS_OPAQUE;
    }

    D3DSurfaceData d3dDst = (D3DSurfaceData) dstData;
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
      // make sure the RenderQueue keeps a hard reference to the
      // source (sysmem) SurfaceData to prevent it from being
      // disposed while the operation is processed on the QFT
      rq.addReference(srcData);

      if (texture) {
        // make sure we have a current context before uploading
        // the sysmem data to the texture object
        D3DContext.setScratchSurface(d3dDst.getContext());
      } else {
        D3DContext.validateContext(d3dDst, d3dDst, clip, comp, xform, null, null, ctxflags);
      }

      int packedParams = createPackedParams(false, texture, false, xform != null, hint, srctype);
      enqueueBlit(rq, srcData, dstData, packedParams, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2);

      // always flush immediately, since we (currently) have no means
      // of tracking changes to the system memory surface
      rq.flushNow();
    } finally {
      rq.unlock();
    }

    if (d3dDst.getType() == D3DSurfaceData.WINDOW) {
      // flush immediately when copying to the screen to improve
      // responsiveness of applications using VI or BI backbuffers
      D3DScreenUpdateManager mgr = (D3DScreenUpdateManager) ScreenUpdateManager.getInstance();
      mgr.runUpdateNow();
    }
  }
Пример #4
0
 public Rectangle getNativeBounds() {
   D3DRenderQueue rq = D3DRenderQueue.getInstance();
   // need to lock to make sure nativeWidth and Height are consistent
   // since they are set from the render thread from the native
   // level
   rq.lock();
   try {
     // REMIND: use xyoffsets?
     return new Rectangle(nativeWidth, nativeHeight);
   } finally {
     rq.unlock();
   }
 }
Пример #5
0
  /**
   * Disposes the native resources associated with the given D3DSurfaceData (referenced by the pData
   * parameter). This method is invoked from the native Dispose() method from the Disposer thread
   * when the Java-level D3DSurfaceData object is about to go away.
   */
  static void dispose(long pData) {
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
      RenderBuffer buf = rq.getBuffer();
      rq.ensureCapacityAndAlignment(12, 4);
      buf.putInt(DISPOSE_SURFACE);
      buf.putLong(pData);

      // this call is expected to complete synchronously, so flush now
      rq.flushNow();
    } finally {
      rq.unlock();
    }
  }
Пример #6
0
  @Override
  public void flush() {
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
      RenderBuffer buf = rq.getBuffer();
      rq.ensureCapacityAndAlignment(12, 4);
      buf.putInt(FLUSH_SURFACE);
      buf.putLong(getNativeOps());

      // this call is expected to complete synchronously, so flush now
      rq.flushNow();
    } finally {
      rq.unlock();
    }
  }
Пример #7
0
    protected void setElem(final int x, final int y, final int pixel, final SurfaceData sData) {
      if (sData.isSurfaceLost()) {
        return;
      }

      D3DRenderQueue rq = D3DRenderQueue.getInstance();
      rq.lock();
      try {
        rq.flushAndInvokeNow(
            new Runnable() {
              public void run() {
                dbSetPixelNative(sData.getNativeOps(), x, y, pixel);
              }
            });
        sData.markDirty();
      } finally {
        rq.unlock();
      }
    }
Пример #8
0
    protected int getElem(final int x, final int y, final SurfaceData sData) {
      if (sData.isSurfaceLost()) {
        return 0;
      }

      int retPixel;
      D3DRenderQueue rq = D3DRenderQueue.getInstance();
      rq.lock();
      try {
        rq.flushAndInvokeNow(
            new Runnable() {
              public void run() {
                pixel = dbGetPixelNative(sData.getNativeOps(), x, y);
              }
            });
      } finally {
        retPixel = pixel;
        rq.unlock();
      }
      return retPixel;
    }
Пример #9
0
  public void Blit(
      SurfaceData src,
      SurfaceData dst,
      Composite comp,
      Region clip,
      int sx,
      int sy,
      int dx,
      int dy,
      int w,
      int h) {
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
      // make sure the RenderQueue keeps a hard reference to the
      // destination (sysmem) SurfaceData to prevent it from being
      // disposed while the operation is processed on the QFT
      rq.addReference(dst);

      RenderBuffer buf = rq.getBuffer();
      D3DContext.setScratchSurface(((D3DSurfaceData) src).getContext());

      rq.ensureCapacityAndAlignment(48, 32);
      buf.putInt(SURFACE_TO_SW_BLIT);
      buf.putInt(sx).putInt(sy);
      buf.putInt(dx).putInt(dy);
      buf.putInt(w).putInt(h);
      buf.putInt(typeval);
      buf.putLong(src.getNativeOps());
      buf.putLong(dst.getNativeOps());

      // always flush immediately
      rq.flushNow();
    } finally {
      rq.unlock();
    }
  }
Пример #10
0
 static void swapBuffers(
     D3DSurfaceData sd, final int x1, final int y1, final int x2, final int y2) {
   long pData = sd.getNativeOps();
   D3DRenderQueue rq = D3DRenderQueue.getInstance();
   // swapBuffers can be called from the toolkit thread by swing, we
   // should detect this and prevent the deadlocks
   if (rq.isRenderQueueThread()) {
     if (!rq.tryLock()) {
       // if we could not obtain the lock, repaint the area
       // that was supposed to be swapped, and no-op this swap
       final Component target = (Component) sd.getPeer().getTarget();
       SunToolkit.executeOnEventHandlerThread(
           target,
           new Runnable() {
             public void run() {
               target.repaint(x1, y1, x2, y2);
             }
           });
       return;
     }
   } else {
     rq.lock();
   }
   try {
     RenderBuffer buf = rq.getBuffer();
     rq.ensureCapacityAndAlignment(28, 4);
     buf.putInt(SWAP_BUFFERS);
     buf.putLong(pData);
     buf.putInt(x1);
     buf.putInt(y1);
     buf.putInt(x2);
     buf.putInt(y2);
     rq.flushNow();
   } finally {
     rq.unlock();
   }
 }
Пример #11
0
  /**
   * Note: The srcImg and biop parameters are only used when invoked from the
   * D3DBufImgOps.renderImageWithOp() method; in all other cases, this method can be called with
   * null values for those two parameters, and they will be effectively ignored.
   */
  static void IsoBlit(
      SurfaceData srcData,
      SurfaceData dstData,
      BufferedImage srcImg,
      BufferedImageOp biop,
      Composite comp,
      Region clip,
      AffineTransform xform,
      int hint,
      int sx1,
      int sy1,
      int sx2,
      int sy2,
      double dx1,
      double dy1,
      double dx2,
      double dy2,
      boolean texture) {
    int ctxflags = 0;
    if (srcData.getTransparency() == Transparency.OPAQUE) {
      ctxflags |= D3DContext.SRC_IS_OPAQUE;
    }

    D3DSurfaceData d3dDst = (D3DSurfaceData) dstData;
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    boolean rtt = false;
    rq.lock();
    try {
      D3DSurfaceData d3dSrc = (D3DSurfaceData) srcData;
      int srctype = d3dSrc.getType();
      D3DSurfaceData srcCtxData = d3dSrc;
      if (srctype == D3DSurfaceData.TEXTURE) {
        rtt = false;
      } else {
        // the source is a backbuffer, or render-to-texture
        // surface; we set rtt to true to differentiate this kind
        // of surface from a regular texture object
        rtt = true;
      }

      D3DContext.validateContext(srcCtxData, d3dDst, clip, comp, xform, null, null, ctxflags);

      if (biop != null) {
        D3DBufImgOps.enableBufImgOp(rq, d3dSrc, srcImg, biop);
      }

      int packedParams = createPackedParams(true, texture, rtt, xform != null, hint, 0 /*unused*/);
      enqueueBlit(rq, srcData, dstData, packedParams, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2);

      if (biop != null) {
        D3DBufImgOps.disableBufImgOp(rq, biop);
      }
    } finally {
      rq.unlock();
    }

    if (rtt && (d3dDst.getType() == D3DSurfaceData.WINDOW)) {
      // we only have to flush immediately when copying from a
      // (non-texture) surface to the screen; otherwise Swing apps
      // might appear unresponsive until the auto-flush completes
      D3DScreenUpdateManager mgr = (D3DScreenUpdateManager) ScreenUpdateManager.getInstance();
      mgr.runUpdateNow();
    }
  }