remove unused variables and store the clipregion in an nsCOMPtr

This commit is contained in:
pavlov%netscape.com 2000-04-21 23:28:23 +00:00
Родитель 2c833f43ce
Коммит dd4ba745fc
4 изменённых файлов: 30 добавлений и 55 удалений

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

@ -34,7 +34,6 @@ nsGraphicsState::nsGraphicsState()
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
nsGraphicsState::~nsGraphicsState() nsGraphicsState::~nsGraphicsState()
{ {
NS_IF_RELEASE(mClipRegion);
NS_IF_RELEASE(mFontMetrics); NS_IF_RELEASE(mFontMetrics);
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////

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

@ -27,13 +27,14 @@
#include "nsIFontMetrics.h" #include "nsIFontMetrics.h"
#include "nsTransform2D.h" #include "nsTransform2D.h"
#include "nsRegionGTK.h" #include "nsRegionGTK.h"
#include "nsCOMPtr.h"
class nsGraphicsState class nsGraphicsState
{ {
public: public:
nsTransform2D *mMatrix; nsTransform2D *mMatrix;
nsIRegion *mClipRegion; nsCOMPtr<nsIRegion> mClipRegion;
nscolor mColor; nscolor mColor;
nsLineStyle mLineStyle; nsLineStyle mLineStyle;
nsIFontMetrics *mFontMetrics; nsIFontMetrics *mFontMetrics;

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

@ -65,9 +65,6 @@ nsRenderingContextGTK::nsRenderingContextGTK()
mGC = nsnull; mGC = nsnull;
mFunction = GDK_COPY; mFunction = GDK_COPY;
mClipIsSet = PR_TRUE;
mFontIsSet = PR_TRUE;
mColorIsSet = PR_TRUE;
PushState(); PushState();
} }
@ -91,7 +88,6 @@ nsRenderingContextGTK::~nsRenderingContextGTK()
if (mTMatrix) if (mTMatrix)
delete mTMatrix; delete mTMatrix;
NS_IF_RELEASE(mClipRegion);
NS_IF_RELEASE(mOffscreenSurface); NS_IF_RELEASE(mOffscreenSurface);
NS_IF_RELEASE(mFontMetrics); NS_IF_RELEASE(mFontMetrics);
NS_IF_RELEASE(mContext); NS_IF_RELEASE(mContext);
@ -279,7 +275,7 @@ NS_IMETHODIMP nsRenderingContextGTK::PushState(PRInt32 aFlags)
if (aFlags & NS_STATE_CLIP) { if (aFlags & NS_STATE_CLIP) {
if (mClipRegion) { if (mClipRegion) {
// set the state's clip region to a new copy of the current clip region // set the state's clip region to a new copy of the current clip region
GetClipRegion(&state->mClipRegion); GetClipRegion(getter_AddRefs(state->mClipRegion));
} }
} }
@ -314,7 +310,7 @@ NS_IMETHODIMP nsRenderingContextGTK::PushState(void)
if (mClipRegion) if (mClipRegion)
{ {
// set the state's clip region to a new copy of the current clip region // set the state's clip region to a new copy of the current clip region
GetClipRegion(&state->mClipRegion); GetClipRegion(getter_AddRefs(state->mClipRegion));
} }
NS_IF_ADDREF(mFontMetrics); NS_IF_ADDREF(mFontMetrics);
@ -344,11 +340,7 @@ NS_IMETHODIMP nsRenderingContextGTK::PopState(PRBool &aClipEmpty)
mTMatrix = state->mMatrix; mTMatrix = state->mMatrix;
} }
// state->mClipRegion might be null, but thats ok. we want that.
NS_IF_RELEASE(mClipRegion);
mClipRegion = state->mClipRegion; mClipRegion = state->mClipRegion;
mClipIsSet = PR_FALSE;
if (state->mFontMetrics && (mFontMetrics != state->mFontMetrics)) if (state->mFontMetrics && (mFontMetrics != state->mFontMetrics))
SetFont(state->mFontMetrics); SetFont(state->mFontMetrics);
@ -454,8 +446,6 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRect(const nsRect& aRect,
nsClipCombine_to_string(aCombine)); nsClipCombine_to_string(aCombine));
#endif // TRACE_SET_CLIP #endif // TRACE_SET_CLIP
mClipIsSet = PR_FALSE;
mTMatrix->TransformCoord(&trect.x, &trect.y, mTMatrix->TransformCoord(&trect.x, &trect.y,
&trect.width, &trect.height); &trect.width, &trect.height);
@ -493,7 +483,6 @@ void nsRenderingContextGTK::UpdateGC()
if (mGC) if (mGC)
gdk_gc_unref(mGC); gdk_gc_unref(mGC);
memset(&values, 0, sizeof(GdkGCValues)); memset(&values, 0, sizeof(GdkGCValues));
values.font = mCurrentFont; values.font = mCurrentFont;
@ -528,8 +517,6 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRegion(const nsIRegion& aRegion,
{ {
CreateClipRegion(); CreateClipRegion();
mClipIsSet = PR_FALSE;
switch(aCombine) switch(aCombine)
{ {
case nsClipCombine_kIntersect: case nsClipCombine_kIntersect:
@ -559,7 +546,7 @@ NS_IMETHODIMP nsRenderingContextGTK::CopyClipRegion(nsIRegion &aRegion)
if (!mClipRegion) if (!mClipRegion)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
aRegion.SetTo(*NS_STATIC_CAST(nsIRegion*, mClipRegion)); aRegion.SetTo(*mClipRegion);
return NS_OK; return NS_OK;
} }
@ -570,25 +557,21 @@ NS_IMETHODIMP nsRenderingContextGTK::GetClipRegion(nsIRegion **aRegion)
if (!aRegion || !mClipRegion) if (!aRegion || !mClipRegion)
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
if (*aRegion) { // copy it, they should be using CopyClipRegion if (mClipRegion) {
// printf("you should be calling CopyClipRegion()\n"); if (*aRegion) { // copy it, they should be using CopyClipRegion
(*aRegion)->SetTo(*mClipRegion); (*aRegion)->SetTo(*mClipRegion);
rv = NS_OK; rv = NS_OK;
} else { } else {
if ( NS_SUCCEEDED(nsComponentManager::CreateInstance(kRegionCID, 0, NS_GET_IID(nsIRegion), nsCOMPtr<nsIRegion> newRegion = do_CreateInstance(kRegionCID, &rv);
(void**)aRegion )) ) if (NS_SUCCEEDED(rv)) {
{ newRegion->Init();
if (mClipRegion) { newRegion->SetTo(*mClipRegion);
(*aRegion)->Init(); NS_ADDREF(*aRegion = newRegion);
(*aRegion)->SetTo(*mClipRegion);
NS_ADDREF(*aRegion);
rv = NS_OK;
} else {
printf("null clip region, can't make a valid copy\n");
NS_RELEASE(*aRegion);
rv = NS_ERROR_FAILURE;
} }
} }
} else {
printf("null clip region, can't make a valid copy\n");
rv = NS_ERROR_FAILURE;
} }
return rv; return rv;
@ -599,14 +582,8 @@ NS_IMETHODIMP nsRenderingContextGTK::SetColor(nscolor aColor)
if (nsnull == mContext) if (nsnull == mContext)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
// return if the colors are the same so that mColorIsSet doesn't get changed and we don't update the GC again
if (mCurrentColor == aColor)
return NS_OK;
mCurrentColor = aColor; mCurrentColor = aColor;
mColorIsSet = PR_FALSE;
return NS_OK; return NS_OK;
} }
@ -637,7 +614,6 @@ NS_IMETHODIMP nsRenderingContextGTK::SetFont(nsIFontMetrics *aFontMetrics)
nsFontHandle fontHandle; nsFontHandle fontHandle;
mFontMetrics->GetFontHandle(fontHandle); mFontMetrics->GetFontHandle(fontHandle);
mCurrentFont = (GdkFont *)fontHandle; mCurrentFont = (GdkFont *)fontHandle;
mFontIsSet = PR_FALSE;
} }
return NS_OK; return NS_OK;

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

@ -185,32 +185,31 @@ public:
void CreateClipRegion() { void CreateClipRegion() {
static NS_DEFINE_CID(kRegionCID, NS_REGION_CID); static NS_DEFINE_CID(kRegionCID, NS_REGION_CID);
if (!mClipRegion) { if (mClipRegion)
PRUint32 w, h; return;
mSurface->GetSize(&w, &h);
PRUint32 w, h;
mSurface->GetSize(&w, &h);
if ( NS_SUCCEEDED(nsComponentManager::CreateInstance(kRegionCID, 0, NS_GET_IID(nsIRegion), (void**)&mClipRegion)) ) { mClipRegion = do_CreateInstance(kRegionCID);
mClipRegion->Init(); if (mClipRegion) {
mClipRegion->SetTo(0,0,w,h); mClipRegion->Init();
} mClipRegion->SetTo(0,0,w,h);
} }
} }
GdkGC *GetGC() { return mGC; } GdkGC *GetGC() { return mGC; }
private: private:
nsDrawingSurfaceGTK *mOffscreenSurface; nsDrawingSurfaceGTK *mOffscreenSurface;
nsDrawingSurfaceGTK *mSurface; nsDrawingSurfaceGTK *mSurface;
nsIDeviceContext *mContext; nsIDeviceContext *mContext;
nsIFontMetrics *mFontMetrics; nsIFontMetrics *mFontMetrics;
nsIRegion *mClipRegion; nsCOMPtr<nsIRegion> mClipRegion;
nsTransform2D *mTMatrix; nsTransform2D *mTMatrix;
float mP2T; float mP2T;
GdkWChar* mDrawStringBuf; GdkWChar* mDrawStringBuf;
PRUint32 mDrawStringSize; PRUint32 mDrawStringSize;
PRBool mClipIsSet;
PRBool mFontIsSet;
PRBool mColorIsSet;
// graphic state stack (GraphicsState) // graphic state stack (GraphicsState)
nsVoidArray *mStateCache; nsVoidArray *mStateCache;