src/java.desktop/share/classes/sun/java2d/marlin/DRendererContext.java
author lbourges
Tue, 27 Mar 2018 22:09:43 +0200
changeset 49496 1ea202af7a97
parent 48284 fd7fbc929001
child 51933 4ec74929fbfe
permissions -rw-r--r--
8198885: upgrade Marlin (java2d) to 0.9.1 Summary: clipping implemented in Dasher (curve subdivision at clip edges) + higher quality(curve, subpixels) + new path simplifier Reviewed-by: prr, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     1
/*
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     4
 *
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    10
 *
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    15
 * accompanied this code).
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    16
 *
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    20
 *
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    23
 * questions.
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    24
 */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    25
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    26
package sun.java2d.marlin;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    27
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    28
import java.awt.geom.Path2D;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    29
import java.lang.ref.WeakReference;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    30
import java.util.concurrent.atomic.AtomicInteger;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    31
import sun.java2d.ReentrantContext;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    32
import sun.java2d.marlin.ArrayCacheConst.CacheStats;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    33
import sun.java2d.marlin.DMarlinRenderingEngine.NormalizingPathIterator;
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    34
import sun.java2d.marlin.DTransformingPathConsumer2D.CurveBasicMonotonizer;
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    35
import sun.java2d.marlin.DTransformingPathConsumer2D.CurveClipSplitter;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    36
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    37
/**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    38
 * This class is a renderer context dedicated to a single thread
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    39
 */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    40
final class DRendererContext extends ReentrantContext implements IRendererContext {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    41
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    42
    // RendererContext creation counter
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    43
    private static final AtomicInteger CTX_COUNT = new AtomicInteger(1);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    44
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    45
    /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    46
     * Create a new renderer context
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    47
     *
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    48
     * @return new RendererContext instance
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    49
     */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    50
    static DRendererContext createContext() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    51
        return new DRendererContext("ctx"
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    52
                       + Integer.toString(CTX_COUNT.getAndIncrement()));
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    53
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    54
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    55
    // Smallest object used as Cleaner's parent reference
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    56
    private final Object cleanerObj;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    57
    // dirty flag indicating an exception occured during pipeline in pathTo()
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    58
    boolean dirty = false;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    59
    // shared data
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    60
    final double[] double6 = new double[6];
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    61
    // shared curve (dirty) (Renderer / Stroker)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    62
    final DCurve curve = new DCurve();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    63
    // MarlinRenderingEngine NormalizingPathIterator NearestPixelCenter:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    64
    final NormalizingPathIterator nPCPathIterator;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    65
    // MarlinRenderingEngine NearestPixelQuarter NormalizingPathIterator:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    66
    final NormalizingPathIterator nPQPathIterator;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    67
    // MarlinRenderingEngine.TransformingPathConsumer2D
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    68
    final DTransformingPathConsumer2D transformerPC2D;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    69
    // recycled Path2D instance (weak)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    70
    private WeakReference<Path2D.Double> refPath2D = null;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    71
    final DRenderer renderer;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    72
    final DStroker stroker;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    73
    // Simplifies out collinear lines
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    74
    final DCollinearSimplifier simplifier = new DCollinearSimplifier();
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    75
    // Simplifies path
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    76
    final DPathSimplifier pathSimplifier = new DPathSimplifier();
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    77
    final DDasher dasher;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    78
    final MarlinTileGenerator ptg;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    79
    final MarlinCache cache;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    80
    // flag indicating the shape is stroked (1) or filled (0)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    81
    int stroking = 0;
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    82
    // flag indicating to clip the shape
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    83
    boolean doClip = false;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    84
    // flag indicating if the path is closed or not (in advance) to handle properly caps
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    85
    boolean closedPath = false;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    86
    // clip rectangle (ymin, ymax, xmin, xmax):
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    87
    final double[] clipRect = new double[4];
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    88
    // CurveBasicMonotonizer instance
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    89
    final CurveBasicMonotonizer monotonizer;
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    90
    // CurveClipSplitter instance
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
    91
    final CurveClipSplitter curveClipSplitter;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    92
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    93
    // Array caches:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    94
    /* clean int[] cache (zero-filled) = 5 refs */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
    95
    private final IntArrayCache cleanIntCache = new IntArrayCache(true, 5);
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    96
    /* dirty int[] cache = 5 refs */
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    97
    private final IntArrayCache dirtyIntCache = new IntArrayCache(false, 5);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    98
    /* dirty double[] cache = 4 refs (2 polystack) */
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
    99
    private final DoubleArrayCache dirtyDoubleCache = new DoubleArrayCache(false, 4);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   100
    /* dirty byte[] cache = 2 ref (2 polystack) */
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   101
    private final ByteArrayCache dirtyByteCache = new ByteArrayCache(false, 2);
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   102
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   103
    // RendererContext statistics
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   104
    final RendererStats stats;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   105
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   106
    final PathConsumer2DAdapter p2dAdapter = new PathConsumer2DAdapter();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   107
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   108
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   109
    /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   110
     * Constructor
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   111
     *
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   112
     * @param name context name (debugging)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   113
     */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   114
    DRendererContext(final String name) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   115
        if (LOG_CREATE_CONTEXT) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   116
            MarlinUtils.logInfo("new RendererContext = " + name);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   117
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   118
        this.cleanerObj = new Object();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   119
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   120
        // create first stats (needed by newOffHeapArray):
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   121
        if (DO_STATS || DO_MONITORS) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   122
            stats = RendererStats.createInstance(cleanerObj, name);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   123
            // push cache stats:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   124
            stats.cacheStats = new CacheStats[] { cleanIntCache.stats,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   125
                dirtyIntCache.stats, dirtyDoubleCache.stats, dirtyByteCache.stats
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   126
            };
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   127
        } else {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   128
            stats = null;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   129
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   130
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   131
        // NormalizingPathIterator instances:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   132
        nPCPathIterator = new NormalizingPathIterator.NearestPixelCenter(double6);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   133
        nPQPathIterator  = new NormalizingPathIterator.NearestPixelQuarter(double6);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   134
49496
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   135
        // curve monotonizer & clip subdivider (before transformerPC2D init)
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   136
        monotonizer = new CurveBasicMonotonizer(this);
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   137
        curveClipSplitter = new CurveClipSplitter(this);
1ea202af7a97 8198885: upgrade Marlin (java2d) to 0.9.1
lbourges
parents: 48284
diff changeset
   138
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   139
        // MarlinRenderingEngine.TransformingPathConsumer2D
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   140
        transformerPC2D = new DTransformingPathConsumer2D(this);
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   141
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   142
        // Renderer:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   143
        cache = new MarlinCache(this);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   144
        renderer = new DRenderer(this); // needs MarlinCache from rdrCtx.cache
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   145
        ptg = new MarlinTileGenerator(stats, renderer, cache);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   146
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   147
        stroker = new DStroker(this);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   148
        dasher = new DDasher(this);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   149
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   150
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   151
    /**
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   152
     * Disposes this renderer context:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   153
     * clean up before reusing this context
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   154
     */
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   155
    void dispose() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   156
        if (DO_STATS) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   157
            if (stats.totalOffHeap > stats.totalOffHeapMax) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   158
                stats.totalOffHeapMax = stats.totalOffHeap;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   159
            }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   160
            stats.totalOffHeap = 0L;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   161
        }
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   162
        stroking   = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   163
        doClip     = false;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   164
        closedPath = false;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   165
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   166
        // if context is maked as DIRTY:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   167
        if (dirty) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   168
            // may happen if an exception if thrown in the pipeline processing:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   169
            // force cleanup of all possible pipelined blocks (except Renderer):
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   170
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   171
            // NormalizingPathIterator instances:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   172
            this.nPCPathIterator.dispose();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   173
            this.nPQPathIterator.dispose();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   174
            // Dasher:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   175
            this.dasher.dispose();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   176
            // Stroker:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   177
            this.stroker.dispose();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   178
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   179
            // mark context as CLEAN:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   180
            dirty = false;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   181
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   182
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   183
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   184
    Path2D.Double getPath2D() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   185
        // resolve reference:
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   186
        Path2D.Double p2d = (refPath2D != null) ? refPath2D.get() : null;
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   187
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   188
        // create a new Path2D ?
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   189
        if (p2d == null) {
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents: 47216
diff changeset
   190
            p2d = new Path2D.Double(WIND_NON_ZERO, INITIAL_EDGES_COUNT); // 32K
47126
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   191
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   192
            // update weak reference:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   193
            refPath2D = new WeakReference<Path2D.Double>(p2d);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   194
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   195
        // reset the path anyway:
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   196
        p2d.reset();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   197
        return p2d;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   198
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   199
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   200
    @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   201
    public RendererStats stats() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   202
        return stats;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   203
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   204
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   205
    @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   206
    public OffHeapArray newOffHeapArray(final long initialSize) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   207
        if (DO_STATS) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   208
            stats.totalOffHeapInitial += initialSize;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   209
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   210
        return new OffHeapArray(cleanerObj, initialSize);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   211
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   212
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   213
    @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   214
    public IntArrayCache.Reference newCleanIntArrayRef(final int initialSize) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   215
        return cleanIntCache.createRef(initialSize);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   216
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   217
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   218
    IntArrayCache.Reference newDirtyIntArrayRef(final int initialSize) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   219
        return dirtyIntCache.createRef(initialSize);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   220
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   221
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   222
    DoubleArrayCache.Reference newDirtyDoubleArrayRef(final int initialSize) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   223
        return dirtyDoubleCache.createRef(initialSize);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   224
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   225
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   226
    ByteArrayCache.Reference newDirtyByteArrayRef(final int initialSize) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   227
        return dirtyByteCache.createRef(initialSize);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   228
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   229
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   230
    static final class PathConsumer2DAdapter implements DPathConsumer2D {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   231
        private sun.awt.geom.PathConsumer2D out;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   232
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   233
        PathConsumer2DAdapter() {}
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   234
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   235
        PathConsumer2DAdapter init(sun.awt.geom.PathConsumer2D out) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   236
            this.out = out;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   237
            return this;
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   238
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   239
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   240
        @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   241
        public void moveTo(double x0, double y0) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   242
            out.moveTo((float)x0, (float)y0);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   243
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   244
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   245
        @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   246
        public void lineTo(double x1, double y1) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   247
            out.lineTo((float)x1, (float)y1);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   248
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   249
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   250
        @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   251
        public void closePath() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   252
            out.closePath();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   253
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   254
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   255
        @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   256
        public void pathDone() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   257
            out.pathDone();
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   258
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   259
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   260
        @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   261
        public void curveTo(double x1, double y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   262
                            double x2, double y2,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   263
                            double x3, double y3)
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   264
        {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   265
            out.curveTo((float)x1, (float)y1,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   266
                    (float)x2, (float)y2,
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   267
                    (float)x3, (float)y3);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   268
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   269
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   270
        @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   271
        public void quadTo(double x1, double y1, double x2, double y2) {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   272
            out.quadTo((float)x1, (float)y1, (float)x2, (float)y2);
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   273
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   274
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   275
        @Override
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   276
        public long getNativeConsumer() {
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   277
            throw new InternalError("Not using a native peer");
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   278
        }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   279
    }
188ef162f019 8180055: Upgrade the Marlin renderer in Java2D
lbourges
parents:
diff changeset
   280
}