8216318: The usage of Disposer in the java.awt.Robot can be deleted

Reviewed-by: prr
This commit is contained in:
Sergey Bylokhov 2019-01-31 15:20:42 -08:00
parent 8d0f4c267d
commit 293f77f18f
7 changed files with 33 additions and 188 deletions

View File

@ -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 @@ final class CRobot implements RobotPeer {
initRobot();
}
@Override
public void dispose() {
}
/**
* Moves mouse pointer to given screen coordinates.
* @param x X position

View File

@ -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 @@ public class Robot {
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 @@ public class Robot {
}
}
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

View File

@ -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 @@ public interface RobotPeer
* @see Robot#createScreenCapture(Rectangle)
*/
int[] getRGBPixels(Rectangle bounds);
/**
* Disposes the robot peer when it is not needed anymore.
*/
void dispose();
}

View File

@ -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 {
@ -69,11 +72,6 @@ class XRobotPeer implements RobotPeer {
useGtk = (tryGtk && isGtkSupported);
}
@Override
public void dispose() {
// does nothing
}
@Override
public void mouseMove(int x, int y) {
mouseMoveImpl(xgc, xgc.scaleUp(x), xgc.scaleUp(y));

View File

@ -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 java.awt.peer.RobotPeer;
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) {

View File

@ -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 @@ void AwtRobot::MouseMove( jint x, jint y)
::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 @@ void AwtRobot::MousePress( jint buttonMask )
::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 @@ void AwtRobot::MouseRelease( jint buttonMask )
::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 @@ inline jint AwtRobot::WinToJavaPixel(USHORT r, USHORT g, USHORT b)
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 @@ void AwtRobot::GetRGBPixels(jint x, jint y, jint width, jint height, jintArray p
::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 @@ void AwtRobot::DoKeyEvent( jint jkey, DWORD dwFlags )
}
}
//
// 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 @@ JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_mousePress(
{
TRY;
AwtRobot::GetRobot(self)->MousePress(buttons);
MousePress(buttons);
CATCH_BAD_ALLOC;
}
@ -358,7 +301,7 @@ JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_mouseRelease(
{
TRY;
AwtRobot::GetRobot(self)->MouseRelease(buttons);
MouseRelease(buttons);
CATCH_BAD_ALLOC;
}
@ -368,7 +311,7 @@ JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_mouseWheel(
{
TRY;
AwtRobot::GetRobot(self)->MouseWheel(wheelAmt);
MouseWheel(wheelAmt);
CATCH_BAD_ALLOC;
}
@ -378,7 +321,7 @@ JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_getRGBPixels(
{
TRY;
AwtRobot::GetRobot(self)->GetRGBPixels(x, y, width, height, pixelArray);
GetRGBPixels(x, y, width, height, pixelArray);
CATCH_BAD_ALLOC;
}
@ -388,7 +331,7 @@ JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_keyPress(
{
TRY;
AwtRobot::GetRobot(self)->KeyPress(javakey);
DoKeyEvent(javakey, 0); // no flags means key down
CATCH_BAD_ALLOC;
}
@ -398,7 +341,7 @@ JNIEXPORT void JNICALL Java_sun_awt_windows_WRobotPeer_keyRelease(
{
TRY;
AwtRobot::GetRobot(self)->KeyRelease(javakey);
DoKeyEvent(javakey, KEYEVENTF_KEYUP);
CATCH_BAD_ALLOC;
}

View File

@ -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