From 59d969da88f66cc174c2af727d3742e27dfb2b06 Mon Sep 17 00:00:00 2001 From: "pavlov%pavlov.net" Date: Tue, 28 Jun 2005 09:27:02 +0000 Subject: [PATCH] fixing a few refcounting related issues git-svn-id: svn://10.0.0.236/trunk@175210 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/thebes/public/gfxASurface.h | 8 -------- mozilla/gfx/thebes/public/gfxContext.h | 7 ++++--- mozilla/gfx/thebes/public/gfxTypes.h | 1 + mozilla/gfx/thebes/src/gfxContext.cpp | 8 +++----- 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/mozilla/gfx/thebes/public/gfxASurface.h b/mozilla/gfx/thebes/public/gfxASurface.h index 17f5b4cf033..cc6cb263cab 100644 --- a/mozilla/gfx/thebes/public/gfxASurface.h +++ b/mozilla/gfx/thebes/public/gfxASurface.h @@ -42,9 +42,6 @@ #include "gfxTypes.h" -// this key can be used to look up a Surface object given a cairo_surface_t -static cairo_user_data_key_t gSurfaceMapKey; - class gfxASurface { THEBES_DECL_REFCOUNTING @@ -52,14 +49,9 @@ public: /*** this DOES NOT addref the surface */ cairo_surface_t *CairoSurface() { return mSurface; } - static gfxASurface* LookupSurface(cairo_surface_t* surface) { - return static_cast(cairo_surface_get_user_data(surface, &gSurfaceMapKey)); - } - protected: void Init(cairo_surface_t* surface) { mSurface = surface; - cairo_surface_set_user_data(mSurface, &gSurfaceMapKey, static_cast(this), 0); } virtual ~gfxASurface() { diff --git a/mozilla/gfx/thebes/public/gfxContext.h b/mozilla/gfx/thebes/public/gfxContext.h index 30caa2e9ac4..61f08200c8b 100644 --- a/mozilla/gfx/thebes/public/gfxContext.h +++ b/mozilla/gfx/thebes/public/gfxContext.h @@ -41,12 +41,12 @@ #include +#include "gfxASurface.h" #include "gfxColor.h" #include "gfxPoint.h" #include "gfxRect.h" #include "gfxTypes.h" -class gfxASurface; class gfxMatrix; class gfxRegion; class gfxFilter; @@ -60,7 +60,7 @@ public: gfxContext(gfxASurface* surface); ~gfxContext(); - // this will addref + // this does not addref gfxASurface* CurrentSurface(); /** @@ -95,7 +95,7 @@ public: void Rectangle(gfxRect rect, PRBool snapToPixels = PR_FALSE); - void Polygon(const gfxPoint *points, PRUInt32 numPoints); + void Polygon(const gfxPoint *points, PRUint32 numPoints); /** ** Text @@ -245,6 +245,7 @@ public: private: cairo_t *mCairo; + nsRefPtr mSurface; }; #endif /* GFX_CONTEXT_H */ diff --git a/mozilla/gfx/thebes/public/gfxTypes.h b/mozilla/gfx/thebes/public/gfxTypes.h index 8d0b9abeba0..e0e9e6e7dda 100644 --- a/mozilla/gfx/thebes/public/gfxTypes.h +++ b/mozilla/gfx/thebes/public/gfxTypes.h @@ -52,6 +52,7 @@ typedef double gfxFloat; * even though it forces the functions to be virtual... */ #include "nsISupportsImpl.h" +#include "nsAutoPtr.h" #define THEBES_IMPL_REFCOUNTING(_class) \ NS_IMPL_ADDREF(_class) \ diff --git a/mozilla/gfx/thebes/src/gfxContext.cpp b/mozilla/gfx/thebes/src/gfxContext.cpp index 0893cd615d0..949bef87aee 100644 --- a/mozilla/gfx/thebes/src/gfxContext.cpp +++ b/mozilla/gfx/thebes/src/gfxContext.cpp @@ -47,6 +47,7 @@ THEBES_IMPL_REFCOUNTING(gfxContext) gfxContext::gfxContext(gfxASurface* surface) { mCairo = cairo_create(surface->CairoSurface()); + mSurface = surface; } gfxContext::~gfxContext() { @@ -55,10 +56,7 @@ gfxContext::~gfxContext() gfxASurface* gfxContext::CurrentSurface() { - cairo_surface_t *surface = cairo_get_target(mCairo); - gfxASurface *ret = gfxASurface::LookupSurface(surface); - NS_IF_ADDREF(ret); - return ret; + return mSurface; } void gfxContext::Save() @@ -147,7 +145,7 @@ dontsnap: cairo_rectangle(mCairo, rect.pos.x, rect.pos.y, rect.size.width, rect.size.height); } -void gfxContext::Polygon(const gfxPoint *points, unsigned long numPoints) +void gfxContext::Polygon(const gfxPoint *points, PRUint32 numPoints) { if (numPoints == 0) return;