package sun.awt;
import java.awt.AWTError;
import java.awt.GraphicsDevice;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Enumeration;
import sun.java2d.SunGraphicsEnvironment;
import sun.java2d.SurfaceManagerFactory;
import sun.java2d.UnixSurfaceManagerFactory;
import sun.java2d.xr.XRSurfaceData;
import sun.util.logging.PlatformLogger;
public final class X11GraphicsEnvironment extends SunGraphicsEnvironment {
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11GraphicsEnvironment");
private static final PlatformLogger screenLog = PlatformLogger.getLogger("sun.awt.screen.X11GraphicsEnvironment");
private static Boolean xinerState;
static {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Object>() {
public Object run() {
System.loadLibrary("awt");
if (!isHeadless()) {
boolean glxRequested = false;
String prop = System.getProperty("sun.java2d.opengl");
if (prop != null) {
if (prop.equals("true") || prop.equals("t")) {
glxRequested = true;
} else if (prop.equals("True") || prop.equals("T")) {
glxRequested = true;
glxVerbose = true;
}
}
boolean xRenderRequested = true;
boolean xRenderIgnoreLinuxVersion = false;
String xProp = System.getProperty("sun.java2d.xrender");
if (xProp != null) {
if (xProp.equals("false") || xProp.equals("f")) {
xRenderRequested = false;
} else if (xProp.equals("True") || xProp.equals("T")) {
xRenderRequested = true;
xRenderVerbose = true;
}
if(xProp.equalsIgnoreCase("t") || xProp.equalsIgnoreCase("true")) {
xRenderIgnoreLinuxVersion = true;
}
}
initDisplay(glxRequested);
if (glxRequested) {
glxAvailable = initGLX();
if (glxVerbose && !glxAvailable) {
System.out.println(
"Could not enable OpenGL " +
"pipeline (GLX 1.3 not available)");
}
}
if (xRenderRequested) {
xRenderAvailable = initXRender(xRenderVerbose, xRenderIgnoreLinuxVersion);
if (xRenderVerbose && !xRenderAvailable) {
System.out.println(
"Could not enable XRender pipeline");
}
}
if (xRenderAvailable) {
XRSurfaceData.initXRSurfaceData();
}
}
return null;
}
});
SurfaceManagerFactory.setInstance(new UnixSurfaceManagerFactory());
}
private static boolean glxAvailable;
private static boolean glxVerbose;
private static native boolean initGLX();
public static boolean isGLXAvailable() {
return glxAvailable;
}
public static boolean isGLXVerbose() {
return glxVerbose;
}
private static boolean xRenderVerbose;
private static boolean xRenderAvailable;
private static native boolean initXRender(boolean verbose, boolean ignoreLinuxVersion);
public static boolean isXRenderAvailable() {
return xRenderAvailable;
}
public static boolean isXRenderVerbose() {
return xRenderVerbose;
}
private static native int checkShmExt();
private static native String getDisplayString();
private Boolean isDisplayLocal;
private static native void initDisplay(boolean glxRequested);
public X11GraphicsEnvironment() {
}
protected native int getNumScreens();
protected GraphicsDevice makeScreenDevice(int screennum) {
return new X11GraphicsDevice(screennum);
}
private native int getDefaultScreenNum();
public GraphicsDevice getDefaultScreenDevice() {
GraphicsDevice[] screens = getScreenDevices();
if (screens.length == 0) {
throw new AWTError("no screen devices");
}
int index = getDefaultScreenNum();
return screens[0 < index && index < screens.length ? index : 0];
}
public boolean isDisplayLocal() {
if (isDisplayLocal == null) {
SunToolkit.awtLock();
try {
if (isDisplayLocal == null) {
isDisplayLocal = Boolean.valueOf(_isDisplayLocal());
}
} finally {
SunToolkit.awtUnlock();
}
}
return isDisplayLocal.booleanValue();
}
private static boolean _isDisplayLocal() {
if (isHeadless()) {
return true;
}
String isRemote = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("sun.java2d.remote"));
if (isRemote != null) {
return isRemote.equals("false");
}
int shm = checkShmExt();
if (shm != -1) {
return (shm == 1);
}
String display = getDisplayString();
int ind = display.indexOf(':');
final String hostName = display.substring(0, ind);
if (ind <= 0) {
return true;
}
Boolean result = java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Boolean>() {
public Boolean run() {
InetAddress[] remAddr = null;
Enumeration<InetAddress> locals = null;
Enumeration<NetworkInterface> interfaces = null;
try {
interfaces = NetworkInterface.getNetworkInterfaces();
remAddr = InetAddress.getAllByName(hostName);
if (remAddr == null) {
return Boolean.FALSE;
}
} catch (UnknownHostException e) {
System.err.println("Unknown host: " + hostName);
return Boolean.FALSE;
} catch (SocketException e1) {
System.err.println(e1.getMessage());
return Boolean.FALSE;
}
for (; interfaces.hasMoreElements();) {
locals = interfaces.nextElement().getInetAddresses();
for (; locals.hasMoreElements();) {
final InetAddress localAddr = locals.nextElement();
for (int i = 0; i < remAddr.length; i++) {
if (localAddr.equals(remAddr[i])) {
return Boolean.TRUE;
}