51 /* 52 * Find the best possible match in the list of display modes that we can switch to based on 53 * the provided parameters. 54 */ 55 static CGDisplayModeRef getBestModeForParameters(CFArrayRef allModes, int w, int h, int bpp, int refrate) { 56 CGDisplayModeRef bestGuess = NULL; 57 CFIndex numModes = CFArrayGetCount(allModes), n; 58 int thisBpp = 0; 59 for(n = 0; n < numModes; n++ ) { 60 CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n); 61 if(cRef == NULL) { 62 continue; 63 } 64 CFStringRef modeString = CGDisplayModeCopyPixelEncoding(cRef); 65 thisBpp = getBPPFromModeString(modeString); 66 CFRelease(modeString); 67 if (thisBpp != bpp || (int)CGDisplayModeGetHeight(cRef) != h || (int)CGDisplayModeGetWidth(cRef) != w) { 68 // One of the key parameters does not match 69 continue; 70 } 71 // Refresh rate might be 0 in display mode and we ask for specific display rate 72 // but if we do not find exact match then 0 refresh rate might be just Ok 73 if (CGDisplayModeGetRefreshRate(cRef) == refrate) { 74 // Exact match 75 return cRef; 76 } 77 if (CGDisplayModeGetRefreshRate(cRef) == 0) { 78 // Not exactly what was asked for, but may fit our needs if we don't find an exact match 79 bestGuess = cRef; 80 } 81 } 82 return bestGuess; 83 } 84 85 /* 86 * Create a new java.awt.DisplayMode instance based on provided CGDisplayModeRef 87 */ 88 static jobject createJavaDisplayMode(CGDisplayModeRef mode, JNIEnv *env, jint displayID) { 89 jobject ret = NULL; 90 jint h, w, bpp, refrate; | 51 /* 52 * Find the best possible match in the list of display modes that we can switch to based on 53 * the provided parameters. 54 */ 55 static CGDisplayModeRef getBestModeForParameters(CFArrayRef allModes, int w, int h, int bpp, int refrate) { 56 CGDisplayModeRef bestGuess = NULL; 57 CFIndex numModes = CFArrayGetCount(allModes), n; 58 int thisBpp = 0; 59 for(n = 0; n < numModes; n++ ) { 60 CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n); 61 if(cRef == NULL) { 62 continue; 63 } 64 CFStringRef modeString = CGDisplayModeCopyPixelEncoding(cRef); 65 thisBpp = getBPPFromModeString(modeString); 66 CFRelease(modeString); 67 if (thisBpp != bpp || (int)CGDisplayModeGetHeight(cRef) != h || (int)CGDisplayModeGetWidth(cRef) != w) { 68 // One of the key parameters does not match 69 continue; 70 } 71 72 if (refrate == 0) { // REFRESH_RATE_UNKNOWN 73 return cRef; 74 } 75 76 // Refresh rate might be 0 in display mode and we ask for specific display rate 77 // but if we do not find exact match then 0 refresh rate might be just Ok 78 if (CGDisplayModeGetRefreshRate(cRef) == refrate) { 79 // Exact match 80 return cRef; 81 } 82 if (CGDisplayModeGetRefreshRate(cRef) == 0) { 83 // Not exactly what was asked for, but may fit our needs if we don't find an exact match 84 bestGuess = cRef; 85 } 86 } 87 return bestGuess; 88 } 89 90 /* 91 * Create a new java.awt.DisplayMode instance based on provided CGDisplayModeRef 92 */ 93 static jobject createJavaDisplayMode(CGDisplayModeRef mode, JNIEnv *env, jint displayID) { 94 jobject ret = NULL; 95 jint h, w, bpp, refrate; |