/**
  * 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();
   }
 }
Example #2
0
  /** Performs the native GLX flip operation for the given target Component. */
  @Override
  public void flip(
      X11ComponentPeer peer,
      Component target,
      VolatileImage xBackBuffer,
      int x1,
      int y1,
      int x2,
      int y2,
      BufferCapabilities.FlipContents flipAction) {
    if (flipAction == BufferCapabilities.FlipContents.COPIED) {
      SurfaceManager vsm = SurfaceManager.getManager(xBackBuffer);
      SurfaceData sd = vsm.getPrimarySurfaceData();

      if (sd instanceof GLXVSyncOffScreenSurfaceData) {
        GLXVSyncOffScreenSurfaceData vsd = (GLXVSyncOffScreenSurfaceData) sd;
        SurfaceData bbsd = vsd.getFlipSurface();
        Graphics2D bbg = new SunGraphics2D(bbsd, Color.black, Color.white, null);
        try {
          bbg.drawImage(xBackBuffer, 0, 0, null);
        } finally {
          bbg.dispose();
        }
      } else {
        Graphics g = peer.getGraphics();
        try {
          g.drawImage(xBackBuffer, x1, y1, x2, y2, x1, y1, x2, y2, null);
        } finally {
          g.dispose();
        }
        return;
      }
    } else if (flipAction == BufferCapabilities.FlipContents.PRIOR) {
      // not supported by GLX...
      return;
    }

    OGLSurfaceData.swapBuffers(peer.getContentWindow());

    if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) {
      Graphics g = xBackBuffer.getGraphics();
      try {
        g.setColor(target.getBackground());
        g.fillRect(0, 0, xBackBuffer.getWidth(), xBackBuffer.getHeight());
      } finally {
        g.dispose();
      }
    }
  }
 /**
  * If acceleration should no longer be used for this surface. This implementation flags to the
  * manager that it should no longer attempt to re-create a D3DSurface.
  */
 void disableAccelerationForSurface() {
   if (offscreenImage != null) {
     SurfaceManager sm = SurfaceManager.getManager(offscreenImage);
     if (sm instanceof D3DVolatileSurfaceManager) {
       setSurfaceLost(true);
       ((D3DVolatileSurfaceManager) sm).setAccelerationEnabled(false);
     }
   }
 }
 /**
  * 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;
 }
 /**
  * Restores the contents of the given Image and then returns the new SurfaceData object in use by
  * the Image's SurfaceManager.
  */
 public static SurfaceData restoreContents(Image img) {
   SurfaceManager sMgr = SurfaceManager.getManager(img);
   return sMgr.restoreContents();
 }
 /**
  * Extracts the SurfaceManager from the given Image, and then returns the SurfaceData object that
  * would best be suited as the destination surface in some rendering operation.
  */
 public static SurfaceData getPrimarySurfaceData(Image img) {
   SurfaceManager sMgr = SurfaceManager.getManager(img);
   return sMgr.getPrimarySurfaceData();
 }