< prev index next >
src/java.desktop/share/classes/sun/awt/SunToolkit.java
Print this page
@@ -35,11 +35,10 @@
import java.awt.image.ImageObserver;
import java.awt.image.ImageProducer;
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;
import java.io.IOException;
import java.io.InputStream;
@@ -70,10 +69,13 @@
import sun.security.action.GetBooleanAction;
import sun.security.action.GetPropertyAction;
import sun.util.logging.PlatformLogger;
import static java.awt.RenderingHints.*;
+import java.awt.image.ResolutionVariantItem;
+import java.util.Arrays;
+import java.util.List;
public abstract class SunToolkit extends Toolkit
implements ComponentFactory, InputMethodSupport, KeyboardFocusManagerPeerProvider {
// 8014718: logging has been removed from SunToolkit
@@ -745,16 +747,22 @@
return createImage(new ByteArrayImageSource(data, offset, length));
}
@Override
public Image createImage(ImageProducer producer) {
- return new ToolkitImage(producer);
+ return (producer.isMultiResolutionImageProducer())
+ ? new MultiResolutionToolkitImage(producer)
+ : new ToolkitImage(producer);
}
public static Image createImageWithResolutionVariant(Image image,
- Image resolutionVariant) {
- return new MultiResolutionToolkitImage(image, resolutionVariant);
+ Image resolutionVariant)
+ {
+ return new MultiResolutionToolkitImage(Arrays.asList(
+ new ResolutionVariantItem<>((ToolkitImage) image, 1, 1),
+ new ResolutionVariantItem<>((ToolkitImage) resolutionVariant, 2, 2)
+ ));
}
@Override
public int checkImage(Image img, int w, int h, ImageObserver o) {
if (!(img instanceof ToolkitImage)) {
@@ -766,11 +774,11 @@
if (w == 0 || h == 0) {
repbits = ImageObserver.ALLBITS;
} 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
public boolean prepareImage(Image img, int w, int h, ImageObserver o) {
if (w == 0 || h == 0) {
@@ -789,50 +797,61 @@
-1, -1, -1, -1);
}
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;
}
- private boolean prepareResolutionVariant(Image img, int w, int h,
- ImageObserver o) {
+ List<ResolutionVariantItem<Image>> rvItems
+ = ((MultiResolutionToolkitImage) img).getResolutionVariantItems();
- 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,
+ return rvItems.stream().map(rvItem -> {
+ double sx = rvItem.getScaleX();
+ double sy = rvItem.getScaleY();
+ return checkImage(
+ rvItem.getValue(),
+ getRVSize(w, sx),
+ getRVSize(h, sy),
MultiResolutionToolkitImage.getResolutionVariantObserver(
- img, o, w, h, rvw, rvh, true));
- }
+ img, o, sx, sy, true));
+ }).reduce(0xFFFF , (a, b) -> a & b);
+
- 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;
+ private boolean prepareResolutionVariants(Image img, int w, int h,
+ ImageObserver o) {
+
+ if (!(img instanceof MultiResolutionToolkitImage)) {
+ return true;
}
+
+ List<ResolutionVariantItem<Image>> rvItems
+ = ((MultiResolutionToolkitImage) img).getResolutionVariantItems();
+
+ return rvItems.stream().map(rvItem -> {
+ double sx = rvItem.getScaleX();
+ double sy = rvItem.getScaleY();
+ return prepareImage(
+ rvItem.getValue(),
+ getRVSize(w, sx),
+ getRVSize(h, sy),
+ MultiResolutionToolkitImage.getResolutionVariantObserver(
+ img, o, sx, sy, true));
+ }).reduce(true, (a, b) -> a && b);
}
- return null;
+
+ private static int getRVSize(int size, double scale) {
+ return (size == -1)
+ ? -1
+ : (scale == 1 ? size : (int) Math.round(scale * size));
}
protected static boolean imageCached(String fileName) {
return fileImgCache.containsKey(fileName);
}
< prev index next >