--- old/src/java.desktop/share/classes/java/awt/MediaTracker.java 2016-04-05 17:09:48.000000000 +0400 +++ new/src/java.desktop/share/classes/java/awt/MediaTracker.java 2016-04-05 17:09:47.000000000 +0400 @@ -25,10 +25,11 @@ package java.awt; -import java.awt.Component; -import java.awt.Image; import java.awt.image.ImageObserver; +import java.awt.image.ResolutionVariantItem; import sun.awt.image.MultiResolutionToolkitImage; +import java.util.List; +import java.util.stream.Stream; /** * The {@code MediaTracker} class is a utility class to track @@ -224,14 +225,26 @@ */ public synchronized void addImage(Image image, int id, int w, int h) { addImageImpl(image, id, w, h); - Image rvImage = getResolutionVariant(image); - if (rvImage != null) { - addImageImpl(rvImage, id, - w == -1 ? -1 : 2 * w, - h == -1 ? -1 : 2 * h); + + if (image instanceof MultiResolutionToolkitImage) { + getRVItems(image).forEach(rvItem -> + addImageImpl(rvItem.getValue(), id, + scale(w, rvItem.getScaleX()), + scale(h, rvItem.getScaleY()) + )); } } + + private static Stream> getRVItems(Image image) { + return ((MultiResolutionToolkitImage) image) + .getResolutionVariantItems().stream(); + } + + private static int scale(int size, double scale) { + return size == -1 ? -1 : (int) Math.floor(scale * size); + } + private void addImageImpl(Image image, int id, int w, int h) { head = MediaEntry.insert(head, new ImageMediaEntry(this, image, id, w, h)); @@ -732,10 +745,11 @@ */ public synchronized void removeImage(Image image) { removeImageImpl(image); - Image rvImage = getResolutionVariant(image); - if (rvImage != null) { - removeImageImpl(rvImage); + if (image instanceof MultiResolutionToolkitImage) { + getRVItems(image).forEach(rvItem -> + removeImageImpl(rvItem.getValue())); } + notifyAll(); // Notify in case remaining images are "done". } @@ -771,9 +785,10 @@ */ public synchronized void removeImage(Image image, int id) { removeImageImpl(image, id); - Image rvImage = getResolutionVariant(image); - if (rvImage != null) { - removeImageImpl(rvImage, id); + + if (image instanceof MultiResolutionToolkitImage) { + getRVItems(image).forEach(rvItem -> + removeImageImpl(rvItem.getValue(), id)); } notifyAll(); // Notify in case remaining images are "done". } @@ -812,11 +827,14 @@ public synchronized void removeImage(Image image, int id, int width, int height) { removeImageImpl(image, id, width, height); - Image rvImage = getResolutionVariant(image); - if (rvImage != null) { - removeImageImpl(rvImage, id, - width == -1 ? -1 : 2 * width, - height == -1 ? -1 : 2 * height); + + if (image instanceof MultiResolutionToolkitImage) { + + getRVItems(image).forEach(rvItem -> + removeImageImpl(rvItem.getValue(), id, + scale(width, rvItem.getScaleX()), + scale(height, rvItem.getScaleY()) + )); } notifyAll(); // Notify in case remaining images are "done". } @@ -845,13 +863,6 @@ synchronized void setDone() { notifyAll(); } - - private static Image getResolutionVariant(Image image) { - if (image instanceof MultiResolutionToolkitImage) { - return ((MultiResolutionToolkitImage) image).getResolutionVariant(); - } - return null; - } } abstract class MediaEntry {