Path: blob/master/src/java.desktop/share/native/libawt/java2d/loops/FillPath.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_FillPath.h"3536static void drawScanline(DrawHandler* hnd, jint x0, jint x1, jint y0) {37DHND(hnd)->pPrim->funcs.drawline(38DHND(hnd)->pRasInfo, x0, y0, DHND(hnd)->pixel, x1 - x0 + 1, 0,39BUMP_POS_PIXEL, 0, BUMP_NOOP, 0,40DHND(hnd)->pPrim, DHND(hnd)->pCompInfo);41}4243/*44* Class: sun_java2d_loops_FillPath45* Method: FillPath46* Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;IILjava/awt/geom/Path2D.Float;)V47*/48JNIEXPORT void JNICALL Java_sun_java2d_loops_FillPath_FillPath49(JNIEnv *env, jobject self,50jobject sg2d, jobject sData,51jint transX, jint transY, jobject p2df)52{53jarray typesArray;54jarray coordsArray;55jint numTypes;56jint fillRule;57jboolean ok = JNI_TRUE;58jint pixel = GrPrim_Sg2dGetPixel(env, sg2d);59jint maxCoords;60jfloat *coords;61SurfaceDataOps *sdOps;62SurfaceDataRasInfo rasInfo;63CompositeInfo compInfo;64jint ret;65NativePrimitive *pPrim = GetNativePrim(env, self);66jint stroke;67jboolean throwExc = JNI_FALSE;6869if (pPrim == NULL) {70return;71}72if (pPrim->pCompType->getCompInfo != NULL) {73GrPrim_Sg2dGetCompInfo(env, sg2d, pPrim, &compInfo);74}7576stroke = (*env)->GetIntField(env, sg2d, sg2dStrokeHintID);7778sdOps = SurfaceData_GetOps(env, sData);79if (sdOps == 0) {80return;81}8283typesArray = (jarray)(*env)->GetObjectField(env, p2df, path2DTypesID);84coordsArray = (jarray)(*env)->GetObjectField(env, p2df,85path2DFloatCoordsID);86if (coordsArray == NULL) {87JNU_ThrowNullPointerException(env, "coordinates array");88return;89}90numTypes = (*env)->GetIntField(env, p2df, path2DNumTypesID);91fillRule = (*env)->GetIntField(env, p2df, path2DWindingRuleID);92if ((*env)->GetArrayLength(env, typesArray) < numTypes) {93JNU_ThrowArrayIndexOutOfBoundsException(env, "types array");94return;95}9697GrPrim_Sg2dGetClip(env, sg2d, &rasInfo.bounds);9899ret = sdOps->Lock(env, sdOps, &rasInfo, SD_LOCK_FASTEST | pPrim->dstflags);100if (ret == SD_FAILURE) {101return;102}103104maxCoords = (*env)->GetArrayLength(env, coordsArray);105coords = (jfloat*)(*env)->GetPrimitiveArrayCritical(106env, coordsArray, NULL);107if (coords == NULL) {108SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);109return;110}111112if (ret == SD_SLOWLOCK) {113GrPrim_RefineBounds(&rasInfo.bounds, transX, transY,114coords, maxCoords);115ok = (rasInfo.bounds.x2 > rasInfo.bounds.x1 &&116rasInfo.bounds.y2 > rasInfo.bounds.y1);117}118119if (ok) {120sdOps->GetRasInfo(env, sdOps, &rasInfo);121if (rasInfo.rasBase) {122if (rasInfo.bounds.x2 > rasInfo.bounds.x1 &&123rasInfo.bounds.y2 > rasInfo.bounds.y1)124{125DrawHandlerData dHData;126DrawHandler drawHandler = {127NULL,128NULL,129&drawScanline,1300, 0, 0, 0,1310, 0, 0, 0,132NULL133};134135jbyte *types = (jbyte*)(*env)->GetPrimitiveArrayCritical(136env, typesArray, NULL);137138/* Initialization of the following fields in the declaration of139* the dHData and drawHandler above causes warnings on sun140* studio compiler with141* -xc99=%none option applied (this option means compliance142* with C90 standard instead of C99)143*/144dHData.pRasInfo = &rasInfo;145dHData.pixel = pixel;146dHData.pPrim = pPrim;147dHData.pCompInfo = &compInfo;148149drawHandler.xMin = rasInfo.bounds.x1;150drawHandler.yMin = rasInfo.bounds.y1;151drawHandler.xMax = rasInfo.bounds.x2;152drawHandler.yMax = rasInfo.bounds.y2;153drawHandler.pData = &dHData;154155if (types != NULL) {156if (!doFillPath(&drawHandler,157transX, transY, coords,158maxCoords, types, numTypes,159(stroke == sunHints_INTVAL_STROKE_PURE)?160PH_STROKE_PURE : PH_STROKE_DEFAULT,161fillRule))162{163throwExc = JNI_TRUE;164}165166(*env)->ReleasePrimitiveArrayCritical(env, typesArray, types,167JNI_ABORT);168}169}170}171SurfaceData_InvokeRelease(env, sdOps, &rasInfo);172}173(*env)->ReleasePrimitiveArrayCritical(env, coordsArray, coords,174JNI_ABORT);175176if (throwExc) {177JNU_ThrowArrayIndexOutOfBoundsException(env,178"coords array");179}180181SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);182}183184185