changeset 5220:bf5bf37108c1

7182902: [macosx] Test api/java_awt/GraphicsDevice/indexTGF.html#SetDisplayMode fails on Mac OS X 10.7 Reviewed-by: bae, kizune
author alexsch
date Fri, 20 Jul 2012 13:58:52 +0400
parents 1318ba62cd1e
children 84d5cdbe7bce
files src/macosx/classes/sun/awt/CGraphicsDevice.java src/macosx/native/sun/awt/CGraphicsDevice.m
diffstat 2 files changed, 21 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/awt/CGraphicsDevice.java	Thu Jul 19 20:19:35 2012 -0700
+++ b/src/macosx/classes/sun/awt/CGraphicsDevice.java	Fri Jul 20 13:58:52 2012 +0400
@@ -48,6 +48,9 @@
 
     private static AWTPermission fullScreenExclusivePermission;
 
+    // Save/restore DisplayMode for the Full Screen mode
+    private DisplayMode originalMode;
+
     public CGraphicsDevice(int displayID) {
         this.displayID = displayID;
         configs = new GraphicsConfiguration[] {
@@ -124,18 +127,22 @@
         }
 
         boolean fsSupported = isFullScreenSupported();
+
         if (fsSupported && old != null) {
             // enter windowed mode (and restore original display mode)
             exitFullScreenExclusive(old);
-
-            // TODO: restore display mode
+            if (originalMode != null) {
+                setDisplayMode(originalMode);
+                originalMode = null;
+            }
         }
 
         super.setFullScreenWindow(w);
 
         if (fsSupported && w != null) {
-            // TODO: save current display mode
-
+            if (isDisplayChangeSupported()) {
+                originalMode = getDisplayMode();
+            }
             // enter fullscreen mode
             enterFullScreenExclusive(w);
         }
--- a/src/macosx/native/sun/awt/CGraphicsDevice.m	Thu Jul 19 20:19:35 2012 -0700
+++ b/src/macosx/native/sun/awt/CGraphicsDevice.m	Fri Jul 20 13:58:52 2012 +0400
@@ -28,7 +28,7 @@
 /*
  * Convert the mode string to the more convinient bits per pixel value
  */
-static int getBPPFromModeString(CFStringRef mode) 
+static int getBPPFromModeString(CFStringRef mode)
 {
     if ((CFStringCompare(mode, CFSTR(kIO30BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)) {
         // This is a strange mode, where we using 10 bits per RGB component and pack it into 32 bits
@@ -44,7 +44,7 @@
     else if (CFStringCompare(mode, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
         return 8;
     }
-    
+
     return 0;
 }
 
@@ -68,6 +68,11 @@
             // One of the key parameters does not match
             continue;
         }
+
+        if (refrate == 0) { // REFRESH_RATE_UNKNOWN
+            return cRef;
+        }
+
         // 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) {
@@ -165,7 +170,10 @@
                 }
             }
         }];
+    } else {
+        [JNFException raise:env as:kIllegalArgumentException reason:"Invalid display mode"];
     }
+
     CFRelease(allModes);
     JNF_COCOA_EXIT(env);
 }