java.awt.image.BufferStrategy Java Examples

The following examples show how to use java.awt.image.BufferStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BufferStrategyExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example #2
Source File: BufferStrategyExceptionTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example #3
Source File: VSyncedBSManager.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void relinquishVsync(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy b = strategy.get();
        if (b == bs) {
            strategy.clear();
            strategy = null;
        }
    }
}
 
Example #4
Source File: VSyncedBSManager.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #5
Source File: VSyncedBSManager.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void relinquishVsync(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy b = strategy.get();
        if (b == bs) {
            strategy.clear();
            strategy = null;
        }
    }
}
 
Example #6
Source File: GamePanel.java    From yt-java-game with MIT License 5 votes vote down vote up
public GamePanel(BufferStrategy bs, int width, int height) {
    GamePanel.width = width;
    GamePanel.height = height;
    this.bs = bs;
    setPreferredSize(new Dimension(width, height));
    setFocusable(true);
    requestFocus();
}
 
Example #7
Source File: VSyncedBSManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #8
Source File: VSyncedBSManager.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #9
Source File: VSyncedBSManager.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void relinquishVsync(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy b = strategy.get();
        if (b == bs) {
            strategy.clear();
            strategy = null;
        }
    }
}
 
Example #10
Source File: VSyncedBSManager.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void relinquishVsync(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy b = strategy.get();
        if (b == bs) {
            strategy.clear();
            strategy = null;
        }
    }
}
 
Example #11
Source File: VSyncedBSManager.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void relinquishVsync(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy b = strategy.get();
        if (b == bs) {
            strategy.clear();
            strategy = null;
        }
    }
}
 
Example #12
Source File: VSyncedBSManager.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #13
Source File: GameCanvas.java    From design_principles_dojo with MIT License 5 votes vote down vote up
public void draw() throws Exception {
    BufferStrategy strategy = getBufferStrategy();
    Graphics2D graphics = (Graphics2D) strategy.getDrawGraphics();
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    graphics.setColor(Color.white);
    graphics.fill(new Rectangle(dimension));

    currentScreen = currentScreen.getNextScreen();
    currentScreen.draw(graphics);

    graphics.dispose();
    strategy.show();
}
 
Example #14
Source File: VSyncedBSManager.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #15
Source File: VSyncedBSManager.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #16
Source File: VSyncedBSManager.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #17
Source File: VSyncedBSManager.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #18
Source File: BufferStrategyExceptionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example #19
Source File: VSyncedBSManager.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #20
Source File: VSyncedBSManager.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #21
Source File: VSyncedBSManager.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void relinquishVsync(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy b = strategy.get();
        if (b == bs) {
            strategy.clear();
            strategy = null;
        }
    }
}
 
Example #22
Source File: VSyncedBSManager.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #23
Source File: VSyncedBSManager.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #24
Source File: VSyncedBSManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public synchronized void relinquishVsync(BufferStrategy bs) {
    if (strategy != null) {
        BufferStrategy b = strategy.get();
        if (b == bs) {
            strategy.clear();
            strategy = null;
        }
    }
}
 
Example #25
Source File: BufferStrategyExceptionTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example #26
Source File: VSyncedBSManager.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #27
Source File: BufferStrategyExceptionTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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());
}
 
Example #28
Source File: VSyncedBSManager.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #29
Source File: VSyncedBSManager.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #30
Source File: VSyncedBSManager.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@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;
}