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