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