6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
authoranthony
Tue, 19 May 2009 14:14:31 +0400
changeset 2805 9f18d7e66042
parent 2804 a947dcefc8cb
child 2806 27edf81ff967
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms Summary: The peer gets recreated if the visual of the new GC differs from the previous one Reviewed-by: art, dcherepanov
jdk/src/share/classes/java/awt/Component.java
jdk/src/share/classes/java/awt/Container.java
jdk/src/share/classes/java/awt/peer/ComponentPeer.java
jdk/src/share/classes/sun/awt/NullComponentPeer.java
jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java
jdk/src/solaris/classes/sun/awt/X11/XEmbedChildProxyPeer.java
jdk/src/solaris/classes/sun/awt/X11/XWindow.java
jdk/src/windows/classes/sun/awt/windows/WComponentPeer.java
--- a/jdk/src/share/classes/java/awt/Component.java	Tue May 19 12:15:18 2009 +0400
+++ b/jdk/src/share/classes/java/awt/Component.java	Tue May 19 14:14:31 2009 +0400
@@ -1038,13 +1038,23 @@
 
     void setGraphicsConfiguration(GraphicsConfiguration gc) {
         synchronized(getTreeLock()) {
-            graphicsConfig = gc;
-
-            ComponentPeer peer = getPeer();
-            if (peer != null) {
-                peer.updateGraphicsData(gc);
-            }
-        }
+            if (updateGraphicsData(gc)) {
+                removeNotify();
+                addNotify();
+            }
+        }
+    }
+
+    boolean updateGraphicsData(GraphicsConfiguration gc) {
+        checkTreeLock();
+
+        graphicsConfig = gc;
+
+        ComponentPeer peer = getPeer();
+        if (peer != null) {
+            return peer.updateGraphicsData(gc);
+        }
+        return false;
     }
 
     /**
--- a/jdk/src/share/classes/java/awt/Container.java	Tue May 19 12:15:18 2009 +0400
+++ b/jdk/src/share/classes/java/awt/Container.java	Tue May 19 14:14:31 2009 +0400
@@ -1113,16 +1113,17 @@
     }
 
     @Override
-    void setGraphicsConfiguration(GraphicsConfiguration gc) {
-        synchronized (getTreeLock()) {
-            super.setGraphicsConfiguration(gc);
-
-            for (Component comp : component) {
-                if (comp != null) {
-                    comp.setGraphicsConfiguration(gc);
-                }
+    boolean updateGraphicsData(GraphicsConfiguration gc) {
+        checkTreeLock();
+
+        boolean ret = super.updateGraphicsData(gc);
+
+        for (Component comp : component) {
+            if (comp != null) {
+                ret |= comp.updateGraphicsData(gc);
             }
         }
+        return ret;
     }
 
     /**
--- a/jdk/src/share/classes/java/awt/peer/ComponentPeer.java	Tue May 19 12:15:18 2009 +0400
+++ b/jdk/src/share/classes/java/awt/peer/ComponentPeer.java	Tue May 19 14:14:31 2009 +0400
@@ -548,7 +548,8 @@
     /**
      * Updates internal data structures related to the component's GC.
      *
+     * @return if the peer needs to be recreated for the changes to take effect
      * @since 1.7
      */
-    void updateGraphicsData(GraphicsConfiguration gc);
+    boolean updateGraphicsData(GraphicsConfiguration gc);
 }
--- a/jdk/src/share/classes/sun/awt/NullComponentPeer.java	Tue May 19 12:15:18 2009 +0400
+++ b/jdk/src/share/classes/sun/awt/NullComponentPeer.java	Tue May 19 14:14:31 2009 +0400
@@ -300,7 +300,9 @@
     public void setZOrder(ComponentPeer above) {
     }
 
-    public void updateGraphicsData(GraphicsConfiguration gc) {}
+    public boolean updateGraphicsData(GraphicsConfiguration gc) {
+        return false;
+    }
 
     public GraphicsConfiguration getAppropriateGraphicsConfiguration(
                         GraphicsConfiguration gc)
--- a/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java	Tue May 19 12:15:18 2009 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java	Tue May 19 14:14:31 2009 +0400
@@ -1429,7 +1429,26 @@
         }
     }
 
-    public void updateGraphicsData(GraphicsConfiguration gc) {
+    public boolean updateGraphicsData(GraphicsConfiguration gc) {
+        int oldVisual = -1, newVisual = -1;
+
+        if (graphicsConfig != null) {
+            oldVisual = graphicsConfig.getVisual();
+        }
+        if (gc != null && gc instanceof X11GraphicsConfig) {
+            newVisual = ((X11GraphicsConfig)gc).getVisual();
+        }
+
+        // If the new visual differs from the old one, the peer must be
+        // recreated because X11 does not allow changing the visual on the fly.
+        // So we even skip the initGraphicsConfiguration() call.
+        // The initial assignment should happen though, hence the != -1 thing.
+        if (oldVisual != -1 && oldVisual != newVisual) {
+            return true;
+        }
+
         initGraphicsConfiguration();
+        doValidateSurface();
+        return false;
     }
 }
--- a/jdk/src/solaris/classes/sun/awt/X11/XEmbedChildProxyPeer.java	Tue May 19 12:15:18 2009 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XEmbedChildProxyPeer.java	Tue May 19 14:14:31 2009 +0400
@@ -386,5 +386,7 @@
     public void setZOrder(ComponentPeer above) {
     }
 
-    public void updateGraphicsData(GraphicsConfiguration gc) {}
+    public boolean updateGraphicsData(GraphicsConfiguration gc) {
+        return false;
+    }
 }
--- a/jdk/src/solaris/classes/sun/awt/X11/XWindow.java	Tue May 19 12:15:18 2009 +0400
+++ b/jdk/src/solaris/classes/sun/awt/X11/XWindow.java	Tue May 19 14:14:31 2009 +0400
@@ -1343,18 +1343,23 @@
         setSizeHints(flags, x, y, width, height);
     }
 
-      void validateSurface() {
+    void validateSurface() {
         if ((width != oldWidth) || (height != oldHeight)) {
-            SurfaceData oldData = surfaceData;
-            if (oldData != null) {
-                surfaceData = graphicsConfig.createSurfaceData(this);
-                oldData.invalidate();
-            }
+            doValidateSurface();
+
             oldWidth = width;
             oldHeight = height;
         }
     }
 
+    final void doValidateSurface() {
+        SurfaceData oldData = surfaceData;
+        if (oldData != null) {
+            surfaceData = graphicsConfig.createSurfaceData(this);
+            oldData.invalidate();
+        }
+    }
+
     public SurfaceData getSurfaceData() {
         return surfaceData;
     }
--- a/jdk/src/windows/classes/sun/awt/windows/WComponentPeer.java	Tue May 19 12:15:18 2009 +0400
+++ b/jdk/src/windows/classes/sun/awt/windows/WComponentPeer.java	Tue May 19 14:14:31 2009 +0400
@@ -488,13 +488,14 @@
         }
     }
 
-    public void updateGraphicsData(GraphicsConfiguration gc) {
+    public boolean updateGraphicsData(GraphicsConfiguration gc) {
         winGraphicsConfig = (Win32GraphicsConfig)gc;
         try {
             replaceSurfaceData();
         } catch (InvalidPipeException e) {
             // REMIND : what do we do if our surface creation failed?
         }
+        return false;
     }
 
     //This will return null for Components not yet added to a Container