Path: blob/master/src/java.desktop/share/native/libawt/java2d/pipe/Region.h
41159 views
/*1* Copyright (c) 2002, 2007, 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#ifndef _Included_Region26#define _Included_Region2728#ifdef __cplusplus29extern "C" {30#endif3132#include <SurfaceData.h>33#include "utility/rect.h"343536/*37* This file provides a number of structures, macros, and C functions38* for native code to use to iterate through the list of rectangles39* included in a Java Region object. The intended usage pattern should40* comply with the following code sample:41*42* RegionData rgnInfo;43* Region_GetInfo(env, javaregion, &rgnInfo);44* // Calculate the area of interest for the graphics operation.45* Region_IntersectBounds(&rgnInfo, lox, loy, hix, hiy);46* if (!Region_IsEmpty(&rgnInfo)) {47* If (Region_IsRectangular(&rgnInfo)) {48* // Optional code optimized for a single rectangle49* } else {50* SurfaceDataBounds span;51* Region_StartIteration(env, &rgnInfo);52* // this next line is optional if the info is needed53* int numrects = Region_CountIterationRects(&rgnInfo);54* while (Region_NextIteration(&rgnInfo, &span)) {55* // Process span.x1, span.y1, span.x2, span.y256* }57* Region_EndIteration(env, &rgnInfo);58* }59* }60*/6162/*63* This structure is not meant to be accessed by code outside of64* Region.h or Region.c. It is exposed here so that callers can65* stack-allocate one of these structures for performance.66*/67typedef struct {68SurfaceDataBounds bounds;69jint endIndex;70jobject bands;71jint index;72jint numrects;73jint *pBands;74} RegionData;7576/*77* Initialize a native RegionData structure from a Java object78* of type sun.java2d.pipe.Region.79*80* Note to callers:81* This function may use JNI methods so it is important that the82* caller not have any outstanding GetPrimitiveArrayCritical or83* GetStringCritical locks which have not been released.84*/85JNIEXPORT jint JNICALL86Region_GetInfo(JNIEnv *env, jobject region, RegionData *pRgnInfo);8788/*89* This function retrieves the bounds from a Java Region object and90* returns them in the specified SurfaceDataBounds structure.91*92* Note to callers:93* This function may use JNI methods so it is important that the94* caller not have any outstanding GetPrimitiveArrayCritical or95* GetStringCritical locks which have not been released.96*/97JNIEXPORT void JNICALL98Region_GetBounds(JNIEnv *env, jobject region, SurfaceDataBounds *b);99100/*101* Intersect the specified SurfaceDataBounds with the bounds of102* the indicated RegionData structure. The Region iteration will103* subsequently honor those bounds.104*/105#define Region_IntersectBounds(pRgnInfo, pDstBounds) \106SurfaceData_IntersectBounds(&(pRgnInfo)->bounds, pDstBounds)107108/*109* Intersect the specified bounding coordinates with the bounds of110* the indicated RegionData structure. The Region iteration will111* subsequently honor those bounds.112*/113#define Region_IntersectBoundsXYXY(pRgnInfo, x1, y1, x2, y2) \114SurfaceData_IntersectBoundsXYXY(&(pRgnInfo)->bounds, x1, y1, x2, y2)115116/*117* Test whether the bounds of the specified RegionData structure118* are now trivially empty.119*120* Note that this test only checks the overall bounds of the Region121* and does not check to see if there are any individual subrectangles122* which make up the region that intersect the current bounds.123* Typically a Java Region object will have tight bounds that reflects124* a non-empty set of subrectangles in the list, but after a given125* graphics operation has intersected the RegionData with the area126* of interest for that operation using one of the above calls to127* IntersectBounds, the new bounds may fail to intersect any of128* the subrectangles.129*/130#define Region_IsEmpty(pRgnInfo) \131((pRgnInfo)->bounds.x1 >= (pRgnInfo)->bounds.x2 || \132(pRgnInfo)->bounds.y1 >= (pRgnInfo)->bounds.y2)133134/*135* Test whether the RegionData structure represents a single rectangle.136*137* Note that this test only checks to see if the original Java Region138* object is a simple rectangle and does not take into account the139* subsetting of the list of rectangles that might occur if a given140* graphics operation intersects the bounds with an area of interest.141*/142#define Region_IsRectangular(pRgnInfo) \143((pRgnInfo)->endIndex == 0)144145/*146* Initialize a given RegionData structure for iteration of the147* list of subrectangles. This operation can be performed on148* empty regions, simple rectangular regions and complex regions149* without loss of generality.150*151* Note to callers:152* This function may use JNI Critical methods so it is important153* that the caller not call any other JNI methods after this function154* returns until the RegionEndIteration function is called.155*/156JNIEXPORT void JNICALL157Region_StartIteration(JNIEnv *env, RegionData *pRgnInfo);158159/*160* Count the number of subrectangles in the indicated RegionData.161* The subrectangles will be compared against the bounds of the162* Region so only those subrectangles that intersect the area of163* interest will be included in the returned count.164*165* Note to callers:166* This function may only be called after Region_StartIteration167* and before Region_EndIteration are called on a given RegionData168* structure.169*/170JNIEXPORT jint JNICALL171Region_CountIterationRects(RegionData *pRgnInfo);172173/*174* Process the list of subrectangles in the RegionData structure and175* assign the bounds of that subrectangle to the pSpan structure and176* return a non-zero return value if one exists. If there are no177* more subrectangles in the given area of interest specified by178* the bounds of the RegionData structure, then return 0.179*180* Note to callers:181* This function may only be called after Region_StartIteration182* and before Region_EndIteration are called on a given RegionData183* structure.184*/185JNIEXPORT jint JNICALL186Region_NextIteration(RegionData *pRgnInfo, SurfaceDataBounds *pSpan);187188/*189* Uninitialize a RegionData structure and discard any information190* that was needed to iterate the list of subrectangles.191*192* Note to callers:193* This function will release any outstanding JNI Critical locks so194* it will once again be safe to use arbitrary JNI calls or return195* to the enclosing JNI native context.196*/197JNIEXPORT void JNICALL198Region_EndIteration(JNIEnv *env, RegionData *pRgnInfo);199200201/*202* Converts a sun.java2d.pipe.Region object to a list of203* rectangles using platform specific native data representation204* (see the src/$PLATFORM/native/sun/awt/utility/rect.h header205* files.)206*/207JNIEXPORT int JNICALL208RegionToYXBandedRectangles(JNIEnv *env,209jint x1, jint y1, jint x2, jint y2, jobject region,210RECT_T ** pRect, unsigned int initialBufferSize);211212213#ifdef __cplusplus214};215#endif216217#endif218219220