Path: blob/master/src/java.desktop/share/native/libawt/java2d/loops/FillParallelogram.c
41159 views
/*1* Copyright (c) 2008, 2010, 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 "GraphicsPrimitiveMgr.h"27#include "ParallelogramUtils.h"2829#include "sun_java2d_loops_FillParallelogram.h"3031/*32* Class: sun_java2d_loops_FillParallelogram33* Method: FillParallelogram34* Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;DDDDDD)V35*/36JNIEXPORT void JNICALL37Java_sun_java2d_loops_FillParallelogram_FillParallelogram38(JNIEnv *env, jobject self,39jobject sg2d, jobject sData,40jdouble x0, jdouble y0,41jdouble dx1, jdouble dy1,42jdouble dx2, jdouble dy2)43{44SurfaceDataOps *sdOps;45SurfaceDataRasInfo rasInfo;46NativePrimitive *pPrim;47CompositeInfo compInfo;48jint pixel;49jint ix1, iy1, ix2, iy2;5051if ((dy1 == 0 && dx1 == 0) || (dy2 == 0 && dx2 == 0)) {52return;53}5455/*56* Sort parallelogram by y values, ensure that each delta vector57* has a non-negative y delta.58*/59SORT_PGRAM(x0, y0, dx1, dy1, dx2, dy2, );6061PGRAM_MIN_MAX(ix1, ix2, x0, dx1, dx2, JNI_FALSE);62iy1 = (jint) floor(y0 + 0.5);63iy2 = (jint) floor(y0 + dy1 + dy2 + 0.5);6465pPrim = GetNativePrim(env, self);66if (pPrim == NULL) {67return;68}69pixel = GrPrim_Sg2dGetPixel(env, sg2d);70if (pPrim->pCompType->getCompInfo != NULL) {71GrPrim_Sg2dGetCompInfo(env, sg2d, pPrim, &compInfo);72}7374sdOps = SurfaceData_GetOps(env, sData);75if (sdOps == NULL) {76return;77}7879GrPrim_Sg2dGetClip(env, sg2d, &rasInfo.bounds);80SurfaceData_IntersectBoundsXYXY(&rasInfo.bounds, ix1, iy1, ix2, iy2);81if (rasInfo.bounds.y2 <= rasInfo.bounds.y1 ||82rasInfo.bounds.x2 <= rasInfo.bounds.x1)83{84return;85}8687if (sdOps->Lock(env, sdOps, &rasInfo, pPrim->dstflags) != SD_SUCCESS) {88return;89}9091ix1 = rasInfo.bounds.x1;92iy1 = rasInfo.bounds.y1;93ix2 = rasInfo.bounds.x2;94iy2 = rasInfo.bounds.y2;95if (ix2 > ix1 && iy2 > iy1) {96sdOps->GetRasInfo(env, sdOps, &rasInfo);97if (rasInfo.rasBase) {98jdouble lslope = (dy1 == 0) ? 0 : dx1 / dy1;99jdouble rslope = (dy2 == 0) ? 0 : dx2 / dy2;100jlong ldx = DblToLong(lslope);101jlong rdx = DblToLong(rslope);102jint cy1, cy2, loy, hiy;103dx1 += x0;104dy1 += y0;105dx2 += x0;106dy2 += y0;107cy1 = (jint) floor(dy1 + 0.5);108cy2 = (jint) floor(dy2 + 0.5);109110/* Top triangular portion. */111loy = iy1;112hiy = (cy1 < cy2) ? cy1 : cy2;113if (hiy > iy2) hiy = iy2;114if (loy < hiy) {115jlong lx = PGRAM_INIT_X(loy, x0, y0, lslope);116jlong rx = PGRAM_INIT_X(loy, x0, y0, rslope);117(*pPrim->funcs.fillparallelogram)(&rasInfo,118ix1, loy, ix2, hiy,119lx, ldx, rx, rdx,120pixel, pPrim, &compInfo);121}122123/* Middle parallelogram portion, which way does it slant? */124if (cy1 < cy2) {125/* Middle parallelogram portion, slanted to right. */126/* left leg turned a corner at y0+dy1 */127/* right leg continuing on its initial trajectory from y0 */128loy = cy1;129hiy = cy2;130if (loy < iy1) loy = iy1;131if (hiy > iy2) hiy = iy2;132if (loy < hiy) {133jlong lx = PGRAM_INIT_X(loy, dx1, dy1, rslope);134jlong rx = PGRAM_INIT_X(loy, x0, y0, rslope);135(*pPrim->funcs.fillparallelogram)(&rasInfo,136ix1, loy, ix2, hiy,137lx, rdx, rx, rdx,138pixel, pPrim, &compInfo);139}140} else if (cy2 < cy1) {141/* Middle parallelogram portion, slanted to left. */142/* left leg continuing on its initial trajectory from y0 */143/* right leg turned a corner at y0+dy2 */144loy = cy2;145hiy = cy1;146if (loy < iy1) loy = iy1;147if (hiy > iy2) hiy = iy2;148if (loy < hiy) {149jlong lx = PGRAM_INIT_X(loy, x0, y0, lslope);150jlong rx = PGRAM_INIT_X(loy, dx2, dy2, lslope);151(*pPrim->funcs.fillparallelogram)(&rasInfo,152ix1, loy, ix2, hiy,153lx, ldx, rx, ldx,154pixel, pPrim, &compInfo);155}156}157158/* Bottom triangular portion. */159loy = (cy1 > cy2) ? cy1 : cy2;160if (loy < iy1) loy = iy1;161hiy = iy2;162if (loy < hiy) {163/* left leg turned its corner at y0+dy1, now moving right */164/* right leg turned its corner at y0+dy2, now moving left */165jlong lx = PGRAM_INIT_X(loy, dx1, dy1, rslope);166jlong rx = PGRAM_INIT_X(loy, dx2, dy2, lslope);167(*pPrim->funcs.fillparallelogram)(&rasInfo,168ix1, loy, ix2, hiy,169lx, rdx, rx, ldx,170pixel, pPrim, &compInfo);171}172}173SurfaceData_InvokeRelease(env, sdOps, &rasInfo);174}175SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);176}177178179