首页 > 解决方案 > javaFX误报屏幕设备的数量

问题描述

我在 Red Hat 6.8 x64 上使用 java 8u162 和 NVidia GPU(及其最新驱动程序)在 Linux 上开发了一个 javaFX 应用程序,带有 2 个全高清屏幕。

我在检索物理屏幕数量时遇到问题:

我将 JavaFX API 与 AWT API 进行了比较:

GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gdev = env.getScreenDevices();

AWT 在两种配置模式下都返回 2 个屏幕设备。

我还使用 ubuntu x64 机器检查了 java 9 和 java 10,并在 JavaFX 上遇到了同样的问题。

我尝试对此进行调试,似乎问题出在本机代码中的 libglass.so 中。

你怎么看待这件事 ?我错过了什么吗?

这是重现该问题的代码:

public class ScreenTest extends Application {

private static final int SIZE = 1600;
private final AnchorPane root = new AnchorPane();

@Override
public void start(Stage primaryStage) throws Exception {

    root.backgroundProperty().set(new Background(new BackgroundFill(Color.BEIGE, null, null)));
    Scene scene = new Scene(root, SIZE, SIZE);
    primaryStage.show();

    Screen.getScreens().forEach(screen -> System.out.println("JAVAFX :"+ screen));
    GraphicsEnvironment env =GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gdev = env.getScreenDevices();

    for (GraphicsDevice d : gdev) {
        System.out.println("AWT:" + d);
    }
}
public static void main(String... strings) {
    launch(strings);
}
}

这是我的 xorg.conf X11 配置:

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0" 0 0
    Screen      1  "Screen1" RightOf "Screen0"
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
    Option         "Xinerama" "0"
EndSection

Section "Files"
EndSection

Section "InputDevice"

    # generated from default
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/psaux"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"

    # generated from default
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "CMN"
    HorizSync       53.0 - 66.0
    VertRefresh     48.0 - 60.0
    Option         "DPMS"
EndSection

Section "Monitor"
    Identifier     "Monitor1"
    VendorName     "Unknown"
    ModelName      "DELL C7017T"
    HorizSync       30.0 - 83.0
    VertRefresh     56.0 - 76.0
EndSection

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "Quadro K3100M"
    BusID          "PCI:1:0:0"
    Screen          0
EndSection

Section "Device"
    Identifier     "Device1"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "Quadro K3100M"
    BusID          "PCI:1:0:0"
    Screen          1
EndSection

标签: javajavafxgraphicsx11nvidia

解决方案


推荐阅读