Path: blob/master/src/java.desktop/share/native/libawt/java2d/loops/DrawPath.c
41159 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <math.h>26#include <float.h>27#include "jni_util.h"2829#include "GraphicsPrimitiveMgr.h"30#include "LineUtils.h"31#include "ProcessPath.h"32#include "DrawPath.h"3334#include "sun_java2d_loops_DrawPath.h"3536static void processLine(DrawHandler* hnd,37jint x0, jint y0, jint x1, jint y1)38{39LineUtils_ProcessLine(DHND(hnd)->pRasInfo,40DHND(hnd)->pixel,41DHND(hnd)->pPrim->funcs.drawline,42DHND(hnd)->pPrim,43DHND(hnd)->pCompInfo,44x0, y0, x1, y1, 0);45}4647static void processPoint(DrawHandler* hnd, jint x0, jint y0)48{49DHND(hnd)->pPrim->funcs.drawline(50DHND(hnd)->pRasInfo, x0, y0, DHND(hnd)->pixel, 1, 0,51BUMP_POS_PIXEL, 0, BUMP_NOOP, 0,52DHND(hnd)->pPrim, DHND(hnd)->pCompInfo);53}5455/*56* Class: sun_java2d_loops_DrawPath57* Method: DrawPath58* Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;IILjava/awt/geom/Path2D.Float;)V59*/60JNIEXPORT void JNICALL Java_sun_java2d_loops_DrawPath_DrawPath61(JNIEnv *env, jobject self,62jobject sg2d, jobject sData,63jint transX, jint transY, jobject p2df)64{65jarray typesArray;66jarray coordsArray;67jint numTypes;68jboolean ok = JNI_TRUE;69jint pixel = GrPrim_Sg2dGetPixel(env, sg2d);70jint maxCoords;71jfloat *coords;72SurfaceDataOps *sdOps;73SurfaceDataRasInfo rasInfo;74CompositeInfo compInfo;75jint ret;76NativePrimitive *pPrim = GetNativePrim(env, self);77jint stroke;78jboolean throwExc = JNI_FALSE;7980if (pPrim == NULL) {81return;82}83if (pPrim->pCompType->getCompInfo != NULL) {84GrPrim_Sg2dGetCompInfo(env, sg2d, pPrim, &compInfo);85}8687stroke = (*env)->GetIntField(env, sg2d, sg2dStrokeHintID);8889sdOps = SurfaceData_GetOps(env, sData);90if (sdOps == 0) {91return;92}9394typesArray = (jarray)(*env)->GetObjectField(env, p2df, path2DTypesID);95coordsArray = (jarray)(*env)->GetObjectField(env, p2df,96path2DFloatCoordsID);97if (coordsArray == NULL) {98JNU_ThrowNullPointerException(env, "coordinates array");99return;100}101numTypes = (*env)->GetIntField(env, p2df, path2DNumTypesID);102if ((*env)->GetArrayLength(env, typesArray) < numTypes) {103JNU_ThrowArrayIndexOutOfBoundsException(env, "types array");104return;105}106107GrPrim_Sg2dGetClip(env, sg2d, &rasInfo.bounds);108109ret = sdOps->Lock(env, sdOps, &rasInfo, SD_LOCK_FASTEST | pPrim->dstflags);110if (ret == SD_FAILURE) {111return;112}113114maxCoords = (*env)->GetArrayLength(env, coordsArray);115coords = (jfloat*)(*env)->GetPrimitiveArrayCritical(116env, coordsArray, NULL);117if (coords == NULL) {118SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);119return;120}121122if (ret == SD_SLOWLOCK) {123GrPrim_RefineBounds(&rasInfo.bounds, transX, transY,124coords, maxCoords);125ok = (rasInfo.bounds.x2 > rasInfo.bounds.x1 &&126rasInfo.bounds.y2 > rasInfo.bounds.y1);127}128129if (ok) {130sdOps->GetRasInfo(env, sdOps, &rasInfo);131if (rasInfo.rasBase) {132if (rasInfo.bounds.x2 > rasInfo.bounds.x1 &&133rasInfo.bounds.y2 > rasInfo.bounds.y1)134{135DrawHandlerData dHData;136DrawHandler drawHandler =137{138&processLine,139&processPoint,140NULL,1410, 0, 0, 0,1420, 0, 0, 0,143NULL144};145146jbyte *types = (jbyte*)(*env)->GetPrimitiveArrayCritical(147env, typesArray, NULL);148149/* Initialization of the following fields in the declaration of150* the dHData and drawHandler above causes warnings on sun151* studio compiler with152* -xc99=%none option applied (this option means compliance153* with C90 standard instead of C99)154*/155dHData.pRasInfo = &rasInfo;156dHData.pixel = pixel;157dHData.pPrim = pPrim;158dHData.pCompInfo = &compInfo;159160drawHandler.xMin = rasInfo.bounds.x1;161drawHandler.yMin = rasInfo.bounds.y1;162drawHandler.xMax = rasInfo.bounds.x2;163drawHandler.yMax = rasInfo.bounds.y2;164drawHandler.pData = &dHData;165166if (types != NULL) {167if (!doDrawPath(&drawHandler, NULL, transX, transY,168coords, maxCoords, types, numTypes,169(stroke == sunHints_INTVAL_STROKE_PURE)?170PH_STROKE_PURE : PH_STROKE_DEFAULT))171{172throwExc = JNI_TRUE;173}174175(*env)->ReleasePrimitiveArrayCritical(env, typesArray, types,176JNI_ABORT);177}178}179}180SurfaceData_InvokeRelease(env, sdOps, &rasInfo);181}182(*env)->ReleasePrimitiveArrayCritical(env, coordsArray, coords,183JNI_ABORT);184185if (throwExc) {186JNU_ThrowArrayIndexOutOfBoundsException(env,187"coords array");188}189190SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);191}192193194