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

Print this page




  77 import sun.java2d.pipe.ShapeSpanIterator;
  78 import sun.java2d.pipe.Region;
  79 import sun.java2d.pipe.TextPipe;
  80 import sun.java2d.pipe.DrawImagePipe;
  81 import sun.java2d.pipe.LoopPipe;
  82 import sun.java2d.loops.FontInfo;
  83 import sun.java2d.loops.RenderLoops;
  84 import sun.java2d.loops.CompositeType;
  85 import sun.java2d.loops.SurfaceType;
  86 import sun.java2d.loops.Blit;
  87 import sun.java2d.loops.MaskFill;
  88 import java.awt.font.FontRenderContext;
  89 import sun.java2d.loops.XORComposite;
  90 import sun.awt.ConstrainableGraphics;
  91 import sun.awt.SunHints;
  92 import java.util.Map;
  93 import java.util.Iterator;
  94 import sun.misc.PerformanceLogger;
  95 
  96 import java.lang.annotation.Native;
  97 import sun.awt.image.MultiResolutionImage;
  98 
  99 import static java.awt.geom.AffineTransform.TYPE_FLIP;
 100 import static java.awt.geom.AffineTransform.TYPE_MASK_SCALE;
 101 import static java.awt.geom.AffineTransform.TYPE_TRANSLATION;
 102 import sun.awt.image.MultiResolutionToolkitImage;
 103 import sun.awt.image.ToolkitImage;
 104 
 105 /**
 106  * This is a the master Graphics2D superclass for all of the Sun
 107  * Graphics implementations.  This class relies on subclasses to
 108  * manage the various device information, but provides an overall
 109  * general framework for performing all of the requests in the
 110  * Graphics and Graphics2D APIs.
 111  *
 112  * @author Jim Graham
 113  */
 114 public final class SunGraphics2D
 115     extends Graphics2D
 116     implements ConstrainableGraphics, Cloneable, DestSurfaceProvider
 117 {


3159         double destRegionWidth;
3160         double destRegionHeight;
3161 
3162         if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP)) == 0) {
3163             destRegionWidth = dw;
3164             destRegionHeight = dh;
3165         } else if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP | TYPE_MASK_SCALE)) == 0) {
3166             destRegionWidth = dw * transform.getScaleX();
3167             destRegionHeight = dh * transform.getScaleY();
3168         } else {
3169             destRegionWidth = dw * Math.hypot(
3170                     transform.getScaleX(), transform.getShearY());
3171             destRegionHeight = dh * Math.hypot(
3172                     transform.getShearX(), transform.getScaleY());
3173         }
3174 
3175         int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw);
3176         int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh);
3177 
3178         Image resolutionVariant
3179                 = img.getResolutionVariant(destImageWidth, destImageHeight);

3180 
3181         if (resolutionVariant instanceof ToolkitImage
3182                 && ((ToolkitImage) resolutionVariant).hasError()) {
3183             return null;
3184         }
3185 
3186         return resolutionVariant;
3187     }
3188 
3189     /**
3190      * Draws an image scaled to x,y,w,h in nonblocking mode with a
3191      * callback object.
3192      */
3193     public boolean drawImage(Image img, int x, int y, int width, int height,
3194                              ImageObserver observer) {
3195         return drawImage(img, x, y, width, height, null, observer);
3196     }
3197 
3198     /**
3199      * Not part of the advertised API but a useful utility method




  77 import sun.java2d.pipe.ShapeSpanIterator;
  78 import sun.java2d.pipe.Region;
  79 import sun.java2d.pipe.TextPipe;
  80 import sun.java2d.pipe.DrawImagePipe;
  81 import sun.java2d.pipe.LoopPipe;
  82 import sun.java2d.loops.FontInfo;
  83 import sun.java2d.loops.RenderLoops;
  84 import sun.java2d.loops.CompositeType;
  85 import sun.java2d.loops.SurfaceType;
  86 import sun.java2d.loops.Blit;
  87 import sun.java2d.loops.MaskFill;
  88 import java.awt.font.FontRenderContext;
  89 import sun.java2d.loops.XORComposite;
  90 import sun.awt.ConstrainableGraphics;
  91 import sun.awt.SunHints;
  92 import java.util.Map;
  93 import java.util.Iterator;
  94 import sun.misc.PerformanceLogger;
  95 
  96 import java.lang.annotation.Native;
  97 import java.awt.image.MultiResolutionImage;
  98 
  99 import static java.awt.geom.AffineTransform.TYPE_FLIP;
 100 import static java.awt.geom.AffineTransform.TYPE_MASK_SCALE;
 101 import static java.awt.geom.AffineTransform.TYPE_TRANSLATION;
 102 import sun.awt.image.MultiResolutionToolkitImage;
 103 import sun.awt.image.ToolkitImage;
 104 
 105 /**
 106  * This is a the master Graphics2D superclass for all of the Sun
 107  * Graphics implementations.  This class relies on subclasses to
 108  * manage the various device information, but provides an overall
 109  * general framework for performing all of the requests in the
 110  * Graphics and Graphics2D APIs.
 111  *
 112  * @author Jim Graham
 113  */
 114 public final class SunGraphics2D
 115     extends Graphics2D
 116     implements ConstrainableGraphics, Cloneable, DestSurfaceProvider
 117 {


3159         double destRegionWidth;
3160         double destRegionHeight;
3161 
3162         if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP)) == 0) {
3163             destRegionWidth = dw;
3164             destRegionHeight = dh;
3165         } else if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP | TYPE_MASK_SCALE)) == 0) {
3166             destRegionWidth = dw * transform.getScaleX();
3167             destRegionHeight = dh * transform.getScaleY();
3168         } else {
3169             destRegionWidth = dw * Math.hypot(
3170                     transform.getScaleX(), transform.getShearY());
3171             destRegionHeight = dh * Math.hypot(
3172                     transform.getShearX(), transform.getScaleY());
3173         }
3174 
3175         int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw);
3176         int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh);
3177 
3178         Image resolutionVariant
3179                 = img.getResolutionVariant(devScale, devScale,
3180                         srcWidth, srcHeight, destImageWidth, destImageHeight);
3181 
3182         if (resolutionVariant instanceof ToolkitImage
3183                 && ((ToolkitImage) resolutionVariant).hasError()) {
3184             return null;
3185         }
3186 
3187         return resolutionVariant;
3188     }
3189 
3190     /**
3191      * Draws an image scaled to x,y,w,h in nonblocking mode with a
3192      * callback object.
3193      */
3194     public boolean drawImage(Image img, int x, int y, int width, int height,
3195                              ImageObserver observer) {
3196         return drawImage(img, x, y, width, height, null, observer);
3197     }
3198 
3199     /**
3200      * Not part of the advertised API but a useful utility method