jdk/src/share/classes/sun/java2d/pipe/BufferedRenderPipe.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 11080 7e18e343964e
child 23010 6dadb192ad81
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
     2
 * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
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: 888
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: 888
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 888
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.pipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    28
import java.awt.BasicStroke;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Polygon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Shape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.geom.Arc2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.geom.Ellipse2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.geom.Path2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.geom.IllegalPathStateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.geom.PathIterator;
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    37
import java.awt.geom.Rectangle2D;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.geom.RoundRectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.java2d.SunGraphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.java2d.loops.ProcessPath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import static sun.java2d.pipe.BufferedOpCodes.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * Base class for enqueuing rendering operations in a single-threaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * rendering environment.  Instead of each operation being rendered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * immediately by the underlying graphics library, the operation will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * added to the provided RenderQueue, which will be processed at a later
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * time by a single thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * This class provides implementations of drawLine(), drawRect(), drawPoly(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * fillRect(), draw(Shape), and fill(Shape), which are useful for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * hardware-accelerated renderer.  The other draw*() and fill*() methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * simply delegate to draw(Shape) and fill(Shape), respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public abstract class BufferedRenderPipe
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    56
    implements PixelDrawPipe, PixelFillPipe, ShapeDrawPipe, ParallelogramPipe
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
{
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    58
    ParallelogramPipe aapgrampipe = new AAParallelogramPipe();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    59
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static final int BYTES_PER_POLY_POINT = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static final int BYTES_PER_SCANLINE = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static final int BYTES_PER_SPAN = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    protected RenderQueue rq;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    protected RenderBuffer buf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private BufferedDrawHandler drawHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public BufferedRenderPipe(RenderQueue rq) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        this.rq = rq;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        this.buf = rq.getBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        this.drawHandler = new BufferedDrawHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    74
    public ParallelogramPipe getAAParallelogramPipe() {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    75
        return aapgrampipe;
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    76
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    77
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Validates the state in the provided SunGraphics2D object and sets up
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * any special resources for this operation (e.g. enabling gradient
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * shading).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    protected abstract void validateContext(SunGraphics2D sg2d);
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
    84
    protected abstract void validateContextAA(SunGraphics2D sg2d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public void drawLine(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                         int x1, int y1, int x2, int y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        int transx = sg2d.transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        int transy = sg2d.transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        rq.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            validateContext(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            rq.ensureCapacity(20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            buf.putInt(DRAW_LINE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            buf.putInt(x1 + transx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            buf.putInt(y1 + transy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            buf.putInt(x2 + transx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            buf.putInt(y2 + transy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            rq.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public void drawRect(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                         int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        rq.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            validateContext(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            rq.ensureCapacity(20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            buf.putInt(DRAW_RECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            buf.putInt(x + sg2d.transX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            buf.putInt(y + sg2d.transY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            buf.putInt(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            buf.putInt(height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            rq.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public void fillRect(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                         int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        rq.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            validateContext(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            rq.ensureCapacity(20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            buf.putInt(FILL_RECT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            buf.putInt(x + sg2d.transX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            buf.putInt(y + sg2d.transY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            buf.putInt(width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            buf.putInt(height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            rq.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public void drawRoundRect(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                              int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                              int arcWidth, int arcHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        draw(sg2d, new RoundRectangle2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                              arcWidth, arcHeight));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public void fillRoundRect(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                              int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                              int arcWidth, int arcHeight)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        fill(sg2d, new RoundRectangle2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                              arcWidth, arcHeight));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public void drawOval(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                         int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        draw(sg2d, new Ellipse2D.Float(x, y, width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public void fillOval(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                         int x, int y, int width, int height)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        fill(sg2d, new Ellipse2D.Float(x, y, width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public void drawArc(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                        int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                        int startAngle, int arcAngle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        draw(sg2d, new Arc2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                   startAngle, arcAngle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                   Arc2D.OPEN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public void fillArc(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                        int x, int y, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                        int startAngle, int arcAngle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        fill(sg2d, new Arc2D.Float(x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                   startAngle, arcAngle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                   Arc2D.PIE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    protected void drawPoly(final SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                            final int[] xPoints, final int[] yPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                            final int nPoints, final boolean isClosed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (xPoints == null || yPoints == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw new NullPointerException("coordinate array");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (xPoints.length < nPoints || yPoints.length < nPoints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            throw new ArrayIndexOutOfBoundsException("coordinate array");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        if (nPoints < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            // render nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        } else if (nPoints == 2 && !isClosed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            // render a simple line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            drawLine(sg2d, xPoints[0], yPoints[0], xPoints[1], yPoints[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        rq.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            validateContext(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            int pointBytesRequired = nPoints * BYTES_PER_POLY_POINT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            int totalBytesRequired = 20 + pointBytesRequired;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            if (totalBytesRequired <= buf.capacity()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                if (totalBytesRequired > buf.remaining()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    // process the queue first and then enqueue the points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    rq.flushNow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                buf.putInt(DRAW_POLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                // enqueue parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                buf.putInt(nPoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                buf.putInt(isClosed ? 1 : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                buf.putInt(sg2d.transX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                buf.putInt(sg2d.transY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                // enqueue the points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                buf.put(xPoints, 0, nPoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                buf.put(yPoints, 0, nPoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            } else {
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 11080
diff changeset
   227
                // queue is too small to accommodate all points; perform the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                // operation directly on the queue flushing thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                rq.flushAndInvokeNow(new Runnable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                        drawPoly(xPoints, yPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                                 nPoints, isClosed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                                 sg2d.transX, sg2d.transY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            rq.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    protected abstract void drawPoly(int[] xPoints, int[] yPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                                     int nPoints, boolean isClosed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                                     int transX, int transY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public void drawPolyline(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                             int[] xPoints, int[] yPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                             int nPoints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        drawPoly(sg2d, xPoints, yPoints, nPoints, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public void drawPolygon(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                            int[] xPoints, int[] yPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                            int nPoints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        drawPoly(sg2d, xPoints, yPoints, nPoints, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public void fillPolygon(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                            int[] xPoints, int[] yPoints,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                            int nPoints)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        fill(sg2d, new Polygon(xPoints, yPoints, nPoints));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    private class BufferedDrawHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        extends ProcessPath.DrawHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        BufferedDrawHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            // these are bogus values; the caller will use validate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            // to ensure that they are set properly prior to each usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            super(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
         * This method needs to be called prior to each draw/fillPath()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
         * operation to ensure the clip bounds are up to date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        void validate(SunGraphics2D sg2d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            Region clip = sg2d.getCompClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            setBounds(clip.getLoX(), clip.getLoY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                      clip.getHiX(), clip.getHiY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                      sg2d.strokeHint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
         * drawPath() support...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        public void drawLine(int x1, int y1, int x2, int y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            // assert rq.lock.isHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            rq.ensureCapacity(20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            buf.putInt(DRAW_LINE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            buf.putInt(x1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            buf.putInt(y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            buf.putInt(x2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            buf.putInt(y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        public void drawPixel(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            // assert rq.lock.isHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            rq.ensureCapacity(12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            buf.putInt(DRAW_PIXEL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            buf.putInt(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            buf.putInt(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
         * fillPath() support...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        private int scanlineCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        private int scanlineCountIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        private int remainingScanlines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        private void resetFillPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            buf.putInt(DRAW_SCANLINES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            scanlineCountIndex = buf.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            buf.putInt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            scanlineCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            remainingScanlines = buf.remaining() / BYTES_PER_SCANLINE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        private void updateScanlineCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            buf.putInt(scanlineCountIndex, scanlineCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
         * Called from fillPath() to indicate that we are about to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
         * start issuing drawScanline() calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        public void startFillPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            rq.ensureCapacity(20); // to ensure room for at least a scanline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            resetFillPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        public void drawScanline(int x1, int x2, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            if (remainingScanlines == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                updateScanlineCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                rq.flushNow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                resetFillPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            buf.putInt(x1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            buf.putInt(x2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            buf.putInt(y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            scanlineCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            remainingScanlines--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
         * Called from fillPath() to indicate that we are done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
         * issuing drawScanline() calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        public void endFillPath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            updateScanlineCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    protected void drawPath(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                            Path2D.Float p2df, int transx, int transy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        rq.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            validateContext(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            drawHandler.validate(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            ProcessPath.drawPath(drawHandler, p2df, transx, transy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            rq.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    protected void fillPath(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                            Path2D.Float p2df, int transx, int transy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        rq.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            validateContext(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            drawHandler.validate(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            drawHandler.startFillPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            ProcessPath.fillPath(drawHandler, p2df, transx, transy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            drawHandler.endFillPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            rq.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    private native int fillSpans(RenderQueue rq, long buf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                                 int pos, int limit,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                 SpanIterator si, long iterator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                                 int transx, int transy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    protected void fillSpans(SunGraphics2D sg2d, SpanIterator si,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                             int transx, int transy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        rq.lock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            validateContext(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            rq.ensureCapacity(24); // so that we have room for at least a span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            int newpos = fillSpans(rq, buf.getAddress(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                   buf.position(), buf.capacity(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                                   si, si.getNativeIterator(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                                   transx, transy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            buf.position(newpos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            rq.unlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   410
    public void fillParallelogram(SunGraphics2D sg2d,
9653
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents: 5506
diff changeset
   411
                                  double ux1, double uy1,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents: 5506
diff changeset
   412
                                  double ux2, double uy2,
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   413
                                  double x, double y,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   414
                                  double dx1, double dy1,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   415
                                  double dx2, double dy2)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   416
    {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   417
        rq.lock();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   418
        try {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   419
            validateContext(sg2d);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   420
            rq.ensureCapacity(28);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   421
            buf.putInt(FILL_PARALLELOGRAM);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   422
            buf.putFloat((float) x);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   423
            buf.putFloat((float) y);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   424
            buf.putFloat((float) dx1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   425
            buf.putFloat((float) dy1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   426
            buf.putFloat((float) dx2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   427
            buf.putFloat((float) dy2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   428
        } finally {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   429
            rq.unlock();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   430
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   431
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   432
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   433
    public void drawParallelogram(SunGraphics2D sg2d,
9653
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents: 5506
diff changeset
   434
                                  double ux1, double uy1,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents: 5506
diff changeset
   435
                                  double ux2, double uy2,
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   436
                                  double x, double y,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   437
                                  double dx1, double dy1,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   438
                                  double dx2, double dy2,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   439
                                  double lw1, double lw2)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   440
    {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   441
        rq.lock();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   442
        try {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   443
            validateContext(sg2d);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   444
            rq.ensureCapacity(36);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   445
            buf.putInt(DRAW_PARALLELOGRAM);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   446
            buf.putFloat((float) x);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   447
            buf.putFloat((float) y);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   448
            buf.putFloat((float) dx1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   449
            buf.putFloat((float) dy1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   450
            buf.putFloat((float) dx2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   451
            buf.putFloat((float) dy2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   452
            buf.putFloat((float) lw1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   453
            buf.putFloat((float) lw2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   454
        } finally {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   455
            rq.unlock();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   456
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   457
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   458
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   459
    private class AAParallelogramPipe implements ParallelogramPipe {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   460
        public void fillParallelogram(SunGraphics2D sg2d,
9653
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents: 5506
diff changeset
   461
                                      double ux1, double uy1,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents: 5506
diff changeset
   462
                                      double ux2, double uy2,
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   463
                                      double x, double y,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   464
                                      double dx1, double dy1,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   465
                                      double dx2, double dy2)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   466
        {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   467
            rq.lock();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   468
            try {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   469
                validateContextAA(sg2d);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   470
                rq.ensureCapacity(28);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   471
                buf.putInt(FILL_AAPARALLELOGRAM);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   472
                buf.putFloat((float) x);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   473
                buf.putFloat((float) y);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   474
                buf.putFloat((float) dx1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   475
                buf.putFloat((float) dy1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   476
                buf.putFloat((float) dx2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   477
                buf.putFloat((float) dy2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   478
            } finally {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   479
                rq.unlock();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   480
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   481
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   482
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   483
        public void drawParallelogram(SunGraphics2D sg2d,
9653
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents: 5506
diff changeset
   484
                                      double ux1, double uy1,
6a1eff16874d 7043054: REGRESSION: JDK 7 b126 : Wrong userBounds in Paint.createContext()
flar
parents: 5506
diff changeset
   485
                                      double ux2, double uy2,
887
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   486
                                      double x, double y,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   487
                                      double dx1, double dy1,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   488
                                      double dx2, double dy2,
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   489
                                      double lw1, double lw2)
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   490
        {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   491
            rq.lock();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   492
            try {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   493
                validateContextAA(sg2d);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   494
                rq.ensureCapacity(36);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   495
                buf.putInt(DRAW_AAPARALLELOGRAM);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   496
                buf.putFloat((float) x);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   497
                buf.putFloat((float) y);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   498
                buf.putFloat((float) dx1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   499
                buf.putFloat((float) dy1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   500
                buf.putFloat((float) dx2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   501
                buf.putFloat((float) dy2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   502
                buf.putFloat((float) lw1);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   503
                buf.putFloat((float) lw2);
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   504
            } finally {
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   505
                rq.unlock();
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   506
            }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   507
        }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   508
    }
0aab8d3fa11a 6725214: D3D: forward-port the new pipeline from 6u10
tdv
parents: 2
diff changeset
   509
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    public void draw(SunGraphics2D sg2d, Shape s) {
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 9653
diff changeset
   511
        if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            if (s instanceof Polygon) {
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 9653
diff changeset
   513
                if (sg2d.transformState < SunGraphics2D.TRANSFORM_TRANSLATESCALE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    Polygon p = (Polygon)s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    drawPolygon(sg2d, p.xpoints, p.ypoints, p.npoints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            Path2D.Float p2df;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            int transx, transy;
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 9653
diff changeset
   521
            if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                if (s instanceof Path2D.Float) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    p2df = (Path2D.Float)s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                    p2df = new Path2D.Float(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                transx = sg2d.transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                transy = sg2d.transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                p2df = new Path2D.Float(s, sg2d.transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                transx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                transy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            drawPath(sg2d, p2df, transx, transy);
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 9653
diff changeset
   535
        } else if (sg2d.strokeState < SunGraphics2D.STROKE_CUSTOM) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            ShapeSpanIterator si = LoopPipe.getStrokeSpans(sg2d, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                fillSpans(sg2d, si, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                si.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            fill(sg2d, sg2d.stroke.createStrokedShape(s));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    public void fill(SunGraphics2D sg2d, Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        int transx, transy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 9653
diff changeset
   550
        if (sg2d.strokeState == SunGraphics2D.STROKE_THIN) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            // Here we are able to use fillPath() for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            // high-quality fills.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            Path2D.Float p2df;
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 9653
diff changeset
   554
            if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                if (s instanceof Path2D.Float) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    p2df = (Path2D.Float)s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    p2df = new Path2D.Float(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                transx = sg2d.transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                transy = sg2d.transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                p2df = new Path2D.Float(s, sg2d.transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                transx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                transy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            fillPath(sg2d, p2df, transx, transy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        AffineTransform at;
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 9653
diff changeset
   572
        if (sg2d.transformState <= SunGraphics2D.TRANSFORM_INT_TRANSLATE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            // Transform (translation) will be done by FillSpans (we could
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            // delegate to fillPolygon() here, but most hardware accelerated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            // libraries cannot handle non-convex polygons, so we will use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            // the FillSpans approach by default)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            at = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            transx = sg2d.transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            transy = sg2d.transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            // Transform will be done by the PathIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            at = sg2d.transform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            transx = transy = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        ShapeSpanIterator ssi = LoopPipe.getFillSSI(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            // Subtract transx/y from the SSI clip to match the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            // (potentially untranslated) geometry fed to it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            Region clip = sg2d.getCompClip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            ssi.setOutputAreaXYXY(clip.getLoX() - transx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                                  clip.getLoY() - transy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                                  clip.getHiX() - transx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                  clip.getHiY() - transy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            ssi.appendPath(s.getPathIterator(at));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            fillSpans(sg2d, ssi, transx, transy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            ssi.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
}