src/java.desktop/macosx/native/libawt_lwawt/awt/CGraphicsDevice.m
changeset 59171 85d7af399ef5
parent 52537 814c49afb1a7
equal deleted inserted replaced
59170:945f5bfab0f7 59171:85d7af399ef5
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   106  * the provided parameters.
   106  * the provided parameters.
   107  */
   107  */
   108 static CGDisplayModeRef getBestModeForParameters(CFArrayRef allModes, int w, int h, int bpp, int refrate) {
   108 static CGDisplayModeRef getBestModeForParameters(CFArrayRef allModes, int w, int h, int bpp, int refrate) {
   109     CGDisplayModeRef bestGuess = NULL;
   109     CGDisplayModeRef bestGuess = NULL;
   110     CFIndex numModes = allModes ? CFArrayGetCount(allModes) : 0, n;
   110     CFIndex numModes = allModes ? CFArrayGetCount(allModes) : 0, n;
   111     int thisBpp = 0;
   111 
   112     for(n = 0; n < numModes; n++ ) {
   112     for(n = 0; n < numModes; n++ ) {
   113         CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n);
   113         CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n);
   114         if(cRef == NULL) {
   114         if(cRef == NULL) {
   115             continue;
   115             continue;
   116         }
   116         }
   117         CFStringRef modeString = CGDisplayModeCopyPixelEncoding(cRef);
   117         CFStringRef modeString = CGDisplayModeCopyPixelEncoding(cRef);
   118         thisBpp = getBPPFromModeString(modeString);
   118         int thisBpp = getBPPFromModeString(modeString);
   119         CFRelease(modeString);
   119         CFRelease(modeString);
   120         if (thisBpp != bpp || (int)CGDisplayModeGetHeight(cRef) != h || (int)CGDisplayModeGetWidth(cRef) != w) {
   120         int thisH = (int)CGDisplayModeGetHeight(cRef);
       
   121         int thisW = (int)CGDisplayModeGetWidth(cRef);
       
   122         if (thisBpp != bpp || thisH != h || thisW != w) {
   121             // One of the key parameters does not match
   123             // One of the key parameters does not match
   122             continue;
   124             continue;
   123         }
   125         }
   124 
   126 
   125         if (refrate == 0) { // REFRESH_RATE_UNKNOWN
   127         if (refrate == 0) { // REFRESH_RATE_UNKNOWN
   126             return cRef;
   128             return cRef;
   127         }
   129         }
   128 
   130 
   129         // Refresh rate might be 0 in display mode and we ask for specific display rate
   131         // Refresh rate might be 0 in display mode and we ask for specific display rate
   130         // but if we do not find exact match then 0 refresh rate might be just Ok
   132         // but if we do not find exact match then 0 refresh rate might be just Ok
   131         if (CGDisplayModeGetRefreshRate(cRef) == refrate) {
   133         int thisRefrate = (int)CGDisplayModeGetRefreshRate(cRef);
       
   134         if (thisRefrate == refrate) {
   132             // Exact match
   135             // Exact match
   133             return cRef;
   136             return cRef;
   134         }
   137         }
   135         if (CGDisplayModeGetRefreshRate(cRef) == 0) {
   138         if (thisRefrate == 0) {
   136             // Not exactly what was asked for, but may fit our needs if we don't find an exact match
   139             // Not exactly what was asked for, but may fit our needs if we don't find an exact match
   137             bestGuess = cRef;
   140             bestGuess = cRef;
   138         }
   141         }
   139     }
   142     }
   140     return bestGuess;
   143     return bestGuess;