[OpenJDK 2D-Dev] [PATCH] SwingUtilities2.isLocalDisplay()

Roman Kennke roman.kennke at aicas.com
Fri Sep 5 18:55:05 UTC 2008


Hi there,

I've just synced up the Cacio forest with the JDK7 master forest, and
I'd like to discuss and try to merge back (into JDK7) some of our
patches. The following one affects all of AWT, Swing and J2D, this is
why I'm posting it to 3 lists at once.

In SwingUtilities2.isLocalDisplay(), we have some crazy platform
specific code to find if we have a local display or not. This is of
course not very nice for other Toolkit implementations than the Win32
and X11 ones in OpenJDK. Our solution is to introduce an abstract method
isLocalDisplay() in SunGraphicsEnvironment, which we call from
SwingUtilities2. This method is then overridden by the specific GE
implementations. If we don't have a SGE, we assume a local display.

There are also some changes in the native font code, which used to call
the static X11GraphicsEnvironment.isLocalDisplay(), to call the new
instance method in SGE.

What do you think? Is this reasonable to merge into mainline?

/Roman

-- 
Dipl.-Inform. (FH) Roman Kennke, Software Engineer, http://kennke.org
aicas Allerton Interworks Computer Automated Systems GmbH
Haid-und-Neu-Straße 18 * D-76131 Karlsruhe * Germany
http://www.aicas.com   * Tel: +49-721-663 968-48
USt-Id: DE216375633, Handelsregister HRB 109481, AG Karlsruhe
Geschäftsführer: Dr. James J. Hunt
-------------- next part --------------
# HG changeset patch
# User Mario Torre <mario.torre at aicas.com>
# Date 1217450571 -7200
# Node ID f3ae1241a9b87efec5e22618dcf978ae38c94abd
# Parent  9e3c020a78dd72dcbcc8580762f2542055110e2e
imported patch j2d-localdisplay.patch

diff -r 9e3c020a78dd -r f3ae1241a9b8 src/share/classes/sun/java2d/SunGraphicsEnvironment.java
--- a/src/share/classes/sun/java2d/SunGraphicsEnvironment.java	Wed Jul 30 22:42:51 2008 +0200
+++ b/src/share/classes/sun/java2d/SunGraphicsEnvironment.java	Wed Jul 30 22:42:51 2008 +0200
@@ -1270,6 +1270,13 @@
         displayChanger.notifyPaletteChanged();
     }
 
+    /**
+     * Returns true when the display is local, false for remote displays.
+     *
+     * @return true when the display is local, false for remote displays
+     */
+    public abstract boolean isDisplayLocal();
+
     /*
      * ----DISPLAY CHANGE SUPPORT----
      */
diff -r 9e3c020a78dd -r f3ae1241a9b8 src/share/classes/sun/swing/SwingUtilities2.java
--- a/src/share/classes/sun/swing/SwingUtilities2.java	Wed Jul 30 22:42:51 2008 +0200
+++ b/src/share/classes/sun/swing/SwingUtilities2.java	Wed Jul 30 22:42:51 2008 +0200
@@ -55,6 +55,7 @@
 import java.util.*;
 import sun.font.FontDesignMetrics;
 import sun.font.FontManager;
+import sun.java2d.SunGraphicsEnvironment;
 
 import java.util.concurrent.Callable;
 import java.util.concurrent.Future;
@@ -1482,22 +1483,14 @@
      * appear capable of performing gamma correction needed for LCD text.
      */
     public static boolean isLocalDisplay() {
-        try {
-            // On Windows just return true. Permission to read os.name
-            // is granted to all code but wrapped in try to be safe.
-            if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS) {
-                return true;
-            }
-            // Else probably Solaris or Linux in which case may be remote X11
-            Class x11Class = Class.forName("sun.awt.X11GraphicsEnvironment");
-            Method isDisplayLocalMethod = x11Class.getMethod(
-                      "isDisplayLocal", new Class[0]);
-            return (Boolean)isDisplayLocalMethod.invoke(null, (Object[])null);
-        } catch (Throwable t) {
+        boolean isLocal;
+        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+        if (ge instanceof SunGraphicsEnvironment) {
+            isLocal = ((SunGraphicsEnvironment) ge).isDisplayLocal();
+        } else {
+            isLocal = true;
         }
-        // If we get here we're most likely being run on some other O/S
-        // or we didn't properly detect Windows.
-        return true;
+        return isLocal;
     }
 
     /**
diff -r 9e3c020a78dd -r f3ae1241a9b8 src/solaris/classes/sun/awt/X11GraphicsEnvironment.java
--- a/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java	Wed Jul 30 22:42:51 2008 +0200
+++ b/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java	Wed Jul 30 22:42:51 2008 +0200
@@ -208,7 +208,7 @@
     private static native int checkShmExt();
 
     private static  native String getDisplayString();
-    private static Boolean isDisplayLocal;
+    private Boolean isDisplayLocal;
 
     /**
      * This should only be called from the static initializer, so no need for
@@ -233,7 +233,7 @@
         return getScreenDevices()[getDefaultScreenNum()];
     }
 
-    public static boolean isDisplayLocal() {
+    public boolean isDisplayLocal() {
         if (isDisplayLocal == null) {
             SunToolkit.awtLock();
             try {
diff -r 9e3c020a78dd -r f3ae1241a9b8 src/solaris/native/sun/awt/fontpath.c
--- a/src/solaris/native/sun/awt/fontpath.c	Wed Jul 30 22:42:51 2008 +0200
+++ b/src/solaris/native/sun/awt/fontpath.c	Wed Jul 30 22:42:51 2008 +0200
@@ -150,15 +150,26 @@
     static jboolean isLocalSet = False;
     jboolean ret;
 
-    if (isLocalSet) {
-        return isLocal;
+    if (! isLocalSet) {
+      jclass geCls = (*env)->FindClass(env, "java/awt/GraphicsEnvironment");
+      jmethodID getLocalGE = (*env)->GetStaticMethodID(env, geCls,
+                                                 "getLocalGraphicsEnvironment",
+                                           "()Ljava/awt/GraphicsEnvironment;");
+      jobject ge = (*env)->CallStaticObjectMethod(env, geCls, getLocalGE);
+
+      jclass sgeCls = (*env)->FindClass(env,
+                                        "sun/java2d/SunGraphicsEnvironment");
+      if ((*env)->IsInstanceOf(env, ge, sgeCls)) {
+        jmethodID isDisplayLocal = (*env)->GetMethodID(env, sgeCls,
+                                                       "isDisplayLocal",
+                                                       "()Z");
+        isLocal = (*env)->CallBooleanMethod(env, ge, isDisplayLocal);
+      } else {
+        isLocal = True;
+      }
+      isLocalSet = True;
     }
 
-    isLocal = JNU_CallStaticMethodByName(env, NULL,
-                                         "sun/awt/X11GraphicsEnvironment",
-                                         "isDisplayLocal",
-                                         "()Z").z;
-    isLocalSet = True;
     return isLocal;
 }
 
diff -r 9e3c020a78dd -r f3ae1241a9b8 src/windows/classes/sun/awt/Win32GraphicsEnvironment.java
--- a/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java	Wed Jul 30 22:42:51 2008 +0200
+++ b/src/windows/classes/sun/awt/Win32GraphicsEnvironment.java	Wed Jul 30 22:42:51 2008 +0200
@@ -346,4 +346,8 @@
 
         return new WFontConfiguration(this, preferLocaleFonts,preferPropFonts);
     }
+
+    public boolean isDisplayLocal() {
+        return true;
+    }
 }


More information about the 2d-dev mailing list