jdk/src/share/classes/sun/java2d/pisces/Renderer.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8748 99ac71f8ef92
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8748
diff changeset
     2
 * Copyright (c) 2007, 2011, 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
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
    50
        // Preconditions: Only subpixel scanlines in the range
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
    51
        // (start <= subpixel_y <= end) will be evaluated. No
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
    52
        // edge may have a valid (i.e. inside the supplied clip)
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
    53
        // crossing that would be generated outside that range.
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
    54
        private ScanlineIterator(int start, int end) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
    55
            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
    56
            edgePtrs = new int[INIT_CROSSINGS_SIZE];
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
    57
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
    58
            nextY = start;
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
    59
            maxY = end;
8131
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;
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   151
    private static final int INIT_NUM_EDGES = 8;
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   152
    private int[] edgeBuckets = null;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   153
    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
   154
    private int numEdges;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   155
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   156
    private static final float DEC_BND = 20f;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   157
    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
   158
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   159
    // each bucket is a linked list. this method adds eptr to the
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   160
    // start of the "bucket"th linked list.
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   161
    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
   162
        edges[eptr+NEXT] = edgeBuckets[bucket];
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   163
        edgeBuckets[bucket] = eptr;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   164
        edgeBucketCounts[bucket] += 2;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   165
    }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   166
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   167
    // 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
   168
    // 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
   169
    // 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
   170
    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
   171
                                          final Curve c,
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   172
                                          final float x2, final float y2)
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   173
    {
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   174
        final float QUAD_DEC_BND = 32;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   175
        final int countlg = 4;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   176
        int count = 1 << countlg;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   177
        int countsq = count * count;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   178
        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
   179
        while (maxDD > QUAD_DEC_BND) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   180
            maxDD /= 4;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   181
            count <<= 1;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   182
        }
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   183
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   184
        countsq = count * count;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   185
        final float ddx = c.dbx / countsq;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   186
        final float ddy = c.dby / countsq;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   187
        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
   188
        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
   189
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   190
        while (count-- > 1) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   191
            float x1 = x0 + dx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   192
            dx += ddx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   193
            float y1 = y0 + dy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   194
            dy += ddy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   195
            addLine(x0, y0, x1, y1);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   196
            x0 = x1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   197
            y0 = y1;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   198
        }
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   199
        addLine(x0, y0, x2, y2);
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   200
    }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   201
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   202
    // 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
   203
    // 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
   204
    // 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
   205
    // 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
   206
    // 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
   207
    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
   208
                                           final Curve c,
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   209
                                           final float x3, final float y3)
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   210
    {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   211
        final int countlg = 3;
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   212
        int count = 1 << countlg;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   213
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   214
        // 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
   215
        // coefficients of the "points" polynomial
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   216
        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
   217
        dddx = 2f * c.dax / (1 << (3 * countlg));
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   218
        dddy = 2f * c.day / (1 << (3 * countlg));
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   219
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   220
        ddx = dddx + c.dbx / (1 << (2 * countlg));
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   221
        ddy = dddy + c.dby / (1 << (2 * countlg));
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   222
        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
   223
        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
   224
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   225
        // 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
   226
        float x1 = x0, y1 = y0;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   227
        while (count > 0) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   228
            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
   229
                dddx /= 8;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   230
                dddy /= 8;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   231
                ddx = ddx/4 - dddx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   232
                ddy = ddy/4 - dddy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   233
                dx = (dx - ddx) / 2;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   234
                dy = (dy - ddy) / 2;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   235
                count <<= 1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   236
            }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   237
            // 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
   238
            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
   239
                dx = 2 * dx + ddx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   240
                dy = 2 * dy + ddy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   241
                ddx = 4 * (ddx + dddx);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   242
                ddy = 4 * (ddy + dddy);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   243
                dddx = 8 * dddx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   244
                dddy = 8 * dddy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   245
                count >>= 1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   246
            }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   247
            count--;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   248
            if (count > 0) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   249
                x1 += dx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   250
                dx += ddx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   251
                ddx += dddx;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   252
                y1 += dy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   253
                dy += ddy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   254
                ddy += dddy;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   255
            } else {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   256
                x1 = x3;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   257
                y1 = y3;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   258
            }
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   259
            addLine(x0, y0, x1, y1);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   260
            x0 = x1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   261
            y0 = y1;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   262
        }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   263
    }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   264
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   265
    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
   266
        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
   267
        if (y2 < y1) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   268
            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
   269
            y2 = y1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   270
            y1 = or;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   271
            or = x2;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   272
            x2 = x1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   273
            x1 = or;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   274
            or = 0;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   275
        }
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   276
        final int firstCrossing = Math.max((int)Math.ceil(y1), boundsMinY);
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   277
        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
   278
        if (firstCrossing >= lastCrossing) {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   279
            return;
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;
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   300
        edges[ptr+YMAX] = lastCrossing;
8131
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);
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   303
        edgeBucketCounts[lastCrossing - boundsMinY] |= 1;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   304
    }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   305
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   306
// END EDGE LIST
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   307
//////////////////////////////////////////////////////////////////////////////
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   308
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   309
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public static final int WIND_EVEN_ODD = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public static final int WIND_NON_ZERO = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    // Antialiasing
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   314
    final private int SUBPIXEL_LG_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   315
    final private int SUBPIXEL_LG_POSITIONS_Y;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   316
    final private int SUBPIXEL_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   317
    final private int SUBPIXEL_POSITIONS_Y;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   318
    final private int SUBPIXEL_MASK_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   319
    final private int SUBPIXEL_MASK_Y;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   320
    final int MAX_AA_ALPHA;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    // 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
   323
    PiscesCache cache;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   325
    // 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
   326
    private final int boundsMinX, boundsMinY, boundsMaxX, boundsMaxY;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    // Current winding rule
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   329
    private final int windingRule;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    // 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
   332
    private float x0, y0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    // Position of most recent 'moveTo' command
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   335
    private float pix_sx0, pix_sy0;
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
    public Renderer(int subpixelLgPositionsX, int subpixelLgPositionsY,
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   338
                    int pix_boundsX, int pix_boundsY,
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   339
                    int pix_boundsWidth, int pix_boundsHeight,
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   340
                    int windingRule)
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   341
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        this.SUBPIXEL_LG_POSITIONS_X = subpixelLgPositionsX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        this.SUBPIXEL_LG_POSITIONS_Y = subpixelLgPositionsY;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   344
        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
   345
        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
   346
        this.SUBPIXEL_POSITIONS_X = 1 << (SUBPIXEL_LG_POSITIONS_X);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   347
        this.SUBPIXEL_POSITIONS_Y = 1 << (SUBPIXEL_LG_POSITIONS_Y);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   348
        this.MAX_AA_ALPHA = (SUBPIXEL_POSITIONS_X * SUBPIXEL_POSITIONS_Y);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   350
        this.windingRule = windingRule;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   352
        this.boundsMinX = pix_boundsX * SUBPIXEL_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   353
        this.boundsMinY = pix_boundsY * SUBPIXEL_POSITIONS_Y;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   354
        this.boundsMaxX = (pix_boundsX + pix_boundsWidth) * SUBPIXEL_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   355
        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
   356
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   357
        edges = new float[INIT_NUM_EDGES * SIZEOF_EDGE];
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   358
        numEdges = 0;
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   359
        edgeBuckets = new int[boundsMaxY - boundsMinY];
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   360
        java.util.Arrays.fill(edgeBuckets, NULL);
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   361
        edgeBucketCounts = new int[edgeBuckets.length + 1];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
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
    private float tosubpixx(float pix_x) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   365
        return pix_x * SUBPIXEL_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   366
    }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   367
    private float tosubpixy(float pix_y) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   368
        return pix_y * SUBPIXEL_POSITIONS_Y;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   371
    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
   372
        closePath();
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   373
        this.pix_sx0 = pix_x0;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   374
        this.pix_sy0 = pix_y0;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   375
        this.y0 = tosubpixy(pix_y0);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   376
        this.x0 = tosubpixx(pix_x0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   379
    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
   380
        float x1 = tosubpixx(pix_x1);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   381
        float y1 = tosubpixy(pix_y1);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   382
        addLine(x0, y0, x1, y1);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   383
        x0 = x1;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   384
        y0 = y1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   387
    private Curve c = new Curve();
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   388
    @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
   389
                                  float x2, float y2,
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   390
                                  float x3, float y3)
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   391
    {
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   392
        final float xe = tosubpixx(x3);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   393
        final float ye = tosubpixy(y3);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   394
        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
   395
        curveBreakIntoLinesAndAdd(x0, y0, c, xe, ye);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   396
        x0 = xe;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   397
        y0 = ye;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   398
    }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   399
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   400
    @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
   401
        final float xe = tosubpixx(x2);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   402
        final float ye = tosubpixy(y2);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   403
        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
   404
        quadBreakIntoLinesAndAdd(x0, y0, c, xe, ye);
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   405
        x0 = xe;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   406
        y0 = ye;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   407
    }
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
    public void closePath() {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   410
        // lineTo expects its input in pixel coordinates.
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   411
        lineTo(pix_sx0, pix_sy0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   414
    public void pathDone() {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   415
        closePath();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
6997
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
    @Override
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   420
    public long getNativeConsumer() {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   421
        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
   422
    }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   423
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   424
    private void _endRendering(final int pix_bboxx0, final int pix_bboxx1,
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   425
                               int ymin, int ymax)
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   426
    {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   427
        // 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
   428
        // 0x1 if EVEN_ODD, all bits if NON_ZERO
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   429
        int mask = (windingRule == WIND_EVEN_ODD) ? 0x1 : ~0x0;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   430
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   431
        // 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
   432
        int width = pix_bboxx1 - pix_bboxx0;
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   433
        int[] alpha = new int[width+2];
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   434
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   435
        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
   436
        int bboxx1 = pix_bboxx1 << SUBPIXEL_LG_POSITIONS_X;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   438
        // 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
   439
        // 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
   440
        // 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
   441
        // that we will emit.
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   442
        // 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
   443
        // 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
   444
        int pix_maxX = Integer.MIN_VALUE;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   445
        int pix_minX = Integer.MAX_VALUE;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   447
        int y = boundsMinY; // needs to be declared here so we emit the last row properly.
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   448
        ScanlineIterator it = this.new ScanlineIterator(ymin, ymax);
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   449
        for ( ; it.hasNext(); ) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   450
            int numCrossings = it.next();
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   451
            int[] crossings = it.crossings;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   452
            y = it.curY();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   454
            if (numCrossings > 0) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   455
                int lowx = crossings[0] >> 1;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   456
                int highx = crossings[numCrossings - 1] >> 1;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   457
                int x0 = Math.max(lowx, bboxx0);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   458
                int x1 = Math.min(highx, bboxx1);
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   459
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   460
                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
   461
                pix_maxX = Math.max(pix_maxX, x1 >> SUBPIXEL_LG_POSITIONS_X);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            }
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
            int sum = 0;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   465
            int prev = bboxx0;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   466
            for (int i = 0; i < numCrossings; i++) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   467
                int curxo = crossings[i];
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   468
                int curx = curxo >> 1;
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   469
                // to turn {0, 1} into {-1, 1}, multiply by 2 and subtract 1.
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   470
                int crorientation = ((curxo & 0x1) << 1) - 1;
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   471
                if ((sum & mask) != 0) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   472
                    int x0 = Math.max(prev, bboxx0);
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   473
                    int x1 = Math.min(curx, bboxx1);
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   474
                    if (x0 < x1) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   475
                        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
   476
                        x1 -= bboxx0; // in the alpha array.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   478
                        int pix_x = x0 >> SUBPIXEL_LG_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   479
                        int pix_xmaxm1 = (x1 - 1) >> SUBPIXEL_LG_POSITIONS_X;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   481
                        if (pix_x == pix_xmaxm1) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   482
                            // Start and end in same pixel
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   483
                            alpha[pix_x] += (x1 - x0);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   484
                            alpha[pix_x+1] -= (x1 - x0);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   485
                        } else {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   486
                            int pix_xmax = x1 >> SUBPIXEL_LG_POSITIONS_X;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   487
                            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
   488
                            alpha[pix_x+1] += (x0 & SUBPIXEL_MASK_X);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   489
                            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
   490
                            alpha[pix_xmax+1] -= (x1 & SUBPIXEL_MASK_X);
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   491
                        }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   492
                    }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   493
                }
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   494
                sum += crorientation;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   495
                prev = curx;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   496
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   498
            // 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
   499
            // 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
   500
            // 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
   501
            if ((y & SUBPIXEL_MASK_Y) == SUBPIXEL_MASK_Y) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   502
                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
   503
                pix_minX = Integer.MAX_VALUE;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   504
                pix_maxX = Integer.MIN_VALUE;
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   505
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   508
        // Emit final row
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   509
        if (pix_maxX >= pix_minX) {
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   510
            emitRow(alpha, y >> SUBPIXEL_LG_POSITIONS_Y, pix_minX, pix_maxX);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   512
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    public void endRendering() {
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   515
        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
   516
        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
   517
        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
   518
        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
   519
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   520
        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
   521
        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
   522
        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
   523
        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
   524
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   525
        if (pminX > pmaxX || pminY > pmaxY) {
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   526
            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
   527
                                         boundsMinY >> SUBPIXEL_LG_POSITIONS_Y,
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   528
                                         boundsMaxX >> SUBPIXEL_LG_POSITIONS_X,
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   529
                                         boundsMaxY >> SUBPIXEL_LG_POSITIONS_Y);
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   530
            return;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
8131
e2932d8114cb 7016856: dashing performance was reduced during latest changes to the OpenJDK rasterizer
dlila
parents: 7668
diff changeset
   533
        this.cache = new PiscesCache(pminX, pminY, pmaxX, pmaxY);
8748
99ac71f8ef92 7019861: Last scanline is skipped in pisces.Renderer.
dlila
parents: 8131
diff changeset
   534
        _endRendering(pminX, pmaxX, spminY, spmaxY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   537
    public PiscesCache getCache() {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   538
        if (cache == null) {
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   539
            throw new InternalError("cache not yet initialized");
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   540
        }
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   541
        return cache;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   544
    private void emitRow(int[] alphaRow, int pix_y, int pix_from, int pix_to) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        // Copy rowAA data into the cache if one is present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        if (cache != null) {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   547
            if (pix_to >= pix_from) {
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   548
                cache.startRow(pix_y, pix_from);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   550
                // 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
   551
                int from = pix_from - cache.bboxX0;
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   552
                int to = pix_to - cache.bboxX0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                int runLen = 1;
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   555
                int startVal = alphaRow[from];
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   556
                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
   557
                    int nextVal = startVal + alphaRow[i];
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   558
                    if (nextVal == startVal) {
6284
695b3c6241c8 6967436: lines longer than 2^15 can fill window.
dlila
parents: 5506
diff changeset
   559
                        runLen++;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                        cache.addRLERun(startVal, runLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                        runLen = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                        startVal = nextVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                cache.addRLERun(startVal, runLen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
6997
3642614e2282 6967434: Round joins/caps of scaled up lines have poor quality.
dlila
parents: 6284
diff changeset
   569
        java.util.Arrays.fill(alphaRow, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
}