Path: blob/master/src/java.desktop/share/native/libawt/java2d/loops/DrawRect.c
41159 views
/*1* Copyright (c) 2000, 2001, 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 "GraphicsPrimitiveMgr.h"26#include "LineUtils.h"2728#include "sun_java2d_loops_DrawRect.h"2930/*31* Class: sun_java2d_loops_DrawRect32* Method: DrawRect33* Signature: (Lsun/java2d/SunGraphics2D;Lsun/java2d/SurfaceData;IIII)V34*/35JNIEXPORT void JNICALL36Java_sun_java2d_loops_DrawRect_DrawRect37(JNIEnv *env, jobject self,38jobject sg2d, jobject sData,39jint x, jint y, jint w, jint h)40{41SurfaceDataOps *sdOps;42SurfaceDataRasInfo rasInfo;43NativePrimitive *pPrim;44CompositeInfo compInfo;45jint lox, loy, hix, hiy;46jint pixel = GrPrim_Sg2dGetPixel(env, sg2d);4748if (w < 0 || h < 0) {49return;50}5152pPrim = GetNativePrim(env, self);53if (pPrim == NULL) {54return;55}56if (pPrim->pCompType->getCompInfo != NULL) {57GrPrim_Sg2dGetCompInfo(env, sg2d, pPrim, &compInfo);58}5960sdOps = SurfaceData_GetOps(env, sData);61if (sdOps == 0) {62return;63}6465lox = x;66loy = y;67hix = x + w + 1;68hiy = y + h + 1;69if (hix < lox) {70hix = 0x7fffffff;71}72if (hiy < loy) {73hiy = 0x7fffffff;74}7576GrPrim_Sg2dGetClip(env, sg2d, &rasInfo.bounds);77if (rasInfo.bounds.x1 < lox) rasInfo.bounds.x1 = lox;78if (rasInfo.bounds.y1 < loy) rasInfo.bounds.y1 = loy;79if (rasInfo.bounds.x2 > hix) rasInfo.bounds.x2 = hix;80if (rasInfo.bounds.y2 > hiy) rasInfo.bounds.y2 = hiy;81if (sdOps->Lock(env, sdOps, &rasInfo, pPrim->dstflags) != SD_SUCCESS) {82return;83}8485if (rasInfo.bounds.x2 > rasInfo.bounds.x1 &&86rasInfo.bounds.y2 > rasInfo.bounds.y1)87{88sdOps->GetRasInfo(env, sdOps, &rasInfo);89if (rasInfo.rasBase) {90DrawLineFunc *pLine = pPrim->funcs.drawline;91int loyin = (loy == rasInfo.bounds.y1);92int hiyin = (hiy == rasInfo.bounds.y2);93int xsize = (rasInfo.bounds.x2 - rasInfo.bounds.x1);94int ysize = (rasInfo.bounds.y2 - rasInfo.bounds.y1 - loyin - hiyin);95/*96* To avoid drawing the corners twice (both for performance97* and because XOR erases them otherwise) and to maximize the98* number of pixels we draw in the horizontal portions99* which are more cache-friendly, we include the corner100* pixels only in the top and bottom segments.101* We also protect against degenerate rectangles where we102* would draw the same line for top & bottom or left & right.103*/104if (loyin) {105/* Line across the top */106(*pLine)(&rasInfo,107rasInfo.bounds.x1, rasInfo.bounds.y1,108pixel, xsize, 0,109BUMP_POS_PIXEL, 0, BUMP_NOOP, 0, pPrim, &compInfo);110}111if (lox == rasInfo.bounds.x1 && ysize > 0) {112/* Line down the left side */113(*pLine)(&rasInfo,114rasInfo.bounds.x1, rasInfo.bounds.y1 + loyin,115pixel, ysize, 0,116BUMP_POS_SCAN, 0, BUMP_NOOP, 0, pPrim, &compInfo);117}118if (hix == rasInfo.bounds.x2 && ysize > 0 && lox != hix - 1) {119/* Line down the right side */120(*pLine)(&rasInfo,121rasInfo.bounds.x2 - 1, rasInfo.bounds.y1 + loyin,122pixel, ysize, 0,123BUMP_POS_SCAN, 0, BUMP_NOOP, 0, pPrim, &compInfo);124}125if (hiyin && loy != hiy - 1) {126/* Line across the bottom */127(*pLine)(&rasInfo,128rasInfo.bounds.x1, rasInfo.bounds.y2 - 1,129pixel, xsize, 0,130BUMP_POS_PIXEL, 0, BUMP_NOOP, 0, pPrim, &compInfo);131}132}133SurfaceData_InvokeRelease(env, sdOps, &rasInfo);134}135SurfaceData_InvokeUnlock(env, sdOps, &rasInfo);136}137138139