8020210: [macosx] JVM crashes in CWrapper$NSWindow.screen(long)
Reviewed-by: anthony, art
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Tue Jul 09 21:21:55 2013 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java Thu Jul 11 16:42:13 2013 +0400
@@ -479,12 +479,14 @@
deliverZoom(true);
this.normalBounds = peer.getBounds();
- long screen = CWrapper.NSWindow.screen(getNSWindowPtr());
- Rectangle toBounds = CWrapper.NSScreen.visibleFrame(screen).getBounds();
- // Flip the y coordinate
- Rectangle frame = CWrapper.NSScreen.frame(screen).getBounds();
- toBounds.y = frame.height - toBounds.y - toBounds.height;
- setBounds(toBounds.x, toBounds.y, toBounds.width, toBounds.height);
+
+ GraphicsConfiguration config = getPeer().getGraphicsConfiguration();
+ Insets i = ((CGraphicsDevice)config.getDevice()).getScreenInsets();
+ Rectangle toBounds = config.getBounds();
+ setBounds(toBounds.x + i.left,
+ toBounds.y + i.top,
+ toBounds.width - i.left - i.right,
+ toBounds.height - i.top - i.bottom);
}
}
@@ -751,13 +753,7 @@
// the move/size notification from the underlying system comes
// but it contains a bounds smaller than the whole screen
// and therefore we need to create the synthetic notifications
- Rectangle screenBounds;
- final long screenPtr = CWrapper.NSWindow.screen(getNSWindowPtr());
- try {
- screenBounds = CWrapper.NSScreen.frame(screenPtr).getBounds();
- } finally {
- CWrapper.NSObject.release(screenPtr);
- }
+ Rectangle screenBounds = getPeer().getGraphicsConfiguration().getBounds();
peer.notifyReshape(screenBounds.x, screenBounds.y, screenBounds.width,
screenBounds.height);
}
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CWrapper.java Tue Jul 09 21:21:55 2013 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CWrapper.java Thu Jul 11 16:42:13 2013 +0400
@@ -71,8 +71,6 @@
public static native void zoom(long window);
public static native void makeFirstResponder(long window, long responder);
-
- public static native long screen(long window);
}
public static final class NSView {
@@ -95,12 +93,6 @@
public static native void release(long object);
}
- public static final class NSScreen {
- public static native Rectangle2D frame(long screen);
- public static native Rectangle2D visibleFrame(long screen);
- public static native long screenByDisplayId(int displayID);
- }
-
public static final class NSColor {
public static native long clearColor();
}
--- a/jdk/src/macosx/native/sun/awt/CWrapper.m Tue Jul 09 21:21:55 2013 +0400
+++ b/jdk/src/macosx/native/sun/awt/CWrapper.m Thu Jul 11 16:42:13 2013 +0400
@@ -397,31 +397,6 @@
}
/*
- * Class: sun_lwawt_macosx_CWrapper$NSWindow
- * Method: screen
- * Signature: (J)J
- */
-JNIEXPORT jlong JNICALL
-Java_sun_lwawt_macosx_CWrapper_00024NSWindow_screen
-(JNIEnv *env, jclass cls, jlong windowPtr)
-{
- __block jlong screenPtr = 0L;
-
-JNF_COCOA_ENTER(env);
-
- AWTWindow *window = (AWTWindow *)jlong_to_ptr(windowPtr);
- [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
- const NSScreen *screen = [window screen];
- CFRetain(screen); // GC
- screenPtr = ptr_to_jlong(screen);
- }];
-
-JNF_COCOA_EXIT(env);
-
- return screenPtr;
-}
-
-/*
* Method: miniaturize
* Signature: (J)V
*/
@@ -690,92 +665,6 @@
JNF_COCOA_EXIT(env);
}
-
-/*
- * Class: sun_lwawt_macosx_CWrapper$NSScreen
- * Method: frame
- * Signature: (J)Ljava/awt/Rectangle;
- */
-JNIEXPORT jobject JNICALL
-Java_sun_lwawt_macosx_CWrapper_00024NSScreen_frame
-(JNIEnv *env, jclass cls, jlong screenPtr)
-{
- jobject jRect = NULL;
-
-JNF_COCOA_ENTER(env);
-
- __block NSRect rect = NSZeroRect;
-
- NSScreen *screen = (NSScreen *)jlong_to_ptr(screenPtr);
- [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
- rect = [screen frame];
- }];
-
- jRect = NSToJavaRect(env, rect);
-
-JNF_COCOA_EXIT(env);
-
- return jRect;
-}
-
-/*
- * Class: sun_lwawt_macosx_CWrapper_NSScreen
- * Method: visibleFrame
- * Signature: (J)Ljava/awt/geom/Rectangle2D;
- */
-JNIEXPORT jobject JNICALL
-Java_sun_lwawt_macosx_CWrapper_00024NSScreen_visibleFrame
-(JNIEnv *env, jclass cls, jlong screenPtr)
-{
- jobject jRect = NULL;
-
-JNF_COCOA_ENTER(env);
-
- __block NSRect rect = NSZeroRect;
-
- NSScreen *screen = (NSScreen *)jlong_to_ptr(screenPtr);
- [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
- rect = [screen visibleFrame];
- }];
-
- jRect = NSToJavaRect(env, rect);
-
-JNF_COCOA_EXIT(env);
-
- return jRect;
-}
-
-/*
- * Class: sun_lwawt_macosx_CWrapper_NSScreen
- * Method: screenByDisplayId
- * Signature: (J)J
- */
-JNIEXPORT jlong JNICALL
-Java_sun_lwawt_macosx_CWrapper_00024NSScreen_screenByDisplayId
-(JNIEnv *env, jclass cls, jint displayID)
-{
- __block jlong screenPtr = 0L;
-
-JNF_COCOA_ENTER(env);
-
- [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
- NSArray *screens = [NSScreen screens];
- for (NSScreen *screen in screens) {
- NSDictionary *screenInfo = [screen deviceDescription];
- NSNumber *screenID = [screenInfo objectForKey:@"NSScreenNumber"];
- if ([screenID intValue] == displayID){
- CFRetain(screen); // GC
- screenPtr = ptr_to_jlong(screen);
- break;
- }
- }
- }];
-
-JNF_COCOA_EXIT(env);
-
- return screenPtr;
-}
-
/*
* Class: sun_lwawt_macosx_CWrapper$NSColor
* Method: clearColor
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Window/MaximizeOffscreen/MaximizeOffscreenTest.java Thu Jul 11 16:42:13 2013 +0400
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 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.
+ *
+ * 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.
+ */
+
+/**
+ * @test @summary JVM crash if the frame maximized from offscreen
+ * @author Petr Pchelko
+ * @library ../../regtesthelpers
+ * @build Util
+ * @compile MaximizeOffscreenTest.java
+ * @run main/othervm MaximizeOffscreenTest
+ */
+
+import test.java.awt.regtesthelpers.Util;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class MaximizeOffscreenTest {
+
+ private static JFrame frame;
+
+ public static void main(String[] args) throws Throwable {
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ constructTestUI();
+ }
+ });
+
+ Util.waitForIdle(null);
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ frame.setExtendedState(Frame.MAXIMIZED_BOTH);
+ }
+ });
+ Util.waitForIdle(null);
+ }
+
+ private static void constructTestUI() {
+ frame = new JFrame("Test frame");
+ frame.setUndecorated(true);
+ frame.setBounds(-1000, -1000, 100, 100);
+ frame.setVisible(true);
+ }
+}