renamed GraphicState "nsGraphicState", put it in a sepate file, added memory pools for GraphicStates and native regions.

This commit is contained in:
pierre%netscape.com 1999-05-12 07:27:31 +00:00
Родитель ddb408f173
Коммит 9fce556ee9
9 изменённых файлов: 123 добавлений и 219 удалений

Двоичные данные
gfx/macbuild/gfx.mcp

Двоичный файл не отображается.

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

@ -356,7 +356,7 @@ nsATSUIToolkit::nsATSUIToolkit()
//
//------------------------------------------------------------------------
void nsATSUIToolkit::PrepareToDraw(PRBool aFontOrColorChanged, GraphicState* aGS, GrafPtr aPort, nsIDeviceContext* aContext)
void nsATSUIToolkit::PrepareToDraw(PRBool aFontOrColorChanged, nsGraphicState* aGS, GrafPtr aPort, nsIDeviceContext* aContext)
{
mFontOrColorChanged |= aFontOrColorChanged;
mGS = aGS;

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

@ -29,7 +29,7 @@
class ATSUILayoutCache;
class nsDrawingSurfaceMac;
class nsIDeviceContext;
class GraphicState;
class nsGraphicState;
class nsATSUIUtils
@ -54,7 +54,7 @@ public:
nsATSUIToolkit();
~nsATSUIToolkit() {};
void PrepareToDraw(PRBool aFontOrColorChanged, GraphicState* aGS, GrafPtr aPort, nsIDeviceContext* aContext);
void PrepareToDraw(PRBool aFontOrColorChanged, nsGraphicState* aGS, GrafPtr aPort, nsIDeviceContext* aContext);
NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth, PRInt32 *aFontID);
NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY, PRInt32 aFontID, const nscoord* aSpacing);
@ -64,9 +64,9 @@ private:
private:
ATSUTextLayout mLastTextLayout;
PRBool mFontOrColorChanged;
GraphicState* mGS;
GrafPtr mPort;
PRBool mFontOrColorChanged;
nsGraphicState* mGS;
GrafPtr mPort;
nsIDeviceContext* mContext;
};

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

@ -18,6 +18,7 @@
#include "nsDrawingSurfaceMac.h"
#include "nsGraphicState.h"
static NS_DEFINE_IID(kIDrawingSurfaceIID, NS_IDRAWING_SURFACE_IID);
@ -34,7 +35,7 @@ nsDrawingSurfaceMac :: nsDrawingSurfaceMac()
NS_INIT_REFCNT();
mPort = NULL;
mGS = new GraphicState();
mGS = sGraphicStatePool.GetNewGS(); //new nsGraphicState();
mWidth = mHeight = 0;
mLockOffset = mLockHeight = 0;
mLockFlags = 0;
@ -58,7 +59,7 @@ GWorldPtr offscreenGWorld;
}
if (mGS){
delete mGS;
sGraphicStatePool.ReleaseGS(mGS); //delete mGS;
}
}

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

@ -22,39 +22,7 @@
#include "nsIDrawingSurface.h"
#include "nsIDrawingSurfaceMac.h"
#include "nsFontMetricsMac.h"
class GraphicState
{
public:
GraphicState();
~GraphicState();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
void Clear();
void Init(nsDrawingSurface aSurface);
void Init(GrafPtr aPort);
void Init(nsIWidget* aWindow);
void Duplicate(GraphicState* aGS); // would you prefer an '=' operator?
protected:
RgnHandle DuplicateRgn(RgnHandle aRgn);
public:
nsTransform2D * mTMatrix; // transform that all the graphics drawn here will obey
PRInt32 mOffx;
PRInt32 mOffy;
RgnHandle mMainRegion;
RgnHandle mClipRegion;
nscolor mColor;
PRInt32 mFont;
nsIFontMetrics * mFontMetrics;
PRInt32 mCurrFontHandle;
};
#include "nsGraphicState.h"
class nsDrawingSurfaceMac : public nsIDrawingSurface,
@ -84,7 +52,7 @@ public:
NS_IMETHOD GetGrafPtr(GrafPtr *aTheGrafPtr) {*aTheGrafPtr = mPort;return NS_OK;}
// locals
GraphicState* GetGS(void) {return mGS;}
nsGraphicState* GetGS(void) {return mGS;}
private:
GrafPtr mPort; // the onscreen or offscreen GrafPtr;
@ -96,7 +64,7 @@ private:
PRUint32 mLockFlags;
PRBool mIsOffscreen;
GraphicState* mGS; // a graphics state for the surface
nsGraphicState* mGS; // a graphics state for the surface
};
#endif

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

@ -19,6 +19,65 @@
#include "nsRegionMac.h"
#include "prmem.h"
nsNativeRegionPool sNativeRegionPool;
//------------------------------------------------------------------------
nsNativeRegionPool::nsNativeRegionPool()
{
for (short i = 0; i < kRegionPoolCount; i ++)
{
mRegionArray[i].mRegion = ::NewRgn();
mRegionArray[i].mFree = PR_TRUE;
}
}
//------------------------------------------------------------------------
nsNativeRegionPool::~nsNativeRegionPool()
{
for (short i = 0; i < kRegionPoolCount; i ++)
{
::DisposeRgn(mRegionArray[i].mRegion);
}
}
//------------------------------------------------------------------------
RgnHandle nsNativeRegionPool::GetNewRegion()
{
for (short i = 0; i < kRegionPoolCount; i ++)
{
if (mRegionArray[i].mFree)
{
mRegionArray[i].mFree = PR_FALSE;
return mRegionArray[i].mRegion;
}
}
return (::NewRgn()); // we overflew the pool: return a new region
}
//------------------------------------------------------------------------
void nsNativeRegionPool::ReleaseRegion(RgnHandle aRgnHandle)
{
for (short i = 0; i < kRegionPoolCount; i ++)
{
if (mRegionArray[i].mRegion == aRgnHandle)
{
::SetEmptyRgn(mRegionArray[i].mRegion);
mRegionArray[i].mFree = PR_TRUE;
return;
}
}
::DisposeRgn(aRgnHandle); // we overflew the pool: delete the GraphicState
}
#pragma mark -
//------------------------------------------------------------------------
static NS_DEFINE_IID(kRegionIID, NS_IREGION_IID);
//---------------------------------------------------------------------
@ -35,19 +94,19 @@ nsRegionMac :: nsRegionMac()
nsRegionMac :: ~nsRegionMac()
{
if (mRegion)
::DisposeRgn(mRegion);
sNativeRegionPool.ReleaseRegion(mRegion); //::DisposeRgn(mRegion);
mRegion = nsnull;
}
NS_IMPL_QUERY_INTERFACE(nsRegionMac, kRegionIID)
NS_IMPL_ADDREF(nsRegionMac)
NS_IMPL_RELEASE(nsRegionMac)
NS_IMPL_QUERY_INTERFACE(nsRegionMac, kRegionIID);
NS_IMPL_ADDREF(nsRegionMac);
NS_IMPL_RELEASE(nsRegionMac);
//---------------------------------------------------------------------
nsresult nsRegionMac :: Init(void)
{
mRegion = ::NewRgn();
mRegion = sNativeRegionPool.GetNewRegion(); //::NewRgn();
mRegionType = eRegionComplexity_empty;
return NS_OK;
}
@ -82,10 +141,10 @@ void nsRegionMac :: Intersect(const nsIRegion &aRegion)
void nsRegionMac :: Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
RgnHandle rectRgn = ::NewRgn();
RgnHandle rectRgn = sNativeRegionPool.GetNewRegion(); //::NewRgn();
::SetRectRgn(rectRgn, aX, aY, aX + aWidth, aY + aHeight);
::SectRgn(mRegion, rectRgn, mRegion);
::DisposeRgn(rectRgn);
sNativeRegionPool.ReleaseRegion(rectRgn); //::DisposeRgn(rectRgn);
SetRegionType();
}
@ -102,10 +161,10 @@ void nsRegionMac :: Union(const nsIRegion &aRegion)
void nsRegionMac :: Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
RgnHandle rectRgn = ::NewRgn();
RgnHandle rectRgn = sNativeRegionPool.GetNewRegion(); //::NewRgn();
::SetRectRgn(rectRgn, aX, aY, aX + aWidth, aY + aHeight);
::UnionRgn(mRegion, rectRgn, mRegion);
::DisposeRgn(rectRgn);
sNativeRegionPool.ReleaseRegion(rectRgn); //::DisposeRgn(rectRgn);
SetRegionType();
}
@ -122,10 +181,10 @@ void nsRegionMac :: Subtract(const nsIRegion &aRegion)
void nsRegionMac :: Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
RgnHandle rectRgn = ::NewRgn();
RgnHandle rectRgn = sNativeRegionPool.GetNewRegion(); //::NewRgn();
::SetRectRgn(rectRgn, aX, aY, aX + aWidth, aY + aHeight);
::DiffRgn(mRegion, rectRgn, mRegion);
::DisposeRgn(rectRgn);
sNativeRegionPool.ReleaseRegion(rectRgn); //::DisposeRgn(rectRgn);
SetRegionType();
}
@ -431,7 +490,7 @@ void nsRegionMac :: SetRegionEmpty()
RgnHandle nsRegionMac :: CreateRectRegion(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
{
RgnHandle rectRgn = ::NewRgn();
RgnHandle rectRgn = sNativeRegionPool.GetNewRegion(); //::NewRgn();
::SetRectRgn(rectRgn, aX, aY, aX + aWidth, aY + aHeight);
return rectRgn;
}

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

@ -22,6 +22,34 @@
#include "nsIRegion.h"
#include <quickdraw.h>
//------------------------------------------------------------------------
class nsNativeRegionPool
{
public:
nsNativeRegionPool();
~nsNativeRegionPool();
RgnHandle GetNewRegion();
void ReleaseRegion(RgnHandle aRgnHandle);
private:
static const short kRegionPoolCount = 200;
typedef struct nsRegionRec
{
RgnHandle mRegion;
PRBool mFree;
} nsRegionRec;
nsRegionRec mRegionArray[kRegionPoolCount];
};
//------------------------------------------------------------------------
extern nsNativeRegionPool sNativeRegionPool;
//------------------------------------------------------------------------
class nsRegionMac : public nsIRegion
{

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

@ -22,6 +22,7 @@
#include "nsIRegion.h"
#include "nsIEnumerator.h"
#include "nsRegionMac.h"
#include "nsGraphicState.h"
#include "nsTransform2D.h"
#include "nsVoidArray.h"
@ -33,164 +34,11 @@
#include <Gestalt.h>
#pragma mark -
//------------------------------------------------------------------------
// GraphicState
//
//------------------------------------------------------------------------
#define DrawingSurface nsDrawingSurfaceMac
//------------------------------------------------------------------------
GraphicState::GraphicState()
{
// everything is initialized to 0 through the 'new' operator
}
//------------------------------------------------------------------------
GraphicState::~GraphicState()
{
Clear();
}
//------------------------------------------------------------------------
void GraphicState::Clear()
{
if (mTMatrix)
{
delete mTMatrix;
mTMatrix = nsnull;
}
if (mMainRegion)
{
::DisposeRgn(mMainRegion);
mMainRegion = nsnull;
}
if (mClipRegion)
{
::DisposeRgn(mClipRegion);
mClipRegion = nsnull;
}
NS_IF_RELEASE(mFontMetrics);
mOffx = 0;
mOffy = 0;
mColor = NS_RGB(255,255,255);
mFont = 0;
mFontMetrics = nsnull;
mCurrFontHandle = 0;
}
//------------------------------------------------------------------------
void GraphicState::Init(nsDrawingSurface aSurface)
{
// retrieve the grafPort
DrawingSurface* surface = static_cast<DrawingSurface*>(aSurface);
GrafPtr port;
surface->GetGrafPtr(&port);
// init from grafPort
Init(port);
}
//------------------------------------------------------------------------
void GraphicState::Init(GrafPtr aPort)
{
// delete old values
Clear();
// init from grafPort (usually an offscreen port)
RgnHandle rgn = ::NewRgn();
#if TARGET_CARBON
if ( rgn ) {
Rect bounds;
::RectRgn(rgn, ::GetPortBounds(aPort, &bounds));
}
#else
if (rgn)
::RectRgn(rgn, &aPort->portRect);
#endif
mMainRegion = rgn;
mClipRegion = DuplicateRgn(rgn);
}
//------------------------------------------------------------------------
void GraphicState::Init(nsIWidget* aWindow)
{
// delete old values
Clear();
// init from widget
mOffx = (PRInt32)aWindow->GetNativeData(NS_NATIVE_OFFSETX);
mOffy = (PRInt32)aWindow->GetNativeData(NS_NATIVE_OFFSETY);
RgnHandle widgetRgn = (RgnHandle)aWindow->GetNativeData(NS_NATIVE_REGION);
mMainRegion = DuplicateRgn(widgetRgn);
mClipRegion = DuplicateRgn(widgetRgn);
}
//------------------------------------------------------------------------
void GraphicState::Duplicate(GraphicState* aGS)
{
// delete old values
Clear();
// copy new ones
if (aGS->mTMatrix)
mTMatrix = new nsTransform2D(aGS->mTMatrix);
else
mTMatrix = nsnull;
mOffx = aGS->mOffx;
mOffy = aGS->mOffy;
mMainRegion = DuplicateRgn(aGS->mMainRegion);
mClipRegion = DuplicateRgn(aGS->mClipRegion);
mColor = aGS->mColor;
mFont = aGS->mFont;
mFontMetrics = aGS->mFontMetrics;
NS_IF_ADDREF(mFontMetrics);
mCurrFontHandle = aGS->mCurrFontHandle;
}
//------------------------------------------------------------------------
RgnHandle GraphicState::DuplicateRgn(RgnHandle aRgn)
{
RgnHandle dupRgn = nsnull;
if (aRgn)
{
dupRgn = ::NewRgn();
if (dupRgn)
::CopyRgn(aRgn, dupRgn);
}
return dupRgn;
}
//------------------------------------------------------------------------
#pragma mark -
static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
//------------------------------------------------------------------------
nsRenderingContextMac::nsRenderingContextMac()
{
@ -241,9 +89,9 @@ nsRenderingContextMac::~nsRenderingContextMac()
PRInt32 cnt = mGSStack->Count();
for (PRInt32 i = 0; i < cnt; i ++)
{
GraphicState* gs = (GraphicState*)mGSStack->ElementAt(i);
nsGraphicState* gs = (nsGraphicState*)mGSStack->ElementAt(i);
if (gs)
delete gs;
sGraphicStatePool.ReleaseGS(gs); //delete gs;
}
delete mGSStack;
mGSStack = nsnull;
@ -405,7 +253,7 @@ NS_IMETHODIMP nsRenderingContextMac::SetPortTextState()
NS_IMETHODIMP nsRenderingContextMac :: PushState(void)
{
// create a GS
GraphicState * gs = new GraphicState();
nsGraphicState * gs = sGraphicStatePool.GetNewGS(); //new nsGraphicState();
if (!gs)
return NS_ERROR_OUT_OF_MEMORY;
@ -426,7 +274,7 @@ NS_IMETHODIMP nsRenderingContextMac :: PopState(PRBool &aClipEmpty)
if (cnt > 0)
{
// get the GS from the stack
GraphicState* gs = (GraphicState *)mGSStack->ElementAt(cnt - 1);
nsGraphicState* gs = (nsGraphicState *)mGSStack->ElementAt(cnt - 1);
// copy the GS into the current one and tell the current surface to use it
mGS->Duplicate(gs);
@ -434,7 +282,7 @@ NS_IMETHODIMP nsRenderingContextMac :: PopState(PRBool &aClipEmpty)
// remove the GS object from the stack and delete it
mGSStack->RemoveElementAt(cnt - 1);
delete gs;
sGraphicStatePool.ReleaseGS(gs); //delete gs;
}
aClipEmpty = (::EmptyRgn(mGS->mClipRegion));
@ -717,7 +565,7 @@ NS_IMETHODIMP nsRenderingContextMac :: SetClipRect(const nsRect& aRect, nsClipCo
Rect macRect;
::SetRect(&macRect, trect.x, trect.y, trect.x + trect.width, trect.y + trect.height);
RgnHandle rectRgn = ::NewRgn();
RgnHandle rectRgn = sNativeRegionPool.GetNewRegion(); //::NewRgn();
RgnHandle clipRgn = mGS->mClipRegion;
if (!clipRgn || !rectRgn)
return NS_ERROR_OUT_OF_MEMORY;
@ -743,7 +591,7 @@ NS_IMETHODIMP nsRenderingContextMac :: SetClipRect(const nsRect& aRect, nsClipCo
::SectRgn(rectRgn, mGS->mMainRegion, clipRgn);
break;
}
::DisposeRgn(rectRgn);
sNativeRegionPool.ReleaseRegion(rectRgn); //::DisposeRgn(rectRgn);
StartDraw();
::SetClip(clipRgn);
@ -889,7 +737,7 @@ NS_IMETHODIMP nsRenderingContextMac :: GetColor(nscolor &aColor) const
NS_IMETHODIMP nsRenderingContextMac :: SetLineStyle(nsLineStyle aLineStyle)
{
// note: the line style must be saved in the GraphicState like font, color, etc...
// note: the line style must be saved in the nsGraphicState like font, color, etc...
NS_NOTYETIMPLEMENTED("nsRenderingContextMac::SetLineStyle");//¥TODO
return NS_OK;
}

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

@ -31,7 +31,7 @@ class nsFont;
class nsTransform2D;
class nsVoidArray;
class GraphicState;
class nsGraphicState;
class DrawingSurface; // a surface is a combination of a port and a graphic state
@ -156,7 +156,7 @@ protected:
nsDrawingSurfaceMac* mCurrentSurface; // pointer to the current surface
GrafPtr mPort; // current grafPort - shortcut for mCurrentSurface->GetPort()
GraphicState * mGS; // current graphic state - shortcut for mCurrentSurface->GetGS()
nsGraphicState * mGS; // current graphic state - shortcut for mCurrentSurface->GetGS()
nsVoidArray * mGSStack; // GraphicStates stack, used for PushState/PopState
PRInt8 mChanges;