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