src/java.desktop/share/native/libawt/java2d/loops/DrawLine.c
author ihse
Mon, 11 Jun 2018 11:23:20 +0200
branchihse-remove-mapfiles-branch
changeset 56721 01b558efd286
parent 47216 71c04702a3d5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "GraphicsPrimitiveMgr.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "LineUtils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "sun_java2d_loops_DrawLine.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#define OUTCODE_TOP     1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#define OUTCODE_BOTTOM  2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#define OUTCODE_LEFT    4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#define OUTCODE_RIGHT   8
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
RefineBounds(SurfaceDataBounds *bounds, jint x1, jint y1, jint x2, jint y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    jint min, max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    if (x1 < x2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        min = x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        max = x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        min = x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        max = x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    max++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    if (max <= min) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        /* integer overflow */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        max--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    if (bounds->x1 < min) bounds->x1 = min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    if (bounds->x2 > max) bounds->x2 = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    if (y1 < y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        min = y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        max = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        min = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        max = y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    max++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    if (max <= min) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        /* integer overflow */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        max--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    if (bounds->y1 < min) bounds->y1 = min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    if (bounds->y2 > max) bounds->y2 = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
#define _out(v, vmin, vmax, cmin, cmax) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    ((v < vmin) ? cmin : ((v > vmax) ? cmax : 0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#define outcode(x, y, xmin, ymin, xmax, ymax) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    (_out(y, ymin, ymax, OUTCODE_TOP, OUTCODE_BOTTOM) | \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     _out(x, xmin, xmax, OUTCODE_LEFT, OUTCODE_RIGHT))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * "Small" math here will be done if the coordinates are less
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * than 15 bits in range (-16384 => 16383).  This could be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * expanded to 16 bits if we rearrange some of the math in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * the normal version of SetupBresenham.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * "Big" math here will be done with coordinates with 30 bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * of total range - 2 bits less than a jint holds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * Intermediate calculations for "Big" coordinates will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * done using jlong variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
#define OverflowsSmall(v)       ((v) != (((v) << 17) >> 17))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#define OverflowsBig(v)         ((v) != (((v) << 2) >> 2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
#define BIG_MAX                 ((1 << 29) - 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
#define BIG_MIN                 (-(1 << 29))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
#define SETUP_BRESENHAM(CALC_TYPE, ORIGX1, ORIGY1, ORIGX2, ORIGY2, SHORTEN) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
do { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    jint X1 = ORIGX1, Y1 = ORIGY1, X2 = ORIGX2, Y2 = ORIGY2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    jint dx, dy, ax, ay; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    jint cxmin, cymin, cxmax, cymax; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    jint outcode1, outcode2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    jboolean xmajor; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    jint errminor, errmajor; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    jint error; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    jint steps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    dx = X2 - X1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    dy = Y2 - Y1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    ax = (dx < 0) ? -dx : dx; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    ay = (dy < 0) ? -dy : dy; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    cxmin = pBounds->x1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    cymin = pBounds->y1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    cxmax = pBounds->x2 - 1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    cymax = pBounds->y2 - 1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    xmajor = (ax >= ay); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    outcode1 = outcode(X1, Y1, cxmin, cymin, cxmax, cymax); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    outcode2 = outcode(X2, Y2, cxmin, cymin, cxmax, cymax); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    while ((outcode1 | outcode2) != 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        CALC_TYPE xsteps, ysteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if ((outcode1 & outcode2) != 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            return JNI_FALSE; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (outcode1 != 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (outcode1 & (OUTCODE_TOP | OUTCODE_BOTTOM)) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                if (outcode1 & OUTCODE_TOP) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    Y1 = cymin; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                } else { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    Y1 = cymax; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                ysteps = Y1 - ORIGY1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                if (ysteps < 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                    ysteps = -ysteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                xsteps = 2 * ysteps * ax + ay; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                if (xmajor) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                    xsteps += ay - ax - 1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                xsteps = xsteps / (2 * ay); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                if (dx < 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    xsteps = -xsteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                X1 = ORIGX1 + (jint) xsteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            } else if (outcode1 & (OUTCODE_LEFT | OUTCODE_RIGHT)) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                if (outcode1 & OUTCODE_LEFT) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                    X1 = cxmin; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                } else { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    X1 = cxmax; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                xsteps = X1 - ORIGX1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                if (xsteps < 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    xsteps = -xsteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                ysteps = 2 * xsteps * ay + ax; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                if (!xmajor) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    ysteps += ax - ay - 1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                ysteps = ysteps / (2 * ax); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                if (dy < 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    ysteps = -ysteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                Y1 = ORIGY1 + (jint) ysteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            outcode1 = outcode(X1, Y1, cxmin, cymin, cxmax, cymax); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        } else { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            if (outcode2 & (OUTCODE_TOP | OUTCODE_BOTTOM)) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                if (outcode2 & OUTCODE_TOP) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    Y2 = cymin; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                } else { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    Y2 = cymax; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                ysteps = Y2 - ORIGY2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                if (ysteps < 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    ysteps = -ysteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                xsteps = 2 * ysteps * ax + ay; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                if (xmajor) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    xsteps += ay - ax; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                } else { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    xsteps -= 1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                xsteps = xsteps / (2 * ay); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                if (dx > 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    xsteps = -xsteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                X2 = ORIGX2 + (jint) xsteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            } else if (outcode2 & (OUTCODE_LEFT | OUTCODE_RIGHT)) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                if (outcode2 & OUTCODE_LEFT) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    X2 = cxmin; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                } else { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    X2 = cxmax; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                xsteps = X2 - ORIGX2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                if (xsteps < 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                    xsteps = -xsteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                ysteps = 2 * xsteps * ay + ax; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                if (xmajor) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                    ysteps -= 1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                } else { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    ysteps += ax - ay; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                ysteps = ysteps / (2 * ax); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                if (dy > 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    ysteps = -ysteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                Y2 = ORIGY2 + (jint) ysteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            outcode2 = outcode(X2, Y2, cxmin, cymin, cxmax, cymax); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    *pStartX = X1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    *pStartY = Y1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    if (xmajor) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        errmajor = ay * 2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        errminor = ax * 2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        *pBumpMajorMask = (dx < 0) ? BUMP_NEG_PIXEL : BUMP_POS_PIXEL; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        *pBumpMinorMask = (dy < 0) ? BUMP_NEG_SCAN : BUMP_POS_SCAN; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        ax = -ax; /* For clipping adjustment below */ \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        steps = X2 - X1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (X2 != ORIGX2) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            SHORTEN = 0; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    } else { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        errmajor = ax * 2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        errminor = ay * 2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        *pBumpMajorMask = (dy < 0) ? BUMP_NEG_SCAN : BUMP_POS_SCAN; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        *pBumpMinorMask = (dx < 0) ? BUMP_NEG_PIXEL : BUMP_POS_PIXEL; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        ay = -ay; /* For clipping adjustment below */ \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        steps = Y2 - Y1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (Y2 != ORIGY2) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            SHORTEN = 0; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    if ((steps = ((steps >= 0) ? steps : -steps) + 1 - SHORTEN) == 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return JNI_FALSE; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    error = - (errminor / 2); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    if (Y1 != ORIGY1) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        jint ysteps = Y1 - ORIGY1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (ysteps < 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            ysteps = -ysteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        error += ysteps * ax * 2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    if (X1 != ORIGX1) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        jint xsteps = X1 - ORIGX1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (xsteps < 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            xsteps = -xsteps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        error += xsteps * ay * 2; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    } \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    error += errmajor; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    errminor -= errmajor; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    *pSteps = steps; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    *pError = error; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    *pErrMajor = errmajor; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    *pErrMinor = errminor; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
} while (0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
static jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
LineUtils_SetupBresenhamBig(jint _x1, jint _y1, jint _x2, jint _y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                            jint shorten,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                            SurfaceDataBounds *pBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                            jint *pStartX, jint *pStartY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                            jint *pSteps, jint *pError,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                            jint *pErrMajor, jint *pBumpMajorMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                            jint *pErrMinor, jint *pBumpMinorMask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * Part of calculating the Bresenham parameters for line stepping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * involves being able to store numbers that are twice the magnitude
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * of the biggest absolute difference in coordinates.  Since we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * want the stepping parameters to be stored in jints, we then need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * to avoid any absolute differences more than 30 bits.  Thus, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * need to preprocess the coordinates to reduce their range to 30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * bits regardless of clipping.  We need to cut their range back
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * before we do the clipping because the Bresenham stepping values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * need to be calculated based on the "unclipped" coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Thus, first we perform a "pre-clipping" stage to bring the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * coordinates within the 30-bit range and then we proceed to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * regular clipping procedure, pretending that these were the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * original coordinates all along.  Since this operation occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * based on a constant "pre-clip" rectangle of +/- 30 bits without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * any consideration for the final clip, the rounding errors that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * occur here will depend only on the line coordinates and be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * invariant with respect to the particular device/user clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * rectangles in effect at the time.  Thus, rendering a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * large-range line will be consistent under a variety of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * clipping conditions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    if (OverflowsBig(_x1) || OverflowsBig(_y1) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        OverflowsBig(_x2) || OverflowsBig(_y2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         * Use doubles to get us into range for "Big" arithmetic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         * The math of adjusting an endpoint for clipping can involve
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
         * an intermediate result with twice the number of bits as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
         * original coordinate range.  Since we want to maintain as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
         * much as 30 bits of precision in the resulting coordinates,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
         * we will get roundoff here even using IEEE double-precision
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
         * arithmetic which cannot carry 60 bits of mantissa.  Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
         * the rounding errors will be consistent for a given set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
         * of input coordinates the potential roundoff error should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
         * not affect the consistency of our rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        double X1d = _x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        double Y1d = _y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        double X2d = _x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        double Y2d = _y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        double DXd = X2d - X1d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        double DYd = Y2d - Y1d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        if (_x1 < BIG_MIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            Y1d = _y1 + (BIG_MIN - _x1) * DYd / DXd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            X1d = BIG_MIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        } else if (_x1 > BIG_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            Y1d = _y1 - (_x1 - BIG_MAX) * DYd / DXd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            X1d = BIG_MAX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        /* Use Y1d instead of _y1 for testing now as we may have modified it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (Y1d < BIG_MIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            X1d = _x1 + (BIG_MIN - _y1) * DXd / DYd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            Y1d = BIG_MIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        } else if (Y1d > BIG_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            X1d = _x1 - (_y1 - BIG_MAX) * DXd / DYd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            Y1d = BIG_MAX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if (_x2 < BIG_MIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            Y2d = _y2 + (BIG_MIN - _x2) * DYd / DXd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            X2d = BIG_MIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        } else if (_x2 > BIG_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            Y2d = _y2 - (_x2 - BIG_MAX) * DYd / DXd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            X2d = BIG_MAX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        /* Use Y2d instead of _y2 for testing now as we may have modified it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (Y2d < BIG_MIN) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            X2d = _x2 + (BIG_MIN - _y2) * DXd / DYd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            Y2d = BIG_MIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        } else if (Y2d > BIG_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            X2d = _x2 - (_y2 - BIG_MAX) * DXd / DYd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            Y2d = BIG_MAX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        _x1 = (int) X1d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        _y1 = (int) Y1d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        _x2 = (int) X2d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        _y2 = (int) Y2d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    SETUP_BRESENHAM(jlong, _x1, _y1, _x2, _y2, shorten);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
jboolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
LineUtils_SetupBresenham(jint _x1, jint _y1, jint _x2, jint _y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                         jint shorten,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                         SurfaceDataBounds *pBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                         jint *pStartX, jint *pStartY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                         jint *pSteps, jint *pError,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                         jint *pErrMajor, jint *pBumpMajorMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                         jint *pErrMinor, jint *pBumpMinorMask)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    if (OverflowsSmall(_x1) || OverflowsSmall(_y1) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        OverflowsSmall(_x2) || OverflowsSmall(_y2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        return LineUtils_SetupBresenhamBig(_x1, _y1, _x2, _y2, shorten,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                                           pBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                                           pStartX, pStartY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                                           pSteps, pError,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                                           pErrMajor, pBumpMajorMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                           pErrMinor, pBumpMinorMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    SETUP_BRESENHAM(jint, _x1, _y1, _x2, _y2, shorten);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
 * Class:     sun_java2d_loops_DrawLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
 * Method:    DrawLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
 * Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;IIII)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
Java_sun_java2d_loops_DrawLine_DrawLine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    (JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     jobject sg2d, jobject sData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     jint x1, jint y1, jint x2, jint y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    SurfaceDataOps *sdOps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    SurfaceDataRasInfo rasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    NativePrimitive *pPrim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    CompositeInfo compInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    jint pixel = GrPrim_Sg2dGetPixel(env, sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    pPrim = GetNativePrim(env, self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    if (pPrim == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    if (pPrim->pCompType->getCompInfo != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        GrPrim_Sg2dGetCompInfo(env, sg2d, pPrim, &compInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    sdOps = SurfaceData_GetOps(env, sData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    if (sdOps == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    GrPrim_Sg2dGetClip(env, sg2d, &rasInfo.bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    RefineBounds(&rasInfo.bounds, x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    if (sdOps->Lock(env, sdOps, &rasInfo, pPrim->dstflags) != SD_SUCCESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    if (rasInfo.bounds.x2 > rasInfo.bounds.x1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        rasInfo.bounds.y2 > rasInfo.bounds.y1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        sdOps->GetRasInfo(env, sdOps, &rasInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        if (rasInfo.rasBase) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            LineUtils_ProcessLine(&rasInfo, pixel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                  pPrim->funcs.drawline, pPrim, &compInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                  x1, y1, x2, y2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        SurfaceData_InvokeRelease(env, sdOps, &rasInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
}