< prev index next >
src/share/classes/javax/swing/RepaintManager.java
Print this page
rev 1527 : 6727662: Code improvement and warnings removing from swing packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: malenkov
rev 1555 : 6608456: need API to define RepaintManager per components hierarchy
Reviewed-by: alexp
rev 1556 : 6794764: Translucent windows are completely repainted on every paint event, on Windows
6719382: Printing of AWT components on windows is not working
6726866: Repainting artifacts when resizing or dragging JInternalFrames in non-opaque toplevel
6683775: Painting artifacts is seen when panel is made setOpaque(false) for a translucent window
Reviewed-by: anthony, tdv, alexp
*** 43,52 ****
--- 43,53 ----
import sun.java2d.SunGraphicsEnvironment;
import sun.misc.JavaSecurityAccess;
import sun.misc.SharedSecrets;
import sun.security.action.GetPropertyAction;
+ import com.sun.java.swing.SwingUtilities3;
/**
* This class manages repaint requests, allowing the number
* of repaints to be minimized, for example by collapsing multiple
* requests into a single repaint for members of a component tree.
*** 309,318 ****
--- 310,324 ----
* @see JComponent#isValidateRoot
* @see #removeInvalidComponent
*/
public synchronized void addInvalidComponent(JComponent invalidComponent)
{
+ RepaintManager delegate = getDelegate(invalidComponent);
+ if (delegate != null) {
+ delegate.addInvalidComponent(invalidComponent);
+ return;
+ }
Component validateRoot = null;
/* Find the first JComponent ancestor of this component whose
* isValidateRoot() method returns true.
*/
*** 379,388 ****
--- 385,399 ----
* Remove a component from the list of invalid components.
*
* @see #addInvalidComponent
*/
public synchronized void removeInvalidComponent(JComponent component) {
+ RepaintManager delegate = getDelegate(component);
+ if (delegate != null) {
+ delegate.removeInvalidComponent(component);
+ return;
+ }
if(invalidComponents != null) {
int index = invalidComponents.indexOf(component);
if(index != -1) {
invalidComponents.remove(index);
}
*** 470,479 ****
--- 481,495 ----
* @param h Height of the region to repaint
* @see JComponent#repaint
*/
public void addDirtyRegion(JComponent c, int x, int y, int w, int h)
{
+ RepaintManager delegate = getDelegate(c);
+ if (delegate != null) {
+ delegate.addDirtyRegion(c, x, y, w, h);
+ return;
+ }
addDirtyRegion0(c, x, y, w, h);
}
/**
* Adds <code>window</code> to the list of <code>Component</code>s that
*** 591,601 ****
*
* @return false if <code>c</code> is not yet marked dirty.
*/
private synchronized boolean extendDirtyRegion(
Component c, int x, int y, int w, int h) {
! Rectangle r = (Rectangle)dirtyComponents.get(c);
if (r != null) {
// A non-null r implies c is already marked as dirty,
// and that the parent is valid. Therefore we can
// just union the rect and bail.
SwingUtilities.computeUnion(x, y, w, h, r);
--- 607,617 ----
*
* @return false if <code>c</code> is not yet marked dirty.
*/
private synchronized boolean extendDirtyRegion(
Component c, int x, int y, int w, int h) {
! Rectangle r = dirtyComponents.get(c);
if (r != null) {
// A non-null r implies c is already marked as dirty,
// and that the parent is valid. Therefore we can
// just union the rect and bail.
SwingUtilities.computeUnion(x, y, w, h, r);
*** 607,619 ****
/** Return the current dirty region for a component.
* Return an empty rectangle if the component is not
* dirty.
*/
public Rectangle getDirtyRegion(JComponent aComponent) {
! Rectangle r = null;
synchronized(this) {
! r = (Rectangle)dirtyComponents.get(aComponent);
}
if(r == null)
return new Rectangle(0,0,0,0);
else
return new Rectangle(r);
--- 623,639 ----
/** Return the current dirty region for a component.
* Return an empty rectangle if the component is not
* dirty.
*/
public Rectangle getDirtyRegion(JComponent aComponent) {
! RepaintManager delegate = getDelegate(aComponent);
! if (delegate != null) {
! return delegate.getDirtyRegion(aComponent);
! }
! Rectangle r;
synchronized(this) {
! r = dirtyComponents.get(aComponent);
}
if(r == null)
return new Rectangle(0,0,0,0);
else
return new Rectangle(r);
*** 622,639 ****
--- 642,669 ----
/**
* Mark a component completely dirty. <b>aComponent</b> will be
* completely painted during the next paintDirtyRegions() call.
*/
public void markCompletelyDirty(JComponent aComponent) {
+ RepaintManager delegate = getDelegate(aComponent);
+ if (delegate != null) {
+ delegate.markCompletelyDirty(aComponent);
+ return;
+ }
addDirtyRegion(aComponent,0,0,Integer.MAX_VALUE,Integer.MAX_VALUE);
}
/**
* Mark a component completely clean. <b>aComponent</b> will not
* get painted during the next paintDirtyRegions() call.
*/
public void markCompletelyClean(JComponent aComponent) {
+ RepaintManager delegate = getDelegate(aComponent);
+ if (delegate != null) {
+ delegate.markCompletelyClean(aComponent);
+ return;
+ }
synchronized(this) {
dirtyComponents.remove(aComponent);
}
}
*** 642,651 ****
--- 672,685 ----
* painted during the next paintDirtyRegions(). If computing dirty regions is
* expensive for your component, use this method and avoid computing dirty region
* if it return true.
*/
public boolean isCompletelyDirty(JComponent aComponent) {
+ RepaintManager delegate = getDelegate(aComponent);
+ if (delegate != null) {
+ return delegate.isCompletelyDirty(aComponent);
+ }
Rectangle r;
r = getDirtyRegion(aComponent);
if(r.width == Integer.MAX_VALUE &&
r.height == Integer.MAX_VALUE)
*** 710,755 ****
// with toplevels.
paintDirtyRegions(dirtyComponents);
}
}
! private Map<Component,Rectangle>
! updateWindows(Map<Component,Rectangle> dirtyComponents)
! {
Toolkit toolkit = Toolkit.getDefaultToolkit();
if (!(toolkit instanceof SunToolkit &&
((SunToolkit)toolkit).needUpdateWindow()))
{
! return dirtyComponents;
}
Set<Window> windows = new HashSet<Window>();
Set<Component> dirtyComps = dirtyComponents.keySet();
for (Iterator<Component> it = dirtyComps.iterator(); it.hasNext();) {
Component dirty = it.next();
Window window = dirty instanceof Window ?
(Window)dirty :
SwingUtilities.getWindowAncestor(dirty);
-
if (window != null &&
!AWTAccessor.getWindowAccessor().isOpaque(window))
{
- // if this component's toplevel is perpixel translucent, it will
- // be repainted below
- it.remove();
- // add to the set of windows to update (so that we don't update
- // the window many times for each component to be repainted that
- // belongs to this window)
windows.add(window);
}
}
for (Window window : windows) {
! AWTAccessor.getWindowAccessor().updateWindow(window, null);
}
! return dirtyComponents;
}
/**
* Paint all of the components that have been marked dirty.
*
--- 744,782 ----
// with toplevels.
paintDirtyRegions(dirtyComponents);
}
}
! private void updateWindows(Map<Component,Rectangle> dirtyComponents) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
if (!(toolkit instanceof SunToolkit &&
((SunToolkit)toolkit).needUpdateWindow()))
{
! return;
}
Set<Window> windows = new HashSet<Window>();
Set<Component> dirtyComps = dirtyComponents.keySet();
for (Iterator<Component> it = dirtyComps.iterator(); it.hasNext();) {
Component dirty = it.next();
Window window = dirty instanceof Window ?
(Window)dirty :
SwingUtilities.getWindowAncestor(dirty);
if (window != null &&
!AWTAccessor.getWindowAccessor().isOpaque(window))
{
windows.add(window);
}
}
for (Window window : windows) {
! AWTAccessor.getWindowAccessor().updateWindow(window);
! }
}
! boolean isPainting() {
! return painting;
}
/**
* Paint all of the components that have been marked dirty.
*
*** 770,783 ****
{
if (tmpDirtyComponents.isEmpty()) {
return;
}
- // the components belonging to perpixel-translucent windows will be
- // removed from the list
- updateWindows(tmpDirtyComponents);
-
final java.util.List<Component> roots =
new ArrayList<Component>(tmpDirtyComponents.size());
for (Component dirty : tmpDirtyComponents.keySet()) {
collectDirtyComponents(tmpDirtyComponents, dirty, roots);
--- 797,806 ----
*** 840,849 ****
--- 863,875 ----
}, stack, acc);
}
} finally {
painting = false;
}
+
+ updateWindows(tmpDirtyComponents);
+
tmpDirtyComponents.clear();
}
/**
*** 888,898 ****
int w = dirtyComponent.getWidth();
int h = dirtyComponent.getHeight();
dx = rootDx = 0;
dy = rootDy = 0;
! tmp.setBounds((Rectangle) dirtyComponents.get(dirtyComponent));
// System.out.println("Collect dirty component for bound " + tmp +
// "component bounds is " + cBounds);;
SwingUtilities.computeIntersection(0,0,w,h,tmp);
--- 914,924 ----
int w = dirtyComponent.getWidth();
int h = dirtyComponent.getHeight();
dx = rootDx = 0;
dy = rootDy = 0;
! tmp.setBounds(dirtyComponents.get(dirtyComponent));
// System.out.println("Collect dirty component for bound " + tmp +
// "component bounds is " + cBounds);;
SwingUtilities.computeIntersection(0,0,w,h,tmp);
*** 935,945 ****
if (dirtyComponent != rootDirtyComponent) {
Rectangle r;
tmp.setLocation(tmp.x + rootDx - dx,
tmp.y + rootDy - dy);
! r = (Rectangle)dirtyComponents.get(rootDirtyComponent);
SwingUtilities.computeUnion(tmp.x,tmp.y,tmp.width,tmp.height,r);
}
// If we haven't seen this root before, then we need to add it to the
// list of root dirty Views.
--- 961,971 ----
if (dirtyComponent != rootDirtyComponent) {
Rectangle r;
tmp.setLocation(tmp.x + rootDx - dx,
tmp.y + rootDy - dy);
! r = dirtyComponents.get(rootDirtyComponent);
SwingUtilities.computeUnion(tmp.x,tmp.y,tmp.width,tmp.height,r);
}
// If we haven't seen this root before, then we need to add it to the
// list of root dirty Views.
*** 970,979 ****
--- 996,1009 ----
* The buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>
* This happens when the maximum double buffer size as been set for the receiving
* repaint manager.
*/
public Image getOffscreenBuffer(Component c,int proposedWidth,int proposedHeight) {
+ RepaintManager delegate = getDelegate(c);
+ if (delegate != null) {
+ return delegate.getOffscreenBuffer(c, proposedWidth, proposedHeight);
+ }
return _getOffscreenBuffer(c, proposedWidth, proposedHeight);
}
/**
* Return a volatile offscreen buffer that should be used as a
*** 987,996 ****
--- 1017,1041 ----
* @see java.awt.image.VolatileImage
* @since 1.4
*/
public Image getVolatileOffscreenBuffer(Component c,
int proposedWidth,int proposedHeight) {
+ RepaintManager delegate = getDelegate(c);
+ if (delegate != null) {
+ return delegate.getVolatileOffscreenBuffer(c, proposedWidth,
+ proposedHeight);
+ }
+
+ // If the window is non-opaque, it's double-buffered at peer's level
+ Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
+ if (!AWTAccessor.getWindowAccessor().isOpaque(w)) {
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
+ return null;
+ }
+ }
+
GraphicsConfiguration config = c.getGraphicsConfiguration();
if (config == null) {
config = GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration();
}
*** 1011,1023 ****
return image;
}
private Image _getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) {
Dimension maxSize = getDoubleBufferMaximumSize();
! DoubleBufferInfo doubleBuffer = null;
int width, height;
if (standardDoubleBuffer == null) {
standardDoubleBuffer = new DoubleBufferInfo();
}
doubleBuffer = standardDoubleBuffer;
--- 1056,1077 ----
return image;
}
private Image _getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) {
Dimension maxSize = getDoubleBufferMaximumSize();
! DoubleBufferInfo doubleBuffer;
int width, height;
+ // If the window is non-opaque, it's double-buffered at peer's level
+ Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
+ if (!AWTAccessor.getWindowAccessor().isOpaque(w)) {
+ Toolkit tk = Toolkit.getDefaultToolkit();
+ if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
+ return null;
+ }
+ }
+
if (standardDoubleBuffer == null) {
standardDoubleBuffer = new DoubleBufferInfo();
}
doubleBuffer = standardDoubleBuffer;
*** 1080,1090 ****
}
// Clear out the VolatileImages
Iterator gcs = volatileMap.keySet().iterator();
while (gcs.hasNext()) {
GraphicsConfiguration gc = (GraphicsConfiguration)gcs.next();
! VolatileImage image = (VolatileImage)volatileMap.get(gc);
if (image.getWidth() > width || image.getHeight() > height) {
image.flush();
gcs.remove();
}
}
--- 1134,1144 ----
}
// Clear out the VolatileImages
Iterator gcs = volatileMap.keySet().iterator();
while (gcs.hasNext()) {
GraphicsConfiguration gc = (GraphicsConfiguration)gcs.next();
! VolatileImage image = volatileMap.get(gc);
if (image.getWidth() > width || image.getHeight() > height) {
image.flush();
gcs.remove();
}
}
*** 1248,1258 ****
* }
* </pre>
*/
void beginPaint() {
boolean multiThreadedPaint = false;
! int paintDepth = 0;
Thread currentThread = Thread.currentThread();
synchronized(this) {
paintDepth = this.paintDepth;
if (paintThread == null || currentThread == paintThread) {
paintThread = currentThread;
--- 1302,1312 ----
* }
* </pre>
*/
void beginPaint() {
boolean multiThreadedPaint = false;
! int paintDepth;
Thread currentThread = Thread.currentThread();
synchronized(this) {
paintDepth = this.paintDepth;
if (paintThread == null || currentThread == paintThread) {
paintThread = currentThread;
*** 1620,1625 ****
--- 1674,1686 ----
// Do the actual validation and painting.
validateInvalidComponents();
prePaintDirtyRegions();
}
}
+ private RepaintManager getDelegate(Component c) {
+ RepaintManager delegate = SwingUtilities3.getDelegateRepaintManager(c);
+ if (this == delegate) {
+ delegate = null;
+ }
+ return delegate;
+ }
}
< prev index next >