8213119: [macos] java/awt/GraphicsDevice/CheckDisplayModes.java fails
Reviewed-by: prr, jdv
--- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m Fri Oct 18 09:25:06 2019 -0700
+++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m Thu Oct 24 01:02:08 2019 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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
@@ -108,16 +108,18 @@
static CGDisplayModeRef getBestModeForParameters(CFArrayRef allModes, int w, int h, int bpp, int refrate) {
CGDisplayModeRef bestGuess = NULL;
CFIndex numModes = allModes ? CFArrayGetCount(allModes) : 0, n;
- int thisBpp = 0;
+
for(n = 0; n < numModes; n++ ) {
CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n);
if(cRef == NULL) {
continue;
}
CFStringRef modeString = CGDisplayModeCopyPixelEncoding(cRef);
- thisBpp = getBPPFromModeString(modeString);
+ int thisBpp = getBPPFromModeString(modeString);
CFRelease(modeString);
- if (thisBpp != bpp || (int)CGDisplayModeGetHeight(cRef) != h || (int)CGDisplayModeGetWidth(cRef) != w) {
+ int thisH = (int)CGDisplayModeGetHeight(cRef);
+ int thisW = (int)CGDisplayModeGetWidth(cRef);
+ if (thisBpp != bpp || thisH != h || thisW != w) {
// One of the key parameters does not match
continue;
}
@@ -128,11 +130,12 @@
// Refresh rate might be 0 in display mode and we ask for specific display rate
// but if we do not find exact match then 0 refresh rate might be just Ok
- if (CGDisplayModeGetRefreshRate(cRef) == refrate) {
+ int thisRefrate = (int)CGDisplayModeGetRefreshRate(cRef);
+ if (thisRefrate == refrate) {
// Exact match
return cRef;
}
- if (CGDisplayModeGetRefreshRate(cRef) == 0) {
+ if (thisRefrate == 0) {
// Not exactly what was asked for, but may fit our needs if we don't find an exact match
bestGuess = cRef;
}
--- a/test/jdk/ProblemList.txt Fri Oct 18 09:25:06 2019 -0700
+++ b/test/jdk/ProblemList.txt Thu Oct 24 01:02:08 2019 -0700
@@ -527,7 +527,6 @@
java/awt/Frame/DisposeParentGC/DisposeParentGC.java 8079786 macosx-all
java/awt/FullScreen/NoResizeEventOnDMChangeTest/NoResizeEventOnDMChangeTest.java 8169468 macosx-all
-java/awt/GraphicsDevice/CheckDisplayModes.java 8213119 macosx-all
java/awt/TextArea/AutoScrollOnSelectAndAppend/AutoScrollOnSelectAndAppend.java 8213120 macosx-all
java/awt/Window/MainKeyWindowTest/TestMainKeyWindow.java 8213126 macosx-all
--- a/test/jdk/java/awt/GraphicsDevice/CheckDisplayModes.java Fri Oct 18 09:25:06 2019 -0700
+++ b/test/jdk/java/awt/GraphicsDevice/CheckDisplayModes.java Thu Oct 24 01:02:08 2019 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -24,10 +24,8 @@
/*
* @test
* @key headful
- * @bug 8007146
+ * @bug 8007146 8213119
* @summary [macosx] Setting a display mode crashes JDK under VNC
- * @author Alexander Scherbatiy
- * @run main CheckDisplayModes
*/
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
@@ -37,27 +35,28 @@
public static void main(String[] args) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
- GraphicsDevice graphicDevice = ge.getDefaultScreenDevice();
- if (!graphicDevice.isDisplayChangeSupported()) {
- System.err.println("Display mode change is not supported on this host. Test is considered passed.");
- return;
- }
- DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
- checkDisplayMode(defaultDisplayMode);
- graphicDevice.setDisplayMode(defaultDisplayMode);
+ for (GraphicsDevice graphicDevice : ge.getScreenDevices()) {
+ if (!graphicDevice.isDisplayChangeSupported()) {
+ System.err.println("Display mode change is not supported on this host. Test is considered passed.");
+ continue;
+ }
+ DisplayMode defaultDisplayMode = graphicDevice.getDisplayMode();
+ checkDisplayMode(defaultDisplayMode);
+ graphicDevice.setDisplayMode(defaultDisplayMode);
- DisplayMode[] displayModes = graphicDevice.getDisplayModes();
- boolean isDefaultDisplayModeIncluded = false;
- for (DisplayMode displayMode : displayModes) {
- checkDisplayMode(displayMode);
- graphicDevice.setDisplayMode(displayMode);
- if (defaultDisplayMode.equals(displayMode)) {
- isDefaultDisplayModeIncluded = true;
+ DisplayMode[] displayModes = graphicDevice.getDisplayModes();
+ boolean isDefaultDisplayModeIncluded = false;
+ for (DisplayMode displayMode : displayModes) {
+ checkDisplayMode(displayMode);
+ graphicDevice.setDisplayMode(displayMode);
+ if (defaultDisplayMode.equals(displayMode)) {
+ isDefaultDisplayModeIncluded = true;
+ }
}
- }
- if (!isDefaultDisplayModeIncluded) {
- throw new RuntimeException("Default display mode is not included");
+ if (!isDefaultDisplayModeIncluded) {
+ throw new RuntimeException("Default display mode is not included");
+ }
}
}