Java ゲーム エンジンを使用していますが、Windows のログイン画面に切り替えて戻ると、バッファ ストラテジがハードウェア アクセラレーションを失います。プログラムをシャットダウンして再起動するまで、バッファをハードウェアアクセラレーションに再度復元することはありません。
プログラムが開始されたときの ((Graphics2D) bufferStrategy.getDrawGraphics()).getDeviceConfiguration() のプロパティの数を次に示します。
Bounds: java.awt.Rectangle[x=0,y=0,width=1440,height=900]
Buffer Capabilities: sun.java2d.d3d.D3DGraphicsConfig$D3DBufferCaps@114b82b
Back Buffer Capabilities: sun.java2d.d3d.D3DGraphicsConfig$D3DImageCaps@147358f
Accelerated: true
True Volatile: true
Flip Contents: undefined
Front Buffer Capabilities: sun.java2d.d3d.D3DGraphicsConfig$D3DImageCaps@147358f
Accelerated: true
True Volatile: true
Is Full Screen Required: false
Is MultiBuffer Available: true
Is Page Flipping: true
Device: D3DGraphicsDevice[screen=1]
Available Accelerated Memory: 750780416
ID String: \Display1
Type: 0
Display Mode: java.awt.DisplayMode@dd3
Image Capabilities: sun.java2d.d3d.D3DGraphicsConfig$D3DImageCaps@147358f
Accelerated: true
True Volatile: true
ログイン画面が表示された後の同じプロパティを次に示します。
Bounds: java.awt.Rectangle[x=0,y=0,width=942,height=566]
Buffer Capabilities: java.awt.GraphicsConfiguration$DefaultBufferCapabilities@19d688
Back Buffer Capabilities: java.awt.ImageCapabilities@539a92
Accelerated: false
True Volatile: false
Flip Contents: null
Front Buffer Capabilities: java.awt.ImageCapabilities@539a92
Accelerated: false
True Volatile: false
Is Full Screen Required: false
Is MultiBuffer Available: false
Is Page Flipping: false
Device: sun.awt.image.BufferedImageDevice@c8f0a4
Available Accelerated Memory: -1
ID String: BufferedImage
Type: 2
Display Mode: java.awt.DisplayMode@68c
Image Capabilities: java.awt.ImageCapabilities@539a92
Accelerated: false
True Volatile: false
バッファ機能がsun.java2d.d3d.D3DGraphicsConfig$D3DImageCaps@147358fからjava.awt.GraphicsConfiguration$DefaultBufferCapabilities@19d688に変更されました。バッファー戦略をハードウェア アクセラレーションに戻す方法が見つからない場合。バッファ戦略を破棄して再度作成しても、ハードウェア アクセラレーションは復元されません。
バッファ戦略は Canvas オブジェクトで作成されます。上記の ((Graphics2D) bufferStrategy.getDrawGraphics()).getDeviceConfiguration() プロパティは加速を失いますが、canvas.getGraphicsConfiguration() を呼び出して Canvas オブジェクトの GraphicsConfiguration を取得すると、Canvas オブジェクト自体はまだ加速されていることを示します。
以下は、canvas.getGraphicsConfiguration() のプロパティです。バッファ ストラテジのグラフィックス オブジェクトは、アクセラレータに対して false を返します。
Bounds: java.awt.Rectangle[x=0,y=0,width=1440,height=900]
Buffer Capabilities: sun.java2d.d3d.D3DGraphicsConfig$D3DBufferCaps@1672113
Back Buffer Capabilities: sun.java2d.d3d.D3DGraphicsConfig$D3DImageCaps@d5eb7
Accelerated: true
True Volatile: true
Flip Contents: undefined
Front Buffer Capabilities: sun.java2d.d3d.D3DGraphicsConfig$D3DImageCaps@d5eb7
Accelerated: true
True Volatile: true
Is Full Screen Required: false
Is MultiBuffer Available: true
Is Page Flipping: true
Device: D3DGraphicsDevice[screen=1]
Available Accelerated Memory: 764411904
ID String: \Display1
Type: 0
Display Mode: java.awt.DisplayMode@dd3
Image Capabilities: sun.java2d.d3d.D3DGraphicsConfig$D3DImageCaps@d5eb7
Accelerated: true
True Volatile: true
上記の問題を再現するために使用できるコードは次のとおりです。
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
public class AccelerationTest extends JFrame {
public AccelerationTest(){
setSize(500, 500);
setVisible(true);
setIgnoreRepaint(true);
createBufferStrategy(2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
(new Thread(new Runnable(){
public void run(){
do{
render();
try{Thread.sleep(200);}catch(InterruptedException e){}
}while (true);
}
})).start();
}
public static void main(String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new AccelerationTest();
}
});
}
private void render(){
BufferStrategy bufferStrategy = getBufferStrategy();
Graphics2D graphic = (Graphics2D) bufferStrategy.getDrawGraphics();
graphic.setColor(Color.red);
graphic.fillRect(0, 0, getWidth(), getHeight());
graphic.setColor(Color.white);
graphic.fillRect((int) (getWidth() * 0.1), (int) (getHeight() * 0.1), (int) (getWidth() * 0.8), (int) (getHeight() * 0.8));
bufferStrategy.show();
System.out.println();
System.out.println("graphic from frame: \n" + getDeviceConfigurationString(graphic.getDeviceConfiguration()));
System.out.println();
System.out.println("frame: \n" + getDeviceConfigurationString(getGraphicsConfiguration()));
graphic.dispose();
}
private String getDeviceConfigurationString(GraphicsConfiguration gc){
return "Bounds: " + gc.getBounds() + "\n" +
"Buffer Capabilities: " + gc.getBufferCapabilities() + "\n" +
" Back Buffer Capabilities: " + gc.getBufferCapabilities().getBackBufferCapabilities() + "\n" +
" Accelerated: " + gc.getBufferCapabilities().getBackBufferCapabilities().isAccelerated() + "\n" +
" True Volatile: " + gc.getBufferCapabilities().getBackBufferCapabilities().isTrueVolatile() + "\n" +
" Flip Contents: " + gc.getBufferCapabilities().getFlipContents() + "\n" +
" Front Buffer Capabilities: " + gc.getBufferCapabilities().getFrontBufferCapabilities() + "\n" +
" Accelerated: " + gc.getBufferCapabilities().getFrontBufferCapabilities().isAccelerated() + "\n" +
" True Volatile: " + gc.getBufferCapabilities().getFrontBufferCapabilities().isTrueVolatile() + "\n" +
" Is Full Screen Required: " + gc.getBufferCapabilities().isFullScreenRequired() + "\n" +
" Is MultiBuffer Available: " + gc.getBufferCapabilities().isMultiBufferAvailable() + "\n" +
" Is Page Flipping: " + gc.getBufferCapabilities().isPageFlipping() + "\n" +
"Device: " + gc.getDevice() + "\n" +
" Available Accelerated Memory: " + gc.getDevice().getAvailableAcceleratedMemory() + "\n" +
" ID String: " + gc.getDevice().getIDstring() + "\n" +
" Type: " + gc.getDevice().getType() + "\n" +
" Display Mode: " + gc.getDevice().getDisplayMode() + "\n" +
"Image Capabilities: " + gc.getImageCapabilities() + "\n" +
" Accelerated: " + gc.getImageCapabilities().isAccelerated() + "\n" +
" True Volatile: " + gc.getImageCapabilities().isTrueVolatile() + "\n";
}
}