8008660: Failure in 2D Queue Flusher thread on Mac
authorserb
Thu, 28 Feb 2013 17:04:19 +0400
changeset 15988 6db6e40405cf
parent 15987 1cd2a92ba636
child 15989 0fe0985a7bde
8008660: Failure in 2D Queue Flusher thread on Mac Reviewed-by: swingler, bae
jdk/src/macosx/classes/sun/awt/CGraphicsConfig.java
jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java
jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java
jdk/src/macosx/classes/sun/lwawt/macosx/CRobot.java
jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java
jdk/src/macosx/native/sun/awt/CRobot.m
jdk/src/macosx/native/sun/awt/LWCToolkit.h
jdk/src/macosx/native/sun/awt/LWCToolkit.m
jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m
--- a/jdk/src/macosx/classes/sun/awt/CGraphicsConfig.java	Wed Feb 27 20:34:04 2013 +0400
+++ b/jdk/src/macosx/classes/sun/awt/CGraphicsConfig.java	Thu Feb 28 17:04:19 2013 +0400
@@ -53,7 +53,7 @@
 
     @Override
     public Rectangle getBounds() {
-        final Rectangle2D nativeBounds = nativeGetBounds(device.getCoreGraphicsScreen());
+        final Rectangle2D nativeBounds = nativeGetBounds(device.getCGDisplayID());
         return nativeBounds.getBounds(); // does integer rounding
     }
 
--- a/jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java	Wed Feb 27 20:34:04 2013 +0400
+++ b/jdk/src/macosx/classes/sun/awt/CGraphicsDevice.java	Thu Feb 28 17:04:19 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/jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java	Wed Feb 27 20:34:04 2013 +0400
+++ b/jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java	Thu Feb 28 17:04:19 2013 +0400
@@ -80,10 +80,8 @@
     private ContextCapabilities oglCaps;
     private OGLContext context;
     private final Object disposerReferent = new Object();
-
-    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);
 
@@ -137,15 +135,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();
         }
@@ -253,8 +252,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+"]");
     }
 
     @Override
@@ -413,8 +412,8 @@
 
     @Override
     public void addDeviceEventListener(AccelDeviceEventListener l) {
-        int screen = getDevice().getCoreGraphicsScreen();
-        AccelDeviceEventNotifier.addListener(l, screen);
+        int displayID = getDevice().getCGDisplayID();
+        AccelDeviceEventNotifier.addListener(l, displayID);
     }
 
     @Override
--- a/jdk/src/macosx/classes/sun/lwawt/macosx/CRobot.java	Wed Feb 27 20:34:04 2013 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CRobot.java	Thu Feb 28 17:04:19 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/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Wed Feb 27 20:34:04 2013 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/macosx/LWCToolkit.java	Thu Feb 28 17:04:19 2013 +0400
@@ -352,7 +352,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/jdk/src/macosx/native/sun/awt/CRobot.m	Wed Feb 27 20:34:04 2013 +0400
+++ b/jdk/src/macosx/native/sun/awt/CRobot.m	Thu Feb 28 17:04:19 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/jdk/src/macosx/native/sun/awt/LWCToolkit.h	Wed Feb 27 20:34:04 2013 +0400
+++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.h	Thu Feb 28 17:04:19 2013 +0400
@@ -44,8 +44,6 @@
 + (void) eventCountPlusPlus;
 @end
 
-CGDirectDisplayID FindCGDirectDisplayIDForScreenIndex(jint screenIndex);
-
 /*
  * Utility Macros
  */
--- a/jdk/src/macosx/native/sun/awt/LWCToolkit.m	Wed Feb 27 20:34:04 2013 +0400
+++ b/jdk/src/macosx/native/sun/awt/LWCToolkit.m	Thu Feb 28 17:04:19 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/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m	Wed Feb 27 20:34:04 2013 +0400
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m	Thu Feb 28 17:04:19 2013 +0400
@@ -192,12 +192,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]) {
@@ -217,7 +217,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];
@@ -230,16 +230,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,
@@ -412,7 +407,7 @@
         return;
     }
     memset(cglinfo, 0, sizeof(CGLGraphicsConfigInfo));
-    cglinfo->screen = screennum;
+    cglinfo->screen = displayID;
     cglinfo->pixfmt = sharedPixelFormat;
     cglinfo->context = oglc;
 
@@ -422,17 +417,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)