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

Print this page




 220     static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets");
 221     static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V");
 222     ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right);
 223 
 224 JNF_COCOA_EXIT(env);
 225 
 226     return ret;
 227 }
 228 
 229 /*
 230  * Class:     sun_awt_CGraphicsDevice
 231  * Method:    nativeSetDisplayMode
 232  * Signature: (IIIII)V
 233  */
 234 JNIEXPORT void JNICALL
 235 Java_sun_awt_CGraphicsDevice_nativeSetDisplayMode
 236 (JNIEnv *env, jclass class, jint displayID, jint w, jint h, jint bpp, jint refrate)
 237 {
 238     JNF_COCOA_ENTER(env);
 239     CFArrayRef allModes = getAllValidDisplayModes(displayID);
 240 
 241     CGDisplayModeRef closestMatch = getBestModeForParameters(allModes, (int)w, (int)h, (int)bpp, (int)refrate);

 242     __block CGError retCode = kCGErrorSuccess;
 243     if (closestMatch != NULL) {
 244         [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){

 245             CGDisplayConfigRef config;
 246             retCode = CGBeginDisplayConfiguration(&config);
 247             if (retCode == kCGErrorSuccess) {
 248                 CGConfigureDisplayWithDisplayMode(config, displayID, closestMatch, NULL);
 249                 retCode = CGCompleteDisplayConfiguration(config, kCGConfigureForAppOnly);
 250             }

 251         }];
 252     } else {
 253         [JNFException raise:env as:kIllegalArgumentException reason:"Invalid display mode"];
 254     }
 255 
 256     if (retCode != kCGErrorSuccess){
 257         [JNFException raise:env as:kIllegalArgumentException reason:"Unable to set display mode!"];
 258     }    
 259 
 260     CFRelease(allModes);
 261     JNF_COCOA_EXIT(env);
 262 }
 263 /*
 264  * Class:     sun_awt_CGraphicsDevice
 265  * Method:    nativeGetDisplayMode
 266  * Signature: (I)Ljava/awt/DisplayMode
 267  */
 268 JNIEXPORT jobject JNICALL
 269 Java_sun_awt_CGraphicsDevice_nativeGetDisplayMode
 270 (JNIEnv *env, jclass class, jint displayID)
 271 {
 272     jobject ret = NULL;
 273     CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(displayID);
 274     ret = createJavaDisplayMode(currentMode, env, displayID);
 275     CGDisplayModeRelease(currentMode);
 276     return ret;
 277 }
 278 
 279 /*




 220     static JNF_CLASS_CACHE(jc_Insets, "java/awt/Insets");
 221     static JNF_CTOR_CACHE(jc_Insets_ctor, jc_Insets, "(IIII)V");
 222     ret = JNFNewObject(env, jc_Insets_ctor, top, left, bottom, right);
 223 
 224 JNF_COCOA_EXIT(env);
 225 
 226     return ret;
 227 }
 228 
 229 /*
 230  * Class:     sun_awt_CGraphicsDevice
 231  * Method:    nativeSetDisplayMode
 232  * Signature: (IIIII)V
 233  */
 234 JNIEXPORT void JNICALL
 235 Java_sun_awt_CGraphicsDevice_nativeSetDisplayMode
 236 (JNIEnv *env, jclass class, jint displayID, jint w, jint h, jint bpp, jint refrate)
 237 {
 238     JNF_COCOA_ENTER(env);
 239     CFArrayRef allModes = getAllValidDisplayModes(displayID);

 240     CGDisplayModeRef closestMatch = getBestModeForParameters(allModes, (int)w, (int)h, (int)bpp, (int)refrate);
 241     
 242     __block CGError retCode = kCGErrorSuccess;
 243     if (closestMatch != NULL) {
 244         CGDisplayModeRetain(closestMatch);
 245         [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
 246             CGDisplayConfigRef config;
 247             retCode = CGBeginDisplayConfiguration(&config);
 248             if (retCode == kCGErrorSuccess) {
 249                 CGConfigureDisplayWithDisplayMode(config, displayID, closestMatch, NULL);
 250                 retCode = CGCompleteDisplayConfiguration(config, kCGConfigureForAppOnly);
 251             }
 252             CGDisplayModeRelease(closestMatch);
 253         }];
 254     } else {
 255         [JNFException raise:env as:kIllegalArgumentException reason:"Invalid display mode"];
 256     }
 257 
 258     if (retCode != kCGErrorSuccess){
 259         [JNFException raise:env as:kIllegalArgumentException reason:"Unable to set display mode!"];
 260     }

 261     CFRelease(allModes);
 262     JNF_COCOA_EXIT(env);
 263 }
 264 /*
 265  * Class:     sun_awt_CGraphicsDevice
 266  * Method:    nativeGetDisplayMode
 267  * Signature: (I)Ljava/awt/DisplayMode
 268  */
 269 JNIEXPORT jobject JNICALL
 270 Java_sun_awt_CGraphicsDevice_nativeGetDisplayMode
 271 (JNIEnv *env, jclass class, jint displayID)
 272 {
 273     jobject ret = NULL;
 274     CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(displayID);
 275     ret = createJavaDisplayMode(currentMode, env, displayID);
 276     CGDisplayModeRelease(currentMode);
 277     return ret;
 278 }
 279 
 280 /*