jdk/src/share/classes/sun/java2d/SunGraphics2D.java
author serb
Thu, 12 Jun 2014 00:32:33 +0400
changeset 25195 9de77f5b0df2
parent 24522 3a0bbf9f5e81
child 25777 bb88947b6766
permissions -rw-r--r--
8029455: [JLightweightFrame] support scaled painting Reviewed-by: anthony, ant
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
     2
 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4250
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4250
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4250
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4250
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4250
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.java2d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Graphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.RenderingHints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.RenderingHints.Key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.geom.Area;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.geom.NoninvertibleTransformException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.AlphaComposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.BasicStroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.image.BufferedImageOp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.image.RenderedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.image.renderable.RenderableImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.image.renderable.RenderContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.image.AffineTransformOp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.image.Raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.image.WritableRaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.Composite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.Paint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.awt.GradientPaint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.awt.LinearGradientPaint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.awt.RadialGradientPaint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.awt.TexturePaint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.awt.geom.PathIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.awt.geom.GeneralPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.awt.Shape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.awt.Stroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import java.awt.FontMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import java.text.AttributedCharacterIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import java.awt.Font;
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
    64
import java.awt.Point;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import java.awt.image.ImageObserver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import java.awt.Transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import java.awt.font.GlyphVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import java.awt.font.TextLayout;
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
    69
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
    70
import sun.awt.image.SurfaceManager;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import sun.font.FontDesignMetrics;
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 889
diff changeset
    72
import sun.font.FontUtilities;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import sun.java2d.pipe.PixelDrawPipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import sun.java2d.pipe.PixelFillPipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
import sun.java2d.pipe.ShapeDrawPipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
import sun.java2d.pipe.ValidatePipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
import sun.java2d.pipe.ShapeSpanIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
import sun.java2d.pipe.Region;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
import sun.java2d.pipe.TextPipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
import sun.java2d.pipe.DrawImagePipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
import sun.java2d.pipe.LoopPipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
import sun.java2d.loops.FontInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
import sun.java2d.loops.RenderLoops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
import sun.java2d.loops.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
import sun.java2d.loops.SurfaceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
import sun.java2d.loops.Blit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
import sun.java2d.loops.MaskFill;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
import java.awt.font.FontRenderContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
import sun.java2d.loops.XORComposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
import sun.awt.ConstrainableGraphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
import sun.awt.SunHints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
import sun.misc.PerformanceLogger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    96
import java.lang.annotation.Native;
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
    97
import sun.awt.image.MultiResolutionImage;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
    98
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
    99
import static java.awt.geom.AffineTransform.TYPE_FLIP;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
   100
import static java.awt.geom.AffineTransform.TYPE_MASK_SCALE;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
   101
import static java.awt.geom.AffineTransform.TYPE_TRANSLATION;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
   102
import sun.awt.image.MultiResolutionToolkitImage;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
   103
import sun.awt.image.ToolkitImage;
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 12047
diff changeset
   104
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * This is a the master Graphics2D superclass for all of the Sun
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * Graphics implementations.  This class relies on subclasses to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * manage the various device information, but provides an overall
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * general framework for performing all of the requests in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * Graphics and Graphics2D APIs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * @author Jim Graham
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
public final class SunGraphics2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    extends Graphics2D
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 560
diff changeset
   116
    implements ConstrainableGraphics, Cloneable, DestSurfaceProvider
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Attribute States
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /* Paint */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   122
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public static final int PAINT_CUSTOM       = 6; /* Any other Paint object */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   124
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public static final int PAINT_TEXTURE      = 5; /* Tiled Image */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   126
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public static final int PAINT_RAD_GRADIENT = 4; /* Color RadialGradient */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   128
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public static final int PAINT_LIN_GRADIENT = 3; /* Color LinearGradient */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   130
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public static final int PAINT_GRADIENT     = 2; /* Color Gradient */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   132
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public static final int PAINT_ALPHACOLOR   = 1; /* Non-opaque Color */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   134
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public static final int PAINT_OPAQUECOLOR  = 0; /* Opaque Color */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /* Composite*/
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   138
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public static final int COMP_CUSTOM = 3;/* Custom Composite */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   140
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public static final int COMP_XOR    = 2;/* XOR Mode Composite */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   142
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public static final int COMP_ALPHA  = 1;/* AlphaComposite */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   144
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public static final int COMP_ISCOPY = 0;/* simple stores into destination,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                             * i.e. Src, SrcOverNoEa, and other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                             * alpha modes which replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                             * the destination.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /* Stroke */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   152
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    public static final int STROKE_CUSTOM = 3; /* custom Stroke */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   154
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public static final int STROKE_WIDE   = 2; /* BasicStroke */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   156
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public static final int STROKE_THINDASHED   = 1; /* BasicStroke */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   158
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public static final int STROKE_THIN   = 0; /* BasicStroke */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /* Transform */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   162
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public static final int TRANSFORM_GENERIC = 4; /* any 3x2 */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   164
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public static final int TRANSFORM_TRANSLATESCALE = 3; /* scale XY */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   166
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public static final int TRANSFORM_ANY_TRANSLATE = 2; /* non-int translate */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   168
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public static final int TRANSFORM_INT_TRANSLATE = 1; /* int translate */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   170
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public static final int TRANSFORM_ISIDENT = 0; /* Identity */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /* Clipping */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   174
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public static final int CLIP_SHAPE       = 2; /* arbitrary clip */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   176
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public static final int CLIP_RECTANGULAR = 1; /* rectangular clip */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
   178
    @Native
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public static final int CLIP_DEVICE      = 0; /* no clipping set */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /* The following fields are used when the current Paint is a Color. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public int eargb;  // ARGB value with ExtraAlpha baked in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public int pixel;  // pixel value for eargb
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public SurfaceData surfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public PixelDrawPipe drawpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public PixelFillPipe fillpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public DrawImagePipe imagepipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public ShapeDrawPipe shapepipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public TextPipe textpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public MaskFill alphafill;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public RenderLoops loops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public CompositeType imageComp;     /* Image Transparency checked on fly */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public int paintState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public int compositeState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public int strokeState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public int transformState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public int clipState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public Color foregroundColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public Color backgroundColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public AffineTransform transform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public int transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public int transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    protected static final Stroke defaultStroke = new BasicStroke();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    protected static final Composite defaultComposite = AlphaComposite.SrcOver;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    private static final Font defaultFont =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        new Font(Font.DIALOG, Font.PLAIN, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public Paint paint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public Stroke stroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public Composite composite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    protected Font font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    protected FontMetrics fontMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public int renderHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public int antialiasHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public int textAntialiasHint;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 11902
diff changeset
   225
    protected int fractionalMetricsHint;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /* A gamma adjustment to the colour used in lcd text blitting */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public int lcdTextContrast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    private static int lcdTextContrastDefaultValue = 140;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private int interpolationHint;      // raw value of rendering Hint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public int strokeHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public int interpolationType;       // algorithm choice based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                                        // interpolation and render Hints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public RenderingHints hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   239
    public Region constrainClip;        // lightweight bounds in pixels
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public int constrainX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public int constrainY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public Region clipRegion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public Shape usrClip;
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   245
    protected Region devClip;           // Actual physical drawable in pixels
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   246
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   247
    private final int devScale;         // Actual physical scale factor
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
   248
    private int resolutionVariantHint;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    // cached state for text rendering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    private boolean validFontInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    private FontInfo fontInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    private FontInfo glyphVectorFontInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    private FontRenderContext glyphVectorFRC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    private final static int slowTextTransformMask =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                            AffineTransform.TYPE_GENERAL_TRANSFORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                        |   AffineTransform.TYPE_MASK_ROTATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                        |   AffineTransform.TYPE_FLIP;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (PerformanceLogger.loggingEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            PerformanceLogger.setTime("SunGraphics2D static initialization");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public SunGraphics2D(SurfaceData sd, Color fg, Color bg, Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        surfaceData = sd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        foregroundColor = fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        backgroundColor = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        transform = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        stroke = defaultStroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        composite = defaultComposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        paint = foregroundColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        imageComp = CompositeType.SrcOverNoEa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        renderHint = SunHints.INTVAL_RENDER_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        lcdTextContrast = lcdTextContrastDefaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        interpolationHint = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        strokeHint = SunHints.INTVAL_STROKE_DEFAULT;
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
   286
        resolutionVariantHint = SunHints.INTVAL_RESOLUTION_VARIANT_DEFAULT;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        validateColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   292
        devScale = sd.getDefaultScale();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   293
        if (devScale != 1) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   294
            transform.setToScale(devScale, devScale);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   295
            invalidateTransform();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   296
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   297
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        font = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        if (font == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            font = defaultFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        setDevClip(sd.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        invalidatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    protected Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            SunGraphics2D g = (SunGraphics2D) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            g.transform = new AffineTransform(this.transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            if (hints != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                g.hints = (RenderingHints) this.hints.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            /* FontInfos are re-used, so must be cloned too, if they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
             * are valid, and be nulled out if invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
             * The implied trade-off is that there is more to be gained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
             * from re-using these objects than is lost by having to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
             * clone them when the SG2D is cloned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            if (this.fontInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                if (this.validFontInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    g.fontInfo = (FontInfo)this.fontInfo.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                    g.fontInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            if (this.glyphVectorFontInfo != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                g.glyphVectorFontInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    (FontInfo)this.glyphVectorFontInfo.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                g.glyphVectorFRC = this.glyphVectorFRC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            //g.invalidatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            return g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * Create a new SunGraphics2D based on this one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public Graphics create() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        return (Graphics) clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public void setDevClip(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        Region c = constrainClip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            devClip = Region.getInstanceXYWH(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            devClip = c.getIntersectionXYWH(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        validateCompClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public void setDevClip(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        setDevClip(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Constrain rendering for lightweight objects.
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   362
     */
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   363
    public void constrain(int x, int y, int w, int h, Region region) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   364
        if ((x | y) != 0) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   365
            translate(x, y);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   366
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   367
        if (transformState > TRANSFORM_TRANSLATESCALE) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   368
            clipRect(0, 0, w, h);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   369
            return;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   370
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   371
        // changes parameters according to the current scale and translate.
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   372
        final double scaleX = transform.getScaleX();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   373
        final double scaleY = transform.getScaleY();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   374
        x = constrainX = (int) transform.getTranslateX();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   375
        y = constrainY = (int) transform.getTranslateY();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   376
        w = Region.dimAdd(x, Region.clipScale(w, scaleX));
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   377
        h = Region.dimAdd(y, Region.clipScale(h, scaleY));
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   378
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   379
        Region c = constrainClip;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   380
        if (c == null) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   381
            c = Region.getInstanceXYXY(x, y, w, h);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   382
        } else {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   383
            c = c.getIntersectionXYXY(x, y, w, h);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   384
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   385
        if (region != null) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   386
            region = region.getScaledRegion(scaleX, scaleY);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   387
            region = region.getTranslatedRegion(x, y);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   388
            c = c.getIntersection(region);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   389
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   390
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   391
        if (c == constrainClip) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   392
            // Common case to ignore
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   393
            return;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   394
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   395
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   396
        constrainClip = c;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   397
        if (!devClip.isInsideQuickCheck(c)) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   398
            devClip = devClip.getIntersection(c);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   399
            validateCompClip();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   400
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   401
    }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   402
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   403
    /**
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   404
     * Constrain rendering for lightweight objects.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * REMIND: This method will back off to the "workaround"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * of using translate and clipRect if the Graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * to be constrained has a complex transform.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * drawback of the workaround is that the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * clip and device origin cannot be "enforced".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @exception IllegalStateException If the Graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * to be constrained has a complex transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   415
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public void constrain(int x, int y, int w, int h) {
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
   417
        constrain(x, y, w, h, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    protected static ValidatePipe invalidpipe = new ValidatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * Invalidate the pipeline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    protected void invalidatePipe() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        drawpipe = invalidpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        fillpipe = invalidpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        shapepipe = invalidpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        textpipe = invalidpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        imagepipe = invalidpipe;
4250
e88776b21913 6896068: SunGraphics2D exposes a reference to itself while non fully initialised.
neugens
parents: 3928
diff changeset
   431
        loops = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public void validatePipe() {
11897
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   435
        /* This workaround is for the situation when we update the Pipelines
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   436
         * for invalid SurfaceData and run further code when the current
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   437
         * pipeline doesn't support the type of new SurfaceData created during
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   438
         * the current pipeline's work (in place of the invalid SurfaceData).
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   439
         * Usually SurfaceData and Pipelines are repaired (through revalidateAll)
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   440
         * and called again in the exception handlers */
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   441
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   442
        if (!surfaceData.isValid()) {
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   443
            throw new InvalidPipeException("attempt to validate Pipe with invalid SurfaceData");
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   444
        }
9e80dbac0293 7112642: Incorrect checking for graphics rendering object
bagiras
parents: 5506
diff changeset
   445
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        surfaceData.validatePipe(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * Intersect two Shapes by the simplest method, attempting to produce
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * a simplified result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * The boolean arguments keep1 and keep2 specify whether or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * the first or second shapes can be modified during the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * or whether that shape must be "kept" unmodified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    Shape intersectShapes(Shape s1, Shape s2, boolean keep1, boolean keep2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (s1 instanceof Rectangle && s2 instanceof Rectangle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            return ((Rectangle) s1).intersection((Rectangle) s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (s1 instanceof Rectangle2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            return intersectRectShape((Rectangle2D) s1, s2, keep1, keep2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        } else if (s2 instanceof Rectangle2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            return intersectRectShape((Rectangle2D) s2, s1, keep2, keep1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        return intersectByArea(s1, s2, keep1, keep2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * Intersect a Rectangle with a Shape by the simplest method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * attempting to produce a simplified result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * The boolean arguments keep1 and keep2 specify whether or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * the first or second shapes can be modified during the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * or whether that shape must be "kept" unmodified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    Shape intersectRectShape(Rectangle2D r, Shape s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                             boolean keep1, boolean keep2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (s instanceof Rectangle2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            Rectangle2D r2 = (Rectangle2D) s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            Rectangle2D outrect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            if (!keep1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                outrect = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            } else if (!keep2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                outrect = r2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                outrect = new Rectangle2D.Float();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            double x1 = Math.max(r.getX(), r2.getX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            double x2 = Math.min(r.getX()  + r.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                                 r2.getX() + r2.getWidth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            double y1 = Math.max(r.getY(), r2.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            double y2 = Math.min(r.getY()  + r.getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                                 r2.getY() + r2.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            if (((x2 - x1) < 0) || ((y2 - y1) < 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                // Width or height is negative. No intersection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                outrect.setFrameFromDiagonal(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                outrect.setFrameFromDiagonal(x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            return outrect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if (r.contains(s.getBounds2D())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            if (keep2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                s = cloneShape(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return intersectByArea(r, s, keep1, keep2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    protected static Shape cloneShape(Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        return new GeneralPath(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * Intersect two Shapes using the Area class.  Presumably other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * attempts at simpler intersection methods proved fruitless.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * The boolean arguments keep1 and keep2 specify whether or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * the first or second shapes can be modified during the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * or whether that shape must be "kept" unmodified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @see #intersectShapes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @see #intersectRectShape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    Shape intersectByArea(Shape s1, Shape s2, boolean keep1, boolean keep2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        Area a1, a2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        // First see if we can find an overwriteable source shape
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        // to use as our destination area to avoid duplication.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        if (!keep1 && (s1 instanceof Area)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            a1 = (Area) s1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        } else if (!keep2 && (s2 instanceof Area)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            a1 = (Area) s2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            s2 = s1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            a1 = new Area(s1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        if (s2 instanceof Area) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            a2 = (Area) s2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            a2 = new Area(s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        a1.intersect(a2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        if (a1.isRectangular()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            return a1.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return a1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * Intersect usrClip bounds and device bounds to determine the composite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * rendering boundaries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    public Region getCompClip() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (!surfaceData.isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            // revalidateAll() implicitly recalculcates the composite clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            revalidateAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return clipRegion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if (font == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            font = defaultFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        return font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    private static final double[] IDENT_MATRIX = {1, 0, 0, 1};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    private static final AffineTransform IDENT_ATX =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    private static final int MINALLOCATED = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    private static final int TEXTARRSIZE = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    private static double[][] textTxArr = new double[TEXTARRSIZE][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    private static AffineTransform[] textAtArr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        new AffineTransform[TEXTARRSIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        for (int i=MINALLOCATED;i<TEXTARRSIZE;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
          textTxArr[i] = new double [] {i, 0, 0, i};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
          textAtArr[i] = new AffineTransform( textTxArr[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    // cached state for various draw[String,Char,Byte] optimizations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    public FontInfo checkFontInfo(FontInfo info, Font font,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                                  FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        /* Do not create a FontInfo object as part of construction of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
         * SG2D as its possible it may never be needed - ie if no text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
         * is drawn using this SG2D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        if (info == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            info = new FontInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        float ptSize = font.getSize2D();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        int txFontType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        AffineTransform devAt, textAt=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        if (font.isTransformed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            textAt = font.getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            textAt.scale(ptSize, ptSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            txFontType = textAt.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            info.originX = (float)textAt.getTranslateX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            info.originY = (float)textAt.getTranslateY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            textAt.translate(-info.originX, -info.originY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            if (transformState >= TRANSFORM_TRANSLATESCALE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                transform.getMatrix(info.devTx = new double[4]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                devAt = new AffineTransform(info.devTx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                textAt.preConcatenate(devAt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                info.devTx = IDENT_MATRIX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                devAt = IDENT_ATX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            textAt.getMatrix(info.glyphTx = new double[4]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            double shearx = textAt.getShearX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            double scaley = textAt.getScaleY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            if (shearx != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                scaley = Math.sqrt(shearx * shearx + scaley * scaley);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            info.pixelHeight = (int)(Math.abs(scaley)+0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            txFontType = AffineTransform.TYPE_IDENTITY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            info.originX = info.originY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            if (transformState >= TRANSFORM_TRANSLATESCALE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                transform.getMatrix(info.devTx = new double[4]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                devAt = new AffineTransform(info.devTx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                info.glyphTx = new double[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                for (int i = 0; i < 4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                    info.glyphTx[i] = info.devTx[i] * ptSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                textAt = new AffineTransform(info.glyphTx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                double shearx = transform.getShearX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                double scaley = transform.getScaleY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                if (shearx != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                    scaley = Math.sqrt(shearx * shearx + scaley * scaley);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                info.pixelHeight = (int)(Math.abs(scaley * ptSize)+0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                /* If the double represents a common integral, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                 * may have pre-allocated objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                 * A "sparse" array be seems to be as fast as a switch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                 * even for 3 or 4 pt sizes, and is more flexible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                 * This should perform comparably in single-threaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                 * rendering to the old code which synchronized on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                 * class and scale better on MP systems.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                int pszInt = (int)ptSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                if (ptSize == pszInt &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    pszInt >= MINALLOCATED && pszInt < TEXTARRSIZE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                    info.glyphTx = textTxArr[pszInt];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                    textAt = textAtArr[pszInt];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                    info.pixelHeight = pszInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                    info.pixelHeight = (int)(ptSize+0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                if (textAt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                    info.glyphTx = new double[] {ptSize, 0, 0, ptSize};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                    textAt = new AffineTransform(info.glyphTx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                info.devTx = IDENT_MATRIX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                devAt = IDENT_ATX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 889
diff changeset
   669
        info.font2D = FontUtilities.getFont2D(font);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        int fmhint = fractionalMetricsHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        if (fmhint == SunHints.INTVAL_FRACTIONALMETRICS_DEFAULT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
            fmhint = SunHints.INTVAL_FRACTIONALMETRICS_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        info.lcdSubPixPos = false; // conditionally set true in LCD mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        /* The text anti-aliasing hints that are set by the client need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
         * to be interpreted for the current state and stored in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
         * FontInfo.aahint which is what will actually be used and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
         * will be one of OFF, ON, LCD_HRGB or LCD_VRGB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
         * This is what pipe selection code should typically refer to, not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
         * textAntialiasHint. This means we are now evaluating the meaning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
         * of "default" here. Any pipe that really cares about that will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
         * also need to consult that variable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
         * Otherwise these are being used only as args to getStrike,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
         * and are encapsulated in that object which is part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
         * FontInfo, so we do not need to store them directly as fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
         * in the FontInfo object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
         * That could change if FontInfo's were more selectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
         * revalidated when graphics state changed. Presently this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
         * method re-evaluates all fields in the fontInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
         * The strike doesn't need to know the RGB subpixel order. Just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
         * if its H or V orientation, so if an LCD option is specified we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
         * always pass in the RGB hint to the strike.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
         * frc is non-null only if this is a GlyphVector. For reasons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
         * which are probably a historical mistake the AA hint in a GV
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
         * is honoured when we render, overriding the Graphics setting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        int aahint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        if (frc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            aahint = textAntialiasHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            aahint = ((SunHints.Value)frc.getAntiAliasingHint()).getIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        if (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            if (antialiasHint == SunHints.INTVAL_ANTIALIAS_ON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                aahint = SunHints.INTVAL_TEXT_ANTIALIAS_ON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                aahint = SunHints.INTVAL_TEXT_ANTIALIAS_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            /* If we are in checkFontInfo because a rendering hint has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
             * set then all pipes are revalidated. But we can also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
             * be here because setFont() has been called when the 'gasp'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
             * hint is set, as then the font size determines the text pipe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
             * See comments in SunGraphics2d.setFont(Font).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            if (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_GASP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                if (info.font2D.useAAForPtSize(info.pixelHeight)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                    aahint = SunHints.INTVAL_TEXT_ANTIALIAS_ON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                    aahint = SunHints.INTVAL_TEXT_ANTIALIAS_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            } else if (aahint >= SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                /* loops for default rendering modes are installed in the SG2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                 * constructor. If there are none this will be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                 * Not all compositing modes update the render loops, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                 * we also test that this is a mode we know should support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                 * this. One minor issue is that the loops aren't necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                 * installed for a new rendering mode until after this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                 * method is called during pipeline validation. So it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                 * theoretically possible that it was set to null for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                 * compositing mode, the composite is then set back to Src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                 * but the loop is still null when this is called and AA=ON
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                 * is installed instead of an LCD mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                 * However this is done in the right order in SurfaceData.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                 * so this is not likely to be a problem - but not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                 * guaranteed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                if (
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                    !surfaceData.canRenderLCDText(this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
//                    loops.drawGlyphListLCDLoop == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
//                    compositeState > COMP_ISCOPY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
//                    paintState > PAINT_ALPHACOLOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                      ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                    aahint = SunHints.INTVAL_TEXT_ANTIALIAS_ON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                    info.lcdRGBOrder = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                    /* Collapse these into just HRGB or VRGB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                     * Pipe selection code needs only to test for these two.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                     * Since these both select the same pipe anyway its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                     * tempting to collapse into one value. But they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                     * different strikes (glyph caches) so the distinction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                     * needs to be made for that purpose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                    if (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HBGR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                        aahint = SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                        info.lcdRGBOrder = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                    } else if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                        (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VBGR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                        aahint = SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                        info.lcdRGBOrder = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                    /* Support subpixel positioning only for the case in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                     * which the horizontal resolution is increased
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                    info.lcdSubPixPos =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                        fmhint == SunHints.INTVAL_FRACTIONALMETRICS_ON &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                        aahint == SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        info.aaHint = aahint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        info.fontStrike = info.font2D.getStrike(font, devAt, textAt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                                                aahint, fmhint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    public static boolean isRotated(double [] mtx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        if ((mtx[0] == mtx[3]) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            (mtx[1] == 0.0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            (mtx[2] == 0.0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            (mtx[0] > 0.0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    public void setFont(Font font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        /* replacing the reference equality test font != this.font with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
         * !font.equals(this.font) did not yield any measurable difference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
         * in testing, but there may be yet to be identified cases where it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
         * is beneficial.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        if (font != null && font!=this.font/*!font.equals(this.font)*/) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            /* In the GASP AA case the textpipe depends on the glyph size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
             * as determined by graphics and font transforms as well as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
             * font size, and information in the font. But we may invalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
             * the pipe only to find that it made no difference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
             * Deferring pipe invalidation to checkFontInfo won't work because
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
             * when called we may already be rendering to the wrong pipe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
             * So, if the font is transformed, or the graphics has more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
             * a simple scale, we'll take that as enough of a hint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
             * revalidate everything. But if they aren't we will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
             * use the font's point size to query the gasp table and see if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
             * what it says matches what's currently being used, in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
             * case there's no need to invalidate the textpipe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
             * This should be sufficient for all typical uses cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            if (textAntialiasHint == SunHints.INTVAL_TEXT_ANTIALIAS_GASP &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                textpipe != invalidpipe &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                (transformState > TRANSFORM_ANY_TRANSLATE ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                 font.isTransformed() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                 fontInfo == null || // Precaution, if true shouldn't get here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                 (fontInfo.aaHint == SunHints.INTVAL_TEXT_ANTIALIAS_ON) !=
3928
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 889
diff changeset
   818
                     FontUtilities.getFont2D(font).
be186a33df9b 6795908: Refactor FontManager
rkennke
parents: 889
diff changeset
   819
                         useAAForPtSize(font.getSize()))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                textpipe = invalidpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
            this.font = font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            this.fontMetrics = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            this.validFontInfo = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    public FontInfo getFontInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        if (!validFontInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
            this.fontInfo = checkFontInfo(this.fontInfo, font, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            validFontInfo = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        return this.fontInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    /* Used by drawGlyphVector which specifies its own font. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    public FontInfo getGVFontInfo(Font font, FontRenderContext frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        if (glyphVectorFontInfo != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            glyphVectorFontInfo.font == font &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            glyphVectorFRC == frc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
            return glyphVectorFontInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            glyphVectorFRC = frc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            return glyphVectorFontInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                checkFontInfo(glyphVectorFontInfo, font, frc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    public FontMetrics getFontMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        if (this.fontMetrics != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            return this.fontMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        /* NB the constructor and the setter disallow "font" being null */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        return this.fontMetrics =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
           FontDesignMetrics.getMetrics(font, getFontRenderContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    public FontMetrics getFontMetrics(Font font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        if ((this.fontMetrics != null) && (font == this.font)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            return this.fontMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
        FontMetrics fm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
          FontDesignMetrics.getMetrics(font, getFontRenderContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        if (this.font == font) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            this.fontMetrics = fm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        return fm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * Checks to see if a Path intersects the specified Rectangle in device
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * space.  The rendering attributes taken into account include the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * clip, transform, and stroke attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * @param rect The area in device space to check for a hit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * @param p The path to check for a hit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @param onStroke Flag to choose between testing the stroked or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * the filled path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * @return True if there is a hit, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @see #setStroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * @see #fillPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @see #drawPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @see #setTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @see #clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @see #setClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    public boolean hit(Rectangle rect, Shape s, boolean onStroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        if (onStroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            s = stroke.createStrokedShape(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        s = transformShape(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        if ((constrainX|constrainY) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            rect = new Rectangle(rect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            rect.translate(constrainX, constrainY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        return s.intersects(rect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * Return the ColorModel associated with this Graphics2D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    public ColorModel getDeviceColorModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        return surfaceData.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * Return the device configuration associated with this Graphics2D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    public GraphicsConfiguration getDeviceConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        return surfaceData.getDeviceConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * Return the SurfaceData object assigned to manage the destination
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * drawable surface of this Graphics2D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    public final SurfaceData getSurfaceData() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        return surfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * Sets the Composite in the current graphics state. Composite is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * in all drawing methods such as drawImage, drawString, drawPath,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * and fillPath.  It specifies how new pixels are to be combined with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * the existing pixels on the graphics device in the rendering process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * @param comp The Composite object to be used for drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @see java.awt.Graphics#setXORMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * @see java.awt.Graphics#setPaintMode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * @see AlphaComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    public void setComposite(Composite comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        if (composite == comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        int newCompState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        CompositeType newCompType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        if (comp instanceof AlphaComposite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            AlphaComposite alphacomp = (AlphaComposite) comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            newCompType = CompositeType.forAlphaComposite(alphacomp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            if (newCompType == CompositeType.SrcOverNoEa) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                if (paintState == PAINT_OPAQUECOLOR ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                    (paintState > PAINT_ALPHACOLOR &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                     paint.getTransparency() == Transparency.OPAQUE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                    newCompState = COMP_ISCOPY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                    newCompState = COMP_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            } else if (newCompType == CompositeType.SrcNoEa ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                       newCompType == CompositeType.Src ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                       newCompType == CompositeType.Clear)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                newCompState = COMP_ISCOPY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            } else if (surfaceData.getTransparency() == Transparency.OPAQUE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                       newCompType == CompositeType.SrcIn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                newCompState = COMP_ISCOPY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                newCompState = COMP_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        } else if (comp instanceof XORComposite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            newCompState = COMP_XOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            newCompType = CompositeType.Xor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        } else if (comp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
            throw new IllegalArgumentException("null Composite");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            surfaceData.checkCustomComposite();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            newCompState = COMP_CUSTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            newCompType = CompositeType.General;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        if (compositeState != newCompState ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            imageComp != newCompType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            compositeState = newCompState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            imageComp = newCompType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            invalidatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            validFontInfo = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        composite = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        if (paintState <= PAINT_ALPHACOLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            validateColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * Sets the Paint in the current graphics state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * @param paint The Paint object to be used to generate color in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * the rendering process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * @see java.awt.Graphics#setColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @see GradientPaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * @see TexturePaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    public void setPaint(Paint paint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        if (paint instanceof Color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            setColor((Color) paint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        if (paint == null || this.paint == paint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        this.paint = paint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        if (imageComp == CompositeType.SrcOverNoEa) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            // special case where compState depends on opacity of paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            if (paint.getTransparency() == Transparency.OPAQUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                if (compositeState != COMP_ISCOPY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                    compositeState = COMP_ISCOPY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                if (compositeState == COMP_ISCOPY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                    compositeState = COMP_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        }
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 5506
diff changeset
  1017
        Class<? extends Paint> paintClass = paint.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        if (paintClass == GradientPaint.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            paintState = PAINT_GRADIENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        } else if (paintClass == LinearGradientPaint.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            paintState = PAINT_LIN_GRADIENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        } else if (paintClass == RadialGradientPaint.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            paintState = PAINT_RAD_GRADIENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        } else if (paintClass == TexturePaint.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            paintState = PAINT_TEXTURE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            paintState = PAINT_CUSTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        validFontInfo = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        invalidatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    static final int NON_UNIFORM_SCALE_MASK =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        (AffineTransform.TYPE_GENERAL_TRANSFORM |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
         AffineTransform.TYPE_GENERAL_SCALE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    public static final double MinPenSizeAA =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        sun.java2d.pipe.RenderingEngine.getInstance().getMinimumAAPenSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    public static final double MinPenSizeAASquared =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        (MinPenSizeAA * MinPenSizeAA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    // Since inaccuracies in the trig package can cause us to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    // calculated a rotated pen width of just slightly greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    // than 1.0, we add a fudge factor to our comparison value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    // here so that we do not misclassify single width lines as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    // wide lines under certain rotations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    public static final double MinPenSizeSquared = 1.000000001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    private void validateBasicStroke(BasicStroke bs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        boolean aa = (antialiasHint == SunHints.INTVAL_ANTIALIAS_ON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        if (transformState < TRANSFORM_TRANSLATESCALE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            if (aa) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                if (bs.getLineWidth() <= MinPenSizeAA) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                    if (bs.getDashArray() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                        strokeState = STROKE_THIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                        strokeState = STROKE_THINDASHED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                    strokeState = STROKE_WIDE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                if (bs == defaultStroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                    strokeState = STROKE_THIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                } else if (bs.getLineWidth() <= 1.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                    if (bs.getDashArray() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                        strokeState = STROKE_THIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                        strokeState = STROKE_THINDASHED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                    strokeState = STROKE_WIDE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            double widthsquared;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            if ((transform.getType() & NON_UNIFORM_SCALE_MASK) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                /* sqrt omitted, compare to squared limits below. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                widthsquared = Math.abs(transform.getDeterminant());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                /* First calculate the "maximum scale" of this transform. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                double A = transform.getScaleX();       // m00
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                double C = transform.getShearX();       // m01
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                double B = transform.getShearY();       // m10
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                double D = transform.getScaleY();       // m11
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                 * Given a 2 x 2 affine matrix [ A B ] such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                 *                             [ C D ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                 * v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                 * find the maximum magnitude (norm) of the vector v'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                 * with the constraint (x^2 + y^2 = 1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                 * The equation to maximize is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                 *     |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                 * or  |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                 * Since sqrt is monotonic we can maximize |v'|^2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                 * instead and plug in the substitution y = sqrt(1 - x^2).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                 * Trigonometric equalities can then be used to get
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                 * rid of most of the sqrt terms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                double EA = A*A + B*B;          // x^2 coefficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                double EB = 2*(A*C + B*D);      // xy coefficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                double EC = C*C + D*D;          // y^2 coefficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                 * There is a lot of calculus omitted here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                 * Conceptually, in the interests of understanding the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                 * terms that the calculus produced we can consider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                 * that EA and EC end up providing the lengths along
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                 * the major axes and the hypot term ends up being an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                 * adjustment for the additional length along the off-axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                 * angle of rotated or sheared ellipses as well as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                 * adjustment for the fact that the equation below
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                 * averages the two major axis lengths.  (Notice that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                 * the hypot term contains a part which resolves to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                 * difference of these two axis lengths in the absence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                 * of rotation.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                 * In the calculus, the ratio of the EB and (EA-EC) terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                 * ends up being the tangent of 2*theta where theta is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                 * the angle that the long axis of the ellipse makes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                 * with the horizontal axis.  Thus, this equation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                 * calculating the length of the hypotenuse of a triangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                 * along that axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                /* sqrt omitted, compare to squared limits below. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                widthsquared = ((EA + EC + hypot)/2.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            if (bs != defaultStroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                widthsquared *= bs.getLineWidth() * bs.getLineWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            if (widthsquared <=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                (aa ? MinPenSizeAASquared : MinPenSizeSquared))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                if (bs.getDashArray() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                    strokeState = STROKE_THIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                    strokeState = STROKE_THINDASHED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                strokeState = STROKE_WIDE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * Sets the Stroke in the current graphics state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * @param s The Stroke object to be used to stroke a Path in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * the rendering process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * @see BasicStroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    public void setStroke(Stroke s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            throw new IllegalArgumentException("null Stroke");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        int saveStrokeState = strokeState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        stroke = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        if (s instanceof BasicStroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            validateBasicStroke((BasicStroke) s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            strokeState = STROKE_CUSTOM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        if (strokeState != saveStrokeState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            invalidatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * Sets the preferences for the rendering algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * Hint categories include controls for rendering quality and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * overall time/quality trade-off in the rendering process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * @param hintKey The key of hint to be set. The strings are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * defined in the RenderingHints class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * @param hintValue The value indicating preferences for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * hint category. These strings are defined in the RenderingHints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * @see RenderingHints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    public void setRenderingHint(Key hintKey, Object hintValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        // If we recognize the key, we must recognize the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        //     otherwise throw an IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        //     and do not change the Hints object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        // If we do not recognize the key, just pass it through
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        //     to the Hints object untouched
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        if (!hintKey.isCompatibleValue(hintValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                (hintValue+" is not compatible with "+hintKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        if (hintKey instanceof SunHints.Key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            boolean stateChanged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            boolean textStateChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            boolean recognized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            SunHints.Key sunKey = (SunHints.Key) hintKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            int newHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            if (sunKey == SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                newHint = ((Integer)hintValue).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                newHint = ((SunHints.Value) hintValue).getIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            switch (sunKey.getIndex()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            case SunHints.INTKEY_RENDERING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                stateChanged = (renderHint != newHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                if (stateChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                    renderHint = newHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                    if (interpolationHint == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                        interpolationType =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                            (newHint == SunHints.INTVAL_RENDER_QUALITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                             ? AffineTransformOp.TYPE_BILINEAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                             : AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            case SunHints.INTKEY_ANTIALIASING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                stateChanged = (antialiasHint != newHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                antialiasHint = newHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                if (stateChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                    textStateChanged =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                        (textAntialiasHint ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                         SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                    if (strokeState != STROKE_CUSTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                        validateBasicStroke((BasicStroke) stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            case SunHints.INTKEY_TEXT_ANTIALIASING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                stateChanged = (textAntialiasHint != newHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                textStateChanged = stateChanged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                textAntialiasHint = newHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            case SunHints.INTKEY_FRACTIONALMETRICS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                stateChanged = (fractionalMetricsHint != newHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                textStateChanged = stateChanged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                fractionalMetricsHint = newHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            case SunHints.INTKEY_AATEXT_LCD_CONTRAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                stateChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                /* Already have validated it is an int 100 <= newHint <= 250 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                lcdTextContrast = newHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
            case SunHints.INTKEY_INTERPOLATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                interpolationHint = newHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                switch (newHint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                case SunHints.INTVAL_INTERPOLATION_BICUBIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                    newHint = AffineTransformOp.TYPE_BICUBIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                case SunHints.INTVAL_INTERPOLATION_BILINEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                    newHint = AffineTransformOp.TYPE_BILINEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                case SunHints.INTVAL_INTERPOLATION_NEAREST_NEIGHBOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                    newHint = AffineTransformOp.TYPE_NEAREST_NEIGHBOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                stateChanged = (interpolationType != newHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                interpolationType = newHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            case SunHints.INTKEY_STROKE_CONTROL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                stateChanged = (strokeHint != newHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                strokeHint = newHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                break;
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  1262
            case SunHints.INTKEY_RESOLUTION_VARIANT:
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  1263
                stateChanged = (resolutionVariantHint != newHint);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  1264
                resolutionVariantHint = newHint;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  1265
                break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                recognized = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                stateChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            if (recognized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                if (stateChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                    invalidatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                    if (textStateChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                        fontMetrics = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                        this.cachedFRC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                        validFontInfo = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                        this.glyphVectorFontInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                if (hints != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                    hints.put(hintKey, hintValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        // Nothing we recognize so none of "our state" has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        if (hints == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            hints = makeHints(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        hints.put(hintKey, hintValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * Returns the preferences for the rendering algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * @param hintCategory The category of hint to be set. The strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * are defined in the RenderingHints class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * @return The preferences for rendering algorithms. The strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * are defined in the RenderingHints class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * @see RenderingHints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    public Object getRenderingHint(Key hintKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        if (hints != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            return hints.get(hintKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        if (!(hintKey instanceof SunHints.Key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        int keyindex = ((SunHints.Key)hintKey).getIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
        switch (keyindex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        case SunHints.INTKEY_RENDERING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            return SunHints.Value.get(SunHints.INTKEY_RENDERING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                                      renderHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        case SunHints.INTKEY_ANTIALIASING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            return SunHints.Value.get(SunHints.INTKEY_ANTIALIASING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                                      antialiasHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        case SunHints.INTKEY_TEXT_ANTIALIASING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
            return SunHints.Value.get(SunHints.INTKEY_TEXT_ANTIALIASING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                                      textAntialiasHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        case SunHints.INTKEY_FRACTIONALMETRICS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            return SunHints.Value.get(SunHints.INTKEY_FRACTIONALMETRICS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                                      fractionalMetricsHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        case SunHints.INTKEY_AATEXT_LCD_CONTRAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            return new Integer(lcdTextContrast);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        case SunHints.INTKEY_INTERPOLATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            switch (interpolationHint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
            case SunHints.INTVAL_INTERPOLATION_NEAREST_NEIGHBOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                return SunHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            case SunHints.INTVAL_INTERPOLATION_BILINEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                return SunHints.VALUE_INTERPOLATION_BILINEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            case SunHints.INTVAL_INTERPOLATION_BICUBIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                return SunHints.VALUE_INTERPOLATION_BICUBIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        case SunHints.INTKEY_STROKE_CONTROL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            return SunHints.Value.get(SunHints.INTKEY_STROKE_CONTROL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                                      strokeHint);
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  1339
        case SunHints.INTKEY_RESOLUTION_VARIANT:
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  1340
            return SunHints.Value.get(SunHints.INTKEY_RESOLUTION_VARIANT,
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  1341
                                      resolutionVariantHint);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * Sets the preferences for the rendering algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * Hint categories include controls for rendering quality and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     * overall time/quality trade-off in the rendering process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     * @param hints The rendering hints to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * @see RenderingHints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    public void setRenderingHints(Map<?,?> hints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        this.hints = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        renderHint = SunHints.INTVAL_RENDER_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        antialiasHint = SunHints.INTVAL_ANTIALIAS_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        textAntialiasHint = SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        fractionalMetricsHint = SunHints.INTVAL_FRACTIONALMETRICS_OFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        lcdTextContrast = lcdTextContrastDefaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        interpolationHint = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        interpolationType = AffineTransformOp.TYPE_NEAREST_NEIGHBOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        boolean customHintPresent = false;
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 5506
diff changeset
  1363
        Iterator<?> iter = hints.keySet().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            Object key = iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            if (key == SunHints.KEY_RENDERING ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                key == SunHints.KEY_ANTIALIASING ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                key == SunHints.KEY_TEXT_ANTIALIASING ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                key == SunHints.KEY_FRACTIONALMETRICS ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                key == SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                key == SunHints.KEY_STROKE_CONTROL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                key == SunHints.KEY_INTERPOLATION)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                setRenderingHint((Key) key, hints.get(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                customHintPresent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        if (customHintPresent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            this.hints = makeHints(hints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        invalidatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * Adds a number of preferences for the rendering algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * Hint categories include controls for rendering quality and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * overall time/quality trade-off in the rendering process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * @param hints The rendering hints to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * @see RenderingHints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    public void addRenderingHints(Map<?,?> hints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        boolean customHintPresent = false;
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 5506
diff changeset
  1394
        Iterator<?> iter = hints.keySet().iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
            Object key = iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
            if (key == SunHints.KEY_RENDERING ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                key == SunHints.KEY_ANTIALIASING ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                key == SunHints.KEY_TEXT_ANTIALIASING ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                key == SunHints.KEY_FRACTIONALMETRICS ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                key == SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                key == SunHints.KEY_STROKE_CONTROL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                key == SunHints.KEY_INTERPOLATION)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                setRenderingHint((Key) key, hints.get(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                customHintPresent = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        if (customHintPresent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            if (this.hints == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                this.hints = makeHints(hints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                this.hints.putAll(hints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * Gets the preferences for the rendering algorithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * Hint categories include controls for rendering quality and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * overall time/quality trade-off in the rendering process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * @see RenderingHints
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    public RenderingHints getRenderingHints() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        if (hints == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            return makeHints(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
            return (RenderingHints) hints.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
24522
3a0bbf9f5e81 8038644: Fix raw and unchecked warnings in sun.java2d.*
henryjen
parents: 23685
diff changeset
  1433
    RenderingHints makeHints(Map<?,?> hints) {
3a0bbf9f5e81 8038644: Fix raw and unchecked warnings in sun.java2d.*
henryjen
parents: 23685
diff changeset
  1434
        RenderingHints model = new RenderingHints(null);
3a0bbf9f5e81 8038644: Fix raw and unchecked warnings in sun.java2d.*
henryjen
parents: 23685
diff changeset
  1435
        if (hints != null) {
3a0bbf9f5e81 8038644: Fix raw and unchecked warnings in sun.java2d.*
henryjen
parents: 23685
diff changeset
  1436
            model.putAll(hints);
3a0bbf9f5e81 8038644: Fix raw and unchecked warnings in sun.java2d.*
henryjen
parents: 23685
diff changeset
  1437
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        model.put(SunHints.KEY_RENDERING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                  SunHints.Value.get(SunHints.INTKEY_RENDERING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                                     renderHint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        model.put(SunHints.KEY_ANTIALIASING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                  SunHints.Value.get(SunHints.INTKEY_ANTIALIASING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                                     antialiasHint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        model.put(SunHints.KEY_TEXT_ANTIALIASING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                  SunHints.Value.get(SunHints.INTKEY_TEXT_ANTIALIASING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                                     textAntialiasHint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
        model.put(SunHints.KEY_FRACTIONALMETRICS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                  SunHints.Value.get(SunHints.INTKEY_FRACTIONALMETRICS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                                     fractionalMetricsHint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        model.put(SunHints.KEY_TEXT_ANTIALIAS_LCD_CONTRAST,
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
  1451
                  Integer.valueOf(lcdTextContrast));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        Object value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        switch (interpolationHint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        case SunHints.INTVAL_INTERPOLATION_NEAREST_NEIGHBOR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
            value = SunHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
        case SunHints.INTVAL_INTERPOLATION_BILINEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            value = SunHints.VALUE_INTERPOLATION_BILINEAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        case SunHints.INTVAL_INTERPOLATION_BICUBIC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            value = SunHints.VALUE_INTERPOLATION_BICUBIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            model.put(SunHints.KEY_INTERPOLATION, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        model.put(SunHints.KEY_STROKE_CONTROL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                  SunHints.Value.get(SunHints.INTKEY_STROKE_CONTROL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                                     strokeHint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        return model;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * Concatenates the current transform of this Graphics2D with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     * translation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     * This is equivalent to calling transform(T), where T is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * AffineTransform represented by the following matrix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     *          [   1    0    tx  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     *          [   0    1    ty  ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    public void translate(double tx, double ty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
        transform.translate(tx, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        invalidateTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
     * Concatenates the current transform of this Graphics2D with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
     * rotation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
     * This is equivalent to calling transform(R), where R is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
     * AffineTransform represented by the following matrix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
     *          [   cos(theta)    -sin(theta)    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     *          [   sin(theta)     cos(theta)    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     *          [       0              0         1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     * Rotating with a positive angle theta rotates points on the positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     * x axis toward the positive y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
     * @param theta The angle of rotation in radians.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
    public void rotate(double theta) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        transform.rotate(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
        invalidateTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * Concatenates the current transform of this Graphics2D with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * translated rotation transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     * This is equivalent to the following sequence of calls:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
     *          translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     *          rotate(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     *          translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * Rotating with a positive angle theta rotates points on the positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     * x axis toward the positive y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     * @param theta The angle of rotation in radians.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
     * @param x The x coordinate of the origin of the rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
     * @param y The x coordinate of the origin of the rotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
    public void rotate(double theta, double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        transform.rotate(theta, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
        invalidateTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     * Concatenates the current transform of this Graphics2D with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     * scaling transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     * This is equivalent to calling transform(S), where S is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     * AffineTransform represented by the following matrix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     *          [   sx   0    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     *          [   0    sy   0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
    public void scale(double sx, double sy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        transform.scale(sx, sy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        invalidateTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     * Concatenates the current transform of this Graphics2D with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
     * shearing transformation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
     * This is equivalent to calling transform(SH), where SH is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
     * AffineTransform represented by the following matrix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
     *          [   1   shx   0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
     *          [  shy   1    0   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     *          [   0    0    1   ]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
     * @param shx The factor by which coordinates are shifted towards the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
     * positive X axis direction according to their Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
     * @param shy The factor by which coordinates are shifted towards the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
     * positive Y axis direction according to their X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
    public void shear(double shx, double shy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        transform.shear(shx, shy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
        invalidateTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
     * Composes a Transform object with the transform in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
     * Graphics2D according to the rule last-specified-first-applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
     * If the currrent transform is Cx, the result of composition
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
     * with Tx is a new transform Cx'.  Cx' becomes the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     * transform for this Graphics2D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     * Transforming a point p by the updated transform Cx' is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     * equivalent to first transforming p by Tx and then transforming
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     * the result by the original transform Cx.  In other words,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     * Cx'(p) = Cx(Tx(p)).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     * A copy of the Tx is made, if necessary, so further
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     * modifications to Tx do not affect rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     * @param Tx The Transform object to be composed with the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     * transform.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * @see #setTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     * @see AffineTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    public void transform(AffineTransform xform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        this.transform.concatenate(xform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
        invalidateTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * Translate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
    public void translate(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        transform.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        if (transformState <= TRANSFORM_INT_TRANSLATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
            transX += x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
            transY += y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
            transformState = (((transX | transY) == 0) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                              TRANSFORM_ISIDENT : TRANSFORM_INT_TRANSLATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
            invalidateTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
     * Sets the Transform in the current graphics state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
     * @param Tx The Transform object to be used in the rendering process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
     * @see TransformChain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
     * @see AffineTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
     */
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  1611
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
    public void setTransform(AffineTransform Tx) {
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  1613
        if ((constrainX | constrainY) == 0 && devScale == 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
            transform.setTransform(Tx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        } else {
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  1616
            transform.setTransform(devScale, 0, 0, devScale, constrainX,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  1617
                                   constrainY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
            transform.concatenate(Tx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        invalidateTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
    protected void invalidateTransform() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        int type = transform.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
        int origTransformState = transformState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
        if (type == AffineTransform.TYPE_IDENTITY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
            transformState = TRANSFORM_ISIDENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
            transX = transY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
        } else if (type == AffineTransform.TYPE_TRANSLATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            double dtx = transform.getTranslateX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
            double dty = transform.getTranslateY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
            transX = (int) Math.floor(dtx + 0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
            transY = (int) Math.floor(dty + 0.5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
            if (dtx == transX && dty == transY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                transformState = TRANSFORM_INT_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                transformState = TRANSFORM_ANY_TRANSLATE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        } else if ((type & (AffineTransform.TYPE_FLIP |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                            AffineTransform.TYPE_MASK_ROTATION |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                            AffineTransform.TYPE_GENERAL_TRANSFORM)) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            transformState = TRANSFORM_TRANSLATESCALE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
            transX = transY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            transformState = TRANSFORM_GENERIC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
            transX = transY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        if (transformState >= TRANSFORM_TRANSLATESCALE ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
            origTransformState >= TRANSFORM_TRANSLATESCALE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            /* Its only in this case that the previous or current transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
             * was more than a translate that font info is invalidated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
            cachedFRC = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
            this.validFontInfo = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
            this.fontMetrics = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
            this.glyphVectorFontInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            if (transformState != origTransformState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                invalidatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
        if (strokeState != STROKE_CUSTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
            validateBasicStroke((BasicStroke) stroke);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
     * Returns the current Transform in the Graphics2D state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
     * @see #setTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
     */
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  1675
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
    public AffineTransform getTransform() {
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  1677
        if ((constrainX | constrainY) == 0 && devScale == 1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            return new AffineTransform(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
        }
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  1680
        final double invScale = 1.0 / devScale;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  1681
        AffineTransform tx = new AffineTransform(invScale, 0, 0, invScale,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  1682
                                                 -constrainX * invScale,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  1683
                                                 -constrainY * invScale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
        tx.concatenate(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
        return tx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
     * Returns the current Transform ignoring the "constrain"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
     * rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
    public AffineTransform cloneTransform() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
        return new AffineTransform(transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * Returns the current Paint in the Graphics2D state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     * @see #setPaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * @see java.awt.Graphics#setColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
    public Paint getPaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
        return paint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
     * Returns the current Composite in the Graphics2D state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
     * @see #setComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
    public Composite getComposite() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        return composite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
    public Color getColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        return foregroundColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     * Validate the eargb and pixel fields against the current color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * The eargb field must take into account the extraAlpha
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * value of an AlphaComposite.  It may also take into account
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     * the Fsrc Porter-Duff blending function if such a function is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * a constant (see handling of Clear mode below).  For instance,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     * by factoring in the (Fsrc == 0) state of the Clear mode we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     * use a SrcNoEa loop just as easily as a general Alpha loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * since the math will be the same in both cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     * The pixel field will always be the best pixel data choice for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     * the final result of all calculations applied to the eargb field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     * Note that this method is only necessary under the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     * conditions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     *     (paintState <= PAINT_ALPHA_COLOR &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     *      compositeState <= COMP_CUSTOM)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     * though nothing bad will happen if it is run in other states.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
    final void validateColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        int eargb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        if (imageComp == CompositeType.Clear) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            eargb = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
            eargb = foregroundColor.getRGB();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            if (compositeState <= COMP_ALPHA &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                imageComp != CompositeType.SrcNoEa &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                imageComp != CompositeType.SrcOverNoEa)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                AlphaComposite alphacomp = (AlphaComposite) composite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                int a = Math.round(alphacomp.getAlpha() * (eargb >>> 24));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                eargb = (eargb & 0x00ffffff) | (a << 24);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
        this.eargb = eargb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
        this.pixel = surfaceData.pixelFor(eargb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
    public void setColor(Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        if (color == null || color == paint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
        this.paint = foregroundColor = color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
        validateColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
        if ((eargb >> 24) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
            if (paintState == PAINT_OPAQUECOLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
            paintState = PAINT_OPAQUECOLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
            if (imageComp == CompositeType.SrcOverNoEa) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                // special case where compState depends on opacity of paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                compositeState = COMP_ISCOPY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            if (paintState == PAINT_ALPHACOLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
            paintState = PAINT_ALPHACOLOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
            if (imageComp == CompositeType.SrcOverNoEa) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                // special case where compState depends on opacity of paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                compositeState = COMP_ALPHA;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        validFontInfo = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        invalidatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
     * Sets the background color in this context used for clearing a region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     * When Graphics2D is constructed for a component, the backgroung color is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     * inherited from the component. Setting the background color in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     * Graphics2D context only affects the subsequent clearRect() calls and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     * not the background color of the component. To change the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     * of the component, use appropriate methods of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
     * @param color The background color that should be used in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     * subsequent calls to clearRect().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     * @see getBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     * @see Graphics.clearRect()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
    public void setBackground(Color color) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        backgroundColor = color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     * Returns the background color used for clearing a region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     * @see setBackground
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
    public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
        return backgroundColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * Returns the current Stroke in the Graphics2D state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     * @see setStroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
    public Stroke getStroke() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
        return stroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
    public Rectangle getClipBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
        if (clipState == CLIP_DEVICE) {
18749
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  1819
            return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
        }
18749
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  1821
        return getClipBounds(new Rectangle());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
    public Rectangle getClipBounds(Rectangle r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
        if (clipState != CLIP_DEVICE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
            if (transformState <= TRANSFORM_INT_TRANSLATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                if (usrClip instanceof Rectangle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                    r.setBounds((Rectangle) usrClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                } else {
18749
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  1830
                    r.setFrame(usrClip.getBounds2D());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                r.translate(-transX, -transY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
            } else {
18749
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  1834
                r.setFrame(getClip().getBounds2D());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
        } else if (r == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
            throw new NullPointerException("null rectangle parameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
    public boolean hitClip(int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
        if (width <= 0 || height <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
        if (transformState > TRANSFORM_INT_TRANSLATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
            // Note: Technically the most accurate test would be to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
            // raster scan the parallelogram of the transformed rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            // and do a span for span hit test against the clip, but for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
            // speed we approximate the test with a bounding box of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
            // transformed rectangle.  The cost of rasterizing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
            // transformed rectangle is probably high enough that it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
            // not worth doing so to save the caller from having to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
            // a rendering method where we will end up discovering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
            // same answer in about the same amount of time anyway.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
            // This logic breaks down if this hit test is being performed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
            // on the bounds of a group of shapes in which case it might
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
            // be beneficial to be a little more accurate to avoid lots
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
            // of subsequent rendering calls.  In either case, this relaxed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
            // test should not be significantly less accurate than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
            // optimal test for most transforms and so the conservative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
            // answer should not cause too much extra work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
            double d[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
                x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                x+width, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                x, y+height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                x+width, y+height
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            transform.transform(d, 0, d, 0, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
            x = (int) Math.floor(Math.min(Math.min(d[0], d[2]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                                          Math.min(d[4], d[6])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
            y = (int) Math.floor(Math.min(Math.min(d[1], d[3]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                                          Math.min(d[5], d[7])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
            width = (int) Math.ceil(Math.max(Math.max(d[0], d[2]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                                             Math.max(d[4], d[6])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            height = (int) Math.ceil(Math.max(Math.max(d[1], d[3]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                                              Math.max(d[5], d[7])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
            x += transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
            y += transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
            width += x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
            height += y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
        }
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  1885
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  1886
        try {
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  1887
            if (!getCompClip().intersectsQuickCheckXYXY(x, y, width, height)) {
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  1888
                return false;
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  1889
            }
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  1890
        } catch (InvalidPipeException e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
        // REMIND: We could go one step further here and examine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
        // non-rectangular clip shape more closely if there is one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        // Since the clip has already been rasterized, the performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
        // penalty of doing the scan is probably still within the bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
        // of a good tradeoff between speed and quality of the answer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
    protected void validateCompClip() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        int origClipState = clipState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
        if (usrClip == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
            clipState = CLIP_DEVICE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
            clipRegion = devClip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
        } else if (usrClip instanceof Rectangle2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
            clipState = CLIP_RECTANGULAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
            if (usrClip instanceof Rectangle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                clipRegion = devClip.getIntersection((Rectangle)usrClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                clipRegion = devClip.getIntersection(usrClip.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
            PathIterator cpi = usrClip.getPathIterator(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
            int box[] = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
            ShapeSpanIterator sr = LoopPipe.getFillSSI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                sr.setOutputArea(devClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
                sr.appendPath(cpi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                sr.getPathBox(box);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
                Region r = Region.getInstance(box);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                r.appendSpans(sr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
                clipRegion = r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
                clipState =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
                    r.isRectangular() ? CLIP_RECTANGULAR : CLIP_SHAPE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                sr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
        if (origClipState != clipState &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
            (clipState == CLIP_SHAPE || origClipState == CLIP_SHAPE))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
            validFontInfo = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            invalidatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
    static final int NON_RECTILINEAR_TRANSFORM_MASK =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
        (AffineTransform.TYPE_GENERAL_TRANSFORM |
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
         AffineTransform.TYPE_GENERAL_ROTATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
    protected Shape transformShape(Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
        if (transformState > TRANSFORM_INT_TRANSLATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
            return transformShape(transform, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
            return transformShape(transX, transY, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
    public Shape untransformShape(Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
        if (transformState > TRANSFORM_INT_TRANSLATE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
                return transformShape(transform.createInverse(), s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
            } catch (NoninvertibleTransformException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
            return transformShape(-transX, -transY, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
    protected static Shape transformShape(int tx, int ty, Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        if (s instanceof Rectangle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
            Rectangle r = s.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            r.translate(tx, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
        if (s instanceof Rectangle2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
            Rectangle2D rect = (Rectangle2D) s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
            return new Rectangle2D.Double(rect.getX() + tx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                                          rect.getY() + ty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                                          rect.getWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                                          rect.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
        if (tx == 0 && ty == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            return cloneShape(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
        AffineTransform mat = AffineTransform.getTranslateInstance(tx, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        return mat.createTransformedShape(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
    protected static Shape transformShape(AffineTransform tx, Shape clip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
        if (clip == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
        if (clip instanceof Rectangle2D &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
            (tx.getType() & NON_RECTILINEAR_TRANSFORM_MASK) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
            Rectangle2D rect = (Rectangle2D) clip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
            double matrix[] = new double[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
            matrix[0] = rect.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
            matrix[1] = rect.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
            matrix[2] = matrix[0] + rect.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
            matrix[3] = matrix[1] + rect.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
            tx.transform(matrix, 0, matrix, 0, 2);
18749
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2009
            fixRectangleOrientation(matrix, rect);
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2010
            return new Rectangle2D.Double(matrix[0], matrix[1],
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2011
                                          matrix[2] - matrix[0],
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2012
                                          matrix[3] - matrix[1]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        if (tx.isIdentity()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            return cloneShape(clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        return tx.createTransformedShape(clip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
18749
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2022
    /**
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2023
     * Sets orientation of the rectangle according to the clip.
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2024
     */
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2025
    private static void fixRectangleOrientation(double[] m, Rectangle2D clip) {
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2026
        if (clip.getWidth() > 0 != (m[2] - m[0] > 0)) {
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2027
            double t = m[0];
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2028
            m[0] = m[2];
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2029
            m[2] = t;
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2030
        }
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2031
        if (clip.getHeight() > 0 != (m[3] - m[1] > 0)) {
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2032
            double t = m[1];
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2033
            m[1] = m[3];
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2034
            m[3] = t;
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2035
        }
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2036
    }
482096e5f614 8004859: Graphics.getClipBounds/getClip return difference nonequivalent bounds, depending from transform
serb
parents: 16843
diff changeset
  2037
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
    public void clipRect(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
        clip(new Rectangle(x, y, w, h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
    public void setClip(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
        setClip(new Rectangle(x, y, w, h));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
    public Shape getClip() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
        return untransformShape(usrClip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
    public void setClip(Shape sh) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
        usrClip = transformShape(sh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
        validateCompClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     * Intersects the current clip with the specified Path and sets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     * current clip to the resulting intersection. The clip is transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     * with the current transform in the Graphics2D state before being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
     * intersected with the current clip. This method is used to make the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     * current clip smaller. To make the clip larger, use any setClip method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
     * @param p The Path to be intersected with the current clip.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
    public void clip(Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
        s = transformShape(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
        if (usrClip != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
            s = intersectShapes(usrClip, s, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
        usrClip = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
        validateCompClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
    public void setPaintMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
        setComposite(AlphaComposite.SrcOver);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
    public void setXORMode(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
            throw new IllegalArgumentException("null XORColor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
        setComposite(new XORComposite(c, surfaceData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
    Blit lastCAblit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
    Composite lastCAcomp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
    public void copyArea(int x, int y, int w, int h, int dx, int dy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
            doCopyArea(x, y, w, h, dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2091
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                doCopyArea(x, y, w, h, dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
    private void doCopyArea(int x, int y, int w, int h, int dx, int dy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
        if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
        SurfaceData theData = surfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
        if (theData.copyArea(this, x, y, w, h, dx, dy)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
        }
25195
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2111
        if (transformState > TRANSFORM_TRANSLATESCALE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
            throw new InternalError("transformed copyArea not implemented yet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
        // REMIND: This method does not deal with missing data from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
        // source object (i.e. it does not send exposure events...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
        Region clip = getCompClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
        Composite comp = composite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
        if (lastCAcomp != comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
            SurfaceType dsttype = theData.getSurfaceType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
            CompositeType comptype = imageComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
            if (CompositeType.SrcOverNoEa.equals(comptype) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
                theData.getTransparency() == Transparency.OPAQUE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                comptype = CompositeType.SrcNoEa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
            lastCAblit = Blit.locate(dsttype, comptype, dsttype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
            lastCAcomp = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
25195
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2132
        double[] coords = {x, y, x + w, y + h, x + dx, y + dy};
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2133
        transform.transform(coords, 0, coords, 0, 3);
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2134
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2135
        x = (int)Math.ceil(coords[0] - 0.5);
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2136
        y = (int)Math.ceil(coords[1] - 0.5);
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2137
        w = ((int)Math.ceil(coords[2] - 0.5)) - x;
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2138
        h = ((int)Math.ceil(coords[3] - 0.5)) - y;
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2139
        dx = ((int)Math.ceil(coords[4] - 0.5)) - x;
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2140
        dy = ((int)Math.ceil(coords[5] - 0.5)) - y;
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2141
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2142
        // In case of negative scale transform, reflect the rect coords.
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2143
        if (w < 0) {
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2144
            w *= -1;
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2145
            x -= w;
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2146
        }
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2147
        if (h < 0) {
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2148
            h *= -1;
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2149
            y -= h;
9de77f5b0df2 8029455: [JLightweightFrame] support scaled painting
serb
parents: 24522
diff changeset
  2150
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
        Blit ob = lastCAblit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
        if (dy == 0 && dx > 0 && dx < w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
            while (w > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
                int partW = Math.min(w, dx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
                w -= partW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
                int sx = x + w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
                ob.Blit(theData, theData, comp, clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
                        sx, y, sx+dx, y+dy, partW, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
        if (dy > 0 && dy < h && dx > -w && dx < w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
            while (h > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
                int partH = Math.min(h, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
                h -= partH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
                int sy = y + h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
                ob.Blit(theData, theData, comp, clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
                        x, sy, x+dx, sy+dy, w, partH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
        ob.Blit(theData, theData, comp, clip, x, y, x+dx, y+dy, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
    public void XcopyArea(int x, int y, int w, int h, int dx, int dy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
        Rectangle rect = new Rectangle(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
        rect = transformBounds(rect, transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
        Point2D    point = new Point2D.Float(dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
        Point2D    root  = new Point2D.Float(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
        point = transform.transform(point, point);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
        root  = transform.transform(root, root);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
        int fdx = (int)(point.getX()-root.getX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
        int fdy = (int)(point.getY()-root.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        Rectangle r = getCompBounds().intersection(rect.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
        if (r.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
        // Begin Rasterizer for Clip Shape
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
        boolean skipClip = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
        byte[] clipAlpha = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
        if (clipState == CLIP_SHAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
            int box[] = new int[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
            clipRegion.getBounds(box);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
            Rectangle devR = new Rectangle(box[0], box[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                                           box[2] - box[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
                                           box[3] - box[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
            if (!devR.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
                OutputManager mgr = getOutputManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
                RegionIterator ri = clipRegion.getIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
                while (ri.nextYRange(box)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
                    int spany = box[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
                    int spanh = box[3] - spany;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
                    while (ri.nextXBand(box)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
                        int spanx = box[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
                        int spanw = box[2] - spanx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
                        mgr.copyArea(this, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
                                     spanw, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
                                     spanx, spany,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
                                     spanw, spanh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
                                     fdx, fdy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
                                     null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
        // End Rasterizer for Clip Shape
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
        getOutputManager().copyArea(this, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
                                    r.width, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
                                    r.x, r.y, r.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
                                    r.height, fdx, fdy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
                                    null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
    public void drawLine(int x1, int y1, int x2, int y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
            drawpipe.drawLine(this, x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2240
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
                drawpipe.drawLine(this, x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
    public void drawRoundRect(int x, int y, int w, int h, int arcW, int arcH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
            drawpipe.drawRoundRect(this, x, y, w, h, arcW, arcH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2257
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
                drawpipe.drawRoundRect(this, x, y, w, h, arcW, arcH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
    public void fillRoundRect(int x, int y, int w, int h, int arcW, int arcH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
            fillpipe.fillRoundRect(this, x, y, w, h, arcW, arcH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2274
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
                fillpipe.fillRoundRect(this, x, y, w, h, arcW, arcH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
    public void drawOval(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
            drawpipe.drawOval(this, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2291
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
                drawpipe.drawOval(this, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
    public void fillOval(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
            fillpipe.fillOval(this, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2308
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
                fillpipe.fillOval(this, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
    public void drawArc(int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
                        int startAngl, int arcAngl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
            drawpipe.drawArc(this, x, y, w, h, startAngl, arcAngl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2326
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
                drawpipe.drawArc(this, x, y, w, h, startAngl, arcAngl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
    public void fillArc(int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
                        int startAngl, int arcAngl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
            fillpipe.fillArc(this, x, y, w, h, startAngl, arcAngl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2344
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
                fillpipe.fillArc(this, x, y, w, h, startAngl, arcAngl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
    public void drawPolyline(int xPoints[], int yPoints[], int nPoints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
            drawpipe.drawPolyline(this, xPoints, yPoints, nPoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2361
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
                drawpipe.drawPolyline(this, xPoints, yPoints, nPoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
    public void drawPolygon(int xPoints[], int yPoints[], int nPoints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
            drawpipe.drawPolygon(this, xPoints, yPoints, nPoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2378
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
                drawpipe.drawPolygon(this, xPoints, yPoints, nPoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
    public void fillPolygon(int xPoints[], int yPoints[], int nPoints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
            fillpipe.fillPolygon(this, xPoints, yPoints, nPoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2395
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
                fillpipe.fillPolygon(this, xPoints, yPoints, nPoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
    public void drawRect (int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
            drawpipe.drawRect(this, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2412
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
                drawpipe.drawRect(this, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
    public void fillRect (int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
            fillpipe.fillRect(this, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2429
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
                fillpipe.fillRect(this, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
    private void revalidateAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
            // REMIND: This locking needs to be done around the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
            // caller of this method so that the pipe stays valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
            // long enough to call the new primitive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
            // REMIND: No locking yet in screen SurfaceData objects!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
            // surfaceData.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
            surfaceData = surfaceData.getReplacement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
            if (surfaceData == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
                surfaceData = NullSurfaceData.theInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
23685
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents: 23256
diff changeset
  2453
            invalidatePipe();
3a2788a3f2ee 8036022: D3D: rendering with XOR composite causes InternalError.
bae
parents: 23256
diff changeset
  2454
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
            // this will recalculate the composite clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
            setDevClip(surfaceData.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
            if (paintState <= PAINT_ALPHACOLOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
                validateColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
            if (composite instanceof XORComposite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
                Color c = ((XORComposite) composite).getXorColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
                setComposite(new XORComposite(c, surfaceData));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
            validatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
            // REMIND: No locking yet in screen SurfaceData objects!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
            // surfaceData.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
    public void clearRect(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        // REMIND: has some "interesting" consequences if threads are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
        // not synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
        Composite c = composite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
        Paint p = paint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
        setComposite(AlphaComposite.Src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
        setColor(getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
        fillRect(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
        setPaint(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
        setComposite(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
     * Strokes the outline of a Path using the settings of the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
     * graphics state.  The rendering attributes applied include the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
     * clip, transform, paint or color, composite and stroke attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
     * @param p The path to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
     * @see #setStroke
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
     * @see #setPaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
     * @see java.awt.Graphics#setColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
     * @see #setTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
     * @see #clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
     * @see #setClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
     * @see #setComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
    public void draw(Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
            shapepipe.draw(this, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2503
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
                shapepipe.draw(this, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
     * Fills the interior of a Path using the settings of the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
     * graphics state. The rendering attributes applied include the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
     * clip, transform, paint or color, and composite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
     * @see #setPaint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
     * @see java.awt.Graphics#setColor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
     * @see #setTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
     * @see #setComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
     * @see #clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
     * @see #setClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
    public void fill(Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
            shapepipe.fill(this, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2533
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
                shapepipe.fill(this, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
     * Returns true if the given AffineTransform is an integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
     * translation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
    private static boolean isIntegerTranslation(AffineTransform xform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
        if (xform.isIdentity()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
        if (xform.getType() == AffineTransform.TYPE_TRANSLATION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
            double tx = xform.getTranslateX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
            double ty = xform.getTranslateY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
            return (tx == (int)tx && ty == (int)ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
     * Returns the index of the tile corresponding to the supplied position
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
     * given the tile grid offset and size along the same axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
    private static int getTileIndex(int p, int tileGridOffset, int tileSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
        p -= tileGridOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
        if (p < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
            p += 1 - tileSize;          // force round to -infinity (ceiling)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
        return p/tileSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     * Returns a rectangle in image coordinates that may be required
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     * in order to draw the given image into the given clipping region
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     * through a pair of AffineTransforms.  In addition, horizontal and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
     * vertical padding factors for antialising and interpolation may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
     * be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
    private static Rectangle getImageRegion(RenderedImage img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
                                            Region compClip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
                                            AffineTransform transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
                                            AffineTransform xform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
                                            int padX, int padY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
        Rectangle imageRect =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
            new Rectangle(img.getMinX(), img.getMinY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
                          img.getWidth(), img.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
        Rectangle result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
            double p[] = new double[8];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
            p[0] = p[2] = compClip.getLoX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
            p[4] = p[6] = compClip.getHiX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
            p[1] = p[5] = compClip.getLoY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
            p[3] = p[7] = compClip.getHiY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
            // Inverse transform the output bounding rect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
            transform.inverseTransform(p, 0, p, 0, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
            xform.inverseTransform(p, 0, p, 0, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
            // Determine a bounding box for the inverse transformed region
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
            double x0,x1,y0,y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
            x0 = x1 = p[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
            y0 = y1 = p[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
            for (int i = 2; i < 8; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
                double pt = p[i++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
                if (pt < x0)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
                    x0 = pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
                } else if (pt > x1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
                    x1 = pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
                pt = p[i++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
                if (pt < y0)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
                    y0 = pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
                } else if (pt > y1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
                    y1 = pt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
            // This is padding for anti-aliasing and such.  It may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
            // be more than is needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
            int x = (int)x0 - padX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
            int w = (int)(x1 - x0 + 2*padX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
            int y = (int)y0 - padY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
            int h = (int)(y1 - y0 + 2*padY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
            Rectangle clipRect = new Rectangle(x,y,w,h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
            result = clipRect.intersection(imageRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
        } catch (NoninvertibleTransformException nte) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
            // Worst case bounds are the bounds of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
            result = imageRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
     * Draws an image, applying a transform from image space into user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
     * before drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
     * The transformation from user space into device space is done with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
     * the current transform in the Graphics2D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
     * The given transformation is applied to the image before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
     * transform attribute in the Graphics2D state is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
     * The rendering attributes applied include the clip, transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
     * and composite attributes. Note that the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
     * undefined, if the given transform is noninvertible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
     * @param img The image to be drawn. Does nothing if img is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
     * @param xform The transformation from image space into user space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
     * @see #setTransform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
     * @see #setComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
     * @see #clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
     * @see #setClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
    public void drawRenderedImage(RenderedImage img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
                                  AffineTransform xform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
        // BufferedImage case: use a simple drawImage call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
        if (img instanceof BufferedImage) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
            BufferedImage bufImg = (BufferedImage)img;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
            drawImage(bufImg,xform,null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
        // transformState tracks the state of transform and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
        // transX, transY contain the integer casts of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
        // translation factors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
        boolean isIntegerTranslate =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
            (transformState <= TRANSFORM_INT_TRANSLATE) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
            isIntegerTranslation(xform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
        // Include padding for interpolation/antialiasing if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
        int pad = isIntegerTranslate ? 0 : 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2680
        Region clip;
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2681
        try {
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2682
            clip = getCompClip();
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2683
        } catch (InvalidPipeException e) {
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2684
            return;
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2685
        }
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2686
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
        // Determine the region of the image that may contribute to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
        // the clipped drawing area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
        Rectangle region = getImageRegion(img,
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2690
                                          clip,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
                                          transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
                                          xform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
                                          pad, pad);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
        if (region.width <= 0 || region.height <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
        // Attempt to optimize integer translation of tiled images.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
        // Although theoretically we are O.K. if the concatenation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
        // the user transform and the device transform is an integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
        // translation, we'll play it safe and only optimize the case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
        // where both are integer translations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
        if (isIntegerTranslate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
            // Use optimized code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
            // Note that drawTranslatedRenderedImage calls copyImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
            // which takes the user space to device space transform into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
            // account, but we need to provide the image space to user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
            // translations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
            drawTranslatedRenderedImage(img, region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
                                        (int) xform.getTranslateX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
                                        (int) xform.getTranslateY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
        // General case: cobble the necessary region into a single Raster
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
        Raster raster = img.getData(region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
        // Make a new Raster with the same contents as raster
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
        // but starting at (0, 0).  This raster is thus in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
        // coordinate system as the SampleModel of the original raster.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
        WritableRaster wRaster =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
              Raster.createWritableRaster(raster.getSampleModel(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
                                          raster.getDataBuffer(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
                                          null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
        // If the original raster was in a different coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
        // system than its SampleModel, we need to perform an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
        // additional translation in order to get the (minX, minY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
        // pixel of raster to be pixel (0, 0) of wRaster.  We also
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
        // have to have the correct width and height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
        int minX = raster.getMinX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
        int minY = raster.getMinY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
        int width = raster.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
        int height = raster.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
        int px = minX - raster.getSampleModelTranslateX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
        int py = minY - raster.getSampleModelTranslateY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
        if (px != 0 || py != 0 || width != wRaster.getWidth() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
            height != wRaster.getHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
            wRaster =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
                wRaster.createWritableChild(px,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
                                            py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
                                            width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
                                            height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
                                            0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
                                            null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
        // Now we have a BufferedImage starting at (0, 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
        // with the same contents that started at (minX, minY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
        // in raster.  So we must draw the BufferedImage with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
        // translation of (minX, minY).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
        AffineTransform transXform = (AffineTransform)xform.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
        transXform.translate(minX, minY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
        ColorModel cm = img.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
        BufferedImage bufImg = new BufferedImage(cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
                                                 wRaster,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
                                                 cm.isAlphaPremultiplied(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
                                                 null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
        drawImage(bufImg, transXform, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
     * Intersects <code>destRect</code> with <code>clip</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
     * overwrites <code>destRect</code> with the result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
     * Returns false if the intersection was empty, true otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
    private boolean clipTo(Rectangle destRect, Rectangle clip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
        int x1 = Math.max(destRect.x, clip.x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
        int x2 = Math.min(destRect.x + destRect.width, clip.x + clip.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
        int y1 = Math.max(destRect.y, clip.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
        int y2 = Math.min(destRect.y + destRect.height, clip.y + clip.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
        if (((x2 - x1) < 0) || ((y2 - y1) < 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
            destRect.width = -1; // Set both just to be safe
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
            destRect.height = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
            destRect.x = x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
            destRect.y = y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
            destRect.width = x2 - x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
            destRect.height = y2 - y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
     * Draw a portion of a RenderedImage tile-by-tile with a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
     * integer image to user space translation.  The user to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
     * device transform must also be an integer translation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
    private void drawTranslatedRenderedImage(RenderedImage img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
                                             Rectangle region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
                                             int i2uTransX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
                                             int i2uTransY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
        // Cache tile grid info
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
        int tileGridXOffset = img.getTileGridXOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
        int tileGridYOffset = img.getTileGridYOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
        int tileWidth = img.getTileWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
        int tileHeight = img.getTileHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
        // Determine the tile index extrema in each direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
        int minTileX =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
            getTileIndex(region.x, tileGridXOffset, tileWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
        int minTileY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
            getTileIndex(region.y, tileGridYOffset, tileHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
        int maxTileX =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
            getTileIndex(region.x + region.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
                         tileGridXOffset, tileWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
        int maxTileY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
            getTileIndex(region.y + region.height - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
                         tileGridYOffset, tileHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
        // Create a single ColorModel to use for all BufferedImages
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
        ColorModel colorModel = img.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
        // Reuse the same Rectangle for each iteration
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
        Rectangle tileRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
        for (int ty = minTileY; ty <= maxTileY; ty++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
            for (int tx = minTileX; tx <= maxTileX; tx++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
                // Get the current tile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
                Raster raster = img.getTile(tx, ty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
                // Fill in tileRect with the tile bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
                tileRect.x = tx*tileWidth + tileGridXOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
                tileRect.y = ty*tileHeight + tileGridYOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
                tileRect.width = tileWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
                tileRect.height = tileHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
                // Clip the tile against the image bounds and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
                // backwards mapped clip region
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
                // The result can't be empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
                clipTo(tileRect, region);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
                // Create a WritableRaster containing the tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
                WritableRaster wRaster = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
                if (raster instanceof WritableRaster) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
                    wRaster = (WritableRaster)raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
                    // Create a WritableRaster in the same coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
                    // as the original raster.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
                    wRaster =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
                        Raster.createWritableRaster(raster.getSampleModel(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
                                                    raster.getDataBuffer(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
                                                    null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
                // Translate wRaster to start at (0, 0) and to contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
                // only the relevent portion of the tile
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
                wRaster = wRaster.createWritableChild(tileRect.x, tileRect.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
                                                      tileRect.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
                                                      tileRect.height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
                                                      0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
                                                      null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
                // Wrap wRaster in a BufferedImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
                BufferedImage bufImg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
                    new BufferedImage(colorModel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
                                      wRaster,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
                                      colorModel.isAlphaPremultiplied(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
                                      null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
                // Now we have a BufferedImage starting at (0, 0) that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
                // represents data from a Raster starting at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
                // (tileRect.x, tileRect.y).  Additionally, it needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
                // to be translated by (i2uTransX, i2uTransY).  We call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
                // copyImage to draw just the region of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
                // without needing to create a child image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
                copyImage(bufImg, tileRect.x + i2uTransX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
                          tileRect.y + i2uTransY, 0, 0, tileRect.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
                          tileRect.height, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
    public void drawRenderableImage(RenderableImage img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
                                    AffineTransform xform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
        AffineTransform pipeTransform = transform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
        AffineTransform concatTransform = new AffineTransform(xform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
        concatTransform.concatenate(pipeTransform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
        AffineTransform reverseTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
        RenderContext rc = new RenderContext(concatTransform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
            reverseTransform = pipeTransform.createInverse();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
        } catch (NoninvertibleTransformException nte) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
            rc = new RenderContext(pipeTransform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
            reverseTransform = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
        RenderedImage rendering = img.createRendering(rc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
        drawRenderedImage(rendering,reverseTransform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
     * Transform the bounding box of the BufferedImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
    protected Rectangle transformBounds(Rectangle rect,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
                                        AffineTransform tx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
        if (tx.isIdentity()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
            return rect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
        Shape s = transformShape(tx, rect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
        return s.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
    // text rendering methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
    public void drawString(String str, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
        if (str == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
            throw new NullPointerException("String is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
        if (font.hasLayoutAttributes()) {
551
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  2923
            if (str.length() == 0) {
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  2924
                return;
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  2925
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
            new TextLayout(str, font, getFontRenderContext()).draw(this, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
            textpipe.drawString(this, str, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2934
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
                textpipe.drawString(this, str, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
    public void drawString(String str, float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
        if (str == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
            throw new NullPointerException("String is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
        if (font.hasLayoutAttributes()) {
551
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  2952
            if (str.length() == 0) {
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  2953
                return;
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  2954
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
            new TextLayout(str, font, getFontRenderContext()).draw(this, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
            textpipe.drawString(this, str, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  2963
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
                textpipe.drawString(this, str, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
    public void drawString(AttributedCharacterIterator iterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
                           int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
        if (iterator == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
            throw new NullPointerException("AttributedCharacterIterator is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
        }
551
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  2980
        if (iterator.getBeginIndex() == iterator.getEndIndex()) {
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  2981
            return; /* nothing to draw */
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  2982
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
        TextLayout tl = new TextLayout(iterator, getFontRenderContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
        tl.draw(this, (float) x, (float) y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
    public void drawString(AttributedCharacterIterator iterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
                           float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
        if (iterator == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
            throw new NullPointerException("AttributedCharacterIterator is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
        }
551
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  2992
        if (iterator.getBeginIndex() == iterator.getEndIndex()) {
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  2993
            return; /* nothing to draw */
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  2994
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
        TextLayout tl = new TextLayout(iterator, getFontRenderContext());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
        tl.draw(this, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
    public void drawGlyphVector(GlyphVector gv, float x, float y)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
        if (gv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
            throw new NullPointerException("GlyphVector is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
            textpipe.drawGlyphVector(this, gv, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  3009
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
                textpipe.drawGlyphVector(this, gv, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
    public void drawChars(char data[], int offset, int length, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
        if (data == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
            throw new NullPointerException("char data is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
        if (offset < 0 || length < 0 || offset + length > data.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
            throw new ArrayIndexOutOfBoundsException("bad offset/length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
        if (font.hasLayoutAttributes()) {
551
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  3030
            if (data.length == 0) {
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  3031
                return;
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  3032
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
            new TextLayout(new String(data, offset, length),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
                           font, getFontRenderContext()).draw(this, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
            textpipe.drawChars(this, data, offset, length, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  3042
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
                textpipe.drawChars(this, data, offset, length, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
    public void drawBytes(byte data[], int offset, int length, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
        if (data == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
            throw new NullPointerException("byte data is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
        if (offset < 0 || length < 0 || offset + length > data.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
            throw new ArrayIndexOutOfBoundsException("bad offset/length");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
        /* Byte data is interpreted as 8-bit ASCII. Re-use drawChars loops */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
        char chData[] = new char[length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
        for (int i = length; i-- > 0; ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
            chData[i] = (char)(data[i+offset] & 0xff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
        if (font.hasLayoutAttributes()) {
551
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  3067
            if (data.length == 0) {
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  3068
                return;
6a51745b2784 6699843: IllegalArgumentException when using Graphics.drawString( "", 0, 0 )
prr
parents: 2
diff changeset
  3069
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
            new TextLayout(new String(chData),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
                           font, getFontRenderContext()).draw(this, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
            textpipe.drawChars(this, chData, 0, length, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  3079
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
                textpipe.drawChars(this, chData, 0, length, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
// end of text rendering methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3092
    private boolean isHiDPIImage(final Image img) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3093
        return (SurfaceManager.getImageScale(img) != 1) ||
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3094
               (resolutionVariantHint != SunHints.INTVAL_RESOLUTION_VARIANT_OFF
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3095
                    && img instanceof MultiResolutionImage);
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3096
    }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3097
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3098
    private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3099
                                   int dy2, int sx1, int sy1, int sx2, int sy2,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3100
                                   Color bgcolor, ImageObserver observer) {
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3101
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3102
        if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3103
            final int scale = SurfaceManager.getImageScale(img);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3104
            sx1 = Region.clipScale(sx1, scale);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3105
            sx2 = Region.clipScale(sx2, scale);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3106
            sy1 = Region.clipScale(sy1, scale);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3107
            sy2 = Region.clipScale(sy2, scale);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3108
        } else if (img instanceof MultiResolutionImage) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3109
            // get scaled destination image size
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3110
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3111
            int width = img.getWidth(observer);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3112
            int height = img.getHeight(observer);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3113
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3114
            Image resolutionVariant = getResolutionVariant(
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3115
                    (MultiResolutionImage) img, width, height,
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3116
                    dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3117
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3118
            if (resolutionVariant != img && resolutionVariant != null) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3119
                // recalculate source region for the resolution variant
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3120
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3121
                ImageObserver rvObserver = MultiResolutionToolkitImage.
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3122
                        getResolutionVariantObserver(img, observer,
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3123
                                width, height, -1, -1);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3124
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3125
                int rvWidth = resolutionVariant.getWidth(rvObserver);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3126
                int rvHeight = resolutionVariant.getHeight(rvObserver);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3127
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3128
                if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3129
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3130
                    float widthScale = ((float) rvWidth) / width;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3131
                    float heightScale = ((float) rvHeight) / height;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3132
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3133
                    sx1 = Region.clipScale(sx1, widthScale);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3134
                    sy1 = Region.clipScale(sy1, heightScale);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3135
                    sx2 = Region.clipScale(sx2, widthScale);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3136
                    sy2 = Region.clipScale(sy2, heightScale);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3137
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3138
                    observer = rvObserver;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3139
                    img = resolutionVariant;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3140
                }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3141
            }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3142
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3143
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3144
        try {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3145
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3146
                                        sx2, sy2, bgcolor, observer);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3147
        } catch (InvalidPipeException e) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3148
            try {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3149
                revalidateAll();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3150
                return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3151
                                            sy1, sx2, sy2, bgcolor, observer);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3152
            } catch (InvalidPipeException e2) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3153
                // Still catching the exception; we are not yet ready to
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3154
                // validate the surfaceData correctly.  Fail for now and
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3155
                // try again next time around.
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3156
                return false;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3157
            }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3158
        } finally {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3159
            surfaceData.markDirty();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3160
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3161
    }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3162
23256
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3163
    private Image getResolutionVariant(MultiResolutionImage img,
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3164
            int srcWidth, int srcHeight, int dx1, int dy1, int dx2, int dy2,
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3165
            int sx1, int sy1, int sx2, int sy2) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3166
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3167
        if (srcWidth <= 0 || srcHeight <= 0) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3168
            return null;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3169
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3170
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3171
        int sw = sx2 - sx1;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3172
        int sh = sy2 - sy1;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3173
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3174
        if (sw == 0 || sh == 0) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3175
            return null;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3176
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3177
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3178
        int type = transform.getType();
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3179
        int dw = dx2 - dx1;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3180
        int dh = dy2 - dy1;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3181
        double destRegionWidth;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3182
        double destRegionHeight;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3183
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3184
        if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP)) == 0) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3185
            destRegionWidth = dw;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3186
            destRegionHeight = dh;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3187
        } else if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP | TYPE_MASK_SCALE)) == 0) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3188
            destRegionWidth = dw * transform.getScaleX();
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3189
            destRegionHeight = dh * transform.getScaleY();
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3190
        } else {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3191
            destRegionWidth = dw * Math.hypot(
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3192
                    transform.getScaleX(), transform.getShearY());
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3193
            destRegionHeight = dh * Math.hypot(
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3194
                    transform.getShearX(), transform.getScaleY());
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3195
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3196
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3197
        int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3198
        int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3199
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3200
        Image resolutionVariant
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3201
                = img.getResolutionVariant(destImageWidth, destImageHeight);
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3202
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3203
        if (resolutionVariant instanceof ToolkitImage
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3204
                && ((ToolkitImage) resolutionVariant).hasError()) {
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3205
            return null;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3206
        }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3207
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3208
        return resolutionVariant;
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3209
    }
d71287a532f8 8011059: [macosx] Support automatic @2x images loading on Mac OS X
alexsch
parents: 18749
diff changeset
  3210
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
     * Draws an image scaled to x,y,w,h in nonblocking mode with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
     * callback object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
    public boolean drawImage(Image img, int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
                             ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
        return drawImage(img, x, y, width, height, null, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
     * Not part of the advertised API but a useful utility method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
     * to call internally.  This is for the case where we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
     * drawing to/from given coordinates using a given width/height,
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3224
     * but we guarantee that the surfaceData's width/height of the src and dest
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3225
     * areas are equal (no scale needed). Note that this method intentionally
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3226
     * ignore scale factor of the source image, and copy it as is.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
    public boolean copyImage(Image img, int dx, int dy, int sx, int sy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
                             int width, int height, Color bgcolor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
                             ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
            return imagepipe.copyImage(this, img, dx, dy, sx, sy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
                                       width, height, bgcolor, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  3236
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
                return imagepipe.copyImage(this, img, dx, dy, sx, sy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
                                           width, height, bgcolor, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
     * Draws an image scaled to x,y,w,h in nonblocking mode with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
     * solid background color and a callback object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
    public boolean drawImage(Image img, int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
                             Color bg, ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
        if ((width == 0) || (height == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
        }
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3264
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3265
        final int imgW = img.getWidth(null);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3266
        final int imgH = img.getHeight(null);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3267
        if (isHiDPIImage(img)) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3268
            return drawHiDPIImage(img, x, y, x + width, y + height, 0, 0, imgW,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3269
                                  imgH, bg, observer);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3270
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3271
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3272
        if (width == imgW && height == imgH) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
            return copyImage(img, x, y, 0, 0, width, height, bg, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
            return imagepipe.scaleImage(this, img, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
                                        bg, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  3281
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
                return imagepipe.scaleImage(this, img, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
                                            bg, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
     * Draws an image at x,y in nonblocking mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
    public boolean drawImage(Image img, int x, int y, ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
        return drawImage(img, x, y, null, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
     * Draws an image at x,y in nonblocking mode with a solid background
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
     * color and a callback object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
    public boolean drawImage(Image img, int x, int y, Color bg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
                             ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3313
        if (isHiDPIImage(img)) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3314
            final int imgW = img.getWidth(null);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3315
            final int imgH = img.getHeight(null);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3316
            return drawHiDPIImage(img, x, y, x + imgW, y + imgH, 0, 0, imgW,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3317
                                  imgH, bg, observer);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3318
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3319
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
            return imagepipe.copyImage(this, img, x, y, bg, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  3324
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
                return imagepipe.copyImage(this, img, x, y, bg, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
     * Draws a subrectangle of an image scaled to a destination rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
     * in nonblocking mode with a callback object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
    public boolean drawImage(Image img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
                             int dx1, int dy1, int dx2, int dy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
                             int sx1, int sy1, int sx2, int sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
                             ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
        return drawImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
                         observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
     * Draws a subrectangle of an image scaled to a destination rectangle in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
     * nonblocking mode with a solid background color and a callback object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
    public boolean drawImage(Image img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
                             int dx1, int dy1, int dx2, int dy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
                             int sx1, int sy1, int sx2, int sy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
                             Color bgcolor, ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
        if (dx1 == dx2 || dy1 == dy2 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
            sx1 == sx2 || sy1 == sy2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3368
        if (isHiDPIImage(img)) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3369
            return drawHiDPIImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3370
                                  bgcolor, observer);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3371
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3372
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
        if (((sx2 - sx1) == (dx2 - dx1)) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
            ((sy2 - sy1) == (dy2 - dy1)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
            // Not a scale - forward it to a copy routine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
            int srcX, srcY, dstX, dstY, width, height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
            if (sx2 > sx1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
                width = sx2 - sx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
                srcX = sx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
                dstX = dx1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
                width = sx1 - sx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
                srcX = sx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
                dstX = dx2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
            if (sy2 > sy1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
                height = sy2-sy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
                srcY = sy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
                dstY = dy1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
                height = sy1-sy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
                srcY = sy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
                dstY = dy2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
            return copyImage(img, dstX, dstY, srcX, srcY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
                             width, height, bgcolor, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
                                          sx1, sy1, sx2, sy2, bgcolor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
                                          observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  3406
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
                return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
                                              sx1, sy1, sx2, sy2, bgcolor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
                                              observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
     * Draw an image, applying a transform from image space into user space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
     * before drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
     * The transformation from user space into device space is done with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
     * the current transform in the Graphics2D.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
     * The given transformation is applied to the image before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
     * transform attribute in the Graphics2D state is applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
     * The rendering attributes applied include the clip, transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
     * paint or color and composite attributes. Note that the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
     * undefined, if the given transform is non-invertible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3431
     * @param img The image to be drawn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3432
     * @param xform The transformation from image space into user space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3433
     * @param observer The image observer to be notified on the image producing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3434
     * progress.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3435
     * @see #transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3436
     * @see #setComposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3437
     * @see #setClip
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3438
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3439
    public boolean drawImage(Image img,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3440
                             AffineTransform xform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3441
                             ImageObserver observer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3443
        if (img == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3444
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3447
        if (xform == null || xform.isIdentity()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3448
            return drawImage(img, 0, 0, null, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3450
16840
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3451
        if (isHiDPIImage(img)) {
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3452
            final int w = img.getWidth(null);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3453
            final int h = img.getHeight(null);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3454
            final AffineTransform tx = new AffineTransform(transform);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3455
            transform(xform);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3456
            boolean result = drawHiDPIImage(img, 0, 0, w, h, 0, 0, w, h, null,
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3457
                                            observer);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3458
            transform.setTransform(tx);
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3459
            invalidateTransform();
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3460
            return result;
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3461
        }
64446d4710c4 8000629: [macosx] Blurry rendering with Java 7 on Retina display
serb
parents: 12813
diff changeset
  3462
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3463
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3464
            return imagepipe.transformImage(this, img, xform, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3465
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3466
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  3467
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3468
                return imagepipe.transformImage(this, img, xform, observer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3469
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3470
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3471
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3472
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3473
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3475
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3476
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3479
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3480
    public void drawImage(BufferedImage bImg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3481
                          BufferedImageOp op,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3482
                          int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3483
                          int y)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3485
        if (bImg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3486
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3489
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3490
            imagepipe.transformImage(this, bImg, op, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3491
        } catch (InvalidPipeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3492
            try {
11899
d2eb55fd95a1 7121482: some sun/java2d and sun/awt tests failed with InvalidPipeException since 1.7.0_03b02, 6u31b02
bagiras
parents: 11897
diff changeset
  3493
                revalidateAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3494
                imagepipe.transformImage(this, bImg, op, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3495
            } catch (InvalidPipeException e2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3496
                // Still catching the exception; we are not yet ready to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3497
                // validate the surfaceData correctly.  Fail for now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3498
                // try again next time around.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3499
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3500
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3501
            surfaceData.markDirty();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3506
    * Get the rendering context of the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3507
    * within this Graphics2D context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3508
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3509
    public FontRenderContext getFontRenderContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3510
        if (cachedFRC == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3511
            int aahint = textAntialiasHint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3512
            if (aahint == SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3513
                antialiasHint == SunHints.INTVAL_ANTIALIAS_ON) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3514
                aahint = SunHints.INTVAL_TEXT_ANTIALIAS_ON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3515
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3516
            // Translation components should be excluded from the FRC transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3517
            AffineTransform tx = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3518
            if (transformState >= TRANSFORM_TRANSLATESCALE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3519
                if (transform.getTranslateX() == 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3520
                    transform.getTranslateY() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3521
                    tx = transform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3522
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3523
                    tx = new AffineTransform(transform.getScaleX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3524
                                             transform.getShearY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3525
                                             transform.getShearX(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3526
                                             transform.getScaleY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3527
                                             0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3530
            cachedFRC = new FontRenderContext(tx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3531
             SunHints.Value.get(SunHints.INTKEY_TEXT_ANTIALIASING, aahint),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3532
             SunHints.Value.get(SunHints.INTKEY_FRACTIONALMETRICS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3533
                                fractionalMetricsHint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3535
        return cachedFRC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3537
    private FontRenderContext cachedFRC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3540
     * This object has no resources to dispose of per se, but the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3541
     * doc comments for the base method in java.awt.Graphics imply
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3542
     * that this object will not be useable after it is disposed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3543
     * So, we sabotage the object to prevent further use to prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3544
     * developers from relying on behavior that may not work on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3545
     * other, less forgiving, VMs that really need to dispose of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3546
     * resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3548
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3549
        surfaceData = NullSurfaceData.theInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3550
        invalidatePipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3551
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3554
     * Graphics has a finalize method that automatically calls dispose()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3555
     * for subclasses.  For SunGraphics2D we do not need to be finalized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3556
     * so that method simply causes us to be enqueued on the Finalizer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3557
     * queues for no good reason.  Unfortunately, that method and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3558
     * implementation are now considered part of the public contract
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3559
     * of that base class so we can not remove or gut the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3560
     * We override it here with an empty method and the VM is smart
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3561
     * enough to know that if our override is empty then it should not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3562
     * mark us as finalizeable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3564
    public void finalize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3565
        // DO NOT REMOVE THIS METHOD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3568
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3569
     * Returns destination that this Graphics renders to.  This could be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3570
     * either an Image or a Component; subclasses of SurfaceData are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3571
     * responsible for returning the appropriate object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3572
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3573
    public Object getDestination() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3574
        return surfaceData.getDestination();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3575
    }
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 560
diff changeset
  3576
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 560
diff changeset
  3577
    /**
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 560
diff changeset
  3578
     * {@inheritDoc}
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 560
diff changeset
  3579
     *
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 560
diff changeset
  3580
     * @see sun.java2d.DestSurfaceProvider#getDestSurface
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 560
diff changeset
  3581
     */
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 560
diff changeset
  3582
    @Override
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 560
diff changeset
  3583
    public Surface getDestSurface() {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 560
diff changeset
  3584
        return surfaceData;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 560
diff changeset
  3585
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3586
}