提交 00ac0d0c 编写于 作者: A anthony

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
上级 0e2b7c8f
...@@ -1038,15 +1038,25 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -1038,15 +1038,25 @@ public abstract class Component implements ImageObserver, MenuContainer,
void setGraphicsConfiguration(GraphicsConfiguration gc) { void setGraphicsConfiguration(GraphicsConfiguration gc) {
synchronized(getTreeLock()) { synchronized(getTreeLock()) {
graphicsConfig = gc; if (updateGraphicsData(gc)) {
removeNotify();
ComponentPeer peer = getPeer(); addNotify();
if (peer != null) {
peer.updateGraphicsData(gc);
} }
} }
} }
boolean updateGraphicsData(GraphicsConfiguration gc) {
checkTreeLock();
graphicsConfig = gc;
ComponentPeer peer = getPeer();
if (peer != null) {
return peer.updateGraphicsData(gc);
}
return false;
}
/** /**
* Checks that this component's <code>GraphicsDevice</code> * Checks that this component's <code>GraphicsDevice</code>
* <code>idString</code> matches the string argument. * <code>idString</code> matches the string argument.
......
...@@ -1113,16 +1113,17 @@ public class Container extends Component { ...@@ -1113,16 +1113,17 @@ public class Container extends Component {
} }
@Override @Override
void setGraphicsConfiguration(GraphicsConfiguration gc) { boolean updateGraphicsData(GraphicsConfiguration gc) {
synchronized (getTreeLock()) { checkTreeLock();
super.setGraphicsConfiguration(gc);
for (Component comp : component) { boolean ret = super.updateGraphicsData(gc);
if (comp != null) {
comp.setGraphicsConfiguration(gc); for (Component comp : component) {
} if (comp != null) {
ret |= comp.updateGraphicsData(gc);
} }
} }
return ret;
} }
/** /**
......
...@@ -548,7 +548,8 @@ public interface ComponentPeer { ...@@ -548,7 +548,8 @@ public interface ComponentPeer {
/** /**
* Updates internal data structures related to the component's GC. * 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 * @since 1.7
*/ */
void updateGraphicsData(GraphicsConfiguration gc); boolean updateGraphicsData(GraphicsConfiguration gc);
} }
...@@ -300,7 +300,9 @@ public class NullComponentPeer implements LightweightPeer, ...@@ -300,7 +300,9 @@ public class NullComponentPeer implements LightweightPeer,
public void setZOrder(ComponentPeer above) { public void setZOrder(ComponentPeer above) {
} }
public void updateGraphicsData(GraphicsConfiguration gc) {} public boolean updateGraphicsData(GraphicsConfiguration gc) {
return false;
}
public GraphicsConfiguration getAppropriateGraphicsConfiguration( public GraphicsConfiguration getAppropriateGraphicsConfiguration(
GraphicsConfiguration gc) GraphicsConfiguration gc)
......
...@@ -1429,7 +1429,26 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget ...@@ -1429,7 +1429,26 @@ public class XComponentPeer extends XWindow implements ComponentPeer, DropTarget
} }
} }
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(); initGraphicsConfiguration();
doValidateSurface();
return false;
} }
} }
...@@ -386,5 +386,7 @@ public class XEmbedChildProxyPeer implements ComponentPeer, XEventDispatcher{ ...@@ -386,5 +386,7 @@ public class XEmbedChildProxyPeer implements ComponentPeer, XEventDispatcher{
public void setZOrder(ComponentPeer above) { public void setZOrder(ComponentPeer above) {
} }
public void updateGraphicsData(GraphicsConfiguration gc) {} public boolean updateGraphicsData(GraphicsConfiguration gc) {
return false;
}
} }
...@@ -1343,18 +1343,23 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer { ...@@ -1343,18 +1343,23 @@ public class XWindow extends XBaseWindow implements X11ComponentPeer {
setSizeHints(flags, x, y, width, height); setSizeHints(flags, x, y, width, height);
} }
void validateSurface() { void validateSurface() {
if ((width != oldWidth) || (height != oldHeight)) { if ((width != oldWidth) || (height != oldHeight)) {
SurfaceData oldData = surfaceData; doValidateSurface();
if (oldData != null) {
surfaceData = graphicsConfig.createSurfaceData(this);
oldData.invalidate();
}
oldWidth = width; oldWidth = width;
oldHeight = height; oldHeight = height;
} }
} }
final void doValidateSurface() {
SurfaceData oldData = surfaceData;
if (oldData != null) {
surfaceData = graphicsConfig.createSurfaceData(this);
oldData.invalidate();
}
}
public SurfaceData getSurfaceData() { public SurfaceData getSurfaceData() {
return surfaceData; return surfaceData;
} }
......
...@@ -488,13 +488,14 @@ public abstract class WComponentPeer extends WObjectPeer ...@@ -488,13 +488,14 @@ public abstract class WComponentPeer extends WObjectPeer
} }
} }
public void updateGraphicsData(GraphicsConfiguration gc) { public boolean updateGraphicsData(GraphicsConfiguration gc) {
winGraphicsConfig = (Win32GraphicsConfig)gc; winGraphicsConfig = (Win32GraphicsConfig)gc;
try { try {
replaceSurfaceData(); replaceSurfaceData();
} catch (InvalidPipeException e) { } catch (InvalidPipeException e) {
// REMIND : what do we do if our surface creation failed? // REMIND : what do we do if our surface creation failed?
} }
return false;
} }
//This will return null for Components not yet added to a Container //This will return null for Components not yet added to a Container
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册