モジュール java.desktop
パッケージ java.awt.image

クラスBufferStrategy

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
関連項目:
Window, Canvas, GraphicsConfiguration, VolatileImage
  • コンストラクタのサマリー

    コンストラクタ
    コンストラクタ 説明
    BufferStrategy()  
  • メソッドのサマリー

    修飾子と型 メソッド 説明
    abstract boolean contentsLost()
    getDrawGraphicsの最後の呼出しのあとに描画バッファが失われたかどうかを返します。
    abstract boolean contentsRestored()
    描画バッファが消失状態から最近復元され、デフォルトのバックグラウンド・カラー(白)に再初期化されたかどうかを返します。
    void dispose()
    現在このBufferStrategyによって消費されているシステム・リソースを解放し、関連付けられたコンポーネントから削除します。
    abstract BufferCapabilities getCapabilities()
    このBufferStrategyBufferCapabilitiesを返します。
    abstract Graphics getDrawGraphics()
    描画バッファのグラフィックス・コンテキストを作成します。
    abstract void show()
    メモリーを複製(Blit)するかディスプレイ・ポインタを変更する(切り替える)ことにより、次に使用可能なバッファを可視状態にします。

    クラス java.lang.Objectで宣言されたメソッド

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • コンストラクタの詳細

    • BufferStrategy

      public BufferStrategy()
  • メソッドの詳細

    • getCapabilities

      public abstract BufferCapabilities getCapabilities()
      このBufferStrategyBufferCapabilitiesを返します。
      戻り値:
      この方針のバッファ容量
    • getDrawGraphics

      public abstract Graphics getDrawGraphics()
      描画バッファのグラフィックス・コンテキストを作成します。 このメソッドはパフォーマンスの理由から同期しない場合があります。複数スレッドでこのメソッドを使用するには、アプリケーション・レベルでの処理が必要です。 取得したグラフィックス・オブジェクトの処理は、アプリケーション側で行う必要があります。
      戻り値:
      描画バッファのグラフィックス・コンテキスト
    • contentsLost

      public abstract boolean contentsLost()
      getDrawGraphicsの最後の呼出しのあとに描画バッファが失われたかどうかを返します。 バッファ方式内のバッファは通常、タイプがVolatileImageであるため、失われることがあります。 失われたバッファに関する説明については、VolatileImageを参照してください。
      戻り値:
      getDrawGraphicsへの最後の呼出しのために描画バッファが消失したかどうか。
      関連項目:
      VolatileImage
    • contentsRestored

      public abstract boolean contentsRestored()
      描画バッファが消失状態から最近復元され、デフォルトのバックグラウンド・カラー(白)に再初期化されたかどうかを返します。 バッファ方式内のバッファは通常、タイプがVolatileImageであるため、失われることがあります。 getDrawGraphicsの最後の呼出しのあとに表面が最近、失われた状態から復元された場合は、その表面に再ペイントが必要になることがあります。 失われたバッファに関する説明については、VolatileImageを参照してください。
      戻り値:
      getDrawGraphicsへの最後の呼出しのために描画バッファが復元されたかどうか。
      関連項目:
      VolatileImage
    • show

      public abstract void show()
      メモリーを複製(Blit)するかディスプレイ・ポインタを変更する(切り替える)ことにより、次に使用可能なバッファを可視状態にします。
    • dispose

      public void dispose()
      現在このBufferStrategyによって消費されているシステム・リソースを解放し、関連付けられたコンポーネントから削除します。 このメソッドを呼び出したあと、getBufferStrategyはnullを返します。 BufferStrategyをそれが破棄されたあとに使用しようとすると、未定義の動作になります。
      導入されたバージョン:
      1.6
      関連項目:
      Window.createBufferStrategy(int), Canvas.createBufferStrategy(int), Window.getBufferStrategy(), Canvas.getBufferStrategy()