test/jdk/sun/java2d/marlin/ClipShapeTest.java
author lbourges
Mon, 11 Dec 2017 21:14:43 +0100
changeset 48284 fd7fbc929001
child 49496 1ea202af7a97
permissions -rw-r--r--
8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip Summary: upgrade to Marlin 0.8.2 providing efficient path clipping (Stroker and Filler) Reviewed-by: prr, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
     1
/*
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
     4
 *
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
     8
 *
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    13
 * accompanied this code).
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    14
 *
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    18
 *
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    21
 * questions.
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    22
 */
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    23
import java.awt.BasicStroke;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    24
import java.awt.Color;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    25
import java.awt.Graphics2D;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    26
import java.awt.RenderingHints;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    27
import java.awt.Shape;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    28
import java.awt.Stroke;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    29
import java.awt.geom.Ellipse2D;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    30
import java.awt.geom.Path2D;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    31
import java.awt.geom.PathIterator;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    32
import java.awt.image.BufferedImage;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    33
import java.awt.image.DataBufferInt;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    34
import java.io.File;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    35
import java.io.FileOutputStream;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    36
import java.io.IOException;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    37
import java.util.Arrays;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    38
import java.util.Iterator;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    39
import java.util.Locale;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    40
import java.util.Random;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    41
import java.util.concurrent.atomic.AtomicBoolean;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    42
import java.util.concurrent.atomic.AtomicInteger;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    43
import java.util.logging.Handler;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    44
import java.util.logging.LogRecord;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    45
import java.util.logging.Logger;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    46
import javax.imageio.IIOImage;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    47
import javax.imageio.ImageIO;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    48
import javax.imageio.ImageWriteParam;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    49
import javax.imageio.ImageWriter;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    50
import javax.imageio.stream.ImageOutputStream;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    51
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    52
/**
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    53
 * @test
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    54
 * @bug 8191814
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    55
 * @summary Verifies that Marlin rendering generates the same
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    56
 * images with and without clipping optimization with all possible
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    57
 * stroke (cap/join) and fill modes (EO rules)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    58
 * Note: Use the argument -slow to run more intensive tests (too much time)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    59
 * @run main/othervm/timeout=120 -Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine ClipShapeTest
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    60
 * @run main/othervm/timeout=120 -Dsun.java2d.renderer=sun.java2d.marlin.DMarlinRenderingEngine ClipShapeTest
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    61
 */
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    62
public final class ClipShapeTest {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    63
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    64
    static final boolean TEST_STROKER = true;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    65
    static final boolean TEST_FILLER = true;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    66
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    67
    // complementary tests in slow mode:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    68
    static boolean USE_DASHES = false;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    69
    static boolean USE_VAR_STROKE = false;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    70
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    71
    static int NUM_TESTS = 5000;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    72
    static final int TESTW = 100;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    73
    static final int TESTH = 100;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    74
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    75
    // shape settings:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    76
    static final ShapeMode SHAPE_MODE = ShapeMode.NINE_LINE_POLYS;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    77
    static final boolean SHAPE_REPEAT = true;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    78
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    79
    // dump path on console:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    80
    static final boolean DUMP_SHAPE = true;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    81
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    82
    static final boolean SHOW_DETAILS = true;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    83
    static final boolean SHOW_OUTLINE = true;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    84
    static final boolean SHOW_POINTS = true;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    85
    static final boolean SHOW_INFO = false;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    86
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    87
    static final int MAX_SHOW_FRAMES = 10;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    88
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    89
    // use fixed seed to reproduce always same polygons between tests
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    90
    static final boolean FIXED_SEED = false;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    91
    static final double RAND_SCALE = 3.0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    92
    static final double RANDW = TESTW * RAND_SCALE;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    93
    static final double OFFW = (TESTW - RANDW) / 2.0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    94
    static final double RANDH = TESTH * RAND_SCALE;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    95
    static final double OFFH = (TESTH - RANDH) / 2.0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    96
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    97
    static enum ShapeMode {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    98
        TWO_CUBICS,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
    99
        FOUR_QUADS,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   100
        FIVE_LINE_POLYS,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   101
        NINE_LINE_POLYS,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   102
        FIFTY_LINE_POLYS,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   103
        MIXED
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   104
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   105
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   106
    static final long SEED = 1666133789L;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   107
    // Fixed seed to avoid any difference between runs:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   108
    static final Random RANDOM = new Random(SEED);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   109
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   110
    static final File OUTPUT_DIR = new File(".");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   111
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   112
    /**
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   113
     * Test
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   114
     * @param args
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   115
     */
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   116
    public static void main(String[] args) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   117
        boolean runSlowTests = (args.length != 0 && "-slow".equals(args[0]));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   118
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   119
        if (runSlowTests) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   120
            NUM_TESTS = 20000; // or 100000 (very slow)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   121
            USE_DASHES = true;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   122
            USE_VAR_STROKE = true;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   123
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   124
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   125
        Locale.setDefault(Locale.US);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   126
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   127
        // Get Marlin runtime state from its log:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   128
        final AtomicBoolean isMarlin = new AtomicBoolean();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   129
        final AtomicBoolean isClipRuntime = new AtomicBoolean();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   130
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   131
        // initialize j.u.l Looger:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   132
        final Logger log = Logger.getLogger("sun.java2d.marlin");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   133
        log.addHandler(new Handler() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   134
            @Override
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   135
            public void publish(LogRecord record) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   136
                final String msg = record.getMessage();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   137
                if (msg != null) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   138
                    // last space to avoid matching other settings:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   139
                    if (msg.startsWith("sun.java2d.renderer ")) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   140
                        isMarlin.set(msg.contains("MarlinRenderingEngine"));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   141
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   142
                    if (msg.startsWith("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:
diff changeset
   143
                        isClipRuntime.set(msg.contains("true"));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   144
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   145
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   146
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   147
                final Throwable th = record.getThrown();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   148
                // detect any Throwable:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   149
                if (th != null) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   150
                    System.out.println("Test failed:\n" + record.getMessage());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   151
                    th.printStackTrace(System.out);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   152
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   153
                    throw new RuntimeException("Test failed: ", th);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   154
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   155
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   156
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   157
            @Override
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   158
            public void flush() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   159
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   160
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   161
            @Override
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   162
            public void close() throws SecurityException {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   163
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   164
        });
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   165
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   166
        // enable Marlin logging & internal checks:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   167
        System.setProperty("sun.java2d.renderer.log", "true");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   168
        System.setProperty("sun.java2d.renderer.useLogger", "true");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   169
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   170
        // disable static clipping setting:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   171
        System.setProperty("sun.java2d.renderer.clip", "false");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   172
        System.setProperty("sun.java2d.renderer.clip.runtime.enable", "true");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   173
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   174
        System.out.println("ClipShapeTests: image = " + TESTW + " x " + TESTH);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   175
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   176
        int failures = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   177
        final long start = System.nanoTime();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   178
        try {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   179
            // TODO: test affine transforms ?
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   180
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   181
            if (TEST_STROKER) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   182
                final float[][] dashArrays = (USE_DASHES)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   183
                        ? new float[][]{null, new float[]{1f, 2f}}
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   184
                        : new float[][]{null};
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   185
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   186
                System.out.println("dashes: " + Arrays.toString(dashArrays));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   187
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   188
                final float[] strokeWidths = (USE_VAR_STROKE)
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   189
                        ? new float[5] : new float[]{8f};
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   190
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   191
                int nsw = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   192
                if (USE_VAR_STROKE) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   193
                    for (float width = 0.1f; width < 110f; width *= 5f) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   194
                        strokeWidths[nsw++] = width;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   195
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   196
                } else {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   197
                    nsw = 1;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   198
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   199
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   200
                System.out.println("stroke widths: " + Arrays.toString(strokeWidths));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   201
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   202
                // Stroker tests:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   203
                for (int w = 0; w < nsw; w++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   204
                    final float width = strokeWidths[w];
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   205
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   206
                    for (float[] dashes : dashArrays) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   207
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   208
                        for (int cap = 0; cap <= 2; cap++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   209
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   210
                            for (int join = 0; join <= 2; join++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   211
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   212
                                failures += paintPaths(new TestSetup(SHAPE_MODE, false, width, cap, join, dashes));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   213
                                failures += paintPaths(new TestSetup(SHAPE_MODE, true, width, cap, join, dashes));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   214
                            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   215
                        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   216
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   217
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   218
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   219
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   220
            if (TEST_FILLER) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   221
                // Filler tests:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   222
                failures += paintPaths(new TestSetup(SHAPE_MODE, false, Path2D.WIND_NON_ZERO));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   223
                failures += paintPaths(new TestSetup(SHAPE_MODE, true, Path2D.WIND_NON_ZERO));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   224
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   225
                failures += paintPaths(new TestSetup(SHAPE_MODE, false, Path2D.WIND_EVEN_ODD));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   226
                failures += paintPaths(new TestSetup(SHAPE_MODE, true, Path2D.WIND_EVEN_ODD));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   227
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   228
        } catch (IOException ioe) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   229
            throw new RuntimeException(ioe);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   230
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   231
        System.out.println("main: duration= " + (1e-6 * (System.nanoTime() - start)) + " ms.");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   232
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   233
        if (!isMarlin.get()) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   234
            throw new RuntimeException("Marlin renderer not used at runtime !");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   235
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   236
        if (!isClipRuntime.get()) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   237
            throw new RuntimeException("Marlin clipping not enabled at runtime !");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   238
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   239
        if (failures != 0) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   240
            throw new RuntimeException("Clip test failures : " + failures);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   241
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   242
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   243
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   244
    static int paintPaths(final TestSetup ts) throws IOException {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   245
        final long start = System.nanoTime();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   246
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   247
        if (FIXED_SEED) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   248
            // Reset seed for random numbers:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   249
            RANDOM.setSeed(SEED);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   250
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   251
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   252
        System.out.println("paintPaths: " + NUM_TESTS
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   253
                + " paths (" + SHAPE_MODE + ") - setup: " + ts);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   254
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   255
        final boolean fill = !ts.isStroke();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   256
        final Path2D p2d = new Path2D.Double(ts.windingRule);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   257
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   258
        final BufferedImage imgOn = newImage(TESTW, TESTH);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   259
        final Graphics2D g2dOn = initialize(imgOn, ts);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   260
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   261
        final BufferedImage imgOff = newImage(TESTW, TESTH);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   262
        final Graphics2D g2dOff = initialize(imgOff, ts);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   263
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   264
        final BufferedImage imgDiff = newImage(TESTW, TESTH);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   265
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   266
        final DiffContext globalCtx = new DiffContext("All tests");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   267
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   268
        int nd = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   269
        try {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   270
            final DiffContext testCtx = new DiffContext("Test");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   271
            BufferedImage diffImage;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   272
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   273
            for (int n = 0; n < NUM_TESTS; n++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   274
                genShape(p2d, ts);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   275
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   276
                // Runtime clip setting OFF:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   277
                paintShape(p2d, g2dOff, fill, false);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   278
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   279
                // Runtime clip setting ON:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   280
                paintShape(p2d, g2dOn, fill, true);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   281
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   282
                /* compute image difference if possible */
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   283
                diffImage = computeDiffImage(testCtx, imgOn, imgOff, imgDiff, globalCtx);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   284
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   285
                final String testName = "Setup_" + ts.id + "_test_" + n;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   286
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   287
                if (diffImage != null) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   288
                    nd++;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   289
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   290
                    final double ratio = (100.0 * testCtx.histPix.count) / testCtx.histAll.count;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   291
                    System.out.println("Diff ratio: " + testName + " = " + trimTo3Digits(ratio) + " %");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   292
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   293
                    if (false) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   294
                        saveImage(diffImage, OUTPUT_DIR, testName + "-diff.png");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   295
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   296
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   297
                    if (DUMP_SHAPE) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   298
                        dumpShape(p2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   299
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   300
                    if (nd < MAX_SHOW_FRAMES) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   301
                        if (SHOW_DETAILS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   302
                            paintShapeDetails(g2dOff, p2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   303
                            paintShapeDetails(g2dOn, p2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   304
                        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   305
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   306
                        saveImage(imgOff, OUTPUT_DIR, testName + "-off.png");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   307
                        saveImage(imgOn, OUTPUT_DIR, testName + "-on.png");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   308
                        saveImage(diffImage, OUTPUT_DIR, testName + "-diff.png");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   309
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   310
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   311
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   312
        } finally {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   313
            g2dOff.dispose();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   314
            g2dOn.dispose();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   315
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   316
            if (nd != 0) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   317
                System.out.println("paintPaths: " + NUM_TESTS + " paths - "
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   318
                        + "Number of differences = " + nd
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   319
                        + " ratio = " + (100f * nd) / NUM_TESTS + " %");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   320
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   321
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   322
            globalCtx.dump();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   323
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   324
        System.out.println("paintPaths: duration= " + (1e-6 * (System.nanoTime() - start)) + " ms.");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   325
        return nd;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   326
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   327
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   328
    private static void paintShape(final Path2D p2d, final Graphics2D g2d,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   329
                                   final boolean fill, final boolean clip) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   330
        reset(g2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   331
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   332
        setClip(g2d, clip);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   333
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   334
        if (fill) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   335
            g2d.fill(p2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   336
        } else {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   337
            g2d.draw(p2d);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   338
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   339
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   340
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   341
    private static Graphics2D initialize(final BufferedImage img,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   342
                                         final TestSetup ts) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   343
        final Graphics2D g2d = (Graphics2D) img.getGraphics();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   344
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   345
                RenderingHints.VALUE_RENDER_QUALITY);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   346
        g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   347
                RenderingHints.VALUE_STROKE_PURE);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   348
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   349
        if (ts.isStroke()) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   350
            g2d.setStroke(createStroke(ts));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   351
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   352
        g2d.setColor(Color.GRAY);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   353
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   354
        return g2d;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   355
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   356
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   357
    private static void reset(final Graphics2D g2d) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   358
        // Disable antialiasing:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   359
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   360
                RenderingHints.VALUE_ANTIALIAS_OFF);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   361
        g2d.setBackground(Color.WHITE);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   362
        g2d.clearRect(0, 0, TESTW, TESTH);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   363
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   364
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   365
    private static void setClip(final Graphics2D g2d, final boolean clip) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   366
        // Enable antialiasing:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   367
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   368
                RenderingHints.VALUE_ANTIALIAS_ON);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   369
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   370
        // Enable or Disable clipping:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   371
        System.setProperty("sun.java2d.renderer.clip.runtime", (clip) ? "true" : "false");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   372
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   373
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   374
    static void genShape(final Path2D p2d, final TestSetup ts) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   375
        p2d.reset();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   376
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   377
        final int end = (SHAPE_REPEAT) ? 2 : 1;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   378
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   379
        for (int p = 0; p < end; p++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   380
            p2d.moveTo(randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   381
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   382
            switch (ts.shapeMode) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   383
                case MIXED:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   384
                case FIFTY_LINE_POLYS:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   385
                case NINE_LINE_POLYS:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   386
                case FIVE_LINE_POLYS:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   387
                    p2d.lineTo(randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   388
                    p2d.lineTo(randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   389
                    p2d.lineTo(randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   390
                    p2d.lineTo(randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   391
                    if (ts.shapeMode == ShapeMode.FIVE_LINE_POLYS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   392
                        // And an implicit close makes 5 lines
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   393
                        break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   394
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   395
                    p2d.lineTo(randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   396
                    p2d.lineTo(randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   397
                    p2d.lineTo(randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   398
                    p2d.lineTo(randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   399
                    if (ts.shapeMode == ShapeMode.NINE_LINE_POLYS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   400
                        // And an implicit close makes 9 lines
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   401
                        break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   402
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   403
                    if (ts.shapeMode == ShapeMode.FIFTY_LINE_POLYS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   404
                        for (int i = 0; i < 41; i++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   405
                            p2d.lineTo(randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   406
                        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   407
                        // And an implicit close makes 50 lines
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   408
                        break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   409
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   410
                case TWO_CUBICS:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   411
                    p2d.curveTo(randX(), randY(), randX(), randY(), randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   412
                    p2d.curveTo(randX(), randY(), randX(), randY(), randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   413
                    if (ts.shapeMode == ShapeMode.TWO_CUBICS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   414
                        break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   415
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   416
                case FOUR_QUADS:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   417
                    p2d.quadTo(randX(), randY(), randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   418
                    p2d.quadTo(randX(), randY(), randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   419
                    p2d.quadTo(randX(), randY(), randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   420
                    p2d.quadTo(randX(), randY(), randX(), randY());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   421
                    if (ts.shapeMode == ShapeMode.FOUR_QUADS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   422
                        break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   423
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   424
                default:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   425
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   426
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   427
            if (ts.closed) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   428
                p2d.closePath();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   429
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   430
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   431
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   432
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   433
    static final float POINT_RADIUS = 2f;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   434
    static final float LINE_WIDTH = 1f;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   435
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   436
    static final Stroke OUTLINE_STROKE = new BasicStroke(LINE_WIDTH);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   437
    static final int COLOR_ALPHA = 128;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   438
    static final Color COLOR_MOVETO = new Color(255, 0, 0, COLOR_ALPHA);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   439
    static final Color COLOR_LINETO_ODD = new Color(0, 0, 255, COLOR_ALPHA);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   440
    static final Color COLOR_LINETO_EVEN = new Color(0, 255, 0, COLOR_ALPHA);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   441
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   442
    static final Ellipse2D.Float ELL_POINT = new Ellipse2D.Float();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   443
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   444
    private static void paintShapeDetails(final Graphics2D g2d, final Shape shape) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   445
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   446
        final Stroke oldStroke = g2d.getStroke();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   447
        final Color oldColor = g2d.getColor();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   448
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   449
        setClip(g2d, false);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   450
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   451
        if (SHOW_OUTLINE) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   452
            g2d.setStroke(OUTLINE_STROKE);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   453
            g2d.setColor(COLOR_LINETO_ODD);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   454
            g2d.draw(shape);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   455
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   456
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   457
        final float[] coords = new float[6];
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   458
        float px, py;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   459
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   460
        int nMove = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   461
        int nLine = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   462
        int n = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   463
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   464
        for (final PathIterator it = shape.getPathIterator(null); !it.isDone(); it.next()) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   465
            int type = it.currentSegment(coords);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   466
            switch (type) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   467
                case PathIterator.SEG_MOVETO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   468
                    if (SHOW_POINTS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   469
                        g2d.setColor(COLOR_MOVETO);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   470
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   471
                    break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   472
                case PathIterator.SEG_LINETO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   473
                    if (SHOW_POINTS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   474
                        g2d.setColor((nLine % 2 == 0) ? COLOR_LINETO_ODD : COLOR_LINETO_EVEN);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   475
                    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   476
                    nLine++;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   477
                    break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   478
                case PathIterator.SEG_CLOSE:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   479
                    continue;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   480
                default:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   481
                    System.out.println("unsupported segment type= " + type);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   482
                    continue;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   483
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   484
            px = coords[0];
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   485
            py = coords[1];
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   486
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   487
            if (SHOW_INFO) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   488
                System.out.println("point[" + (n++) + "|seg=" + type + "]: " + px + " " + py);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   489
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   490
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   491
            if (SHOW_POINTS) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   492
                ELL_POINT.setFrame(px - POINT_RADIUS, py - POINT_RADIUS,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   493
                        POINT_RADIUS * 2f, POINT_RADIUS * 2f);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   494
                g2d.fill(ELL_POINT);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   495
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   496
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   497
        if (SHOW_INFO) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   498
            System.out.println("Path moveTo=" + nMove + ", lineTo=" + nLine);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   499
            System.out.println("--------------------------------------------------");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   500
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   501
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   502
        g2d.setStroke(oldStroke);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   503
        g2d.setColor(oldColor);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   504
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   505
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   506
    private static void dumpShape(final Shape shape) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   507
        final float[] coords = new float[6];
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   508
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   509
        for (final PathIterator it = shape.getPathIterator(null); !it.isDone(); it.next()) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   510
            final int type = it.currentSegment(coords);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   511
            switch (type) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   512
                case PathIterator.SEG_MOVETO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   513
                    System.out.println("p2d.moveTo(" + coords[0] + ", " + coords[1] + ");");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   514
                    break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   515
                case PathIterator.SEG_LINETO:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   516
                    System.out.println("p2d.lineTo(" + coords[0] + ", " + coords[1] + ");");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   517
                    break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   518
                case PathIterator.SEG_CLOSE:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   519
                    System.out.println("p2d.closePath();");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   520
                    break;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   521
                default:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   522
                    System.out.println("// Unsupported segment type= " + type);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   523
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   524
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   525
        System.out.println("--------------------------------------------------");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   526
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   527
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   528
    static double randX() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   529
        return RANDOM.nextDouble() * RANDW + OFFW;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   530
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   531
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   532
    static double randY() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   533
        return RANDOM.nextDouble() * RANDH + OFFH;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   534
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   535
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   536
    private static BasicStroke createStroke(final TestSetup ts) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   537
        return new BasicStroke(ts.strokeWidth, ts.strokeCap, ts.strokeJoin, 10.0f, ts.dashes, 0.0f);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   538
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   539
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   540
    private final static class TestSetup {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   541
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   542
        static final AtomicInteger COUNT = new AtomicInteger();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   543
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   544
        final int id;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   545
        final ShapeMode shapeMode;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   546
        final boolean closed;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   547
        // stroke
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   548
        final float strokeWidth;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   549
        final int strokeCap;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   550
        final int strokeJoin;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   551
        final float[] dashes;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   552
        // fill
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   553
        final int windingRule;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   554
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   555
        TestSetup(ShapeMode shapeMode, final boolean closed,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   556
                  final float strokeWidth, final int strokeCap, final int strokeJoin, final float[] dashes) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   557
            this.id = COUNT.incrementAndGet();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   558
            this.shapeMode = shapeMode;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   559
            this.closed = closed;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   560
            this.strokeWidth = strokeWidth;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   561
            this.strokeCap = strokeCap;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   562
            this.strokeJoin = strokeJoin;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   563
            this.dashes = dashes;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   564
            this.windingRule = Path2D.WIND_NON_ZERO;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   565
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   566
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   567
        TestSetup(ShapeMode shapeMode, final boolean closed, final int windingRule) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   568
            this.id = COUNT.incrementAndGet();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   569
            this.shapeMode = shapeMode;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   570
            this.closed = closed;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   571
            this.strokeWidth = 0f;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   572
            this.strokeCap = this.strokeJoin = -1; // invalid
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   573
            this.dashes = null;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   574
            this.windingRule = windingRule;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   575
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   576
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   577
        boolean isStroke() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   578
            return this.strokeWidth > 0f;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   579
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   580
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   581
        @Override
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   582
        public String toString() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   583
            return "TestSetup{id=" + id + ", shapeMode=" + shapeMode + ", closed=" + closed
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   584
                    + ", strokeWidth=" + strokeWidth + ", strokeCap=" + strokeCap + ", strokeJoin=" + strokeJoin
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   585
                    + ((dashes != null) ? ", dashes: " + Arrays.toString(dashes) : "")
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   586
                    + ", windingRule=" + windingRule + '}';
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   587
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   588
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   589
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   590
    // --- utilities ---
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   591
    private static final int DCM_ALPHA_MASK = 0xff000000;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   592
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   593
    public static BufferedImage newImage(final int w, final int h) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   594
        return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   595
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   596
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   597
    public static BufferedImage computeDiffImage(final DiffContext localCtx,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   598
                                                 final BufferedImage tstImage,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   599
                                                 final BufferedImage refImage,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   600
                                                 final BufferedImage diffImage,
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   601
                                                 final DiffContext globalCtx) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   602
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   603
        final int[] aRefPix = ((DataBufferInt) refImage.getRaster().getDataBuffer()).getData();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   604
        final int[] aTstPix = ((DataBufferInt) tstImage.getRaster().getDataBuffer()).getData();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   605
        final int[] aDifPix = ((DataBufferInt) diffImage.getRaster().getDataBuffer()).getData();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   606
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   607
        // reset local diff context:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   608
        localCtx.reset();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   609
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   610
        int ref, tst, dg, v;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   611
        for (int i = 0, len = aRefPix.length; i < len; i++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   612
            ref = aRefPix[i];
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   613
            tst = aTstPix[i];
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   614
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   615
            // grayscale diff:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   616
            dg = (r(ref) + g(ref) + b(ref)) - (r(tst) + g(tst) + b(tst));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   617
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   618
            // max difference on grayscale values:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   619
            v = (int) Math.ceil(Math.abs(dg / 3.0));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   620
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   621
            aDifPix[i] = toInt(v, v, v);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   622
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   623
            localCtx.add(v);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   624
            globalCtx.add(v);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   625
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   626
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   627
        if (!localCtx.isDiff()) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   628
            return null;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   629
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   630
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   631
        return diffImage;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   632
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   633
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   634
    static void saveImage(final BufferedImage image, final File resDirectory, final String imageFileName) throws IOException {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   635
        final Iterator<ImageWriter> itWriters = ImageIO.getImageWritersByFormatName("PNG");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   636
        if (itWriters.hasNext()) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   637
            final ImageWriter writer = itWriters.next();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   638
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   639
            final ImageWriteParam writerParams = writer.getDefaultWriteParam();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   640
            writerParams.setProgressiveMode(ImageWriteParam.MODE_DISABLED);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   641
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   642
            final File imgFile = new File(resDirectory, imageFileName);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   643
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   644
            if (!imgFile.exists() || imgFile.canWrite()) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   645
                System.out.println("saveImage: saving image as PNG [" + imgFile + "]...");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   646
                imgFile.delete();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   647
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   648
                // disable cache in temporary files:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   649
                ImageIO.setUseCache(false);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   650
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   651
                final long start = System.nanoTime();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   652
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   653
                // PNG uses already buffering:
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   654
                final ImageOutputStream imgOutStream = ImageIO.createImageOutputStream(new FileOutputStream(imgFile));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   655
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   656
                writer.setOutput(imgOutStream);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   657
                try {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   658
                    writer.write(null, new IIOImage(image, null, null), writerParams);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   659
                } finally {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   660
                    imgOutStream.close();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   661
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   662
                    final long time = System.nanoTime() - start;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   663
                    System.out.println("saveImage: duration= " + (time / 1000000l) + " ms.");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   664
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   665
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   666
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   667
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   668
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   669
    static int r(final int v) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   670
        return (v >> 16 & 0xff);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   671
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   672
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   673
    static int g(final int v) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   674
        return (v >> 8 & 0xff);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   675
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   676
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   677
    static int b(final int v) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   678
        return (v & 0xff);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   679
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   680
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   681
    static int clamp127(final int v) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   682
        return (v < 128) ? (v > -127 ? (v + 127) : 0) : 255;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   683
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   684
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   685
    static int toInt(final int r, final int g, final int b) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   686
        return DCM_ALPHA_MASK | (r << 16) | (g << 8) | b;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   687
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   688
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   689
    /* stats */
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   690
    static class StatInteger {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   691
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   692
        public final String name;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   693
        public long count = 0l;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   694
        public long sum = 0l;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   695
        public long min = Integer.MAX_VALUE;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   696
        public long max = Integer.MIN_VALUE;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   697
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   698
        StatInteger(String name) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   699
            this.name = name;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   700
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   701
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   702
        void reset() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   703
            count = 0l;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   704
            sum = 0l;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   705
            min = Integer.MAX_VALUE;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   706
            max = Integer.MIN_VALUE;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   707
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   708
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   709
        void add(int val) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   710
            count++;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   711
            sum += val;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   712
            if (val < min) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   713
                min = val;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   714
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   715
            if (val > max) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   716
                max = val;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   717
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   718
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   719
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   720
        void add(long val) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   721
            count++;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   722
            sum += val;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   723
            if (val < min) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   724
                min = val;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   725
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   726
            if (val > max) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   727
                max = val;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   728
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   729
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   730
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   731
        public final double average() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   732
            return ((double) sum) / count;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   733
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   734
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   735
        @Override
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   736
        public String toString() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   737
            final StringBuilder sb = new StringBuilder(128);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   738
            toString(sb);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   739
            return sb.toString();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   740
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   741
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   742
        public final StringBuilder toString(final StringBuilder sb) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   743
            sb.append(name).append("[n: ").append(count);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   744
            sb.append("] sum: ").append(sum).append(" avg: ").append(trimTo3Digits(average()));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   745
            sb.append(" [").append(min).append(" | ").append(max).append("]");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   746
            return sb;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   747
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   748
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   749
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   750
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   751
    final static class Histogram extends StatInteger {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   752
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   753
        static final int BUCKET = 2;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   754
        static final int MAX = 20;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   755
        static final int LAST = MAX - 1;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   756
        static final int[] STEPS = new int[MAX];
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   757
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   758
        static {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   759
            STEPS[0] = 0;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   760
            STEPS[1] = 1;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   761
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   762
            for (int i = 2; i < MAX; i++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   763
                STEPS[i] = STEPS[i - 1] * BUCKET;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   764
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   765
//            System.out.println("Histogram.STEPS = " + Arrays.toString(STEPS));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   766
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   767
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   768
        static int bucket(int val) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   769
            for (int i = 1; i < MAX; i++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   770
                if (val < STEPS[i]) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   771
                    return i - 1;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   772
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   773
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   774
            return LAST;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   775
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   776
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   777
        private final StatInteger[] stats = new StatInteger[MAX];
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   778
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   779
        public Histogram(String name) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   780
            super(name);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   781
            for (int i = 0; i < MAX; i++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   782
                stats[i] = new StatInteger(String.format("%5s .. %5s", STEPS[i], ((i + 1 < MAX) ? STEPS[i + 1] : "~")));
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   783
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   784
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   785
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   786
        @Override
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   787
        final void reset() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   788
            super.reset();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   789
            for (int i = 0; i < MAX; i++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   790
                stats[i].reset();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   791
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   792
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   793
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   794
        @Override
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   795
        final void add(int val) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   796
            super.add(val);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   797
            stats[bucket(val)].add(val);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   798
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   799
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   800
        @Override
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   801
        final void add(long val) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   802
            add((int) val);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   803
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   804
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   805
        @Override
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   806
        public final String toString() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   807
            final StringBuilder sb = new StringBuilder(2048);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   808
            super.toString(sb).append(" { ");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   809
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   810
            for (int i = 0; i < MAX; i++) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   811
                if (stats[i].count != 0l) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   812
                    sb.append("\n        ").append(stats[i].toString());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   813
                }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   814
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   815
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   816
            return sb.append(" }").toString();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   817
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   818
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   819
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   820
    /**
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   821
     * Adjust the given double value to keep only 3 decimal digits
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   822
     * @param value value to adjust
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   823
     * @return double value with only 3 decimal digits
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   824
     */
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   825
    static double trimTo3Digits(final double value) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   826
        return ((long) (1e3d * value)) / 1e3d;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   827
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   828
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   829
    static final class DiffContext {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   830
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   831
        public final Histogram histAll;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   832
        public final Histogram histPix;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   833
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   834
        DiffContext(String name) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   835
            histAll = new Histogram("All  Pixels [" + name + "]");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   836
            histPix = new Histogram("Diff Pixels [" + name + "]");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   837
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   838
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   839
        void reset() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   840
            histAll.reset();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   841
            histPix.reset();
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   842
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   843
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   844
        void dump() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   845
            if (isDiff()) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   846
                System.out.println("Differences [" + histAll.name + "]:");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   847
                System.out.println("Total [all pixels]:\n" + histAll.toString());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   848
                System.out.println("Total [different pixels]:\n" + histPix.toString());
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   849
            } else {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   850
                System.out.println("No difference for [" + histAll.name + "].");
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   851
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   852
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   853
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   854
        void add(int val) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   855
            histAll.add(val);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   856
            if (val != 0) {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   857
                histPix.add(val);
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   858
            }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   859
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   860
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   861
        boolean isDiff() {
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   862
            return histAll.sum != 0l;
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   863
        }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   864
    }
fd7fbc929001 8191814: Marlin rasterizer spends time computing geometry for stroked segments that do not intersect the clip
lbourges
parents:
diff changeset
   865
}