public abstract class BufferStrategy extends Object
BufferStrategy
クラスは、特定のCanvas
またはWindow
上の複雑なメモリーを編成するメカニズムを表します。特定のバッファ・ストラテジが実装可能かどうか、およびその実装方法は、ハードウェアとソフトウェアの制限事項によって決まります。これらの制限事項は、Canvas
またはWindow
を作成するときに使用するGraphicsConfiguration
の機能を介して検出されます。
バッファおよび表面という語は同義であり、ビデオ・デバイス・メモリー内またはシステム・メモリー内での連続したメモリー領域を指します。
複雑なバッファ・ストラテジには、順次リング・バッファリング、Blitバッファリングなどいくつかの種類があります。もっとも一般的なのは、順次リング・バッファリング(ダブル・バッファリングまたはトリプル・バッファリング)です。アプリケーションは単一のバック・バッファへ描画してから、データを複製するかビデオ・ポインタを移動することにより単一ステップで内容をフロント(ディスプレイ)へ移動します。ビデオ・ポインタを移動することでバッファが交換され、最初に描画されたバッファまたはデバイスに現在表示されているイメージがフロント・バッファになります。これはページ・フリッピングと呼ばれます。
代わりに、ビデオ・ポインタを移動するのではなく、チェーン内で先行してバック・バッファの内容を複製またはBlitすることができます。
Double buffering:
*********** ***********
* * ------> * *
[To display] <---- * Front B * Show * Back B. * <---- Rendering
* * <------ * *
*********** ***********
Triple buffering:
[To *********** *********** ***********
display] * * --------+---------+------> * *
<---- * Front B * Show * Mid. B. * * Back B. * <---- Rendering
* * <------ * * <----- * *
*********** *********** ***********
バッファ・ストラテジの作成と使用の例を示します。
// Check the capabilities of the GraphicsConfiguration
...
// Create our component
Window w = new Window(gc);
// Show our window
w.setVisible(true);
// Create a general double-buffering strategy
w.createBufferStrategy(2);
BufferStrategy strategy = w.getBufferStrategy();
// Main loop
while (!done) {
// Prepare for rendering the next frame
// ...
// Render single frame
do {
// The following loop ensures that the contents of the drawing buffer
// are consistent in case the underlying surface was recreated
do {
// Get a new graphics context every time through the loop
// to make sure the strategy is validated
Graphics graphics = strategy.getDrawGraphics();
// Render to graphics
// ...
// Dispose the graphics
graphics.dispose();
// Repeat the rendering if the drawing buffer contents
// were restored
} while (strategy.contentsRestored());
// Display the buffer
strategy.show();
// Repeat the rendering if the drawing buffer was lost
} while (strategy.contentsLost());
}
// Dispose the window
w.setVisible(false);
w.dispose();
Window
, Canvas
, GraphicsConfiguration
, VolatileImage
コンストラクタと説明 |
---|
BufferStrategy() |
修飾子と型 | メソッドと説明 |
---|---|
abstract boolean |
contentsLost()
getDrawGraphics の最後の呼出しのあとに描画バッファが失われたかどうかを返します。 |
abstract boolean |
contentsRestored()
描画バッファが消失状態から最近復元され、デフォルトのバックグラウンド・カラー(白)に再初期化されたかどうかを返します。
|
void |
dispose()
現在この
BufferStrategy によって消費されているシステム・リソースを解放し、関連付けられたコンポーネントから削除します。 |
abstract BufferCapabilities |
getCapabilities()
この
BufferStrategy のBufferCapabilities を返します。 |
abstract Graphics |
getDrawGraphics()
描画バッファのグラフィックス・コンテキストを作成します。
|
abstract void |
show()
メモリーを複製(Blit)するかディスプレイ・ポインタを変更する(切り替える)ことにより、次に使用可能なバッファを可視状態にします。
|
public abstract BufferCapabilities getCapabilities()
BufferStrategy
のBufferCapabilities
を返します。public abstract Graphics getDrawGraphics()
public abstract boolean contentsLost()
getDrawGraphics
の最後の呼出しのあとに描画バッファが失われたかどうかを返します。バッファ方式内のバッファは通常、タイプがVolatileImage
であるため、失われることがあります。失われたバッファに関する説明については、VolatileImage
を参照してください。getDrawGraphics
への最後の呼出しのために描画バッファが消失したかどうか。VolatileImage
public abstract boolean contentsRestored()
VolatileImage
であるため、失われることがあります。getDrawGraphics
の最後の呼出しのあとに表面が最近、失われた状態から復元された場合は、その表面に再ペイントが必要になることがあります。失われたバッファに関する説明については、VolatileImage
を参照してください。getDrawGraphics
への最後の呼出しのために描画バッファが復元されたかどうか。VolatileImage
public abstract void show()
public void dispose()
BufferStrategy
によって消費されているシステム・リソースを解放し、関連付けられたコンポーネントから削除します。このメソッドを呼び出したあと、getBufferStrategy
はnullを返します。BufferStrategy
をそれが破棄されたあとに使用しようとすると、未定義の動作になります。 バグまたは機能を送信
詳細なAPIリファレンスおよび開発者ドキュメントについては、Java SEのドキュメントを参照してください。そのドキュメントには、概念的な概要、用語の定義、回避方法、有効なコード例などの、開発者を対象にしたより詳細な説明が含まれています。
Copyright © 1993, 2016, Oracle and/or its affiliates. All rights reserved.Use is subject to license termsDocumentation Redistribution Policyも参照してください。