jdk/src/share/classes/sun/java2d/pisces/Renderer.java
author dlila
Tue, 08 Feb 2011 09:22:49 -0500
changeset 8131 e2932d8114cb
parent 7668 d4a77089c587
child 8748 99ac71f8ef92
permissions -rw-r--r--
7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer Summary: Optimized dashing, rasterizing, and the flow of transformed coordinates Reviewed-by: flar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6997
diff changeset
     2
 * Copyright (c) 2007, 2010, 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: 4244
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: 4244
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: 4244
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4244
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4244
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.pisces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    28
import sun.awt.geom.PathConsumer2D;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    29
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    30
final class Renderer implements PathConsumer2D {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    31
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    32
    private class ScanlineIterator {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    33
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    34
        private int[] crossings;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    35
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    36
        // crossing bounds. The bounds are not necessarily tight (the scan line
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    37
        // at minY, for example, might have no crossings). The x bounds will
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    38
        // be accumulated as crossings are computed.
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    39
        private final int maxY;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    40
        private int nextY;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    41
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    42
        // indices into the segment pointer lists. They indicate the "active"
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    43
        // sublist in the segment lists (the portion of the list that contains
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    44
        // all the segments that cross the next scan line).
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    45
        private int edgeCount;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    46
        private int[] edgePtrs;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    47
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    48
        private static final int INIT_CROSSINGS_SIZE = 10;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    49
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    50
        private ScanlineIterator() {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    51
            crossings = new int[INIT_CROSSINGS_SIZE];
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    52
            edgePtrs = new int[INIT_CROSSINGS_SIZE];
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    53
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    54
            // We don't care if we clip some of the line off with ceil, since
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    55
            // no scan line crossings will be eliminated (in fact, the ceil is
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    56
            // the y of the first scan line crossing).
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    57
            final int minY = getFirstScanLineCrossing();
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    58
            nextY = minY;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    59
            maxY = getScanLineCrossingEnd()-1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    60
            edgeCount = 0;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    61
        }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    62
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    63
        private int next() {
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    64
            int cury = nextY++;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    65
            int bucket = cury - boundsMinY;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    66
            int count = this.edgeCount;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    67
            int ptrs[] = this.edgePtrs;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    68
            int bucketcount = edgeBucketCounts[bucket];
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    69
            if ((bucketcount & 0x1) != 0) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    70
                int newCount = 0;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    71
                for (int i = 0; i < count; i++) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    72
                    int ecur = ptrs[i];
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    73
                    if (edges[ecur+YMAX] > cury) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    74
                        ptrs[newCount++] = ecur;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    75
                    }
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    76
                }
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    77
                count = newCount;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    78
            }
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    79
            ptrs = Helpers.widenArray(ptrs, count, bucketcount >> 1);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    80
            for (int ecur = edgeBuckets[bucket]; ecur != NULL; ecur = (int)edges[ecur+NEXT]) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    81
                ptrs[count++] = ecur;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    82
                // REMIND: Adjust start Y if necessary
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    83
            }
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    84
            this.edgePtrs = ptrs;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    85
            this.edgeCount = count;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    86
//            if ((count & 0x1) != 0) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    87
//                System.out.println("ODD NUMBER OF EDGES!!!!");
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    88
//            }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    89
            int xings[] = this.crossings;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    90
            if (xings.length < count) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    91
                this.crossings = xings = new int[ptrs.length];
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    92
            }
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    93
            for (int i = 0; i < count; i++) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    94
                int ecur = ptrs[i];
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    95
                float curx = edges[ecur+CURX];
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    96
                int cross = ((int) curx) << 1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    97
                edges[ecur+CURX] = curx + edges[ecur+SLOPE];
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    98
                if (edges[ecur+OR] > 0) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
    99
                    cross |= 1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   100
                }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   101
                int j = i;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   102
                while (--j >= 0) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   103
                    int jcross = xings[j];
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   104
                    if (jcross <= cross) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   105
                        break;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   106
                    }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   107
                    xings[j+1] = jcross;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   108
                    ptrs[j+1] = ptrs[j];
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   109
                }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   110
                xings[j+1] = cross;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   111
                ptrs[j+1] = ecur;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   112
            }
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   113
            return count;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   114
        }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   115
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   116
        private boolean hasNext() {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   117
            return nextY < maxY;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   118
        }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   119
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   120
        private int curY() {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   121
            return nextY - 1;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   122
        }
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   123
    }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   124
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   125
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   126
//////////////////////////////////////////////////////////////////////////////
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   127
//  EDGE LIST
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   128
//////////////////////////////////////////////////////////////////////////////
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   129
// TODO(maybe): very tempting to use fixed point here. A lot of opportunities
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   130
// for shifts and just removing certain operations altogether.
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   131
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   132
    // common to all types of input path segments.
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   133
    private static final int YMAX = 0;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   134
    private static final int CURX = 1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   135
    // NEXT and OR are meant to be indices into "int" fields, but arrays must
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   136
    // be homogenous, so every field is a float. However floats can represent
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   137
    // exactly up to 26 bit ints, so we're ok.
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   138
    private static final int OR   = 2;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   139
    private static final int SLOPE = 3;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   140
    private static final int NEXT = 4;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   141
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   142
    private float edgeMinY = Float.POSITIVE_INFINITY;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   143
    private float edgeMaxY = Float.NEGATIVE_INFINITY;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   144
    private float edgeMinX = Float.POSITIVE_INFINITY;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   145
    private float edgeMaxX = Float.NEGATIVE_INFINITY;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   146
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   147
    private static final int SIZEOF_EDGE = 5;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   148
    // don't just set NULL to -1, because we want NULL+NEXT to be negative.
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   149
    private static final int NULL = -SIZEOF_EDGE;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   150
    private float[] edges = null;
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   151
    private int[] edgeBuckets = null;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   152
    private int[] edgeBucketCounts = null; // 2*newedges + (1 if pruning needed)
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   153
    private int numEdges;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   154
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   155
    private static final float DEC_BND = 20f;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   156
    private static final float INC_BND = 8f;
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   157
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   158
    // each bucket is a linked list. this method adds eptr to the
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   159
    // start "bucket"th linked list.
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   160
    private void addEdgeToBucket(final int eptr, final int bucket) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   161
        edges[eptr+NEXT] = edgeBuckets[bucket];
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   162
        edgeBuckets[bucket] = eptr;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   163
        edgeBucketCounts[bucket] += 2;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   164
    }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   165
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   166
    // Flattens using adaptive forward differencing. This only carries out
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   167
    // one iteration of the AFD loop. All it does is update AFD variables (i.e.
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   168
    // X0, Y0, D*[X|Y], COUNT; not variables used for computing scanline crossings).
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   169
    private void quadBreakIntoLinesAndAdd(float x0, float y0,
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   170
                                          final Curve c,
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   171
                                          final float x2, final float y2) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   172
        final float QUAD_DEC_BND = 32;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   173
        final int countlg = 4;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   174
        int count = 1 << countlg;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   175
        int countsq = count * count;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   176
        float maxDD = Math.max(c.dbx / countsq, c.dby / countsq);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   177
        while (maxDD > QUAD_DEC_BND) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   178
            maxDD /= 4;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   179
            count <<= 1;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   180
        }
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   181
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   182
        countsq = count * count;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   183
        final float ddx = c.dbx / countsq;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   184
        final float ddy = c.dby / countsq;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   185
        float dx = c.bx / countsq + c.cx / count;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   186
        float dy = c.by / countsq + c.cy / count;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   187
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   188
        while (count-- > 1) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   189
            float x1 = x0 + dx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   190
            dx += ddx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   191
            float y1 = y0 + dy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   192
            dy += ddy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   193
            addLine(x0, y0, x1, y1);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   194
            x0 = x1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   195
            y0 = y1;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   196
        }
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   197
        addLine(x0, y0, x2, y2);
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   198
    }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   199
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   200
    // x0, y0 and x3,y3 are the endpoints of the curve. We could compute these
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   201
    // using c.xat(0),c.yat(0) and c.xat(1),c.yat(1), but this might introduce
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   202
    // numerical errors, and our callers already have the exact values.
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   203
    // Another alternative would be to pass all the control points, and call c.set
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   204
    // here, but then too many numbers are passed around.
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   205
    private void curveBreakIntoLinesAndAdd(float x0, float y0,
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   206
                                           final Curve c,
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   207
                                           final float x3, final float y3) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   208
        final int countlg = 3;
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   209
        int count = 1 << countlg;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   210
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   211
        // the dx and dy refer to forward differencing variables, not the last
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   212
        // coefficients of the "points" polynomial
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   213
        float dddx, dddy, ddx, ddy, dx, dy;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   214
        dddx = 2f * c.dax / (1 << (3 * countlg));
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   215
        dddy = 2f * c.day / (1 << (3 * countlg));
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   216
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   217
        ddx = dddx + c.dbx / (1 << (2 * countlg));
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   218
        ddy = dddy + c.dby / (1 << (2 * countlg));
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   219
        dx = c.ax / (1 << (3 * countlg)) + c.bx / (1 << (2 * countlg)) + c.cx / (1 << countlg);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   220
        dy = c.ay / (1 << (3 * countlg)) + c.by / (1 << (2 * countlg)) + c.cy / (1 << countlg);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   221
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   222
        // we use x0, y0 to walk the line
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   223
        float x1 = x0, y1 = y0;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   224
        while (count > 0) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   225
            while (Math.abs(ddx) > DEC_BND || Math.abs(ddy) > DEC_BND) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   226
                dddx /= 8;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   227
                dddy /= 8;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   228
                ddx = ddx/4 - dddx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   229
                ddy = ddy/4 - dddy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   230
                dx = (dx - ddx) / 2;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   231
                dy = (dy - ddy) / 2;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   232
                count <<= 1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   233
            }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   234
            // can only do this on even "count" values, because we must divide count by 2
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   235
            while (count % 2 == 0 && Math.abs(dx) <= INC_BND && Math.abs(dy) <= INC_BND) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   236
                dx = 2 * dx + ddx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   237
                dy = 2 * dy + ddy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   238
                ddx = 4 * (ddx + dddx);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   239
                ddy = 4 * (ddy + dddy);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   240
                dddx = 8 * dddx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   241
                dddy = 8 * dddy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   242
                count >>= 1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   243
            }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   244
            count--;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   245
            if (count > 0) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   246
                x1 += dx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   247
                dx += ddx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   248
                ddx += dddx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   249
                y1 += dy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   250
                dy += ddy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   251
                ddy += dddy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   252
            } else {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   253
                x1 = x3;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   254
                y1 = y3;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   255
            }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   256
            addLine(x0, y0, x1, y1);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   257
            x0 = x1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   258
            y0 = y1;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   259
        }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   260
    }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   261
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   262
    // Preconditions: y2 > y1 and the curve must cross some scanline
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   263
    // i.e.: y1 <= y < y2 for some y such that boundsMinY <= y < boundsMaxY
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   264
    private void addLine(float x1, float y1, float x2, float y2) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   265
        float or = 1; // orientation of the line. 1 if y increases, 0 otherwise.
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   266
        if (y2 < y1) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   267
            or = y2; // no need to declare a temp variable. We have or.
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   268
            y2 = y1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   269
            y1 = or;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   270
            or = x2;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   271
            x2 = x1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   272
            x1 = or;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   273
            or = 0;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   274
        }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   275
        final int firstCrossing = Math.max((int) Math.ceil(y1), boundsMinY);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   276
        final int lastCrossing = Math.min((int)Math.ceil(y2), boundsMaxY);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   277
        if (firstCrossing >= lastCrossing) {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   278
            return;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   279
        }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   280
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   281
        if (y1 < edgeMinY) { edgeMinY = y1; }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   282
        if (y2 > edgeMaxY) { edgeMaxY = y2; }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   283
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   284
        final float slope = (x2 - x1) / (y2 - y1);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   285
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   286
        if (slope > 0) { // <==> x1 < x2
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   287
            if (x1 < edgeMinX) { edgeMinX = x1; }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   288
            if (x2 > edgeMaxX) { edgeMaxX = x2; }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   289
        } else {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   290
            if (x2 < edgeMinX) { edgeMinX = x2; }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   291
            if (x1 > edgeMaxX) { edgeMaxX = x1; }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   292
        }
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   293
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   294
        final int ptr = numEdges * SIZEOF_EDGE;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   295
        edges = Helpers.widenArray(edges, ptr, SIZEOF_EDGE);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   296
        numEdges++;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   297
        edges[ptr+OR] = or;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   298
        edges[ptr+CURX] = x1 + (firstCrossing - y1) * slope;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   299
        edges[ptr+SLOPE] = slope;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   300
        edges[ptr+YMAX] = y2;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   301
        final int bucketIdx = firstCrossing - boundsMinY;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   302
        addEdgeToBucket(ptr, bucketIdx);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   303
        if (lastCrossing < boundsMaxY) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   304
            edgeBucketCounts[lastCrossing - boundsMinY] |= 1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   305
        }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   306
    }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   307
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   308
    // preconditions: should not be called before the last line has been added
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   309
    // to the edge list (even though it will return a correct answer at that
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   310
    // point in time, it's not meant to be used that way).
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   311
    private int getFirstScanLineCrossing() {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   312
        return Math.max(boundsMinY, (int)Math.ceil(edgeMinY));
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   313
    }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   314
    private int getScanLineCrossingEnd() {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   315
        return Math.min(boundsMaxY, (int)Math.ceil(edgeMaxY));
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   316
    }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   317
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   318
// END EDGE LIST
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   319
//////////////////////////////////////////////////////////////////////////////
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   320
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   321
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public static final int WIND_EVEN_ODD = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public static final int WIND_NON_ZERO = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    // Antialiasing
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   326
    final private int SUBPIXEL_LG_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   327
    final private int SUBPIXEL_LG_POSITIONS_Y;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   328
    final private int SUBPIXEL_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   329
    final private int SUBPIXEL_POSITIONS_Y;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   330
    final private int SUBPIXEL_MASK_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   331
    final private int SUBPIXEL_MASK_Y;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   332
    final int MAX_AA_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    // Cache to store RLE-encoded coverage mask of the current primitive
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   335
    PiscesCache cache;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   337
    // Bounds of the drawing region, at subpixel precision.
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   338
    private final int boundsMinX, boundsMinY, boundsMaxX, boundsMaxY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    // Current winding rule
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   341
    private final int windingRule;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    // Current drawing position, i.e., final point of last segment
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   344
    private float x0, y0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    // Position of most recent 'moveTo' command
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   347
    private float pix_sx0, pix_sy0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   349
    public Renderer(int subpixelLgPositionsX, int subpixelLgPositionsY,
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   350
                    int pix_boundsX, int pix_boundsY,
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   351
                    int pix_boundsWidth, int pix_boundsHeight,
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   352
                    int windingRule)
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   353
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        this.SUBPIXEL_LG_POSITIONS_X = subpixelLgPositionsX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        this.SUBPIXEL_LG_POSITIONS_Y = subpixelLgPositionsY;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   356
        this.SUBPIXEL_MASK_X = (1 << (SUBPIXEL_LG_POSITIONS_X)) - 1;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   357
        this.SUBPIXEL_MASK_Y = (1 << (SUBPIXEL_LG_POSITIONS_Y)) - 1;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   358
        this.SUBPIXEL_POSITIONS_X = 1 << (SUBPIXEL_LG_POSITIONS_X);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   359
        this.SUBPIXEL_POSITIONS_Y = 1 << (SUBPIXEL_LG_POSITIONS_Y);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   360
        this.MAX_AA_ALPHA = (SUBPIXEL_POSITIONS_X * SUBPIXEL_POSITIONS_Y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   362
        this.windingRule = windingRule;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   364
        this.boundsMinX = pix_boundsX * SUBPIXEL_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   365
        this.boundsMinY = pix_boundsY * SUBPIXEL_POSITIONS_Y;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   366
        this.boundsMaxX = (pix_boundsX + pix_boundsWidth) * SUBPIXEL_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   367
        this.boundsMaxY = (pix_boundsY + pix_boundsHeight) * SUBPIXEL_POSITIONS_Y;
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   368
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   369
        edgeBuckets = new int[boundsMaxY - boundsMinY];
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   370
        java.util.Arrays.fill(edgeBuckets, NULL);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   371
        edgeBucketCounts = new int[edgeBuckets.length];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   374
    private float tosubpixx(float pix_x) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   375
        return pix_x * SUBPIXEL_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   376
    }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   377
    private float tosubpixy(float pix_y) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   378
        return pix_y * SUBPIXEL_POSITIONS_Y;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   381
    public void moveTo(float pix_x0, float pix_y0) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   382
        closePath();
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   383
        this.pix_sx0 = pix_x0;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   384
        this.pix_sy0 = pix_y0;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   385
        this.y0 = tosubpixy(pix_y0);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   386
        this.x0 = tosubpixx(pix_x0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   389
    public void lineTo(float pix_x1, float pix_y1) {
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   390
        float x1 = tosubpixx(pix_x1);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   391
        float y1 = tosubpixy(pix_y1);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   392
        addLine(x0, y0, x1, y1);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   393
        x0 = x1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   394
        y0 = y1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   397
    Curve c = new Curve();
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   398
    @Override public void curveTo(float x1, float y1,
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   399
                                  float x2, float y2,
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   400
                                  float x3, float y3)
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   401
    {
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   402
        final float xe = tosubpixx(x3);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   403
        final float ye = tosubpixy(y3);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   404
        c.set(x0, y0, tosubpixx(x1), tosubpixy(y1), tosubpixx(x2), tosubpixy(y2), xe, ye);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   405
        curveBreakIntoLinesAndAdd(x0, y0, c, xe, ye);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   406
        x0 = xe;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   407
        y0 = ye;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   408
    }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   409
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   410
    @Override public void quadTo(float x1, float y1, float x2, float y2) {
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   411
        final float xe = tosubpixx(x2);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   412
        final float ye = tosubpixy(y2);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   413
        c.set(x0, y0, tosubpixx(x1), tosubpixy(y1), xe, ye);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   414
        quadBreakIntoLinesAndAdd(x0, y0, c, xe, ye);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   415
        x0 = xe;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   416
        y0 = ye;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   417
    }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   418
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   419
    public void closePath() {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   420
        // lineTo expects its input in pixel coordinates.
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   421
        lineTo(pix_sx0, pix_sy0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   424
    public void pathDone() {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   425
        closePath();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   428
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   429
    @Override
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   430
    public long getNativeConsumer() {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   431
        throw new InternalError("Renderer does not use a native consumer.");
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   432
    }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   433
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   434
    private void _endRendering(final int pix_bboxx0, final int pix_bboxy0,
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   435
                               final int pix_bboxx1, final int pix_bboxy1)
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   436
    {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   437
        // Mask to determine the relevant bit of the crossing sum
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   438
        // 0x1 if EVEN_ODD, all bits if NON_ZERO
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   439
        int mask = (windingRule == WIND_EVEN_ODD) ? 0x1 : ~0x0;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   440
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   441
        // add 2 to better deal with the last pixel in a pixel row.
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   442
        int width = pix_bboxx1 - pix_bboxx0;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   443
        int[] alpha = new int[width+2];
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   444
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   445
        int bboxx0 = pix_bboxx0 << SUBPIXEL_LG_POSITIONS_X;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   446
        int bboxx1 = pix_bboxx1 << SUBPIXEL_LG_POSITIONS_X;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   448
        // Now we iterate through the scanlines. We must tell emitRow the coord
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   449
        // of the first non-transparent pixel, so we must keep accumulators for
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   450
        // the first and last pixels of the section of the current pixel row
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   451
        // that we will emit.
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   452
        // We also need to accumulate pix_bbox*, but the iterator does it
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   453
        // for us. We will just get the values from it once this loop is done
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   454
        int pix_maxX = Integer.MIN_VALUE;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   455
        int pix_minX = Integer.MAX_VALUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   457
        int y = boundsMinY; // needs to be declared here so we emit the last row properly.
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   458
        ScanlineIterator it = this.new ScanlineIterator();
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   459
        for ( ; it.hasNext(); ) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   460
            int numCrossings = it.next();
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   461
            int[] crossings = it.crossings;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   462
            y = it.curY();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   464
            if (numCrossings > 0) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   465
                int lowx = crossings[0] >> 1;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   466
                int highx = crossings[numCrossings - 1] >> 1;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   467
                int x0 = Math.max(lowx, bboxx0);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   468
                int x1 = Math.min(highx, bboxx1);
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   469
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   470
                pix_minX = Math.min(pix_minX, x0 >> SUBPIXEL_LG_POSITIONS_X);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   471
                pix_maxX = Math.max(pix_maxX, x1 >> SUBPIXEL_LG_POSITIONS_X);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   474
            int sum = 0;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   475
            int prev = bboxx0;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   476
            for (int i = 0; i < numCrossings; i++) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   477
                int curxo = crossings[i];
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   478
                int curx = curxo >> 1;
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   479
                // to turn {0, 1} into {-1, 1}, multiply by 2 and subtract 1.
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   480
                int crorientation = ((curxo & 0x1) << 1) -1;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   481
                if ((sum & mask) != 0) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   482
                    int x0 = Math.max(prev, bboxx0);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   483
                    int x1 = Math.min(curx, bboxx1);
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   484
                    if (x0 < x1) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   485
                        x0 -= bboxx0; // turn x0, x1 from coords to indeces
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   486
                        x1 -= bboxx0; // in the alpha array.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   488
                        int pix_x = x0 >> SUBPIXEL_LG_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   489
                        int pix_xmaxm1 = (x1 - 1) >> SUBPIXEL_LG_POSITIONS_X;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   491
                        if (pix_x == pix_xmaxm1) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   492
                            // Start and end in same pixel
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   493
                            alpha[pix_x] += (x1 - x0);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   494
                            alpha[pix_x+1] -= (x1 - x0);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   495
                        } else {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   496
                            int pix_xmax = x1 >> SUBPIXEL_LG_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   497
                            alpha[pix_x] += SUBPIXEL_POSITIONS_X - (x0 & SUBPIXEL_MASK_X);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   498
                            alpha[pix_x+1] += (x0 & SUBPIXEL_MASK_X);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   499
                            alpha[pix_xmax] -= SUBPIXEL_POSITIONS_X - (x1 & SUBPIXEL_MASK_X);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   500
                            alpha[pix_xmax+1] -= (x1 & SUBPIXEL_MASK_X);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   501
                        }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   502
                    }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   503
                }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   504
                sum += crorientation;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   505
                prev = curx;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   506
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   508
            // even if this last row had no crossings, alpha will be zeroed
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   509
            // from the last emitRow call. But this doesn't matter because
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   510
            // maxX < minX, so no row will be emitted to the cache.
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   511
            if ((y & SUBPIXEL_MASK_Y) == SUBPIXEL_MASK_Y) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   512
                emitRow(alpha, y >> SUBPIXEL_LG_POSITIONS_Y, pix_minX, pix_maxX);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   513
                pix_minX = Integer.MAX_VALUE;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   514
                pix_maxX = Integer.MIN_VALUE;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   515
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   518
        // Emit final row
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   519
        if (pix_maxX >= pix_minX) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   520
            emitRow(alpha, y >> SUBPIXEL_LG_POSITIONS_Y, pix_minX, pix_maxX);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   522
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    public void endRendering() {
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   525
        int spminX = Math.max((int)Math.ceil(edgeMinX), boundsMinX);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   526
        int spmaxX = Math.min((int)Math.ceil(edgeMaxX), boundsMaxX);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   527
        int spminY = Math.max((int)Math.ceil(edgeMinY), boundsMinY);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   528
        int spmaxY = Math.min((int)Math.ceil(edgeMaxY), boundsMaxY);
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   529
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   530
        int pminX = spminX >> SUBPIXEL_LG_POSITIONS_X;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   531
        int pmaxX = (spmaxX + SUBPIXEL_MASK_X) >> SUBPIXEL_LG_POSITIONS_X;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   532
        int pminY = spminY >> SUBPIXEL_LG_POSITIONS_Y;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   533
        int pmaxY = (spmaxY + SUBPIXEL_MASK_Y) >> SUBPIXEL_LG_POSITIONS_Y;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   534
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   535
        if (pminX > pmaxX || pminY > pmaxY) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   536
            this.cache = new PiscesCache(boundsMinX >> SUBPIXEL_LG_POSITIONS_X,
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   537
                                         boundsMinY >> SUBPIXEL_LG_POSITIONS_Y,
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   538
                                         boundsMaxX >> SUBPIXEL_LG_POSITIONS_X,
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   539
                                         boundsMaxY >> SUBPIXEL_LG_POSITIONS_Y);
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   540
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   543
        this.cache = new PiscesCache(pminX, pminY, pmaxX, pmaxY);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   544
        _endRendering(pminX, pminY, pmaxX, pmaxY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   547
    public PiscesCache getCache() {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   548
        if (cache == null) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   549
            throw new InternalError("cache not yet initialized");
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   550
        }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   551
        return cache;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   554
    private void emitRow(int[] alphaRow, int pix_y, int pix_from, int pix_to) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        // Copy rowAA data into the cache if one is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (cache != null) {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   557
            if (pix_to >= pix_from) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   558
                cache.startRow(pix_y, pix_from);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   560
                // Perform run-length encoding and store results in the cache
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   561
                int from = pix_from - cache.bboxX0;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   562
                int to = pix_to - cache.bboxX0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                int runLen = 1;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   565
                int startVal = alphaRow[from];
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   566
                for (int i = from + 1; i <= to; i++) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   567
                    int nextVal = startVal + alphaRow[i];
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   568
                    if (nextVal == startVal) {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   569
                        runLen++;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                        cache.addRLERun(startVal, runLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                        runLen = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                        startVal = nextVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                cache.addRLERun(startVal, runLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   579
        java.util.Arrays.fill(alphaRow, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
}