src/share/classes/sun/swing/JLightweightFrame.java

Print this page

        

*** 52,61 **** --- 52,62 ---- import javax.swing.LayoutFocusTraversalPolicy; import javax.swing.RepaintManager; import javax.swing.RootPaneContainer; import javax.swing.SwingUtilities; + import sun.awt.DisplayChangedListener; import sun.awt.LightweightFrame; import sun.security.action.GetPropertyAction; import sun.swing.SwingUtilities2.RepaintListener; /**
*** 78,98 **** private Component component; private JPanel contentPane; 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; private PropertyChangeListener layoutSizeListener; private RepaintListener repaintListener; --- 79,101 ---- private Component component; private JPanel contentPane; private BufferedImage bbImage; + private volatile int scaleFactor = 1; + /** * {@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 static boolean copyBufferEnabled; private int[] copyBuffer; private PropertyChangeListener layoutSizeListener; private RepaintListener repaintListener;
*** 101,110 **** --- 104,115 ---- @Override public void updateCursor(JLightweightFrame frame) { frame.updateClientCursor(); } }); + copyBufferEnabled = "true".equals(AccessController. + doPrivileged(new GetPropertyAction("swing.jlf.copyBufferEnabled", "true"))); } /** * Constructs a new, initially invisible {@code JLightweightFrame} * instance.
*** 142,152 **** if (jlf != JLightweightFrame.this) { return; } Point p = SwingUtilities.convertPoint(c, x, y, jlf); Rectangle r = new Rectangle(p.x, p.y, w, h).intersection( ! new Rectangle(0, 0, bbImage.getWidth(), bbImage.getHeight())); if (!r.isEmpty()) { notifyImageUpdated(r.x, r.y, r.width, r.height); } }; --- 147,158 ---- if (jlf != JLightweightFrame.this) { return; } Point p = SwingUtilities.convertPoint(c, x, y, jlf); Rectangle r = new Rectangle(p.x, p.y, w, h).intersection( ! new Rectangle(0, 0, bbImage.getWidth() / scaleFactor, ! bbImage.getHeight() / scaleFactor)); if (!r.isEmpty()) { notifyImageUpdated(r.x, r.y, r.width, r.height); } };
*** 196,205 **** --- 202,212 ---- Graphics2D g = bbImage.createGraphics(); g.setBackground(getBackground()); g.setColor(getForeground()); g.setFont(getFont()); + g.scale(scaleFactor, scaleFactor); return g; } /** * {@inheritDoc}
*** 219,237 **** @Override public void ungrabFocus() { 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<h; i++) { int from = (y + i) * linestride + x; System.arraycopy(srcBuffer, from, copyBuffer, from, w); } } finally { --- 226,281 ---- @Override public void ungrabFocus() { if (content != null) content.focusUngrabbed(); } ! @Override ! public int getScaleFactor() { ! return scaleFactor; ! } ! ! @Override ! public void notifyDisplayChanged(final int scaleFactor) { ! if (scaleFactor != this.scaleFactor) { ! if (!copyBufferEnabled) content.paintLock(); ! try { ! if (bbImage != null) { ! resizeBuffer(getWidth(), getHeight(), scaleFactor); ! } ! } finally { ! if (!copyBufferEnabled) content.paintUnlock(); ! } ! this.scaleFactor = scaleFactor; ! } ! if (getPeer() instanceof DisplayChangedListener) { ! ((DisplayChangedListener)getPeer()).displayChanged(); ! } ! repaint(); ! } ! ! @Override ! public void addNotify() { ! super.addNotify(); ! if (getPeer() instanceof DisplayChangedListener) { ! ((DisplayChangedListener)getPeer()).displayChanged(); ! } ! } ! ! private void syncCopyBuffer(boolean reset, int x, int y, int w, int h, int scale) { content.paintLock(); try { int[] srcBuffer = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData(); if (reset) { copyBuffer = new int[srcBuffer.length]; } int linestride = bbImage.getWidth(); + x *= scale; + y *= scale; + w *= scale; + h *= scale; + for (int i=0; i<h; i++) { int from = (y + i) * linestride + x; System.arraycopy(srcBuffer, from, copyBuffer, from, w); } } finally {
*** 239,249 **** } } private void notifyImageUpdated(int x, int y, int width, int height) { if (copyBufferEnabled) { ! syncCopyBuffer(false, x, y, width, height); } content.imageUpdated(x, y, width, height); } @SuppressWarnings("serial") // anonymous class inside --- 283,293 ---- } } private void notifyImageUpdated(int x, int y, int width, int height) { if (copyBufferEnabled) { ! syncCopyBuffer(false, x, y, width, height, scaleFactor); } content.imageUpdated(x, y, width, height); } @SuppressWarnings("serial") // anonymous class inside
*** 267,277 **** clip.height = Math.min(contentPane.getHeight(), clip.height); EventQueue.invokeLater(new Runnable() { @Override public void run() { ! notifyImageUpdated(clip.x, clip.y, clip.width, clip.height); } }); } finally { if (!copyBufferEnabled) { content.paintUnlock(); --- 311,322 ---- clip.height = Math.min(contentPane.getHeight(), clip.height); EventQueue.invokeLater(new Runnable() { @Override public void run() { ! Rectangle c = contentPane.getBounds().intersection(clip); ! notifyImageUpdated(c.x, c.y, c.width, c.height); } }); } finally { if (!copyBufferEnabled) { content.paintUnlock();
*** 321,337 **** } if (!copyBufferEnabled) { content.paintLock(); } try { ! if ((bbImage == null) || (width != bbImage.getWidth()) || (height != bbImage.getHeight())) { ! boolean createBB = true; int newW = width; int newH = height; if (bbImage != null) { ! int oldW = bbImage.getWidth(); ! int oldH = bbImage.getHeight(); if ((oldW >= newW) && (oldH >= newH)) { createBB = false; } else { if (oldW >= newW) { newW = oldW; --- 366,386 ---- } if (!copyBufferEnabled) { content.paintLock(); } try { ! boolean createBB = (bbImage == null); int newW = width; int newH = height; if (bbImage != null) { ! int imgWidth = bbImage.getWidth() / scaleFactor; ! int imgHeight = bbImage.getHeight() / scaleFactor; ! if (width != imgWidth || height != imgHeight) { ! createBB = true; ! if (bbImage != null) { ! int oldW = imgWidth; ! int oldH = imgHeight; if ((oldW >= newW) && (oldH >= newH)) { createBB = false; } else { if (oldW >= newW) { newW = oldW;
*** 343,382 **** } else { newH = Math.max((int)(oldH * 1.2), height); } } } - if (createBB) { - BufferedImage oldBB = bbImage; - bbImage = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_ARGB_PRE); - if (oldBB != null) { - Graphics g = bbImage.getGraphics(); - try { - g.drawImage(oldBB, 0, 0, newW, newH, null); - } finally { - g.dispose(); - oldBB.flush(); } } ! int[] pixels = ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData(); ! if (copyBufferEnabled) { ! syncCopyBuffer(true, 0, 0, width, height); ! pixels = copyBuffer; ! } ! content.imageBufferReset(pixels, 0, 0, width, height, bbImage.getWidth()); return; } - } content.imageReshaped(0, 0, width, height); } finally { if (!copyBufferEnabled) { content.paintUnlock(); } } } @Override public JRootPane getRootPane() { return rootPane; } --- 392,428 ---- } else { newH = Math.max((int)(oldH * 1.2), height); } } } } } ! if (createBB) { ! resizeBuffer(newW, newH, scaleFactor); return; } content.imageReshaped(0, 0, width, height); } finally { if (!copyBufferEnabled) { content.paintUnlock(); } } } + private void resizeBuffer(int width, int height, int newScaleFactor) { + bbImage = new BufferedImage(width*newScaleFactor,height*newScaleFactor, + BufferedImage.TYPE_INT_ARGB_PRE); + int[] pixels= ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData(); + if (copyBufferEnabled) { + syncCopyBuffer(true, 0, 0, width, height, newScaleFactor); + pixels = copyBuffer; + } + content.imageBufferReset(pixels, 0, 0, width, height, + width * newScaleFactor, newScaleFactor); + } + @Override public JRootPane getRootPane() { return rootPane; }