2

誰かが以前に次の問題に遭遇したことがあることを願っています。

私のJavaアプリケーションにはMacでのグラフィックパフォーマンスの問題があるため、簡単なテストアプリケーションを作成しました(以下のコード)。これをWindowsで実行すると、コンソールに次のように表示されます。

GraphicsConfigurationフリッピング?真の
BufferStrategyフリッピング?true

Mac OSでまったく同じコードを実行すると、次のようになります。

GraphicsConfigurationフリッピング?真の
BufferStrategyフリッピング?false

これは、Mac OSでは、ウィンドウ化されたアプリケーションでページめくりがサポートされていないことを意味しますか?フルスクリーンにならずにMacOSでページめくりを機能させるためのトリックはありますか?


Mattijs 、すべてのポインタは大歓迎です

WindowsXPおよびMacOS10.5でのJDK1.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();
 }
}
4

2 に答える 2

2

悪いニュース:同じMacOSX構成で同じ結果が得られます。良いニュース:isAccelerated()本当です。

System.out.println("BufferStrategy accelerated? " + bufferStrategy
    .getCapabilities().getFrontBufferCapabilities().isAccelerated());

との代わりにCanvasBufferStrategy私はただ使用しますnew JPanel(true)

補遺:たとえば、

import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class NewTest extends JPanel implements ActionListener, Runnable {

    private Random r = new Random();
    private Timer t = new Timer(10, this);

    public static void main(String[] args) {
        EventQueue.invokeLater(new NewTest());
    }

    @Override
    public void run() {
        JFrame f = new JFrame("NewTest");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(this);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
        t.start();
    }

    public NewTest() {
        super(true);
        this.setPreferredSize(new Dimension(640, 480));
    }

    @Override
    protected void paintComponent(Graphics g) {
        int width = this.getWidth();
        int height = this.getHeight();
        g.setColor(Color.BLACK);
        g.fillRect(0, 0, width, height);
        g.setColor(Color.RED);
        g.drawLine(r.nextInt(width), r.nextInt(height),
            r.nextInt(width), r.nextInt(height));

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        this.repaint();
    }
}
于 2010-06-25T17:29:06.480 に答える
0

Linuxでは、コマンドラインパラメータ-Dsun.java2d.opengl = trueを設定すると、これが発生します。したがって、反対の-Dsun.java2d.opengl=falseを実行する価値があるかもしれません。

于 2020-05-25T22:16:56.703 に答える