--- old/src/java.desktop/share/classes/sun/awt/SunToolkit.java 2016-08-24 20:28:05.000000000 +0400 +++ new/src/java.desktop/share/classes/sun/awt/SunToolkit.java 2016-08-24 20:28:05.000000000 +0400 @@ -37,7 +37,6 @@ import java.awt.image.Raster; import java.awt.peer.FramePeer; import java.awt.peer.KeyboardFocusManagerPeer; -import java.awt.peer.MouseInfoPeer; import java.awt.peer.SystemTrayPeer; import java.awt.peer.TrayIconPeer; import java.io.File; @@ -69,6 +68,9 @@ import sun.security.action.GetBooleanAction; import sun.security.action.GetPropertyAction; import sun.util.logging.PlatformLogger; +import java.util.Arrays; +import java.util.List; +import sun.awt.image.MultiResolutionToolkitImage.ResolutionVariantItem; import static java.awt.RenderingHints.*; @@ -751,7 +753,8 @@ public static Image createImageWithResolutionVariant(Image image, Image resolutionVariant) { - return new MultiResolutionToolkitImage(image, resolutionVariant); + return new MultiResolutionToolkitImage(image, + Arrays.asList(new ResolutionVariantItem(resolutionVariant, 2, 2))); } @Override @@ -767,7 +770,7 @@ } else { repbits = tkimg.getImageRep().check(o); } - return (tkimg.check(o) | repbits) & checkResolutionVariant(img, w, h, o); + return (tkimg.check(o) | repbits) & checkResolutionVariants(img, w, h, o); } @Override @@ -790,46 +793,55 @@ return false; } ImageRepresentation ir = tkimg.getImageRep(); - return ir.prepare(o) & prepareResolutionVariant(img, w, h, o); + return ir.prepare(o) & prepareResolutionVariants(img, w, h, o); } - private int checkResolutionVariant(Image img, int w, int h, ImageObserver o) { - ToolkitImage rvImage = getResolutionVariant(img); - int rvw = getRVSize(w); - int rvh = getRVSize(h); - // Ignore the resolution variant in case of error - return (rvImage == null || rvImage.hasError()) ? 0xFFFF : - checkImage(rvImage, rvw, rvh, MultiResolutionToolkitImage. - getResolutionVariantObserver( - img, o, w, h, rvw, rvh, true)); + private int checkResolutionVariants(Image img, int w, int h, ImageObserver o) { + if (!(img instanceof MultiResolutionToolkitImage)) { + return 0xFFFF; + } + + List rvItems + = ((MultiResolutionToolkitImage) img).getResolutionVariantItems(); + + return rvItems.stream().map(rvItem -> { + double scaleX = rvItem.getScaleX(); + double scaleY = rvItem.getScaleY(); + return checkImage( + rvItem.getImage(), + getRVSize(w, scaleX), + getRVSize(h, scaleY), + MultiResolutionToolkitImage.getResolutionVariantObserver( + img, o, scaleX, scaleY, true)); + }).reduce(0xFFFF , (a, b) -> a & b); + + } - private boolean prepareResolutionVariant(Image img, int w, int h, + private boolean prepareResolutionVariants(Image img, int w, int h, ImageObserver o) { - ToolkitImage rvImage = getResolutionVariant(img); - int rvw = getRVSize(w); - int rvh = getRVSize(h); - // Ignore the resolution variant in case of error - return rvImage == null || rvImage.hasError() || prepareImage( - rvImage, rvw, rvh, - MultiResolutionToolkitImage.getResolutionVariantObserver( - img, o, w, h, rvw, rvh, true)); - } - - private static int getRVSize(int size){ - return size == -1 ? -1 : 2 * size; - } - - private static ToolkitImage getResolutionVariant(Image image) { - if (image instanceof MultiResolutionToolkitImage) { - Image resolutionVariant = ((MultiResolutionToolkitImage) image). - getResolutionVariant(); - if (resolutionVariant instanceof ToolkitImage) { - return (ToolkitImage) resolutionVariant; - } + if (!(img instanceof MultiResolutionToolkitImage)) { + return true; } - return null; + + List rvItems + = ((MultiResolutionToolkitImage) img).getResolutionVariantItems(); + + return rvItems.stream().map(rvItem -> { + double scaleX = rvItem.getScaleX(); + double scaleY = rvItem.getScaleY(); + return prepareImage( + rvItem.getImage(), + getRVSize(w, scaleX), + getRVSize(h, scaleY), + MultiResolutionToolkitImage.getResolutionVariantObserver( + img, o, scaleX, scaleY, true)); + }).reduce(true, (a, b) -> a && b); + } + + private static int getRVSize(int size, double scale) { + return (scale == 1 || size == -1) ? size : (int) Math.ceil(scale * size); } protected static boolean imageCached(String fileName) { @@ -841,7 +853,7 @@ return urlImgCache.containsKey(key); } - protected static boolean imageExists(String filename) { + public static boolean imageExists(String filename) { if (filename != null) { checkPermissions(filename); return new File(filename).exists();