--- old/src/java.desktop/share/classes/sun/swing/CachedPainter.java 2016-06-29 18:46:48.715520400 +0300 +++ new/src/java.desktop/share/classes/sun/swing/CachedPainter.java 2016-06-29 18:46:48.481006200 +0300 @@ -100,47 +100,19 @@ } private void paint0(Component c, Graphics g, int x, - int y, int w, int h, Object... args) { + int y, int w, int h, Object... args) { Object key = getClass(); GraphicsConfiguration config = getGraphicsConfiguration(c); ImageCache cache = getCache(key); Image image = cache.getImage(key, config, w, h, args); - int attempts = 0; - do { - boolean draw = false; - if (image instanceof VolatileImage) { - // See if we need to recreate the image - switch (((VolatileImage)image).validate(config)) { - case VolatileImage.IMAGE_INCOMPATIBLE: - ((VolatileImage)image).flush(); - image = null; - break; - case VolatileImage.IMAGE_RESTORED: - draw = true; - break; - } - } - if (image == null) { - // Recreate the image - image = createImage(c, w, h, config, args); - cache.setImage(key, config, w, h, args, image); - draw = true; - } - if (draw) { - // Render to the Image - Graphics g2 = image.getGraphics(); - paintToImage(c, image, g2, w, h, args); - g2.dispose(); - } - - // Render to the passed in Graphics - paintImage(c, g, x, y, w, h, image, args); - - // If we did this 3 times and the contents are still lost - // assume we're painting to a VolatileImage that is bogus and - // give up. Presumably we'll be called again to paint. - } while ((image instanceof VolatileImage) && - ((VolatileImage)image).contentsLost() && ++attempts < 3); + + if (image == null) { + image = new PainterMultiResolutionCachedImage(c, w, h, args); + cache.setImage(key, config, w, h, args, image); + } + + // Render to the passed in Graphics + paintImage(c, g, x, y, w, h, image, args); } /** @@ -210,4 +182,80 @@ } return c.getGraphicsConfiguration(); } -} + + class PainterMultiResolutionCachedImage extends AbstractMultiResolutionImage { + + private final int baseWidth; + private final int baseHeight; + private final Component c; + private final Object[] args; + + public PainterMultiResolutionCachedImage(Component c, int w, int h, + Object[] args) { + this.c = c; + this.args = args; + this.baseWidth = w; + this.baseHeight = h; + } + + @Override + public Image getResolutionVariant(double destWidth, double destHeight) { + + int w = (int) Math.ceil(destWidth); + int h = (int) Math.ceil(destHeight); + + Object key = this; + GraphicsConfiguration config = getGraphicsConfiguration(c); + ImageCache cache = getCache(key); + Image image = cache.getImage(key, config, w, h, args); + int attempts = 0; + do { + boolean draw = false; + if (image instanceof VolatileImage) { + // See if we need to recreate the image + switch (((VolatileImage) image).validate(config)) { + case VolatileImage.IMAGE_INCOMPATIBLE: + ((VolatileImage) image).flush(); + image = null; + break; + case VolatileImage.IMAGE_RESTORED: + draw = true; + break; + } + } + if (image == null) { + // Recreate the image + image = createImage(c, w, h, config, args); + cache.setImage(key, config, w, h, args, image); + draw = true; + } + if (draw) { + // Render to the Image + Graphics g2 = image.getGraphics(); + paintToImage(c, image, g2, w, h, args); + g2.dispose(); + } + + // If we did this 3 times and the contents are still lost + // assume we're painting to a VolatileImage that is bogus and + // give up. Presumably we'll be called again to paint. + } while ((image instanceof VolatileImage) + && ((VolatileImage) image).contentsLost() && ++attempts < 3); + + return image; + } + + @Override + protected Image getBaseImage() { + return getResolutionVariant(baseWidth, baseHeight); + } + + @Override + public java.util.List getResolutionVariants() { + return Arrays.asList( + getResolutionVariant(baseWidth, baseHeight), + getResolutionVariant(2 * baseWidth, 2 * baseHeight) + ); + } + } +} \ No newline at end of file