8238936: The crash in XRobotPeer when the custom GraphicsDevice is used
Reviewed-by: kizune
This commit is contained in:
parent
70e2c013d7
commit
9d0a4875d7
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2020, 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
|
||||
@ -27,7 +27,6 @@ package sun.lwawt.macosx;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.peer.RobotPeer;
|
||||
|
||||
import sun.awt.CGraphicsDevice;
|
||||
@ -49,7 +48,7 @@ final class CRobot implements RobotPeer {
|
||||
* Uses the given GraphicsDevice as the coordinate system for subsequent
|
||||
* coordinate calls.
|
||||
*/
|
||||
public CRobot(Robot r, CGraphicsDevice d) {
|
||||
CRobot(CGraphicsDevice d) {
|
||||
fDevice = d;
|
||||
initRobot();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2020, 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
|
||||
@ -26,6 +26,7 @@
|
||||
package sun.lwawt.macosx;
|
||||
|
||||
import java.awt.AWTError;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.CheckboxMenuItem;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
@ -49,7 +50,6 @@ import java.awt.MenuItem;
|
||||
import java.awt.Point;
|
||||
import java.awt.PopupMenu;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Robot;
|
||||
import java.awt.SystemTray;
|
||||
import java.awt.Taskbar;
|
||||
import java.awt.Toolkit;
|
||||
@ -492,8 +492,11 @@ public final class LWCToolkit extends LWToolkit {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RobotPeer createRobot(Robot target, GraphicsDevice screen) {
|
||||
return new CRobot(target, (CGraphicsDevice)screen);
|
||||
public RobotPeer createRobot(GraphicsDevice screen) throws AWTException {
|
||||
if (screen instanceof CGraphicsDevice) {
|
||||
return new CRobot((CGraphicsDevice) screen);
|
||||
}
|
||||
return super.createRobot(screen);
|
||||
}
|
||||
|
||||
private native boolean isCapsLockOn();
|
||||
|
@ -132,7 +132,7 @@ public class Robot {
|
||||
checkRobotAllowed();
|
||||
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||
if (toolkit instanceof ComponentFactory) {
|
||||
peer = ((ComponentFactory)toolkit).createRobot(this, screen);
|
||||
peer = ((ComponentFactory)toolkit).createRobot(screen);
|
||||
}
|
||||
initLegalButtonMask();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2020, 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,12 +25,60 @@
|
||||
|
||||
package sun.awt;
|
||||
|
||||
import java.awt.peer.TaskbarPeer;
|
||||
import java.awt.*;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Button;
|
||||
import java.awt.Canvas;
|
||||
import java.awt.Checkbox;
|
||||
import java.awt.CheckboxMenuItem;
|
||||
import java.awt.Choice;
|
||||
import java.awt.Component;
|
||||
import java.awt.Desktop;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.Label;
|
||||
import java.awt.Menu;
|
||||
import java.awt.MenuBar;
|
||||
import java.awt.MenuItem;
|
||||
import java.awt.Panel;
|
||||
import java.awt.PopupMenu;
|
||||
import java.awt.ScrollPane;
|
||||
import java.awt.Scrollbar;
|
||||
import java.awt.Taskbar;
|
||||
import java.awt.TextArea;
|
||||
import java.awt.TextField;
|
||||
import java.awt.Window;
|
||||
import java.awt.dnd.DragGestureEvent;
|
||||
import java.awt.dnd.InvalidDnDOperationException;
|
||||
import java.awt.dnd.peer.DragSourceContextPeer;
|
||||
import java.awt.peer.*;
|
||||
import java.awt.peer.ButtonPeer;
|
||||
import java.awt.peer.CanvasPeer;
|
||||
import java.awt.peer.CheckboxMenuItemPeer;
|
||||
import java.awt.peer.CheckboxPeer;
|
||||
import java.awt.peer.ChoicePeer;
|
||||
import java.awt.peer.DesktopPeer;
|
||||
import java.awt.peer.DialogPeer;
|
||||
import java.awt.peer.FileDialogPeer;
|
||||
import java.awt.peer.FontPeer;
|
||||
import java.awt.peer.FramePeer;
|
||||
import java.awt.peer.LabelPeer;
|
||||
import java.awt.peer.LightweightPeer;
|
||||
import java.awt.peer.ListPeer;
|
||||
import java.awt.peer.MenuBarPeer;
|
||||
import java.awt.peer.MenuItemPeer;
|
||||
import java.awt.peer.MenuPeer;
|
||||
import java.awt.peer.MouseInfoPeer;
|
||||
import java.awt.peer.PanelPeer;
|
||||
import java.awt.peer.PopupMenuPeer;
|
||||
import java.awt.peer.RobotPeer;
|
||||
import java.awt.peer.ScrollPanePeer;
|
||||
import java.awt.peer.ScrollbarPeer;
|
||||
import java.awt.peer.TaskbarPeer;
|
||||
import java.awt.peer.TextAreaPeer;
|
||||
import java.awt.peer.TextFieldPeer;
|
||||
import java.awt.peer.WindowPeer;
|
||||
|
||||
import sun.awt.datatransfer.DataTransferer;
|
||||
|
||||
@ -437,9 +485,17 @@ public interface ComponentFactory {
|
||||
return null;
|
||||
}
|
||||
|
||||
default RobotPeer createRobot(Robot target, GraphicsDevice screen)
|
||||
throws AWTException {
|
||||
throw new HeadlessException();
|
||||
/**
|
||||
* Creates the peer for a Robot.
|
||||
*
|
||||
* @param screen the GraphicsDevice indicating the coordinate system the
|
||||
* Robot will operate in
|
||||
* @return the peer created
|
||||
* @throws AWTException if the platform configuration does not allow
|
||||
* low-level input control
|
||||
*/
|
||||
default RobotPeer createRobot(GraphicsDevice screen) throws AWTException {
|
||||
throw new AWTException(String.format("Unsupported device: %s", screen));
|
||||
}
|
||||
|
||||
default DataTransferer getDataTransferer() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2020, 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,6 @@
|
||||
|
||||
package sun.awt.X11;
|
||||
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.peer.RobotPeer;
|
||||
@ -35,11 +34,12 @@ import sun.awt.AWTAccessor;
|
||||
import sun.awt.SunToolkit;
|
||||
import sun.awt.UNIXToolkit;
|
||||
import sun.awt.X11GraphicsConfig;
|
||||
import sun.awt.X11GraphicsDevice;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
|
||||
final class XRobotPeer implements RobotPeer {
|
||||
|
||||
static final boolean tryGtk;
|
||||
private static final boolean tryGtk;
|
||||
static {
|
||||
loadNativeLibraries();
|
||||
tryGtk = Boolean.parseBoolean(
|
||||
@ -48,16 +48,10 @@ final class XRobotPeer implements RobotPeer {
|
||||
));
|
||||
}
|
||||
private static volatile boolean useGtk;
|
||||
private X11GraphicsConfig xgc = null;
|
||||
private final X11GraphicsConfig xgc;
|
||||
|
||||
/*
|
||||
* native implementation uses some static shared data (pipes, processes)
|
||||
* so use a class lock to synchronize native method calls
|
||||
*/
|
||||
static Object robotLock = new Object();
|
||||
|
||||
XRobotPeer(GraphicsConfiguration gc) {
|
||||
this.xgc = (X11GraphicsConfig)gc;
|
||||
XRobotPeer(X11GraphicsDevice gd) {
|
||||
xgc = (X11GraphicsConfig) gd.getDefaultConfiguration();
|
||||
SunToolkit tk = (SunToolkit)Toolkit.getDefaultToolkit();
|
||||
setup(tk.getNumberOfButtons(),
|
||||
AWTAccessor.getInputEventAccessor().getButtonDownMasks());
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2020, 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
|
||||
@ -58,7 +58,6 @@ import java.awt.Point;
|
||||
import java.awt.PopupMenu;
|
||||
import java.awt.PrintJob;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.ScrollPane;
|
||||
import java.awt.Scrollbar;
|
||||
import java.awt.SystemColor;
|
||||
@ -1077,11 +1076,13 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RobotPeer createRobot(Robot target, GraphicsDevice screen) {
|
||||
return new XRobotPeer(screen.getDefaultConfiguration());
|
||||
public RobotPeer createRobot(GraphicsDevice screen) throws AWTException {
|
||||
if (screen instanceof X11GraphicsDevice) {
|
||||
return new XRobotPeer((X11GraphicsDevice) screen);
|
||||
}
|
||||
return super.createRobot(screen);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* On X, support for dynamic layout on resizing is governed by the
|
||||
* window manager. If the window manager supports it, it happens
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2020, 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,6 @@
|
||||
|
||||
package sun.awt.windows;
|
||||
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.peer.RobotPeer;
|
||||
@ -34,9 +33,6 @@ import sun.java2d.SunGraphicsEnvironment;
|
||||
|
||||
final class WRobotPeer implements RobotPeer {
|
||||
|
||||
WRobotPeer(GraphicsDevice screen) {
|
||||
}
|
||||
|
||||
public native void mouseMoveImpl(int x, int y);
|
||||
@Override
|
||||
public void mouseMove(int x, int y) {
|
||||
|
@ -60,7 +60,6 @@ import java.awt.Point;
|
||||
import java.awt.PopupMenu;
|
||||
import java.awt.PrintJob;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.Robot;
|
||||
import java.awt.ScrollPane;
|
||||
import java.awt.Scrollbar;
|
||||
import java.awt.SystemTray;
|
||||
@ -553,11 +552,11 @@ public final class WToolkit extends SunToolkit implements Runnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RobotPeer createRobot(Robot target, GraphicsDevice screen) {
|
||||
// (target is unused for now)
|
||||
// Robot's don't need to go in the peer map since
|
||||
// they're not Component's
|
||||
return new WRobotPeer(screen);
|
||||
public RobotPeer createRobot(GraphicsDevice screen) throws AWTException {
|
||||
if (screen instanceof Win32GraphicsDevice) {
|
||||
return new WRobotPeer();
|
||||
}
|
||||
return super.createRobot(screen);
|
||||
}
|
||||
|
||||
public WEmbeddedFramePeer createEmbeddedFrame(WEmbeddedFrame target) {
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.Robot;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @key headful
|
||||
* @bug 8238936
|
||||
* @summary Check that Robot(GraphicsDevice) constructor throw AWTException if
|
||||
* device is unsupported
|
||||
*/
|
||||
public final class CreateRobotCustomGC {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
new Robot(new GraphicsDevice() {
|
||||
@Override
|
||||
public int getType() {
|
||||
return TYPE_RASTER_SCREEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIDstring() {
|
||||
return "Custom screen device";
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphicsConfiguration[] getConfigurations() {
|
||||
return new GraphicsConfiguration[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphicsConfiguration getDefaultConfiguration() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
throw new RuntimeException("Expected AWTException did not occur");
|
||||
} catch (AWTException ignored) {
|
||||
// expected AWTException
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user