Пример #1
0
 /**
  * Enqueues a BLIT operation with the given parameters. Note that the RenderQueue lock must be
  * held before calling this method.
  */
 private static void enqueueBlit(
     RenderQueue rq,
     SurfaceData src,
     SurfaceData dst,
     int packedParams,
     int sx1,
     int sy1,
     int sx2,
     int sy2,
     double dx1,
     double dy1,
     double dx2,
     double dy2) {
   // assert rq.lock.isHeldByCurrentThread();
   RenderBuffer buf = rq.getBuffer();
   rq.ensureCapacityAndAlignment(72, 24);
   buf.putInt(BLIT);
   buf.putInt(packedParams);
   buf.putInt(sx1).putInt(sy1);
   buf.putInt(sx2).putInt(sy2);
   buf.putDouble(dx1).putDouble(dy1);
   buf.putDouble(dx2).putDouble(dy2);
   buf.putLong(src.getNativeOps());
   buf.putLong(dst.getNativeOps());
 }
  /**
   * Moves the visible location of the frame being dragged to the location specified. The means by
   * which this occurs can vary depending on the dragging algorithm being used. The actual logical
   * location of the frame might not change until <code>endDraggingFrame</code> is called.
   */
  public void dragFrame(JComponent f, int newX, int newY) {

    if (dragMode == OUTLINE_DRAG_MODE) {
      JDesktopPane desktopPane = getDesktopPane(f);
      if (desktopPane != null) {
        Graphics g = JComponent.safelyGetGraphics(desktopPane);

        g.setXORMode(Color.white);
        if (currentLoc != null) {
          g.drawRect(currentLoc.x, currentLoc.y, f.getWidth() - 1, f.getHeight() - 1);
        }
        g.drawRect(newX, newY, f.getWidth() - 1, f.getHeight() - 1);
        /* Work around for 6635462: XOR mode may cause a SurfaceLost on first use.
         * Swing doesn't expect that its XOR drawRect did
         * not complete, so believes that on re-entering at
         * the next update location, that there is an XOR rect
         * to draw out at "currentLoc". But in fact
         * it's now got a new clean surface without that rect,
         * so drawing it "out" in fact draws it on, leaving garbage.
         * So only update/set currentLoc if the draw completed.
         */
        sun.java2d.SurfaceData sData = ((sun.java2d.SunGraphics2D) g).getSurfaceData();

        if (!sData.isSurfaceLost()) {
          currentLoc = new Point(newX, newY);
        }
        g.dispose();
      }
    } else if (dragMode == FASTER_DRAG_MODE) {
      dragFrameFaster(f, newX, newY);
    } else {
      setBoundsForFrame(f, newX, newY, f.getWidth(), f.getHeight());
    }
  }
 /*     */ public void Blit(
     SurfaceData paramSurfaceData1,
     SurfaceData paramSurfaceData2,
     Composite paramComposite,
     Region paramRegion,
     int paramInt1,
     int paramInt2,
     int paramInt3,
     int paramInt4,
     int paramInt5,
     int paramInt6)
       /*     */ {
   /* 120 */ Raster localRaster1 =
       paramSurfaceData1.getRaster(paramInt1, paramInt2, paramInt5, paramInt6);
   /* 121 */ ColorModel localColorModel = paramSurfaceData1.getColorModel();
   /*     */
   /* 123 */ Raster localRaster2 =
       paramSurfaceData2.getRaster(paramInt3, paramInt4, paramInt5, paramInt6);
   /* 124 */ IntegerComponentRaster localIntegerComponentRaster =
       (IntegerComponentRaster) localRaster2;
   /* 125 */ int[] arrayOfInt1 = localIntegerComponentRaster.getDataStorage();
   /*     */
   /* 127 */ Region localRegion =
       CustomComponent.getRegionOfInterest(
           paramSurfaceData1,
           paramSurfaceData2,
           paramRegion,
           paramInt1,
           paramInt2,
           paramInt3,
           paramInt4,
           paramInt5,
           paramInt6);
   /*     */
   /* 130 */ SpanIterator localSpanIterator = localRegion.getSpanIterator();
   /*     */
   /* 132 */ Object localObject = null;
   /*     */
   /* 134 */ int i = localIntegerComponentRaster.getScanlineStride();
   /*     */
   /* 136 */ paramInt1 -= paramInt3;
   /* 137 */ paramInt2 -= paramInt4;
   /* 138 */ int[] arrayOfInt2 = new int[4];
   /* 139 */ while (localSpanIterator.nextSpan(arrayOfInt2)) {
     /* 140 */ int j =
         localIntegerComponentRaster.getDataOffset(0) + arrayOfInt2[1] * i + arrayOfInt2[0];
     /* 141 */ for (int k = arrayOfInt2[1]; k < arrayOfInt2[3]; k++) {
       /* 142 */ int m = j;
       /* 143 */ for (int n = arrayOfInt2[0]; n < arrayOfInt2[2]; n++) {
         /* 144 */ localObject =
             localRaster1.getDataElements(n + paramInt1, k + paramInt2, localObject);
         /* 145 */ arrayOfInt1[(m++)] = localColorModel.getRGB(localObject);
         /*     */ }
       /* 147 */ j += i;
       /*     */ }
     /*     */
     /*     */ }
   /*     */
   /* 152 */ localIntegerComponentRaster.markDirty();
   /*     */ }
  /**
   * Calls <code>setBoundsForFrame</code> with the new values.
   *
   * @param f the component to be resized
   * @param newX the new x-coordinate
   * @param newY the new y-coordinate
   * @param newWidth the new width
   * @param newHeight the new height
   */
  public void resizeFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) {

    if (dragMode == DEFAULT_DRAG_MODE || dragMode == FASTER_DRAG_MODE) {
      setBoundsForFrame(f, newX, newY, newWidth, newHeight);
    } else {
      JDesktopPane desktopPane = getDesktopPane(f);
      if (desktopPane != null) {
        Graphics g = JComponent.safelyGetGraphics(desktopPane);

        g.setXORMode(Color.white);
        if (currentBounds != null) {
          g.drawRect(
              currentBounds.x, currentBounds.y, currentBounds.width - 1, currentBounds.height - 1);
        }
        g.drawRect(newX, newY, newWidth - 1, newHeight - 1);

        // Work around for 6635462, see comment in dragFrame()
        sun.java2d.SurfaceData sData = ((sun.java2d.SunGraphics2D) g).getSurfaceData();
        if (!sData.isSurfaceLost()) {
          currentBounds = new Rectangle(newX, newY, newWidth, newHeight);
        }

        g.setPaintMode();
        g.dispose();
      }
    }
  }
Пример #5
0
  private void replaceSurfaceData(
      int newBackBufferCount, BufferCapabilities newBackBufferCaps, boolean blit) {
    synchronized (surfaceDataLock) {
      final SurfaceData oldData = getSurfaceData();
      surfaceData = platformWindow.replaceSurfaceData();
      // TODO: volatile image
      //        VolatileImage oldBB = backBuffer;
      BufferedImage oldBB = backBuffer;
      backBufferCount = newBackBufferCount;
      backBufferCaps = newBackBufferCaps;
      final Rectangle size = getSize();
      if (getSurfaceData() != null && oldData != getSurfaceData()) {
        clearBackground(size.width, size.height);
      }

      if (blit) {
        blitSurfaceData(oldData, getSurfaceData());
      }

      if (oldData != null && oldData != getSurfaceData()) {
        // TODO: drop oldData for D3D/WGL pipelines
        // This can only happen when this peer is being created
        oldData.flush();
      }

      // TODO: volatile image
      //        backBuffer = (VolatileImage)delegate.createBackBuffer();
      backBuffer = (BufferedImage) platformWindow.createBackBuffer();
      if (backBuffer != null) {
        Graphics g = backBuffer.getGraphics();
        try {
          Rectangle r = getBounds();
          if (g instanceof Graphics2D) {
            ((Graphics2D) g).setComposite(AlphaComposite.Src);
          }
          g.setColor(nonOpaqueBackground);
          g.fillRect(0, 0, r.width, r.height);
          if (g instanceof SunGraphics2D) {
            ((SunGraphics2D) g).constrain(0, 0, r.width, r.height, getRegion());
          }
          if (!isTextured()) {
            g.setColor(getBackground());
            g.fillRect(0, 0, r.width, r.height);
          }
          if (oldBB != null) {
            // Draw the old back buffer to the new one
            g.drawImage(oldBB, 0, 0, null);
            oldBB.flush();
          }
        } finally {
          g.dispose();
        }
      }
    }
    flushOnscreenGraphics();
  }
Пример #6
0
  // Render an image using only integer scaling (no transform).
  protected boolean renderImageScale(
      SunGraphics2D sg,
      Image img,
      Color bgColor,
      int interpType,
      int sx1,
      int sy1,
      int sx2,
      int sy2,
      double dx1,
      double dy1,
      double dx2,
      double dy2) {
    // Currently only NEAREST_NEIGHBOR interpolation is implemented
    // for ScaledBlit operations.
    if (interpType != AffineTransformOp.TYPE_NEAREST_NEIGHBOR) {
      return false;
    }

    Region clip = sg.getCompClip();
    SurfaceData dstData = sg.surfaceData;

    int attempts = 0;
    // Loop up to twice through; this gives us a chance to
    // revalidate the surfaceData objects in case of an exception
    // and try it once more
    while (true) {
      SurfaceData srcData =
          dstData.getSourceSurfaceData(img, sg.TRANSFORM_TRANSLATESCALE, sg.imageComp, bgColor);

      if (srcData == null || isBgOperation(srcData, bgColor)) {
        return false;
      }

      try {
        SurfaceType srcType = srcData.getSurfaceType();
        SurfaceType dstType = dstData.getSurfaceType();
        return scaleSurfaceData(
            sg, clip, srcData, dstData, srcType, dstType, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2);
      } catch (NullPointerException e) {
        if (!SurfaceData.isNull(dstData)) {
          // Something else caused the exception, throw it...
          throw e;
        }
        return false;
        // NOP if we have been disposed
      } catch (InvalidPipeException e) {
        // Always catch the exception; try this a couple of times
        // and fail silently if the system is not yet ready to
        // revalidate the source or dest surfaceData objects.
        ++attempts;
        clip = sg.getCompClip(); // ensures sg.surfaceData is valid
        dstData = sg.surfaceData;
        if (SurfaceData.isNull(dstData) || SurfaceData.isNull(srcData) || (attempts > 1)) {
          return false;
        }
      }
    }
  }
Пример #7
0
  public synchronized void Blit(
      SurfaceData src,
      SurfaceData dst,
      Composite comp,
      Region clip,
      int sx,
      int sy,
      int dx,
      int dy,
      int w,
      int h) {
    Blit convertsrc =
        Blit.getFromCache(src.getSurfaceType(), CompositeType.SrcNoEa, SurfaceType.IntArgbPre);

    SurfaceData cachedSrc = null;
    if (srcTmp != null) {
      // use cached intermediate surface, if available
      cachedSrc = (SurfaceData) srcTmp.get();
    }

    // convert source to IntArgbPre
    src = convertFrom(convertsrc, src, sx, sy, w, h, cachedSrc, BufferedImage.TYPE_INT_ARGB_PRE);

    // copy IntArgbPre intermediate surface to D3D surface
    performop.Blit(src, dst, comp, clip, 0, 0, dx, dy, w, h);

    if (src != cachedSrc) {
      // cache the intermediate surface
      srcTmp = new WeakReference(src);
    }
  }
Пример #8
0
  protected boolean scaleSurfaceData(
      SunGraphics2D sg,
      Region clipRegion,
      SurfaceData srcData,
      SurfaceData dstData,
      SurfaceType srcType,
      SurfaceType dstType,
      int sx1,
      int sy1,
      int sx2,
      int sy2,
      double dx1,
      double dy1,
      double dx2,
      double dy2) {
    CompositeType comp = sg.imageComp;
    if (CompositeType.SrcOverNoEa.equals(comp)
        && (srcData.getTransparency() == Transparency.OPAQUE)) {
      comp = CompositeType.SrcNoEa;
    }

    ScaledBlit blit = ScaledBlit.getFromCache(srcType, comp, dstType);
    if (blit != null) {
      blit.Scale(
          srcData, dstData, sg.composite, clipRegion, sx1, sy1, sx2, sy2, dx1, dy1, dx2, dy2);
      return true;
    }
    return false;
  }
Пример #9
0
 public synchronized RenderLoops getSolidLoops(SurfaceType stype) {
   if (solidloops == null || sTypeOrig != stype) {
     solidloops =
         SurfaceData.makeRenderLoops(SurfaceType.OpaqueColor, CompositeType.SrcNoEa, stype);
     sTypeOrig = stype;
   }
   return solidloops;
 }
Пример #10
0
 /**
  * We need to let the surface manager know that the surface is lost so that for example
  * BufferStrategy.contentsLost() returns correct result. Normally the status of contentsLost is
  * set in validate(), but in some cases (like Swing's buffer per window) we intentionally don't
  * call validate from the toolkit thread but only check for the BS status.
  */
 @Override
 public void setSurfaceLost(boolean lost) {
   super.setSurfaceLost(lost);
   if (lost && offscreenImage != null) {
     SurfaceManager sm = SurfaceManager.getManager(offscreenImage);
     sm.acceleratedSurfaceLost();
   }
 }
Пример #11
0
 @Override
 public void invalidate() {
   if (isValid()) {
     invalidateSD();
     super.invalidate();
     // peer.invalidateBackBuffer();
   }
 }
 /**
  * This method is called on a destination SurfaceData to choose the best SurfaceData from a source
  * Image for an imaging operation, with help from its SurfaceManager. The method may determine
  * that the default SurfaceData was really the best choice in the first place, or it may decide to
  * use a cached surface. Some general decisions about whether acceleration is enabled are made by
  * this method, but any decision based on the type of the source image is made in the makeProxyFor
  * method below when it comes up with the appropriate SurfaceDataProxy instance. The parameters
  * describe the type of imaging operation being performed.
  *
  * <p>If a blitProxyKey was supplied by the subclass then it is used to potentially override the
  * choice of source SurfaceData. The outline of this process is:
  *
  * <ol>
  *   <li>Image pipeline asks destSD to find an appropriate srcSD for a given source Image object.
  *   <li>destSD gets the SurfaceManager of the source Image and first retrieves the default SD
  *       from it using getPrimarySurfaceData()
  *   <li>destSD uses its "blit proxy key" (if set) to look for some cached data stored in the
  *       source SurfaceManager
  *   <li>If the cached data is null then makeProxyFor() is used to create some cached data which
  *       is stored back in the source SurfaceManager under the same key for future uses.
  *   <li>The cached data will be a SurfaceDataProxy object.
  *   <li>The SurfaceDataProxy object is then consulted to return a replacement SurfaceData object
  *       (typically a cached copy if appropriate, or the original if not).
  * </ol>
  */
 public SurfaceData getSourceSurfaceData(
     Image img, int txtype, CompositeType comp, Color bgColor) {
   SurfaceManager srcMgr = SurfaceManager.getManager(img);
   SurfaceData srcData = srcMgr.getPrimarySurfaceData();
   if (img.getAccelerationPriority() > 0.0f && blitProxyKey != null) {
     SurfaceDataProxy sdp = (SurfaceDataProxy) srcMgr.getCacheData(blitProxyKey);
     if (sdp == null || !sdp.isValid()) {
       if (srcData.getState() == State.UNTRACKABLE) {
         sdp = SurfaceDataProxy.UNCACHED;
       } else {
         sdp = makeProxyFor(srcData);
       }
       srcMgr.setCacheData(blitProxyKey, sdp);
     }
     srcData = sdp.replaceData(srcData, txtype, comp, bgColor);
   }
   return srcData;
 }
Пример #13
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();
    }
  }
Пример #14
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();
      }
    }
Пример #15
0
  @Override
  protected void disposeImpl() {
    deactivateDisplayListener();
    SurfaceData oldData = getSurfaceData();
    synchronized (surfaceDataLock) {
      surfaceData = null;
    }
    if (oldData != null) {
      oldData.invalidate();
    }
    if (isGrabbing()) {
      ungrab();
    }
    if (warningWindow != null) {
      warningWindow.dispose();
    }

    platformWindow.dispose();
    super.disposeImpl();
  }
Пример #16
0
  private void replaceSurfaceData(final boolean blit) {
    synchronized (surfaceDataLock) {
      final SurfaceData oldData = getSurfaceData();
      surfaceData = platformWindow.replaceSurfaceData();
      final Rectangle size = getSize();
      if (getSurfaceData() != null && oldData != getSurfaceData()) {
        clearBackground(size.width, size.height);
      }

      if (blit) {
        blitSurfaceData(oldData, getSurfaceData());
      }

      if (oldData != null && oldData != getSurfaceData()) {
        // TODO: drop oldData for D3D/WGL pipelines
        // This can only happen when this peer is being created
        oldData.flush();
      }
    }
    flushOnscreenGraphics();
  }
Пример #17
0
 /**
  * Need to override this method as we don't need to check for the number of copies done from
  * this image
  */
 @Override
 public SurfaceData getSourceSurfaceData(
     SurfaceData destSD, CompositeType comp, Color bgColor, boolean scale) {
   if (accelerationEnabled && (destSD != sdAccel) && isDestSurfaceAccelerated(destSD)) {
     // First, we validate the pbuffer surface if necessary and
     // then return the appropriate SurfaceData object.
     validate(destSD.getDeviceConfiguration());
     if (sdAccel != null) {
       return sdAccel;
     }
   }
   return sdDefault;
 }
Пример #18
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();
    }
  }
Пример #19
0
  // Render an image using only integer translation
  // (no scale or transform or sub-pixel interpolated translations).
  protected boolean renderImageCopy(
      SunGraphics2D sg, Image img, Color bgColor, int dx, int dy, int sx, int sy, int w, int h) {
    Region clip = sg.getCompClip();
    SurfaceData dstData = sg.surfaceData;

    int attempts = 0;
    // Loop up to twice through; this gives us a chance to
    // revalidate the surfaceData objects in case of an exception
    // and try it once more
    while (true) {
      SurfaceData srcData =
          dstData.getSourceSurfaceData(img, sg.TRANSFORM_ISIDENT, sg.imageComp, bgColor);
      if (srcData == null) {
        return false;
      }

      try {
        SurfaceType srcType = srcData.getSurfaceType();
        SurfaceType dstType = dstData.getSurfaceType();
        blitSurfaceData(
            sg, clip, srcData, dstData, srcType, dstType, sx, sy, dx, dy, w, h, bgColor);
        return true;
      } catch (NullPointerException e) {
        if (!(SurfaceData.isNull(dstData) || SurfaceData.isNull(srcData))) {
          // Something else caused the exception, throw it...
          throw e;
        }
        return false;
        // NOP if we have been disposed
      } catch (InvalidPipeException e) {
        // Always catch the exception; try this a couple of times
        // and fail silently if the system is not yet ready to
        // revalidate the source or dest surfaceData objects.
        ++attempts;
        clip = sg.getCompClip(); // ensures sg.surfaceData is valid
        dstData = sg.surfaceData;
        if (SurfaceData.isNull(dstData) || SurfaceData.isNull(srcData) || (attempts > 1)) {
          return false;
        }
      }
    }
  }
Пример #20
0
 protected void blitSurfaceData(
     SunGraphics2D sg,
     Region clipRegion,
     SurfaceData srcData,
     SurfaceData dstData,
     SurfaceType srcType,
     SurfaceType dstType,
     int sx,
     int sy,
     int dx,
     int dy,
     int w,
     int h,
     Color bgColor) {
   if (w <= 0 || h <= 0) {
     /*
      * Fix for bugid 4783274 - BlitBg throws an exception for
      * a particular set of anomalous parameters.
      * REMIND: The native loops do proper clipping and would
      * detect this situation themselves, but the Java loops
      * all seem to trust their parameters a little too well
      * to the point where they will try to process a negative
      * area of pixels and throw exceptions.  The real fix is
      * to modify the Java loops to do proper clipping so that
      * they can deal with negative dimensions as well as
      * improperly large dimensions, but that fix is too risky
      * to integrate for Mantis at this point.  In the meantime
      * eliminating the negative or zero dimensions here is
      * "correct" and saves them from some nasty exceptional
      * conditions, one of which is the test case of 4783274.
      */
     return;
   }
   CompositeType comp = sg.imageComp;
   if (CompositeType.SrcOverNoEa.equals(comp)
       && (srcData.getTransparency() == Transparency.OPAQUE
           || (bgColor != null && bgColor.getTransparency() == Transparency.OPAQUE))) {
     comp = CompositeType.SrcNoEa;
   }
   if (!isBgOperation(srcData, bgColor)) {
     Blit blit = Blit.getFromCache(srcType, comp, dstType);
     blit.Blit(srcData, dstData, sg.composite, clipRegion, sx, sy, dx, dy, w, h);
   } else {
     BlitBg blit = BlitBg.getFromCache(srcType, comp, dstType);
     blit.BlitBg(
         srcData, dstData, sg.composite, clipRegion, bgColor.getRGB(), sx, sy, dx, dy, w, h);
   }
 }
Пример #21
0
 private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
   // TODO blit. proof-of-concept
   if (src != dst
       && src != null
       && dst != null
       && !(dst instanceof NullSurfaceData)
       && !(src instanceof NullSurfaceData)
       && src.getSurfaceType().equals(dst.getSurfaceType())
       && src.getDefaultScale() == dst.getDefaultScale()) {
     final Rectangle size = src.getBounds();
     final Blit blit = Blit.locate(src.getSurfaceType(), CompositeType.Src, dst.getSurfaceType());
     if (blit != null) {
       blit.Blit(src, dst, AlphaComposite.Src, null, 0, 0, 0, 0, size.width, size.height);
     }
   }
 }
Пример #22
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;
    }
Пример #23
0
  public void validatePipe(SunGraphics2D sg2d) {
    if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON
        && sg2d.paintState <= SunGraphics2D.PAINT_ALPHACOLOR
        && (sg2d.compositeState <= SunGraphics2D.COMP_ISCOPY
            || sg2d.compositeState == SunGraphics2D.COMP_XOR)) {
      if (sg2d.clipState == SunGraphics2D.CLIP_SHAPE) {
        // Do this to init textpipe correctly; we will override the
        // other non-text pipes below
        // REMIND: we should clean this up eventually instead of
        // having this work duplicated.
        super.validatePipe(sg2d);
      } else {
        switch (sg2d.textAntialiasHint) {
          case SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT:
            /* equate DEFAULT to OFF which it is for us */
          case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
            sg2d.textpipe = solidTextRenderer;
            break;

          case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
            sg2d.textpipe = aaTextRenderer;
            break;

          default:
            switch (sg2d.getFontInfo().aaHint) {
              case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
              case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
                sg2d.textpipe = lcdTextRenderer;
                break;

              case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
                sg2d.textpipe = aaTextRenderer;
                break;

              default:
                sg2d.textpipe = solidTextRenderer;
            }
        }
      }
      sg2d.imagepipe = imagepipe;
      if (sg2d.transformState >= SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
        sg2d.drawpipe = gdiTxPipe;
        sg2d.fillpipe = gdiTxPipe;
      } else if (sg2d.strokeState != SunGraphics2D.STROKE_THIN) {
        sg2d.drawpipe = gdiTxPipe;
        sg2d.fillpipe = gdiPipe;
      } else {
        sg2d.drawpipe = gdiPipe;
        sg2d.fillpipe = gdiPipe;
      }
      sg2d.shapepipe = gdiPipe;
      // This is needed for AA text.
      // Note that even a SolidTextRenderer can dispatch AA text
      // if a GlyphVector overrides the AA setting.
      // We use getRenderLoops() rather than setting solidloops
      // directly so that we get the appropriate loops in XOR mode.
      if (sg2d.loops == null) {
        // assert(some pipe will always be a LoopBasedPipe)
        sg2d.loops = getRenderLoops(sg2d);
      }
    } else {
      super.validatePipe(sg2d);
    }
  }
Пример #24
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();
    }
  }
Пример #25
0
 protected static boolean isBgOperation(SurfaceData srcData, Color bgColor) {
   // If we cannot get the srcData, then cannot assume anything about
   // the image
   return ((srcData == null)
       || ((bgColor != null) && (srcData.getTransparency() != Transparency.OPAQUE)));
 }
Пример #26
0
  public void validatePipe(SunGraphics2D sg2d) {
    TextPipe textpipe;
    boolean validated = false;

    // REMIND: the D3D pipeline doesn't support XOR!, more
    // fixes will be needed below. For now we disable D3D rendering
    // for the surface which had any XOR rendering done to.
    if (sg2d.compositeState >= sg2d.COMP_XOR) {
      super.validatePipe(sg2d);
      sg2d.imagepipe = d3dImagePipe;
      disableAccelerationForSurface();
      return;
    }

    // D3DTextRenderer handles both AA and non-AA text, but
    // only works with the following modes:
    // (Note: For LCD text we only enter this code path if
    // canRenderLCDText() has already validated that the mode is
    // CompositeType.SrcNoEa (opaque color), which will be subsumed
    // by the CompositeType.SrcNoEa (any color) test below.)

    if (
    /* CompositeType.SrcNoEa (any color) */
    (sg2d.compositeState <= sg2d.COMP_ISCOPY && sg2d.paintState <= sg2d.PAINT_ALPHACOLOR)
        ||

        /* CompositeType.SrcOver (any color) */
        (sg2d.compositeState == sg2d.COMP_ALPHA
            && sg2d.paintState <= sg2d.PAINT_ALPHACOLOR
            && (((AlphaComposite) sg2d.composite).getRule() == AlphaComposite.SRC_OVER))
        ||

        /* CompositeType.Xor (any color) */
        (sg2d.compositeState == sg2d.COMP_XOR && sg2d.paintState <= sg2d.PAINT_ALPHACOLOR)) {
      textpipe = d3dTextPipe;
    } else {
      // do this to initialize textpipe correctly; we will attempt
      // to override the non-text pipes below
      super.validatePipe(sg2d);
      textpipe = sg2d.textpipe;
      validated = true;
    }

    PixelToParallelogramConverter txPipe = null;
    D3DRenderer nonTxPipe = null;

    if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
      if (sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) {
        if (sg2d.compositeState <= sg2d.COMP_XOR) {
          txPipe = d3dTxRenderPipe;
          nonTxPipe = d3dRenderPipe;
        }
      } else if (sg2d.compositeState <= sg2d.COMP_ALPHA) {
        if (D3DPaints.isValid(sg2d)) {
          txPipe = d3dTxRenderPipe;
          nonTxPipe = d3dRenderPipe;
        }
        // custom paints handled by super.validatePipe() below
      }
    } else {
      if (sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) {
        if (graphicsDevice.isCapPresent(CAPS_AA_SHADER)
            && (sg2d.imageComp == CompositeType.SrcOverNoEa
                || sg2d.imageComp == CompositeType.SrcOver)) {
          if (!validated) {
            super.validatePipe(sg2d);
            validated = true;
          }
          PixelToParallelogramConverter aaConverter =
              new PixelToParallelogramConverter(
                  sg2d.shapepipe, d3dAAPgramPipe, 1.0 / 8.0, 0.499, false);
          sg2d.drawpipe = aaConverter;
          sg2d.fillpipe = aaConverter;
          sg2d.shapepipe = aaConverter;
        } else if (sg2d.compositeState == sg2d.COMP_XOR) {
          // install the solid pipes when AA and XOR are both enabled
          txPipe = d3dTxRenderPipe;
          nonTxPipe = d3dRenderPipe;
        }
      }
      // other cases handled by super.validatePipe() below
    }

    if (txPipe != null) {
      if (sg2d.transformState >= sg2d.TRANSFORM_TRANSLATESCALE) {
        sg2d.drawpipe = txPipe;
        sg2d.fillpipe = txPipe;
      } else if (sg2d.strokeState != sg2d.STROKE_THIN) {
        sg2d.drawpipe = txPipe;
        sg2d.fillpipe = nonTxPipe;
      } else {
        sg2d.drawpipe = nonTxPipe;
        sg2d.fillpipe = nonTxPipe;
      }
      // Note that we use the transforming pipe here because it
      // will examine the shape and possibly perform an optimized
      // operation if it can be simplified.  The simplifications
      // will be valid for all STROKE and TRANSFORM types.
      sg2d.shapepipe = txPipe;
    } else {
      if (!validated) {
        super.validatePipe(sg2d);
      }
    }

    // install the text pipe based on our earlier decision
    sg2d.textpipe = textpipe;

    // always override the image pipe with the specialized D3D pipe
    sg2d.imagepipe = d3dImagePipe;
  }
Пример #27
0
  protected void renderImageXform(
      SunGraphics2D sg,
      Image img,
      AffineTransform tx,
      int interpType,
      int sx1,
      int sy1,
      int sx2,
      int sy2,
      Color bgColor) {
    Region clip = sg.getCompClip();
    SurfaceData dstData = sg.surfaceData;
    SurfaceData srcData =
        dstData.getSourceSurfaceData(img, sg.TRANSFORM_GENERIC, sg.imageComp, bgColor);

    if (srcData == null) {
      img = getBufferedImage(img);
      srcData = dstData.getSourceSurfaceData(img, sg.TRANSFORM_GENERIC, sg.imageComp, bgColor);
      if (srcData == null) {
        // REMIND: Is this correct?  Can this happen?
        return;
      }
    }

    if (isBgOperation(srcData, bgColor)) {
      // We cannot perform bg operations during transform so make
      // an opaque temp image with the appropriate background
      // and work from there.
      img = makeBufferedImage(img, bgColor, BufferedImage.TYPE_INT_RGB, sx1, sy1, sx2, sy2);
      // Temp image has appropriate subimage at 0,0 now.
      sx2 -= sx1;
      sy2 -= sy1;
      sx1 = sy1 = 0;

      srcData = dstData.getSourceSurfaceData(img, sg.TRANSFORM_GENERIC, sg.imageComp, bgColor);
    }

    SurfaceType srcType = srcData.getSurfaceType();
    TransformHelper helper = TransformHelper.getFromCache(srcType);

    if (helper == null) {
      /* We have no helper for this source image type.
       * But we know that we do have helpers for both RGB and ARGB,
       * so convert to one of those types depending on transparency.
       * ARGB_PRE might be a better choice if the source image has
       * alpha, but it may cause some recursion here since we only
       * tend to have converters that convert to ARGB.
       */
      int type =
          ((srcData.getTransparency() == Transparency.OPAQUE)
              ? BufferedImage.TYPE_INT_RGB
              : BufferedImage.TYPE_INT_ARGB);
      img = makeBufferedImage(img, null, type, sx1, sy1, sx2, sy2);
      // Temp image has appropriate subimage at 0,0 now.
      sx2 -= sx1;
      sy2 -= sy1;
      sx1 = sy1 = 0;

      srcData = dstData.getSourceSurfaceData(img, sg.TRANSFORM_GENERIC, sg.imageComp, null);
      srcType = srcData.getSurfaceType();
      helper = TransformHelper.getFromCache(srcType);
      // assert(helper != null);
    }

    AffineTransform itx;
    try {
      itx = tx.createInverse();
    } catch (NoninvertibleTransformException e) {
      // Non-invertible transform means no output
      return;
    }

    /*
     * Find the maximum bounds on the destination that will be
     * affected by the transformed source.  First, transform all
     * four corners of the source and then min and max the resulting
     * destination coordinates of the transformed corners.
     * Note that tx already has the offset to sx1,sy1 accounted
     * for so we use the box (0, 0, sx2-sx1, sy2-sy1) as the
     * source coordinates.
     */
    double coords[] = new double[8];
    /* corner:  UL      UR      LL      LR   */
    /* index:  0  1    2  3    4  5    6  7  */
    /* coord: (0, 0), (w, 0), (0, h), (w, h) */
    coords[2] = coords[6] = sx2 - sx1;
    coords[5] = coords[7] = sy2 - sy1;
    tx.transform(coords, 0, coords, 0, 4);
    double ddx1, ddy1, ddx2, ddy2;
    ddx1 = ddx2 = coords[0];
    ddy1 = ddy2 = coords[1];
    for (int i = 2; i < coords.length; i += 2) {
      double d = coords[i];
      if (ddx1 > d) ddx1 = d;
      else if (ddx2 < d) ddx2 = d;
      d = coords[i + 1];
      if (ddy1 > d) ddy1 = d;
      else if (ddy2 < d) ddy2 = d;
    }
    int dx1 = (int) Math.floor(ddx1);
    int dy1 = (int) Math.floor(ddy1);
    int dx2 = (int) Math.ceil(ddx2);
    int dy2 = (int) Math.ceil(ddy2);

    SurfaceType dstType = dstData.getSurfaceType();
    MaskBlit maskblit;
    Blit blit;
    if (sg.compositeState <= sg.COMP_ALPHA) {
      /* NOTE: We either have, or we can make,
       * a MaskBlit for any alpha composite type
       */
      maskblit = MaskBlit.getFromCache(SurfaceType.IntArgbPre, sg.imageComp, dstType);

      /* NOTE: We can only use the native TransformHelper
       * func to go directly to the dest if both the helper
       * and the MaskBlit are native.
       * All helpers are native at this point, but some MaskBlit
       * objects are implemented in Java, so we need to check.
       */
      if (maskblit.getNativePrim() != 0) {
        // We can render directly.
        helper.Transform(
            maskblit,
            srcData,
            dstData,
            sg.composite,
            clip,
            itx,
            interpType,
            sx1,
            sy1,
            sx2,
            sy2,
            dx1,
            dy1,
            dx2,
            dy2,
            null,
            0,
            0);
        return;
      }
      blit = null;
    } else {
      /* NOTE: We either have, or we can make,
       * a Blit for any composite type, even Custom
       */
      maskblit = null;
      blit = Blit.getFromCache(SurfaceType.IntArgbPre, sg.imageComp, dstType);
    }

    // We need to transform to a temp image and then copy
    // just the pieces that are valid data to the dest.
    BufferedImage tmpimg = new BufferedImage(dx2 - dx1, dy2 - dy1, BufferedImage.TYPE_INT_ARGB);
    SurfaceData tmpData = SurfaceData.getPrimarySurfaceData(tmpimg);
    SurfaceType tmpType = tmpData.getSurfaceType();
    MaskBlit tmpmaskblit =
        MaskBlit.getFromCache(SurfaceType.IntArgbPre, CompositeType.SrcNoEa, tmpType);
    /*
     * The helper function fills a temporary edges buffer
     * for us with the bounding coordinates of each scanline
     * in the following format:
     *
     * edges[0, 1] = [top y, bottom y)
     * edges[2, 3] = [left x, right x) of top row
     * ...
     * edges[h*2, h*2+1] = [left x, right x) of bottom row
     *
     * all coordinates in the edges array will be relative to dx1, dy1
     *
     * edges thus has to be h*2+2 in length
     */
    int edges[] = new int[(dy2 - dy1) * 2 + 2];
    // It is important that edges[0]=edges[1]=0 when we call
    // Transform in case it must return early and we would
    // not want to render anything on an error condition.
    helper.Transform(
        tmpmaskblit,
        srcData,
        tmpData,
        AlphaComposite.Src,
        null,
        itx,
        interpType,
        sx1,
        sy1,
        sx2,
        sy2,
        0,
        0,
        dx2 - dx1,
        dy2 - dy1,
        edges,
        dx1,
        dy1);

    /*
     * Now copy the results, scanline by scanline, into the dest.
     * The edges array helps us minimize the work.
     */
    int index = 2;
    for (int y = edges[0]; y < edges[1]; y++) {
      int relx1 = edges[index++];
      int relx2 = edges[index++];
      if (relx1 >= relx2) {
        continue;
      }
      if (maskblit != null) {
        maskblit.MaskBlit(
            tmpData,
            dstData,
            sg.composite,
            clip,
            relx1,
            y,
            dx1 + relx1,
            dy1 + y,
            relx2 - relx1,
            1,
            null,
            0,
            0);
      } else {
        blit.Blit(
            tmpData, dstData, sg.composite, clip, relx1, y, dx1 + relx1, dy1 + y, relx2 - relx1, 1);
      }
    }
  }