< prev index next >

src/solaris/classes/sun/awt/UNIXToolkit.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2004, 2010, 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 --- 1,7 ---- /* ! * Copyright (c) 2004, 2018, 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,49 **** --- 27,85 ---- 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; + // Allowed GTK versions + public enum GtkVersions { + ANY(0), + GTK2(Constants.GTK2_MAJOR_NUMBER), + GTK3(Constants.GTK3_MAJOR_NUMBER); + + static class Constants { + static final int GTK2_MAJOR_NUMBER = 2; + static final int GTK3_MAJOR_NUMBER = 3; + } + + final int number; + + GtkVersions(int number) { + this.number = number; + } + + public static GtkVersions getVersion(int number) { + switch (number) { + case Constants.GTK2_MAJOR_NUMBER: + return GTK2; + case Constants.GTK3_MAJOR_NUMBER: + return GTK3; + default: + return ANY; + } + } + + // major GTK version number + public int getNumber() { + return number; + } + }; + private Boolean nativeGTKAvailable; private Boolean nativeGTKLoaded; private BufferedImage tmpImage = null; public static int getDatatransferTimeout() {
*** 77,87 **** // 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(); nativeGTKAvailable = success; return success; } } } --- 113,123 ---- // 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(getEnabledGtkVersion().getNumber()); nativeGTKAvailable = success; return success; } } }
*** 95,105 **** * lightweight boolean check, no native calls required). */ public boolean loadGTK() { synchronized (GTK_LOCK) { if (nativeGTKLoaded == null) { ! nativeGTKLoaded = load_gtk(); } } return nativeGTKLoaded; } --- 131,142 ---- * lightweight boolean check, no native calls required). */ public boolean loadGTK() { synchronized (GTK_LOCK) { if (nativeGTKLoaded == null) { ! nativeGTKLoaded = load_gtk(getEnabledGtkVersion().getNumber(), ! isGtkVerbose()); } } return nativeGTKLoaded; }
*** 238,255 **** // 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 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(); @Override public void sync() { // flush the X11 buffer nativeSync(); --- 275,293 ---- // 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(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();
*** 335,340 **** --- 373,400 ---- 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.getVersion(get_gtk_version()); + } + + public static boolean isGtkVerbose() { + return AccessController.doPrivileged((PrivilegedAction<Boolean>)() + -> Boolean.getBoolean("jdk.gtk.verbose")); + } }
< prev index next >