diff --git a/src/macosx/native/sun/awt/CGraphicsDevice.m b/src/macosx/native/sun/awt/CGraphicsDevice.m index c04a6a3807f91fcdf59470a25b798bedbd568220..870162e9fdda2334b93f1a7893f5332fc96757a0 100644 --- a/src/macosx/native/sun/awt/CGraphicsDevice.m +++ b/src/macosx/native/sun/awt/CGraphicsDevice.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, 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 @@ -94,16 +94,18 @@ static CFMutableArrayRef getAllValidDisplayModes(jint displayID){ static CGDisplayModeRef getBestModeForParameters(CFArrayRef allModes, int w, int h, int bpp, int refrate) { CGDisplayModeRef bestGuess = NULL; CFIndex numModes = CFArrayGetCount(allModes), 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; } @@ -114,11 +116,12 @@ static CGDisplayModeRef getBestModeForParameters(CFArrayRef allModes, int w, int // 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; } diff --git a/test/java/awt/GraphicsDevice/CheckDisplayModes.java b/test/java/awt/GraphicsDevice/CheckDisplayModes.java index 719ee9b43a7d785aed465cdba7f7976b99942ea5..9fced188d63c4c745c39ed1b70d6a60a32af0866 100644 --- a/test/java/awt/GraphicsDevice/CheckDisplayModes.java +++ b/test/java/awt/GraphicsDevice/CheckDisplayModes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 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 @@ -23,7 +23,7 @@ /* * @test - * @bug 8007146 + * @bug 8007146 8213119 * @summary [macosx] Setting a display mode crashes JDK under VNC * @author Alexander Scherbatiy * @run main CheckDisplayModes @@ -36,27 +36,28 @@ public class CheckDisplayModes { 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"); + } } }