|
JavaTM 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 Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。