public abstract class BufferStrategy extends Object
BufferStrategy
类表示与该机制在特定
Canvas
或
Window
组织复杂的记忆。硬件和软件的限制,确定是否与特定的缓存策略可以实现。这些限制是通过探测的
GraphicsConfiguration
用于创建
Canvas
或
Window
当能力。
值得注意的是,该条款无效缓冲区和空表面是同义词:连续的内存区域,无论是在视频设备内存或系统内存。
有复杂的缓冲策略的几种类型,包括连续的环形缓冲的blit缓冲。连续的环形缓冲(即双重或三重缓冲)是最常见的;应用程序绘制一个单一的空后台缓冲区然后移动到前面的内容(显示)在一个单一的步骤,通过复制数据或视频移动指针。移动视频的缓冲区指针交流,第一缓冲绘制成空前台缓冲区,或什么是目前显示在设备上;这就是所谓的零页面翻转。
另外,的后台缓冲区的内容可以被复制,或nullblitted了链而不是视频指针移动。
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
Constructor and Description |
---|
BufferStrategy() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
contentsLost()
返回是否绘制缓冲区是因为
getDrawGraphics 最后呼叫丢失。
|
abstract boolean |
contentsRestored()
返回是否绘制缓冲区最近从迷失状态和初始化为默认背景色恢复(白色)。
|
void |
dispose()
释放系统资源的消耗,目前这
BufferStrategy 删除它的相关部件。
|
abstract BufferCapabilities |
getCapabilities()
返回此
BufferStrategy 的
BufferCapabilities 。
|
abstract Graphics |
getDrawGraphics()
为绘图缓冲区创建一个图形上下文。
|
abstract void |
show()
使下一个可用的缓冲区通过复制记忆可见(位图)或改变显示指针(翻转)。
|
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
将导致未定义的行为。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.