8216318: The usage of Disposer in the java.awt.Robot can be deleted
authorserb
Thu, 31 Jan 2019 15:20:42 -0800
changeset 53677 01980f91eac1
parent 53676 24a861d4b4f0
child 53678 9b93a6b30cbe
8216318: The usage of Disposer in the java.awt.Robot can be deleted Reviewed-by: prr
src/java.desktop/macosx/classes/sun/lwawt/macosx/CRobot.java
src/java.desktop/share/classes/java/awt/Robot.java
src/java.desktop/share/classes/java/awt/peer/RobotPeer.java
src/java.desktop/unix/classes/sun/awt/X11/XRobotPeer.java
src/java.desktop/windows/classes/sun/awt/windows/WRobotPeer.java
src/java.desktop/windows/native/libawt/windows/awt_Robot.cpp
src/java.desktop/windows/native/libawt/windows/awt_Robot.h
--- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CRobot.java	Thu Jan 31 08:45:23 2019 +0530
+++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CRobot.java	Thu Jan 31 15:20:42 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2019, 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
@@ -54,10 +54,6 @@
         initRobot();
     }
 
-    @Override
-    public void dispose() {
-    }
-
     /**
      * Moves mouse pointer to given screen coordinates.
      * @param x X position
--- a/src/java.desktop/share/classes/java/awt/Robot.java	Thu Jan 31 08:45:23 2019 +0530
+++ b/src/java.desktop/share/classes/java/awt/Robot.java	Thu Jan 31 15:20:42 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2019, 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
@@ -134,8 +134,6 @@
         Toolkit toolkit = Toolkit.getDefaultToolkit();
         if (toolkit instanceof ComponentFactory) {
             peer = ((ComponentFactory)toolkit).createRobot(this, screen);
-            disposer = new RobotDisposer(peer);
-            sun.java2d.Disposer.addRecord(anchor, disposer);
         }
         initLegalButtonMask();
     }
@@ -177,22 +175,6 @@
         }
     }
 
-    private transient Object anchor = new Object();
-
-    static class RobotDisposer implements sun.java2d.DisposerRecord {
-        private final RobotPeer peer;
-        public RobotDisposer(RobotPeer peer) {
-            this.peer = peer;
-        }
-        public void dispose() {
-            if (peer != null) {
-                peer.dispose();
-            }
-        }
-    }
-
-    private transient RobotDisposer disposer;
-
     /**
      * Moves mouse pointer to given screen coordinates.
      * @param x         X position
--- a/src/java.desktop/share/classes/java/awt/peer/RobotPeer.java	Thu Jan 31 08:45:23 2019 +0530
+++ b/src/java.desktop/share/classes/java/awt/peer/RobotPeer.java	Thu Jan 31 15:20:42 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2019, 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
@@ -25,7 +25,8 @@
 
 package java.awt.peer;
 
-import java.awt.*;
+import java.awt.Rectangle;
+import java.awt.Robot;
 
 /**
  * RobotPeer defines an interface whereby toolkits support automated testing
@@ -116,9 +117,4 @@
      * @see Robot#createScreenCapture(Rectangle)
      */
     int[] getRGBPixels(Rectangle bounds);
-
-    /**
-     * Disposes the robot peer when it is not needed anymore.
-     */
-    void dispose();
 }
--- a/src/java.desktop/unix/classes/sun/awt/X11/XRobotPeer.java	Thu Jan 31 08:45:23 2019 +0530
+++ b/src/java.desktop/unix/classes/sun/awt/X11/XRobotPeer.java	Thu Jan 31 15:20:42 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2019, 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
@@ -22,19 +22,22 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
 package sun.awt.X11;
 
-import java.awt.*;
-import java.awt.peer.*;
+import java.awt.GraphicsConfiguration;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.peer.RobotPeer;
 import java.security.AccessController;
-import sun.security.action.GetPropertyAction;
 
 import sun.awt.AWTAccessor;
 import sun.awt.SunToolkit;
 import sun.awt.UNIXToolkit;
 import sun.awt.X11GraphicsConfig;
+import sun.security.action.GetPropertyAction;
 
-class XRobotPeer implements RobotPeer {
+final class XRobotPeer implements RobotPeer {
 
     static final boolean tryGtk;
     static {
@@ -70,11 +73,6 @@
     }
 
     @Override
-    public void dispose() {
-        // does nothing
-    }
-
-    @Override
     public void mouseMove(int x, int y) {
         mouseMoveImpl(xgc, xgc.scaleUp(x), xgc.scaleUp(y));
     }
--- a/src/java.desktop/windows/classes/sun/awt/windows/WRobotPeer.java	Thu Jan 31 08:45:23 2019 +0530
+++ b/src/java.desktop/windows/classes/sun/awt/windows/WRobotPeer.java	Thu Jan 31 15:20:42 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, 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
@@ -32,23 +32,11 @@
 
 import sun.java2d.SunGraphicsEnvironment;
 
-final class WRobotPeer extends WObjectPeer implements RobotPeer
-{
-    WRobotPeer() {
-        create();
-    }
+final class WRobotPeer implements RobotPeer {
+
     WRobotPeer(GraphicsDevice screen) {
-        create();
     }
 
-    private synchronized native void _dispose();
-
-    @Override
-    protected void disposeImpl() {
-        _dispose();
-    }
-
-    public native void create();
     public native void mouseMoveImpl(int x, int y);
     @Override
     public void mouseMove(int x, int y) {
--- a/src/java.desktop/windows/native/libawt/windows/awt_Robot.cpp	Thu Jan 31 08:45:23 2019 +0530
+++ b/src/java.desktop/windows/native/libawt/windows/awt_Robot.cpp	Thu Jan 31 15:20:42 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, 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
@@ -23,32 +23,17 @@
  * questions.
  */
 
-#include "awt.h"
-#include "awt_Toolkit.h"
-#include "awt_Component.h"
-#include "awt_Robot.h"
 #include "sun_awt_windows_WRobotPeer.h"
 #include "java_awt_event_InputEvent.h"
+#include "awt_Component.h"
 #include <winuser.h>
 
-AwtRobot::AwtRobot( jobject peer )
-{
-    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
-    m_peerObject = env->NewWeakGlobalRef(peer);
-    JNU_CHECK_EXCEPTION(env);
-    JNI_SET_PDATA(peer, this);
-}
-
-AwtRobot::~AwtRobot()
-{
-}
-
 static int signum(int i) {
   // special version of signum which returns 1 when value is 0
   return i >= 0 ? 1 : -1;
 }
 
-void AwtRobot::MouseMove( jint x, jint y)
+static void MouseMove(jint x, jint y)
 {
     INPUT mouseInput = {0};
     mouseInput.type = INPUT_MOUSE;
@@ -59,7 +44,7 @@
     ::SendInput(1, &mouseInput, sizeof(mouseInput));
 }
 
-void AwtRobot::MousePress( jint buttonMask )
+static void MousePress(jint buttonMask)
 {
     DWORD dwFlags = 0L;
     // According to MSDN: Software Driving Software
@@ -101,7 +86,7 @@
     ::SendInput(1, &mouseInput, sizeof(mouseInput));
 }
 
-void AwtRobot::MouseRelease( jint buttonMask )
+static void MouseRelease(jint buttonMask)
 {
     DWORD dwFlags = 0L;
     // According to MSDN: Software Driving Software
@@ -144,11 +129,11 @@
     ::SendInput(1, &mouseInput, sizeof(mouseInput));
 }
 
-void AwtRobot::MouseWheel (jint wheelAmt) {
+static void MouseWheel(jint wheelAmt) {
     mouse_event(MOUSEEVENTF_WHEEL, 0, 0, wheelAmt * -1 * WHEEL_DELTA, 0);
 }
 
-inline jint AwtRobot::WinToJavaPixel(USHORT r, USHORT g, USHORT b)
+inline jint WinToJavaPixel(USHORT r, USHORT g, USHORT b)
 {
     jint value =
             0xFF << 24 | // alpha channel is always turned all the way up
@@ -158,7 +143,7 @@
     return value;
 }
 
-void AwtRobot::GetRGBPixels(jint x, jint y, jint width, jint height, jintArray pixelArray)
+static void GetRGBPixels(jint x, jint y, jint width, jint height, jintArray pixelArray)
 {
     DASSERT(width > 0 && height > 0);
 
@@ -255,17 +240,7 @@
     ::DeleteDC(hdcScreen);
 }
 
-void AwtRobot::KeyPress( jint jkey )
-{
-    DoKeyEvent(jkey, 0); // no flags means key down
-}
-
-void AwtRobot::KeyRelease( jint jkey )
-{
-    DoKeyEvent(jkey, KEYEVENTF_KEYUP);
-}
-
-void AwtRobot::DoKeyEvent( jint jkey, DWORD dwFlags )
+static void DoKeyEvent(jint jkey, DWORD dwFlags)
 {
     UINT        vkey;
     UINT        modifiers;
@@ -297,48 +272,16 @@
     }
 }
 
-//
-// utility function to get the C++ object from the Java one
-//
-// (static)
-AwtRobot * AwtRobot::GetRobot( jobject self )
-{
-    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
-    AwtRobot * robot = (AwtRobot *)JNI_GET_PDATA(self);
-    DASSERT( !::IsBadWritePtr( robot, sizeof(AwtRobot)));
-    return robot;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
 // Native method declarations
 //
 
-JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_create(
-    JNIEnv * env, jobject self)
-{
-    TRY;
-
-    new AwtRobot(self);
-
-    CATCH_BAD_ALLOC;
-}
-
-JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer__1dispose(
-    JNIEnv *env, jobject self)
-{
-    TRY_NO_VERIFY;
-
-    AwtObject::_Dispose(self);
-
-    CATCH_BAD_ALLOC;
-}
-
 JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_mouseMoveImpl(
     JNIEnv * env, jobject self, jint x, jint y)
 {
     TRY;
 
-    AwtRobot::GetRobot(self)->MouseMove(x, y);
+    MouseMove(x, y);
 
     CATCH_BAD_ALLOC;
 }
@@ -348,7 +291,7 @@
 {
     TRY;
 
-    AwtRobot::GetRobot(self)->MousePress(buttons);
+    MousePress(buttons);
 
     CATCH_BAD_ALLOC;
 }
@@ -358,7 +301,7 @@
 {
     TRY;
 
-    AwtRobot::GetRobot(self)->MouseRelease(buttons);
+    MouseRelease(buttons);
 
     CATCH_BAD_ALLOC;
 }
@@ -368,7 +311,7 @@
 {
     TRY;
 
-    AwtRobot::GetRobot(self)->MouseWheel(wheelAmt);
+    MouseWheel(wheelAmt);
 
     CATCH_BAD_ALLOC;
 }
@@ -378,7 +321,7 @@
 {
     TRY;
 
-    AwtRobot::GetRobot(self)->GetRGBPixels(x, y, width, height, pixelArray);
+    GetRGBPixels(x, y, width, height, pixelArray);
 
     CATCH_BAD_ALLOC;
 }
@@ -388,7 +331,7 @@
 {
     TRY;
 
-    AwtRobot::GetRobot(self)->KeyPress(javakey);
+    DoKeyEvent(javakey, 0); // no flags means key down
 
     CATCH_BAD_ALLOC;
 }
@@ -398,7 +341,7 @@
 {
     TRY;
 
-    AwtRobot::GetRobot(self)->KeyRelease(javakey);
+    DoKeyEvent(javakey, KEYEVENTF_KEYUP);
 
     CATCH_BAD_ALLOC;
 }
--- a/src/java.desktop/windows/native/libawt/windows/awt_Robot.h	Thu Jan 31 08:45:23 2019 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,58 +0,0 @@
-/*
- * Copyright (c) 1998, 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.
- */
-
-#ifndef AWT_ROBOT_H
-#define AWT_ROBOT_H
-
-#include "awt_Toolkit.h"
-#include "awt_Object.h"
-#include "sun_awt_windows_WRobotPeer.h"
-#include "jlong.h"
-
-class AwtRobot : public AwtObject
-{
-    public:
-        AwtRobot( jobject peer );
-        virtual ~AwtRobot();
-
-        void MouseMove( jint x, jint y);
-        void MousePress( jint buttonMask );
-        void MouseRelease( jint buttonMask );
-
-        void MouseWheel(jint wheelAmt);
-        jint getNumberOfButtons();
-
-        void GetRGBPixels(jint x, jint y, jint width, jint height, jintArray pixelArray);
-
-        void KeyPress( jint key );
-        void KeyRelease( jint key );
-        static AwtRobot * GetRobot( jobject self );
-
-    private:
-        void DoKeyEvent( jint jkey, DWORD dwFlags );
-        static jint WinToJavaPixel(USHORT r, USHORT g, USHORT b);
-};
-
-#endif // AWT_ROBOT_H