additional fixes for bug #37352. reduce region creation/mallocing

This commit is contained in:
pavlov%netscape.com 2000-04-28 20:08:16 +00:00
parent 05b9ed63a8
commit 6458ce2a4e
3 changed files with 107 additions and 61 deletions

View File

@ -1,23 +1,23 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Stuart Parmenter.
* Portions created by Stuart Parmenter are Copyright (C) 1998-2000
* Stuart Parmenter. All Rights Reserved.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#include <gtk/gtk.h>
@ -136,12 +136,14 @@ void nsRegionGTK::Union(const nsIRegion &aRegion)
{
nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
if (mRegion) {
GdkRegion *nRegion = ::gdk_regions_union(mRegion, pRegion->mRegion);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
} else {
mRegion = gdk_region_copy(pRegion->mRegion);
if (pRegion->mRegion) {
if (mRegion) {
GdkRegion *nRegion = ::gdk_regions_union(mRegion, pRegion->mRegion);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
} else {
mRegion = gdk_region_copy(pRegion->mRegion);
}
}
}
@ -166,12 +168,14 @@ void nsRegionGTK::Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
void nsRegionGTK::Subtract(const nsIRegion &aRegion)
{
nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
if (mRegion) {
GdkRegion *nRegion = ::gdk_regions_subtract(mRegion, pRegion->mRegion);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
} else {
mRegion = ::gdk_regions_subtract(GetCopyRegion(), pRegion->mRegion);
if (pRegion->mRegion) {
if (mRegion) {
GdkRegion *nRegion = ::gdk_regions_subtract(mRegion, pRegion->mRegion);
::gdk_region_destroy(mRegion);
mRegion = nRegion;
} else {
mRegion = ::gdk_regions_subtract(GetCopyRegion(), pRegion->mRegion);
}
}
}
@ -215,38 +219,47 @@ PRBool nsRegionGTK::IsEqual(const nsIRegion &aRegion)
void nsRegionGTK::GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
{
GdkRectangle rect;
if (mRegion) {
GdkRectangle rect;
::gdk_region_get_clipbox(mRegion, &rect);
::gdk_region_get_clipbox(mRegion, &rect);
*aX = rect.x;
*aY = rect.y;
*aWidth = rect.width;
*aHeight = rect.height;
*aX = rect.x;
*aY = rect.y;
*aWidth = rect.width;
*aHeight = rect.height;
} else {
*aX = 0;
*aY = 0;
*aWidth = 0;
*aHeight = 0;
}
}
void nsRegionGTK::Offset(PRInt32 aXOffset, PRInt32 aYOffset)
{
::gdk_region_offset(mRegion, aXOffset, aYOffset);
if (mRegion) {
::gdk_region_offset(mRegion, aXOffset, aYOffset);
}
}
PRBool nsRegionGTK::ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
GdkOverlapType containment;
GdkRectangle rect;
if (mRegion) {
GdkOverlapType containment;
GdkRectangle rect;
rect.x = aX;
rect.y = aY;
rect.width = aWidth;
rect.height = aHeight;
rect.x = aX;
rect.y = aY;
rect.width = aWidth;
rect.height = aHeight;
containment = ::gdk_region_rect_in(mRegion, &rect);
if (containment != GDK_OVERLAP_RECTANGLE_OUT)
return PR_TRUE;
else
return PR_FALSE;
containment = ::gdk_region_rect_in(mRegion, &rect);
if (containment != GDK_OVERLAP_RECTANGLE_OUT)
return PR_TRUE;
}
return PR_FALSE;
}
NS_IMETHODIMP nsRegionGTK::GetRects(nsRegionRectSet **aRects)

View File

@ -1,23 +1,23 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Stuart Parmenter.
* Portions created by Stuart Parmenter are Copyright (C) 1998-2000
* Stuart Parmenter. All Rights Reserved.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
*/
#ifndef nsRegionGTK_h___
@ -64,9 +64,10 @@ protected:
private:
inline GdkRegion *GetCopyRegion();
inline void SetRegionEmpty();
GdkRegion *mRegion;
static GdkRegion *copyRegion;
void SetRegionEmpty();
};
#endif // nsRegionGTK_h___

View File

@ -273,10 +273,7 @@ NS_IMETHODIMP nsRenderingContextGTK::PushState(PRInt32 aFlags)
}
if (aFlags & NS_STATE_CLIP) {
if (mClipRegion) {
// set the state's clip region to a new copy of the current clip region
GetClipRegion(getter_AddRefs(state->mClipRegion));
}
state->mClipRegion = mClipRegion;
}
if (aFlags & NS_STATE_LINESTYLE) {
@ -307,11 +304,8 @@ NS_IMETHODIMP nsRenderingContextGTK::PushState(void)
else
mTMatrix = new nsTransform2D(mTMatrix);
if (mClipRegion)
{
// set the state's clip region to a new copy of the current clip region
GetClipRegion(getter_AddRefs(state->mClipRegion));
}
// set state to mClipRegion.. SetClip{Rect,Region}() will do copy-on-write stuff
state->mClipRegion = mClipRegion;
NS_IF_ADDREF(mFontMetrics);
state->mFontMetrics = mFontMetrics;
@ -437,6 +431,26 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRect(const nsRect& aRect,
nsClipCombine aCombine,
PRBool &aClipEmpty)
{
PRUint32 cnt = mStateCache->Count();
nsGraphicsState *state = nsnull;
if (cnt > 0) {
state = (nsGraphicsState *)mStateCache->ElementAt(cnt - 1);
}
if (state) {
if (state->mClipRegion) {
if (state->mClipRegion == mClipRegion) {
nsCOMPtr<nsIRegion> tmpRgn;
GetClipRegion(getter_AddRefs(tmpRgn));
mClipRegion = tmpRgn;
}
}
}
CreateClipRegion();
nsRect trect = aRect;
@ -515,6 +529,24 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRegion(const nsIRegion& aRegion,
nsClipCombine aCombine,
PRBool &aClipEmpty)
{
PRUint32 cnt = mStateCache->Count();
nsGraphicsState *state = nsnull;
if (cnt > 0) {
state = (nsGraphicsState *)mStateCache->ElementAt(cnt - 1);
}
if (state) {
if (state->mClipRegion) {
if (state->mClipRegion == mClipRegion) {
nsCOMPtr<nsIRegion> tmpRgn;
GetClipRegion(getter_AddRefs(tmpRgn));
mClipRegion = tmpRgn;
}
}
}
CreateClipRegion();
switch(aCombine)