8027778: [macosx] Full screen not working properly on 7u45 and jdk8
authorserb
Thu, 27 Feb 2014 19:01:32 +0400
changeset 23325 4c3942938b0d
parent 23324 fb6002beb0ce
child 23326 4b7f5c8d649d
child 23328 4c53a6ebc779
8027778: [macosx] Full screen not working properly on 7u45 and jdk8 8010999: [macosx] a constrain of the top level window should be improved 8015100: [macosx] Applet graphics corrupted when applet width/height exceeds screen dimensions Reviewed-by: anthony, pchelko
jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java
jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java
jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m
--- a/jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java	Thu Feb 27 16:14:22 2014 +0400
+++ b/jdk/src/macosx/classes/sun/java2d/opengl/CGLGraphicsConfig.java	Thu Feb 27 19:01:32 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -30,9 +30,6 @@
 import java.awt.Component;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.GraphicsDevice;
-import java.awt.GraphicsEnvironment;
 import java.awt.Image;
 import java.awt.ImageCapabilities;
 import java.awt.Rectangle;
@@ -80,23 +77,34 @@
     private ContextCapabilities oglCaps;
     private OGLContext context;
     private final Object disposerReferent = new Object();
+    private final int maxTextureSize;
+
     private static native boolean initCGL();
     private static native long getCGLConfigInfo(int displayID, int visualnum,
                                                 int swapInterval);
     private static native int getOGLCapabilities(long configInfo);
 
+    /**
+     * Returns GL_MAX_TEXTURE_SIZE from the shared opengl context. Must be
+     * called under OGLRQ lock, because this method change current context.
+     *
+     * @return GL_MAX_TEXTURE_SIZE
+     */
+    private static native int nativeGetMaxTextureSize();
+
     static {
         cglAvailable = initCGL();
     }
 
     private CGLGraphicsConfig(CGraphicsDevice device, int pixfmt,
-                                long configInfo, ContextCapabilities oglCaps)
-    {
+                              long configInfo, int maxTextureSize,
+                              ContextCapabilities oglCaps) {
         super(device);
 
         this.pixfmt = pixfmt;
         this.pConfigInfo = configInfo;
         this.oglCaps = oglCaps;
+        this.maxTextureSize = maxTextureSize;
         context = new OGLContext(OGLRenderQueue.getInstance(), this);
 
         // add a record to the Disposer so that we destroy the native
@@ -126,6 +134,7 @@
         }
 
         long cfginfo = 0;
+        int textureSize = 0;
         final String ids[] = new String[1];
         OGLRenderQueue rq = OGLRenderQueue.getInstance();
         rq.lock();
@@ -138,11 +147,14 @@
             cfginfo = getCGLConfigInfo(device.getCGDisplayID(), pixfmt,
                                        kOpenGLSwapInterval);
             if (cfginfo != 0L) {
+                textureSize = nativeGetMaxTextureSize();
+                // 7160609: GL still fails to create a square texture of this
+                // size. Half should be safe enough.
+                // Explicitly not support a texture more than 2^14, see 8010999.
+                textureSize = textureSize <= 16384 ? textureSize / 2 : 8192;
                 OGLContext.setScratchSurface(cfginfo);
-                rq.flushAndInvokeNow(new Runnable() {
-                    public void run() {
-                        ids[0] = OGLContext.getOGLIdString();
-                    }
+                rq.flushAndInvokeNow(() -> {
+                    ids[0] = OGLContext.getOGLIdString();
                 });
             }
         } finally {
@@ -154,8 +166,7 @@
 
         int oglCaps = getOGLCapabilities(cfginfo);
         ContextCapabilities caps = new OGLContextCaps(oglCaps, ids[0]);
-
-        return new CGLGraphicsConfig(device, pixfmt, cfginfo, caps);
+        return new CGLGraphicsConfig(device, pixfmt, cfginfo, textureSize, caps);
     }
 
     public static boolean isCGLAvailable() {
@@ -246,8 +257,6 @@
         } finally {
             rq.unlock();
         }
-
-        updateTotalDisplayBounds();
     }
 
     @Override
@@ -421,57 +430,15 @@
         AccelDeviceEventNotifier.removeListener(l);
     }
 
-    private static final Rectangle totalDisplayBounds = new Rectangle();
-
-    private static void updateTotalDisplayBounds() {
-        synchronized (totalDisplayBounds) {
-            Rectangle virtualBounds = new Rectangle();
-            for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) {
-                for (GraphicsConfiguration gc : gd.getConfigurations()) {
-                    virtualBounds = virtualBounds.union(gc.getBounds());
-                }
-            }
-            totalDisplayBounds.setBounds(virtualBounds);
-        }
-    }
-
-    // 7160609: GL still fails to create a square texture of this size,
-    //          so we use this value to cap the total display bounds.
-    native private static int getMaxTextureSize();
-
     @Override
     public int getMaxTextureWidth() {
-        //Temporary disable this logic and use some magic constrain.
-        /*
-         int width;
-
-         synchronized (totalDisplayBounds) {
-         if (totalDisplayBounds.width == 0) {
-         updateTotalDisplayBounds();
-         }
-         width = totalDisplayBounds.width;
-         }
-
-         return Math.min(width, getMaxTextureSize());
-         */
-        return getMaxTextureSize() / (getDevice().getScaleFactor() * 2);
+        return Math.max(maxTextureSize / getDevice().getScaleFactor(),
+                        getBounds().width);
     }
 
     @Override
     public int getMaxTextureHeight() {
-        //Temporary disable this logic and use some magic constrain.
-        /*
-         int height;
-
-         synchronized (totalDisplayBounds) {
-         if (totalDisplayBounds.height == 0) {
-         updateTotalDisplayBounds();
-         }
-         height = totalDisplayBounds.height;
-         }
-
-         return Math.min(height, getMaxTextureSize());
-         */
-        return getMaxTextureSize() / (getDevice().getScaleFactor() * 2);
+        return Math.max(maxTextureSize / getDevice().getScaleFactor(),
+                        getBounds().height);
     }
 }
--- a/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Thu Feb 27 16:14:22 2014 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWWindowPeer.java	Thu Feb 27 19:01:32 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -629,6 +629,7 @@
         final boolean isNewDevice = updateGraphicsDevice();
         if (resized || isNewDevice) {
             replaceSurfaceData();
+            updateMinimumSize();
         }
 
         // Third, COMPONENT_MOVED/COMPONENT_RESIZED/PAINT events
@@ -1046,7 +1047,9 @@
 
     @Override
     public final void displayChanged() {
-        updateGraphicsDevice();
+        if (updateGraphicsDevice()) {
+            updateMinimumSize();
+        }
         // Replace surface unconditionally, because internal state of the
         // GraphicsDevice could be changed.
         replaceSurfaceData();
--- a/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m	Thu Feb 27 16:14:22 2014 +0400
+++ b/jdk/src/macosx/native/sun/java2d/opengl/CGLGraphicsConfig.m	Thu Feb 27 19:01:32 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -433,18 +433,18 @@
 }
 
 JNIEXPORT jint JNICALL
-Java_sun_java2d_opengl_CGLGraphicsConfig_getMaxTextureSize
+Java_sun_java2d_opengl_CGLGraphicsConfig_nativeGetMaxTextureSize
     (JNIEnv *env, jclass cglgc)
 {
-    J2dTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_getMaxTextureSize");
+    J2dTraceLn(J2D_TRACE_INFO, "CGLGraphicsConfig_nativeGetMaxTextureSize");
 
     __block int max = 0;
 
-    [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^(){
+    [ThreadUtilities performOnMainThreadWaiting:YES block:^(){
         [sharedContext makeCurrentContext];
         j2d_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
+        [NSOpenGLContext clearCurrentContext];
     }];
 
     return (jint)max;
 }
-