src/java.desktop/share/classes/sun/java2d/marlin/Helpers.java
author lbourges
Mon, 11 Dec 2017 21:14:43 +0100
changeset 48284 fd7fbc929001
parent 47216 71c04702a3d5
child 49496 1ea202af7a97
permissions -rw-r--r--
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip Summary: upgrade to Marlin 0.8.2 providing efficient path clipping (Stroker and Filler) Reviewed-by: prr, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     1
/*
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
     2
 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     4
 *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    10
 *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    15
 * accompanied this code).
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    16
 *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    20
 *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    23
 * questions.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    24
 */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    25
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    26
package sun.java2d.marlin;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    27
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    28
import static java.lang.Math.PI;
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    29
import java.util.Arrays;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    30
import sun.awt.geom.PathConsumer2D;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    31
import sun.java2d.marlin.stats.Histogram;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    32
import sun.java2d.marlin.stats.StatLong;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    33
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    34
final class Helpers implements MarlinConst {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    35
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    36
    private Helpers() {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    37
        throw new Error("This is a non instantiable class");
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    38
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    39
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    40
    static boolean within(final float x, final float y, final float err) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    41
        final float d = y - x;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    42
        return (d <= err && d >= -err);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    43
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    44
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    45
    static boolean within(final double x, final double y, final double err) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    46
        final double d = y - x;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    47
        return (d <= err && d >= -err);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    48
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    49
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    50
    static int quadraticRoots(final float a, final float b,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    51
                              final float c, float[] zeroes, final int off)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    52
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    53
        int ret = off;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    54
        float t;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    55
        if (a != 0.0f) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    56
            final float dis = b*b - 4*a*c;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    57
            if (dis > 0.0f) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    58
                final float sqrtDis = (float) Math.sqrt(dis);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    59
                // depending on the sign of b we use a slightly different
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    60
                // algorithm than the traditional one to find one of the roots
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    61
                // so we can avoid adding numbers of different signs (which
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    62
                // might result in loss of precision).
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    63
                if (b >= 0.0f) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    64
                    zeroes[ret++] = (2.0f * c) / (-b - sqrtDis);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    65
                    zeroes[ret++] = (-b - sqrtDis) / (2.0f * a);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    66
                } else {
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    67
                    zeroes[ret++] = (-b + sqrtDis) / (2.0f * a);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    68
                    zeroes[ret++] = (2.0f * c) / (-b + sqrtDis);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    69
                }
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    70
            } else if (dis == 0.0f) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    71
                t = (-b) / (2.0f * a);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    72
                zeroes[ret++] = t;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    73
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    74
        } else {
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    75
            if (b != 0.0f) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    76
                t = (-c) / b;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    77
                zeroes[ret++] = t;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    78
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    79
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    80
        return ret - off;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    81
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    82
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    83
    // find the roots of g(t) = d*t^3 + a*t^2 + b*t + c in [A,B)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    84
    static int cubicRootsInAB(float d, float a, float b, float c,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    85
                              float[] pts, final int off,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    86
                              final float A, final float B)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    87
    {
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
    88
        if (d == 0.0f) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    89
            int num = quadraticRoots(a, b, c, pts, off);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    90
            return filterOutNotInAB(pts, off, num, A, B) - off;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    91
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    92
        // From Graphics Gems:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    93
        // http://tog.acm.org/resources/GraphicsGems/gems/Roots3And4.c
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    94
        // (also from awt.geom.CubicCurve2D. But here we don't need as
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    95
        // much accuracy and we don't want to create arrays so we use
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    96
        // our own customized version).
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    97
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    98
        // normal form: x^3 + ax^2 + bx + c = 0
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    99
        a /= d;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   100
        b /= d;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   101
        c /= d;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   102
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   103
        //  substitute x = y - A/3 to eliminate quadratic term:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   104
        //     x^3 +Px + Q = 0
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   105
        //
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   106
        // Since we actually need P/3 and Q/2 for all of the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   107
        // calculations that follow, we will calculate
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   108
        // p = P/3
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   109
        // q = Q/2
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   110
        // instead and use those values for simplicity of the code.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   111
        double sq_A = a * a;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   112
        double p = (1.0d/3.0d) * ((-1.0d/3.0d) * sq_A + b);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   113
        double q = (1.0d/2.0d) * ((2.0d/27.0d) * a * sq_A - (1.0d/3.0d) * a * b + c);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   114
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   115
        // use Cardano's formula
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   116
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   117
        double cb_p = p * p * p;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   118
        double D = q * q + cb_p;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   119
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   120
        int num;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   121
        if (D < 0.0d) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   122
            // see: http://en.wikipedia.org/wiki/Cubic_function#Trigonometric_.28and_hyperbolic.29_method
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   123
            final double phi = (1.0d/3.0d) * Math.acos(-q / Math.sqrt(-cb_p));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   124
            final double t = 2.0d * Math.sqrt(-p);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   125
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   126
            pts[ off+0 ] = (float) ( t * Math.cos(phi));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   127
            pts[ off+1 ] = (float) (-t * Math.cos(phi + (PI / 3.0d)));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   128
            pts[ off+2 ] = (float) (-t * Math.cos(phi - (PI / 3.0d)));
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   129
            num = 3;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   130
        } else {
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   131
            final double sqrt_D = Math.sqrt(D);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   132
            final double u =   Math.cbrt(sqrt_D - q);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   133
            final double v = - Math.cbrt(sqrt_D + q);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   134
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   135
            pts[ off ] = (float) (u + v);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   136
            num = 1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   137
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   138
            if (within(D, 0.0d, 1e-8d)) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   139
                pts[off+1] = -(pts[off] / 2.0f);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   140
                num = 2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   141
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   142
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   143
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   144
        final float sub = (1.0f/3.0f) * a;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   145
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   146
        for (int i = 0; i < num; ++i) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   147
            pts[ off+i ] -= sub;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   148
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   149
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   150
        return filterOutNotInAB(pts, off, num, A, B) - off;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   151
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   152
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   153
    static float evalCubic(final float a, final float b,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   154
                           final float c, final float d,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   155
                           final float t)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   156
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   157
        return t * (t * (t * a + b) + c) + d;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   158
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   159
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   160
    static float evalQuad(final float a, final float b,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   161
                          final float c, final float t)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   162
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   163
        return t * (t * a + b) + c;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   164
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   165
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   166
    // returns the index 1 past the last valid element remaining after filtering
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   167
    static int filterOutNotInAB(float[] nums, final int off, final int len,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   168
                                final float a, final float b)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   169
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   170
        int ret = off;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   171
        for (int i = off, end = off + len; i < end; i++) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   172
            if (nums[i] >= a && nums[i] < b) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   173
                nums[ret++] = nums[i];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   174
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   175
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   176
        return ret;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   177
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   178
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   179
    static float linelen(float x1, float y1, float x2, float y2) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   180
        final float dx = x2 - x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   181
        final float dy = y2 - y1;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   182
        return (float) Math.sqrt(dx*dx + dy*dy);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   183
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   184
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   185
    static void subdivide(float[] src, int srcoff, float[] left, int leftoff,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   186
                          float[] right, int rightoff, int type)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   187
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   188
        switch(type) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   189
        case 6:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   190
            Helpers.subdivideQuad(src, srcoff, left, leftoff, right, rightoff);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   191
            return;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   192
        case 8:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   193
            Helpers.subdivideCubic(src, srcoff, left, leftoff, right, rightoff);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   194
            return;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   195
        default:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   196
            throw new InternalError("Unsupported curve type");
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   197
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   198
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   199
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   200
    static void isort(float[] a, int off, int len) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   201
        for (int i = off + 1, end = off + len; i < end; i++) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   202
            float ai = a[i];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   203
            int j = i - 1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   204
            for (; j >= off && a[j] > ai; j--) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   205
                a[j+1] = a[j];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   206
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   207
            a[j+1] = ai;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   208
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   209
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   210
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   211
    // Most of these are copied from classes in java.awt.geom because we need
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   212
    // both single and double precision variants of these functions, and Line2D,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   213
    // CubicCurve2D, QuadCurve2D don't provide them.
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   214
    /**
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   215
     * Subdivides the cubic curve specified by the coordinates
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   216
     * stored in the <code>src</code> array at indices <code>srcoff</code>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   217
     * through (<code>srcoff</code>&nbsp;+&nbsp;7) and stores the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   218
     * resulting two subdivided curves into the two result arrays at the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   219
     * corresponding indices.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   220
     * Either or both of the <code>left</code> and <code>right</code>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   221
     * arrays may be <code>null</code> or a reference to the same array
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   222
     * as the <code>src</code> array.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   223
     * Note that the last point in the first subdivided curve is the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   224
     * same as the first point in the second subdivided curve. Thus,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   225
     * it is possible to pass the same array for <code>left</code>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   226
     * and <code>right</code> and to use offsets, such as <code>rightoff</code>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   227
     * equals (<code>leftoff</code> + 6), in order
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   228
     * to avoid allocating extra storage for this common point.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   229
     * @param src the array holding the coordinates for the source curve
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   230
     * @param srcoff the offset into the array of the beginning of the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   231
     * the 6 source coordinates
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   232
     * @param left the array for storing the coordinates for the first
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   233
     * half of the subdivided curve
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   234
     * @param leftoff the offset into the array of the beginning of the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   235
     * the 6 left coordinates
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   236
     * @param right the array for storing the coordinates for the second
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   237
     * half of the subdivided curve
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   238
     * @param rightoff the offset into the array of the beginning of the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   239
     * the 6 right coordinates
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   240
     * @since 1.7
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   241
     */
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   242
    static void subdivideCubic(float[] src, int srcoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   243
                               float[] left, int leftoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   244
                               float[] right, int rightoff)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   245
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   246
        float x1 = src[srcoff + 0];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   247
        float y1 = src[srcoff + 1];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   248
        float ctrlx1 = src[srcoff + 2];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   249
        float ctrly1 = src[srcoff + 3];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   250
        float ctrlx2 = src[srcoff + 4];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   251
        float ctrly2 = src[srcoff + 5];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   252
        float x2 = src[srcoff + 6];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   253
        float y2 = src[srcoff + 7];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   254
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   255
            left[leftoff + 0] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   256
            left[leftoff + 1] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   257
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   258
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   259
            right[rightoff + 6] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   260
            right[rightoff + 7] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   261
        }
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   262
        x1 = (x1 + ctrlx1) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   263
        y1 = (y1 + ctrly1) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   264
        x2 = (x2 + ctrlx2) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   265
        y2 = (y2 + ctrly2) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   266
        float centerx = (ctrlx1 + ctrlx2) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   267
        float centery = (ctrly1 + ctrly2) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   268
        ctrlx1 = (x1 + centerx) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   269
        ctrly1 = (y1 + centery) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   270
        ctrlx2 = (x2 + centerx) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   271
        ctrly2 = (y2 + centery) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   272
        centerx = (ctrlx1 + ctrlx2) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   273
        centery = (ctrly1 + ctrly2) / 2.0f;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   274
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   275
            left[leftoff + 2] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   276
            left[leftoff + 3] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   277
            left[leftoff + 4] = ctrlx1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   278
            left[leftoff + 5] = ctrly1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   279
            left[leftoff + 6] = centerx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   280
            left[leftoff + 7] = centery;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   281
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   282
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   283
            right[rightoff + 0] = centerx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   284
            right[rightoff + 1] = centery;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   285
            right[rightoff + 2] = ctrlx2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   286
            right[rightoff + 3] = ctrly2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   287
            right[rightoff + 4] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   288
            right[rightoff + 5] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   289
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   290
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   291
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   292
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   293
    static void subdivideCubicAt(float t, float[] src, int srcoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   294
                                 float[] left, int leftoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   295
                                 float[] right, int rightoff)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   296
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   297
        float x1 = src[srcoff + 0];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   298
        float y1 = src[srcoff + 1];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   299
        float ctrlx1 = src[srcoff + 2];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   300
        float ctrly1 = src[srcoff + 3];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   301
        float ctrlx2 = src[srcoff + 4];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   302
        float ctrly2 = src[srcoff + 5];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   303
        float x2 = src[srcoff + 6];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   304
        float y2 = src[srcoff + 7];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   305
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   306
            left[leftoff + 0] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   307
            left[leftoff + 1] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   308
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   309
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   310
            right[rightoff + 6] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   311
            right[rightoff + 7] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   312
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   313
        x1 = x1 + t * (ctrlx1 - x1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   314
        y1 = y1 + t * (ctrly1 - y1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   315
        x2 = ctrlx2 + t * (x2 - ctrlx2);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   316
        y2 = ctrly2 + t * (y2 - ctrly2);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   317
        float centerx = ctrlx1 + t * (ctrlx2 - ctrlx1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   318
        float centery = ctrly1 + t * (ctrly2 - ctrly1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   319
        ctrlx1 = x1 + t * (centerx - x1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   320
        ctrly1 = y1 + t * (centery - y1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   321
        ctrlx2 = centerx + t * (x2 - centerx);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   322
        ctrly2 = centery + t * (y2 - centery);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   323
        centerx = ctrlx1 + t * (ctrlx2 - ctrlx1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   324
        centery = ctrly1 + t * (ctrly2 - ctrly1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   325
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   326
            left[leftoff + 2] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   327
            left[leftoff + 3] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   328
            left[leftoff + 4] = ctrlx1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   329
            left[leftoff + 5] = ctrly1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   330
            left[leftoff + 6] = centerx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   331
            left[leftoff + 7] = centery;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   332
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   333
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   334
            right[rightoff + 0] = centerx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   335
            right[rightoff + 1] = centery;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   336
            right[rightoff + 2] = ctrlx2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   337
            right[rightoff + 3] = ctrly2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   338
            right[rightoff + 4] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   339
            right[rightoff + 5] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   340
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   341
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   342
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   343
    static void subdivideQuad(float[] src, int srcoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   344
                              float[] left, int leftoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   345
                              float[] right, int rightoff)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   346
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   347
        float x1 = src[srcoff + 0];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   348
        float y1 = src[srcoff + 1];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   349
        float ctrlx = src[srcoff + 2];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   350
        float ctrly = src[srcoff + 3];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   351
        float x2 = src[srcoff + 4];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   352
        float y2 = src[srcoff + 5];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   353
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   354
            left[leftoff + 0] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   355
            left[leftoff + 1] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   356
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   357
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   358
            right[rightoff + 4] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   359
            right[rightoff + 5] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   360
        }
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   361
        x1 = (x1 + ctrlx) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   362
        y1 = (y1 + ctrly) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   363
        x2 = (x2 + ctrlx) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   364
        y2 = (y2 + ctrly) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   365
        ctrlx = (x1 + x2) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 39519
diff changeset
   366
        ctrly = (y1 + y2) / 2.0f;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   367
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   368
            left[leftoff + 2] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   369
            left[leftoff + 3] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   370
            left[leftoff + 4] = ctrlx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   371
            left[leftoff + 5] = ctrly;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   372
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   373
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   374
            right[rightoff + 0] = ctrlx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   375
            right[rightoff + 1] = ctrly;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   376
            right[rightoff + 2] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   377
            right[rightoff + 3] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   378
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   379
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   380
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   381
    static void subdivideQuadAt(float t, float[] src, int srcoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   382
                                float[] left, int leftoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   383
                                float[] right, int rightoff)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   384
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   385
        float x1 = src[srcoff + 0];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   386
        float y1 = src[srcoff + 1];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   387
        float ctrlx = src[srcoff + 2];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   388
        float ctrly = src[srcoff + 3];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   389
        float x2 = src[srcoff + 4];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   390
        float y2 = src[srcoff + 5];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   391
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   392
            left[leftoff + 0] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   393
            left[leftoff + 1] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   394
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   395
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   396
            right[rightoff + 4] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   397
            right[rightoff + 5] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   398
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   399
        x1 = x1 + t * (ctrlx - x1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   400
        y1 = y1 + t * (ctrly - y1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   401
        x2 = ctrlx + t * (x2 - ctrlx);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   402
        y2 = ctrly + t * (y2 - ctrly);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   403
        ctrlx = x1 + t * (x2 - x1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   404
        ctrly = y1 + t * (y2 - y1);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   405
        if (left != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   406
            left[leftoff + 2] = x1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   407
            left[leftoff + 3] = y1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   408
            left[leftoff + 4] = ctrlx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   409
            left[leftoff + 5] = ctrly;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   410
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   411
        if (right != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   412
            right[rightoff + 0] = ctrlx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   413
            right[rightoff + 1] = ctrly;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   414
            right[rightoff + 2] = x2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   415
            right[rightoff + 3] = y2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   416
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   417
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   418
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   419
    static void subdivideAt(float t, float[] src, int srcoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   420
                            float[] left, int leftoff,
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 34417
diff changeset
   421
                            float[] right, int rightoff, int size)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   422
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   423
        switch(size) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   424
        case 8:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   425
            subdivideCubicAt(t, src, srcoff, left, leftoff, right, rightoff);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   426
            return;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   427
        case 6:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   428
            subdivideQuadAt(t, src, srcoff, left, leftoff, right, rightoff);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   429
            return;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   430
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   431
    }
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   432
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   433
    // From sun.java2d.loops.GeneralRenderer:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   434
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   435
    static int outcode(final float x, final float y,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   436
                       final float[] clipRect)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   437
    {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   438
        int code;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   439
        if (y < clipRect[0]) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   440
            code = OUTCODE_TOP;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   441
        } else if (y >= clipRect[1]) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   442
            code = OUTCODE_BOTTOM;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   443
        } else {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   444
            code = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   445
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   446
        if (x < clipRect[2]) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   447
            code |= OUTCODE_LEFT;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   448
        } else if (x >= clipRect[3]) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   449
            code |= OUTCODE_RIGHT;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   450
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   451
        return code;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   452
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   453
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   454
    // a stack of polynomial curves where each curve shares endpoints with
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   455
    // adjacent ones.
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   456
    static final class PolyStack {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   457
        private static final byte TYPE_LINETO  = (byte) 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   458
        private static final byte TYPE_QUADTO  = (byte) 1;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   459
        private static final byte TYPE_CUBICTO = (byte) 2;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   460
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   461
        // curves capacity = edges count (8192) = edges x 2 (coords)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   462
        private static final int INITIAL_CURVES_COUNT = INITIAL_EDGES_COUNT << 1;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   463
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   464
        // types capacity = edges count (4096)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   465
        private static final int INITIAL_TYPES_COUNT = INITIAL_EDGES_COUNT;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   466
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   467
        float[] curves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   468
        int end;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   469
        byte[] curveTypes;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   470
        int numCurves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   471
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   472
        // curves ref (dirty)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   473
        final FloatArrayCache.Reference curves_ref;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   474
        // curveTypes ref (dirty)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   475
        final ByteArrayCache.Reference curveTypes_ref;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   476
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   477
        // used marks (stats only)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   478
        int curveTypesUseMark;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   479
        int curvesUseMark;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   480
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   481
        private final StatLong stat_polystack_types;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   482
        private final StatLong stat_polystack_curves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   483
        private final Histogram hist_polystack_curves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   484
        private final StatLong stat_array_polystack_curves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   485
        private final StatLong stat_array_polystack_curveTypes;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   486
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   487
        PolyStack(final RendererContext rdrCtx) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   488
            this(rdrCtx, null, null, null, null, null);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   489
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   490
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   491
        PolyStack(final RendererContext rdrCtx,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   492
                  final StatLong stat_polystack_types,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   493
                  final StatLong stat_polystack_curves,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   494
                  final Histogram hist_polystack_curves,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   495
                  final StatLong stat_array_polystack_curves,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   496
                  final StatLong stat_array_polystack_curveTypes)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   497
        {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   498
            curves_ref = rdrCtx.newDirtyFloatArrayRef(INITIAL_CURVES_COUNT); // 32K
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   499
            curves     = curves_ref.initial;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   500
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   501
            curveTypes_ref = rdrCtx.newDirtyByteArrayRef(INITIAL_TYPES_COUNT); // 4K
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   502
            curveTypes     = curveTypes_ref.initial;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   503
            numCurves = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   504
            end = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   505
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   506
            if (DO_STATS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   507
                curveTypesUseMark = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   508
                curvesUseMark = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   509
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   510
            this.stat_polystack_types = stat_polystack_types;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   511
            this.stat_polystack_curves = stat_polystack_curves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   512
            this.hist_polystack_curves = hist_polystack_curves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   513
            this.stat_array_polystack_curves = stat_array_polystack_curves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   514
            this.stat_array_polystack_curveTypes = stat_array_polystack_curveTypes;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   515
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   516
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   517
        /**
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   518
         * Disposes this PolyStack:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   519
         * clean up before reusing this instance
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   520
         */
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   521
        void dispose() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   522
            end = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   523
            numCurves = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   524
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   525
            if (DO_STATS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   526
                stat_polystack_types.add(curveTypesUseMark);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   527
                stat_polystack_curves.add(curvesUseMark);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   528
                hist_polystack_curves.add(curvesUseMark);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   529
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   530
                // reset marks
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   531
                curveTypesUseMark = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   532
                curvesUseMark = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   533
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   534
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   535
            // Return arrays:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   536
            // curves and curveTypes are kept dirty
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   537
            curves     = curves_ref.putArray(curves);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   538
            curveTypes = curveTypes_ref.putArray(curveTypes);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   539
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   540
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   541
        private void ensureSpace(final int n) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   542
            // use substraction to avoid integer overflow:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   543
            if (curves.length - end < n) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   544
                if (DO_STATS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   545
                    stat_array_polystack_curves.add(end + n);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   546
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   547
                curves = curves_ref.widenArray(curves, end, end + n);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   548
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   549
            if (curveTypes.length <= numCurves) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   550
                if (DO_STATS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   551
                    stat_array_polystack_curveTypes.add(numCurves + 1);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   552
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   553
                curveTypes = curveTypes_ref.widenArray(curveTypes,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   554
                                                       numCurves,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   555
                                                       numCurves + 1);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   556
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   557
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   558
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   559
        void pushCubic(float x0, float y0,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   560
                       float x1, float y1,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   561
                       float x2, float y2)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   562
        {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   563
            ensureSpace(6);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   564
            curveTypes[numCurves++] = TYPE_CUBICTO;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   565
            // we reverse the coordinate order to make popping easier
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   566
            final float[] _curves = curves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   567
            int e = end;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   568
            _curves[e++] = x2;    _curves[e++] = y2;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   569
            _curves[e++] = x1;    _curves[e++] = y1;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   570
            _curves[e++] = x0;    _curves[e++] = y0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   571
            end = e;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   572
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   573
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   574
        void pushQuad(float x0, float y0,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   575
                      float x1, float y1)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   576
        {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   577
            ensureSpace(4);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   578
            curveTypes[numCurves++] = TYPE_QUADTO;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   579
            final float[] _curves = curves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   580
            int e = end;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   581
            _curves[e++] = x1;    _curves[e++] = y1;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   582
            _curves[e++] = x0;    _curves[e++] = y0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   583
            end = e;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   584
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   585
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   586
        void pushLine(float x, float y) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   587
            ensureSpace(2);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   588
            curveTypes[numCurves++] = TYPE_LINETO;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   589
            curves[end++] = x;    curves[end++] = y;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   590
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   591
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   592
        void pullAll(final PathConsumer2D io) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   593
            final int nc = numCurves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   594
            if (nc == 0) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   595
                return;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   596
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   597
            if (DO_STATS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   598
                // update used marks:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   599
                if (numCurves > curveTypesUseMark) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   600
                    curveTypesUseMark = numCurves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   601
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   602
                if (end > curvesUseMark) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   603
                    curvesUseMark = end;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   604
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   605
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   606
            final byte[]  _curveTypes = curveTypes;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   607
            final float[] _curves = curves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   608
            int e = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   609
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   610
            for (int i = 0; i < nc; i++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   611
                switch(_curveTypes[i]) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   612
                case TYPE_LINETO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   613
                    io.lineTo(_curves[e], _curves[e+1]);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   614
                    e += 2;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   615
                    continue;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   616
                case TYPE_QUADTO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   617
                    io.quadTo(_curves[e+0], _curves[e+1],
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   618
                              _curves[e+2], _curves[e+3]);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   619
                    e += 4;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   620
                    continue;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   621
                case TYPE_CUBICTO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   622
                    io.curveTo(_curves[e+0], _curves[e+1],
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   623
                               _curves[e+2], _curves[e+3],
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   624
                               _curves[e+4], _curves[e+5]);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   625
                    e += 6;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   626
                    continue;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   627
                default:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   628
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   629
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   630
            numCurves = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   631
            end = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   632
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   633
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   634
        void popAll(final PathConsumer2D io) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   635
            int nc = numCurves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   636
            if (nc == 0) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   637
                return;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   638
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   639
            if (DO_STATS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   640
                // update used marks:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   641
                if (numCurves > curveTypesUseMark) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   642
                    curveTypesUseMark = numCurves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   643
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   644
                if (end > curvesUseMark) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   645
                    curvesUseMark = end;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   646
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   647
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   648
            final byte[]  _curveTypes = curveTypes;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   649
            final float[] _curves = curves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   650
            int e  = end;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   651
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   652
            while (nc != 0) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   653
                switch(_curveTypes[--nc]) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   654
                case TYPE_LINETO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   655
                    e -= 2;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   656
                    io.lineTo(_curves[e], _curves[e+1]);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   657
                    continue;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   658
                case TYPE_QUADTO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   659
                    e -= 4;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   660
                    io.quadTo(_curves[e+0], _curves[e+1],
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   661
                              _curves[e+2], _curves[e+3]);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   662
                    continue;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   663
                case TYPE_CUBICTO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   664
                    e -= 6;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   665
                    io.curveTo(_curves[e+0], _curves[e+1],
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   666
                               _curves[e+2], _curves[e+3],
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   667
                               _curves[e+4], _curves[e+5]);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   668
                    continue;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   669
                default:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   670
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   671
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   672
            numCurves = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   673
            end = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   674
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   675
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   676
        @Override
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   677
        public String toString() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   678
            String ret = "";
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   679
            int nc = numCurves;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   680
            int last = end;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   681
            int len;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   682
            while (nc != 0) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   683
                switch(curveTypes[--nc]) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   684
                case TYPE_LINETO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   685
                    len = 2;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   686
                    ret += "line: ";
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   687
                    break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   688
                case TYPE_QUADTO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   689
                    len = 4;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   690
                    ret += "quad: ";
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   691
                    break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   692
                case TYPE_CUBICTO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   693
                    len = 6;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   694
                    ret += "cubic: ";
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   695
                    break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   696
                default:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   697
                    len = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   698
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   699
                last -= len;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   700
                ret += Arrays.toString(Arrays.copyOfRange(curves, last, last+len))
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   701
                                       + "\n";
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   702
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   703
            return ret;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   704
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   705
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   706
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   707
    // a stack of integer indices
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   708
    static final class IndexStack {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   709
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   710
        // integer capacity = edges count / 4 ~ 1024
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   711
        private static final int INITIAL_COUNT = INITIAL_EDGES_COUNT >> 2;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   712
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   713
        private int end;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   714
        private int[] indices;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   715
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   716
        // indices ref (dirty)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   717
        private final IntArrayCache.Reference indices_ref;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   718
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   719
        // used marks (stats only)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   720
        private int indicesUseMark;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   721
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   722
        private final StatLong stat_idxstack_indices;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   723
        private final Histogram hist_idxstack_indices;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   724
        private final StatLong stat_array_idxstack_indices;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   725
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   726
        IndexStack(final RendererContext rdrCtx) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   727
            this(rdrCtx, null, null, null);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   728
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   729
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   730
        IndexStack(final RendererContext rdrCtx,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   731
                   final StatLong stat_idxstack_indices,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   732
                   final Histogram hist_idxstack_indices,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   733
                   final StatLong stat_array_idxstack_indices)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   734
        {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   735
            indices_ref = rdrCtx.newDirtyIntArrayRef(INITIAL_COUNT); // 4K
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   736
            indices     = indices_ref.initial;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   737
            end = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   738
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   739
            if (DO_STATS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   740
                indicesUseMark = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   741
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   742
            this.stat_idxstack_indices = stat_idxstack_indices;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   743
            this.hist_idxstack_indices = hist_idxstack_indices;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   744
            this.stat_array_idxstack_indices = stat_array_idxstack_indices;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   745
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   746
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   747
        /**
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   748
         * Disposes this PolyStack:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   749
         * clean up before reusing this instance
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   750
         */
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   751
        void dispose() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   752
            end = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   753
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   754
            if (DO_STATS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   755
                stat_idxstack_indices.add(indicesUseMark);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   756
                hist_idxstack_indices.add(indicesUseMark);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   757
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   758
                // reset marks
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   759
                indicesUseMark = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   760
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   761
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   762
            // Return arrays:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   763
            // values is kept dirty
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   764
            indices = indices_ref.putArray(indices);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   765
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   766
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   767
        boolean isEmpty() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   768
            return (end == 0);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   769
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   770
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   771
        void reset() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   772
            end = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   773
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   774
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   775
        void push(final int v) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   776
            // remove redundant values (reverse order):
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   777
            int[] _values = indices;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   778
            final int nc = end;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   779
            if (nc != 0) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   780
                if (_values[nc - 1] == v) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   781
                    // remove both duplicated values:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   782
                    end--;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   783
                    return;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   784
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   785
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   786
            if (_values.length <= nc) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   787
                if (DO_STATS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   788
                    stat_array_idxstack_indices.add(nc + 1);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   789
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   790
                indices = _values = indices_ref.widenArray(_values, nc, nc + 1);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   791
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   792
            _values[end++] = v;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   793
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   794
            if (DO_STATS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   795
                // update used marks:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   796
                if (end > indicesUseMark) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   797
                    indicesUseMark = end;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   798
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   799
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   800
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   801
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   802
        void pullAll(final float[] points, final PathConsumer2D io) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   803
            final int nc = end;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   804
            if (nc == 0) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   805
                return;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   806
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   807
            final int[] _values = indices;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   808
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   809
            for (int i = 0, j; i < nc; i++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   810
                j = _values[i] << 1;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   811
                io.lineTo(points[j], points[j + 1]);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   812
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   813
            end = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   814
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   815
    }
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   816
}