src/share/classes/sun/java2d/SunGraphics2D.java
Print this page
*** 91,100 ****
--- 91,101 ----
import java.util.Map;
import java.util.Iterator;
import sun.misc.PerformanceLogger;
import java.lang.annotation.Native;
+ import com.sun.awt.MultiResolutionImage;
/**
* This is a the master Graphics2D superclass for all of the Sun
* Graphics implementations. This class relies on subclasses to
* manage the various device information, but provides an overall
*** 235,244 ****
--- 236,246 ----
public Region clipRegion;
public Shape usrClip;
protected Region devClip; // Actual physical drawable in pixels
private final int devScale; // Actual physical scale factor
+ private int resolutionVariantHint;
// cached state for text rendering
private boolean validFontInfo;
private FontInfo fontInfo;
private FontInfo glyphVectorFontInfo;
*** 281,290 ****
--- 283,295 ----
devScale = sd.getDefaultScale();
if (devScale != 1) {
transform.setToScale(devScale, devScale);
invalidateTransform();
+ resolutionVariantHint = SunHints.INTVAL_RESOLUTION_VARIANT_ON;
+ } else {
+ resolutionVariantHint = SunHints.INTVAL_RESOLUTION_VARIANT_OFF;
}
font = f;
if (font == null) {
font = defaultFont;
*** 1247,1256 ****
--- 1252,1265 ----
break;
case SunHints.INTKEY_STROKE_CONTROL:
stateChanged = (strokeHint != newHint);
strokeHint = newHint;
break;
+ case SunHints.INTKEY_RESOLUTION_VARIANT:
+ stateChanged = (resolutionVariantHint != newHint);
+ resolutionVariantHint = newHint;
+ break;
default:
recognized = false;
stateChanged = false;
break;
}
*** 1320,1329 ****
--- 1329,1341 ----
}
return null;
case SunHints.INTKEY_STROKE_CONTROL:
return SunHints.Value.get(SunHints.INTKEY_STROKE_CONTROL,
strokeHint);
+ case SunHints.INTKEY_RESOLUTION_VARIANT:
+ return SunHints.Value.get(SunHints.INTKEY_RESOLUTION_VARIANT,
+ resolutionVariantHint);
}
return null;
}
/**
*** 3048,3069 ****
surfaceData.markDirty();
}
}
// end of text rendering methods
! private static boolean isHiDPIImage(final Image img) {
! return SurfaceManager.getImageScale(img) != 1;
}
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
int dy2, int sx1, int sy1, int sx2, int sy2,
Color bgcolor, ImageObserver observer) {
final int scale = SurfaceManager.getImageScale(img);
sx1 = Region.clipScale(sx1, scale);
sx2 = Region.clipScale(sx2, scale);
sy1 = Region.clipScale(sy1, scale);
sy2 = Region.clipScale(sy2, scale);
try {
return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
sx2, sy2, bgcolor, observer);
} catch (InvalidPipeException e) {
try {
--- 3060,3125 ----
surfaceData.markDirty();
}
}
// end of text rendering methods
! private boolean isHiDPIImage(final Image img) {
! return SurfaceManager.getImageScale(img) != 1
! || (resolutionVariantHint != SunHints.INTVAL_RESOLUTION_VARIANT_OFF
! && img instanceof MultiResolutionImage);
}
private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
int dy2, int sx1, int sy1, int sx2, int sy2,
Color bgcolor, ImageObserver observer) {
+
+ if (SurfaceManager.getImageScale(img) != 1) { // Volatile Image
final int scale = SurfaceManager.getImageScale(img);
sx1 = Region.clipScale(sx1, scale);
sx2 = Region.clipScale(sx2, scale);
sy1 = Region.clipScale(sy1, scale);
sy2 = Region.clipScale(sy2, scale);
+ } else { // Image scaling hints are on
+ // get scaled destination image size
+
+ double scaleX = devScale;
+ double scaleY = devScale;
+
+ if (transformState == TRANSFORM_TRANSLATESCALE) {
+ scaleX = transform.getScaleX();
+ scaleY = transform.getScaleY();
+ }
+
+ int scaledImageWidth = Math.abs(Region.clipScale(dx2 - dx1, scaleX));
+ int scaledImageHeight = Math.abs(Region.clipScale(dy2 - dy1, scaleY));
+
+ Image scaledImage = ((MultiResolutionImage) img).
+ getResolutionVariant(scaledImageWidth, scaledImageHeight);
+
+ if (scaledImage != null && scaledImage != img) {
+ // recalculate source region for the scaled image
+ int width = img.getWidth(null);
+ int height = img.getHeight(null);
+
+ int scaledWidth = scaledImage.getWidth(null);
+ int scaledHeight = scaledImage.getHeight(null);
+
+ if (0 < width && 0 < height
+ && 0 < scaledWidth && 0 < scaledHeight) {
+
+ float widthScale = (float) scaledWidth / width;
+ float heightScale = (float) scaledHeight / height;
+
+ sx1 = Region.clipScale(sx1, widthScale);
+ sy1 = Region.clipScale(sy1, heightScale);
+ sx2 = Region.clipScale(sx2, widthScale);
+ sy2 = Region.clipScale(sy2, heightScale);
+ img = scaledImage;
+ }
+ }
+ }
+
try {
return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
sx2, sy2, bgcolor, observer);
} catch (InvalidPipeException e) {
try {