diff --git a/jdk/src/share/classes/java/awt/Canvas.java b/jdk/src/share/classes/java/awt/Canvas.java index 04b3bc2dca4..86315e7c12e 100644 --- a/jdk/src/share/classes/java/awt/Canvas.java +++ b/jdk/src/share/classes/java/awt/Canvas.java @@ -25,6 +25,7 @@ package java.awt; import java.awt.image.BufferStrategy; +import java.awt.peer.CanvasPeer; import javax.accessibility.*; /** @@ -65,7 +66,17 @@ public class Canvas extends Component implements Accessible { */ public Canvas(GraphicsConfiguration config) { this(); - graphicsConfig = config; + setGraphicsConfiguration(config); + } + + @Override + void setGraphicsConfiguration(GraphicsConfiguration gc) { + CanvasPeer peer = (CanvasPeer)getPeer(); + if (peer != null) { + gc = peer.getAppropriateGraphicsConfiguration(gc); + } + + super.setGraphicsConfiguration(gc); } /** diff --git a/jdk/src/share/classes/java/awt/Component.java b/jdk/src/share/classes/java/awt/Component.java index 9828ddb5661..e59d37a5826 100644 --- a/jdk/src/share/classes/java/awt/Component.java +++ b/jdk/src/share/classes/java/awt/Component.java @@ -300,7 +300,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * @see GraphicsConfiguration * @see #getGraphicsConfiguration */ - transient GraphicsConfiguration graphicsConfig = null; + private transient GraphicsConfiguration graphicsConfig = null; /** * A reference to a BufferStrategy object @@ -845,6 +845,12 @@ public abstract class Component implements ImageObserver, MenuContainer, } } } + + public void setGraphicsConfiguration(Component comp, + GraphicsConfiguration gc) + { + comp.setGraphicsConfiguration(gc); + } }); } @@ -1012,50 +1018,21 @@ public abstract class Component implements ImageObserver, MenuContainer, */ public GraphicsConfiguration getGraphicsConfiguration() { synchronized(getTreeLock()) { - if (graphicsConfig != null) { - return graphicsConfig; - } else if (getParent() != null) { - return getParent().getGraphicsConfiguration(); - } else { - return null; - } + return getGraphicsConfiguration_NoClientCode(); } } final GraphicsConfiguration getGraphicsConfiguration_NoClientCode() { - GraphicsConfiguration graphicsConfig = this.graphicsConfig; - Container parent = this.parent; - if (graphicsConfig != null) { - return graphicsConfig; - } else if (parent != null) { - return parent.getGraphicsConfiguration_NoClientCode(); - } else { - return null; - } + return graphicsConfig; } - /** - * Resets this Component's - * GraphicsConfiguration back to a default - * value. For most componenets, this is null. - * Called from the Toolkit thread, so NO CLIENT CODE. - */ - void resetGC() { + void setGraphicsConfiguration(GraphicsConfiguration gc) { synchronized(getTreeLock()) { - graphicsConfig = null; - } - } + graphicsConfig = gc; - /* - * Not called on Component, but needed for Canvas and Window - */ - void setGCFromPeer() { - synchronized(getTreeLock()) { - if (peer != null) { // can't imagine how this will be false, - // but just in case - graphicsConfig = peer.getGraphicsConfiguration(); - } else { - graphicsConfig = null; + ComponentPeer peer = getPeer(); + if (peer != null) { + peer.updateGraphicsData(gc); } } } diff --git a/jdk/src/share/classes/java/awt/Container.java b/jdk/src/share/classes/java/awt/Container.java index 64de85477a7..fb520547e1e 100644 --- a/jdk/src/share/classes/java/awt/Container.java +++ b/jdk/src/share/classes/java/awt/Container.java @@ -506,6 +506,7 @@ public class Container extends Component { adjustDescendants(-(comp.countHierarchyMembers())); comp.parent = null; + comp.setGraphicsConfiguration(null); component.remove(index); invalidateIfValid(); @@ -789,6 +790,7 @@ public class Container extends Component { component.add(index, comp); } comp.parent = this; + comp.setGraphicsConfiguration(getGraphicsConfiguration()); adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK, comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK)); @@ -1056,6 +1058,7 @@ public class Container extends Component { component.add(index, comp); } comp.parent = this; + comp.setGraphicsConfiguration(thisGC); adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK, comp.numListening(AWTEvent.HIERARCHY_EVENT_MASK)); @@ -1094,6 +1097,19 @@ public class Container extends Component { } } + @Override + void setGraphicsConfiguration(GraphicsConfiguration gc) { + synchronized (getTreeLock()) { + super.setGraphicsConfiguration(gc); + + for (Component comp : component) { + if (comp != null) { + comp.setGraphicsConfiguration(gc); + } + } + } + } + /** * Checks that all Components that this Container contains are on * the same GraphicsDevice as this Container. If not, throws an @@ -1151,6 +1167,7 @@ public class Container extends Component { comp.parent = null; component.remove(index); + comp.setGraphicsConfiguration(null); invalidateIfValid(); if (containerListener != null || @@ -1227,6 +1244,7 @@ public class Container extends Component { layoutMgr.removeLayoutComponent(comp); } comp.parent = null; + comp.setGraphicsConfiguration(null); if (containerListener != null || (eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 || Toolkit.enabledOnToolkit(AWTEvent.CONTAINER_EVENT_MASK)) { diff --git a/jdk/src/share/classes/java/awt/Window.java b/jdk/src/share/classes/java/awt/Window.java index e1ff8db14c3..062870fe101 100644 --- a/jdk/src/share/classes/java/awt/Window.java +++ b/jdk/src/share/classes/java/awt/Window.java @@ -394,6 +394,18 @@ public class Window extends Container implements Accessible { } } + private GraphicsConfiguration initGC(GraphicsConfiguration gc) { + GraphicsEnvironment.checkHeadless(); + + if (gc == null) { + gc = GraphicsEnvironment.getLocalGraphicsEnvironment(). + getDefaultScreenDevice().getDefaultConfiguration(); + } + setGraphicsConfiguration(gc); + + return gc; + } + private void init(GraphicsConfiguration gc) { GraphicsEnvironment.checkHeadless(); @@ -405,14 +417,10 @@ public class Window extends Container implements Accessible { setWarningString(); this.cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); this.visible = false; - if (gc == null) { - this.graphicsConfig = - GraphicsEnvironment.getLocalGraphicsEnvironment(). - getDefaultScreenDevice().getDefaultConfiguration(); - } else { - this.graphicsConfig = gc; - } - if (graphicsConfig.getDevice().getType() != + + gc = initGC(gc); + + if (gc.getDevice().getType() != GraphicsDevice.TYPE_RASTER_SCREEN) { throw new IllegalArgumentException("not a screen device"); } @@ -420,8 +428,8 @@ public class Window extends Container implements Accessible { /* offset the initial location with the original of the screen */ /* and any insets */ - Rectangle screenBounds = graphicsConfig.getBounds(); - Insets screenInsets = getToolkit().getScreenInsets(graphicsConfig); + Rectangle screenBounds = gc.getBounds(); + Insets screenInsets = getToolkit().getScreenInsets(gc); int x = getX() + screenBounds.x + screenInsets.left; int y = getY() + screenBounds.y + screenInsets.top; if (x != this.x || y != this.y) { @@ -2765,7 +2773,7 @@ public class Window extends Container implements Accessible { sun.java2d.Disposer.addRecord(anchor, new WindowDisposerRecord(appContext, this)); addToWindowList(); - + initGC(null); } private void deserializeResources(ObjectInputStream s) @@ -2939,41 +2947,18 @@ public class Window extends Container implements Accessible { } // inner class AccessibleAWTWindow - /** - * This method returns the GraphicsConfiguration used by this Window. - * @since 1.3 - */ - public GraphicsConfiguration getGraphicsConfiguration() { - //NOTE: for multiscreen, this will need to take into account - //which screen the window is on/mostly on instead of returning the - //default or constructor argument config. - synchronized(getTreeLock()) { - if (graphicsConfig == null && !GraphicsEnvironment.isHeadless()) { - graphicsConfig = - GraphicsEnvironment. getLocalGraphicsEnvironment(). - getDefaultScreenDevice(). - getDefaultConfiguration(); - } - return graphicsConfig; - } - } - - /** - * Reset this Window's GraphicsConfiguration to match its peer. - */ - void resetGC() { - if (!GraphicsEnvironment.isHeadless()) { - // use the peer's GC - setGCFromPeer(); - // if it's still null, use the default - if (graphicsConfig == null) { - graphicsConfig = GraphicsEnvironment. + @Override + void setGraphicsConfiguration(GraphicsConfiguration gc) { + if (gc == null) { + gc = GraphicsEnvironment. getLocalGraphicsEnvironment(). getDefaultScreenDevice(). getDefaultConfiguration(); - } + } + synchronized (getTreeLock()) { + super.setGraphicsConfiguration(gc); if (log.isLoggable(Level.FINER)) { - log.finer("+ Window.resetGC(): new GC is \n+ " + graphicsConfig + "\n+ this is " + this); + log.finer("+ Window.setGraphicsConfiguration(): new GC is \n+ " + getGraphicsConfiguration_NoClientCode() + "\n+ this is " + this); } } } @@ -3033,7 +3018,7 @@ public class Window extends Container implements Accessible { // target location int dx = 0, dy = 0; // target GC - GraphicsConfiguration gc = this.graphicsConfig; + GraphicsConfiguration gc = getGraphicsConfiguration_NoClientCode(); Rectangle gcBounds = gc.getBounds(); Dimension windowSize = getSize(); diff --git a/jdk/src/share/classes/java/awt/peer/CanvasPeer.java b/jdk/src/share/classes/java/awt/peer/CanvasPeer.java index bbf6a111086..94b8d189d8d 100644 --- a/jdk/src/share/classes/java/awt/peer/CanvasPeer.java +++ b/jdk/src/share/classes/java/awt/peer/CanvasPeer.java @@ -25,6 +25,7 @@ package java.awt.peer; import java.awt.Canvas; +import java.awt.GraphicsConfiguration; /** * The peer interface for {@link Canvas}. @@ -36,4 +37,13 @@ import java.awt.Canvas; * instances. */ public interface CanvasPeer extends ComponentPeer { + /** + * Requests a GC that best suits this Canvas. The returned GC may differ + * from the requested GC passed as the argument to this method. This method + * must return a non-null value (given the argument is non-null as well). + * + * @since 1.7 + */ + GraphicsConfiguration getAppropriateGraphicsConfiguration( + GraphicsConfiguration gc); } diff --git a/jdk/src/share/classes/java/awt/peer/ComponentPeer.java b/jdk/src/share/classes/java/awt/peer/ComponentPeer.java index e71ab27f7ac..3a2845f37fa 100644 --- a/jdk/src/share/classes/java/awt/peer/ComponentPeer.java +++ b/jdk/src/share/classes/java/awt/peer/ComponentPeer.java @@ -539,4 +539,10 @@ public interface ComponentPeer { */ void applyShape(Region shape); + /** + * Updates internal data structures related to the component's GC. + * + * @since 1.7 + */ + void updateGraphicsData(GraphicsConfiguration gc); } diff --git a/jdk/src/share/classes/sun/awt/AWTAccessor.java b/jdk/src/share/classes/sun/awt/AWTAccessor.java index 2145f0f10a4..767b4147778 100644 --- a/jdk/src/share/classes/sun/awt/AWTAccessor.java +++ b/jdk/src/share/classes/sun/awt/AWTAccessor.java @@ -78,6 +78,11 @@ public final class AWTAccessor { * See 6797587, 6776743, 6768307, and 6768332 for details */ void setMixingCutoutShape(Component comp, Shape shape); + + /** + * Sets GraphicsConfiguration value for the component. + */ + void setGraphicsConfiguration(Component comp, GraphicsConfiguration gc); } /* diff --git a/jdk/src/share/classes/sun/awt/ComponentAccessor.java b/jdk/src/share/classes/sun/awt/ComponentAccessor.java index af3abcf8a95..49a383815db 100644 --- a/jdk/src/share/classes/sun/awt/ComponentAccessor.java +++ b/jdk/src/share/classes/sun/awt/ComponentAccessor.java @@ -73,7 +73,6 @@ public class ComponentAccessor private static Field fieldPacked; private static Field fieldIgnoreRepaint; private static Field fieldPeer; - private static Method methodResetGC; private static Field fieldVisible; private static Method methodIsEnabledImpl; private static Method methodGetCursorNoClientCode; @@ -124,9 +123,6 @@ public class ComponentAccessor fieldPeer = componentClass.getDeclaredField("peer"); fieldPeer.setAccessible(true); - methodResetGC = componentClass.getDeclaredMethod("resetGC", (Class[]) null); - methodResetGC.setAccessible(true); - fieldVisible = componentClass.getDeclaredField("visible"); fieldVisible.setAccessible(true); @@ -425,18 +421,6 @@ public class ComponentAccessor return false; } - public static void resetGC(Component c) { - try { - methodResetGC.invoke(c, (Object[]) null); - } - catch (IllegalAccessException e) { - log.log(Level.FINE, "Unable to access the Component object", e); - } - catch (InvocationTargetException e) { - log.log(Level.FINE, "Unable to invoke on the Component object", e); - } - } - public static boolean getVisible(Component c) { try { return fieldVisible.getBoolean(c); diff --git a/jdk/src/share/classes/sun/awt/NullComponentPeer.java b/jdk/src/share/classes/sun/awt/NullComponentPeer.java index 8818c472877..2feea7b518c 100644 --- a/jdk/src/share/classes/sun/awt/NullComponentPeer.java +++ b/jdk/src/share/classes/sun/awt/NullComponentPeer.java @@ -305,4 +305,12 @@ public class NullComponentPeer implements LightweightPeer, */ public void applyShape(Region shape) { } + + public void updateGraphicsData(GraphicsConfiguration gc) {} + + public GraphicsConfiguration getAppropriateGraphicsConfiguration( + GraphicsConfiguration gc) + { + return gc; + } } diff --git a/jdk/src/solaris/classes/sun/awt/X11/XCanvasPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XCanvasPeer.java index 4c38c88b9fc..8fc6f1f7d28 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XCanvasPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XCanvasPeer.java @@ -27,7 +27,6 @@ package sun.awt.X11; import java.awt.*; import java.awt.peer.*; -import sun.awt.ComponentAccessor; import sun.awt.SunToolkit; import sun.awt.X11GraphicsConfig; @@ -54,60 +53,45 @@ class XCanvasPeer extends XComponentPeer implements CanvasPeer { } } - void resetTargetGC(Component target) { - ComponentAccessor.resetGC(target); - } - - /* - * Called when the Window this - * Canvas is on is moved onto another Xinerama screen. - * - * Canvases can be created with a non-defulat GraphicsConfiguration. The - * GraphicsConfiguration needs to be changed to one on the new screen, - * preferably with the same visual ID. - * - * Up-called for other windows peer instances (XPanelPeer, XWindowPeer). - * - * Should only be called from the event thread. - */ - public void displayChanged(int screenNum) { - resetLocalGC(screenNum); - resetTargetGC(target); - } - - /* Set graphicsConfig to a GraphicsConfig with the same visual on the new + /* Get a GraphicsConfig with the same visual on the new * screen, which should be easy in Xinerama mode. - * - * Should only be called from displayChanged(), and therefore only from - * the event thread. */ - void resetLocalGC(int screenNum) { + public GraphicsConfiguration getAppropriateGraphicsConfiguration( + GraphicsConfiguration gc) + { + if (graphicsConfig == null || gc == null) { + return gc; + } // Opt: Only need to do if we're not using the default GC - if (graphicsConfig != null) { - X11GraphicsConfig parentgc; - // save vis id of current gc - int visual = graphicsConfig.getVisual(); - X11GraphicsDevice newDev = (X11GraphicsDevice) GraphicsEnvironment. - getLocalGraphicsEnvironment(). - getScreenDevices()[screenNum]; + int screenNum = ((X11GraphicsDevice)gc.getDevice()).getScreen(); - for (int i = 0; i < newDev.getNumConfigs(screenNum); i++) { - if (visual == newDev.getConfigVisualId(i, screenNum)) { - // use that - graphicsConfig = (X11GraphicsConfig)newDev.getConfigurations()[i]; - break; - } - } - // just in case... - if (graphicsConfig == null) { - graphicsConfig = (X11GraphicsConfig) GraphicsEnvironment. - getLocalGraphicsEnvironment(). - getScreenDevices()[screenNum]. - getDefaultConfiguration(); + X11GraphicsConfig parentgc; + // save vis id of current gc + int visual = graphicsConfig.getVisual(); + + X11GraphicsDevice newDev = (X11GraphicsDevice) GraphicsEnvironment. + getLocalGraphicsEnvironment(). + getScreenDevices()[screenNum]; + + for (int i = 0; i < newDev.getNumConfigs(screenNum); i++) { + if (visual == newDev.getConfigVisualId(i, screenNum)) { + // use that + graphicsConfig = (X11GraphicsConfig)newDev.getConfigurations()[i]; + break; } } + // just in case... + if (graphicsConfig == null) { + graphicsConfig = (X11GraphicsConfig) GraphicsEnvironment. + getLocalGraphicsEnvironment(). + getScreenDevices()[screenNum]. + getDefaultConfiguration(); + } + + return graphicsConfig; } + protected boolean shouldFocusOnClick() { // Canvas should always be able to be focused by mouse clicks. return true; diff --git a/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java index 46c4a8768f0..4c83ac750c8 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XComponentPeer.java @@ -35,6 +35,7 @@ import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; +import java.awt.GraphicsConfiguration; import java.awt.Image; import java.awt.Insets; import java.awt.KeyboardFocusManager; @@ -1556,4 +1557,8 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget } } } + + public void updateGraphicsData(GraphicsConfiguration gc) { + initGraphicsConfiguration(); + } } diff --git a/jdk/src/solaris/classes/sun/awt/X11/XEmbedChildProxyPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XEmbedChildProxyPeer.java index e4500043ae1..eae300aee08 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XEmbedChildProxyPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XEmbedChildProxyPeer.java @@ -379,4 +379,6 @@ public class XEmbedChildProxyPeer implements ComponentPeer, XEventDispatcher{ public void applyShape(Region shape) { } + + public void updateGraphicsData(GraphicsConfiguration gc) {} } diff --git a/jdk/src/solaris/classes/sun/awt/X11/XPanelPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XPanelPeer.java index aac632569ad..c070fcf3ad8 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XPanelPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XPanelPeer.java @@ -130,39 +130,6 @@ public class XPanelPeer extends XCanvasPeer implements PanelPeer { return getInsets(); } - /* - * This method is called from XWindowPeer.displayChanged, when - * the window this Panel is on is moved to the new screen, or - * display mode is changed. - * - * The notification is propagated to the child Canvas components. - * Top-level windows and other Panels are notified too as their - * peers are subclasses of XCanvasPeer. - */ - public void displayChanged(int screenNum) { - super.displayChanged(screenNum); - displayChanged((Container)target, screenNum); - } - - /* - * Recursively iterates through all the HW and LW children - * of the container and calls displayChanged() for HW peers. - * Iteration through children peers only is not enough as the - * displayChanged notification may not be propagated to HW - * components inside LW containers, see 4452373 for details. - */ - private static void displayChanged(Container target, int screenNum) { - Component children[] = ((Container)target).getComponents(); - for (Component child : children) { - ComponentPeer cpeer = child.getPeer(); - if (cpeer instanceof XCanvasPeer) { - ((XCanvasPeer)cpeer).displayChanged(screenNum); - } else if (child instanceof Container) { - displayChanged((Container)child, screenNum); - } - } - } - public void dispose() { if (embedder != null) { embedder.deinstall(); diff --git a/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java b/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java index 619ff8a9c9b..4f9fa56fd8f 100644 --- a/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java +++ b/jdk/src/solaris/classes/sun/awt/X11/XWindowPeer.java @@ -47,6 +47,7 @@ import java.util.logging.Logger; import sun.awt.AWTAccessor; import sun.awt.ComponentAccessor; import sun.awt.WindowAccessor; +import sun.awt.AWTAccessor; import sun.awt.DisplayChangedListener; import sun.awt.SunToolkit; import sun.awt.X11GraphicsDevice; @@ -711,6 +712,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer, int curScreenNum = ((X11GraphicsDevice)getGraphicsConfiguration().getDevice()).getScreen(); int newScreenNum = 0; GraphicsDevice gds[] = XToolkit.localEnv.getScreenDevices(); + GraphicsConfiguration newGC = null; Rectangle screenBounds; for (int i = 0; i < gds.length; i++) { @@ -726,11 +728,13 @@ class XWindowPeer extends XPanelPeer implements WindowPeer, if (intAmt == area) { // Completely on this screen - done! newScreenNum = i; + newGC = gds[i].getDefaultConfiguration(); break; } if (intAmt > largestAmt) { largestAmt = intAmt; newScreenNum = i; + newGC = gds[i].getDefaultConfiguration(); } } } @@ -738,28 +742,20 @@ class XWindowPeer extends XPanelPeer implements WindowPeer, if (log.isLoggable(Level.FINEST)) { log.finest("XWindowPeer: Moved to a new screen"); } - draggedToNewScreen(newScreenNum); + executeDisplayChangedOnEDT(newGC); } } - /* Xinerama - * called to update our GC when dragged onto another screen - */ - public void draggedToNewScreen(int screenNum) { - executeDisplayChangedOnEDT(screenNum); - } - /** * Helper method that executes the displayChanged(screen) method on * the event dispatch thread. This method is used in the Xinerama case * and after display mode change events. */ - private void executeDisplayChangedOnEDT(final int screenNum) { + private void executeDisplayChangedOnEDT(final GraphicsConfiguration gc) { Runnable dc = new Runnable() { public void run() { - // Updates this window's GC and notifies all the children. - // See XPanelPeer/XCanvasPeer.displayChanged(int) for details. - displayChanged(screenNum); + AWTAccessor.getComponentAccessor(). + setGraphicsConfiguration((Component)target, gc); } }; SunToolkit.executeOnEventHandlerThread((Component)target, dc); @@ -770,9 +766,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer, * X11GraphicsDevice when the display mode has been changed. */ public void displayChanged() { - GraphicsConfiguration gc = getGraphicsConfiguration(); - int curScreenNum = ((X11GraphicsDevice)gc.getDevice()).getScreen(); - executeDisplayChangedOnEDT(curScreenNum); + executeDisplayChangedOnEDT(getGraphicsConfiguration()); } /** diff --git a/jdk/src/solaris/native/sun/awt/awt_Component.h b/jdk/src/solaris/native/sun/awt/awt_Component.h index 8ee7fe82f45..d6ee776be01 100644 --- a/jdk/src/solaris/native/sun/awt/awt_Component.h +++ b/jdk/src/solaris/native/sun/awt/awt_Component.h @@ -41,7 +41,6 @@ struct ComponentIDs { jfieldID appContext; jmethodID getParent; jmethodID getLocationOnScreen; - jmethodID resetGCMID; }; /* field and method IDs for Container */ @@ -65,7 +64,3 @@ struct MComponentPeerIDs { extern void processTree(Widget from, Widget to, Boolean action); #endif // HEADLESS -/* fieldIDs for Canvas fields that may be accessed from C */ -struct CanvasIDs { - jmethodID setGCFromPeerMID; -}; diff --git a/jdk/src/solaris/native/sun/awt/awt_Window.h b/jdk/src/solaris/native/sun/awt/awt_Window.h index 875f55b2fa1..a93e4ad34d1 100644 --- a/jdk/src/solaris/native/sun/awt/awt_Window.h +++ b/jdk/src/solaris/native/sun/awt/awt_Window.h @@ -28,7 +28,6 @@ /* fieldIDs for Window fields that may be accessed from C */ struct WindowIDs { jfieldID warningString; - jmethodID resetGCMID; jfieldID locationByPlatform; jfieldID isAutoRequestFocus; }; diff --git a/jdk/src/solaris/native/sun/xawt/XToolkit.c b/jdk/src/solaris/native/sun/xawt/XToolkit.c index ac3fecc0c76..3b9669cb92b 100644 --- a/jdk/src/solaris/native/sun/xawt/XToolkit.c +++ b/jdk/src/solaris/native/sun/xawt/XToolkit.c @@ -182,9 +182,6 @@ Java_java_awt_Component_initIDs (*env)->GetMethodID(env, cls, "getLocationOnScreen_NoTreeLock", "()Ljava/awt/Point;"); - componentIDs.resetGCMID = - (*env)->GetMethodID(env, cls, "resetGC", "()V"); - keyclass = (*env)->FindClass(env, "java/awt/event/KeyEvent"); DASSERT (keyclass != NULL); @@ -197,9 +194,6 @@ Java_java_awt_Component_initIDs "Lsun/awt/AppContext;"); (*env)->DeleteLocalRef(env, keyclass); - - DASSERT(componentIDs.resetGCMID); - } diff --git a/jdk/src/windows/classes/sun/awt/Win32GraphicsDevice.java b/jdk/src/windows/classes/sun/awt/Win32GraphicsDevice.java index ba4769813d8..1da339ce9f1 100644 --- a/jdk/src/windows/classes/sun/awt/Win32GraphicsDevice.java +++ b/jdk/src/windows/classes/sun/awt/Win32GraphicsDevice.java @@ -380,7 +380,6 @@ public class Win32GraphicsDevice extends GraphicsDevice implements // fix for 4868278 peer.updateGC(); - peer.resetTargetGC(); } } diff --git a/jdk/src/windows/classes/sun/awt/windows/WCanvasPeer.java b/jdk/src/windows/classes/sun/awt/windows/WCanvasPeer.java index e1657102900..b97a3787b64 100644 --- a/jdk/src/windows/classes/sun/awt/windows/WCanvasPeer.java +++ b/jdk/src/windows/classes/sun/awt/windows/WCanvasPeer.java @@ -38,44 +38,12 @@ class WCanvasPeer extends WComponentPeer implements CanvasPeer { private boolean eraseBackground; - Method resetGCMethod; - // Toolkit & peer internals WCanvasPeer(Component target) { super(target); } - /* - * From the DisplayChangedListener interface. - * - * Overrides WComponentPeer version because Canvases can be created with - * a non-defulat GraphicsConfiguration, which is no longer valid. - * Up-called for other windows peer instances (WPanelPeer, WWindowPeer). - */ - public void displayChanged() { - clearLocalGC(); - resetTargetGC(); - super.displayChanged(); - } - - /* - * Reset the graphicsConfiguration member of our target Component. - * Component.resetGC() is a package-private method, so we have to call it - * through reflection. - */ - public void resetTargetGC() { - ComponentAccessor.resetGC((Component)target); - } - - /* - * Clears the peer's winGraphicsConfig member. - * Overridden by WWindowPeer, which shouldn't have a null winGraphicsConfig. - */ - void clearLocalGC() { - winGraphicsConfig = null; - } - native void create(WComponentPeer parent); void initialize() { @@ -152,4 +120,10 @@ class WCanvasPeer extends WComponentPeer implements CanvasPeer { */ private native void setNativeBackgroundErase(boolean doErase, boolean doEraseOnResize); + + public GraphicsConfiguration getAppropriateGraphicsConfiguration( + GraphicsConfiguration gc) + { + return gc; + } } diff --git a/jdk/src/windows/classes/sun/awt/windows/WComponentPeer.java b/jdk/src/windows/classes/sun/awt/windows/WComponentPeer.java index 3a414d1c328..56eb45fa3f5 100644 --- a/jdk/src/windows/classes/sun/awt/windows/WComponentPeer.java +++ b/jdk/src/windows/classes/sun/awt/windows/WComponentPeer.java @@ -59,7 +59,7 @@ import java.util.logging.*; public abstract class WComponentPeer extends WObjectPeer - implements ComponentPeer, DropTargetPeer, DisplayChangedListener + implements ComponentPeer, DropTargetPeer { /** * Handle to native window @@ -452,15 +452,8 @@ public abstract class WComponentPeer extends WObjectPeer } } - /** - * From the DisplayChangedListener interface. - * - * Called after a change in the display mode. This event - * triggers replacing the surfaceData object (since that object - * reflects the current display depth information, which has - * just changed). - */ - public void displayChanged() { + public void updateGraphicsData(GraphicsConfiguration gc) { + winGraphicsConfig = (Win32GraphicsConfig)gc; try { replaceSurfaceData(); } catch (InvalidPipeException e) { @@ -468,13 +461,6 @@ public abstract class WComponentPeer extends WObjectPeer } } - /** - * Part of the DisplayChangedListener interface: components - * do not need to react to this event - */ - public void paletteChanged() { - } - //This will return null for Components not yet added to a Container public ColorModel getColorModel() { GraphicsConfiguration gc = getGraphicsConfiguration(); diff --git a/jdk/src/windows/classes/sun/awt/windows/WPanelPeer.java b/jdk/src/windows/classes/sun/awt/windows/WPanelPeer.java index 8a0d7ffbcc1..10ca423146c 100644 --- a/jdk/src/windows/classes/sun/awt/windows/WPanelPeer.java +++ b/jdk/src/windows/classes/sun/awt/windows/WPanelPeer.java @@ -100,34 +100,6 @@ class WPanelPeer extends WCanvasPeer implements PanelPeer { return getInsets(); } - /* - * From the DisplayChangedListener interface. Often is - * up-called from a WWindowPeer instance. - */ - public void displayChanged() { - super.displayChanged(); - displayChanged((Container)target); - } - - /* - * Recursively iterates through all the HW and LW children - * of the container and calls displayChanged() for HW peers. - * Iteration through children peers only is not enough as the - * displayChanged notification may not be propagated to HW - * components inside LW containers, see 4452373 for details. - */ - private static void displayChanged(Container target) { - Component children[] = ((Container)target).getComponents(); - for (Component child : children) { - ComponentPeer cpeer = child.getPeer(); - if (cpeer instanceof WComponentPeer) { - ((WComponentPeer)cpeer).displayChanged(); - } else if (child instanceof Container) { - displayChanged((Container)child); - } - } - } - private native void pRestack(Object[] peers); private void restack(Container cont, Vector peers) { for (int i = 0; i < cont.getComponentCount(); i++) { diff --git a/jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java b/jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java index 79818431063..73f9e3f811f 100644 --- a/jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java +++ b/jdk/src/windows/classes/sun/awt/windows/WWindowPeer.java @@ -41,7 +41,9 @@ import sun.awt.*; import sun.java2d.pipe.Region; -public class WWindowPeer extends WPanelPeer implements WindowPeer { +public class WWindowPeer extends WPanelPeer implements WindowPeer, + DisplayChangedListener +{ private static final Logger log = Logger.getLogger("sun.awt.windows.WWindowPeer"); private static final Logger screenLog = Logger.getLogger("sun.awt.windows.screen.WWindowPeer"); @@ -198,7 +200,6 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer { // super.displayChanged() in WWindowPeer.displayChanged() regardless of whether // GraphicsDevice was really changed, or not. So we need to track it here. updateGC(); - resetTargetGC(); realShow(); updateMinimumSize(); @@ -400,14 +401,6 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer { }); } - - /* - * Called from WCanvasPeer.displayChanged(). - * Override to do nothing - Window and WWindowPeer GC must never be set to - * null! - */ - void clearLocalGC() {} - public void updateGC() { int scrn = getScreenImOn(); if (screenLog.isLoggable(Level.FINER)) { @@ -446,18 +439,36 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer { oldDev.removeDisplayChangedListener(this); newDev.addDisplayChangedListener(this); } + + SunToolkit.executeOnEventHandlerThread((Component)target, + new Runnable() { + public void run() { + AWTAccessor.getComponentAccessor(). + setGraphicsConfiguration((Component)target, winGraphicsConfig); + } + }); } - /* - * From the DisplayChangedListener interface + /** + * From the DisplayChangedListener interface. * * This method handles a display change - either when the display settings * are changed, or when the window has been dragged onto a different * display. + * Called after a change in the display mode. This event + * triggers replacing the surfaceData object (since that object + * reflects the current display depth information, which has + * just changed). */ public void displayChanged() { updateGC(); - super.displayChanged(); + } + + /** + * Part of the DisplayChangedListener interface: components + * do not need to react to this event + */ + public void paletteChanged() { } private native int getScreenImOn();