changeset 3080:3a2a2a75190e

R-29259: Get rid of DesktopToolkit Reviewed-by: Kevin Rushforth
author Artem Ananiev <artem.ananiev@oracle.com>
date Fri, 29 Mar 2013 05:19:31 -0700
parents 8105bb179397
children cd1c891fe695
files javafx-ui-common/src/com/sun/javafx/tk/AppletWindow.java javafx-ui-common/src/com/sun/javafx/tk/DummyToolkit.java javafx-ui-common/src/com/sun/javafx/tk/Toolkit.java javafx-ui-quantum/src/com/sun/javafx/tk/quantum/GlassAppletWindow.java javafx-ui-quantum/src/com/sun/javafx/tk/quantum/MasterTimer.java javafx-ui-quantum/src/com/sun/javafx/tk/quantum/PerformanceTrackerHelper.java javafx-ui-quantum/src/com/sun/javafx/tk/quantum/PerformanceTrackerImpl.java javafx-ui-quantum/src/com/sun/javafx/tk/quantum/QuantumToolkit.java test-stub-toolkit/src/com/sun/javafx/pgstub/StubToolkit.java
diffstat 9 files changed, 503 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/javafx-ui-common/src/com/sun/javafx/tk/AppletWindow.java	Fri Mar 29 05:19:31 2013 -0700
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2010, 2013, 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
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.javafx.tk;
+
+import javafx.stage.Stage;
+import java.util.Map;
+
+/**
+ * Applets must run within a parent window, so this interface will allow the
+ * plugin access to the underlying parent window that all Stages will be created
+ * in.
+ */
+public interface AppletWindow {
+    /*
+     * topStage must be a primary stage and it's backing window a child window
+     * of this AppletWindow or this method will have no effect.
+     * The window will do what it can to make sure the given stage is on top of
+     * the other primary applet stages. In the future we will allow specifying
+     * Z order but that requires low level changes to Glass to do properly.
+     */
+    public void setStageOnTop(Stage topStage);
+
+    public void setBackgroundColor(int color); // RGB triplet: 0xRRGGBB
+    public void setForegroundColor(int color);
+    
+    public void setVisible(boolean state);
+    
+    public void setSize(int width, int height);
+    public int getWidth();
+    public int getHeight();
+    
+    public void setPosition(int x, int y);
+    public int getPositionX();
+    public int getPositionY();
+    
+    // returns CARemoteLayer id (only used on Mac)
+    public int getRemoteLayerId();
+    // dispatchEvent (only used on Mac)
+    public void dispatchEvent(Map eventInfo);
+}
--- a/javafx-ui-common/src/com/sun/javafx/tk/DummyToolkit.java	Fri Mar 29 15:06:14 2013 +0400
+++ b/javafx-ui-common/src/com/sun/javafx/tk/DummyToolkit.java	Fri Mar 29 05:19:31 2013 -0700
@@ -136,6 +136,16 @@
     }
 
     @Override
+    public AppletWindow createAppletWindow(long parent, String serverName) {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
+    public void closeAppletWindow() {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
+
+    @Override
     public TKSystemMenu getSystemMenu() {
         throw new UnsupportedOperationException("Not supported yet.");
     }
--- a/javafx-ui-common/src/com/sun/javafx/tk/Toolkit.java	Fri Mar 29 15:06:14 2013 +0400
+++ b/javafx-ui-common/src/com/sun/javafx/tk/Toolkit.java	Fri Mar 29 05:19:31 2013 -0700
@@ -321,6 +321,24 @@
     public abstract TKStage createTKPopupStage(StageStyle stageStyle, Object owner);
     public abstract TKStage createTKEmbeddedStage(HostInterface host);
 
+    /**
+     * Creates an AppletWindow using the provided window pointer as the parent
+     * window.
+     *
+     * @param parent the native parent which will contain the primary stage
+     * window(s). Used on Windows/Linux platforms.
+     *
+     * @param serverName the name of CARemoteLayerServer which
+     * will be used to register native layer. Used on Mac platform.
+     */
+    public abstract AppletWindow createAppletWindow(long parent, String serverName);
+
+    /**
+     * Perform cleanup in preparation for applet termination, including closing
+     * the applet window.
+     */
+    public abstract void closeAppletWindow();
+
     private final Map<TKPulseListener,Object> stagePulseListeners =
             new WeakHashMap<TKPulseListener,Object>();
     private final Map<TKPulseListener,Object> scenePulseListeners =
@@ -790,7 +808,9 @@
      *
      * @return the key code for shortcut modifier key
      */
-    public abstract KeyCode getPlatformShortcutKey();
+    public KeyCode getPlatformShortcutKey() {
+        return PlatformUtil.isMac() ? KeyCode.META : KeyCode.CONTROL;
+    }
 
     public abstract List<File> showFileChooser(
             TKStage ownerWindow,
--- a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/GlassAppletWindow.java	Fri Mar 29 15:06:14 2013 +0400
+++ b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/GlassAppletWindow.java	Fri Mar 29 05:19:31 2013 -0700
@@ -28,10 +28,13 @@
 import com.sun.glass.ui.Application;
 import com.sun.glass.ui.Window;
 import com.sun.glass.ui.View;
+
+import com.sun.javafx.tk.AppletWindow;
 import com.sun.javafx.tk.TKStage;
-import com.sun.javafx.tk.desktop.AppletWindow;
+
 import java.lang.ref.WeakReference;
 import java.util.Map;
+
 import javafx.stage.Stage;
 
 /**
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/MasterTimer.java	Fri Mar 29 05:19:31 2013 -0700
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2010, 2013, 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
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.javafx.tk.quantum;
+
+import java.util.Map;
+import javafx.animation.Timeline;
+import com.sun.javafx.tk.Toolkit;
+import com.sun.scenario.DelayedRunnable;
+import com.sun.scenario.Settings;
+import com.sun.scenario.animation.AbstractMasterTimer;
+import com.sun.scenario.animation.AnimationPulse;
+
+/**
+ * This class encapsulates the global static methods that manage scheduling and
+ * actual running of animations against real wall clock time. It only deals in
+ * absolute time values - all relative times that are specified in the
+ * {@link Timeline} class will need to be turned into absolute times when the
+ * {@code Timeline} objects are started.
+ *
+ * For now it is hidden until we have some use to expose it.
+ */
+public final class MasterTimer extends AbstractMasterTimer {
+    
+    /** Prevent external instantiation of MasterTimer */
+    private MasterTimer() {
+        super(true);
+    }
+
+    private static final Object MASTER_TIMER_KEY = new StringBuilder(
+            "MasterTimerKey");
+
+    public static synchronized MasterTimer getInstance() {
+        Map<Object, Object> contextMap = Toolkit.getToolkit().getContextMap();
+        MasterTimer instance = (MasterTimer) contextMap.get(MASTER_TIMER_KEY);
+        if (instance == null) {
+            instance = new MasterTimer();
+            contextMap.put(MASTER_TIMER_KEY, instance);
+            if (Settings.getBoolean(ANIMATION_MBEAN_ENABLED,
+                                    enableAnimationMBean)) {
+                AnimationPulse.getDefaultBean().setEnabled(true);
+            }
+        }
+        return instance;
+    }
+
+    /*
+     * Called to set the value of PULSE_DURATION or PULSE_DURATION_NS based on
+     * the refresh rate of the primary screen (unless overridden by the
+     * FRAMERATE_PROP Setting). If the refresh rate can not be determined the
+     * default of 60hz is used.
+     *
+     * @param precision - precision in (1000 for ms or 1000000000 for ns)
+     *
+     * @return pulse duration value, either in ms or ns depending on the
+     * parameter.
+     */
+    protected int getPulseDuration(int precision) {
+        int retVal = precision / 60;
+        // Allow Setting to override monitor refresh
+        if (Settings.get(FRAMERATE_PROP) != null) {
+            int overrideHz = Settings.getInt(FRAMERATE_PROP, 60);
+            if (overrideHz > 0) {
+                retVal = precision / overrideHz;
+            }
+        } else if (Settings.get(PULSE_PROP) != null) {
+            int overrideHz = Settings.getInt(PULSE_PROP, 60);
+            if (overrideHz > 0) {
+                retVal = precision / overrideHz;
+            }
+        } else {
+            // If not explicitly set in Settings, try to set based on
+            // refresh rate of display
+            int rate = Toolkit.getToolkit().getRefreshRate();
+            if (rate > 0) {
+                retVal = precision / rate;
+            }
+            // if unknown, use default
+        }
+        return retVal;
+    }
+
+    protected void postUpdateAnimationRunnable(DelayedRunnable animationRunnable) {
+        Toolkit.getToolkit().setAnimationRunnable(animationRunnable);
+    }
+
+    @Override
+    protected void recordStart(long shiftMillis) {
+        AnimationPulse.getDefaultBean().recordStart(shiftMillis);
+    }
+
+    @Override
+    protected void recordEnd() {
+        AnimationPulse.getDefaultBean().recordEnd();
+    }
+
+    @Override
+    protected void recordAnimationEnd() {
+        AnimationPulse.getDefaultBean().recordAnimationEnd();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/PerformanceTrackerHelper.java	Fri Mar 29 05:19:31 2013 -0700
@@ -0,0 +1,203 @@
+/*
+ * Copyright (c) 2010, 2013, 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
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.javafx.tk.quantum;
+
+import com.sun.javafx.tk.Toolkit;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Class containing implementation for logging, and performance tracking.
+ */
+abstract class PerformanceTrackerHelper {
+
+    private static final PerformanceTrackerHelper instance = createInstance();
+
+    public static PerformanceTrackerHelper getInstance() {
+        return instance;
+    }
+
+    private PerformanceTrackerHelper() {
+    }
+
+    private static PerformanceTrackerHelper createInstance() {
+        PerformanceTrackerHelper trackerImpl = AccessController.doPrivileged(
+                new PrivilegedAction<PerformanceTrackerHelper>() {
+
+                    @Override
+                    public PerformanceTrackerHelper run() {
+                        try {
+                            if (System.getProperty("sun.perflog") != null) {
+                                final PerformanceTrackerHelper trackerImpl =
+                                        new PerformanceTrackerDefaultImpl();
+
+                                if (System.getProperty(
+                                        "sun.perflog.fx.exitflush") != null) {
+                                    Runtime.getRuntime().addShutdownHook(
+                                            new Thread() {
+
+                                                @Override
+                                                public void run() {
+                                                    trackerImpl.outputLog();
+                                                }
+                                            });
+                                }
+
+                                return trackerImpl;
+                            }
+                        } catch (Throwable t) {
+                        }
+
+                        return null;
+                    }
+                });
+
+        if (trackerImpl == null) {
+            trackerImpl = new PerformanceTrackerDummyImpl();
+        }
+
+        return trackerImpl;
+    }
+
+    public abstract void logEvent(final String s);
+
+    public abstract void outputLog();
+
+    public abstract boolean isPerfLoggingEnabled();
+
+    public final long nanoTime() {
+        return Toolkit.getToolkit().getMasterTimer().nanos();
+    }
+
+    private static final class PerformanceTrackerDefaultImpl
+            extends PerformanceTrackerHelper {
+        private long firstTime;
+        private long lastTime;
+
+        private final Method logEventMethod;
+        private final Method outputLogMethod;
+        private final Method getStartTimeMethod;
+        private final Method setStartTimeMethod;
+
+        public PerformanceTrackerDefaultImpl() throws ClassNotFoundException,
+                                                      NoSuchMethodException {
+            final Class perfLoggerClass =
+                    Class.forName("sun.misc.PerformanceLogger", true, null);
+
+            logEventMethod =
+                    perfLoggerClass.getMethod("setTime", String.class);
+            outputLogMethod =
+                    perfLoggerClass.getMethod("outputLog");
+            getStartTimeMethod =
+                    perfLoggerClass.getMethod("getStartTime");
+            setStartTimeMethod =
+                    perfLoggerClass.getMethod("setStartTime", String.class,
+                                              long.class);
+        }
+
+        @Override
+        public void logEvent(final String s) {
+            final long time = System.currentTimeMillis();
+            if (firstTime == 0) {
+                firstTime = time;
+            }
+
+            try {
+                logEventMethod.invoke(
+                        null,
+                        "JavaFX> " + s + " ("
+                        + (time - firstTime) + "ms total, "
+                        + (time - lastTime) + "ms)");
+            } catch (IllegalAccessException ex) {
+            } catch (IllegalArgumentException ex) {
+            } catch (InvocationTargetException ex) {
+            }
+
+            lastTime = time;
+        }
+
+        @Override
+        public void outputLog() {
+
+            logLaunchTime();
+
+            // Output the log
+            try {
+                outputLogMethod.invoke(null);
+            } catch (Exception e) {
+            }
+        }
+
+        @Override
+        public boolean isPerfLoggingEnabled() {
+            return true;
+        }
+
+        private void logLaunchTime() {
+            try {
+                // Attempt to log launchTime, if not set already
+                if ((Long) getStartTimeMethod.invoke(null) <= 0) {
+                    // Standalone apps record launch time as sysprop
+                    String launchTimeString = AccessController.doPrivileged(
+                            new PrivilegedAction<String>() {
+
+                                @Override
+                                public String run() {
+                                    return System.getProperty("launchTime");
+                                }
+                            });
+                    
+                    if (launchTimeString != null
+                            && !launchTimeString.equals("")) {
+                        long launchTime = Long.parseLong(launchTimeString);
+                        setStartTimeMethod.invoke(
+                                null, "LaunchTime", launchTime);
+                    }
+                }
+            } catch (Throwable t) {
+                t.printStackTrace();
+            }
+        }
+    }
+
+    private static final class PerformanceTrackerDummyImpl
+            extends PerformanceTrackerHelper {
+        @Override
+        public void logEvent(final String s) {
+        }
+
+        @Override
+        public void outputLog() {
+        }
+
+        @Override
+        public boolean isPerfLoggingEnabled() {
+            return false;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/PerformanceTrackerImpl.java	Fri Mar 29 05:19:31 2013 -0700
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2010, 2013, 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
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.javafx.tk.quantum;
+
+import com.sun.javafx.perf.PerformanceTracker;
+
+/**
+ * Class containing implementation for logging, and performance tracking.
+ */
+final class PerformanceTrackerImpl extends PerformanceTracker {
+
+    final PerformanceTrackerHelper helper =
+            PerformanceTrackerHelper.getInstance();
+
+    public PerformanceTrackerImpl() {
+       setPerfLoggingEnabled(helper.isPerfLoggingEnabled());
+    }
+
+    @Override public void doLogEvent(String s) {
+        helper.logEvent(s);
+    }
+
+    @Override public void doOutputLog() {
+        helper.outputLog();
+    }
+
+    @Override public long nanoTime() {
+        return helper.nanoTime();
+    }
+}
--- a/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/QuantumToolkit.java	Fri Mar 29 15:06:14 2013 +0400
+++ b/javafx-ui-quantum/src/com/sun/javafx/tk/quantum/QuantumToolkit.java	Fri Mar 29 05:19:31 2013 -0700
@@ -124,6 +124,7 @@
 import com.sun.javafx.sg.prism.NGRegion;
 import com.sun.javafx.sg.prism.NGSVGPath;
 import com.sun.javafx.sg.prism.NGText;
+import com.sun.javafx.tk.AppletWindow;
 import com.sun.javafx.tk.FileChooserType;
 import com.sun.javafx.tk.FontLoader;
 import com.sun.javafx.tk.ImageLoader;
@@ -138,9 +139,6 @@
 import com.sun.javafx.tk.TKStage;
 import com.sun.javafx.tk.TKSystemMenu;
 import com.sun.javafx.tk.Toolkit;
-import com.sun.javafx.tk.desktop.AppletWindow;
-import com.sun.javafx.tk.desktop.DesktopToolkit;
-import com.sun.javafx.tk.desktop.MasterTimer;
 import com.sun.prism.BasicStroke;
 import com.sun.prism.Graphics;
 import com.sun.prism.GraphicsPipeline;
@@ -189,7 +187,7 @@
 import com.sun.javafx.sg.prism.NGTriangleMesh;
 import com.sun.javafx.sg.prism.NGExternalNode;
 
-public final class QuantumToolkit extends DesktopToolkit implements ToolkitInterface {
+public final class QuantumToolkit extends Toolkit implements ToolkitInterface {
 
     public static final boolean verbose =
             AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
@@ -272,6 +270,8 @@
 
     private HashMap<Object,EventLoop> eventLoopMap = null;
 
+    private final PerformanceTracker perfTracker = new PerformanceTrackerImpl();
+
     @Override public boolean init() {
         /*
          * The below no longer applies with for jfx 8.0 on jdk 8.0. But leaving
@@ -708,6 +708,16 @@
         return Screen.getScreens();
     }
 
+    @Override
+    public PerformanceTracker getPerformanceTracker() {
+        return perfTracker;
+    }
+
+    @Override
+    public PerformanceTracker createPerformanceTracker() {
+        return new PerformanceTrackerImpl();
+    }
+
     public float getMaxPixelScale() {
         if (_maxPixelScale == 0) {
             for (Object o : getScreens()) {
@@ -1293,11 +1303,6 @@
         view.setTKDragGestureListener(l);
     }
 
-    /* com.sun.javafx.tk.desktop.DesktopToolkit */
-    @Override public boolean isAppletDragSupported() {
-        return false;
-    }
-
     @Override
     public void installInputMethodRequests(TKScene scene, InputMethodRequests requests) {
 
--- a/test-stub-toolkit/src/com/sun/javafx/pgstub/StubToolkit.java	Fri Mar 29 15:06:14 2013 +0400
+++ b/test-stub-toolkit/src/com/sun/javafx/pgstub/StubToolkit.java	Fri Mar 29 05:19:31 2013 -0700
@@ -106,6 +106,7 @@
 import com.sun.javafx.sg.PGSphere;
 import com.sun.javafx.sg.PGText;
 import com.sun.javafx.sg.PGTriangleMesh;
+import com.sun.javafx.tk.AppletWindow;
 import com.sun.javafx.tk.FileChooserType;
 import com.sun.javafx.tk.FontLoader;
 import com.sun.javafx.tk.ImageLoader;
@@ -199,6 +200,17 @@
     }
 
     @Override
+    public AppletWindow createAppletWindow(long parent, String serverName) {
+        // unsupported
+        return null;
+    }
+
+    @Override
+    public void closeAppletWindow() {
+        // unsupported
+    }
+
+    @Override
     public TKSystemMenu getSystemMenu() {
         return new StubSystemMenu();
     }