Ejemplo n.º 1
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();
  }
Ejemplo n.º 2
0
 private void clearBackground(final int w, final int h) {
   final Graphics g = getOnscreenGraphics(getForeground(), getBackground(), getFont());
   if (g != null) {
     try {
       if (g instanceof Graphics2D) {
         ((Graphics2D) g).setComposite(AlphaComposite.Src);
       }
       if (isTranslucent()) {
         g.setColor(nonOpaqueBackground);
         g.fillRect(0, 0, w, h);
       }
       if (!isTextured()) {
         if (g instanceof SunGraphics2D) {
           ((SunGraphics2D) g).constrain(0, 0, w, h, getRegion());
         }
         g.setColor(getBackground());
         g.fillRect(0, 0, w, h);
       }
     } finally {
       g.dispose();
     }
   }
 }