From 09eb9877d33c9b31bc824c7ebc59bcb9f6bf60b7 Mon Sep 17 00:00:00 2001 From: Joe Drew Date: Thu, 11 Nov 2010 15:31:23 -0500 Subject: [PATCH] Bug 575521 - Add gfxQuartzSurface::GetAsImageSurface. r=jrmuizel,vlad --- gfx/thebes/gfxQuartzSurface.cpp | 17 +++++++++++++++++ gfx/thebes/gfxQuartzSurface.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/gfx/thebes/gfxQuartzSurface.cpp b/gfx/thebes/gfxQuartzSurface.cpp index 76cc57cb74b..f344386ea3b 100644 --- a/gfx/thebes/gfxQuartzSurface.cpp +++ b/gfx/thebes/gfxQuartzSurface.cpp @@ -117,6 +117,23 @@ PRInt32 gfxQuartzSurface::GetDefaultContextFlags() const return 0; } +already_AddRefed gfxQuartzSurface::GetAsImageSurface() +{ + cairo_surface_t *surface = cairo_quartz_surface_get_image(mSurface); + if (!surface) + return nsnull; + + nsRefPtr img = Wrap(surface); + + // cairo_quartz_surface_get_image returns a referenced image, and thebes + // shares the refcounts of Cairo surfaces. However, Wrap also adds a + // reference to the image. We need to remove one of these references + // explicitly so we don't leak. + img->Release(); + + return static_cast(img.forget().get()); +} + gfxQuartzSurface::~gfxQuartzSurface() { CGContextRelease(mCGContext); diff --git a/gfx/thebes/gfxQuartzSurface.h b/gfx/thebes/gfxQuartzSurface.h index 25358a8cea6..65ac8fec8db 100644 --- a/gfx/thebes/gfxQuartzSurface.h +++ b/gfx/thebes/gfxQuartzSurface.h @@ -73,6 +73,8 @@ public: virtual PRInt32 GetDefaultContextFlags() const; + already_AddRefed GetAsImageSurface(); + protected: CGContextRef mCGContext; gfxSize mSize;