< prev index next >

src/java.desktop/unix/classes/sun/awt/UNIXToolkit.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -27,23 +27,28 @@
 import java.awt.RenderingHints;
 import static java.awt.RenderingHints.*;
 import java.awt.color.ColorSpace;
 import java.awt.image.*;
 import java.security.AccessController;
+import java.security.PrivilegedAction;
+
 import sun.security.action.GetIntegerAction;
 import com.sun.java.swing.plaf.gtk.GTKConstants.TextDirection;
 import sun.java2d.opengl.OGLRenderQueue;
+import sun.security.action.GetPropertyAction;
 
 public abstract class UNIXToolkit extends SunToolkit
 {
     /** All calls into GTK should be synchronized on this lock */
     public static final Object GTK_LOCK = new Object();
 
     private static final int[] BAND_OFFSETS = { 0, 1, 2 };
     private static final int[] BAND_OFFSETS_ALPHA = { 0, 1, 2, 3 };
     private static final int DEFAULT_DATATRANSFER_TIMEOUT = 10000;
 
+    public enum GtkVersions {ANY, GTK1, GTK2, GTK3};
+
     private Boolean nativeGTKAvailable;
     private Boolean nativeGTKLoaded;
     private BufferedImage tmpImage = null;
 
     public static int getDatatransferTimeout() {

@@ -77,11 +82,11 @@
                 // We've already checked the availability of the native GTK
                 // libraries, so just return the status of that attempt.
                 return nativeGTKAvailable;
 
             } else {
-                boolean success = check_gtk();
+                boolean success = check_gtk(getEnabledGtkVersion().ordinal());
                 nativeGTKAvailable = success;
                 return success;
             }
         }
     }

@@ -95,11 +100,12 @@
      * lightweight boolean check, no native calls required).
      */
     public boolean loadGTK() {
         synchronized (GTK_LOCK) {
             if (nativeGTKLoaded == null) {
-                nativeGTKLoaded = load_gtk();
+                nativeGTKLoaded = load_gtk(getEnabledGtkVersion().ordinal(),
+                                                                isGtkVerbose());
             }
         }
         return nativeGTKLoaded;
     }
 

@@ -239,18 +245,19 @@
         // Set the local image so we can return it later from
         // getStockIcon().
         tmpImage = new BufferedImage(colorModel, raster, false, null);
     }
 
-    private static native boolean check_gtk();
-    private static native boolean load_gtk();
+    private static native boolean check_gtk(int version);
+    private static native boolean load_gtk(int version, boolean verbose);
     private static native boolean unload_gtk();
     private native boolean load_gtk_icon(String filename);
     private native boolean load_stock_icon(int widget_type, String stock_id,
             int iconSize, int textDirection, String detail);
 
     private native void nativeSync();
+    private static native int get_gtk_version();
 
     @Override
     public void sync() {
         // flush the X11 buffer
         nativeSync();

@@ -336,6 +343,28 @@
         if (loadGTK()) {
             return gtkCheckVersionImpl(major, minor, micro);
         }
         return false;
     }
+
+    public static GtkVersions getEnabledGtkVersion() {
+        String version = AccessController.doPrivileged(
+                new GetPropertyAction("jdk.gtk.version"));
+        if (version == null) {
+            return GtkVersions.ANY;
+        } else if (version.startsWith("2")) {
+            return GtkVersions.GTK2;
+        } else if("3".equals(version) ){
+            return GtkVersions.GTK3;
+        }
+        return GtkVersions.ANY;
+    }
+
+    public static GtkVersions getGtkVersion() {
+        return GtkVersions.values()[get_gtk_version()];
+    }
+
+    public static boolean isGtkVerbose() {
+        return AccessController.doPrivileged((PrivilegedAction<Boolean>)()
+                -> Boolean.getBoolean("jdk.gtk.verbose"));
+    }
 }
< prev index next >