Performance: use GetSpaceWidth() / removed mOriginalClipRegion and replaced it with mMainRegion.

This commit is contained in:
pierre%netscape.com 1999-05-07 04:10:38 +00:00
Родитель f6a730da57
Коммит 78190756bd
2 изменённых файлов: 28 добавлений и 46 удалений

Просмотреть файл

@ -50,14 +50,6 @@ GraphicState::GraphicState()
// everything is initialized to 0 through the 'new' operator // everything is initialized to 0 through the 'new' operator
} }
//------------------------------------------------------------------------
GraphicState::GraphicState(GraphicState* aGS)
{
this->Duplicate(aGS);
}
//------------------------------------------------------------------------ //------------------------------------------------------------------------
GraphicState::~GraphicState() GraphicState::~GraphicState()
@ -87,12 +79,6 @@ void GraphicState::Clear()
mClipRegion = nsnull; mClipRegion = nsnull;
} }
if (mOriginalClipRegion)
{
::DisposeRgn(mOriginalClipRegion);
mOriginalClipRegion = nsnull;
}
NS_IF_RELEASE(mFontMetrics); NS_IF_RELEASE(mFontMetrics);
mOffx = 0; mOffx = 0;
@ -130,8 +116,6 @@ void GraphicState::Init(GrafPtr aPort)
mMainRegion = rgn; mMainRegion = rgn;
mClipRegion = DuplicateRgn(rgn); mClipRegion = DuplicateRgn(rgn);
mOriginalClipRegion = DuplicateRgn(rgn);
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@ -148,7 +132,6 @@ void GraphicState::Init(nsIWidget* aWindow)
RgnHandle widgetRgn = (RgnHandle)aWindow->GetNativeData(NS_NATIVE_REGION); RgnHandle widgetRgn = (RgnHandle)aWindow->GetNativeData(NS_NATIVE_REGION);
mMainRegion = DuplicateRgn(widgetRgn); mMainRegion = DuplicateRgn(widgetRgn);
mClipRegion = DuplicateRgn(widgetRgn); mClipRegion = DuplicateRgn(widgetRgn);
mOriginalClipRegion = DuplicateRgn(widgetRgn);
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@ -169,7 +152,6 @@ void GraphicState::Duplicate(GraphicState* aGS)
mMainRegion = DuplicateRgn(aGS->mMainRegion); mMainRegion = DuplicateRgn(aGS->mMainRegion);
mClipRegion = DuplicateRgn(aGS->mClipRegion); mClipRegion = DuplicateRgn(aGS->mClipRegion);
mOriginalClipRegion = DuplicateRgn(aGS->mOriginalClipRegion);
mColor = aGS->mColor; mColor = aGS->mColor;
mFont = aGS->mFont; mFont = aGS->mFont;
@ -281,8 +263,8 @@ NS_IMETHODIMP nsRenderingContextMac::Init(nsIDeviceContext* aContext, nsIWidget*
mFrontSurface->Init(aWindow); mFrontSurface->Init(aWindow);
SelectDrawingSurface(mFrontSurface); SelectDrawingSurface(mFrontSurface);
// NOTE: here, we used to clip out the children from mGS->mMainRegion and copy // NOTE: here, we used to clip out the children from mGS->mMainRegion
// the resulting region into mMainRegion, mClipRegion and mOriginalClipRegion. // and copy the resulting region into mMainRegion and mClipRegion.
// This is no longer necessary because when initializing mGS from an nsIWidget, we // This is no longer necessary because when initializing mGS from an nsIWidget, we
// call GetNativeData(NS_NATIVE_REGION) that now returns the widget's visRegion // call GetNativeData(NS_NATIVE_REGION) that now returns the widget's visRegion
// with the children already clipped out (as well as the areas masked by the // with the children already clipped out (as well as the areas masked by the
@ -537,7 +519,7 @@ NS_IMETHODIMP nsRenderingContextMac :: CopyOffScreenBits(nsDrawingSurface aSrcSu
if (aCopyFlags & NS_COPYBITS_USE_SOURCE_CLIP_REGION) if (aCopyFlags & NS_COPYBITS_USE_SOURCE_CLIP_REGION)
clipRgn = srcPort->clipRgn; clipRgn = srcPort->clipRgn;
else else
clipRgn = mGS->mOriginalClipRegion; clipRgn = mGS->mMainRegion;
// clipRgn = nil; // clipRgn = nil;
// get the destination port and surface // get the destination port and surface
@ -700,17 +682,21 @@ NS_IMETHODIMP nsRenderingContextMac :: IsVisibleRect(const nsRect& aRect, PRBool
//------------------------------------------------------------------------ //------------------------------------------------------------------------
NS_IMETHODIMP nsRenderingContextMac :: SetClipRectInPixels(const nsRect& aRect, nsClipCombine aCombine, PRBool &aClipEmpty) NS_IMETHODIMP nsRenderingContextMac :: SetClipRect(const nsRect& aRect, nsClipCombine aCombine, PRBool &aClipEmpty)
{ {
nsRect trect = aRect;
mGS->mTMatrix->TransformCoord(&trect.x, &trect.y, &trect.width, &trect.height);
Rect macRect; Rect macRect;
::SetRect(&macRect, aRect.x, aRect.y, aRect.x + aRect.width, aRect.y + aRect.height); ::SetRect(&macRect, trect.x, trect.y, trect.x + trect.width, trect.y + trect.height);
RgnHandle rectRgn = ::NewRgn(); RgnHandle rectRgn = ::NewRgn();
::RectRgn(rectRgn, &macRect);
RgnHandle clipRgn = mGS->mClipRegion; RgnHandle clipRgn = mGS->mClipRegion;
if (clipRgn == nsnull) if (!clipRgn || !rectRgn)
clipRgn = ::NewRgn(); return NS_ERROR_OUT_OF_MEMORY;
::RectRgn(rectRgn, &macRect);
switch (aCombine) switch (aCombine)
{ {
@ -728,7 +714,7 @@ NS_IMETHODIMP nsRenderingContextMac :: SetClipRectInPixels(const nsRect& aRect,
case nsClipCombine_kReplace: case nsClipCombine_kReplace:
// ::CopyRgn(rectRgn, clipRgn); // ::CopyRgn(rectRgn, clipRgn);
::SectRgn(rectRgn, mGS->mOriginalClipRegion, clipRgn); ::SectRgn(rectRgn, mGS->mMainRegion, clipRgn);
break; break;
} }
::DisposeRgn(rectRgn); ::DisposeRgn(rectRgn);
@ -745,17 +731,6 @@ NS_IMETHODIMP nsRenderingContextMac :: SetClipRectInPixels(const nsRect& aRect,
//------------------------------------------------------------------------ //------------------------------------------------------------------------
NS_IMETHODIMP nsRenderingContextMac :: SetClipRect(const nsRect& aRect, nsClipCombine aCombine, PRBool &aClipEmpty)
{
nsRect trect = aRect;
mGS->mTMatrix->TransformCoord(&trect.x, &trect.y,&trect.width, &trect.height);
return SetClipRectInPixels(trect, aCombine, aClipEmpty);
}
//------------------------------------------------------------------------
NS_IMETHODIMP nsRenderingContextMac :: GetClipRect(nsRect &aRect, PRBool &aClipValid) NS_IMETHODIMP nsRenderingContextMac :: GetClipRect(nsRect &aRect, PRBool &aClipValid)
{ {
Rect cliprect; Rect cliprect;
@ -783,11 +758,7 @@ NS_IMETHODIMP nsRenderingContextMac :: SetClipRegion(const nsIRegion& aRegion, n
aRegion.GetNativeRegion(regionH); aRegion.GetNativeRegion(regionH);
RgnHandle clipRgn = mGS->mClipRegion; RgnHandle clipRgn = mGS->mClipRegion;
if (!clipRgn) if (!clipRgn) return NS_ERROR_OUT_OF_MEMORY;
{
clipRgn = ::NewRgn();
if (!clipRgn) return NS_ERROR_OUT_OF_MEMORY;
}
switch (aCombine) switch (aCombine)
{ {
@ -805,7 +776,7 @@ NS_IMETHODIMP nsRenderingContextMac :: SetClipRegion(const nsIRegion& aRegion, n
case nsClipCombine_kReplace: case nsClipCombine_kReplace:
// ::CopyRgn(regionH, clipRgn); // ::CopyRgn(regionH, clipRgn);
::SectRgn(regionH, mGS->mOriginalClipRegion, clipRgn); ::SectRgn(regionH, mGS->mMainRegion, clipRgn);
break; break;
} }
@ -1258,6 +1229,12 @@ NS_IMETHODIMP nsRenderingContextMac :: FillArc(nscoord aX, nscoord aY, nscoord a
NS_IMETHODIMP nsRenderingContextMac :: GetWidth(char ch, nscoord &aWidth) NS_IMETHODIMP nsRenderingContextMac :: GetWidth(char ch, nscoord &aWidth)
{ {
if (ch == ' ' && mGS->mFontMetrics)
{
nsFontMetricsMac* fontMetricsMac = static_cast<nsFontMetricsMac*>(mGS->mFontMetrics);
return fontMetricsMac->GetSpaceWidth(aWidth);
}
char buf[1]; char buf[1];
buf[0] = ch; buf[0] = ch;
return GetWidth(buf, 1, aWidth); return GetWidth(buf, 1, aWidth);
@ -1267,6 +1244,12 @@ NS_IMETHODIMP nsRenderingContextMac :: GetWidth(char ch, nscoord &aWidth)
NS_IMETHODIMP nsRenderingContextMac :: GetWidth(PRUnichar ch, nscoord &aWidth, PRInt32 *aFontID) NS_IMETHODIMP nsRenderingContextMac :: GetWidth(PRUnichar ch, nscoord &aWidth, PRInt32 *aFontID)
{ {
if (ch == ' ' && mGS->mFontMetrics)
{
nsFontMetricsMac* fontMetricsMac = static_cast<nsFontMetricsMac*>(mGS->mFontMetrics);
return fontMetricsMac->GetSpaceWidth(aWidth);
}
PRUnichar buf[1]; PRUnichar buf[1];
buf[0] = ch; buf[0] = ch;
return GetWidth(buf, 1, aWidth, aFontID); return GetWidth(buf, 1, aWidth, aFontID);

Просмотреть файл

@ -118,7 +118,6 @@ public:
const nsRect &aDestBounds, PRUint32 aCopyFlags); const nsRect &aDestBounds, PRUint32 aCopyFlags);
//locals //locals
NS_IMETHOD SetClipRectInPixels(const nsRect& aRect, nsClipCombine aCombine, PRBool &aClipEmpty);
NS_IMETHOD SetPortTextState(); NS_IMETHOD SetPortTextState();
nsresult Init(nsIDeviceContext* aContext, GrafPtr aPort); nsresult Init(nsIDeviceContext* aContext, GrafPtr aPort);