Java 类java.awt.image.BufferStrategy 实例源码

项目:Lunar    文件:Game.java   
/**
 * Draw all game objects.
 */

private void onDraw() {
    BufferStrategy frameStrategy = frame.getBufferStrategy();
    if (frameStrategy == null) {
        // create the buffer strategy, its null.
        frame.createBufferStrategy(3);
        frameStrategy = frame.getBufferStrategy();
    }
    // clear and get our graphics object.
    graphics = frameStrategy.getDrawGraphics();
    graphics.clearRect(0, 0, width, height);

    if (showFPS) {
        graphics.setColor(Color.red);
        graphics.drawString(Integer.toString(fps) + " fps", 50, 50);
    }

    // update stack.
    stack.forEach(state -> state.onDraw(graphics));

    graphics.dispose();
    frameStrategy.show();

}
项目:KingdomKing    文件:Game.java   
public void render() {
    //creates place for image to be rendered behind screen then shown
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
        createBufferStrategy(3); //3 "screens"
        return;
    }

    screen.clear();
    int xScroll = player.x - screen.width / 2;
    int yScroll = player.y - screen.height / 2;
    level.render(xScroll, yScroll, screen);
    player.render(screen);

    for (int i = 0; i < pixels.length; i++) {
        pixels[i] = screen.pixels[i];
    }

    Graphics g = bs.getDrawGraphics(); //linking buffer with graphics
    g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
    g.setColor(Color.WHITE);
    g.setFont(new Font("Verdena", 0, 20));
    g.drawString("X: " + (player.x >> 4) + ", Y: " + (player.y >> 4), 0, 16);
    g.dispose(); //remove graphics that are not used
    bs.show(); //swapping out the buffers
}
项目:jvb    文件:MergedScreen.java   
@Override
public void update(RenderedFrame left, RenderedFrame right, DebugDrawer debugDrawer) {
    this.requestFocusInWindow();
    BufferStrategy bufferStrategy = getBufferStrategy();
    if (bufferStrategy == null) {
        createBufferStrategy(2);
        bufferStrategy = getBufferStrategy();
    }
    for (int row = 0; row < Screen.HEIGHT; row++) {
        for (int col = 0; col < Screen.WIDTH; col++) {
            imageData[col + Screen.WIDTH * row] = (left.getPixel(row, col) & 0xff) << 16 | (right.getPixel(row, col) & 0xff);
        }
    }
    Graphics g = bufferStrategy.getDrawGraphics();
    g.drawImage(bufferedImage, 0, 0, Screen.WIDTH * SCALE, Screen.HEIGHT * SCALE, null);
    if (debugDrawer != null) {
        debugDrawer.drawDebug(g, SCALE);
    }
    g.dispose();
    bufferStrategy.show();
}
项目:AutoDrivingCarUsingNeuronNetwork    文件:CarDemo.java   
private void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
        createBufferStrategy(3);
        return;
    }
    Graphics2D g = (Graphics2D) bs.getDrawGraphics();
    screen.setGraphic(g);
    entityManager.renderByPixels(screen);
    for (int i = 0; i < pixels.length; i++) {
        pixels[i] = screen.getPixels()[i];
    }
    g.setStroke(new BasicStroke(2));
    g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
    entityManager.renderByGraphics(screen);
    screen.dispose();
    bs.show();
}
项目:DungeonRun2    文件:Game.java   
private void render() {
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null) {
        createBufferStrategy(3);
        return;
    }
    screen.clear(ColorUtil.toARGBColor(Color.BLACK));
    gsm.render(screen);

    for (int i = 0; i < screen.getWidth() * screen.getHeight(); i++) {
        pixels[i] = screen.getPixels()[i];
    }

    Graphics g = bs.getDrawGraphics();
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, this.getWidth(), this.getHeight());
    if (settings.fullscreen) {
        g.drawImage(img, fullScreenXOff, fullScreenYOff, fullScreenImageWidth, fullScreenImageHeight, null);
    } else {
        g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), null);
    }
    g.dispose();
    bs.show();
}
项目:PhET    文件:OffscreenCanvasExample.java   
/**
 * Render offscreen graphics into the frame.
 */
private void render() {
    final BufferStrategy bufferStrategy = frame.getBufferStrategy();
    do {
        do {
            final Graphics2D graphics = (Graphics2D) bufferStrategy.getDrawGraphics();
            // canvas is not opaque, so fill with background color
            graphics.setPaint(background);
            graphics.fillRect(0, 0, 400, 400);
            // then let canvas render into graphics
            canvas.render(graphics);
            graphics.dispose();
        } while (bufferStrategy.contentsRestored());
        bufferStrategy.show();
    } while (bufferStrategy.contentsLost());
}
项目:DataVec    文件:DrawReconstruction.java   
public void start() {


        int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
        boolean running = true;
        while (running) {
            BufferStrategy bs = frame.getBufferStrategy();
            if (bs == null) {
                frame.createBufferStrategy(4);
                return;
            }
            for (int i = 0; i < width * height; i++)
                pixels[i] = 0;

            Graphics g = bs.getDrawGraphics();
            g.drawImage(img, heightOffset, widthOffset, width, height, null);
            g.dispose();
            bs.show();

        }
    }
项目:marshmallow    文件:Game.java   
private void render(){
    BufferStrategy bs = this.getBufferStrategy();
    if(bs == null){
        this.createBufferStrategy(3);
        return;
    }
    Graphics g = bs.getDrawGraphics();
    drawBackground(g); //TODO: fix it up? Background Images
    handler.render(g);
    if(gameState == STATE.Game){
        hud.render(g);  
        gun.render(g);
    }else if (gameState != STATE.Game){
        handler.clear();
        menu.render(g);
    }
    g.dispose();
    bs.show();
}
项目:OriginalSpaceShooter    文件:Game.java   
private void render() {
    BufferStrategy gameBS = this.getBufferStrategy();
    if (gameBS == null) {
        this.createBufferStrategy(3);
        return;
    }
    Graphics gameG = gameBS.getDrawGraphics();

    ///////////////DRAW GRAPHICS///////////////////
    gameG.setColor(Color.black); //TODO Replace Background Color with a Background Picture
    gameG.fillRect(0, 0, getWidth(), getHeight()); //background size
    handler.render(gameG);

    gameG.setColor(Color.white);
    gameG.drawString("| SCORE: " +
            handler.getScore() + " | HEALTH: " +
            handler.getHealth() + " | LEVEL: " +
            handler.getLevel() + " | MONEY: " +
            handler.getMoney() + " |", 15, 15);
    /////////////////////////////////////////////

    gameG.dispose();
    gameBS.show();
}
项目:Firestorm    文件:Game.java   
private void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
        createBufferStrategy(3);
        return;
    }

    Graphics g = bs.getDrawGraphics();
    Graphics2D g2d = (Graphics2D) g;
    // At least on Ubuntu we seem not to need to translate the canvas
    if(!Util.isUnix())
        g2d.translate(-6, -28);
    ////////////////////////////////////////////////

    g2d.setColor(Color.BLACK);
    g2d.fillRect(0, 0, WIDTH, HEIGHT);

    stateManager.render(g2d);

    ////////////////////////////////////////////////
    g.dispose();
    bs.show();
}
项目:piccolo2d.java    文件:OffscreenCanvasExample.java   
/**
 * Render offscreen graphics into the frame.
 */
private void render() {
    final BufferStrategy bufferStrategy = frame.getBufferStrategy();
    do {
        do {
            final Graphics2D graphics = (Graphics2D) bufferStrategy.getDrawGraphics();
            // canvas is not opaque, so fill with background color
            graphics.setPaint(background);
            graphics.fillRect(0, 0, 400, 400);
            // then let canvas render into graphics
            canvas.render(graphics);
            graphics.dispose();
        } while (bufferStrategy.contentsRestored());
        bufferStrategy.show();
    } while (bufferStrategy.contentsLost());
}
项目:JBomberman    文件:GameCanvas.java   
/**
 * Kümmert sich um die BufferStrategy und delegiert das 
 * zeichnen der Sprites direkt an die Sprites selbst.
 * 
 */
public void render() {
    BufferStrategy bs = getBufferStrategy();
    if(bs == null) {
        try {
        createBufferStrategy(3);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return;
    }

    Graphics g = bs.getDrawGraphics();
    game.drawAll(image.getGraphics());
    g.drawImage(image, 0, 0, getWidth(), getHeight(), null);

    g.dispose();
    bs.show();
}
项目:aritzh    文件:CanvasEngine.java   
@Override
public void render() {
    if (!running) return;

    BufferStrategy bs = canvas.getBufferStrategy();
    if (bs == null) {
        canvas.createBufferStrategy(3);
        return;
    }
    Graphics g = bs.getDrawGraphics();

    g.setColor(Color.BLACK);
    g.fillRect(0, 0, this.size.width, this.size.height);

    this.graphics = g;

    this.getGame().onRender();
    this.getGame().onPostRender();

    this.graphics = null;

    g.dispose();
    bs.show();
}
项目:StickJumper    文件:Game.java   
private void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
        createBufferStrategy(3);
        return;
    }
    Graphics g = bs.getDrawGraphics();
    if (state == GameState.LOADING) LoadScreen.render(g);
    if (state == GameState.MENU) menu.render(g);
    if (state == GameState.CREDITS) credits.render(g);
    if (state == GameState.ABOUT) about.render(g);
    if (state == GameState.CONTROLS) controlScreen.render(g);
    if (state == GameState.GAMEOVER) endScreen.render(g);
    renderGame(g);
    g.dispose();
    bs.show();
}
项目:Dystopia    文件:DystopiaCanvas.java   
public void render() {
    BufferStrategy bs = this.getBufferStrategy();

    if (bs == null) {
        this.createBufferStrategy(DystopiaCanvas.BUFFERS);
        this.requestFocus();
        return;
    }

    Graphics2D g = (Graphics2D) bs.getDrawGraphics();

    g.setColor(new Color(0xEEEEEE));
    g.fillRect(0, 0, DisplayCarrier.getCanvas().getWidth(), DisplayCarrier.getCanvas().getHeight());
    GridDisplay.drawGrid(g);
    Rectangle2D rect = new Rectangle2D.Double(DisplayCarrier.getCanvas().getWidth() / 2 - Tile.getTileSize(), DisplayCarrier.getCanvas().getHeight() / 2 - Tile.getTileSize(), Tile.getTileSize() * 2, Tile.getTileSize() * 2);
    g.draw(rect);
    PlayerCamera.drawPlayer(g);

       g.dispose();

       if (!bs.contentsLost()) {
        bs.show();
       }
       Toolkit.getDefaultToolkit().sync();
}
项目:org.dayflower    文件:ProgressUpdateFutureImpl.java   
private void doPaint(String status, int percent) {
    try {
        int width = (int)(jFrame.getWidth() / 1.5D);
        int height = 30;
        int x = (jFrame.getWidth() - width) / 2;
        int y = jFrame.getHeight() - (50 + height);

        BufferStrategy bufferStrategy = jFrame.getBufferStrategy();

        Graphics graphics = bufferStrategy.getDrawGraphics();

        Graphics2D graphics2D = Graphics2D.class.cast(graphics);
        graphics2D.setColor(Color.BLACK);
        graphics2D.fillRect(0, 0, jFrame.getWidth(), jFrame.getHeight());

        doPaintBackground(graphics2D, x, y, width, height);
        doPaintForeground(graphics2D, x, y, width, height, status, percent);

        graphics2D.dispose();
    } catch(IllegalStateException e) {

    }
}
项目:rabbit-escape    文件:SwingGraphics.java   
public DrawFrame(
    BufferStrategy strategy,
    java.awt.Canvas canvas,
    Renderer<SwingBitmap, SwingPaint> renderer,
    SoundPlayer soundPlayer,
    SpriteAnimator animator,
    int frameNum,
    World world,
    WaterAnimation waterAnimation
)
{
    super( strategy );
    this.canvas = canvas;
    this.renderer = renderer;
    this.soundPlayer = soundPlayer;
    this.animator = animator;
    this.frameNum = frameNum;
    this.world = world;
    this.waterAnimation = waterAnimation;
}
项目:SuperSquirrel    文件:Game.java   
private void render() {
    BufferStrategy bs = this.getBufferStrategy();
    if (bs == null) {
        this.createBufferStrategy(3);
        return;
    }
    Graphics g = bs.getDrawGraphics();
    Graphics2D g2d = (Graphics2D) g;

    /////////// Drawing begins;
    g.setColor(new Color(25, 191, 224));  // background color
    g.fillRect(0, 0, getWidth(), getHeight()); // Fill
    for (int i = 0; i < (level.getWidth() * scale) / (tex.cloud.getWidth() / 2); i++) { // Clouds
        g.drawImage(tex.cloud, (int)-cam.getX()/2 + ((tex.cloud.getWidth()/3) * i), (i % 3) * (i % 4) * 10, tex.cloud.getWidth()/2, tex.cloud.getHeight()/2, null);
    }
    g2d.translate(-cam.getX(), -cam.getY()); // Cam Begins 
    handler.render(g); // Object rendering
    g2d.translate(cam.getX(), cam.getY()); // Cam Ends

    hud.render(g); // Draw HUD
    /////////// Drawing ends;

    g.dispose();
    bs.show();
}
项目:Project--H    文件:game.java   
/**render**/
public void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
        createBufferStrategy(3);
        return; 
    }
    Screen.clear();
    Screen.render(x, y);

    for (int i = 0; i < pixels.length; i++) {
        pixels[i] = Screen.pixels[i];

    }

    Graphics g = bs.getDrawGraphics();
    g.drawImage(image,0, 0, getWidth(), getHeight(), null);
    g.dispose();
    bs.show();

}
项目:Canova    文件:DrawReconstruction.java   
public void start(){


        int[] pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
        boolean running = true;
        while(running){
            BufferStrategy bs = frame.getBufferStrategy();
            if(bs==null){
                frame.createBufferStrategy(4);
                return;
            }
            for (int i = 0; i < width * height; i++)
                pixels[i] = 0;

            Graphics g= bs.getDrawGraphics();
            g.drawImage(img, heightOffset, widthOffset, width, height, null);
            g.dispose();
            bs.show();

        }
    }
项目:deeplearning4j    文件:DrawReconstruction.java   
public void start() {


        int[] pixels = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
        boolean running = true;
        while (running) {
            BufferStrategy bs = frame.getBufferStrategy();
            if (bs == null) {
                frame.createBufferStrategy(4);
                return;
            }
            for (int i = 0; i < width * height; i++)
                pixels[i] = 0;

            Graphics g = bs.getDrawGraphics();
            g.drawImage(img, heightOffset, widthOffset, width, height, null);
            g.dispose();
            bs.show();

        }
    }
项目:consulo    文件:DialogWrapperPeerImpl.java   
@Override
public void dispose() {
  if (isShowing()) {
    hide();
  }

  if (myWindowListener != null) {
    myWindowListener.saveSize();
    removeWindowListener(myWindowListener);
    myWindowListener = null;
  }

  DialogWrapper.cleanupWindowListeners(this);

  final BufferStrategy strategy = getBufferStrategy();
  if (strategy != null) {
    strategy.dispose();
  }
  super.dispose();

  removeAll();
  DialogWrapper.cleanupRootPane(rootPane);
  rootPane = null;

}
项目:spacewar-2d    文件:Game.java   
public void render(){
    BufferStrategy bs = this.getBufferStrategy();
    if(bs == null){
        createBufferStrategy(3);
        return;
    }

    Graphics g = bs.getDrawGraphics();
    /////////////////////////////////

    g.drawImage(background, 0, 0, getWidth(), getHeight(), this);
    player.render(g);
    bullets.render(g);

    ////////////////////////////////
    g.dispose();
    bs.show();
}
项目:11-Zain    文件:Game.java   
public void render() {
    BufferStrategy bs = getBufferStrategy();
    if (bs == null) {
        /** Increasing number could improve speed but would slow down performance **/
        createBufferStrategy(3);
        return;
    }

    screen.clear();
    int xScroll = player.x - screen.width / 2;
    int yScroll = player.y - screen.height / 2;
    level.render(xScroll, yScroll, screen);
    player.render(screen);

    for (int i = 0; i < pixels.length; i++) {
        pixels[i] = screen.pixels[i];
    }

    Graphics g = bs.getDrawGraphics();
    g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
    g.setColor(Color.WHITE);
    g.setFont(new Font("Verdana", 0, 50));
    g.dispose();
    bs.show();
}
项目:AutonomousCar    文件:LooiWindow.java   
private void paint()
{

    BufferStrategy bs = canvas.getBufferStrategy();
    if(bs == null)
        {
            canvas.createBufferStrategy(3);
            return;
        }
    g = bs.getDrawGraphics();

    g.clearRect(0,0,(int)getWindowWidth(),(int)getWindowHeight());

    for(int i = paintActiveLooiObjects.size()-1; i > -1 ; i--)
        {
            paintActiveLooiObjects.get(i).setGraphics(g);
            g.setColor(Color.black);//set default color here! omg it used to be yellow and I had no idea... and i was so confused y everything was YELLOW
            paintActiveLooiObjects.get(i).looiPaint();
        }



    g.setColor(Color.black);
    g.fillRect(0,0,getWindowWidth(),viewVerticalOffset);
    g.fillRect(0,viewHeight+viewVerticalOffset,getWindowWidth(),getWindowHeight());
    g.fillRect(0,0,viewHorizontalOffset,getWindowHeight());
    g.fillRect(viewWidth+viewHorizontalOffset,0,getWindowWidth(),getWindowHeight());

    bs.show();
    g.dispose();
    //g.finalize();//This line gives the program a TINY performance boost
}
项目:The-Mysterious-Mind-Of-Jack    文件:GameCanvas.java   
public void draw() {
    requestFocus();
       BufferStrategy bs = getBufferStrategy();
       if (bs == null) {
           createBufferStrategy(3);
           return;
       }

       Graphics g = currentFrame.getGraphics();
       GameCanvas.g = g;
       g.setColor(Color.GRAY);
       g.fillRect(0, 0, getWidth(), getHeight());

       if (Game.paused) {
        if (!isBlurred) {
            if (StateHandler.pausedGame != null) {
                StateHandler.pausedGame.render(g);
                blurred = Tools.blur(currentFrame);
                isBlurred = true;
            }
        }
       } else isBlurred = false;

       StateHandler.render(g);

       bs.getDrawGraphics().drawImage(currentFrame, 0, 0, StateHandler.WIDTH, StateHandler.HEIGHT, null);

       g.dispose();
       bs.show();
}
项目:OpenJSharp    文件:VSyncedBSManager.java   
/**
 * Lets the manager know that this buffer strategy is no longer interested
 * in being v-synced.
 */
public static synchronized void releaseVsync(BufferStrategy bs) {
    VSyncedBSManager bsm = getInstance(false);
    if (bsm != null) {
        bsm.relinquishVsync(bs);
    }
}
项目:OpenJSharp    文件:VSyncedBSManager.java   
@Override
public synchronized boolean checkAllowed(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy current = strategy.get();
        if (current != null) {
            return (current == bs);
        }
    }
    strategy = new WeakReference<BufferStrategy>(bs);
    return true;
}
项目:OpenJSharp    文件:VSyncedBSManager.java   
@Override
public synchronized void relinquishVsync(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy b = strategy.get();
        if (b == bs) {
            strategy.clear();
            strategy = null;
        }
    }
}
项目:VTerminal    文件:Panel.java   
/** Draws every character of every row onto the canvas. */
public void draw() {
    final BufferStrategy bs = this.getBufferStrategy();

    do {
        do {
            final Graphics2D gc;

            try {
                gc = (Graphics2D) bs.getDrawGraphics();
            } catch (final NullPointerException | IllegalStateException e) {
                // BufferStrategy may not have been created on the first call,
                // so just do a recursive call until it works.
                // This may be a bad idea.
                draw();
                return;
            }

            gc.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
            gc.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
            gc.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
            gc.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);

            // Font characters are pre-rendered images, so no need for AA.
            gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);

            // No-need for text rendering related options.
            gc.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
            gc.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);

            // If alpha is used in the character images, we want computations related to drawing them to be fast.
            gc.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);

            screen.draw(gc, imageCache);
            gc.dispose();
        } while (bs.contentsRestored()); // Repeat render if drawing buffer contents were restored.

        bs.show();
    } while (bs.contentsLost()); // Repeat render if drawing buffer was lost.
}
项目:snowstorm    文件:AwtCanvasPainter.java   
@Override
public void drawScene(Snowflake[] scene, ScreenParameters screenParameters) {
    if (DEBUG_SHOW_FPS) fpsCounter.recordFrame();

    BufferStrategy strategy = getBufferStrategy();
    do {
        do {
            Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics();
            SnowFlake3DRenderer snowFlake3DRenderer = new AwtSnowflakeRenderer(g2d, screenParameters);

            drawBackground(g2d, screenParameters);
            for (Snowflake snowflake : scene) {
                snowFlake3DRenderer.renderSnowflake(snowflake.x + xoffset, snowflake.y, snowflake.size, snowflake.z, screenParameters);
            }

            if (DEBUG_SHOW_FPS) {
                g2d.setColor(Color.white);
                g2d.drawString(String.format("%.2f min FPS", fpsCounter.getMinFps()), 20, 20);
                g2d.drawString(String.format("%.2f max FPS", fpsCounter.getMaxFps()), 20, 35);
            }

            g2d.dispose();

        } while (strategy.contentsRestored());

        strategy.show();
        DEFAULT_TOOLKIT.sync(); // Seems like this is necessary on Ubuntu for smooth animation
    } while (strategy.contentsLost());
}
项目:jdk8u-jdk    文件:VSyncedBSManager.java   
/**
 * Lets the manager know that this buffer strategy is no longer interested
 * in being v-synced.
 */
public static synchronized void releaseVsync(BufferStrategy bs) {
    VSyncedBSManager bsm = getInstance(false);
    if (bsm != null) {
        bsm.relinquishVsync(bs);
    }
}
项目:jdk8u-jdk    文件:VSyncedBSManager.java   
@Override
public synchronized boolean checkAllowed(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy current = strategy.get();
        if (current != null) {
            return (current == bs);
        }
    }
    strategy = new WeakReference<BufferStrategy>(bs);
    return true;
}
项目:jdk8u-jdk    文件:VSyncedBSManager.java   
@Override
public synchronized void relinquishVsync(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy b = strategy.get();
        if (b == bs) {
            strategy.clear();
            strategy = null;
        }
    }
}
项目:jdk8u-jdk    文件:BufferStrategyExceptionTest.java   
public void render() {
    ImageCapabilities imgBackBufCap = new ImageCapabilities(true);
    ImageCapabilities imgFrontBufCap = new ImageCapabilities(true);
    BufferCapabilities bufCap =
        new BufferCapabilities(imgFrontBufCap,
            imgBackBufCap, BufferCapabilities.FlipContents.COPIED);
    try {

        createBufferStrategy(2, bufCap);
    } catch (AWTException ex) {
        createBufferStrategy(2);
    }

    BufferStrategy bs = getBufferStrategy();
    do {
        Graphics g =  bs.getDrawGraphics();
        g.setColor(Color.green);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(Color.red);
        g.drawString("Rendering test", 20, 20);

        g.drawImage(bi, 50, 50, null);

        g.dispose();
        bs.show();
    } while (bs.contentsLost()||bs.contentsRestored());
}
项目:openjdk-jdk10    文件:VSyncedBSManager.java   
/**
 * Lets the manager know that this buffer strategy is no longer interested
 * in being v-synced.
 */
public static synchronized void releaseVsync(BufferStrategy bs) {
    VSyncedBSManager bsm = getInstance(false);
    if (bsm != null) {
        bsm.relinquishVsync(bs);
    }
}
项目:openjdk-jdk10    文件:VSyncedBSManager.java   
@Override
public synchronized boolean checkAllowed(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy current = strategy.get();
        if (current != null) {
            return (current == bs);
        }
    }
    strategy = new WeakReference<BufferStrategy>(bs);
    return true;
}
项目:openjdk-jdk10    文件:VSyncedBSManager.java   
@Override
public synchronized void relinquishVsync(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy b = strategy.get();
        if (b == bs) {
            strategy.clear();
            strategy = null;
        }
    }
}
项目:openjdk-jdk10    文件:BufferStrategyExceptionTest.java   
public void render() {
    ImageCapabilities imgBackBufCap = new ImageCapabilities(true);
    ImageCapabilities imgFrontBufCap = new ImageCapabilities(true);
    BufferCapabilities bufCap =
        new BufferCapabilities(imgFrontBufCap,
            imgBackBufCap, BufferCapabilities.FlipContents.COPIED);
    try {

        createBufferStrategy(2, bufCap);
    } catch (AWTException ex) {
        createBufferStrategy(2);
    }

    BufferStrategy bs = getBufferStrategy();
    do {
        Graphics g =  bs.getDrawGraphics();
        g.setColor(Color.green);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(Color.red);
        g.drawString("Rendering test", 20, 20);

        g.drawImage(bi, 50, 50, null);

        g.dispose();
        bs.show();
    } while (bs.contentsLost()||bs.contentsRestored());
}
项目:openjdk9    文件:VSyncedBSManager.java   
/**
 * Lets the manager know that this buffer strategy is no longer interested
 * in being v-synced.
 */
public static synchronized void releaseVsync(BufferStrategy bs) {
    VSyncedBSManager bsm = getInstance(false);
    if (bsm != null) {
        bsm.relinquishVsync(bs);
    }
}