src/share/classes/javax/swing/RepaintManager.java
Print this page
@@ -45,10 +45,14 @@
import sun.security.action.GetPropertyAction;
import com.sun.java.swing.SwingUtilities3;
import sun.swing.SwingAccessor;
import sun.swing.SwingUtilities2.RepaintListener;
+import sun.awt.image.OffScreenImage;
+import sun.awt.image.SurfaceManager;
+import sun.java2d.SunGraphics2D;
+import sun.swing.JLightweightFrame;
/**
* 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.
@@ -1084,14 +1088,24 @@
}
width = Math.max(doubleBuffer.size.width, width);
height = Math.max(doubleBuffer.size.height, height);
}
+ Graphics g = c.getGraphics();
+ int scale = g instanceof SunGraphics2D ?
+ ((SunGraphics2D)g).surfaceData.getDefaultScale() : 1;
+
Image result = doubleBuffer.image;
- if (doubleBuffer.image == null) {
- result = c.createImage(width , height);
+ if (doubleBuffer.image == null ||
+ SurfaceManager.getImageScale(doubleBuffer.image) != scale)
+ {
+ if (w instanceof JLightweightFrame) {
+ result = ((JLightweightFrame)w).createHiDPIImage(width, height);
+ } else {
+ result = c.createImage(width, height);
+ }
doubleBuffer.size = new Dimension(width, height);
if (c instanceof JComponent) {
((JComponent)c).setCreatedDoubleBuffer(true);
doubleBuffer.image = result;
}
@@ -1550,12 +1564,18 @@
*/
protected void paintDoubleBuffered(JComponent c, Image image,
Graphics g, int clipX, int clipY,
int clipW, int clipH) {
Graphics osg = image.getGraphics();
- int bw = Math.min(clipW, image.getWidth(null));
- int bh = Math.min(clipH, image.getHeight(null));
+ int lw = image.getWidth(null);
+ int lh = image.getHeight(null);
+ if (image instanceof OffScreenImage) {
+ lw = ((OffScreenImage)image).getLayoutWidth();
+ lh = ((OffScreenImage)image).getLayoutHeight();
+ }
+ int bw = Math.min(clipW, lw);
+ int bh = Math.min(clipH, lh);
int x,y,maxx,maxy;
try {
for(x = clipX, maxx = clipX+clipW; x < maxx ; x += bw ) {
for(y=clipY, maxy = clipY + clipH; y < maxy ; y += bh) {
@@ -1574,14 +1594,14 @@
if (volatileBufferType != Transparency.OPAQUE
&& g instanceof Graphics2D) {
final Graphics2D g2d = (Graphics2D) g;
final Composite oldComposite = g2d.getComposite();
g2d.setComposite(AlphaComposite.Src);
- g2d.drawImage(image, x, y, c);
+ g2d.drawImage(image, x, y, lw, lh, c);
g2d.setComposite(oldComposite);
} else {
- g.drawImage(image, x, y, c);
+ g.drawImage(image, x, y, lw, lh, c);
}
osg.translate(x, y);
}
}
} finally {