|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjava.awt.image.BufferStrategy
public abstract class BufferStrategy
BufferStrategy 類別表示用來在特定的 Canvas 或 Window 上組織複雜記憶體的機制。硬體和軟體限制決定了是否能夠實作特定的緩衝區策略以及如何實作它。從創建 Canvas 或 Window 時所用 GraphicsConfiguration 的性能中可以發覺這些限制。
值得注意的是,術語 buffer 和 surface 意思相同:視頻設備記憶體或系統記憶體中的連續記憶體區域。
存在幾種型別的複雜緩衝區策略,包括連續環形緩衝和 blit 緩衝。連續環形緩衝(即雙緩衝或三次緩衝)是最常見的緩衝區策略;將一個應用程序繪製到單個後備緩衝區,然後只用一個步驟將其內容移入到前端(顯示),這可通過複製資料或移動視頻指針完成。移動視頻指針可交換緩衝區,於是繪製的第一個緩衝區成為前端緩衝區,或稱設備上當前所顯示的內容;這稱為頁面翻轉。
作為一種替代方式,可以複製後備緩衝區的內容,即使用鏈而不是移動視頻指針進行位圖傳輸 (blitted)。
雙緩衝:
*********** ***********
* * ------> * *
[到顯示器] <---- * Front B * 顯示 * Back B. * <---- 呈現
* * <------ * *
*********** ***********
三次緩衝:
[到 *********** *********** ***********
顯示器] * * --------+---------+------> * *
<---- * Front B * 顯示 * Mid. B. * * Back B. * <---- 呈現
* * <------ * * <----- * *
*********** *********** ***********
以下是一個如何創建和使用緩衝區策略的例子:
// 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();
Component,
GraphicsConfiguration,
VolatileImage| 建構子摘要 | |
|---|---|
BufferStrategy()
|
|
| 方法摘要 | |
|---|---|
abstract boolean |
contentsLost()
返回上次調用 getDrawGraphics 後繪製緩衝區是否丟失。 |
abstract boolean |
contentsRestored()
返回繪製緩衝區最近是否從丟失狀態恢復,並重新初始化為預設背景色(白色)。 |
void |
dispose()
釋放當前由此 BufferStrategy 使用的系統資源,並從關聯 Component 中移除它們。 |
abstract BufferCapabilities |
getCapabilities()
返回此 BufferStrategy 的 BufferCapabilities。 |
abstract Graphics |
getDrawGraphics()
創建用於繪製緩衝區的圖形上下文。 |
abstract void |
show()
通過複製記憶體(位圖傳輸)或更改顯示指針(翻轉)使下一個可用緩衝區可見。 |
| 從類別 java.lang.Object 繼承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 建構子詳細資訊 |
|---|
public BufferStrategy()
| 方法詳細資訊 |
|---|
public abstract BufferCapabilities getCapabilities()
BufferStrategy 的 BufferCapabilities。
public abstract Graphics getDrawGraphics()
public abstract boolean contentsLost()
getDrawGraphics 後繪製緩衝區是否丟失。由於使用緩衝區策略的緩衝區通常是 VolatileImage 型別的,因此它們有可能丟失。有關對丟失緩衝區的討論,請參閱 VolatileImage。
getDrawGraphics 之後繪圖緩衝區是否丟失VolatileImagepublic abstract boolean contentsRestored()
VolatileImage 型別的,因此它們有可能丟失。如果上次調用 getDrawGraphics 後,緩衝區最近已從丟失狀態恢復,則緩衝區可能要求重新繪製。有關對丟失緩衝區的討論,請參閱 VolatileImage。
getDrawGraphics 之後是否恢復了繪圖緩衝區VolatileImagepublic abstract void show()
public void dispose()
BufferStrategy 使用的系統資源,並從關聯 Component 中移除它們。在調用此方法之後,getBufferStrategy 將返回 null。試圖在釋放 BufferStrategy 後使用它將導致不確定的行為。
Component.createBufferStrategy(int),
Component.getBufferStrategy()
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。