< prev index next >

src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java

Print this page

        

*** 59,69 **** import java.awt.Stroke; import java.awt.FontMetrics; import java.awt.Rectangle; import java.text.AttributedCharacterIterator; import java.awt.Font; - import java.awt.Point; import java.awt.image.ImageObserver; import java.awt.Transparency; import java.awt.font.GlyphVector; import java.awt.font.TextLayout; --- 59,68 ----
*** 97,106 **** --- 96,106 ---- import java.awt.image.MultiResolutionImage; import static java.awt.geom.AffineTransform.TYPE_FLIP; import static java.awt.geom.AffineTransform.TYPE_MASK_SCALE; import static java.awt.geom.AffineTransform.TYPE_TRANSLATION; + import java.awt.image.VolatileImage; import sun.awt.image.MultiResolutionToolkitImage; import sun.awt.image.ToolkitImage; /** * This is a the master Graphics2D superclass for all of the Sun
*** 3084,3117 **** surfaceData.markDirty(); } } // end of text rendering methods ! private boolean isHiDPIImage(final Image img) { ! return (SurfaceManager.getImageScale(img) != 1) ! || 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 if (img instanceof MultiResolutionImage) { // get scaled destination image size int width = img.getWidth(observer); int height = img.getHeight(observer); ! Image resolutionVariant = getResolutionVariant( ! (MultiResolutionImage) img, width, height, ! dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2); if (resolutionVariant != img && resolutionVariant != null) { // recalculate source region for the resolution variant ImageObserver rvObserver = MultiResolutionToolkitImage. --- 3084,3127 ---- surfaceData.markDirty(); } } // end of text rendering methods ! 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, ! AffineTransform xform) { ! if (img instanceof VolatileImage) { ! final SurfaceData sd = SurfaceManager.getManager(img) ! .getPrimarySurfaceData(); ! final double scaleX = sd.getDefaultScaleX(); ! final double scaleY = sd.getDefaultScaleY(); ! if (scaleX == 1 && scaleY == 1) { ! return null; ! } ! sx1 = Region.clipScale(sx1, scaleX); ! sx2 = Region.clipScale(sx2, scaleX); ! sy1 = Region.clipScale(sy1, scaleY); ! sy2 = Region.clipScale(sy2, scaleY); ! ! return scaleImage(img, dx1, dy1, dx2, dy2, ! sx1, sy1, sx2, sy2, ! bgcolor, xform, observer); ! } else if (resolutionVariantHint != SunHints.INTVAL_RESOLUTION_VARIANT_BASE ! && (img instanceof MultiResolutionImage)) { // get scaled destination image size int width = img.getWidth(observer); int height = img.getHeight(observer); ! MultiResolutionImage mrImage = (MultiResolutionImage) img; ! Image resolutionVariant = getResolutionVariant(mrImage, width, height, ! dx1, dy1, dx2, dy2, ! sx1, sy1, sx2, sy2, ! xform); if (resolutionVariant != img && resolutionVariant != null) { // recalculate source region for the resolution variant ImageObserver rvObserver = MultiResolutionToolkitImage.
*** 3131,3142 **** --- 3141,3168 ---- sx2 = Region.clipScale(sx2, widthScale); sy2 = Region.clipScale(sy2, heightScale); observer = rvObserver; img = resolutionVariant; + return scaleImage(img, dx1, dy1, dx2, dy2, + sx1, sy1, sx2, sy2, + bgcolor, xform, observer); + } } } + return null; + } + + private boolean scaleImage(Image img, int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, + Color bgcolor, AffineTransform xform, + ImageObserver observer) { + + if (xform != null) { + assert dx1 == 0 && dy1 == 0; + assert dx2 == img.getWidth(observer) && dy2 == img.getHeight(observer); + return transformImage(img, xform, observer); } try { return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
*** 3154,3166 **** } finally { surfaceData.markDirty(); } } private Image getResolutionVariant(MultiResolutionImage img, int srcWidth, int srcHeight, int dx1, int dy1, int dx2, int dy2, ! int sx1, int sy1, int sx2, int sy2) { if (srcWidth <= 0 || srcHeight <= 0) { return null; } --- 3180,3211 ---- } finally { surfaceData.markDirty(); } } + private boolean transformImage(Image img, AffineTransform xform, + ImageObserver observer) { + try { + return imagepipe.transformImage(this, img, xform, observer); + } catch (InvalidPipeException e) { + try { + revalidateAll(); + return imagepipe.transformImage(this, img, xform, observer); + } catch (InvalidPipeException e2) { + // Still catching the exception; we are not yet ready to + // validate the surfaceData correctly. Fail for now and + // try again next time around. + return false; + } + } finally { + surfaceData.markDirty(); + } + } + private Image getResolutionVariant(MultiResolutionImage img, int srcWidth, int srcHeight, int dx1, int dy1, int dx2, int dy2, ! int sx1, int sy1, int sx2, int sy2, AffineTransform xform) { if (srcWidth <= 0 || srcHeight <= 0) { return null; }
*** 3169,3179 **** if (sw == 0 || sh == 0) { return null; } ! int type = transform.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; double destImageWidth; double destImageHeight; --- 3214,3233 ---- if (sw == 0 || sh == 0) { return null; } ! AffineTransform tx; ! ! if (xform == null) { ! tx = transform; ! } else { ! tx = new AffineTransform(transform); ! tx.concatenate(xform); ! } ! ! int type = tx.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; double destImageWidth; double destImageHeight;
*** 3196,3212 **** if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP)) == 0) { destRegionWidth = dw; destRegionHeight = dh; } else if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP | TYPE_MASK_SCALE)) == 0) { ! destRegionWidth = dw * transform.getScaleX(); ! destRegionHeight = dh * transform.getScaleY(); } else { destRegionWidth = dw * Math.hypot( ! transform.getScaleX(), transform.getShearY()); destRegionHeight = dh * Math.hypot( ! transform.getShearX(), transform.getScaleY()); } destImageWidth = Math.abs(srcWidth * destRegionWidth / sw); destImageHeight = Math.abs(srcHeight * destRegionHeight / sh); } --- 3250,3266 ---- if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP)) == 0) { destRegionWidth = dw; destRegionHeight = dh; } else if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP | TYPE_MASK_SCALE)) == 0) { ! destRegionWidth = dw * tx.getScaleX(); ! destRegionHeight = dh * tx.getScaleY(); } else { destRegionWidth = dw * Math.hypot( ! tx.getScaleX(), tx.getShearY()); destRegionHeight = dh * Math.hypot( ! tx.getShearX(), tx.getScaleY()); } destImageWidth = Math.abs(srcWidth * destRegionWidth / sw); destImageHeight = Math.abs(srcHeight * destRegionHeight / sh); }
*** 3275,3287 **** return true; } final int imgW = img.getWidth(null); final int imgH = img.getHeight(null); ! if (isHiDPIImage(img)) { ! return drawHiDPIImage(img, x, y, x + width, y + height, 0, 0, imgW, ! imgH, bg, observer); } if (width == imgW && height == imgH) { return copyImage(img, x, y, 0, 0, width, height, bg, observer); } --- 3329,3343 ---- return true; } final int imgW = img.getWidth(null); final int imgH = img.getHeight(null); ! Boolean hidpiImageDrawn = drawHiDPIImage(img, x, y, x + width, y + height, ! 0, 0, imgW, imgH, bg, observer, ! null); ! if (hidpiImageDrawn != null) { ! return hidpiImageDrawn; } if (width == imgW && height == imgH) { return copyImage(img, x, y, 0, 0, width, height, bg, observer); }
*** 3321,3335 **** if (img == null) { return true; } - if (isHiDPIImage(img)) { final int imgW = img.getWidth(null); final int imgH = img.getHeight(null); ! return drawHiDPIImage(img, x, y, x + imgW, y + imgH, 0, 0, imgW, ! imgH, bg, observer); } try { return imagepipe.copyImage(this, img, x, y, bg, observer); } catch (InvalidPipeException e) { --- 3377,3393 ---- if (img == null) { return true; } final int imgW = img.getWidth(null); final int imgH = img.getHeight(null); ! Boolean hidpiImageDrawn = drawHiDPIImage(img, x, y, x + imgW, y + imgH, ! 0, 0, imgW, imgH, bg, observer, ! null); ! if (hidpiImageDrawn != null) { ! return hidpiImageDrawn; } try { return imagepipe.copyImage(this, img, x, y, bg, observer); } catch (InvalidPipeException e) {
*** 3376,3388 **** sx1 == sx2 || sy1 == sy2) { return true; } ! if (isHiDPIImage(img)) { ! return drawHiDPIImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, ! bgcolor, observer); } if (((sx2 - sx1) == (dx2 - dx1)) && ((sy2 - sy1) == (dy2 - dy1))) { --- 3434,3449 ---- sx1 == sx2 || sy1 == sy2) { return true; } ! Boolean hidpiImageDrawn = drawHiDPIImage(img, dx1, dy1, dx2, dy2, ! sx1, sy1, sx2, sy2, ! bgcolor, observer, null); ! ! if (hidpiImageDrawn != null) { ! return hidpiImageDrawn; } if (((sx2 - sx1) == (dx2 - dx1)) && ((sy2 - sy1) == (dy2 - dy1))) {
*** 3459,3478 **** if (xform == null || xform.isIdentity()) { return drawImage(img, 0, 0, null, observer); } - if (isHiDPIImage(img)) { final int w = img.getWidth(null); final int h = img.getHeight(null); ! final AffineTransform tx = new AffineTransform(transform); ! transform(xform); ! boolean result = drawHiDPIImage(img, 0, 0, w, h, 0, 0, w, h, null, ! observer); ! transform.setTransform(tx); ! invalidateTransform(); ! return result; } try { return imagepipe.transformImage(this, img, xform, observer); } catch (InvalidPipeException e) { --- 3520,3536 ---- if (xform == null || xform.isIdentity()) { return drawImage(img, 0, 0, null, observer); } final int w = img.getWidth(null); final int h = img.getHeight(null); ! Boolean hidpiImageDrawn = drawHiDPIImage(img, 0, 0, w, h, 0, 0, w, h, ! null, observer, xform); ! ! if (hidpiImageDrawn != null) { ! return hidpiImageDrawn; } try { return imagepipe.transformImage(this, img, xform, observer); } catch (InvalidPipeException e) {
< prev index next >