Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, 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 @@ public CRobot(Robot r, CGraphicsDevice d) {
initRobot();
}

@Override
public void dispose() {
}

/**
* Moves mouse pointer to given screen coordinates.
* @param x X position
@@ -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 @@ private void init(GraphicsDevice screen) throws AWTException {
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 void checkIsScreenDevice(GraphicsDevice device) {
}
}

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
@@ -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();
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2017, 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));
@@ -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();
}
WRobotPeer(GraphicsDevice screen) {
create();
}
final class WRobotPeer implements RobotPeer {

private synchronized native void _dispose();

@Override
protected void disposeImpl() {
_dispose();
WRobotPeer(GraphicsDevice screen) {
}

public native void create();
public native void mouseMoveImpl(int x, int y);
@Override
public void mouseMove(int x, int y) {
@@ -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;
}