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