changeset 4872:2a8bd80fe31d

7128597: [macosx] Program freeze when Swing is used with -XstartOnFirstThread Reviewed-by: art
author dcherepanov
date Fri, 20 Jan 2012 14:05:25 +0300
parents d2494547f2d7
children 4156455c1481
files src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.h src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m
diffstat 3 files changed, 10 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java	Thu Jan 19 14:42:36 2012 +0000
+++ b/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java	Fri Jan 20 14:05:25 2012 +0300
@@ -134,10 +134,10 @@
             // surfaces/contexts, so we should first invalidate the current
             // Java-level context and flush the queue...
             OGLContext.invalidateCurrentContext();
-            CGLGetConfigInfo action =
-                new CGLGetConfigInfo(device.getCoreGraphicsScreen(), pixfmt);
-            rq.flushAndInvokeNow(action);
-            cfginfo = action.getConfigInfo();
+
+            cfginfo = getCGLConfigInfo(device.getCoreGraphicsScreen(), pixfmt,
+                                       kOpenGLSwapInterval);
+
             OGLContext.setScratchSurface(cfginfo);
             rq.flushAndInvokeNow(new Runnable() {
                 public void run() {
@@ -157,26 +157,6 @@
         return new CGLGraphicsConfig(device, pixfmt, cfginfo, caps);
     }
 
-    /**
-     * This is a small helper class that allows us to execute
-     * getCGLConfigInfo() on the queue flushing thread.
-     */
-    private static class CGLGetConfigInfo implements Runnable {
-        private int screen;
-        private int pixfmt;
-        private long cfginfo;
-        private CGLGetConfigInfo(int screen, int pixfmt) {
-            this.screen = screen;
-            this.pixfmt = pixfmt;
-        }
-        public void run() {
-            cfginfo = getCGLConfigInfo(screen, pixfmt, kOpenGLSwapInterval);
-        }
-        public long getConfigInfo() {
-            return cfginfo;
-        }
-    }
-
     public static boolean isCGLAvailable() {
         return cglAvailable;
     }
--- a/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.h	Thu Jan 19 14:42:36 2012 +0000
+++ b/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.h	Fri Jan 20 14:05:25 2012 +0300
@@ -33,6 +33,7 @@
 #import <Cocoa/Cocoa.h>
 
 @interface GraphicsConfigUtil : NSObject {}
++ (void) _getCGLConfigInfo: (NSMutableArray *)argValue;
 @end
 
 // Prototyped CAOpenGLLayer drawing directly from Java2D OpenGL rendering
--- a/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m	Thu Jan 19 14:42:36 2012 +0000
+++ b/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m	Fri Jan 20 14:05:25 2012 +0300
@@ -198,7 +198,11 @@
   [retArray addObject: [NSNumber numberWithInt: (int)screennum]];
   [retArray addObject: [NSNumber numberWithInt: (int)pixfmt]];
   [retArray addObject: [NSNumber numberWithInt: (int)swapInterval]];
-  [GraphicsConfigUtil performSelectorOnMainThread: @selector(_getCGLConfigInfo:) withObject: retArray waitUntilDone: YES];
+  if ([NSThread isMainThread]) {
+      [GraphicsConfigUtil _getCGLConfigInfo: retArray];
+  } else {
+      [GraphicsConfigUtil performSelectorOnMainThread: @selector(_getCGLConfigInfo:) withObject: retArray waitUntilDone: YES];
+  }
   NSNumber * num = (NSNumber *)[retArray objectAtIndex: 0];
   ret = (jlong)[num longValue];
   JNF_COCOA_EXIT(env);