我希望有人碰巧之前偶然发现了以下问题。
我的 Java 应用程序在 Mac 上存在图形性能问题,所以我做了一个简单的测试应用程序(代码如下)。当我在 Windows 上运行它时,控制台告诉我:
图形配置翻转?真正的
BufferStrategy 翻转?真的
当我在 Mac OS 上运行完全相同的代码时,我得到:
图形配置翻转?真正的
BufferStrategy 翻转?错误的
这是否意味着在 Mac OS 上,窗口应用程序根本不支持翻页?是否有任何技巧可以在不全屏的情况下在 Mac OS 上进行翻页工作?
非常欢迎所有的指点,
Mattijs
在 Windows XP 和 Mac OS 10.5 上使用 JDK 1.6。
编码:
import java.awt.image.BufferStrategy;
import javax.swing.*;
import java.awt.*;
public class Test {
int width = 640;
int height = 480;
GraphicsEnvironment graphEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice graphDevice = graphEnv.getDefaultScreenDevice();
GraphicsConfiguration graphicConf = graphDevice.getDefaultConfiguration();
public Test() {
JFrame jFrame = new JFrame(graphicConf);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setTitle("double buffer test");
jFrame.setResizable(false);
jFrame.setFocusTraversalKeysEnabled(false);
Canvas canvas = new Canvas();
canvas.setSize(width, height);
canvas.setIgnoreRepaint(true);
jFrame.getContentPane().add(canvas);
jFrame.pack();
jFrame.setVisible(true);
System.out.println("GraphicsConfiguration flipping? " + graphicConf.getBufferCapabilities().isPageFlipping());
canvas.createBufferStrategy(2);
BufferStrategy bufferStrategy = canvas.getBufferStrategy();
System.out.println("BufferStrategy flipping? " + bufferStrategy.getCapabilities().isPageFlipping());
while(true) {
Graphics g = bufferStrategy.getDrawGraphics();
g.setColor(Color.BLACK);
g.fillRect(0,0,width,height);
g.setColor(Color.RED);
g.drawLine((int)(Math.random()*width),(int)(Math.random()*height),
(int)(Math.random()*width),(int)(Math.random()*height));
bufferStrategy.show();
g.dispose();
}
}
public static void main(String[] args) {
new Test();
}
}