提交 b47df9ef 编写于 作者: R rupashka

7072167: The "root" field in BufferStrategyPaintManager leaks memory

Reviewed-by: alexp
上级 5fadc98d
...@@ -24,20 +24,17 @@ ...@@ -24,20 +24,17 @@
*/ */
package javax.swing; package javax.swing;
import java.applet.Applet;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.image.*; import java.awt.image.*;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.util.*; import java.util.*;
import com.sun.java.swing.SwingUtilities3; import com.sun.java.swing.SwingUtilities3;
import sun.awt.SubRegionShowable; import sun.awt.SubRegionShowable;
import sun.java2d.SunGraphics2D; import sun.java2d.SunGraphics2D;
import sun.security.action.GetPropertyAction;
import sun.java2d.pipe.hw.ExtendedBufferCapabilities; import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
import sun.awt.SunToolkit; import sun.awt.SunToolkit;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
...@@ -119,10 +116,6 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager { ...@@ -119,10 +116,6 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
* Farthest JComponent ancestor for the current paint/copyArea. * Farthest JComponent ancestor for the current paint/copyArea.
*/ */
private JComponent rootJ; private JComponent rootJ;
/**
* Parent Applet/Window for the current paint/copyArea
*/
private Container root;
/** /**
* Location of component being painted relative to root. * Location of component being painted relative to root.
*/ */
...@@ -278,7 +271,9 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager { ...@@ -278,7 +271,9 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
public boolean paint(JComponent paintingComponent, public boolean paint(JComponent paintingComponent,
JComponent bufferComponent, Graphics g, JComponent bufferComponent, Graphics g,
int x, int y, int w, int h) { int x, int y, int w, int h) {
if (prepare(paintingComponent, true, x, y, w, h)) { Container root = fetchRoot(paintingComponent);
if (prepare(paintingComponent, root, true, x, y, w, h)) {
if ((g instanceof SunGraphics2D) && if ((g instanceof SunGraphics2D) &&
((SunGraphics2D)g).getDestination() == root) { ((SunGraphics2D)g).getDestination() == root) {
// BufferStrategy may have already constrained the Graphics. To // BufferStrategy may have already constrained the Graphics. To
...@@ -319,7 +314,9 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager { ...@@ -319,7 +314,9 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
// //
// If the buffer isn't in sync there is no point in doing a copyArea, // If the buffer isn't in sync there is no point in doing a copyArea,
// it has garbage. // it has garbage.
if (prepare(c, false, 0, 0, 0, 0) && bufferInfo.isInSync()) { Container root = fetchRoot(c);
if (prepare(c, root, false, 0, 0, 0, 0) && bufferInfo.isInSync()) {
if (clip) { if (clip) {
Rectangle cBounds = c.getVisibleRect(); Rectangle cBounds = c.getVisibleRect();
int relX = xOffset + x; int relX = xOffset + x;
...@@ -500,14 +497,14 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager { ...@@ -500,14 +497,14 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
* *
* @return true if should use buffering per window in painting. * @return true if should use buffering per window in painting.
*/ */
private boolean prepare(JComponent c, boolean isPaint, int x, int y, private boolean prepare(JComponent c, Container root, boolean isPaint, int x, int y,
int w, int h) { int w, int h) {
if (bsg != null) { if (bsg != null) {
bsg.dispose(); bsg.dispose();
bsg = null; bsg = null;
} }
bufferStrategy = null; bufferStrategy = null;
if (fetchRoot(c)) { if (root != null) {
boolean contentsLost = false; boolean contentsLost = false;
BufferInfo bufferInfo = getBufferInfo(root); BufferInfo bufferInfo = getBufferInfo(root);
if (bufferInfo == null) { if (bufferInfo == null) {
...@@ -567,10 +564,10 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager { ...@@ -567,10 +564,10 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
return false; return false;
} }
private boolean fetchRoot(JComponent c) { private Container fetchRoot(JComponent c) {
boolean encounteredHW = false; boolean encounteredHW = false;
rootJ = c; rootJ = c;
root = c; Container root = c;
xOffset = yOffset = 0; xOffset = yOffset = 0;
while (root != null && while (root != null &&
(!(root instanceof Window) && (!(root instanceof Window) &&
...@@ -597,7 +594,7 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager { ...@@ -597,7 +594,7 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
// heavyweights. If we didn't do this when we // heavyweights. If we didn't do this when we
// went to show the descendants of the nested hw // went to show the descendants of the nested hw
// you would see nothing, so, we bail out here. // you would see nothing, so, we bail out here.
return false; return null;
} }
} }
} }
...@@ -613,11 +610,11 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager { ...@@ -613,11 +610,11 @@ class BufferStrategyPaintManager extends RepaintManager.PaintManager {
// bit tricky with Swing. This gives a good approximation // bit tricky with Swing. This gives a good approximation
// of the various ways to turn on double buffering for // of the various ways to turn on double buffering for
// components. // components.
return true; return root;
} }
} }
// Don't do true double buffering. // Don't do true double buffering.
return false; return null;
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册