Add #ifdef use of graphics state pool.

This commit is contained in:
ramiro%netscape.com 1999-06-10 13:11:22 +00:00
parent c0ae575180
commit c4c2d1d42d
3 changed files with 132 additions and 5 deletions

View File

@ -18,6 +18,7 @@
#include "nsGraphicsStateGTK.h"
//////////////////////////////////////////////////////////////////////////
nsGraphicsState::nsGraphicsState()
{
mMatrix = nsnull;
@ -26,9 +27,96 @@ nsGraphicsState::nsGraphicsState()
mLineStyle = nsLineStyle_kSolid;
mFontMetrics = nsnull;
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsState::~nsGraphicsState()
{
NS_IF_RELEASE(mClipRegion);
NS_IF_RELEASE(mFontMetrics);
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool::nsGraphicsStatePool()
{
mFreeList = nsnull;
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// Public nsGraphicsStatePool
//
//////////////////////////////////////////////////////////////////////////
/* static */ nsGraphicsState *
nsGraphicsStatePool::GetNewGS()
{
nsGraphicsStatePool * thePool = PrivateGetPool();
return thePool->PrivateGetNewGS();
}
//////////////////////////////////////////////////////////////////////////
/* static */ void
nsGraphicsStatePool::ReleaseGS(nsGraphicsState* aGS)
{
nsGraphicsStatePool * thePool = PrivateGetPool();
thePool->PrivateReleaseGS(aGS);
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
//
// Private nsGraphicsStatePool
//
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool *
nsGraphicsStatePool::gsThePool = nsnull;
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool *
nsGraphicsStatePool::PrivateGetPool()
{
if (nsnull == gsThePool)
{
gsThePool = new nsGraphicsStatePool();
}
return gsThePool;
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsStatePool::~nsGraphicsStatePool()
{
nsGraphicsState* gs = mFreeList;
while (gs != nsnull) {
nsGraphicsState* next = gs->mNext;
delete gs;
gs = next;
}
}
//////////////////////////////////////////////////////////////////////////
nsGraphicsState *
nsGraphicsStatePool::PrivateGetNewGS()
{
nsGraphicsState* gs = mFreeList;
if (gs != nsnull) {
mFreeList = gs->mNext;
return gs;
}
return new nsGraphicsState;
}
//////////////////////////////////////////////////////////////////////////
void
nsGraphicsStatePool::PrivateReleaseGS(nsGraphicsState* aGS)
{
// aGS->Clear();
aGS->mNext = mFreeList;
mFreeList = aGS;
}
//////////////////////////////////////////////////////////////////////////

View File

@ -27,14 +27,45 @@
class nsGraphicsState
{
public:
nsGraphicsState();
virtual ~nsGraphicsState();
nsTransform2D *mMatrix;
nsRegionGTK *mClipRegion;
nscolor mColor;
nsLineStyle mLineStyle;
nsIFontMetrics *mFontMetrics;
nsGraphicsState *mNext; // link into free list of graphics states.
friend class nsGraphicsStatePool;
#ifndef USE_GS_POOL
friend class nsRenderingContextGTK;
#endif
private:
nsGraphicsState();
~nsGraphicsState();
};
class nsGraphicsStatePool
{
public:
static nsGraphicsState * GetNewGS();
static void ReleaseGS(nsGraphicsState* aGS);
private:
nsGraphicsStatePool();
~nsGraphicsStatePool();
nsGraphicsState* mFreeList;
static nsGraphicsStatePool * PrivateGetPool();
nsGraphicsState * PrivateGetNewGS();
void PrivateReleaseGS(nsGraphicsState* aGS);
static nsGraphicsStatePool * gsThePool;
};
#endif /* nsGraphicsStateGTK_h___ */

View File

@ -217,8 +217,12 @@ NS_IMETHODIMP nsRenderingContextGTK::GetDeviceContext(nsIDeviceContext *&aContex
NS_IMETHODIMP nsRenderingContextGTK::PushState(void)
{
nsGraphicsState *state = new nsGraphicsState();
// Get a new GS
#ifdef USE_GS_POOL
nsGraphicsState *state = nsGraphicsStatePool::GetNewGS();
#else
nsGraphicsState *state = new nsGraphicsState;
#endif
// Push into this state object, add to vector
state->mMatrix = mTMatrix;
@ -282,7 +286,11 @@ NS_IMETHODIMP nsRenderingContextGTK::PopState(PRBool &aClipEmpty)
SetLineStyle(state->mLineStyle);
// Delete this graphics state object
#ifdef USE_GS_POOL
nsGraphicsStatePool::ReleaseGS(state);
#else
delete state;
#endif
}
if (mClipRegion)