Files
narya/src/java/com/threerings/media/FlipFrameManager.java
T
Michael Bayne 055bd6a642 Factored out the flip-buffer versus volatile image back-buffer code into
start-time selectable implementations. Modified back buffer to use
BufferCapabilities.FlipContents.COPIED which should do what we need in
terms of providing us with the current frame's contents on which to paint.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2468 542714f4-19e9-0310-aa3c-eee0fc999fb1
2003-04-26 17:56:26 +00:00

71 lines
2.0 KiB
Java

//
// $Id: FlipFrameManager.java,v 1.1 2003/04/26 17:56:26 mdb Exp $
package com.threerings.media;
import java.awt.BufferCapabilities;
import java.awt.Graphics2D;
import java.awt.ImageCapabilities;
import java.awt.Rectangle;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
import com.threerings.media.timer.MediaTimer;
/**
* A {@link FrameManager} extension that uses a flip-buffer (via {@link
* BufferStrategy} to do its rendering.
*/
public class FlipFrameManager extends FrameManager
{
// documentation inherited
protected void paint (long tickStamp)
{
// create our buffer strategy if we don't already have one
if (_bufstrat == null) {
BufferCapabilities cap = new BufferCapabilities(
new ImageCapabilities(true), new ImageCapabilities(true),
BufferCapabilities.FlipContents.COPIED);
_frame.createBufferStrategy(2);
_bufstrat = _frame.getBufferStrategy();
}
// start out assuming we can do an incremental render
boolean incremental = true;
do {
Graphics2D gfx = (Graphics2D)_bufstrat.getDrawGraphics();
// dirty everything if we're not incrementally rendering
if (!incremental) {
Log.info("Doing non-incremental render; contents lost.");
_frame.update(gfx);
}
// request to paint our participants and components and bail
// if they paint nothing
if (!paint(gfx)) {
return;
}
// flip our buffer to visible
_bufstrat.show();
// if we loop through a second time, we'll need to rerender
// everything
incremental = false;
} while (_bufstrat.contentsLost());
}
// documentation inherited
protected void restoreFromBack (Rectangle dirty)
{
// nothing doing
}
/** The buffer strategy used to do our rendering. */
protected BufferStrategy _bufstrat;
}