diff options
Diffstat (limited to 'libjava/java/awt/Canvas.java')
-rw-r--r-- | libjava/java/awt/Canvas.java | 152 |
1 files changed, 151 insertions, 1 deletions
diff --git a/libjava/java/awt/Canvas.java b/libjava/java/awt/Canvas.java index e223d9e..9a63119 100644 --- a/libjava/java/awt/Canvas.java +++ b/libjava/java/awt/Canvas.java @@ -179,6 +179,157 @@ public class Canvas } /** + * A BltBufferStrategy for canvases. + */ + private class CanvasBltBufferStrategy extends BltBufferStrategy + { + /** + * Creates a block transfer strategy for this canvas. + * + * @param numBuffers the number of buffers in this strategy + * @param accelerated true if the buffer should be accelerated, + * false otherwise + */ + CanvasBltBufferStrategy(int numBuffers, boolean accelerated) + { + super(numBuffers, + new BufferCapabilities(new ImageCapabilities(accelerated), + new ImageCapabilities(accelerated), + BufferCapabilities.FlipContents.COPIED)); + } + } + + /** + * A FlipBufferStrategy for canvases. + */ + private class CanvasFlipBufferStrategy extends FlipBufferStrategy + { + /** + * Creates a flip buffer strategy for this canvas. + * + * @param numBuffers the number of buffers in this strategy + * + * @throws AWTException if the requested number of buffers is not + * supported + */ + CanvasFlipBufferStrategy(int numBuffers) + throws AWTException + { + super(numBuffers, + new BufferCapabilities(new ImageCapabilities(true), + new ImageCapabilities(true), + BufferCapabilities.FlipContents.COPIED)); + } + } + + /** + * Creates a buffering strategy that manages how this canvas is + * repainted. This method attempts to create the optimum strategy + * based on the desired number of buffers. Hardware or software + * acceleration may be used. + * + * createBufferStrategy attempts different levels of optimization, + * but guarantees that some strategy with the requested number of + * buffers will be created even if it is not optimal. First it + * attempts to create a page flipping strategy, then an accelerated + * blitting strategy, then an unaccelerated blitting strategy. + * + * Calling this method causes any existing buffer strategy to be + * destroyed. + * + * @param numBuffers the number of buffers in this strategy + * + * @throws IllegalArgumentException if requested number of buffers + * is less than one + * @throws IllegalStateException if this canvas is not displayable + * + * @since 1.4 + */ + public void createBufferStrategy(int numBuffers) + { + if (numBuffers < 1) + throw new IllegalArgumentException("Canvas.createBufferStrategy: number" + + " of buffers is less than one"); + + if (!isDisplayable()) + throw new IllegalStateException("Canvas.createBufferStrategy: canvas is" + + " not displayable"); + + // try a flipping strategy + try + { + bufferStrategy = new CanvasFlipBufferStrategy(numBuffers); + return; + } + catch (AWTException e) + { + } + + // try an accelerated blitting strategy + try + { + bufferStrategy = new CanvasBltBufferStrategy(numBuffers, true); + } + catch (AWTException e) + { + } + + // fall back to an unaccelerated blitting strategy + try + { + bufferStrategy = new CanvasBltBufferStrategy(numBuffers, false); + } + catch (AWTException e) + { + } + } + + /** + * Creates a buffering strategy that manages how this canvas is + * repainted. This method attempts to create a strategy based on + * the specified capabilities and throws an exception if the + * requested strategy is not supported. + * + * Calling this method causes any existing buffer strategy to be + * destroyed. + * + * @param numBuffers the number of buffers in this strategy + * @param caps the requested buffering capabilities + * + * @throws AWTException if the requested capabilities are not + * supported + * @throws IllegalArgumentException if requested number of buffers + * is less than one or if caps is null + * + * @since 1.4 + */ + public void createBufferStrategy(int numBuffers, + BufferCapabilities caps) + { + if (numBuffers < 1) + throw new IllegalArgumentException("Canvas.createBufferStrategy: number" + + " of buffers is less than one"); + + if (caps == null) + throw new IllegalArgumentException("Canvas.createBufferStrategy:" + + " capabilities object is null"); + + // a flipping strategy was requested + if (caps.isPageFlipping()) + { + try + { + bufferStrategy = new CanvasFlipBufferStrategy(numBuffers); + } + catch (AWTException e) + { + } + } + else + bufferStrategy = new CanvasBltBufferStrategy(numBuffers, true); + } + + /** * Returns the buffer strategy used by the canvas. * * @return the buffer strategy. @@ -211,5 +362,4 @@ public class Canvas /* Call the paint method */ paint(graphics); } - } |