# HG changeset patch # User ant # Date 1368622174 -14400 # Node ID 62b97a10da72b4122a35ce99a256b819b9bdc924 # Parent 3e422b97a601fc7b902dbdd963f8d9c7d88bea49 8014227: JLightweightFrame needs another synchronization policy Reviewed-by: art diff -r 3e422b97a601 -r 62b97a10da72 jdk/src/share/classes/sun/swing/JLightweightFrame.java --- a/jdk/src/share/classes/sun/swing/JLightweightFrame.java Tue May 14 17:25:59 2013 +0400 +++ b/jdk/src/share/classes/sun/swing/JLightweightFrame.java Wed May 15 16:49:34 2013 +0400 @@ -35,6 +35,7 @@ import java.awt.Rectangle; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; +import java.security.AccessController; import javax.swing.JLayeredPane; import javax.swing.JPanel; @@ -43,6 +44,7 @@ import javax.swing.RootPaneContainer; import sun.awt.LightweightFrame; +import sun.security.action.GetPropertyAction; /** * The frame serves as a lightweight container which paints its content @@ -66,11 +68,27 @@ private BufferedImage bbImage; /** + * {@code copyBufferEnabled}, true by default, defines the following strategy. + * A duplicating (copy) buffer is created for the original pixel buffer. + * The copy buffer is synchronized with the original buffer every time the + * latter changes. {@code JLightweightFrame} passes the copy buffer array + * to the {@link LightweightContent#imageBufferReset} method. The code spot + * which synchronizes two buffers becomes the only critical section guarded + * by the lock (managed with the {@link LightweightContent#paintLock()}, + * {@link LightweightContent#paintUnlock()} methods). + */ + private boolean copyBufferEnabled; + private int[] copyBuffer; + + /** * Constructs a new, initially invisible {@code JLightweightFrame} * instance. */ public JLightweightFrame() { super(); + copyBufferEnabled = "true".equals(AccessController. + doPrivileged(new GetPropertyAction("jlf.copyBufferEnabled", "true"))); + add(rootPane, BorderLayout.CENTER); setFocusTraversalPolicy(new LayoutFocusTraversalPolicy()); if (getGraphicsConfiguration().isTranslucencyCapable()) { @@ -124,16 +142,37 @@ if (content != null) content.focusUngrabbed(); } + private void syncCopyBuffer(boolean reset, int x, int y, int w, int h) { + content.paintLock(); + try { + int[] srcBuffer = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData(); + if (reset) { + copyBuffer = new int[srcBuffer.length]; + } + int linestride = bbImage.getWidth(); + + for (int i=0; i