src/macosx/native/sun/awt/CGraphicsDevice.m

Print this page




  49     return 0;
  50 }
  51 
  52 static BOOL isValidDisplayMode(CGDisplayModeRef mode){
  53     return (1 < CGDisplayModeGetWidth(mode) && 1 < CGDisplayModeGetHeight(mode));
  54 }
  55 
  56 static CFMutableArrayRef getAllValidDisplayModes(jint displayID){
  57     CFArrayRef allModes = CGDisplayCopyAllDisplayModes(displayID, NULL);
  58 
  59     CFIndex numModes = CFArrayGetCount(allModes);
  60     CFMutableArrayRef validModes = CFArrayCreateMutable(kCFAllocatorDefault, numModes + 1, NULL);
  61 
  62     CFIndex n;
  63     for (n=0; n < numModes; n++) {
  64         CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n);
  65         if (cRef != NULL && isValidDisplayMode(cRef)) {
  66             CFArrayAppendValue(validModes, cRef);
  67         }
  68     }

  69 
  70     CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(displayID);
  71 
  72     BOOL containsCurrentMode = NO;
  73     numModes = CFArrayGetCount(validModes);
  74     for (n=0; n < numModes; n++) {
  75         if(CFArrayGetValueAtIndex(validModes, n) == currentMode){
  76             containsCurrentMode = YES;
  77             break;
  78         }
  79     }
  80 
  81     if (!containsCurrentMode) {
  82         CFArrayAppendValue(validModes, currentMode);
  83     }

  84 
  85     return validModes;
  86 }
  87 
  88 /*
  89  * Find the best possible match in the list of display modes that we can switch to based on
  90  * the provided parameters.
  91  */
  92 static CGDisplayModeRef getBestModeForParameters(CFArrayRef allModes, int w, int h, int bpp, int refrate) {
  93     CGDisplayModeRef bestGuess = NULL;
  94     CFIndex numModes = CFArrayGetCount(allModes), n;
  95     int thisBpp = 0;
  96     for(n = 0; n < numModes; n++ ) {
  97         CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n);
  98         if(cRef == NULL) {
  99             continue;
 100         }
 101         CFStringRef modeString = CGDisplayModeCopyPixelEncoding(cRef);
 102         thisBpp = getBPPFromModeString(modeString);
 103         CFRelease(modeString);




  49     return 0;
  50 }
  51 
  52 static BOOL isValidDisplayMode(CGDisplayModeRef mode){
  53     return (1 < CGDisplayModeGetWidth(mode) && 1 < CGDisplayModeGetHeight(mode));
  54 }
  55 
  56 static CFMutableArrayRef getAllValidDisplayModes(jint displayID){
  57     CFArrayRef allModes = CGDisplayCopyAllDisplayModes(displayID, NULL);
  58 
  59     CFIndex numModes = CFArrayGetCount(allModes);
  60     CFMutableArrayRef validModes = CFArrayCreateMutable(kCFAllocatorDefault, numModes + 1, NULL);
  61 
  62     CFIndex n;
  63     for (n=0; n < numModes; n++) {
  64         CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n);
  65         if (cRef != NULL && isValidDisplayMode(cRef)) {
  66             CFArrayAppendValue(validModes, cRef);
  67         }
  68     }
  69     CFRelease(allModes);
  70     
  71     CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(displayID);
  72 
  73     BOOL containsCurrentMode = NO;
  74     numModes = CFArrayGetCount(validModes);
  75     for (n=0; n < numModes; n++) {
  76         if(CFArrayGetValueAtIndex(validModes, n) == currentMode){
  77             containsCurrentMode = YES;
  78             break;
  79         }
  80     }
  81 
  82     if (!containsCurrentMode) {
  83         CFArrayAppendValue(validModes, currentMode);
  84     }
  85     CGDisplayModeRelease(currentMode);
  86 
  87     return validModes;
  88 }
  89 
  90 /*
  91  * Find the best possible match in the list of display modes that we can switch to based on
  92  * the provided parameters.
  93  */
  94 static CGDisplayModeRef getBestModeForParameters(CFArrayRef allModes, int w, int h, int bpp, int refrate) {
  95     CGDisplayModeRef bestGuess = NULL;
  96     CFIndex numModes = CFArrayGetCount(allModes), n;
  97     int thisBpp = 0;
  98     for(n = 0; n < numModes; n++ ) {
  99         CGDisplayModeRef cRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(allModes, n);
 100         if(cRef == NULL) {
 101             continue;
 102         }
 103         CFStringRef modeString = CGDisplayModeCopyPixelEncoding(cRef);
 104         thisBpp = getBPPFromModeString(modeString);
 105         CFRelease(modeString);