mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 14:55:47 +00:00
Add #ifdef use of graphics state pool.
This commit is contained in:
parent
c0ae575180
commit
c4c2d1d42d
@ -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;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -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___ */
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user