java.lang.Object
java.awt.image.BufferStrategy
- 直系の既知のサブクラス:
Component.BltBufferStrategy
,Component.FlipBufferStrategy
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();
- 導入されたバージョン:
- 1.4
- 関連項目:
-
コンストラクタのサマリー
-
メソッドのサマリー
修飾子と型メソッド説明abstract boolean
getDrawGraphics
の最後の呼出しのあとに描画バッファが失われたかどうかを返します。abstract boolean
描画バッファが消失状態から最近復元され、デフォルトのバックグラウンド・カラー(白)に再初期化されたかどうかを返します。void
dispose()
現在このBufferStrategy
によって消費されているシステム・リソースを解放し、関連付けられたコンポーネントから削除します。abstract BufferCapabilities
このBufferStrategy
のBufferCapabilities
を返します。abstract Graphics
描画バッファのグラフィックス・コンテキストを作成します。abstract void
show()
メモリーを複製(Blit)するかディスプレイ・ポインタを変更する(切り替える)ことにより、次に使用可能なバッファを可視状態にします。
-
コンストラクタの詳細
-
BufferStrategy
protected BufferStrategy()サブクラスが呼び出すためのコンストラクタ。
-
-
メソッドの詳細
-
getCapabilities
public abstract BufferCapabilities getCapabilities()このBufferStrategy
のBufferCapabilities
を返します。- 戻り値:
- この方針のバッファ容量
-
getDrawGraphics
public abstract Graphics getDrawGraphics()描画バッファのグラフィックス・コンテキストを作成します。 このメソッドはパフォーマンスの理由から同期しない場合があります。複数スレッドでこのメソッドを使用するには、アプリケーション・レベルでの処理が必要です。 取得したグラフィックス・オブジェクトの処理は、アプリケーション側で行う必要があります。- 戻り値:
- 描画バッファのグラフィックス・コンテキスト
-
contentsLost
public abstract boolean contentsLost()getDrawGraphics
の最後の呼出しのあとに描画バッファが失われたかどうかを返します。 バッファ方式内のバッファは通常、タイプがVolatileImage
であるため、失われることがあります。 失われたバッファに関する説明については、VolatileImage
を参照してください。- 戻り値:
getDrawGraphics
への最後の呼出しのために描画バッファが消失したかどうか。- 関連項目:
-
contentsRestored
public abstract boolean contentsRestored()描画バッファが消失状態から最近復元され、デフォルトのバックグラウンド・カラー(白)に再初期化されたかどうかを返します。 バッファ方式内のバッファは通常、タイプがVolatileImage
であるため、失われることがあります。getDrawGraphics
の最後の呼出しのあとに表面が最近、失われた状態から復元された場合は、その表面に再ペイントが必要になることがあります。 失われたバッファに関する説明については、VolatileImage
を参照してください。- 戻り値:
getDrawGraphics
への最後の呼出しのために描画バッファが復元されたかどうか。- 関連項目:
-
show
public abstract void show()メモリーを複製(Blit)するかディスプレイ・ポインタを変更する(切り替える)ことにより、次に使用可能なバッファを可視状態にします。 -
dispose
public void dispose()現在このBufferStrategy
によって消費されているシステム・リソースを解放し、関連付けられたコンポーネントから削除します。 このメソッドを呼び出したあと、getBufferStrategy
はnullを返します。BufferStrategy
をそれが破棄されたあとに使用しようとすると、未定義の動作になります。- 導入されたバージョン:
- 1.6
- 関連項目:
-