fixing a few refcounting related issues

This commit is contained in:
pavlov%pavlov.net 2005-06-28 09:27:02 +00:00
parent e79c48491a
commit 7e7b13fc9d
4 changed files with 8 additions and 16 deletions

View File

@ -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<gfxASurface*>(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<void*>(this), 0);
}
virtual ~gfxASurface() {

View File

@ -41,12 +41,12 @@
#include <cairo.h>
#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<gfxASurface> mSurface;
};
#endif /* GFX_CONTEXT_H */

View File

@ -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) \

View File

@ -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;