1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
39
#include "nsRegionPh.h"
41
/* Turn debug off to limit all the output to PhGfxLog */
45
#include "nsPhGfxLog.h"
48
#define tulx t->rect.ul.x
49
#define tuly t->rect.ul.y
50
#define tlrx t->rect.lr.x
51
#define tlry t->rect.lr.y
53
#define culx c->rect.ul.x
54
#define culy c->rect.ul.y
55
#define clrx c->rect.lr.x
56
#define clry c->rect.lr.y
58
NS_IMPL_ISUPPORTS1(nsRegionPh, nsIRegion)
61
void nsRegionPh :: Intersect( PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight )
63
if( aWidth > 0 && aHeight > 0 ) {
64
/* Create a temporary tile to assign to mRegion */
68
tile.rect.lr.x = (aX+aWidth-1);
69
tile.rect.lr.y = (aY+aHeight-1);
72
PhTile_t *original = mRegion;
73
mRegion = PhIntersectTilings( mRegion, &tile, NULL );
74
PhFreeTiles( original );
75
if ( mRegion == NULL )
83
PRBool nsRegionPh :: IsEqual( const nsIRegion &aRegion ) {
84
PRBool result = PR_TRUE;
86
aRegion.GetNativeRegion((void*&)tiles);
88
/* If both are equal/NULL then it is equal */
89
if( mRegion == tiles ) return PR_TRUE;
90
else if( mRegion == NULL || tiles == NULL ) return PR_FALSE;
92
PhSortTiles( mRegion );
95
PhTile_t *t = mRegion, *c = tiles;
97
if( tulx != culx || tuly != culy || tlrx != clrx || tlry != clry ) {
108
void nsRegionPh :: GetBoundingBox( PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight ) {
110
/* 99.99% there is only one tile - so simplify things, while allow the general case to work as well */
111
if( mRegion && !mRegion->next ) {
112
*aX = mRegion->rect.ul.x;
113
*aY = mRegion->rect.ul.y;
114
*aWidth = mRegion->rect.lr.x - mRegion->rect.ul.x + 1;
115
*aHeight = mRegion->rect.lr.y - mRegion->rect.ul.y + 1;
119
int bX=-32767, bY=-32767;
124
PhTile_t *t = mRegion;
127
*aX = PR_MIN( *aX, tulx );
128
*aY = PR_MIN( *aY, tuly );
129
bX = PR_MAX( bX, tlrx );
130
bY = PR_MAX( bY, tlry );
134
*aWidth = bX - *aX + 1;
135
*aHeight = bY - *aY + 1;
139
PRBool nsRegionPh :: ContainsRect( PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight ) {
140
if( !mRegion ) return PR_FALSE;
142
PhCoalesceTiles( PhMergeTiles( PhSortTiles( mRegion )));
144
/* Create a temporary tile to assign to mRegion */
145
PhTile_t *tile = PhGetTile();
146
tile->rect.ul.x = aX;
147
tile->rect.ul.y = aY;
148
tile->rect.lr.x = (aX+aWidth-1);
149
tile->rect.lr.y = (aY+aHeight-1);
153
test = PhIntersectTilings( tile, mRegion, NULL );
161
else return PR_FALSE;
165
NS_IMETHODIMP nsRegionPh :: GetRects( nsRegionRectSet **aRects ) {
167
/* 99.99% there is only one tile - so simplify things, while allow the general case to work as well */
168
if( mRegion && !mRegion->next ) {
169
if( *aRects == nsnull ) *aRects = ( nsRegionRectSet * ) PR_Malloc( sizeof( nsRegionRectSet ) );
170
nsRegionRect *rect = (*aRects)->mRects;
171
(*aRects)->mRectsLen = (*aRects)->mNumRects = 1;
172
rect->x = mRegion->rect.ul.x;
173
rect->y = mRegion->rect.ul.y;
174
rect->width = mRegion->rect.lr.x - mRegion->rect.ul.x + 1;
175
rect->height = mRegion->rect.lr.y - mRegion->rect.ul.y + 1;
176
(*aRects)->mArea = rect->width * rect->height;
180
/* the general case - old code */
181
nsRegionRectSet *rects;
184
PhTile_t *t = mRegion;
186
while( t ) { nbox++; t = t->next; } /* Count the Tiles */
190
if ((nsnull == rects) || (rects->mRectsLen < (PRUint32) nbox)) {
191
void *buf = PR_Realloc(rects, sizeof(nsRegionRectSet) + (sizeof(nsRegionRect) * (nbox - 1)));//was -1
193
if (nsnull != rects) rects->mNumRects = 0;
197
rects = (nsRegionRectSet *) buf;
198
rects->mRectsLen = nbox;
201
rects->mNumRects = nbox;
203
rect = &rects->mRects[0];
204
t = mRegion; /* Reset tile indexer */
208
rect->width = (tlrx - tulx+1);
210
rect->height = (tlry - tuly+1);
211
rects->mArea += rect->width * rect->height;