changeset 6054:52af1f496486

8008660: Failure in 2D Queue Flusher thread on Mac Reviewed-by: swingler, bae
author serb
date Thu, 09 May 2013 03:26:41 +0400
parents 99b3f9c060b9
children 0fb7552db146
files src/macosx/classes/sun/awt/CGraphicsConfig.java src/macosx/classes/sun/awt/CGraphicsDevice.java src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java src/macosx/classes/sun/lwawt/macosx/CRobot.java src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java src/macosx/native/sun/awt/CRobot.m src/macosx/native/sun/awt/LWCToolkit.h src/macosx/native/sun/awt/LWCToolkit.m src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m
diffstat 9 files changed, 32 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/awt/CGraphicsConfig.java	Wed Apr 10 12:43:18 2013 -0700
+++ b/src/macosx/classes/sun/awt/CGraphicsConfig.java	Thu May 09 03:26:41 2013 +0400
@@ -50,7 +50,7 @@
 
     @Override
     public Rectangle getBounds() {
-        final Rectangle2D nativeBounds = nativeGetBounds(device.getCoreGraphicsScreen());
+        final Rectangle2D nativeBounds = nativeGetBounds(device.getCGDisplayID());
         return nativeBounds.getBounds(); // does integer rounding
     }
 
--- a/src/macosx/classes/sun/awt/CGraphicsDevice.java	Wed Apr 10 12:43:18 2013 -0700
+++ b/src/macosx/classes/sun/awt/CGraphicsDevice.java	Thu May 09 03:26:41 2013 +0400
@@ -25,11 +25,11 @@
 
 package sun.awt;
 
+import java.awt.AWTPermission;
+import java.awt.DisplayMode;
 import java.awt.GraphicsConfiguration;
 import java.awt.GraphicsDevice;
 import java.awt.Window;
-import java.awt.AWTPermission;
-import java.awt.DisplayMode;
 import java.util.Objects;
 
 import sun.java2d.opengl.CGLGraphicsConfig;
@@ -58,9 +58,12 @@
     }
 
     /**
+     * Returns CGDirectDisplayID, which is the same id as @"NSScreenNumber" in
+     * NSScreen.
+     *
      * @return CoreGraphics display id.
      */
-    public int getCoreGraphicsScreen() {
+    public int getCGDisplayID() {
         return displayID;
     }
 
--- a/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java	Wed Apr 10 12:43:18 2013 -0700
+++ b/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java	Thu May 09 03:26:41 2013 +0400
@@ -85,10 +85,8 @@
     private Object disposerReferent = new Object();
 
     private final int cachedMaxTextureSize;
-
-    public static native int getDefaultPixFmt(int screennum);
     private static native boolean initCGL();
-    private static native long getCGLConfigInfo(int screennum, int visualnum,
+    private static native long getCGLConfigInfo(int displayID, int visualnum,
                                                 int swapInterval);
     private static native int getOGLCapabilities(long configInfo);
     private static native int _getMaxTextureSize();
@@ -147,15 +145,16 @@
             // Java-level context and flush the queue...
             OGLContext.invalidateCurrentContext();
 
-            cfginfo = getCGLConfigInfo(device.getCoreGraphicsScreen(), pixfmt,
+            cfginfo = getCGLConfigInfo(device.getCGDisplayID(), pixfmt,
                                        kOpenGLSwapInterval);
-
-            OGLContext.setScratchSurface(cfginfo);
-            rq.flushAndInvokeNow(new Runnable() {
-                public void run() {
-                    ids[0] = OGLContext.getOGLIdString();
-                }
-            });
+            if (cfginfo != 0L) {
+                OGLContext.setScratchSurface(cfginfo);
+                rq.flushAndInvokeNow(new Runnable() {
+                    public void run() {
+                        ids[0] = OGLContext.getOGLIdString();
+                    }
+                });
+            }
         } finally {
             rq.unlock();
         }
@@ -260,8 +259,8 @@
 
     @Override
     public String toString() {
-        int screen = getDevice().getCoreGraphicsScreen();
-        return ("CGLGraphicsConfig[dev="+screen+",pixfmt="+pixfmt+"]");
+        int displayID = getDevice().getCGDisplayID();
+        return ("CGLGraphicsConfig[dev="+displayID+",pixfmt="+pixfmt+"]");
     }
 
 
@@ -485,8 +484,8 @@
     }
 
     public void addDeviceEventListener(AccelDeviceEventListener l) {
-        int screen = getDevice().getCoreGraphicsScreen();
-        AccelDeviceEventNotifier.addListener(l, screen);
+        int displayID = getDevice().getCGDisplayID();
+        AccelDeviceEventNotifier.addListener(l, displayID);
     }
 
     public void removeDeviceEventListener(AccelDeviceEventListener l) {
--- a/src/macosx/classes/sun/lwawt/macosx/CRobot.java	Wed Apr 10 12:43:18 2013 -0700
+++ b/src/macosx/classes/sun/lwawt/macosx/CRobot.java	Thu May 09 03:26:41 2013 +0400
@@ -65,7 +65,7 @@
         mouseLastX = x;
         mouseLastY = y;
 
-        mouseEvent(fDevice.getCoreGraphicsScreen(), mouseLastX, mouseLastY,
+        mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY,
                    mouseButtonsState, true, true);
     }
 
@@ -79,7 +79,7 @@
     public void mousePress(int buttons) {
         mouseButtonsState |= buttons;
 
-        mouseEvent(fDevice.getCoreGraphicsScreen(), mouseLastX, mouseLastY,
+        mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY,
                    buttons, true, false);
     }
 
@@ -93,7 +93,7 @@
     public void mouseRelease(int buttons) {
         mouseButtonsState &= ~buttons;
 
-        mouseEvent(fDevice.getCoreGraphicsScreen(), mouseLastX, mouseLastY,
+        mouseEvent(fDevice.getCGDisplayID(), mouseLastX, mouseLastY,
                    buttons, false, false);
     }
 
@@ -163,7 +163,7 @@
     }
 
     private native void initRobot();
-    private native void mouseEvent(int screen, int lastX, int lastY,
+    private native void mouseEvent(int displayID, int lastX, int lastY,
                                    int buttonsState,
                                    boolean isButtonsDownState,
                                    boolean isMouseMove);
--- a/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Wed Apr 10 12:43:18 2013 -0700
+++ b/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Thu May 09 03:26:41 2013 +0400
@@ -346,7 +346,7 @@
     @Override
     public Insets getScreenInsets(final GraphicsConfiguration gc) {
         final CGraphicsConfig cgc = (CGraphicsConfig) gc;
-        final int displayId = cgc.getDevice().getCoreGraphicsScreen();
+        final int displayId = cgc.getDevice().getCGDisplayID();
         Rectangle fullScreen, workArea;
         final long screen = CWrapper.NSScreen.screenByDisplayId(displayId);
         try {
--- a/src/macosx/native/sun/awt/CRobot.m	Wed Apr 10 12:43:18 2013 -0700
+++ b/src/macosx/native/sun/awt/CRobot.m	Thu May 09 03:26:41 2013 +0400
@@ -135,7 +135,7 @@
 JNIEXPORT void JNICALL
 Java_sun_lwawt_macosx_CRobot_mouseEvent
 (JNIEnv *env, jobject peer,
- jint screenIndex, jint mouseLastX, jint mouseLastY, jint buttonsState,
+ jint displayID, jint mouseLastX, jint mouseLastY, jint buttonsState,
  jboolean isButtonsDownState, jboolean isMouseMove)
 {
     JNF_COCOA_ENTER(env);
@@ -149,8 +149,6 @@
 
     CGError err = kCGErrorSuccess;
 
-    CGDirectDisplayID displayID =
-    FindCGDirectDisplayIDForScreenIndex(screenIndex);
     CGRect globalDeviceBounds = CGDisplayBounds(displayID);
 
     // Set unknown mouse location, if needed.
--- a/src/macosx/native/sun/awt/LWCToolkit.h	Wed Apr 10 12:43:18 2013 -0700
+++ b/src/macosx/native/sun/awt/LWCToolkit.h	Thu May 09 03:26:41 2013 +0400
@@ -44,8 +44,6 @@
 + (void) eventCountPlusPlus;
 @end
 
-CGDirectDisplayID FindCGDirectDisplayIDForScreenIndex(jint screenIndex);
-
 /*
  * Utility Macros
  */
--- a/src/macosx/native/sun/awt/LWCToolkit.m	Wed Apr 10 12:43:18 2013 -0700
+++ b/src/macosx/native/sun/awt/LWCToolkit.m	Thu May 09 03:26:41 2013 +0400
@@ -177,39 +177,6 @@
     NSBeep(); // produces both sound and visual flash, if configured in System Preferences
 }
 
-CGDirectDisplayID
-FindCGDirectDisplayIDForScreenIndex(jint screenIndex)
-{
-    // most common case - just one monitor
-    CGDirectDisplayID screenID = CGMainDisplayID();
-
-    CGDisplayCount displayCount = 0;
-    CGGetOnlineDisplayList(0, NULL, &displayCount);
-
-    if ((displayCount > 1) &&
-        (screenIndex >= 0) &&
-        (screenIndex < (jint)displayCount))
-    {
-        if (displayCount < 10) {
-            // stack allocated optimization for less than 10 monitors
-            CGDirectDisplayID onlineDisplays[displayCount];
-            CGGetOnlineDisplayList(displayCount, onlineDisplays, &displayCount);
-            screenID = (CGDirectDisplayID)onlineDisplays[screenIndex];
-        } else {
-            CGDirectDisplayID *onlineDisplays =
-            malloc(displayCount*sizeof(CGDirectDisplayID));
-            if (onlineDisplays != NULL) {
-                CGGetOnlineDisplayList(displayCount, onlineDisplays,
-                                       &displayCount);
-                screenID = (CGDirectDisplayID)onlineDisplays[screenIndex];
-                free(onlineDisplays);
-            }
-        }
-    }
-
-    return screenID;
-}
-
 /*
  * Class:     sun_lwawt_macosx_LWCToolkit
  * Method:    initIDs
--- a/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m	Wed Apr 10 12:43:18 2013 -0700
+++ b/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m	Thu May 09 03:26:41 2013 +0400
@@ -190,12 +190,12 @@
 JNIEXPORT jlong JNICALL
 Java_sun_java2d_opengl_CGLGraphicsConfig_getCGLConfigInfo
     (JNIEnv *env, jclass cglgc,
-     jint screennum, jint pixfmt, jint swapInterval)
+     jint displayID, jint pixfmt, jint swapInterval)
 {
   jlong ret = 0L;
   JNF_COCOA_ENTER(env);
   NSMutableArray * retArray = [NSMutableArray arrayWithCapacity:3];
-  [retArray addObject: [NSNumber numberWithInt: (int)screennum]];
+  [retArray addObject: [NSNumber numberWithInt: (int)displayID]];
   [retArray addObject: [NSNumber numberWithInt: (int)pixfmt]];
   [retArray addObject: [NSNumber numberWithInt: (int)swapInterval]];
   if ([NSThread isMainThread]) {
@@ -215,7 +215,7 @@
 + (void) _getCGLConfigInfo: (NSMutableArray *)argValue {
     AWT_ASSERT_APPKIT_THREAD;
 
-    jint screennum = (jint)[(NSNumber *)[argValue objectAtIndex: 0] intValue];
+    jint displayID = (jint)[(NSNumber *)[argValue objectAtIndex: 0] intValue];
     jint pixfmt = (jint)[(NSNumber *)[argValue objectAtIndex: 1] intValue];
     jint swapInterval = (jint)[(NSNumber *)[argValue objectAtIndex: 2] intValue];
     JNIEnv *env = [ThreadUtilities getJNIEnvUncached];
@@ -228,16 +228,11 @@
     CGOpenGLDisplayMask glMask = (CGOpenGLDisplayMask)pixfmt;
     if (sharedContext == NULL) {
         if (glMask == 0) {
-            CGDirectDisplayID id =
-                FindCGDirectDisplayIDForScreenIndex(screennum);
-            glMask = CGDisplayIDToOpenGLDisplayMask(id);
+            glMask = CGDisplayIDToOpenGLDisplayMask(displayID);
         }
 
         NSOpenGLPixelFormatAttribute attrs[] = {
             NSOpenGLPFAClosestPolicy,
-            NSOpenGLPFANoRecovery,
-            NSOpenGLPFAAccelerated,
-            NSOpenGLPFAFullScreen,
             NSOpenGLPFAWindow,
             NSOpenGLPFAPixelBuffer,
             NSOpenGLPFADoubleBuffer,
@@ -410,7 +405,7 @@
         return;
     }
     memset(cglinfo, 0, sizeof(CGLGraphicsConfigInfo));
-    cglinfo->screen = screennum;
+    cglinfo->screen = displayID;
     cglinfo->pixfmt = sharedPixelFormat;
     cglinfo->context = oglc;
 
@@ -420,17 +415,6 @@
 }
 @end //GraphicsConfigUtil
 
-
-JNIEXPORT jint JNICALL
-Java_sun_java2d_opengl_CGLGraphicsConfig_getDefaultPixFmt
-    (JNIEnv *env, jclass cglgc, jint screennum)
-{
-    J2dTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getDefaultPixFmt");
-
-    CGDirectDisplayID id = FindCGDirectDisplayIDForScreenIndex(screennum);
-    return (jint)CGDisplayIDToOpenGLDisplayMask(id);
-}
-
 JNIEXPORT jint JNICALL
 Java_sun_java2d_opengl_CGLGraphicsConfig_getOGLCapabilities
     (JNIEnv *env, jclass cglgc, jlong configInfo)