モジュール 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
関連項目: