Exemplo n.º 1
0
  /**
   * Flags processing of output as finished. Updates all stats in the process.
   *
   * @param g graphics context in which processing has finished
   */
  public static void endProcessingOutput(final Graphics g) {
    processOutputTime += System.currentTimeMillis() - startProcessingOutputTime;
    framesProcessed++;

    if (framesProcessed % printResultsFrameRate == 0) {
      if (PDebug.debugPrintFrameRate) {
        System.out.println("Process output frame rate: " + getOutputFPS() + " fps");
        System.out.println("Process input frame rate: " + getInputFPS() + " fps");
        System.out.println("Total frame rate: " + getTotalFPS() + " fps");
        System.out.println();
        resetFPSTiming();
      }

      if (PDebug.debugPrintUsedMemory) {
        System.out.println("Approximate used memory: " + getApproximateUsedMemory() / 1024 + " k");
      }
    }

    if (PDebug.debugRegionManagement) {
      final Graphics2D g2 = (Graphics2D) g;
      g2.setColor(PDebug.getDebugPaintColor());
      g2.fill(g.getClipBounds().getBounds2D());
    }

    processingOutput = false;
  }
Exemplo n.º 2
0
  /**
   * Paints the region specified of the canvas onto the given Graphics Context.
   *
   * @param gc graphics onto within painting should occur
   * @param x left of the dirty region
   * @param y top of the dirty region
   * @param w width of the dirty region
   * @param h height of the dirty region
   */
  public void paintComponent(final GC gc, final int x, final int y, final int w, final int h) {
    PDebug.startProcessingOutput();

    GC imageGC = null;
    Graphics2D g2 = null;
    if (doubleBuffered) {
      imageGC = new GC(backBuffer);
      g2 = new SWTGraphics2D(imageGC, getDisplay());
    } else {
      g2 = new SWTGraphics2D(gc, getDisplay());
    }

    g2.setColor(Color.white);
    g2.setBackground(Color.white);

    final Rectangle rect = getBounds();
    g2.fillRect(0, 0, rect.width, rect.height);

    // This fixes a problem with standard debugging of region management in
    // SWT
    if (PDebug.debugRegionManagement) {
      final Rectangle r = gc.getClipping();
      final Rectangle2D r2 = new Rectangle2D.Double(r.x, r.y, r.width, r.height);
      g2.setBackground(PDebug.getDebugPaintColor());
      g2.fill(r2);
    }

    // create new paint context and set render quality
    final PPaintContext paintContext = new PPaintContext(g2);
    if (getInteracting() || getAnimating()) {
      if (interactingRenderQuality > animatingRenderQuality) {
        paintContext.setRenderQuality(interactingRenderQuality);
      } else {
        paintContext.setRenderQuality(animatingRenderQuality);
      }
    } else {
      paintContext.setRenderQuality(defaultRenderQuality);
    }

    // paint Piccolo2D
    camera.fullPaint(paintContext);

    // if switched state from animating to not animating invalidate
    // the entire screen so that it will be drawn with the default instead
    // of animating render quality.
    if (animatingOnLastPaint && !getAnimating()) {
      repaint();
    }
    animatingOnLastPaint = getAnimating();

    final boolean region = PDebug.debugRegionManagement;
    PDebug.debugRegionManagement = false;
    PDebug.endProcessingOutput(g2);
    PDebug.debugRegionManagement = region;

    if (doubleBuffered) {
      gc.drawImage(backBuffer, 0, 0);

      // Dispose of the allocated image gc
      imageGC.dispose();
    }
  }