src/java.desktop/share/classes/sun/java2d/marlin/MarlinRenderingEngine.java
author lbourges
Tue, 10 Sep 2019 21:20:51 +0200
changeset 58321 7f55aad34ac4
parent 51933 4ec74929fbfe
permissions -rw-r--r--
8230728: Thin stroked shapes are not rendered if affine transform has flip bit Summary: use abs(at.getDeterminant()) in userSpaceLineWidth() to ensure positive value Reviewed-by: prr, jdv
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
     1
/*
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
     2
 * Copyright (c) 2007, 2018, 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 java.awt.BasicStroke;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    29
import java.awt.Shape;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    30
import java.awt.geom.AffineTransform;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    31
import java.awt.geom.Path2D;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    32
import java.awt.geom.PathIterator;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    33
import java.security.AccessController;
51933
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
    34
import java.util.Arrays;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    35
import static sun.java2d.marlin.MarlinUtils.logInfo;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    36
import sun.awt.geom.PathConsumer2D;
36458
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
    37
import sun.java2d.ReentrantContextProvider;
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
    38
import sun.java2d.ReentrantContextProviderCLQ;
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
    39
import sun.java2d.ReentrantContextProviderTL;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    40
import sun.java2d.pipe.AATileGenerator;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    41
import sun.java2d.pipe.Region;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    42
import sun.java2d.pipe.RenderingEngine;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    43
import sun.security.action.GetPropertyAction;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    44
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    45
/**
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    46
 * Marlin RendererEngine implementation (derived from Pisces)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    47
 */
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
    48
public final class MarlinRenderingEngine extends RenderingEngine
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
    49
                                         implements MarlinConst
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    50
{
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    51
    // slightly slower ~2% if enabled stroker clipping (lines) but skipping cap / join handling is few percents faster in specific cases
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    52
    static final boolean DISABLE_2ND_STROKER_CLIPPING = true;
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    53
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    54
    static final boolean DO_TRACE_PATH = false;
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    55
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    56
    static final boolean DO_CLIP = MarlinProperties.isDoClip();
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    57
    static final boolean DO_CLIP_FILL = true;
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    58
    static final boolean DO_CLIP_RUNTIME_ENABLE = MarlinProperties.isDoClipRuntimeFlag();
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    59
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    60
    private static final float MIN_PEN_SIZE = 1.0f / MIN_SUBPIXELS;
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    61
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    62
    static final float UPPER_BND = Float.MAX_VALUE / 2.0f;
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    63
    static final float LOWER_BND = -UPPER_BND;
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    64
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    65
    private enum NormMode {
40421
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    66
        ON_WITH_AA {
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    67
            @Override
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    68
            PathIterator getNormalizingPathIterator(final RendererContext rdrCtx,
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    69
                                                    final PathIterator src)
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    70
            {
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    71
                // NormalizingPathIterator NearestPixelCenter:
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    72
                return rdrCtx.nPCPathIterator.init(src);
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    73
            }
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    74
        },
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    75
        ON_NO_AA{
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    76
            @Override
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    77
            PathIterator getNormalizingPathIterator(final RendererContext rdrCtx,
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    78
                                                    final PathIterator src)
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    79
            {
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    80
                // NearestPixel NormalizingPathIterator:
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    81
                return rdrCtx.nPQPathIterator.init(src);
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    82
            }
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    83
        },
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    84
        OFF{
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    85
            @Override
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    86
            PathIterator getNormalizingPathIterator(final RendererContext rdrCtx,
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    87
                                                    final PathIterator src)
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    88
            {
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    89
                // return original path iterator if normalization is disabled:
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    90
                return src;
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    91
            }
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    92
        };
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    93
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    94
        abstract PathIterator getNormalizingPathIterator(RendererContext rdrCtx,
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    95
                                                         PathIterator src);
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
    96
    }
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    97
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    98
    /**
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
    99
     * Public constructor
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   100
     */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   101
    public MarlinRenderingEngine() {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   102
        super();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   103
        logSettings(MarlinRenderingEngine.class.getName());
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   104
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   105
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   106
    /**
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   107
     * Create a widened path as specified by the parameters.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   108
     * <p>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   109
     * The specified {@code src} {@link Shape} is widened according
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   110
     * to the specified attribute parameters as per the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   111
     * {@link BasicStroke} specification.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   112
     *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   113
     * @param src the source path to be widened
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   114
     * @param width the width of the widened path as per {@code BasicStroke}
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   115
     * @param caps the end cap decorations as per {@code BasicStroke}
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   116
     * @param join the segment join decorations as per {@code BasicStroke}
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   117
     * @param miterlimit the miter limit as per {@code BasicStroke}
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   118
     * @param dashes the dash length array as per {@code BasicStroke}
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   119
     * @param dashphase the initial dash phase as per {@code BasicStroke}
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   120
     * @return the widened path stored in a new {@code Shape} object
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   121
     * @since 1.7
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   122
     */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   123
    @Override
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   124
    public Shape createStrokedShape(Shape src,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   125
                                    float width,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   126
                                    int caps,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   127
                                    int join,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   128
                                    float miterlimit,
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
   129
                                    float[] dashes,
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   130
                                    float dashphase)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   131
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   132
        final RendererContext rdrCtx = getRendererContext();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   133
        try {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   134
            // initialize a large copyable Path2D to avoid a lot of array growing:
40421
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
   135
            final Path2D.Float p2d = rdrCtx.getPath2D();
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   136
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   137
            strokeTo(rdrCtx,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   138
                     src,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   139
                     null,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   140
                     width,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   141
                     NormMode.OFF,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   142
                     caps,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   143
                     join,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   144
                     miterlimit,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   145
                     dashes,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   146
                     dashphase,
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   147
                     rdrCtx.transformerPC2D.wrapPath2D(p2d)
34417
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
            // Use Path2D copy constructor (trim)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   151
            return new Path2D.Float(p2d);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   152
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   153
        } finally {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   154
            // recycle the RendererContext instance
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   155
            returnRendererContext(rdrCtx);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   156
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   157
    }
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
     * Sends the geometry for a widened path as specified by the parameters
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   161
     * to the specified consumer.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   162
     * <p>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   163
     * The specified {@code src} {@link Shape} is widened according
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   164
     * to the parameters specified by the {@link BasicStroke} object.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   165
     * Adjustments are made to the path as appropriate for the
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 40421
diff changeset
   166
     * {@link java.awt.RenderingHints#VALUE_STROKE_NORMALIZE} hint if the
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 40421
diff changeset
   167
     * {@code normalize} boolean parameter is true.
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   168
     * Adjustments are made to the path as appropriate for the
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 40421
diff changeset
   169
     * {@link java.awt.RenderingHints#VALUE_ANTIALIAS_ON} hint if the
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 40421
diff changeset
   170
     * {@code antialias} boolean parameter is true.
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   171
     * <p>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   172
     * The geometry of the widened path is forwarded to the indicated
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   173
     * {@link PathConsumer2D} object as it is calculated.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   174
     *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   175
     * @param src the source path to be widened
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   176
     * @param bs the {@code BasicSroke} object specifying the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   177
     *           decorations to be applied to the widened path
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   178
     * @param normalize indicates whether stroke normalization should
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   179
     *                  be applied
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   180
     * @param antialias indicates whether or not adjustments appropriate
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   181
     *                  to antialiased rendering should be applied
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   182
     * @param consumer the {@code PathConsumer2D} instance to forward
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   183
     *                 the widened geometry to
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   184
     * @since 1.7
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   185
     */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   186
    @Override
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   187
    public void strokeTo(Shape src,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   188
                         AffineTransform at,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   189
                         BasicStroke bs,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   190
                         boolean thin,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   191
                         boolean normalize,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   192
                         boolean antialias,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   193
                         final PathConsumer2D consumer)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   194
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   195
        final NormMode norm = (normalize) ?
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   196
                ((antialias) ? NormMode.ON_WITH_AA : NormMode.ON_NO_AA)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   197
                : NormMode.OFF;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   198
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   199
        final RendererContext rdrCtx = getRendererContext();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   200
        try {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   201
            strokeTo(rdrCtx, src, at, bs, thin, norm, antialias, consumer);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   202
        } finally {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   203
            // recycle the RendererContext instance
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   204
            returnRendererContext(rdrCtx);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   205
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   206
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   207
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   208
    void strokeTo(final RendererContext rdrCtx,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   209
                  Shape src,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   210
                  AffineTransform at,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   211
                  BasicStroke bs,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   212
                  boolean thin,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   213
                  NormMode normalize,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   214
                  boolean antialias,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   215
                  PathConsumer2D pc2d)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   216
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   217
        float lw;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   218
        if (thin) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   219
            if (antialias) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   220
                lw = userSpaceLineWidth(at, MIN_PEN_SIZE);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   221
            } else {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   222
                lw = userSpaceLineWidth(at, 1.0f);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   223
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   224
        } else {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   225
            lw = bs.getLineWidth();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   226
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   227
        strokeTo(rdrCtx,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   228
                 src,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   229
                 at,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   230
                 lw,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   231
                 normalize,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   232
                 bs.getEndCap(),
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   233
                 bs.getLineJoin(),
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   234
                 bs.getMiterLimit(),
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   235
                 bs.getDashArray(),
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   236
                 bs.getDashPhase(),
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   237
                 pc2d);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   238
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   239
47971
75686e8da573 8190228: Remove redundant modifiers in java.desktop module.
ssadetsky
parents: 47216
diff changeset
   240
    private float userSpaceLineWidth(AffineTransform at, float lw) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   241
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   242
        float widthScale;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   243
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   244
        if (at == null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   245
            widthScale = 1.0f;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   246
        } else if ((at.getType() & (AffineTransform.TYPE_GENERAL_TRANSFORM  |
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   247
                                    AffineTransform.TYPE_GENERAL_SCALE)) != 0) {
58321
7f55aad34ac4 8230728: Thin stroked shapes are not rendered if affine transform has flip bit
lbourges
parents: 51933
diff changeset
   248
            // Determinant may be negative (flip), use its absolute value:
7f55aad34ac4 8230728: Thin stroked shapes are not rendered if affine transform has flip bit
lbourges
parents: 51933
diff changeset
   249
            widthScale = (float)Math.sqrt(Math.abs(at.getDeterminant()));
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   250
        } else {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   251
            // First calculate the "maximum scale" of this transform.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   252
            double A = at.getScaleX();       // m00
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   253
            double C = at.getShearX();       // m01
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   254
            double B = at.getShearY();       // m10
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   255
            double D = at.getScaleY();       // m11
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   256
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   257
            /*
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   258
             * Given a 2 x 2 affine matrix [ A B ] such that
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   259
             *                             [ C D ]
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   260
             * v' = [x' y'] = [Ax + Cy, Bx + Dy], we want to
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   261
             * find the maximum magnitude (norm) of the vector v'
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   262
             * with the constraint (x^2 + y^2 = 1).
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   263
             * The equation to maximize is
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   264
             *     |v'| = sqrt((Ax+Cy)^2+(Bx+Dy)^2)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   265
             * or  |v'| = sqrt((AA+BB)x^2 + 2(AC+BD)xy + (CC+DD)y^2).
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   266
             * Since sqrt is monotonic we can maximize |v'|^2
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   267
             * instead and plug in the substitution y = sqrt(1 - x^2).
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   268
             * Trigonometric equalities can then be used to get
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   269
             * rid of most of the sqrt terms.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   270
             */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   271
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   272
            double EA = A*A + B*B;          // x^2 coefficient
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   273
            double EB = 2.0d * (A*C + B*D); // xy coefficient
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   274
            double EC = C*C + D*D;          // y^2 coefficient
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   275
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   276
            /*
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   277
             * There is a lot of calculus omitted here.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   278
             *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   279
             * Conceptually, in the interests of understanding the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   280
             * terms that the calculus produced we can consider
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   281
             * that EA and EC end up providing the lengths along
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   282
             * the major axes and the hypot term ends up being an
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   283
             * adjustment for the additional length along the off-axis
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   284
             * angle of rotated or sheared ellipses as well as an
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   285
             * adjustment for the fact that the equation below
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   286
             * averages the two major axis lengths.  (Notice that
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   287
             * the hypot term contains a part which resolves to the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   288
             * difference of these two axis lengths in the absence
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   289
             * of rotation.)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   290
             *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   291
             * In the calculus, the ratio of the EB and (EA-EC) terms
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   292
             * ends up being the tangent of 2*theta where theta is
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   293
             * the angle that the long axis of the ellipse makes
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   294
             * with the horizontal axis.  Thus, this equation is
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   295
             * calculating the length of the hypotenuse of a triangle
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   296
             * along that axis.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   297
             */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   298
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   299
            double hypot = Math.sqrt(EB*EB + (EA-EC)*(EA-EC));
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   300
            // sqrt omitted, compare to squared limits below.
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   301
            double widthsquared = ((EA + EC + hypot) / 2.0d);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   302
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   303
            widthScale = (float)Math.sqrt(widthsquared);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   304
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   305
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   306
        return (lw / widthScale);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   307
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   308
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   309
    void strokeTo(final RendererContext rdrCtx,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   310
                  Shape src,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   311
                  AffineTransform at,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   312
                  float width,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   313
                  NormMode norm,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   314
                  int caps,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   315
                  int join,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   316
                  float miterlimit,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   317
                  float[] dashes,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   318
                  float dashphase,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   319
                  PathConsumer2D pc2d)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   320
    {
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   321
        // We use strokerat so that in Stroker and Dasher we can work only
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   322
        // with the pre-transformation coordinates. This will repeat a lot of
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   323
        // computations done in the path iterator, but the alternative is to
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   324
        // work with transformed paths and compute untransformed coordinates
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   325
        // as needed. This would be faster but I do not think the complexity
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   326
        // of working with both untransformed and transformed coordinates in
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   327
        // the same code is worth it.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   328
        // However, if a path's width is constant after a transformation,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   329
        // we can skip all this untransforming.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   330
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   331
        // As pathTo() will check transformed coordinates for invalid values
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   332
        // (NaN / Infinity) to ignore such points, it is necessary to apply the
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   333
        // transformation before the path processing.
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   334
        AffineTransform strokerat = null;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   335
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   336
        int dashLen = -1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   337
        boolean recycleDashes = false;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   338
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   339
        if (at != null && !at.isIdentity()) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   340
            final double a = at.getScaleX();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   341
            final double b = at.getShearX();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   342
            final double c = at.getShearY();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   343
            final double d = at.getScaleY();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   344
            final double det = a * d - c * b;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   345
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   346
            if (Math.abs(det) <= (2.0f * Float.MIN_VALUE)) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   347
                // this rendering engine takes one dimensional curves and turns
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   348
                // them into 2D shapes by giving them width.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   349
                // However, if everything is to be passed through a singular
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   350
                // transformation, these 2D shapes will be squashed down to 1D
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   351
                // again so, nothing can be drawn.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   352
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   353
                // Every path needs an initial moveTo and a pathDone. If these
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   354
                // are not there this causes a SIGSEGV in libawt.so (at the time
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   355
                // of writing of this comment (September 16, 2010)). Actually,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   356
                // I am not sure if the moveTo is necessary to avoid the SIGSEGV
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   357
                // but the pathDone is definitely needed.
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   358
                pc2d.moveTo(0.0f, 0.0f);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   359
                pc2d.pathDone();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   360
                return;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   361
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   362
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   363
            // If the transform is a constant multiple of an orthogonal transformation
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   364
            // then every length is just multiplied by a constant, so we just
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   365
            // need to transform input paths to stroker and tell stroker
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   366
            // the scaled width. This condition is satisfied if
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   367
            // a*b == -c*d && a*a+c*c == b*b+d*d. In the actual check below, we
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   368
            // leave a bit of room for error.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   369
            if (nearZero(a*b + c*d) && nearZero(a*a + c*c - (b*b + d*d))) {
51933
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   370
                final float scale = (float) Math.sqrt(a*a + c*c);
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   371
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   372
                if (dashes != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   373
                    recycleDashes = true;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   374
                    dashLen = dashes.length;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   375
                    dashes = rdrCtx.dasher.copyDashArray(dashes);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   376
                    for (int i = 0; i < dashLen; i++) {
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   377
                        dashes[i] *= scale;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   378
                    }
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   379
                    dashphase *= scale;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   380
                }
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   381
                width *= scale;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   382
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   383
                // by now strokerat == null. Input paths to
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   384
                // stroker (and maybe dasher) will have the full transform at
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   385
                // applied to them and nothing will happen to the output paths.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   386
            } else {
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   387
                strokerat = at;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   388
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   389
                // by now strokerat == at. Input paths to
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   390
                // stroker (and maybe dasher) will have the full transform at
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   391
                // applied to them, then they will be normalized, and then
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   392
                // the inverse of *only the non translation part of at* will
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   393
                // be applied to the normalized paths. This won't cause problems
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   394
                // in stroker, because, suppose at = T*A, where T is just the
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   395
                // translation part of at, and A is the rest. T*A has already
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   396
                // been applied to Stroker/Dasher's input. Then Ainv will be
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   397
                // applied. Ainv*T*A is not equal to T, but it is a translation,
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   398
                // which means that none of stroker's assumptions about its
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   399
                // input will be violated. After all this, A will be applied
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   400
                // to stroker's output.
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   401
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   402
        } else {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   403
            // either at is null or it's the identity. In either case
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   404
            // we don't transform the path.
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   405
            at = null;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   406
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   407
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   408
        final TransformingPathConsumer2D transformerPC2D = rdrCtx.transformerPC2D;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   409
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   410
        if (DO_TRACE_PATH) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   411
            // trace Stroker:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   412
            pc2d = transformerPC2D.traceStroker(pc2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   413
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   414
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
   415
        if (USE_SIMPLIFIER) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   416
            // Use simplifier after stroker before Renderer
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   417
            // to remove collinear segments (notably due to cap square)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   418
            pc2d = rdrCtx.simplifier.init(pc2d);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   419
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   420
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   421
        // deltaTransformConsumer may adjust the clip rectangle:
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   422
        pc2d = transformerPC2D.deltaTransformConsumer(pc2d, strokerat);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   423
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   424
        // stroker will adjust the clip rectangle (width / miter limit):
51933
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   425
        pc2d = rdrCtx.stroker.init(pc2d, width, caps, join, miterlimit,
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   426
                (dashes == null));
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   427
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   428
        // Curve Monotizer:
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   429
        rdrCtx.monotonizer.init(width);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   430
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   431
        if (dashes != null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   432
            if (!recycleDashes) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   433
                dashLen = dashes.length;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   434
            }
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   435
            if (DO_TRACE_PATH) {
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   436
                pc2d = transformerPC2D.traceDasher(pc2d);
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   437
            }
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   438
            pc2d = rdrCtx.dasher.init(pc2d, dashes, dashLen, dashphase,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   439
                                      recycleDashes);
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   440
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   441
            if (DISABLE_2ND_STROKER_CLIPPING) {
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   442
                // disable stoker clipping
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   443
                rdrCtx.stroker.disableClipping();
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   444
            }
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   445
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   446
        } else if (rdrCtx.doClip && (caps != Stroker.CAP_BUTT)) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   447
            if (DO_TRACE_PATH) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   448
                pc2d = transformerPC2D.traceClosedPathDetector(pc2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   449
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   450
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   451
            // If no dash and clip is enabled:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   452
            // detect closedPaths (polygons) for caps
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   453
            pc2d = transformerPC2D.detectClosedPath(pc2d);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   454
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   455
        pc2d = transformerPC2D.inverseDeltaTransformConsumer(pc2d, strokerat);
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   456
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   457
        if (DO_TRACE_PATH) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   458
            // trace Input:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   459
            pc2d = transformerPC2D.traceInput(pc2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   460
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   461
40421
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
   462
        final PathIterator pi = norm.getNormalizingPathIterator(rdrCtx,
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
   463
                                         src.getPathIterator(at));
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   464
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   465
        pathTo(rdrCtx, pi, pc2d);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   466
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   467
        /*
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   468
         * Pipeline seems to be:
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   469
         * shape.getPathIterator(at)
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   470
         * -> (NormalizingPathIterator)
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   471
         * -> (inverseDeltaTransformConsumer)
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   472
         * -> (Dasher)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   473
         * -> Stroker
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   474
         * -> (deltaTransformConsumer)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   475
         *
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   476
         * -> (CollinearSimplifier) to remove redundant segments
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   477
         *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   478
         * -> pc2d = Renderer (bounding box)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   479
         */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   480
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   481
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   482
    private static boolean nearZero(final double num) {
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   483
        return Math.abs(num) < 2.0d * Math.ulp(num);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   484
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   485
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   486
    abstract static class NormalizingPathIterator implements PathIterator {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   487
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   488
        private PathIterator src;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   489
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   490
        // the adjustment applied to the current position.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   491
        private float curx_adjust, cury_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   492
        // the adjustment applied to the last moveTo position.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   493
        private float movx_adjust, movy_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   494
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   495
        private final float[] tmp;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   496
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   497
        NormalizingPathIterator(final float[] tmp) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   498
            this.tmp = tmp;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   499
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   500
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   501
        final NormalizingPathIterator init(final PathIterator src) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   502
            this.src = src;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   503
            return this; // fluent API
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   504
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   505
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   506
        /**
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   507
         * Disposes this path iterator:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   508
         * clean up before reusing this instance
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   509
         */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   510
        final void dispose() {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   511
            // free source PathIterator:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   512
            this.src = null;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   513
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   514
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   515
        @Override
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   516
        public final int currentSegment(final float[] coords) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   517
            int lastCoord;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   518
            final int type = src.currentSegment(coords);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   519
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   520
            switch(type) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   521
                case PathIterator.SEG_MOVETO:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   522
                case PathIterator.SEG_LINETO:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   523
                    lastCoord = 0;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   524
                    break;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   525
                case PathIterator.SEG_QUADTO:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   526
                    lastCoord = 2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   527
                    break;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   528
                case PathIterator.SEG_CUBICTO:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   529
                    lastCoord = 4;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   530
                    break;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   531
                case PathIterator.SEG_CLOSE:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   532
                    // we don't want to deal with this case later. We just exit now
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   533
                    curx_adjust = movx_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   534
                    cury_adjust = movy_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   535
                    return type;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   536
                default:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   537
                    throw new InternalError("Unrecognized curve type");
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   538
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   539
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   540
            // normalize endpoint
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   541
            float coord, x_adjust, y_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   542
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   543
            coord = coords[lastCoord];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   544
            x_adjust = normCoord(coord); // new coord
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   545
            coords[lastCoord] = x_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   546
            x_adjust -= coord;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   547
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   548
            coord = coords[lastCoord + 1];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   549
            y_adjust = normCoord(coord); // new coord
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   550
            coords[lastCoord + 1] = y_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   551
            y_adjust -= coord;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   552
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   553
            // now that the end points are done, normalize the control points
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   554
            switch(type) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   555
                case PathIterator.SEG_MOVETO:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   556
                    movx_adjust = x_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   557
                    movy_adjust = y_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   558
                    break;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   559
                case PathIterator.SEG_LINETO:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   560
                    break;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   561
                case PathIterator.SEG_QUADTO:
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   562
                    coords[0] += (curx_adjust + x_adjust) / 2.0f;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   563
                    coords[1] += (cury_adjust + y_adjust) / 2.0f;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   564
                    break;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   565
                case PathIterator.SEG_CUBICTO:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   566
                    coords[0] += curx_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   567
                    coords[1] += cury_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   568
                    coords[2] += x_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   569
                    coords[3] += y_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   570
                    break;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   571
                case PathIterator.SEG_CLOSE:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   572
                    // handled earlier
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   573
                default:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   574
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   575
            curx_adjust = x_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   576
            cury_adjust = y_adjust;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   577
            return type;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   578
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   579
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   580
        abstract float normCoord(final float coord);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   581
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   582
        @Override
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   583
        public final int currentSegment(final double[] coords) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   584
            final float[] _tmp = tmp; // dirty
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   585
            int type = this.currentSegment(_tmp);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   586
            for (int i = 0; i < 6; i++) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   587
                coords[i] = _tmp[i];
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   588
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   589
            return type;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   590
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   591
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   592
        @Override
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   593
        public final int getWindingRule() {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   594
            return src.getWindingRule();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   595
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   596
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   597
        @Override
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   598
        public final boolean isDone() {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   599
            if (src.isDone()) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   600
                // Dispose this instance:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   601
                dispose();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   602
                return true;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   603
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   604
            return false;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   605
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   606
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   607
        @Override
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   608
        public final void next() {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   609
            src.next();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   610
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   611
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   612
        static final class NearestPixelCenter
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   613
                                extends NormalizingPathIterator
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   614
        {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   615
            NearestPixelCenter(final float[] tmp) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   616
                super(tmp);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   617
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   618
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   619
            @Override
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   620
            float normCoord(final float coord) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   621
                // round to nearest pixel center
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   622
                return FloatMath.floor_f(coord) + 0.5f;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   623
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   624
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   625
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   626
        static final class NearestPixelQuarter
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   627
                                extends NormalizingPathIterator
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   628
        {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   629
            NearestPixelQuarter(final float[] tmp) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   630
                super(tmp);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   631
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   632
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   633
            @Override
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   634
            float normCoord(final float coord) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   635
                // round to nearest (0.25, 0.25) pixel quarter
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   636
                return FloatMath.floor_f(coord + 0.25f) + 0.25f;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   637
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   638
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   639
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   640
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   641
    private static void pathTo(final RendererContext rdrCtx, final PathIterator pi,
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   642
                               PathConsumer2D pc2d)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   643
    {
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   644
        if (USE_PATH_SIMPLIFIER) {
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   645
            // Use path simplifier at the first step
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   646
            // to remove useless points
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   647
            pc2d = rdrCtx.pathSimplifier.init(pc2d);
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   648
        }
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   649
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   650
        // mark context as DIRTY:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   651
        rdrCtx.dirty = true;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   652
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   653
        pathToLoop(rdrCtx.float6, pi, pc2d);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   654
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   655
        // mark context as CLEAN:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   656
        rdrCtx.dirty = false;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   657
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   658
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   659
    private static void pathToLoop(final float[] coords, final PathIterator pi,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   660
                                   final PathConsumer2D pc2d)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   661
    {
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   662
        // ported from DuctusRenderingEngine.feedConsumer() but simplified:
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   663
        // - removed skip flag = !subpathStarted
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   664
        // - removed pathClosed (ie subpathStarted not set to false)
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   665
        boolean subpathStarted = false;
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   666
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   667
        for (; !pi.isDone(); pi.next()) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   668
            switch (pi.currentSegment(coords)) {
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   669
            case PathIterator.SEG_MOVETO:
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   670
                /* Checking SEG_MOVETO coordinates if they are out of the
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   671
                 * [LOWER_BND, UPPER_BND] range. This check also handles NaN
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   672
                 * and Infinity values. Skipping next path segment in case of
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   673
                 * invalid data.
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   674
                 */
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   675
                if (coords[0] < UPPER_BND && coords[0] > LOWER_BND &&
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   676
                    coords[1] < UPPER_BND && coords[1] > LOWER_BND)
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   677
                {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   678
                    pc2d.moveTo(coords[0], coords[1]);
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   679
                    subpathStarted = true;
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   680
                }
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   681
                break;
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   682
            case PathIterator.SEG_LINETO:
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   683
                /* Checking SEG_LINETO coordinates if they are out of the
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   684
                 * [LOWER_BND, UPPER_BND] range. This check also handles NaN
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   685
                 * and Infinity values. Ignoring current path segment in case
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   686
                 * of invalid data. If segment is skipped its endpoint
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   687
                 * (if valid) is used to begin new subpath.
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   688
                 */
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   689
                if (coords[0] < UPPER_BND && coords[0] > LOWER_BND &&
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   690
                    coords[1] < UPPER_BND && coords[1] > LOWER_BND)
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   691
                {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   692
                    if (subpathStarted) {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   693
                        pc2d.lineTo(coords[0], coords[1]);
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   694
                    } else {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   695
                        pc2d.moveTo(coords[0], coords[1]);
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   696
                        subpathStarted = true;
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   697
                    }
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   698
                }
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   699
                break;
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   700
            case PathIterator.SEG_QUADTO:
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   701
                // Quadratic curves take two points
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   702
                /* Checking SEG_QUADTO coordinates if they are out of the
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   703
                 * [LOWER_BND, UPPER_BND] range. This check also handles NaN
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   704
                 * and Infinity values. Ignoring current path segment in case
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   705
                 * of invalid endpoints's data. Equivalent to the SEG_LINETO
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   706
                 * if endpoint coordinates are valid but there are invalid data
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   707
                 * among other coordinates
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   708
                 */
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   709
                if (coords[2] < UPPER_BND && coords[2] > LOWER_BND &&
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   710
                    coords[3] < UPPER_BND && coords[3] > LOWER_BND)
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   711
                {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   712
                    if (subpathStarted) {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   713
                        if (coords[0] < UPPER_BND && coords[0] > LOWER_BND &&
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   714
                            coords[1] < UPPER_BND && coords[1] > LOWER_BND)
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   715
                        {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   716
                            pc2d.quadTo(coords[0], coords[1],
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   717
                                        coords[2], coords[3]);
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   718
                        } else {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   719
                            pc2d.lineTo(coords[2], coords[3]);
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   720
                        }
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   721
                    } else {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   722
                        pc2d.moveTo(coords[2], coords[3]);
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   723
                        subpathStarted = true;
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   724
                    }
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   725
                }
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   726
                break;
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   727
            case PathIterator.SEG_CUBICTO:
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   728
                // Cubic curves take three points
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   729
                /* Checking SEG_CUBICTO coordinates if they are out of the
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   730
                 * [LOWER_BND, UPPER_BND] range. This check also handles NaN
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   731
                 * and Infinity values. Ignoring current path segment in case
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   732
                 * of invalid endpoints's data. Equivalent to the SEG_LINETO
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   733
                 * if endpoint coordinates are valid but there are invalid data
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   734
                 * among other coordinates
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   735
                 */
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   736
                if (coords[4] < UPPER_BND && coords[4] > LOWER_BND &&
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   737
                    coords[5] < UPPER_BND && coords[5] > LOWER_BND)
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   738
                {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   739
                    if (subpathStarted) {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   740
                        if (coords[0] < UPPER_BND && coords[0] > LOWER_BND &&
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   741
                            coords[1] < UPPER_BND && coords[1] > LOWER_BND &&
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   742
                            coords[2] < UPPER_BND && coords[2] > LOWER_BND &&
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   743
                            coords[3] < UPPER_BND && coords[3] > LOWER_BND)
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   744
                        {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   745
                            pc2d.curveTo(coords[0], coords[1],
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   746
                                         coords[2], coords[3],
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   747
                                         coords[4], coords[5]);
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   748
                        } else {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   749
                            pc2d.lineTo(coords[4], coords[5]);
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   750
                        }
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   751
                    } else {
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   752
                        pc2d.moveTo(coords[4], coords[5]);
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   753
                        subpathStarted = true;
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   754
                    }
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   755
                }
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   756
                break;
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   757
            case PathIterator.SEG_CLOSE:
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   758
                if (subpathStarted) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   759
                    pc2d.closePath();
36902
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   760
                    // do not set subpathStarted to false
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   761
                    // in case of missing moveTo() after close()
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   762
                }
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   763
                break;
bb30d89aa00e 8144938: Handle properly coordinate overflow in Marlin Renderer
lbourges
parents: 36458
diff changeset
   764
            default:
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   765
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   766
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   767
        pc2d.pathDone();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   768
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   769
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   770
    /**
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   771
     * Construct an antialiased tile generator for the given shape with
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   772
     * the given rendering attributes and store the bounds of the tile
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   773
     * iteration in the bbox parameter.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   774
     * The {@code at} parameter specifies a transform that should affect
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   775
     * both the shape and the {@code BasicStroke} attributes.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   776
     * The {@code clip} parameter specifies the current clip in effect
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   777
     * in device coordinates and can be used to prune the data for the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   778
     * operation, but the renderer is not required to perform any
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   779
     * clipping.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   780
     * If the {@code BasicStroke} parameter is null then the shape
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   781
     * should be filled as is, otherwise the attributes of the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   782
     * {@code BasicStroke} should be used to specify a draw operation.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   783
     * The {@code thin} parameter indicates whether or not the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   784
     * transformed {@code BasicStroke} represents coordinates smaller
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   785
     * than the minimum resolution of the antialiasing rasterizer as
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   786
     * specified by the {@code getMinimumAAPenWidth()} method.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   787
     * <p>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   788
     * Upon returning, this method will fill the {@code bbox} parameter
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   789
     * with 4 values indicating the bounds of the iteration of the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   790
     * tile generator.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   791
     * The iteration order of the tiles will be as specified by the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   792
     * pseudo-code:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   793
     * <pre>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   794
     *     for (y = bbox[1]; y < bbox[3]; y += tileheight) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   795
     *         for (x = bbox[0]; x < bbox[2]; x += tilewidth) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   796
     *         }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   797
     *     }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   798
     * </pre>
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   799
     * If there is no output to be rendered, this method may return
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   800
     * null.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   801
     *
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   802
     * @param s the shape to be rendered (fill or draw)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   803
     * @param at the transform to be applied to the shape and the
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   804
     *           stroke attributes
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   805
     * @param clip the current clip in effect in device coordinates
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   806
     * @param bs if non-null, a {@code BasicStroke} whose attributes
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   807
     *           should be applied to this operation
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   808
     * @param thin true if the transformed stroke attributes are smaller
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   809
     *             than the minimum dropout pen width
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   810
     * @param normalize true if the {@code VALUE_STROKE_NORMALIZE}
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   811
     *                  {@code RenderingHint} is in effect
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   812
     * @param bbox returns the bounds of the iteration
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   813
     * @return the {@code AATileGenerator} instance to be consulted
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   814
     *         for tile coverages, or null if there is no output to render
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   815
     * @since 1.7
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   816
     */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   817
    @Override
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   818
    public AATileGenerator getAATileGenerator(Shape s,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   819
                                              AffineTransform at,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   820
                                              Region clip,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   821
                                              BasicStroke bs,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   822
                                              boolean thin,
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   823
                                              boolean normalize,
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
   824
                                              int[] bbox)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   825
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   826
        MarlinTileGenerator ptg = null;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   827
        Renderer r = null;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   828
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   829
        final RendererContext rdrCtx = getRendererContext();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   830
        try {
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   831
            if (DO_CLIP || (DO_CLIP_RUNTIME_ENABLE && MarlinProperties.isDoClipAtRuntime())) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   832
                // Define the initial clip bounds:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   833
                final float[] clipRect = rdrCtx.clipRect;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   834
51933
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   835
                // Adjust the clipping rectangle with the renderer offsets
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   836
                final float rdrOffX = Renderer.RDR_OFFSET_X;
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   837
                final float rdrOffY = Renderer.RDR_OFFSET_Y;
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   838
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   839
                // add a small rounding error:
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   840
                final float margin = 1e-3f;
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   841
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   842
                clipRect[0] = clip.getLoY()
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   843
                                - margin + rdrOffY;
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   844
                clipRect[1] = clip.getLoY() + clip.getHeight()
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   845
                                + margin + rdrOffY;
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   846
                clipRect[2] = clip.getLoX()
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   847
                                - margin + rdrOffX;
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   848
                clipRect[3] = clip.getLoX() + clip.getWidth()
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   849
                                + margin + rdrOffX;
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   850
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   851
                if (MarlinConst.DO_LOG_CLIP) {
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   852
                    MarlinUtils.logInfo("clipRect (clip): "
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   853
                                        + Arrays.toString(rdrCtx.clipRect));
4ec74929fbfe 8210335: Clipping problems with complex affine transforms: negative scaling factors or small scaling factors
lbourges
parents: 49496
diff changeset
   854
                }
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   855
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   856
                // Enable clipping:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   857
                rdrCtx.doClip = true;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   858
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   859
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   860
            // Test if at is identity:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   861
            final AffineTransform _at = (at != null && !at.isIdentity()) ? at
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   862
                                        : null;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   863
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   864
            final NormMode norm = (normalize) ? NormMode.ON_WITH_AA : NormMode.OFF;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   865
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   866
            if (bs == null) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   867
                // fill shape:
40421
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
   868
                final PathIterator pi = norm.getNormalizingPathIterator(rdrCtx,
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
   869
                                                 s.getPathIterator(_at));
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   870
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
   871
                // note: Winding rule may be EvenOdd ONLY for fill operations !
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   872
                r = rdrCtx.renderer.init(clip.getLoX(), clip.getLoY(),
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   873
                                         clip.getWidth(), clip.getHeight(),
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   874
                                         pi.getWindingRule());
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   875
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   876
                PathConsumer2D pc2d = r;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   877
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   878
                if (DO_CLIP_FILL && rdrCtx.doClip) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   879
                    if (DO_TRACE_PATH) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   880
                        // trace Filler:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   881
                        pc2d = rdrCtx.transformerPC2D.traceFiller(pc2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   882
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   883
                    pc2d = rdrCtx.transformerPC2D.pathClipper(pc2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   884
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   885
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   886
                if (DO_TRACE_PATH) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   887
                    // trace Input:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   888
                    pc2d = rdrCtx.transformerPC2D.traceInput(pc2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   889
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   890
                pathTo(rdrCtx, pi, pc2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   891
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   892
            } else {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   893
                // draw shape with given stroke:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   894
                r = rdrCtx.renderer.init(clip.getLoX(), clip.getLoY(),
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   895
                                         clip.getWidth(), clip.getHeight(),
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   896
                                         WIND_NON_ZERO);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   897
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   898
                strokeTo(rdrCtx, s, _at, bs, thin, norm, true, r);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   899
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   900
            if (r.endRendering()) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   901
                ptg = rdrCtx.ptg.init();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   902
                ptg.getBbox(bbox);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   903
                // note: do not returnRendererContext(rdrCtx)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   904
                // as it will be called later by MarlinTileGenerator.dispose()
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   905
                r = null;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   906
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   907
        } finally {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   908
            if (r != null) {
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   909
                // dispose renderer and recycle the RendererContext instance:
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   910
                r.dispose();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   911
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   912
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   913
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   914
        // Return null to cancel AA tile generation (nothing to render)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   915
        return ptg;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   916
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   917
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   918
    @Override
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   919
    public AATileGenerator getAATileGenerator(double x, double y,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   920
                                              double dx1, double dy1,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   921
                                              double dx2, double dy2,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   922
                                              double lw1, double lw2,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   923
                                              Region clip,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   924
                                              int[] bbox)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   925
    {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   926
        // REMIND: Deal with large coordinates!
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   927
        double ldx1, ldy1, ldx2, ldy2;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   928
        boolean innerpgram = (lw1 > 0.0d && lw2 > 0.0d);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   929
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   930
        if (innerpgram) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   931
            ldx1 = dx1 * lw1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   932
            ldy1 = dy1 * lw1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   933
            ldx2 = dx2 * lw2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   934
            ldy2 = dy2 * lw2;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   935
            x -= (ldx1 + ldx2) / 2.0d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   936
            y -= (ldy1 + ldy2) / 2.0d;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   937
            dx1 += ldx1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   938
            dy1 += ldy1;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   939
            dx2 += ldx2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   940
            dy2 += ldy2;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   941
            if (lw1 > 1.0d && lw2 > 1.0d) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   942
                // Inner parallelogram was entirely consumed by stroke...
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   943
                innerpgram = false;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   944
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   945
        } else {
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   946
            ldx1 = ldy1 = ldx2 = ldy2 = 0.0d;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   947
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   948
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   949
        MarlinTileGenerator ptg = null;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   950
        Renderer r = null;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   951
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   952
        final RendererContext rdrCtx = getRendererContext();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   953
        try {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   954
            r = rdrCtx.renderer.init(clip.getLoX(), clip.getLoY(),
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   955
                                     clip.getWidth(), clip.getHeight(),
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
   956
                                     WIND_EVEN_ODD);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   957
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   958
            r.moveTo((float) x, (float) y);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   959
            r.lineTo((float) (x+dx1), (float) (y+dy1));
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   960
            r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2));
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   961
            r.lineTo((float) (x+dx2), (float) (y+dy2));
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   962
            r.closePath();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   963
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   964
            if (innerpgram) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   965
                x += ldx1 + ldx2;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   966
                y += ldy1 + ldy2;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   967
                dx1 -= 2.0d * ldx1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   968
                dy1 -= 2.0d * ldy1;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   969
                dx2 -= 2.0d * ldx2;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   970
                dy2 -= 2.0d * ldy2;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   971
                r.moveTo((float) x, (float) y);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   972
                r.lineTo((float) (x+dx1), (float) (y+dy1));
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   973
                r.lineTo((float) (x+dx1+dx2), (float) (y+dy1+dy2));
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   974
                r.lineTo((float) (x+dx2), (float) (y+dy2));
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   975
                r.closePath();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   976
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   977
            r.pathDone();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   978
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   979
            if (r.endRendering()) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   980
                ptg = rdrCtx.ptg.init();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   981
                ptg.getBbox(bbox);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   982
                // note: do not returnRendererContext(rdrCtx)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   983
                // as it will be called later by MarlinTileGenerator.dispose()
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   984
                r = null;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   985
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   986
        } finally {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   987
            if (r != null) {
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
   988
                // dispose renderer and recycle the RendererContext instance:
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   989
                r.dispose();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   990
            }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   991
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   992
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   993
        // Return null to cancel AA tile generation (nothing to render)
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   994
        return ptg;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   995
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   996
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   997
    /**
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   998
     * Returns the minimum pen width that the antialiasing rasterizer
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
   999
     * can represent without dropouts occuring.
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1000
     * @since 1.7
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1001
     */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1002
    @Override
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1003
    public float getMinimumAAPenSize() {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1004
        return MIN_PEN_SIZE;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1005
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1006
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1007
    static {
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1008
        if (PathIterator.WIND_NON_ZERO != WIND_NON_ZERO ||
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1009
            PathIterator.WIND_EVEN_ODD != WIND_EVEN_ODD ||
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1010
            BasicStroke.JOIN_MITER != JOIN_MITER ||
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1011
            BasicStroke.JOIN_ROUND != JOIN_ROUND ||
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1012
            BasicStroke.JOIN_BEVEL != JOIN_BEVEL ||
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1013
            BasicStroke.CAP_BUTT != CAP_BUTT ||
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1014
            BasicStroke.CAP_ROUND != CAP_ROUND ||
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1015
            BasicStroke.CAP_SQUARE != CAP_SQUARE)
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1016
        {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1017
            throw new InternalError("mismatched renderer constants");
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1018
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1019
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1020
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1021
    // --- RendererContext handling ---
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1022
    // use ThreadLocal or ConcurrentLinkedQueue to get one RendererContext
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1023
    private static final boolean USE_THREAD_LOCAL;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1024
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1025
    // reference type stored in either TL or CLQ
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1026
    static final int REF_TYPE;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1027
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1028
    // Per-thread RendererContext
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1029
    private static final ReentrantContextProvider<RendererContext> RDR_CTX_PROVIDER;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1030
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1031
    // Static initializer to use TL or CLQ mode
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1032
    static {
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1033
        USE_THREAD_LOCAL = MarlinProperties.isUseThreadLocal();
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1034
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1035
        // Soft reference by default:
36458
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1036
        final String refType = AccessController.doPrivileged(
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1037
                            new GetPropertyAction("sun.java2d.renderer.useRef",
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1038
                            "soft"));
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1039
        switch (refType) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1040
            default:
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1041
            case "soft":
36458
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1042
                REF_TYPE = ReentrantContextProvider.REF_SOFT;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1043
                break;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1044
            case "weak":
36458
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1045
                REF_TYPE = ReentrantContextProvider.REF_WEAK;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1046
                break;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1047
            case "hard":
36458
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1048
                REF_TYPE = ReentrantContextProvider.REF_HARD;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1049
                break;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1050
        }
36458
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1051
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1052
        if (USE_THREAD_LOCAL) {
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1053
            RDR_CTX_PROVIDER = new ReentrantContextProviderTL<RendererContext>(REF_TYPE)
36458
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1054
                {
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1055
                    @Override
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1056
                    protected RendererContext newContext() {
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1057
                        return RendererContext.createContext();
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1058
                    }
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1059
                };
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1060
        } else {
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1061
            RDR_CTX_PROVIDER = new ReentrantContextProviderCLQ<RendererContext>(REF_TYPE)
36458
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1062
                {
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1063
                    @Override
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1064
                    protected RendererContext newContext() {
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1065
                        return RendererContext.createContext();
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1066
                    }
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1067
                };
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1068
        }
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1069
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1070
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1071
    private static boolean SETTINGS_LOGGED = !ENABLE_LOGS;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1072
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1073
    private static void logSettings(final String reClass) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1074
        // log information at startup
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1075
        if (SETTINGS_LOGGED) {
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1076
            return;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1077
        }
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1078
        SETTINGS_LOGGED = true;
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1079
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1080
        String refType;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1081
        switch (REF_TYPE) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1082
            default:
36458
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1083
            case ReentrantContextProvider.REF_HARD:
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1084
                refType = "hard";
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1085
                break;
36458
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1086
            case ReentrantContextProvider.REF_SOFT:
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1087
                refType = "soft";
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1088
                break;
36458
25786a73a5fc 8148886: SEGV in sun.java2d.marlin.Renderer._endRendering
lbourges
parents: 34417
diff changeset
  1089
            case ReentrantContextProvider.REF_WEAK:
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1090
                refType = "weak";
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1091
                break;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1092
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1093
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1094
        logInfo("=========================================================="
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1095
                + "=====================");
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1096
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1097
        logInfo("Marlin software rasterizer           = ENABLED");
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1098
        logInfo("Version                              = ["
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1099
                + Version.getVersion() + "]");
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1100
        logInfo("sun.java2d.renderer                  = "
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1101
                + reClass);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1102
        logInfo("sun.java2d.renderer.useThreadLocal   = "
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1103
                + USE_THREAD_LOCAL);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1104
        logInfo("sun.java2d.renderer.useRef           = "
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1105
                + refType);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1106
40421
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
  1107
        logInfo("sun.java2d.renderer.edges            = "
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
  1108
                + MarlinConst.INITIAL_EDGES_COUNT);
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1109
        logInfo("sun.java2d.renderer.pixelWidth       = "
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1110
                + MarlinConst.INITIAL_PIXEL_WIDTH);
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1111
        logInfo("sun.java2d.renderer.pixelHeight      = "
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1112
                + MarlinConst.INITIAL_PIXEL_HEIGHT);
40421
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
  1113
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1114
        logInfo("sun.java2d.renderer.subPixel_log2_X  = "
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1115
                + MarlinConst.SUBPIXEL_LG_POSITIONS_X);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1116
        logInfo("sun.java2d.renderer.subPixel_log2_Y  = "
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1117
                + MarlinConst.SUBPIXEL_LG_POSITIONS_Y);
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
  1118
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1119
        logInfo("sun.java2d.renderer.tileSize_log2    = "
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
  1120
                + MarlinConst.TILE_H_LG);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
  1121
        logInfo("sun.java2d.renderer.tileWidth_log2   = "
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
  1122
                + MarlinConst.TILE_W_LG);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1123
        logInfo("sun.java2d.renderer.blockSize_log2   = "
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1124
                + MarlinConst.BLOCK_SIZE_LG);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1125
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1126
        // RLE / blockFlags settings
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1127
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1128
        logInfo("sun.java2d.renderer.forceRLE         = "
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1129
                + MarlinProperties.isForceRLE());
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1130
        logInfo("sun.java2d.renderer.forceNoRLE       = "
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1131
                + MarlinProperties.isForceNoRLE());
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1132
        logInfo("sun.java2d.renderer.useTileFlags     = "
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1133
                + MarlinProperties.isUseTileFlags());
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1134
        logInfo("sun.java2d.renderer.useTileFlags.useHeuristics = "
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1135
                + MarlinProperties.isUseTileFlagsWithHeuristics());
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1136
        logInfo("sun.java2d.renderer.rleMinWidth      = "
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1137
                + MarlinCache.RLE_MIN_WIDTH);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1138
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1139
        // optimisation parameters
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1140
        logInfo("sun.java2d.renderer.useSimplifier    = "
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1141
                + MarlinConst.USE_SIMPLIFIER);
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1142
        logInfo("sun.java2d.renderer.usePathSimplifier= "
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1143
                + MarlinConst.USE_PATH_SIMPLIFIER);
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1144
        logInfo("sun.java2d.renderer.pathSimplifier.pixTol = "
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1145
                + MarlinProperties.getPathSimplifierPixelTolerance());
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1146
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1147
        logInfo("sun.java2d.renderer.clip             = "
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1148
                + MarlinProperties.isDoClip());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1149
        logInfo("sun.java2d.renderer.clip.runtime.enable = "
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1150
                + MarlinProperties.isDoClipRuntimeFlag());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47971
diff changeset
  1151
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1152
        logInfo("sun.java2d.renderer.clip.subdivider  = "
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1153
                + MarlinProperties.isDoClipSubdivider());
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1154
        logInfo("sun.java2d.renderer.clip.subdivider.minLength = "
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1155
                + MarlinProperties.getSubdividerMinLength());
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1156
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1157
        // debugging parameters
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1158
        logInfo("sun.java2d.renderer.doStats          = "
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1159
                + MarlinConst.DO_STATS);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1160
        logInfo("sun.java2d.renderer.doMonitors       = "
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1161
                + MarlinConst.DO_MONITORS);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1162
        logInfo("sun.java2d.renderer.doChecks         = "
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1163
                + MarlinConst.DO_CHECKS);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1164
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1165
        // logging parameters
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1166
        logInfo("sun.java2d.renderer.useLogger        = "
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1167
                + MarlinConst.USE_LOGGER);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1168
        logInfo("sun.java2d.renderer.logCreateContext = "
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1169
                + MarlinConst.LOG_CREATE_CONTEXT);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1170
        logInfo("sun.java2d.renderer.logUnsafeMalloc  = "
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1171
                + MarlinConst.LOG_UNSAFE_MALLOC);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1172
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1173
        // quality settings
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1174
        logInfo("sun.java2d.renderer.curve_len_err    = "
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
  1175
                + MarlinProperties.getCurveLengthError());
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
  1176
        logInfo("sun.java2d.renderer.cubic_dec_d2     = "
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
  1177
                + MarlinProperties.getCubicDecD2());
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
  1178
        logInfo("sun.java2d.renderer.cubic_inc_d1     = "
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
  1179
                + MarlinProperties.getCubicIncD1());
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
  1180
        logInfo("sun.java2d.renderer.quad_dec_d2      = "
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
  1181
                + MarlinProperties.getQuadDecD2());
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents: 44655
diff changeset
  1182
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1183
        logInfo("Renderer settings:");
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1184
        logInfo("CUB_DEC_BND  = " + Renderer.CUB_DEC_BND);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1185
        logInfo("CUB_INC_BND  = " + Renderer.CUB_INC_BND);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1186
        logInfo("QUAD_DEC_BND = " + Renderer.QUAD_DEC_BND);
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1187
40421
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
  1188
        logInfo("INITIAL_EDGES_CAPACITY               = "
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
  1189
                + MarlinConst.INITIAL_EDGES_CAPACITY);
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
  1190
        logInfo("INITIAL_CROSSING_COUNT               = "
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
  1191
                + Renderer.INITIAL_CROSSING_COUNT);
d5ee65e2b0fb 8159638: Improve array caches and renderer stats in Marlin renderer
lbourges
parents: 39519
diff changeset
  1192
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1193
        logInfo("=========================================================="
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1194
                + "=====================");
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1195
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1196
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1197
    /**
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1198
     * Get the RendererContext instance dedicated to the current thread
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1199
     * @return RendererContext instance
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1200
     */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1201
    @SuppressWarnings({"unchecked"})
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1202
    static RendererContext getRendererContext() {
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1203
        final RendererContext rdrCtx = RDR_CTX_PROVIDER.acquire();
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1204
        if (DO_MONITORS) {
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1205
            rdrCtx.stats.mon_pre_getAATileGenerator.start();
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1206
        }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1207
        return rdrCtx;
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1208
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1209
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1210
    /**
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1211
     * Reset and return the given RendererContext instance for reuse
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1212
     * @param rdrCtx RendererContext instance
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1213
     */
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1214
    static void returnRendererContext(final RendererContext rdrCtx) {
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1215
        rdrCtx.dispose();
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1216
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1217
        if (DO_MONITORS) {
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1218
            rdrCtx.stats.mon_pre_getAATileGenerator.stop();
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1219
        }
39519
21bfc4452441 8159093: Fix coding conventions in Marlin renderer
lbourges
parents: 36902
diff changeset
  1220
        RDR_CTX_PROVIDER.release(rdrCtx);
34417
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1221
    }
57a3863abbb4 8076529: Marlin antialiasing renderer integration
flar
parents:
diff changeset
  1222
}