jdk/src/share/native/sun/java2d/loops/FillPath.c
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 20421 8fab9959a1bc
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
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) 2005, 2006, 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 <math.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <float.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "GraphicsPrimitiveMgr.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "LineUtils.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "ProcessPath.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "DrawPath.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "sun_java2d_loops_FillPath.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
static void drawScanline(DrawHandler* hnd, jint x0, jint x1, jint y0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    DHND(hnd)->pPrim->funcs.drawline(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        DHND(hnd)->pRasInfo, x0, y0, DHND(hnd)->pixel, x1 - x0 + 1, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        BUMP_POS_PIXEL, 0, BUMP_NOOP, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        DHND(hnd)->pPrim, DHND(hnd)->pCompInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Class:     sun_java2d_loops_FillPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Method:    FillPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;IILjava/awt/geom/Path2D.Float;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
JNIEXPORT void JNICALL Java_sun_java2d_loops_FillPath_FillPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    (JNIEnv *env, jobject self,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     jobject sg2d, jobject sData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     jint transX, jint transY, jobject p2df)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    jarray typesArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    jarray coordsArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    jint numTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    jint fillRule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    jboolean ok = JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    jint pixel = GrPrim_Sg2dGetPixel(env, sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    jint maxCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    jfloat *coords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    SurfaceDataOps *sdOps;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    SurfaceDataRasInfo rasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    CompositeInfo compInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    jint ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    NativePrimitive *pPrim = GetNativePrim(env, self);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    jint stroke = (*env)->GetIntField(env, sg2d, sg2dStrokeHintID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    if (pPrim == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    if (pPrim->pCompType->getCompInfo != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        GrPrim_Sg2dGetCompInfo(env, sg2d, pPrim, &compInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    sdOps = SurfaceData_GetOps(env, sData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    if (sdOps == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    typesArray = (jarray)(*env)->GetObjectField(env, p2df, path2DTypesID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    coordsArray = (jarray)(*env)->GetObjectField(env, p2df,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                                 path2DFloatCoordsID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    if (coordsArray == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        JNU_ThrowNullPointerException(env, "coordinates array");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    numTypes = (*env)->GetIntField(env, p2df, path2DNumTypesID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    fillRule = (*env)->GetIntField(env, p2df, path2DWindingRuleID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    if ((*env)->GetArrayLength(env, typesArray) < numTypes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        JNU_ThrowArrayIndexOutOfBoundsException(env, "types array");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    GrPrim_Sg2dGetClip(env, sg2d, &rasInfo.bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    ret = sdOps->Lock(env, sdOps, &rasInfo, SD_LOCK_FASTEST | pPrim->dstflags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    if (ret == SD_FAILURE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    maxCoords = (*env)->GetArrayLength(env, coordsArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    coords = (jfloat*)(*env)->GetPrimitiveArrayCritical(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            env, coordsArray, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    if (ret == SD_SLOWLOCK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        GrPrim_RefineBounds(&rasInfo.bounds, transX, transY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                     coords, maxCoords);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        ok = (rasInfo.bounds.x2 > rasInfo.bounds.x1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
              rasInfo.bounds.y2 > rasInfo.bounds.y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    if (ok) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        sdOps->GetRasInfo(env, sdOps, &rasInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (rasInfo.rasBase) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            if (rasInfo.bounds.x2 > rasInfo.bounds.x1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                rasInfo.bounds.y2 > rasInfo.bounds.y1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                DrawHandlerData dHData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                DrawHandler drawHandler = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    &drawScanline,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    0, 0, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    0, 0, 0, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                jbyte *types = (jbyte*)(*env)->GetPrimitiveArrayCritical(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    env, typesArray, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                /* Initialization of the following fields in the declaration of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                 * the dHData and drawHandler above causes warnings on sun
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                 * studio compiler with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                 * -xc99=%none option applied (this option means compliance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                 *  with C90 standard instead of C99)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                dHData.pRasInfo = &rasInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                dHData.pixel = pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                dHData.pPrim = pPrim;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                dHData.pCompInfo = &compInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                drawHandler.xMin = rasInfo.bounds.x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                drawHandler.yMin = rasInfo.bounds.y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                drawHandler.xMax = rasInfo.bounds.x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                drawHandler.yMax = rasInfo.bounds.y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                drawHandler.pData = &dHData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                if (!doFillPath(&drawHandler,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                transX, transY, coords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                maxCoords, types, numTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                (stroke == sunHints_INTVAL_STROKE_PURE)?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                     PH_STROKE_PURE : PH_STROKE_DEFAULT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                fillRule))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    JNU_ThrowArrayIndexOutOfBoundsException(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                                            "coords array");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                (*env)->ReleasePrimitiveArrayCritical(env, typesArray, types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                                      JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        SurfaceData_InvokeRelease(env, sdOps, &rasInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    (*env)->ReleasePrimitiveArrayCritical(env, coordsArray, coords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                          JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
}