diff --git a/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp b/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp index 7e2c4e56d1f..3b1cf2b6124 100644 --- a/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp +++ b/mozilla/gfx/src/gtk/nsGfxFactoryGTK.cpp @@ -145,7 +145,9 @@ nsresult nsGfxFactoryGTK::CreateInstance(nsISupports *aOuter, inst = (nsISupports *)new nsImageGTK(); } else if (mClassID.Equals(kCRegion)) { - inst = (nsISupports *)new nsRegionGTK(); + nsRegionGTK* dcs; + NS_NEWXPCOM(dcs, nsRegionGTK); + inst = (nsISupports *)dcs; } else if (mClassID.Equals(kCBlender)) { inst = (nsISupports *)new nsBlender; diff --git a/mozilla/gfx/src/gtk/nsGraphicsStateGTK.h b/mozilla/gfx/src/gtk/nsGraphicsStateGTK.h index c355d5b9568..fe31d72348c 100644 --- a/mozilla/gfx/src/gtk/nsGraphicsStateGTK.h +++ b/mozilla/gfx/src/gtk/nsGraphicsStateGTK.h @@ -29,7 +29,7 @@ class nsGraphicsState public: nsTransform2D *mMatrix; - nsRegionGTK *mClipRegion; + nsIRegion *mClipRegion; nscolor mColor; nsLineStyle mLineStyle; nsIFontMetrics *mFontMetrics; diff --git a/mozilla/gfx/src/gtk/nsRegionGTK.cpp b/mozilla/gfx/src/gtk/nsRegionGTK.cpp index 5919eea4a96..668ac7394c9 100644 --- a/mozilla/gfx/src/gtk/nsRegionGTK.cpp +++ b/mozilla/gfx/src/gtk/nsRegionGTK.cpp @@ -22,16 +22,30 @@ #include "xregion.h" #include "prmem.h" +#ifdef DEBUG_REGIONS +static int nRegions; +#endif + nsRegionGTK::nsRegionGTK() { NS_INIT_REFCNT(); - + +#ifdef DEBUG_REGIONS + ++nRegions; + printf("REGIONS+ = %i\n", nRegions); +#endif + mRegion = nsnull; mRegionType = eRegionComplexity_empty; } nsRegionGTK::~nsRegionGTK() { +#ifdef DEBUG_REGIONS + --nRegions; + printf("REGIONS- = %i\n", nRegions); +#endif + if (mRegion) ::gdk_region_destroy(mRegion); mRegion = nsnull; @@ -41,7 +55,6 @@ NS_IMPL_ISUPPORTS1(nsRegionGTK, nsIRegion) nsresult nsRegionGTK::Init(void) { - NS_ADDREF_THIS(); mRegion = ::gdk_region_new(); mRegionType = eRegionComplexity_empty; return NS_OK; diff --git a/mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp b/mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp index 42e43ae4fcc..d665b22f2fa 100644 --- a/mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp +++ b/mozilla/gfx/src/gtk/nsRenderingContextGTK.cpp @@ -30,6 +30,7 @@ NS_IMPL_ISUPPORTS1(nsRenderingContextGTK, nsIRenderingContext) +static NS_DEFINE_CID(kRegionCID, NS_REGION_CID); #define NSRECT_TO_GDKRECT(ns,gdk) \ PR_BEGIN_MACRO \ @@ -145,9 +146,11 @@ NS_IMETHODIMP nsRenderingContextGTK::CommonInit() gint x, y, w, h, d; gdk_window_get_geometry(mSurface->GetDrawable(), &x, &y, &w, &h, &d); - mClipRegion = new nsRegionGTK(); - mClipRegion->Init(); - mClipRegion->SetTo(0, 0, w, h); + if ( NS_SUCCEEDED(nsComponentManager::CreateInstance(kRegionCID, 0, NS_GET_IID(nsIRegion), (void**)&mClipRegion)) ) + { + mClipRegion->Init(); + mClipRegion->SetTo(0, 0, w, h); + } mContext->GetDevUnitsToAppUnits(mP2T); float app2dev; @@ -244,12 +247,8 @@ NS_IMETHODIMP nsRenderingContextGTK::PushState(void) if (mClipRegion) { - NS_IF_ADDREF(mClipRegion); - state->mClipRegion = mClipRegion; - - mClipRegion = new nsRegionGTK(); - mClipRegion->Init(); - mClipRegion->SetTo(state->mClipRegion); + // set the state's clip region to a new copy of the current clip region + GetClipRegion(&state->mClipRegion); } NS_IF_ADDREF(mFontMetrics); @@ -277,9 +276,11 @@ NS_IMETHODIMP nsRenderingContextGTK::PopState(PRBool &aClipEmpty) delete mTMatrix; mTMatrix = state->mMatrix; + // get rid of the current clip region NS_IF_RELEASE(mClipRegion); + mClipRegion = nsnull; -// restore everything + // restore everything mClipRegion = state->mClipRegion; mFontMetrics = state->mFontMetrics; @@ -456,23 +457,33 @@ NS_IMETHODIMP nsRenderingContextGTK::GetClipRegion(nsIRegion **aRegion) { nsresult rv = NS_ERROR_FAILURE; - static NS_DEFINE_IID(kRegionCID, NS_REGION_CID); - if (!aRegion) return NS_ERROR_NULL_POINTER; if (*aRegion) // copy it, they should be using CopyClipRegion { - (*aRegion)->SetTo(*NS_STATIC_CAST(nsIRegion*, mClipRegion)); + printf("you should be calling CopyClipRegion()\n"); + (*aRegion)->SetTo(*mClipRegion); rv = NS_OK; } else { - if ( NS_SUCCEEDED(nsComponentManager::CreateInstance(kRegionCID, 0, NS_GET_IID(nsIRegion), (void**)*aRegion)) ) + if ( NS_SUCCEEDED(nsComponentManager::CreateInstance(kRegionCID, 0, NS_GET_IID(nsIRegion), + (void**)aRegion )) ) { - (*aRegion)->Init(); - (*aRegion)->SetTo( *NS_STATIC_CAST(nsIRegion*, mClipRegion) ); - rv = NS_OK; + if (mClipRegion) + { + (*aRegion)->Init(); + (*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; + } } } diff --git a/mozilla/gfx/src/gtk/nsRenderingContextGTK.h b/mozilla/gfx/src/gtk/nsRenderingContextGTK.h index 9dfb9949344..cefb9374430 100644 --- a/mozilla/gfx/src/gtk/nsRenderingContextGTK.h +++ b/mozilla/gfx/src/gtk/nsRenderingContextGTK.h @@ -162,7 +162,7 @@ protected: nsDrawingSurfaceGTK *mSurface; nsIDeviceContext *mContext; nsIFontMetrics *mFontMetrics; - nsRegionGTK *mClipRegion; + nsIRegion *mClipRegion; nsTransform2D *mTMatrix; float mP2T; GdkWChar* mDrawStringBuf;