modules/graphics/src/main/java/com/sun/glass/ui/win/WinApplication.java

Print this page




  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package com.sun.glass.ui.win;
  26 
  27 import com.sun.glass.ui.*;
  28 import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
  29 import com.sun.glass.ui.CommonDialogs.FileChooserResult;
  30 import com.sun.glass.utils.NativeLibLoader;
  31 import com.sun.prism.impl.PrismSettings;
  32 
  33 import java.io.File;
  34 import java.nio.ByteBuffer;
  35 import java.nio.IntBuffer;
  36 import java.security.AccessController;
  37 import java.security.PrivilegedAction;
  38 
  39 final class WinApplication extends Application implements InvokeLaterDispatcher.InvokeLaterSubmitter {
  40     static float   overrideUIScale;
  41     static float   overrideRenderScale;
  42     static float   minDPIScale;
  43     static boolean forceIntegerRenderScale;
  44 
  45     private static boolean getBoolean(String propname, boolean defval, String description) {
  46         String str = System.getProperty(propname);
  47         if (str == null) {
  48             str = System.getenv(propname);
  49         }
  50         if (str == null) {
  51             return defval;
  52         }
  53         Boolean ret = Boolean.parseBoolean(str);
  54         if (PrismSettings.verbose) {
  55             System.out.println((ret ? "" : "not ")+description);
  56         }
  57         return ret;
  58     }
  59 
  60     private static float getFloat(String propname, float defval, String description) {
  61         String str = System.getProperty(propname);
  62         if (str == null) {
  63             str = System.getenv(propname);
  64         }
  65         if (str == null) {
  66             return defval;
  67         }
  68         str = str.trim();
  69         float val;
  70         if (str.endsWith("%")) {
  71             val = Integer.parseInt(str.substring(0, str.length()-1)) / 100.0f;
  72         } else if (str.endsWith("DPI") || str.endsWith("dpi")) {
  73             val = Integer.parseInt(str.substring(0, str.length()-3)) / 96.0f;
  74         } else {
  75             val = Float.parseFloat(str);
  76         }
  77         if (PrismSettings.verbose) {
  78             System.out.println(description+val);
  79         }
  80         return val;
  81     }
  82 
  83     private static native void initIDs(float overrideUIScale,
  84                                        float overrideRenderScale,
  85                                        float minDPIScale,
  86                                        boolean forceIntegerRenderScale);
  87     static {
  88         // This loading of msvcr120.dll and msvcp120.dll (VS2013) is required when run with Java 8
  89         // since it was build with VS2010 and doesn't include msvcr120.dll in its JRE.
  90         // Note: See README-builds.html on MSVC requirement: VS2013 is required.
  91         AccessController.doPrivileged(new PrivilegedAction<Void>() {
  92             public Void run() {
  93                 verbose = Boolean.getBoolean("javafx.verbose");
  94                 if (PrismSettings.allowHiDPIScaling) {
  95                     overrideUIScale = getFloat("glass.win.uiScale", -1.0f, "Forcing UI scaling factor: ");
  96                     overrideRenderScale = getFloat("glass.win.renderScale", -1.0f, "Forcing Rendering scaling factor: ");
  97                     minDPIScale = getFloat("glass.win.minHiDPI", 1.5f, "Threshold to enable UI scaling factor: ");
  98                     forceIntegerRenderScale = getBoolean("glass.win.forceIntegerRenderScale", true, "forcing integer rendering scale");






  99                 } else {
 100                     overrideUIScale = overrideRenderScale = 1.0f;
 101                     minDPIScale = Float.MAX_VALUE;
 102                     forceIntegerRenderScale = false;
 103                 }
 104                 try {
 105                     NativeLibLoader.loadLibrary("msvcr120");
 106                 } catch (Throwable t) {
 107                     if (verbose) {
 108                         System.err.println("Error: failed to load msvcr120.dll : " + t);
 109                     }
 110                 }
 111                 try {
 112                     NativeLibLoader.loadLibrary("msvcp120");
 113                 } catch (Throwable t) {
 114                     if (verbose) {
 115                         System.err.println("Error: failed to load msvcp120.dll : " + t);
 116                     }
 117                 }
 118                 Application.loadNativeLibrary();
 119                 return null;
 120             }
 121         });
 122         initIDs(overrideUIScale, overrideRenderScale, minDPIScale, forceIntegerRenderScale);
 123     }
 124 
 125     private final InvokeLaterDispatcher invokeLaterDispatcher;
 126     WinApplication() {
 127         // Embedded in SWT, with shared event thread
 128         boolean isEventThread = AccessController
 129                 .doPrivileged((PrivilegedAction<Boolean>) () -> Boolean.getBoolean("javafx.embed.isEventThread"));
 130         if (!isEventThread) {
 131             invokeLaterDispatcher = new InvokeLaterDispatcher(this);
 132             invokeLaterDispatcher.start();
 133         } else {
 134             invokeLaterDispatcher = null;
 135         }
 136     }
 137 
 138     private static boolean verbose;
 139 
 140     // returng toolkit window HWND
 141     private native long _init(int awarenessRequested);
 142     private native void _setClassLoader(ClassLoader classLoader);


 252         return new WinCursor(x, y, pixels);
 253     }
 254 
 255     @Override protected void staticCursor_setVisible(boolean visible) {
 256         WinCursor.setVisible_impl(visible);
 257     }
 258 
 259     @Override protected Size staticCursor_getBestSize(int width, int height) {
 260         return WinCursor.getBestSize_impl(width, height);
 261     }
 262 
 263     @Override public Pixels createPixels(int width, int height, ByteBuffer data) {
 264         return new WinPixels(width, height, data);
 265     }
 266 
 267     @Override public Pixels createPixels(int width, int height, IntBuffer data) {
 268         return new WinPixels(width, height, data);
 269     }
 270 
 271     @Override
 272     public Pixels createPixels(int width, int height, IntBuffer data, float scale) {
 273         return new WinPixels(width, height, data, scale);
 274     }
 275 
 276     @Override protected int staticPixels_getNativeFormat() {
 277         return WinPixels.getNativeFormat_impl();
 278     }
 279 
 280     @Override public Robot createRobot() {
 281         return new WinRobot();
 282     }
 283 
 284     @Override protected double staticScreen_getVideoRefreshPeriod() {
 285         return 0.0;     // indicate millisecond resolution
 286     }
 287 
 288     @Override native protected Screen[] staticScreen_getScreens();
 289 
 290     @Override public Timer createTimer(Runnable runnable) {
 291         return new WinTimer(runnable);
 292     }
 293 




  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package com.sun.glass.ui.win;
  26 
  27 import com.sun.glass.ui.*;
  28 import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
  29 import com.sun.glass.ui.CommonDialogs.FileChooserResult;
  30 import com.sun.glass.utils.NativeLibLoader;
  31 import com.sun.prism.impl.PrismSettings;
  32 
  33 import java.io.File;
  34 import java.nio.ByteBuffer;
  35 import java.nio.IntBuffer;
  36 import java.security.AccessController;
  37 import java.security.PrivilegedAction;
  38 
  39 final class WinApplication extends Application implements InvokeLaterDispatcher.InvokeLaterSubmitter {
  40     static float   overrideUIScale;



  41 
  42     private static boolean getBoolean(String propname, boolean defval, String description) {
  43         String str = System.getProperty(propname);
  44         if (str == null) {
  45             str = System.getenv(propname);
  46         }
  47         if (str == null) {
  48             return defval;
  49         }
  50         Boolean ret = Boolean.parseBoolean(str);
  51         if (PrismSettings.verbose) {
  52             System.out.println((ret ? "" : "not ")+description);
  53         }
  54         return ret;
  55     }
  56 
  57     private static float getFloat(String propname, float defval, String description) {
  58         String str = System.getProperty(propname);
  59         if (str == null) {
  60             str = System.getenv(propname);
  61         }
  62         if (str == null) {
  63             return defval;
  64         }
  65         str = str.trim();
  66         float val;
  67         if (str.endsWith("%")) {
  68             val = Integer.parseInt(str.substring(0, str.length()-1)) / 100.0f;
  69         } else if (str.endsWith("DPI") || str.endsWith("dpi")) {
  70             val = Integer.parseInt(str.substring(0, str.length()-3)) / 96.0f;
  71         } else {
  72             val = Float.parseFloat(str);
  73         }
  74         if (PrismSettings.verbose) {
  75             System.out.println(description+val);
  76         }
  77         return val;
  78     }
  79 
  80     private static native void initIDs(float overrideUIScale);



  81     static {
  82         // This loading of msvcr120.dll and msvcp120.dll (VS2013) is required when run with Java 8
  83         // since it was build with VS2010 and doesn't include msvcr120.dll in its JRE.
  84         // Note: See README-builds.html on MSVC requirement: VS2013 is required.
  85         AccessController.doPrivileged(new PrivilegedAction<Void>() {
  86             public Void run() {
  87                 verbose = Boolean.getBoolean("javafx.verbose");
  88                 if (PrismSettings.allowHiDPIScaling) {
  89                     overrideUIScale = getFloat("glass.win.uiScale", -1.0f, "Forcing UI scaling factor: ");
  90                     // We only parse these if verbose, to inform the user...
  91                     if (PrismSettings.verbose) {
  92                         getFloat("glass.win.renderScale", -1.0f,
  93                                  "(No longer supported) Rendering scaling factor: ");
  94                         getFloat("glass.win.minHiDPI", 1.5f,
  95                                  "(No longer supported) UI scaling threshold: ");
  96                         getBoolean("glass.win.forceIntegerRenderScale", true,
  97                                    "(No longer supported) force integer rendering scale");
  98                     }
  99                 } else {
 100                     overrideUIScale = 1.0f;


 101                 }
 102                 try {
 103                     NativeLibLoader.loadLibrary("msvcr120");
 104                 } catch (Throwable t) {
 105                     if (verbose) {
 106                         System.err.println("Error: failed to load msvcr120.dll : " + t);
 107                     }
 108                 }
 109                 try {
 110                     NativeLibLoader.loadLibrary("msvcp120");
 111                 } catch (Throwable t) {
 112                     if (verbose) {
 113                         System.err.println("Error: failed to load msvcp120.dll : " + t);
 114                     }
 115                 }
 116                 Application.loadNativeLibrary();
 117                 return null;
 118             }
 119         });
 120         initIDs(overrideUIScale);
 121     }
 122 
 123     private final InvokeLaterDispatcher invokeLaterDispatcher;
 124     WinApplication() {
 125         // Embedded in SWT, with shared event thread
 126         boolean isEventThread = AccessController
 127                 .doPrivileged((PrivilegedAction<Boolean>) () -> Boolean.getBoolean("javafx.embed.isEventThread"));
 128         if (!isEventThread) {
 129             invokeLaterDispatcher = new InvokeLaterDispatcher(this);
 130             invokeLaterDispatcher.start();
 131         } else {
 132             invokeLaterDispatcher = null;
 133         }
 134     }
 135 
 136     private static boolean verbose;
 137 
 138     // returng toolkit window HWND
 139     private native long _init(int awarenessRequested);
 140     private native void _setClassLoader(ClassLoader classLoader);


 250         return new WinCursor(x, y, pixels);
 251     }
 252 
 253     @Override protected void staticCursor_setVisible(boolean visible) {
 254         WinCursor.setVisible_impl(visible);
 255     }
 256 
 257     @Override protected Size staticCursor_getBestSize(int width, int height) {
 258         return WinCursor.getBestSize_impl(width, height);
 259     }
 260 
 261     @Override public Pixels createPixels(int width, int height, ByteBuffer data) {
 262         return new WinPixels(width, height, data);
 263     }
 264 
 265     @Override public Pixels createPixels(int width, int height, IntBuffer data) {
 266         return new WinPixels(width, height, data);
 267     }
 268 
 269     @Override
 270     public Pixels createPixels(int width, int height, IntBuffer data, float scalex, float scaley) {
 271         return new WinPixels(width, height, data, scalex, scaley);
 272     }
 273 
 274     @Override protected int staticPixels_getNativeFormat() {
 275         return WinPixels.getNativeFormat_impl();
 276     }
 277 
 278     @Override public Robot createRobot() {
 279         return new WinRobot();
 280     }
 281 
 282     @Override protected double staticScreen_getVideoRefreshPeriod() {
 283         return 0.0;     // indicate millisecond resolution
 284     }
 285 
 286     @Override native protected Screen[] staticScreen_getScreens();
 287 
 288     @Override public Timer createTimer(Runnable runnable) {
 289         return new WinTimer(runnable);
 290     }
 291