3172N/A/*
3261N/A * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
3172N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3172N/A *
3172N/A * This code is free software; you can redistribute it and/or modify it
3172N/A * under the terms of the GNU General Public License version 2 only, as
3172N/A * published by the Free Software Foundation. Oracle designates this
3172N/A * particular file as subject to the "Classpath" exception as provided
3172N/A * by Oracle in the LICENSE file that accompanied this code.
3172N/A *
3172N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3172N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3172N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3172N/A * version 2 for more details (a copy is included in the LICENSE file that
3172N/A * accompanied this code).
3172N/A *
3172N/A * You should have received a copy of the GNU General Public License version
3172N/A * 2 along with this work; if not, write to the Free Software Foundation,
3172N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3172N/A *
3172N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3172N/A * or visit www.oracle.com if you need additional information or have any
3172N/A * questions.
3172N/A */
3172N/A
3172N/A#include "math.h"
3172N/A#include "GraphicsPrimitiveMgr.h"
3265N/A#include "ParallelogramUtils.h"
3172N/A
3172N/A#include "sun_java2d_loops_FillParallelogram.h"
3172N/A
3172N/A/*
3172N/A * Class: sun_java2d_loops_FillParallelogram
3172N/A * Method: FillParallelogram
3172N/A * Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;DDDDDD)V
3172N/A */
3172N/AJNIEXPORT void JNICALL
3172N/AJava_sun_java2d_loops_FillParallelogram_FillParallelogram
3172N/A (JNIEnv *env, jobject self,
3172N/A jobject sg2d, jobject sData,
3172N/A jdouble x0, jdouble y0,
3172N/A jdouble dx1, jdouble dy1,
3172N/A jdouble dx2, jdouble dy2)
3172N/A{
3172N/A SurfaceDataOps *sdOps;
3172N/A SurfaceDataRasInfo rasInfo;
3172N/A NativePrimitive *pPrim;
3172N/A CompositeInfo compInfo;
3172N/A jint pixel;
3172N/A jint ix1, iy1, ix2, iy2;
3172N/A
3172N/A if ((dy1 == 0 && dx1 == 0) || (dy2 == 0 && dx2 == 0)) {
3172N/A return;
3172N/A }
3172N/A
3172N/A /*
3172N/A * Sort parallelogram by y values, ensure that each delta vector
3265N/A * has a non-negative y delta.
3172N/A */
3265N/A SORT_PGRAM(x0, y0, dx1, dy1, dx2, dy2, );
3265N/A
3265N/A PGRAM_MIN_MAX(ix1, ix2, x0, dx1, dx2, JNI_FALSE);
3172N/A iy1 = (jint) floor(y0 + 0.5);
3172N/A iy2 = (jint) floor(y0 + dy1 + dy2 + 0.5);
3172N/A
3172N/A pPrim = GetNativePrim(env, self);
3172N/A if (pPrim == NULL) {
3172N/A return;
3172N/A }
3172N/A pixel = GrPrim_Sg2dGetPixel(env, sg2d);
3172N/A if (pPrim->pCompType->getCompInfo != NULL) {
3172N/A GrPrim_Sg2dGetCompInfo(env, sg2d, pPrim, &compInfo);
3172N/A }
3172N/A
3172N/A sdOps = SurfaceData_GetOps(env, sData);
3172N/A if (sdOps == NULL) {
3172N/A return;
3172N/A }
3172N/A
3172N/A GrPrim_Sg2dGetClip(env, sg2d, &rasInfo.bounds);
3172N/A SurfaceData_IntersectBoundsXYXY(&rasInfo.bounds, ix1, iy1, ix2, iy2);
3172N/A if (rasInfo.bounds.y2 <= rasInfo.bounds.y1 ||
3172N/A rasInfo.bounds.x2 <= rasInfo.bounds.x1)
3172N/A {
3172N/A return;
3172N/A }
3172N/A
3172N/A if (sdOps->Lock(env, sdOps, &rasInfo, pPrim->dstflags) != SD_SUCCESS) {
3172N/A return;
3172N/A }
3172N/A
3172N/A ix1 = rasInfo.bounds.x1;
3172N/A iy1 = rasInfo.bounds.y1;
3172N/A ix2 = rasInfo.bounds.x2;
3172N/A iy2 = rasInfo.bounds.y2;
3172N/A if (ix2 > ix1 && iy2 > iy1) {
3172N/A sdOps->GetRasInfo(env, sdOps, &rasInfo);
3172N/A if (rasInfo.rasBase) {
3172N/A jdouble lslope = (dy1 == 0) ? 0 : dx1 / dy1;
3172N/A jdouble rslope = (dy2 == 0) ? 0 : dx2 / dy2;
3172N/A jlong ldx = DblToLong(lslope);
3172N/A jlong rdx = DblToLong(rslope);
3172N/A jint cy1, cy2, loy, hiy;
3172N/A dx1 += x0;
3172N/A dy1 += y0;
3172N/A dx2 += x0;
3172N/A dy2 += y0;
3172N/A cy1 = (jint) floor(dy1 + 0.5);
3172N/A cy2 = (jint) floor(dy2 + 0.5);
3172N/A
3172N/A /* Top triangular portion. */
3172N/A loy = iy1;
3172N/A hiy = (cy1 < cy2) ? cy1 : cy2;
3172N/A if (hiy > iy2) hiy = iy2;
3172N/A if (loy < hiy) {
3172N/A jlong lx = PGRAM_INIT_X(loy, x0, y0, lslope);
3172N/A jlong rx = PGRAM_INIT_X(loy, x0, y0, rslope);
3172N/A (*pPrim->funcs.fillparallelogram)(&rasInfo,
3172N/A ix1, loy, ix2, hiy,
3172N/A lx, ldx, rx, rdx,
3172N/A pixel, pPrim, &compInfo);
3172N/A }
3172N/A
3172N/A /* Middle parallelogram portion, which way does it slant? */
3172N/A if (cy1 < cy2) {
3172N/A /* Middle parallelogram portion, slanted to right. */
3172N/A /* left leg turned a corner at y0+dy1 */
3172N/A /* right leg continuing on its initial trajectory from y0 */
3172N/A loy = cy1;
3172N/A hiy = cy2;
3172N/A if (loy < iy1) loy = iy1;
3172N/A if (hiy > iy2) hiy = iy2;
3172N/A if (loy < hiy) {
3172N/A jlong lx = PGRAM_INIT_X(loy, dx1, dy1, rslope);
3172N/A jlong rx = PGRAM_INIT_X(loy, x0, y0, rslope);
3172N/A (*pPrim->funcs.fillparallelogram)(&rasInfo,
3172N/A ix1, loy, ix2, hiy,
3172N/A lx, rdx, rx, rdx,
3172N/A pixel, pPrim, &compInfo);
3172N/A }
3172N/A } else if (cy2 < cy1) {
3172N/A /* Middle parallelogram portion, slanted to left. */
3172N/A /* left leg continuing on its initial trajectory from y0 */
3172N/A /* right leg turned a corner at y0+dy2 */
3172N/A loy = cy2;
3172N/A hiy = cy1;
3172N/A if (loy < iy1) loy = iy1;
3172N/A if (hiy > iy2) hiy = iy2;
3172N/A if (loy < hiy) {
3172N/A jlong lx = PGRAM_INIT_X(loy, x0, y0, lslope);
3172N/A jlong rx = PGRAM_INIT_X(loy, dx2, dy2, lslope);
3172N/A (*pPrim->funcs.fillparallelogram)(&rasInfo,
3172N/A ix1, loy, ix2, hiy,
3172N/A lx, ldx, rx, ldx,
3172N/A pixel, pPrim, &compInfo);
3172N/A }
3172N/A }
3172N/A
3172N/A /* Bottom triangular portion. */
3172N/A loy = (cy1 > cy2) ? cy1 : cy2;
3172N/A if (loy < iy1) loy = iy1;
3172N/A hiy = iy2;
3172N/A if (loy < hiy) {
3172N/A /* left leg turned its corner at y0+dy1, now moving right */
3172N/A /* right leg turned its corner at y0+dy2, now moving left */
3172N/A jlong lx = PGRAM_INIT_X(loy, dx1, dy1, rslope);
3172N/A jlong rx = PGRAM_INIT_X(loy, dx2, dy2, lslope);
3172N/A (*pPrim->funcs.fillparallelogram)(&rasInfo,
3172N/A ix1, loy, ix2, hiy,
3172N/A lx, rdx, rx, ldx,
3172N/A pixel, pPrim, &compInfo);
3172N/A }
3172N/A }
3172N/A SurfaceData_InvokeRelease(env, sdOps, &rasInfo);
3172N/A }
3172N/A SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);
3172N/A}